22
22
# including build.make.
23
23
REGISTRY_NAME =quay.io/k8scsi
24
24
25
+ # Can be set to -mod=vendor to ensure that the "vendor" directory is used.
26
+ GOFLAGS_VENDOR =
27
+
25
28
# Revision that gets built into each binary via the main.version
26
29
# string. Uses the `git describe` output based on the most recent
27
30
# version tag with a short revision suffix or, if nothing has been
@@ -62,11 +65,12 @@ ARCH := $(if $(GOARCH),$(GOARCH),$(shell go env GOARCH))
62
65
# Specific packages can be excluded from each of the tests below by setting the *_FILTER_CMD variables
63
66
# to something like "| grep -v 'github.com/kubernetes-csi/project/pkg/foobar'". See usage below.
64
67
65
- build-% :
68
+ build-% : check-go-version-go
66
69
mkdir -p bin
67
- CGO_ENABLED=0 GOOS=linux go build -a -ldflags ' -X main.version=$(REV) -extldflags "-static"' -o ./bin/$* ./cmd/$*
70
+ CGO_ENABLED=0 GOOS=linux go build $( GOFLAGS_VENDOR ) -a -ldflags ' -X main.version=$(REV) -extldflags "-static"' -o ./bin/$* ./cmd/$*
68
71
if [ " $$ ARCH" = " amd64" ]; then \
69
- CGO_ENABLED=0 GOOS=windows go build -a -ldflags ' -X main.version=$(REV) -extldflags "-static"' -o ./bin/$* .exe ./cmd/$* ; \
72
+ CGO_ENABLED=0 GOOS=windows go build $(GOFLAGS_VENDOR ) -a -ldflags ' -X main.version=$(REV) -extldflags "-static"' -o ./bin/$* .exe ./cmd/$* ; \
73
+ CGO_ENABLED=0 GOOS=linux GOARCH=ppc64le go build $(GOFLAGS_VENDOR ) -a -ldflags ' -X main.version=$(REV) -extldflags "-static"' -o ./bin/$* -ppc64le ./cmd/$* ; \
70
74
fi
71
75
72
76
container-% : build-%
@@ -97,19 +101,19 @@ push: $(CMDS:%=push-%)
97
101
clean :
98
102
-rm -rf bin
99
103
100
- test :
104
+ test : check-go-version-go
101
105
102
106
.PHONY : test-go
103
107
test : test-go
104
108
test-go :
105
109
@ echo ; echo " ### $@ :"
106
- go test ` go list ./... | grep -v -e ' vendor' -e ' /test/e2e$$' $( TEST_GO_FILTER_CMD) ` $(TESTARGS )
110
+ go test $( GOFLAGS_VENDOR ) ` go list $( GOFLAGS_VENDOR ) ./... | grep -v -e ' vendor' -e ' /test/e2e$$' $( TEST_GO_FILTER_CMD) ` $(TESTARGS )
107
111
108
112
.PHONY : test-vet
109
113
test : test-vet
110
114
test-vet :
111
115
@ echo ; echo " ### $@ :"
112
- go vet ` go list ./... | grep -v vendor $( TEST_VET_FILTER_CMD) `
116
+ go test $( GOFLAGS_VENDOR ) ` go list $( GOFLAGS_VENDOR ) ./... | grep -v vendor $( TEST_VET_FILTER_CMD) `
113
117
114
118
.PHONY : test-fmt
115
119
test : test-fmt
@@ -154,43 +158,7 @@ test-fmt:
154
158
test : test-vendor
155
159
test-vendor :
156
160
@ echo ; echo " ### $@ :"
157
- @ if [ -f Gopkg.toml ]; then \
158
- echo " Repo uses 'dep' for vendoring." ; \
159
- case " $$ (dep version 2>/dev/null | grep 'version *:')" in \
160
- * v0.[56789]* ) dep check && echo " vendor up-to-date" || false ;; \
161
- * ) echo " skipping check, dep >= 0.5 required" ;; \
162
- esac ; \
163
- elif [ -f go.mod ]; then \
164
- echo " Repo uses 'go mod'." ; \
165
- if [ " $$ {JOB_NAME}" ] && \
166
- ( [ "$${JOB_TYPE}" != "presubmit" ] || \
167
- [ $$( (git diff "${PULL_BASE_SHA}..HEAD" -- go.mod go.sum vendor release-tools; \
168
- git diff "${PULL_BASE_SHA}..HEAD" | grep -e '^@@.*@@ import (' -e '^[+-]import') | \
169
- wc -l) -eq 0 ] ); then \
170
- echo "Skipping vendor check because the Prow pre-submit job does not affect dependencies."; \
171
- elif ! GO111MODULE=on go mod tidy; then \
172
- echo "ERROR: vendor check failed."; \
173
- false; \
174
- elif [ $$(git status --porcelain -- go.mod go.sum | wc -l) -gt 0 ]; then \
175
- echo "ERROR: go module files *not* up-to-date, they did get modified by 'GO111MODULE=on go mod tidy':"; \
176
- git diff -- go.mod go.sum; \
177
- false; \
178
- elif [ -d vendor ]; then \
179
- if ! GO111MODULE=on go mod vendor; then \
180
- echo "ERROR: vendor check failed."; \
181
- false; \
182
- elif [ $$(git status --porcelain -- vendor | wc -l) -gt 0 ]; then \
183
- echo "ERROR: vendor directory *not* up-to-date, it did get modified by 'GO111MODULE=on go mod vendor':"; \
184
- git status -- vendor; \
185
- git diff -- vendor; \
186
- false; \
187
- else \
188
- echo "Go dependencies and vendor directory up-to-date."; \
189
- fi; \
190
- else \
191
- echo "Go dependencies up-to-date."; \
192
- fi; \
193
- fi
161
+ @ ./release-tools/verify-vendor.sh
194
162
195
163
.PHONY : test-subtree
196
164
test : test-subtree
@@ -216,3 +184,11 @@ test-shellcheck:
216
184
./release-tools/verify-shellcheck.sh "$$dir" || ret=1; \
217
185
done; \
218
186
exit $$ret
187
+
188
+ # Targets in the makefile can depend on check-go-version-<path to go binary>
189
+ # to trigger a warning if the x.y version of that binary does not match
190
+ # what the project uses. Make ensures that this is only checked once per
191
+ # invocation.
192
+ .PHONY : check-go-version-%
193
+ check-go-version-% :
194
+ ./release-tools/verify-go-version.sh " $* "
0 commit comments