Skip to content

Commit f7a67e7

Browse files
James DeFelicejdef
authored andcommitted
Go protos register fully qualified package root.
Generated golang bindings invoke proto.Register with a "file name" and a metadata blob. The primary goal of this change is to support protobuf reflection libraries that attempt to examine the generated metadata blobs; abbreviated file names (prior to this change set) make reflection difficult. A secondary goal is to avoid overlap with other non-fully qualified proto packages: a longer, fully qualified package root has less chance of overlapping with that of another package in the wild.
1 parent 560f21a commit f7a67e7

File tree

2 files changed

+277
-267
lines changed

2 files changed

+277
-267
lines changed

lib/go/Makefile

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,24 @@ export PATH := $(shell pwd):$(PATH)
8383
## BUILD ##
8484
########################################################################
8585
CSI_PROTO := ../../csi.proto
86-
CSI_PKG := $(shell cat $(CSI_PROTO) | sed -n -e 's/^package.\([^;]*\);$$/\1/p'|tr '.' '/')
87-
CSI_GO := $(CSI_PKG)/csi.pb.go
86+
CSI_PKG_ROOT := github.com/container-storage-interface/spec
87+
CSI_PKG_SUB := $(shell cat $(CSI_PROTO) | sed -n -e 's/^package.\([^;]*\);$$/\1/p'|tr '.' '/')
88+
CSI_BUILD := $(CSI_PKG_SUB)/.build
89+
CSI_GO := $(CSI_PKG_SUB)/csi.pb.go
8890
CSI_A := csi.a
89-
CSI_GO_TMP := $(CSI_PKG)/.build/csi.pb.go
91+
CSI_GO_TMP := $(CSI_BUILD)/$(CSI_PKG_ROOT)/csi.pb.go
9092

9193
# This recipe generates the go language bindings to a temp area.
94+
$(CSI_GO_TMP): HERE := $(shell pwd)
95+
$(CSI_GO_TMP): PTYPES_PKG := github.com/golang/protobuf/ptypes
9296
$(CSI_GO_TMP): GO_OUT := plugins=grpc
93-
$(CSI_GO_TMP): GO_OUT := $(GO_OUT),Mgoogle/protobuf/wrappers.proto=github.com/golang/protobuf/ptypes/wrappers
94-
$(CSI_GO_TMP): INCLUDE = -I$(PROTOC_TMP_DIR)/include
97+
$(CSI_GO_TMP): GO_OUT := $(GO_OUT),Mgoogle/protobuf/wrappers.proto=$(PTYPES_PKG)/wrappers
98+
$(CSI_GO_TMP): GO_OUT := $(GO_OUT):"$(HERE)/$(CSI_BUILD)"
99+
$(CSI_GO_TMP): INCLUDE := -I$(GOPATH)/src -I$(HERE)/$(PROTOC_TMP_DIR)/include
95100
$(CSI_GO_TMP): $(CSI_PROTO) | $(PROTOC) $(PROTOC_GEN_GO)
96101
@mkdir -p "$(@D)"
97-
$(PROTOC) -I "$(<D)" $(INCLUDE) --go_out=$(GO_OUT):"$(@D)" "$<"
102+
(cd "$(GOPATH)/src" && \
103+
$(HERE)/$(PROTOC) $(INCLUDE) --go_out=$(GO_OUT) "$(CSI_PKG_ROOT)/$(<F)")
98104

99105
# The temp language bindings are compared to the ones that are
100106
# versioned. If they are different then it means the language
@@ -114,16 +120,16 @@ endif
114120
# 3. Build the archive file.
115121
$(CSI_A): $(CSI_GO)
116122
go get -v -d ./...
117-
go install ./$(CSI_PKG)
118-
go build -o "$@" ./$(CSI_PKG)
123+
go install ./$(CSI_PKG_SUB)
124+
go build -o "$@" ./$(CSI_PKG_SUB)
119125

120126
build: $(CSI_A)
121127

122128
clean:
123129
go clean -i ./...
124-
rm -f "$(CSI_A)" "$(CSI_GO)" "$(CSI_GO_TMP)"
130+
rm -rf "$(CSI_A)" "$(CSI_GO)" "$(CSI_BUILD)"
125131

126132
clobber: clean
127-
rm -fr "$(PROTOC)" "$(PROTOC_GEN_GO)" "$(CSI_PKG)"
133+
rm -fr "$(PROTOC)" "$(PROTOC_GEN_GO)" "$(CSI_PKG_SUB)"
128134

129135
.PHONY: clean clobber

0 commit comments

Comments
 (0)