Skip to content

Commit a9dc8ac

Browse files
authored
Rollup merge of rust-lang#40780 - aidanhs:aphs-cache-git-modules, r=alexcrichton
Attempt to cache git modules Partial resolution of rust-lang#40772, appveyor remains to be done once travis looks like it's working ok. The approach in this PR is based on the `--reference` flag to `git-clone`/`git-submodule --update` and is a compromise based on the current limitations of the tools we're using. The ideal would be: 1. have a cached pristine copy of rust-lang/rust master in `$HOME/rustsrc` with all submodules initialised 2. clone the PR branch with `git clone --recurse-submodules --reference $HOME/rustsrc [email protected]:rust-lang/rust.git` This would (in the nonexistent ideal world) use the pristine copy as an object cache for the top level repo and all submodules, transferring over the network only the changes on the branch. Unfortunately, a) there is no way to manually control the initial clone with travis and b) even if there was, cloned submodules don't use the submodules of the reference as an object cache. So the steps we end up with are: 1. have a cached pristine copy of rust-lang/rust master in `$HOME/rustsrc` with all submodules initialised 2. have a cloned PR branch 3. extract the path of each submodule, and explicitly `git submodule update --init --reference $HOME/rustsrc/$module $module` (i.e. point directly to the location of the pristine submodule repo) for each one I've also taken some care to make this forward compatible, both for adding and removing submodules. r? @alexcrichton
2 parents e1cec5d + 96e174f commit a9dc8ac

File tree

5 files changed

+97
-10
lines changed

5 files changed

+97
-10
lines changed

.travis.yml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,14 @@ before_script:
133133
script:
134134
- >
135135
if [ "$ALLOW_PR" = "" ] && [ "$TRAVIS_BRANCH" != "auto" ]; then
136-
echo skipping, not a full build;
137-
elif [ "$TRAVIS_OS_NAME" = "osx" ]; then
138-
travis_retry stamp sh -c 'git submodule deinit -f . && git submodule update --init' &&
139-
stamp src/ci/run.sh;
136+
echo skipping, not a full build
140137
else
141-
travis_retry stamp sh -c 'git submodule deinit -f . && git submodule update --init' &&
142-
stamp src/ci/docker/run.sh $IMAGE;
138+
stamp src/ci/init_repo.sh . "$HOME/rustsrc" &&
139+
if [ "$TRAVIS_OS_NAME" = "osx" ]; then
140+
stamp src/ci/run.sh;
141+
else
142+
stamp src/ci/docker/run.sh $IMAGE;
143+
fi
143144
fi
144145
145146
after_success:
@@ -169,20 +170,29 @@ after_failure:
169170
- dmesg | grep -i kill
170171

171172
# Save tagged docker images we created and load them if they're available
173+
# Travis saves caches whether the build failed or not, nuke rustsrc if
174+
# the failure was while updating it (as it may be in an bad state)
175+
# https://github.com/travis-ci/travis-ci/issues/4472
172176
before_cache:
173177
- docker history -q rust-ci |
174178
grep -v missing |
175179
xargs docker save |
176180
gzip > $HOME/docker/rust-ci.tar.gz
181+
- if [ ! -f $HOME/rustsrc/cache_valid1 ]; then
182+
echo "WARNING rustsrc cache was invalid when saving";
183+
rm -rf $HOME/rustsrc && mkdir $HOME/rustsrc;
184+
fi
177185
before_install:
178186
- zcat $HOME/docker/rust-ci.tar.gz | docker load || true
187+
- mkdir -p $HOME/rustsrc
179188

180189
notifications:
181190
email: false
182191

183192
cache:
184193
directories:
185194
- $HOME/docker
195+
- $HOME/rustsrc
186196

187197
before_deploy:
188198
- mkdir -p deploy/$TRAVIS_COMMIT

appveyor.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ install:
141141
- set SCCACHE_ERROR_LOG=%CD%/sccache.log
142142

143143
test_script:
144-
- appveyor-retry sh -c 'git submodule deinit -f . && git submodule update --init'
144+
- mkdir C:\cache\rustsrc
145+
- sh src/ci/init_repo.sh . /c/cache/rustsrc
145146
- set SRC=.
146147
- set NO_CCACHE=1
147148
- sh src/ci/run.sh
@@ -150,6 +151,7 @@ on_failure:
150151
- cat %CD%/sccache.log
151152

