mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-10 02:15:36 +08:00
fix version reevaluating regression from v2
This commit is contained in:
@@ -60,7 +60,7 @@ trait unix
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (self::getPHPVersionID() >= 80300 && self::getPHPVersionID() < 80400) {
|
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');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -731,6 +731,16 @@ class ArtifactDownloader
|
|||||||
$binary_downloaded = $artifact->isBinaryDownloaded(compare_hash: true);
|
$binary_downloaded = $artifact->isBinaryDownloaded(compare_hash: true);
|
||||||
$source_downloaded = $artifact->isSourceDownloaded(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 = ['display' => 'source', 'lock' => 'source', 'config' => $artifact->getDownloadConfig('source')];
|
||||||
$item_source_mirror = ['display' => 'source (mirror)', 'lock' => 'source', 'config' => $artifact->getDownloadConfig('source-mirror')];
|
$item_source_mirror = ['display' => 'source (mirror)', 'lock' => 'source', 'config' => $artifact->getDownloadConfig('source-mirror')];
|
||||||
|
|
||||||
|
|||||||
@@ -154,6 +154,8 @@ class PackageInstaller
|
|||||||
$this->resolvePackages();
|
$this->resolvePackages();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->reconcilePhpSrcVersion();
|
||||||
|
|
||||||
if ($this->interactive && !$disable_delay_msg) {
|
if ($this->interactive && !$disable_delay_msg) {
|
||||||
// show install or build options in terminal with beautiful output
|
// show install or build options in terminal with beautiful output
|
||||||
$this->printInstallerInfo();
|
$this->printInstallerInfo();
|
||||||
@@ -571,6 +573,67 @@ class PackageInstaller
|
|||||||
return null;
|
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
|
private function kindLabel(Package $package): string
|
||||||
{
|
{
|
||||||
return match (true) {
|
return match (true) {
|
||||||
|
|||||||
Reference in New Issue
Block a user