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

build: respect GOBIN when using make targets #12077

Merged
merged 1 commit into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions .changelog/12077.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
build: make targets now respect GOBIN variable
```
16 changes: 11 additions & 5 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ ifneq (MSYS_NT,$(THIS_OS))
# GOPATH supports PATH style multi-paths; assume the first entry is favorable.
# Necessary because new Circle images override GOPATH with multiple values.
# See: https://discuss.circleci.com/t/gopath-is-set-to-multiple-directories/7174
GOPATH=$(shell go env GOPATH | cut -d: -f1)
GOPATH := $(shell go env GOPATH | cut -d: -f1)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drive by improvement (= vs :=)

https://stackoverflow.com/a/6283363

endif

# Respect $GOBIN if set in environment or via $GOENV file.
BIN := $(shell go env GOBIN)
ifndef BIN
BIN := $(shell go env GOPATH)/bin
endif

GO_TAGS ?=
Expand Down Expand Up @@ -253,15 +259,15 @@ dev: hclfmt ## Build for the current development platform
@echo "==> Removing old development build..."
@rm -f $(PROJECT_ROOT)/$(DEV_TARGET)
@rm -f $(PROJECT_ROOT)/bin/nomad
@rm -f $(GOPATH)/bin/nomad
@rm -f $(BIN)/nomad
@if [ -d vendor ]; then echo -e "==> WARNING: Found vendor directory. This may cause build errors, consider running 'rm -r vendor' or 'make clean' to remove.\n"; fi
@$(MAKE) --no-print-directory \
$(DEV_TARGET) \
GO_TAGS="$(GO_TAGS) $(NOMAD_UI_TAG)"
@mkdir -p $(PROJECT_ROOT)/bin
@mkdir -p $(GOPATH)/bin
@mkdir -p $(BIN)
@cp $(PROJECT_ROOT)/$(DEV_TARGET) $(PROJECT_ROOT)/bin/
@cp $(PROJECT_ROOT)/$(DEV_TARGET) $(GOPATH)/bin
@cp $(PROJECT_ROOT)/$(DEV_TARGET) $(BIN)

.PHONY: prerelease
prerelease: GO_TAGS=ui codegen_generated release
Expand Down Expand Up @@ -341,7 +347,7 @@ clean: ## Remove build artifacts
@rm -rf "$(PROJECT_ROOT)/bin/"
@rm -rf "$(PROJECT_ROOT)/pkg/"
@rm -rf "$(PROJECT_ROOT)/vendor/"
@rm -f "$(GOPATH)/bin/nomad"
@rm -f "$(BIN)/nomad"

.PHONY: testcluster
testcluster: ## Bring up a Linux test cluster using Vagrant. Set PROVIDER if necessary.
Expand Down