From 70e717adb61a5c74994d1d5b970db6775cb7130e Mon Sep 17 00:00:00 2001 From: henderkes Date: Fri, 15 May 2026 14:05:33 +0700 Subject: [PATCH] fix version reevaluating regression from v2 --- src/Package/Target/php/unix.php | 2 +- src/StaticPHP/Artifact/ArtifactDownloader.php | 10 +++ src/StaticPHP/Package/PackageInstaller.php | 63 +++++++++++++++++++ ...> spc_fix_avx512_cache_before_80400.patch} | 0 4 files changed, 74 insertions(+), 1 deletion(-) rename src/globals/patch/{spc_fix_avx512_cache_before_80400.patch‎ => spc_fix_avx512_cache_before_80400.patch} (100%) diff --git a/src/Package/Target/php/unix.php b/src/Package/Target/php/unix.php index 82a99840..b8d3371a 100644 --- a/src/Package/Target/php/unix.php +++ b/src/Package/Target/php/unix.php @@ -60,7 +60,7 @@ trait unix } if (self::getPHPVersionID() >= 80300 && self::getPHPVersionID() < 80400) { - SourcePatcher::patchFile('spc_fix_avx512_cache_before_80400.patch', $this->getSourceDir()); + SourcePatcher::patchFile('spc_fix_avx512_cache_before_80400.patch', SOURCE_PATH . '/php-src'); } } diff --git a/src/StaticPHP/Artifact/ArtifactDownloader.php b/src/StaticPHP/Artifact/ArtifactDownloader.php index f52036c6..345f9120 100644 --- a/src/StaticPHP/Artifact/ArtifactDownloader.php +++ b/src/StaticPHP/Artifact/ArtifactDownloader.php @@ -731,6 +731,16 @@ class ArtifactDownloader $binary_downloaded = $artifact->isBinaryDownloaded(compare_hash: true); $source_downloaded = $artifact->isSourceDownloaded(compare_hash: true); + if ($source_downloaded && $artifact->getName() === 'php-src' && ($requested = $this->getOption('with-php'))) { + $info = ApplicationContext::get(ArtifactCache::class)->getSourceInfo('php-src'); + $cv = $info['version'] ?? null; + $ct = $info['cache_type'] ?? null; + $matches = $requested === 'git' ? $ct === 'git' : ($cv !== null && $ct !== 'git' && ($cv === $requested || str_starts_with($cv, $requested . '.'))); + if (!$matches) { + $source_downloaded = false; + } + } + $item_source = ['display' => 'source', 'lock' => 'source', 'config' => $artifact->getDownloadConfig('source')]; $item_source_mirror = ['display' => 'source (mirror)', 'lock' => 'source', 'config' => $artifact->getDownloadConfig('source-mirror')]; diff --git a/src/StaticPHP/Package/PackageInstaller.php b/src/StaticPHP/Package/PackageInstaller.php index 86f1aac8..8510a94b 100644 --- a/src/StaticPHP/Package/PackageInstaller.php +++ b/src/StaticPHP/Package/PackageInstaller.php @@ -154,6 +154,8 @@ class PackageInstaller $this->resolvePackages(); } + $this->reconcilePhpSrcVersion(); + if ($this->interactive && !$disable_delay_msg) { // show install or build options in terminal with beautiful output $this->printInstallerInfo(); @@ -571,6 +573,67 @@ class PackageInstaller return null; } + private function reconcilePhpSrcVersion(): void + { + $src_dir = SOURCE_PATH . '/php-src'; + $cache = ApplicationContext::get(ArtifactCache::class); + $requested = $this->options['dl-with-php'] ?? null; + if ($requested !== null && $requested !== '' && $requested !== 'git') { + $info = $cache->getSourceInfo('php-src') ?? []; + $cv = $info['version'] ?? null; + if (($info['cache_type'] ?? null) === 'git' || $cv === null + || ($cv !== $requested && !str_starts_with($cv, $requested . '.'))) { + $resolved = null; + $candidates = glob(DOWNLOAD_PATH . '/php-' . $requested . '.*.tar.xz') ?: []; + if ($candidates !== []) { + usort($candidates, 'strnatcmp'); + if (preg_match('/^php-([0-9.]+)\.tar\.xz$/', basename(end($candidates)), $vm)) { + $resolved = $vm[1]; + } + } elseif ($this->download) { + $j = @file_get_contents('https://www.php.net/releases/index.php?json&version=' . urlencode($requested)); + $rel = is_string($j) ? json_decode($j, true) : null; + $resolved = is_array($rel) ? ($rel['version'] ?? null) : null; + } else { + throw new WrongUsageException("Requested PHP '{$requested}' but no php-{$requested}.*.tar.xz in downloads/; drop --no-download or run 'bin/spc download php-src --with-php={$requested}' first."); + } + if ($resolved !== null) { + $cf = DOWNLOAD_PATH . '/.cache.json'; + $j = json_decode(@file_get_contents($cf) ?: '{}', true) ?: []; + $tarball = DOWNLOAD_PATH . "/php-{$resolved}.tar.xz"; + $j['php-src']['source'] = [ + 'lock_type' => 'source', 'cache_type' => 'archive', + 'filename' => "php-{$resolved}.tar.xz", + 'extract' => $info['extract'] ?? null, + 'hash' => is_file($tarball) ? sha1_file($tarball) : null, + 'time' => time(), 'version' => $resolved, + 'config' => $info['config'] ?? ['type' => 'php-release', 'domain' => 'https://www.php.net'], + 'downloader' => $info['downloader'] ?? \StaticPHP\Artifact\Downloader\Type\PhpRelease::class, + ]; + $j['php-src']['binary'] ??= []; + file_put_contents($cf, json_encode($j, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); + ApplicationContext::set(ArtifactCache::class, $cache = new ArtifactCache()); + } + } + } + if (!is_dir($src_dir) || ($info = $cache->getSourceInfo('php-src')) === null) { + return; + } + if (($info['cache_type'] ?? null) === 'git') { + if (!is_dir($src_dir . '/.git')) { + FileSystem::removeDir($src_dir); + } + return; + } + $vh = $src_dir . '/main/php_version.h'; + if (is_file($vh) + && preg_match('/#define\s+PHP_VERSION\s+"([^"]+)"/', file_get_contents($vh), $m) + && $m[1] !== ($info['version'] ?? null) + ) { + FileSystem::removeDir($src_dir); + } + } + private function kindLabel(Package $package): string { return match (true) { diff --git a/src/globals/patch/spc_fix_avx512_cache_before_80400.patch‎ b/src/globals/patch/spc_fix_avx512_cache_before_80400.patch similarity index 100% rename from src/globals/patch/spc_fix_avx512_cache_before_80400.patch‎ rename to src/globals/patch/spc_fix_avx512_cache_before_80400.patch