-
Notifications
You must be signed in to change notification settings - Fork 19
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 #19 from asgrim/build-implementation
Build Command implementation
- Loading branch information
Showing
31 changed files
with
1,223 additions
and
119 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
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 */ | ||
interface Build | ||
{ | ||
/** @param list<non-empty-string> $configureOptions */ | ||
public function __invoke( | ||
DownloadedPackage $downloadedPackage, | ||
TargetPlatform $targetPlatform, | ||
array $configureOptions, | ||
OutputInterface $output, | ||
): void; | ||
} |
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,76 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
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; | ||
|
||
use function count; | ||
use function file_exists; | ||
use function implode; | ||
use function sprintf; | ||
|
||
/** @internal This is not public API for PIE, so should not be depended upon unless you accept the risk of BC breaks */ | ||
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); | ||
|
||
$this->make($downloadedPackage); | ||
|
||
$expectedSoFile = $downloadedPackage->extractedSourcePath . '/modules/' . $downloadedPackage->package->extensionName->name() . '.so'; | ||
|
||
if (! file_exists($expectedSoFile)) { | ||
$output->writeln(sprintf( | ||
'Build complete, but expected <comment>%s</comment> does not exist - however, this may be normal if this extension outputs the .so file in a different location.', | ||
$expectedSoFile, | ||
)); | ||
|
||
return; | ||
} | ||
|
||
$output->writeln(sprintf( | ||
'<info>Build complete:</info> %s', | ||
$expectedSoFile, | ||
)); | ||
} | ||
|
||
private function phpize(DownloadedPackage $downloadedPackage): void | ||
{ | ||
(new Process(['phpize'], $downloadedPackage->extractedSourcePath)) | ||
->mustRun(); | ||
} | ||
|
||
/** @param list<non-empty-string> $configureOptions */ | ||
private function configure(DownloadedPackage $downloadedPackage, array $configureOptions = []): void | ||
{ | ||
(new Process(['./configure', ...$configureOptions], $downloadedPackage->extractedSourcePath)) | ||
->mustRun(); | ||
} | ||
|
||
private function make(DownloadedPackage $downloadedPackage): void | ||
{ | ||
(new Process(['make'], $downloadedPackage->extractedSourcePath)) | ||
->mustRun(); | ||
} | ||
} |
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,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
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 */ | ||
final class WindowsBuild implements Build | ||
{ | ||
/** {@inheritDoc} */ | ||
public function __invoke( | ||
DownloadedPackage $downloadedPackage, | ||
TargetPlatform $targetPlatform, | ||
array $configureOptions, | ||
OutputInterface $output, | ||
): void { | ||
$output->writeln('<info>Nothing to do on Windows.</info>'); | ||
} | ||
} |
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,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Php\Pie\Command; | ||
|
||
use Php\Pie\Building\Build; | ||
use Php\Pie\DependencyResolver\DependencyResolver; | ||
use Php\Pie\Downloading\DownloadAndExtract; | ||
use Symfony\Component\Console\Attribute\AsCommand; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
#[AsCommand( | ||
name: 'build', | ||
description: 'Download and build a PIE-compatible PHP extension, without installing it.', | ||
)] | ||
final class BuildCommand extends Command | ||
{ | ||
public function __construct( | ||
private readonly DependencyResolver $dependencyResolver, | ||
private readonly DownloadAndExtract $downloadAndExtract, | ||
private readonly Build $build, | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
public function configure(): void | ||
{ | ||
parent::configure(); | ||
|
||
CommandHelper::configureOptions($this); | ||
} | ||
|
||
public function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$targetPlatform = CommandHelper::determineTargetPlatformFromInputs($input, $output); | ||
|
||
$requestedNameAndVersionPair = CommandHelper::requestedNameAndVersionPair($input); | ||
|
||
$downloadedPackage = CommandHelper::downloadPackage( | ||
$this->dependencyResolver, | ||
$targetPlatform, | ||
$requestedNameAndVersionPair, | ||
$this->downloadAndExtract, | ||
$output, | ||
); | ||
|
||
CommandHelper::bindConfigureOptionsFromPackage($this, $downloadedPackage->package, $input); | ||
|
||
$configureOptionsValues = CommandHelper::processConfigureOptionsFromInput($downloadedPackage->package, $input); | ||
|
||
($this->build)($downloadedPackage, $targetPlatform, $configureOptionsValues, $output); | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
Oops, something went wrong.