Commit Graph

279 Commits

Author SHA1 Message Date
Joe Tsai
4532dd7969 internal/fileinit: prevent map entry descriptors from implementing MessageType
The protobuf type system hacks the representation of map entries into that
of a pseudo-message descriptor.

Previously, we made all message descriptors implement MessageType
where type descriptors had a GoType method that simply returned nil.
Unfortunately, this violates a nice property in the Go type system
where being able to assert to a MessageType guarantees that Go type
information is truly associated with that descriptor.

This CL makes it such that message descriptors for map entries
do not implement MessageType.

Change-Id: I23873cb71fe0ab3c0befd8052830ea6e53c97ca9
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/168399
Reviewed-by: Damien Neil <dneil@google.com>
2019-03-21 17:47:49 +00:00
Herbie Ong
300cff08c7 encoding/textpb: clean up tests on Any
Remove unnecessary v1 wrapping. Change most tests to operate on message
Any directly.

Change-Id: I19bbca6c1af72894f6a292aab8ebd09e0301a260
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/168517
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2019-03-21 01:19:44 +00:00
Joe Tsai
ca46d8c924 internal/fieldnum: generate field numbers for the google.protobuf package
Generate field numbers for the well-known types,
so that encoding/jsonpb can benefit from them as well.

This CL fixes internal/cmd/generate-protos, which was silently failing
because the modulePath was not properly initialized. We fix this by
moving it to the start of the init function.

Change-Id: I87637176f29218cffa512b4baa49f39dae924061
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/168497
Reviewed-by: Herbie Ong <herbie@google.com>
2019-03-21 00:57:40 +00:00
Herbie Ong
0b0f4036db encoding/jsonpb: add support for marshaling well-known types
Also, changed MarshalOptions.Compact to Indent for consistency with v1
and to make compact as the default.

Change-Id: Id08aaa5ca5656f18e7925d2eabc0b6b055b1cebb
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/168352
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2019-03-20 23:30:00 +00:00
Herbie Ong
3a385917c0 encoding/jsonpb: change MarshalOptions.Compact option to Indent
This makes it consistent with jsonpb.MarshalOptions. This does change
the default to be in compact form.

Change-Id: I1b07f06f282c019b30f3f1cbb43f6c8cba18f385
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/168405
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2019-03-20 22:46:14 +00:00
Joe Tsai
1321a0e05b cmd/protoc-gen-go: generate descriptor proto using v2 textpb
Changes:
* Modify protoc-gen-go to use a helper from internal/impl
to print the message as text.
* Add a helper function to internal/impl that calls v2 textpb.
* Modify encoding/textpb to avoid depending on descriptor proto,
which would cause an import cycle.
* Modify internal/fileinit to populate a pseudo-internal
method on MessageDescriptor to check whether the message should
use the message set wire format. We avoid adding this to the
main MessageDescriptor interface since message sets are a
deprecated proto1 feature that we should avoid promoting.

Change-Id: Ibaf79a563af695756f11ddc4db69b38e25a8f1a7
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/168439
Reviewed-by: Herbie Ong <herbie@google.com>
2019-03-20 20:58:24 +00:00
Joe Tsai
559d47f1da cmd/protoc-gen-go: fix init order for v1 registration
The v1 registration leaks the message types out to the proto package.
When doing that, it must ensure that the reflection data structures
for those types are properly initialized first. We achieve that by
doing v1 registration at the end of the reflection init function.

Change-Id: If6df18df59d05bad50ff39c2eff6beb19e7466cc
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/168348
Reviewed-by: Damien Neil <dneil@google.com>
2019-03-20 04:16:33 +00:00
Herbie Ong
4630b3daa6 integration_test: fix race condition between stderr and stdout
Split output of stderr and stdout instead of using combined buffer.

Change-Id: I4099ebca15099e91539b3ebab6b410fc49f76ce1
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/168347
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2019-03-19 23:48:10 +00:00
Joe Tsai
b936504483 internal/legacy: guarantee one-to-one generation of wrapper types
When concurrent requests to wrap a type occurs, it is possible that
two different descriptors are created for the same Go type.
Add sufficient synchronization to ensure that one descriptor is ever
returned for one Go type.

