]> git.lizzy.rs Git - rust.git/blob - src/ci/init_repo.sh
Rollup merge of #57908 - petrochenkov:errepice, r=estebank
[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 travis_fold start init_repo
11 travis_time_start
12
13 REPO_DIR="$1"
14 CACHE_DIR="$2"
15
16 cache_src_dir="$CACHE_DIR/src"
17
18 if [ ! -d "$REPO_DIR" -o ! -d "$REPO_DIR/.git" ]; then
19     echo "Error: $REPO_DIR does not exist or is not a git repo"
20     exit 1
21 fi
22 cd $REPO_DIR
23 if [ ! -d "$CACHE_DIR" ]; then
24     echo "Error: $CACHE_DIR does not exist or is not an absolute path"
25     exit 1
26 fi
27
28 rm -rf "$CACHE_DIR"
29 mkdir "$CACHE_DIR"
30
31 # On the beta channel we'll be automatically calculating the prerelease version
32 # via the git history, so unshallow our shallow clone from CI.
33 if grep -q RUST_RELEASE_CHANNEL=beta src/ci/run.sh; then
34   git fetch origin --unshallow beta master
35 fi
36
37 function fetch_submodule {
38     local module=$1
39     local cached="download-${module//\//-}.tar.gz"
40     retry sh -c "rm -f $cached && \
41         curl -sSL -o $cached $2"
42     mkdir $module
43     touch "$module/.git"
44     tar -C $module --strip-components=1 -xf $cached
45     rm $cached
46 }
47
48 included="src/llvm-project src/llvm-emscripten src/doc/book src/doc/rust-by-example"
49 modules="$(git config --file .gitmodules --get-regexp '\.path$' | cut -d' ' -f2)"
50 modules=($modules)
51 use_git=""
52 urls="$(git config --file .gitmodules --get-regexp '\.url$' | cut -d' ' -f2)"
53 urls=($urls)
54 for i in ${!modules[@]}; do
55     module=${modules[$i]}
56     if [[ " $included " = *" $module "* ]]; then
57         commit="$(git ls-tree HEAD $module | awk '{print $3}')"
58         git rm $module
59         url=${urls[$i]}
60         url=${url/\.git/}
61         fetch_submodule $module "$url/archive/$commit.tar.gz" &
62         continue
63     else
64         use_git="$use_git $module"
65     fi
66 done
67 retry sh -c "git submodule deinit -f $use_git && \
68     git submodule sync && \
69     git submodule update -j 16 --init --recursive $use_git"
70 wait
71 travis_fold end init_repo
72 travis_time_finish