[ObjC] Enable generation of .proto files using editions.

PiperOrigin-RevId: 559119403
pull/13280/head
Thomas Van Lenten 2 years ago committed by Copybara-Service
parent 68f9d84079
commit 55ab8316c1
  1. 32
      src/google/protobuf/compiler/objectivec/file.cc
  2. 13
      src/google/protobuf/compiler/objectivec/generator.cc
  3. 2
      src/google/protobuf/compiler/objectivec/generator.h
  4. 2
      src/google/protobuf/compiler/objectivec/options.h

@ -734,19 +734,25 @@ void FileGenerator::EmitFileDescription(io::Printer* p) const {
const std::string objc_prefix(FileClassPrefix(file_));
std::string syntax;
switch (FileDescriptorLegacy(file_).syntax()) {
case FileDescriptorLegacy::Syntax::SYNTAX_UNKNOWN:
syntax = "GPBFileSyntaxUnknown";
break;
case FileDescriptorLegacy::Syntax::SYNTAX_PROTO2:
syntax = "GPBFileSyntaxProto2";
break;
case FileDescriptorLegacy::Syntax::SYNTAX_PROTO3:
syntax = "GPBFileSyntaxProto3";
break;
case FileDescriptorLegacy::Syntax::SYNTAX_EDITIONS:
syntax = "GPBFileSyntaxProtoEditions";
break;
if (generation_options_.experimental_strip_nonfunctional_codegen) {
// Doesn't matter for current sources, use Unknown as a marker for this
// mode.
syntax = "GPBFileSyntaxUnknown";
} else {
switch (FileDescriptorLegacy(file_).syntax()) {
case FileDescriptorLegacy::Syntax::SYNTAX_UNKNOWN:
syntax = "GPBFileSyntaxUnknown";
break;
case FileDescriptorLegacy::Syntax::SYNTAX_PROTO2:
syntax = "GPBFileSyntaxProto2";
break;
case FileDescriptorLegacy::Syntax::SYNTAX_PROTO3:
syntax = "GPBFileSyntaxProto3";
break;
case FileDescriptorLegacy::Syntax::SYNTAX_EDITIONS:
syntax = "GPBFileSyntaxProtoEditions";
break;
}
}
p->Emit({{"file_description_name", file_description_name_},

@ -302,6 +302,16 @@ bool ObjectiveCGenerator::GenerateAll(
options[i].second);
return false;
}
} else if (options[i].first == "experimental_strip_nonfunctional_codegen") {
if (!StringToBool(
options[i].second,
&generation_options.experimental_strip_nonfunctional_codegen)) {
*error = absl::StrCat(
"error: Unknown value for "
"experimental_strip_nonfunctional_codegen: ",
options[i].second);
return false;
}
} else {
*error =
absl::StrCat("error: Unknown generator option: ", options[i].first);
@ -314,6 +324,9 @@ bool ObjectiveCGenerator::GenerateAll(
if (generation_options.experimental_multi_source_generation) {
generation_options.headers_use_forward_declarations = false;
}
if (generation_options.experimental_strip_nonfunctional_codegen) {
generation_options.generate_minimal_imports = true;
}
// -----------------------------------------------------------------

@ -69,7 +69,7 @@ class PROTOC_EXPORT ObjectiveCGenerator : public CodeGenerator {
std::string* error) const override;
uint64_t GetSupportedFeatures() const override {
return FEATURE_PROTO3_OPTIONAL;
return (FEATURE_PROTO3_OPTIONAL | FEATURE_SUPPORTS_EDITIONS);
}
};

@ -52,6 +52,8 @@ struct GenerationOptions {
// TODO(thomasvl): Eventually flip this default to true.
bool generate_minimal_imports = false;
bool experimental_multi_source_generation = false;
// This is used by some of the protobuf infrastructure.
bool experimental_strip_nonfunctional_codegen = false;
};
} // namespace objectivec

Loading…
Cancel
Save