-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from asgrim/fix-phpize-path
Fix phpize path used for UnixBuild & a bunch of test fixes
- Loading branch information
Showing
12 changed files
with
340 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Php\Pie\Platform\TargetPhp; | ||
|
||
use RuntimeException; | ||
use Symfony\Component\Process\Process; | ||
|
||
use function array_key_exists; | ||
use function assert; | ||
use function file_exists; | ||
use function is_executable; | ||
use function preg_match; | ||
use function preg_replace; | ||
use function trim; | ||
|
||
/** | ||
* @internal This is not public API for PIE, so should not be depended upon unless you accept the risk of BC breaks | ||
* | ||
* @immutable | ||
*/ | ||
final class PhpizePath | ||
{ | ||
/** @param non-empty-string $phpizeBinaryPath */ | ||
public function __construct(public readonly string $phpizeBinaryPath) | ||
{ | ||
} | ||
|
||
public static function guessFrom(PhpBinaryPath $phpBinaryPath): self | ||
{ | ||
$expectedApiVersion = $phpBinaryPath->phpApiVersion(); | ||
|
||
$phpizeAttempts = []; | ||
|
||
// Try to add `phpize` from path | ||
$whichPhpize = new Process(['which', 'phpize']); | ||
if ($whichPhpize->run() === 0) { | ||
$phpizeAttempts[] = trim($whichPhpize->getOutput()); | ||
} | ||
|
||
// Try to guess based on the `php` path itself | ||
$phpizeAttempts[] = preg_replace('((.*)php)', '$1phpize', $phpBinaryPath->phpBinaryPath); | ||
|
||
foreach ($phpizeAttempts as $phpizeAttempt) { | ||
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]) { | ||
return new self($phpizeAttempt); | ||
} | ||
} | ||
|
||
// @todo add a way to specify --phpize or similar | ||
throw new RuntimeException('did not find a good phpize, oh'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.