travis-ci: don't repeat the path of the cache directory

Some of our 'ci/*' scripts repeat the name or full path of the Travis CI cache directory, and the following patches will add new places using that path. Use a variable to refer to the path of the cache directory instead, so it's hard-coded only in a single place. Pay extra attention to the 32 bit Linux build: it runs in a Docker container, so pass the path of the cache directory from the host to the container in an environment variable. Note that an environment variable passed this way is exported inside the container, therefore its value is directly available in the 'su' snippet even though that snippet is single quoted. Furthermore, use the variable in the container only if it's been assigned a non-empty value, to prevent errors when someone is running or debugging the Docker build locally, because in that case the variable won't be set as there won't be any Travis CI cache. Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

SZEDER Gábor committed Jan 29, 2018 at 18:17 UTC b2cbaa091ca676478d131afd40ca4717cc5eed39
4 files changed +11 -6
ci/lib-travisci.sh
+4 -3
@@ -21,8 +21,6 @@ skip_branch_tip_with_tag () {
21 fi
22 }
23
24 -good_trees_file="$HOME/travis-cache/good-trees"
25 -
24 # Save some info about the current commit's tree, so we can skip the build
25 # job if we encounter the same tree again and can provide a useful info
26 # message.
@@ -83,7 +81,10 @@ check_unignored_build_artifacts ()
81 # and installing dependencies.
82 set -ex
83
86 -mkdir -p "$HOME/travis-cache"
84 +cache_dir="$HOME/travis-cache"
85 +good_trees_file="$cache_dir/good-trees"
86 +
87 +mkdir -p "$cache_dir"
88
89 skip_branch_tip_with_tag
90 skip_good_tree
ci/run-linux32-build.sh
+1 -1
@@ -28,7 +28,7 @@ test -z $HOST_UID || (CI_USER="ci" && useradd -u $HOST_UID $CI_USER)
28 linux32 --32bit i386 su -m -l $CI_USER -c '
29 set -ex
30 cd /usr/src/git
31 - ln -s /tmp/travis-cache/.prove t/.prove
31 + test -n "$cache_dir" && ln -s "$cache_dir/.prove" t/.prove
32 make --jobs=2
33 make --quiet test
34 '
ci/run-linux32-docker.sh
+4 -1
@@ -11,6 +11,8 @@ docker pull daald/ubuntu32:xenial
11 # $ docker run -itv "${PWD}:/usr/src/git" --entrypoint /bin/bash daald/ubuntu32:xenial
12 # root@container:/# /usr/src/git/ci/run-linux32-build.sh
13
14 +container_cache_dir=/tmp/travis-cache
15 +
16 docker run \
17 --interactive \
18 --env DEVELOPER \
@@ -18,8 +20,9 @@ docker run \
20 --env GIT_PROVE_OPTS \
21 --env GIT_TEST_OPTS \
22 --env GIT_TEST_CLONE_2GB \
23 + --env cache_dir="$container_cache_dir" \
24 --volume "${PWD}:/usr/src/git" \
22 - --volume "${HOME}/travis-cache:/tmp/travis-cache" \
25 + --volume "$cache_dir:$container_cache_dir" \
26 daald/ubuntu32:xenial \
27 /usr/src/git/ci/run-linux32-build.sh $(id -u $USER)
28
ci/run-tests.sh
+2 -1
@@ -5,7 +5,8 @@
5
6 . ${0%/*}/lib-travisci.sh
7
8 -ln -s $HOME/travis-cache/.prove t/.prove
8 +ln -s "$cache_dir/.prove" t/.prove
9 +
10 make --quiet test
11
12 check_unignored_build_artifacts