-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sort out binary installation in Makefile
- Align all binaries to use a predefined bin dir in project - Add cleanup for bin dir - modify/rename go-get-tool to go-install-tool and clean up its logic - cleanup lint target Signed-off-by: adrianc <[email protected]>
- Loading branch information
1 parent
8f5bcbb
commit 0b8e716
Showing
1 changed file
with
21 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ SHELL = /usr/bin/env bash -o pipefail | |
.SHELLFLAGS = -ec | ||
CURPATH=$(PWD) | ||
TARGET_DIR=$(CURPATH)/build/_output | ||
BIN_DIR=$(CURPATH)/bin | ||
KUBECONFIG?=$(HOME)/.kube/config | ||
export OPERATOR_EXEC?=oc | ||
|
||
|
@@ -53,7 +54,7 @@ else | |
GOBIN=$(shell go env GOBIN) | ||
endif | ||
|
||
GOLANGCI_LINT = $(GOBIN)/golangci-lint | ||
GOLANGCI_LINT = $(BIN_DIR)/golangci-lint | ||
# golangci-lint version should be updated periodically | ||
# we keep it fixed to avoid it from unexpectedly failing on the project | ||
# in case of a version bump | ||
|
@@ -71,6 +72,7 @@ _build-%: | |
|
||
clean: | ||
@rm -rf $(TARGET_DIR) | ||
@rm -rf $(BIN_DIR) | ||
|
||
update-codegen: | ||
hack/update-codegen.sh | ||
|
@@ -143,29 +145,24 @@ vet: | |
generate: controller-gen | ||
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." | ||
|
||
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen | ||
CONTROLLER_GEN = $(BIN_DIR)/controller-gen | ||
controller-gen: ## Download controller-gen locally if necessary. | ||
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected]) | ||
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected]) | ||
|
||
KUSTOMIZE = $(shell pwd)/bin/kustomize | ||
KUSTOMIZE = $(BIN_DIR)/kustomize | ||
kustomize: ## Download kustomize locally if necessary. | ||
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected]) | ||
$(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected]) | ||
|
||
ENVTEST = $(shell pwd)/bin/setup-envtest | ||
ENVTEST = $(BIN_DIR)/setup-envtest | ||
envtest: ## Download envtest-setup locally if necessary. | ||
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest) | ||
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest) | ||
|
||
# go-get-tool will 'go install' any package $2 and install it to $1. | ||
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST)))) | ||
define go-get-tool | ||
# go-install-tool will 'go install' any package $2 and install it to $1. | ||
define go-install-tool | ||
@[ -f $(1) ] || { \ | ||
set -e ;\ | ||
TMP_DIR=$$(mktemp -d) ;\ | ||
cd $$TMP_DIR ;\ | ||
go mod init tmp ;\ | ||
echo "Downloading $(2)" ;\ | ||
GOBIN=$(PROJECT_DIR)/bin go install -mod=readonly $(2) ;\ | ||
rm -rf $$TMP_DIR ;\ | ||
GOBIN=$(BIN_DIR) go install -mod=mod $(2) ;\ | ||
} | ||
endef | ||
|
||
|
@@ -222,15 +219,17 @@ test-%: generate vet manifests envtest | |
# deploy-setup-k8s: export CNI_BIN_PATH=/opt/cni/bin | ||
# test-e2e-k8s: test-e2e | ||
|
||
GOCOVMERGE = $(BIN_DIR)/gocovmerge | ||
gocovmerge: ## Download gocovmerge locally if necessary. | ||
go install -mod=readonly github.com/shabbyrobe/gocovmerge/cmd/gocovmerge@latest | ||
$(call go-install-tool,$(GOCOVMERGE),github.com/shabbyrobe/gocovmerge/cmd/gocovmerge@latest) | ||
|
||
GCOV2LCOV = $(BIN_DIR)/gcov2lcov | ||
gcov2lcov: | ||
go install -mod=readonly github.com/jandelgado/[email protected] | ||
$(call go-install-tool,$(GCOV2LCOV),github.com/jandelgado/[email protected]) | ||
|
||
merge-test-coverage: gocovmerge gcov2lcov | ||
gocovmerge cover-*.out > cover.out | ||
gcov2lcov -infile cover.out -outfile lcov.out | ||
$(GOCOVMERGE) cover-*.out > cover.out | ||
$(GCOV2LCOV) -infile cover.out -outfile lcov.out | ||
|
||
deploy-wait: | ||
hack/deploy-wait.sh | ||
|
@@ -246,13 +245,9 @@ deps-update: | |
go mod tidy && \ | ||
go mod vendor | ||
|
||
$(GOLANGCI_LINT): $(info building golangci-lint...) | ||
$Q curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) $(GOLANGCI_LINT_VER) | ||
$(GOLANGCI_LINT): ; $(info installing golangci-lint...) | ||
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VER)) | ||
|
||
.PHONY: lint | ||
lint: | $(GOLANGCI_LINT) ; $(info running golangci-lint...) @ ## Run golangci-lint | ||
mkdir -p $(CURPATH)/test-lint | ||
cd $(CURPATH) && ret=0 && \ | ||
test -z "$$($(GOLANGCI_LINT) run | tee $(CURPATH)/test-lint/lint.out)" || ret=1 ; \ | ||
cat $(CURPATH)/test-lint/lint.out ; rm -rf $(CURPATH)/test-lint ; \ | ||
exit $$ret | ||
$(GOLANGCI_LINT) run --timeout=10m |