Skip to content

Commit 3d6672f

Browse files
authored
Manually vendor the required .proto files from googleapis (#2765)
This resolves some weird references to GOPATH, that while it worked, was weird (#2763). It also simplifies new user onboarding (one less instruction to follow), makes CI more lightweight (one less big repo to clone), and avoids mismatched versions of these protos from causing havoc (because they were less hermetic before).
1 parent 44e4aff commit 3d6672f

File tree

12 files changed

+676
-17
lines changed

12 files changed

+676
-17
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
* Updated golangci-lint to v1.46.1 (developers should update to this version)
1313
* Removed dependency on certificate-transparency-go
1414

15+
### Developer updates
16+
17+
* #2765 copies the required protos from `googleapis` into `third_party` in this
18+
repository. This simplifies the preconditions in order to compile the proto
19+
definitions, and removes a big dependency on `$GOPATH/src` which was archaic;
20+
`$GOPATH/src/github.com/googleapis/googleapis` is no longer required.
21+
1522
## v1.4.1
1623

1724
* `countFromInformationSchema` function to add support for MySQL 8.

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,6 @@ the original files; if you do, you'll need to install the prerequisites:
179179
go install github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc; \
180180
go install golang.org/x/tools/cmd/stringer
181181
```
182-
- protocol buffer definitions for standard Google APIs:
183-
TODO(#2763): this doesn't need to be in `GOPATH/src`.
184-
185-
```bash
186-
git clone https://github.com/googleapis/googleapis.git $(go env GOPATH)/src/github.com/googleapis/googleapis
187-
```
188182
189183
and run the following:
190184

gen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
package trillian
1616

17-
//go:generate protoc -I=. -I=$GOPATH/src/github.com/googleapis/googleapis --go_out=paths=source_relative:. --go-grpc_out=paths=source_relative:. --go-grpc_opt=require_unimplemented_servers=false trillian_log_api.proto trillian_admin_api.proto trillian.proto --doc_out=markdown,api.md:./docs/
17+
//go:generate protoc -I=. -I=third_party/googleapis --go_out=paths=source_relative:. --go-grpc_out=paths=source_relative:. --go-grpc_opt=require_unimplemented_servers=false trillian_log_api.proto trillian_admin_api.proto trillian.proto --doc_out=markdown,api.md:./docs/
1818
//go:generate protoc -I=. --go_out=paths=source_relative:. crypto/keyspb/keyspb.proto
1919

2020
//go:generate mockgen -package tmock -destination testonly/tmock/mock_log_server.go github.com/google/trillian TrillianLogServer

integration/cloudbuild/prepare.sh

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@ set -ex
55
# TODO(pavelkalinnikov): This script can be made a definitive "how to" for
66
# setting up dev environment. Eliminate duplicating these steps in many places.
77

8-
# Install Google API definitions. Some APIs are used by the protoc tool when
9-
# [re-]generating Trillian API packages from protobufs.
10-
#
11-
# TODO(pavelkalinnikov): It doesn't have to be within $GOPATH. There is no Go
12-
# code/module in this repository, and we use it only for API proto definitions.
13-
git clone --depth=1 https://github.com/googleapis/googleapis.git "$GOPATH/src/github.com/googleapis/googleapis"
14-
158
# Install the tooling used for auto-generating code. Specifically, these are the
169
# tools mentioned in //go:generate comments throughout this repository, and used
1710
# by the "go generate" command. In CI this is used for ensuring that developers

quota/etcd/quotapb/gen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414

1515
package quotapb
1616

17-
//go:generate protoc -I=. -I=$GOPATH/src/github.com/googleapis/googleapis --go_out=paths=source_relative:. --go-grpc_out=paths=source_relative:. --go-grpc_opt=require_unimplemented_servers=false quotapb.proto
17+
//go:generate protoc -I=. -I=../../../third_party/googleapis --go_out=paths=source_relative:. --go-grpc_out=paths=source_relative:. --go-grpc_opt=require_unimplemented_servers=false quotapb.proto

storage/cloudspanner/spannerpb/gen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414

1515
package spannerpb
1616

17-
//go:generate protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/googleapis/googleapis/ --go_out=paths=source_relative:. spanner.proto
17+
//go:generate protoc -I=. -I=../../../third_party/googleapis --go_out=paths=source_relative:. spanner.proto

storage/storagepb/gen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@
2424
// b) data structures are defined in the application layer.
2525
package storagepb
2626

27-
//go:generate protoc -I=. -I=$GOPATH/src --go_out=paths=source_relative:. storage.proto
27+
//go:generate protoc -I=. --go_out=paths=source_relative:. storage.proto

third_party/googleapis/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
## Purpose
2+
3+
This directory is manually vendored in order to take the required proto definitions from `googleapis`.
4+
The principle is that the dependency should be hermetic and lightweight.
5+
6+
Previously, the instructions were to manually clone the whole googleapis repository at head, into
7+
a known location.
8+
9+
## Updating
10+
11+
The required files were determined by manual inspection of the codebase and closing the
12+
transitive dependencies by checking the imports of the files.
13+
Should the upstream repository be significantly refactored then it is possible that further files
14+
may need to be imported if an update is performed.
15+
16+
The files here were cloned at commit `c81bb70`.
17+
The workflow is simple and documented here for future maintainers:
18+
```sh
19+
export GA_VERSION=c81bb701eb53991d6faf74b2656eaf539261a122
20+
mkdir -p google/api
21+
wget https://raw.githubusercontent.com/googleapis/googleapis/$GA_VERSION/google/api/annotations.proto -O google/api/annotations.proto
22+
wget https://raw.githubusercontent.com/googleapis/googleapis/$GA_VERSION/google/api/http.proto -O google/api/http.proto
23+
mkdir -p google/rpc
24+
wget https://raw.githubusercontent.com/googleapis/googleapis/$GA_VERSION/google/rpc/code.proto -O google/rpc/code.proto
25+
wget https://raw.githubusercontent.com/googleapis/googleapis/$GA_VERSION/google/rpc/status.proto -O google/rpc/status.proto
26+
```
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2015 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
syntax = "proto3";
16+
17+
package google.api;
18+
19+
import "google/api/http.proto";
20+
import "google/protobuf/descriptor.proto";
21+
22+
option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations";
23+
option java_multiple_files = true;
24+
option java_outer_classname = "AnnotationsProto";
25+
option java_package = "com.google.api";
26+
option objc_class_prefix = "GAPI";
27+
28+
extend google.protobuf.MethodOptions {
29+
// See `HttpRule`.
30+
HttpRule http = 72295728;
31+
}

0 commit comments

Comments
 (0)