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
73 changes: 27 additions & 46 deletions src/Platform/PrePackagedBinaryAssetName.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,51 +21,32 @@ private function __construct()
/** @return non-empty-list<non-empty-string> */
public static function packageNames(TargetPlatform $targetPlatform, Package $package): array
{
return array_values(array_unique([
strtolower(sprintf(
'php_%s-%s_php%s-%s-%s-%s%s%s.zip',
$package->extensionName()->name(),
$package->version(),
$targetPlatform->phpBinaryPath->majorMinorVersion(),
$targetPlatform->architecture->name,
$targetPlatform->operatingSystemFamily->value,
$targetPlatform->libcFlavour()->value,
$targetPlatform->phpBinaryPath->debugMode() === DebugBuild::Debug ? '-debug' : '',
$targetPlatform->threadSafety === ThreadSafetyMode::ThreadSafe ? '-zts' : '',
)),
strtolower(sprintf(
'php_%s-%s_php%s-%s-%s-%s%s%s.tgz',
$package->extensionName()->name(),
$package->version(),
$targetPlatform->phpBinaryPath->majorMinorVersion(),
$targetPlatform->architecture->name,
$targetPlatform->operatingSystemFamily->value,
$targetPlatform->libcFlavour()->value,
$targetPlatform->phpBinaryPath->debugMode() === DebugBuild::Debug ? '-debug' : '',
$targetPlatform->threadSafety === ThreadSafetyMode::ThreadSafe ? '-zts' : '',
)),
strtolower(sprintf(
'php_%s-%s_php%s-%s-%s-%s%s%s.zip',
$package->extensionName()->name(),
$package->version(),
$targetPlatform->phpBinaryPath->majorMinorVersion(),
$targetPlatform->architecture->name,
$targetPlatform->operatingSystemFamily->value,
$targetPlatform->libcFlavour()->value,
$targetPlatform->phpBinaryPath->debugMode() === DebugBuild::Debug ? '-debug' : '',
$targetPlatform->threadSafety === ThreadSafetyMode::ThreadSafe ? '-zts' : '-nts',
)),
strtolower(sprintf(
'php_%s-%s_php%s-%s-%s-%s%s%s.tgz',
$package->extensionName()->name(),
$package->version(),
$targetPlatform->phpBinaryPath->majorMinorVersion(),
$targetPlatform->architecture->name,
$targetPlatform->operatingSystemFamily->value,
$targetPlatform->libcFlavour()->value,
$targetPlatform->phpBinaryPath->debugMode() === DebugBuild::Debug ? '-debug' : '',
$targetPlatform->threadSafety === ThreadSafetyMode::ThreadSafe ? '-zts' : '-nts',
)),
]));
$debug = $targetPlatform->phpBinaryPath->debugMode() === DebugBuild::Debug ? '-debug' : '';
$tsNoSuffix = $targetPlatform->threadSafety === ThreadSafetyMode::ThreadSafe ? '-zts' : '';
$tsWithSuffix = $targetPlatform->threadSafety === ThreadSafetyMode::ThreadSafe ? '-zts' : '-nts';
$libc = $targetPlatform->libcFlavour()->value;

$name = $package->extensionName()->name();
$version = $package->version();
$phpVer = $targetPlatform->phpBinaryPath->majorMinorVersion();
$arch = $targetPlatform->architecture->name;
$os = $targetPlatform->operatingSystemFamily->value;

$names = [
strtolower(sprintf('php_%s-%s_php%s-%s-%s-%s%s%s.zip', $name, $version, $phpVer, $arch, $os, $libc, $debug, $tsNoSuffix)),
strtolower(sprintf('php_%s-%s_php%s-%s-%s-%s%s%s.tgz', $name, $version, $phpVer, $arch, $os, $libc, $debug, $tsNoSuffix)),
strtolower(sprintf('php_%s-%s_php%s-%s-%s-%s%s%s.zip', $name, $version, $phpVer, $arch, $os, $libc, $debug, $tsWithSuffix)),
strtolower(sprintf('php_%s-%s_php%s-%s-%s-%s%s%s.tgz', $name, $version, $phpVer, $arch, $os, $libc, $debug, $tsWithSuffix)),
];

// Fallbacks with anylibc suffix, for unified binaries compatible with both glibc and musl (Linux only)
if ($targetPlatform->operatingSystemFamily === OperatingSystemFamily::Linux) {
$names[] = strtolower(sprintf('php_%s-%s_php%s-%s-%s-anylibc%s%s.zip', $name, $version, $phpVer, $arch, $os, $debug, $tsNoSuffix));
$names[] = strtolower(sprintf('php_%s-%s_php%s-%s-%s-anylibc%s%s.tgz', $name, $version, $phpVer, $arch, $os, $debug, $tsNoSuffix));
$names[] = strtolower(sprintf('php_%s-%s_php%s-%s-%s-anylibc%s%s.zip', $name, $version, $phpVer, $arch, $os, $debug, $tsWithSuffix));
$names[] = strtolower(sprintf('php_%s-%s_php%s-%s-%s-anylibc%s%s.tgz', $name, $version, $phpVer, $arch, $os, $debug, $tsWithSuffix));
}

return array_values(array_unique($names));
}
}
24 changes: 18 additions & 6 deletions test/unit/Downloading/DownloadUrlMethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,15 @@ public function testPrePackagedBinaryDownloads(): void

