From dd3c07773d6d0ae8bbc83bd0f80a899d7aa74a51 Mon Sep 17 00:00:00 2001 From: James Titcumb Date: Mon, 2 Feb 2026 16:45:06 +0000 Subject: [PATCH] 492: fix finding libtoolize on OSX --- .../BuildTools/BinaryBuildToolFinder.php | 24 ++++++++++++++++--- .../BuildTools/CheckAllBuildTools.php | 8 +++---- .../BuildTools/PhpizeBuildToolFinder.php | 14 +++++++++-- .../BuildTools/BinaryBuildToolFinderTest.php | 10 ++++++++ 4 files changed, 47 insertions(+), 9 deletions(-) diff --git a/src/SelfManage/BuildTools/BinaryBuildToolFinder.php b/src/SelfManage/BuildTools/BinaryBuildToolFinder.php index 4c236638..700aa7b7 100644 --- a/src/SelfManage/BuildTools/BinaryBuildToolFinder.php +++ b/src/SelfManage/BuildTools/BinaryBuildToolFinder.php @@ -8,21 +8,39 @@ use Symfony\Component\Process\ExecutableFinder; use function array_key_exists; +use function implode; +use function is_array; use function str_replace; /** @internal This is not public API for PIE, so should not be depended upon unless you accept the risk of BC breaks */ class BinaryBuildToolFinder { - /** @param array $packageManagerPackages */ + /** + * @param non-empty-string|array $tool + * @param array $packageManagerPackages + */ public function __construct( - public readonly string $tool, + protected readonly string|array $tool, private readonly array $packageManagerPackages, ) { } + public function toolNames(): string + { + return is_array($this->tool) ? implode('/', $this->tool) : $this->tool; + } + public function check(): bool { - return (new ExecutableFinder())->find($this->tool) !== null; + $tools = is_array($this->tool) ? $this->tool : [$this->tool]; + + foreach ($tools as $tool) { + if ((new ExecutableFinder())->find($tool) !== null) { + return true; + } + } + + return false; } /** @return non-empty-string|null */ diff --git a/src/SelfManage/BuildTools/CheckAllBuildTools.php b/src/SelfManage/BuildTools/CheckAllBuildTools.php index 4e4b0e8a..9dd82366 100644 --- a/src/SelfManage/BuildTools/CheckAllBuildTools.php +++ b/src/SelfManage/BuildTools/CheckAllBuildTools.php @@ -80,7 +80,7 @@ public static function buildToolsFactory(): self ], ), new BinaryBuildToolFinder( - 'libtoolize', + ['libtoolize', 'glibtoolize'], [ PackageManager::Apt->value => 'libtool', PackageManager::Apk->value => 'libtool', @@ -118,12 +118,12 @@ public function check(IOInterface $io, PackageManager|null $packageManager, Targ foreach ($this->buildTools as $buildTool) { if ($buildTool->check() !== false) { - $io->write('Build tool ' . $buildTool->tool . ' is installed.', verbosity: IOInterface::VERY_VERBOSE); + $io->write('Build tool ' . $buildTool->toolNames() . ' is installed.', verbosity: IOInterface::VERY_VERBOSE); continue; } $allFound = false; - $missingTools[] = $buildTool->tool; + $missingTools[] = $buildTool->toolNames(); if ($packageManager === null) { continue; @@ -132,7 +132,7 @@ public function check(IOInterface $io, PackageManager|null $packageManager, Targ $packageName = $buildTool->packageNameFor($packageManager, $targetPlatform); if ($packageName === null) { - $io->writeError('Could not find package name for build tool ' . $buildTool->tool . '.', verbosity: IOInterface::VERBOSE); + $io->writeError('Could not find package name for build tool ' . $buildTool->toolNames() . '.', verbosity: IOInterface::VERBOSE); continue; } diff --git a/src/SelfManage/BuildTools/PhpizeBuildToolFinder.php b/src/SelfManage/BuildTools/PhpizeBuildToolFinder.php index e1c51011..8c4e72ac 100644 --- a/src/SelfManage/BuildTools/PhpizeBuildToolFinder.php +++ b/src/SelfManage/BuildTools/PhpizeBuildToolFinder.php @@ -7,13 +7,23 @@ use Php\Pie\Platform\TargetPhp\PhpizePath; use Symfony\Component\Process\ExecutableFinder; +use function is_array; + /** @internal This is not public API for PIE, so should not be depended upon unless you accept the risk of BC breaks */ class PhpizeBuildToolFinder extends BinaryBuildToolFinder { public function check(): bool { - $foundTool = (new ExecutableFinder())->find($this->tool); + $tools = is_array($this->tool) ? $this->tool : [$this->tool]; + + foreach ($tools as $tool) { + $foundTool = (new ExecutableFinder())->find($tool); + + if ($foundTool !== null && PhpizePath::looksLikeValidPhpize($foundTool)) { + return true; + } + } - return $foundTool !== null && PhpizePath::looksLikeValidPhpize($foundTool); + return false; } } diff --git a/test/unit/SelfManage/BuildTools/BinaryBuildToolFinderTest.php b/test/unit/SelfManage/BuildTools/BinaryBuildToolFinderTest.php index ac7c27de..5eb1d582 100644 --- a/test/unit/SelfManage/BuildTools/BinaryBuildToolFinderTest.php +++ b/test/unit/SelfManage/BuildTools/BinaryBuildToolFinderTest.php @@ -19,11 +19,21 @@ public function testCheckFailsToFindTool(): void self::assertFalse((new BinaryBuildToolFinder('this-should-not-be-anything-in-path', []))->check()); } + public function testCheckFailsToFindToolInList(): void + { + self::assertFalse((new BinaryBuildToolFinder(['this-should-not-be-anything-in-path-1', 'this-should-not-be-anything-in-path-2'], []))->check()); + } + public function testCheckFindsTool(): void { self::assertTrue((new BinaryBuildToolFinder('echo', []))->check()); } + public function testCheckFindsToolFromList(): void + { + self::assertTrue((new BinaryBuildToolFinder(['this-should-not-be-anything-in-path', 'echo'], []))->check()); + } + public function testPackageNameIsNullWhenNoPackageConfiguredForPackageManager(): void { self::assertNull(