@@ -69,6 +69,25 @@ $(PROTOC_GEN_GO):
6969 go build -o " $@ " $(PROTOC_GEN_GO_PKG )
7070
7171
72+ # #######################################################################
73+ # # PROTOC-GEN-GO-JSON ##
74+ # #######################################################################
75+
76+ # This is the recipe for getting and installing the json plug-in
77+ # for protoc-gen-go
78+ PROTOC_GEN_GO_JSON_PKG := github.com/mitchellh/protoc-gen-go-json
79+ PROTOC_GEN_GO_JSON := protoc-gen-go-json
80+ $(PROTOC_GEN_GO_JSON ) : PROTOC_GEN_GO_JSON_VERSION := v1.0.0
81+ $(PROTOC_GEN_GO_JSON ) :
82+ mkdir -p $(dir $(GOPATH ) /src/$(PROTOC_GEN_GO_JSON_PKG ) )
83+ test -d $(GOPATH ) /src/$(PROTOC_GEN_GO_JSON_PKG ) /.git || git clone https://$(PROTOC_GEN_GO_JSON_PKG ) $(GOPATH ) /src/$(PROTOC_GEN_GO_JSON_PKG )
84+ (cd $( GOPATH) /src/$( PROTOC_GEN_GO_JSON_PKG) && \
85+ (test " $$ (git describe --tags | head -1)" = " $( PROTOC_GEN_GO_JSON_VERSION) " || \
86+ (git fetch && git checkout tags/$( PROTOC_GEN_GO_JSON_VERSION) )))
87+ (cd $( GOPATH) /src/$( PROTOC_GEN_GO_JSON_PKG) && go get -v -d $$ (go list -f ' {{ .ImportPath }}' ./...)) && \
88+ go build -o " $@ " $(PROTOC_GEN_GO_JSON_PKG )
89+
90+
7291# #######################################################################
7392# # GEN-PROTO-GO ##
7493# #######################################################################
@@ -123,12 +142,15 @@ export PATH := $(shell pwd):$(PATH)
123142# # BUILD ##
124143# #######################################################################
125144COSI_PROTO := ./cosi.proto
126- COSI_PKG_ROOT := github.com/kubernetes-sigs/container-object-storage-interface-spec
145+ COSI_SPEC := spec.md
146+ COSI_PKG_ROOT := sigs.k8s.io/container-object-storage-interface-spec
127147COSI_PKG_SUB := .
128148COSI_BUILD := $(COSI_PKG_SUB ) /.build
129149COSI_GO := $(COSI_PKG_SUB ) /cosi.pb.go
150+ COSI_GO_JSON := $(COSI_PKG_SUB ) /cosi.pb.json.go
130151COSI_A := cosi.a
131152COSI_GO_TMP := $(COSI_BUILD ) /$(COSI_PKG_ROOT ) /cosi.pb.go
153+ COSI_GO_JSON_TMP := $(COSI_BUILD ) /$(COSI_PKG_ROOT ) /cosi.pb.json.go
132154
133155# This recipe generates the go language bindings to a temp area.
134156$(COSI_GO_TMP ) : HERE := $(shell pwd)
@@ -137,11 +159,13 @@ $(COSI_GO_TMP): GO_OUT := plugins=grpc
137159$(COSI_GO_TMP ) : GO_OUT := $(GO_OUT ) ,Mgoogle/protobuf/descriptor.proto=github.com/golang/protobuf/protoc-gen-go/descriptor
138160$(COSI_GO_TMP ) : GO_OUT := $(GO_OUT ) ,Mgoogle/protobuf/wrappers.proto=$(PTYPES_PKG ) /wrappers
139161$(COSI_GO_TMP ) : GO_OUT := $(GO_OUT ) :"$(HERE ) /$(COSI_BUILD ) "
162+ $(COSI_GO_TMP ) : GO_JSON_OUT := emit_defaults
163+ $(COSI_GO_TMP ) : GO_JSON_OUT := $(GO_JSON_OUT ) :"$(HERE ) /$(COSI_BUILD ) "
140164$(COSI_GO_TMP ) : INCLUDE := -I$(GOPATH ) /src -I$(HERE ) /$(PROTOC_TMP_DIR ) /include
141- $(COSI_GO_TMP ) : $(COSI_PROTO ) | $(PROTOC ) $(PROTOC_GEN_GO )
165+ $(COSI_GO_TMP ) : $(COSI_PROTO ) | $(PROTOC ) $(PROTOC_GEN_GO ) $( PROTOC_GEN_GO_JSON )
142166 @mkdir -p " $( @D) "
143167 (cd " $( GOPATH) /src" && \
144- $(HERE ) /$(PROTOC ) $(INCLUDE ) --go_out=$(GO_OUT ) " $( COSI_PKG_ROOT) /$( < F) " )
168+ $(HERE ) /$(PROTOC ) $(INCLUDE ) --go_out=$(GO_OUT ) --go-json_out= $( GO_JSON_OUT ) " $( COSI_PKG_ROOT) /$( < F) " )
145169
146170# The temp language bindings are compared to the ones that are
147171# versioned. If they are different then it means the language
@@ -154,23 +178,38 @@ else
154178 diff "$@" "$?" > /dev/null 2>&1 || cp -f "$?" "$@"
155179endif
156180
181+ # The temp language bindings are compared to the ones that are
182+ # versioned. If they are different then it means the language
183+ # bindings were not updated prior to being committed.
184+ $(COSI_GO_JSON ) : $(COSI_GO_JSON_TMP )
185+ ifeq (true,$(TRAVIS ) )
186+ diff "$@" "$?"
187+ else
188+ @mkdir -p "$(@D)"
189+ diff "$@" "$?" > /dev/null 2>&1 || cp -f "$?" "$@"
190+ endif
191+
157192# This recipe builds the Go archive from the sources in three steps:
158193#
159194# 1. Go get any missing dependencies.
160195# 2. Cache the packages.
161196# 3. Build the archive file.
162- $(COSI_A ) : $(COSI_GO ) $(GENPROTO_BUILD_GO ) $(GRPC_BUILD_GO )
197+ $(COSI_A ) : $(COSI_GO ) $(COSI_GO_JSON ) $( GENPROTO_BUILD_GO ) $(GRPC_BUILD_GO )
163198 go get -v -d ./...
164199 go install ./$(COSI_PKG_SUB )
165200 go build -o " $@ " ./$(COSI_PKG_SUB )
166201
167- build : $(COSI_A )
202+ generate :
203+ echo " // Code generated by make; DO NOT EDIT." > " $( COSI_PROTO) "
204+ cat $(COSI_SPEC ) | sed -n -e ' /```protobuf$$/,/^```$$/ p' | sed ' /^```/d' >> " $( COSI_PROTO) "
205+
206+ build : generate $(COSI_A )
168207
169208clean :
170209 go clean -i ./...
171- rm -rf " $( COSI_A) " " $( COSI_GO) " " $( COSI_BUILD) "
210+ rm -rf " $( COSI_PROTO ) " " $( COSI_A) " " $( COSI_GO) " " $( COSI_GO_JSON ) " " $( COSI_BUILD) "
172211
173212clobber : clean
174- rm -fr " $( PROTOC) " " $( PROTOC_GEN_GO) " " $( COSI_PKG_SUB ) "
213+ rm -fr " $( PROTOC) " " $( PROTOC_TMP_DIR ) " " $( PROTOC_GEN_GO) " " $( PROTOC_GEN_GO_JSON ) "
175214
176215.PHONY : clean clobber $(GRPC_BUILD_GO ) $(GENPROTO_BUILD_GO )
0 commit comments