perfetto: remove merged protos from Bazel and reduce usage elsewhere
This CL removes the merged protos from being built in Bazel as they
cause a lot of problems with ODR violations in G3 (i.e. if one static
lib depends on the merged trace, another on the merged config)
Instead, expose the non_minimal and config protos directly to be
depended on.
Change-Id: I24a05e5c42f270b15d0e68d4fcedc37a5dcd2b9b
Bug: 221191510
diff --git a/Android.bp b/Android.bp
index c42d742..c6f7526 100644
--- a/Android.bp
+++ b/Android.bp
@@ -2934,21 +2934,6 @@
],
}
-// GN: //protos/perfetto/config:merged_config_descriptor
-genrule {
- name: "perfetto_protos_perfetto_config_merged_config_descriptor",
- srcs: [
- "protos/perfetto/config/perfetto_config.proto",
- ],
- tools: [
- "aprotoc",
- ],
- cmd: "mkdir -p $(genDir)/external/perfetto/ && $(location aprotoc) --proto_path=external/perfetto --descriptor_set_out=$(out) $(in)",
- out: [
- "perfetto_protos_perfetto_config_merged_config_descriptor.bin",
- ],
-}
-
// GN: //protos/perfetto/config/power:cpp
genrule {
name: "perfetto_protos_perfetto_config_power_cpp_gen",
@@ -7235,11 +7220,11 @@
genrule {
name: "perfetto_src_perfetto_cmd_gen_cc_config_descriptor",
srcs: [
- ":perfetto_protos_perfetto_config_merged_config_descriptor",
+ ":perfetto_protos_perfetto_config_descriptor",
],
cmd: "$(location tools/gen_cc_proto_descriptor.py) --gen_dir=$(genDir) --cpp_out=$(out) $(in)",
out: [
- "src/perfetto_cmd/perfetto_config.descriptor.h",
+ "src/perfetto_cmd/config.descriptor.h",
],
tool_files: [
"tools/gen_cc_proto_descriptor.py",
diff --git a/BUILD b/BUILD
index 5f047e5..23b99dd 100644
--- a/BUILD
+++ b/BUILD
@@ -787,10 +787,10 @@
perfetto_cc_proto_descriptor(
name = "src_perfetto_cmd_gen_cc_config_descriptor",
deps = [
- ":protos_perfetto_config_merged_config_descriptor",
+ ":protos_perfetto_config_descriptor",
],
outs = [
- "src/perfetto_cmd/perfetto_config.descriptor.h",
+ "src/perfetto_cmd/config.descriptor.h",
],
)
@@ -1974,17 +1974,76 @@
# Proto libraries
# ##############################################################################
-# GN target: //protos/perfetto/common:cpp
-perfetto_cc_protocpp_library(
- name = "protos_perfetto_common_cpp",
+# GN target: [//protos/perfetto/config:source_set]
+perfetto_proto_library(
+ name = "config_proto",
+ visibility = PERFETTO_CONFIG.public_visibility,
deps = [
- ":protos_perfetto_common_protos",
+ ":protos_perfetto_config_protos",
],
)
-# GN target: //protos/perfetto/common:lite
perfetto_cc_proto_library(
- name = "protos_perfetto_common_lite",
+ name = "config_cc_proto",
+ visibility = PERFETTO_CONFIG.public_visibility,
+ deps = [
+ ":config_proto",
+ ],
+)
+
+perfetto_java_proto_library(
+ name = "config_java_proto",
+ visibility = PERFETTO_CONFIG.public_visibility,
+ deps = [
+ ":config_proto",
+ ],
+)
+
+perfetto_java_proto_library(
+ name = "config_java_proto_lite",
+ visibility = PERFETTO_CONFIG.public_visibility,
+ deps = [
+ ":config_proto",
+ ],
+)
+
+# GN target: [//protos/perfetto/trace:non_minimal_source_set, //protos/perfetto/trace:minimal_source_set]
+perfetto_proto_library(
+ name = "trace_proto",
+ visibility = PERFETTO_CONFIG.public_visibility,
+ deps = [
+ ":protos_perfetto_trace_minimal_protos",
+ ":protos_perfetto_trace_non_minimal_protos",
+ ],
+)
+
+perfetto_cc_proto_library(
+ name = "trace_cc_proto",
+ visibility = PERFETTO_CONFIG.public_visibility,
+ deps = [
+ ":trace_proto",
+ ],
+)
+
+perfetto_java_proto_library(
+ name = "trace_java_proto",
+ visibility = PERFETTO_CONFIG.public_visibility,
+ deps = [
+ ":trace_proto",
+ ],
+)
+
+perfetto_java_proto_library(
+ name = "trace_java_proto_lite",
+ visibility = PERFETTO_CONFIG.public_visibility,
+ deps = [
+ ":trace_proto",
+ ],
+)
+
+# GN target: //protos/perfetto/common:cpp
+perfetto_cc_protocpp_library(
+ name = "protos_perfetto_common_cpp",
deps = [
":protos_perfetto_common_protos",
],
@@ -2033,14 +2092,6 @@
],
)
-# GN target: //protos/perfetto/config/android:lite
-perfetto_cc_proto_library(
- name = "protos_perfetto_config_android_lite",
- deps = [
- ":protos_perfetto_config_android_protos",
- ],
-)
-
# GN target: //protos/perfetto/config/android:source_set
perfetto_proto_library(
name = "protos_perfetto_config_android_protos",
@@ -2104,14 +2155,6 @@
],
)
-# GN target: //protos/perfetto/config/ftrace:lite
-perfetto_cc_proto_library(
- name = "protos_perfetto_config_ftrace_lite",
- deps = [
- ":protos_perfetto_config_ftrace_protos",
- ],
-)
-
# GN target: //protos/perfetto/config/ftrace:source_set
perfetto_proto_library(
name = "protos_perfetto_config_ftrace_protos",
@@ -2139,14 +2182,6 @@
],
)
-# GN target: //protos/perfetto/config/gpu:lite
-perfetto_cc_proto_library(
- name = "protos_perfetto_config_gpu_lite",
- deps = [
- ":protos_perfetto_config_gpu_protos",
- ],
-)
-
# GN target: //protos/perfetto/config/gpu:source_set
perfetto_proto_library(
name = "protos_perfetto_config_gpu_protos",
@@ -2175,14 +2210,6 @@
],
)
-# GN target: //protos/perfetto/config/inode_file:lite
-perfetto_cc_proto_library(
- name = "protos_perfetto_config_inode_file_lite",
- deps = [
- ":protos_perfetto_config_inode_file_protos",
- ],
-)
-
# GN target: //protos/perfetto/config/inode_file:source_set
perfetto_proto_library(
name = "protos_perfetto_config_inode_file_protos",
@@ -2211,14 +2238,6 @@
],
)
-# GN target: //protos/perfetto/config/interceptors:lite
-perfetto_cc_proto_library(
- name = "protos_perfetto_config_interceptors_lite",
- deps = [
- ":protos_perfetto_config_interceptors_protos",
- ],
-)
-
# GN target: //protos/perfetto/config/interceptors:source_set
perfetto_proto_library(
name = "protos_perfetto_config_interceptors_protos",
@@ -2242,34 +2261,6 @@
],
)
-# GN target: //protos/perfetto/config:lite
-perfetto_cc_proto_library(
- name = "protos_perfetto_config_lite",
- deps = [
- ":protos_perfetto_config_protos",
- ],
-)
-
-# GN target: //protos/perfetto/config:merged_config_descriptor
-perfetto_proto_descriptor(
- name = "protos_perfetto_config_merged_config_descriptor",
- deps = [
- ":protos_perfetto_config_merged_config_protos",
- ],
- outs = [
- "protos_perfetto_config_merged_config_descriptor.bin",
- ],
-)
-
-# GN target: //protos/perfetto/config:merged_config_source_set
-perfetto_proto_library(
- name = "protos_perfetto_config_merged_config_protos",
- srcs = [
- "protos/perfetto/config/perfetto_config.proto",
- ],
- visibility = PERFETTO_CONFIG.public_visibility,
-)
-
# GN target: //protos/perfetto/config/power:cpp
perfetto_cc_protocpp_library(
name = "protos_perfetto_config_power_cpp",
@@ -2278,14 +2269,6 @@
],
)
-# GN target: //protos/perfetto/config/power:lite
-perfetto_cc_proto_library(
- name = "protos_perfetto_config_power_lite",
- deps = [
- ":protos_perfetto_config_power_protos",
- ],
-)
-
# GN target: //protos/perfetto/config/power:source_set
perfetto_proto_library(
name = "protos_perfetto_config_power_protos",
@@ -2313,14 +2296,6 @@
],
)
-# GN target: //protos/perfetto/config/process_stats:lite
-perfetto_cc_proto_library(
- name = "protos_perfetto_config_process_stats_lite",
- deps = [
- ":protos_perfetto_config_process_stats_protos",
- ],
-)
-
# GN target: //protos/perfetto/config/process_stats:source_set
perfetto_proto_library(
name = "protos_perfetto_config_process_stats_protos",
@@ -2349,14 +2324,6 @@
],
)
-# GN target: //protos/perfetto/config/profiling:lite
-perfetto_cc_proto_library(
- name = "protos_perfetto_config_profiling_lite",
- deps = [
- ":protos_perfetto_config_profiling_protos",
- ],
-)
-
# GN target: //protos/perfetto/config/profiling:source_set
perfetto_proto_library(
name = "protos_perfetto_config_profiling_protos",
@@ -2393,7 +2360,9 @@
"protos/perfetto/config/test_config.proto",
"protos/perfetto/config/trace_config.proto",
],
- visibility = PERFETTO_CONFIG.public_visibility,
+ visibility = [
+ PERFETTO_CONFIG.proto_library_visibility,
+ ],
deps = [
":protos_perfetto_common_protos",
":protos_perfetto_config_android_protos",
@@ -2418,14 +2387,6 @@
],
)
-# GN target: //protos/perfetto/config/sys_stats:lite
-perfetto_cc_proto_library(
- name = "protos_perfetto_config_sys_stats_lite",
- deps = [
- ":protos_perfetto_config_sys_stats_protos",
- ],
-)
-
# GN target: //protos/perfetto/config/sys_stats:source_set
perfetto_proto_library(
name = "protos_perfetto_config_sys_stats_protos",
@@ -2457,14 +2418,6 @@
],
)
-# GN target: //protos/perfetto/config/track_event:lite
-perfetto_cc_proto_library(
- name = "protos_perfetto_config_track_event_lite",
- deps = [
- ":protos_perfetto_config_track_event_protos",
- ],
-)
-
# GN target: //protos/perfetto/config/track_event:source_set
perfetto_proto_library(
name = "protos_perfetto_config_track_event_protos",
@@ -2639,7 +2592,9 @@
"protos/perfetto/metrics/android/trace_quality.proto",
"protos/perfetto/metrics/android/unsymbolized_frames.proto",
],
- visibility = PERFETTO_CONFIG.public_visibility,
+ visibility = [
+ PERFETTO_CONFIG.proto_library_visibility,
+ ],
)
# GN target: //protos/perfetto/metrics/chrome:descriptor
@@ -2721,14 +2676,6 @@
],
)
-# GN target: //protos/perfetto/trace/android:lite
-perfetto_cc_proto_library(
- name = "protos_perfetto_trace_android_lite",
- deps = [
- ":protos_perfetto_trace_android_protos",
- ],
-)
-
# GN target: //protos/perfetto/trace/android:source_set
perfetto_proto_library(
name = "protos_perfetto_trace_android_protos",
@@ -2758,14 +2705,6 @@
],
)
-# GN target: //protos/perfetto/trace/chrome:lite
-perfetto_cc_proto_library(
- name = "protos_perfetto_trace_chrome_lite",
- deps = [
- ":protos_perfetto_trace_chrome_protos",
- ],
-)
-
# GN target: //protos/perfetto/trace/chrome:source_set
perfetto_proto_library(
name = "protos_perfetto_trace_chrome_protos",
@@ -2798,14 +2737,6 @@
],
)
-# GN target: //protos/perfetto/trace/filesystem:lite
-perfetto_cc_proto_library(
- name = "protos_perfetto_trace_filesystem_lite",
- deps = [
- ":protos_perfetto_trace_filesystem_protos",
- ],
-)
-
# GN target: //protos/perfetto/trace/filesystem:source_set
perfetto_proto_library(
name = "protos_perfetto_trace_filesystem_protos",
@@ -2825,14 +2756,6 @@
],
)
-# GN target: //protos/perfetto/trace/ftrace:lite
-perfetto_cc_proto_library(
- name = "protos_perfetto_trace_ftrace_lite",
- deps = [
- ":protos_perfetto_trace_ftrace_protos",
- ],
-)
-
# GN target: //protos/perfetto/trace/ftrace:source_set
perfetto_proto_library(
name = "protos_perfetto_trace_ftrace_protos",
@@ -2900,14 +2823,6 @@
],
)
-# GN target: //protos/perfetto/trace/gpu:lite
-perfetto_cc_proto_library(
- name = "protos_perfetto_trace_gpu_lite",
- deps = [
- ":protos_perfetto_trace_gpu_protos",
- ],
-)
-
# GN target: //protos/perfetto/trace/gpu:source_set
perfetto_proto_library(
name = "protos_perfetto_trace_gpu_protos",
@@ -2935,14 +2850,6 @@
],
)
-# GN target: //protos/perfetto/trace/interned_data:lite
-perfetto_cc_proto_library(
- name = "protos_perfetto_trace_interned_data_lite",
- deps = [
- ":protos_perfetto_trace_interned_data_protos",
- ],
-)
-
# GN target: //protos/perfetto/trace/interned_data:source_set
perfetto_proto_library(
name = "protos_perfetto_trace_interned_data_protos",
@@ -2972,23 +2879,6 @@
],
)
-# GN target: //protos/perfetto/trace:merged_trace_source_set
-perfetto_proto_library(
- name = "protos_perfetto_trace_merged_trace_protos",
- srcs = [
- "protos/perfetto/trace/perfetto_trace.proto",
- ],
- visibility = PERFETTO_CONFIG.public_visibility,
-)
-
-# GN target: //protos/perfetto/trace:minimal_lite
-perfetto_cc_proto_library(
- name = "protos_perfetto_trace_minimal_lite",
- deps = [
- ":protos_perfetto_trace_minimal_protos",
- ],
-)
-
# GN target: //protos/perfetto/trace:minimal_source_set
perfetto_proto_library(
name = "protos_perfetto_trace_minimal_protos",
@@ -3036,14 +2926,6 @@
],
)
-# GN target: //protos/perfetto/trace:non_minimal_lite
-perfetto_cc_proto_library(
- name = "protos_perfetto_trace_non_minimal_lite",
- deps = [
- ":protos_perfetto_trace_non_minimal_protos",
- ],
-)
-
# GN target: //protos/perfetto/trace:non_minimal_source_set
perfetto_proto_library(
name = "protos_perfetto_trace_non_minimal_protos",
@@ -3057,7 +2939,9 @@
"protos/perfetto/trace/trace_packet_defaults.proto",
"protos/perfetto/trace/ui_state.proto",
],
- visibility = PERFETTO_CONFIG.public_visibility,
+ visibility = [
+ PERFETTO_CONFIG.proto_library_visibility,
+ ],
deps = [
":protos_perfetto_common_protos",
":protos_perfetto_config_android_protos",
@@ -3125,14 +3009,6 @@
],
)
-# GN target: //protos/perfetto/trace/perfetto:lite
-perfetto_cc_proto_library(
- name = "protos_perfetto_trace_perfetto_lite",
- deps = [
- ":protos_perfetto_trace_perfetto_protos",
- ],
-)
-
# GN target: //protos/perfetto/trace/perfetto:source_set
perfetto_proto_library(
name = "protos_perfetto_trace_perfetto_protos",
@@ -3153,14 +3029,6 @@
],
)
-# GN target: //protos/perfetto/trace/power:lite
-perfetto_cc_proto_library(
- name = "protos_perfetto_trace_power_lite",
- deps = [
- ":protos_perfetto_trace_power_protos",
- ],
-)
-
# GN target: //protos/perfetto/trace/power:source_set
perfetto_proto_library(
name = "protos_perfetto_trace_power_protos",
@@ -3228,14 +3096,6 @@
],
)
-# GN target: //protos/perfetto/trace/profiling:lite
-perfetto_cc_proto_library(
- name = "protos_perfetto_trace_profiling_lite",
- deps = [
- ":protos_perfetto_trace_profiling_protos",
- ],
-)
-
# GN target: //protos/perfetto/trace/profiling:source_set
perfetto_proto_library(
name = "protos_perfetto_trace_profiling_protos",
@@ -3263,14 +3123,6 @@
],
)
-# GN target: //protos/perfetto/trace/ps:lite
-perfetto_cc_proto_library(
- name = "protos_perfetto_trace_ps_lite",
- deps = [
- ":protos_perfetto_trace_ps_protos",
- ],
-)
-
# GN target: //protos/perfetto/trace/ps:source_set
perfetto_proto_library(
name = "protos_perfetto_trace_ps_protos",
@@ -3291,14 +3143,6 @@
],
)
-# GN target: //protos/perfetto/trace/sys_stats:lite
-perfetto_cc_proto_library(
- name = "protos_perfetto_trace_sys_stats_lite",
- deps = [
- ":protos_perfetto_trace_sys_stats_protos",
- ],
-)
-
# GN target: //protos/perfetto/trace/sys_stats:source_set
perfetto_proto_library(
name = "protos_perfetto_trace_sys_stats_protos",
@@ -3322,14 +3166,6 @@
],
)
-# GN target: //protos/perfetto/trace/system_info:lite
-perfetto_cc_proto_library(
- name = "protos_perfetto_trace_system_info_lite",
- deps = [
- ":protos_perfetto_trace_system_info_protos",
- ],
-)
-
# GN target: //protos/perfetto/trace/system_info:source_set
perfetto_proto_library(
name = "protos_perfetto_trace_system_info_protos",
@@ -4067,6 +3903,7 @@
deps = [
":protos_perfetto_metrics_protos",
],
+ visibility = PERFETTO_CONFIG.public_visibility,
)
perfetto_java_proto_library(
@@ -4074,27 +3911,7 @@
deps = [
":protos_perfetto_metrics_android_protos",
],
-)
-
-perfetto_java_proto_library(
- name = "protos_perfetto_trace_merged_trace_java",
- deps = [
- ":protos_perfetto_trace_merged_trace_protos",
- ],
-)
-
-perfetto_java_proto_library(
- name = "protos_perfetto_config_merged_config_java",
- deps = [
- ":protos_perfetto_config_merged_config_protos",
- ],
-)
-
-perfetto_java_lite_proto_library(
- name = "protos_perfetto_config_merged_config_java_lite",
- deps = [
- ":protos_perfetto_config_merged_config_protos",
- ],
+ visibility = PERFETTO_CONFIG.public_visibility,
)
perfetto_gensignature_internal_only(
diff --git a/BUILD.extras b/BUILD.extras
index f91b2f4..dbf18af 100644
--- a/BUILD.extras
+++ b/BUILD.extras
@@ -36,6 +36,7 @@
deps = [
":protos_perfetto_metrics_protos",
],
+ visibility = PERFETTO_CONFIG.public_visibility,
)
perfetto_java_proto_library(
@@ -43,27 +44,7 @@
deps = [
":protos_perfetto_metrics_android_protos",
],
-)
-
-perfetto_java_proto_library(
- name = "protos_perfetto_trace_merged_trace_java",
- deps = [
- ":protos_perfetto_trace_merged_trace_protos",
- ],
-)
-
-perfetto_java_proto_library(
- name = "protos_perfetto_config_merged_config_java",
- deps = [
- ":protos_perfetto_config_merged_config_protos",
- ],
-)
-
-perfetto_java_lite_proto_library(
- name = "protos_perfetto_config_merged_config_java_lite",
- deps = [
- ":protos_perfetto_config_merged_config_protos",
- ],
+ visibility = PERFETTO_CONFIG.public_visibility,
)
perfetto_gensignature_internal_only(
diff --git a/BUILD.gn b/BUILD.gn
index 53b8d9a..33f8818 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -134,7 +134,6 @@
"test/configs",
# For syntax-checking the protos.
- "protos/perfetto/config:merged_config_lite",
"protos/perfetto/trace:merged_trace_lite",
# For checking all generated xxx.gen.{cc,h} files without waiting for
diff --git a/CHANGELOG b/CHANGELOG
index ebad664..02ab1f8 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,7 @@
Unreleased:
Tracing service and probes:
- *
+ * Removed merged trace and config protos from Bazel. Embedder should
+ instead depend on the non-merged proto targets.
Trace Processor:
*
UI:
diff --git a/protos/perfetto/config/BUILD.gn b/protos/perfetto/config/BUILD.gn
index 471bfbe..4b96859 100644
--- a/protos/perfetto/config/BUILD.gn
+++ b/protos/perfetto/config/BUILD.gn
@@ -49,20 +49,3 @@
deps = [ ":source_set" ]
sources = [ "trace_config.proto" ]
}
-
-# This target is not used in the tree and is built only to guarantee that the
-# autogenerated merged proto has a valid syntax.
-perfetto_proto_library("merged_config_@TYPE@") {
- proto_generators = [
- "lite",
- "source_set",
- ]
- sources = [ "perfetto_config.proto" ]
-}
-
-perfetto_proto_library("merged_config_descriptor") {
- proto_generators = [ "descriptor" ]
- generate_descriptor = "perfetto_config.descriptor"
- sources = [ "perfetto_config.proto" ]
- deps = [ ":merged_config_source_set" ]
-}
diff --git a/protos/perfetto/trace/BUILD.gn b/protos/perfetto/trace/BUILD.gn
index cfcca49..f0d0462 100644
--- a/protos/perfetto/trace/BUILD.gn
+++ b/protos/perfetto/trace/BUILD.gn
@@ -137,9 +137,6 @@
# This target are not used in the tree and is built only to guarantee that the
# autogenerated merged proto has a valid syntax.
perfetto_proto_library("merged_trace_@TYPE@") {
- proto_generators = [
- "lite",
- "source_set",
- ]
+ proto_generators = [ "lite" ]
sources = [ "perfetto_trace.proto" ]
}
diff --git a/src/perfetto_cmd/BUILD.gn b/src/perfetto_cmd/BUILD.gn
index 9cfe232..74ca8fb 100644
--- a/src/perfetto_cmd/BUILD.gn
+++ b/src/perfetto_cmd/BUILD.gn
@@ -82,8 +82,8 @@
}
perfetto_cc_proto_descriptor("gen_cc_config_descriptor") {
- descriptor_name = "perfetto_config.descriptor"
- descriptor_target = "../../protos/perfetto/config:merged_config_descriptor"
+ descriptor_name = "config.descriptor"
+ descriptor_target = "../../protos/perfetto/config:descriptor"
}
source_set("trigger_perfetto_cmd") {
diff --git a/src/perfetto_cmd/pbtxt_to_pb.cc b/src/perfetto_cmd/pbtxt_to_pb.cc
index 7420502..2c7b67a 100644
--- a/src/perfetto_cmd/pbtxt_to_pb.cc
+++ b/src/perfetto_cmd/pbtxt_to_pb.cc
@@ -33,7 +33,7 @@
#include "perfetto/protozero/message.h"
#include "perfetto/protozero/message_handle.h"
#include "perfetto/protozero/scattered_heap_buffer.h"
-#include "src/perfetto_cmd/perfetto_config.descriptor.h"
+#include "src/perfetto_cmd/config.descriptor.h"
#include "protos/perfetto/common/descriptor.gen.h"
@@ -707,8 +707,7 @@
{
file_descriptor_set.ParseFromArray(
- kPerfettoConfigDescriptor.data(),
- static_cast<int>(kPerfettoConfigDescriptor.size()));
+ kConfigDescriptor.data(), static_cast<int>(kConfigDescriptor.size()));
for (const auto& file_descriptor : file_descriptor_set.file()) {
for (const auto& enum_descriptor : file_descriptor.enum_type()) {
const std::string name =
diff --git a/test/configs/BUILD.gn b/test/configs/BUILD.gn
index b57b9aa..230fe01 100644
--- a/test/configs/BUILD.gn
+++ b/test/configs/BUILD.gn
@@ -21,8 +21,7 @@
script = "../../tools/protoc_helper.py"
deps = [
- "../../protos/perfetto/config:merged_config_source_set",
- "../../protos/perfetto/trace:merged_trace_source_set",
+ "../../protos/perfetto/trace:non_minimal_source_set",
protoc_target,
]
diff --git a/tools/gen_bazel b/tools/gen_bazel
index e5c7f82..7ece08e 100755
--- a/tools/gen_bazel
+++ b/tools/gen_bazel
@@ -25,6 +25,7 @@
from __future__ import print_function
import argparse
+import itertools
import json
import os
import re
@@ -76,21 +77,25 @@
# Root proto targets (to force discovery of intermediate proto targets).
# These targets are marked public.
+# TODO(lalitm): remove these in a followup.
proto_targets = [
- '//protos/perfetto/trace:merged_trace_source_set',
- '//protos/perfetto/trace:non_minimal_lite',
- '//protos/perfetto/trace:non_minimal_source_set',
- '//protos/perfetto/config:merged_config_source_set',
'//protos/perfetto/metrics:lite',
'//protos/perfetto/metrics:source_set',
- '//protos/perfetto/metrics/android:lite',
- '//protos/perfetto/metrics/android:source_set',
- '//protos/perfetto/trace:source_set',
- '//protos/perfetto/config:source_set',
'//protos/third_party/chromium:lite',
'//protos/third_party/chromium:source_set',
]
+# Proto target groups which will be made public.
+proto_groups = {
+ 'config': [
+ '//protos/perfetto/config:source_set'
+ ],
+ 'trace': [
+ '//protos/perfetto/trace:non_minimal_source_set',
+ '//protos/perfetto/trace:minimal_source_set'
+ ],
+}
+
# Path for the protobuf sources in the standalone build.
buildtools_protobuf_src = '//buildtools/protobuf/src'
@@ -257,15 +262,17 @@
return gn_utils.label_to_target_name_with_path(gn_name)
+def get_bazel_proto_sources_label(target_name):
+ """Converts a GN target name into a Bazel proto label name."""
+ return re.sub('_(lite|zero|cpp|ipc|source_set|descriptor)$', '',
+ get_bazel_label_name(target_name)) + '_protos'
+
+
def gen_proto_label(target):
""" Generates the xx_proto_library label for proto targets."""
assert (target.type == 'proto_library')
- def get_sources_label(target_name):
- return re.sub('_(lite|zero|cpp|ipc|source_set|descriptor)$', '',
- get_bazel_label_name(target_name)) + '_protos'
-
- sources_label_name = get_sources_label(target.name)
+ sources_label_name = get_bazel_proto_sources_label(target.name)
# For 'source_set' plugins, we don't want to generate any plugin-dependent
# targets so just return the label of the proto sources only.
@@ -276,7 +283,7 @@
assert (all(x.endswith('.proto') for x in target.sources))
sources_label.srcs = sorted([x[2:] for x in target.sources]) # Strip //.
sources_label.deps = sorted(
- [':' + get_sources_label(x) for x in target.proto_deps])
+ [':' + get_bazel_proto_sources_label(x) for x in target.proto_deps])
# In Bazel, proto_paths are not a supported concept becauase strong
# dependency checking is enabled. Instead, we need to depend on the target
@@ -295,7 +302,7 @@
sources_label.visibility = ['PERFETTO_CONFIG.proto_library_visibility']
sources_label.exports = sorted([
- ':' + get_sources_label(d) for d in target.proto_exports
+ ':' + get_bazel_proto_sources_label(d) for d in target.proto_exports
])
return sources_label
@@ -332,7 +339,7 @@
# implicit.
if target.proto_plugin == 'descriptor':
plugin_label.deps += [
- ':' + get_sources_label(x) for x in target.proto_deps
+ ':' + get_bazel_proto_sources_label(x) for x in target.proto_deps
]
else:
plugin_label.deps += [':' + sources_label_name]
@@ -345,6 +352,45 @@
return plugin_label
+def gen_proto_group_target(name, targets):
+ names = ', '.join((t.name for t in targets))
+ comment = f'[{names}]'
+
+ # First, create a root source set target which references all the child
+ # source set targets. We publish this as well as depending on this in all
+ # subsequent targets.
+ sources_label = BazelLabel(name + '_proto', 'perfetto_proto_library')
+ sources_label.deps = [
+ ':' + get_bazel_proto_sources_label(target.name)
+ for target in targets
+ ]
+ sources_label.visibility = PUBLIC_VISIBILITY
+ sources_label.comment = comment
+
+ # Next we create a cc proto target depending on the source set target.
+ cc_label = BazelLabel(name + '_cc_proto', 'perfetto_cc_proto_library')
+ cc_label.deps = [':' + sources_label.name]
+ cc_label.visibility = PUBLIC_VISIBILITY
+ sources_label.comment = comment
+
+ # Next we create a java proto target depending on the source set
+ # target.
+ java_label = BazelLabel(name + '_java_proto', 'perfetto_java_proto_library')
+ java_label.deps = [':' + sources_label.name]
+ java_label.visibility = PUBLIC_VISIBILITY
+ sources_label.comment = comment
+
+ # Finally we create a java lite proto target depending on the source
+ # set target.
+ lite_name = name + '_java_proto_lite'
+ java_lite_label = BazelLabel(lite_name, 'perfetto_java_proto_library')
+ java_lite_label.deps = [':' + sources_label.name]
+ java_lite_label.visibility = PUBLIC_VISIBILITY
+ sources_label.comment = comment
+
+ return [sources_label, cc_label, java_label, java_lite_label]
+
+
def gen_target(gn_target):
if gn_target.type == 'proto_library':
return [gen_proto_label(gn_target)]
@@ -511,6 +557,11 @@
# ##############################################################################
'''.lstrip()
+ # Generate targets for proto groups.
+ for label_name, target_names in proto_groups.items():
+ targets = [gn.get_target(name) for name in target_names]
+ res += ''.join(str(x) for x in gen_proto_group_target(label_name, targets))
+
# Force discovery of explicilty listed root proto targets.
for target_name in sorted(proto_targets):
gn.get_target(target_name)