Skip to content

Commit

Permalink
Implement option retention for C#
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 528023935
  • Loading branch information
acozzette authored and copybara-github committed Apr 29, 2023
1 parent 1c05447 commit 5f64444
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
14 changes: 9 additions & 5 deletions src/google/protobuf/compiler/csharp/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -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",
],
Expand Down Expand Up @@ -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__"],
)
4 changes: 2 additions & 2 deletions src/google/protobuf/compiler/csharp/csharp_helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions src/google/protobuf/unittest_retention.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 5f64444

Please sign in to comment.