Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/SelfManage/BuildTools/BinaryBuildToolFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<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 */
Expand Down
8 changes: 4 additions & 4 deletions src/SelfManage/BuildTools/CheckAllBuildTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static function buildToolsFactory(): self
],
),
new BinaryBuildToolFinder(
'libtoolize',
['libtoolize', 'glibtoolize'],
[
PackageManager::Apt->value => 'libtool',
PackageManager::Apk->value => 'libtool',
Expand Down Expand Up @@ -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;
Expand All @@ -132,7 +132,7 @@ public function check(IOInterface $io, PackageManager|null $packageManager, Targ
$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;
}

Expand Down
14 changes: 12 additions & 2 deletions src/SelfManage/BuildTools/PhpizeBuildToolFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
10 changes: 10 additions & 0 deletions test/unit/SelfManage/BuildTools/BinaryBuildToolFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down