From 7947913642a3a9746a0ffb9a5a5c1e523ae6e583 Mon Sep 17 00:00:00 2001 From: Benjamin Elder Date: Fri, 29 Jun 2018 16:57:48 -0700 Subject: [PATCH] fix shellcheck lints --- images/bootstrap/create_bazel_cache_rcs.sh | 30 ++++++++++++++-------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/images/bootstrap/create_bazel_cache_rcs.sh b/images/bootstrap/create_bazel_cache_rcs.sh index 94e02b2b36fc..2b09eaec518b 100755 --- a/images/bootstrap/create_bazel_cache_rcs.sh +++ b/images/bootstrap/create_bazel_cache_rcs.sh @@ -18,19 +18,21 @@ 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}" } @@ -38,15 +40,19 @@ 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 } @@ -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 } @@ -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