summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntoine Musso <hashar@free.fr>2021-05-04 11:14:05 +0200
committerAntoine Musso <hashar@free.fr>2021-05-07 16:23:32 +0000
commitff89f79e83691d6d093a57187ecda094507600be (patch)
tree6a371107371a6ef5b85bbb6d8df7e386b3eb0935
parentdfbc9d03bc2c98729af947a294858f72a51046d3 (diff)
download_file: download to GERRIT_CACHE_HOME when set
When building a plugin as user `nobody`, download_file is unable to write the artifacts to the cache since the user does not have a home directory. For a CI build I also need to be set the cache directory to a predetermined value. Introduce the optional `GERRIT_CACHE_HOME` environment variable to support relocating downloaded artifacts. When the environment variable is not set, behavior is unchanged. Update documentation to mention support for `GERRIT_CACHE_HOME`. While at it, explain how to override the bazel repository and disk cache, would have same a bit of time the first time I had to tweak them. Change-Id: Ie4fac83928527e0e71b159b9500983234c2261ac
-rw-r--r--Documentation/dev-bazel.txt4
-rwxr-xr-xtools/download_file.py7
2 files changed, 9 insertions, 2 deletions
diff --git a/Documentation/dev-bazel.txt b/Documentation/dev-bazel.txt
index 782aba0678..2a8b7c17f0 100644
--- a/Documentation/dev-bazel.txt
+++ b/Documentation/dev-bazel.txt
@@ -495,6 +495,10 @@ To accelerate builds, several caches are activated per default:
* ~/.gerritcodereview/bazel-cache/repository
* ~/.gerritcodereview/bazel-cache/cas
+The `downloaded-artifacts` cache can be relocated by setting the
+`GERRIT_CACHE_HOME` environment variable. The other two can be adjusted with
+`bazel build` options `--repository_cache` and `--disk_cache` respectively.
+
Currently none of these caches have a maximum size limit. See
link:https://github.com/bazelbuild/bazel/issues/5139[this bazel issue] for
details. Users should watch the cache sizes and clean them manually if
diff --git a/tools/download_file.py b/tools/download_file.py
index f86fd3e034..936bcef32c 100755
--- a/tools/download_file.py
+++ b/tools/download_file.py
@@ -17,7 +17,7 @@ from __future__ import print_function
import argparse
from hashlib import sha1
-from os import link, makedirs, path, remove
+from os import environ, link, makedirs, path, remove
import shutil
from subprocess import check_call, CalledProcessError
from sys import stderr
@@ -25,7 +25,10 @@ from util import hash_file, resolve_url
from zipfile import ZipFile, BadZipfile, LargeZipFile
GERRIT_HOME = path.expanduser('~/.gerritcodereview')
-CACHE_DIR = path.join(GERRIT_HOME, 'bazel-cache', 'downloaded-artifacts')
+CACHE_DIR = environ.get(
+ 'GERRIT_CACHE_HOME',
+ path.join(GERRIT_HOME, 'bazel-cache', 'downloaded-artifacts'))
+
LOCAL_PROPERTIES = 'local.properties'