Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ parameters:
-
message: '#^Cannot cast mixed to string\.$#'
identifier: cast.string
count: 2
count: 1
path: src/Command/InstallExtensionsForProjectCommand.php

-
Expand Down
4 changes: 2 additions & 2 deletions src/Building/Build.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace Php\Pie\Building;

use Composer\IO\IOInterface;
use Php\Pie\Downloading\DownloadedPackage;
use Php\Pie\File\BinaryFile;
use Php\Pie\Platform\TargetPhp\PhpizePath;
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
Expand All @@ -18,7 +18,7 @@ public function __invoke(
DownloadedPackage $downloadedPackage,
TargetPlatform $targetPlatform,
array $configureOptions,
OutputInterface $output,
IOInterface $io,
PhpizePath|null $phpizePath,
): BinaryFile;
}
79 changes: 42 additions & 37 deletions src/Building/UnixBuild.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

namespace Php\Pie\Building;

use Composer\IO\IOInterface;
use Php\Pie\ComposerIntegration\BundledPhpExtensionsRepository;
use Php\Pie\Downloading\DownloadedPackage;
use Php\Pie\File\BinaryFile;
use Php\Pie\Platform\TargetPhp\PhpizePath;
use Php\Pie\Platform\TargetPlatform;
use Php\Pie\Util\Process;
use Php\Pie\Util\ProcessFailedWithLimitedOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process as SymfonyProcess;

