932 Commits

Author SHA1 Message Date
Damien Neil
50a85913fb all: build Windows protoc-gen-go as a .exe in a zip
Add a .exe suffix to the protoc-gen-go Windows binary.
Use zip instead of tar for the Windows release archive.

Fixes golang/protobuf#1323

Change-Id: If42fa6dfd8b5496148310fa2a3359161f1124229
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/321530
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2021-05-20 19:40:23 +00:00
Damien Neil
24d799b3c1 internal/impl: support typed nil source for Merge of aberrant messages
When merging aberrant messages with legacy Marshal and Unmarshal
methods, check for a typed nil source before calling Marshal.

Add an aberrant message with Marshal/Unmarshal methods to
internal/testprotos/nullable and use it to test the internal/impl
support for these methods.

Fixes golang/protobuf#1324

Change-Id: Ib6ce85b30b46e3392a226ca6abe411932a371f02
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/321529
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2021-05-20 18:23:20 +00:00
sryoya
0e358a402f reflect/protorange: fix typo of func name in comment
Change-Id: I80ffc34e29757e0cbdccdd530404fa215cfaf75f
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/317989
Reviewed-by: Alberto Donizetti <alb.donizetti@gmail.com>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
Trust: Alberto Donizetti <alb.donizetti@gmail.com>
2021-05-07 17:05:00 +00:00
Joe Tsai
c30776bb3b encoding/prototext: fix skipping of unknown fields
Inside decoder.skipValue we should not be calling skipValue again
since we had already read the value earlier. The only possible
composite type in the context of a list is another message,
which is already handled in the case above.

Change-Id: If40da2d369e0a64a64ba9b961377331231158fe2
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/317430
Trust: Joe Tsai <joetsai@digital-static.net>
Trust: Herbie Ong <herbie@google.com>
Reviewed-by: Herbie Ong <herbie@google.com>
2021-05-06 20:07:56 +00:00
Joe Tsai
fb30439f55 testing/protopack: add Message.UnmarshalAbductive
The protobuf wire format is insufficiently self-decribing such that
it is impossible to know whether for sure whether an unknown bytes value
is a sub-message or not. However, protopack is primarily used for debugging
where a best-effort guess is still very useful.

The Message.UnmarshalAbductive unmarshals an unknown bytes value as a message
if it is syntactically well-formed. Otherwise, it is left as is.

Change-Id: I5e2b4b995e2b5eb60942a242558bf4cea1da9891
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/309669
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
2021-04-14 20:38:42 +00:00
Aliaksandr Mianzhynski
fc9592f7ac cmd/protoc-gen-go: add protoc suffix
Change-Id: Ib09bd3cbd15088d534de34b08d01a4d7a4880c0a
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/306209
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
Trust: Damien Neil <dneil@google.com>
2021-04-08 23:03:09 +00:00
Joe Tsai
e4fcb9f7e7 reflect: add protopath and protorange packages
The protopath package provides a means to programmatically represent
a sequence of protobuf reflection operations.
The protorange package traverses through a message and
calls a user-provided function as it iterates.

This feature sets the groundwork for the often requested feature
of being able to exclude certain fields when merging or serializing.

package protopath
    type Path []Step
    type Step struct{ ... }
        func Root(protoreflect.MessageDescriptor) Step
        func FieldAccess(protoreflect.FieldDescriptor) Step
        func UnknownAccess() Step
        func ListIndex(int) Step
        func MapIndex(protoreflect.MapKey) Step
        func AnyExpand(protoreflect.MessageDescriptor) Step
        func (Step) Kind() StepKind
        func (Step) FieldDescriptor() protoreflect.FieldDescriptor
        func (Step) MessageDescriptor() protoreflect.MessageDescriptor
        func (Step) ListIndex() int
        func (Step) MapIndex() protoreflect.MapKey
        func (Step) String() string
    type StepKind int
        const RootStep StepKind
        const FieldAccessStep StepKind
        const UnknownAccessStep StepKind
        const ListIndexStep StepKind
        const MapIndexStep StepKind
        const AnyExpandStep StepKind
    type Values struct {
        Path   Path
        Values []protoreflect.Value
    }
    func (Values) Index(int) (out struct{ ... })
    func (Values) Len() int
    func (Values) String() string

