Specify proto2/proto3 defaults on feature specs.

This hooks up legacy proto2/proto3 editions, but prohibits them from being used in proto files.  These will be hooked up directly to `syntax` declarations in a later change.

PiperOrigin-RevId: 570746314
pull/14280/head
Mike Kruskal 1 year ago committed by Copybara-Service
parent 17e06c108d
commit 5b340ded2b
  1. 5
      java/core/src/main/java/com/google/protobuf/java_features.proto
  2. 22
      src/google/protobuf/compiler/code_generator_unittest.cc
  3. 86
      src/google/protobuf/compiler/command_line_interface_unittest.cc
  4. 2
      src/google/protobuf/compiler/parser.cc
  5. 20
      src/google/protobuf/compiler/parser_unittest.cc
  6. 12
      src/google/protobuf/cpp_features.pb.cc
  7. 3
      src/google/protobuf/cpp_features.proto
  8. 112
      src/google/protobuf/descriptor.pb.cc
  9. 16
      src/google/protobuf/descriptor.proto
  10. 45
      src/google/protobuf/feature_resolver_test.cc
  11. 34
      src/google/protobuf/unittest_features.proto

@ -24,7 +24,8 @@ message JavaFeatures {
retention = RETENTION_RUNTIME,
targets = TARGET_TYPE_FIELD,
targets = TARGET_TYPE_FILE,
edition_defaults = { edition: EDITION_2023, value: "false" }
edition_defaults = { edition: EDITION_PROTO2, value: "true" },
edition_defaults = { edition: EDITION_PROTO3, value: "false" }
];
// The UTF8 validation strategy to use. See go/editions-utf8-validation for
@ -43,6 +44,6 @@ message JavaFeatures {
retention = RETENTION_RUNTIME,
targets = TARGET_TYPE_FIELD,
targets = TARGET_TYPE_FILE,
edition_defaults = { edition: EDITION_2023, value: "DEFAULT" }
edition_defaults = { edition: EDITION_PROTO2, value: "DEFAULT" }
];
}

