From 77b53e2a8fe3fae123fad8c0fae7656e7a29d726 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20Hu=C3=9F?= Date: Tue, 9 Jun 2020 15:42:32 +0200 Subject: [PATCH] Fix build.sh for macOs users (#883) * Fix build.sh for macOs users Fixes #882 * cleanup tempdir after installing --- hack/build.sh | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/hack/build.sh b/hack/build.sh index 7dc3e43d0c..b61e4c9cfd 100755 --- a/hack/build.sh +++ b/hack/build.sh @@ -16,9 +16,6 @@ set -o pipefail -[[ ! -v REPO_ROOT_DIR ]] && REPO_ROOT_DIR="$(git rev-parse --show-toplevel)" -readonly REPO_ROOT_DIR - source_dirs="cmd pkg test lib" # Store for later @@ -113,27 +110,16 @@ go_fmt() { find $(echo $source_dirs) -name "*.go" -print0 | xargs -0 gofmt -s -w } -# Run a go tool, installing it first if necessary. -# Parameters: $1 - tool package/dir for go get/install. -# $2 - tool to run. -# $3..$n - parameters passed to the tool. +# Run a go tool, get it first if necessary. run_go_tool() { local tool=$2 local install_failed=0 - if [[ -z "$(which ${tool})" ]]; then - local action=get - [[ $1 =~ ^[\./].* ]] && action=install - # Avoid running `go get` from root dir of the repository, as it can change go.sum and go.mod files. - # See discussions in https://github.com/golang/go/issues/27643. - if [[ ${action} == "get" && $(pwd) == "${REPO_ROOT_DIR}" ]]; then - local temp_dir="$(mktemp -d)" - # Swallow the output as we are returning the stdout in the end. - pushd "${temp_dir}" > /dev/null 2>&1 - GOFLAGS="" go ${action} "$1" || install_failed=1 - popd > /dev/null 2>&1 - else - GOFLAGS="" go ${action} "$1" || install_failed=1 - fi + if [ -z "$(which ${tool})" ]; then + local temp_dir="$(mktemp -d)" + pushd "${temp_dir}" > /dev/null 2>&1 + GOFLAGS="" go get "$1" || install_failed=1 + popd > /dev/null 2>&1 + rm -rf "${temp_dir}" fi (( install_failed )) && return ${install_failed} shift 2