|
| 1 | +## This Makefile is meant to be run on Unix hosts - as such, it only supports the few |
| 2 | +## operations that don't require on a Windows host, mostly code generation and linting. |
| 3 | + |
| 4 | +.DEFAULT_GOAL := all |
| 5 | +SHELL := /bin/bash |
| 6 | + |
| 7 | +ifeq ($(GOPATH),) |
| 8 | +$(error "GOPATH env variable not defined") |
| 9 | +endif |
| 10 | + |
| 11 | +REPO_ROOT = $(CURDIR) |
| 12 | +BUILD_DIR = build |
| 13 | +BUILD_TOOLS_DIR = $(BUILD_DIR)/tools |
| 14 | + |
| 15 | +GO_ENV_VARS = GO111MODULE=on GOOS=windows |
| 16 | + |
| 17 | +.PHONY: all |
| 18 | +all: generate compile lint |
| 19 | + |
| 20 | +.PHONY: compile |
| 21 | +compile: compile-client compile-server compile-csi-proxy-api-gen |
| 22 | + |
| 23 | +.PHONY: compile-client |
| 24 | +compile-client: |
| 25 | + $(GO_ENV_VARS) go build ./client/... |
| 26 | + |
| 27 | +.PHONY: compile-server |
| 28 | +compile-server: |
| 29 | + $(GO_ENV_VARS) go build -o $(BUILD_DIR)/server.exe ./cmd/server |
| 30 | + |
| 31 | +CSI_PROXY_API_GEN = $(BUILD_DIR)/csi-proxy-api-gen |
| 32 | + |
| 33 | +.PHONY: compile-csi-proxy-api-gen |
| 34 | +compile-csi-proxy-api-gen: |
| 35 | + GO111MODULE=on go build -o $(CSI_PROXY_API_GEN) ./cmd/csi-proxy-api-gen |
| 36 | + |
| 37 | +.PHONY: generate |
| 38 | +generate: generate-protobuf generate-csi-proxy-api-gen |
| 39 | + |
| 40 | +# using xargs instead of -exec since the latter doesn't propagate exit statuses |
| 41 | +.PHONY: generate-protobuf |
| 42 | +generate-protobuf: |
| 43 | + @ if ! which protoc > /dev/null 2>&1; then echo 'Unable to find protoc binary' ; exit 1; fi |
| 44 | + @ generate_protobuf_for() { \ |
| 45 | + local FILE="$$1"; \ |
| 46 | + local FILE_DIR="$$(dirname "$$FILE")"; \ |
| 47 | + echo "Generating protobuf file from $$FILE"; \ |
| 48 | + protoc -I "$$FILE_DIR" -I "$$GOPATH/src" -I '$(REPO_ROOT)/client/api' "$$FILE" --go_out=plugins="grpc:$$FILE_DIR"; \ |
| 49 | + } ; \ |
| 50 | + export -f generate_protobuf_for; \ |
| 51 | + find '$(REPO_ROOT)' -name '*.proto' -print0 | xargs -0 -n1 $(SHELL) -c 'generate_protobuf_for "$$0"' |
| 52 | + |
| 53 | +.PHONY: generate-csi-proxy-api-gen |
| 54 | +generate-csi-proxy-api-gen: compile-csi-proxy-api-gen |
| 55 | + $(CSI_PROXY_API_GEN) -i github.com/kubernetes-csi/csi-proxy/client/api,github.com/kubernetes-csi/csi-proxy/integrationtests/apigroups/api/dummy |
| 56 | + |
| 57 | +.PHONY: clean |
| 58 | +clean: clean-protobuf clean-generated |
| 59 | + |
| 60 | +.PHONY: clean-protobuf |
| 61 | +clean-protobuf: |
| 62 | + find '$(REPO_ROOT)' -name '*.proto' -exec $(SHELL) -c 'rm -vf "$$(dirname {})/$$(basename {} .proto).pb.go"' \; |
| 63 | + |
| 64 | +.PHONY: clean-generated |
| 65 | +clean-generated: |
| 66 | + find '$(REPO_ROOT)' -name '*_generated.go' -exec $(SHELL) -c '[[ "$$(head -n 1 "{}")" == "// Code generated by csi-proxy-api-gen"* ]] && rm -v {}' \; |
| 67 | + |
| 68 | +# see https://github.com/golangci/golangci-lint/releases |
| 69 | +GOLANGCI_LINT_VERSION = v1.21.0 |
| 70 | +GOLANGCI_LINT = $(BUILD_TOOLS_DIR)/golangci-lint/$(GOLANGCI_LINT_VERSION)/golangci-lint |
| 71 | + |
| 72 | +.PHONY: lint |
| 73 | +lint: $(GOLANGCI_LINT) |
| 74 | + $(GO_ENV_VARS) $(GOLANGCI_LINT) run |
| 75 | + git --no-pager diff --exit-code |
| 76 | + |
| 77 | +# see https://github.com/golangci/golangci-lint#binary-release |
| 78 | +$(GOLANGCI_LINT): |
| 79 | + curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "$$(dirname '$(GOLANGCI_LINT)')" '$(GOLANGCI_LINT_VERSION)' |
0 commit comments