Change-Id: Idbbca4c1877a70317b39900ae83bfc3085d4a9c5
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/168398
Reviewed-by: Herbie Ong <herbie@google.com>
2019-03-19 23:48:09 +00:00
Joe Tsai
08cd8842f1 cmd/protoc-gen-go: register with the v2 registry for descriptor
By passing the global registries to fileinit.Builder, the Build
method can register the newly constructed descriptors on our behalf.
As a result, we can stop registering with the v1 registries as well.

We only do this for descriptor proto to remove another dependency on v1.
We deliberately keep the v1 registration logic for now to make it easy
to patch away this new behavior.

Change-Id: Ic6aa8ffba3d2d0abe08a61fc5e1c9ca7668e0988
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/168000
Reviewed-by: Herbie Ong <herbie@google.com>
2019-03-19 05:04:43 +00:00
Joe Tsai
ce07f39688 internal/cmd/generate-protos: disable detrand
The .pb.go.meta file is checked into the repository as testdata.
The deliberate instability of outputs breaks golden tests within
our own repository. It is reasonable for us to depend on stability
since we control the output.

Change-Id: I1f73027a08a0757732d46610f334d40840cc4cfd
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/168001
Reviewed-by: Herbie Ong <herbie@google.com>
2019-03-19 05:04:31 +00:00
Joe Tsai
f31bf2612e cmd/protoc-gen-go: only depend on v2 proto package
This CL breaks another dependency of v2 on v1.
A missing feature in v2 is proto.Clone, but we can use a
Marshal/Unmarshal roundtrip to achieve the same effect
as a temporary stop-gap.

Change-Id: I9d0432fd3efe9fc8b34db6c5a1eabbef0c36277c
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/168217
Reviewed-by: Damien Neil <dneil@google.com>
2019-03-18 23:11:12 +00:00
Joe Tsai
8e506a8704 cmd/protoc-gen-go: rely on protoimpl for basic helpers
The EnumName, UnmarshalJSONEnum, and CompressGZIP helpers currently live
in v1 protoapi, which would cause all generated messages to depend on v1.
In an effort to break the dependency of v2 on v1, we move these helper
functions to v2 (and re-written to take advantage of protobuf reflection).

These helpers are unfortunate, but we cannot eliminate the functionality
that they implement since they are exposed in the publicly generated API.

Since EnumName does not rely on the enum maps, it removes another dependency
on those variables. Eventually, we can get to the point where these variables
(though declared) are not linked into the binary if the user does not use them.

Also, we rely on the v1 proto package for registration instead of v1 protoapi.
This may re-introduce a cyclic dependency on descriptor proto again in the
future, but the better approach is to just start registering with v2.

Change-Id: Id755585a7a1df14e4a6a2dfa650df221a3c153fb
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/167921
Reviewed-by: Damien Neil <dneil@google.com>
2019-03-18 18:50:16 +00:00
Herbie Ong
e52379a5c2 encoding/jsonpb: add support for unmarshaling extensions and messagesets
Change-Id: I7f3e0091c4f46924d2e8a08c614c7ab64917014c
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/167773
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2019-03-16 07:23:11 +00:00
Herbie Ong
e0cf15babe encoding/textpb: fix failed tests due to ordering of marshaled binary fields
Added temporary work-around for now by always using deterninistic
marshaling so that protoV1.Equals knows how to do comparison.

Change-Id: Idec412647269d59f86ed3e485a1893c070355b3d
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/167917
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2019-03-16 07:20:46 +00:00
Herbie Ong
4d1c3be76f encoding/textpb: reduce dependency on proto v1 package
Substitute protoV1.Marshal calls to use proto v2.

A few tests still need to use v1 due to missing required field checks in
v2.

Change-Id: I97ee208b81afc85c81142e70c1d7bdc47db76ce4
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/167774
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2019-03-16 01:54:17 +00:00
Herbie Ong
c96a79da29 encoding/jsonpb: add support for basic unmarshaling
Unmarshaling of scalar, messages, repeated, and maps.

Need to further improve on error messages for consistency, some error
messages contain the position info while some currently do not.  There
are cases where position info is wrong as well when a value is decoded
in another pass, e.g. numbers in string value, or map keys.