@ -263,6 +263,28 @@ TEST_F(CodeGeneratorTest, BuildFeatureSetDefaults) {
generator.set_maximum_edition(EDITION_99999_TEST_ONLY);
EXPECT_THAT(generator.BuildFeatureSetDefaults(),
IsOkAndHolds(EqualsProto(R"pb(
defaults {
edition: EDITION_PROTO2
features {
field_presence: EXPLICIT
enum_type: CLOSED
repeated_field_encoding: EXPANDED
utf8_validation: UNVERIFIED
message_encoding: LENGTH_PREFIXED
json_format: LEGACY_BEST_EFFORT
}
}
defaults {
edition: EDITION_PROTO3
features {
field_presence: IMPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
}
}
defaults {
edition: EDITION_2023
features {

@ -1747,6 +1747,28 @@ TEST_F(CommandLineInterfaceTest, EditionDefaults) {
FeatureSetDefaults defaults = ReadEditionDefaults("defaults");
EXPECT_THAT(defaults, EqualsProto(R"pb(
defaults {
edition: EDITION_PROTO2
features {
field_presence: EXPLICIT
enum_type: CLOSED
repeated_field_encoding: EXPANDED
utf8_validation: UNVERIFIED
message_encoding: LENGTH_PREFIXED
json_format: LEGACY_BEST_EFFORT
}
}
defaults {
edition: EDITION_PROTO3
features {
field_presence: IMPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
}
}
defaults {
edition: EDITION_2023
features {
@ -1774,6 +1796,28 @@ TEST_F(CommandLineInterfaceTest, EditionDefaultsWithMaximum) {
FeatureSetDefaults defaults = ReadEditionDefaults("defaults");
EXPECT_THAT(defaults, EqualsProto(R"pb(
defaults {
edition: EDITION_PROTO2
features {
field_presence: EXPLICIT
enum_type: CLOSED
repeated_field_encoding: EXPANDED
utf8_validation: UNVERIFIED
message_encoding: LENGTH_PREFIXED
json_format: LEGACY_BEST_EFFORT
}
}
defaults {
edition: EDITION_PROTO3
features {
field_presence: IMPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
}
}
defaults {
edition: EDITION_2023
features {
@ -1802,6 +1846,28 @@ TEST_F(CommandLineInterfaceTest, EditionDefaultsWithMinimum) {
FeatureSetDefaults defaults = ReadEditionDefaults("defaults");
EXPECT_THAT(defaults, EqualsProto(R"pb(
defaults {
edition: EDITION_PROTO2
features {
field_presence: EXPLICIT
enum_type: CLOSED
repeated_field_encoding: EXPANDED
utf8_validation: UNVERIFIED
message_encoding: LENGTH_PREFIXED
json_format: LEGACY_BEST_EFFORT
}
}
defaults {
edition: EDITION_PROTO3
features {
field_presence: IMPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
}
}
defaults {
edition: EDITION_2023
features {
@ -1832,18 +1898,26 @@ TEST_F(CommandLineInterfaceTest, EditionDefaultsWithExtension) {
FeatureSetDefaults defaults = ReadEditionDefaults("defaults");
EXPECT_EQ(defaults.minimum_edition(), EDITION_2023);
EXPECT_EQ(defaults.maximum_edition(), EDITION_99999_TEST_ONLY);
ASSERT_EQ(defaults.defaults_size(), 3);
EXPECT_EQ(defaults.defaults(0).edition(), EDITION_2023);
EXPECT_EQ(defaults.defaults(1).edition(), EDITION_99997_TEST_ONLY);
EXPECT_EQ(defaults.defaults(2).edition(), EDITION_99998_TEST_ONLY);
ASSERT_EQ(defaults.defaults_size(), 5);
EXPECT_EQ(defaults.defaults(0).edition(), EDITION_PROTO2);
EXPECT_EQ(defaults.defaults(1).edition(), EDITION_PROTO3);
EXPECT_EQ(defaults.defaults(2).edition(), EDITION_2023);
EXPECT_EQ(defaults.defaults(3).edition(), EDITION_99997_TEST_ONLY);
EXPECT_EQ(defaults.defaults(4).edition(), EDITION_99998_TEST_ONLY);
EXPECT_EQ(
defaults.defaults(0).features().GetExtension(pb::test).int_file_feature(),
1);
0);
EXPECT_EQ(
defaults.defaults(1).features().GetExtension(pb::test).int_file_feature(),
2);
0);
EXPECT_EQ(
defaults.defaults(2).features().GetExtension(pb::test).int_file_feature(),
1);
EXPECT_EQ(
defaults.defaults(3).features().GetExtension(pb::test).int_file_feature(),
2);
EXPECT_EQ(
defaults.defaults(4).features().GetExtension(pb::test).int_file_feature(),
3);
}

@ -731,7 +731,7 @@ bool Parser::ParseSyntaxIdentifier(const FileDescriptorProto* file,
if (has_edition) {
if (!Edition_Parse(absl::StrCat("EDITION_", syntax), &edition_) ||
edition_ == Edition::EDITION_UNKNOWN) {
edition_ < Edition::EDITION_2023) {
RecordError(syntax_token.line, syntax_token.column,
absl::StrCat("Unknown edition \"", syntax, "\"."));
return false;

@ -4214,6 +4214,26 @@ TEST_F(ParseEditionsTest, UnknownEdition) {
"1:18: Unknown edition \"UNKNOWN\".\n");
}
TEST_F(ParseEditionsTest, LegacyProto2Edition) {
ExpectHasEarlyExitErrors(
R"schema(
edition = "PROTO2";
message A {
optional int32 b = 1;
})schema",
"1:18: Unknown edition \"PROTO2\".\n");
}
TEST_F(ParseEditionsTest, LegacyProto3Edition) {
ExpectHasEarlyExitErrors(
R"schema(
edition = "PROTO3";
message A {
optional int32 b = 1;
})schema",
"1:18: Unknown edition \"PROTO3\".\n");
}
TEST_F(ParseEditionsTest, SyntaxEditions) {
ExpectHasEarlyExitErrors(
R"schema(

@ -70,11 +70,11 @@ static const ::_pb::Message* const file_default_instances[] = {
};
const char descriptor_table_protodef_google_2fprotobuf_2fcpp_5ffeatures_2eproto[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = {
"\n\"google/protobuf/cpp_features.proto\022\002pb"
"\032 google/protobuf/descriptor.proto\"A\n\013Cp"
"pFeatures\0222\n\022legacy_closed_enum\030\001 \001(\010B\026\210"
"\001\001\230\001\004\230\001\001\242\001\n\022\005false\030\350\007::\n\003cpp\022\033.google.pr"
"otobuf.FeatureSet\030\350\007 \001(\0132\017.pb.CppFeature"
"s"
"\032 google/protobuf/descriptor.proto\"M\n\013Cp"
"pFeatures\022>\n\022legacy_closed_enum\030\001 \001(\010B\"\210"
"\001\001\230\001\004\230\001\001\242\001\t\022\004true\030\346\007\242\001\n\022\005false\030\347\007::\n\003cpp"
"\022\033.google.protobuf.FeatureSet\030\350\007 \001(\0132\017.p"
"b.CppFeatures"
};
static const ::_pbi::DescriptorTable* const descriptor_table_google_2fprotobuf_2fcpp_5ffeatures_2eproto_deps[1] =
{
@ -84,7 +84,7 @@ static ::absl::once_flag descriptor_table_google_2fprotobuf_2fcpp_5ffeatures_2ep
const ::_pbi::DescriptorTable descriptor_table_google_2fprotobuf_2fcpp_5ffeatures_2eproto = {
false,
false,
201,
213,
descriptor_table_protodef_google_2fprotobuf_2fcpp_5ffeatures_2eproto,
"google/protobuf/cpp_features.proto",
&descriptor_table_google_2fprotobuf_2fcpp_5ffeatures_2eproto_once,

@ -24,6 +24,7 @@ message CppFeatures {
retention = RETENTION_RUNTIME,
targets = TARGET_TYPE_FIELD,
targets = TARGET_TYPE_FILE,
edition_defaults = { edition: EDITION_2023, value: "false" }
edition_defaults = { edition: EDITION_PROTO2, value: "true" },
edition_defaults = { edition: EDITION_PROTO3, value: "false" }
];
}

@ -1838,70 +1838,72 @@ const char descriptor_table_protodef_google_2fprotobuf_2fdescriptor_2eproto[] PR
"e\030\005 \001(\003\022\024\n\014double_value\030\006 \001(\001\022\024\n\014string_"
"value\030\007 \001(\014\022\027\n\017aggregate_value\030\010 \001(\t\0323\n\010"
"NamePart\022\021\n\tname_part\030\001 \002(\t\022\024\n\014is_extens"
"ion\030\002 \002(\010\"\277\010\n\nFeatureSet\022\\\n\016field_presen"
"ion\030\002 \002(\010\"\251\t\n\nFeatureSet\022|\n\016field_presen"
"ce\030\001 \001(\0162).google.protobuf.FeatureSet.Fi"
"eldPresenceB\031\210\001\001\230\001\004\230\001\001\242\001\r\022\010EXPLICIT\030\350\007\022N"
"\n\tenum_type\030\002 \001(\0162$.google.protobuf.Feat"
"ureSet.EnumTypeB\025\210\001\001\230\001\006\230\001\001\242\001\t\022\004OPEN\030\350\007\022k"
"\n\027repeated_field_encoding\030\003 \001(\01621.google"
".protobuf.FeatureSet.RepeatedFieldEncodi"
"ngB\027\210\001\001\230\001\004\230\001\001\242\001\013\022\006PACKED\030\350\007\022\\\n\017utf8_vali"
"dation\030\004 \001(\0162*.google.protobuf.FeatureSe"
"t.Utf8ValidationB\027\210\001\001\230\001\004\230\001\001\242\001\013\022\006VERIFY\030\350"
"eldPresenceB9\210\001\001\230\001\004\230\001\001\242\001\r\022\010EXPLICIT\030\346\007\242\001"
"\r\022\010IMPLICIT\030\347\007\242\001\r\022\010EXPLICIT\030\350\007\022\\\n\tenum_t"
"ype\030\002 \001(\0162$.google.protobuf.FeatureSet.E"
"numTypeB#\210\001\001\230\001\006\230\001\001\242\001\013\022\006CLOSED\030\346\007\242\001\t\022\004OPE"
"N\030\347\007\022{\n\027repeated_field_encoding\030\003 \001(\01621."
"google.protobuf.FeatureSet.RepeatedField"
"EncodingB\'\210\001\001\230\001\004\230\001\001\242\001\r\022\010EXPANDED\030\346\007\242\001\013\022\006"
"PACKED\030\347\007\022n\n\017utf8_validation\030\004 \001(\0162*.goo"
"gle.protobuf.FeatureSet.Utf8ValidationB)"
"\210\001\001\230\001\004\230\001\001\242\001\017\022\nUNVERIFIED\030\346\007\242\001\013\022\006VERIFY\030\347"
"\007\022g\n\020message_encoding\030\005 \001(\0162+.google.pro"
"tobuf.FeatureSet.MessageEncodingB \210\001\001\230\001\004"
"\230\001\001\242\001\024\022\017LENGTH_PREFIXED\030\350\007\022V\n\013json_forma"
"\230\001\001\242\001\024\022\017LENGTH_PREFIXED\030\346\007\022p\n\013json_forma"
"t\030\006 \001(\0162&.google.protobuf.FeatureSet.Jso"
"nFormatB\031\210\001\001\230\001\003\230\001\006\230\001\001\242\001\n\022\005ALLOW\030\350\007\"\\\n\rFi"
"eldPresence\022\032\n\026FIELD_PRESENCE_UNKNOWN\020\000\022"
"\014\n\010EXPLICIT\020\001\022\014\n\010IMPLICIT\020\002\022\023\n\017LEGACY_RE"
"QUIRED\020\003\"7\n\010EnumType\022\025\n\021ENUM_TYPE_UNKNOW"
"N\020\000\022\010\n\004OPEN\020\001\022\n\n\006CLOSED\020\002\"V\n\025RepeatedFie"
"ldEncoding\022#\n\037REPEATED_FIELD_ENCODING_UN"
"KNOWN\020\000\022\n\n\006PACKED\020\001\022\014\n\010EXPANDED\020\002\"I\n\016Utf"
"8Validation\022\033\n\027UTF8_VALIDATION_UNKNOWN\020\000"
"\022\016\n\nUNVERIFIED\020\001\022\n\n\006VERIFY\020\002\"S\n\017MessageE"
"ncoding\022\034\n\030MESSAGE_ENCODING_UNKNOWN\020\000\022\023\n"
"\017LENGTH_PREFIXED\020\001\022\r\n\tDELIMITED\020\002\"H\n\nJso"
"nFormat\022\027\n\023JSON_FORMAT_UNKNOWN\020\000\022\t\n\005ALLO"
"W\020\001\022\026\n\022LEGACY_BEST_EFFORT\020\002*\006\010\350\007\020\351\007*\006\010\351\007"
"\020\352\007*\006\010\213N\020\220NJ\006\010\347\007\020\350\007\"\300\002\n\022FeatureSetDefaul"
"ts\022N\n\010defaults\030\001 \003(\0132<.google.protobuf.F"
"eatureSetDefaults.FeatureSetEditionDefau"
"lt\0221\n\017minimum_edition\030\004 \001(\0162\030.google.pro"
"tobuf.Edition\0221\n\017maximum_edition\030\005 \001(\0162\030"
".google.protobuf.Edition\032t\n\030FeatureSetEd"
"itionDefault\022)\n\007edition\030\003 \001(\0162\030.google.p"
"rotobuf.Edition\022-\n\010features\030\002 \001(\0132\033.goog"
"le.protobuf.FeatureSet\"\325\001\n\016SourceCodeInf"
"o\022:\n\010location\030\001 \003(\0132(.google.protobuf.So"
"urceCodeInfo.Location\032\206\001\n\010Location\022\020\n\004pa"
"th\030\001 \003(\005B\002\020\001\022\020\n\004span\030\002 \003(\005B\002\020\001\022\030\n\020leadin"
"g_comments\030\003 \001(\t\022\031\n\021trailing_comments\030\004 "
"\001(\t\022!\n\031leading_detached_comments\030\006 \003(\t\"\234"
"\002\n\021GeneratedCodeInfo\022A\n\nannotation\030\001 \003(\013"
"2-.google.protobuf.GeneratedCodeInfo.Ann"
"otation\032\303\001\n\nAnnotation\022\020\n\004path\030\001 \003(\005B\002\020\001"
"\022\023\n\013source_file\030\002 \001(\t\022\r\n\005begin\030\003 \001(\005\022\013\n\003"
"end\030\004 \001(\005\022H\n\010semantic\030\005 \001(\01626.google.pro"
"tobuf.GeneratedCodeInfo.Annotation.Seman"
"tic\"(\n\010Semantic\022\010\n\004NONE\020\000\022\007\n\003SET\020\001\022\t\n\005AL"
"IAS\020\002*\352\001\n\007Edition\022\023\n\017EDITION_UNKNOWN\020\000\022\023"
"\n\016EDITION_PROTO2\020\346\007\022\023\n\016EDITION_PROTO3\020\347\007"
"\022\021\n\014EDITION_2023\020\350\007\022\027\n\023EDITION_1_TEST_ON"
"LY\020\001\022\027\n\023EDITION_2_TEST_ONLY\020\002\022\035\n\027EDITION"
"_99997_TEST_ONLY\020\235\215\006\022\035\n\027EDITION_99998_TE"
"ST_ONLY\020\236\215\006\022\035\n\027EDITION_99999_TEST_ONLY\020\237"
"\215\006B~\n\023com.google.protobufB\020DescriptorPro"
"tosH\001Z-google.golang.org/protobuf/types/"
"descriptorpb\370\001\001\242\002\003GPB\252\002\032Google.Protobuf."
"Reflection"
"nFormatB3\210\001\001\230\001\003\230\001\006\230\001\001\242\001\027\022\022LEGACY_BEST_EF"
"FORT\030\346\007\242\001\n\022\005ALLOW\030\347\007\"\\\n\rFieldPresence\022\032\n"
"\026FIELD_PRESENCE_UNKNOWN\020\000\022\014\n\010EXPLICIT\020\001\022"
"\014\n\010IMPLICIT\020\002\022\023\n\017LEGACY_REQUIRED\020\003\"7\n\010En"
"umType\022\025\n\021ENUM_TYPE_UNKNOWN\020\000\022\010\n\004OPEN\020\001\022"
"\n\n\006CLOSED\020\002\"V\n\025RepeatedFieldEncoding\022#\n\037"
"REPEATED_FIELD_ENCODING_UNKNOWN\020\000\022\n\n\006PAC"
"KED\020\001\022\014\n\010EXPANDED\020\002\"I\n\016Utf8Validation\022\033\n"
"\027UTF8_VALIDATION_UNKNOWN\020\000\022\016\n\nUNVERIFIED"
"\020\001\022\n\n\006VERIFY\020\002\"S\n\017MessageEncoding\022\034\n\030MES"
"SAGE_ENCODING_UNKNOWN\020\000\022\023\n\017LENGTH_PREFIX"
"ED\020\001\022\r\n\tDELIMITED\020\002\"H\n\nJsonFormat\022\027\n\023JSO"
"N_FORMAT_UNKNOWN\020\000\022\t\n\005ALLOW\020\001\022\026\n\022LEGACY_"
"BEST_EFFORT\020\002*\006\010\350\007\020\351\007*\006\010\351\007\020\352\007*\006\010\213N\020\220NJ\006\010"
"\347\007\020\350\007\"\300\002\n\022FeatureSetDefaults\022N\n\010defaults"
"\030\001 \003(\0132<.google.protobuf.FeatureSetDefau"
"lts.FeatureSetEditionDefault\0221\n\017minimum_"
"edition\030\004 \001(\0162\030.google.protobuf.Edition\022"
"1\n\017maximum_edition\030\005 \001(\0162\030.google.protob"
"uf.Edition\032t\n\030FeatureSetEditionDefault\022)"
"\n\007edition\030\003 \001(\0162\030.google.protobuf.Editio"
"n\022-\n\010features\030\002 \001(\0132\033.google.protobuf.Fe"
"atureSet\"\325\001\n\016SourceCodeInfo\022:\n\010location\030"
"\001 \003(\0132(.google.protobuf.SourceCodeInfo.L"
"ocation\032\206\001\n\010Location\022\020\n\004path\030\001 \003(\005B\002\020\001\022\020"
"\n\004span\030\002 \003(\005B\002\020\001\022\030\n\020leading_comments\030\003 \001"
"(\t\022\031\n\021trailing_comments\030\004 \001(\t\022!\n\031leading"
"_detached_comments\030\006 \003(\t\"\234\002\n\021GeneratedCo"
"deInfo\022A\n\nannotation\030\001 \003(\0132-.google.prot"
"obuf.GeneratedCodeInfo.Annotation\032\303\001\n\nAn"
"notation\022\020\n\004path\030\001 \003(\005B\002\020\001\022\023\n\013source_fil"
"e\030\002 \001(\t\022\r\n\005begin\030\003 \001(\005\022\013\n\003end\030\004 \001(\005\022H\n\010s"
"emantic\030\005 \001(\01626.google.protobuf.Generate"
"dCodeInfo.Annotation.Semantic\"(\n\010Semanti"
"c\022\010\n\004NONE\020\000\022\007\n\003SET\020\001\022\t\n\005ALIAS\020\002*\352\001\n\007Edit"
"ion\022\023\n\017EDITION_UNKNOWN\020\000\022\023\n\016EDITION_PROT"
"O2\020\346\007\022\023\n\016EDITION_PROTO3\020\347\007\022\021\n\014EDITION_20"
"23\020\350\007\022\027\n\023EDITION_1_TEST_ONLY\020\001\022\027\n\023EDITIO"
"N_2_TEST_ONLY\020\002\022\035\n\027EDITION_99997_TEST_ON"
"LY\020\235\215\006\022\035\n\027EDITION_99998_TEST_ONLY\020\236\215\006\022\035\n"
"\027EDITION_99999_TEST_ONLY\020\237\215\006B~\n\023com.goog"
"le.protobufB\020DescriptorProtosH\001Z-google."
"golang.org/protobuf/types/descriptorpb\370\001"
"\001\242\002\003GPB\252\002\032Google.Protobuf.Reflection"
};
static ::absl::once_flag descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once;
const ::_pbi::DescriptorTable descriptor_table_google_2fprotobuf_2fdescriptor_2eproto = {
false,
false,
9450,
9556,
descriptor_table_protodef_google_2fprotobuf_2fdescriptor_2eproto,
"google/protobuf/descriptor.proto",
&descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once,

@ -935,6 +935,8 @@ message FeatureSet {
retention = RETENTION_RUNTIME,
targets = TARGET_TYPE_FIELD,
targets = TARGET_TYPE_FILE,
edition_defaults = { edition: EDITION_PROTO2, value: "EXPLICIT" },
edition_defaults = { edition: EDITION_PROTO3, value: "IMPLICIT" },
edition_defaults = { edition: EDITION_2023, value: "EXPLICIT" }
];
@ -947,7 +949,8 @@ message FeatureSet {
retention = RETENTION_RUNTIME,
targets = TARGET_TYPE_ENUM,
targets = TARGET_TYPE_FILE,
edition_defaults = { edition: EDITION_2023, value: "OPEN" }
edition_defaults = { edition: EDITION_PROTO2, value: "CLOSED" },
edition_defaults = { edition: EDITION_PROTO3, value: "OPEN" }
];
enum RepeatedFieldEncoding {
@ -959,7 +962,8 @@ message FeatureSet {
retention = RETENTION_RUNTIME,
targets = TARGET_TYPE_FIELD,
targets = TARGET_TYPE_FILE,
edition_defaults = { edition: EDITION_2023, value: "PACKED" }
edition_defaults = { edition: EDITION_PROTO2, value: "EXPANDED" },
edition_defaults = { edition: EDITION_PROTO3, value: "PACKED" }
];
enum Utf8Validation {
@ -971,7 +975,8 @@ message FeatureSet {
retention = RETENTION_RUNTIME,
targets = TARGET_TYPE_FIELD,
targets = TARGET_TYPE_FILE,
edition_defaults = { edition: EDITION_2023, value: "VERIFY" }
edition_defaults = { edition: EDITION_PROTO2, value: "UNVERIFIED" },
edition_defaults = { edition: EDITION_PROTO3, value: "VERIFY" }
];
enum MessageEncoding {
@ -983,7 +988,7 @@ message FeatureSet {
retention = RETENTION_RUNTIME,
targets = TARGET_TYPE_FIELD,
targets = TARGET_TYPE_FILE,
edition_defaults = { edition: EDITION_2023, value: "LENGTH_PREFIXED" }
edition_defaults = { edition: EDITION_PROTO2, value: "LENGTH_PREFIXED" }
];
enum JsonFormat {
@ -996,7 +1001,8 @@ message FeatureSet {
targets = TARGET_TYPE_MESSAGE,
targets = TARGET_TYPE_ENUM,
targets = TARGET_TYPE_FILE,
edition_defaults = { edition: EDITION_2023, value: "ALLOW" }
edition_defaults = { edition: EDITION_PROTO2, value: "LEGACY_BEST_EFFORT" },
edition_defaults = { edition: EDITION_PROTO3, value: "ALLOW" }
];
reserved 999;

@ -216,9 +216,9 @@ TEST(FeatureResolverTest, DefaultsGeneratedPoolCustom) {
pool.FindMessageTypeByName("google.protobuf.FeatureSet"),
{pool.FindExtensionByName("pb.test")}, EDITION_2023, EDITION_2023);
ASSERT_OK(defaults);
ASSERT_EQ(defaults->defaults().size(), 1);
ASSERT_EQ(defaults->defaults().at(0).edition(), EDITION_2023);
FeatureSet merged = defaults->defaults().at(0).features();
ASSERT_EQ(defaults->defaults().size(), 3);
ASSERT_EQ(defaults->defaults().at(2).edition(), EDITION_2023);
FeatureSet merged = defaults->defaults().at(2).features();
EXPECT_EQ(merged.field_presence(), FeatureSet::EXPLICIT);
EXPECT_TRUE(merged.HasExtension(pb::test));
@ -778,7 +778,7 @@ TEST_F(FeatureResolverPoolTest,
}
optional MessageFeature message_field_feature = 12 [
targets = TARGET_TYPE_FIELD,
edition_defaults = { edition: EDITION_2023, value: "9987" }
edition_defaults = { edition: EDITION_PROTO2, value: "9987" }
];
}
)schema");
@ -809,6 +809,7 @@ TEST_F(FeatureResolverPoolTest,
targets = TARGET_TYPE_FIELD,
edition_defaults = { edition: EDITION_99998_TEST_ONLY, value: "int_field: 2" },
edition_defaults = { edition: EDITION_99997_TEST_ONLY, value: "int_field: 1" },
edition_defaults = { edition: EDITION_PROTO2, value: "" },
edition_defaults = { edition: EDITION_2023, value: "9987" }
];
}
@ -840,7 +841,8 @@ TEST_F(FeatureResolverPoolTest,
targets = TARGET_TYPE_FIELD,
edition_defaults = { edition: EDITION_99997_TEST_ONLY, value: "int_field: 2" },
edition_defaults = { edition: EDITION_2023, value: "int_field: 1" },
edition_defaults = { edition: EDITION_99998_TEST_ONLY, value: "9987" }
edition_defaults = { edition: EDITION_99998_TEST_ONLY, value: "9987" },
edition_defaults = { edition: EDITION_PROTO2, value: "" }
];
}
)schema");
@ -870,7 +872,7 @@ TEST_F(FeatureResolverPoolTest,
message Foo {
optional int32 int_field_feature = 12 [
targets = TARGET_TYPE_FIELD,
edition_defaults = { edition: EDITION_2023, value: "1.23" }
edition_defaults = { edition: EDITION_PROTO2, value: "1.23" }
];
}
)schema");
@ -897,7 +899,7 @@ TEST_F(FeatureResolverPoolTest,
optional int32 int_field_feature = 12 [
targets = TARGET_TYPE_FIELD,
edition_defaults = { edition: EDITION_99997_TEST_ONLY, value: "1.5" },
edition_defaults = { edition: EDITION_2023, value: "1" }
edition_defaults = { edition: EDITION_PROTO2, value: "1" }
];
}
)schema");
@ -951,7 +953,7 @@ TEST_F(FeatureResolverPoolTest, CompileDefaultsMinimumTooEarly) {
message Foo {
optional int32 int_field_feature = 12 [
targets = TARGET_TYPE_FIELD,
edition_defaults = { edition: EDITION_2023, value: "1" }
edition_defaults = { edition: EDITION_PROTO2, value: "1" }
];
}
)schema");
@ -977,7 +979,8 @@ TEST_F(FeatureResolverPoolTest, CompileDefaultsMinimumCovered) {
optional int32 int_file_feature = 1 [
targets = TARGET_TYPE_FIELD,
edition_defaults = { edition: EDITION_99998_TEST_ONLY, value: "2" },
edition_defaults = { edition: EDITION_2023, value: "1" }
edition_defaults = { edition: EDITION_2023, value: "1" },
edition_defaults = { edition: EDITION_PROTO2, value: "0" }
];
}
)schema");
@ -991,6 +994,30 @@ TEST_F(FeatureResolverPoolTest, CompileDefaultsMinimumCovered) {
EXPECT_THAT(*defaults, EqualsProto(R"pb(
minimum_edition: EDITION_99997_TEST_ONLY
maximum_edition: EDITION_99999_TEST_ONLY
defaults {
edition: EDITION_PROTO2
features {
field_presence: EXPLICIT
enum_type: CLOSED
repeated_field_encoding: EXPANDED
utf8_validation: UNVERIFIED
message_encoding: LENGTH_PREFIXED
json_format: LEGACY_BEST_EFFORT
[pb.test] { int_file_feature: 0 }
}
}
defaults {
edition: EDITION_PROTO3
features {
field_presence: IMPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
[pb.test] { int_file_feature: 0 }
}
}
defaults {
edition: EDITION_2023
features {

@ -30,6 +30,7 @@ message TestFeatures {
optional int32 int_file_feature = 1 [
retention = RETENTION_RUNTIME,
targets = TARGET_TYPE_FILE,
edition_defaults = { edition: EDITION_PROTO2, value: "0" },
edition_defaults = { edition: EDITION_2023, value: "1" },
edition_defaults = { edition: EDITION_99997_TEST_ONLY, value: "2" },
edition_defaults = { edition: EDITION_99998_TEST_ONLY, value: "3" }
@ -37,42 +38,42 @@ message TestFeatures {
optional int32 int_extension_range_feature = 2 [
retention = RETENTION_RUNTIME,
targets = TARGET_TYPE_EXTENSION_RANGE,
edition_defaults = { edition: EDITION_2023, value: "1" }
edition_defaults = { edition: EDITION_PROTO2, value: "1" }
];
optional int32 int_message_feature = 3 [
retention = RETENTION_RUNTIME,
targets = TARGET_TYPE_MESSAGE,
edition_defaults = { edition: EDITION_2023, value: "1" }
edition_defaults = { edition: EDITION_PROTO2, value: "1" }
];
optional int32 int_field_feature = 4 [
retention = RETENTION_RUNTIME,
targets = TARGET_TYPE_FIELD,
edition_defaults = { edition: EDITION_2023, value: "1" }
edition_defaults = { edition: EDITION_PROTO2, value: "1" }
];
optional int32 int_oneof_feature = 5 [
retention = RETENTION_RUNTIME,
targets = TARGET_TYPE_ONEOF,
edition_defaults = { edition: EDITION_2023, value: "1" }
edition_defaults = { edition: EDITION_PROTO2, value: "1" }
];
optional int32 int_enum_feature = 6 [
retention = RETENTION_RUNTIME,
targets = TARGET_TYPE_ENUM,
edition_defaults = { edition: EDITION_2023, value: "1" }
edition_defaults = { edition: EDITION_PROTO2, value: "1" }
];
optional int32 int_enum_entry_feature = 7 [
retention = RETENTION_RUNTIME,
targets = TARGET_TYPE_ENUM_ENTRY,
edition_defaults = { edition: EDITION_2023, value: "1" }
edition_defaults = { edition: EDITION_PROTO2, value: "1" }
];
optional int32 int_service_feature = 8 [
retention = RETENTION_RUNTIME,
targets = TARGET_TYPE_SERVICE,
edition_defaults = { edition: EDITION_2023, value: "1" }
edition_defaults = { edition: EDITION_PROTO2, value: "1" }
];
optional int32 int_method_feature = 9 [
retention = RETENTION_RUNTIME,
targets = TARGET_TYPE_METHOD,
edition_defaults = { edition: EDITION_2023, value: "1" }
edition_defaults = { edition: EDITION_PROTO2, value: "1" }
];
optional int32 int_multiple_feature = 10 [
retention = RETENTION_RUNTIME,
@ -85,19 +86,19 @@ message TestFeatures {
targets = TARGET_TYPE_METHOD,
targets = TARGET_TYPE_ONEOF,
targets = TARGET_TYPE_EXTENSION_RANGE,
edition_defaults = { edition: EDITION_2023, value: "1" }
edition_defaults = { edition: EDITION_PROTO2, value: "1" }
];
optional bool bool_field_feature = 11 [
retention = RETENTION_RUNTIME,
targets = TARGET_TYPE_FIELD,
edition_defaults = { edition: EDITION_2023, value: "false" },
edition_defaults = { edition: EDITION_PROTO2, value: "false" },
edition_defaults = { edition: EDITION_99997_TEST_ONLY, value: "true" }
];
optional float float_field_feature = 12 [
retention = RETENTION_RUNTIME,
targets = TARGET_TYPE_FIELD,
edition_defaults = { edition: EDITION_2023, value: "1.1" },
edition_defaults = { edition: EDITION_PROTO2, value: "1.1" },
edition_defaults = { edition: EDITION_99997_TEST_ONLY, value: "1.2" }
];
@ -121,7 +122,8 @@ message TestFeatures {
edition_defaults = {
edition: EDITION_2023,
value: "bool_field: true int_field: 1 float_field: 1.5 string_field: '2023'"
}
},
edition_defaults = { edition: EDITION_PROTO2, value: "" }
];
enum EnumFeature {
@ -135,6 +137,10 @@ message TestFeatures {
optional EnumFeature enum_field_feature = 14 [
retention = RETENTION_RUNTIME,
targets = TARGET_TYPE_FIELD,
edition_defaults = {
edition: EDITION_PROTO2,
value: "TEST_ENUM_FEATURE_UNKNOWN"
},
edition_defaults = { edition: EDITION_2023, value: "ENUM_VALUE1" },
edition_defaults = {
edition: EDITION_99997_TEST_ONLY,
@ -157,7 +163,7 @@ message TestFeatures {
targets = TARGET_TYPE_METHOD,
targets = TARGET_TYPE_ONEOF,
targets = TARGET_TYPE_EXTENSION_RANGE,
edition_defaults = { edition: EDITION_2023, value: "1" }
edition_defaults = { edition: EDITION_PROTO2, value: "1" }
];
optional string string_source_feature = 16 [
@ -171,6 +177,6 @@ message TestFeatures {
targets = TARGET_TYPE_METHOD,
targets = TARGET_TYPE_ONEOF,
targets = TARGET_TYPE_EXTENSION_RANGE,
edition_defaults = { edition: EDITION_2023, value: "'2023'" }
edition_defaults = { edition: EDITION_PROTO2, value: "'2023'" }
];
}

Loading…
Cancel
Save