Merge branch 'protocolbuffers:main' into wunused-parameters

pull/10390/head
marjoleinheyndrickx 2 years ago committed by GitHub
commit 53211b88e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      .bazelignore
  2. 1
      .bazelrc
  3. 4
      .gitmodules
  4. 39
      BUILD.bazel
  5. 21
      CMakeLists.txt
  6. 7
      WORKSPACE
  7. 2
      benchmarks/BUILD.bazel
  8. 2
      benchmarks/cpp/cpp_benchmark.cc
  9. 12
      benchmarks/datasets/BUILD.bazel
  10. 4
      benchmarks/datasets/google_message1/proto2/BUILD.bazel
  11. 2
      benchmarks/datasets/google_message1/proto3/BUILD.bazel
  12. 4
      benchmarks/datasets/google_message2/BUILD.bazel
  13. 2
      benchmarks/datasets/google_message3/BUILD.bazel
  14. 2
      benchmarks/datasets/google_message4/BUILD.bazel
  15. 4
      benchmarks/internal.bzl
  16. 6
      benchmarks/java/BUILD.bazel
  17. 26
      benchmarks/php/BUILD.bazel
  18. 25
      benchmarks/python/BUILD.bazel
  19. 22
      benchmarks/python/py_benchmark.py
  20. 8
      benchmarks/util/BUILD.bazel
  21. 20
      benchmarks/util/compatibility.bzl
  22. 4
      benchmarks/util/proto3_data_stripper.cc
  23. 25
      benchmarks/util/protoc-gen-proto2_to_proto3.cc
  24. 4
      benchmarks/util/result_parser.py
  25. 4
      benchmarks/util/schema_proto2_to_proto3_util.h
  26. 42
      build_defs/arch_tests.bzl
  27. 28
      build_defs/internal_shell.bzl
  28. 32
      cmake/abseil-cpp.cmake
  29. 3
      cmake/conformance.cmake
  30. 1
      cmake/libprotobuf-lite.cmake
  31. 1
      cmake/libprotobuf.cmake
  32. 1
      cmake/libprotoc.cmake
  33. 1
      cmake/protobuf-config.cmake.in
  34. 1
      cmake/protoc.cmake
  35. 8
      cmake/tests.cmake
  36. 78
      conformance/BUILD.bazel
  37. 1
      conformance/conformance_cpp.cc
  38. 2
      conformance/conformance_python.py
  39. 2
      conformance/conformance_test.cc
  40. 2
      conformance/conformance_test.h
  41. 2
      conformance/conformance_test_runner.cc
  42. 2
      conformance/defs.bzl
  43. 4
      examples/Makefile
  44. 2
      generate_descriptor_proto.sh
  45. 6
      java/internal/BUILD.bazel
  46. 1
      java/kotlin/BUILD.bazel
  47. 5
      java/kotlin/pom.xml
  48. 2
      kokoro/linux/aarch64/protoc_crosscompile_aarch64.sh
  49. 2
      kokoro/linux/aarch64/python_crosscompile_aarch64.sh
  50. 2
      kokoro/linux/aarch64/test_ruby_aarch64.sh
  51. 4
      kokoro/linux/python310_cpp/continuous.cfg
  52. 1
      kokoro/linux/python310_cpp/presubmit.cfg
  53. 3
      kokoro/linux/python37_cpp/continuous.cfg
  54. 1
      kokoro/linux/python37_cpp/presubmit.cfg
  55. 3
      kokoro/linux/python38_cpp/continuous.cfg
  56. 1
      kokoro/linux/python38_cpp/presubmit.cfg
  57. 3
      kokoro/linux/python39_cpp/continuous.cfg
  58. 1
      kokoro/linux/python39_cpp/presubmit.cfg
  59. 16
      kokoro/linux/ruby_aarch64/build.sh
  60. 19
      kokoro/linux/ruby_aarch64/continuous.cfg
  61. 19
      kokoro/linux/ruby_aarch64/presubmit.cfg
  62. 2
      kokoro/release/protoc/macos/build.sh
  63. 4
      maven_install.json
  64. 29
      php/generate_descriptor_protos.sh
  65. 8
      pkg/BUILD.bazel
  66. 2
      protobuf_deps.bzl
  67. 31
      python/BUILD.bazel
  68. 13
      python/python_version.py
  69. 5
      python/setup.py
  70. 61
      ruby/ext/google/protobuf_c/message.c
  71. 5
      ruby/lib/google/protobuf/message_exts.rb
  72. 37
      src/google/protobuf/BUILD.bazel
  73. 4
      src/google/protobuf/api.pb.cc
  74. 2
      src/google/protobuf/compiler/BUILD.bazel
  75. 2
      src/google/protobuf/compiler/command_line_interface.cc
  76. 3
      src/google/protobuf/compiler/command_line_interface_unittest.cc
  77. 4
      src/google/protobuf/compiler/cpp/parse_function_generator.cc
  78. 2
      src/google/protobuf/compiler/java/context.cc
  79. 1
      src/google/protobuf/compiler/java/doc_comment.h
  80. 39
      src/google/protobuf/compiler/java/enum.cc
  81. 10
      src/google/protobuf/compiler/java/enum_field.cc
  82. 37
      src/google/protobuf/compiler/java/enum_field_lite.cc
  83. 60
      src/google/protobuf/compiler/java/enum_lite.cc
  84. 11
      src/google/protobuf/compiler/java/extension.cc
  85. 10
      src/google/protobuf/compiler/java/extension.h
  86. 6
      src/google/protobuf/compiler/java/extension_lite.cc
  87. 1
      src/google/protobuf/compiler/java/extension_lite.h
  88. 25
      src/google/protobuf/compiler/java/file.cc
  89. 2
      src/google/protobuf/compiler/java/generator.cc
  90. 2
      src/google/protobuf/compiler/java/generator.h
  91. 27
      src/google/protobuf/compiler/java/helpers.cc
  92. 25
      src/google/protobuf/compiler/java/helpers.h
  93. 180
      src/google/protobuf/compiler/java/map_field.cc
  94. 1
      src/google/protobuf/compiler/java/map_field.h
  95. 151
      src/google/protobuf/compiler/java/map_field_lite.cc
  96. 54
      src/google/protobuf/compiler/java/message.cc
  97. 162
      src/google/protobuf/compiler/java/message_builder.cc
  98. 17
      src/google/protobuf/compiler/java/message_field.cc
  99. 1
      src/google/protobuf/compiler/java/message_field.h
  100. 21
      src/google/protobuf/compiler/java/message_field_lite.cc
  101. Some files were not shown because too many files have changed in this diff Show More

@ -1,4 +1,5 @@
# These are fetched as external repositories.
third_party/abseil-cpp
third_party/benchmark
third_party/googletest
_build/

@ -0,0 +1 @@
build --cxxopt=-std=c++14

4
.gitmodules vendored

@ -6,3 +6,7 @@
path = third_party/googletest
url = https://github.com/google/googletest.git
ignore = dirty
[submodule "third_party/abseil-cpp"]
path = third_party/abseil-cpp
url = https://github.com/abseil/abseil-cpp
branch = lts_2021_11_02