Expand All @@ -35,13 +35,13 @@ public function __invoke(
DownloadedPackage $downloadedPackage,
TargetPlatform $targetPlatform,
array $configureOptions,
OutputInterface $output,
IOInterface $io,
PhpizePath|null $phpizePath,
): BinaryFile {
$outputCallback = null;
if ($output->isVerbose()) {
$outputCallback = static function (string $type, string $outputMessage) use ($output): void {
$output->write(sprintf(
if ($io->isVerbose()) {
$outputCallback = static function (string $type, string $outputMessage) use ($io): void {
$io->write(sprintf(
'%s%s%s',
$type === SymfonyProcess::ERR ? '<comment>' : '',
$outputMessage,
Expand All @@ -58,29 +58,29 @@ public function __invoke(
* already clean anyway; however, sometimes we want to rebuild the
* current ext, so this will perform a clean first
*/
$this->cleanup($phpizePath, $downloadedPackage, $output, $outputCallback);
$this->cleanup($phpizePath, $downloadedPackage, $io, $outputCallback);

$this->phpize(
$phpizePath,
$downloadedPackage,
$output,
$io,
$outputCallback,
);

$output->writeln('<info>phpize complete</info>.');
$io->write('<info>phpize complete</info>.');

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

$this->configure($downloadedPackage, $configureOptions, $output, $outputCallback);
$this->configure($downloadedPackage, $configureOptions, $io, $outputCallback);

$optionsOutput = count($configureOptions) ? ' with options: ' . implode(' ', $configureOptions) : '.';
$output->writeln('<info>Configure complete</info>' . $optionsOutput);
$io->write('<info>Configure complete</info>' . $optionsOutput);

try {
$this->make($targetPlatform, $downloadedPackage, $output, $outputCallback);
$this->make($targetPlatform, $downloadedPackage, $io, $outputCallback);
} catch (ProcessFailedException $p) {
throw ProcessFailedWithLimitedOutput::fromProcessFailedException($p);
}
Expand All @@ -91,26 +91,26 @@ public function __invoke(
throw ExtensionBinaryNotFound::fromExpectedBinary($expectedSoFile);
}

$output->writeln(sprintf(
$io->write(sprintf(
'<info>Build complete:</info> %s',
$expectedSoFile,
));

return BinaryFile::fromFileWithSha256Checksum($expectedSoFile);
}

private function renamesToConfigM4(DownloadedPackage $downloadedPackage, OutputInterface $output): void
private function renamesToConfigM4(DownloadedPackage $downloadedPackage, IOInterface $io): void
{
$configM4 = $downloadedPackage->extractedSourcePath . DIRECTORY_SEPARATOR . 'config.m4';
if (file_exists($configM4)) {
return;
}

$output->writeln('config.m4 does not exist; checking alternatives', OutputInterface::VERBOSITY_VERY_VERBOSE);
$io->write('config.m4 does not exist; checking alternatives', verbosity: IOInterface::VERY_VERBOSE);
foreach (['config0.m4', 'config9.m4'] as $alternateConfigM4) {
$fullPathToAlternate = $downloadedPackage->extractedSourcePath . DIRECTORY_SEPARATOR . $alternateConfigM4;
if (file_exists($fullPathToAlternate)) {
$output->writeln(sprintf('Renaming %s to config.m4', $alternateConfigM4), OutputInterface::VERBOSITY_VERY_VERBOSE);
$io->write(sprintf('Renaming %s to config.m4', $alternateConfigM4), verbosity: IOInterface::VERY_VERBOSE);
rename($fullPathToAlternate, $configM4);

return;
Expand All @@ -122,16 +122,17 @@ private function renamesToConfigM4(DownloadedPackage $downloadedPackage, OutputI
private function phpize(
PhpizePath $phpize,
DownloadedPackage $downloadedPackage,
OutputInterface $output,
IOInterface $io,
callable|null $outputCallback,
): void {
$phpizeCommand = [$phpize->phpizeBinaryPath];

if ($output->isVerbose()) {
$output->writeln('<comment>Running phpize step using: ' . implode(' ', $phpizeCommand) . '</comment>');
}
$io->write(
'<comment>Running phpize step using: ' . implode(' ', $phpizeCommand) . '</comment>',
verbosity: IOInterface::VERBOSE,
);

$this->renamesToConfigM4($downloadedPackage, $output);
$this->renamesToConfigM4($downloadedPackage, $io);

Process::run(
$phpizeCommand,
Expand All @@ -148,14 +149,15 @@ private function phpize(
private function configure(
DownloadedPackage $downloadedPackage,
array $configureOptions,
OutputInterface $output,
IOInterface $io,
callable|null $outputCallback,
): void {
$configureCommand = ['./configure', ...$configureOptions];

if ($output->isVerbose()) {
$output->writeln('<comment>Running configure step with: ' . implode(' ', $configureCommand) . '</comment>');
}
$io->write(
'<comment>Running configure step with: ' . implode(' ', $configureCommand) . '</comment>',
verbosity: IOInterface::VERBOSE,
);

Process::run(
$configureCommand,
Expand All @@ -169,13 +171,13 @@ private function configure(
private function make(
TargetPlatform $targetPlatform,
DownloadedPackage $downloadedPackage,
OutputInterface $output,
IOInterface $io,
callable|null $outputCallback,
): void {
$makeCommand = ['make'];

if ($targetPlatform->makeParallelJobs === 1) {
$output->writeln('Running make without parallelization - try providing -jN to PIE where N is the number of cores you have.');
$io->write('Running make without parallelization - try providing -jN to PIE where N is the number of cores you have.');
} else {
$makeCommand[] = sprintf('-j%d', $targetPlatform->makeParallelJobs);
}
Expand All @@ -185,9 +187,10 @@ private function make(
$downloadedPackage,
);

if ($output->isVerbose()) {
$output->writeln('<comment>Running make step with: ' . implode(' ', $makeCommand) . '</comment>');
}
$io->write(
'<comment>Running make step with: ' . implode(' ', $makeCommand) . '</comment>',
verbosity: IOInterface::VERBOSE,
);

Process::run(
$makeCommand,
Expand All @@ -201,7 +204,7 @@ private function make(
private function cleanup(
PhpizePath $phpize,
DownloadedPackage $downloadedPackage,
OutputInterface $output,
IOInterface $io,
callable|null $outputCallback,
): void {
/**
Expand All @@ -210,18 +213,20 @@ private function cleanup(
* configure script manually...
*/
if (! file_exists($downloadedPackage->extractedSourcePath . '/configure')) {
if ($output->isVerbose()) {
$output->writeln('<comment>Skipping phpize --clean, configure does not exist</comment>');
}
$io->write(
'<comment>Skipping phpize --clean, configure does not exist</comment>',
verbosity: IOInterface::VERBOSE,
);

return;
}

$phpizeCleanCommand = [$phpize->phpizeBinaryPath, '--clean'];

if ($output->isVerbose()) {
$output->writeln('<comment>Running phpize --clean step using: ' . implode(' ', $phpizeCleanCommand) . '</comment>');
}
$io->write(
'<comment>Running phpize --clean step using: ' . implode(' ', $phpizeCleanCommand) . '</comment>',
verbosity: IOInterface::VERBOSE,
);

Process::run(
$phpizeCleanCommand,
Expand All @@ -230,6 +235,6 @@ private function cleanup(
$outputCallback,
);

$output->writeln('<info>Build files cleaned up.</info>');
$io->write('<info>Build files cleaned up.</info>');
}
}
6 changes: 3 additions & 3 deletions src/Building/WindowsBuild.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace Php\Pie\Building;

use Composer\IO\IOInterface;
use Php\Pie\Downloading\DownloadedPackage;
use Php\Pie\File\BinaryFile;
use Php\Pie\Platform\TargetPhp\PhpizePath;
use Php\Pie\Platform\TargetPlatform;
use Php\Pie\Platform\WindowsExtensionAssetName;
use Symfony\Component\Console\Output\OutputInterface;

use function sprintf;

Expand All @@ -21,12 +21,12 @@ public function __invoke(
DownloadedPackage $downloadedPackage,
TargetPlatform $targetPlatform,
array $configureOptions,
OutputInterface $output,
IOInterface $io,
PhpizePath|null $phpizePath,
): BinaryFile {
$prebuiltDll = WindowsExtensionAssetName::determineDllName($targetPlatform, $downloadedPackage);

$output->writeln(sprintf(
$io->write(sprintf(
'<info>Nothing to do on Windows, prebuilt DLL found:</info> %s',
$prebuiltDll,
));
Expand Down
20 changes: 11 additions & 9 deletions src/Command/BuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Php\Pie\Command;

use Composer\IO\IOInterface;
use Php\Pie\ComposerIntegration\ComposerIntegrationHandler;
use Php\Pie\ComposerIntegration\ComposerRunFailed;
use Php\Pie\ComposerIntegration\PieComposerFactory;
Expand Down Expand Up @@ -33,6 +34,7 @@ public function __construct(
private readonly DependencyResolver $dependencyResolver,
private readonly ComposerIntegrationHandler $composerIntegrationHandler,
private readonly FindMatchingPackages $findMatchingPackages,
private readonly IOInterface $io,
) {
parent::__construct();
}
Expand All @@ -46,14 +48,14 @@ public function configure(): void

public function execute(InputInterface $input, OutputInterface $output): int
{
$targetPlatform = CommandHelper::determineTargetPlatformFromInputs($input, $output);
$targetPlatform = CommandHelper::determineTargetPlatformFromInputs($input, $this->io);
try {
$requestedNameAndVersion = CommandHelper::requestedNameAndVersionPair($input);
} catch (InvalidPackageName $invalidPackageName) {
return CommandHelper::handlePackageNotFound(
$invalidPackageName,
$this->findMatchingPackages,
$output,
$this->io,
$targetPlatform,
$this->container,
);
Expand All @@ -64,7 +66,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
$composer = PieComposerFactory::createPieComposer(
$this->container,
new PieComposerRequest(
$output,
$this->io,
$targetPlatform,
$requestedNameAndVersion,
PieOperation::Resolve,
Expand All @@ -85,18 +87,18 @@ public function execute(InputInterface $input, OutputInterface $output): int
return CommandHelper::handlePackageNotFound(
$unableToResolveRequirement,
$this->findMatchingPackages,
$output,
$this->io,
$targetPlatform,
$this->container,
);
} catch (BundledPhpExtensionRefusal $bundledPhpExtensionRefusal) {
$output->writeln('');
$output->writeln('<comment>' . $bundledPhpExtensionRefusal->getMessage() . '</comment>');
$this->io->writeError('');
$this->io->writeError('<comment>' . $bundledPhpExtensionRefusal->getMessage() . '</comment>');

return self::INVALID;
}

$output->writeln(sprintf('<info>Found package:</info> %s which provides <info>%s</info>', $package->prettyNameAndVersion(), $package->extensionName()->nameWithExtPrefix()));
$this->io->write(sprintf('<info>Found package:</info> %s which provides <info>%s</info>', $package->prettyNameAndVersion(), $package->extensionName()->nameWithExtPrefix()));

// Now we know what package we have, we can validate the configure options for the command and re-create the
// Composer instance with the populated configure options
Expand All @@ -106,7 +108,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
$composer = PieComposerFactory::createPieComposer(
$this->container,
new PieComposerRequest(
$output,
$this->io,
$targetPlatform,
$requestedNameAndVersion,
PieOperation::Build,
Expand All @@ -126,7 +128,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
false,
);
} catch (ComposerRunFailed $composerRunFailed) {
$output->writeln('<error>' . $composerRunFailed->getMessage() . '</error>');
$this->io->writeError('<error>' . $composerRunFailed->getMessage() . '</error>');

return $composerRunFailed->getCode();
}
Expand Down
Loading