mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-07 08:45:40 +08:00
Allow locking different arch pre-built content
This commit is contained in:
@@ -7,6 +7,7 @@ namespace SPC\command;
|
||||
use SPC\exception\DownloaderException;
|
||||
use SPC\exception\FileSystemException;
|
||||
use SPC\exception\WrongUsageException;
|
||||
use SPC\store\Downloader;
|
||||
use SPC\store\FileSystem;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
@@ -47,30 +48,35 @@ class DeleteDownloadCommand extends BaseCommand
|
||||
$chosen_sources = $sources;
|
||||
$lock = json_decode(FileSystem::readFile(DOWNLOAD_PATH . '/.lock.json'), true) ?? [];
|
||||
|
||||
$deleted_sources = [];
|
||||
foreach ($chosen_sources as $source) {
|
||||
$source = trim($source);
|
||||
if (!isset($lock[$source])) {
|
||||
logger()->warning("Source/Package [{$source}] not locked or not downloaded, skipped.");
|
||||
continue;
|
||||
foreach ([$source, Downloader::getPreBuiltName($source)] as $name) {
|
||||
if (isset($lock[$name])) {
|
||||
$deleted_sources[] = $name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($deleted_sources as $lock_name) {
|
||||
// remove download file/dir if exists
|
||||
if ($lock[$source]['source_type'] === 'archive') {
|
||||
if (file_exists($path = FileSystem::convertPath(DOWNLOAD_PATH . '/' . $lock[$source]['filename']))) {
|
||||
if ($lock[$lock_name]['source_type'] === 'archive') {
|
||||
if (file_exists($path = FileSystem::convertPath(DOWNLOAD_PATH . '/' . $lock[$lock_name]['filename']))) {
|
||||
logger()->info('Deleting file ' . $path);
|
||||
unlink($path);
|
||||
} else {
|
||||
logger()->warning("Source/Package [{$source}] file not found, skip deleting file.");
|
||||
logger()->warning("Source/Package [{$lock_name}] file not found, skip deleting file.");
|
||||
}
|
||||
} else {
|
||||
if (is_dir($path = FileSystem::convertPath(DOWNLOAD_PATH . '/' . $lock[$source]['dirname']))) {
|
||||
if (is_dir($path = FileSystem::convertPath(DOWNLOAD_PATH . '/' . $lock[$lock_name]['dirname']))) {
|
||||
logger()->info('Deleting dir ' . $path);
|
||||
FileSystem::removeDir($path);
|
||||
} else {
|
||||
logger()->warning("Source/Package [{$source}] directory not found, skip deleting dir.");
|
||||
logger()->warning("Source/Package [{$lock_name}] directory not found, skip deleting dir.");
|
||||
}
|
||||
}
|
||||
// remove locked sources
|
||||
unset($lock[$source]);
|
||||
unset($lock[$lock_name]);
|
||||
}
|
||||
FileSystem::writeFile(DOWNLOAD_PATH . '/.lock.json', json_encode($lock, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
|
||||
logger()->info('Delete success!');
|
||||
|
||||
@@ -231,11 +231,17 @@ class DownloadCommand extends BaseCommand
|
||||
// Prefer pre-built, we need to search pre-built library
|
||||
if ($this->getOption('prefer-pre-built') && ($config['provide-pre-built'] ?? false) === true) {
|
||||
// We need to replace pattern
|
||||
$find = str_replace(['{name}', '{arch}', '{os}'], [$source, arch2gnu(php_uname('m')), strtolower(PHP_OS_FAMILY)], Config::getPreBuilt('match-pattern'));
|
||||
$replace = [
|
||||
'{name}' => $source,
|
||||
'{arch}' => arch2gnu(php_uname('m')),
|
||||
'{os}' => strtolower(PHP_OS_FAMILY),
|
||||
'{libc}' => getenv('SPC_LIBC') ?: 'default',
|
||||
];
|
||||
$find = str_replace(array_keys($replace), array_values($replace), Config::getPreBuilt('match-pattern'));
|
||||
// find filename in asset list
|
||||
if (($url = $this->findPreBuilt($pre_built_libs, $find)) !== null) {
|
||||
logger()->info("[{$ni}/{$cnt}] Downloading pre-built content {$source}");
|
||||
Downloader::downloadSource($source, ['type' => 'url', 'url' => $url], $force_all || in_array($source, $force_list), SPC_LOCK_PRE_BUILT);
|
||||
Downloader::downloadSource($source, ['type' => 'url', 'url' => $url], $force_all || in_array($source, $force_list), SPC_DOWN_PRE_BUILT);
|
||||
continue;
|
||||
}
|
||||
logger()->warning("Pre-built content not found for {$source}, fallback to source download");
|
||||
|
||||
@@ -47,7 +47,7 @@ class PackLibCommand extends BuildCommand
|
||||
// Get lock info
|
||||
$lock = json_decode(file_get_contents(DOWNLOAD_PATH . '/.lock.json'), true) ?? [];
|
||||
$source = Config::getLib($lib->getName(), 'source');
|
||||
if (!isset($lock[$source]) || ($lock[$source]['lock_as'] ?? SPC_LOCK_SOURCE) === SPC_LOCK_PRE_BUILT) {
|
||||
if (!isset($lock[$source]) || ($lock[$source]['lock_as'] ?? SPC_DOWN_SOURCE) === SPC_DOWN_PRE_BUILT) {
|
||||
logger()->critical("The library {$lib->getName()} is downloaded as pre-built, we need to build it instead of installing pre-built.");
|
||||
return static::FAILURE;
|
||||
}
|
||||
@@ -69,7 +69,15 @@ class PackLibCommand extends BuildCommand
|
||||
// write list to packlib_files.txt
|
||||
FileSystem::writeFile(WORKING_DIR . '/packlib_files.txt', implode("\n", $increase_files));
|
||||
// pack
|
||||
$filename = WORKING_DIR . '/dist/' . $lib->getName() . '-' . arch2gnu(php_uname('m')) . '-' . strtolower(PHP_OS_FAMILY) . '.' . Config::getPreBuilt('suffix');
|
||||
$filename = Config::getPreBuilt('match-pattern');
|
||||
$replace = [
|
||||
'{name}' => $lib->getName(),
|
||||
'{arch}' => arch2gnu(php_uname('m')),
|
||||
'{os}' => strtolower(PHP_OS_FAMILY),
|
||||
'{libc}' => getenv('SPC_LIBC') ?: 'default',
|
||||
];
|
||||
$filename = str_replace(array_keys($replace), array_values($replace), $filename);
|
||||
$filename = WORKING_DIR . '/dist/' . $filename . '.' . Config::getPreBuilt('suffix');
|
||||
f_passthru('tar -czf ' . $filename . ' -T ' . WORKING_DIR . '/packlib_files.txt');
|
||||
logger()->info('Pack library ' . $lib->getName() . ' to ' . $filename . ' complete.');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user