mirror of
https://github.com/php/pie.git
synced 2026-03-23 23:12:17 +01:00
@@ -2,6 +2,7 @@
|
|||||||
"alias": "pie.phar",
|
"alias": "pie.phar",
|
||||||
"output": "pie.phar",
|
"output": "pie.phar",
|
||||||
"git": "pie_version",
|
"git": "pie_version",
|
||||||
|
"stub": "phar-stub.php",
|
||||||
"force-autodiscovery": true,
|
"force-autodiscovery": true,
|
||||||
"directories": [
|
"directories": [
|
||||||
"resources"
|
"resources"
|
||||||
|
|||||||
19
phar-stub.php
Normal file
19
phar-stub.php
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#!/usr/bin/env php
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
// echo "James says hello :)\n";
|
||||||
|
|
||||||
|
// Workaround for https://github.com/php/pie/issues/537 and https://github.com/box-project/box/issues/1577
|
||||||
|
error_reporting(error_reporting() & ~E_DEPRECATED);
|
||||||
|
|
||||||
|
Phar::mapPhar('pie.phar');
|
||||||
|
|
||||||
|
require 'phar://pie.phar/.box/bin/check-requirements.php';
|
||||||
|
|
||||||
|
$_SERVER['SCRIPT_FILENAME'] = 'phar://pie.phar/bin/pie';
|
||||||
|
require 'phar://pie.phar/bin/pie';
|
||||||
|
|
||||||
|
// phpcs:ignore Generic.Files.InlineHTML.Found
|
||||||
|
__HALT_COMPILER(); ?>
|
||||||
@@ -300,18 +300,6 @@ parameters:
|
|||||||
count: 4
|
count: 4
|
||||||
path: src/Platform/TargetPhp/PhpBinaryPath.php
|
path: src/Platform/TargetPhp/PhpBinaryPath.php
|
||||||
|
|
||||||
-
|
|
||||||
message: '#^Call to function array_key_exists\(\) with 2 and array\{non\-falsy\-string, string, non\-falsy\-string\} will always evaluate to true\.$#'
|
|
||||||
identifier: function.alreadyNarrowedType
|
|
||||||
count: 1
|
|
||||||
path: src/Platform/TargetPlatform.php
|
|
||||||
|
|
||||||
-
|
|
||||||
message: '#^Strict comparison using \!\=\= between non\-falsy\-string and '''' will always evaluate to true\.$#'
|
|
||||||
identifier: notIdentical.alwaysTrue
|
|
||||||
count: 1
|
|
||||||
path: src/Platform/TargetPlatform.php
|
|
||||||
|
|
||||||
-
|
-
|
||||||
message: '#^Dead catch \- Php\\Pie\\SelfManage\\Verify\\GithubCliNotAvailable is never thrown in the try block\.$#'
|
message: '#^Dead catch \- Php\\Pie\\SelfManage\\Verify\\GithubCliNotAvailable is never thrown in the try block\.$#'
|
||||||
identifier: catch.neverThrown
|
identifier: catch.neverThrown
|
||||||
|
|||||||
@@ -385,6 +385,20 @@ PHP,
|
|||||||
|
|
||||||
public function machineType(): Architecture
|
public function machineType(): Architecture
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* On Windows, this will be x32 or x64; should not be used on other platforms
|
||||||
|
*
|
||||||
|
* Based on xdebug.org wizard, copyright Derick Rethans, used under MIT licence
|
||||||
|
*
|
||||||
|
* @link https://github.com/xdebug/xdebug.org/blob/aff649f2c3ca303ad471e6ed9dd29c0db16d3e22/src/XdebugVersion.php#L186-L190
|
||||||
|
*/
|
||||||
|
if (
|
||||||
|
$this->operatingSystem() === OperatingSystem::Windows
|
||||||
|
&& preg_match('/Architecture([ =>\t]*)(x[0-9]*)/', $this->phpinfo(), $m)
|
||||||
|
) {
|
||||||
|
return Architecture::parseArchitecture($m[2]);
|
||||||
|
}
|
||||||
|
|
||||||
$phpMachineType = self::cleanWarningAndDeprecationsFromOutput(Process::run([
|
$phpMachineType = self::cleanWarningAndDeprecationsFromOutput(Process::run([
|
||||||
$this->phpBinaryPath,
|
$this->phpBinaryPath,
|
||||||
'-r',
|
'-r',
|
||||||
@@ -392,7 +406,14 @@ PHP,
|
|||||||
]));
|
]));
|
||||||
Assert::stringNotEmpty($phpMachineType, 'Could not determine PHP machine type');
|
Assert::stringNotEmpty($phpMachineType, 'Could not determine PHP machine type');
|
||||||
|
|
||||||
return Architecture::parseArchitecture($phpMachineType);
|
$unameArchitecture = Architecture::parseArchitecture($phpMachineType);
|
||||||
|
|
||||||
|
// If we're not on ARM, a more reliable way of determining 32-bit/64-bit is to use PHP_INT_SIZE
|
||||||
|
if ($unameArchitecture !== Architecture::arm64) {
|
||||||
|
return $this->phpIntSize() === 4 ? Architecture::x86 : Architecture::x86_64;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $unameArchitecture;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function phpIntSize(): int
|
public function phpIntSize(): int
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ use Fidry\CpuCoreCounter\CpuCoreCounter;
|
|||||||
use Php\Pie\Platform\TargetPhp\PhpBinaryPath;
|
use Php\Pie\Platform\TargetPhp\PhpBinaryPath;
|
||||||
use Php\Pie\Platform\TargetPhp\PhpizePath;
|
use Php\Pie\Platform\TargetPhp\PhpizePath;
|
||||||
|
|
||||||
use function array_key_exists;
|
|
||||||
use function explode;
|
use function explode;
|
||||||
use function function_exists;
|
use function function_exists;
|
||||||
use function posix_getuid;
|
use function posix_getuid;
|
||||||
@@ -52,31 +51,10 @@ class TargetPlatform
|
|||||||
|
|
||||||
public static function fromPhpBinaryPath(PhpBinaryPath $phpBinaryPath, int|null $makeParallelJobs, PhpizePath|null $phpizePath): self
|
public static function fromPhpBinaryPath(PhpBinaryPath $phpBinaryPath, int|null $makeParallelJobs, PhpizePath|null $phpizePath): self
|
||||||
{
|
{
|
||||||
$os = $phpBinaryPath->operatingSystem();
|
$os = $phpBinaryPath->operatingSystem();
|
||||||
$osFamily = $phpBinaryPath->operatingSystemFamily();
|
$osFamily = $phpBinaryPath->operatingSystemFamily();
|
||||||
|
$phpinfo = $phpBinaryPath->phpinfo();
|
||||||
$phpinfo = $phpBinaryPath->phpinfo();
|
$architecture = $phpBinaryPath->machineType();
|
||||||
|
|
||||||
$architecture = $phpBinaryPath->machineType();
|
|
||||||
|
|
||||||
// If we're not on ARM, a more reliable way of determining 32-bit/64-bit is to use PHP_INT_SIZE
|
|
||||||
if ($architecture !== Architecture::arm64) {
|
|
||||||
$architecture = $phpBinaryPath->phpIntSize() === 4 ? Architecture::x86 : Architecture::x86_64;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Based on xdebug.org wizard, copyright Derick Rethans, used under MIT licence
|
|
||||||
*
|
|
||||||
* @link https://github.com/xdebug/xdebug.org/blob/aff649f2c3ca303ad471e6ed9dd29c0db16d3e22/src/XdebugVersion.php#L186-L190
|
|
||||||
*/
|
|
||||||
if (
|
|
||||||
preg_match('/Architecture([ =>\t]*)(x[0-9]*)/', $phpinfo, $m)
|
|
||||||
&& array_key_exists(2, $m)
|
|
||||||
&& $m[2] !== ''
|
|
||||||
) {
|
|
||||||
$architecture = Architecture::parseArchitecture($m[2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$windowsCompiler = null;
|
$windowsCompiler = null;
|
||||||
$threadSafety = ThreadSafetyMode::ThreadSafe;
|
$threadSafety = ThreadSafetyMode::ThreadSafe;
|
||||||
|
|
||||||
|
|||||||
@@ -30,22 +30,25 @@ use function array_key_exists;
|
|||||||
use function array_map;
|
use function array_map;
|
||||||
use function array_unique;
|
use function array_unique;
|
||||||
use function assert;
|
use function assert;
|
||||||
|
use function chmod;
|
||||||
use function count;
|
use function count;
|
||||||
use function defined;
|
use function defined;
|
||||||
use function dirname;
|
use function dirname;
|
||||||
use function file_exists;
|
use function file_exists;
|
||||||
|
use function file_put_contents;
|
||||||
use function get_loaded_extensions;
|
use function get_loaded_extensions;
|
||||||
use function ini_get;
|
use function ini_get;
|
||||||
use function is_dir;
|
use function is_dir;
|
||||||
use function is_executable;
|
use function is_executable;
|
||||||
use function mkdir;
|
use function mkdir;
|
||||||
use function php_uname;
|
|
||||||
use function phpversion;
|
use function phpversion;
|
||||||
use function sprintf;
|
use function sprintf;
|
||||||
use function strtolower;
|
use function strtolower;
|
||||||
use function sys_get_temp_dir;
|
use function sys_get_temp_dir;
|
||||||
|
use function tempnam;
|
||||||
use function trim;
|
use function trim;
|
||||||
use function uniqid;
|
use function uniqid;
|
||||||
|
use function unlink;
|
||||||
|
|
||||||
use const DIRECTORY_SEPARATOR;
|
use const DIRECTORY_SEPARATOR;
|
||||||
use const PHP_INT_SIZE;
|
use const PHP_INT_SIZE;
|
||||||
@@ -241,15 +244,46 @@ final class PhpBinaryPathTest extends TestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMachineType(): void
|
/** @return list<array{0: OperatingSystem, 1: string, 2: string, 3: int, 4: Architecture}> */
|
||||||
|
public static function machineTypeProvider(): array
|
||||||
{
|
{
|
||||||
$myUnameMachineType = php_uname('m');
|
return [
|
||||||
assert($myUnameMachineType !== '');
|
// x86 (32-bit)
|
||||||
self::assertSame(
|
[OperatingSystem::Windows, 'Architecture => x32', '', 4, Architecture::x86],
|
||||||
Architecture::parseArchitecture($myUnameMachineType),
|
[OperatingSystem::NonWindows, 'Architecture => x86', 'x86', 4, Architecture::x86],
|
||||||
PhpBinaryPath::fromCurrentProcess()
|
[OperatingSystem::NonWindows, '', 'x86', 4, Architecture::x86],
|
||||||
->machineType(),
|
|
||||||
);
|
// x86_64 (64-bit)
|
||||||
|
[OperatingSystem::Windows, 'Architecture => x64', 'AMD64', 8, Architecture::x86_64],
|
||||||
|
[OperatingSystem::Windows, 'Architecture => x64', '', 8, Architecture::x86_64],
|
||||||
|
[OperatingSystem::NonWindows, 'Architecture => x86_64', 'x86_64', 8, Architecture::x86_64],
|
||||||
|
[OperatingSystem::NonWindows, '', 'x86_64', 8, Architecture::x86_64],
|
||||||
|
|
||||||
|
// arm64
|
||||||
|
[OperatingSystem::NonWindows, 'Architecture => arm64', 'arm64', 8, Architecture::arm64],
|
||||||
|
[OperatingSystem::NonWindows, '', 'arm64', 8, Architecture::arm64],
|
||||||
|
[OperatingSystem::NonWindows, 'Architecture => aarch64', 'aarch64', 8, Architecture::arm64],
|
||||||
|
[OperatingSystem::NonWindows, '', 'aarch64', 8, Architecture::arm64],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
#[RequiresOperatingSystemFamily('Linux')]
|
||||||
|
#[DataProvider('machineTypeProvider')]
|
||||||
|
public function testMachineType(OperatingSystem $os, string $phpinfo, string $uname, int $phpIntSize, Architecture $expectedArchitecture): void
|
||||||
|
{
|
||||||
|
$tmpSh = tempnam(sys_get_temp_dir(), uniqid('pie_machine_type_test'));
|
||||||
|
file_put_contents($tmpSh, "#!/usr/bin/env bash\necho \"" . $uname . "\";\n");
|
||||||
|
chmod($tmpSh, 0777);
|
||||||
|
|
||||||
|
$phpBinary = $this->createPartialMock(PhpBinaryPath::class, ['operatingSystem', 'phpinfo', 'phpIntSize']);
|
||||||
|
(new ReflectionMethod($phpBinary, '__construct'))->invoke($phpBinary, $tmpSh, null);
|
||||||
|
|
||||||
|
$phpBinary->method('operatingSystem')->willReturn($os);
|
||||||
|
$phpBinary->method('phpinfo')->willReturn($phpinfo);
|
||||||
|
$phpBinary->method('phpIntSize')->willReturn($phpIntSize);
|
||||||
|
|
||||||
|
self::assertEquals($expectedArchitecture, $phpBinary->machineType());
|
||||||
|
unlink($tmpSh);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPhpIntSize(): void
|
public function testPhpIntSize(): void
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ final class TargetPlatformTest extends TestCase
|
|||||||
->willReturn(OperatingSystemFamily::Windows);
|
->willReturn(OperatingSystemFamily::Windows);
|
||||||
$phpBinaryPath->expects(self::any())
|
$phpBinaryPath->expects(self::any())
|
||||||
->method('machineType')
|
->method('machineType')
|
||||||
->willReturn(Architecture::x86);
|
->willReturn(Architecture::x86_64);
|
||||||
$phpBinaryPath->expects(self::any())
|
$phpBinaryPath->expects(self::any())
|
||||||
->method('phpinfo')
|
->method('phpinfo')
|
||||||
->willReturn(<<<'TEXT'
|
->willReturn(<<<'TEXT'
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ use PHPUnit\Framework\TestCase;
|
|||||||
final class ReleaseIsNewerTest extends TestCase
|
final class ReleaseIsNewerTest extends TestCase
|
||||||
{
|
{
|
||||||
/** @return array<non-empty-string, array{0: Channel, 1: non-empty-string, 2: non-empty-string, 3: bool}> */
|
/** @return array<non-empty-string, array{0: Channel, 1: non-empty-string, 2: non-empty-string, 3: bool}> */
|
||||||
public function provider(): array
|
public static function provider(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'stable-oldstable-to-newstable' => [Channel::Stable, '1.0.0', '1.0.1', true],
|
'stable-oldstable-to-newstable' => [Channel::Stable, '1.0.0', '1.0.1', true],
|
||||||
|
|||||||
Reference in New Issue
Block a user