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

434: ensure phpize is thoroughly checked on dnf/yum systems due to placeholder

This commit is contained in:
James Titcumb
2025-12-10 17:05:14 +00:00
parent e0fab35c36
commit 81d8f982f0
3 changed files with 48 additions and 19 deletions

View File

@@ -27,6 +27,32 @@ final class PhpizePath
{
}
public static function looksLikeValidPhpize(string $phpizePathToCheck, string|null $forPhpApiVersion = null): bool
{
$phpizeAttempt = $phpizePathToCheck; // @todo
if ($phpizeAttempt === '') {
return false;
}
if (! file_exists($phpizeAttempt) || ! is_executable($phpizeAttempt)) {
return false;
}
$phpizeProcess = new Process([$phpizeAttempt, '--version']);
if ($phpizeProcess->run() !== 0) {
return false;
}
if (
! preg_match('/PHP Api Version:\s*(.*)/', $phpizeProcess->getOutput(), $m)
|| $m[1] === ''
) {
return false;
}
return $forPhpApiVersion === null || $forPhpApiVersion === $m[1];
}
public static function guessFrom(PhpBinaryPath $phpBinaryPath): self
{
$expectedApiVersion = $phpBinaryPath->phpApiVersion();
@@ -45,24 +71,8 @@ final class PhpizePath
foreach ($phpizeAttempts as $phpizeAttempt) {
assert($phpizeAttempt !== null);
assert($phpizeAttempt !== '');
if (! file_exists($phpizeAttempt) || ! is_executable($phpizeAttempt)) {
continue;
}
$phpizeProcess = new Process([$phpizeAttempt, '--version']);
if ($phpizeProcess->run() !== 0) {
continue;
}
if (
! preg_match('/PHP Api Version:\s*(.*)/', $phpizeProcess->getOutput(), $m)
|| ! array_key_exists(1, $m)
|| $m[1] === ''
) {
continue;
}
if ($expectedApiVersion === $m[1]) {
if (self::looksLikeValidPhpize($phpizeAttempt, $expectedApiVersion)) {
return new self($phpizeAttempt);
}
}

View File

@@ -82,12 +82,12 @@ class CheckAllBuildTools
PackageManager::Yum->value => 'libtool',
],
),
new BinaryBuildToolFinder(
new PhpizeBuildToolFinder(
'phpize',
[
PackageManager::Apt->value => 'php-dev',
PackageManager::Apk->value => 'php{major}{minor}-dev',
PackageManager::Dnf->value => 'php-devel', // @todo /usr/sbin/phpize exists on Fedora, but is like a placeholder - need step 2: run `phpize --version`
PackageManager::Dnf->value => 'php-devel',
PackageManager::Yum->value => 'php-devel',
],
),

View File

@@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
namespace Php\Pie\SelfManage\BuildTools;
use Php\Pie\Platform\TargetPhp\PhpizePath;
use Symfony\Component\Process\ExecutableFinder;
/** @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);
return $foundTool !== null && PhpizePath::looksLikeValidPhpize($foundTool);
}
}