mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-08 11:46:35 +00:00
ensure_php_toolchain installed the php and composer binaries and stopped there. A distro ships the interpreter and its extensions as separate packages, and ensure_command_present returns early once shutil.which finds php - which it always does since the image bakes the interpreter - so the extensions were never provisioned on any path. composer then refused to resolve the vendor tree with "phpunit/phpunit requires ext-dom * -> it is missing from your system" and test-unit-php failed in every workspace job. The loaded ini list in those logs shows 20-mbstring.ini present and no 20-dom.ini, 20-xml.ini or 20-xmlwriter.ini, i.e. php-xml missing. Extensions are now probed against php -m and installed from a per-manager mapping, then re-probed so a package that does not deliver the extension raises instead of leaving composer to fail later. The loop sits in ensure_php_toolchain because both entry points pass through it: the image build via utils.install.interpreters and the test run via scripts/install/php.sh, so a prebuilt image is repaired at test time. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
60 lines
1.8 KiB
Python
60 lines
1.8 KiB
Python
"""PHP toolchain provisioning for the PHP unit suite."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import subprocess
|
|
|
|
from utils import PROJECT_ROOT
|
|
from utils.install.primitives import log
|
|
from utils.install.system_pkg import (
|
|
ensure_command_present,
|
|
ensure_php_extension_present,
|
|
)
|
|
|
|
_PHPUNIT = PROJECT_ROOT / "vendor" / "bin" / "phpunit"
|
|
|
|
_PHPUNIT_EXTENSIONS = ("dom", "mbstring", "xmlwriter")
|
|
|
|
|
|
def ensure_php_toolchain() -> None:
|
|
"""Install the PHP interpreter, Composer and the extensions PHPUnit needs.
|
|
|
|
``phpunit/phpunit ^11`` declares ``_PHPUNIT_EXTENSIONS`` as platform
|
|
requirements and Composer refuses to resolve the vendor tree without them,
|
|
so they are part of the toolchain rather than of the suite consuming it.
|
|
A distro ships them as packages separate from the interpreter, which is why
|
|
a present ``php`` binary does not imply they are there.
|
|
|
|
Raises:
|
|
RuntimeError: php, composer or one of the extensions is still absent.
|
|
"""
|
|
ensure_command_present("php")
|
|
ensure_command_present("composer")
|
|
for extension in _PHPUNIT_EXTENSIONS:
|
|
ensure_php_extension_present(extension)
|
|
|
|
|
|
def ensure_php_present() -> None:
|
|
"""Install the PHP toolchain and the Composer vendor tree.
|
|
|
|
Raises:
|
|
RuntimeError: php, composer or phpunit is still absent afterwards.
|
|
subprocess.CalledProcessError: ``composer install`` failed.
|
|
"""
|
|
ensure_php_toolchain()
|
|
|
|
if not _PHPUNIT.is_file():
|
|
log("phpunit missing; running composer install.")
|
|
subprocess.run(
|
|
["composer", "install", "--no-interaction", "--no-progress"],
|
|
cwd=PROJECT_ROOT,
|
|
check=True,
|
|
)
|
|
|
|
if not _PHPUNIT.is_file():
|
|
raise RuntimeError(f"{_PHPUNIT} missing after composer install")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
ensure_php_present()
|