Skip to content

Commit 908c186

Browse files
authored
Merge pull request #496 from asgrim/492-fix-libtool-finding-osx
492: fix finding libtoolize on OSX
2 parents 319e4fa + dd3c077 commit 908c186

File tree

4 files changed

+47
-9
lines changed

4 files changed

+47
-9
lines changed

src/SelfManage/BuildTools/BinaryBuildToolFinder.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,39 @@
88
use Symfony\Component\Process\ExecutableFinder;
99

1010
use function array_key_exists;
11+
use function implode;
12+
use function is_array;
1113
use function str_replace;
1214

1315
/** @internal This is not public API for PIE, so should not be depended upon unless you accept the risk of BC breaks */
1416
class BinaryBuildToolFinder
1517
{
16-
/** @param array<PackageManager::*, non-empty-string|null> $packageManagerPackages */
18+
/**
19+
* @param non-empty-string|array<non-empty-string> $tool
20+
* @param array<PackageManager::*, non-empty-string|null> $packageManagerPackages
21+
*/
1722
public function __construct(
18-
public readonly string $tool,
23+
protected readonly string|array $tool,
1924
private readonly array $packageManagerPackages,
2025
) {
2126
}
2227

28+
public function toolNames(): string
29+
{
30+
return is_array($this->tool) ? implode('/', $this->tool) : $this->tool;
31+
}
32+
2333
public function check(): bool
2434
{
25-
return (new ExecutableFinder())->find($this->tool) !== null;
35+
$tools = is_array($this->tool) ? $this->tool : [$this->tool];
36+
37+
foreach ($tools as $tool) {
38+
if ((new ExecutableFinder())->find($tool) !== null) {
39+
return true;
40+
}
41+
}
42+
43+
return false;
2644
}
2745

2846
/** @return non-empty-string|null */

src/SelfManage/BuildTools/CheckAllBuildTools.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public static function buildToolsFactory(): self
8080
],
8181
),
8282
new BinaryBuildToolFinder(
83-
'libtoolize',
83+
['libtoolize', 'glibtoolize'],
8484
[
8585
PackageManager::Apt->value => 'libtool',
8686
PackageManager::Apk->value => 'libtool',
@@ -118,12 +118,12 @@ public function check(IOInterface $io, PackageManager|null $packageManager, Targ
118118

119119
foreach ($this->buildTools as $buildTool) {
120120
if ($buildTool->check() !== false) {
121-
$io->write('Build tool ' . $buildTool->tool . ' is installed.', verbosity: IOInterface::VERY_VERBOSE);
121+
$io->write('Build tool ' . $buildTool->toolNames() . ' is installed.', verbosity: IOInterface::VERY_VERBOSE);
122122
continue;
123123
}
124124

125125
$allFound = false;
126-
$missingTools[] = $buildTool->tool;
126+
$missingTools[] = $buildTool->toolNames();
127127

128128
if ($packageManager === null) {
129129
continue;
@@ -132,7 +132,7 @@ public function check(IOInterface $io, PackageManager|null $packageManager, Targ
132132
$packageName = $buildTool->packageNameFor($packageManager, $targetPlatform);
133133

134134
if ($packageName === null) {
135-
$io->writeError('<warning>Could not find package name for build tool ' . $buildTool->tool . '.</warning>', verbosity: IOInterface::VERBOSE);
135+
$io->writeError('<warning>Could not find package name for build tool ' . $buildTool->toolNames() . '.</warning>', verbosity: IOInterface::VERBOSE);
136136
continue;
137137
}
138138

src/SelfManage/BuildTools/PhpizeBuildToolFinder.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,23 @@
77
use Php\Pie\Platform\TargetPhp\PhpizePath;
88
use Symfony\Component\Process\ExecutableFinder;
99

10+
use function is_array;
11+
1012
/** @internal This is not public API for PIE, so should not be depended upon unless you accept the risk of BC breaks */
1113
class PhpizeBuildToolFinder extends BinaryBuildToolFinder
1214
{
1315
public function check(): bool
1416
{
15-
$foundTool = (new ExecutableFinder())->find($this->tool);
17+
$tools = is_array($this->tool) ? $this->tool : [$this->tool];
18+
19+
foreach ($tools as $tool) {
20+
$foundTool = (new ExecutableFinder())->find($tool);
21+
22+
if ($foundTool !== null && PhpizePath::looksLikeValidPhpize($foundTool)) {
23+
return true;
24+
}
25+
}
1626

17-
return $foundTool !== null && PhpizePath::looksLikeValidPhpize($foundTool);
27+
return false;
1828
}
1929
}

test/unit/SelfManage/BuildTools/BinaryBuildToolFinderTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,21 @@ public function testCheckFailsToFindTool(): void
1919
self::assertFalse((new BinaryBuildToolFinder('this-should-not-be-anything-in-path', []))->check());
2020
}
2121

22+
public function testCheckFailsToFindToolInList(): void
23+
{
24+
self::assertFalse((new BinaryBuildToolFinder(['this-should-not-be-anything-in-path-1', 'this-should-not-be-anything-in-path-2'], []))->check());
25+
}
26+
2227
public function testCheckFindsTool(): void
2328
{
2429
self::assertTrue((new BinaryBuildToolFinder('echo', []))->check());
2530
}
2631

32+
public function testCheckFindsToolFromList(): void
33+
{
34+
self::assertTrue((new BinaryBuildToolFinder(['this-should-not-be-anything-in-path', 'echo'], []))->check());
35+
}
36+
2737
public function testPackageNameIsNullWhenNoPackageConfiguredForPackageManager(): void
2838
{
2939
self::assertNull(

0 commit comments

Comments
 (0)