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.
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.
16 ci_dir=$(cd $(dirname $0) && pwd)
19 travis_fold start init_repo
24 cache_src_dir="$CACHE_DIR/src"
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"
31 if [ ! -d "$CACHE_DIR" ]; then
32 echo "Error: $CACHE_DIR does not exist or is not an absolute path"
39 travis_fold start update_cache
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"
49 travis_fold end update_cache
52 travis_fold start update_submodules
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}')"
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"
68 mv "src/llvm-$commit" src/llvm
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"
77 retry sh -c "git submodule deinit -f $module && \
78 git submodule update --init --recursive --reference $cache_src_dir/$module $module"
81 travis_fold end update_submodules
84 travis_fold end init_repo