11
11
12
12
REPO = github.com/operator-framework/api
13
13
BUILD_PATH = $(REPO ) /cmd/operator-verify
14
- PKGS = $(shell go list ./... | grep -v /vendor/)
15
- YQ := go run $(MOD_FLAGS ) ./vendor/github.com/mikefarah/yq/v3/
14
+ PKGS = $(shell go list ./...)
16
15
17
16
.PHONY : help
18
17
help : # # Show this help screen
@@ -25,7 +24,6 @@ help: ## Show this help screen
25
24
.PHONY : install
26
25
27
26
install : # # Build & install operator-verify
28
-
29
27
$(Q ) go install \
30
28
-gcflags " all=-trimpath=${GOPATH} " \
31
29
-asmflags " all=-trimpath=${GOPATH} " \
@@ -35,25 +33,25 @@ install: ## Build & install operator-verify
35
33
" \
36
34
$(BUILD_PATH )
37
35
36
+ # ##
38
37
# Code management.
39
- .PHONY : format tidy clean vendor generate manifests
38
+ # ##
39
+ .PHONY : format tidy clean generate manifests
40
40
41
41
format : # # Format the source code
42
42
$(Q ) go fmt $(PKGS )
43
43
44
44
tidy : # # Update dependencies
45
45
$(Q ) go mod tidy -v
46
-
47
- vendor : tidy # # Update vendor directory
48
- $(Q ) go mod vendor
46
+ $(Q ) go mod verify
49
47
50
48
clean : # # Clean up the build artifacts
51
49
$(Q ) rm -rf build
52
50
53
51
generate : controller-gen # # Generate code
54
52
$(CONTROLLER_GEN ) object:headerFile=./hack/boilerplate.go.txt paths=./...
55
53
56
- manifests : controller-gen # # Generate manifests e.g. CRD, RBAC etc
54
+ manifests : yq controller-gen # # Generate manifests e.g. CRD, RBAC etc
57
55
@# Create CRDs for new APIs
58
56
$(CONTROLLER_GEN ) crd:crdVersions=v1 output:crd:dir=./crds paths=./pkg/operators/...
59
57
@@ -88,9 +86,28 @@ test-unit: ## Run the unit tests
88
86
verify : manifests generate format
89
87
git diff --exit-code
90
88
89
+ # ##
91
90
# Utilities.
92
- .PHONY : controller-gen
93
-
94
- controller-gen : vendor # # Find or download controller-gen
95
- CONTROLLER_GEN =$(Q ) go run -mod=vendor ./vendor/sigs.k8s.io/controller-tools/cmd/controller-gen
96
-
91
+ # ##
92
+
93
+ # go-get-tool will 'go get' any package $2 and install it to $1.
94
+ PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST ) ) ) )
95
+ define go-get-tool
96
+ @[ -f $(1 ) ] || { \
97
+ set -e ;\
98
+ TMP_DIR=$$(mktemp -d ) ;\
99
+ cd $$TMP_DIR ;\
100
+ go mod init tmp ;\
101
+ echo "Downloading $(2 ) " ;\
102
+ GOBIN=$(PROJECT_DIR ) /bin go get $(2 ) ;\
103
+ rm -rf $$TMP_DIR ;\
104
+ }
105
+ endef
106
+
107
+ CONTROLLER_GEN = $(shell pwd) /bin/controller-gen
108
+ controller-gen : # # Download controller-gen locally if necessary.
109
+ $(call go-get-tool,$(CONTROLLER_GEN ) ,sigs.k8s.io/controller-tools/cmd/[email protected] )
110
+
111
+ YQ = $(shell pwd) /bin/yq
112
+ yq :
113
+ $(call go-get-tool,$(YQ ) ,github.com/mikefarah/yq/v3)
0 commit comments