Skip to content

Commit

Permalink
Add support for option retention in PHP
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 528842376
  • Loading branch information
acozzette authored and copybara-github committed May 2, 2023
1 parent 99529a2 commit ba348e2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
14 changes: 9 additions & 5 deletions src/google/protobuf/compiler/php/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/php",
visibility = ["//visibility:public"],
Expand All @@ -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",
],
)
Expand All @@ -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__"],
)
8 changes: 4 additions & 4 deletions src/google/protobuf/compiler/php/php_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit ba348e2

Please sign in to comment.