]> git.lizzy.rs Git - rust.git/blob - src/ci/init_repo.sh
e073a3d99c157dc765293c8ca770a63a34a3ec33
[rust.git] / src / ci / init_repo.sh
1 #!/usr/bin/env bash
2 # Copyright 2016 The Rust Project Developers. See the COPYRIGHT
3 # file at the top-level directory of this distribution and at
4 # http://rust-lang.org/COPYRIGHT.
5 #
6 # Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
7 # http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
8 # <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
9 # option. This file may not be copied, modified, or distributed
10 # except according to those terms.
11
12 set -o errexit
13 set -o pipefail
14 set -o nounset
15
16 ci_dir=$(cd $(dirname $0) && pwd)
17 . "$ci_dir/shared.sh"
18
19 travis_fold start init_repo
20
21 REPO_DIR="$1"
22 CACHE_DIR="$2"
23
24 cache_src_dir="$CACHE_DIR/src"
25
26 if [ ! -d "$REPO_DIR" -o ! -d "$REPO_DIR/.git" ]; then
27     echo "Error: $REPO_DIR does not exist or is not a git repo"
28     exit 1
29 fi
30 cd $REPO_DIR
31 if [ ! -d "$CACHE_DIR" ]; then
32     echo "Error: $CACHE_DIR does not exist or is not an absolute path"
33     exit 1
34 fi
35
36 rm -rf "$CACHE_DIR"
37 mkdir "$CACHE_DIR"
38
39 travis_fold start update_cache
40 travis_time_start
41
42 # Update the cache (a pristine copy of the rust source master)
43 retry sh -c "rm -rf $cache_src_dir && mkdir -p $cache_src_dir && \
44     git clone --depth 1 https://github.com/rust-lang/rust.git $cache_src_dir"
45 (cd $cache_src_dir && git rm src/llvm)
46 retry sh -c "cd $cache_src_dir && \
47     git submodule deinit -f . && git submodule sync && git submodule update --init"
48
49 travis_fold end update_cache
50 travis_time_finish
51
52 travis_fold start update_submodules
53 travis_time_start
54
55 # Update the submodules of the repo we're in, using the pristine repo as
56 # a cache for any object files
57 # No, `git submodule foreach` won't work:
58 # http://stackoverflow.com/questions/12641469/list-submodules-in-a-git-repository
59 modules="$(git config --file .gitmodules --get-regexp '\.path$' | cut -d' ' -f2)"
60 for module in $modules; do
61     if [ "$module" = src/llvm ]; then
62         commit="$(git ls-tree HEAD src/llvm | awk '{print $3}')"
63         git rm src/llvm
64         retry sh -c "rm -f $commit.tar.gz && \
65             curl -sSL -O https://github.com/rust-lang/llvm/archive/$commit.tar.gz"
66         tar -C src/ -xf "$commit.tar.gz"
67         rm "$commit.tar.gz"
68         mv "src/llvm-$commit" src/llvm
69         continue
70     fi
71     if [ ! -e "$cache_src_dir/$module/.git" ]; then
72         echo "WARNING: $module not found in pristine repo"
73         retry sh -c "git submodule deinit -f $module && \
74             git submodule update --init --recursive $module"
75         continue
76     fi
77     retry sh -c "git submodule deinit -f $module && \
78         git submodule update --init --recursive --reference $cache_src_dir/$module $module"
79 done
80
81 travis_fold end update_submodules
82 travis_time_finish
83
84 travis_fold end init_repo