package protorange
    var Break error
    var Terminate error
    func Range(protoreflect.Message, func(protopath.Values) error) error
    type Options struct {
        Stable bool
        Resolver interface { ... }
    }
    func (Options) Range(m protoreflect.Message, push, pop func(protopath.Values) error) error

Change-Id: I29cbd5142fe169d78367d54a95d37801888b64f4
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/236540
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
2021-04-01 23:09:19 +00:00
Joe Tsai
31610fd913 cmd/protoc-gen-go: remove generation of the ExtensionRangeArray method
The ExtensionRangeArray was a pseudo-internal API that was used by
the protobuf runtime implementation to know what the extension ranges are.
For some time now, the runtime implementation does not make use of this.

According to all the latest modules known by the module proxy,
no code depends directly on this method being present.

In the extremely rare case where some user code is depending on this method,
the user can place a .go file next to the generated .pb.go file that
injects this method.

Change-Id: Iae40a9a33b8c9b5a243d48db14f25b05ca24e3dc
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/305574
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-29 20:25:28 +00:00
Joe Tsai
f821cae922 all: start v1.26.0-devel
Change-Id: I544bd53c41794d5da2d381d3b182293a465f3c4b
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/302753
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-18 00:28:12 +00:00
Joe Tsai
f2d1f6cbe1 all: release v1.26.0
Change-Id: I15ecd5b768516fd2382cfbc8b337ad3d8817deab
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/302752
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
v1.26.0
2021-03-18 00:27:53 +00:00
Joe Tsai
41ef85a559 all: add weak dependency on github.com/golang/protobuf
Add back the weak dependency on github.com/golang/protobuf.

Change-Id: I2e6fabbe2cac3b694fb56a86bb3aa85cc8615b42
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/262684
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-18 00:24:57 +00:00
Joe Tsai
bdf6e19f23 all: start v1.26.0-rc.1.devel
Change-Id: I46da1bbedc2a0e53de1b02b07c5d6b76a18e1894
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/302751
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-17 22:45:59 +00:00
Joe Tsai
1c57cacb03 all: release v1.26.0-rc.1
Change-Id: I849df1819bf980fea006516beba4a551696e3811
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/302750
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
v1.26.0-rc.1
2021-03-17 22:45:34 +00:00
Joe Tsai
b7197c14de all: remove weak dependency on github.com/golang/protobuf
Temporarily remove the dependency on github.com/golang/protobuf
and add it back in a subsequent CL. This allows us to break some of
the infinite cycles of old versions in the go.sum file.

Change-Id: Ifb5c2c160713d47a43ba2bcedc18ebe2ce33dcea
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/262683
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-17 21:55:02 +00:00
Joe Tsai
e471641887 cmd/protoc-gen-go: support --help flag
When someone has no idea what a binary does, it is convention to
pass the "--help" flag. When done, we should point the user
to the devsite documentation on protoc with protoc-gen-go.

Change-Id: I36289a1ae025b9e12521b34362370aba5235a44b
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/302330
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-16 20:24:12 +00:00
Joe Tsai
174b9ecfe3 all: document that Unmarshal must be a mutable message
Fixes #937

Change-Id: I40b2678eba0195ed01676167f8e01e2fedea293b
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/302329
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-16 20:06:34 +00:00
Joe Tsai
8b366e8807 compiler/protogen: require that the import path be specified
Since the release of v1.20, we have warned that it be required
that the import path for every generated package be specified.
This CL simplifies the mechanism for specifying such information
to just the "M" command-line flags and the "go_package" options
in the .proto source files, where the former takes precedence
over the latter.

