Commit Graph

16 Commits

Author SHA1 Message Date
Joe Tsai
42fa50da34 test.bash: do not run golden tests by default
The golden tests are sensitive to the exact version used:
* Protobuf toolchain since the generated Descriptor is dependendent on protoc
(for example, default json_names were auto-populated in later versions of protoc)
* Go toolchain since the generated .pb.go files is dependent on the exact output
of gofmt and the gzip compression used.

There are other areas where it depends on unstable output, but the above are the
major causes.

Since test.bash ensures that the golden tests are run with exact versions of the
protobuf and Go toolchains, we can ensure that the tests are reproducible across
different developer workstations.

Thus, we add a "golden" build tag to disable them for normal invocations of
"go test ./..." and only run them if test.bash is run.

If test.bash is ever updated with newer versions, the golden testdata can be
updated at the same time.

Change-Id: Ia2b7b039aad2ddaef7652e332215bf9403a6d856
Reviewed-on: https://go-review.googlesource.com/c/142458
Reviewed-by: Damien Neil <dneil@google.com>
2018-10-16 16:49:18 +00:00
Joe Tsai
a85e9569ed test.bash: update to go1.10.4 and go1.11.1
Change-Id: Ib593768cb30fab41ff93e90cc12401e3b7126e6c
Reviewed-on: https://go-review.googlesource.com/c/142457
Reviewed-by: Damien Neil <dneil@google.com>
2018-10-16 16:43:44 +00:00
Damien Neil
2dc6718b59 cmd/protoc-gen-go-grpc: add gRPC code generator
This is a straight translation of the v1 API gRPC "plugin" to protogen.

Add a protoc-gen-go-grpc command. The preferred way to generate gRPC
services is to invoke both plugins separately:

  protoc --go_out=. --go-grpc_out=. foo.proto

When invoked in this fashion, the generators will produce separate
foo.pb.go and foo_grpc.pb.go files.

Change-Id: Ie180385dab3da7063db96f7c2f9de3abbd749f63
Reviewed-on: https://go-review.googlesource.com/137037
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2018-09-27 19:32:34 +00:00
Joe Tsai
b4af2c62e0 test.bash: set GOPATH before running go list
The "go list" command is used only to get the module name.
However, just invoking the command results in a series of network IO
fetching package information about dependencies.
That information is then placed in the default GOPATH,
which previously was the system's default.

This is not generally a problem, but results in additional time spent
in Travis since the system's GOPATH is not cached between test runs.
By setting the GOPATH beforehand to be within TEST_DIR, we can ensure
that the result is cached and preserved between runs.

Change-Id: Ib750a9a31b9891b354fe9a70b3f592d949186ba3
Reviewed-on: https://go-review.googlesource.com/136738
Reviewed-by: Damien Neil <dneil@google.com>
2018-09-24 16:06:15 +00:00
Joe Tsai
ded92f8033 reflect/prototype: lower minimum support to Go1.9
The minimum supported version is currently Go1.10 since we use strings.Builder
for a fairly significant optimization when constructing all of the descriptor
full names.

The strings.Builder implementation is not particularly complicated,
so just fork it into our code. The golang/protobuf and the golang/go
projects share the same authors and copyright license.

Change-Id: Ibb9519dbe756327a07369f10f80c15761002b5e7
Reviewed-on: https://go-review.googlesource.com/136735
Reviewed-by: Damien Neil <dneil@google.com>
2018-09-21 19:30:05 +00:00
Damien Neil
a6c374a8f1 cmd/protoc-gen-go: add test data for proto3 extensions
Change-Id: I2d47db2c177553dc2a3dacc66c70db579c1145fd
Reviewed-on: https://go-review.googlesource.com/136535
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2018-09-20 19:56:44 +00:00
Joe Tsai
f8505dac3f test.bash: use repo-local cache
Use a local ".cache" directory in the repository root for the cache
instead of a directory in /tmp. On many operating systems, files are arbitrarily
purged as part of the OS' cleanup procedures, leading to obscure failures.

Since the build cache is in the repo root, we adjust the invocation of gofmt
to only act upon the set of Go files tracked by git.

Change-Id: I10cd0ea0de3370ea25fcd3870451fb41c4204a4b
Reviewed-on: https://go-review.googlesource.com/133875
Reviewed-by: Damien Neil <dneil@google.com>
2018-09-06 19:58:40 +00:00
Joe Tsai
9f9e0ee48a test.bash: use go1.11
Change-Id: Ia0b76eba666738e477d3a7403aee2dc16dd8e0f9
Reviewed-on: https://go-review.googlesource.com/131344
Reviewed-by: Herbie Ong <herbie@google.com>
2018-08-25 06:39:00 +00:00
Joe Tsai
c046d8696c test.bash: use go1.11rc2
Change-Id: I5228fc8156a1a2800cab5b753f97dc542d520ba5
Reviewed-on: https://go-review.googlesource.com/131155
Reviewed-by: Herbie Ong <herbie@google.com>
2018-08-24 00:06:45 +00:00
Joe Tsai
913ace2501 test.bash: more test script improvements
Changes made:
* create a /bin directory for symlinks and prepend it to the PATH
* include the "go" prefix in the Go toolchain versions
* move setting up GOPATH before calling "go mod vendor" since modules dump their
results inside a special directory within the GOPATH
* setup a per-version Go cache to 1) work around a bug in the toolchain and
2) to allow Travis to also cache this state
* factor out common logic into a check function that ensures stdout is empty

