Skip to content
Open
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
12 changes: 6 additions & 6 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ parameters:
count: 1
path: src/Command/CommandHelper.php

-
message: '#^Cannot cast mixed to string\.$#'
identifier: cast.string
count: 1
path: src/Command/CommandHelper.php

-
message: '#^Cannot cast mixed to string\.$#'
identifier: cast.string
Expand Down Expand Up @@ -480,6 +474,12 @@ parameters:
count: 1
path: test/unit/Installing/InstallForPhpProject/InstallSelectedPackageTest.php

-
message: '#^Access to an undefined property Php\\PieUnitTest\\SelfManage\\BuildTools\\PhpizeBuildToolFinderTest\:\:\$phpBinaryPath\.$#'
identifier: property.notFound
count: 3
path: test/unit/SelfManage/BuildTools/PhpizeBuildToolFinderTest.php

-
message: '#^Method Php\\PieUnitTest\\SelfManage\\Verify\\FallbackVerificationUsingOpenSslTest\:\:prepareCertificateAndSignature\(\) should return array\{string, string\} but returns array\{mixed, mixed\}\.$#'
identifier: return.type
Expand Down
2 changes: 0 additions & 2 deletions src/Building/Build.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
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;

/** @internal This is not public API for PIE, so should not be depended upon unless you accept the risk of BC breaks */
Expand All @@ -19,6 +18,5 @@ public function __invoke(
TargetPlatform $targetPlatform,
array $configureOptions,
IOInterface $io,
PhpizePath|null $phpizePath,
): BinaryFile;
}
6 changes: 2 additions & 4 deletions src/Building/UnixBuild.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public function __invoke(
TargetPlatform $targetPlatform,
array $configureOptions,
IOInterface $io,
PhpizePath|null $phpizePath,
): BinaryFile {
$selectedDownloadMethod = DownloadUrlMethod::fromDownloadedPackage($downloadedPackage);
switch ($selectedDownloadMethod) {
Expand All @@ -43,7 +42,7 @@ public function __invoke(

case DownloadUrlMethod::ComposerDefaultDownload:
case DownloadUrlMethod::PrePackagedSourceDownload:
return $this->buildFromSource($downloadedPackage, $targetPlatform, $configureOptions, $io, $phpizePath);
return $this->buildFromSource($downloadedPackage, $targetPlatform, $configureOptions, $io);

default:
throw new LogicException('Unsupported download method: ' . $selectedDownloadMethod->value);
Expand Down Expand Up @@ -74,7 +73,6 @@ private function buildFromSource(
TargetPlatform $targetPlatform,
array $configureOptions,
IOInterface $io,
PhpizePath|null $phpizePath,
): BinaryFile {
$outputCallback = null;
if ($io->isVerbose()) {
Expand All @@ -88,7 +86,7 @@ private function buildFromSource(
};
}

$phpizePath ??= PhpizePath::guessFrom($targetPlatform->phpBinaryPath);
$phpizePath = $targetPlatform->phpizePath ?? PhpizePath::guessFrom($targetPlatform->phpBinaryPath);

/**
* Call a cleanup first; most of the time, we expect to be changing a
Expand Down
2 changes: 0 additions & 2 deletions src/Building/WindowsBuild.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
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;

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

Expand Down
2 changes: 0 additions & 2 deletions src/Command/BuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public function execute(InputInterface $input, OutputInterface $output): int
$requestedNameAndVersion,
PieOperation::Resolve,
[], // Configure options are not needed for resolve only
null,
false, // setting up INI not needed for build
),
);
Expand Down Expand Up @@ -126,7 +125,6 @@ public function execute(InputInterface $input, OutputInterface $output): int
$requestedNameAndVersion,
PieOperation::Build,
$configureOptionsValues,
CommandHelper::determinePhpizePathFromInputs($input),
false, // setting up INI not needed for build
),
);
Expand Down
35 changes: 13 additions & 22 deletions src/Command/CommandHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,6 @@ public static function determineTargetPlatformFromInputs(InputInterface $input,
throw new InvalidArgumentException('The --with-php-path=/path/to/php cannot be used on non-Windows, use --with-php-config=/path/to/php-config instead.');
}

if (Platform::isWindows() && $input->hasOption(self::OPTION_WITH_PHPIZE_PATH)) {
/** @var mixed $withPhpizePath */
$withPhpizePath = $input->getOption(self::OPTION_WITH_PHPIZE_PATH);

if (is_string($withPhpizePath) && trim($withPhpizePath) !== '') {
throw new InvalidArgumentException('The --with-phpize-path=/path/to/phpize cannot be used on Windows.');
}
}

if ($specifiedWithPhpConfig) {
$phpBinaryPath = PhpBinaryPath::fromPhpConfigExecutable($withPhpConfig);
}
Expand All @@ -210,7 +201,19 @@ public static function determineTargetPlatformFromInputs(InputInterface $input,
}
}

$targetPlatform = TargetPlatform::fromPhpBinaryPath($phpBinaryPath, $makeParallelJobs);
$phpizePath = null;
if ($input->hasOption(self::OPTION_WITH_PHPIZE_PATH)) {
$phpizePathOption = $input->getOption(self::OPTION_WITH_PHPIZE_PATH);
if (is_string($phpizePathOption) && trim($phpizePathOption) !== '') {
if (Platform::isWindows()) {
throw new InvalidArgumentException('The --with-phpize-path=/path/to/phpize cannot be used on Windows.');
}

$phpizePath = new PhpizePath($phpizePathOption);
}
}

$targetPlatform = TargetPlatform::fromPhpBinaryPath($phpBinaryPath, $makeParallelJobs, $phpizePath);

if (PiePlatform::isRunningStaticPhp()) {
$io->write(sprintf('<info>You are running a PIE Static PHP %s build</info>', PHP_VERSION));
Expand Down Expand Up @@ -264,18 +267,6 @@ public static function shouldCheckForBuildTools(InputInterface $input): bool
|| ! $input->getOption(self::OPTION_SUPPRESS_BUILD_TOOLS_CHECK);
}

public static function determinePhpizePathFromInputs(InputInterface $input): PhpizePath|null
{
if ($input->hasOption(self::OPTION_WITH_PHPIZE_PATH)) {
$phpizePathOption = (string) $input->getOption(self::OPTION_WITH_PHPIZE_PATH);
if (trim($phpizePathOption) !== '') {
return new PhpizePath($phpizePathOption);
}
}

return null;
}

public static function requestedNameAndVersionPair(InputInterface $input): RequestedPackageAndVersion
{
$requestedPackageString = $input->getArgument(self::ARG_REQUESTED_PACKAGE_AND_VERSION);
Expand Down
1 change: 0 additions & 1 deletion src/Command/DownloadCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public function execute(InputInterface $input, OutputInterface $output): int
$requestedNameAndVersion,
PieOperation::Download,
[], // Configure options are not needed for download only
null,
false, // setting up INI not needed for download
),
);
Expand Down
1 change: 0 additions & 1 deletion src/Command/InfoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public function execute(InputInterface $input, OutputInterface $output): int
$requestedNameAndVersion,
PieOperation::Resolve,
[], // Configure options are not needed for resolve only
null,
false, // setting up INI not needed for info
),
);
Expand Down
2 changes: 0 additions & 2 deletions src/Command/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ public function execute(InputInterface $input, OutputInterface $output): int
$requestedNameAndVersion,
PieOperation::Resolve,
[], // Configure options are not needed for resolve only
null,
false, // setting up INI not needed for resolve step
),
);
Expand Down Expand Up @@ -140,7 +139,6 @@ public function execute(InputInterface $input, OutputInterface $output): int
$requestedNameAndVersion,
PieOperation::Install,
$configureOptionsValues,
CommandHelper::determinePhpizePathFromInputs($input),
CommandHelper::determineAttemptToSetupIniFile($input),
),
);
Expand Down
1 change: 0 additions & 1 deletion src/Command/UninstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public function execute(InputInterface $input, OutputInterface $output): int
$requestedPackageAndVersionToRemove,
PieOperation::Uninstall,
[], // Configure options are not needed for uninstall
null,
true,
),
);
Expand Down
1 change: 0 additions & 1 deletion src/ComposerIntegration/InstallAndBuildProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public function __invoke(
$composerRequest->targetPlatform,
$composerRequest->configureOptions,
$io,
$composerRequest->phpizePath,
);

