Skip to content

Commit 0609953

Browse files
committed
make tools: support no GOPATH, ignore typos
use `go env GOPATH` to pickup the default value of GOPATH for environments that don't have GOPATH explicitly set give a more informative error message if, totally hypothetically, someone were to type `compile-tools WHAT=kubectl`
1 parent a1c2b30 commit 0609953

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ test-go-integration: ## Runs Golang integration tests
8686

8787
.PHONY: tools
8888

89-
KEP_TOOLS ?=
89+
WHAT ?= kepctl kepify
9090

91-
tools: ## Compiles a set of KEP tools, specified by $KEP_TOOLS
92-
./compile-tools $(KEP_TOOLS)
91+
tools: ## Installs all KEP tools, can select via e.g. WHAT=kepctl
92+
./compile-tools $(WHAT)
9393

9494
##@ Dependencies
9595

compile-tools

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ setup_env() {
2929

3030
if [[ -z "${TOOL_BIN:-}" ]]; then
3131
if [ -n "${GOBIN:-}" ]; then
32-
export TOOL_BIN="${GOBIN}"
32+
TOOL_BIN="${GOBIN}"
3333
else
34-
export TOOL_BIN="${GOPATH}/bin"
34+
TOOL_BIN="$(go env GOPATH)/bin"
3535
fi
36+
export TOOL_BIN
3637
fi
3738

3839
export PATH="${PATH}:${TOOL_BIN}"
@@ -89,20 +90,22 @@ main() {
8990
setup_env
9091
check_deps
9192

92-
if [ $# -gt 0 ]; then
93-
for tool in "$@"; do
94-
if [[ ${tool} =~ github.com\/ ]]; then
95-
compile "${tool}"
96-
else
97-
compile_with_flags "${tool}"
98-
fi
99-
done
100-
else
101-
for tool in "${TOOLS[@]}"; do
102-
echo "Compiling default tools..."
103-
compile_with_flags "${tool}"
104-
done
93+
if [ $# = 0 ]; then
94+
# default to all tools
95+
set -- "${TOOLS[@]}"
10596
fi
97+
98+
for tool; do
99+
if ! (printf '%s\n' "${TOOLS[@]}" | grep -q "^${tool}$"); then
100+
echo "Skipping unrecognized tool name: ${tool}" >&2
101+
continue
102+
fi
103+
if [[ ${tool} =~ github.com\/ ]]; then
104+
compile "${tool}"
105+
else
106+
compile_with_flags "${tool}"
107+
fi
108+
done
106109
}
107110

108111
main "$@"

0 commit comments

Comments
 (0)