From 5f64444e7b19421c25ae12d3c69acbab3a70a1bb Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Fri, 28 Apr 2023 17:19:14 -0700 Subject: [PATCH] Implement option retention for C# PiperOrigin-RevId: 528023935 --- src/google/protobuf/compiler/csharp/BUILD.bazel | 14 +++++++++----- .../protobuf/compiler/csharp/csharp_helpers.cc | 4 ++-- src/google/protobuf/unittest_retention.proto | 1 + 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/google/protobuf/compiler/csharp/BUILD.bazel b/src/google/protobuf/compiler/csharp/BUILD.bazel index 96b8dcbc0eee..414dd0ffd6d0 100644 --- a/src/google/protobuf/compiler/csharp/BUILD.bazel +++ b/src/google/protobuf/compiler/csharp/BUILD.bazel @@ -8,8 +8,8 @@ load("//build_defs:cpp_opts.bzl", "COPTS") cc_library( name = "names", - hdrs = ["names.h"], srcs = ["names.cc"], + hdrs = ["names.h"], copts = COPTS, include_prefix = "google/protobuf/compiler/csharp", visibility = ["//visibility:public"], @@ -71,6 +71,7 @@ cc_library( ":names", "//src/google/protobuf:protobuf_nowkt", "//src/google/protobuf/compiler:code_generator", + "//src/google/protobuf/compiler:retention", "@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/strings", ], @@ -125,9 +126,12 @@ pkg_files( filegroup( name = "test_srcs", - srcs = glob([ - "*_test.cc", - "*unittest.cc", - ], allow_empty = True), + srcs = glob( + [ + "*_test.cc", + "*unittest.cc", + ], + allow_empty = True, + ), visibility = ["//src/google/protobuf/compiler:__pkg__"], ) diff --git a/src/google/protobuf/compiler/csharp/csharp_helpers.cc b/src/google/protobuf/compiler/csharp/csharp_helpers.cc index a08c1be0841b..2db328bc77cf 100644 --- a/src/google/protobuf/compiler/csharp/csharp_helpers.cc +++ b/src/google/protobuf/compiler/csharp/csharp_helpers.cc @@ -56,6 +56,7 @@ #include "google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h" #include "google/protobuf/compiler/csharp/csharp_wrapper_field.h" #include "google/protobuf/compiler/csharp/names.h" +#include "google/protobuf/compiler/retention.h" #include "google/protobuf/descriptor.pb.h" // Must be last. @@ -380,8 +381,7 @@ std::string StringToBase64(absl::string_view input) { std::string FileDescriptorToBase64(const FileDescriptor* descriptor) { std::string fdp_bytes; - FileDescriptorProto fdp; - descriptor->CopyTo(&fdp); + FileDescriptorProto fdp = StripSourceRetentionOptions(*descriptor); fdp.SerializeToString(&fdp_bytes); return StringToBase64(fdp_bytes); } diff --git a/src/google/protobuf/unittest_retention.proto b/src/google/protobuf/unittest_retention.proto index e157bc452ea0..643cc359829e 100644 --- a/src/google/protobuf/unittest_retention.proto +++ b/src/google/protobuf/unittest_retention.proto @@ -34,6 +34,7 @@ package protobuf_unittest; import "google/protobuf/descriptor.proto"; +option csharp_namespace = "ProtobufUnittest"; // Retention attributes set directly on custom options extend google.protobuf.FileOptions {