Skip to content

Commit

Permalink
fix shellcheck lints
Browse files Browse the repository at this point in the history
  • Loading branch information
BenTheElder committed Jun 29, 2018
1 parent d6cdefa commit 7947913
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions images/bootstrap/create_bazel_cache_rcs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,41 @@ CACHE_PORT="8080"

# get the installed version of a debian package
package_to_version () {
dpkg-query --showformat='${Version}' --show $1
dpkg-query --showformat='${Version}' --show "$1"
}

# look up a binary with which and return the debian package it belongs to
command_to_package () {
local binary_path=$(readlink -f $(which $1))
local binary_path
binary_path=$(readlink -f "$(which "$1")")
# `dpkg -S $package` spits out lines with the format: "package: file"
dpkg -S $1 | grep "${binary_path}" | cut -d':' -f1
dpkg -S "$1" | grep "${binary_path}" | cut -d':' -f1
}

# get the installed package version relating to a binary
command_to_version () {
local package=$(command_to_package $1)
local package
package=$(command_to_package "$1")
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
local cc="${CC:-gcc}"
local cc_version=$(command_to_version $cc)
local cc_version
cc_version=$(command_to_version "$cc")
# NOTE: IIRC some rules call python internally, this can't hurt
local python_version=$(command_to_version python)
local python_version
python_version=$(command_to_version python)
# the rpm packaging rules use rpmbuild
local rpmbuild_version=$(command_to_version rpmbuild)
local rpmbuild_version
rpmbuild_version=$(command_to_version rpmbuild)
# 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
local tool_versions="CC:${cc_version},PY:${python_version},RPM:${rpmbuild_version}"
local tool_versions
tool_versions="CC:${cc_version},PY:${python_version},RPM:${rpmbuild_version}"
echo "${tool_versions}" | md5sum | cut -d" " -f1
}

Expand All @@ -55,7 +61,7 @@ get_workspace () {
if [[ -n "${REPO_NAME}" ]] && [[ -n "${REPO_OWNER}" ]]; then
echo "${REPO_OWNER}/${REPO_NAME}"
else
echo "$(basename $(dirname $PWD))/$(basename $PWD)"
echo "$(basename "$(dirname "$PWD")")/$(basename "$PWD")"
fi
}

Expand All @@ -70,8 +76,10 @@ make_bazel_rc () {
# point bazel at our http cache ...
# NOTE our caches are versioned by all path segments up until the last two
# IE PUT /foo/bar/baz/cas/asdf -> is in cache "/foo/bar/baz"
local cache_id="$(get_workspace),$(hash_toolchains)"
local cache_url="http://${CACHE_HOST}:${CACHE_PORT}/${cache_id}"
local cache_id
cache_id="$(get_workspace),$(hash_toolchains)"
local cache_url
cache_url="http://${CACHE_HOST}:${CACHE_PORT}/${cache_id}"
echo "build --remote_http_cache=${cache_url}"
# specifically for bazel 0.15.0 we want to set this flag
# our docker image now sets BAZEL_VERSION with the bazel version as installed
Expand Down

0 comments on commit 7947913

Please sign in to comment.