Change-Id: I6f9e903c499b5e87fb258dbdada7434389fc7522
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/166338
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2019-03-15 18:53:18 +00:00
Joe Tsai
e0f1ea4a69 encoding/textpb: remove blank line
A blank line between the docstring and the package expression prevents
godoc from recognizing the comment as the package's docstring.

Change-Id: Id3c46ec6dbadb85a9b393c34fe1f0e46ed41a447
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/167766
Reviewed-by: Herbie Ong <herbie@google.com>
2019-03-15 17:05:22 +00:00
Joe Tsai
afb455eaf8 cmd/protoc-gen-go: correlate v1 ExtensionDesc with v2 ExtensionType
Unfortunately a good amount of code uses pointer comparisons on the
v1 ExtensionDesc to determine exactly which extension field is set,
rather than checking whether the extension descriptor semantically
describes the field that they are interested in.

To preserve this behavior in v1, we need a 1:1 mapping between
a v2 ExtensionType and a specific v1 ExtensionDesc.

Change-Id: I852b3cefb4585bd656e48e5adad6cc28795d02df
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/167759
Reviewed-by: Damien Neil <dneil@google.com>
2019-03-15 01:24:42 +00:00
Joe Tsai
69996ba400 internal/legacy: use proto.Unmarshal from v2
Change-Id: Ic1e757a11f233657d6c3a840719ebef34d81e4f5
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/167716
Reviewed-by: Damien Neil <dneil@google.com>
2019-03-14 21:46:02 +00:00
Herbie Ong
f83d5bb6f0 encoding/jsonpb: add support for marshaling of extensions and messagesets
Change-Id: I839660146760a66c5cbf25d24f81f0ba5096d9e1
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/167395
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2019-03-14 20:53:14 +00:00
Damien Neil
99f24c33b0 proto: wire encoding support
Add proto.Marshal.

Change-Id: If7254bb4c4cbbee782a2a163762f9fcf98e7ab08
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/167388
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2019-03-14 19:12:27 +00:00
Damien Neil
4866b95a73 internal/impl: try to work with ExtensionDescs when legacy is absent
Don't rely on legacyWrapper.ExtensionTypeFromDesc when desc.Type
is populated. Avoids panics when working with extensions when
internal/legacy has not been imported.

Change-Id: Id41ffa3c60b6e5503d0a3e29ef48e4f523fad588
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/167465
Reviewed-by: Joe Tsai <joetsai@google.com>
2019-03-14 01:46:22 +00:00
Joe Tsai
990b9f5919 internal/prototype: move from reflect/prototype
The prototype package was initially used by generated reflection support,
but has now been replaced by internal/fileinit.
Eventually, this functionality should be deleted and re-written in terms
of other components in the repo.

Usages that prototype currently provides (but should be moved) are:
* Constructing standalone messages and enums, which is behavior we should
provide in reflect/protodesc. The google.protobuf.{Enum,Type} are well-known
proto messages designed for this purpose.
* Constructing placeholder files, enums, and messages.
* Consructing protoreflect.{Message,Enum,Extension}Types, which are protobuf
descriptors with associated Go type information.

Change-Id: Id7dbefff952682781b439aa555508c59b2629f9e
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/167383
Reviewed-by: Damien Neil <dneil@google.com>
2019-03-13 20:17:00 +00:00
Joe Tsai
cf4f80a2cc .travis.yml: configure for OSX
Change-Id: I5096dc5360f3c06c32b39ab07b8ba4f989fa5b0b
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/167377
Reviewed-by: Herbie Ong <herbie@google.com>
2019-03-13 18:04:08 +00:00
Joe Tsai
94a8510010 protogen: fix protogen_test.go
The test had a "golden" tag, which meant that it wasn't being tested.

Changes made:
* Alter the test to avoid shelling out to protoc
* Modify TestFiles to TestNoGoPackage, where the testdata files seem
concerned about making sure the lack of a go_package statement works
* Upgrade to latest cmp, which provides diffing for multiline strings
* Delete protogen/testdata directory

Change-Id: Ic576167bfce1046f45c8c614d0ab76af8c5ba723
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/167279
Reviewed-by: Damien Neil <dneil@google.com>
2019-03-13 17:12:03 +00:00
Herbie Ong
250c6eaf92 internal/encoding/text: change Value.Float{32,64} to Value.Float
Collapse Value.Float32 and Value.Float64 into single API to keep it
consistent with Value.{Int,Uint}.

Change-Id: I07737e72715fe3cc3f6bcad579cf5d6cfe3757d5
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/167317
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2019-03-13 04:35:13 +00:00
Joe Tsai
4989810018 cmd/protoc-gen-go: always generate support for reflection
Now that binary bloat concerns have been addressed, remove the flag
to control whether to generate support for reflection.

Change-Id: Ia0d11183707572caaf91d2f01dfa77e3aac0a417
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/167140
Reviewed-by: Damien Neil <dneil@google.com>
2019-03-12 23:04:05 +00:00
Joe Tsai
9e88bc0b67 test.bash: purge unused directories based on timeout
Rather than manually keeping track of which directories may be used
by other branches, use a time-based approach to determine whether
to purge a sub-directory or not.

Change-Id: I648dcca075e351e4e5624c48e73792782fc349ca
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/167042
Reviewed-by: Herbie Ong <herbie@google.com>
2019-03-12 17:29:50 +00:00
Joe Tsai
bb786ea59e test.bash: update to protobuf 3.7.0
Change-Id: Id1237eaf92d6a07c57b279a59fb6bd794af0f231
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/167041
Reviewed-by: Herbie Ong <herbie@google.com>
2019-03-12 08:34:56 +00:00
Joe Tsai
d9bfe8bc52 all: fix travis after v1 update
Change-Id: I3194f4d2e57903d7ae0d6c20bae551dc6ab7d8ce
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/166891
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2019-03-12 00:05:04 +00:00
Joe Tsai
8692540cce go.mod: re-add go.mod file
Change-Id: I3aa495eccec26ec14d102d1b41901516c7238929
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/166887
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2019-03-11 23:42:37 +00:00
Joe Tsai
61d82d9a7d go.mod: temporarily delete go.mod file
Change-Id: I23933890226513318f13094009167aa7922361b4
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/166885
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2019-03-11 23:38:35 +00:00
Herbie Ong
87608a75eb encoding/jsonpb: switch MarshalOptions to use new JSON encoder
Delete temporary copy of old JSON encoder/decoder internal/encoding/jsonx.

Change-Id: I8b23d7907370d069d0930c360979a2d8b62adc93
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/165778
Reviewed-by: Damien Neil <dneil@google.com>
2019-03-11 21:54:53 +00:00
Joe Tsai
a7a0de8747 go.sum: temporarily delete go.sum file
Change-Id: I052b54d6c7843cd3dbb7d4da00cea6aa0fc06212
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/167000
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2019-03-11 21:54:37 +00:00
Herbie Ong
d3f8f2d412 internal/encoding/json: rewrite to a token-based encoder and decoder
Previous decoder decodes a JSON number into a float64, which lacks
64-bit integer precision.

I attempted to retrofit it with storing the raw bytes and parsed out
number parts, see golang.org/cl/164377.  While that is possible, the
encoding logic for Value is not symmetrical with the decoding logic and
can be confusing since both utilizes the same Value struct.

Joe and I decided that it would be better to rewrite the JSON encoder
and decoder to be token-based instead, removing the need for sharing a
model type plus making it more efficient.

Change-Id: Ic0601428a824be4e20141623409ab4d92b6167c7
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/165677
Reviewed-by: Damien Neil <dneil@google.com>
2019-03-11 21:53:21 +00:00
Joe Tsai
9d8c804b55 go.sum: purge unused dependencies
Change-Id: Ide440311b62cdbb3f4b64b032cf01cf21f98cba7
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/166997
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2019-03-11 21:48:45 +00:00
Joe Tsai
22b1ebd068 internal/impl: split messageWrapper into different types
The previous implementation of messageWrapper implemented both
proto.Message and protoreflect.Message. This made it possible for users
to accidentally rely on this fact when it was actually an internal
implementation detail.

To avoid this, we split the wrapper type into two, ensuring that each
only implements one or the other. Doing so also revealed bugs in our
own code where we accidentally relied on this fact.

