From ba348e2b3bf30f3d6f6c356020ac6999ddcf13b0 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Tue, 2 May 2023 11:32:29 -0700 Subject: [PATCH] Add support for option retention in PHP PiperOrigin-RevId: 528842376 --- src/google/protobuf/compiler/php/BUILD.bazel | 14 +++++++++----- src/google/protobuf/compiler/php/php_generator.cc | 8 ++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/google/protobuf/compiler/php/BUILD.bazel b/src/google/protobuf/compiler/php/BUILD.bazel index fe9e75c2c5..f814a03a74 100644 --- a/src/google/protobuf/compiler/php/BUILD.bazel +++ b/src/google/protobuf/compiler/php/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/php", visibility = ["//visibility:public"], @@ -35,6 +35,7 @@ cc_library( "//src/google/protobuf:descriptor_legacy", "//src/google/protobuf:protobuf_nowkt", "//src/google/protobuf/compiler:code_generator", + "//src/google/protobuf/compiler:retention", "@com_google_absl//absl/strings", ], ) @@ -52,9 +53,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/php/php_generator.cc b/src/google/protobuf/compiler/php/php_generator.cc index 392ca368d8..fca9c3826d 100644 --- a/src/google/protobuf/compiler/php/php_generator.cc +++ b/src/google/protobuf/compiler/php/php_generator.cc @@ -45,6 +45,7 @@ #include "absl/strings/str_replace.h" #include "absl/strings/str_split.h" #include "absl/strings/string_view.h" +#include "google/protobuf/compiler/retention.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.pb.h" #include "google/protobuf/descriptor_legacy.h" @@ -943,7 +944,7 @@ void GenerateAddFileToPool(const FileDescriptor* file, const Options& options, // Add messages and enums to descriptor pool. FileDescriptorSet files; FileDescriptorProto* file_proto = files.add_file(); - file->CopyTo(file_proto); + *file_proto = StripSourceRetentionOptions(*file); // Filter out descriptor.proto as it cannot be depended on for now. RepeatedPtrField* dependency = @@ -1086,7 +1087,7 @@ void GenerateAddFilesToPool(const FileDescriptor* file, const Options& options, if (needs_aggregate) { auto file_proto = sorted_file_set.add_file(); - file_node->CopyTo(file_proto); + *file_proto = StripSourceRetentionOptions(*file_node); // Filter out descriptor.proto as it cannot be depended on for now. RepeatedPtrField* dependency = @@ -2192,8 +2193,7 @@ void GenerateCWellKnownTypes(const std::vector& files, absl::StrReplaceAll(metadata_classname, {{"\\", "_"}}); metadata_classname = absl::StrReplaceAll(metadata_classname, {{"\\", "\\\\"}}); - FileDescriptorProto file_proto; - file->CopyTo(&file_proto); + FileDescriptorProto file_proto = StripSourceRetentionOptions(*file); std::string serialized; file_proto.SerializeToString(&serialized); printer.Print(