@@ -10,65 +10,42 @@ if ! [[ "$0" =~ scripts/genproto.sh ]]; then
10
10
exit 255
11
11
fi
12
12
13
+ source ./scripts/test_lib.sh
14
+
13
15
if [[ $( protoc --version | cut -f2 -d' ' ) != " 3.12.3" ]]; then
14
16
echo " could not find protoc 3.12.3, is it installed + in PATH?"
15
17
exit 255
16
18
fi
17
19
18
- # directories containing protos to be built
19
- DIRS=" ./wal/walpb ./api/etcdserverpb ./etcdserver/api/snap/snappb ./raft/raftpb ./api/mvccpb ./lease/leasepb ./api/authpb ./etcdserver/api/v3lock/v3lockpb ./etcdserver/api/v3election/v3electionpb ./api/membershippb"
20
+ export GOMOD=" ./tools/mod"
21
+
22
+ run env GO111MODULE=off go get -u github.com/myitcv/gobin
20
23
21
- # disable go mod - this is for the go get/install invocations
22
- export GO111MODULE=off
24
+ GOFAST_BIN=$( tool_get_bin github.com/gogo/protobuf/protoc-gen-gofast)
25
+ GRPC_GATEWAY_BIN=$( tool_get_bin github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway)
26
+ SWAGGER_BIN=
$( tool_get_bin github.com/grpc-ecosystem/grpc-gateway/[email protected] )
27
+ GOGOPROTO_ROOT=" $( tool_pkg_dir github.com/gogo/protobuf/proto) /.."
28
+ GRPC_GATEWAY_ROOT=" $( tool_pkg_dir github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway) /.."
23
29
24
- # exact version of packages to build
25
- GOGO_PROTO_SHA=" 1adfc126b41513cc696b209667c8656ea7aac67c"
26
- GRPC_GATEWAY_SHA=" 92583770e3f01b09a0d3e9bdf64321d8bebd48f2"
27
- SCHWAG_SHA=" b7d0fc9aadaaae3d61aaadfc12e4a2f945514912"
30
+ echo
31
+ echo " Resolved binary and packages versions:"
32
+ echo " - protoc-gen-gofast: ${GOFAST_BIN} "
33
+ echo " - protoc-gen-grpc-gateway: ${GRPC_GATEWAY_BIN} "
34
+ echo " - swagger: ${SWAGGER_BIN} "
35
+ echo " - gogoproto-root: ${GOGOPROTO_ROOT} "
36
+ echo " - grpc-gateway-root: ${GRPC_GATEWAY_ROOT} "
28
37
29
- # set up self-contained GOPATH for building
30
- export GOPATH=${PWD} /gopath.proto
31
- export GOBIN=${PWD} /bin
32
- export PATH=" ${GOBIN} :${PATH} "
38
+ # directories containing protos to be built
39
+ DIRS=" ./wal/walpb ./api/etcdserverpb ./etcdserver/api/snap/snappb ./raft/raftpb ./api/mvccpb ./lease/leasepb ./api/authpb ./etcdserver/api/v3lock/v3lockpb ./etcdserver/api/v3election/v3electionpb ./api/membershippb"
33
40
34
- ETCD_IO_ROOT=" ${GOPATH} /src/go.etcd.io"
35
- ETCD_ROOT=" ${ETCD_IO_ROOT} /etcd"
36
- GOGOPROTO_ROOT=" ${GOPATH} /src/github.com/gogo/protobuf"
37
- SCHWAG_ROOT=" ${GOPATH} /src/github.com/hexfusion/schwag"
38
41
GOGOPROTO_PATH=" ${GOGOPROTO_ROOT} :${GOGOPROTO_ROOT} /protobuf"
39
- GRPC_GATEWAY_ROOT=" ${GOPATH} /src/github.com/grpc-ecosystem/grpc-gateway"
40
-
41
- function cleanup {
42
- # Remove the whole fake GOPATH which can really confuse go mod.
43
- rm -rf " ${PWD} /gopath.proto"
44
- }
45
-
46
- cleanup
47
- trap cleanup EXIT
48
-
49
- mkdir -p " ${ETCD_IO_ROOT} "
50
- ln -s " ${PWD} " " ${ETCD_ROOT} "
51
-
52
- # Ensure we have the right version of protoc-gen-gogo by building it every time.
53
- # TODO(jonboulle): vendor this instead of `go get`ting it.
54
- go get -u github.com/gogo/protobuf/{proto,protoc-gen-gogo,gogoproto}
55
- go get -u golang.org/x/tools/cmd/goimports
56
- pushd " ${GOGOPROTO_ROOT} "
57
- git reset --hard " ${GOGO_PROTO_SHA} "
58
- make install
59
- popd
60
-
61
- # generate gateway code
62
- go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
63
- go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
64
- pushd " ${GRPC_GATEWAY_ROOT} "
65
- git reset --hard " ${GRPC_GATEWAY_SHA} "
66
- go install ./protoc-gen-grpc-gateway
67
- popd
42
+
43
+ log_callout -e " \nRunning gofast proto generation..."
68
44
69
45
for dir in ${DIRS} ; do
70
- pushd " ${dir} "
71
- protoc --gofast_out=plugins=grpc,import_prefix=go.etcd.io/:. -I=" .:${GOGOPROTO_PATH} :${ETCD_IO_ROOT} :${GRPC_GATEWAY_ROOT} /third_party/googleapis" ./* .proto
46
+ run pushd " ${dir} "
47
+ run protoc --gofast_out=plugins=grpc,import_prefix=go.etcd.io/:. -I=" .:${GOGOPROTO_PATH} :${ETCD_ROOT_DIR} /..:${GRPC_GATEWAY_ROOT} /third_party/googleapis" \
48
+ --plugin=" ${GOFAST_BIN} " ./* .proto
72
49
# shellcheck disable=SC1117
73
50
sed -i.bak -E ' s/go\.etcd\.io\/(gogoproto|github\.com|golang\.org|google\.golang\.org)/\1/g' ./* .pb.go
74
51
# shellcheck disable=SC1117
@@ -86,30 +63,30 @@ for dir in ${DIRS}; do
86
63
# shellcheck disable=SC1117
87
64
sed -i.bak -E " s|go.etcd.io/etcd/v3/api|go.etcd.io/etcd/api/v3|g" ./* .pb.go
88
65
rm -f ./* .bak
89
- gofmt -s -w ./* .pb.go
90
- goimports -w ./* .pb.go
91
- popd
66
+ run gofmt -s -w ./* .pb.go
67
+ run goimports -w ./* .pb.go
68
+ run popd
92
69
done
93
70
71
+ log_callout -e " \nRunning swagger & grpc_gateway proto generation..."
72
+
94
73
# remove old swagger files so it's obvious whether the files fail to generate
95
74
rm -rf Documentation/dev-guide/apispec/swagger/* json
96
75
for pb in api/etcdserverpb/rpc etcdserver/api/v3lock/v3lockpb/v3lock etcdserver/api/v3election/v3electionpb/v3election; do
97
76
protobase=" ${pb} "
98
- protoc -I. \
77
+ run protoc -I. \
99
78
-I" ${GRPC_GATEWAY_ROOT} " /third_party/googleapis \
100
79
-I" ${GOGOPROTO_PATH} " \
101
- -I" ${ETCD_IO_ROOT} " \
80
+ -I" ${ETCD_ROOT_DIR} /.. " \
102
81
--grpc-gateway_out=logtostderr=true:. \
103
82
--swagger_out=logtostderr=true:./Documentation/dev-guide/apispec/swagger/. \
83
+ --plugin=" ${SWAGGER_BIN} " --plugin=" ${GRPC_GATEWAY_BIN} " \
104
84
${protobase} .proto
105
85
# hack to move gw files around so client won't include them
106
86
pkgpath=$( dirname " ${protobase} " )
107
87
pkg=$( basename " ${pkgpath} " )
108
88
gwfile=" ${protobase} .pb.gw.go"
109
89
110
- echo " >>> $gwfile "
111
- head -n 30 " $gwfile "
112
-
113
90
sed -i.bak -E " s/package $pkg /package gw/g" ${gwfile}
114
91
# shellcheck disable=SC1117
115
92
sed -i.bak -E " s/protoReq /&$pkg \./g" ${gwfile}
@@ -125,52 +102,36 @@ for pb in api/etcdserverpb/rpc etcdserver/api/v3lock/v3lockpb/v3lock etcdserver/
125
102
# shellcheck disable=SC1117
126
103
sed -i.bak -E " s|go.etcd.io/etcd/v3/api|go.etcd.io/etcd/api/v3|g" ${gwfile}
127
104
mkdir -p " ${pkgpath} " /gw/
128
- go fmt ${gwfile}
105
+ run go fmt ${gwfile}
129
106
mv ${gwfile} " ${pkgpath} /gw/"
130
107
rm -f ./${protobase} * .bak
131
108
swaggerName=$( basename ${protobase} )
132
- mv Documentation/dev-guide/apispec/swagger/${protobase} .swagger.json \
109
+ run mv Documentation/dev-guide/apispec/swagger/${protobase} .swagger.json \
133
110
Documentation/dev-guide/apispec/swagger/" ${swaggerName} " .swagger.json
134
111
done
135
- rm -rf Documentation/dev-guide/apispec/swagger/etcdserver/
136
-
137
- # append security to swagger spec
138
- go get -u " github.com/hexfusion/schwag"
139
- pushd " ${SCHWAG_ROOT} "
140
- git reset --hard " ${SCHWAG_SHA} "
141
- go install .
142
- popd
143
- schwag -input=Documentation/dev-guide/apispec/swagger/rpc.swagger.json
144
-
145
- # install protodoc
146
- # go get -v -u go.etcd.io/protodoc
147
- #
148
- # run './scripts/genproto.sh --skip-protodoc'
149
- # to skip protodoc generation
150
- #
112
+
113
+ log_callout -e " \nRunning swagger ..."
114
+ run_go_tool github.com/hexfusion/schwag -input=Documentation/dev-guide/apispec/swagger/rpc.swagger.json
115
+
151
116
if [ " $1 " != " --skip-protodoc" ]; then
152
- echo " protodoc is auto-generating grpc API reference documentation..."
153
- go get -v -u go.etcd.io/protodoc
154
- SHA_PROTODOC=" 484ab544e116302a9a6021cc7c427d334132e94a"
155
- PROTODOC_PATH=" ${GOPATH} /src/go.etcd.io/protodoc"
156
- pushd " ${PROTODOC_PATH} "
157
- git reset --hard " ${SHA_PROTODOC} "
158
- go install
159
- echo " protodoc is updated"
160
- popd
161
-
162
- protodoc --directories=" api/etcdserverpb=service_message,api/mvccpb=service_message,lease/leasepb=service_message,api/authpb=service_message" \
117
+ log_callout " protodoc is auto-generating grpc API reference documentation..."
118
+
119
+ run rm -rf Documentation/dev-guide/api_reference_v3.md
120
+ run_go_tool go.etcd.io/protodoc --directories=" api/etcdserverpb=service_message,api/mvccpb=service_message,lease/leasepb=service_message,api/authpb=service_message" \
163
121
--title=" etcd API Reference" \
164
122
--output=" Documentation/dev-guide/api_reference_v3.md" \
165
123
--message-only-from-this-file=" api/etcdserverpb/rpc.proto" \
166
- --disclaimer=" This is a generated documentation. Please read the proto files for more."
124
+ --disclaimer=" This is a generated documentation. Please read the proto files for more." || exit 2
167
125
168
- protodoc --directories=" etcdserver/api/v3lock/v3lockpb=service_message,etcdserver/api/v3election/v3electionpb=service_message,api/mvccpb=service_message" \
126
+ run rm -rf Documentation/dev-guide/api_concurrency_reference_v3.md
127
+ run_go_tool go.etcd.io/protodoc --directories=" etcdserver/api/v3lock/v3lockpb=service_message,etcdserver/api/v3election/v3electionpb=service_message,api/mvccpb=service_message" \
169
128
--title=" etcd concurrency API Reference" \
170
129
--output=" Documentation/dev-guide/api_concurrency_reference_v3.md" \
171
- --disclaimer=" This is a generated documentation. Please read the proto files for more."
130
+ --disclaimer=" This is a generated documentation. Please read the proto files for more." || exit 2
172
131
173
- echo " protodoc is finished.. ."
132
+ log_success " protodoc is finished."
174
133
else
175
- echo " skipping grpc API reference document auto-generation..."
134
+ log_warning " skipping grpc API reference document auto-generation..."
176
135
fi
136
+
137
+ log_success -e " \n./genproto SUCCESS"
0 commit comments