Improve 1k/fetch.ps1

This commit is contained in:
halx99 2024-03-24 12:55:10 +08:00
parent e303cf2ded
commit 968ab10a74
1 changed files with 7 additions and 13 deletions

View File

@ -45,7 +45,6 @@ function fetch_repo($url, $name, $dest, $ext) {
else { else {
$out = Join-Path $cache_dir "${name}$ext" $out = Join-Path $cache_dir "${name}$ext"
download_file $url $out download_file $url $out
try { try {
if ($ext -eq '.zip') { if ($ext -eq '.zip') {
Expand-Archive -Path $out -DestinationPath $prefix -Force Expand-Archive -Path $out -DestinationPath $prefix -Force
@ -55,10 +54,11 @@ function fetch_repo($url, $name, $dest, $ext) {
} }
} }
catch { catch {
throw "fetch.ps1: extract $out failed, $_" Remove-Item $out -Force
throw "fetch.ps1: extract $out failed, try again"
} }
if (!(Test-Path $dest)) { if (!(Test-Path $dest -PathType Container)) {
throw "fetch.ps1: the package name mismatch for $out" throw "fetch.ps1: the package name mismatch for $out"
} }
} }
@ -175,12 +175,8 @@ if (!$revision) {
} }
if ($is_git_repo) { if ($is_git_repo) {
$old_rev_hash = $(git -C $lib_src rev-parse HEAD) $old_rev_hash = $(git -C $lib_src rev-parse HEAD)
$tag_info = git -C $lib_src tag | Select-String $revision $tag_info = git -C $lib_src tag | Select-String $revision
if ($tag_info) { if ($tag_info) { $revision = ([array]$tag_info.Line)[0] }
$revision = ([array]$tag_info.Line)[0]
}
$cur_rev_hash = $(git -C $lib_src rev-parse --verify --quiet "$revision^{}") $cur_rev_hash = $(git -C $lib_src rev-parse --verify --quiet "$revision^{}")
if (!$cur_rev_hash) { if (!$cur_rev_hash) {
@ -193,9 +189,7 @@ if ($is_git_repo) {
if ($old_rev_hash -ne $cur_rev_hash) { if ($old_rev_hash -ne $cur_rev_hash) {
git -C $lib_src checkout $revision 1>$null 2>$null git -C $lib_src checkout $revision 1>$null 2>$null
$new_rev_hash = $(git -C $lib_src rev-parse HEAD) $new_rev_hash = $(git -C $lib_src rev-parse HEAD)
println "fetch.ps1: Checked out to $revision@$new_rev_hash" println "fetch.ps1: Checked out to $revision@$new_rev_hash"
if (!$is_rev_modified) { if (!$is_rev_modified) {
@ -209,7 +203,6 @@ if ($is_git_repo) {
if ($is_rev_modified) { if ($is_rev_modified) {
$sentry_content = "ver: $version" $sentry_content = "ver: $version"
if ($is_git_repo) { if ($is_git_repo) {
$branch_name = $(git -C $lib_src branch --show-current) $branch_name = $(git -C $lib_src branch --show-current)
if ($branch_name) { if ($branch_name) {
@ -225,7 +218,7 @@ if ($is_rev_modified) {
[System.IO.File]::WriteAllText($sentry, $sentry_content) [System.IO.File]::WriteAllText($sentry, $sentry_content)
git -C $lib_src add '_1kiss' if ($is_git_repo) { git -C $lib_src add '_1kiss' }
} }
# google gclient spec # google gclient spec
@ -233,7 +226,8 @@ if (Test-Path (Join-Path $lib_src '.gn') -PathType Leaf) {
# the repo use google gn build system manage deps and build # the repo use google gn build system manage deps and build
Push-Location $lib_src Push-Location $lib_src
# angle (A GLES native implementation by google) # angle (A GLES native implementation by google)
if (Test-Path 'scripts/bootstrap.py' -PathType Leaf) { if (Test-Path 'scripts/bootstrap.py' -PathType Leaf)
{
python scripts/bootstrap.py python scripts/bootstrap.py
} }
# darwin (A WebGPU native implementation by google) # darwin (A WebGPU native implementation by google)