@@ -69,6 +69,25 @@ $(PROTOC_GEN_GO):
69
69
go build -o " $@ " $(PROTOC_GEN_GO_PKG )
70
70
71
71
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
+
72
91
# #######################################################################
73
92
# # GEN-PROTO-GO ##
74
93
# #######################################################################
@@ -123,12 +142,15 @@ export PATH := $(shell pwd):$(PATH)
123
142
# # BUILD ##
124
143
# #######################################################################
125
144
COSI_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
127
147
COSI_PKG_SUB := .
128
148
COSI_BUILD := $(COSI_PKG_SUB ) /.build
129
149
COSI_GO := $(COSI_PKG_SUB ) /cosi.pb.go
150
+ COSI_GO_JSON := $(COSI_PKG_SUB ) /cosi.pb.json.go
130
151
COSI_A := cosi.a
131
152
COSI_GO_TMP := $(COSI_BUILD ) /$(COSI_PKG_ROOT ) /cosi.pb.go
153
+ COSI_GO_JSON_TMP := $(COSI_BUILD ) /$(COSI_PKG_ROOT ) /cosi.pb.json.go
132
154
133
155
# This recipe generates the go language bindings to a temp area.
134
156
$(COSI_GO_TMP ) : HERE := $(shell pwd)
@@ -137,11 +159,13 @@ $(COSI_GO_TMP): GO_OUT := plugins=grpc
137
159
$(COSI_GO_TMP ) : GO_OUT := $(GO_OUT ) ,Mgoogle/protobuf/descriptor.proto=github.com/golang/protobuf/protoc-gen-go/descriptor
138
160
$(COSI_GO_TMP ) : GO_OUT := $(GO_OUT ) ,Mgoogle/protobuf/wrappers.proto=$(PTYPES_PKG ) /wrappers
139
161
$(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 ) "
140
164
$(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 )
142
166
@mkdir -p " $( @D) "
143
167
(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) " )
145
169
146
170
# The temp language bindings are compared to the ones that are
147
171
# versioned. If they are different then it means the language
@@ -154,23 +178,38 @@ else
154
178
diff "$@" "$?" > /dev/null 2>&1 || cp -f "$?" "$@"
155
179
endif
156
180
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
+
157
192
# This recipe builds the Go archive from the sources in three steps:
158
193
#
159
194
# 1. Go get any missing dependencies.
160
195
# 2. Cache the packages.
161
196
# 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 )
163
198
go get -v -d ./...
164
199
go install ./$(COSI_PKG_SUB )
165
200
go build -o " $@ " ./$(COSI_PKG_SUB )
166
201
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 )
168
207
169
208
clean :
170
209
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) "
172
211
173
212
clobber : 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 ) "
175
214
176
215
.PHONY : clean clobber $(GRPC_BUILD_GO ) $(GENPROTO_BUILD_GO )
0 commit comments