-
Notifications
You must be signed in to change notification settings - Fork 372
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- use git to check for out-of-date generated files, avoids all the temp files and manual diff in the Makefile. - not specify version for protoc-gen-go, it will use the version from go.mod - do not copy over the protoc binary. Call it directly from unzipped path. So it can find the includes automatically, and we don't need the -I or --go_opts=Mxxx flags. - use paths=source_relative to generate go files directly into destination, avoid the copy. - simplify the sed command used to extract "csi.proto" file.
- Loading branch information
Showing
3 changed files
with
25 additions
and
65 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
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
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 |
---|---|---|
|
@@ -41,22 +41,24 @@ else ifeq (arm64,$(PROTOC_ARCH)) | |
PROTOC_ARCH := aarch_64 | ||
endif | ||
|
||
PROTOC := ./protoc | ||
PROTOC_ZIP := protoc-$(PROTOC_VER)-$(PROTOC_OS)-$(PROTOC_ARCH).zip | ||
PROTOC_URL := https://github.com/protocolbuffers/protobuf/releases/download/v$(PROTOC_VER)/$(PROTOC_ZIP) | ||
PROTOC_TMP_DIR := .protoc | ||
PROTOC_TMP_BIN := $(PROTOC_TMP_DIR)/bin/protoc | ||
PROTOC := $(PROTOC_TMP_DIR)/bin/protoc | ||
|
||
$(GOBIN)/protoc-gen-go: ../../go.mod | ||
go install google.golang.org/protobuf/cmd/protoc-gen-go | ||
$(GOBIN)/protoc-gen-go-grpc: | ||
go install google.golang.org/grpc/cmd/[email protected] | ||
|
||
$(PROTOC): | ||
-go install google.golang.org/protobuf/cmd/[email protected] && \ | ||
go install google.golang.org/grpc/cmd/[email protected] && \ | ||
mkdir -p "$(PROTOC_TMP_DIR)" && \ | ||
-mkdir -p "$(PROTOC_TMP_DIR)" && \ | ||
curl -L $(PROTOC_URL) -o "$(PROTOC_TMP_DIR)/$(PROTOC_ZIP)" && \ | ||
unzip "$(PROTOC_TMP_DIR)/$(PROTOC_ZIP)" -d "$(PROTOC_TMP_DIR)" && \ | ||
chmod 0755 "$(PROTOC_TMP_BIN)" && \ | ||
cp -f "$(PROTOC_TMP_BIN)" "$@" | ||
chmod 0755 "$@" | ||
stat "$@" > /dev/null 2>&1 | ||
|
||
PROTOC_ALL := $(GOBIN)/protoc-gen-go $(GOBIN)/protoc-gen-go-grpc $(PROTOC) | ||
|
||
######################################################################## | ||
## PATH ## | ||
|
@@ -71,49 +73,24 @@ export PATH := $(GOBIN):$(PATH) | |
## BUILD ## | ||
######################################################################## | ||
CSI_PROTO := ../../csi.proto | ||
CSI_PKG_ROOT := github.com/container-storage-interface/spec | ||
CSI_PKG_SUB := $(shell cat $(CSI_PROTO) | sed -nE -e 's/^package.([^;]*).v[0-9]+;$$/\1/p'|tr '.' '/') | ||
CSI_BUILD := $(CSI_PKG_SUB)/.build | ||
CSI_PKG_SUB := csi | ||
CSI_GO := $(CSI_PKG_SUB)/csi.pb.go | ||
CSI_GRPC := $(CSI_PKG_SUB)/csi_grpc.pb.go | ||
CSI_GRPC_TMP := $(CSI_BUILD)/$(CSI_PKG_ROOT)/lib/go/$(CSI_PKG_SUB)/csi_grpc.pb.go | ||
CSI_GO_TMP := $(CSI_BUILD)/$(CSI_PKG_ROOT)/lib/go/$(CSI_PKG_SUB)/csi.pb.go | ||
|
||
# This recipe generates the go language bindings to a temp area. | ||
$(CSI_GO_TMP) $(CSI_GRPC_TMP): INCLUDE := -I../.. -I$(PROTOC_TMP_DIR)/include | ||
$(CSI_GO_TMP) $(CSI_GRPC_TMP): $(CSI_PROTO) | $(PROTOC) | ||
# This recipe generates the go language bindings | ||
$(CSI_GO) $(CSI_GRPC): $(CSI_PROTO) $(PROTOC_ALL) | ||
@mkdir -p "$(@D)" | ||
$(PROTOC) $(INCLUDE) --go-grpc_out=$(CSI_BUILD) --go_out=$(CSI_BUILD) \ | ||
--go_opt=Mgoogle/protobuf/descriptor.proto=google.golang.org/protobuf/types/descriptorpb \ | ||
--go_opt=Mgoogle/protobuf/wrappers.proto=google.golang.org/protobuf/types/known/wrapperspb \ | ||
$(PROTOC) -I../.. --go-grpc_out=$(CSI_PKG_SUB) --go_out=$(CSI_PKG_SUB) \ | ||
--go_opt=paths=source_relative --go-grpc_opt=paths=source_relative \ | ||
"$(<F)" | ||
|
||
# The temp language bindings are compared to the ones that are | ||
# versioned. If they are different then it means the language | ||
# bindings were not updated prior to being committed. | ||
$(CSI_GO): $(CSI_GO_TMP) | ||
ifeq (true,$(GITHUB_ACTIONS)) | ||
diff "$@" "$?" | ||
else | ||
@mkdir -p "$(@D)" | ||
diff "$@" "$?" > /dev/null 2>&1 || cp -f "$?" "$@" | ||
endif | ||
$(CSI_GRPC): $(CSI_GRPC_TMP) | ||
ifeq (true,$(GITHUB_ACTIONS)) | ||
diff "$@" "$?" | ||
else | ||
@mkdir -p "$(@D)" | ||
diff "$@" "$?" > /dev/null 2>&1 || cp -f "$?" "$@" | ||
endif | ||
|
||
|
||
build: $(CSI_GO) $(CSI_GRPC) | ||
|
||
clean: | ||
go clean -i ./... | ||
rm -rf "$(CSI_GO)" "$(CSI_GRPC)" "$(CSI_BUILD)" | ||
rm -rf "$(CSI_PKG_SUB)" | ||
|
||
clobber: clean | ||
rm -fr "$(PROTOC)" "$(CSI_PKG_SUB)" | ||
rm -fr "$(PROTOC_TMP_DIR)" | ||
|
||
.PHONY: clean clobber |