diff --git a/java/core/BUILD.bazel b/java/core/BUILD.bazel index 248fd7cd0a..04fe1ec146 100644 --- a/java/core/BUILD.bazel +++ b/java/core/BUILD.bazel @@ -10,6 +10,7 @@ load("//build_defs:java_opts.bzl", "protobuf_java_export", "protobuf_java_librar load("//conformance:defs.bzl", "conformance_test") load("//java/internal:testing.bzl", "junit_tests") load("//src/google/protobuf/editions:defaults.bzl", "compile_edition_defaults", "embed_edition_defaults") +load("//upb/cmake:build_defs.bzl", "staleness_test") LITE_SRCS = [ # Keep in sync with `//java/lite:pom.xml`. @@ -106,6 +107,15 @@ LITE_SRCS = [ "src/main/java/com/google/protobuf/Writer.java", ] +FULL_SRCS = glob( + [ + "src/main/java/com/google/protobuf/*.java", + ], + exclude = LITE_SRCS, +) + [ + ":gen_well_known_protos_java", +] + internal_gen_well_known_protos_java( name = "gen_well_known_protos_javalite", javalite = True, @@ -190,6 +200,32 @@ filegroup( visibility = ["//pkg:__pkg__"], ) +compile_edition_defaults( + name = "java_edition_defaults", + srcs = [ + "//:descriptor_proto", + "//java/core:java_features_proto", + ], + maximum_edition = "2023", + minimum_edition = "PROTO2", +) + +embed_edition_defaults( + name = "embedded_java_edition_defaults_generate", + defaults = "java_edition_defaults", + output = "generated/src/main/java/com/google/protobuf/JavaEditionDefaults.java", + placeholder = "DEFAULTS_VALUE", + template = "src/main/java/com/google/protobuf/JavaEditionDefaults.java.template", +) + +staleness_test( + name = "generated_java_defaults_staleness_test", + outs = ["src/main/java/com/google/protobuf/JavaEditionDefaults.java"], + generated_pattern = "generated/%s", + tags = ["manual"], + target_files = ["src/main/java/com/google/protobuf/JavaEditionDefaults.java"], +) + internal_gen_well_known_protos_java( name = "gen_well_known_protos_java", deps = [ @@ -211,14 +247,7 @@ internal_gen_well_known_protos_java( java_library( name = "core", - srcs = glob( - [ - "src/main/java/com/google/protobuf/*.java", - ], - exclude = LITE_SRCS, - ) + [ - ":gen_well_known_protos_java", - ], + srcs = FULL_SRCS, visibility = ["//visibility:public"], exports = [ ":lite_runtime_only", @@ -230,14 +259,7 @@ java_library( protobuf_versioned_java_library( name = "core_bundle", - srcs = glob( - [ - "src/main/java/com/google/protobuf/*.java", - ], - exclude = LITE_SRCS, - ) + [ - ":gen_well_known_protos_java", - ], + srcs = FULL_SRCS, automatic_module_name = "com.google.protobuf", bundle_description = "Core Protocol Buffers library. Protocol Buffers " + "are a way of encoding structured data in an " + diff --git a/regenerate_stale_files.sh b/regenerate_stale_files.sh index 7134e173a8..b7322b5c70 100755 --- a/regenerate_stale_files.sh +++ b/regenerate_stale_files.sh @@ -13,6 +13,8 @@ cd $(dirname -- "$0") readonly BazelBin="${BAZEL:-bazel} ${BAZEL_STARTUP_FLAGS}" STALENESS_TESTS=( + "java/core:generated_java_defaults_staleness_test" + "upb/reflection:bootstrap_upb_defaults_staleness_test" "src:cmake_lists_staleness_test" "src/google/protobuf:well_known_types_staleness_test" "objectivec:well_known_types_staleness_test" diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc index 0d271d4dcb..82cce7b73a 100644 --- a/src/google/protobuf/compiler/command_line_interface.cc +++ b/src/google/protobuf/compiler/command_line_interface.cc @@ -3006,8 +3006,12 @@ bool CommandLineInterface::WriteDescriptorSet( } bool CommandLineInterface::WriteEditionDefaults(const DescriptorPool& pool) { - const Descriptor* feature_set = - pool.FindMessageTypeByName("google.protobuf.FeatureSet"); + const Descriptor* feature_set; + if (opensource_runtime_) { + feature_set = pool.FindMessageTypeByName("google.protobuf.FeatureSet"); + } else { + feature_set = pool.FindMessageTypeByName("google.protobuf.FeatureSet"); + } if (feature_set == nullptr) { std::cerr << edition_defaults_out_name_ << ": Could not find FeatureSet in descriptor pool. Please make " diff --git a/src/google/protobuf/compiler/command_line_interface.h b/src/google/protobuf/compiler/command_line_interface.h index e99deada8e..43ab8eee1d 100644 --- a/src/google/protobuf/compiler/command_line_interface.h +++ b/src/google/protobuf/compiler/command_line_interface.h @@ -193,6 +193,11 @@ class PROTOC_EXPORT CommandLineInterface { void SetVersionInfo(const std::string& text) { version_info_ = text; } + // Configure protoc to act as if we're in opensource. + void set_opensource_runtime(bool opensource) { + opensource_runtime_ = opensource; + } + private: // ----------------------------------------------------------------- @@ -463,6 +468,8 @@ class PROTOC_EXPORT CommandLineInterface { // When using --encode, this will be passed to SetSerializationDeterministic. bool deterministic_output_ = false; + + bool opensource_runtime_ = PROTO2_IS_OSS; }; } // namespace compiler diff --git a/src/google/protobuf/compiler/main.cc b/src/google/protobuf/compiler/main.cc index 2268f61dbb..a5c7537f4d 100644 --- a/src/google/protobuf/compiler/main.cc +++ b/src/google/protobuf/compiler/main.cc @@ -39,6 +39,9 @@ int ProtobufMain(int argc, char* argv[]) { CommandLineInterface cli; cli.AllowPlugins("protoc-"); +#ifdef GOOGLE_PROTOBUF_RUNTIME_INCLUDE_BASE + cli.set_opensource_runtime(true); +#endif // Proto2 C++ cpp::CppGenerator cpp_generator; diff --git a/src/google/protobuf/editions/defaults.bzl b/src/google/protobuf/editions/defaults.bzl index e20b9222b8..0974d9da02 100644 --- a/src/google/protobuf/editions/defaults.bzl +++ b/src/google/protobuf/editions/defaults.bzl @@ -31,7 +31,7 @@ def _compile_edition_defaults_impl(ctx): ctx.actions.run( outputs = [out_file], inputs = sources, - executable = ctx.executable._protoc, + executable = ctx.executable.protoc or ctx.executable._protoc_minimal, arguments = [args], progress_message = "Generating edition defaults", ) @@ -45,7 +45,12 @@ compile_edition_defaults = rule( ), "minimum_edition": attr.string(mandatory = True), "maximum_edition": attr.string(mandatory = True), - "_protoc": attr.label( + "protoc": attr.label( + mandatory = False, + executable = True, + cfg = "exec", + ), + "_protoc_minimal": attr.label( default = "//src/google/protobuf/compiler:protoc_minimal", executable = True, cfg = "exec", diff --git a/upb/reflection/BUILD b/upb/reflection/BUILD index 3e3cccb02c..88e4d91f8e 100644 --- a/upb/reflection/BUILD +++ b/upb/reflection/BUILD @@ -7,12 +7,16 @@ load("//bazel:upb_minitable_proto_library.bzl", "upb_minitable_proto_library") load("//bazel:upb_proto_library.bzl", "upb_proto_reflection_library") + +# end:github_only load( "//src/google/protobuf/editions:defaults.bzl", "compile_edition_defaults", "embed_edition_defaults", ) load("//upb/bazel:build_defs.bzl", "UPB_DEFAULT_COPTS") + +# begin:github_only load( "//upb/cmake:build_defs.bzl", "staleness_test", @@ -188,6 +192,29 @@ cc_test( ], ) +# begin:google_only +# compile_edition_defaults( +# name = "upb_edition_defaults", +# srcs = [ +# "//:descriptor_proto", +# ], +# compatible_with = ["//buildenv/target:non_prod"], +# maximum_edition = "2023", +# minimum_edition = "PROTO2", +# ) +# +# embed_edition_defaults( +# name = "embedded_upb_edition_defaults_generate", +# compatible_with = ["//buildenv/target:non_prod"], +# defaults = "upb_edition_defaults", +# output = "internal/upb_edition_defaults.h", +# placeholder = "DEFAULTS_VALUE", +# template = "internal/upb_edition_defaults.h.template", +# ) +# end:google_only + +# TODO Merge these once we deal with the whitespace issues with reversible stripping. +# begin:github_only compile_edition_defaults( name = "upb_edition_defaults", srcs = [ @@ -209,8 +236,10 @@ staleness_test( name = "bootstrap_upb_defaults_staleness_test", outs = ["internal/upb_edition_defaults.h"], generated_pattern = "generated/%s", + tags = ["manual"], target_files = ["internal/upb_edition_defaults.h"], ) +# end:github_only # begin:github_only filegroup(