Commit b1d7759d authored by Andrew Shulaev's avatar Andrew Shulaev Committed by Commit Bot

Descriptor support in proto_library

This is needed in order to enable support for extension-based typed
tracing events. For more information, see
https://perfetto.dev/docs/design-docs/extensions

Change-Id: I43bd82ee1c94cf7ae5be0a1fd7db4104cf8ece6a
Bug: 161696674
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2332180Reviewed-by: default avatarBruce Dawson <brucedawson@chromium.org>
Reviewed-by: default avatarTommy Nyquist <nyquist@chromium.org>
Reviewed-by: default avatarEric Seckler <eseckler@chromium.org>
Commit-Queue: Andrew Shulaev <ddrone@google.com>
Cr-Commit-Position: refs/heads/master@{#795191}
parent 2da6b555
......@@ -2147,7 +2147,10 @@ jumbo_component("base") {
public_deps += [ "//third_party/perfetto:libperfetto" ]
deps += [ "//third_party/perfetto/include/perfetto/protozero" ]
deps += [
"//base/tracing/protos:chrome_track_event",
"//third_party/perfetto/include/perfetto/protozero",
]
all_dependent_configs += [ "//third_party/perfetto/gn:public_config" ]
......
# Copyright (c) 2020 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//third_party/protobuf/proto_library.gni")
proto_library("chrome_track_event") {
proto_in_dir = "//"
import_dirs = [ "//third_party/perfetto/" ]
sources = [ "chrome_track_event.proto" ]
generate_cc = false
generate_python = false
generate_descriptor = "chrome_track_event.descriptor"
}
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
syntax = "proto2";
import "third_party/perfetto/protos/perfetto/trace/track_event/track_event.proto";
package perfetto.protos;
enum ChromeAppState {
APP_STATE_FOREGROUND = 1;
APP_STATE_BACKGROUND = 2;
}
message ChromeTrackEvent {
// Extension range for Chrome: 1000-1099
extend TrackEvent { optional ChromeAppState chrome_app_state = 1000; }
}
......@@ -160,6 +160,12 @@ template("proto_library") {
generate_javascript = false
}
if (defined(invoker.generate_descriptor)) {
generate_descriptor = invoker.generate_descriptor
} else {
generate_descriptor = ""
}
if (defined(invoker.generator_plugin_label)) {
# Straightforward way to get the name of executable doesn't work because
# |root_out_dir| and |root_build_dir| may differ in cross-compilation and
......@@ -235,37 +241,55 @@ template("proto_library") {
js_out_dir = "$root_out_dir/jsproto/" + proto_out_dir
rel_js_out_dir = rebase_path(js_out_dir, root_build_dir)
}
if (generate_descriptor != "") {
descriptor_out =
"$root_gen_dir/" + proto_out_dir + "/" + generate_descriptor
rel_descriptor_out = rebase_path(descriptor_out, root_build_dir)
}
protos = rebase_path(invoker.sources, proto_in_dir)
protogens = []
protogens_cc = []
protogens_js = []
# Whether library should be generated.
# Library is not needed when proto_library is used to generate binary descriptor, in which case
# corresponding library target should be omitted entirely.
generate_library = generate_cc || generate_python || generate_with_plugin ||
generate_javascript
# List output files.
foreach(proto, protos) {
proto_dir = get_path_info(proto, "dir")
proto_name = get_path_info(proto, "name")
proto_path = proto_dir + "/" + proto_name
if (generate_library) {
foreach(proto, protos) {
proto_dir = get_path_info(proto, "dir")
proto_name = get_path_info(proto, "name")
proto_path = proto_dir + "/" + proto_name
if (generate_cc) {
protogens_cc += [
"$cc_out_dir/$proto_path.pb.h",
"$cc_out_dir/$proto_path.pb.cc",
]
}
if (generate_python) {
protogens += [ "$py_out_dir/${proto_path}_pb2.py" ]
}
if (generate_with_plugin) {
foreach(suffix, generator_plugin_suffixes) {
protogens_cc += [ "$cc_out_dir/${proto_path}${suffix}" ]
if (generate_cc) {
protogens_cc += [
"$cc_out_dir/$proto_path.pb.h",
"$cc_out_dir/$proto_path.pb.cc",
]
}
if (generate_python) {
protogens += [ "$py_out_dir/${proto_path}_pb2.py" ]
}
if (generate_with_plugin) {
foreach(suffix, generator_plugin_suffixes) {
protogens_cc += [ "$cc_out_dir/${proto_path}${suffix}" ]
}
}
if (generate_javascript) {
protogens_js += [ "$js_out_dir/${proto_path}.js" ]
}
}
if (generate_javascript) {
protogens_js += [ "$js_out_dir/${proto_path}.js" ]
}
}
# If descriptor needs to be generated, it should be added to list of outputs once.
if (generate_descriptor != "") {
protogens += [ descriptor_out ]
}
action_name = "${target_name}_gen"
source_set_name = target_name
javascript_name = "${target_name}_js"
......@@ -346,6 +370,13 @@ template("proto_library") {
}
}
if (generate_descriptor != "") {
args += [
"--descriptor-set-out",
rel_descriptor_out,
]
}
if (defined(invoker.import_dirs)) {
foreach(path, invoker.import_dirs) {
args += [ "--import-dir=" + rebase_path(path, root_build_dir) ]
......@@ -377,9 +408,12 @@ template("proto_library") {
}
}
# Option to disable building a library in component build.
if (defined(invoker.component_build_force_source_set) &&
invoker.component_build_force_source_set && is_component_build) {
if (!generate_library) {
# If only descriptor is required, just generate a group wrapper for action output.
link_target_type = "group"
} else if (defined(invoker.component_build_force_source_set) &&
invoker.component_build_force_source_set && is_component_build) {
# Option to disable building a library in component build.
link_target_type = "source_set"
} else {
link_target_type = "static_library"
......@@ -392,7 +426,7 @@ template("proto_library") {
config_name = "${target_name}_config"
config(config_name) {
include_dirs = []
if (has_nested_dirs) {
if (has_nested_dirs && generate_cc) {
include_dirs += [ cc_out_dir ]
}
if (defined(invoker.import_dirs)) {
......@@ -428,21 +462,23 @@ template("proto_library") {
"visibility",
])
sources = get_path_info(protogens_cc, "abspath")
if (generate_library) {
sources = get_path_info(protogens_cc, "abspath")
if (defined(invoker.remove_configs)) {
configs -= invoker.remove_configs
}
if (defined(invoker.remove_configs)) {
configs -= invoker.remove_configs
}
if (defined(invoker.extra_configs)) {
configs += invoker.extra_configs
}
if (defined(invoker.extra_configs)) {
configs += invoker.extra_configs
}
# Remove Sanitizer and coverage instrumentation for a performance boost when
# fuzzing, since the only fuzzers that use protobuf are libprotobuf-mutator
# based fuzzers, and they don't actually target protobuf code.
configs -= not_fuzzed_remove_configs
configs += [ "//build/config/sanitizers:not_fuzzed" ]
# Remove Sanitizer and coverage instrumentation for a performance boost when
# fuzzing, since the only fuzzers that use protobuf are libprotobuf-mutator
# based fuzzers, and they don't actually target protobuf code.
configs -= not_fuzzed_remove_configs
configs += [ "//build/config/sanitizers:not_fuzzed" ]
}
public_configs = [ "//third_party/protobuf:using_proto" ]
public_deps = []
......
......@@ -97,6 +97,8 @@ def main(argv):
parser.add_argument("--import-dir", action="append", default=[],
help="Extra import directory for protos, can be repeated."
)
parser.add_argument("--descriptor-set-out",
help="Path to write a descriptor.")
parser.add_argument("protos", nargs="+",
help="Input protobuf definition file(s).")
......@@ -151,6 +153,9 @@ def main(argv):
protoc_cmd += [os.path.join(proto_dir, name) for name in protos]
if options.descriptor_set_out:
protoc_cmd += ["--descriptor_set_out", options.descriptor_set_out]
ret = subprocess.call(protoc_cmd)
if ret != 0:
if ret <= -100:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment