diff --git a/docs/en/guide/manual-build.md b/docs/en/guide/manual-build.md index a8d252dc..487d3329 100644 --- a/docs/en/guide/manual-build.md +++ b/docs/en/guide/manual-build.md @@ -204,6 +204,19 @@ bin/spc download --all -U "php-src:https://downloads.php.net/~eric/php-8.3.0beta bin/spc download --all -U "curl:https://curl.se/download/curl-7.88.1.tar.gz" ``` +If the source you download is not a link, but a git repository, you can use `-G` or `--custom-git` to rewrite the download link, +so that the downloader can force the use of the specified git repository to download packages from this source. +The usage method is `{source-name}:{branch}:{url}`, which can rewrite the download link of multiple libraries at the same time. +It is also available when downloading with the `--for-extensions` option. + +```bash +# Specifying to download the source code of the PHP extension from the specified branch of the git repository +bin/spc download --for-extensions=redis -G "php-src:master:https://github.com/php/php-src.git" + +# Download the latest code from the master branch of the swoole-src repository instead of PECL release version +bin/spc download --for-extensions=swoole -G "swoole:master:https://github.com/swoole/swoole-src.git" +``` + ## Command - doctor If you can run `bin/spc` normally but cannot compile static PHP or dependent libraries normally, diff --git a/docs/zh/guide/manual-build.md b/docs/zh/guide/manual-build.md index dd3d38ac..98f939a7 100644 --- a/docs/zh/guide/manual-build.md +++ b/docs/zh/guide/manual-build.md @@ -176,6 +176,17 @@ bin/spc download --all -U "php-src:https://downloads.php.net/~eric/php-8.3.0beta bin/spc download --all -U "curl:https://curl.se/download/curl-7.88.1.tar.gz" ``` +如果你下载的资源不是链接,而是一个 Git 仓库,你可以使用 `-G` 或 `--custom-git` 重写下载链接,让下载器强制使用你指定的 Git 仓库下载此 source 的包。 +使用方法为 `{source-name}:{branch}:{url}` 即可,可同时重写多个库的下载地址。在使用 `--for-extensions` 选项下载时同样可用。 + +```bash +# 例如:下载 master 分支的 php-src +bin/spc download --for-extensions=redis,phar -G "php-src:master:https://github.com/php/php-src.git" + +# 从 swoole-src 仓库下载 master 分支的最新代码,而不是发行版 +bin/spc download --for-extensions=swoole -G "swoole:master:https://github.com/swoole/swoole-src.git" +``` + ## 命令 doctor - 环境检查 如果你可以正常运行 `bin/spc` 但无法正常编译静态的 PHP 或依赖库,可以先运行 `bin/spc doctor` 检查系统自身是否缺少依赖。 diff --git a/src/SPC/command/DownloadCommand.php b/src/SPC/command/DownloadCommand.php index 9f217dbf..7419c60e 100644 --- a/src/SPC/command/DownloadCommand.php +++ b/src/SPC/command/DownloadCommand.php @@ -34,6 +34,7 @@ public function configure(): void $this->addOption('clean', null, null, 'Clean old download cache and source before fetch'); $this->addOption('all', 'A', null, 'Fetch all sources that static-php-cli needed'); $this->addOption('custom-url', 'U', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Specify custom source download url, e.g "php-src:https://downloads.php.net/~eric/php-8.3.0beta1.tar.gz"'); + $this->addOption('custom-git', 'G', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Specify custom source git url, e.g "php-src:master:https://github.com/php/php-src.git"'); $this->addOption('from-zip', 'Z', InputOption::VALUE_REQUIRED, 'Fetch from zip archive'); $this->addOption('for-extensions', 'e', InputOption::VALUE_REQUIRED, 'Fetch by extensions, e.g "openssl,mbstring"'); $this->addOption('for-libs', 'l', InputOption::VALUE_REQUIRED, 'Fetch by libraries, e.g "libcares,openssl,onig"'); @@ -179,6 +180,12 @@ public function handle(): int [$source_name, $url] = explode(':', $value, 2); $custom_urls[$source_name] = $url; } + // Process -G options + $custom_gits = []; + foreach ($this->input->getOption('custom-git') as $value) { + [$source_name, $branch, $url] = explode(':', $value, 3); + $custom_gits[$source_name] = [$branch, $url]; + } // If passing --prefer-pre-built option, we need to load pre-built library list from pre-built.json targeted releases if ($this->getOption('prefer-pre-built')) { @@ -211,6 +218,18 @@ public function handle(): int } logger()->info("Fetching source {$source} from custom url [{$ni}/{$cnt}]"); Downloader::downloadSource($source, $new_config, true); + } elseif (isset($custom_gits[$source])) { + $config = Config::getSource($source); + $new_config = [ + 'type' => 'git', + 'rev' => $custom_gits[$source][0], + 'url' => $custom_gits[$source][1], + ]; + if (isset($config['path'])) { + $new_config['path'] = $config['path']; + } + logger()->info("Fetching source {$source} from custom git [{$ni}/{$cnt}]"); + Downloader::downloadSource($source, $new_config, true); } else { $config = Config::getSource($source); // Prefer pre-built, we need to search pre-built library