Changes made:
* Remove "import_prefix" and "import_path" flags.
* Make the Go import path and package name derivation logic simpler
where both "M" flags and "go_package" options are parsed the same way
by calling the common splitImportPathAndPackageName function, and
where "M" flags take precedence over "go_package" options.
The exception to this occurs when neither "M" nor "go_package" specify
an explicit Go package name, where the derivation may be non-intuitive.
See the "NOTE" comment for the rationale for this behavior,
which actually matches what was already the case.
* Remove the pathTypeLegacy output mode and make pathTypeImport
the default. The pathTypeLegacy mode becomes even more non-sensible
now that we require that the import path always be provided.
* Remove the baseName function. After deleting unsupported functionality,
this seems to only be used by GeneratedFile.QualifiedGoIdent.
However, that method does not need to create stable package names
since they are only used locally within the generated file.
They only need to guarantee the property of validity and uniqueness.
* Remove the warn function since there are no more warnings.

Change-Id: Ic95fb3cde5ffcb71bbcc829fcff34369758cebef
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/301953
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-16 18:59:04 +00:00
Joe Tsai
23ccb359e1 internal/impl: add runtime support for aberrant messages
Implement support in the protobuf runtime to better understand
message types that are not generated by the official generator.

In particular:
* Add a best-effort implementation of protobuf reflection for
"non-nullable" fields which are supposed to be represented by *T,
but are instead represented by a T. "Non-nullable" message fields
report presence based on whether the message is the zero Go value.
* We do NOT implement support for "non-nullable" fields in the
table-driven implementation since we assume that the aberrant messages
that we care about have a Marshal and Unmarshal method.
* We better handle custom messages that implement Marshal and Unmarshal,
but do NOT implement Merge. In that case, we implement merge in terms of
a back-to-back marshal and unmarshal.
* We better tolerate the situations where a protobuf message field
cannot be mapped to a Go struct field since the latter is missing.
In such cases, reflection treats the field as if it were unpopulated.
Setting such fields will panic.

This change allows the runtime to handle all message types declared
in the "go.etcd.io/etcd" and "k8s.io" modules where protobuf reflection,
Marshal, Unmarshal, Reset, Merge, and Equal all work.

The only types that still do not fully work are:
	* "k8s.io/api/authentication/v1".ExtraValue
	* "k8s.io/api/authentication/v1beta1".ExtraValue
	* "k8s.io/api/authorization/v1".ExtraValue
	* "k8s.io/api/authorization/v1beta1".ExtraValue
	* "k8s.io/api/certificates/v1".ExtraValue
	* "k8s.io/api/certificates/v1beta1".ExtraValue
	* "k8s.io/apimachinery/pkg/apis/meta/v1".MicroTime
	* "k8s.io/apimachinery/pkg/apis/meta/v1".Time
	* "k8s.io/apimachinery/pkg/apis/meta/v1".Verbs
While Marshal, Unmarshal, Reset, and Merge continue to work,
protobuf reflection and any functionality that depends on it
(e.g., prototext, protojson, Equal, etc.) will not work.

Change-Id: I67a9d2f1bec35248045ad0c16220d02fc2e0e172
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/300869
Trust: Joe Tsai <joetsai@digital-static.net>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-16 02:41:12 +00:00
Joe Tsai
e31c6dd73d cmd/protoc-gen-go: print version to stdout
Fixes #1279

Change-Id: I2f5459087c915cd1fc1e38ccbaa7c44b0f286137
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/301952
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-16 00:13:35 +00:00
Joe Tsai
e7ab1125a6 all: switch to GitHub actions
Travis-CI is dead. The new hotness if GitHub actions.
For now we only test on Linux since testing on macOS and Windows
takes more effort to figure out.

Change-Id: I464df75b9142dafcdf07281f70c1bcf52514f71a
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/298089
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-11 19:23:10 +00:00
Joe Tsai
731520d340 all: update to use Go1.16.1
Change-Id: I9d899131c09f16b4de7cbece8099aa463eec0f75
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/298049
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-11 19:04:25 +00:00
Joe Tsai
839ce43689 internal/filedesc: remove ProtoLegacyRawDesc method
This method existed in the past to avoid a cyclic dependency
on descriptorpb from the legacy proto package.
This restriction no longer applies.

Change-Id: I5c61fa7de370063a126d8ea15c376b0882417b43
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/259900
Reviewed-by: Damien Neil <dneil@google.com>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
2021-03-03 02:26:38 +00:00
Joe Tsai
85f47621e0 all: update protobuf toolchain dependency
This updates the dependency on the protobuf toolchain to an unreleased
version that has the go_package option for relevant .proto files in
that repository to reference this module.