Change-Id: I0ff521b5c806b7dcb0b86942bd97e8319d8e8657
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/166938
Reviewed-by: Damien Neil <dneil@google.com>
2019-03-11 21:23:31 +00:00
Joe Tsai
c93f494f4a cmd/protoc-gen-go/testdata: ignore go.sum
The go.sum is not particularly important for the testdata directory,
so ignore it.

Change-Id: I069613deda2af4944d09aed34008fec201df6bb4
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/166879
Reviewed-by: Herbie Ong <herbie@google.com>
2019-03-11 20:19:03 +00:00
Joe Tsai
d56458e71b internal/cmd/generate-protos: generate test for testdata
Running "go build ./..." does not descend into testdata directories.
However, the testdata in this repository is source code that is
intended to build properly. We could rename the directory, but that does
not test whether the generated packages can initialize properly.

Thus, we generate a trivial test that simply blank imports all packages.

Doing this reveals that some of the generated files have incorrect imports,
leading to registration conflicts.

To avoid introducing a dependency on gRPC from our go.mod file, we put
the testdata directories in their own module. Also, we avoid running
internal/testprotos through the grpc plugin because the servie and method
definitions in that directory are more for testing proto file initialization
rather than testing grpc generation.

Change-Id: Iaa6a06449787a085200e31bc7606e3ac904d3180
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/164917
Reviewed-by: Damien Neil <dneil@google.com>
2019-03-11 19:40:53 +00:00
Joe Tsai
beda404070 protogen: drop dependency on golang.org/x/tools/go/ast/astutil
To keep the dependency tree of Go protobufs as small as possible,
avoid depending on astutil. Most of the complexity of astutil.AddNamedImport
was for identifying an existing import block to insert imports into,
which is not relevant for our use-case.

Assuming that we always create a new import block after the package
statement, the logic for doing the AST manipulation is relatively simple.
This re-write properly handles an inline comment after the
package statement, which astutil.AddNamedImport (see golang.org/issue/30724)
currently fails to do.

Change-Id: I894e733aa82a241719b6f0c23de8d2fbfb67b778
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/166522
Reviewed-by: Damien Neil <dneil@google.com>
2019-03-11 19:34:12 +00:00
Damien Neil
0fc224513b cmd/protoc-gen-go: enforce init order within packages
Ensure that the init funcs for files within a Go package run in the
dependency order of the source .proto files. That is, if a.proto and b.proto
are part of the same Go package, and a.proto imports b.proto, then b.pb.go's
init funcs must run before a.pb.go's.

Change-Id: I0e86ff22e5c4cab9df7a73fe4805390fadd34b0d
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/166419
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Herbie Ong <herbie@google.com>
2019-03-10 22:19:14 +00:00
Herbie Ong
db6ad14102 encoding/textpb: add package doc
Change-Id: I678785de4a227b7df2807b297a7bd40b5459d499
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/166418
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2019-03-10 03:14:08 +00:00
Joe Tsai
f398784f99 .travis.yml: fix travis CI
Changes made:
* Call autogen.sh before building protobuf.
It's unclear how this worked before, but the README instructions for
protobuf does state to run autogen.sh prior to building and installing.
* Fix downloadArchive to take in a prefix path rather than the number of
prefix directories to skip. The reason for this change is due to a bug
in the Go build system where unexpected directories were being packed.
See https://golang.org/issue/29906
* Explicitly set Travis dist to be "xenial", which comes with Go1.11.
We require Go1.11 for two reasons:
	* The use of t.Helper in integration_test.go
	* Proper understanding of the -mod=vendor flag
	(even if all that flag does is disable modules).
* Add a hack to integration_test.go to periodically output the timestamp
to work around a restriction in Travis where it auto-kills the test
after 10 minutes of no stdout activity.

Change-Id: I114fe2855faeed091c34d79df3d97068be7eccd8
Reviewed-on: https://go-review.googlesource.com/c/164919
Reviewed-by: Herbie Ong <herbie@google.com>
2019-03-03 00:55:36 +00:00
Joe Tsai
1af1de0c15 internal/cmd/generate-protos: generate internal descfield package
Generate a list of descriptor fields from the descriptor.proto itself
as an internal package. Use these fields for the internal implementation.

