Skip to content

Commit 5a2b124

Browse files
committed
build,ui: add support for protobuf WKTs
- Address warnings in server/status/status.proto - Remove overzealous `any`s Closes #6616
1 parent f7893e0 commit 5a2b124

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+65318
-19008
lines changed

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
*.pb.* -diff
22
embedded.go -diff
33
pkg/sql/parser/sql.go -diff
4-
pkg/ui/src/js/protos.js -diff
4+
pkg/ui/src/js/protos.* -diff
55
pkg/ui/generated/* -diff
66
pkg/ui/yarn.lock -merge
77
glide.lock -merge

build/package.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

build/protobuf.mk

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,28 @@
2121
# while BSD sed requires an empty string as the following argument.
2222
SED_INPLACE := sed $(shell sed --version 2>&1 | grep -q GNU && echo -i || echo "-i ''")
2323

24-
ORG_ROOT := .
25-
REPO_ROOT := $(ORG_ROOT)/cockroach
26-
PKG_ROOT := $(REPO_ROOT)/pkg
27-
GITHUB_ROOT := $(REPO_ROOT)/vendor/github.com
28-
GOGOPROTO_ROOT := $(GITHUB_ROOT)/gogo/protobuf
29-
PROTOBUF_ROOT := $(GOGOPROTO_ROOT)/protobuf
24+
ORG_ROOT := .
25+
REPO_ROOT := $(ORG_ROOT)/cockroach
26+
PKG_ROOT := $(REPO_ROOT)/pkg
3027

3128
NATIVE_ROOT := $(PKG_ROOT)/storage/engine
29+
GITHUB_ROOT := $(REPO_ROOT)/vendor/github.com
3230

3331
# Ensure we have an unambiguous GOPATH
3432
GOPATH := $(realpath $(ORG_ROOT)/../../..)
3533
# ^ ^~ GOPATH
3634
# |~ GOPATH/src
3735

36+
GOGO_PROTOBUF_PACKAGE := github.com/gogo/protobuf
37+
GOGO_PROTOBUF_TYPES_PACKAGE := $(GOGO_PROTOBUF_PACKAGE)/types
38+
GOGO_PROTOBUF_PATH := $(GITHUB_ROOT)/../$(GOGO_PROTOBUF_PACKAGE)
39+
PROTOBUF_PATH := $(GOGO_PROTOBUF_PATH)/protobuf
40+
3841
GOPATH_BIN := $(GOPATH)/bin
3942
PROTOC := $(GOPATH_BIN)/protoc
4043
PLUGIN_SUFFIX := gogoroach
4144
PROTOC_PLUGIN := $(GOPATH_BIN)/protoc-gen-$(PLUGIN_SUFFIX)
42-
GOGOPROTO_PROTO := $(GOGOPROTO_ROOT)/gogoproto/gogo.proto
45+
GOGOPROTO_PROTO := $(GOGO_PROTOBUF_PATH)/gogoproto/gogo.proto
4346

4447
COREOS_PATH := $(GITHUB_ROOT)/coreos
4548
COREOS_RAFT_PROTOS := $(addprefix $(COREOS_PATH)/etcd/raft/, $(sort $(shell git -C $(COREOS_PATH)/etcd/raft ls-files --exclude-standard --cached --others -- '*.proto')))
@@ -48,9 +51,10 @@ GRPC_GATEWAY_PACKAGE := github.com/grpc-ecosystem/grpc-gateway
4851
GRPC_GATEWAY_GOOGLEAPIS_PACKAGE := $(GRPC_GATEWAY_PACKAGE)/third_party/googleapis
4952
GRPC_GATEWAY_GOOGLEAPIS_PATH := $(GITHUB_ROOT)/../$(GRPC_GATEWAY_GOOGLEAPIS_PACKAGE)
5053

51-
# Map protobuf includes of annotations.proto to the Go package containing the
52-
# generated Go code.
53-
GRPC_GATEWAY_MAPPING := Mgoogle/api/annotations.proto=$(GRPC_GATEWAY_GOOGLEAPIS_PACKAGE)/google/api
54+
# Map protobuf includes to the Go package containing the generated Go code.
55+
MAPPINGS :=
56+
MAPPINGS := $(MAPPINGS)Mgoogle/api/annotations.proto=$(GRPC_GATEWAY_GOOGLEAPIS_PACKAGE)/google/api,
57+
MAPPINGS := $(MAPPINGS)Mgoogle/protobuf/timestamp.proto=$(GOGOPROTO_ROOT)/protobuf/types,
5458

5559
GW_SERVER_PROTOS := $(PKG_ROOT)/server/serverpb/admin.proto $(PKG_ROOT)/server/serverpb/status.proto
5660
GW_TS_PROTOS := $(PKG_ROOT)/ts/tspb/timeseries.proto
@@ -61,7 +65,9 @@ GW_SOURCES := $(GW_PROTOS:%.proto=%.pb.gw.go)
6165
GO_PROTOS := $(addprefix $(REPO_ROOT)/, $(sort $(shell git -C $(REPO_ROOT) ls-files --exclude-standard --cached --others -- '*.proto')))
6266
GO_SOURCES := $(GO_PROTOS:%.proto=%.pb.go)
6367

64-
UI_SOURCES := $(PKG_ROOT)/ui/src/js/protos.js $(PKG_ROOT)/ui/generated/protos.json $(PKG_ROOT)/ui/generated/protos.d.ts
68+
UI_JS := $(PKG_ROOT)/ui/src/js/protos.js
69+
UI_TS := $(PKG_ROOT)/ui/src/js/protos.d.ts
70+
UI_SOURCES := $(UI_JS) $(UI_TS)
6571

6672
CPP_PROTOS := $(filter %/roachpb/metadata.proto %/roachpb/data.proto %/roachpb/internal.proto %/engine/enginepb/mvcc.proto %/engine/enginepb/rocksdb.proto %/hlc/timestamp.proto %/unresolved_addr.proto,$(GO_PROTOS))
6773
CPP_HEADERS := $(subst ./,$(NATIVE_ROOT)/,$(CPP_PROTOS:%.proto=%.pb.h))
@@ -84,42 +90,36 @@ IMPORT_PREFIX := github.com/$(REPO_NAME)/
8490
$(GO_SOURCES): $(PROTOC) $(GO_PROTOS) $(GOGOPROTO_PROTO)
8591
(cd $(REPO_ROOT) && git ls-files --exclude-standard --cached --others -- '*.pb.go' | xargs rm -f)
8692
for dir in $(sort $(dir $(GO_PROTOS))); do \
87-
$(PROTOC) -I.:$(GOGOPROTO_ROOT):$(PROTOBUF_ROOT):$(COREOS_PATH):$(GRPC_GATEWAY_GOOGLEAPIS_PATH) --plugin=$(PROTOC_PLUGIN) --$(PLUGIN_SUFFIX)_out=$(GRPC_GATEWAY_MAPPING),plugins=grpc,import_prefix=$(IMPORT_PREFIX):$(ORG_ROOT) $$dir/*.proto; \
93+
$(PROTOC) -I.:$(GOGO_PROTOBUF_PATH):$(PROTOBUF_PATH):$(COREOS_PATH):$(GRPC_GATEWAY_GOOGLEAPIS_PATH) --plugin=$(PROTOC_PLUGIN) --$(PLUGIN_SUFFIX)_out=$(MAPPINGS),plugins=grpc,import_prefix=$(IMPORT_PREFIX):$(ORG_ROOT) $$dir/*.proto; \
8894
done
89-
$(SED_INPLACE) -E '/gogoproto/d' $(GO_SOURCES)
95+
$(SED_INPLACE) '/import _/d' $(GO_SOURCES)
96+
$(SED_INPLACE) '/gogoproto/d' $(GO_SOURCES)
9097
$(SED_INPLACE) -E 's!import (fmt|math) "$(IMPORT_PREFIX)(fmt|math)"! !g' $(GO_SOURCES)
9198
$(SED_INPLACE) -E 's!$(IMPORT_PREFIX)(errors|fmt|io|github\.com|golang\.org|google\.golang\.org)!\1!g' $(GO_SOURCES)
9299
$(SED_INPLACE) -E 's!$(REPO_NAME)/(etcd)!coreos/\1!g' $(GO_SOURCES)
93100
gofmt -s -w $(GO_SOURCES)
94101

95102
$(GW_SOURCES) : $(GW_SERVER_PROTOS) $(GW_TS_PROTOS) $(GO_PROTOS) $(GOGOPROTO_PROTO) $(PROTOC)
96103
(cd $(REPO_ROOT) && git ls-files --exclude-standard --cached --others -- '*.pb.gw.go' | xargs rm -f)
97-
$(PROTOC) -I.:$(GOGOPROTO_ROOT):$(PROTOBUF_ROOT):$(COREOS_PATH):$(GRPC_GATEWAY_GOOGLEAPIS_PATH) --grpc-gateway_out=logtostderr=true,request_context=true:. $(GW_SERVER_PROTOS)
98-
$(PROTOC) -I.:$(GOGOPROTO_ROOT):$(PROTOBUF_ROOT):$(COREOS_PATH):$(GRPC_GATEWAY_GOOGLEAPIS_PATH) --grpc-gateway_out=logtostderr=true,request_context=true:. $(GW_TS_PROTOS)
99-
100-
$(REPO_ROOT)/build/yarn.installed: $(REPO_ROOT)/build/package.json
101-
cd $(REPO_ROOT)/build && yarn install
102-
touch $@
104+
$(PROTOC) -I.:$(GOGO_PROTOBUF_PATH):$(PROTOBUF_PATH):$(COREOS_PATH):$(GRPC_GATEWAY_GOOGLEAPIS_PATH) --grpc-gateway_out=logtostderr=true,request_context=true:. $(GW_SERVER_PROTOS)
105+
$(PROTOC) -I.:$(GOGO_PROTOBUF_PATH):$(PROTOBUF_PATH):$(COREOS_PATH):$(GRPC_GATEWAY_GOOGLEAPIS_PATH) --grpc-gateway_out=logtostderr=true,request_context=true:. $(GW_TS_PROTOS)
103106

104-
PBJS_ARGS = --path $(ORG_ROOT) --path $(GOGOPROTO_ROOT) --path $(COREOS_PATH) --path $(GRPC_GATEWAY_GOOGLEAPIS_PATH) $(GW_PROTOS)
107+
$(PKG_ROOT)/ui/yarn.installed: $(PKG_ROOT)/ui/package.json $(PKG_ROOT)/ui/yarn.lock
108+
$(MAKE) -C $(PKG_ROOT)/ui yarn.installed
105109

106-
$(PKG_ROOT)/ui/src/js/protos.js: $(REPO_ROOT)/build/yarn.installed $(GO_PROTOS) $(COREOS_RAFT_PROTOS)
110+
$(UI_JS): $(GO_PROTOS) $(COREOS_RAFT_PROTOS) $(PKG_ROOT)/ui/yarn.installed
107111
# Add comment recognized by reviewable.
108112
echo '// GENERATED FILE DO NOT EDIT' > $@
109-
$(REPO_ROOT)/build/node_modules/.bin/pbjs -t commonjs $(PBJS_ARGS) >> $@
110-
111-
$(PKG_ROOT)/ui/generated/protos.json: $(REPO_ROOT)/build/yarn.installed $(GO_PROTOS) $(COREOS_RAFT_PROTOS)
112-
$(REPO_ROOT)/build/node_modules/.bin/pbjs $(PBJS_ARGS) > $@
113+
$(REPO_ROOT)/pkg/ui/node_modules/.bin/pbjs -t static-module -w es6 --strict-long --keep-case --path $(ORG_ROOT) --path $(GOGO_PROTOBUF_PATH) --path $(COREOS_PATH) --path $(GRPC_GATEWAY_GOOGLEAPIS_PATH) $(GW_PROTOS) >> $@
113114

114-
$(PKG_ROOT)/ui/generated/protos.d.ts: $(PKG_ROOT)/ui/generated/protos.json
115+
$(UI_TS): $(UI_JS)
115116
# Add comment recognized by reviewable.
116117
echo '// GENERATED FILE DO NOT EDIT' > $@
117-
$(REPO_ROOT)/build/node_modules/.bin/proto2ts --file $(PKG_ROOT)/ui/generated/protos.json >> $@
118-
$(SED_INPLACE) -E '/delete : string/d' $@ # This line produces a duplicate identifier error. Why?
118+
$(REPO_ROOT)/pkg/ui/node_modules/.bin/pbts $(UI_JS) >> $@
119119

120120
$(CPP_HEADERS) $(CPP_SOURCES): $(PROTOC) $(CPP_PROTOS)
121121
(cd $(REPO_ROOT) && git ls-files --exclude-standard --cached --others -- '*.pb.h' '*.pb.cc' | xargs rm -f)
122-
$(PROTOC) -I.:$(GOGOPROTO_ROOT):$(PROTOBUF_ROOT) --cpp_out=lite:$(NATIVE_ROOT) $(CPP_PROTOS)
122+
$(PROTOC) -I.:$(GOGO_PROTOBUF_PATH):$(PROTOBUF_PATH) --cpp_out=lite:$(NATIVE_ROOT) $(CPP_PROTOS)
123123
$(SED_INPLACE) -E '/gogoproto/d' $(CPP_HEADERS) $(CPP_SOURCES)
124124
@# For c++, protoc generates a directory structure mirroring the package
125125
@# structure (and these directories must be in the include path), but cgo can

0 commit comments

Comments
 (0)