Hook up staleness tests to non-bootstrap edition defaults

PiperOrigin-RevId: 623936729
pull/16469/head
Mike Kruskal 2024-04-11 14:14:43 -07:00 committed by Copybara-Service
parent de5e7b6b8e
commit 7d87a1780a
7 changed files with 92 additions and 20 deletions

View File

@ -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 " +

View File

@ -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"

View File

@ -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 "

View File

@ -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

View File

@ -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;

View File

@ -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",

View File

@ -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(