Skip to content

Commit

Permalink
Enable Editions in preparation for 27.0 release.
Browse files Browse the repository at this point in the history
This marks the official launch of editions, which no longer requires an --experimental_editions flag to use with supported generators.  The flag can still be used for generators that don't yet explicitly support editions.

PiperOrigin-RevId: 614729247
  • Loading branch information
mkruskal-google authored and copybara-github committed Mar 11, 2024
1 parent 7a0e10e commit baa83b6
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 86 deletions.
9 changes: 0 additions & 9 deletions protobuf.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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("/")
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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):
Expand All @@ -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.
Expand All @@ -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)
Expand All @@ -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"],
Expand All @@ -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"],
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 @@ -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",
Expand Down
16 changes: 0 additions & 16 deletions src/google/protobuf/compiler/command_line_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
67 changes: 30 additions & 37 deletions src/google/protobuf/compiler/command_line_interface_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1367,16 +1367,15 @@ 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) {
CreateTempFile("foo.proto",
"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();
}

Expand All @@ -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();
}

Expand Down Expand Up @@ -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();
}

Expand All @@ -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");
Expand All @@ -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`");
}
Expand All @@ -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");
Expand Down Expand Up @@ -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");
}
Expand All @@ -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 "
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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");
}
Expand All @@ -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();
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
24 changes: 8 additions & 16 deletions src/google/protobuf/compiler/cpp/generator_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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.");
Expand All @@ -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.");
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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.");
Expand All @@ -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.");
Expand Down
3 changes: 3 additions & 0 deletions src/google/protobuf/compiler/fake_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <unistd.h>
#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"
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit baa83b6

Please sign in to comment.