152153
cache:
154+
- C:\cache\rustsrc
153155
- "build/i686-pc-windows-msvc/llvm -> src/rustllvm/llvm-rebuild-trigger"
154156
- "build/x86_64-pc-windows-msvc/llvm -> src/rustllvm/llvm-rebuild-trigger"
155157
- "i686-pc-windows-msvc/llvm -> src/rustllvm/llvm-rebuild-trigger"

src/ci/docker/run.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ exec docker \
5757
--env DEPLOY_ALT=$DEPLOY_ALT \
5858
--env LOCAL_USER_ID=`id -u` \
5959
--volume "$HOME/.cargo:/cargo" \
60+
--volume "$HOME/rustsrc:$HOME/rustsrc" \
6061
--privileged \
6162
--rm \
6263
rust-ci \

src/ci/init_repo.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/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+
set -o xtrace
17+
18+
ci_dir=$(cd $(dirname $0) && pwd)
19+
. "$ci_dir/shared.sh"
20+
21+
REPO_DIR="$1"
22+
CACHE_DIR="$2"
23+
24+
cache_src_dir="$CACHE_DIR/src"
25+
# If the layout of the cache directory changes, bump the number here
26+
# (and anywhere else this file is referenced) so the cache is wiped
27+
cache_valid_file="$CACHE_DIR/cache_valid1"
28+
29+
if [ ! -d "$REPO_DIR" -o ! -d "$REPO_DIR/.git" ]; then
30+
echo "Error: $REPO_DIR does not exist or is not a git repo"
31+
exit 1
32+
fi
33+
cd $REPO_DIR
34+
if [ ! -d "$CACHE_DIR" ]; then
35+
echo "Error: $CACHE_DIR does not exist or is not an absolute path"
36+
exit 1
37+
fi
38+
39+
# Wipe the cache if it's not valid, or mark it as invalid while we update it
40+
if [ ! -f "$cache_valid_file" ]; then
41+
rm -rf "$CACHE_DIR" && mkdir "$CACHE_DIR"
42+
else
43+
rm "$cache_valid_file"
44+
fi
45+
46+
# Update the cache (a pristine copy of the rust source master)
47+
if [ ! -d "$cache_src_dir/.git" ]; then
48+
retry sh -c "rm -rf $cache_src_dir && mkdir -p $cache_src_dir && \
49+
git clone https://github.com/rust-lang/rust.git $cache_src_dir"
50+
fi
51+
retry sh -c "cd $cache_src_dir && git reset --hard && git pull"
52+
retry sh -c "cd $cache_src_dir && \
53+
git submodule deinit -f . && git submodule sync && git submodule update --init"
54+
55+
# Cache was updated without errors, mark it as valid
56+
touch "$cache_valid_file"
57+
58+
# Update the submodules of the repo we're in, using the pristine repo as
59+
# a cache for any object files
60+
# No, `git submodule foreach` won't work:
61+
# http://stackoverflow.com/questions/12641469/list-submodules-in-a-git-repository
62+
modules="$(git config --file .gitmodules --get-regexp '\.path$' | cut -d' ' -f2)"
63+
for module in $modules; do
64+
if [ ! -d "$cache_src_dir/$module" ]; then
65+
echo "WARNING: $module not found in pristine repo"
66+
retry sh -c "git submodule deinit -f $module && git submodule update --init $module"
67+
continue
68+
fi
69+
retry sh -c "git submodule deinit -f $module && \
70+
git submodule update --init --reference $cache_src_dir/$module $module"
71+
done

src/ci/shared.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/bin/false
22
# Copyright 2016 The Rust Project Developers. See the COPYRIGHT
33
# file at the top-level directory of this distribution and at
44
# http://rust-lang.org/COPYRIGHT.
@@ -9,13 +9,16 @@
99
# option. This file may not be copied, modified, or distributed
1010
# except according to those terms.
1111

12+
# This file is intended to be sourced with `. shared.sh` or
13+
# `source shared.sh`, hence the invalid shebang and not being
14+
# marked as an executable file in git.
15+
1216
# See http://unix.stackexchange.com/questions/82598
1317
function retry {
18+
echo "Attempting with retry:" "$@"
1419
local n=1
1520
local max=5
16-
local delay=15
1721
while true; do
18-
echo "Attempting:" "$@"
1922
"$@" && break || {
2023
if [[ $n -lt $max ]]; then
2124
((n++))

0 commit comments

Comments
 (0)