]> git.lizzy.rs Git - rust.git/blob - src/ci/init_repo.sh
Clean up build-x86_64-fortanix-unknown-sgx-toolchain.sh
[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 # Duplicated in docker/dist-various-2/shared.sh
38 function fetch_github_commit_archive {
39     local module=$1
40     local cached="download-${module//\//-}.tar.gz"
41     retry sh -c "rm -f $cached && \
42         curl -f -sSL -o $cached $2"
43     mkdir $module
44     touch "$module/.git"
45     tar -C $module --strip-components=1 -xf $cached
46     rm $cached
47 }
48
49 included="src/llvm-project src/llvm-emscripten src/doc/book src/doc/rust-by-example"
50 modules="$(git config --file .gitmodules --get-regexp '\.path$' | cut -d' ' -f2)"
51 modules=($modules)
52 use_git=""
53 urls="$(git config --file .gitmodules --get-regexp '\.url$' | cut -d' ' -f2)"
54 urls=($urls)
55 for i in ${!modules[@]}; do
56     module=${modules[$i]}
57     if [[ " $included " = *" $module "* ]]; then
58         commit="$(git ls-tree HEAD $module | awk '{print $3}')"
59         git rm $module
60         url=${urls[$i]}
61         url=${url/\.git/}
62         fetch_github_commit_archive $module "$url/archive/$commit.tar.gz" &
63         continue
64     else
65         use_git="$use_git $module"
66     fi
67 done
68 retry sh -c "git submodule deinit -f $use_git && \
69     git submodule sync && \
70     git submodule update -j 16 --init --recursive $use_git"
71 wait
72 travis_fold end init_repo
73 travis_time_finish