Add support for option retention in PHP

PiperOrigin-RevId: 528842376
pull/12603/head
Adam Cozzette 2 years ago committed by Copybara-Service
parent 99529a2209
commit ba348e2b3b
  1. 10
      src/google/protobuf/compiler/php/BUILD.bazel
  2. 8
      src/google/protobuf/compiler/php/php_generator.cc

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

@ -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<std::string>* 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<std::string>* dependency =
@ -2192,8 +2193,7 @@ void GenerateCWellKnownTypes(const std::vector<const FileDescriptor*>& 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(

Loading…
Cancel
Save