diff --git a/.github/workflows/objc_cocoapods.yml b/.github/workflows/objc_cocoapods.yml new file mode 100644 index 0000000000..dd330a880b --- /dev/null +++ b/.github/workflows/objc_cocoapods.yml @@ -0,0 +1,36 @@ +name: 'ObjC CocoaPods' + +on: + push: + paths: + - '.github/workflows/objc_cocoapods.yml' + - 'Protobuf.podspec' + - 'objectivec/**' + - '!objectivec/DevTools/**' + - '!objectivec/ProtocolBuffers_*.xcodeproj/**' + - '!objectivec/Tests/**' + pull_request: + paths: + - '.github/workflows/objc_cocoapods.yml' + - 'Protobuf.podspec' + - 'objectivec/**' + - '!objectivec/DevTools/**' + - '!objectivec/ProtocolBuffers_*.xcodeproj/**' + - '!objectivec/Tests/**' + +jobs: + pod-lib-lint: + runs-on: macos-latest + strategy: + fail-fast: false + matrix: + PLATFORM: ["ios", "macos", "tvos", "watchos"] + CONFIGURATION: ["Debug", "Release"] + steps: + - uses: actions/checkout@v2 + - name: Pod lib lint + run: | + pod lib lint --verbose \ + --configuration=${{ matrix.CONFIGURATION }} \ + --platforms=${{ matrix.PLATFORM }} \ + Protobuf.podspec diff --git a/BUILD b/BUILD index e437626514..83ba240113 100644 --- a/BUILD +++ b/BUILD @@ -2,6 +2,7 @@ load("@bazel_skylib//rules:common_settings.bzl", "string_flag") load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test", "objc_library", native_cc_proto_library = "cc_proto_library") +load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain", "proto_library") load("@rules_python//python:defs.bzl", "py_library") load("@rules_java//java:defs.bzl", "java_binary", "java_lite_proto_library", "java_proto_library") @@ -530,7 +531,10 @@ cc_binary( filegroup( name = "testdata", srcs = glob(["src/google/protobuf/testdata/**/*"]), - visibility = ["//:__subpackages__"], + visibility = [ + "//:__subpackages__", + "@upb//:__subpackages__", + ], ) RELATIVE_LITE_TEST_PROTOS = [ @@ -892,13 +896,23 @@ py_library( [ "python/google/protobuf/**/*.py", ], - exclude = [ + ), + imports = ["python"], + srcs_version = "PY2AND3", + visibility = ["@upb//:__subpackages__"], +) + +py_library( + name = "python_test_srcs", + srcs = glob( + [ "python/google/protobuf/internal/*_test.py", "python/google/protobuf/internal/test_util.py", ], ), imports = ["python"], - srcs_version = "PY2AND3", + srcs_version = "PY3", + visibility = ["@upb//:__subpackages__"], ) cc_binary( @@ -995,9 +1009,21 @@ internal_copied_filegroup( COPIED_WELL_KNOWN_PROTOS = ["python/" + s[4:] for s in WELL_KNOWN_PROTOS] py_proto_library( - name = "protobuf_python", + name = "well_known_types_py_pb2", srcs = COPIED_WELL_KNOWN_PROTOS, include = "python", + default_runtime = "", + protoc = ":protoc", + srcs_version = "PY2AND3", + visibility = ["@upb//:__subpackages__"], +) + +py_library( + name = "protobuf_python", + deps = [ + ":well_known_types_py_pb2", + ":python_srcs", + ], data = select({ "//conditions:default": [], ":use_fast_cpp_protos": [ @@ -1005,13 +1031,6 @@ py_proto_library( ":python/google/protobuf/pyext/_message.so", ], }), - default_runtime = "", - protoc = ":protoc", - py_libs = [ - ":python_srcs", - ], - srcs_version = "PY2AND3", - visibility = ["//visibility:public"], ) # Copy the test proto files from src/google/protobuf to @@ -1039,7 +1058,8 @@ py_proto_library( default_runtime = "", protoc = ":protoc", srcs_version = "PY2AND3", - deps = [":protobuf_python"], + deps = [":well_known_types_py_pb2"], + visibility = ["//visibility:public"], ) py_proto_library( @@ -1053,6 +1073,7 @@ py_proto_library( protoc = ":protoc", srcs_version = "PY2AND3", deps = [":python_common_test_protos"], + visibility = ["//visibility:public"], ) py_library( @@ -1445,3 +1466,140 @@ internal_gen_kt_protos( visibility = ["//java:__subpackages__"], deps = [":kt_proto3_unittest"], ) + +################################################################################ +# Packaging rules +################################################################################ + +# Files included in all source distributions +pkg_files( + name = "common_dist_files", + srcs = glob([ + "*.bzl", + "cmake/*.cmake", + "cmake/*.in", + "editors/*", + + # Several of these files are generated by autogen.sh, so using + # glob() lets us ignore them if they are missing. (This is not good + # practice, though.) + "Makefile.in", + "aclocal.m4", + "ar-lib", + "compile", + "config*", + "depcomp", + "install-sh", + "ltmain.sh", + "m4/*.m4", + "missing", + "protobuf*.pc.in", + "test-driver", + ]) + [ + "BUILD", + "CHANGES.txt", + "CMakeLists.txt", + "CONTRIBUTORS.txt", + "LICENSE", + "Makefile.am", + "README.md", + "WORKSPACE", + "autogen.sh", + "build_files_updated_unittest.sh", + "cmake/CMakeLists.txt", + "cmake/README.md", + "generate_descriptor_proto.sh", + "maven_install.json", + "update_file_lists.sh", + "//third_party:zlib.BUILD", + "//util/python:BUILD", + ], + strip_prefix = strip_prefix.from_root(""), + visibility = ["//pkg:__pkg__"], +) + +# Conformance tests +pkg_files( + name = "conformance_dist_files", + srcs = glob( + ["conformance/**/*"], + exclude = [ + # The following are not in autotools dist: + "conformance/autoload.php", + "conformance/conformance_nodejs.js", + "conformance/conformance_test_runner.sh", + "conformance/failure_list_java_lite.txt", + "conformance/failure_list_jruby.txt", + "conformance/text_format_failure_list_*.txt", + "conformance/update_failure_list.py", + ], + ), + strip_prefix = strip_prefix.from_root(""), + visibility = ["//pkg:__pkg__"], +) + +# C++ runtime +pkg_files( + name = "cpp_dist_files", + srcs = glob( + ["src/**/*"], + exclude = [ + "src/google/protobuf/compiler/objectivec/method_dump.sh", # not in autotools dist + ], + ), + strip_prefix = strip_prefix.from_root(""), + visibility = ["//pkg:__pkg__"], +) + +# Additional files for C# +pkg_files( + name = "csharp_dist_files", + srcs = [ + "global.json", + ], + visibility = ["//pkg:__pkg__"], +) + +# Additional files for ObjC +pkg_files( + name = "objectivec_dist_files", + srcs = [ + "Protobuf.podspec", + ], + visibility = ["//pkg:__pkg__"], +) + +# Additional files for PHP +pkg_files( + name = "php_dist_files", + srcs = [ + "composer.json", + ], + visibility = ["//pkg:__pkg__"], +) + +# Python runtime +pkg_files( + name = "python_dist_files", + srcs = glob([ + "python/google/**/*.proto", + "python/google/**/*.py", + "python/google/protobuf/internal/*.cc", + "python/google/protobuf/pyext/*.cc", + "python/google/protobuf/pyext/*.h", + ]) + [ + "python/MANIFEST.in", + "python/README.md", + "python/google/protobuf/proto_api.h", + "python/google/protobuf/pyext/README", + "python/google/protobuf/python_protobuf.h", + "python/mox.py", + "python/release.sh", + "python/setup.cfg", + "python/setup.py", + "python/stubout.py", + "python/tox.ini", + ], + strip_prefix = strip_prefix.from_root(""), + visibility = ["//pkg:__pkg__"], +) diff --git a/CHANGES.txt b/CHANGES.txt index 8d7f98acf2..5f6e297cd3 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,35 +1,41 @@ Unreleased Changes (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) - Compiler - * Require package names to be less than 512 bytes in length - -2022-04-05 version 3.20.1 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) - PHP * Fix building packaged PHP extension (#9727) + * Fixed composer.json to only advertise compatibility with PHP 7.0+. (#9819) + + Ruby + * Disable the aarch64 build on macOS until it can be fixed. (#9816) Other * Fix versioning issues in 3.20.0 -Unreleased Changes - -C++ + C++ * Refactor generated message class layout * Optimize tokenizer ParseInteger by removing division * Reserve exactly the right amount of capacity in ExtensionSet::MergeFrom -Compiler + Compiler * Protoc outputs the list of suggested field numbers when invalid field numbers are specified in the .proto file. + * Require package names to be less than 512 bytes in length -Java + Java * 6x speedup in ArrayEncoder.writeUInt32NotTag -Python + Python * Added UnknownFieldSet(message) for pure Python. The old message.UnknownFields() will be deprecated after UnknownFieldSet(message) is added for cpp extension. +2022-04-21 version 3.20.1 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) + + PHP + * Fix building packaged PHP extension (#9727) + + Other + * Fix versioning issues in 3.20.0 + 2022-03-04 version 3.20.0 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript) Ruby @@ -97,6 +103,8 @@ Python JSON serializations with UTF-8 or other non-ASCII encodings. * Added experimental support for directly assigning numpy scalars and array. * Improve the calculation of public_dependencies in DescriptorPool. + * [Breaking Change] Disallow setting fields to numpy singleton arrays or repeated fields to numpy + multi-dimensional arrays. Numpy arrays should be indexed or flattened explicitly before assignment. Compiler * Migrate IsDefault(const std::string*) and UnsafeSetDefault(const std::string*) diff --git a/Protobuf.podspec b/Protobuf.podspec index 6c6b37bfcc..3a5132d090 100644 --- a/Protobuf.podspec +++ b/Protobuf.podspec @@ -5,7 +5,7 @@ # dependent projects use the :git notation to refer to the library. Pod::Spec.new do |s| s.name = 'Protobuf' - s.version = '3.20.1-rc1' + s.version = '3.20.1' s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.' s.homepage = 'https://github.com/protocolbuffers/protobuf' s.license = 'BSD-3-Clause' @@ -39,4 +39,12 @@ Pod::Spec.new do |s| s.tvos.deployment_target = '9.0' s.watchos.deployment_target = '2.0' s.requires_arc = false + + # The unittest need the generate sources from the testing related .proto + # files. So to add a `test_spec`, there would also need to be something like a + # `script_phases` to generate them, but there would also need to be a way to + # ensure `protoc` had be built. Another option would be to move to a model + # where the needed files are always generated and checked in. Neither of these + # seem that great at the moment, so the tests have *not* been wired into here + # at this time. end diff --git a/WORKSPACE b/WORKSPACE index 36df3f3371..d01122a90a 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -66,3 +66,6 @@ kotlin_repositories() load("@io_bazel_rules_kotlin//kotlin:core.bzl", "kt_register_toolchains") kt_register_toolchains() + +load("@upb//bazel:workspace_deps.bzl", "upb_deps") +upb_deps() diff --git a/benchmarks/BUILD b/benchmarks/BUILD index 8e6063ba83..2f7b4c749f 100644 --- a/benchmarks/BUILD +++ b/benchmarks/BUILD @@ -1,5 +1,6 @@ load("@rules_cc//cc:defs.bzl", "cc_proto_library") load("@rules_java//java:defs.bzl", "java_proto_library") +load("@rules_pkg//:mappings.bzl", "pkg_filegroup", "pkg_files", "strip_prefix") load("@rules_proto//proto:defs.bzl", "proto_library") proto_library( @@ -63,3 +64,36 @@ java_proto_library( "google_size_proto", ], ) + +pkg_files( + name = "dist_files", + srcs = glob( + [ + "*", + "python/*.cc", + "util/*.cc", + ], + exclude = [ + "__init__.py", # not in autotools dist + "BUILD", + "go/*", + ], + ), + strip_prefix = strip_prefix.from_root(""), +) + +# Convenience filegroup for all files that should be packaged. +pkg_filegroup( + name = "all_dist_files", + srcs = [ + ":dist_files", + "//benchmarks/cpp:dist_files", + # "//benchmarks/datasets:dist_files", # not in autotools dist + "//benchmarks/datasets/google_message1/proto2:dist_files", + "//benchmarks/datasets/google_message1/proto3:dist_files", + "//benchmarks/datasets/google_message2:dist_files", + "//benchmarks/datasets/google_message3:dist_files", + "//benchmarks/datasets/google_message4:dist_files", + ], + visibility = ["//pkg:__pkg__"], +) diff --git a/benchmarks/cpp/BUILD b/benchmarks/cpp/BUILD index b744f896ad..ba93f641e5 100644 --- a/benchmarks/cpp/BUILD +++ b/benchmarks/cpp/BUILD @@ -1,4 +1,5 @@ load("@rules_cc//cc:defs.bzl", "cc_binary") +load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") cc_binary( name = "cpp", @@ -13,3 +14,10 @@ cc_binary( "@com_github_google_benchmark//:benchmark_main", ], ) + +pkg_files( + name = "dist_files", + srcs = ["cpp_benchmark.cc"], + strip_prefix = strip_prefix.from_root(""), + visibility = ["//benchmarks:__pkg__"], +) diff --git a/benchmarks/datasets/BUILD b/benchmarks/datasets/BUILD index f29a27650b..1cb11bddad 100644 --- a/benchmarks/datasets/BUILD +++ b/benchmarks/datasets/BUILD @@ -1,5 +1,6 @@ load("@rules_cc//cc:defs.bzl", "cc_library") load("@rules_java//java:defs.bzl", "java_library") +load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") load("@rules_proto//proto:defs.bzl", "proto_library") filegroup( @@ -57,3 +58,10 @@ java_library( "//benchmarks/datasets/google_message4:benchmark_message4_java_proto", ], ) + +pkg_files( + name = "dist_files", + srcs = ["BUILD"], + strip_prefix = strip_prefix.from_root(""), + visibility = ["//benchmarks:__pkg__"], +) diff --git a/benchmarks/datasets/google_message1/proto2/BUILD b/benchmarks/datasets/google_message1/proto2/BUILD index d4d38cec22..e3159327b9 100644 --- a/benchmarks/datasets/google_message1/proto2/BUILD +++ b/benchmarks/datasets/google_message1/proto2/BUILD @@ -1,5 +1,6 @@ load("@rules_cc//cc:defs.bzl", "cc_proto_library") load("@rules_java//java:defs.bzl", "java_proto_library") +load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") load("@rules_proto//proto:defs.bzl", "proto_library") filegroup( @@ -42,3 +43,10 @@ java_proto_library( "benchmark_message1_proto2_proto", ], ) + +pkg_files( + name = "dist_files", + srcs = glob(["*.proto"]), + strip_prefix = strip_prefix.from_root(""), + visibility = ["//benchmarks:__pkg__"], +) diff --git a/benchmarks/datasets/google_message1/proto3/BUILD b/benchmarks/datasets/google_message1/proto3/BUILD index c2d627acd8..2628d020aa 100644 --- a/benchmarks/datasets/google_message1/proto3/BUILD +++ b/benchmarks/datasets/google_message1/proto3/BUILD @@ -1,6 +1,7 @@ load("@rules_cc//cc:defs.bzl", "cc_proto_library") load("@rules_java//java:defs.bzl", "java_proto_library") load("@rules_proto//proto:defs.bzl", "proto_library") +load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") filegroup( name = "datasets", @@ -42,3 +43,10 @@ java_proto_library( "benchmark_message1_proto3_proto", ], ) + +pkg_files( + name = "dist_files", + srcs = glob(["*.proto"]), + strip_prefix = strip_prefix.from_root(""), + visibility = ["//benchmarks:__pkg__"], +) diff --git a/benchmarks/datasets/google_message2/BUILD b/benchmarks/datasets/google_message2/BUILD index 1ca87fb64f..a3208d08c3 100644 --- a/benchmarks/datasets/google_message2/BUILD +++ b/benchmarks/datasets/google_message2/BUILD @@ -1,5 +1,6 @@ load("@rules_cc//cc:defs.bzl", "cc_proto_library") load("@rules_java//java:defs.bzl", "java_proto_library") +load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") load("@rules_proto//proto:defs.bzl", "proto_library") filegroup( @@ -42,3 +43,10 @@ java_proto_library( "benchmark_message2_proto", ], ) + +pkg_files( + name = "dist_files", + srcs = glob(["*.proto"]), + strip_prefix = strip_prefix.from_root(""), + visibility = ["//benchmarks:__pkg__"], +) diff --git a/benchmarks/datasets/google_message3/BUILD b/benchmarks/datasets/google_message3/BUILD index 9a00294464..130c8749b3 100644 --- a/benchmarks/datasets/google_message3/BUILD +++ b/benchmarks/datasets/google_message3/BUILD @@ -1,5 +1,6 @@ load("@rules_cc//cc:defs.bzl", "cc_proto_library") load("@rules_java//java:defs.bzl", "java_proto_library") +load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") load("@rules_proto//proto:defs.bzl", "proto_library") filegroup( @@ -48,3 +49,10 @@ java_proto_library( "benchmark_message3_proto", ], ) + +pkg_files( + name = "dist_files", + srcs = glob(["*.proto"]), + strip_prefix = strip_prefix.from_root(""), + visibility = ["//benchmarks:__pkg__"], +) diff --git a/benchmarks/datasets/google_message4/BUILD b/benchmarks/datasets/google_message4/BUILD index b23a4c955c..9c7190d93b 100644 --- a/benchmarks/datasets/google_message4/BUILD +++ b/benchmarks/datasets/google_message4/BUILD @@ -1,5 +1,6 @@ load("@rules_cc//cc:defs.bzl", "cc_proto_library") load("@rules_java//java:defs.bzl", "java_proto_library") +load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") load("@rules_proto//proto:defs.bzl", "proto_library") filegroup( @@ -43,3 +44,10 @@ java_proto_library( "benchmark_message4_proto", ], ) + +pkg_files( + name = "dist_files", + srcs = glob(["*.proto"]), + strip_prefix = strip_prefix.from_root(""), + visibility = ["//benchmarks:__pkg__"], +) diff --git a/csharp/BUILD b/csharp/BUILD new file mode 100644 index 0000000000..6d31ba0cc6 --- /dev/null +++ b/csharp/BUILD @@ -0,0 +1,34 @@ +# Protobuf C# runtime +# +# See also code generation logic under /src/google/protobuf/compiler/csharp. + +load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") + +pkg_files( + name = "dist_files", + srcs = glob([ + "keys/*", + "protos/*", + "src/**/*.cs*", # .cs and .csproj + ]) + [ + ".editorconfig", + ".gitignore", + "BUILD", + "CHANGES.txt", + "Google.Protobuf.Tools.nuspec", + "Google.Protobuf.Tools.targets", + "NuGet.Config", + "README.md", + "build_packages.bat", + "build_tools.sh", + "buildall.bat", + "buildall.sh", + "generate_protos.sh", + "install_dotnet_sdk.ps1", + "src/Google.Protobuf.Benchmarks/wrapper_benchmark_messages.proto", + "src/Google.Protobuf.Test/testprotos.pb", + "src/Google.Protobuf.sln", + ], + strip_prefix = strip_prefix.from_root(""), + visibility = ["//pkg:__pkg__"], +) diff --git a/csharp/Google.Protobuf.Tools.nuspec b/csharp/Google.Protobuf.Tools.nuspec index 29b698e182..1d34a5e2d7 100644 --- a/csharp/Google.Protobuf.Tools.nuspec +++ b/csharp/Google.Protobuf.Tools.nuspec @@ -5,7 +5,7 @@ Google Protocol Buffers tools Tools for Protocol Buffers - Google's data interchange format. See project site for more info. - 3.20.1-rc1 + 3.20.1 Google Inc. protobuf-packages https://github.com/protocolbuffers/protobuf/blob/main/LICENSE diff --git a/csharp/src/Google.Protobuf.Test/testprotos.pb b/csharp/src/Google.Protobuf.Test/testprotos.pb index b1dfc97ea7..83958c6097 100644 Binary files a/csharp/src/Google.Protobuf.Test/testprotos.pb and b/csharp/src/Google.Protobuf.Test/testprotos.pb differ diff --git a/csharp/src/Google.Protobuf/CodedInputStream.cs b/csharp/src/Google.Protobuf/CodedInputStream.cs index 912c11f74f..96ae84c3fe 100644 --- a/csharp/src/Google.Protobuf/CodedInputStream.cs +++ b/csharp/src/Google.Protobuf/CodedInputStream.cs @@ -431,7 +431,7 @@ namespace Google.Protobuf { // TODO(jtattermusch): if the message doesn't implement IBufferMessage (and thus does not provide the InternalMergeFrom method), // what we're doing here works fine, but could be more efficient. - // What happends is that we first initialize a ParseContext from the current coded input stream only to parse the length of the message, at which point + // What happens is that we first initialize a ParseContext from the current coded input stream only to parse the length of the message, at which point // we will need to switch back again to CodedInputStream-based parsing (which involves copying and storing the state) to be able to // invoke the legacy MergeFrom(CodedInputStream) method. // For now, this inefficiency is fine, considering this is only a backward-compatibility scenario (and regenerating the code fixes it). diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index 14a83a0654..79af7f3d8e 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -4,7 +4,7 @@ C# runtime library for Protocol Buffers - Google's data interchange format. Copyright 2015, Google Inc. Google Protocol Buffers - 3.20.1-rc1 + 3.20.1 7.2 Google Inc. diff --git a/csharp/src/Google.Protobuf/Reflection/ExtensionCollection.cs b/csharp/src/Google.Protobuf/Reflection/ExtensionCollection.cs index 9664559df2..ca874f9885 100644 --- a/csharp/src/Google.Protobuf/Reflection/ExtensionCollection.cs +++ b/csharp/src/Google.Protobuf/Reflection/ExtensionCollection.cs @@ -93,7 +93,7 @@ namespace Google.Protobuf.Reflection /// /// Returns a readonly list of all the extensions define in this type that extend - /// the provided descriptor type in accending field order + /// the provided descriptor type in ascending field order /// public IList GetExtensionsInNumberOrder(MessageDescriptor descriptor) { diff --git a/docs/field_presence.md b/docs/field_presence.md index ed763758bd..218622dea9 100644 --- a/docs/field_presence.md +++ b/docs/field_presence.md @@ -16,7 +16,7 @@ _Presence disciplines_ define the semantics for translating between the _API rep The wire format is a stream of tagged, _self-delimiting_ values. By definition, the wire format represents a sequence of _present_ values. In other words, every value found within a serialization represents a _present_ field; furthermore, the serialization contains no information about not-present values. -The generated API for a proto message includes (de)serialization definitions which translate between API types and a stream of definitionally _present_ (tag, value) pairs. This translation is designed to be forward- and backward-compatibile across changes to the message definition; however, this compatibility introduces some (perhaps surprising) considerations when deserializing wire-formatted messages: +The generated API for a proto message includes (de)serialization definitions which translate between API types and a stream of definitionally _present_ (tag, value) pairs. This translation is designed to be forward- and backward-compatible across changes to the message definition; however, this compatibility introduces some (perhaps surprising) considerations when deserializing wire-formatted messages: - When serializing, fields with _no presence_ are not serialized if they contain their default value. - For numeric types, the default is 0. diff --git a/examples/BUILD b/examples/BUILD index 7d15e83ab4..358a1529bc 100644 --- a/examples/BUILD +++ b/examples/BUILD @@ -6,6 +6,7 @@ load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_proto_library") load("@rules_java//java:defs.bzl", "java_binary", "java_lite_proto_library", "java_proto_library") +load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") load("@rules_proto//proto:defs.bzl", "proto_library") # For each .proto file, a proto_library target should be defined. This target @@ -103,3 +104,34 @@ java_binary( main_class = "ListPeople", deps = [":addressbook_java_lite_proto"], ) + +# Files included in all source distributions +pkg_files( + name = "dist_files", + srcs = [ + "AddPerson.java", + "BUILD", + "CMakeLists.txt", + "ListPeople.java", + "Makefile", + "README.md", + "WORKSPACE", + "add_person.cc", + "add_person.dart", + "add_person.py", + "addressbook.proto", + "go/cmd/add_person/add_person.go", + "go/cmd/add_person/add_person_test.go", + "go/cmd/list_people/list_people.go", + "go/cmd/list_people/list_people_test.go", + "go/go.mod", + "go/go.sum", + "list_people.cc", + "list_people.dart", + "list_people.py", + "pubspec.yaml", + ], + prefix = "examples/", + strip_prefix = strip_prefix.from_root(""), + visibility = ["//visibility:public"], +) diff --git a/java/BUILD b/java/BUILD index 4a1cdc2c0f..c084db6390 100644 --- a/java/BUILD +++ b/java/BUILD @@ -1,3 +1,5 @@ +load("@rules_pkg//:mappings.bzl", "pkg_filegroup", "pkg_files", "strip_prefix") + test_suite( name = "tests", tests = [ @@ -12,9 +14,40 @@ test_suite( filegroup( name = "release", srcs = [ - "//java/core:release", # contains lite. + "//java/core:release", # contains lite. "//java/kotlin:release", "//java/kotlin-lite:release", "//java/util:release", - ] + ], +) + +################################################################################ +# Packaging rules +################################################################################ + +pkg_files( + name = "dist_files", + srcs = [ + "BUILD", + "README.md", + "bom/pom.xml", + "lite.md", + "pom.xml", + ], + strip_prefix = strip_prefix.from_root(""), + visibility = ["//pkg:__pkg__"], +) + +pkg_filegroup( + name = "all_dist_files", + srcs = [ + ":dist_files", + "//java/core:dist_files", + "//java/internal:dist_files", + "//java/kotlin:dist_files", + "//java/kotlin-lite:dist_files", + "//java/lite:dist_files", + "//java/util:dist_files", + ], + visibility = ["//pkg:__pkg__"], ) diff --git a/java/README.md b/java/README.md index 34b543775e..c5c0bfab58 100644 --- a/java/README.md +++ b/java/README.md @@ -23,7 +23,7 @@ If you are using Maven, use the following: com.google.protobuf protobuf-java - 3.20.1-rc-1 + 3.20.1 ``` @@ -37,7 +37,7 @@ protobuf-java-util package: com.google.protobuf protobuf-java-util - 3.20.1-rc-1 + 3.20.1 ``` @@ -45,7 +45,7 @@ protobuf-java-util package: If you are using Gradle, add the following to your `build.gradle` file's dependencies: ``` - implementation 'com.google.protobuf:protobuf-java:3.20.1-rc-1' + implementation 'com.google.protobuf:protobuf-java:3.20.1' ``` Again, be sure to check that the version number matches (or is newer than) the version number of protoc that you are using. diff --git a/java/bom/pom.xml b/java/bom/pom.xml index fa31209a30..045dc285aa 100644 --- a/java/bom/pom.xml +++ b/java/bom/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-bom - 3.20.1-rc-1 + 3.20.1 pom Protocol Buffers [BOM] diff --git a/java/core/BUILD b/java/core/BUILD index 011fb1c7e1..685ebd0981 100644 --- a/java/core/BUILD +++ b/java/core/BUILD @@ -1,6 +1,7 @@ load("@bazel_skylib//rules:build_test.bzl", "build_test") load("@rules_java//java:defs.bzl", "java_library", "java_lite_proto_library", "java_proto_library") load("@rules_jvm_external//:defs.bzl", "java_export") +load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain", "proto_library") load("//:internal.bzl", "conformance_test") load("//:protobuf_version.bzl", "PROTOBUF_VERSION") @@ -175,9 +176,6 @@ filegroup( proto_lang_toolchain( name = "toolchain", - command_line = "--java_out=$(OUT)", - runtime = ":core", - visibility = ["//visibility:public"], # keep this in sync w/ WELL_KNOWN_PROTO_MAP in //:BUILD blacklisted_protos = [ "//:any_proto", @@ -193,6 +191,9 @@ proto_lang_toolchain( "//:type_proto", "//:wrappers_proto", ], + command_line = "--java_out=$(OUT)", + runtime = ":core", + visibility = ["//visibility:public"], ) proto_library( @@ -226,6 +227,7 @@ java_library( "src/test/java/com/google/protobuf/TestUtil.java", "src/test/java/com/google/protobuf/TestUtilLite.java", ], + visibility = ["//java:__subpackages__"], deps = [ ":core", ":generic_test_protos_java_proto", @@ -233,7 +235,6 @@ java_library( "@maven//:com_google_guava_guava", "@maven//:junit_junit", ], - visibility = ["//java:__subpackages__"], ) test_suite( @@ -336,8 +337,8 @@ java_library( ":rewrite_javalite_test_util", ], visibility = [ - "//java/lite:__pkg__", "//java/kotlin-lite:__pkg__", + "//java/lite:__pkg__", ], deps = [ ":generic_test_protos_java_proto_lite", @@ -411,3 +412,20 @@ junit_tests( "@maven//:org_mockito_mockito_core", ], ) + +pkg_files( + name = "dist_files", + srcs = glob([ + "src/main/java/com/google/protobuf/*.java", + "src/test/java/**/*.java", + "src/test/proto/**/*.proto", + ]) + [ + "BUILD", + "generate-sources-build.xml", + "generate-test-sources-build.xml", + "pom.xml", + "pom_template.xml", + ], + strip_prefix = strip_prefix.from_root(""), + visibility = ["//java:__pkg__"], +) diff --git a/java/core/pom.xml b/java/core/pom.xml index 7fd02c5210..bc0726c357 100644 --- a/java/core/pom.xml +++ b/java/core/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.20.1-rc-1 + 3.20.1 protobuf-java diff --git a/java/core/src/main/java/com/google/protobuf/DescriptorMessageInfoFactory.java b/java/core/src/main/java/com/google/protobuf/DescriptorMessageInfoFactory.java index b856952c73..cc26855217 100644 --- a/java/core/src/main/java/com/google/protobuf/DescriptorMessageInfoFactory.java +++ b/java/core/src/main/java/com/google/protobuf/DescriptorMessageInfoFactory.java @@ -83,8 +83,7 @@ final class DescriptorMessageInfoFactory implements MessageInfoFactory { "AllFields", "DescriptorForType", "InitializationErrorString", - // TODO(b/219045204): re-enable - // "UnknownFields", + "UnknownFields", // obsolete. kept for backwards compatibility of generated code "CachedSize")); diff --git a/java/core/src/test/proto/com/google/protobuf/test_bad_identifiers.proto b/java/core/src/test/proto/com/google/protobuf/test_bad_identifiers.proto index 88ea5e3cae..58665e0486 100644 --- a/java/core/src/test/proto/com/google/protobuf/test_bad_identifiers.proto +++ b/java/core/src/test/proto/com/google/protobuf/test_bad_identifiers.proto @@ -57,8 +57,7 @@ message ForbiddenWordsUnderscoreMessage { optional bool all_fields = 5; optional bool descriptor_for_type = 6; optional bool initialization_error_string = 7; - // TODO(b/219045204): re-enable - // optional bool unknown_fields = 8; + optional bool unknown_fields = 8; // obsolete. kept for backwards compatibility of generated code optional bool cached_size = 9; } diff --git a/java/internal/BUILD b/java/internal/BUILD index 4f542ecee1..d2e0b538ff 100644 --- a/java/internal/BUILD +++ b/java/internal/BUILD @@ -1 +1,13 @@ -package(default_visibility = ["//java:__subpackages__"]) \ No newline at end of file +package(default_visibility = ["//java:__subpackages__"]) + +load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") + +pkg_files( + name = "dist_files", + srcs = [ + "BUILD", + "testing.bzl", + ], + strip_prefix = strip_prefix.from_root(""), + visibility = ["//java:__pkg__"], +) diff --git a/java/kotlin-lite/BUILD b/java/kotlin-lite/BUILD index fd0c103166..18914441c9 100644 --- a/java/kotlin-lite/BUILD +++ b/java/kotlin-lite/BUILD @@ -1,6 +1,7 @@ load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") load("@rules_java//java:defs.bzl", "java_lite_proto_library") load("@rules_jvm_external//:kt_defs.bzl", "kt_jvm_export") +load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") load("//:protobuf_version.bzl", "PROTOBUF_VERSION") load("//:protobuf.bzl", "internal_gen_kt_protos") @@ -21,14 +22,18 @@ kt_jvm_library( "//:gen_well_known_protos_kotlinlite", ], deps = [ - "//java/lite", "//java/kotlin:only_for_use_in_proto_generated_code_its_generator_and_tests", "//java/kotlin:shared_runtime", + "//java/lite", ], ) kt_jvm_export( name = "kotlin-lite_mvn", + deploy_env = [ + "@com_github_jetbrains_kotlin//:kotlin-stdlib", + "//java/lite", + ], maven_coordinates = "com.google.protobuf:protobuf-kotlin-lite:%s" % PROTOBUF_VERSION, pom_template = "//java/kotlin-lite:pom_template.xml", resources = ["//:well_known_protos"], @@ -39,10 +44,6 @@ kt_jvm_export( "//java/kotlin:only_for_use_in_proto_generated_code_its_generator_and_tests", "//java/kotlin:shared_runtime", ], - deploy_env = [ - "@com_github_jetbrains_kotlin//:kotlin-stdlib", - "//java/lite", - ], ) filegroup( @@ -59,9 +60,9 @@ filegroup( test_suite( name = "tests", tests = [ - "test_lite_extensions", "proto2_test_lite", "proto3_test_lite", + "test_lite_extensions", ], ) @@ -71,9 +72,9 @@ kt_jvm_library( deps = [ ":example_extensible_message_java_proto_lite", ":lite_extensions", - "//java/lite", "//java/kotlin:only_for_use_in_proto_generated_code_its_generator_and_tests", "//java/kotlin:shared_runtime", + "//java/lite", "@com_github_jetbrains_kotlin//:kotlin-test", "@maven//:com_google_truth_truth", "@maven//:junit_junit", @@ -82,8 +83,8 @@ kt_jvm_library( java_test( name = "test_lite_extensions", - runtime_deps = [":test_lite_extensions_library"], test_class = "com.google.protobuf.kotlin.ExtendableMessageLiteExtensionsTest", + runtime_deps = [":test_lite_extensions_library"], ) java_lite_proto_library( @@ -93,8 +94,8 @@ java_lite_proto_library( internal_gen_kt_protos( name = "gen_evil_names_proto2_lite", - deps = ["//java/kotlin:evil_names_proto2"], lite = True, + deps = ["//java/kotlin:evil_names_proto2"], ) java_lite_proto_library( @@ -104,8 +105,8 @@ java_lite_proto_library( internal_gen_kt_protos( name = "gen_evil_names_proto3_lite", - deps = ["//java/kotlin:evil_names_proto3"], lite = True, + deps = ["//java/kotlin:evil_names_proto3"], ) java_lite_proto_library( @@ -126,10 +127,10 @@ kt_jvm_library( ], deps = [ ":evil_names_proto2_java_proto_lite", - "//java/lite:lite", + "//:java_lite_test_protos", "//java/kotlin:only_for_use_in_proto_generated_code_its_generator_and_tests", "//java/kotlin:shared_runtime", - "//:java_lite_test_protos", + "//java/lite", ], ) @@ -143,10 +144,10 @@ kt_jvm_library( deps = [ ":evil_names_proto3_java_proto_lite", ":multiple_files_proto3_java_proto_lite", - "//java/lite:lite", + "//:java_lite_test_protos", "//java/kotlin:only_for_use_in_proto_generated_code_its_generator_and_tests", "//java/kotlin:shared_runtime", - "//:java_lite_test_protos", + "//java/lite", ], ) @@ -163,8 +164,8 @@ kt_jvm_library( java_test( name = "proto2_test_lite", - runtime_deps = [":proto2_test_lite_library"], test_class = "com.google.protobuf.kotlin.Proto2LiteTest", + runtime_deps = [":proto2_test_lite_library"], ) kt_jvm_library( @@ -180,6 +181,24 @@ kt_jvm_library( java_test( name = "proto3_test_lite", - runtime_deps = [":proto3_test_lite_library"], test_class = "com.google.protobuf.kotlin.Proto3Test", + runtime_deps = [":proto3_test_lite_library"], +) + +pkg_files( + name = "dist_files", + srcs = glob([ + "src/main/kotlin/com/google/protobuf/*.kt", + "src/test/kotlin/**/*.kt", + ]) + [ + "BUILD", + "generate-sources-build.xml", + "generate-test-sources-build.xml", + "lite.awk", + "pom.xml", + "pom_template.xml", + "process-lite-sources-build.xml", + ], + strip_prefix = strip_prefix.from_root(""), + visibility = ["//java:__pkg__"], ) diff --git a/java/kotlin-lite/pom.xml b/java/kotlin-lite/pom.xml index 2f2ddb66d2..d0ef96d467 100644 --- a/java/kotlin-lite/pom.xml +++ b/java/kotlin-lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.20.1-rc-1 + 3.20.1 protobuf-kotlin-lite diff --git a/java/kotlin/BUILD b/java/kotlin/BUILD index 1da4de535c..c8aae0a047 100644 --- a/java/kotlin/BUILD +++ b/java/kotlin/BUILD @@ -1,12 +1,13 @@ load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") load("@rules_java//java:defs.bzl", "java_proto_library") load("@rules_jvm_external//:kt_defs.bzl", "kt_jvm_export") +load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") load("@rules_proto//proto:defs.bzl", "proto_library") load("//:protobuf_version.bzl", "PROTOBUF_VERSION") load("//:protobuf.bzl", "internal_gen_kt_protos") exports_files([ - "src/test/kotlin/com/google/protobuf/Proto3Test.kt", + "src/test/kotlin/com/google/protobuf/Proto3Test.kt", ]) # Kotlin generated protos depend on this and only this. @@ -36,34 +37,34 @@ kt_jvm_library( kt_jvm_library( name = "bytestring_lib", srcs = ["src/main/kotlin/com/google/protobuf/ByteStrings.kt"], - deps = ["//java/lite"], visibility = ["//java:__subpackages__"], + deps = ["//java/lite"], ) kt_jvm_library( name = "full_extensions", srcs = [ - "src/main/kotlin/com/google/protobuf/Anies.kt", - "src/main/kotlin/com/google/protobuf/ExtendableMessageExtensions.kt", + "src/main/kotlin/com/google/protobuf/Anies.kt", + "src/main/kotlin/com/google/protobuf/ExtendableMessageExtensions.kt", ], deps = ["//java/core"], ) kt_jvm_export( name = "kotlin_mvn", + deploy_env = [ + "@com_github_jetbrains_kotlin//:kotlin-stdlib", + "//java/core", + ], maven_coordinates = "com.google.protobuf:protobuf-kotlin:%s" % PROTOBUF_VERSION, pom_template = "//java/kotlin:pom_template.xml", resources = ["//:well_known_protos"], runtime_deps = [ - ":bytestring_lib", - ":full_extensions", - ":only_for_use_in_proto_generated_code_its_generator_and_tests", - ":shared_runtime", - ":well_known_protos_kotlin", - ], - deploy_env = [ - "@com_github_jetbrains_kotlin//:kotlin-stdlib", - "//java/core", + ":bytestring_lib", + ":full_extensions", + ":only_for_use_in_proto_generated_code_its_generator_and_tests", + ":shared_runtime", + ":well_known_protos_kotlin", ], ) @@ -82,10 +83,10 @@ test_suite( name = "tests", tests = [ "bytestring_test", - "shared_tests", - "test_extensions", "proto2_test", "proto3_test", + "shared_tests", + "test_extensions", ], ) @@ -103,8 +104,8 @@ kt_jvm_library( java_test( name = "bytestring_test", - runtime_deps = [":bytestring_test_library"], test_class = "com.google.protobuf.kotlin.ByteStringsTest", + runtime_deps = [":bytestring_test_library"], ) proto_library( @@ -131,31 +132,31 @@ kt_jvm_library( ":only_for_use_in_proto_generated_code_its_generator_and_tests", ":shared_runtime", "@com_github_jetbrains_kotlin//:kotlin-test", - "@maven//:com_google_truth_truth", "@maven//:com_google_guava_guava_testlib", + "@maven//:com_google_truth_truth", "@maven//:junit_junit", ], ) java_test( name = "shared_tests", - runtime_deps = [":shared_tests_library"], test_class = "com.google.protobuf.kotlin.DslListTest", + runtime_deps = [":shared_tests_library"], ) kt_jvm_library( name = "test_extensions_library", srcs = [ - "src/test/kotlin/com/google/protobuf/AniesTest.kt", - "src/test/kotlin/com/google/protobuf/ExtendableMessageExtensionsTest.kt", + "src/test/kotlin/com/google/protobuf/AniesTest.kt", + "src/test/kotlin/com/google/protobuf/ExtendableMessageExtensionsTest.kt", ], deps = [ ":example_extensible_message_java_proto", ":full_extensions", - "//java/core:core", ":kotlin_unittest", ":only_for_use_in_proto_generated_code_its_generator_and_tests", ":shared_runtime", + "//java/core", "@com_github_jetbrains_kotlin//:kotlin-test", "@maven//:com_google_truth_truth", "@maven//:junit_junit", @@ -164,8 +165,8 @@ kt_jvm_library( java_test( name = "test_extensions", - runtime_deps = [":test_extensions_library"], test_class = "com.google.protobuf.kotlin.ExtendableMessageExtensionsTest", + runtime_deps = [":test_extensions_library"], ) proto_library( @@ -224,11 +225,11 @@ kt_jvm_library( ], deps = [ ":evil_names_proto2_java_proto", - "//java/core:core", ":only_for_use_in_proto_generated_code_its_generator_and_tests", ":shared_runtime", ":well_known_protos_kotlin", "//:java_test_protos", + "//java/core", ], ) @@ -242,10 +243,10 @@ kt_jvm_library( deps = [ ":evil_names_proto3_java_proto", ":multiple_files_proto3_java_proto", - "//java/core:core", ":only_for_use_in_proto_generated_code_its_generator_and_tests", ":shared_runtime", "//:java_test_protos", + "//java/core", ], ) @@ -262,8 +263,8 @@ kt_jvm_library( java_test( name = "proto2_test", - runtime_deps = [":proto2_test_library"], test_class = "com.google.protobuf.kotlin.Proto2Test", + runtime_deps = [":proto2_test_library"], ) kt_jvm_library( @@ -279,8 +280,8 @@ kt_jvm_library( java_test( name = "proto3_test", - runtime_deps = [":proto3_test_library"], test_class = "com.google.protobuf.kotlin.Proto3Test", + runtime_deps = [":proto3_test_library"], ) kt_jvm_library( @@ -289,8 +290,25 @@ kt_jvm_library( "//:gen_well_known_protos_kotlin", ], deps = [ - "//java/core", - ":only_for_use_in_proto_generated_code_its_generator_and_tests", - ":shared_runtime", + ":only_for_use_in_proto_generated_code_its_generator_and_tests", + ":shared_runtime", + "//java/core", ], ) + +pkg_files( + name = "dist_files", + srcs = glob([ + "src/main/kotlin/com/google/protobuf/*.kt", + "src/test/kotlin/**/*.kt", + "src/test/proto/**/*.proto", + ]) + [ + "BUILD", + "generate-sources-build.xml", + "generate-test-sources-build.xml", + "pom.xml", + "pom_template.xml", + ], + strip_prefix = strip_prefix.from_root(""), + visibility = ["//java:__pkg__"], +) diff --git a/java/kotlin/pom.xml b/java/kotlin/pom.xml index d16a1e4333..591c4ae387 100644 --- a/java/kotlin/pom.xml +++ b/java/kotlin/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.20.1-rc-1 + 3.20.1 protobuf-kotlin diff --git a/java/lite.md b/java/lite.md index 759d50b5b1..0620a66fec 100644 --- a/java/lite.md +++ b/java/lite.md @@ -29,7 +29,7 @@ protobuf Java Lite runtime. If you are using Maven, include the following: com.google.protobuf protobuf-javalite - 3.20.1-rc-1 + 3.20.1 ``` diff --git a/java/lite/BUILD b/java/lite/BUILD index fac19f609c..6ff858e3f6 100644 --- a/java/lite/BUILD +++ b/java/lite/BUILD @@ -1,4 +1,5 @@ load("@bazel_skylib//rules:build_test.bzl", "build_test") +load("@rules_pkg//:mappings.bzl", "pkg_filegroup", "pkg_files", "strip_prefix") load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain") load("//:internal.bzl", "conformance_test") load("//java/internal:testing.bzl", "junit_tests") @@ -21,9 +22,6 @@ alias( proto_lang_toolchain( name = "toolchain", - command_line = "--java_out=lite:$(OUT)", - runtime = ":lite", - visibility = ["//visibility:public"], # keep this in sync w/ LITE_WELL_KNOWN_PROTO_MAP in //:BUILD blacklisted_protos = [ "//:any_proto", @@ -37,6 +35,9 @@ proto_lang_toolchain( "//:type_proto", "//:wrappers_proto", ], + command_line = "--java_out=lite:$(OUT)", + runtime = ":lite", + visibility = ["//visibility:public"], ) test_suite( @@ -76,3 +77,20 @@ junit_tests( "@maven//:junit_junit", ], ) + +pkg_files( + name = "dist_files", + srcs = glob([ + "**/*.java", + ]) + [ + "BUILD", + "generate-sources-build.xml", + "generate-test-sources-build.xml", + "lite.awk", + "pom.xml", + "pom_template.xml", + "process-lite-sources-build.xml", + ], + strip_prefix = strip_prefix.from_root(""), + visibility = ["//java:__pkg__"], +) diff --git a/java/lite/pom.xml b/java/lite/pom.xml index a2444f0a92..8055508e4c 100644 --- a/java/lite/pom.xml +++ b/java/lite/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.20.1-rc-1 + 3.20.1 protobuf-javalite diff --git a/java/pom.xml b/java/pom.xml index b3ef5a345f..3c44917e6a 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.20.1-rc-1 + 3.20.1 pom Protocol Buffers [Parent] diff --git a/java/util/BUILD b/java/util/BUILD index 753fabb712..820adb9a01 100644 --- a/java/util/BUILD +++ b/java/util/BUILD @@ -1,5 +1,6 @@ load("@rules_java//java:defs.bzl", "java_proto_library") load("@rules_jvm_external//:defs.bzl", "java_export") +load("@rules_pkg//:mappings.bzl", "pkg_filegroup", "pkg_files", "strip_prefix") load("@rules_proto//proto:defs.bzl", "proto_library") load("//:protobuf_version.bzl", "PROTOBUF_VERSION") load("//java/internal:testing.bzl", "junit_tests") @@ -23,11 +24,11 @@ java_library( # Bazel users, don't depend on this target, use :util. java_export( name = "util_mvn", + deploy_env = ["//java/core"], maven_coordinates = "com.google.protobuf:protobuf-java-util:%s" % PROTOBUF_VERSION, pom_template = "pom_template.xml", visibility = ["//java:__pkg__"], runtime_deps = [":util"], - deploy_env = ["//java/core"], ) filegroup( @@ -74,3 +75,18 @@ junit_tests( "@maven//:junit_junit", ], ) + +pkg_files( + name = "dist_files", + srcs = glob([ + "src/main/**/*.java", + "src/test/**/*.java", + "src/test/**/*.proto", + ]) + [ + "BUILD", + "pom.xml", + "pom_template.xml", + ], + strip_prefix = strip_prefix.from_root(""), + visibility = ["//java:__pkg__"], +) diff --git a/java/util/pom.xml b/java/util/pom.xml index 75b50aa9ed..cd5f96e26e 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -4,7 +4,7 @@ com.google.protobuf protobuf-parent - 3.20.1-rc-1 + 3.20.1 protobuf-java-util diff --git a/js/BUILD b/js/BUILD new file mode 100644 index 0000000000..baa93be9cf --- /dev/null +++ b/js/BUILD @@ -0,0 +1,29 @@ +# Protobuf JS runtime +# +# See also code generation logic under /src/google/protobuf/compiler/js. + +load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") + +pkg_files( + name = "dist_files", + srcs = glob([ + "*.js", + "*.json", + "*.proto", + "binary/*.js", + "commonjs/*.js*", # js, json + "commonjs/**/*.proto", + "compatibility_tests/v3.0.0/**/*.js*", + "compatibility_tests/v3.0.0/**/*.proto", + "compatibility_tests/v3.0.0/**/*.sh", + "compatibility_tests/v3.1.0/**/*.js*", + "compatibility_tests/v3.1.0/**/*.proto", + "experimental/benchmarks/**/*.js", + "experimental/runtime/**/*.js", + ]) + [ + "BUILD", + "README.md", + ], + strip_prefix = strip_prefix.from_root(""), + visibility = ["//pkg:__pkg__"], +) diff --git a/js/package.json b/js/package.json index 555d057607..f3c0e724f8 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "google-protobuf", - "version": "3.20.1-rc.1", + "version": "3.20.1", "description": "Protocol Buffers for JavaScript", "main": "google-protobuf.js", "files": [ diff --git a/kokoro/linux/64-bit/Dockerfile b/kokoro/linux/64-bit/Dockerfile deleted file mode 100644 index 189d0cf941..0000000000 --- a/kokoro/linux/64-bit/Dockerfile +++ /dev/null @@ -1,242 +0,0 @@ -# This Dockerfile specifies the recipe for creating an image for the tests -# to run in. -# -# We install as many test dependencies here as we can, because these setup -# steps can be cached. They do *not* run every time we run the build. -# The Docker image is only rebuilt when the Dockerfile (ie. this file) -# changes. - -# Base Dockerfile for gRPC dev images -FROM debian:latest - -# Apt source for old Python versions. -RUN echo 'deb http://ppa.launchpad.net/fkrull/deadsnakes/ubuntu trusty main' > /etc/apt/sources.list.d/deadsnakes.list && \ - apt-key adv --keyserver keyserver.ubuntu.com --recv-keys DB82666C - -# Apt source for Oracle Java. -RUN echo 'deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main' > /etc/apt/sources.list.d/webupd8team-java-trusty.list && \ - apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886 && \ - echo "oracle-java7-installer shared/accepted-oracle-license-v1-1 select true" | debconf-set-selections - -# Apt source for Mono -RUN echo "deb http://download.mono-project.com/repo/debian wheezy main" | tee /etc/apt/sources.list.d/mono-xamarin.list && \ - echo "deb http://download.mono-project.com/repo/debian wheezy-libjpeg62-compat main" | tee -a /etc/apt/sources.list.d/mono-xamarin.list && \ - apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF - -# Apt source for php -RUN echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu trusty main" | tee /etc/apt/sources.list.d/various-php.list && \ - apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F4FCBB07 - -# Install dotnet SDK based on https://www.microsoft.com/net/core#debian -# (Ubuntu instructions need apt to support https) -RUN apt-get update && apt-get install -y --force-yes curl libunwind8 gettext && \ - curl -sSL -o dotnet.tar.gz https://go.microsoft.com/fwlink/?LinkID=847105 && \ - mkdir -p /opt/dotnet && tar zxf dotnet.tar.gz -C /opt/dotnet && \ - ln -s /opt/dotnet/dotnet /usr/local/bin - -# Install dependencies. We start with the basic ones require to build protoc -# and the C++ build -RUN apt-get clean && apt-get update && apt-get install -y --force-yes \ - autoconf \ - autotools-dev \ - build-essential \ - bzip2 \ - ccache \ - curl \ - gcc \ - git \ - libc6 \ - libc6-dbg \ - libc6-dev \ - libgtest-dev \ - libtool \ - make \ - parallel \ - time \ - wget \ - # -- For csharp -- - mono-devel \ - referenceassemblies-pcl \ - nunit \ - # -- For all Java builds -- \ - maven \ - # -- For java_jdk7 -- \ - openjdk-7-jdk \ - # -- For java_oracle7 -- \ - oracle-java7-installer \ - # -- For python / python_cpp -- \ - python-setuptools \ - python-pip \ - python-dev \ - python2.6-dev \ - python3.3-dev \ - python3.4-dev \ - # -- For Ruby -- - ruby \ - # -- For C++ benchmarks -- - cmake \ - # -- For PHP -- - php5.6 \ - php5.6-dev \ - php5.6-xml \ - php7.0 \ - php7.0-dev \ - php7.0-xml \ - phpunit \ - valgrind \ - libxml2-dev \ - && apt-get clean - -################## -# C# dependencies - -RUN wget www.nuget.org/NuGet.exe -O /usr/local/bin/nuget.exe - -################## -# Python dependencies - -# These packages exist in apt-get, but their versions are too old, so we have -# to get updates from pip. - -RUN pip install pip --upgrade -RUN pip install virtualenv tox yattag - -################## -# Ruby dependencies - -# Install rvm -RUN gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 -RUN \curl -sSL https://get.rvm.io | bash -s stable - -# Install Ruby 2.1, Ruby 2.2 and JRuby 1.7 -RUN /bin/bash -l -c "rvm install ruby-2.1" -RUN /bin/bash -l -c "rvm install ruby-2.2" -RUN /bin/bash -l -c "rvm install jruby-1.7" -RUN /bin/bash -l -c "echo 'gem: --no-ri --no-rdoc' > ~/.gemrc" -RUN /bin/bash -l -c "echo 'export PATH=/usr/local/rvm/bin:$PATH' >> ~/.bashrc" -RUN /bin/bash -l -c "gem install bundler --no-ri --no-rdoc" - -################## -# Java dependencies - -# This step requires compiling protoc. :( - -ENV MAVEN_REPO /var/maven_local_repository -ENV MVN mvn --batch-mode - -RUN cd /tmp && \ - git clone https://github.com/google/protobuf.git && \ - cd protobuf && \ - git reset --hard 129a6e2aca95dcfb6c3e717d7b9cca1f104fde39 && \ - ./autogen.sh && \ - ./configure && \ - make -j4 && \ - cd java && \ - $MVN install dependency:go-offline -Dmaven.repo.local=$MAVEN_REPO && \ - cd ../javanano && \ - $MVN install dependency:go-offline -Dmaven.repo.local=$MAVEN_REPO - -################## -# PHP dependencies. -RUN wget http://am1.php.net/get/php-5.5.38.tar.bz2/from/this/mirror -RUN mv mirror php-5.5.38.tar.bz2 -RUN tar -xvf php-5.5.38.tar.bz2 -RUN cd php-5.5.38 && ./configure --enable-maintainer-zts --prefix=/usr/local/php-5.5-zts && \ - make && make install && cd .. -RUN cd php-5.5.38 && make clean && ./configure --enable-bcmath --prefix=/usr/local/php-5.5 && \ - make && make install && cd .. - -RUN wget http://am1.php.net/get/php-5.6.30.tar.bz2/from/this/mirror -RUN mv mirror php-5.6.30.tar.bz2 -RUN tar -xvf php-5.6.30.tar.bz2 -RUN cd php-5.6.30 && ./configure --enable-maintainer-zts --prefix=/usr/local/php-5.6-zts && \ - make && make install && cd .. -RUN cd php-5.6.30 && make clean && ./configure --enable-bcmath --prefix=/usr/local/php-5.6 && \ - make && make install && cd .. - -RUN wget http://am1.php.net/get/php-7.0.18.tar.bz2/from/this/mirror -RUN mv mirror php-7.0.18.tar.bz2 -RUN tar -xvf php-7.0.18.tar.bz2 -RUN cd php-7.0.18 && ./configure --enable-maintainer-zts --prefix=/usr/local/php-7.0-zts && \ - make && make install && cd .. -RUN cd php-7.0.18 && make clean && ./configure --enable-bcmath --prefix=/usr/local/php-7.0 && \ - make && make install && cd .. - -RUN wget http://am1.php.net/get/php-7.1.4.tar.bz2/from/this/mirror -RUN mv mirror php-7.1.4.tar.bz2 -RUN tar -xvf php-7.1.4.tar.bz2 -RUN cd php-7.1.4 && ./configure --enable-maintainer-zts --prefix=/usr/local/php-7.1-zts && \ - make && make install && cd .. -RUN cd php-7.1.4 && make clean && ./configure --enable-bcmath --prefix=/usr/local/php-7.1 && \ - make && make install && cd .. - -RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" -RUN php composer-setup.php -RUN mv composer.phar /usr/bin/composer -RUN php -r "unlink('composer-setup.php');" -RUN composer config -g -- disable-tls true -RUN composer config -g -- secure-http false -RUN cd /tmp && \ - rm -rf protobuf && \ - git clone https://github.com/google/protobuf.git && \ - cd protobuf && \ - git reset --hard 49b44bff2b6257a119f9c6a342d6151c736586b8 && \ - cd php && \ - ln -sfn /usr/local/php-5.5/bin/php /usr/bin/php && \ - ln -sfn /usr/local/php-5.5/bin/php-config /usr/bin/php-config && \ - ln -sfn /usr/local/php-5.5/bin/phpize /usr/bin/phpize && \ - composer install && \ - mv vendor /usr/local/vendor-5.5 && \ - ln -sfn /usr/local/php-5.6/bin/php /usr/bin/php && \ - ln -sfn /usr/local/php-5.6/bin/php-config /usr/bin/php-config && \ - ln -sfn /usr/local/php-5.6/bin/phpize /usr/bin/phpize && \ - composer install && \ - mv vendor /usr/local/vendor-5.6 && \ - ln -sfn /usr/local/php-7.0/bin/php /usr/bin/php && \ - ln -sfn /usr/local/php-7.0/bin/php-config /usr/bin/php-config && \ - ln -sfn /usr/local/php-7.0/bin/phpize /usr/bin/phpize && \ - composer install && \ - mv vendor /usr/local/vendor-7.0 && \ - ln -sfn /usr/local/php-7.1/bin/php /usr/bin/php && \ - ln -sfn /usr/local/php-7.1/bin/php-config /usr/bin/php-config && \ - ln -sfn /usr/local/php-7.1/bin/phpize /usr/bin/phpize && \ - composer install && \ - mv vendor /usr/local/vendor-7.1 - -################## -# Go dependencies. -RUN apt-get install -y \ - # -- For go -- \ - golang - -################## -# Javascript dependencies. -RUN apt-get install -y \ - # -- For javascript -- \ - npm - -################## -# Python 3.5 3.6 dependencies. -RUN apt-get clean && apt-get update && apt-get install -y --force-yes \ - python3.5-dev \ - python3.6-dev \ - && apt-get clean - -# On Debian/Ubuntu, nodejs binary is named 'nodejs' because the name 'node' -# is taken by another legacy binary. We don't have that legacy binary and -# npm expects the binary to be named 'node', so we just create a symbol -# link here. -RUN ln -s `which nodejs` /usr/bin/node - -################## -# Prepare ccache - -RUN ln -s /usr/bin/ccache /usr/local/bin/gcc -RUN ln -s /usr/bin/ccache /usr/local/bin/g++ -RUN ln -s /usr/bin/ccache /usr/local/bin/cc -RUN ln -s /usr/bin/ccache /usr/local/bin/c++ -RUN ln -s /usr/bin/ccache /usr/local/bin/clang -RUN ln -s /usr/bin/ccache /usr/local/bin/clang++ - -# Define the default command. -CMD ["bash"] diff --git a/kokoro/linux/aarch64/test_java_aarch64.sh b/kokoro/linux/aarch64/test_java_aarch64.sh index 874c04a638..a80665907c 100755 --- a/kokoro/linux/aarch64/test_java_aarch64.sh +++ b/kokoro/linux/aarch64/test_java_aarch64.sh @@ -18,7 +18,7 @@ fi kokoro/linux/aarch64/dockcross_helpers/run_dockcross_manylinux2014_aarch64.sh kokoro/linux/aarch64/protoc_crosscompile_aarch64.sh # the command that will be used to build and test java under an emulator -# * IsValidUtf8Test and DecodeUtf8Test tests are being skipped because that take very long under an emulator. +# * IsValidUtf8Test and DecodeUtf8Test tests are skipped because they take very long under an emulator. TEST_JAVA_COMMAND="mvn --batch-mode -DskipTests install && mvn --batch-mode -Dtest='**/*Test, !**/*IsValidUtf8Test, !**/*DecodeUtf8Test' -DfailIfNoTests=false -Dsurefire.failIfNoSpecifiedTests=false surefire:test" # use an actual aarch64 docker image (with a real aarch64 java and maven) to run build & test protobuf java under an emulator diff --git a/kokoro/linux/dockerfile/test/java_stretch/Dockerfile b/kokoro/linux/dockerfile/test/java_stretch/Dockerfile index 8eeb6a2d1c..0716927637 100644 --- a/kokoro/linux/dockerfile/test/java_stretch/Dockerfile +++ b/kokoro/linux/dockerfile/test/java_stretch/Dockerfile @@ -28,6 +28,7 @@ RUN apt-get update && apt-get install -y \ # Java dependencies maven \ openjdk-11-jdk \ + openjdk-17-jdk \ # Required for the gtest build. python2 \ # Python dependencies diff --git a/kokoro/linux/golang/build.sh b/kokoro/linux/golang/build.sh deleted file mode 100755 index 79cddff15c..0000000000 --- a/kokoro/linux/golang/build.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -# -# This is the top-level script we give to Kokoro as the entry point for -# running the "pull request" project: -# -# This script selects a specific Dockerfile (for building a Docker image) and -# a script to run inside that image. Then we delegate to the general -# build_and_run_docker.sh script. - -# Change to repo root -cd $(dirname $0)/../../.. - -export DOCKERFILE_DIR=kokoro/linux/64-bit -export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh -export OUTPUT_DIR=testoutput -export TEST_SET="golang" -./kokoro/linux/build_and_run_docker.sh diff --git a/kokoro/linux/golang/continuous.cfg b/kokoro/linux/golang/continuous.cfg deleted file mode 100644 index 2282f78f04..0000000000 --- a/kokoro/linux/golang/continuous.cfg +++ /dev/null @@ -1,11 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/golang/build.sh" -timeout_mins: 120 - -action { - define_artifacts { - regex: "**/sponge_log.xml" - } -} diff --git a/kokoro/linux/golang/presubmit.cfg b/kokoro/linux/golang/presubmit.cfg deleted file mode 100644 index 2282f78f04..0000000000 --- a/kokoro/linux/golang/presubmit.cfg +++ /dev/null @@ -1,11 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/golang/build.sh" -timeout_mins: 120 - -action { - define_artifacts { - regex: "**/sponge_log.xml" - } -} diff --git a/kokoro/linux/python_compatibility/build.sh b/kokoro/linux/java_jdk11/build.sh similarity index 70% rename from kokoro/linux/python_compatibility/build.sh rename to kokoro/linux/java_jdk11/build.sh index 1ba35394d1..428f8546c9 100755 --- a/kokoro/linux/python_compatibility/build.sh +++ b/kokoro/linux/java_jdk11/build.sh @@ -10,8 +10,10 @@ # Change to repo root cd $(dirname $0)/../../.. -export DOCKERFILE_DIR=kokoro/linux/64-bit +export DOCKERHUB_ORGANIZATION=protobuftesting +# The image of the Dockerfile sha1 is fetched from the organization +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/java_stretch export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh export OUTPUT_DIR=testoutput -export TEST_SET="python_compatibility" +export TEST_SET="java_jdk11" ./kokoro/linux/build_and_run_docker.sh diff --git a/kokoro/linux/python_cpp/continuous.cfg b/kokoro/linux/java_jdk11/continuous.cfg similarity index 75% rename from kokoro/linux/python_cpp/continuous.cfg rename to kokoro/linux/java_jdk11/continuous.cfg index b1b0e550ff..f8af54d4eb 100644 --- a/kokoro/linux/python_cpp/continuous.cfg +++ b/kokoro/linux/java_jdk11/continuous.cfg @@ -1,7 +1,7 @@ # Config file for running tests in Kokoro # Location of the build script in repository -build_file: "protobuf/kokoro/linux/python_cpp/build.sh" +build_file: "protobuf/kokoro/linux/java_jdk11/build.sh" timeout_mins: 120 action { diff --git a/kokoro/linux/java_jdk11/presubmit.cfg b/kokoro/linux/java_jdk11/presubmit.cfg new file mode 100644 index 0000000000..366048c920 --- /dev/null +++ b/kokoro/linux/java_jdk11/presubmit.cfg @@ -0,0 +1,12 @@ +# Config file for running Linkage Monitor in Kokoro +# https://github.com/GoogleCloudPlatform/cloud-opensource-java/tree/master/linkage-monitor + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/java_jdk11/build.sh" +timeout_mins: 120 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/kokoro/linux/java_jdk7/build.sh b/kokoro/linux/java_jdk17/build.sh similarity index 70% rename from kokoro/linux/java_jdk7/build.sh rename to kokoro/linux/java_jdk17/build.sh index 0a5604b426..9d0ea2b5ca 100755 --- a/kokoro/linux/java_jdk7/build.sh +++ b/kokoro/linux/java_jdk17/build.sh @@ -10,8 +10,10 @@ # Change to repo root cd $(dirname $0)/../../.. -export DOCKERFILE_DIR=kokoro/linux/64-bit +export DOCKERHUB_ORGANIZATION=protobuftesting +# The image of the Dockerfile sha1 is fetched from the organization +export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/java_stretch export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh export OUTPUT_DIR=testoutput -export TEST_SET="java_jdk7" +export TEST_SET="java_jdk17" ./kokoro/linux/build_and_run_docker.sh diff --git a/kokoro/linux/java_jdk7/continuous.cfg b/kokoro/linux/java_jdk17/continuous.cfg similarity index 68% rename from kokoro/linux/java_jdk7/continuous.cfg rename to kokoro/linux/java_jdk17/continuous.cfg index 07a9df5f44..6bac25c128 100644 --- a/kokoro/linux/java_jdk7/continuous.cfg +++ b/kokoro/linux/java_jdk17/continuous.cfg @@ -1,8 +1,8 @@ # Config file for running tests in Kokoro # Location of the build script in repository -build_file: "protobuf/kokoro/linux/java_jdk7/build.sh" -timeout_mins: 120 +build_file: "protobuf/kokoro/linux/java_jdk17/build.sh" +timeout_mins: 60 action { define_artifacts { diff --git a/kokoro/linux/java_jdk17/presubmit.cfg b/kokoro/linux/java_jdk17/presubmit.cfg new file mode 100644 index 0000000000..ee80517904 --- /dev/null +++ b/kokoro/linux/java_jdk17/presubmit.cfg @@ -0,0 +1,12 @@ +# Config file for running Linkage Monitor in Kokoro +# https://github.com/GoogleCloudPlatform/cloud-opensource-java/tree/master/linkage-monitor + +# Location of the build script in repository +build_file: "protobuf/kokoro/linux/java_jdk17/build.sh" +timeout_mins: 60 + +action { + define_artifacts { + regex: "**/sponge_log.xml" + } +} diff --git a/kokoro/linux/java_jdk7/presubmit.cfg b/kokoro/linux/java_jdk7/presubmit.cfg deleted file mode 100644 index 07a9df5f44..0000000000 --- a/kokoro/linux/java_jdk7/presubmit.cfg +++ /dev/null @@ -1,11 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/java_jdk7/build.sh" -timeout_mins: 120 - -action { - define_artifacts { - regex: "**/sponge_log.xml" - } -} diff --git a/kokoro/linux/java_oracle7/build.sh b/kokoro/linux/java_oracle7/build.sh deleted file mode 100755 index 9ab90dadf2..0000000000 --- a/kokoro/linux/java_oracle7/build.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -# -# This is the top-level script we give to Kokoro as the entry point for -# running the "pull request" project: -# -# This script selects a specific Dockerfile (for building a Docker image) and -# a script to run inside that image. Then we delegate to the general -# build_and_run_docker.sh script. - -# Change to repo root -cd $(dirname $0)/../../.. - -export DOCKERFILE_DIR=kokoro/linux/64-bit -export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh -export OUTPUT_DIR=testoutput -export TEST_SET="java_oracle7" -./kokoro/linux/build_and_run_docker.sh diff --git a/kokoro/linux/java_oracle7/continuous.cfg b/kokoro/linux/java_oracle7/continuous.cfg deleted file mode 100644 index 610469b42c..0000000000 --- a/kokoro/linux/java_oracle7/continuous.cfg +++ /dev/null @@ -1,11 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/java_oracle7/build.sh" -timeout_mins: 120 - -action { - define_artifacts { - regex: "**/sponge_log.xml" - } -} diff --git a/kokoro/linux/java_oracle7/presubmit.cfg b/kokoro/linux/java_oracle7/presubmit.cfg deleted file mode 100644 index 610469b42c..0000000000 --- a/kokoro/linux/java_oracle7/presubmit.cfg +++ /dev/null @@ -1,11 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/java_oracle7/build.sh" -timeout_mins: 120 - -action { - define_artifacts { - regex: "**/sponge_log.xml" - } -} diff --git a/kokoro/linux/php80/build.sh b/kokoro/linux/php80/build.sh deleted file mode 100755 index ba269e52db..0000000000 --- a/kokoro/linux/php80/build.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -# -# This is the entry point for kicking off a Kokoro job. This path is referenced -# from the .cfg files in this directory. - -set -ex - -cd $(dirname $0) - -# Most of our tests use a debug build of PHP, but we do one build against an opt -# php just in case that surfaces anything unexpected. -../test_php.sh gcr.io/protobuf-build/php/linux:8.0.5-14a06550010c0649bf69b6c9b803c1ca609bbb6d - -../test_php.sh gcr.io/protobuf-build/php/linux:7.0.33-dbg-14a06550010c0649bf69b6c9b803c1ca609bbb6d -../test_php.sh gcr.io/protobuf-build/php/linux:7.3.28-dbg-14a06550010c0649bf69b6c9b803c1ca609bbb6d -../test_php.sh gcr.io/protobuf-build/php/linux:7.4.18-dbg-14a06550010c0649bf69b6c9b803c1ca609bbb6d -../test_php.sh gcr.io/protobuf-build/php/linux:8.0.5-dbg-14a06550010c0649bf69b6c9b803c1ca609bbb6d diff --git a/kokoro/linux/php80/continuous.cfg b/kokoro/linux/php80/continuous.cfg deleted file mode 100644 index 6d67a8c31a..0000000000 --- a/kokoro/linux/php80/continuous.cfg +++ /dev/null @@ -1,5 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/php80/build.sh" -timeout_mins: 20 diff --git a/kokoro/linux/php80/presubmit.cfg b/kokoro/linux/php80/presubmit.cfg deleted file mode 100644 index 6d67a8c31a..0000000000 --- a/kokoro/linux/php80/presubmit.cfg +++ /dev/null @@ -1,5 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/php80/build.sh" -timeout_mins: 20 diff --git a/kokoro/linux/python_compatibility/continuous.cfg b/kokoro/linux/python_compatibility/continuous.cfg deleted file mode 100644 index 4cf6bb077c..0000000000 --- a/kokoro/linux/python_compatibility/continuous.cfg +++ /dev/null @@ -1,5 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/python_compatibility/build.sh" -timeout_mins: 1440 diff --git a/kokoro/linux/python_compatibility/presubmit.cfg b/kokoro/linux/python_compatibility/presubmit.cfg deleted file mode 100644 index 4cf6bb077c..0000000000 --- a/kokoro/linux/python_compatibility/presubmit.cfg +++ /dev/null @@ -1,5 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/python_compatibility/build.sh" -timeout_mins: 1440 diff --git a/kokoro/linux/python_cpp/build.sh b/kokoro/linux/python_cpp/build.sh deleted file mode 100755 index add6465190..0000000000 --- a/kokoro/linux/python_cpp/build.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -# -# This is the top-level script we give to Kokoro as the entry point for -# running the "pull request" project: -# -# This script selects a specific Dockerfile (for building a Docker image) and -# a script to run inside that image. Then we delegate to the general -# build_and_run_docker.sh script. - -# Change to repo root -cd $(dirname $0)/../../.. - -export DOCKERFILE_DIR=kokoro/linux/64-bit -export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh -export OUTPUT_DIR=testoutput -export TEST_SET="python_cpp" -./kokoro/linux/build_and_run_docker.sh diff --git a/kokoro/linux/python_cpp/presubmit.cfg b/kokoro/linux/python_cpp/presubmit.cfg deleted file mode 100644 index b1b0e550ff..0000000000 --- a/kokoro/linux/python_cpp/presubmit.cfg +++ /dev/null @@ -1,11 +0,0 @@ -# Config file for running tests in Kokoro - -# Location of the build script in repository -build_file: "protobuf/kokoro/linux/python_cpp/build.sh" -timeout_mins: 120 - -action { - define_artifacts { - regex: "**/sponge_log.xml" - } -} diff --git a/kokoro/release/ruby/macos/ruby/ruby_build_environment.sh b/kokoro/release/ruby/macos/ruby/ruby_build_environment.sh index c3fcd3c584..2a9cb1687b 100755 --- a/kokoro/release/ruby/macos/ruby/ruby_build_environment.sh +++ b/kokoro/release/ruby/macos/ruby/ruby_build_environment.sh @@ -91,7 +91,8 @@ ruby --version | grep 'ruby 3.1.0' for v in 3.1.0 ; do ccache -c rake -f "$CROSS_RUBY31" cross-ruby VERSION="$v" HOST=x86_64-darwin MAKE="$MAKE" - rake -f "$CROSS_RUBY31" cross-ruby VERSION="$v" HOST=aarch64-darwin MAKE="$MAKE" + # Disabled until it can be fixed: https://github.com/protocolbuffers/protobuf/issues/9804 + # rake -f "$CROSS_RUBY31" cross-ruby VERSION="$v" HOST=aarch64-darwin MAKE="$MAKE" done set +x # rvm commands are very verbose @@ -101,7 +102,8 @@ ruby --version | grep 'ruby 2.7.0' for v in 3.0.0 2.7.0 ; do ccache -c rake -f "$CROSS_RUBY" cross-ruby VERSION="$v" HOST=x86_64-darwin MAKE="$MAKE" - rake -f "$CROSS_RUBY" cross-ruby VERSION="$v" HOST=aarch64-darwin MAKE="$MAKE" + # Disabled until it can be fixed: https://github.com/protocolbuffers/protobuf/issues/9804 + # rake -f "$CROSS_RUBY" cross-ruby VERSION="$v" HOST=aarch64-darwin MAKE="$MAKE" done set +x rvm use 2.5.0 @@ -110,7 +112,8 @@ ruby --version | grep 'ruby 2.5.0' for v in 2.6.0 2.5.1; do ccache -c rake -f "$CROSS_RUBY" cross-ruby VERSION="$v" HOST=x86_64-darwin MAKE="$MAKE" - rake -f "$CROSS_RUBY" cross-ruby VERSION="$v" HOST=aarch64-darwin MAKE="$MAKE" + # Disabled until it can be fixed: https://github.com/protocolbuffers/protobuf/issues/9804 + # rake -f "$CROSS_RUBY" cross-ruby VERSION="$v" HOST=aarch64-darwin MAKE="$MAKE" done set +x rvm use 2.7.0 diff --git a/objectivec/BUILD b/objectivec/BUILD index 9f702ec95f..7b0ede6865 100644 --- a/objectivec/BUILD +++ b/objectivec/BUILD @@ -1,4 +1,5 @@ load("@rules_cc//cc:defs.bzl", "objc_library") +load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") objc_library( name = "objectivec", @@ -63,28 +64,59 @@ objc_library( non_arc_srcs = [ "GPBAny.pbobjc.m", "GPBApi.pbobjc.m", - "GPBDuration.pbobjc.m", - "GPBEmpty.pbobjc.m", - "GPBFieldMask.pbobjc.m", - "GPBSourceContext.pbobjc.m", - "GPBStruct.pbobjc.m", - "GPBTimestamp.pbobjc.m", - "GPBType.pbobjc.m", - "GPBWrappers.pbobjc.m", "GPBArray.m", "GPBCodedInputStream.m", "GPBCodedOutputStream.m", "GPBDescriptor.m", "GPBDictionary.m", + "GPBDuration.pbobjc.m", + "GPBEmpty.pbobjc.m", "GPBExtensionInternals.m", "GPBExtensionRegistry.m", + "GPBFieldMask.pbobjc.m", "GPBMessage.m", "GPBRootObject.m", + "GPBSourceContext.pbobjc.m", + "GPBStruct.pbobjc.m", + "GPBTimestamp.pbobjc.m", + "GPBType.pbobjc.m", "GPBUnknownField.m", "GPBUnknownFieldSet.m", "GPBUtilities.m", "GPBWellKnownTypes.m", "GPBWireFormat.m", + "GPBWrappers.pbobjc.m", ], visibility = ["//visibility:public"], ) + +pkg_files( + name = "dist_files", + srcs = glob([ + "*.h", + "*.m", + "**/*.h", + "**/*.m", + "**/*.mm", + "**/*.swift", + "DevTools/*.sh", + "DevTools/*.py", + "ProtocolBuffers_iOS.xcodeproj/**/*", + "ProtocolBuffers_OSX.xcodeproj/**/*", + "ProtocolBuffers_tvOS.xcodeproj/**/*", + "Tests/CocoaPods/**/*", + "Tests/*.pddm", + "Tests/*.txt", + "Tests/*.plist", + "Tests/*.proto", + ]) + [ + ".clang-format", + "BUILD", + "README.md", + "Tests/golden_message", + "Tests/golden_packed_fields_message", + "generate_well_known_types.sh", + ], + strip_prefix = strip_prefix.from_root(""), + visibility = ["//pkg:__pkg__"], +) diff --git a/objectivec/GPBUtilities.m b/objectivec/GPBUtilities.m index 08dd358225..b72d0e2de3 100644 --- a/objectivec/GPBUtilities.m +++ b/objectivec/GPBUtilities.m @@ -2070,9 +2070,9 @@ NSString *GPBTextFormatForUnknownFieldSet(GPBUnknownFieldSet *unknownSet, for (GPBUnknownFieldSet *subUnknownSet in field.groupList) { [result appendFormat:@"%@%d: {\n", lineIndent, fieldNumber]; NSString *subIndent = [lineIndent stringByAppendingString:@" "]; - NSString *subUnknwonSetStr = + NSString *subUnknownSetStr = GPBTextFormatForUnknownFieldSet(subUnknownSet, subIndent); - [result appendString:subUnknwonSetStr]; + [result appendString:subUnknownSetStr]; [result appendFormat:@"%@}\n", lineIndent]; } } diff --git a/php/BUILD b/php/BUILD new file mode 100644 index 0000000000..cf94be1cd4 --- /dev/null +++ b/php/BUILD @@ -0,0 +1,30 @@ +# Protobuf PHP runtime +# +# See also code generation logic under /src/google/protobuf/compiler/php. + +load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") + +pkg_files( + name = "dist_files", + srcs = glob([ + "ext/google/protobuf/**/*", + "src/GPBMetadata/Google/Protobuf/**/*.php", + "src/Google/Protobuf/**/*.php", + "tests/*.php", + "tests/*.sh", + "tests/proto/**/*.proto", + ]) + [ + "BUILD", + "README.md", + "REFCOUNTING.md", + "composer.json", + "generate_descriptor_protos.sh", + "generate_test_protos.sh", + "release.sh", + "src/phpdoc.dist.xml", + "tests/valgrind.supp", + ], + prefix = "php", + strip_prefix = strip_prefix.from_pkg(""), + visibility = ["//pkg:__pkg__"], +) diff --git a/composer.json b/php/composer.json.dist similarity index 66% rename from composer.json rename to php/composer.json.dist index 2c64ad220f..70af0a0330 100644 --- a/composer.json +++ b/php/composer.json.dist @@ -6,18 +6,18 @@ "homepage": "https://developers.google.com/protocol-buffers/", "license": "BSD-3-Clause", "require": { - "php": ">=5.5.0" + "php": ">=7.0.0" }, "require-dev": { - "phpunit/phpunit": ">=4.8.0" + "phpunit/phpunit": ">=5.0.0" }, "suggest": { "ext-bcmath": "Need to support JSON deserialization" }, "autoload": { "psr-4": { - "Google\\Protobuf\\": "php/src/Google/Protobuf", - "GPBMetadata\\Google\\Protobuf\\": "php/src/GPBMetadata/Google/Protobuf" + "Google\\Protobuf\\": "src/Google/Protobuf", + "GPBMetadata\\Google\\Protobuf\\": "src/GPBMetadata/Google/Protobuf" } } } diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index 77cee355cc..0acb23c193 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -10,10 +10,10 @@ protobuf-opensource@google.com yes - 2022-04-05 - + 2022-04-20 + - 3.20.1RC1 + 3.20.1 3.20.1 @@ -1268,5 +1268,20 @@ G A release. + + + 3.20.1 + 3.20.1 + + + stable + stable + + 2022-04-20 + + BSD-3-Clause + + + diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index f20e8ee41e..97adedb32c 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -127,7 +127,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_setter, 0, 0, 1) ZEND_ARG_INFO(0, value) ZEND_END_ARG_INFO() -#define PHP_PROTOBUF_VERSION "3.20.1RC1" +#define PHP_PROTOBUF_VERSION "3.20.1" // ptr -> PHP object cache. This is a weak map that caches lazily-created // wrapper objects around upb types: diff --git a/php/release.sh b/php/release.sh index 9a4b139126..f75906a04c 100755 --- a/php/release.sh +++ b/php/release.sh @@ -10,24 +10,17 @@ set -ex VERSION=$1 +rm -rf protobuf-php git clone https://github.com/protocolbuffers/protobuf-php.git -git clone https://github.com/protocolbuffers/protobuf.git # Clean old files -pushd protobuf-php -rm -rf src -popd - -# Checkout the target version -pushd protobuf/php -git checkout -b $VERSION -popd +rm -rf protobuf-php/src # Copy files -pushd protobuf-php -mv ../protobuf/php/src src -mv ../protobuf/composer.json composer.json -sed -i 's|php/src|src|g' composer.json +cp -r php/src protobuf-php +cp php/composer.json.dist protobuf-php/composer.json + +cd protobuf-php git add . git commit -m "$VERSION" if [ $(git tag -l "$VERSION") ]; then @@ -35,7 +28,3 @@ if [ $(git tag -l "$VERSION") ]; then else git tag "$VERSION" fi -popd - -# Clean up -rm -rf protobuf diff --git a/php/tests/GeneratedClassTest.php b/php/tests/GeneratedClassTest.php index 3c4ef139db..37c33dfabe 100644 --- a/php/tests/GeneratedClassTest.php +++ b/php/tests/GeneratedClassTest.php @@ -291,6 +291,10 @@ class GeneratedClassTest extends TestBase // Test Enum methods $this->assertEquals('ONE', TestEnum::name(1)); $this->assertEquals(1, TestEnum::value('ONE')); + $this->assertEquals('ECHO', TestEnum::name(3)); + $this->assertEquals(3, TestEnum::value('ECHO')); + // Backwards compat value lookup by prefixed-name. + $this->assertEquals(3, TestEnum::value('PBECHO')); } public function testInvalidEnumValueThrowsException() diff --git a/pkg/BUILD b/pkg/BUILD index 3e5f5d1d75..b455cec378 100644 --- a/pkg/BUILD +++ b/pkg/BUILD @@ -1,8 +1,17 @@ -load("@rules_pkg//:pkg.bzl", "pkg_zip") -load("@rules_pkg//:mappings.bzl", "pkg_attributes", "pkg_files") +load("@rules_pkg//:pkg.bzl", "pkg_tar", "pkg_zip") +load( + "@rules_pkg//:mappings.bzl", + "pkg_attributes", + "pkg_filegroup", + "pkg_files", +) load("//:protobuf_release.bzl", "package_naming") load(":cc_dist_library.bzl", "cc_dist_library") +package_naming( + name = "protobuf_pkg_naming", +) + pkg_files( name = "wkt_protos_files", srcs = [ @@ -69,10 +78,6 @@ pkg_files( visibility = ["//visibility:private"], ) -package_naming( - name = "protoc_pkg_naming", -) - pkg_zip( name = "protoc_release", srcs = [ @@ -83,7 +88,249 @@ pkg_zip( ":wkt_protos_files", ], package_file_name = "protoc-{version}-{platform}.zip", - package_variables = ":protoc_pkg_naming", + package_variables = ":protobuf_pkg_naming", +) + +################################################################################ +# Source distribution packaging +# +# TODO: these will eventually replace autotools for release artifact packaging. +################################################################################ + +pkg_filegroup( + name = "dist_common", + srcs = [ + "//:common_dist_files", + "//:conformance_dist_files", + "//:cpp_dist_files", # to build protoc + "//benchmarks:all_dist_files", + "@com_google_protobuf_examples//:dist_files", + ], +) + +pkg_filegroup( + name = "cpp_srcs", + srcs = [ + ":dist_common", + "//:cpp_dist_files", + ], +) + +pkg_tar( + name = "dist_cpp_tar", + srcs = [":cpp_srcs"], + extension = "tar.gz", + package_dir = "protobuf-{version}", + package_file_name = "protobuf-cpp-{version}.tar.gz", + package_variables = ":protobuf_pkg_naming", +) + +pkg_zip( + name = "dist_cpp_zip", + srcs = [":cpp_srcs"], + package_file_name = "protobuf-cpp-{version}.zip", + package_variables = ":protobuf_pkg_naming", +) + +pkg_filegroup( + name = "csharp_srcs", + srcs = [ + ":dist_common", + "//:csharp_dist_files", + "//csharp:dist_files", + ], +) + +pkg_tar( + name = "dist_csharp_tar", + srcs = [":csharp_srcs"], + extension = "tar.gz", + package_dir = "protobuf-{version}", + package_file_name = "protobuf-csharp-{version}.tar.gz", + package_variables = ":protobuf_pkg_naming", +) + +pkg_zip( + name = "dist_csharp_zip", + srcs = [":csharp_srcs"], + package_file_name = "protobuf-csharp-{version}.zip", + package_variables = ":protobuf_pkg_naming", +) + +pkg_filegroup( + name = "java_srcs", + srcs = [ + ":dist_common", + "//java:all_dist_files", + ], +) + +pkg_tar( + name = "dist_java_tar", + srcs = [":java_srcs"], + extension = "tar.gz", + package_dir = "protobuf-{version}", + package_file_name = "protobuf-java-{version}.tar.gz", + package_variables = ":protobuf_pkg_naming", +) + +pkg_zip( + name = "dist_java_zip", + srcs = [":java_srcs"], + package_file_name = "protobuf-java-{version}.zip", + package_variables = ":protobuf_pkg_naming", +) + +pkg_filegroup( + name = "js_srcs", + srcs = [ + ":dist_common", + "//js:dist_files", + ], +) + +pkg_tar( + name = "dist_js_tar", + srcs = [":js_srcs"], + extension = "tar.gz", + package_dir = "protobuf-{version}", + package_file_name = "protobuf-js-{version}.tar.gz", + package_variables = ":protobuf_pkg_naming", +) + +pkg_zip( + name = "dist_js_zip", + srcs = [":js_srcs"], + package_file_name = "protobuf-js-{version}.zip", + package_variables = ":protobuf_pkg_naming", +) + +pkg_filegroup( + name = "objectivec_srcs", + srcs = [ + ":dist_common", + "//:objectivec_dist_files", + "//objectivec:dist_files", + ], +) + +pkg_tar( + name = "dist_objectivec_tar", + srcs = [":objectivec_srcs"], + extension = "tar.gz", + package_dir = "protobuf-{version}", + package_file_name = "protobuf-objectivec-{version}.tar.gz", + package_variables = ":protobuf_pkg_naming", +) + +pkg_zip( + name = "dist_objectivec_zip", + srcs = [":objectivec_srcs"], + package_file_name = "protobuf-objectivec-{version}.zip", + package_variables = ":protobuf_pkg_naming", +) + +pkg_filegroup( + name = "php_srcs", + srcs = [ + ":dist_common", + "//:php_dist_files", + "//php:dist_files", + ], +) + +pkg_tar( + name = "dist_php_tar", + srcs = [":php_srcs"], + extension = "tar.gz", + package_dir = "protobuf-{version}", + package_file_name = "protobuf-php-{version}.tar.gz", + package_variables = ":protobuf_pkg_naming", +) + +pkg_zip( + name = "dist_php_zip", + srcs = [":php_srcs"], + package_file_name = "protobuf-php-{version}.zip", + package_variables = ":protobuf_pkg_naming", +) + +pkg_filegroup( + name = "python_srcs", + srcs = [ + ":dist_common", + "//:python_dist_files", + ], +) + +pkg_tar( + name = "dist_python_tar", + srcs = [":python_srcs"], + extension = "tar.gz", + package_dir = "protobuf-{version}", + package_file_name = "protobuf-python-{version}.tar.gz", + package_variables = ":protobuf_pkg_naming", +) + +pkg_zip( + name = "dist_python_zip", + srcs = [":python_srcs"], + package_file_name = "protobuf-python-{version}.zip", + package_variables = ":protobuf_pkg_naming", +) + +pkg_filegroup( + name = "ruby_srcs", + srcs = [ + ":dist_common", + "//ruby:dist_files", + ], +) + +pkg_tar( + name = "dist_ruby_tar", + srcs = [":ruby_srcs"], + extension = "tar.gz", + package_dir = "protobuf-{version}", + package_file_name = "protobuf-ruby-{version}.tar.gz", + package_variables = ":protobuf_pkg_naming", +) + +pkg_zip( + name = "dist_ruby_zip", + srcs = [":ruby_srcs"], + package_file_name = "protobuf-ruby-{version}.zip", + package_variables = ":protobuf_pkg_naming", +) + +pkg_filegroup( + name = "dist_all", + srcs = [ + ":cpp_srcs", + ":csharp_srcs", + ":java_srcs", + ":js_srcs", + ":objectivec_srcs", + ":php_srcs", + ":python_srcs", + ":ruby_srcs", + ], +) + +pkg_tar( + name = "dist_all_tar", + srcs = [":dist_all"], + extension = "tar.gz", + package_dir = "protobuf-{version}", + package_file_name = "protobuf-all-{version}.tar.gz", + package_variables = ":protobuf_pkg_naming", +) + +pkg_zip( + name = "dist_all_zip", + srcs = [":dist_all"], + package_file_name = "protobuf-all-{version}.zip", + package_variables = ":protobuf_pkg_naming", ) ################################################################################ diff --git a/post_process_dist.sh b/post_process_dist.sh index 5b14de6720..116824dd94 100755 --- a/post_process_dist.sh +++ b/post_process_dist.sh @@ -11,7 +11,7 @@ # 2005 *or* 2008 can open them. (In version control, we keep things in # MSVC 2008 format since that's what we use in development.) # 4) Uses the result to create .tar.gz, .tar.bz2, and .zip versions and -# deposites them in the "dist" directory. In the .zip version, all +# deposits them in the "dist" directory. In the .zip version, all # non-testdata .txt files are converted to Windows-style line endings. # 5) Cleans up after itself. diff --git a/protobuf_deps.bzl b/protobuf_deps.bzl index 38d13ff899..ee05113932 100644 --- a/protobuf_deps.bzl +++ b/protobuf_deps.bzl @@ -1,6 +1,7 @@ """Load dependencies needed to compile the protobuf library as a 3rd-party consumer.""" load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") PROTOBUF_MAVEN_ARTIFACTS = [ "com.google.code.findbugs:jsr305:3.0.2", @@ -72,8 +73,9 @@ def protobuf_deps(): if not native.existing_rule("rules_python"): http_archive( name = "rules_python", - sha256 = "b6d46438523a3ec0f3cead544190ee13223a52f6a6765a29eae7b7cc24cc83a0", - urls = ["https://github.com/bazelbuild/rules_python/releases/download/0.1.0/rules_python-0.1.0.tar.gz"], + sha256 = "9fcf91dbcc31fde6d1edb15f117246d912c33c36f44cf681976bd886538deba6", + strip_prefix = "rules_python-0.8.0", + url = "https://github.com/bazelbuild/rules_python/archive/refs/tags/0.8.0.tar.gz", ) if not native.existing_rule("rules_jvm_external"): @@ -100,3 +102,10 @@ def protobuf_deps(): urls = ["https://github.com/bazelbuild/rules_kotlin/releases/download/v1.5.0-beta-4/rules_kotlin_release.tgz"], sha256 = "6cbd4e5768bdfae1598662e40272729ec9ece8b7bded8f0d2c81c8ff96dc139d", ) + + if not native.existing_rule("upb"): + git_repository( + name = "upb", + remote = "https://github.com/protocolbuffers/upb.git", + commit = "a0bc6693b069e6d1f083c7727ea08621cea4155e", + ) diff --git a/protobuf_version.bzl b/protobuf_version.bzl index 404a6437fc..98cf8371dc 100644 --- a/protobuf_version.bzl +++ b/protobuf_version.bzl @@ -1 +1 @@ -PROTOBUF_VERSION = '3.20.1-rc-1' +PROTOBUF_VERSION = '3.20.1' diff --git a/protoc-artifacts/pom.xml b/protoc-artifacts/pom.xml index 31f7b85bbb..e03216bfc0 100644 --- a/protoc-artifacts/pom.xml +++ b/protoc-artifacts/pom.xml @@ -8,7 +8,7 @@ com.google.protobuf protoc - 3.20.1-rc-1 + 3.20.1 pom Protobuf Compiler diff --git a/python/google/protobuf/internal/descriptor_pool_test.py b/python/google/protobuf/internal/descriptor_pool_test.py index 61cec3f9d3..9e451b45be 100644 --- a/python/google/protobuf/internal/descriptor_pool_test.py +++ b/python/google/protobuf/internal/descriptor_pool_test.py @@ -243,10 +243,10 @@ class DescriptorPoolTestBase(object): self.assertRaises(KeyError, self.pool.FindMethodByName, '') # TODO(jieluo): Fix python to raise correct errors. - if api_implementation.Type() == 'cpp': - error_type = TypeError - else: + if api_implementation.Type() == 'python': error_type = AttributeError + else: + error_type = TypeError self.assertRaises(error_type, self.pool.FindMessageTypeByName, 0) self.assertRaises(error_type, self.pool.FindFieldByName, 0) self.assertRaises(error_type, self.pool.FindExtensionByName, 0) @@ -395,7 +395,7 @@ class DescriptorPoolTestBase(object): def testAddSerializedFile(self): if isinstance(self, SecondaryDescriptorFromDescriptorDB): - if api_implementation.Type() == 'cpp': + if api_implementation.Type() != 'python': # Cpp extension cannot call Add on a DescriptorPool # that uses a DescriptorDatabase. # TODO(jieluo): Fix python and cpp extension diff. @@ -434,7 +434,7 @@ class DescriptorPoolTestBase(object): _CheckDefaultValue(file_descriptor) if isinstance(self, SecondaryDescriptorFromDescriptorDB): - if api_implementation.Type() == 'cpp': + if api_implementation.Type() != 'python': # Cpp extension cannot call Add on a DescriptorPool # that uses a DescriptorDatabase. # TODO(jieluo): Fix python and cpp extension diff. @@ -488,7 +488,7 @@ class DescriptorPoolTestBase(object): def testAddFileDescriptor(self): if isinstance(self, SecondaryDescriptorFromDescriptorDB): - if api_implementation.Type() == 'cpp': + if api_implementation.Type() != 'python': # Cpp extension cannot call Add on a DescriptorPool # that uses a DescriptorDatabase. # TODO(jieluo): Fix python and cpp extension diff. @@ -499,7 +499,7 @@ class DescriptorPoolTestBase(object): def testComplexNesting(self): if isinstance(self, SecondaryDescriptorFromDescriptorDB): - if api_implementation.Type() == 'cpp': + if api_implementation.Type() != 'python': # Cpp extension cannot call Add on a DescriptorPool # that uses a DescriptorDatabase. # TODO(jieluo): Fix python and cpp extension diff. @@ -518,7 +518,7 @@ class DescriptorPoolTestBase(object): def testConflictRegister(self): if isinstance(self, SecondaryDescriptorFromDescriptorDB): - if api_implementation.Type() == 'cpp': + if api_implementation.Type() != 'python': # Cpp extension cannot call Add on a DescriptorPool # that uses a DescriptorDatabase. # TODO(jieluo): Fix python and cpp extension diff. @@ -527,7 +527,7 @@ class DescriptorPoolTestBase(object): unittest_pb2.DESCRIPTOR.serialized_pb) conflict_fd = copy.deepcopy(unittest_fd) conflict_fd.name = 'other_file' - if api_implementation.Type() == 'cpp': + if api_implementation.Type() != 'python': pass else: pool = copy.deepcopy(self.pool) @@ -670,7 +670,7 @@ class SecondaryDescriptorFromDescriptorDB(DescriptorPoolTestBase, # called the first time, a KeyError will be raised but call the find # method later will return a descriptor which is not build. # TODO(jieluo): fix pure python to revert the load if file can not be build - if api_implementation.Type() == 'cpp': + if api_implementation.Type() != 'python': error_msg = ('Invalid proto descriptor for file "error_file":\\n ' 'collector.ErrorMessage.nested_message_field: "SubMessage" ' 'is not defined.\\n collector.ErrorMessage.MyOneof: Oneof ' @@ -906,8 +906,8 @@ class AddDescriptorTest(unittest.TestCase): pool.FindFileContainingSymbol( prefix + 'protobuf_unittest.TestAllTypes.NestedMessage').name) - @unittest.skipIf(api_implementation.Type() == 'cpp', - 'With the cpp implementation, Add() must be called first') + @unittest.skipIf(api_implementation.Type() != 'python', + 'Only pure python allows _Add*()') def testMessage(self): self._TestMessage('') self._TestMessage('.') @@ -948,14 +948,14 @@ class AddDescriptorTest(unittest.TestCase): pool.FindFileContainingSymbol( prefix + 'protobuf_unittest.TestAllTypes.NestedEnum').name) - @unittest.skipIf(api_implementation.Type() == 'cpp', - 'With the cpp implementation, Add() must be called first') + @unittest.skipIf(api_implementation.Type() != 'python', + 'Only pure python allows _Add*()') def testEnum(self): self._TestEnum('') self._TestEnum('.') - @unittest.skipIf(api_implementation.Type() == 'cpp', - 'With the cpp implementation, Add() must be called first') + @unittest.skipIf(api_implementation.Type() != 'python', + 'Only pure python allows _Add*()') def testService(self): pool = descriptor_pool.DescriptorPool() with self.assertRaises(KeyError): @@ -965,8 +965,8 @@ class AddDescriptorTest(unittest.TestCase): 'protobuf_unittest.TestService', pool.FindServiceByName('protobuf_unittest.TestService').full_name) - @unittest.skipIf(api_implementation.Type() == 'cpp', - 'With the cpp implementation, Add() must be called first') + @unittest.skipIf(api_implementation.Type() != 'python', + 'Only pure python allows _Add*()') def testFile(self): pool = descriptor_pool.DescriptorPool() pool._AddFileDescriptor(unittest_pb2.DESCRIPTOR) @@ -1043,7 +1043,7 @@ class AddDescriptorTest(unittest.TestCase): def testAddTypeError(self): pool = descriptor_pool.DescriptorPool() - if api_implementation.Type() == 'cpp': + if api_implementation.Type() != 'python': with self.assertRaises(TypeError): pool.AddDescriptor(0) with self.assertRaises(TypeError): diff --git a/python/google/protobuf/internal/message_test.py b/python/google/protobuf/internal/message_test.py index 4002685b02..bd1df8cc77 100644 --- a/python/google/protobuf/internal/message_test.py +++ b/python/google/protobuf/internal/message_test.py @@ -58,11 +58,7 @@ from google.protobuf import map_proto2_unittest_pb2 from google.protobuf import map_unittest_pb2 from google.protobuf import unittest_pb2 from google.protobuf import unittest_proto3_arena_pb2 -from google.protobuf import descriptor_pb2 from google.protobuf import descriptor -from google.protobuf import descriptor_pool -from google.protobuf import message_factory -from google.protobuf import text_format from google.protobuf.internal import api_implementation from google.protobuf.internal import encoder from google.protobuf.internal import more_extensions_pb2 @@ -2542,66 +2538,34 @@ class PackedFieldTest(unittest.TestCase): self.assertEqual(golden_data, message.SerializeToString()) -@unittest.skipIf(api_implementation.Type() != 'cpp', +@unittest.skipIf(api_implementation.Type() == 'python', 'explicit tests of the C++ implementation') @testing_refleaks.TestCase class OversizeProtosTest(unittest.TestCase): - @classmethod - def setUpClass(cls): - # At the moment, reference cycles between DescriptorPool and Message classes - # are not detected and these objects are never freed. - # To avoid errors with ReferenceLeakChecker, we create the class only once. - file_desc = """ - name: "f/f.msg2" - package: "f" - message_type { - name: "msg1" - field { - name: "payload" - number: 1 - label: LABEL_OPTIONAL - type: TYPE_STRING - } - } - message_type { - name: "msg2" - field { - name: "field" - number: 1 - label: LABEL_OPTIONAL - type: TYPE_MESSAGE - type_name: "msg1" - } - } - """ - pool = descriptor_pool.DescriptorPool() - desc = descriptor_pb2.FileDescriptorProto() - text_format.Parse(file_desc, desc) - pool.Add(desc) - cls.proto_cls = message_factory.MessageFactory(pool).GetPrototype( - pool.FindMessageTypeByName('f.msg2')) - - def setUp(self): - self.p = self.proto_cls() - self.p.field.payload = 'c' * (1024 * 1024 * 64 + 1) - self.p_serialized = self.p.SerializeToString() + def GenerateNestedProto(self, n): + msg = unittest_pb2.TestRecursiveMessage() + sub = msg + for _ in range(n): + sub = sub.a + sub.i = 0 + return msg.SerializeToString() + + def testSucceedOkSizedProto(self): + msg = unittest_pb2.TestRecursiveMessage() + msg.ParseFromString(self.GenerateNestedProto(100)) def testAssertOversizeProto(self): - from google.protobuf.pyext._message import SetAllowOversizeProtos - SetAllowOversizeProtos(False) - q = self.proto_cls() - try: - q.ParseFromString(self.p_serialized) - except message.DecodeError as e: - self.assertEqual(str(e), 'Error parsing message') + api_implementation._c_module.SetAllowOversizeProtos(False) + msg = unittest_pb2.TestRecursiveMessage() + with self.assertRaises(message.DecodeError) as context: + msg.ParseFromString(self.GenerateNestedProto(101)) + self.assertIn('Error parsing message', str(context.exception)) def testSucceedOversizeProto(self): - from google.protobuf.pyext._message import SetAllowOversizeProtos - SetAllowOversizeProtos(True) - q = self.proto_cls() - q.ParseFromString(self.p_serialized) - self.assertEqual(self.p.field.payload, q.field.payload) + api_implementation._c_module.SetAllowOversizeProtos(True) + msg = unittest_pb2.TestRecursiveMessage() + msg.ParseFromString(self.GenerateNestedProto(101)) if __name__ == '__main__': diff --git a/python/google/protobuf/internal/unknown_fields_test.py b/python/google/protobuf/internal/unknown_fields_test.py index 0459dba16f..64a0367828 100644 --- a/python/google/protobuf/internal/unknown_fields_test.py +++ b/python/google/protobuf/internal/unknown_fields_test.py @@ -184,7 +184,7 @@ class UnknownFieldsAccessorsTest(unittest.TestCase): # serialized string is checked. # TODO(jieluo): Remove message._unknown_fields. def InternalCheckUnknownField(self, name, expected_value): - if api_implementation.Type() == 'cpp': + if api_implementation.Type() != 'python': return field_descriptor = self.descriptor.fields_by_name[name] wire_type = type_checkers.FIELD_TYPE_TO_WIRE_TYPE[field_descriptor.type] diff --git a/ruby/BUILD b/ruby/BUILD new file mode 100644 index 0000000000..1884c39834 --- /dev/null +++ b/ruby/BUILD @@ -0,0 +1,34 @@ +# Protobuf Ruby runtime +# +# See also code generation logic under /src/google/protobuf/compiler/ruby. + +load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") + +pkg_files( + name = "dist_files", + srcs = glob([ + "compatibility_tests/v3.0.0/**/*", + "ext/google/protobuf_c/*", + "src/main/java/com/google/protobuf/jruby/*.java", + "tests/*.proto", + "tests/*.rb", + ]) + [ + ".gitignore", + "BUILD", + "Gemfile", + "README.md", + "Rakefile", + "google-protobuf.gemspec", + "lib/google/protobuf.rb", + "lib/google/protobuf/descriptor_dsl.rb", + "lib/google/protobuf/message_exts.rb", + "lib/google/protobuf/repeated_field.rb", + "lib/google/protobuf/well_known_types.rb", + "pom.xml", + "src/main/java/google/ProtobufJavaService.java", + "src/main/sentinel.proto", + "travis-test.sh", + ], + strip_prefix = strip_prefix.from_root(""), + visibility = ["//pkg:__pkg__"], +) diff --git a/ruby/google-protobuf.gemspec b/ruby/google-protobuf.gemspec index 3197368f69..cd7aaaa975 100644 --- a/ruby/google-protobuf.gemspec +++ b/ruby/google-protobuf.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = "google-protobuf" - s.version = "3.20.1.rc.1" + s.version = "3.20.1" git_tag = "v#{s.version.to_s.sub('.rc.', '-rc')}" # Converts X.Y.Z.rc.N to vX.Y.Z-rcN, used for the git tag s.licenses = ["BSD-3-Clause"] s.summary = "Protocol Buffers" diff --git a/ruby/pom.xml b/ruby/pom.xml index de421ef4eb..0e7c3fd888 100644 --- a/ruby/pom.xml +++ b/ruby/pom.xml @@ -9,7 +9,7 @@ com.google.protobuf.jruby protobuf-jruby - 3.20.1-rc-1 + 3.20.1 Protocol Buffer JRuby native extension Protocol Buffers are a way of encoding structured data in an efficient yet @@ -76,7 +76,7 @@ com.google.protobuf protobuf-java-util - 3.20.1-rc-1 + 3.20.1 org.jruby diff --git a/src/google/protobuf/compiler/csharp/csharp_enum_field.h b/src/google/protobuf/compiler/csharp/csharp_enum_field.h index e282d72390..0c6b023b13 100644 --- a/src/google/protobuf/compiler/csharp/csharp_enum_field.h +++ b/src/google/protobuf/compiler/csharp/csharp_enum_field.h @@ -31,8 +31,6 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_ENUM_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_CSHARP_ENUM_FIELD_H__ -#include - #include #include diff --git a/src/google/protobuf/compiler/csharp/csharp_map_field.h b/src/google/protobuf/compiler/csharp/csharp_map_field.h index 9b5e214e6d..23b3619913 100644 --- a/src/google/protobuf/compiler/csharp/csharp_map_field.h +++ b/src/google/protobuf/compiler/csharp/csharp_map_field.h @@ -31,8 +31,6 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_MAP_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_CSHARP_MAP_FIELD_H__ -#include - #include #include diff --git a/src/google/protobuf/compiler/csharp/csharp_message_field.h b/src/google/protobuf/compiler/csharp/csharp_message_field.h index 1436fe2008..e76dfd20a3 100644 --- a/src/google/protobuf/compiler/csharp/csharp_message_field.h +++ b/src/google/protobuf/compiler/csharp/csharp_message_field.h @@ -31,8 +31,6 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_MESSAGE_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_CSHARP_MESSAGE_FIELD_H__ -#include - #include #include diff --git a/src/google/protobuf/compiler/csharp/csharp_primitive_field.h b/src/google/protobuf/compiler/csharp/csharp_primitive_field.h index a2c11050e2..6d495d55e1 100644 --- a/src/google/protobuf/compiler/csharp/csharp_primitive_field.h +++ b/src/google/protobuf/compiler/csharp/csharp_primitive_field.h @@ -31,8 +31,6 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_PRIMITIVE_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_CSHARP_PRIMITIVE_FIELD_H__ -#include - #include #include diff --git a/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.h b/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.h index 2e265702fb..2379f38e21 100644 --- a/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.h +++ b/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.h @@ -31,8 +31,6 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_REPEATED_ENUM_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_CSHARP_REPEATED_ENUM_FIELD_H__ -#include - #include #include diff --git a/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.h b/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.h index a2267adf3d..026efea85e 100644 --- a/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.h +++ b/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.h @@ -31,8 +31,6 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_REPEATED_MESSAGE_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_CSHARP_REPEATED_MESSAGE_FIELD_H__ -#include - #include #include diff --git a/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h b/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h index d432f37b2f..bdd12a02f8 100644 --- a/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h +++ b/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h @@ -31,8 +31,6 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_REPEATED_PRIMITIVE_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_CSHARP_REPEATED_PRIMITIVE_FIELD_H__ -#include - #include #include diff --git a/src/google/protobuf/compiler/csharp/csharp_wrapper_field.h b/src/google/protobuf/compiler/csharp/csharp_wrapper_field.h index 57c4f5e76b..cc8a3137d6 100644 --- a/src/google/protobuf/compiler/csharp/csharp_wrapper_field.h +++ b/src/google/protobuf/compiler/csharp/csharp_wrapper_field.h @@ -31,8 +31,6 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_WRAPPER_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_CSHARP_WRAPPER_FIELD_H__ -#include - #include #include diff --git a/src/google/protobuf/compiler/java/helpers.cc b/src/google/protobuf/compiler/java/helpers.cc index 3cbcaca43e..15ee8f55da 100644 --- a/src/google/protobuf/compiler/java/helpers.cc +++ b/src/google/protobuf/compiler/java/helpers.cc @@ -86,8 +86,7 @@ const char* kForbiddenWordList[] = { "AllFields", "DescriptorForType", "InitializationErrorString", - // TODO(b/219045204): re-enable - // "UnknownFields", + "UnknownFields", // obsolete. kept for backwards compatibility of generated code "CachedSize", }; diff --git a/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc b/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc index 1e55f3d95e..6e0d69bcda 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc @@ -34,7 +34,6 @@ #include #include #include -#include namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_field.cc b/src/google/protobuf/compiler/objectivec/objectivec_field.cc index f16dd4b9b6..004ea19fb8 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_field.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_field.cc @@ -37,7 +37,6 @@ #include #include #include -#include #include namespace google { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_message.cc b/src/google/protobuf/compiler/objectivec/objectivec_message.cc index 1cebdd339b..4ebb75c2cd 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_message.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_message.cc @@ -41,8 +41,6 @@ #include #include #include -#include -#include #include namespace google { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_message_field.cc b/src/google/protobuf/compiler/objectivec/objectivec_message_field.cc index 1aa61f1266..2ff0b44a69 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_message_field.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_message_field.cc @@ -34,7 +34,6 @@ #include #include #include -#include namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc b/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc index 5a89f45c0d..1fefde5fe5 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc +++ b/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc @@ -35,8 +35,6 @@ #include #include #include -#include -#include namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.h b/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.h index 291d11a2e3..7c8319d672 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.h @@ -31,8 +31,6 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_PRIMITIVE_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_PRIMITIVE_FIELD_H__ -#include -#include #include namespace google { diff --git a/src/google/protobuf/compiler/php/php_generator.cc b/src/google/protobuf/compiler/php/php_generator.cc index 14261124b2..135a92f654 100644 --- a/src/google/protobuf/compiler/php/php_generator.cc +++ b/src/google/protobuf/compiler/php/php_generator.cc @@ -1373,11 +1373,18 @@ void GenerateEnumFile(const FileDescriptor* file, const EnumDescriptor* en, "name", fullname); Indent(&printer); + bool hasReserved = false; for (int i = 0; i < en->value_count(); i++) { const EnumValueDescriptor* value = en->value(i); GenerateEnumValueDocComment(&printer, value); + + std::string prefix = ConstantNamePrefix(value->name()); + if (!prefix.empty()) { + hasReserved = true; + } + printer.Print("const ^name^ = ^number^;\n", - "name", ConstantNamePrefix(value->name()) + value->name(), + "name", prefix + value->name(), "number", IntToString(value->number())); } @@ -1385,8 +1392,9 @@ void GenerateEnumFile(const FileDescriptor* file, const EnumDescriptor* en, Indent(&printer); for (int i = 0; i < en->value_count(); i++) { const EnumValueDescriptor* value = en->value(i); - printer.Print("self::^name^ => '^name^',\n", - "name", ConstantNamePrefix(value->name()) + value->name()); + printer.Print("self::^constant^ => '^name^',\n", + "constant", ConstantNamePrefix(value->name()) + value->name(), + "name", value->name()); } Outdent(&printer); printer.Print("];\n"); @@ -1416,12 +1424,22 @@ void GenerateEnumFile(const FileDescriptor* file, const EnumDescriptor* en, printer.Print("$const = __CLASS__ . '::' . strtoupper($name);\n" "if (!defined($const)) {\n"); Indent(&printer); + if (hasReserved) { + printer.Print("$pbconst = __CLASS__. '::PB' . strtoupper($name);\n" + "if (!defined($pbconst)) {\n"); + Indent(&printer); + } printer.Print("throw new UnexpectedValueException(sprintf(\n"); Indent(&printer); Indent(&printer); printer.Print("'Enum %s has no value defined for name %s', __CLASS__, $name));\n"); Outdent(&printer); Outdent(&printer); + if (hasReserved) { + Outdent(&printer); + printer.Print("}\n" + "return constant($pbconst);\n"); + } Outdent(&printer); printer.Print("}\n" "return constant($const);\n"); diff --git a/src/google/protobuf/compiler/ruby/ruby_generator.cc b/src/google/protobuf/compiler/ruby/ruby_generator.cc index 2bda459351..d4a53d5632 100644 --- a/src/google/protobuf/compiler/ruby/ruby_generator.cc +++ b/src/google/protobuf/compiler/ruby/ruby_generator.cc @@ -158,7 +158,7 @@ std::string DefaultValueForField(const FieldDescriptor* field) { for (int i = 0; i < default_str.length(); ++i) { // Write the hex form of each byte. os << "\\x" << std::hex << std::setw(2) - << ((uint16)((unsigned char)default_str.at(i))); + << ((uint16_t)((unsigned char)default_str.at(i))); } os << "\".force_encoding(\"ASCII-8BIT\")"; } diff --git a/src/google/protobuf/io/coded_stream_unittest.cc b/src/google/protobuf/io/coded_stream_unittest.cc index 6e45d048c3..b32bf45a97 100644 --- a/src/google/protobuf/io/coded_stream_unittest.cc +++ b/src/google/protobuf/io/coded_stream_unittest.cc @@ -38,7 +38,9 @@ #include +#include #include +#include #include #include @@ -90,7 +92,7 @@ namespace { }; \ \ TEST_F(FIXTURE##_##NAME##_DD, NAME) { \ - for (int i = 0; i < GOOGLE_ARRAYSIZE(CASES); i++) { \ + for (size_t i = 0; i < GOOGLE_ARRAYSIZE(CASES); i++) { \ SCOPED_TRACE(testing::Message() \ << #CASES " case #" << i << ": " << CASES[i]); \ DoSingleCase(CASES[i]); \ @@ -109,8 +111,8 @@ namespace { }; \ \ TEST_F(FIXTURE##_##NAME##_DD, NAME) { \ - for (int i = 0; i < GOOGLE_ARRAYSIZE(CASES1); i++) { \ - for (int j = 0; j < GOOGLE_ARRAYSIZE(CASES2); j++) { \ + for (size_t i = 0; i < GOOGLE_ARRAYSIZE(CASES1); i++) { \ + for (size_t j = 0; j < GOOGLE_ARRAYSIZE(CASES2); j++) { \ SCOPED_TRACE(testing::Message() \ << #CASES1 " case #" << i << ": " << CASES1[i] << ", " \ << #CASES2 " case #" << j << ": " << CASES2[j]); \ @@ -129,10 +131,10 @@ class CodedStreamTest : public testing::Test { protected: // Buffer used during most of the tests. This assumes tests run sequentially. static constexpr int kBufferSize = 1024 * 64; - static uint8 buffer_[kBufferSize]; + static uint8_t buffer_[kBufferSize]; }; -uint8 CodedStreamTest::buffer_[CodedStreamTest::kBufferSize]; +uint8_t CodedStreamTest::buffer_[CodedStreamTest::kBufferSize]; // We test each operation over a variety of block sizes to insure that // we test cases where reads or writes cross buffer boundaries, cases @@ -146,9 +148,9 @@ const int kBlockSizes[] = {1, 2, 3, 5, 7, 13, 32, 1024}; // Varint tests. struct VarintCase { - uint8 bytes[10]; // Encoded bytes. - int size; // Encoded size, in bytes. - uint64 value; // Parsed value. + uint8_t bytes[10]; // Encoded bytes. + size_t size; // Encoded size, in bytes. + uint64_t value; // Parsed value. }; inline std::ostream& operator<<(std::ostream& os, const VarintCase& c) { @@ -192,9 +194,9 @@ TEST_2D(CodedStreamTest, ReadVarint32, kVarintCases, kBlockSizes) { { CodedInputStream coded_input(&input); - uint32 value; + uint32_t value; EXPECT_TRUE(coded_input.ReadVarint32(&value)); - EXPECT_EQ(static_cast(kVarintCases_case.value), value); + EXPECT_EQ(static_cast(kVarintCases_case.value), value); } EXPECT_EQ(kVarintCases_case.size, input.ByteCount()); @@ -207,7 +209,7 @@ TEST_2D(CodedStreamTest, ReadTag, kVarintCases, kBlockSizes) { { CodedInputStream coded_input(&input); - uint32 expected_value = static_cast(kVarintCases_case.value); + uint32_t expected_value = static_cast(kVarintCases_case.value); EXPECT_EQ(expected_value, coded_input.ReadTag()); EXPECT_TRUE(coded_input.LastTagWas(expected_value)); @@ -226,7 +228,7 @@ TEST_F(CodedStreamTest, EmptyInputBeforeEos) { private: bool Next(const void** data, int* size) override { - *data = NULL; + *data = nullptr; *size = 0; return count_++ < 2; } @@ -255,11 +257,11 @@ TEST_1D(CodedStreamTest, ExpectTag, kVarintCases) { // Read one byte to force coded_input.Refill() to be called. Otherwise, // ExpectTag() will return a false negative. - uint8 dummy; + uint8_t dummy; coded_input.ReadRaw(&dummy, 1); EXPECT_EQ((uint)'\0', (uint)dummy); - uint32 expected_value = static_cast(kVarintCases_case.value); + uint32_t expected_value = static_cast(kVarintCases_case.value); // ExpectTag() produces false negatives for large values. if (kVarintCases_case.size <= 2) { @@ -280,16 +282,17 @@ TEST_1D(CodedStreamTest, ExpectTag, kVarintCases) { TEST_1D(CodedStreamTest, ExpectTagFromArray, kVarintCases) { memcpy(buffer_, kVarintCases_case.bytes, kVarintCases_case.size); - const uint32 expected_value = static_cast(kVarintCases_case.value); + const uint32_t expected_value = + static_cast(kVarintCases_case.value); // If the expectation succeeds, it should return a pointer past the tag. if (kVarintCases_case.size <= 2) { - EXPECT_TRUE(NULL == CodedInputStream::ExpectTagFromArray( + EXPECT_TRUE(nullptr == CodedInputStream::ExpectTagFromArray( buffer_, expected_value + 1)); EXPECT_TRUE(buffer_ + kVarintCases_case.size == CodedInputStream::ExpectTagFromArray(buffer_, expected_value)); } else { - EXPECT_TRUE(NULL == + EXPECT_TRUE(nullptr == CodedInputStream::ExpectTagFromArray(buffer_, expected_value)); } } @@ -301,7 +304,7 @@ TEST_2D(CodedStreamTest, ReadVarint64, kVarintCases, kBlockSizes) { { CodedInputStream coded_input(&input); - uint64 value; + uint64_t value; EXPECT_TRUE(coded_input.ReadVarint64(&value)); EXPECT_EQ(kVarintCases_case.value, value); } @@ -320,7 +323,7 @@ TEST_2D(CodedStreamTest, WriteVarint32, kVarintCases, kBlockSizes) { { CodedOutputStream coded_output(&output); - coded_output.WriteVarint32(static_cast(kVarintCases_case.value)); + coded_output.WriteVarint32(static_cast(kVarintCases_case.value)); EXPECT_FALSE(coded_output.HadError()); EXPECT_EQ(kVarintCases_case.size, coded_output.ByteCount()); @@ -352,7 +355,7 @@ TEST_2D(CodedStreamTest, WriteVarint64, kVarintCases, kBlockSizes) { // "sorry, unimplemented: `method_call_expr' not supported by dump_expr" #if !defined(__GNUC__) || __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 3) -int32 kSignExtendedVarintCases[] = {0, 1, -1, 1237894, -37895138}; +int32_t kSignExtendedVarintCases[] = {0, 1, -1, 1237894, -37895138}; TEST_2D(CodedStreamTest, WriteVarint32SignExtended, kSignExtendedVarintCases, kBlockSizes) { @@ -383,10 +386,10 @@ TEST_2D(CodedStreamTest, WriteVarint32SignExtended, kSignExtendedVarintCases, { CodedInputStream coded_input(&input); - uint64 value; + uint64_t value; EXPECT_TRUE(coded_input.ReadVarint64(&value)); - EXPECT_EQ(kSignExtendedVarintCases_case, static_cast(value)); + EXPECT_EQ(kSignExtendedVarintCases_case, static_cast(value)); } EXPECT_EQ(output.ByteCount(), input.ByteCount()); @@ -399,8 +402,8 @@ TEST_2D(CodedStreamTest, WriteVarint32SignExtended, kSignExtendedVarintCases, // Varint failure test. struct VarintErrorCase { - uint8 bytes[12]; - int size; + uint8_t bytes[12]; + size_t size; bool can_parse; }; @@ -430,22 +433,22 @@ const VarintErrorCase kVarintErrorCases[] = { TEST_2D(CodedStreamTest, ReadVarint32Error, kVarintErrorCases, kBlockSizes) { memcpy(buffer_, kVarintErrorCases_case.bytes, kVarintErrorCases_case.size); - ArrayInputStream input(buffer_, kVarintErrorCases_case.size, + ArrayInputStream input(buffer_, static_cast(kVarintErrorCases_case.size), kBlockSizes_case); CodedInputStream coded_input(&input); - uint32 value; + uint32_t value; EXPECT_EQ(kVarintErrorCases_case.can_parse, coded_input.ReadVarint32(&value)); } TEST_2D(CodedStreamTest, ReadVarint32Error_LeavesValueInInitializedState, kVarintErrorCases, kBlockSizes) { memcpy(buffer_, kVarintErrorCases_case.bytes, kVarintErrorCases_case.size); - ArrayInputStream input(buffer_, kVarintErrorCases_case.size, + ArrayInputStream input(buffer_, static_cast(kVarintErrorCases_case.size), kBlockSizes_case); CodedInputStream coded_input(&input); - uint32 value = 0; + uint32_t value = 0; EXPECT_EQ(kVarintErrorCases_case.can_parse, coded_input.ReadVarint32(&value)); // While the specific value following a failure is not critical, we do want to // ensure that it doesn't get set to an uninitialized value. (This check fails @@ -455,22 +458,22 @@ TEST_2D(CodedStreamTest, ReadVarint32Error_LeavesValueInInitializedState, TEST_2D(CodedStreamTest, ReadVarint64Error, kVarintErrorCases, kBlockSizes) { memcpy(buffer_, kVarintErrorCases_case.bytes, kVarintErrorCases_case.size); - ArrayInputStream input(buffer_, kVarintErrorCases_case.size, + ArrayInputStream input(buffer_, static_cast(kVarintErrorCases_case.size), kBlockSizes_case); CodedInputStream coded_input(&input); - uint64 value; + uint64_t value; EXPECT_EQ(kVarintErrorCases_case.can_parse, coded_input.ReadVarint64(&value)); } TEST_2D(CodedStreamTest, ReadVarint64Error_LeavesValueInInitializedState, kVarintErrorCases, kBlockSizes) { memcpy(buffer_, kVarintErrorCases_case.bytes, kVarintErrorCases_case.size); - ArrayInputStream input(buffer_, kVarintErrorCases_case.size, + ArrayInputStream input(buffer_, static_cast(kVarintErrorCases_case.size), kBlockSizes_case); CodedInputStream coded_input(&input); - uint64 value = 0; + uint64_t value = 0; EXPECT_EQ(kVarintErrorCases_case.can_parse, coded_input.ReadVarint64(&value)); // While the specific value following a failure is not critical, we do want to // ensure that it doesn't get set to an uninitialized value. (This check fails @@ -482,7 +485,7 @@ TEST_2D(CodedStreamTest, ReadVarint64Error_LeavesValueInInitializedState, // VarintSize struct VarintSizeCase { - uint64 value; + uint64_t value; int size; }; @@ -509,7 +512,7 @@ TEST_1D(CodedStreamTest, VarintSize32, kVarintSizeCases) { EXPECT_EQ(kVarintSizeCases_case.size, CodedOutputStream::VarintSize32( - static_cast(kVarintSizeCases_case.value))); + static_cast(kVarintSizeCases_case.value))); } TEST_1D(CodedStreamTest, VarintSize64, kVarintSizeCases) { @@ -523,8 +526,8 @@ TEST_F(CodedStreamTest, VarintSize32PowersOfTwo) { if (i % 7 == 0) { expected += 1; } - EXPECT_EQ(expected, - CodedOutputStream::VarintSize32(static_cast(0x1u << i))); + EXPECT_EQ(expected, CodedOutputStream::VarintSize32( + static_cast(0x1u << i))); } } @@ -534,8 +537,7 @@ TEST_F(CodedStreamTest, VarintSize64PowersOfTwo) { if (i % 7 == 0) { expected += 1; } - EXPECT_EQ(expected, CodedOutputStream::VarintSize64( - static_cast(0x1ull << i))); + EXPECT_EQ(expected, CodedOutputStream::VarintSize64(uint64_t{1} << i)); } } @@ -543,13 +545,13 @@ TEST_F(CodedStreamTest, VarintSize64PowersOfTwo) { // Fixed-size int tests struct Fixed32Case { - uint8 bytes[sizeof(uint32)]; // Encoded bytes. - uint32 value; // Parsed value. + uint8_t bytes[sizeof(uint32_t)]; // Encoded bytes. + uint32_t value; // Parsed value. }; struct Fixed64Case { - uint8 bytes[sizeof(uint64)]; // Encoded bytes. - uint64 value; // Parsed value. + uint8_t bytes[sizeof(uint64_t)]; // Encoded bytes. + uint64_t value; // Parsed value. }; inline std::ostream& operator<<(std::ostream& os, const Fixed32Case& c) { @@ -579,12 +581,12 @@ TEST_2D(CodedStreamTest, ReadLittleEndian32, kFixed32Cases, kBlockSizes) { { CodedInputStream coded_input(&input); - uint32 value; + uint32_t value; EXPECT_TRUE(coded_input.ReadLittleEndian32(&value)); EXPECT_EQ(kFixed32Cases_case.value, value); } - EXPECT_EQ(sizeof(uint32), input.ByteCount()); + EXPECT_EQ(sizeof(uint32_t), input.ByteCount()); } TEST_2D(CodedStreamTest, ReadLittleEndian64, kFixed64Cases, kBlockSizes) { @@ -594,12 +596,12 @@ TEST_2D(CodedStreamTest, ReadLittleEndian64, kFixed64Cases, kBlockSizes) { { CodedInputStream coded_input(&input); - uint64 value; + uint64_t value; EXPECT_TRUE(coded_input.ReadLittleEndian64(&value)); EXPECT_EQ(kFixed64Cases_case.value, value); } - EXPECT_EQ(sizeof(uint64), input.ByteCount()); + EXPECT_EQ(sizeof(uint64_t), input.ByteCount()); } TEST_2D(CodedStreamTest, WriteLittleEndian32, kFixed32Cases, kBlockSizes) { @@ -611,11 +613,11 @@ TEST_2D(CodedStreamTest, WriteLittleEndian32, kFixed32Cases, kBlockSizes) { coded_output.WriteLittleEndian32(kFixed32Cases_case.value); EXPECT_FALSE(coded_output.HadError()); - EXPECT_EQ(sizeof(uint32), coded_output.ByteCount()); + EXPECT_EQ(sizeof(uint32_t), coded_output.ByteCount()); } - EXPECT_EQ(sizeof(uint32), output.ByteCount()); - EXPECT_EQ(0, memcmp(buffer_, kFixed32Cases_case.bytes, sizeof(uint32))); + EXPECT_EQ(sizeof(uint32_t), output.ByteCount()); + EXPECT_EQ(0, memcmp(buffer_, kFixed32Cases_case.bytes, sizeof(uint32_t))); } TEST_2D(CodedStreamTest, WriteLittleEndian64, kFixed64Cases, kBlockSizes) { @@ -627,11 +629,11 @@ TEST_2D(CodedStreamTest, WriteLittleEndian64, kFixed64Cases, kBlockSizes) { coded_output.WriteLittleEndian64(kFixed64Cases_case.value); EXPECT_FALSE(coded_output.HadError()); - EXPECT_EQ(sizeof(uint64), coded_output.ByteCount()); + EXPECT_EQ(sizeof(uint64_t), coded_output.ByteCount()); } - EXPECT_EQ(sizeof(uint64), output.ByteCount()); - EXPECT_EQ(0, memcmp(buffer_, kFixed64Cases_case.bytes, sizeof(uint64))); + EXPECT_EQ(sizeof(uint64_t), output.ByteCount()); + EXPECT_EQ(0, memcmp(buffer_, kFixed64Cases_case.bytes, sizeof(uint64_t))); } // Tests using the static methods to read fixed-size values from raw arrays. @@ -639,8 +641,8 @@ TEST_2D(CodedStreamTest, WriteLittleEndian64, kFixed64Cases, kBlockSizes) { TEST_1D(CodedStreamTest, ReadLittleEndian32FromArray, kFixed32Cases) { memcpy(buffer_, kFixed32Cases_case.bytes, sizeof(kFixed32Cases_case.bytes)); - uint32 value; - const uint8* end = + uint32_t value; + const uint8_t* end = CodedInputStream::ReadLittleEndian32FromArray(buffer_, &value); EXPECT_EQ(kFixed32Cases_case.value, value); EXPECT_TRUE(end == buffer_ + sizeof(value)); @@ -649,8 +651,8 @@ TEST_1D(CodedStreamTest, ReadLittleEndian32FromArray, kFixed32Cases) { TEST_1D(CodedStreamTest, ReadLittleEndian64FromArray, kFixed64Cases) { memcpy(buffer_, kFixed64Cases_case.bytes, sizeof(kFixed64Cases_case.bytes)); - uint64 value; - const uint8* end = + uint64_t value; + const uint8_t* end = CodedInputStream::ReadLittleEndian64FromArray(buffer_, &value); EXPECT_EQ(kFixed64Cases_case.value, value); EXPECT_TRUE(end == buffer_ + sizeof(value)); @@ -723,14 +725,14 @@ TEST_1D(CodedStreamTest, ReadStringImpossiblyLarge, kBlockSizes) { TEST_F(CodedStreamTest, ReadStringImpossiblyLargeFromStringOnStack) { // Same test as above, except directly use a buffer. This used to cause // crashes while the above did not. - uint8 buffer[8]; + uint8_t buffer[8]; CodedInputStream coded_input(buffer, 8); std::string str; EXPECT_FALSE(coded_input.ReadString(&str, 1 << 30)); } TEST_F(CodedStreamTest, ReadStringImpossiblyLargeFromStringOnHeap) { - std::unique_ptr buffer(new uint8[8]); + std::unique_ptr buffer(new uint8_t[8]); CodedInputStream coded_input(buffer.get(), 8); std::string str; EXPECT_FALSE(coded_input.ReadString(&str, 1 << 30)); @@ -1021,7 +1023,7 @@ TEST_1D(CodedStreamTest, BasicLimit, kBlockSizes) { CodedInputStream::Limit limit = coded_input.PushLimit(8); // Read until we hit the limit. - uint32 value; + uint32_t value; EXPECT_EQ(8, coded_input.BytesUntilLimit()); EXPECT_TRUE(coded_input.ReadLittleEndian32(&value)); EXPECT_EQ(4, coded_input.BytesUntilLimit()); @@ -1052,7 +1054,7 @@ TEST_1D(CodedStreamTest, SmallLimitOnTopOfBigLimit, kBlockSizes) { EXPECT_EQ(8, coded_input.BytesUntilLimit()); CodedInputStream::Limit limit2 = coded_input.PushLimit(4); - uint32 value; + uint32_t value; // Read until we hit limit2, the top and shortest limit. EXPECT_EQ(4, coded_input.BytesUntilLimit()); @@ -1094,7 +1096,7 @@ TEST_1D(CodedStreamTest, BigLimitOnTopOfSmallLimit, kBlockSizes) { EXPECT_EQ(4, coded_input.BytesUntilLimit()); CodedInputStream::Limit limit2 = coded_input.PushLimit(8); - uint32 value; + uint32_t value; // Read until we hit limit2. Except, wait! limit1 is shorter, so // we end up hitting that first, despite having 4 bytes to go on @@ -1131,7 +1133,7 @@ TEST_F(CodedStreamTest, ExpectAtEnd) { CodedInputStream::Limit limit = coded_input.PushLimit(4); - uint32 value; + uint32_t value; EXPECT_TRUE(coded_input.ReadLittleEndian32(&value)); EXPECT_TRUE(coded_input.ExpectAtEnd()); @@ -1276,7 +1278,6 @@ TEST_F(CodedStreamTest, RecursionLimit) { class ReallyBigInputStream : public ZeroCopyInputStream { public: ReallyBigInputStream() : backup_amount_(0), buffer_count_(0) {} - ~ReallyBigInputStream() {} // implements ZeroCopyInputStream ---------------------------------- bool Next(const void** data, int* size) override { @@ -1316,7 +1317,7 @@ class ReallyBigInputStream : public ZeroCopyInputStream { private: char buffer_[1024]; - int64 buffer_count_; + int64_t buffer_count_; }; TEST_F(CodedStreamTest, InputOver2G) { diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc index 14185afe48..a6f9cfe72c 100644 --- a/src/google/protobuf/port_def.inc +++ b/src/google/protobuf/port_def.inc @@ -256,7 +256,8 @@ #endif #if __has_cpp_attribute(clang::musttail) && !defined(__arm__) && \ !defined(_ARCH_PPC) && !defined(__wasm__) && \ - !(defined(_MSC_VER) && defined(_M_IX86)) + !(defined(_MSC_VER) && defined(_M_IX86)) && \ + !(defined(__NDK_MAJOR__) && __NDK_MAJOR <= 24) # ifndef PROTO2_OPENSOURCE // Compilation fails on ARM32: b/195943306 // Compilation fails on powerpc64le: b/187985113 @@ -861,6 +862,9 @@ #undef TRUE #pragma push_macro("FALSE") #undef FALSE +// Inconvenient macro names from usr/include/sys/syslimits.h in some macOS SDKs. +#pragma push_macro("UID_MAX") +#undef UID_MAX #endif // __APPLE__ #if defined(__clang__) || PROTOBUF_GNUC_MIN(3, 0) || defined(_MSC_VER) @@ -872,9 +876,6 @@ #if defined(__clang__) #pragma clang diagnostic push -// TODO(gerbens) ideally we cleanup the code. But a cursory try shows many -// violations. So let's ignore for now. -#pragma clang diagnostic ignored "-Wshorten-64-to-32" #elif PROTOBUF_GNUC_MIN(3, 0) // GCC does not allow disabling diagnostics within an expression: // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60875, so we disable this one diff --git a/src/google/protobuf/port_undef.inc b/src/google/protobuf/port_undef.inc index 6cb8eacc24..757399f378 100644 --- a/src/google/protobuf/port_undef.inc +++ b/src/google/protobuf/port_undef.inc @@ -143,6 +143,7 @@ #pragma pop_macro("DOMAIN") #pragma pop_macro("TRUE") #pragma pop_macro("FALSE") +#pragma pop_macro("UID_MAX") #endif // __APPLE__ #if defined(__clang__) || defined(__GNUC__) || defined(_MSC_VER) diff --git a/src/google/protobuf/util/delimited_message_util.cc b/src/google/protobuf/util/delimited_message_util.cc index 80cab309be..fdc633f49a 100644 --- a/src/google/protobuf/util/delimited_message_util.cc +++ b/src/google/protobuf/util/delimited_message_util.cc @@ -64,13 +64,13 @@ bool ParseDelimitedFromZeroCopyStream(MessageLite* message, bool ParseDelimitedFromCodedStream(MessageLite* message, io::CodedInputStream* input, bool* clean_eof) { - if (clean_eof != NULL) *clean_eof = false; + if (clean_eof != nullptr) *clean_eof = false; int start = input->CurrentPosition(); // Read the size. - uint32 size; + uint32_t size; if (!input->ReadVarint32(&size)) { - if (clean_eof != NULL) *clean_eof = input->CurrentPosition() == start; + if (clean_eof != nullptr) *clean_eof = input->CurrentPosition() == start; return false; } @@ -79,7 +79,7 @@ bool ParseDelimitedFromCodedStream(MessageLite* message, int position_after_size = input->CurrentPosition(); // Tell the stream not to read beyond that size. - io::CodedInputStream::Limit limit = input->PushLimit(size); + io::CodedInputStream::Limit limit = input->PushLimit(static_cast(size)); // Parse the message. if (!message->MergeFromCodedStream(input)) return false; @@ -105,11 +105,12 @@ bool SerializeDelimitedToCodedStream(const MessageLite& message, size_t size = message.ByteSizeLong(); if (size > INT_MAX) return false; - output->WriteVarint32(size); + output->WriteVarint32(static_cast(size)); // Write the content. - uint8* buffer = output->GetDirectBufferForNBytesAndAdvance(size); - if (buffer != NULL) { + uint8_t* buffer = + output->GetDirectBufferForNBytesAndAdvance(static_cast(size)); + if (buffer != nullptr) { // Optimization: The message fits in one buffer, so use the faster // direct-to-array serialization path. message.SerializeWithCachedSizesToArray(buffer); diff --git a/src/google/protobuf/util/time_util.cc b/src/google/protobuf/util/time_util.cc index 61ce8eca59..9893aa35df 100644 --- a/src/google/protobuf/util/time_util.cc +++ b/src/google/protobuf/util/time_util.cc @@ -116,15 +116,15 @@ std::string FormatNanos(int32_t nanos) { } } -std::string FormatTime(int64 seconds, int32 nanos) { +std::string FormatTime(int64_t seconds, int32_t nanos) { return ::google::protobuf::internal::FormatTime(seconds, nanos); } -bool ParseTime(const std::string& value, int64* seconds, int32* nanos) { +bool ParseTime(const std::string& value, int64_t* seconds, int32_t* nanos) { return ::google::protobuf::internal::ParseTime(value, seconds, nanos); } -void CurrentTime(int64* seconds, int32* nanos) { +void CurrentTime(int64_t* seconds, int32_t* nanos) { return ::google::protobuf::internal::GetCurrentTime(seconds, nanos); } @@ -207,7 +207,7 @@ bool TimeUtil::FromString(const std::string& value, Duration* duration) { return false; } bool negative = (value[0] == '-'); - int sign_length = (negative ? 1 : 0); + size_t sign_length = (negative ? 1 : 0); // Parse the duration value as two integers rather than a float value // to avoid precision loss. std::string seconds_part, nanos_part; @@ -228,7 +228,7 @@ bool TimeUtil::FromString(const std::string& value, Duration* duration) { if (end != nanos_part.c_str() + nanos_part.length()) { return false; } - nanos = nanos * Pow(10, 9 - nanos_part.length()); + nanos = nanos * Pow(10, static_cast(9 - nanos_part.length())); if (negative) { // If a Duration is negative, both seconds and nanos should be negative. seconds = -seconds; @@ -434,9 +434,12 @@ Duration& operator*=(Duration& d, int64_t r) { // NOLINT } Duration& operator*=(Duration& d, double r) { // NOLINT - double result = (d.seconds() * 1.0 + 1.0 * d.nanos() / kNanosPerSecond) * r; + double result = + (static_cast(d.seconds()) + d.nanos() * (1.0 / kNanosPerSecond)) * + r; int64_t seconds = static_cast(result); - int32_t nanos = static_cast((result - seconds) * kNanosPerSecond); + int32_t nanos = static_cast((result - static_cast(seconds)) * + kNanosPerSecond); // Note that we normalize here not just because nanos can have a different // sign from seconds but also that nanos can be any arbitrary value when // overflow happens (i.e., the result is a much larger value than what diff --git a/src/google/protobuf/util/time_util.h b/src/google/protobuf/util/time_util.h index 95cc645203..709527ea27 100644 --- a/src/google/protobuf/util/time_util.h +++ b/src/google/protobuf/util/time_util.h @@ -40,8 +40,8 @@ #ifdef _MSC_VER #ifdef _XBOX_ONE struct timeval { - int64 tv_sec; /* seconds */ - int64 tv_usec; /* and microseconds */ + int64_t tv_sec; /* seconds */ + int64_t tv_usec; /* and microseconds */ }; #else #include diff --git a/tests.sh b/tests.sh index 8e896e8668..b803c7e0d1 100755 --- a/tests.sh +++ b/tests.sh @@ -280,6 +280,11 @@ build_java_jdk8() { build_java_with_conformance_tests } +build_java_jdk11() { + use_java jdk11 + build_java_with_conformance_tests +} + build_java_jdk17() { use_java jdk17 build_java_with_conformance_tests diff --git a/third_party/zlib.BUILD b/third_party/zlib.BUILD index 093dee18dc..098f7bdd89 100644 --- a/third_party/zlib.BUILD +++ b/third_party/zlib.BUILD @@ -2,6 +2,8 @@ load("@rules_cc//cc:defs.bzl", "cc_library") licenses(["notice"]) # BSD/MIT-like license (for zlib) +exports_files(["zlib.BUILD"]) + _ZLIB_HEADERS = [ "crc32.h", "deflate.h", diff --git a/util/python/BUILD b/util/python/BUILD index 9ee56c87e7..85ede91c5b 100644 --- a/util/python/BUILD +++ b/util/python/BUILD @@ -1,5 +1,7 @@ load("@rules_cc//cc:defs.bzl", "cc_library") +exports_files(["BUILD"]) + # This is a placeholder for python headers. Projects needing to use # fast cpp protos in protobuf's python interface should build with # --define=use_fast_cpp_protos=true, and in addition, provide