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