]> git.lizzy.rs Git - rust.git/blob - src/ci/init_repo.sh
Rollup merge of #97764 - RalfJung:strict, r=dtolnay
[rust.git] / src / ci / init_repo.sh
1 #!/usr/bin/env bash
2
3 set -o errexit
4 set -o pipefail
5 set -o nounset
6
7 ci_dir=$(cd $(dirname $0) && pwd)
8 . "$ci_dir/shared.sh"
9
10 REPO_DIR="$1"
11 CACHE_DIR="$2"
12
13 cache_src_dir="$CACHE_DIR/src"
14
15 if [ ! -d "$REPO_DIR" -o ! -d "$REPO_DIR/.git" ]; then
16     echo "Error: $REPO_DIR does not exist or is not a git repo"
17     exit 1
18 fi
19 cd $REPO_DIR
20 if [ ! -d "$CACHE_DIR" ]; then
21     echo "Error: $CACHE_DIR does not exist or is not an absolute path"
22     exit 1
23 fi
24
25 rm -rf "$CACHE_DIR"
26 mkdir "$CACHE_DIR"
27
28 # On the beta channel we'll be automatically calculating the prerelease version
29 # via the git history, so unshallow our shallow clone from CI.
30 if [ "$(releaseChannel)" = "beta" ]; then
31   git fetch origin --unshallow beta master
32 fi
33
34 # Duplicated in docker/dist-various-2/shared.sh
35 function fetch_github_commit_archive {
36     local module=$1
37     local cached="download-${module//\//-}.tar.gz"
38     retry sh -c "rm -f $cached && \
39         curl -f -sSL -o $cached $2"
40     mkdir $module
41     touch "$module/.git"
42     # On Windows, the default behavior is to emulate symlinks by copying
43     # files. However, that ends up being order-dependent while extracting,
44     # which can cause a failure if the symlink comes first. This env var
45     # causes tar to use real symlinks instead, which are allowed to dangle.
46     export MSYS=winsymlinks:nativestrict
47     tar -C $module --strip-components=1 -xf $cached
48     rm $cached
49 }
50
51 included="src/llvm-project src/doc/book src/doc/rust-by-example"
52 modules="$(git config --file .gitmodules --get-regexp '\.path$' | cut -d' ' -f2)"
53 modules=($modules)
54 use_git=""
55 urls="$(git config --file .gitmodules --get-regexp '\.url$' | cut -d' ' -f2)"
56 urls=($urls)
57 # shellcheck disable=SC2068
58 for i in ${!modules[@]}; do
59     module=${modules[$i]}
60     if [[ " $included " = *" $module "* ]]; then
61         commit="$(git ls-tree HEAD $module | awk '{print $3}')"
62         git rm $module
63         url=${urls[$i]}
64         url=${url/\.git/}
65         fetch_github_commit_archive $module "$url/archive/$commit.tar.gz" &
66         bg_pids[${i}]=$!
67         continue
68     else
69         use_git="$use_git $module"
70     fi
71 done
72 retry sh -c "git submodule deinit -f $use_git && \
73     git submodule sync && \
74     git submodule update -j 16 --init --recursive $use_git"
75 STATUS=0
76 for pid in ${bg_pids[*]}
77 do
78     wait $pid || STATUS=1
79 done
80 exit ${STATUS}