1
0
mirror of https://github.com/php/pie.git synced 2026-03-23 23:12:17 +01:00

Merge pull request #496 from asgrim/492-fix-libtool-finding-osx

492: fix finding libtoolize on OSX
This commit is contained in:
James Titcumb
2026-02-03 17:59:19 +00:00
committed by GitHub
4 changed files with 47 additions and 9 deletions

View File

@@ -8,21 +8,39 @@ use Php\Pie\Platform\TargetPlatform;
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<PackageManager::*, non-empty-string|null> $packageManagerPackages */
/**
* @param non-empty-string|array<non-empty-string> $tool
* @param array<PackageManager::*, non-empty-string|null> $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 */

View File

@@ -80,7 +80,7 @@ class CheckAllBuildTools
],
),
new BinaryBuildToolFinder(
'libtoolize',
['libtoolize', 'glibtoolize'],
[
PackageManager::Apt->value => 'libtool',
PackageManager::Apk->value => 'libtool',
@@ -118,12 +118,12 @@ class CheckAllBuildTools
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 @@ class CheckAllBuildTools
$packageName = $buildTool->packageNameFor($packageManager, $targetPlatform);
if ($packageName === null) {
$io->writeError('<warning>Could not find package name for build tool ' . $buildTool->tool . '.</warning>', verbosity: IOInterface::VERBOSE);
$io->writeError('<warning>Could not find package name for build tool ' . $buildTool->toolNames() . '.</warning>', verbosity: IOInterface::VERBOSE);
continue;
}

View File

@@ -7,13 +7,23 @@ namespace Php\Pie\SelfManage\BuildTools;
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];
return $foundTool !== null && PhpizePath::looksLikeValidPhpize($foundTool);
foreach ($tools as $tool) {
$foundTool = (new ExecutableFinder())->find($tool);
if ($foundTool !== null && PhpizePath::looksLikeValidPhpize($foundTool)) {
return true;
}
}
return false;
}
}

View File

@@ -19,11 +19,21 @@ final class BinaryBuildToolFinderTest extends TestCase
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(