Implement option retention for C#

PiperOrigin-RevId: 528023935
pull/10781/head
Adam Cozzette 2 years ago committed by Copybara-Service
parent 1c05447e46
commit 5f64444e7b
  1. 10
      src/google/protobuf/compiler/csharp/BUILD.bazel
  2. 4
      src/google/protobuf/compiler/csharp/csharp_helpers.cc
  3. 1
      src/google/protobuf/unittest_retention.proto

@ -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([
srcs = glob(
[
"*_test.cc",
"*unittest.cc",
], allow_empty = True),
],
allow_empty = True,
),
visibility = ["//src/google/protobuf/compiler:__pkg__"],
)

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

@ -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 {

Loading…
Cancel
Save