summaryrefslogtreecommitdiffstats
path: root/src/ci/scripts/checkout-submodules.sh
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/ci/scripts/checkout-submodules.sh
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/ci/scripts/checkout-submodules.sh')
-rwxr-xr-xsrc/ci/scripts/checkout-submodules.sh68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/ci/scripts/checkout-submodules.sh b/src/ci/scripts/checkout-submodules.sh
new file mode 100755
index 000000000..f6cb8f8a6
--- /dev/null
+++ b/src/ci/scripts/checkout-submodules.sh
@@ -0,0 +1,68 @@
+#!/bin/bash
+# Check out all our submodules, but more quickly than using git by using one of
+# our custom scripts
+
+set -o errexit
+set -o pipefail
+set -o nounset
+
+if [ ! -d ".git" ]; then
+ echo "Error: This must run in the root of the repository"
+ exit 1
+fi
+
+ci_dir=$(cd $(dirname $0) && pwd)/..
+. "$ci_dir/shared.sh"
+
+# On the beta channel we'll be automatically calculating the prerelease version
+# via the git history, so unshallow our shallow clone from CI.
+if [ "$(releaseChannel)" = "beta" ]; then
+ git fetch origin --unshallow beta master
+fi
+
+function fetch_github_commit_archive {
+ local module=$1
+ local cached="download-${module//\//-}.tar.gz"
+ retry sh -c "rm -f $cached && \
+ curl -f -sSL -o $cached $2"
+ mkdir $module
+ touch "$module/.git"
+ # On Windows, the default behavior is to emulate symlinks by copying
+ # files. However, that ends up being order-dependent while extracting,
+ # which can cause a failure if the symlink comes first. This env var
+ # causes tar to use real symlinks instead, which are allowed to dangle.
+ export MSYS=winsymlinks:nativestrict
+ tar -C $module --strip-components=1 -xf $cached
+ rm $cached
+}
+
+included="src/llvm-project src/doc/book src/doc/rust-by-example"
+modules="$(git config --file .gitmodules --get-regexp '\.path$' | cut -d' ' -f2)"
+modules=($modules)
+use_git=""
+urls="$(git config --file .gitmodules --get-regexp '\.url$' | cut -d' ' -f2)"
+urls=($urls)
+# shellcheck disable=SC2068
+for i in ${!modules[@]}; do
+ module=${modules[$i]}
+ if [[ " $included " = *" $module "* ]]; then
+ commit="$(git ls-tree HEAD $module | awk '{print $3}')"
+ git rm $module
+ url=${urls[$i]}
+ url=${url/\.git/}
+ fetch_github_commit_archive $module "$url/archive/$commit.tar.gz" &
+ bg_pids[${i}]=$!
+ continue
+ else
+ use_git="$use_git $module"
+ fi
+done
+retry sh -c "git submodule deinit -f $use_git && \
+ git submodule sync && \
+ git submodule update -j 16 --init --recursive --depth 1 $use_git"
+STATUS=0
+for pid in ${bg_pids[*]}
+do
+ wait $pid || STATUS=1
+done
+exit ${STATUS}