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 # On the beta channel we'll be automatically calculating the prerelease version
40 # via the git history, so unshallow our shallow clone from CI.
41 if grep -q RUST_RELEASE_CHANNEL=beta src/ci/run.sh; then
42 git fetch origin --unshallow beta master
45 travis_fold start update_cache
48 # Update the cache (a pristine copy of the rust source master)
49 retry sh -c "rm -rf $cache_src_dir && mkdir -p $cache_src_dir && \
50 git clone --depth 1 https://github.com/rust-lang/rust.git $cache_src_dir"
51 if [ -d $cache_src_dir/src/llvm ]; then
52 (cd $cache_src_dir && git rm src/llvm)
54 if [ -d $cache_src_dir/src/llvm-emscripten ]; then
55 (cd $cache_src_dir && git rm src/llvm-emscripten)
57 retry sh -c "cd $cache_src_dir && \
58 git submodule deinit -f . && git submodule sync && git submodule update --init"
60 travis_fold end update_cache
63 travis_fold start update_submodules
66 # Update the submodules of the repo we're in, using the pristine repo as
67 # a cache for any object files
68 # No, `git submodule foreach` won't work:
69 # http://stackoverflow.com/questions/12641469/list-submodules-in-a-git-repository
70 modules="$(git config --file .gitmodules --get-regexp '\.path$' | cut -d' ' -f2)"
71 for module in $modules; do
72 if [ "$module" = src/llvm ] || [ "$module" = src/llvm-emscripten ]; then
73 commit="$(git ls-tree HEAD $module | awk '{print $3}')"
75 retry sh -c "rm -f $commit.tar.gz && \
76 curl -sSL -O https://github.com/rust-lang/llvm/archive/$commit.tar.gz"
77 tar -C src/ -xf "$commit.tar.gz"
79 mv "src/llvm-$commit" $module
82 if [ ! -e "$cache_src_dir/$module/.git" ]; then
83 echo "WARNING: $module not found in pristine repo"
84 retry sh -c "git submodule deinit -f $module && \
85 git submodule update --init --recursive $module"
88 retry sh -c "git submodule deinit -f $module && \
89 git submodule update --init --recursive --reference $cache_src_dir/$module $module"
92 travis_fold end update_submodules
95 travis_fold end init_repo