Change-Id: Ie1ac8f81a323285efbd14a17d02c7105e810af2d
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/235283
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-03 01:59:11 +00:00
Joe Tsai
77dfd04893 reflect/protoregistry: add compile-time opt-out for registration conflicts
The next release of this module will panic on registration conflicts.
While we have been warning that this will become a fatal error for about
a year now, it's almost certainly the case that some users still have
ambiguous registrations.

In addition to the GOLANG_PROTOBUF_REGISTRATION_CONFLICT environment variable,
also define a linker-initialized variable that users can set.

Change-Id: I3325d841b9b6c692e2862100d81aebdcfda069fc
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/295349
Trust: Joe Tsai <joetsai@digital-static.net>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
2021-03-02 23:29:07 +00:00
Justin SB
9d4d1ca5ed internal/descfmt: always include type name in FormatList
FormatList previously formatted output inconsistently when called on
EnumDescriptors, ServiceDescriptors and ExtensionDescriptors: other
types included the type name before {{; these types did not.

Add a default case that includes the type in these (and any other)
cases also.

Expanded tests to demonstrate and verify the new behaviour.

Change-Id: I9f53cb6548c4448a12c17d519639357ebdfa809b
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/286132
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
Trust: Joe Tsai <joetsai@google.com>
Trust: Matthew Dempsky <mdempsky@google.com>
2021-02-22 23:39:21 +00:00
cybrcodr
f1ac97a4c3 internal/encoding/json: fix comments
Change-Id: Ia1414d1a6c4edcacc141f0c927ad1f9f0012843a
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/285552
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
Trust: Herbie Ong <herbie@google.com>
2021-01-21 23:58:14 +00:00
Julie Qiu
160c7477e0 README.md: remove /mod from badge URL
Change-Id: I856048c70041287c7f71d26c20b4c565b3abe61e
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/276052
Trust: Julie Qiu <julie@golang.org>
Run-TryBot: Julie Qiu <julie@golang.org>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2020-12-08 04:14:24 +00:00
Julie Qiu
50abaed3ee README.md: update badge SVG
The badge SVG is updated to the official badge for pkg.go.dev.

Change-Id: Ib9f09e1661ee18f854786098ff3528d4175cf0cb
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/275935
Trust: Julie Qiu <julie@golang.org>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
Run-TryBot: Julie Qiu <julie@golang.org>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2020-12-07 23:21:37 +00:00
Damien Neil
81d297c66c internal/fuzz: support coverage builds with oss-fuzz
Use OSS-Fuzz's new compile_go_fuzzer script, which enables code
coverage.

Change-Id: Iff07ac09d054e8c881d819b4ce6d016ad2808978
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/272768
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Joe Tsai <joetsai@google.com>
2020-11-24 20:15:59 +00:00
Joe Tsai
d347099942 internal/cmd/generate-types: use ConsumeBytes instead of ConsumeString
The protowire.{ConsumeBytes,ConsumeString} funcs are identical except
that the latter allocates a string by implicitly converting the []byte.
Avoid using ConsumeString since we can do the conversion ourselves
at a latter point and sometimes avoid the allocation.

Change-Id: Idf31edc013b72ee5ee8461a68d10e57ad461d95c
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/263628
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
2020-10-20 20:17:50 +00:00
Joe Tsai
41134b7e06 internal/cmd/generate-types: name the options variable
This trivially adds a name for marshalOptions and unmarshalOptions
instead of always having it be underscore.
This assists the use of patches that rely on this variable.

Change-Id: I4c23901c93f0362aff412339912522f92749d659
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/263627
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
2020-10-20 19:16:57 +00:00
Joe Tsai
44626bc40b internal/cmd/generate-types: move variable declaration
Move the declaration of the slice variable
as close to its actual use as possible.

Change-Id: Ibe26460b5ca81edbed1073b32faf1c5f5d2c922a
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/263719
Trust: Joe Tsai <joetsai@digital-static.net>
Trust: Joe Tsai <joetsai@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
2020-10-20 18:59:00 +00:00
Joe Tsai
f0affd4123 internal/cmd/generate-types: add outfile flag
Add an outfile flag that specifies that the contents of
the provided file should generated to stdout.
When using this mode, it only generates one file at a time
and does not modify any files on disk.

Change-Id: I80ba1764a7f0ceb180b8b54f4197dd57fec86434
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/263625
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Patrik Nyblom <pnyb@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
2020-10-20 18:45:18 +00:00
Joe Tsai
aa45c46752 reflect/protoregistry: panic upon registration conflicts
In this CL, we switch the behavior of registration conflicts
from simply logging a warning to panicking.
This is a change that we have warned about ever since
the release of v1.20.0 in 2020-03-02.

For users that have not fixed their dependencies or are unable to,
they may set the GOLANG_PROTOBUF_REGISTRATION_CONFLICT environment
to "warn" in order to obtain the prior behavior of simply logging
and ignoring subsequent conflicts (first wins).

Change-Id: Ied7937f0fd5cb5d875858411714ebeb5ce145574
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/235298
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
2020-10-16 22:00:47 +00:00
Damien Neil
711224230b internal/encoding/text: escape Unicode control characters in strings
Escape not only ASCII control characters, but Unicode as well.

Change-Id: I5f5791ae51fc5624599f66ce012ecef364e7ea97
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/262682
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Joe Tsai <joetsai@google.com>
2020-10-15 23:10:26 +00:00
Damien Neil
b1cd8e38bc internal/encoding/text: escape \x7f (DEL) in strings
We already escape ASCII control characters in the range [0x00,0x20).
Escape the one control character outside this range as well.

Change-Id: If954da0d4a178b36128d1a53d25397d1b3fd2e17
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/262681
Trust: Damien Neil <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
2020-10-15 21:51:19 +00:00
Joe Tsai
9712361eda all: rely on dynamic dependency check for genproto
The genproto module incurs an unfortunate amount of dependency bloat
since it has a relatively large set of transitive dependencies.
Even though these are brought in as a weak dependency
(i.e., there is no hard code dependency on genproto),
it complicates dependency inspection since users need to vet
modules that they may not actually be using.

Avoid this weak dependency and instead rely on a dynamic check
to ensure that a sufficiently new version of genproto is used.
While it can't statically prevent old versions of genproto from being
linked into a binary, it guarantees that it will panic at init
with a helpful message on what's wrong.

Change-Id: I2b5a9759a5cd4c4c57aced54278502b1b6352ba7
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/262679
Trust: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
2020-10-15 21:46:17 +00:00
Tzu-Chiao Yeh
f62736dede proto/equal: reduce equal scalar value allocation
Instead of lifting values to interface and then do equality test,
compare scalar values with defined types to reduce allocation
from interface.

Change-Id: Ieb777fbd1a48c83d896d0ebe6ad605433f44c16c
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/253100
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
Trust: Damien Neil <dneil@google.com>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
2020-10-08 23:42:17 +00:00
Joe Tsai
53a58a916f cmd/protoc-gen-go: remove unused protoV1Package variable
The logic that formerly depended on this was deleted in
https://golang.org/cl/259901. This is dead code now.

Updates golang/protobuf#1077

Change-Id: Ieb1b14243d9503b1baac7026c6ce226923873405
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/260817
Trust: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
2020-10-08 21:11:27 +00:00
Joe Tsai
687df2333b reflect/protodesc: fix round-tripping for package field
If a .proto file does not have a package statement,
then protoc will not populate the package field.
Emulate the same behavior for ToFileDescriptorProto.

Fixes golang/protobuf#1195

Change-Id: I617102e50c96f0fa1bac6a6bc4de1cc485750bb9
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/259899
Reviewed-by: Damien Neil <dneil@google.com>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
2020-10-07 22:44:53 +00:00
Joe Tsai
4394568c4b cmd/protoc-gen-go: remove reference to legacy ProtoPackageIsVersion4
A reference to this constant was originally generated to ensure that users
were using a sufficiently new version of the github.com/golnag/protobuf
module to avoid subtle runtime incompatibility issues.
Such a technique is not needed if users were using modules,
which would enforce this constraint based on our go.mod requirements.

When we first released the google.golang.org/protobuf module,
we suggested that we would consider removing it after 6 months.
It has now been 7 months since the release.

Fixes golang/protobuf#1077

Change-Id: I9f2010da27b27fe6b12541a15833721441df8409
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/259901
Reviewed-by: Damien Neil <dneil@google.com>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
2020-10-07 22:34:28 +00:00
Joe Tsai
ac374a2335 internal/encoding/messageset: fix spelling typo
Change-Id: Ic397fba6b382fbbe72779aa919f9109c23c8f209
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/259898
Reviewed-by: Damien Neil <dneil@google.com>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
2020-10-07 22:15:00 +00:00
Joe Tsai
db5c900f0c all: fix touching of dependency directories
Adjust the setup script in integration_test.go to better keep
track of what directories are in current use.
Previously, the staticcheck directory was not tracked as used,
causing it to be deleted unnecessarily.

We ensure consistent tracking, but having each depedency setup step
start with a startWork call, and end with a finishWork call.

Change-Id: I4f5d929f323509237f4f44ed8f57d71b8756f031
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/253617
Reviewed-by: Damien Neil <dneil@google.com>
2020-09-08 20:20:17 +00:00
Joe Tsai
5ebc0b43aa all: drop 386 support for darwin
Darwin 1.15 no longer supports i386 code execution.
Stop supporting it.

See https://support.apple.com/en-us/HT208436
See http://golang.org/issue/34749

Change-Id: I2d1f3cb933ee2555aa95c72b1cba7ca3847e0146
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/253618
Reviewed-by: Damien Neil <dneil@google.com>
2020-09-08 20:15:21 +00:00
Joe Tsai
0fd4f3a506 encoding/protojson: restrict valid values for google.protobuf.Value.number_value
The purpose of struct.proto is to be an exact mapping of JSON in protobufs.
Since JSON doesn't support NaN and Inf, we should reject serialization
of such values. Prior to this CL, they would be serialzed as a JSON string,
which would change the interpretation of the value when round-tripped.

Fixes golang/protobuf#1182

Change-Id: I6dba9973b1c24d99e5688b509611c0a952c00022
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/247737
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Herbie Ong <herbie@google.com>
2020-09-04 00:11:24 +00:00
Joe Tsai
16365ed3d8 all: update to go1.13.15, go1.14.7, and go1.15
Change-Id: I9675b6e1196afb185fab1c2d650894cf68b325e5
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/248277
Reviewed-by: Damien Neil <dneil@google.com>
2020-08-17 16:53:14 +00:00
Joe Tsai
1a3946737f internal/encoding/text: remove dead code
The newline field is unused. Remove it.

Change-Id: I8a6c6ea64eff718920102b87aa1fc66d8e736ac7
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/248297
Reviewed-by: Herbie Ong <herbie@google.com>
2020-08-12 21:05:01 +00:00
Joe Tsai
a180de9f97 testing/protocmp: fix representation of empty bytes
The protoreflect API does not use the distinction between nil and non-nil
empty []byte to preserve presence. As such, avoid accidentally presenting
such information through the transformation.

Change-Id: Ia46b5e2d3fb534d7cd29f478ad47722bfaa06810
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/247458
Reviewed-by: Damien Neil <dneil@google.com>
2020-08-08 01:16:14 +00:00
Joe Tsai
e96d591a68 internal/msgfmt: fix formatting of negative Duration
If the seconds is zero, but the nanoseconds are negative,
there should still be a leading negative sign.

Change-Id: Ia72a26bc3455a80e572b6bf2ff41395381f811c7
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/247457
Reviewed-by: Herbie Ong <herbie@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
2020-08-08 01:07:43 +00:00
Joe Tsai
f2423bb714 encoding/protojson: simplify Duration formatting
Simplify the implementation by reducing the number of branches.

Change-Id: I6e2ffee0fc2d77f7e2a70f76e03d081f4fc0e99d
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/247459
Reviewed-by: Herbie Ong <herbie@google.com>
2020-08-08 00:59:21 +00:00