Change-Id: Ib1ab0c5c6deb332ba6c8018ef55136b7e5974944
Reviewed-on: https://go-review.googlesource.com/c/164864
Reviewed-by: Herbie Ong <herbie@google.com>
2019-03-02 23:16:45 +00:00
Herbie Ong
4b465c007f test.bash: limit running go test to integration_test.go only
Change-Id: Ib2e96183b99deddbbd3132cd2ca6fa34a25994c6
Reviewed-on: https://go-review.googlesource.com/c/164645
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2019-03-02 04:09:19 +00:00
Herbie Ong
1e1e78b71b internal/encoding/jsonx: copy internal/encoding/json
We're rewriting internal/encoding/json. So, make a copy of it first in
order not to break encoding/jsonpb package.

Change-Id: I8b63c468d3f432102d2af4db22a7549998ce3876
Reviewed-on: https://go-review.googlesource.com/c/164642
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2019-03-02 00:23:28 +00:00
Joe Tsai
707894e869 test.bash: rewrite the integration test in Go
This CL switches the integration test to be written in Go instead of bash.
The benefits are:
* The logic for setting up the dependencies is more robust and
handles better a situation where the dependency failed to initialize
(due to network trouble, FS permission problems, etc).
* The logic does a better job at cleaning up stale dependencies.
For example, my .cache folder has go1.9.4, go1.9.5, go1.10.5, and go1.10.6
folders even though we don't use them anymore.
* Being able to run only a subset of the integration test since you can
pass "-run" to the script.
* A signifcant amount of complexity in the test.bash script was running
the tests in parallel. This is trivial to do in Go.

The major detriment is that Go is more verbose as a "scripting" language.

Change-Id: Id7e5b303fb305fdbc0368bdf809dbf29fca1d983
Reviewed-on: https://go-review.googlesource.com/c/164861
Reviewed-by: Herbie Ong <herbie@google.com>
2019-03-02 00:04:20 +00:00
Damien Neil
6bb8dec7f6 cmd/protoc-gen-go: change some arrays to slices to save bytes
Using arrays in the generated reflection information adds unnecessary
eq and hash functions being added to the package. Change to slices
to reduce bloat.

Change-Id: I1a4f6d59021644d93dd6c24679b9233141e89a75
Reviewed-on: https://go-review.googlesource.com/c/164640
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2019-03-01 23:53:03 +00:00
Joe Tsai
19058431cd internal/cmd/generate-protos: initial commit
Create a single binary for handling generation of protos.
This replaces previous logic spread throughout the repo in:
* regenerate.bash
* cmd/protoc-gen-go/golden_test.go
* cmd/protoc-gen-go-grpc/golden_test.go
* (indirectly) internal/protogen/goldentest

One of the problems with the former approaches is that they relied on
a version of protoc that was specific to a developer's workstation.
This meant that the result of generation was not hermetic.
To address this, we rely on the hard-coded version of protobuf specified
in the test.bash script.

A summary of changes in this CL are:
* The internal_gengo.GenerateFile and internal_gengogrpc.GenerateFile
functions are unified to have consistent signatures. It seems that the
former accepted a *protogen.GeneratedFile to support v1 where gRPC code
was generated into the same file as the base .pb.go file. However, the
same functionality can be achieved by having the function return
the generated file object.
* The test.bash script patches the protobuf toolchain to have properly
specified go_package options in each proto source file.
* The test.bash script accepts a "-regenerate" argument.
* Add generation for the well-known types. Contrary to how these were
laid out in the v1 repo, all the well-known types are placed in the
same Go package.
* Add generation for the conformance proto.
* Remove regenerate.bash
* Remove internal/protogen
* Remove cmd/protoc-gen-go/golden_test.go
* Remove cmd/protoc-gen-go-grpc/golden_test.go
* Add cmd/protoc-gen-go/annotation_test.go

Change-Id: I4a1a97ae6f66e2fabcf4e4d292c95ab2a2db0248
Reviewed-on: https://go-review.googlesource.com/c/164477
Reviewed-by: Damien Neil <dneil@google.com>
2019-03-01 20:47:52 +00:00