Change-Id: I9400452b85a66f019cb616aaded33610f2c1eb2f
Reviewed-on: https://go-review.googlesource.com/129402
Reviewed-by: Herbie Ong <herbie@google.com>
2018-08-15 19:47:50 +00:00
Joe Tsai
bfda014ecd reflect/prototype: initial commit
The prototype package provides constructors to create protobuf types that
implement the interfaces defined in the protoreflect package.

High-level API:
	func NewFile(t *File) (protoreflect.FileDescriptor, error)
	type File struct{ ... }
	type Message struct{ ... }
	type Field struct{ ... }
	type Oneof struct{ ... }
	type Enum struct{ ... }
	type EnumValue struct{ ... }
	type Extension struct{ ... }
	type Service struct{ ... }
	type Method struct{ ... }

	func NewEnum(t *StandaloneEnum) (protoreflect.EnumDescriptor, error)
	func NewMessage(t *StandaloneMessage) (protoreflect.MessageDescriptor, error)
	func NewExtension(t *StandaloneExtension) (protoreflect.ExtensionDescriptor, error)
	type StandaloneEnum struct{ ... }
	type StandaloneMessage struct{ ... }
	type StandaloneExtension struct{ ... }

	func PlaceholderFile(path string, pkg protoreflect.FullName) protoreflect.FileDescriptor
	func PlaceholderEnum(name protoreflect.FullName) protoreflect.EnumDescriptor
	func PlaceholderMessage(name protoreflect.FullName) protoreflect.MessageDescriptor

This CL is missing some features that are to be added later:
* The stringer methods are not implemented, providing no way to print the
descriptors in a humanly readable manner.
* There is no support for proto options or retrieving the raw descriptor.
* There are constructors for Go specific types (e.g., protoreflect.MessageType).

We drop go1.9 support since we use strings.Builder.
We switch to go.11rc1 to obtain some bug fixes for modules.

Change-Id: Ieac9a2530afc81e5a5bb9ab5816804372f652b18
Reviewed-on: https://go-review.googlesource.com/129057
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Herbie Ong <herbie@google.com>
2018-08-15 18:44:04 +00:00
Joe Tsai
dbc9a12dbd reflect/protoreflect: initial commit
Package protoreflect provides APIs for programatically interacting with messages
according to the protobuf type system.

Change-Id: I11fa3874e4b3f94771514c69efb2ae8bb812d7fa
Reviewed-on: https://go-review.googlesource.com/127823
Reviewed-by: Damien Neil <dneil@google.com>
2018-08-10 19:59:50 +00:00
Joe Tsai
ea04a135cc test.bash: test harness improvements
Modify the test harness to run Go tests concurrently.
This vastly speeds up execution time on machines with many cores.

Other changes:
* Some stylistic changes to make the output colored and more readable.
* Add protoc and conformance-test-runner to the $PATH
* Check that Go source files were properly formatted

Change-Id: I5d7e14defeef32c587e6f8e2f66367143413a41f
Reviewed-on: https://go-review.googlesource.com/128415
Reviewed-by: Herbie Ong <herbie@google.com>
2018-08-08 01:37:21 +00:00
Joe Tsai
d1e65e6634 test.bash: unset GOROOT to fix Travis-CI
When Travis-CI runs the test.bash, it unnecessarily pollutes the environment
with a GOROOT environment variable, which confuses each of the custom invocations
of different Go toolchains. Rather than setting the GOROOT prior to each
invocation of the Go toolchain, just clear the variable once, and let each
toolchain figure out the root for themselves (which all recent versions of Go
know how to do so correctly).

Change-Id: I45ae9f9f98f5573ff42502b7244c90bf1569f66e
Reviewed-on: https://go-review.googlesource.com/128363
Reviewed-by: Herbie Ong <herbie@google.com>
2018-08-07 22:31:19 +00:00
Joe Tsai
ed2fbe0328 test.bash: download dependencies
Use module support in Go1.11 to download the exact version of dependencies
as specified in the go.mod file, this is contrary to "go get -u", which grabs
the latest version, making reproducible builds and tests difficult.

In order for Go1.9 and Go1.10 to work, we also emit a vendor directory for
pre-module support.

Lastly, check whether the go.mod or go.sum files changed
(by shelling to "git diff"). This provides protection in case
a new dependency was added and the go.mod file was not updated.

Change-Id: Iac4e9b224ca9188dc9e63be720f188bfb5ee56ef
Reviewed-on: https://go-review.googlesource.com/127916
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2018-08-07 21:43:44 +00:00
Joe Tsai
1bed4543ed test.bash: add script for comprehensive testing
This script is not currently executed by Try-Bots since they do not have the
necessary infrastructure, yet. Instead, this script is intended to be ran as
a pre-commit hook on each contributor's workstation.

The test.bash script works on both Darwin and Linux and tests the repository
across a variety of Go toolchains. The toolchains are downloaded and built
into their own versioned directories and cached. Subsequent runs of the script
only need to run the tests.

Change-Id: Id87841ed42da422ab2e966ea073255ba866c80f7
Reviewed-on: https://go-review.googlesource.com/127826
Reviewed-by: Herbie Ong <herbie@google.com>
2018-08-04 06:21:23 +00:00