Skip to content

Commit

Permalink
Merge pull request protocolbuffers#16722 from protocolbuffers/cp-java…
Browse files Browse the repository at this point in the history
…-generator

Cherry pick java_features.proto boostrap and java generator refactor
  • Loading branch information
zhangskz committed May 2, 2024
2 parents 8dedafc + cd337dd commit 4114925
Show file tree
Hide file tree
Showing 69 changed files with 1,610 additions and 996 deletions.
1 change: 1 addition & 0 deletions pkg/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ cc_dist_library(
"//src/google/protobuf/compiler/cpp",
"//src/google/protobuf/compiler/csharp",
"//src/google/protobuf/compiler/java",
"//src/google/protobuf/compiler/java:kotlin",
"//src/google/protobuf/compiler/objectivec",
"//src/google/protobuf/compiler/php",
"//src/google/protobuf/compiler/python",
Expand Down
94 changes: 53 additions & 41 deletions src/file_lists.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -330,36 +330,40 @@ set(libprotoc_srcs
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/names.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/context.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/doc_comment.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/enum.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/enum_field.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/enum_field_lite.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/enum_lite.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/extension.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/extension_lite.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/field.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/field_common.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/file.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/generator.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/generator_factory.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/helpers.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/immutable/enum.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/immutable/enum_field.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/immutable/extension.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/immutable/generator_factory.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/immutable/make_field_generators.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/immutable/map_field.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/immutable/message.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/immutable/message_builder.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/immutable/message_field.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/immutable/primitive_field.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/immutable/service.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/immutable/string_field.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/internal_helpers.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/java_features.pb.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/kotlin_generator.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/map_field.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/map_field_lite.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/message.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/message_builder.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/message_builder_lite.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/message_field.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/message_field_lite.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/message_lite.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/lite/enum.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/lite/enum_field.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/lite/extension.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/lite/generator_factory.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/lite/make_field_generators.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/lite/map_field.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/lite/message.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/lite/message_builder.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/lite/message_field.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/lite/primitive_field.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/lite/string_field.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/message_serialization.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/name_resolver.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/names.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/primitive_field.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/primitive_field_lite.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/service.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/shared_code_generator.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/string_field.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/string_field_lite.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/enum.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/enum_field.cc
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/extension.cc
Expand Down Expand Up @@ -452,37 +456,45 @@ set(libprotoc_hdrs
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/csharp/names.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/context.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/doc_comment.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/enum.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/enum_field.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/enum_field_lite.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/enum_lite.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/extension.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/extension_lite.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/field.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/field_common.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/file.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/generator.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/generator_common.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/generator_factory.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/helpers.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/immutable/enum.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/immutable/enum_field.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/immutable/extension.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/immutable/field_generator.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/immutable/generator_factory.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/immutable/make_field_generators.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/immutable/map_field.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/immutable/message.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/immutable/message_builder.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/immutable/message_field.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/immutable/primitive_field.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/immutable/service.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/immutable/string_field.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/internal_helpers.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/java_features.pb.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/kotlin_generator.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/map_field.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/map_field_lite.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/message.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/message_builder.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/message_builder_lite.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/message_field.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/message_field_lite.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/message_lite.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/lite/enum.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/lite/enum_field.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/lite/extension.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/lite/field_generator.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/lite/generator_factory.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/lite/make_field_generators.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/lite/map_field.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/lite/message.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/lite/message_builder.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/lite/message_field.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/lite/primitive_field.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/lite/string_field.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/message_serialization.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/name_resolver.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/names.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/options.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/primitive_field.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/primitive_field_lite.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/service.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/shared_code_generator.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/string_field.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/java/string_field_lite.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/enum.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/enum_field.h
${protobuf_SOURCE_DIR}/src/google/protobuf/compiler/objectivec/extension.h
Expand Down
1 change: 1 addition & 0 deletions src/google/protobuf/compiler/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ cc_library(
"//src/google/protobuf/compiler/cpp",
"//src/google/protobuf/compiler/csharp",
"//src/google/protobuf/compiler/java",
"//src/google/protobuf/compiler/java:kotlin",
"//src/google/protobuf/compiler/objectivec",
"//src/google/protobuf/compiler/php",
"//src/google/protobuf/compiler/python",
Expand Down
152 changes: 96 additions & 56 deletions src/google/protobuf/compiler/java/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,47 @@ load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix")
load("//build_defs:cpp_opts.bzl", "COPTS")

package(
default_visibility = [
"//src/google/protobuf/compiler/java:__subpackages__",
],
)

cc_library(
name = "names",
hdrs = ["names.h"],
copts = COPTS,
strip_include_prefix = "/src",
visibility = ["//visibility:public"],
deps = [
":names_internal",
":helpers",
"//src/google/protobuf",
],
)

cc_library(
name = "names_internal",
name = "helpers",
srcs = [
"doc_comment.cc",
"helpers.cc",
"name_resolver.cc",
"names.cc",
],
hdrs = [
"generator.h",
"context.h",
"doc_comment.h",
"helpers.h",
"name_resolver.h",
"names.h",
"options.h",
],
copts = COPTS,
strip_include_prefix = "/src",
visibility = ["//pkg:__pkg__"],
visibility = [
"//pkg:__pkg__",
"//src/google/protobuf/compiler/java:__subpackages__",
],
deps = [
":java_features_bootstrap",
"//src/google/protobuf",
"//src/google/protobuf:port",
"//src/google/protobuf/compiler:code_generator",
Expand All @@ -52,6 +62,25 @@ cc_library(
],
)

cc_library(
name = "internal_helpers",
srcs = ["internal_helpers.cc"],
hdrs = [
"generator.h",
"internal_helpers.h",
],
strip_include_prefix = "/src",
visibility = ["//src/google/protobuf/compiler/java:__subpackages__"],
deps = [
":helpers",
":java_features_bootstrap",
"//src/google/protobuf",
"//src/google/protobuf:port",
"//src/google/protobuf/compiler:code_generator",
"@com_google_absl//absl/log:absl_log",
],
)

cc_library(
name = "java_features_bootstrap",
srcs = ["java_features.pb.cc"],
Expand All @@ -70,64 +99,16 @@ cc_library(
name = "java",
srcs = [
"context.cc",
"doc_comment.cc",
"enum.cc",
"enum_field.cc",
"enum_field_lite.cc",
"enum_lite.cc",
"extension.cc",
"extension_lite.cc",
"field.cc",
"file.cc",
"generator.cc",
"generator_factory.cc",
"kotlin_generator.cc",
"map_field.cc",
"map_field_lite.cc",
"message.cc",
"message_builder.cc",
"message_builder_lite.cc",
"message_field.cc",
"message_field_lite.cc",
"message_lite.cc",
"message_serialization.cc",
"primitive_field.cc",
"primitive_field_lite.cc",
"service.cc",
"shared_code_generator.cc",
"string_field.cc",
"string_field_lite.cc",
],
hdrs = [
"context.h",
"doc_comment.h",
"enum.h",
"enum_field.h",
"enum_field_lite.h",
"enum_lite.h",
"extension.h",
"extension_lite.h",
"field.h",
"file.h",
"generator.h",
"generator_factory.h",
"java_features.pb.h",
"kotlin_generator.h",
"map_field.h",
"map_field_lite.h",
"message.h",
"message_builder.h",
"message_builder_lite.h",
"message_field.h",
"message_field_lite.h",
"message_lite.h",
"message_serialization.h",
"primitive_field.h",
"primitive_field_lite.h",
"service.h",
"shared_code_generator.h",
"string_field.h",
"string_field_lite.h",
],
copts = COPTS,
strip_include_prefix = "/src",
Expand All @@ -136,16 +117,19 @@ cc_library(
"//src/google/protobuf/compiler:__pkg__",
],
deps = [
":generator_common",
":helpers",
":java_features_bootstrap",
":names",
":names_internal",
"//src/google/protobuf",
"//src/google/protobuf:arena",
"//src/google/protobuf:port",
"//src/google/protobuf:protobuf_lite",
"//src/google/protobuf/compiler:code_generator",
"//src/google/protobuf/compiler:retention",
"//src/google/protobuf/compiler:versions",
"//src/google/protobuf/compiler/java/immutable",
"//src/google/protobuf/compiler/java/lite",
"//src/google/protobuf/io",
"//src/google/protobuf/io:printer",
"@com_google_absl//absl/container:btree",
Expand All @@ -158,6 +142,62 @@ cc_library(
],
)

cc_library(
name = "generator_common",
srcs = ["field_common.cc"],
hdrs = [
"field_common.h",
"generator_common.h",
"generator_factory.h",
],
strip_include_prefix = "/src",
visibility = ["//src/google/protobuf/compiler/java:__subpackages__"],
deps = [
":helpers",
"//src/google/protobuf",
"//src/google/protobuf:port",
"//src/google/protobuf/io:printer",
"@com_google_absl//absl/container:btree",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/log:absl_check",
"@com_google_absl//absl/log:absl_log",
"@com_google_absl//absl/strings:string_view",
],
)

cc_library(
name = "message_serialization",
srcs = ["message_serialization.cc"],
hdrs = ["message_serialization.h"],
strip_include_prefix = "/src",
deps = [
":generator_common",
":helpers",
"//src/google/protobuf",
"//src/google/protobuf/io:printer",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/types:span",
],
)

cc_library(
name = "kotlin",
srcs = ["kotlin_generator.cc"],
hdrs = ["kotlin_generator.h"],
strip_include_prefix = "/src",
visibility = [
"//pkg:__pkg__",
"//src/google/protobuf/compiler:__pkg__",
],
deps = [
":helpers",
":java",
"//src/google/protobuf",
"//src/google/protobuf:port",
"//src/google/protobuf/compiler:code_generator",
],
)

cc_test(
name = "doc_comment_unittest",
srcs = ["doc_comment_unittest.cc"],
Expand All @@ -167,7 +207,7 @@ cc_test(
"//src/google/protobuf:descriptor_proto_srcs",
],
deps = [
":java",
":helpers",
"@com_google_googletest//:gtest",
"@com_google_googletest//:gtest_main",
],
Expand All @@ -178,7 +218,7 @@ cc_test(
srcs = ["plugin_unittest.cc"],
deps = [
":java",
"//:protobuf",
"//src/google/protobuf",
"//src/google/protobuf/compiler:command_line_interface",
"//src/google/protobuf/io",
"//src/google/protobuf/io:printer",
Expand Down
2 changes: 1 addition & 1 deletion src/google/protobuf/compiler/java/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "absl/strings/strip.h"
#include "google/protobuf/compiler/java/field.h"
#include "google/protobuf/compiler/java/field_common.h"
#include "google/protobuf/compiler/java/helpers.h"
#include "google/protobuf/compiler/java/name_resolver.h"
#include "google/protobuf/descriptor.h"
Expand Down

0 comments on commit 4114925

Please sign in to comment.