Skip to content

Commit

Permalink
Pass the --php-config-path parameter to the ./configure command
Browse files Browse the repository at this point in the history
  • Loading branch information
asgrim committed Jul 11, 2024
1 parent 20abe9b commit 19b7cd0
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/Building/Build.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Php\Pie\Building;

use Php\Pie\Downloading\DownloadedPackage;
use Php\Pie\Platform\TargetPlatform;
use Symfony\Component\Console\Output\OutputInterface;

/** @internal This is not public API for PIE, so should not be depended upon unless you accept the risk of BC breaks */
Expand All @@ -13,6 +14,7 @@ interface Build
/** @param list<non-empty-string> $configureOptions */
public function __invoke(
DownloadedPackage $downloadedPackage,
TargetPlatform $targetPlatform,
array $configureOptions,
OutputInterface $output,
): void;
Expand Down
7 changes: 7 additions & 0 deletions src/Building/UnixBuild.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Php\Pie\Building;

use Php\Pie\Downloading\DownloadedPackage;
use Php\Pie\Platform\TargetPlatform;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\Process;

Expand All @@ -19,12 +20,18 @@ final class UnixBuild implements Build
/** {@inheritDoc} */
public function __invoke(
DownloadedPackage $downloadedPackage,
TargetPlatform $targetPlatform,
array $configureOptions,
OutputInterface $output,
): void {
$this->phpize($downloadedPackage);
$output->writeln('<info>phpize complete</info>.');

$phpConfigPath = $targetPlatform->phpBinaryPath->phpConfigPath();
if ($phpConfigPath !== null) {
$configureOptions[] = '--with-php-config=' . $phpConfigPath;
}

$this->configure($downloadedPackage, $configureOptions);
$optionsOutput = count($configureOptions) ? ' with options: ' . implode(' ', $configureOptions) : '.';
$output->writeln('<info>Configure complete</info>' . $optionsOutput);
Expand Down
2 changes: 2 additions & 0 deletions src/Building/WindowsBuild.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Php\Pie\Building;

use Php\Pie\Downloading\DownloadedPackage;
use Php\Pie\Platform\TargetPlatform;
use Symfony\Component\Console\Output\OutputInterface;

/** @internal This is not public API for PIE, so should not be depended upon unless you accept the risk of BC breaks */
Expand All @@ -13,6 +14,7 @@ final class WindowsBuild implements Build
/** {@inheritDoc} */
public function __invoke(
DownloadedPackage $downloadedPackage,
TargetPlatform $targetPlatform,
array $configureOptions,
OutputInterface $output,
): void {
Expand Down
2 changes: 1 addition & 1 deletion src/Command/BuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function execute(InputInterface $input, OutputInterface $output): int

$configureOptionsValues = CommandHelper::processConfigureOptionsFromInput($downloadedPackage->package, $input);

($this->build)($downloadedPackage, $configureOptionsValues, $output);
($this->build)($downloadedPackage, $targetPlatform, $configureOptionsValues, $output);

return Command::SUCCESS;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Platform/TargetPhp/PhpBinaryPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
class PhpBinaryPath
{
/**
* @param non-empty-string $phpBinaryPath
* @param non-empty-string $phpBinaryPath
* @param non-empty-string|null $phpConfigPath
*/
private function __construct(
public readonly string $phpBinaryPath,
private readonly string|null $phpConfigPath
private readonly string|null $phpConfigPath,
) {
// @todo https://github.com/php/pie/issues/12 - we could verify that the given $phpBinaryPath really is a PHP install
}
Expand Down
9 changes: 8 additions & 1 deletion test/integration/Building/UnixBuildTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use Php\Pie\DependencyResolver\Package;
use Php\Pie\Downloading\DownloadedPackage;
use Php\Pie\ExtensionName;
use Php\Pie\Platform\TargetPhp\PhpBinaryPath;
use Php\Pie\Platform\TargetPlatform;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Output\BufferedOutput;
Expand Down Expand Up @@ -40,7 +42,12 @@ public function testUnixBuildCanBuildExtension(): void
);

$unixBuilder = new UnixBuild();
$unixBuilder->__invoke($downloadedPackage, ['--enable-pie_test_ext'], $output);
$unixBuilder->__invoke(
$downloadedPackage,
TargetPlatform::fromPhpBinaryPath(PhpBinaryPath::fromCurrentProcess()),
['--enable-pie_test_ext'],
$output,
);

$outputString = $output->fetch();

Expand Down
2 changes: 1 addition & 1 deletion test/unit/Platform/TargetPhp/PhpBinaryPathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function testFromPhpConfigExecutable(): void
$exitCode = $process->run();
$phpConfigExecutable = trim($process->getOutput());

if ($exitCode !== 0 || ! file_exists($phpConfigExecutable) || ! is_executable($phpConfigExecutable)) {
if ($exitCode !== 0 || ! file_exists($phpConfigExecutable) || ! is_executable($phpConfigExecutable) || $phpConfigExecutable === '') {
self::markTestSkipped('Needs php-config in path to run this test');
}

Expand Down

0 comments on commit 19b7cd0

Please sign in to comment.