shallow submodules as well (grpc download goes from 2.9 gb to 900mb)

This commit is contained in:
henderkes 2025-09-21 19:59:11 +02:00
parent 8dfe722e14
commit fa87149631
2 changed files with 14 additions and 12 deletions

View File

@ -106,7 +106,7 @@ class DownloadCommand extends BaseCommand
} }
// retry // retry
$retry = intval($this->getOption('retry')); $retry = (int) $this->getOption('retry');
f_putenv('SPC_DOWNLOAD_RETRIES=' . $retry); f_putenv('SPC_DOWNLOAD_RETRIES=' . $retry);
// Use shallow-clone can reduce git resource download // Use shallow-clone can reduce git resource download
@ -265,7 +265,7 @@ class DownloadCommand extends BaseCommand
f_passthru((PHP_OS_FAMILY === 'Windows' ? 'rmdir /s /q ' : 'rm -rf ') . DOWNLOAD_PATH); f_passthru((PHP_OS_FAMILY === 'Windows' ? 'rmdir /s /q ' : 'rm -rf ') . DOWNLOAD_PATH);
} }
// unzip command check // unzip command check
if (PHP_OS_FAMILY !== 'Windows' && !$this->findCommand('unzip')) { if (PHP_OS_FAMILY !== 'Windows' && !self::findCommand('unzip')) {
$this->output->writeln('Missing unzip command, you need to install it first !'); $this->output->writeln('Missing unzip command, you need to install it first !');
$this->output->writeln('You can use "bin/spc doctor" command to check and install required tools'); $this->output->writeln('You can use "bin/spc doctor" command to check and install required tools');
return static::FAILURE; return static::FAILURE;

View File

@ -65,19 +65,19 @@ class Downloader
url: "https://api.github.com/repos/{$source['repo']}/{$type}", url: "https://api.github.com/repos/{$source['repo']}/{$type}",
hooks: [[CurlHook::class, 'setupGithubToken']], hooks: [[CurlHook::class, 'setupGithubToken']],
retries: self::getRetryAttempts() retries: self::getRetryAttempts()
), true); ), true, 512, JSON_THROW_ON_ERROR);
$url = null; $url = null;
for ($i = 0; $i < count($data); ++$i) { foreach ($data as $rel) {
if (($data[$i]['prerelease'] ?? false) === true && ($source['prefer-stable'] ?? false)) { if (($rel['prerelease'] ?? false) === true && ($source['prefer-stable'] ?? false)) {
continue; continue;
} }
if (!($source['match'] ?? null)) { if (!($source['match'] ?? null)) {
$url = $data[$i]['tarball_url'] ?? null; $url = $rel['tarball_url'] ?? null;
break; break;
} }
if (preg_match('|' . $source['match'] . '|', $data[$i]['tarball_url'])) { if (preg_match('|' . $source['match'] . '|', $rel['tarball_url'])) {
$url = $data[$i]['tarball_url']; $url = $rel['tarball_url'];
break; break;
} }
} }
@ -232,7 +232,8 @@ class Downloader
$quiet = !defined('DEBUG_MODE') ? '-q --quiet' : ''; $quiet = !defined('DEBUG_MODE') ? '-q --quiet' : '';
$git = SPC_GIT_EXEC; $git = SPC_GIT_EXEC;
$shallow = defined('GIT_SHALLOW_CLONE') ? '--depth 1 --single-branch' : ''; $shallow = defined('GIT_SHALLOW_CLONE') ? '--depth 1 --single-branch' : '';
$recursive = ($submodules === null) ? '--recursive' : ''; $recursive = ($submodules === null && defined('GIT_SHALLOW_CLONE')) ? '--recursive --shallow-submodules' : null;
$recursive ??= $submodules === null ? '--recursive' : '';
try { try {
self::registerCancelEvent(function () use ($download_path) { self::registerCancelEvent(function () use ($download_path) {
@ -243,8 +244,9 @@ class Downloader
}); });
f_passthru("{$git} clone {$quiet} --config core.autocrlf=false --branch \"{$branch}\" {$shallow} {$recursive} \"{$url}\" \"{$download_path}\""); f_passthru("{$git} clone {$quiet} --config core.autocrlf=false --branch \"{$branch}\" {$shallow} {$recursive} \"{$url}\" \"{$download_path}\"");
if ($submodules !== null) { if ($submodules !== null) {
$depth_flag = defined('GIT_SHALLOW_CLONE') ? '--depth 1' : '';
foreach ($submodules as $submodule) { foreach ($submodules as $submodule) {
f_passthru("cd \"{$download_path}\" && {$git} submodule update --init " . escapeshellarg($submodule)); f_passthru("cd \"{$download_path}\" && {$git} submodule update --init {$depth_flag} " . escapeshellarg($submodule));
} }
} }
} catch (SPCException $e) { } catch (SPCException $e) {
@ -399,7 +401,7 @@ class Downloader
* Download source * Download source
* *
* @param string $name source name * @param string $name source name
* @param null|array{ * @param null|array{
* type: string, * type: string,
* repo: ?string, * repo: ?string,
* url: ?string, * url: ?string,
@ -414,7 +416,7 @@ class Downloader
* path: ?string, * path: ?string,
* text: ?string * text: ?string
* } * }
* } $source source meta info: [type, path, rev, url, filename, regex, license] * } $source source meta info: [type, path, rev, url, filename, regex, license]
* @param bool $force Whether to force download (default: false) * @param bool $force Whether to force download (default: false)
* @param int $download_as Lock source type (default: SPC_LOCK_SOURCE) * @param int $download_as Lock source type (default: SPC_LOCK_SOURCE)
*/ */