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

Allow build tool package name to be null

This commit is contained in:
James Titcumb
2025-12-04 14:07:55 +00:00
parent 90b164dabe
commit 4a85df4657
3 changed files with 34 additions and 16 deletions

View File

@@ -6,8 +6,10 @@ namespace Php\Pie\SelfManage\BuildTools;
use Symfony\Component\Process\ExecutableFinder;
class CheckIndividualBuildToolInPath
/** @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 */
public function __construct(
public readonly string $tool,
private readonly array $packageManagerPackages,
@@ -19,10 +21,9 @@ class CheckIndividualBuildToolInPath
return (new ExecutableFinder())->find($this->tool) !== null;
}
public function packageNameFor(PackageManager $packageManager): string
/** @return non-empty-string|null */
public function packageNameFor(PackageManager $packageManager): string|null
{
// @todo could we do a check the package exists?
// If we need to customise specific package names depending on OS
// specific parameters, this is likely the place to do it
return $this->packageManagerPackages[$packageManager->value];

View File

@@ -9,58 +9,65 @@ use Composer\IO\IOInterface;
use function array_unique;
use function implode;
final class CheckAllBuildTools
/** @internal This is not public API for PIE, so should not be depended upon unless you accept the risk of BC breaks */
class CheckAllBuildTools
{
public static function buildToolsFactory(): self
{
// @todo libtool
return new self([
new CheckIndividualBuildToolInPath(
new BinaryBuildToolFinder(
'gcc',
[
PackageManager::Apt->value => 'gcc',
PackageManager::Apk->value => 'build-base',
],
),
new CheckIndividualBuildToolInPath(
new BinaryBuildToolFinder(
'make',
[
PackageManager::Apt->value => 'make',
PackageManager::Apk->value => 'build-base',
],
),
new CheckIndividualBuildToolInPath(
new BinaryBuildToolFinder(
'autoconf',
[
PackageManager::Apt->value => 'autoconf',
PackageManager::Apk->value => 'autoconf',
],
),
new CheckIndividualBuildToolInPath(
new BinaryBuildToolFinder(
'bison',
[
PackageManager::Apt->value => 'bison',
PackageManager::Apk->value => 'bison',
],
),
new CheckIndividualBuildToolInPath(
new BinaryBuildToolFinder(
're2c',
[
PackageManager::Apt->value => 're2c',
PackageManager::Apk->value => 're2c',
],
),
new CheckIndividualBuildToolInPath(
new BinaryBuildToolFinder(
'pkg-config',
[
PackageManager::Apt->value => 'pkg-config',
PackageManager::Apk->value => 'pkgconfig',
],
),
new BinaryBuildToolFinder(
'libtoolize',
[
PackageManager::Apt->value => 'libtool',
PackageManager::Apk->value => 'libtool',
],
),
]);
}
/** @param list<CheckIndividualBuildToolInPath> $buildTools */
/** @param list<BinaryBuildToolFinder> $buildTools */
public function __construct(
private readonly array $buildTools,
) {
@@ -73,15 +80,23 @@ final class CheckAllBuildTools
$missingTools = [];
$packagesToInstall = [];
$allFound = true;
foreach ($this->buildTools as $buildTool) {
if ($buildTool->check() !== false) {
$io->write('Build tool ' . $buildTool->tool . ' is installed.', verbosity: IOInterface::VERY_VERBOSE);
continue;
}
$allFound = false;
$missingTools[] = $buildTool->tool;
$packagesToInstall[] = $buildTool->packageNameFor($packageManager);
$allFound = false;
$missingTools[] = $buildTool->tool;
$packageName = $buildTool->packageNameFor($packageManager);
if ($packageName === null) {
$io->writeError('<warning>Could not find package name for build tool ' . $buildTool->tool . '.</warning>');
continue;
}
$packagesToInstall[] = $packageName;
}
if ($allFound) {

View File

@@ -10,12 +10,14 @@ use Symfony\Component\Process\ExecutableFinder;
use function array_unshift;
/** @internal This is not public API for PIE, so should not be depended upon unless you accept the risk of BC breaks */
enum PackageManager: string
{
case Apt = 'apt-get';
case Apk = 'apk';
// @todo dnf
// @todo yum
// @todo brew
public static function detect(): self|null
{