Internal changes

PiperOrigin-RevId: 573005248
pull/14366/head
Mike Kruskal 1 year ago committed by Copybara-Service
parent 58722b10c9
commit c0004a8fb1
  1. 8
      src/google/protobuf/compiler/code_generator.cc
  2. 3
      src/google/protobuf/compiler/code_generator.h
  3. 3
      src/google/protobuf/compiler/cpp/file.cc
  4. 2
      src/google/protobuf/editions/BUILD
  5. 13
      src/google/protobuf/editions/golden/editions_transform_proto2.proto
  6. 5
      src/google/protobuf/editions/golden/editions_transform_proto3.proto
  7. 7
      src/google/protobuf/editions/proto/editions_transform_proto2.proto
  8. 5
      src/google/protobuf/editions/proto/editions_transform_proto3.proto

@ -120,6 +120,14 @@ std::string StripProto(absl::string_view filename) {
}
}
bool IsKnownFeatureProto(absl::string_view filename) {
if (filename == "google/protobuf/cpp_features.proto" ||
filename == "google/protobuf/java_features.proto") {
return true;
}
return false;
}
} // namespace compiler
} // namespace protobuf
} // namespace google

@ -230,6 +230,9 @@ PROTOC_EXPORT void ParseGeneratorParameter(
// Strips ".proto" or ".protodevel" from the end of a filename.
PROTOC_EXPORT std::string StripProto(absl::string_view filename);
// Returns true if the proto path corresponds to a known feature file.
PROTOC_EXPORT bool IsKnownFeatureProto(absl::string_view filename);
} // namespace compiler
} // namespace protobuf
} // namespace google

@ -29,6 +29,7 @@
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "absl/strings/strip.h"
#include "google/protobuf/compiler/code_generator.h"
#include "google/protobuf/compiler/cpp/enum.h"
#include "google/protobuf/compiler/cpp/extension.h"
#include "google/protobuf/compiler/cpp/helpers.h"
@ -247,7 +248,7 @@ bool FileGenerator::ShouldSkipDependencyImports(
// Skip feature imports, which are a visible (but non-functional) deviation
// between editions and legacy syntax.
if (options_.strip_nonfunctional_codegen &&
dep->name() == "third_party/protobuf/cpp_features.proto") {
IsKnownFeatureProto(dep->name())) {
return true;
}

@ -5,7 +5,6 @@ proto_library(
testonly = True,
srcs = ["golden/test_messages_proto2.proto"],
strip_import_prefix = "/src",
deps = ["//src/google/protobuf:cpp_features_proto"],
)
cc_proto_library(
@ -26,7 +25,6 @@ proto_library(
"//:struct_proto",
"//:timestamp_proto",
"//:wrappers_proto",
"//src/google/protobuf:cpp_features_proto",
],
)

@ -14,6 +14,10 @@ edition = "2023";
package protobuf_editions_test;
import "third_party/java_src/protobuf/current/java/com/google/protobuf/java_features.proto";
import "google/protobuf/cpp_features.proto";
import "google/protobuf/editions/proto/editions_transform_proto3.proto";
option features.enum_type = CLOSED;
option features.repeated_field_encoding = EXPANDED;
option features.utf8_validation = UNVERIFIED;
@ -113,3 +117,12 @@ enum TestEnum {
BAZ = 3;
NEG = -1; // Intentionally negative.
}
message TestOpenEnumMessage {
TestEnumProto3 open_enum_field = 1 [
features.(pb.cpp).legacy_closed_enum = true,
features.(pb.java).legacy_closed_enum = true
];
TestEnum closed_enum_field = 2;
}

@ -11,6 +11,11 @@ package protobuf_editions_test;
option features.field_presence = IMPLICIT;
enum TestEnumProto3 {
TEST_ENUM_PROTO3_UNKNOWN = 0;
TEST_ENUM_PROTO3_VALUE = 1;
}
message TestMessageProto3 {
string string_field = 1;
map<string, string> string_map_field = 4;

@ -7,6 +7,8 @@
syntax = "proto2";
import "google/protobuf/editions/proto/editions_transform_proto3.proto";
// This file contains various edge cases we've collected from migrating real
// protos in order to lock down the transformations.
@ -82,3 +84,8 @@ enum TestEnum {
BAZ = 3;
NEG = -1; // Intentionally negative.
}
message TestOpenEnumMessage {
optional TestEnumProto3 open_enum_field = 1;
optional TestEnum closed_enum_field = 2;
}

@ -9,6 +9,11 @@ syntax = "proto3";
package protobuf_editions_test;
enum TestEnumProto3 {
TEST_ENUM_PROTO3_UNKNOWN = 0;
TEST_ENUM_PROTO3_VALUE = 1;
}
message TestMessageProto3 {
string string_field = 1;

Loading…
Cancel
Save