Skip to content

Commit 2dc5338

Browse files
Introduce proto filter for inject_field_listener_events.
By default all protos are included in proto instrumentation when inject_field_listener_events option is set. Adding proto instrumentation callbacks for every proto in the binary adds codesize and runtime performance penalties. This cl introduces 'protos_for_field_listener_events' option where a list of proto files can be provided (seperated by ':') for which field listener events will be injected. For example :- protos_for_field_listener_events=foo/bar/foo.proto:foo/bar.proto The field listener event will only be sent for 'foo/bar/foo.proto' and 'foo/bar.proto'. PiperOrigin-RevId: 512905094
1 parent 462964e commit 2dc5338

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/google/protobuf/compiler/cpp/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ cc_library(
8585
":names",
8686
":names_internal",
8787
"//src/google/protobuf/compiler:code_generator",
88+
"//src/google/protobuf/compiler:command_line_interface",
8889
"//src/google/protobuf/compiler:retention",
8990
"@com_google_absl//absl/base:core_headers",
9091
"@com_google_absl//absl/container:btree",

src/google/protobuf/compiler/cpp/generator.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "absl/strings/match.h"
4444
#include "absl/strings/str_cat.h"
4545
#include "absl/strings/string_view.h"
46+
#include "google/protobuf/compiler/command_line_interface.h"
4647
#include "google/protobuf/compiler/cpp/file.h"
4748
#include "google/protobuf/compiler/cpp/helpers.h"
4849
#include "google/protobuf/descriptor.pb.h"
@@ -161,6 +162,15 @@ bool CppGenerator::Generate(const FileDescriptor* file,
161162
} else if (key == "proto_static_reflection_h") {
162163
} else if (key == "annotate_accessor") {
163164
file_options.annotate_accessor = true;
165+
} else if (key == "protos_for_field_listener_events") {
166+
for (absl::string_view proto :
167+
absl::StrSplit(value, CommandLineInterface::kPathSeparator)) {
168+
if (proto == file->name()) {
169+
file_options.field_listener_options.inject_field_listener_events =
170+
true;
171+
break;
172+
}
173+
}
164174
} else if (key == "inject_field_listener_events") {
165175
file_options.field_listener_options.inject_field_listener_events = true;
166176
} else if (key == "forbidden_field_listener_events") {

0 commit comments

Comments
 (0)