mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-17 20:34:51 +08:00
update downloader, make download thing cacheable
This commit is contained in:
parent
880242ed93
commit
b87a633496
@ -17,7 +17,7 @@ Compile A Statically Linked PHP With Swoole and other Extensions. [English READM
|
||||
- Linux
|
||||
- 支持架构: aarch64, amd64
|
||||
- 支持发行版: alpine, ubuntu, centos
|
||||
- 依赖工具: (TODO)
|
||||
- 依赖工具: make, bison, flex, pkg-config, git, autoconf, automake, tar, unzip, gzip, bzip2, cmake
|
||||
- macOS
|
||||
- 支持架构: arm64, x86_64
|
||||
- 依赖工具: make, bison, flex, pkg-config, git, autoconf, automake, tar, unzip, xz, gzip, bzip2, cmake
|
||||
|
||||
@ -142,6 +142,7 @@ class FetchSourceCommand extends BaseCommand
|
||||
f_mkdir(DOWNLOAD_PATH);
|
||||
|
||||
// 下载 PHP
|
||||
logger()->info('Fetching PHP source');
|
||||
Downloader::fetchSource('php-src', Downloader::getLatestPHPInfo($ver));
|
||||
|
||||
// 下载别的依赖资源
|
||||
|
||||
@ -182,6 +182,41 @@ class Downloader
|
||||
}
|
||||
}
|
||||
|
||||
public static function downloadGit(string $name, string $url, string $branch, ?string $path = null): void
|
||||
{
|
||||
if ($path) {
|
||||
$path = SOURCE_PATH . "/{$path}";
|
||||
} else {
|
||||
$path = DOWNLOAD_PATH . "/{$name}";
|
||||
}
|
||||
$download_path = DOWNLOAD_PATH . "/{$name}";
|
||||
if (file_exists($download_path)) {
|
||||
logger()->notice("{$name} git source already fetched");
|
||||
} else {
|
||||
logger()->debug("cloning {$name} source");
|
||||
$check = !defined('DEBUG_MODE') ? ' -q' : '';
|
||||
f_passthru(
|
||||
'git clone' . $check .
|
||||
' --config core.autocrlf=false ' .
|
||||
"--branch \"{$branch}\" " . (defined('GIT_SHALLOW_CLONE') ? '--depth 1 --single-branch' : '') . " --recursive \"{$url}\" \"{$download_path}\""
|
||||
);
|
||||
}
|
||||
// 复制目录过去
|
||||
if ($path !== $download_path) {
|
||||
$dst_path = FileSystem::convertPath($path);
|
||||
$src_path = FileSystem::convertPath($download_path);
|
||||
switch (PHP_OS_FAMILY) {
|
||||
case 'Windows':
|
||||
f_passthru('xcopy "' . $src_path . '" "' . $dst_path . '" /s/e/v/y/i');
|
||||
break;
|
||||
case 'Linux':
|
||||
case 'Darwin':
|
||||
f_passthru('cp -r "' . $src_path . '" "' . $dst_path . '"');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 拉取资源
|
||||
*
|
||||
@ -226,22 +261,7 @@ class Downloader
|
||||
self::downloadUrl($name, $url, $filename, $source['path'] ?? null);
|
||||
break;
|
||||
case 'git': // 通过拉回 Git 仓库的形式拉取
|
||||
if ($source['path'] ?? null) {
|
||||
$path = SOURCE_PATH . "/{$source['path']}";
|
||||
} else {
|
||||
$path = SOURCE_PATH . "/{$name}";
|
||||
}
|
||||
if (file_exists($path)) {
|
||||
logger()->notice("{$name} source already exists");
|
||||
break;
|
||||
}
|
||||
logger()->debug("cloning {$name} source");
|
||||
$check = !defined('DEBUG_MODE') ? ' -q' : '';
|
||||
f_passthru(
|
||||
'git clone' . $check .
|
||||
' --config core.autocrlf=false ' .
|
||||
"--branch \"{$source['rev']}\" " . (defined('GIT_SHALLOW_CLONE') ? '--depth 1 --single-branch' : '') . " --recursive \"{$source['url']}\" \"{$path}\""
|
||||
);
|
||||
self::downloadGit($name, $source['url'], $source['rev'], $source['path'] ?? null);
|
||||
break;
|
||||
default:
|
||||
throw new DownloaderException('unknown source type: ' . $source['type']);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user