]> git.lizzy.rs Git - rust.git/blob - src/ci/init_repo.sh
Rollup merge of #61499 - varkor:issue-53457, r=oli-obk
[rust.git] / src / ci / init_repo.sh
1 #!/usr/bin/env bash
2
3 # FIXME(61301): we need to debug spurious failures with this on Windows on
4 # Azure, so let's print more information in the logs.
5 set -x
6
7 set -o errexit
8 set -o pipefail
9 set -o nounset
10
11 ci_dir=$(cd $(dirname $0) && pwd)
12 . "$ci_dir/shared.sh"
13
14 travis_fold start init_repo
15 travis_time_start
16
17 REPO_DIR="$1"
18 CACHE_DIR="$2"
19
20 cache_src_dir="$CACHE_DIR/src"
21
22 if [ ! -d "$REPO_DIR" -o ! -d "$REPO_DIR/.git" ]; then
23     echo "Error: $REPO_DIR does not exist or is not a git repo"
24     exit 1
25 fi
26 cd $REPO_DIR
27 if [ ! -d "$CACHE_DIR" ]; then
28     echo "Error: $CACHE_DIR does not exist or is not an absolute path"
29     exit 1
30 fi
31
32 rm -rf "$CACHE_DIR"
33 mkdir "$CACHE_DIR"
34
35 # On the beta channel we'll be automatically calculating the prerelease version
36 # via the git history, so unshallow our shallow clone from CI.
37 if grep -q RUST_RELEASE_CHANNEL=beta src/ci/run.sh; then
38   git fetch origin --unshallow beta master
39 fi
40
41 # Duplicated in docker/dist-various-2/shared.sh
42 function fetch_github_commit_archive {
43     local module=$1
44     local cached="download-${module//\//-}.tar.gz"
45     retry sh -c "rm -f $cached && \
46         curl -f -sSL -o $cached $2"
47     mkdir $module
48     touch "$module/.git"
49     tar -C $module --strip-components=1 -xf $cached
50     rm $cached
51 }
52
53 included="src/llvm-project src/llvm-emscripten src/doc/book src/doc/rust-by-example"
54 modules="$(git config --file .gitmodules --get-regexp '\.path$' | cut -d' ' -f2)"
55 modules=($modules)
56 use_git=""
57 urls="$(git config --file .gitmodules --get-regexp '\.url$' | cut -d' ' -f2)"
58 urls=($urls)
59 for i in ${!modules[@]}; do
60     module=${modules[$i]}
61     if [[ " $included " = *" $module "* ]]; then
62         commit="$(git ls-tree HEAD $module | awk '{print $3}')"
63         git rm $module
64         url=${urls[$i]}
65         url=${url/\.git/}
66         fetch_github_commit_archive $module "$url/archive/$commit.tar.gz" &
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 wait
76 travis_fold end init_repo
77 travis_time_finish