Skip to content

Commit

Permalink
update bazelrc creation to use keyed cache
Browse files Browse the repository at this point in the history
  • Loading branch information
BenTheElder committed Feb 10, 2018
1 parent a1a9398 commit fb8f5ec
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions experiment/nursery/create_bazel_cache_rcs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
# Once this moves out of experiment/ we will create these files in the bazel
# images instead (!)
# TODO(bentheelder): verify that this works and move it into the images
CACHE_HOST="http://bazel-cache.default:8080"
CACHE_HOST="bazel-cache.default"
CACHE_PORT="8080"

# get the installed version of a debian package
package_to_version () {
Expand All @@ -37,26 +38,35 @@ command_to_version () {
package_to_version $PACKAGE
}

hash_toolchains () {
# if $CC is set bazel will use this to detect c/c++ toolchains, otherwise gcc
# https://blog.bazel.build/2016/03/31/autoconfiguration.html
CC="${CC:-gcc}"
CC_VERSION=$(command_to_version $CC)
# NOTE: IIRC some rules call python internally, this can't hurt
PYTHON_VERSION=$(command_to_version python)
# combine all tool versions into a hash
# NOTE(bentheelder): if we change the set of tools considered we should
# consider prepending the hash with a """schema version""" for completeness
TOOL_VERSIONS="CC:${CC_VERSION},PY:{PYTHON_VERSION}"
echo "${TOOL_VERSIONS}" | md5sum | cut -d" " -f1
}

make_bazel_rc () {
# this is the default for recent releases but we set it explicitly
# since this is the only hash our cache supports
echo "startup --host_jvm_args=-Dbazel.DigestFunction=sha256"
# use remote caching for all the things
echo "build --experimental_remote_spawn_cache"
# point it at our http cache ...
echo "build --remote_http_cache=${CACHE_HOST}"
# don't fail if the cache is unavailable
echo "build --remote_local_fallback"
# make sure the cache considers host toolchain versions
# NOTE: these assume nobody installs new host toolchains afterwards
# if $CC is set bazel will use this to detect c/c++ toolchains, otherwise gcc
# https://blog.bazel.build/2016/03/31/autoconfiguration.html
CC="${CC:-gcc}"
CC_VERSION=$(command_to_version $CC)
echo "build --action_env=CACHE_GCC_VERSION=${CC_VERSION}"
# NOTE: IIRC some rules call python internally, this can't hurt
PYTHON_VERSION=$(command_to_version python)
echo "build --action_env=CACHE_PYTHON_VERSION=${PYTHON_VERSION}"
# point it at our http cache ...
# NOTE our cache is versioned by the first path segment
# TODO(bentheelder): update the nursery deployment to something that supports this
WORKSPACE_NAME="${REPO_NAME:-$(basename "$PWD")}"
CACHE_ID="${WORKSPACE_NAME},$(hash_toolchains)"
CACHE_URL="http://${CACHE_HOST}:${CACHE_PORT}/${CACHE_ID}"
echo "build --remote_http_cache=${CACHE_URL}"
}

# https://docs.bazel.build/versions/master/user-manual.html#bazelrc
Expand Down

0 comments on commit fb8f5ec

Please sign in to comment.