diff --git a/protobuf.bzl b/protobuf.bzl index 3c8afcc17f5a..888e9787260c 100644 --- a/protobuf.bzl +++ b/protobuf.bzl @@ -80,7 +80,6 @@ def _proto_gen_impl(ctx): srcs = ctx.files.srcs langs = ctx.attr.langs or [] out_type = ctx.attr.out_type - enable_editions = ctx.attr.enable_editions deps = depset(direct = ctx.files.srcs) source_dir = _SourceDir(ctx) gen_dir = _GenDir(ctx).rstrip("/") @@ -131,8 +130,6 @@ def _proto_gen_impl(ctx): generated_files = [] for src in srcs: args = [] - if enable_editions: - args.append("--experimental_editions") in_gen_dir = src.root.path == gen_dir if in_gen_dir: @@ -250,7 +247,6 @@ _proto_gen = rule( attrs = { "srcs": attr.label_list(allow_files = True), "deps": attr.label_list(providers = [ProtoGenInfo]), - "enable_editions": attr.bool(), "includes": attr.string_list(), "protoc": attr.label( cfg = "exec", @@ -410,7 +406,6 @@ def internal_objc_proto_library( includes = ["."], default_runtime = Label("//:protobuf_objc"), protoc = Label("//:protoc"), - enable_editions = False, testonly = None, visibility = ["//visibility:public"], **kwargs): @@ -430,7 +425,6 @@ def internal_objc_proto_library( includes: a string indicating the include path of the .proto files. default_runtime: the Objective-C Protobuf runtime protoc: the label of the protocol compiler to generate the sources. - enable_editions: if editions should be enabled while invoking the compiler. testonly: common rule attribute (see: https://bazel.build/reference/be/common-definitions#common-attributes) visibility: the visibility of the generated files. @@ -445,7 +439,6 @@ def internal_objc_proto_library( testonly = testonly, srcs = proto_deps, protoc = protoc, - enable_editions = enable_editions, includes = includes, ) full_deps.append(":%s_deps_genproto" % name) @@ -460,7 +453,6 @@ def internal_objc_proto_library( out_type = "hdrs", includes = includes, protoc = protoc, - enable_editions = enable_editions, testonly = testonly, visibility = visibility, tags = ["manual"], @@ -474,7 +466,6 @@ def internal_objc_proto_library( out_type = "srcs", includes = includes, protoc = protoc, - enable_editions = enable_editions, testonly = testonly, visibility = visibility, tags = ["manual"], diff --git a/src/google/protobuf/compiler/BUILD.bazel b/src/google/protobuf/compiler/BUILD.bazel index 1631d0c8f19a..60e73a918b35 100644 --- a/src/google/protobuf/compiler/BUILD.bazel +++ b/src/google/protobuf/compiler/BUILD.bazel @@ -346,6 +346,7 @@ cc_binary( srcs = ["fake_plugin.cc"], deps = [ ":plugin_cc_proto", + "//src/google/protobuf", "//src/google/protobuf/io:io_win32", "@com_google_absl//absl/log:absl_check", "@com_google_absl//absl/strings", diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc index 26ef835479f7..84290eff06be 100644 --- a/src/google/protobuf/compiler/command_line_interface.cc +++ b/src/google/protobuf/compiler/command_line_interface.cc @@ -1615,22 +1615,6 @@ bool CommandLineInterface::ParseInputFiles( } parsed_files->push_back(parsed_file); - if (!experimental_editions_ && - !absl::StartsWith(parsed_file->name(), "google/protobuf/") && - !absl::StartsWith(parsed_file->name(), "upb/")) { - if (::google::protobuf::internal::InternalFeatureHelper::GetEdition(*parsed_file) >= - Edition::EDITION_2023) { - std::cerr - << parsed_file->name() - << ": This file uses editions, but --experimental_editions has not " - "been enabled. This syntax is experimental and should be " - "avoided." - << std::endl; - result = false; - break; - } - } - // Enforce --disallow_services. if (disallow_services_ && parsed_file->service_count() > 0) { std::cerr << parsed_file->name() diff --git a/src/google/protobuf/compiler/command_line_interface_unittest.cc b/src/google/protobuf/compiler/command_line_interface_unittest.cc index f351edc06248..376f71900931 100644 --- a/src/google/protobuf/compiler/command_line_interface_unittest.cc +++ b/src/google/protobuf/compiler/command_line_interface_unittest.cc @@ -1367,7 +1367,7 @@ TEST_F(CommandLineInterfaceTest, NonExperimentalEditions) { Run("protocol_compiler --proto_path=$tmpdir --test_out=$tmpdir foo.proto"); - ExpectErrorSubstring("--experimental_editions has not been enabled"); + ExpectNoErrors(); } TEST_F(CommandLineInterfaceTest, EditionsFlagExplicitTrue) { @@ -1375,8 +1375,7 @@ TEST_F(CommandLineInterfaceTest, EditionsFlagExplicitTrue) { "edition = \"2023\";\n" "message FooRequest {}\n"); - Run("protocol_compiler --proto_path=$tmpdir --test_out=$tmpdir " - "--experimental_editions foo.proto"); + Run("protocol_compiler --proto_path=$tmpdir --test_out=$tmpdir foo.proto"); ExpectNoErrors(); } @@ -1390,8 +1389,7 @@ TEST_F(CommandLineInterfaceTest, FeaturesEditionZero) { int32 baz = 2; })schema"); - Run("protocol_compiler --proto_path=$tmpdir --test_out=$tmpdir " - "--experimental_editions foo.proto"); + Run("protocol_compiler --proto_path=$tmpdir --test_out=$tmpdir foo.proto"); ExpectNoErrors(); } @@ -1422,8 +1420,7 @@ TEST_F(CommandLineInterfaceTest, FeatureExtensions) { int32 baz = 2 [features.(pb.test).int_feature = 5]; })schema"); - Run("protocol_compiler --proto_path=$tmpdir --test_out=$tmpdir " - "--experimental_editions foo.proto"); + Run("protocol_compiler --proto_path=$tmpdir --test_out=$tmpdir foo.proto"); ExpectNoErrors(); } @@ -1437,8 +1434,7 @@ TEST_F(CommandLineInterfaceTest, FeatureValidationError) { int32 baz = 2; })schema"); - Run("protocol_compiler --proto_path=$tmpdir --test_out=$tmpdir " - "--experimental_editions foo.proto"); + Run("protocol_compiler --proto_path=$tmpdir --test_out=$tmpdir foo.proto"); ExpectErrorSubstring( "`field_presence` must resolve to a known value, found " "FIELD_PRESENCE_UNKNOWN"); @@ -1454,8 +1450,7 @@ TEST_F(CommandLineInterfaceTest, FeatureTargetError) { int32 baz = 2; })schema"); - Run("protocol_compiler --proto_path=$tmpdir --test_out=$tmpdir " - "--experimental_editions foo.proto"); + Run("protocol_compiler --proto_path=$tmpdir --test_out=$tmpdir foo.proto"); ExpectErrorSubstring( "FeatureSet.field_presence cannot be set on an entity of type `message`"); } @@ -1477,8 +1472,7 @@ TEST_F(CommandLineInterfaceTest, FeatureExtensionError) { mock_generator_->set_feature_extensions( {GetExtensionReflection(pb::test_invalid)}); - Run("protocol_compiler --proto_path=$tmpdir --test_out=$tmpdir " - "--experimental_editions foo.proto"); + Run("protocol_compiler --proto_path=$tmpdir --test_out=$tmpdir foo.proto"); ExpectErrorSubstring( "Feature field pb.TestInvalidFeatures.repeated_feature is an unsupported " "repeated field"); @@ -1511,8 +1505,7 @@ TEST_F(CommandLineInterfaceTest, InvalidFeatureExtensionError) { mock_generator_->set_feature_extensions({nullptr}); - Run("protocol_compiler --proto_path=$tmpdir --test_out=$tmpdir " - "--experimental_editions foo.proto"); + Run("protocol_compiler --proto_path=$tmpdir --test_out=$tmpdir foo.proto"); ExpectErrorSubstring( "generator --test_out specifies an unknown feature extension"); } @@ -1526,8 +1519,7 @@ TEST_F(CommandLineInterfaceTest, Plugin_InvalidFeatureExtensionError) { )schema"); SetMockGeneratorTestCase("invalid_features"); - Run("protocol_compiler --experimental_editions " - "--proto_path=$tmpdir foo.proto --plug_out=$tmpdir"); + Run("protocol_compiler --proto_path=$tmpdir foo.proto --plug_out=$tmpdir"); ExpectErrorSubstring( "error generating feature defaults: Unknown extension of " @@ -1547,8 +1539,9 @@ TEST_F(CommandLineInterfaceTest, Plugin_DeprecatedEdition) { "--proto_path=$tmpdir foo.proto --plug_out=$tmpdir"); ExpectErrorSubstring( - "foo.proto: This file uses editions, but --experimental_editions has not " - "been enabled. This syntax is experimental and should be avoided."); + "foo.proto: is a file using edition 2023, which isn't supported by code " + "generator prefix-gen-plug. Please upgrade your file to at least " + "edition 99997_TEST_ONLY."); } TEST_F(CommandLineInterfaceTest, Plugin_FutureEdition) { @@ -1564,8 +1557,9 @@ TEST_F(CommandLineInterfaceTest, Plugin_FutureEdition) { "--proto_path=$tmpdir foo.proto --plug_out=$tmpdir"); ExpectErrorSubstring( - "foo.proto: This file uses editions, but --experimental_editions has not " - "been enabled. This syntax is experimental and should be avoided."); + "foo.proto: is a file using edition 2023, which isn't supported by code " + "generator prefix-gen-plug. Please ask the owner of this code generator " + "to add support or switch back to a maximum of edition PROTO2."); } TEST_F(CommandLineInterfaceTest, Plugin_VersionSkewFuture) { @@ -1611,8 +1605,7 @@ TEST_F(CommandLineInterfaceTest, Plugin_MissingFeatureExtensionError) { )schema"); SetMockGeneratorTestCase("no_feature_defaults"); - Run("protocol_compiler --experimental_editions " - "--proto_path=$tmpdir foo.proto --plug_out=$tmpdir"); + Run("protocol_compiler --proto_path=$tmpdir foo.proto --plug_out=$tmpdir"); ExpectErrorSubstring("Test features were not resolved properly"); } @@ -1625,8 +1618,7 @@ TEST_F(CommandLineInterfaceTest, Plugin_TestFeatures) { } )schema"); - Run("protocol_compiler --experimental_editions " - "--proto_path=$tmpdir foo.proto --plug_out=$tmpdir"); + Run("protocol_compiler --proto_path=$tmpdir foo.proto --plug_out=$tmpdir"); ExpectNoErrors(); } @@ -1687,11 +1679,10 @@ TEST_F(CommandLineInterfaceTest, Plugin_RuntimeFeatures) { // Invoke protoc with fake_plugin to get ahold of the CodeGeneratorRequest // sent by protoc. - Run( - absl::StrCat("protocol_compiler --experimental_editions " - "--fake_plugin_out=$tmpdir --proto_path=$tmpdir " - "foo.proto --plugin=prefix-gen-fake_plugin=", - plugin_path)); + Run(absl::StrCat( + "protocol_compiler --fake_plugin_out=$tmpdir --proto_path=$tmpdir " + "foo.proto --plugin=prefix-gen-fake_plugin=", + plugin_path)); ExpectNoErrors(); std::string base64_output = ReadFile("foo.proto.request"); std::string binary_request; @@ -1737,11 +1728,10 @@ TEST_F(CommandLineInterfaceTest, Plugin_SourceFeatures) { // Invoke protoc with fake_plugin to get ahold of the CodeGeneratorRequest // sent by protoc. - Run( - absl::StrCat("protocol_compiler --experimental_editions " - "--fake_plugin_out=$tmpdir --proto_path=$tmpdir " - "foo.proto --plugin=prefix-gen-fake_plugin=", - plugin_path)); + Run(absl::StrCat( + "protocol_compiler --fake_plugin_out=$tmpdir --proto_path=$tmpdir " + "foo.proto --plugin=prefix-gen-fake_plugin=", + plugin_path)); ExpectNoErrors(); std::string base64_output = ReadFile("foo.proto.request"); std::string binary_request; @@ -1786,7 +1776,9 @@ TEST_F(CommandLineInterfaceTest, GeneratorNoEditionsSupport) { Run("protocol_compiler " "--proto_path=$tmpdir foo.proto --no_editions_out=$tmpdir"); - ExpectErrorSubstring("--experimental_editions has not been enabled"); + ExpectErrorSubstring( + "code generator --no_editions_out hasn't been updated to support " + "editions"); } TEST_F(CommandLineInterfaceTest, PluginNoEditionsSupport) { @@ -1801,7 +1793,8 @@ TEST_F(CommandLineInterfaceTest, PluginNoEditionsSupport) { Run("protocol_compiler " "--proto_path=$tmpdir foo.proto --plug_out=$tmpdir"); - ExpectErrorSubstring("--experimental_editions has not been enabled"); + ExpectErrorSubstring( + "code generator prefix-gen-plug hasn't been updated to support editions"); } TEST_F(CommandLineInterfaceTest, EditionDefaults) { diff --git a/src/google/protobuf/compiler/cpp/generator_unittest.cc b/src/google/protobuf/compiler/cpp/generator_unittest.cc index 1b7257ddae12..a9cc448a95d8 100644 --- a/src/google/protobuf/compiler/cpp/generator_unittest.cc +++ b/src/google/protobuf/compiler/cpp/generator_unittest.cc @@ -75,8 +75,7 @@ TEST_F(CppGeneratorTest, LegacyClosedEnumOnNonEnumField) { })schema"); RunProtoc( - "protocol_compiler --proto_path=$tmpdir --cpp_out=$tmpdir " - "--experimental_editions foo.proto"); + "protocol_compiler --proto_path=$tmpdir --cpp_out=$tmpdir foo.proto"); ExpectErrorSubstring( "Field Foo.bar specifies the legacy_closed_enum feature but has non-enum " @@ -97,8 +96,7 @@ TEST_F(CppGeneratorTest, LegacyClosedEnum) { })schema"); RunProtoc( - "protocol_compiler --proto_path=$tmpdir --cpp_out=$tmpdir " - "--experimental_editions foo.proto"); + "protocol_compiler --proto_path=$tmpdir --cpp_out=$tmpdir foo.proto"); ExpectNoErrors(); } @@ -119,8 +117,7 @@ TEST_F(CppGeneratorTest, LegacyClosedEnumInherited) { })schema"); RunProtoc( - "protocol_compiler --proto_path=$tmpdir --cpp_out=$tmpdir " - "--experimental_editions foo.proto"); + "protocol_compiler --proto_path=$tmpdir --cpp_out=$tmpdir foo.proto"); ExpectNoErrors(); } @@ -141,8 +138,7 @@ TEST_F(CppGeneratorTest, LegacyClosedEnumImplicit) { )schema"); RunProtoc( - "protocol_compiler --proto_path=$tmpdir --cpp_out=$tmpdir " - "--experimental_editions foo.proto"); + "protocol_compiler --proto_path=$tmpdir --cpp_out=$tmpdir foo.proto"); ExpectErrorSubstring( "Field Foo.bar has a closed enum type with implicit presence."); @@ -160,8 +156,7 @@ TEST_F(CppGeneratorTest, NoStringTypeTillEdition2024) { )schema"); RunProtoc( - "protocol_compiler --proto_path=$tmpdir --cpp_out=$tmpdir " - "--experimental_editions foo.proto"); + "protocol_compiler --proto_path=$tmpdir --cpp_out=$tmpdir foo.proto"); ExpectErrorSubstring( "Field Foo.baz specifies string_type which is not currently allowed."); @@ -196,8 +191,7 @@ TEST_F(CppGeneratorTest, CtypeForCord) { )schema"); RunProtoc( - "protocol_compiler --proto_path=$tmpdir --cpp_out=$tmpdir " - "--experimental_editions foo.proto"); + "protocol_compiler --proto_path=$tmpdir --cpp_out=$tmpdir foo.proto"); ExpectNoErrors(); } @@ -252,8 +246,7 @@ TEST_F(CppGeneratorTest, CtypeOnNoneStringFieldTest) { int32 bar = 1 [ctype=STRING]; })schema"); RunProtoc( - "protocol_compiler --proto_path=$tmpdir --cpp_out=$tmpdir " - "--experimental_editions foo.proto"); + "protocol_compiler --proto_path=$tmpdir --cpp_out=$tmpdir foo.proto"); ExpectErrorSubstring( "Field Foo.bar specifies ctype, but is not " "a string nor bytes field."); @@ -270,8 +263,7 @@ TEST_F(CppGeneratorTest, CtypeOnExtensionTest) { bytes bar = 1 [ctype=CORD]; })schema"); RunProtoc( - "protocol_compiler --proto_path=$tmpdir --cpp_out=$tmpdir " - "--experimental_editions foo.proto"); + "protocol_compiler --proto_path=$tmpdir --cpp_out=$tmpdir foo.proto"); ExpectErrorSubstring( "Extension bar specifies ctype=CORD which is " "not supported for extensions."); diff --git a/src/google/protobuf/compiler/fake_plugin.cc b/src/google/protobuf/compiler/fake_plugin.cc index 51345bf01678..f479c74d69ba 100644 --- a/src/google/protobuf/compiler/fake_plugin.cc +++ b/src/google/protobuf/compiler/fake_plugin.cc @@ -11,6 +11,7 @@ #include #endif +#include "google/protobuf/descriptor.pb.h" #include "absl/log/absl_check.h" #include "absl/strings/escaping.h" #include "google/protobuf/compiler/plugin.pb.h" @@ -36,6 +37,8 @@ int main(int argc, char* argv[]) { CodeGeneratorResponse response; response.set_supported_features( CodeGeneratorResponse::FEATURE_SUPPORTS_EDITIONS); + response.set_minimum_edition(google::protobuf::Edition::EDITION_PROTO2); + response.set_maximum_edition(google::protobuf::Edition::EDITION_MAX); response.add_file()->set_name( absl::StrCat(request.file_to_generate(0), ".request")); response.mutable_file(0)->set_content( diff --git a/src/google/protobuf/compiler/java/message_serialization_unittest.cc b/src/google/protobuf/compiler/java/message_serialization_unittest.cc index 521bce45115e..10183535669f 100644 --- a/src/google/protobuf/compiler/java/message_serialization_unittest.cc +++ b/src/google/protobuf/compiler/java/message_serialization_unittest.cc @@ -46,11 +46,10 @@ int CompileJavaProto(std::string proto_file_name) { "protoc", proto_path.c_str(), java_out.c_str(), - "--experimental_editions", proto_file_name.c_str(), }; - return cli.Run(5, argv); + return cli.Run(4, argv); } TEST(MessageSerializationTest, CollapseAdjacentExtensionRanges) { diff --git a/src/google/protobuf/compiler/java/plugin_unittest.cc b/src/google/protobuf/compiler/java/plugin_unittest.cc index 7a0f55df47fe..2631f3a38be2 100644 --- a/src/google/protobuf/compiler/java/plugin_unittest.cc +++ b/src/google/protobuf/compiler/java/plugin_unittest.cc @@ -91,11 +91,10 @@ TEST(JavaPluginTest, PluginTest) { std::string java_out = absl::StrCat("--java_out=", ::testing::TempDir()); std::string test_out = absl::StrCat("--test_out=", ::testing::TempDir()); - const char* argv[] = { - "protoc", proto_path.c_str(), java_out.c_str(), - test_out.c_str(), "--experimental_editions", "test.proto"}; + const char* argv[] = {"protoc", proto_path.c_str(), java_out.c_str(), + test_out.c_str(), "test.proto"}; - EXPECT_EQ(0, cli.Run(6, argv)); + EXPECT_EQ(0, cli.Run(5, argv)); // Loop over the lines of the generated code and verify that we find what we // expect diff --git a/src/google/protobuf/editions/BUILD b/src/google/protobuf/editions/BUILD index 6f79f410328b..f7fc387ad33f 100644 --- a/src/google/protobuf/editions/BUILD +++ b/src/google/protobuf/editions/BUILD @@ -122,7 +122,6 @@ internal_objc_proto_library( name = "test_messages_proto2_editions_objc_proto", testonly = True, srcs = ["golden/test_messages_proto2_editions.proto"], - enable_editions = True, visibility = ["//conformance:__pkg__"], ) @@ -179,7 +178,6 @@ internal_objc_proto_library( name = "test_messages_proto3_editions_objc_proto", testonly = True, srcs = ["golden/test_messages_proto3_editions.proto"], - enable_editions = True, includes = [ ".", "src",