Skip to content

Commit

Permalink
Introduce proto filter for inject_field_listener_events.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Feb 28, 2023
1 parent 462964e commit 2dc5338
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/google/protobuf/compiler/cpp/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ cc_library(
":names",
":names_internal",
"//src/google/protobuf/compiler:code_generator",
"//src/google/protobuf/compiler:command_line_interface",
"//src/google/protobuf/compiler:retention",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/container:btree",
Expand Down
10 changes: 10 additions & 0 deletions src/google/protobuf/compiler/cpp/generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "absl/strings/match.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "google/protobuf/compiler/command_line_interface.h"
#include "google/protobuf/compiler/cpp/file.h"
#include "google/protobuf/compiler/cpp/helpers.h"
#include "google/protobuf/descriptor.pb.h"
Expand Down Expand Up @@ -161,6 +162,15 @@ bool CppGenerator::Generate(const FileDescriptor* file,
} else if (key == "proto_static_reflection_h") {
} else if (key == "annotate_accessor") {
file_options.annotate_accessor = true;
} else if (key == "protos_for_field_listener_events") {
for (absl::string_view proto :
absl::StrSplit(value, CommandLineInterface::kPathSeparator)) {
if (proto == file->name()) {
file_options.field_listener_options.inject_field_listener_events =
true;
break;
}
}
} else if (key == "inject_field_listener_events") {
file_options.field_listener_options.inject_field_listener_events = true;
} else if (key == "forbidden_field_listener_events") {
Expand Down

0 comments on commit 2dc5338

Please sign in to comment.