Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build.sh for macOs users #883

Merged
merged 2 commits into from
Jun 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 7 additions & 21 deletions hack/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down