@ -1,12 +1,11 @@
# Bazel (https://bazel.build/) BUILD file for Protobuf.
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_proto_library", "cc_test")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_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_java//java:defs.bzl", "java_binary", "java_lite_proto_library", "java_proto_library")
load("@rules_java//java:defs.bzl", "java_lite_proto_library", "java_proto_library")
load("//build_defs:cpp_opts.bzl", "COPTS", "LINK_OPTS", "PROTOC_LINK_OPTS")
load(":protobuf.bzl", "internal_py_proto_library", "internal_php_proto_library", "internal_ruby_proto_library", "internal_objc_proto_library")
load(":protobuf.bzl", "internal_objc_proto_library", "internal_php_proto_library", "internal_py_proto_library", "internal_ruby_proto_library")
licenses(["notice"])
@ -438,9 +437,9 @@ java_lite_proto_library(
internal_objc_proto_library(
name = "test_messages_proto2_objc_proto",
testonly = 1,
srcs = ["//src/google/protobuf:test_messages_proto2.proto"],
includes = ["src/google/protobuf"],
testonly = 1,
visibility = [
"//conformance:__pkg__",
"//objectivec:__subpackages__",
@ -449,10 +448,14 @@ internal_objc_proto_library(
internal_objc_proto_library(
name = "test_messages_proto3_objc_proto",
testonly = 1,
srcs = ["//src/google/protobuf:test_messages_proto3.proto"],
includes = [
"src/google/protobuf",
# The above must come first.
"src",
],
proto_deps = [":well_known_protos"],
includes = ["src/google/protobuf", "src"],
testonly = 1,
visibility = [
"//conformance:__pkg__",
"//objectivec:__subpackages__",
@ -461,10 +464,10 @@ internal_objc_proto_library(
internal_php_proto_library(
name = "test_messages_proto3_php_proto",
testonly = 1,
srcs = ["//src/google/protobuf:test_messages_proto3.proto"],
proto_deps = [":well_known_protos"],
includes = ["src/google/protobuf", "src"],
outs = [
"GPBMetadata/TestMessagesProto3.php",
"Protobuf_test_messages/Proto3/EnumOnlyProto3.php",
"Protobuf_test_messages/Proto3/EnumOnlyProto3/PBBool.php",
"Protobuf_test_messages/Proto3/ForeignEnum.php",
@ -474,9 +477,13 @@ internal_php_proto_library(
"Protobuf_test_messages/Proto3/TestAllTypesProto3/AliasedEnum.php",
"Protobuf_test_messages/Proto3/TestAllTypesProto3/NestedEnum.php",
"Protobuf_test_messages/Proto3/TestAllTypesProto3/NestedMessage.php",
"GPBMetadata/TestMessagesProto3.php",
],
testonly = 1,
includes = [
"src/google/protobuf",
# The above must come first.
"src",
],
proto_deps = [":well_known_protos"],
visibility = [
"//conformance:__pkg__",
"//php:__subpackages__",
@ -485,9 +492,9 @@ internal_php_proto_library(
internal_ruby_proto_library(
name = "test_messages_proto2_ruby_proto",
testonly = 1,
srcs = ["//src/google/protobuf:test_messages_proto2.proto"],
includes = ["src/google/protobuf"],
testonly = 1,
visibility = [
"//conformance:__pkg__",
"//ruby:__subpackages__",
@ -496,10 +503,14 @@ internal_ruby_proto_library(
internal_ruby_proto_library(
name = "test_messages_proto3_ruby_proto",
testonly = 1,
srcs = ["//src/google/protobuf:test_messages_proto3.proto"],
includes = [
"src/google/protobuf",
# The above must come first.
"src",
],
proto_deps = [":well_known_protos"],
includes = ["src/google/protobuf", "src"],
testonly = 1,
visibility = [
"//conformance:__pkg__",
"//ruby:__subpackages__",

@ -32,11 +32,11 @@ if(protobuf_DEPRECATED_CMAKE_SUBDIRECTORY_USAGE)
get_filename_component(protobuf_SOURCE_DIR ${protobuf_SOURCE_DIR} DIRECTORY)
endif()
# Add c++11 flags
# Add c++14 flags
if (CYGWIN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++14")
else()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
endif()
@ -155,6 +155,14 @@ file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/cmaketest.map)
find_package(Threads REQUIRED)
# We can install dependencies from submodules if we're running
# CMake v3.13 or newer.
if(CMAKE_VERSION VERSION_LESS 3.13)
set(_protobuf_INSTALL_SUPPORTED_FROM_MODULE OFF)
else()
set(_protobuf_INSTALL_SUPPORTED_FROM_MODULE ON)
endif()
set(_protobuf_FIND_ZLIB)
if (protobuf_WITH_ZLIB)
find_package(ZLIB)
@ -187,7 +195,7 @@ set(protobuf_LINK_LIBATOMIC false)
if (NOT MSVC)
include(CheckCXXSourceCompiles)
set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} -std=c++11)
set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} -std=c++14)
check_cxx_source_compiles("
#include <atomic>
int main() {
@ -290,6 +298,11 @@ if (protobuf_UNICODE)
add_definitions(-DUNICODE -D_UNICODE)
endif (protobuf_UNICODE)
set(protobuf_ABSL_PROVIDER "module" CACHE STRING "Provider of absl library")
set_property(CACHE protobuf_ABSL_PROVIDER PROPERTY STRINGS "module" "package")
include(${protobuf_SOURCE_DIR}/cmake/abseil-cpp.cmake)
if (protobuf_BUILD_PROTOBUF_BINARIES)
include(${protobuf_SOURCE_DIR}/cmake/libprotobuf-lite.cmake)
if (NOT DEFINED protobuf_LIB_PROTOBUF_LITE)

@ -9,11 +9,10 @@ local_repository(
http_archive(
name = "com_google_googletest",
sha256 = "9dc9157a9a1551ec7a7e43daea9a694a0bb5fb8bec81235d8a1e6ef64c716dcb",
strip_prefix = "googletest-release-1.10.0",
sha256 = "ea54c9845568cb31c03f2eddc7a40f7f83912d04ab977ff50ec33278119548dd",
strip_prefix = "googletest-4c9a3bb62bf3ba1f1010bf96f9c8ed767b363774",
urls = [
"https://mirror.bazel.build/github.com/google/googletest/archive/release-1.10.0.tar.gz",
"https://github.com/google/googletest/archive/release-1.10.0.tar.gz",
"https://github.com/google/googletest/archive/4c9a3bb62bf3ba1f1010bf96f9c8ed767b363774.tar.gz",
],
)

@ -2,7 +2,7 @@ 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")
load("//:protobuf.bzl", "internal_py_proto_library", "internal_php_proto_library")
load("//:protobuf.bzl", "internal_php_proto_library", "internal_py_proto_library")
################################################################################
# Benchmark Protos

@ -30,6 +30,7 @@
#include <fstream>
#include <iostream>
#include "benchmark/benchmark.h"
#include "benchmarks.pb.h"
#include "benchmarks/datasets/google_message1/proto2/benchmark_message1_proto2.pb.h"
@ -38,7 +39,6 @@
#include "benchmarks/datasets/google_message3/benchmark_message3.pb.h"
#include "benchmarks/datasets/google_message4/benchmark_message4.pb.h"
#define PREFIX "dataset."
#define SUFFIX ".pb"

@ -90,21 +90,18 @@ py_library(
filegroup(
name = "php_protos",
visibility = [
"//benchmarks:__subpackages__",
],
srcs = [
"//benchmarks/datasets/google_message1/proto2:benchmark_message1_proto2_php_proto",
"//benchmarks/datasets/google_message1/proto3:benchmark_message1_proto3_php_proto",
"//benchmarks/datasets/google_message2:benchmark_message2_php_proto",
],
visibility = [
"//benchmarks:__subpackages__",
],
)
filegroup(
name = "csharp_protos",
visibility = [
"//benchmarks:__subpackages__",
],
srcs = [
"//benchmarks/datasets/google_message1/proto2:benchmark_message1_proto2_csharp_proto",
"//benchmarks/datasets/google_message1/proto3:benchmark_message1_proto3_csharp_proto",
@ -112,6 +109,9 @@ filegroup(
"//benchmarks/datasets/google_message3:benchmark_message3_csharp_proto",
"//benchmarks/datasets/google_message4:benchmark_message4_csharp_proto",
],
visibility = [
"//benchmarks:__subpackages__",
],
)
pkg_files(

@ -2,8 +2,8 @@ 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")
load("//:protobuf.bzl", "internal_py_proto_library", "internal_csharp_proto_library")
load("//benchmarks/util:compatibility.bzl", "proto3_from_proto2_data", "php_proto3_from_proto2_library")
load("//:protobuf.bzl", "internal_csharp_proto_library", "internal_py_proto_library")
load("//benchmarks/util:compatibility.bzl", "php_proto3_from_proto2_library", "proto3_from_proto2_data")
filegroup(
name = "datasets",

@ -2,7 +2,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")
load("//:protobuf.bzl", "internal_py_proto_library", "internal_php_proto_library", "internal_csharp_proto_library")
load("//:protobuf.bzl", "internal_csharp_proto_library", "internal_php_proto_library", "internal_py_proto_library")
filegroup(
name = "datasets",

@ -2,8 +2,8 @@ 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")
load("//:protobuf.bzl", "internal_py_proto_library", "internal_csharp_proto_library")
load("//benchmarks/util:compatibility.bzl", "proto3_from_proto2_data", "php_proto3_from_proto2_library")
load("//:protobuf.bzl", "internal_csharp_proto_library", "internal_py_proto_library")
load("//benchmarks/util:compatibility.bzl", "php_proto3_from_proto2_library", "proto3_from_proto2_data")
filegroup(
name = "datasets",

@ -2,7 +2,7 @@ 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")
load("//:protobuf.bzl", "internal_py_proto_library", "internal_csharp_proto_library")
load("//:protobuf.bzl", "internal_csharp_proto_library", "internal_py_proto_library")
filegroup(
name = "datasets",

@ -2,7 +2,7 @@ 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")
load("//:protobuf.bzl", "internal_py_proto_library", "internal_csharp_proto_library")
load("//:protobuf.bzl", "internal_csharp_proto_library", "internal_py_proto_library")
filegroup(
name = "datasets",

@ -2,6 +2,7 @@
PLEASE DO NOT DEPEND ON THE CONTENTS OF THIS FILE, IT IS UNSTABLE.
"""
load("//build_defs:internal_shell.bzl", "inline_sh_binary")
def internal_benchmark_test(
@ -31,7 +32,8 @@ def internal_benchmark_test(
" ".join(env_vars),
binary,
" ".join(args),
" ".join(dataset_labels)),
" ".join(dataset_labels),
),
tags = ["benchmark"],
testonly = 1,
)

@ -1,4 +1,4 @@
load("@rules_java//java:defs.bzl", "java_library", "java_binary")
load("@rules_java//java:defs.bzl", "java_binary", "java_library")
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
load("//build_defs:internal_shell.bzl", "inline_sh_binary")
load("//benchmarks:internal.bzl", "internal_benchmark_test")
@ -22,7 +22,6 @@ java_binary(
inline_sh_binary(
name = "java_benchmark",
srcs = ["//benchmarks/datasets"],
tools = [":java_benchmark_jar"],
cmd = """
data_files=""
conf=()
@ -35,7 +34,8 @@ inline_sh_binary(
done
$(rootpath :java_benchmark_jar) com.google.protobuf.ProtoCaliperBenchmark \
-i runtime -DdataFile=$${data_files:0:-1} $${conf[*]}
"""
""",
tools = [":java_benchmark_jar"],
)
# A pre-configured binary using the checked in datasets.

@ -5,58 +5,58 @@ load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
# The benchmark binary which can be run over any dataset.
inline_sh_binary(
name = "php_benchmark",
testonly = 1,
srcs = [
"PhpBenchmark.php",
"autoload.php",
],
deps = [
"//benchmarks:benchmarks_php_proto",
"//benchmarks/datasets:php_protos",
"//php:source_files",
],
cmd = """
php -d include_path=benchmarks:php/src \\
-d auto_prepend_file=$(rootpath autoload.php) \\
$(rootpath PhpBenchmark.php) $$@
""",
testonly = 1,
deps = [
"//benchmarks:benchmarks_php_proto",
"//benchmarks/datasets:php_protos",
"//php:source_files",
],
)
# A pre-configured binary using the checked in datasets.
internal_benchmark_test(
name = "php",
args = ["--behavior_prefix='php'"],
binary = ":php_benchmark",
datasets = ["//benchmarks/datasets:proto3_datasets"],
env_vars = ["PROTOBUF_PHP_SRCDIR=php/src"],
args = ["--behavior_prefix='php'"],
)
# The benchmark binary which can be run over any dataset.
inline_sh_binary(
name = "php_c_benchmark",
testonly = 1,
srcs = [
"PhpBenchmark.php",
"//php:extension",
],
deps = [
"//benchmarks:benchmarks_php_proto",
"//benchmarks/datasets:php_protos",
],
cmd = """
php -d include_path=benchmarks:php/src \\
-dextension=$(rootpath //php:extension) \\
$(rootpath PhpBenchmark.php) $$@
""",
testonly = 1,
deps = [
"//benchmarks:benchmarks_php_proto",
"//benchmarks/datasets:php_protos",
],
)
# A pre-configured binary using the checked in datasets.
internal_benchmark_test(
name = "php_c",
args = ["--behavior_prefix='php_c'"],
binary = ":php_c_benchmark",
datasets = ["//benchmarks/datasets:proto3_datasets"],
env_vars = ["PROTOBUF_PHP_SRCDIR=php/src"],
args = ["--behavior_prefix='php_c'"],
)
pkg_files(

@ -1,37 +1,38 @@
load("@rules_cc//cc:defs.bzl", "cc_binary")
load("@rules_python//python:defs.bzl", "py_library", "py_binary")
load("@rules_python//python:defs.bzl", "py_binary", "py_library")
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
load("//benchmarks:internal.bzl", "internal_benchmark_test")
cc_binary(
name = "libbenchmark_messages.so",
srcs = ["python_benchmark_messages.cc"],
linkshared = True,
linkstatic = True,
visibility = ["//visibility:private"],
deps = [
"@local_config_python//:python_headers",
"//external:python_headers",
"//benchmarks:benchmarks_cc_proto",
"//benchmarks/datasets:cc_protos",
"//external:python_headers",
"@local_config_python//:python_headers",
],
linkshared = True,
linkstatic = True,
visibility = ["//visibility:private"],
)
# The benchmark binary which can be run over any dataset.
py_binary(
name = "python_benchmark",
srcs = ["py_benchmark.py"],
main = "py_benchmark.py",
data = ["libbenchmark_messages.so"],
python_version = "PY3",
env = select({
"//python:use_fast_cpp_protos": {"PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": "cpp"},
"//conditions:default": {"PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": "python"},
}),
main = "py_benchmark.py",
deps = [
"//:protobuf_python",
"//benchmarks:benchmarks_py_proto",
"//benchmarks/datasets:py_protos",
],
env = select({
"//python:use_fast_cpp_protos": {"PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": "cpp"},
"//conditions:default": {"PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": "python"},
}),
)
# Pre-configured binaries using the checked in datasets.
@ -54,10 +55,10 @@ internal_benchmark_test(
# Note: this requires --define=use_fast_cpp_protos=true
internal_benchmark_test(
name = "cpp_generated_code",
args = ["--cpp_generated"],
binary = ":python_benchmark",
datasets = ["//benchmarks/datasets"],
env_vars = ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp"],
args = ["--cpp_generated"],
)
pkg_files(

@ -6,6 +6,12 @@ import math
import argparse
import fnmatch
import json
from benchmarks.datasets.google_message1.proto2 import benchmark_message1_proto2_pb2
from benchmarks.datasets.google_message1.proto3 import benchmark_message1_proto3_pb2
from benchmarks.datasets.google_message2 import benchmark_message2_pb2
from benchmarks.datasets.google_message3 import benchmark_message3_pb2
from benchmarks.datasets.google_message4 import benchmark_message4_pb2
from benchmarks import benchmarks_pb2
parser = argparse.ArgumentParser(description="Python protobuf benchmark")
parser.add_argument("data_files", metavar="dataFile", nargs="+",
@ -27,19 +33,11 @@ args = parser.parse_args()
# for the descriptor can be found in the pool
if args.cpp_generated != "no":
sys.path.append( os.path.dirname( os.path.dirname( os.path.abspath(__file__) ) ) + "/.libs" )
from benchmarks.python import libbenchmark_messages
from benchmarks.python import libbenchmark_messages # pylint: disable=unused-import,g-import-not-at-top
sys.path.append( os.path.dirname( os.path.dirname( os.path.abspath(__file__) ) ) + "/tmp" )
# END CPP GENERATED MESSAGE
import benchmarks.datasets.google_message1.proto2.benchmark_message1_proto2_pb2 as benchmark_message1_proto2_pb2
import benchmarks.datasets.google_message1.proto3.benchmark_message1_proto3_pb2 as benchmark_message1_proto3_pb2
import benchmarks.datasets.google_message2.benchmark_message2_pb2 as benchmark_message2_pb2
import benchmarks.datasets.google_message3.benchmark_message3_pb2 as benchmark_message3_pb2
import benchmarks.datasets.google_message4.benchmark_message4_pb2 as benchmark_message4_pb2
import benchmarks.benchmarks_pb2 as benchmarks_pb2
def run_one_test(filename):
data = open(filename, "rb").read()
benchmark_dataset = benchmarks_pb2.BenchmarkDataset()
@ -135,9 +133,9 @@ class Benchmark:
if t < 3 :
reps = int(math.ceil(3 / t)) * self.full_iteration
if reps != self.full_iteration:
t = timeit.timeit(stmt="%s(%s)" % (self.test_method, test_method_args),
setup=self.full_setup_code(setup_method_args),
number=reps);
t = timeit.timeit(stmt="%s(%s)" % (self.test_method, test_method_args),
setup=self.full_setup_code(setup_method_args),
number=reps);
return self.total_bytes * 1.0 / 2 ** 20 / (1.0 * t / reps * self.full_iteration)

@ -7,15 +7,15 @@ package(default_visibility = ["//benchmarks:__subpackages__"])
cc_binary(
name = "protoc-gen-proto2_to_proto3",
srcs = [
"schema_proto2_to_proto3_util.h",
"protoc-gen-proto2_to_proto3.cc",
"schema_proto2_to_proto3_util.h",
],
visibility = ["//benchmarks:__subpackages__"],
deps = [
"//:protobuf",
"//src/google/protobuf/compiler:code_generator",
"//benchmarks:benchmarks_cc_proto",
"//src/google/protobuf/compiler:code_generator",
],
visibility = ["//benchmarks:__subpackages__"],
)
cc_binary(
@ -26,8 +26,8 @@ cc_binary(
],
deps = [
"//:protobuf",
"//benchmarks/datasets:cc_protos",
"//benchmarks:benchmarks_cc_proto",
"//benchmarks/datasets:cc_protos",
],
)

@ -6,9 +6,9 @@ PLEASE DO NOT DEPEND ON THE CONTENTS OF THIS FILE, IT IS UNSTABLE.
load("//:protobuf.bzl", "internal_php_proto_library")
def proto3_from_proto2_data(
name,
srcs,
**kwargs):
name,
srcs,
**kwargs):
"""Transforms proto2 binary data into a proto3-compatible format,
Args:
@ -22,7 +22,7 @@ def proto3_from_proto2_data(
for src in srcs:
outs.append("proto3/" + src)
out_files.append("$(RULEDIR)/proto3/" + src)
src_files.append("$(rootpath %s)" % src);
src_files.append("$(rootpath %s)" % src)
native.genrule(
name = name + "_genrule",
@ -32,13 +32,15 @@ def proto3_from_proto2_data(
],
outs = outs,
cmd = "$(execpath //benchmarks/util:proto3_data_stripper) %s %s" % (
" ".join(src_files), " ".join(out_files)),
" ".join(src_files),
" ".join(out_files),
),
)
native.filegroup(
name = name,
srcs = outs,
**kwargs,
**kwargs
)
def _proto3_from_proto2_library(
@ -56,7 +58,7 @@ def _proto3_from_proto2_library(
src_files = []
for src in srcs:
outs.append(src + "3")
src_files.append("$(rootpath %s)" % src);
src_files.append("$(rootpath %s)" % src)
native.genrule(
name = name,
@ -74,7 +76,7 @@ def _proto3_from_proto2_library(
--proto2_to_proto3_out=$(GENDIR) \
%s
""" % (" ".join(src_files)),
**kwargs,
**kwargs
)
def php_proto3_from_proto2_library(
@ -99,5 +101,5 @@ def php_proto3_from_proto2_library(
name = name,
srcs = [name + "_genrule"],
outs = outs,
**kwargs,
**kwargs
)

@ -1,3 +1,5 @@
#include <fstream>
#include "benchmarks.pb.h"
#include "benchmarks/datasets/google_message1/proto2/benchmark_message1_proto2.pb.h"
#include "benchmarks/datasets/google_message1/proto3/benchmark_message1_proto3.pb.h"
@ -6,8 +8,6 @@
#include "benchmarks/datasets/google_message4/benchmark_message4.pb.h"
#include "data_proto2_to_proto3_util.h"
#include <fstream>
using google::protobuf::util::Proto3DataStripper;
std::string ReadFile(const std::string& name) {

@ -7,15 +7,15 @@
#include "google/protobuf/compiler/plugin.h"
using google::protobuf::FileDescriptorProto;
using google::protobuf::FileDescriptor;
using google::protobuf::DescriptorPool;
using google::protobuf::FileDescriptor;
using google::protobuf::FileDescriptorProto;
using google::protobuf::io::Printer;
using google::protobuf::util::SchemaGroupStripper;
using google::protobuf::util::EnumScrubber;
using google::protobuf::util::ExtensionStripper;
using google::protobuf::util::FieldScrubber;
using google::protobuf::util::ImportScrubber;
using google::protobuf::util::SchemaGroupStripper;
namespace google {
namespace protobuf {
@ -37,9 +37,8 @@ DescriptorPool* GetPool() {
class Proto2ToProto3Generator final : public CodeGenerator {
public:
bool GenerateAll(const std::vector<const FileDescriptor*>& files,
const std::string& parameter,
GeneratorContext* context,
std::string* error) const {
const std::string& parameter, GeneratorContext* context,
std::string* error) const {
for (int i = 0; i < files.size(); i++) {
for (auto file : files) {
if (CanGenerate(file)) {
@ -52,10 +51,8 @@ class Proto2ToProto3Generator final : public CodeGenerator {
return true;
}
bool Generate(const FileDescriptor* file,
const std::string& parameter,
GeneratorContext* context,
std::string* error) const {
bool Generate(const FileDescriptor* file, const std::string& parameter,
GeneratorContext* context, std::string* error) const {
FileDescriptorProto new_file;
file->CopyTo(&new_file);
new_file.set_name(ImportScrubber::ScrubFilename(file->name()));
@ -71,7 +68,7 @@ class Proto2ToProto3Generator final : public CodeGenerator {
std::string filename = file->name();
std::string basename = StripProtoExt(filename);
std::vector<std::pair<std::string,std::string>> option_pairs;
std::vector<std::pair<std::string, std::string>> option_pairs;
ParseGeneratorParameter(parameter, &option_pairs);
std::unique_ptr<google::protobuf::io::ZeroCopyOutputStream> output(
@ -82,14 +79,16 @@ class Proto2ToProto3Generator final : public CodeGenerator {
return true;
}
private:
bool CanGenerate(const FileDescriptor* file) const {
if (GetPool()->FindFileByName(ImportScrubber::ScrubFilename(file->name())) != nullptr) {
if (GetPool()->FindFileByName(
ImportScrubber::ScrubFilename(file->name())) != nullptr) {
return false;
}
for (int j = 0; j < file->dependency_count(); j++) {
if (GetPool()->FindFileByName(ImportScrubber::ScrubFilename(
file->dependency(j)->name())) == nullptr) {
file->dependency(j)->name())) == nullptr) {
return false;
}
}

@ -1,12 +1,14 @@
"""Parses benchmark results into a standardized json output."""
import argparse
import json
import re
import os.path
from benchmarks import benchmarks_pb2
# BEGIN OPENSOURCE
import sys
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir))
# END OPENSOURCE
from benchmarks import benchmarks_pb2
__file_size_map = {}

@ -189,11 +189,11 @@ class FieldScrubber {
class ImportScrubber {
public:
static std::string ScrubFilename(const std::string& filename) {
static std::string ScrubFilename(const std::string &filename) {
return filename + "3";
}
static void ScrubFile(FileDescriptorProto *file) {
for(std::string& import: *file->mutable_dependency()) {
for (std::string &import : *file->mutable_dependency()) {
import += "3";
}
}

@ -9,9 +9,7 @@ def _arch_test_impl(
bazel_binaries = [],
system_binaries = [],
**kwargs):
"""
Bazel rule to verify that a Bazel or system binary is built for the
aarch64 architecture.
"""Bazel rule to verify that a Bazel or system binary is built for the aarch64 architecture.
Args:
name: the name of the test.
@ -19,7 +17,7 @@ def _arch_test_impl(
file_platform: the expected output of `file`.
bazel_binaries: a set of binary targets to inspect.
system_binaries: a set of paths to system executables to inspect.
**kargs: other keyword arguments that are passed to the test.
**kwargs: other keyword arguments that are passed to the test.
"""
inline_sh_test(
@ -30,27 +28,29 @@ def _arch_test_impl(
(file -L $$binary | grep -q "%s") \
|| (echo "Test binary is not an %s binary: "; file -L $$binary; exit 1)
done
""" % (" ".join(bazel_binaries),
" ".join(system_binaries),
file_platform,
platform),
""" % (
" ".join(bazel_binaries),
" ".join(system_binaries),
file_platform,
platform,
),
target_compatible_with = select({
"//build_defs:"+platform: [],
"//conditions:default": ["@platforms//:incompatible"],
"//build_defs:" + platform: [],
"//conditions:default": ["@platforms//:incompatible"],
}),
**kwargs
)
def aarch64_test(**kwargs):
_arch_test_impl(
platform = "aarch64",
file_platform = "ELF 64-bit LSB executable, ARM aarch64",
**kwargs,
)
_arch_test_impl(
platform = "aarch64",
file_platform = "ELF 64-bit LSB executable, ARM aarch64",
**kwargs
)
def x86_64_test(**kwargs):
_arch_test_impl(
platform = "x86_64",
file_platform = "ELF 64-bit LSB executable, ARM x86_64",
**kwargs,
)
_arch_test_impl(
platform = "x86_64",
file_platform = "ELF 64-bit LSB executable, ARM x86_64",
**kwargs
)

@ -1,3 +1,8 @@
"""
Internal tools to migrate shell commands to Bazel as an intermediate step
to wider Bazelification.
"""
def inline_sh_binary(
name,
srcs = [],
@ -6,9 +11,11 @@ def inline_sh_binary(
cmd = "",
testonly = None,
**kwargs):
"""Bazel rule to wrap up an inline bash script in a binary. This is most
useful as a stop-gap solution for migrating off Autotools. These binaries
are likely to be non-hermetic, with implicit system dependencies.
"""Bazel rule to wrap up an inline bash script in a binary.
This is most useful as a stop-gap solution for migrating off Autotools.
These binaries are likely to be non-hermetic, with implicit system
dependencies.
NOTE: the rule is only an internal workaround. The interface may change and
the rule may be removed when everything is properly "Bazelified".
@ -19,12 +26,12 @@ def inline_sh_binary(
tools: the executable tools used directly by the script. Any target used
with rootpath/execpath/location must be declared here or in `srcs`.
deps: a list of dependency labels that are required to run this binary.
**kargs: other keyword arguments that are passed to sh_binary.
cmd: the inline sh command to run.
**kwargs: other keyword arguments that are passed to sh_binary.
testonly: common rule attribute (see:
https://bazel.build/reference/be/common-definitions#common-attributes)
"""
native.genrule(
name = name + "_genrule",
srcs = srcs,
@ -50,9 +57,10 @@ def inline_sh_test(
deps = [],
cmd = "",
**kwargs):
"""Bazel rule to wrap up an inline bash script in a test. This is most
useful as a stop-gap solution for migrating off Autotools. These tests
are likely to be non-hermetic, with implicit system dependencies.
"""Bazel rule to wrap up an inline bash script in a test.
This is most useful as a stop-gap solution for migrating off Autotools.
These tests are likely to be non-hermetic, with implicit system dependencies.
NOTE: the rule is only an internal workaround. The interface may change and
the rule may be removed when everything is properly "Bazelified".
@ -63,11 +71,11 @@ def inline_sh_test(
tools: the executable tools used directly by the script. Any target used
with rootpath/execpath/location must be declared here or in `srcs`.
deps: a list of dependency labels that are required to run this binary.
**kargs: other keyword arguments that are passed to sh_binary.
cmd: the inline sh command to run.
**kwargs: other keyword arguments that are passed to sh_binary.
https://bazel.build/reference/be/common-definitions#common-attributes)
"""
native.genrule(
name = name + "_genrule",
srcs = srcs,

@ -0,0 +1,32 @@
# Setup our dependency on Abseil.
set(ABSL_PROPAGATE_CXX_STD ON)
if(protobuf_ABSL_PROVIDER STREQUAL "module")
if(NOT ABSL_ROOT_DIR)
set(ABSL_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/abseil-cpp)
endif()
if(EXISTS "${ABSL_ROOT_DIR}/CMakeLists.txt")
if(protobuf_INSTALL)
# When protobuf_INSTALL is enabled and Abseil will be built as a module,
# Abseil will be installed along with protobuf for convenience.
set(ABSL_ENABLE_INSTALL ON)
endif()
add_subdirectory(${ABSL_ROOT_DIR} third_party/abseil-cpp)
else()
message(WARNING "protobuf_ABSL_PROVIDER is \"module\" but ABSL_ROOT_DIR is wrong")
endif()
if(protobuf_INSTALL AND NOT _protobuf_INSTALL_SUPPORTED_FROM_MODULE)
message(WARNING "protobuf_INSTALL will be forced to FALSE because protobuf_ABSL_PROVIDER is \"module\" and CMake version (${CMAKE_VERSION}) is less than 3.13.")
set(protobuf_INSTALL FALSE)
endif()
elseif(protobuf_ABSL_PROVIDER STREQUAL "package")
# Use "CONFIG" as there is no built-in cmake module for absl.
find_package(absl REQUIRED CONFIG)
endif()
set(_protobuf_FIND_ABSL "if(NOT TARGET absl::strings)\n find_package(absl CONFIG)\nendif()")
set(protobuf_ABSL_USED_TARGETS
absl::strings
absl::strings_internal
)

@ -48,8 +48,11 @@ target_include_directories(
conformance_cpp
PUBLIC ${protobuf_SOURCE_DIR})
target_include_directories(conformance_cpp PRIVATE ${ABSL_ROOT_DIR})
target_link_libraries(conformance_test_runner ${protobuf_LIB_PROTOBUF})
target_link_libraries(conformance_cpp ${protobuf_LIB_PROTOBUF})
target_link_libraries(conformance_cpp ${protobuf_ABSL_USED_TARGETS})
add_test(NAME conformance_cpp_test
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/conformance_test_runner

@ -23,6 +23,7 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "Android")
target_link_libraries(libprotobuf-lite PRIVATE log)
endif()
target_include_directories(libprotobuf-lite PUBLIC ${protobuf_SOURCE_DIR}/src)
target_include_directories(libprotobuf-lite PRIVATE ${ABSL_ROOT_DIR})
if(protobuf_BUILD_SHARED_LIBS)
target_compile_definitions(libprotobuf-lite
PUBLIC PROTOBUF_USE_DLLS

@ -26,6 +26,7 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "Android")
target_link_libraries(libprotobuf PRIVATE log)
endif()
target_include_directories(libprotobuf PUBLIC ${protobuf_SOURCE_DIR}/src)
target_include_directories(libprotobuf PRIVATE ${ABSL_ROOT_DIR})
if(protobuf_BUILD_SHARED_LIBS)
target_compile_definitions(libprotobuf
PUBLIC PROTOBUF_USE_DLLS

@ -16,6 +16,7 @@ if(protobuf_HAVE_LD_VERSION_SCRIPT)
LINK_DEPENDS ${protobuf_SOURCE_DIR}/src/libprotoc.map)
endif()
target_link_libraries(libprotoc PRIVATE libprotobuf)
target_include_directories(libprotoc PRIVATE ${ABSL_ROOT_DIR})
if(protobuf_BUILD_SHARED_LIBS)
target_compile_definitions(libprotoc
PUBLIC PROTOBUF_USE_DLLS

@ -3,6 +3,7 @@ include("${CMAKE_CURRENT_LIST_DIR}/protobuf-options.cmake")
# Depend packages
@_protobuf_FIND_ZLIB@
@_protobuf_FIND_ABSL@
# Imported targets
include("${CMAKE_CURRENT_LIST_DIR}/protobuf-targets.cmake")

@ -6,6 +6,7 @@ add_executable(protoc ${protoc_files} ${protobuf_version_rc_file})
target_link_libraries(protoc
libprotoc
libprotobuf
${protobuf_ABSL_USED_TARGETS}
)
add_executable(protobuf::protoc ALIAS protoc)

@ -78,7 +78,9 @@ endforeach(proto_file)
add_library(protobuf-lite-test-common STATIC
${lite_test_util_srcs} ${lite_test_proto_files})
target_link_libraries(protobuf-lite-test-common ${protobuf_LIB_PROTOBUF_LITE} GTest::gmock)
target_include_directories(protobuf-lite-test-common PRIVATE ${ABSL_ROOT_DIR})
target_link_libraries(protobuf-lite-test-common
${protobuf_LIB_PROTOBUF_LITE} ${protobuf_ABSL_USED_TARGETS} GTest::gmock)
set(common_test_files
${test_util_hdrs}
@ -89,7 +91,9 @@ set(common_test_files
add_library(protobuf-test-common STATIC
${common_test_files} ${tests_proto_files})
target_link_libraries(protobuf-test-common ${protobuf_LIB_PROTOBUF} GTest::gmock)
target_include_directories(protobuf-test-common PRIVATE ${ABSL_ROOT_DIR})
target_link_libraries(protobuf-test-common
${protobuf_LIB_PROTOBUF} ${protobuf_ABSL_USED_TARGETS} GTest::gmock)
set(tests_files
${protobuf_test_files}

@ -1,8 +1,7 @@
# Conformance testing for Protobuf.
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_proto_library", "objc_library")
load("@rules_python//python:defs.bzl", "py_library")
load("//:protobuf.bzl", "internal_py_proto_library", "internal_php_proto_library", "internal_csharp_proto_library", "internal_ruby_proto_library", "internal_objc_proto_library")
load("//:protobuf.bzl", "internal_csharp_proto_library", "internal_objc_proto_library", "internal_php_proto_library", "internal_py_proto_library", "internal_ruby_proto_library")
load("//build_defs:internal_shell.bzl", "inline_sh_binary")
load(
"@rules_pkg//:mappings.bzl",
@ -94,10 +93,10 @@ internal_objc_proto_library(
internal_py_proto_library(
name = "conformance_py_proto",
srcs = ["conformance.proto"],
srcs_version = "PY2AND3",
visibility = [
"//python:__subpackages__",
],
srcs_version = "PY2AND3",
)
internal_php_proto_library(
@ -183,21 +182,25 @@ cc_binary(
cc_binary(
name = "conformance_cpp",
testonly = 1,
srcs = ["conformance_cpp.cc"],
visibility = ["//src:__subpackages__"],
deps = [
":conformance_cc_proto",
"//:protobuf",
"//:test_messages_proto2_cc_proto",
"//:test_messages_proto3_cc_proto",
],
testonly = 1,
visibility = ["//src:__subpackages__"],
)
java_binary(
name = "conformance_java",
testonly = 1,
srcs = ["ConformanceJava.java"],
main_class = "ConformanceJava",
visibility = [
"//java:__subpackages__",
],
deps = [
":conformance_java_proto",
"//:protobuf_java",
@ -205,14 +208,12 @@ java_binary(
"//:test_messages_proto2_java_proto",
"//:test_messages_proto3_java_proto",
],
testonly = 1,
visibility = [
"//java:__subpackages__",
],
)
java_binary(
name = "conformance_java_lite",
testonly = 1,
srcs = ["ConformanceJavaLite.java"],
main_class = "ConformanceJavaLite",
visibility = [
"//java:__subpackages__",
@ -224,110 +225,111 @@ java_binary(
"//:test_messages_proto2_java_proto_lite",
"//:test_messages_proto3_java_proto_lite",
],
testonly = 1,
srcs = ["ConformanceJavaLite.java"],
)
py_binary(
name = "conformance_python",
testonly = 1,
srcs = ["conformance_python.py"],
imports = [
"..",
"../python",
],
srcs_version = "PY2AND3",
visibility = ["//python:__subpackages__"],
deps = [
":conformance_py_proto",
"//:protobuf_python",
"//python:test_messages_proto2_py_proto",
"//python:test_messages_proto3_py_proto",
],
imports = [".", "../python"],
srcs_version = "PY2AND3",
testonly = 1,
visibility = ["//python:__subpackages__"],
)
inline_sh_binary(
name = "conformance_php",
testonly = 1,
srcs = [
"conformance_php.php",
"autoload.php",
],
deps = [
":conformance_php_proto",
"//php:source_files",
"//:test_messages_proto3_php_proto",
"conformance_php.php",
],
cmd = """
php -d include_path=conformance:src/google/protobuf \\
-d auto_prepend_file=$(rootpath autoload.php) \\
$(rootpath conformance_php.php)
""",
testonly = 1,
visibility = ["//php:__subpackages__"],
deps = [
":conformance_php_proto",
"//:test_messages_proto3_php_proto",
"//php:source_files",
],
)
inline_sh_binary(
name = "conformance_php_c",
testonly = 1,
srcs = [
"conformance_php.php",
"//php:extension",
],
deps = [
":conformance_php_proto",
"//:test_messages_proto3_php_proto",
],
cmd = """
php -dextension=$(rootpath //php:extension) \\
-d include_path=conformance:src/google/protobuf \\
$(rootpath conformance_php.php)
""",
testonly = 1,
visibility = ["//php:__subpackages__"],
deps = [
":conformance_php_proto",
"//:test_messages_proto3_php_proto",
],
)
inline_sh_binary(
name = "conformance_csharp",
testonly = 1,
srcs = ["//csharp/src/Google.Protobuf.Conformance:conformance_dll"],
cmd = "dotnet $(rootpath //csharp/src/Google.Protobuf.Conformance:conformance_dll)",
visibility = ["//csharp:__subpackages__"],
deps = [
"//csharp/src/Google.Protobuf.Conformance:conformance_runfiles",
],
cmd = "dotnet $(rootpath //csharp/src/Google.Protobuf.Conformance:conformance_dll)",
testonly = 1,
visibility = ["//csharp:__subpackages__"],
)
objc_library(
name = "conformance_objc_lib",
testonly = 1,
non_arc_srcs = ["conformance_objc.m"],
# See https://github.com/bazelbuild/bazel/issues/12897.
tags = ["manual"],
deps = [
":conformance_objc_proto",
"//:test_messages_proto2_objc_proto",
"//:test_messages_proto3_objc_proto",
],
testonly = 1,
# See https://github.com/bazelbuild/bazel/issues/12897.
tags = ["manual"],
)
cc_binary(
name = "conformance_objc",
deps = [":conformance_objc_lib"],
testonly = 1,
# See https://github.com/bazelbuild/bazel/issues/12897.
tags = ["manual"],
visibility = ["//objectivec:__subpackages__"],
deps = [":conformance_objc_lib"],
)
inline_sh_binary(
name = "conformance_ruby",
testonly = 1,
srcs = ["conformance_ruby.rb"],
cmd = "RUBYLIB=ruby/lib:conformance:src $(rootpath conformance_ruby.rb)",
visibility = ["//ruby:__subpackages__"],
deps = [
":conformance_ruby_proto",
"//:well_known_ruby_protos",
"//:test_messages_proto2_ruby_proto",
"//:test_messages_proto3_ruby_proto",
"//:well_known_ruby_protos",
"//ruby:protobuf",
],
cmd = "RUBYLIB=ruby/lib:conformance:src $(rootpath conformance_ruby.rb)",
testonly = 1,
visibility = ["//ruby:__subpackages__"],
)
################################################################################

@ -45,6 +45,7 @@
#include <google/protobuf/stubs/status.h>
#include <google/protobuf/stubs/statusor.h>
#include "conformance/conformance.pb.h"
#include "conformance/conformance.pb.h"
#include <google/protobuf/test_messages_proto2.pb.h>
#include <google/protobuf/test_messages_proto3.pb.h>
#include <google/protobuf/test_messages_proto3.pb.h>

@ -42,7 +42,7 @@ from google.protobuf import message
from google.protobuf import test_messages_proto3_pb2
from google.protobuf import test_messages_proto2_pb2
from google.protobuf import text_format
import conformance_pb2
from conformance import conformance_pb2
sys.stdout = os.fdopen(sys.stdout.fileno(), 'wb', 0)
sys.stdin = os.fdopen(sys.stdin.fileno(), 'rb', 0)

@ -42,7 +42,7 @@
#include <google/protobuf/util/field_comparator.h>
#include <google/protobuf/util/json_util.h>
#include <google/protobuf/util/message_differencer.h>
#include "conformance.pb.h"
#include "conformance/conformance.pb.h"
using conformance::ConformanceRequest;
using conformance::ConformanceResponse;

@ -45,7 +45,7 @@
#include <google/protobuf/descriptor.h>
#include <google/protobuf/wire_format_lite.h>
#include <google/protobuf/util/type_resolver.h>
#include "conformance.pb.h"
#include "conformance/conformance.pb.h"
namespace conformance {
class ConformanceRequest;

@ -63,7 +63,7 @@
#include <vector>
#include <google/protobuf/stubs/stringprintf.h>
#include "conformance.pb.h"
#include "conformance/conformance.pb.h"
#include "conformance_test.h"
using conformance::ConformanceResponse;

@ -39,7 +39,7 @@ def conformance_test(
"@bazel_tools//tools/bash/runfiles",
],
tags = ["conformance"],
**kwargs,
**kwargs
)
def _strip_bazel(testee):

@ -41,11 +41,11 @@ protoc_middleman_dart: addressbook.proto
add_person_cpp: add_person.cc protoc_middleman
pkg-config --cflags protobuf # fails if protobuf is not installed
c++ -std=c++11 add_person.cc addressbook.pb.cc -o add_person_cpp `pkg-config --cflags --libs protobuf`
c++ -std=c++14 add_person.cc addressbook.pb.cc -o add_person_cpp `pkg-config --cflags --libs protobuf`
list_people_cpp: list_people.cc protoc_middleman
pkg-config --cflags protobuf # fails if protobuf is not installed
c++ -std=c++11 list_people.cc addressbook.pb.cc -o list_people_cpp `pkg-config --cflags --libs protobuf`
c++ -std=c++14 list_people.cc addressbook.pb.cc -o list_people_cpp `pkg-config --cflags --libs protobuf`
add_person_dart: add_person.dart protoc_middleman_dart

@ -62,7 +62,7 @@ do
PROTOC=$BOOTSTRAP_PROTOC
BOOTSTRAP_PROTOC=""
else
bazel build -j$(nproc) $@ //:protoc
bazel build $@ //:protoc
if test $? -ne 0; then
echo "Failed to build protoc."
exit 1

@ -1,7 +1,7 @@
package(default_visibility = ["//java:__subpackages__"])
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
package(default_visibility = ["//java:__subpackages__"])
pkg_files(
name = "dist_files",
srcs = [
@ -15,8 +15,8 @@ pkg_files(
java_test(
name = "java_version",
test_class = "JavaVersionTest",
srcs = ["JavaVersionTest.java"],
test_class = "JavaVersionTest",
deps = [
"@maven//:com_google_truth_truth",
"@maven//:junit_junit",

@ -25,6 +25,7 @@ kt_jvm_library(
deps = [
":only_for_use_in_proto_generated_code_its_generator_and_tests",
"//java/lite",
"@maven//:com_google_errorprone_error_prone_annotations",
],
)

@ -34,6 +34,11 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_annotations</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>

@ -4,5 +4,5 @@
set -ex
cmake -DCMAKE_POSITION_INDEPENDENT_CODE=ON -Dprotobuf_WITH_ZLIB=0 .
cmake -DCMAKE_POSITION_INDEPENDENT_CODE=ON -Dprotobuf_WITH_ZLIB=0 -Dprotobuf_BUILD_TESTS=OFF .
make -j8

@ -12,7 +12,7 @@ PYTHON="/opt/python/cp38-cp38/bin/python"
git submodule update --init --recursive
# Build protoc and libprotobuf
cmake -DCMAKE_POSITION_INDEPENDENT_CODE=ON -Dprotobuf_WITH_ZLIB=0 .
cmake -DCMAKE_POSITION_INDEPENDENT_CODE=ON -Dprotobuf_WITH_ZLIB=0 -Dprotobuf_BUILD_TESTS=OFF .
make -j8
# create a simple shell wrapper that runs crosscompiled protoc under qemu

@ -24,4 +24,4 @@ kokoro/linux/aarch64/dockcross_helpers/run_dockcross_manylinux2014_aarch64.sh ko
# otherwise the UID would be homeless under the docker container and pip install wouldn't work. For simplicity,
# we just run map the user's home to a throwaway temporary directory
docker run $DOCKER_TTY_ARGS --rm --user "$(id -u):$(id -g)" -e "HOME=/home/fake-user" -v "$(mktemp -d):/home/fake-user" -v "$(pwd)":/work -w /work arm64v8/ruby:2.7.3-buster kokoro/linux/aarch64/ruby_build_and_run_tests_with_qemu_aarch64.sh
docker run $DOCKER_TTY_ARGS --rm --user "$(id -u):$(id -g)" -e "HOME=/home/fake-user" -e "PROTOC=/work/protoc" -v "$(mktemp -d):/home/fake-user" -v "$(pwd)":/work -w /work arm64v8/ruby:2.7.3-buster kokoro/linux/aarch64/ruby_build_and_run_tests_with_qemu_aarch64.sh

@ -11,7 +11,9 @@ env_vars {
env_vars {
key: "BAZEL_TARGETS"
value: "//python/... @upb//python/..."
# Note: upb tests don't work since the C++ extension takes precedence here.
# Note: upb tests don't work since the C++ extension takes precedence here.
value: "//python/..."
}
env_vars {

@ -11,6 +11,7 @@ env_vars {
env_vars {
key: "BAZEL_TARGETS"
# Note: upb tests don't work since the C++ extension takes precedence here.
value: "//python/..."
}

@ -11,7 +11,8 @@ env_vars {
env_vars {
key: "BAZEL_TARGETS"
value: "//python/... @upb//python/..."
# Note: upb tests don't work since the C++ extension takes precedence here.
value: "//python/..."
}
env_vars {

@ -11,6 +11,7 @@ env_vars {
env_vars {
key: "BAZEL_TARGETS"
# Note: upb tests don't work since the C++ extension takes precedence here.
value: "//python/..."
}

@ -11,7 +11,8 @@ env_vars {
env_vars {
key: "BAZEL_TARGETS"
value: "//python/... @upb//python/..."
# Note: upb tests don't work since the C++ extension takes precedence here.
value: "//python/..."
}
env_vars {

@ -11,6 +11,7 @@ env_vars {
env_vars {
key: "BAZEL_TARGETS"
# Note: upb tests don't work since the C++ extension takes precedence here.
value: "//python/..."
}

@ -11,7 +11,8 @@ env_vars {
env_vars {
key: "BAZEL_TARGETS"
value: "//python/... @upb//python/..."
# Note: upb tests don't work since the C++ extension takes precedence here.
value: "//python/..."
}
env_vars {

@ -11,6 +11,7 @@ env_vars {
env_vars {
key: "BAZEL_TARGETS"
# Note: upb tests don't work since the C++ extension takes precedence here.
value: "//python/..."
}

@ -0,0 +1,16 @@
#!/bin/bash
#
# This is the top-level script we give to Kokoro as the entry point for
# running the "continuous" and "presubmit" jobs.
set -ex
# Change to repo root
cd $(dirname $0)/../../..
# Initialize any submodules.
git submodule update --init --recursive
kokoro/linux/aarch64/qemu_helpers/prepare_qemu.sh
kokoro/linux/aarch64/test_ruby_aarch64.sh

@ -1,26 +1,11 @@
# Config file for running tests in Kokoro
# Location of the build script in repository
build_file: "protobuf/kokoro/linux/bazel.sh"
build_file: "protobuf/kokoro/linux/ruby_aarch64/build.sh"
timeout_mins: 120
env_vars {
key: "CONTAINER_IMAGE"
value: "gcr.io/protobuf-build/emulation/linux:aarch64-4e847d7a01c1792471b6dd985ab0bf2677332e6f"
}
env_vars {
key: "BAZEL_TARGETS"
value: "//ruby/..."
}
env_vars {
key: "BAZEL_EXTRA_FLAGS"
value: "--define=ruby_platform=c"
}
action {
define_artifacts {
regex: "**/sponge_log.*"
regex: "**/sponge_log.xml"
}
}

@ -1,26 +1,11 @@
# Config file for running tests in Kokoro
# Location of the build script in repository
build_file: "protobuf/kokoro/linux/bazel.sh"
build_file: "protobuf/kokoro/linux/ruby_aarch64/build.sh"
timeout_mins: 120
env_vars {
key: "CONTAINER_IMAGE"
value: "gcr.io/protobuf-build/emulation/linux:aarch64-4e847d7a01c1792471b6dd985ab0bf2677332e6f"
}
env_vars {
key: "BAZEL_TARGETS"
value: "//ruby/..."
}
env_vars {
key: "BAZEL_EXTRA_FLAGS"
value: "--define=ruby_platform=c"
}
action {
define_artifacts {
regex: "**/sponge_log.*"
regex: "**/sponge_log.xml"
}
}

@ -6,5 +6,7 @@ CXXFLAGS_COMMON="-std=c++14 -DNDEBUG -mmacosx-version-min=10.9"
cd github/protobuf
bazel build //:protoc --dynamic_mode=off
mkdir -p build64/src
cp bazel-bin/protoc build64/src/protoc
file bazel-bin/protoc
otool -L bazel-bin/protoc | grep dylib

@ -1,10 +1,10 @@
{
"dependency_tree": {
"__AUTOGENERATED_FILE_DO_NOT_MODIFY_THIS_FILE_MANUALLY": "THERE_IS_NO_DATA_ONLY_ZUUL",
"__INPUT_ARTIFACTS_HASH": 579287445,
"__INPUT_ARTIFACTS_HASH": -1875290602,
"__RESOLVED_ARTIFACTS_HASH": -1248440885,
"conflict_resolution": {
"com.google.errorprone:error_prone_annotations:2.3.2": "com.google.errorprone:error_prone_annotations:2.11.0"
"com.google.errorprone:error_prone_annotations:2.5.1": "com.google.errorprone:error_prone_annotations:2.11.0"
},
"dependencies": [
{

@ -5,10 +5,10 @@
set -e
PROTOC=protoc
PROTOC=$(realpath protoc)
if [ ! -f $PROTOC ]; then
bazel build -c opt //:protoc
PROTOC=bazel-bin/protoc
PROTOC=$(realpath bazel-bin/protoc)
fi
if test ! -e src/google/protobuf/stubs/common.h; then
@ -19,16 +19,17 @@ __EOF__
exit 1
fi
$PROTOC --php_out=internal:php/src google/protobuf/descriptor.proto
$PROTOC --php_out=internal_generate_c_wkt:php/src \
src/google/protobuf/any.proto \
src/google/protobuf/api.proto \
src/google/protobuf/duration.proto \
src/google/protobuf/empty.proto \
src/google/protobuf/field_mask.proto \
src/google/protobuf/source_context.proto \
src/google/protobuf/struct.proto \
src/google/protobuf/type.proto \
src/google/protobuf/timestamp.proto \
src/google/protobuf/wrappers.proto
pushd src
$PROTOC --php_out=internal:../php/src google/protobuf/descriptor.proto
$PROTOC --php_out=internal_generate_c_wkt:../php/src \
google/protobuf/any.proto \
google/protobuf/api.proto \
google/protobuf/duration.proto \
google/protobuf/empty.proto \
google/protobuf/field_mask.proto \
google/protobuf/source_context.proto \
google/protobuf/struct.proto \
google/protobuf/type.proto \
google/protobuf/timestamp.proto \
google/protobuf/wrappers.proto
popd

@ -381,9 +381,9 @@ cc_dist_library(
"//src/google/protobuf/util:differencer",
"//src/google/protobuf/util:field_mask_util",
"//src/google/protobuf/util:json_util",
"//src/google/protobuf/util:zero_copy_sink",
"//src/google/protobuf/util:time_util",
"//src/google/protobuf/util:type_resolver_util",
"//src/google/protobuf/util:zero_copy_sink",
"//src/google/protobuf/util/internal:datapiece",
"//src/google/protobuf/util/internal:default_value",
"//src/google/protobuf/util/internal:field_mask_utility",
@ -427,23 +427,23 @@ cc_dist_library(
cc_dist_library(
name = "compiler_annotation_test_util",
deps = ["//src/google/protobuf/compiler:annotation_test_util"],
testonly = 1,
tags = ["manual"],
deps = ["//src/google/protobuf/compiler:annotation_test_util"],
)
cc_dist_library(
name = "compiler_mock_code_generator",
deps = ["//src/google/protobuf/compiler:mock_code_generator"],
testonly = 1,
tags = ["manual"],
deps = ["//src/google/protobuf/compiler:mock_code_generator"],
)
cc_dist_library(
name = "testinglib",
deps = ["//src/google/protobuf/testing"],
testonly = 1,
tags = ["manual"],
deps = ["//src/google/protobuf/testing"],
)
################################################################################

@ -6,7 +6,7 @@ PROTOBUF_MAVEN_ARTIFACTS = [
"com.google.caliper:caliper:1.0-beta-3",
"com.google.code.findbugs:jsr305:3.0.2",
"com.google.code.gson:gson:2.8.9",
"com.google.errorprone:error_prone_annotations:2.3.2",
"com.google.errorprone:error_prone_annotations:2.5.1",
"com.google.j2objc:j2objc-annotations:1.3",
"com.google.guava:guava:31.1-jre",
"com.google.guava:guava-testlib:31.1-jre",

@ -7,7 +7,6 @@
# //:well_known_types_py_pb2
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@rules_python//python:defs.bzl", "py_library")
load("//:protobuf.bzl", "internal_py_proto_library")
load("//build_defs:cpp_opts.bzl", "COPTS")
@ -53,8 +52,8 @@ internal_py_proto_library(
internal_copy_files(
name = "copied_wkt_proto_files",
srcs = [
"//src/google/protobuf:descriptor_proto_srcs",
"//:well_known_type_protos",
"//src/google/protobuf:descriptor_proto_srcs",
],
strip_prefix = "src",
)
@ -216,28 +215,28 @@ internal_py_proto_library(
internal_py_proto_library(
name = "test_messages_proto2_py_proto",
testonly = 1,
visibility = [
"//conformance:__pkg__",
"//python:__subpackages__",
],
srcs = [":copied_test_messages_proto2_files"],
include = ".",
default_runtime = "//:protobuf_python",
protoc = "//:protoc",
visibility = [
"//conformance:__pkg__",
"//python:__subpackages__",
],
)
internal_py_proto_library(
name = "test_messages_proto3_py_proto",
testonly = 1,
srcs = [":copied_test_messages_proto3_files"],
include = ".",
default_runtime = "//:protobuf_python",
protoc = "//:protoc",
visibility = [
"//conformance:__pkg__",
"//python:__subpackages__",
],
srcs = [":copied_test_messages_proto3_files"],
deps = [":well_known_types_py_pb2"],
include = ".",
default_runtime = "//:protobuf_python",
protoc = "//:protoc",
)
py_library(
@ -400,27 +399,27 @@ py_test(
conformance_test(
name = "conformance_test",
failure_list = "//conformance:failure_list_python.txt",
testee = "//conformance:conformance_python",
text_format_failure_list = "//conformance:text_format_failure_list_python.txt",
env = {"PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": "python"},
failure_list = "//conformance:failure_list_python.txt",
target_compatible_with = select({
":use_fast_cpp_protos": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
testee = "//conformance:conformance_python",
text_format_failure_list = "//conformance:text_format_failure_list_python.txt",
)
# Note: this requires --define=use_fast_cpp_protos=true
conformance_test(
name = "conformance_test_cpp",
failure_list = "//conformance:failure_list_python.txt",
testee = "//conformance:conformance_python",
text_format_failure_list = "//conformance:text_format_failure_list_python_cpp.txt",
env = {"PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": "cpp"},
failure_list = "//conformance:failure_list_python.txt",
target_compatible_with = select({
":use_fast_cpp_protos": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
testee = "//conformance:conformance_python",
text_format_failure_list = "//conformance:text_format_failure_list_python_cpp.txt",
)
################################################################################

@ -27,12 +27,12 @@
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""Test that Kokoro is using the expected version of python."""
import os
import unittest
import sys
import unittest
class PythonVersionTest(unittest.TestCase):
@ -40,11 +40,12 @@ class PythonVersionTest(unittest.TestCase):
"""Test that we can import nested import public messages."""
exp = os.getenv('KOKORO_PYTHON_VERSION', '')
if exp == '':
print("No kokoro python version found, skipping check", file=sys.stderr)
if not exp:
print('No kokoro python version found, skipping check', file=sys.stderr)
return
self.assertTrue(sys.version.startswith(exp),
"Expected Python %s but found Python %s" % (exp, sys.version))
self.assertTrue(
sys.version.startswith(exp),
'Expected Python %s but found Python %s' % (exp, sys.version))
if __name__ == '__main__':

@ -306,7 +306,8 @@ if __name__ == '__main__':
else:
library_dirs = ['..']
TestConformanceCmd.target = '//python:conformance_test_cpp --define=use_fast_cpp_protos=true'
TestConformanceCmd.target = ('//python:conformance_test_cpp '
'--define=use_fast_cpp_protos=true')
extra_compile_args = []
@ -331,7 +332,7 @@ if __name__ == '__main__':
extra_compile_args.append('-Wno-invalid-offsetof')
extra_compile_args.append('-Wno-sign-compare')
extra_compile_args.append('-Wno-unused-variable')
extra_compile_args.append('-std=c++11')
extra_compile_args.append('-std=c++14')
if sys.platform == 'darwin':
extra_compile_args.append('-Wno-shorten-64-to-32')

@ -37,6 +37,7 @@
#include "repeated_field.h"
static VALUE cParseError = Qnil;
static VALUE cAbstractMessage = Qnil;
static ID descriptor_instancevar_interned;
static VALUE initialize_rb_class_with_no_args(VALUE klass) {
@ -1201,36 +1202,8 @@ VALUE build_class_from_descriptor(VALUE descriptor) {
klass = rb_define_class_id(
// Docs say this parameter is ignored. User will assign return value to
// their own toplevel constant class name.
rb_intern("Message"), rb_cObject);
rb_intern("Message"), cAbstractMessage);
rb_ivar_set(klass, descriptor_instancevar_interned, descriptor);
rb_define_alloc_func(klass, Message_alloc);
rb_require("google/protobuf/message_exts");
rb_include_module(klass, rb_eval_string("::Google::Protobuf::MessageExts"));
rb_extend_object(
klass, rb_eval_string("::Google::Protobuf::MessageExts::ClassMethods"));
rb_define_method(klass, "method_missing", Message_method_missing, -1);
rb_define_method(klass, "respond_to_missing?", Message_respond_to_missing,
-1);
rb_define_method(klass, "initialize", Message_initialize, -1);
rb_define_method(klass, "dup", Message_dup, 0);
// Also define #clone so that we don't inherit Object#clone.
rb_define_method(klass, "clone", Message_dup, 0);
rb_define_method(klass, "==", Message_eq, 1);
rb_define_method(klass, "eql?", Message_eq, 1);
rb_define_method(klass, "freeze", Message_freeze, 0);
rb_define_method(klass, "hash", Message_hash, 0);
rb_define_method(klass, "to_h", Message_to_h, 0);
rb_define_method(klass, "inspect", Message_inspect, 0);
rb_define_method(klass, "to_s", Message_inspect, 0);
rb_define_method(klass, "[]", Message_index, 1);
rb_define_method(klass, "[]=", Message_index_set, 2);
rb_define_singleton_method(klass, "decode", Message_decode, -1);
rb_define_singleton_method(klass, "encode", Message_encode, -1);
rb_define_singleton_method(klass, "decode_json", Message_decode_json, -1);
rb_define_singleton_method(klass, "encode_json", Message_encode_json, -1);
rb_define_singleton_method(klass, "descriptor", Message_descriptor, 0);
return klass;
}
@ -1392,8 +1365,38 @@ const upb_Message* Message_GetUpbMessage(VALUE value, const upb_MessageDef* m,
return self->msg;
}
static void Message_define_class(VALUE klass) {
rb_define_alloc_func(klass, Message_alloc);
rb_require("google/protobuf/message_exts");
rb_define_method(klass, "method_missing", Message_method_missing, -1);
rb_define_method(klass, "respond_to_missing?", Message_respond_to_missing,
-1);
rb_define_method(klass, "initialize", Message_initialize, -1);
rb_define_method(klass, "dup", Message_dup, 0);
// Also define #clone so that we don't inherit Object#clone.
rb_define_method(klass, "clone", Message_dup, 0);
rb_define_method(klass, "==", Message_eq, 1);
rb_define_method(klass, "eql?", Message_eq, 1);
rb_define_method(klass, "freeze", Message_freeze, 0);
rb_define_method(klass, "hash", Message_hash, 0);
rb_define_method(klass, "to_h", Message_to_h, 0);
rb_define_method(klass, "inspect", Message_inspect, 0);
rb_define_method(klass, "to_s", Message_inspect, 0);
rb_define_method(klass, "[]", Message_index, 1);
rb_define_method(klass, "[]=", Message_index_set, 2);
rb_define_singleton_method(klass, "decode", Message_decode, -1);
rb_define_singleton_method(klass, "encode", Message_encode, -1);
rb_define_singleton_method(klass, "decode_json", Message_decode_json, -1);
rb_define_singleton_method(klass, "encode_json", Message_encode_json, -1);
rb_define_singleton_method(klass, "descriptor", Message_descriptor, 0);
}
void Message_register(VALUE protobuf) {
cParseError = rb_const_get(protobuf, rb_intern("ParseError"));
cAbstractMessage = rb_define_class_under(protobuf, "AbstractMessage", rb_cObject);
Message_define_class(cAbstractMessage);
rb_gc_register_address(&cAbstractMessage);
// Ruby-interned string: "descriptor". We use this identifier to store an
// instance variable on message classes we create in order to link them back

@ -49,5 +49,10 @@ module Google
end
end
class AbstractMessage
include MessageExts
extend MessageExts::ClassMethods
end
private_constant :AbstractMessage
end
end

@ -216,8 +216,8 @@ cc_library(
"field_mask.pb.cc",
"generated_message_bases.cc",
"generated_message_reflection.cc",
"generated_message_tctable_gen.cc",
"generated_message_tctable_full.cc",
"generated_message_tctable_gen.cc",
"map_field.cc",
"message.cc",
"reflection_ops.cc",
@ -458,13 +458,16 @@ proto_library(
],
)
exports_files([
"test_messages_proto2.proto",
"test_messages_proto3.proto",
], visibility = [
"//:__pkg__",
"//python:__pkg__",
])
exports_files(
[
"test_messages_proto2.proto",
"test_messages_proto3.proto",
],
visibility = [
"//:__pkg__",
"//python:__pkg__",
],
)
proto_library(
name = "test_messages_proto2_proto",
@ -480,6 +483,10 @@ proto_library(
name = "test_messages_proto3_proto",
srcs = ["test_messages_proto3.proto"],
strip_import_prefix = "/src",
visibility = [
"//:__pkg__",
"//conformance:__pkg__",
],
deps = [
":any_proto",
":duration_proto",
@ -488,10 +495,6 @@ proto_library(
":timestamp_proto",
":wrappers_proto",
],
visibility = [
"//:__pkg__",
"//conformance:__pkg__",
],
)
cc_proto_library(
@ -1073,16 +1076,6 @@ cc_test(
],
)
# Legacy target: all test sources used to be part of this rule. It is
# still kept around for now.
cc_test(
name = "protobuf_test",
srcs = [],
deps = [
"@com_google_googletest//:gtest_main",
],
)
################################################################################
# Helper targets for Kotlin tests
################################################################################

@ -379,7 +379,7 @@ const char* Api::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) {
// .google.protobuf.Syntax syntax = 7;
case 7:
if (PROTOBUF_PREDICT_TRUE(static_cast<uint8_t>(tag) == 56)) {
uint64_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr);
uint32_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr);
CHK_(ptr);
_internal_set_syntax(static_cast<::PROTOBUF_NAMESPACE_ID::Syntax>(val));
} else
@ -806,7 +806,7 @@ const char* Method::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) {
// .google.protobuf.Syntax syntax = 7;
case 7:
if (PROTOBUF_PREDICT_TRUE(static_cast<uint8_t>(tag) == 56)) {
uint64_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr);
uint32_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr);
CHK_(ptr);
_internal_set_syntax(static_cast<::PROTOBUF_NAMESPACE_ID::Syntax>(val));
} else

@ -6,7 +6,6 @@ load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
load(
"@rules_pkg//:mappings.bzl",
"pkg_attributes",
"pkg_filegroup",
"pkg_files",
"strip_prefix",
)
@ -116,7 +115,6 @@ alias(
visibility = ["//visibility:public"],
)
# Test that the protoc binary is built for the correct architecture.
aarch64_test(
name = "protoc_aarch64_test",

@ -1844,7 +1844,7 @@ CommandLineInterface::InterpretArgument(const std::string& name,
if (!version_info_.empty()) {
std::cout << version_info_ << std::endl;
}
std::cout << "libprotoc " << internal::VersionString(PROTOBUF_VERSION)
std::cout << "libprotoc " << internal::ProtocVersionString(PROTOBUF_VERSION)
<< PROTOBUF_VERSION_SUFFIX << std::endl;
return PARSE_ARGUMENT_DONE_AND_EXIT; // Exit without running compiler.

@ -359,7 +359,8 @@ void CommandLineInterfaceTest::RunWithArgs(std::vector<std::string> args) {
if (plugin_path.empty() || !FileExists(plugin_path)) {
GOOGLE_LOG(ERROR)
<< "Plugin tests are likely to fail. Plugin executable not found at: " << plugin_path;
<< "Plugin executable not found. Plugin tests are likely to fail."
<< plugin_path;
} else {
args.push_back("--plugin=prefix-gen-plug=" + plugin_path);
}

@ -1102,10 +1102,10 @@ void ParseFunctionGenerator::GenerateFieldBody(
format.Set("enum_type",
QualifiedClassName(field->enum_type(), options_));
format(
"$uint64$ val = ::$proto_ns$::internal::ReadVarint64(&ptr);\n"
"$uint32$ val = ::$proto_ns$::internal::ReadVarint32(&ptr);\n"
"CHK_(ptr);\n");
if (!internal::cpp::HasPreservingUnknownEnumSemantics(field)) {
format("if (PROTOBUF_PREDICT_TRUE($enum_type$_IsValid(val))) {\n");
format("if (PROTOBUF_PREDICT_TRUE($enum_type$_IsValid(static_cast<int>(val)))) {\n");
format.Indent();
}
format("$msg$_internal_$put_field$(static_cast<$enum_type$>(val));\n");

@ -43,7 +43,7 @@ namespace compiler {
namespace java {
Context::Context(const FileDescriptor* file, const Options& options)
: name_resolver_(new ClassNameResolver), options_(options) {
: name_resolver_(new ClassNameResolver(options)), options_(options) {
InitializeFieldGeneratorInfo(file);
}

@ -96,6 +96,7 @@ void WriteMethodDocComment(io::Printer* printer,
const MethodDescriptor* method);
// Exposed for testing only.
// Also called by proto1-Java code generator.
PROTOC_EXPORT std::string EscapeJavadoc(const std::string& input);
} // namespace java

@ -80,6 +80,10 @@ EnumGenerator::~EnumGenerator() {}
void EnumGenerator::Generate(io::Printer* printer) {
WriteEnumDocComment(printer, descriptor_);
MaybePrintGeneratedAnnotation(context_, printer, descriptor_, immutable_api_);
if (!context_->options().opensource_runtime) {
printer->Print("@com.google.protobuf.Internal.ProtoNonnullApi\n");
}
printer->Print(
"$deprecation$public enum $classname$\n"
" implements com.google.protobuf.ProtocolMessageEnum {\n",
@ -181,23 +185,32 @@ void EnumGenerator::Generate(io::Printer* printer) {
printer->Print(
" return value;\n"
"}\n"
"\n"
"/**\n"
" * @param value The numeric wire value of the corresponding enum "
"entry.\n"
" * @return The enum associated with the given numeric wire value.\n"
" * @deprecated Use {@link #forNumber(int)} instead.\n"
" */\n"
"@java.lang.Deprecated\n"
"public static $classname$ valueOf(int value) {\n"
" return forNumber(value);\n"
"}\n"
"\n"
"\n");
if (context_->options().opensource_runtime) {
printer->Print(
"/**\n"
" * @param value The numeric wire value of the corresponding enum "
"entry.\n"
" * @return The enum associated with the given numeric wire value.\n"
" * @deprecated Use {@link #forNumber(int)} instead.\n"
" */\n"
"@java.lang.Deprecated\n"
"public static $classname$ valueOf(int value) {\n"
" return forNumber(value);\n"
"}\n"
"\n",
"classname", descriptor_->name());
}
printer->Print(
"/**\n"
" * @param value The numeric wire value of the corresponding enum "
"entry.\n"
" * @return The enum associated with the given numeric wire value.\n"
" */\n"
" */\n");
if (!context_->options().opensource_runtime) {
printer->Print("@com.google.protobuf.Internal.ProtoMethodMayReturnNull\n");
}
printer->Print(
"public static $classname$ forNumber(int value) {\n"
" switch (value) {\n",
"classname", descriptor_->name());

@ -60,7 +60,8 @@ namespace {
void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex,
int builderBitIndex, const FieldGeneratorInfo* info,
ClassNameResolver* name_resolver,
std::map<std::string, std::string>* variables) {
std::map<std::string, std::string>* variables,
Context* context) {
SetCommonFieldVariables(descriptor, info, variables);
(*variables)["type"] =
@ -68,7 +69,8 @@ void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex,
(*variables)["kt_type"] = EscapeKotlinKeywords((*variables)["type"]);
(*variables)["mutable_type"] =
name_resolver->GetMutableClassName(descriptor->enum_type());
(*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver);
(*variables)["default"] =
ImmutableDefaultValue(descriptor, name_resolver, context->options());
(*variables)["default_number"] =
StrCat(descriptor->default_value_enum()->number());
(*variables)["tag"] = StrCat(
@ -142,7 +144,7 @@ ImmutableEnumFieldGenerator::ImmutableEnumFieldGenerator(
: descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
SetEnumVariables(descriptor, messageBitIndex, builderBitIndex,
context->GetFieldGeneratorInfo(descriptor), name_resolver_,
&variables_);
&variables_, context);
}
ImmutableEnumFieldGenerator::~ImmutableEnumFieldGenerator() {}
@ -636,7 +638,7 @@ RepeatedImmutableEnumFieldGenerator::RepeatedImmutableEnumFieldGenerator(
: descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
SetEnumVariables(descriptor, messageBitIndex, builderBitIndex,
context->GetFieldGeneratorInfo(descriptor), name_resolver_,
&variables_);
&variables_, context);
}
RepeatedImmutableEnumFieldGenerator::~RepeatedImmutableEnumFieldGenerator() {}

@ -68,7 +68,8 @@ bool EnableExperimentalRuntimeForLite() {
void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex,
int builderBitIndex, const FieldGeneratorInfo* info,
ClassNameResolver* name_resolver,
std::map<std::string, std::string>* variables) {
std::map<std::string, std::string>* variables,
Context* context) {
SetCommonFieldVariables(descriptor, info, variables);
(*variables)["type"] =
@ -76,7 +77,8 @@ void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex,
(*variables)["kt_type"] = EscapeKotlinKeywords((*variables)["type"]);
(*variables)["mutable_type"] =
name_resolver->GetMutableClassName(descriptor->enum_type());
(*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver);
(*variables)["default"] =
ImmutableDefaultValue(descriptor, name_resolver, context->options());
(*variables)["default_number"] =
StrCat(descriptor->default_value_enum()->number());
(*variables)["tag"] = StrCat(
@ -95,6 +97,12 @@ void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex,
(*variables)["required"] = descriptor->is_required() ? "true" : "false";
if (HasHasbit(descriptor)) {
if (!context->options().opensource_runtime) {
(*variables)["bit_field_id"] = StrCat(messageBitIndex / 32);
(*variables)["bit_field_name"] = GetBitFieldNameForBit(messageBitIndex);
(*variables)["bit_field_mask"] =
StrCat(1 << (messageBitIndex % 32));
}
// For singular messages and builders, one bit is used for the hasField bit.
(*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex);
@ -142,7 +150,7 @@ ImmutableEnumFieldLiteGenerator::ImmutableEnumFieldLiteGenerator(
name_resolver_(context->GetNameResolver()) {
SetEnumVariables(descriptor, messageBitIndex, 0,
context->GetFieldGeneratorInfo(descriptor), name_resolver_,
&variables_);
&variables_, context);
}
ImmutableEnumFieldLiteGenerator::~ImmutableEnumFieldLiteGenerator() {}
@ -169,6 +177,20 @@ void ImmutableEnumFieldLiteGenerator::GenerateInterfaceMembers(
void ImmutableEnumFieldLiteGenerator::GenerateMembers(
io::Printer* printer) const {
if (!context_->options().opensource_runtime) {
printer->Print(
variables_,
"@com.google.protobuf.ProtoField(\n"
" fieldNumber=$number$,\n"
" type=com.google.protobuf.FieldType.$annotation_field_type$,\n"
" isRequired=$required$)\n");
if (HasHazzer(descriptor_)) {
printer->Print(variables_,
"@com.google.protobuf.ProtoPresenceCheckedField(\n"
" presenceBitsId=$bit_field_id$,\n"
" mask=$bit_field_mask$)\n");
}
}
printer->Print(variables_, "private int $name$_;\n");
PrintExtraFieldInfo(variables_, printer);
if (HasHazzer(descriptor_)) {
@ -514,7 +536,7 @@ RepeatedImmutableEnumFieldLiteGenerator::
name_resolver_(context->GetNameResolver()) {
SetEnumVariables(descriptor, messageBitIndex, 0,
context->GetFieldGeneratorInfo(descriptor), name_resolver_,
&variables_);
&variables_, context);
}
RepeatedImmutableEnumFieldLiteGenerator::
@ -550,6 +572,13 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateInterfaceMembers(
void RepeatedImmutableEnumFieldLiteGenerator::GenerateMembers(
io::Printer* printer) const {
if (!context_->options().opensource_runtime) {
printer->Print(
variables_,
"@com.google.protobuf.ProtoField(\n"
" fieldNumber=$number$,\n"
" type=com.google.protobuf.FieldType.$annotation_field_type$)\n");
}
printer->Print(
variables_,
"private com.google.protobuf.Internal.IntList $name$_;\n"

@ -153,17 +153,26 @@ void EnumLiteGenerator::Generate(io::Printer* printer) {
printer->Print(
" return value;\n"
"}\n"
"\n"
"/**\n"
" * @param value The number of the enum to look for.\n"
" * @return The enum associated with the given number.\n"
" * @deprecated Use {@link #forNumber(int)} instead.\n"
" */\n"
"@java.lang.Deprecated\n"
"public static $classname$ valueOf(int value) {\n"
" return forNumber(value);\n"
"}\n"
"\n"
"\n");
if (context_->options().opensource_runtime) {
printer->Print(
"/**\n"
" * @param value The number of the enum to look for.\n"
" * @return The enum associated with the given number.\n"
" * @deprecated Use {@link #forNumber(int)} instead.\n"
" */\n"
"@java.lang.Deprecated\n"
"public static $classname$ valueOf(int value) {\n"
" return forNumber(value);\n"
"}\n"
"\n",
"classname", descriptor_->name());
}
if (!context_->options().opensource_runtime) {
printer->Print("@com.google.protobuf.Internal.ProtoMethodMayReturnNull\n");
}
printer->Print(
"public static $classname$ forNumber(int value) {\n"
" switch (value) {\n",
"classname", descriptor_->name());
@ -212,6 +221,35 @@ void EnumLiteGenerator::Generate(io::Printer* printer) {
" };\n"
"\n",
"classname", descriptor_->name());
if (!context_->options().opensource_runtime) {
printer->Print(
"/**\n"
" * Override of toString that prints the number and name.\n"
" * This is primarily intended as a developer aid.\n"
" *\n"
" * <p>NOTE: This implementation is liable to change in the future,\n"
" * and should not be relied on in code.\n"
" */\n"
"@java.lang.Override\n"
"public java.lang.String toString() {\n"
" StringBuilder result = new StringBuilder(\"<\");\n"
" result.append(getClass().getName()).append('@')\n"
" .append(java.lang.Integer.toHexString(\n"
" java.lang.System.identityHashCode(this)));\n");
if (SupportUnknownEnumValue(descriptor_->file())) {
printer->Print(
" if (this != UNRECOGNIZED) {\n"
" result.append(\" number=\").append(getNumber());\n"
" }\n");
} else {
printer->Print(" result.append(\" number=\").append(getNumber());\n");
}
printer->Print(
" return result.append(\" name=\")\n"
" .append(name()).append('>').toString();\n"
"}\n"
"\n");
}
printer->Print(
"private final int value;\n\n"

@ -51,7 +51,9 @@ namespace java {
ImmutableExtensionGenerator::ImmutableExtensionGenerator(
const FieldDescriptor* descriptor, Context* context)
: descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
: descriptor_(descriptor),
name_resolver_(context->GetNameResolver()),
context_(context) {
if (descriptor_->extension_scope() != NULL) {
scope_ =
name_resolver_->GetImmutableClassName(descriptor_->extension_scope());
@ -66,7 +68,7 @@ ImmutableExtensionGenerator::~ImmutableExtensionGenerator() {}
void ExtensionGenerator::InitTemplateVars(
const FieldDescriptor* descriptor, const std::string& scope, bool immutable,
ClassNameResolver* name_resolver,
std::map<std::string, std::string>* vars_pointer) {
std::map<std::string, std::string>* vars_pointer, Context* context) {
std::map<std::string, std::string>& vars = *vars_pointer;
vars["scope"] = scope;
vars["name"] = UnderscoresToCamelCaseCheckReserved(descriptor);
@ -77,7 +79,8 @@ void ExtensionGenerator::InitTemplateVars(
vars["index"] = StrCat(descriptor->index());
vars["default"] = descriptor->is_repeated()
? ""
: DefaultValue(descriptor, immutable, name_resolver);
: DefaultValue(descriptor, immutable, name_resolver,
context->options());
vars["type_constant"] = FieldTypeName(GetType(descriptor));
vars["packed"] = descriptor->is_packed() ? "true" : "false";
vars["enum_map"] = "null";
@ -116,7 +119,7 @@ void ImmutableExtensionGenerator::Generate(io::Printer* printer) {
std::map<std::string, std::string> vars;
const bool kUseImmutableNames = true;
InitTemplateVars(descriptor_, scope_, kUseImmutableNames, name_resolver_,
&vars);
&vars, context_);
printer->Print(vars, "public static final int $constant_name$ = $number$;\n");
WriteFieldDocComment(printer, descriptor_);

@ -79,10 +79,11 @@ class ExtensionGenerator {
virtual int GenerateRegistrationCode(io::Printer* printer) = 0;
protected:
static void InitTemplateVars(
const FieldDescriptor* descriptor, const std::string& scope,
bool immutable, ClassNameResolver* name_resolver,
std::map<std::string, std::string>* vars_pointer);
static void InitTemplateVars(const FieldDescriptor* descriptor,
const std::string& scope, bool immutable,
ClassNameResolver* name_resolver,
std::map<std::string, std::string>* vars_pointer,
Context* context);
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ExtensionGenerator);
@ -102,6 +103,7 @@ class ImmutableExtensionGenerator : public ExtensionGenerator {
const FieldDescriptor* descriptor_;
ClassNameResolver* name_resolver_;
std::string scope_;
Context* context_;
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableExtensionGenerator);

@ -47,7 +47,9 @@ namespace java {
ImmutableExtensionLiteGenerator::ImmutableExtensionLiteGenerator(
const FieldDescriptor* descriptor, Context* context)
: descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
: descriptor_(descriptor),
name_resolver_(context->GetNameResolver()),
context_(context) {
if (descriptor_->extension_scope() != NULL) {
scope_ =
name_resolver_->GetImmutableClassName(descriptor_->extension_scope());
@ -62,7 +64,7 @@ void ImmutableExtensionLiteGenerator::Generate(io::Printer* printer) {
std::map<std::string, std::string> vars;
const bool kUseImmutableNames = true;
InitTemplateVars(descriptor_, scope_, kUseImmutableNames, name_resolver_,
&vars);
&vars, context_);
printer->Print(vars, "public static final int $constant_name$ = $number$;\n");
WriteFieldDocComment(printer, descriptor_);

@ -63,6 +63,7 @@ class ImmutableExtensionLiteGenerator : public ExtensionGenerator {
const FieldDescriptor* descriptor_;
ClassNameResolver* name_resolver_;
std::string scope_;
Context* context_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableExtensionLiteGenerator);
};

@ -188,7 +188,7 @@ void MaybeRestartJavaMethod(io::Printer* printer, int* bytecode_estimate,
FileGenerator::FileGenerator(const FileDescriptor* file, const Options& options,
bool immutable_api)
: file_(file),
java_package_(FileJavaPackage(file, immutable_api)),
java_package_(FileJavaPackage(file, immutable_api, options)),
message_generators_(file->message_type_count()),
extension_generators_(file->extension_count()),
context_(new Context(file, options)),
@ -196,7 +196,7 @@ FileGenerator::FileGenerator(const FileDescriptor* file, const Options& options,
options_(options),
immutable_api_(immutable_api) {
classname_ = name_resolver_->GetFileClassName(file, immutable_api);
generator_factory_.reset(new ImmutableGeneratorFactory(context_.get()));
generator_factory_.reset(new ImmutableGeneratorFactory(context_.get()));
for (int i = 0; i < file_->message_type_count(); ++i) {
message_generators_[i].reset(
generator_factory_->NewMessageGenerator(file_->message_type(i)));
@ -271,8 +271,12 @@ void FileGenerator::Generate(io::Printer* printer) {
"package", java_package_);
}
PrintGeneratedAnnotation(
printer, '$', options_.annotate_code ? classname_ + ".java.pb.meta" : "");
printer, '$', options_.annotate_code ? classname_ + ".java.pb.meta" : "",
options_);
if (!options_.opensource_runtime) {
printer->Print("@com.google.protobuf.Internal.ProtoNonnullApi\n");
}
printer->Print(
"$deprecation$public final class $classname$ {\n"
" private $ctor$() {}\n",
@ -401,11 +405,14 @@ void FileGenerator::GenerateDescriptorInitializationCodeForImmutable(
" descriptor;\n"
"static {\n",
// TODO(dweis): Mark this as final.
"final", "");
"final", options_.opensource_runtime ? "" : "final");
printer->Indent();
SharedCodeGenerator shared_code_generator(file_, options_);
shared_code_generator.GenerateDescriptors(printer);
if (options_.opensource_runtime) {
SharedCodeGenerator shared_code_generator(file_, options_);
shared_code_generator.GenerateDescriptors(printer);
} else {
}
int bytecode_estimate = 0;
int method_num = 0;
@ -499,8 +506,8 @@ void FileGenerator::GenerateDescriptorInitializationCodeForMutable(
printer->Print(
"descriptor = $immutable_package$.$descriptor_classname$.descriptor;\n",
"immutable_package", FileJavaPackage(file_, true), "descriptor_classname",
name_resolver_->GetDescriptorClassName(file_));
"immutable_package", FileJavaPackage(file_, true, options_),
"descriptor_classname", name_resolver_->GetDescriptorClassName(file_));
for (int i = 0; i < file_->message_type_count(); i++) {
message_generators_[i]->GenerateStaticVariableInitializers(printer);
@ -547,7 +554,7 @@ void FileGenerator::GenerateDescriptorInitializationCodeForMutable(
scope = name_resolver_->GetMutableClassName(field->extension_scope()) +
".getDescriptor()";
} else {
scope = FileJavaPackage(field->file(), true) + "." +
scope = FileJavaPackage(field->file(), true, options_) + "." +
name_resolver_->GetDescriptorClassName(field->file()) +
".descriptor";
}

@ -74,6 +74,8 @@ bool JavaGenerator::Generate(const FileDescriptor* file,
ParseGeneratorParameter(parameter, &options);
Options file_options;
file_options.opensource_runtime = opensource_runtime_;
for (int i = 0; i < options.size(); i++) {
if (options[i].first == "output_list_file") {
file_options.output_list_file = options[i].second;

@ -68,7 +68,7 @@ class PROTOC_EXPORT JavaGenerator : public CodeGenerator {
}
private:
bool opensource_runtime_ = true;
bool opensource_runtime_ = PROTO2_IS_OSS;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(JavaGenerator);
};

@ -66,8 +66,9 @@ const char kThinSeparator[] =
"// -------------------------------------------------------------------\n";
namespace {
const char* kDefaultPackage = "";
const char* DefaultPackage(Options options) {
return options.opensource_runtime ? "" : "com.google.protos";
}
// Names that should be avoided (in UpperCamelCase format).
// Using them will cause the compiler to generate accessors whose names
@ -136,7 +137,8 @@ std::string FieldName(const FieldDescriptor* field) {
} // namespace
void PrintGeneratedAnnotation(io::Printer* printer, char delimiter,
const std::string& annotation_file) {
const std::string& annotation_file,
Options options) {
if (annotation_file.empty()) {
return;
}
@ -305,17 +307,17 @@ std::string CamelCaseFieldName(const FieldDescriptor* field) {
}
std::string FileClassName(const FileDescriptor* file, bool immutable) {
ClassNameResolver name_resolver;
return name_resolver.GetFileClassName(file, immutable);
return ClassNameResolver().GetFileClassName(file, immutable);
}
std::string FileJavaPackage(const FileDescriptor* file, bool immutable) {
std::string FileJavaPackage(const FileDescriptor* file, bool immutable,
Options options) {
std::string result;
if (file->options().has_java_package()) {
result = file->options().java_package();
} else {
result = kDefaultPackage;
result = DefaultPackage(options);
if (!file->package().empty()) {
if (!result.empty()) result += '.';
result += file->package();
@ -325,8 +327,8 @@ std::string FileJavaPackage(const FileDescriptor* file, bool immutable) {
return result;
}
std::string FileJavaPackage(const FileDescriptor* file) {
return FileJavaPackage(file, true /* immutable */);
std::string FileJavaPackage(const FileDescriptor* file, Options options) {
return FileJavaPackage(file, true /* immutable */, options);
}
std::string JavaPackageToDir(std::string package_name) {
@ -532,7 +534,7 @@ std::string GetOneofStoredType(const FieldDescriptor* field) {
case JAVATYPE_ENUM:
return "java.lang.Integer";
case JAVATYPE_MESSAGE:
return ClassName(field->message_type());
return ClassNameResolver().GetClassName(field->message_type(), true);
default:
return BoxedPrimitiveTypeName(javaType);
}
@ -595,7 +597,7 @@ bool AllAscii(const std::string& text) {
}
std::string DefaultValue(const FieldDescriptor* field, bool immutable,
ClassNameResolver* name_resolver) {
ClassNameResolver* name_resolver, Options options) {
// Switch on CppType since we need to know which default_value_* method
// of FieldDescriptor to call.
switch (field->cpp_type()) {
@ -819,7 +821,8 @@ bool IsReferenceType(JavaType type) {
return false;
}
const char* GetCapitalizedType(const FieldDescriptor* field, bool immutable) {
const char* GetCapitalizedType(const FieldDescriptor* field, bool immutable,
Options options) {
switch (GetType(field)) {
case FieldDescriptor::TYPE_INT32:
return "Int32";

@ -41,8 +41,12 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/compiler/java/context.h>
#include <google/protobuf/compiler/java/options.h>
#include <google/protobuf/descriptor.pb.h>
// Must be last.
#include <google/protobuf/port_def.inc>
namespace google {
namespace protobuf {
namespace compiler {
@ -64,7 +68,8 @@ bool IsForbiddenKotlin(const std::string& field_name);
// annotation_file should be generated from the filename of the source file
// being annotated (which in turn must be a Java identifier plus ".java").
void PrintGeneratedAnnotation(io::Printer* printer, char delimiter = '$',
const std::string& annotation_file = "");
const std::string& annotation_file = "",
Options options = {});
// If a GeneratedMessageLite contains non-lite enums, then its verifier
// must be instantiated inline, rather than retrieved from the enum class.
@ -113,7 +118,8 @@ std::string UniqueFileScopeIdentifier(const Descriptor* descriptor);
std::string FileClassName(const FileDescriptor* file, bool immutable = true);
// Returns the file's Java package name.
std::string FileJavaPackage(const FileDescriptor* file, bool immutable);
std::string FileJavaPackage(const FileDescriptor* file, bool immutable,
Options options = {});
// Returns output directory for the given package name.
std::string JavaPackageToDir(std::string package_name);
@ -209,7 +215,8 @@ void MaybePrintGeneratedAnnotation(Context* context, io::Printer* printer,
PrintGeneratedAnnotation(printer, '$',
context->options().annotate_code
? AnnotationFileName(descriptor, suffix)
: "");
: "",
context->options());
}
}
@ -254,10 +261,12 @@ const char* FieldTypeName(const FieldDescriptor::Type field_type);
class ClassNameResolver;
std::string DefaultValue(const FieldDescriptor* field, bool immutable,
ClassNameResolver* name_resolver);
ClassNameResolver* name_resolver,
Options options = {});
inline std::string ImmutableDefaultValue(const FieldDescriptor* field,
ClassNameResolver* name_resolver) {
return DefaultValue(field, true, name_resolver);
ClassNameResolver* name_resolver,
Options options = {}) {
return DefaultValue(field, true, name_resolver, options);
}
bool IsDefaultValueJavaDefault(const FieldDescriptor* field);
bool IsByteStringWithCustomDefaultValue(const FieldDescriptor* field);
@ -336,7 +345,8 @@ bool IsReferenceType(JavaType type);
// Returns the capitalized name for calling relative functions in
// CodedInputStream
const char* GetCapitalizedType(const FieldDescriptor* field, bool immutable);
const char* GetCapitalizedType(const FieldDescriptor* field, bool immutable,
Options options);
// For encodings with fixed sizes, returns that size in bytes. Otherwise
// returns -1.
@ -474,4 +484,5 @@ std::pair<int, int> GetTableDrivenNumberOfEntriesAndLookUpStartFieldNumber(
} // namespace protobuf
} // namespace google
#include <google/protobuf/port_undef.inc>
#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_HELPERS_H__

@ -102,7 +102,12 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
const JavaType keyJavaType = GetJavaType(key);
const JavaType valueJavaType = GetJavaType(value);
std::string pass_through_nullness = "/* nullable */\n";
// The code that generates the open-source version appears not to understand
// #else, so we have an #ifndef instead.
std::string pass_through_nullness =
context->options().opensource_runtime
? "/* nullable */\n"
: "@com.google.protobuf.Internal.ProtoPassThroughNullness ";
(*variables)["key_type"] = TypeName(key, name_resolver, false);
std::string boxed_key_type = TypeName(key, name_resolver, true);
@ -113,7 +118,8 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
(*variables)["short_key_type"] =
boxed_key_type.substr(boxed_key_type.rfind('.') + 1);
(*variables)["key_wire_type"] = WireType(key);
(*variables)["key_default_value"] = DefaultValue(key, true, name_resolver);
(*variables)["key_default_value"] =
DefaultValue(key, true, name_resolver, context->options());
(*variables)["key_null_check"] =
IsReferenceType(keyJavaType)
? "if (key == null) { throw new NullPointerException(\"map key\"); }"
@ -132,7 +138,8 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
(*variables)["boxed_value_type"] = "java.lang.Integer";
(*variables)["value_wire_type"] = WireType(value);
(*variables)["value_default_value"] =
DefaultValue(value, true, name_resolver) + ".getNumber()";
DefaultValue(value, true, name_resolver, context->options()) +
".getNumber()";
(*variables)["value_enum_type"] = TypeName(value, name_resolver, false);
@ -146,7 +153,7 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
} else {
// Map unknown values to the default value if we don't have UNRECOGNIZED.
(*variables)["unrecognized_value"] =
DefaultValue(value, true, name_resolver);
DefaultValue(value, true, name_resolver, context->options());
}
} else {
(*variables)["value_type"] = TypeName(value, name_resolver, false);
@ -158,7 +165,7 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
(*variables)["boxed_value_type"] = TypeName(value, name_resolver, true);
(*variables)["value_wire_type"] = WireType(value);
(*variables)["value_default_value"] =
DefaultValue(value, true, name_resolver);
DefaultValue(value, true, name_resolver, context->options());
}
(*variables)["type_parameters"] =
(*variables)["boxed_key_type"] + ", " + (*variables)["boxed_value_type"];
@ -194,7 +201,9 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
ImmutableMapFieldGenerator::ImmutableMapFieldGenerator(
const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex,
Context* context)
: descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
: descriptor_(descriptor),
name_resolver_(context->GetNameResolver()),
context_(context) {
SetMessageVariables(descriptor, messageBitIndex, builderBitIndex,
context->GetFieldGeneratorInfo(descriptor), context,
&variables_);
@ -218,14 +227,16 @@ void ImmutableMapFieldGenerator::GenerateInterfaceMembers(
" $key_type$ key);\n");
printer->Annotate("{", "}", descriptor_);
if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) {
printer->Print(variables_,
"/**\n"
" * Use {@link #get$capitalized_name$Map()} instead.\n"
" */\n"
"@java.lang.Deprecated\n"
"java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
"${$get$capitalized_name$$}$();\n");
printer->Annotate("{", "}", descriptor_);
if (context_->options().opensource_runtime) {
printer->Print(variables_,
"/**\n"
" * Use {@link #get$capitalized_name$Map()} instead.\n"
" */\n"
"@java.lang.Deprecated\n"
"java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
"${$get$capitalized_name$$}$();\n");
printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
@ -277,14 +288,16 @@ void ImmutableMapFieldGenerator::GenerateInterfaceMembers(
printer->Annotate("{", "}", descriptor_);
}
} else {
printer->Print(variables_,
"/**\n"
" * Use {@link #get$capitalized_name$Map()} instead.\n"
" */\n"
"@java.lang.Deprecated\n"
"java.util.Map<$type_parameters$>\n"
"${$get$capitalized_name$$}$();\n");
printer->Annotate("{", "}", descriptor_);
if (context_->options().opensource_runtime) {
printer->Print(variables_,
"/**\n"
" * Use {@link #get$capitalized_name$Map()} instead.\n"
" */\n"
"@java.lang.Deprecated\n"
"java.util.Map<$type_parameters$>\n"
"${$get$capitalized_name$$}$();\n");
printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$java.util.Map<$type_parameters$>\n"
@ -401,18 +414,20 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers(
"}\n");
printer->Annotate("{", "}", descriptor_);
if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) {
printer->Print(
variables_,
"/**\n"
" * Use alternate mutation accessors instead.\n"
" */\n"
"@java.lang.Deprecated\n"
"public java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
"${$getMutable$capitalized_name$$}$() {\n"
" return internalGetAdapted$capitalized_name$Map(\n"
" internalGetMutable$capitalized_name$().getMutableMap());\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
if (context_->options().opensource_runtime) {
printer->Print(
variables_,
"/**\n"
" * Use alternate mutation accessors instead.\n"
" */\n"
"@java.lang.Deprecated\n"
"public java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
"${$getMutable$capitalized_name$$}$() {\n"
" return internalGetAdapted$capitalized_name$Map(\n"
" internalGetMutable$capitalized_name$().getMutableMap());\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$public Builder ${$put$capitalized_name$$}$(\n"
@ -437,17 +452,19 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers(
"}\n");
printer->Annotate("{", "}", descriptor_);
if (SupportUnknownEnumValue(descriptor_->file())) {
printer->Print(
variables_,
"/**\n"
" * Use alternate mutation accessors instead.\n"
" */\n"
"@java.lang.Deprecated\n"
"public java.util.Map<$boxed_key_type$, $boxed_value_type$>\n"
"${$getMutable$capitalized_name$Value$}$() {\n"
" return internalGetMutable$capitalized_name$().getMutableMap();\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
if (context_->options().opensource_runtime) {
printer->Print(
variables_,
"/**\n"
" * Use alternate mutation accessors instead.\n"
" */\n"
"@java.lang.Deprecated\n"
"public java.util.Map<$boxed_key_type$, $boxed_value_type$>\n"
"${$getMutable$capitalized_name$Value$}$() {\n"
" return internalGetMutable$capitalized_name$().getMutableMap();\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
@ -473,17 +490,19 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers(
printer->Annotate("{", "}", descriptor_);
}
} else {
printer->Print(
variables_,
"/**\n"
" * Use alternate mutation accessors instead.\n"
" */\n"
"@java.lang.Deprecated\n"
"public java.util.Map<$type_parameters$>\n"
"${$getMutable$capitalized_name$$}$() {\n"
" return internalGetMutable$capitalized_name$().getMutableMap();\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
if (context_->options().opensource_runtime) {
printer->Print(
variables_,
"/**\n"
" * Use alternate mutation accessors instead.\n"
" */\n"
"@java.lang.Deprecated\n"
"public java.util.Map<$type_parameters$>\n"
"${$getMutable$capitalized_name$$}$() {\n"
" return internalGetMutable$capitalized_name$().getMutableMap();\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$"
@ -530,17 +549,20 @@ void ImmutableMapFieldGenerator::GenerateMapGetters(
"}\n");
printer->Annotate("{", "}", descriptor_);
if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) {
printer->Print(variables_,
"/**\n"
" * Use {@link #get$capitalized_name$Map()} instead.\n"
" */\n"
"@java.lang.Override\n"
"@java.lang.Deprecated\n"
"public java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
"${$get$capitalized_name$$}$() {\n"
" return get$capitalized_name$Map();\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
if (context_->options().opensource_runtime) {
printer->Print(
variables_,
"/**\n"
" * Use {@link #get$capitalized_name$Map()} instead.\n"
" */\n"
"@java.lang.Override\n"
"@java.lang.Deprecated\n"
"public java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
"${$get$capitalized_name$$}$() {\n"
" return get$capitalized_name$Map();\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"@java.lang.Override\n"
@ -640,17 +662,19 @@ void ImmutableMapFieldGenerator::GenerateMapGetters(
printer->Annotate("{", "}", descriptor_);
}
} else {
printer->Print(variables_,
"/**\n"
" * Use {@link #get$capitalized_name$Map()} instead.\n"
" */\n"
"@java.lang.Override\n"
"@java.lang.Deprecated\n"
"public java.util.Map<$type_parameters$> "
"${$get$capitalized_name$$}$() {\n"
" return get$capitalized_name$Map();\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
if (context_->options().opensource_runtime) {
printer->Print(variables_,
"/**\n"
" * Use {@link #get$capitalized_name$Map()} instead.\n"
" */\n"
"@java.lang.Override\n"
"@java.lang.Deprecated\n"
"public java.util.Map<$type_parameters$> "
"${$get$capitalized_name$$}$() {\n"
" return get$capitalized_name$Map();\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"@java.lang.Override\n"

@ -71,6 +71,7 @@ class ImmutableMapFieldGenerator : public ImmutableFieldGenerator {
const FieldDescriptor* descriptor_;
std::map<std::string, std::string> variables_;
ClassNameResolver* name_resolver_;
Context* context_;
void GenerateMapGetters(io::Printer* printer) const;
};

@ -104,14 +104,18 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
const JavaType keyJavaType = GetJavaType(key);
const JavaType valueJavaType = GetJavaType(value);
std::string pass_through_nullness = "/* nullable */\n";
std::string pass_through_nullness =
context->options().opensource_runtime
? "/* nullable */\n"
: "@com.google.protobuf.Internal.ProtoPassThroughNullness ";
(*variables)["key_type"] = TypeName(key, name_resolver, false);
(*variables)["boxed_key_type"] = TypeName(key, name_resolver, true);
(*variables)["kt_key_type"] = KotlinTypeName(key, name_resolver);
(*variables)["kt_value_type"] = KotlinTypeName(value, name_resolver);
(*variables)["key_wire_type"] = WireType(key);
(*variables)["key_default_value"] = DefaultValue(key, true, name_resolver);
(*variables)["key_default_value"] =
DefaultValue(key, true, name_resolver, context->options());
// We use `x.getClass()` as a null check because it generates less bytecode
// than an `if (x == null) { throw ... }` statement.
(*variables)["key_null_check"] =
@ -131,7 +135,8 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
(*variables)["boxed_value_type"] = "java.lang.Integer";
(*variables)["value_wire_type"] = WireType(value);
(*variables)["value_default_value"] =
DefaultValue(value, true, name_resolver) + ".getNumber()";
DefaultValue(value, true, name_resolver, context->options()) +
".getNumber()";
(*variables)["value_enum_type"] = TypeName(value, name_resolver, false);
@ -145,7 +150,7 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
} else {
// Map unknown values to the default value if we don't have UNRECOGNIZED.
(*variables)["unrecognized_value"] =
DefaultValue(value, true, name_resolver);
DefaultValue(value, true, name_resolver, context->options());
}
} else {
(*variables)["value_type"] = TypeName(value, name_resolver, false);
@ -157,7 +162,7 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
(*variables)["boxed_value_type"] = TypeName(value, name_resolver, true);
(*variables)["value_wire_type"] = WireType(value);
(*variables)["value_default_value"] =
DefaultValue(value, true, name_resolver);
DefaultValue(value, true, name_resolver, context->options());
}
(*variables)["type_parameters"] =
(*variables)["boxed_key_type"] + ", " + (*variables)["boxed_value_type"];
@ -203,14 +208,16 @@ void ImmutableMapFieldLiteGenerator::GenerateInterfaceMembers(
" $key_type$ key);\n");
printer->Annotate("{", "}", descriptor_);
if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) {
printer->Print(variables_,
"/**\n"
" * Use {@link #get$capitalized_name$Map()} instead.\n"
" */\n"
"@java.lang.Deprecated\n"
"java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
"${$get$capitalized_name$$}$();\n");
printer->Annotate("{", "}", descriptor_);
if (context_->options().opensource_runtime) {
printer->Print(variables_,
"/**\n"
" * Use {@link #get$capitalized_name$Map()} instead.\n"
" */\n"
"@java.lang.Deprecated\n"
"java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
"${$get$capitalized_name$$}$();\n");
printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
@ -262,14 +269,16 @@ void ImmutableMapFieldLiteGenerator::GenerateInterfaceMembers(
printer->Annotate("{", "}", descriptor_);
}
} else {
printer->Print(variables_,
"/**\n"
" * Use {@link #get$capitalized_name$Map()} instead.\n"
" */\n"
"@java.lang.Deprecated\n"
"java.util.Map<$type_parameters$>\n"
"${$get$capitalized_name$$}$();\n");
printer->Annotate("{", "}", descriptor_);
if (context_->options().opensource_runtime) {
printer->Print(variables_,
"/**\n"
" * Use {@link #get$capitalized_name$Map()} instead.\n"
" */\n"
"@java.lang.Deprecated\n"
"java.util.Map<$type_parameters$>\n"
"${$get$capitalized_name$$}$();\n");
printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$java.util.Map<$type_parameters$>\n"
@ -306,6 +315,12 @@ void ImmutableMapFieldLiteGenerator::GenerateMembers(
" $value_wire_type$,\n"
" $value_default_value$);\n"
"}\n");
if (!context_->options().opensource_runtime) {
printer->Print(variables_,
"@com.google.protobuf.ProtoField(\n"
" fieldNumber=$number$,\n"
" type=com.google.protobuf.FieldType.MAP)\n");
}
printer->Print(variables_,
"private com.google.protobuf.MapFieldLite<\n"
" $type_parameters$> $name$_ =\n"
@ -347,16 +362,19 @@ void ImmutableMapFieldLiteGenerator::GenerateMembers(
" com.google.protobuf.Internal.MapAdapter.newEnumConverter(\n"
" $value_enum_type$.internalGetValueMap(),\n"
" $unrecognized_value$);\n");
printer->Print(variables_,
"/**\n"
" * Use {@link #get$capitalized_name$Map()} instead.\n"
" */\n"
"@java.lang.Deprecated\n"
"public java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
"${$get$capitalized_name$$}$() {\n"
" return get$capitalized_name$Map();\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
if (context_->options().opensource_runtime) {
printer->Print(
variables_,
"/**\n"
" * Use {@link #get$capitalized_name$Map()} instead.\n"
" */\n"
"@java.lang.Deprecated\n"
"public java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
"${$get$capitalized_name$$}$() {\n"
" return get$capitalized_name$Map();\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
@ -461,17 +479,19 @@ void ImmutableMapFieldLiteGenerator::GenerateMembers(
printer->Annotate("{", "}", descriptor_);
}
} else {
printer->Print(variables_,
"/**\n"
" * Use {@link #get$capitalized_name$Map()} instead.\n"
" */\n"
"@java.lang.Override\n"
"@java.lang.Deprecated\n"
"public java.util.Map<$type_parameters$> "
"${$get$capitalized_name$$}$() {\n"
" return get$capitalized_name$Map();\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
if (context_->options().opensource_runtime) {
printer->Print(variables_,
"/**\n"
" * Use {@link #get$capitalized_name$Map()} instead.\n"
" */\n"
"@java.lang.Override\n"
"@java.lang.Deprecated\n"
"public java.util.Map<$type_parameters$> "
"${$get$capitalized_name$$}$() {\n"
" return get$capitalized_name$Map();\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"@java.lang.Override\n"
@ -602,16 +622,19 @@ void ImmutableMapFieldLiteGenerator::GenerateBuilderMembers(
"}\n");
printer->Annotate("{", "}", descriptor_);
if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) {
printer->Print(variables_,
"/**\n"
" * Use {@link #get$capitalized_name$Map()} instead.\n"
" */\n"
"@java.lang.Deprecated\n"
"public java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
"${$get$capitalized_name$$}$() {\n"
" return get$capitalized_name$Map();\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
if (context_->options().opensource_runtime) {
printer->Print(
variables_,
"/**\n"
" * Use {@link #get$capitalized_name$Map()} instead.\n"
" */\n"
"@java.lang.Deprecated\n"
"public java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
"${$get$capitalized_name$$}$() {\n"
" return get$capitalized_name$Map();\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"@java.lang.Override\n"
@ -757,17 +780,19 @@ void ImmutableMapFieldLiteGenerator::GenerateBuilderMembers(
printer->Annotate("{", "}", descriptor_);
}
} else {
printer->Print(variables_,
"/**\n"
" * Use {@link #get$capitalized_name$Map()} instead.\n"
" */\n"
"@java.lang.Override\n"
"@java.lang.Deprecated\n"
"public java.util.Map<$type_parameters$> "
"${$get$capitalized_name$$}$() {\n"
" return get$capitalized_name$Map();\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
if (context_->options().opensource_runtime) {
printer->Print(variables_,
"/**\n"
" * Use {@link #get$capitalized_name$Map()} instead.\n"
" */\n"
"@java.lang.Override\n"
"@java.lang.Deprecated\n"
"public java.util.Map<$type_parameters$> "
"${$get$capitalized_name$$}$() {\n"
" return get$capitalized_name$Map();\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"@java.lang.Override\n"

@ -261,6 +261,9 @@ int ImmutableMessageGenerator::GenerateFieldAccessorTableInitializer(
void ImmutableMessageGenerator::GenerateInterface(io::Printer* printer) {
MaybePrintGeneratedAnnotation(context_, printer, descriptor_,
/* immutable = */ true, "OrBuilder");
if (!context_->options().opensource_runtime) {
printer->Print("@com.google.protobuf.Internal.ProtoNonnullApi\n");
}
if (descriptor_->extension_range_count() > 0) {
printer->Print(
"$deprecation$public interface ${$$classname$OrBuilder$}$ extends\n"
@ -320,6 +323,10 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
WriteMessageDocComment(printer, descriptor_);
MaybePrintGeneratedAnnotation(context_, printer, descriptor_,
/* immutable = */ true);
if (!context_->options().opensource_runtime) {
printer->Print("@com.google.protobuf.Internal.ProtoNonnullApi\n");
}
// The builder_type stores the super type name of the nested Builder class.
std::string builder_type;
if (descriptor_->extension_range_count() > 0) {
@ -458,18 +465,22 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
"private $oneof_capitalized_name$Case(int value) {\n"
" this.value = value;\n"
"}\n");
if (context_->options().opensource_runtime) {
printer->Print(
vars,
"/**\n"
" * @param value The number of the enum to look for.\n"
" * @return The enum associated with the given number.\n"
" * @deprecated Use {@link #forNumber(int)} instead.\n"
" */\n"
"@java.lang.Deprecated\n"
"public static $oneof_capitalized_name$Case valueOf(int value) {\n"
" return forNumber(value);\n"
"}\n"
"\n");
}
printer->Print(
vars,
"/**\n"
" * @param value The number of the enum to look for.\n"
" * @return The enum associated with the given number.\n"
" * @deprecated Use {@link #forNumber(int)} instead.\n"
" */\n"
"@java.lang.Deprecated\n"
"public static $oneof_capitalized_name$Case valueOf(int value) {\n"
" return forNumber(value);\n"
"}\n"
"\n"
"public static $oneof_capitalized_name$Case forNumber(int value) {\n"
" switch (value) {\n");
for (int j = 0; j < (oneof)->field_count(); j++) {
@ -982,6 +993,10 @@ void ImmutableMessageGenerator::GenerateEqualsAndHashCode(
printer->Print(
"@java.lang.Override\n"
"public boolean equals(");
if (!context_->options().opensource_runtime) {
printer->Print(
"@com.google.protobuf.Internal.ProtoMethodAcceptsNullParameter\n");
}
printer->Print("final java.lang.Object obj) {\n");
printer->Indent();
printer->Print(
@ -1440,8 +1455,15 @@ void ImmutableMessageGenerator::GenerateKotlinDsl(io::Printer* printer) const {
void ImmutableMessageGenerator::GenerateKotlinMembers(
io::Printer* printer) const {
printer->Print("@kotlin.jvm.JvmName(\"-initialize$camelcase_name$\")\n",
"camelcase_name",
name_resolver_->GetKotlinFactoryName(descriptor_));
if (!context_->options().opensource_runtime) {
printer->Print("@com.google.errorprone.annotations.CheckReturnValue\n");
}
printer->Print(
"@kotlin.jvm.JvmName(\"-initialize$camelcase_name$\")\n"
"inline fun $camelcase_name$(block: $message_kt$.Dsl.() -> "
"kotlin.Unit): "
"$message$ "
@ -1470,8 +1492,13 @@ void ImmutableMessageGenerator::GenerateKotlinMembers(
void ImmutableMessageGenerator::GenerateTopLevelKotlinMembers(
io::Printer* printer) const {
printer->Print("@kotlin.jvm.JvmSynthetic\n");
if (context_->options().opensource_runtime) {
printer->Print("@com.google.errorprone.annotations.CheckReturnValue\n");
}
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"inline fun $message$.copy(block: $message_kt$.Dsl.() -> "
"kotlin.Unit): $message$ =\n"
" $message_kt$.Dsl._create(this.toBuilder()).apply { block() "
@ -1716,7 +1743,8 @@ void ImmutableMessageGenerator::GenerateAnyMethods(io::Printer* printer) {
"@java.lang.SuppressWarnings(\"unchecked\")\n"
"public <T extends com.google.protobuf.Message> T unpack(\n"
" java.lang.Class<T> clazz)\n"
" throws com.google.protobuf.InvalidProtocolBufferException {\n"
" throws com.google.protobuf.InvalidProtocolBufferException {\n");
printer->Print(
" boolean invalidClazz = false;\n"
" if (cachedUnpackValue != null) {\n"
" if (cachedUnpackValue.getClass() == clazz) {\n"

@ -168,24 +168,26 @@ void MessageBuilderGenerator::Generate(io::Printer* printer) {
.GenerateBuilderMembers(printer);
}
// Override methods declared in GeneratedMessage to return the concrete
// generated type so callsites won't depend on GeneratedMessage. This
// is needed to keep binary compatibility when we change generated code
// to subclass a different GeneratedMessage class (e.g., in v3.0.0 release
// we changed all generated code to subclass GeneratedMessageV3).
printer->Print(
"@java.lang.Override\n"
"public final Builder setUnknownFields(\n"
" final com.google.protobuf.UnknownFieldSet unknownFields) {\n"
" return super.setUnknownFields(unknownFields);\n"
"}\n"
"\n"
"@java.lang.Override\n"
"public final Builder mergeUnknownFields(\n"
" final com.google.protobuf.UnknownFieldSet unknownFields) {\n"
" return super.mergeUnknownFields(unknownFields);\n"
"}\n"
"\n");
if (context_->options().opensource_runtime) {
// Override methods declared in GeneratedMessage to return the concrete
// generated type so callsites won't depend on GeneratedMessage. This
// is needed to keep binary compatibility when we change generated code
// to subclass a different GeneratedMessage class (e.g., in v3.0.0 release
// we changed all generated code to subclass GeneratedMessageV3).
printer->Print(
"@java.lang.Override\n"
"public final Builder setUnknownFields(\n"
" final com.google.protobuf.UnknownFieldSet unknownFields) {\n"
" return super.setUnknownFields(unknownFields);\n"
"}\n"
"\n"
"@java.lang.Override\n"
"public final Builder mergeUnknownFields(\n"
" final com.google.protobuf.UnknownFieldSet unknownFields) {\n"
" return super.mergeUnknownFields(unknownFields);\n"
"}\n"
"\n");
}
printer->Print(
"\n"
@ -443,75 +445,77 @@ void MessageBuilderGenerator::GenerateCommonBuilderMethods(
"\n",
"classname", name_resolver_->GetImmutableClassName(descriptor_));
// Override methods declared in GeneratedMessage to return the concrete
// generated type so callsites won't depend on GeneratedMessage. This
// is needed to keep binary compatibility when we change generated code
// to subclass a different GeneratedMessage class (e.g., in v3.0.0 release
// we changed all generated code to subclass GeneratedMessageV3).
printer->Print(
"@java.lang.Override\n"
"public Builder clone() {\n"
" return super.clone();\n"
"}\n"
"@java.lang.Override\n"
"public Builder setField(\n"
" com.google.protobuf.Descriptors.FieldDescriptor field,\n"
" java.lang.Object value) {\n"
" return super.setField(field, value);\n"
"}\n"
"@java.lang.Override\n"
"public Builder clearField(\n"
" com.google.protobuf.Descriptors.FieldDescriptor field) {\n"
" return super.clearField(field);\n"
"}\n"
"@java.lang.Override\n"
"public Builder clearOneof(\n"
" com.google.protobuf.Descriptors.OneofDescriptor oneof) {\n"
" return super.clearOneof(oneof);\n"
"}\n"
"@java.lang.Override\n"
"public Builder setRepeatedField(\n"
" com.google.protobuf.Descriptors.FieldDescriptor field,\n"
" int index, java.lang.Object value) {\n"
" return super.setRepeatedField(field, index, value);\n"
"}\n"
"@java.lang.Override\n"
"public Builder addRepeatedField(\n"
" com.google.protobuf.Descriptors.FieldDescriptor field,\n"
" java.lang.Object value) {\n"
" return super.addRepeatedField(field, value);\n"
"}\n");
if (descriptor_->extension_range_count() > 0) {
if (context_->options().opensource_runtime) {
// Override methods declared in GeneratedMessage to return the concrete
// generated type so callsites won't depend on GeneratedMessage. This
// is needed to keep binary compatibility when we change generated code
// to subclass a different GeneratedMessage class (e.g., in v3.0.0 release
// we changed all generated code to subclass GeneratedMessageV3).
printer->Print(
"@java.lang.Override\n"
"public <Type> Builder setExtension(\n"
" com.google.protobuf.GeneratedMessage.GeneratedExtension<\n"
" $classname$, Type> extension,\n"
" Type value) {\n"
" return super.setExtension(extension, value);\n"
"public Builder clone() {\n"
" return super.clone();\n"
"}\n"
"@java.lang.Override\n"
"public <Type> Builder setExtension(\n"
" com.google.protobuf.GeneratedMessage.GeneratedExtension<\n"
" $classname$, java.util.List<Type>> extension,\n"
" int index, Type value) {\n"
" return super.setExtension(extension, index, value);\n"
"public Builder setField(\n"
" com.google.protobuf.Descriptors.FieldDescriptor field,\n"
" java.lang.Object value) {\n"
" return super.setField(field, value);\n"
"}\n"
"@java.lang.Override\n"
"public <Type> Builder addExtension(\n"
" com.google.protobuf.GeneratedMessage.GeneratedExtension<\n"
" $classname$, java.util.List<Type>> extension,\n"
" Type value) {\n"
" return super.addExtension(extension, value);\n"
"public Builder clearField(\n"
" com.google.protobuf.Descriptors.FieldDescriptor field) {\n"
" return super.clearField(field);\n"
"}\n"
"@java.lang.Override\n"
"public <Type> Builder clearExtension(\n"
" com.google.protobuf.GeneratedMessage.GeneratedExtension<\n"
" $classname$, ?> extension) {\n"
" return super.clearExtension(extension);\n"
"}\n",
"classname", name_resolver_->GetImmutableClassName(descriptor_));
"public Builder clearOneof(\n"
" com.google.protobuf.Descriptors.OneofDescriptor oneof) {\n"
" return super.clearOneof(oneof);\n"
"}\n"
"@java.lang.Override\n"
"public Builder setRepeatedField(\n"
" com.google.protobuf.Descriptors.FieldDescriptor field,\n"
" int index, java.lang.Object value) {\n"
" return super.setRepeatedField(field, index, value);\n"
"}\n"
"@java.lang.Override\n"
"public Builder addRepeatedField(\n"
" com.google.protobuf.Descriptors.FieldDescriptor field,\n"
" java.lang.Object value) {\n"
" return super.addRepeatedField(field, value);\n"
"}\n");
if (descriptor_->extension_range_count() > 0) {
printer->Print(
"@java.lang.Override\n"
"public <Type> Builder setExtension(\n"
" com.google.protobuf.GeneratedMessage.GeneratedExtension<\n"
" $classname$, Type> extension,\n"
" Type value) {\n"
" return super.setExtension(extension, value);\n"
"}\n"
"@java.lang.Override\n"
"public <Type> Builder setExtension(\n"
" com.google.protobuf.GeneratedMessage.GeneratedExtension<\n"
" $classname$, java.util.List<Type>> extension,\n"
" int index, Type value) {\n"
" return super.setExtension(extension, index, value);\n"
"}\n"
"@java.lang.Override\n"
"public <Type> Builder addExtension(\n"
" com.google.protobuf.GeneratedMessage.GeneratedExtension<\n"
" $classname$, java.util.List<Type>> extension,\n"
" Type value) {\n"
" return super.addExtension(extension, value);\n"
"}\n"
"@java.lang.Override\n"
"public <Type> Builder clearExtension(\n"
" com.google.protobuf.GeneratedMessage.GeneratedExtension<\n"
" $classname$, ?> extension) {\n"
" return super.clearExtension(extension);\n"
"}\n",
"classname", name_resolver_->GetImmutableClassName(descriptor_));
}
}
// -----------------------------------------------------------------

@ -59,7 +59,8 @@ namespace {
void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
int builderBitIndex, const FieldGeneratorInfo* info,
ClassNameResolver* name_resolver,
std::map<std::string, std::string>* variables) {
std::map<std::string, std::string>* variables,
Context* context) {
SetCommonFieldVariables(descriptor, info, variables);
(*variables)["type"] =
@ -82,8 +83,10 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
(*variables)["on_changed"] = "onChanged();";
(*variables)["ver"] = GeneratedCodeVersionSuffix();
(*variables)["get_parser"] =
ExposePublicParser(descriptor->message_type()->file()) ? "PARSER"
: "parser()";
ExposePublicParser(descriptor->message_type()->file()) &&
context->options().opensource_runtime
? "PARSER"
: "parser()";
if (HasHasbit(descriptor)) {
// For singular messages and builders, one bit is used for the hasField bit.
@ -133,10 +136,12 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
ImmutableMessageFieldGenerator::ImmutableMessageFieldGenerator(
const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex,
Context* context)
: descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
: descriptor_(descriptor),
name_resolver_(context->GetNameResolver()),
context_(context) {
SetMessageVariables(descriptor, messageBitIndex, builderBitIndex,
context->GetFieldGeneratorInfo(descriptor),
name_resolver_, &variables_);
name_resolver_, &variables_, context);
}
ImmutableMessageFieldGenerator::~ImmutableMessageFieldGenerator() {}
@ -861,7 +866,7 @@ RepeatedImmutableMessageFieldGenerator::RepeatedImmutableMessageFieldGenerator(
: descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
SetMessageVariables(descriptor, messageBitIndex, builderBitIndex,
context->GetFieldGeneratorInfo(descriptor),
name_resolver_, &variables_);
name_resolver_, &variables_, context);
}
RepeatedImmutableMessageFieldGenerator::

@ -91,6 +91,7 @@ class ImmutableMessageFieldGenerator : public ImmutableFieldGenerator {
const FieldDescriptor* descriptor_;
std::map<std::string, std::string> variables_;
ClassNameResolver* name_resolver_;
Context* context_;
void PrintNestedBuilderCondition(io::Printer* printer,
const char* regular_case,

@ -59,7 +59,8 @@ namespace {
void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
int builderBitIndex, const FieldGeneratorInfo* info,
ClassNameResolver* name_resolver,
std::map<std::string, std::string>* variables) {
std::map<std::string, std::string>* variables,
Context* context) {
SetCommonFieldVariables(descriptor, info, variables);
(*variables)["type"] =
@ -118,10 +119,11 @@ ImmutableMessageFieldLiteGenerator::ImmutableMessageFieldLiteGenerator(
const FieldDescriptor* descriptor, int messageBitIndex, Context* context)
: descriptor_(descriptor),
messageBitIndex_(messageBitIndex),
name_resolver_(context->GetNameResolver()) {
name_resolver_(context->GetNameResolver()),
context_(context) {
SetMessageVariables(descriptor, messageBitIndex, 0,
context->GetFieldGeneratorInfo(descriptor),
name_resolver_, &variables_);
name_resolver_, &variables_, context);
}
ImmutableMessageFieldLiteGenerator::~ImmutableMessageFieldLiteGenerator() {}
@ -496,10 +498,12 @@ RepeatedImmutableMessageFieldLiteGenerator::
RepeatedImmutableMessageFieldLiteGenerator(
const FieldDescriptor* descriptor, int messageBitIndex,
Context* context)
: descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
: descriptor_(descriptor),
name_resolver_(context->GetNameResolver()),
context_(context) {
SetMessageVariables(descriptor, messageBitIndex, 0,
context->GetFieldGeneratorInfo(descriptor),
name_resolver_, &variables_);
name_resolver_, &variables_, context);
}
RepeatedImmutableMessageFieldLiteGenerator::
@ -529,6 +533,13 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateInterfaceMembers(
void RepeatedImmutableMessageFieldLiteGenerator::GenerateMembers(
io::Printer* printer) const {
if (!context_->options().opensource_runtime) {
printer->Print(
variables_,
"@com.google.protobuf.ProtoField(\n"
" fieldNumber=$number$,\n"
" type=com.google.protobuf.FieldType.$annotation_field_type$)\n");
}
printer->Print(
variables_,
"private com.google.protobuf.Internal.ProtobufList<$type$> $name$_;\n");

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save