$this->installedJsonMetadata->addBuildMetadata(
Expand Down
2 changes: 1 addition & 1 deletion src/ComposerIntegration/InstalledJsonMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function addBuildMetadata(
$composer,
$composerPackage,
MetadataKey::PhpizeBinary,
$composerRequest->phpizePath->phpizeBinaryPath ?? null,
$composerRequest->targetPlatform->phpizePath->phpizeBinaryPath ?? null,
);

$this->addPieMetadata(
Expand Down
3 changes: 0 additions & 3 deletions src/ComposerIntegration/PieComposerRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Composer\IO\IOInterface;
use Php\Pie\DependencyResolver\RequestedPackageAndVersion;
use Php\Pie\Platform\TargetPhp\PhpizePath;
use Php\Pie\Platform\TargetPlatform;

/**
Expand All @@ -23,7 +22,6 @@ public function __construct(
public readonly RequestedPackageAndVersion $requestedPackage,
public readonly PieOperation $operation,
public readonly array $configureOptions,
public readonly PhpizePath|null $phpizePath,
public readonly bool $attemptToSetupIniFile,
) {
}
Expand All @@ -42,7 +40,6 @@ public static function noOperation(
new RequestedPackageAndVersion('null/null', null),
PieOperation::Resolve,
[],
null,
false,
);
}
Expand Down
5 changes: 4 additions & 1 deletion src/Platform/TargetPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Fidry\CpuCoreCounter\CpuCoreCounter;
use Php\Pie\Platform\TargetPhp\PhpBinaryPath;
use Php\Pie\Platform\TargetPhp\PhpizePath;

use function array_key_exists;
use function explode;
Expand All @@ -31,6 +32,7 @@ public function __construct(
public readonly ThreadSafetyMode $threadSafety,
public readonly int $makeParallelJobs,
public readonly WindowsCompiler|null $windowsCompiler,
public readonly PhpizePath|null $phpizePath,
) {
}

Expand All @@ -48,7 +50,7 @@ public static function isRunningAsRoot(): bool
return function_exists('posix_getuid') && posix_getuid() === 0;
}

public static function fromPhpBinaryPath(PhpBinaryPath $phpBinaryPath, int|null $makeParallelJobs): self
public static function fromPhpBinaryPath(PhpBinaryPath $phpBinaryPath, int|null $makeParallelJobs, PhpizePath|null $phpizePath): self
{
$os = $phpBinaryPath->operatingSystem();
$osFamily = $phpBinaryPath->operatingSystemFamily();
Expand Down Expand Up @@ -133,6 +135,7 @@ public static function fromPhpBinaryPath(PhpBinaryPath $phpBinaryPath, int|null
$threadSafety,
$makeParallelJobs,
$windowsCompiler,
$phpizePath,
);
}
}
2 changes: 1 addition & 1 deletion src/SelfManage/BuildTools/BinaryBuildToolFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function toolNames(): string
return is_array($this->tool) ? implode('/', $this->tool) : $this->tool;
}

public function check(): bool
public function check(TargetPlatform $targetPlatform): bool
{
$tools = is_array($this->tool) ? $this->tool : [$this->tool];

Expand Down
3 changes: 1 addition & 2 deletions src/SelfManage/BuildTools/CheckAllBuildTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ public static function buildToolsFactory(): self
],
),
new PhpizeBuildToolFinder(
'phpize',
[
PackageManager::Apt->value => 'php-dev',
PackageManager::Apk->value => 'php{major}{minor}-dev',
Expand All @@ -117,7 +116,7 @@ public function check(IOInterface $io, PackageManager|null $packageManager, Targ
$allFound = true;

foreach ($this->buildTools as $buildTool) {
if ($buildTool->check() !== false) {
if ($buildTool->check($targetPlatform) !== false) {
$io->write('Build tool ' . $buildTool->toolNames() . ' is installed.', verbosity: IOInterface::VERY_VERBOSE);
continue;
}
Expand Down
27 changes: 26 additions & 1 deletion src/SelfManage/BuildTools/PhpizeBuildToolFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,43 @@
namespace Php\Pie\SelfManage\BuildTools;

use Php\Pie\Platform\TargetPhp\PhpizePath;
use Php\Pie\Platform\TargetPlatform;
use RuntimeException;
use Symfony\Component\Process\ExecutableFinder;

use function file_exists;
use function is_array;
use function is_executable;

/** @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
/** @param array<PackageManager::*, non-empty-string|null> $packageManagerPackages */
public function __construct(
array $packageManagerPackages,
) {
parent::__construct('phpize', $packageManagerPackages);
}

public function check(TargetPlatform $targetPlatform): bool
{
$tools = is_array($this->tool) ? $this->tool : [$this->tool];

if ($targetPlatform->phpizePath !== null) {
$tools[] = $targetPlatform->phpizePath->phpizeBinaryPath;
}

try {
$tools[] = PhpizePath::guessFrom($targetPlatform->phpBinaryPath)->phpizeBinaryPath;
} catch (RuntimeException) {
// intentionally ignored - just don't try to use the guessed phpize path
}

foreach ($tools as $tool) {
if (file_exists($tool) && is_executable($tool) && PhpizePath::looksLikeValidPhpize($tool)) {
return true;
}

$foundTool = (new ExecutableFinder())->find($tool);

if ($foundTool !== null && PhpizePath::looksLikeValidPhpize($foundTool)) {
Expand Down
3 changes: 3 additions & 0 deletions test/assets/phpize/bad/phpize
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/bash

echo "Haha! I am not really phpize."
5 changes: 5 additions & 0 deletions test/assets/phpize/good/php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/bash

echo "PHP"

exit 0
9 changes: 9 additions & 0 deletions test/assets/phpize/good/phpize
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/bash

echo "Configuring for:"
echo "PHP Version: 8.4"
echo "PHP Api Version: 20240924"
echo "Zend Module Api No: 20240924"
echo "Zend Extension Api No: 420240924"

exit 0
1 change: 1 addition & 0 deletions test/install-bundled-php-exts.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
TargetPlatform::fromPhpBinaryPath(
$phpBinaryPath,
null,
null,
),
)
->getPackages(),
Expand Down
Loading