self::assertSame(DownloadUrlMethod::PrePackagedBinary, $downloadUrlMethod);

// TargetPlatform doesn't have the libc specified, so the assertion needs to be made
// against the test machine's libc
$libc = $targetPlatform->libcFlavour()->value;
self::assertSame(
[
'php_bar-1.2.3_php8.3-x86_64-linux-glibc-debug-zts.zip',
'php_bar-1.2.3_php8.3-x86_64-linux-glibc-debug-zts.tgz',
'php_bar-1.2.3_php8.3-x86_64-linux-' . $libc . '-debug-zts.zip',
'php_bar-1.2.3_php8.3-x86_64-linux-' . $libc . '-debug-zts.tgz',
'php_bar-1.2.3_php8.3-x86_64-linux-anylibc-debug-zts.zip',
'php_bar-1.2.3_php8.3-x86_64-linux-anylibc-debug-zts.tgz',
],
$downloadUrlMethod->possibleAssetNames($package, $targetPlatform),
);
Expand Down Expand Up @@ -221,12 +226,19 @@ public function testMultipleDownloadUrlMethods(): void

$firstMethod = $downloadUrlMethods[0];
self::assertSame(DownloadUrlMethod::PrePackagedBinary, $firstMethod);
// TargetPlatform doesn't have the libc specified, so the assertion needs to be made
// against the test machine's libc
$libc = $targetPlatform->libcFlavour()->value;
self::assertSame(
[
'php_bar-1.2.3_php8.3-x86_64-linux-glibc-debug.zip',
'php_bar-1.2.3_php8.3-x86_64-linux-glibc-debug.tgz',
'php_bar-1.2.3_php8.3-x86_64-linux-glibc-debug-nts.zip',
'php_bar-1.2.3_php8.3-x86_64-linux-glibc-debug-nts.tgz',
'php_bar-1.2.3_php8.3-x86_64-linux-' . $libc . '-debug.zip',
'php_bar-1.2.3_php8.3-x86_64-linux-' . $libc . '-debug.tgz',
'php_bar-1.2.3_php8.3-x86_64-linux-' . $libc . '-debug-nts.zip',
'php_bar-1.2.3_php8.3-x86_64-linux-' . $libc . '-debug-nts.tgz',
'php_bar-1.2.3_php8.3-x86_64-linux-anylibc-debug.zip',
'php_bar-1.2.3_php8.3-x86_64-linux-anylibc-debug.tgz',
'php_bar-1.2.3_php8.3-x86_64-linux-anylibc-debug-nts.zip',
'php_bar-1.2.3_php8.3-x86_64-linux-anylibc-debug-nts.tgz',
],
$firstMethod->possibleAssetNames($package, $targetPlatform),
);
Expand Down
6 changes: 6 additions & 0 deletions test/unit/Platform/PrePackagedBinaryAssetNameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public function testPackageNamesNts(): void
'php_foobar-1.2.3_php8.2-x86_64-linux-' . $libc->value . '.tgz',
'php_foobar-1.2.3_php8.2-x86_64-linux-' . $libc->value . '-nts.zip',
'php_foobar-1.2.3_php8.2-x86_64-linux-' . $libc->value . '-nts.tgz',
'php_foobar-1.2.3_php8.2-x86_64-linux-anylibc.zip',
'php_foobar-1.2.3_php8.2-x86_64-linux-anylibc.tgz',
'php_foobar-1.2.3_php8.2-x86_64-linux-anylibc-nts.zip',
'php_foobar-1.2.3_php8.2-x86_64-linux-anylibc-nts.tgz',
],
PrePackagedBinaryAssetName::packageNames(
$targetPlatform,
Expand Down Expand Up @@ -83,6 +87,8 @@ public function testPackageNamesZts(): void
[
'php_foobar-1.2.3_php8.3-x86_64-linux-' . $libc->value . '-zts.zip',
'php_foobar-1.2.3_php8.3-x86_64-linux-' . $libc->value . '-zts.tgz',
'php_foobar-1.2.3_php8.3-x86_64-linux-anylibc-zts.zip',
'php_foobar-1.2.3_php8.3-x86_64-linux-anylibc-zts.tgz',
],
PrePackagedBinaryAssetName::packageNames(
$targetPlatform,
Expand Down
Loading