From 4e4eaed1234b567795d7500852866def4ce9e404 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Mon, 31 Mar 2025 16:37:24 +0800 Subject: [PATCH] Add extract source only mode for SourceManager --- src/SPC/builder/BuilderBase.php | 4 ++-- src/SPC/builder/LibraryBase.php | 2 +- src/SPC/command/ExtractCommand.php | 3 ++- src/SPC/store/SourceManager.php | 4 ++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/SPC/builder/BuilderBase.php b/src/SPC/builder/BuilderBase.php index 0456af8b..5974bdf0 100644 --- a/src/SPC/builder/BuilderBase.php +++ b/src/SPC/builder/BuilderBase.php @@ -174,11 +174,11 @@ abstract class BuilderBase { CustomExt::loadCustomExt(); $this->emitPatchPoint('before-php-extract'); - SourceManager::initSource(sources: ['php-src']); + SourceManager::initSource(sources: ['php-src'], source_only: true); $this->emitPatchPoint('after-php-extract'); if ($this->getPHPVersionID() >= 80000) { $this->emitPatchPoint('before-micro-extract'); - SourceManager::initSource(sources: ['micro']); + SourceManager::initSource(sources: ['micro'], source_only: true); $this->emitPatchPoint('after-micro-extract'); } $this->emitPatchPoint('before-exts-extract'); diff --git a/src/SPC/builder/LibraryBase.php b/src/SPC/builder/LibraryBase.php index 2c75f4ca..abf9dd50 100644 --- a/src/SPC/builder/LibraryBase.php +++ b/src/SPC/builder/LibraryBase.php @@ -222,7 +222,7 @@ abstract class LibraryBase // extract first if not exists if (!is_dir($this->source_dir)) { $this->getBuilder()->emitPatchPoint('before-library[ ' . static::NAME . ']-extract'); - SourceManager::initSource(libs: [static::NAME]); + SourceManager::initSource(libs: [static::NAME], source_only: true); $this->getBuilder()->emitPatchPoint('after-library[ ' . static::NAME . ']-extract'); } diff --git a/src/SPC/command/ExtractCommand.php b/src/SPC/command/ExtractCommand.php index aacf5039..e532880d 100644 --- a/src/SPC/command/ExtractCommand.php +++ b/src/SPC/command/ExtractCommand.php @@ -20,6 +20,7 @@ class ExtractCommand extends BaseCommand public function configure(): void { $this->addArgument('sources', InputArgument::REQUIRED, 'The sources will be compiled, comma separated'); + $this->addOption('source-only', null, null, 'Only check the source exist, do not check the lib and ext'); } /** @@ -34,7 +35,7 @@ class ExtractCommand extends BaseCommand $this->output->writeln('sources cannot be empty, at least contain one !'); return static::FAILURE; } - SourceManager::initSource(sources: $sources); + SourceManager::initSource(sources: $sources, source_only: $this->getOption('source-only')); logger()->info('Extract done !'); return static::SUCCESS; } diff --git a/src/SPC/store/SourceManager.php b/src/SPC/store/SourceManager.php index c36bfc58..4b06df34 100644 --- a/src/SPC/store/SourceManager.php +++ b/src/SPC/store/SourceManager.php @@ -15,7 +15,7 @@ class SourceManager * @throws FileSystemException * @throws RuntimeException */ - public static function initSource(?array $sources = null, ?array $libs = null, ?array $exts = null): void + public static function initSource(?array $sources = null, ?array $libs = null, ?array $exts = null, bool $source_only = false): void { if (!file_exists(DOWNLOAD_PATH . '/.lock.json')) { throw new WrongUsageException('Download lock file "downloads/.lock.json" not found, maybe you need to download sources first ?'); @@ -56,7 +56,7 @@ class SourceManager } // check source downloaded $pre_built_name = Downloader::getPreBuiltLockName($source); - if (!isset($lock[$pre_built_name])) { + if ($source_only || !isset($lock[$pre_built_name])) { if (!isset($lock[$source])) { throw new WrongUsageException("Source [{$source}] not downloaded or not locked, you should download it first !"); }