1# Copyright (C) 2017 The Android Open Source Project 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15import("gn/perfetto.gni") 16import("gn/test.gni") 17 18# +----------------------------------------------------------------------------+ 19# | "all" targets definition: defines targets reachable by the various configs | 20# +----------------------------------------------------------------------------+ 21# There is a subtletly here related with chromium and other GN embedders. 22# When adding a dependency some_dir/:target_name, some_dir/BUILD.gn is 23# "discovered". As a side effect any *other* target defined in some_dir/BUILD.gn 24# (and its transitive dependencies) becomes implicitly part of the "default" 25# target, the one invoked running ninja -C out/xxx without further args. 26# Because of this, care must be taken to wrap dependencies to targets in other 27# build files with if (enable_xxx) flags. Accidentally including a harmless 28# target that happens to be defined in the same BUILD.gn that contains targets 29# incompatible with the chromium build will cause build/roll failures. 30 31all_targets = [ "protos/perfetto/trace:perfetto_trace_protos" ] 32 33if (enable_perfetto_platform_services) { 34 all_targets += [ 35 "src/perfetto_cmd:perfetto", 36 "src/perfetto_cmd:trigger_perfetto", 37 "src/traced/service:traced", 38 ] 39 if (enable_perfetto_traced_probes) { 40 all_targets += [ "src/traced/probes:traced_probes" ] 41 } 42 if (enable_perfetto_traced_relay) { 43 all_targets += [ "src/traced_relay:traced_relay" ] 44 } 45} 46 47if (enable_perfetto_trace_processor && enable_perfetto_trace_processor_sqlite) { 48 if (enable_perfetto_grpc) { 49 all_targets += [ "src/bigtrace/orchestrator:orchestrator_main" ] 50 all_targets += [ "src/bigtrace/worker:worker_main" ] 51 } 52 all_targets += [ "src/trace_processor:trace_processor_shell" ] 53} 54 55if (enable_perfetto_trace_processor) { 56 all_targets += [ "src/trace_redaction:trace_redactor" ] 57} 58 59if (enable_perfetto_traceconv) { 60 all_targets += [ 61 "src/traceconv", 62 "src/trace_config_utils", 63 ] 64 if (is_cross_compiling) { 65 # In many cross-compilation scenarios (typically Android) developers expect 66 # the host version of traceconv to be available somewhere in out/, so 67 # they can convert Android traces on their dev machine. Also 68 # tools/gen_android_bp explicitly depends on the host version for the 69 # cc_binary_host("traceconv") target in Android.bp. 70 # Note that when cross-compiling the host executable will be available in 71 # out/xxx/gcc_like_host/traceconv NOT just out/xxx/traceconv. 72 all_targets += [ 73 "src/traceconv($host_toolchain)", 74 "src/trace_config_utils($host_toolchain)", 75 ] 76 } 77} 78 79if (enable_perfetto_heapprofd) { 80 all_targets += [ "src/profiling/memory:heapprofd" ] 81 82 if (is_linux && !is_android) { 83 all_targets += [ "src/profiling/memory:heapprofd_glibc_preload" ] 84 } 85 if (perfetto_build_with_android) { 86 all_targets += [ 87 "src/profiling/memory:heapprofd_client", 88 "src/profiling/memory:heapprofd_client_api", 89 ] 90 } 91} 92 93if (enable_perfetto_traced_perf) { 94 all_targets += [ "src/profiling/perf:traced_perf" ] 95} 96 97if (perfetto_build_with_android) { 98 all_targets += [ "src/android_internal:libperfetto_android_internal" ] 99} 100 101if (enable_perfetto_tools) { 102 all_targets += [ "src/tools" ] 103 104 # Windows does not have an IPC implementation. 105 if (!is_win) { 106 all_targets += [ "src/websocket_bridge" ] 107 } 108} 109 110if (enable_perfetto_unittests) { 111 import("gn/perfetto_unittests.gni") 112 test("perfetto_unittests") { 113 if (is_fuchsia) { 114 additional_manifest_fragments = 115 [ "//build/config/fuchsia/test/network.shard.test-cml" ] # nogncheck 116 } 117 deps = perfetto_unittests_targets 118 } 119 all_targets += [ ":perfetto_unittests" ] 120} 121 122if (enable_perfetto_integration_tests) { 123 import("gn/perfetto_integrationtests.gni") 124 test("perfetto_integrationtests") { 125 deps = [ 126 "gn:default_deps", 127 "test:integrationtest_main", 128 ] 129 deps += perfetto_integrationtests_targets 130 } 131 all_targets += [ 132 ":perfetto_integrationtests", 133 "examples/sdk:sdk_example", 134 "test:client_api_example", 135 "test/stress_test", 136 ] 137 if (!is_win && !is_mac) { 138 all_targets += [ 139 "examples/shared_lib:example_shlib_data_source", 140 "examples/shared_lib:example_shlib_track_event", 141 ] 142 } 143} 144 145if (enable_perfetto_android_java_sdk) { 146 all_targets += [ 147 "src/java_sdk/main:perfetto_java_sdk_app", 148 "src/java_sdk/test:perfetto_java_sdk_test_app", 149 "src/java_sdk/test:perfetto_java_sdk_instrumentation_test", 150 "src/android_sdk/jni:libperfetto_jni", 151 "src/android_sdk/java/main:perfetto_trace_lib", 152 "src/android_sdk/java/test:perfetto_trace_instrumentation_test", 153 ] 154} 155 156if (enable_perfetto_trace_processor_json) { 157 test("trace_processor_minimal_smoke_tests") { 158 testonly = true 159 deps = [ 160 "gn:default_deps", 161 "src/trace_processor:storage_minimal_smoke_tests", 162 ] 163 } 164 all_targets += [ ":trace_processor_minimal_smoke_tests" ] 165} 166 167if (enable_perfetto_benchmarks) { 168 import("gn/perfetto_benchmarks.gni") 169 executable("perfetto_benchmarks") { 170 testonly = true 171 deps = perfetto_benchmarks_targets 172 } 173 all_targets += [ ":perfetto_benchmarks" ] 174} 175 176if (enable_perfetto_fuzzers) { 177 import("gn/perfetto_fuzzers.gni") 178 group("fuzzers") { 179 testonly = true 180 deps = perfetto_fuzzers_targets 181 } 182 all_targets += [ ":fuzzers" ] 183} 184 185# Less interesting stuff that makes sense only in the standalone build, mainly 186# compile-time checks for the CI. 187if (perfetto_build_standalone) { 188 all_targets += [ 189 "test/configs", 190 191 # Used to evaluate the Python folder for Bazel script generation. 192 "python:trace_processor_py", 193 194 # For checking all generated xxx.gen.{cc,h} files without waiting for 195 # embedders to try to use them and fail. 196 "protos/perfetto/config:cpp", 197 "protos/perfetto/common:cpp", 198 199 # Used in the when updating the ftrace protos 200 "protos/perfetto/trace/ftrace:descriptor", 201 202 # Checks that the "fake" backend implementations build. 203 "src/tracing:client_api_no_backends_compile_test", 204 ] 205 if (is_linux || is_android || is_mac) { 206 all_targets += [ "src/tracebox" ] 207 } 208} 209 210if (enable_perfetto_merged_protos_check) { 211 # For syntax-checking the protos. 212 all_targets += [ "protos/perfetto/trace:merged_trace_lite" ] 213} 214 215# The CTS code is built (but not ran) also in standalone builds. This is to 216# catch refactoring breakages earlier without having to wait for treehugger. 217if (is_android && (perfetto_build_standalone || perfetto_build_with_android)) { 218 all_targets += [ "test/cts:perfetto_cts_deps" ] 219 all_targets += [ "test/vts:perfetto_vts_deps" ] 220} 221 222group("all") { 223 testonly = true # allow to build also test targets 224 deps = all_targets 225} 226 227# This target is used when running ninja without any argument (by default would 228# build all reachable targets). This is mainly used to prevent the UI being 229# built when running ninja -C out/xxx. 230# This has effect only in standalone builds, no effect on chromium builds. 231# Chromium's "all" target depends on our "all" target above. However chromium's 232# "default" target depends on any target that we cause to be discovered by 233# depending on other GN files. 234group("default") { 235 testonly = true 236 deps = [ ":all" ] 237} 238 239# +----------------------------------------------------------------------------+ 240# | Other definitions: root targets that don't belong to any other subdirectory| 241# +----------------------------------------------------------------------------+ 242 243if (enable_perfetto_ui) { 244 group("ui") { 245 deps = [ "ui" ] 246 } 247} 248 249if (enable_perfetto_site) { 250 group("site") { 251 deps = [ "infra/perfetto.dev:site" ] 252 } 253} 254 255# In Android builds, we build the code of traced and traced_probes in one shared 256# library that exposes one xxx_main() for each. The executables themselves are 257# tiny shells that just invoke their own entry point into the library. 258# This is done merely for saving binary size, because the three binaries happen 259# to share a lot of code. 260# When setting monolithic_binaries=true (only supported in standalone builds) 261# it builds more conventional executables, where each binary has the full 262# implementation and no shared library dependency. This is to make dev cycles 263# on Android faster, avoiding all the LD_LIBRARY_PATH boilerplate. 264# libperfetto.so is also used for stuff that is exposed to the rest of the 265# Android tree. 266if (enable_perfetto_platform_services) { 267 if (monolithic_binaries) { 268 libperfetto_target_type = "static_library" 269 } else { 270 libperfetto_target_type = "shared_library" 271 } 272 273 target(libperfetto_target_type, "libperfetto") { 274 if (libperfetto_target_type == "static_library") { 275 complete_static_lib = true 276 } 277 deps = [ 278 "gn:default_deps", 279 "src/traced/service", 280 ] 281 if (enable_perfetto_traced_probes) { 282 deps += [ "src/traced/probes" ] 283 } 284 } 285} 286 287if (!build_with_chromium) { 288 # Client library target exposed to the Android tree. 289 # Still in experimental stage and not API stable yet. 290 # See "libperfetto_client_example" (in Android.bp.extras) for an example 291 # on how to use the Perfetto Client API from the android tree. 292 static_library("libperfetto_client_experimental") { 293 complete_static_lib = true 294 public_deps = [ 295 "gn:default_deps", 296 "src/tracing:client_api", 297 ] 298 sources = [ "include/perfetto/tracing.h" ] 299 assert_no_deps = [ "gn:protobuf_lite" ] 300 } 301} 302 303# TODO(primiano): there seem to be two "libperfetto" and one 304# "libperfetto_client_experimental" targets defined within this BUILD.gn file. 305# Rationalize them with eseckler@. For now seems this one is only used from 306# chromium and the other one only from the Android tree. 307if (build_with_chromium) { 308 component("libperfetto") { 309 public_configs = [ "gn:public_config" ] 310 deps = [ 311 "src/trace_processor/importers/memory_tracker:graph_processor", 312 "src/tracing:client_api", 313 "src/tracing/core", 314 ] 315 configs -= [ "//build/config/compiler:chromium_code" ] # nogncheck 316 configs += [ "//build/config/compiler:no_chromium_code" ] # nogncheck 317 public_deps = [ 318 "include/perfetto/ext/trace_processor/importers/memory_tracker", 319 "include/perfetto/ext/tracing/core", 320 "include/perfetto/tracing", 321 "protos/perfetto/common:zero", 322 "protos/perfetto/trace:zero", 323 "protos/perfetto/trace/chrome:zero", 324 "protos/perfetto/trace/etw:zero", 325 "protos/perfetto/trace/interned_data:zero", 326 "protos/perfetto/trace/profiling:zero", 327 "protos/perfetto/trace/ps:zero", 328 "protos/perfetto/trace/track_event:zero", 329 ] 330 if (enable_perfetto_ipc) { 331 deps += [ 332 "src/tracing/ipc/producer", 333 "src/tracing/ipc/service", 334 ] 335 public_deps += [ "include/perfetto/ext/tracing/ipc:ipc" ] 336 } 337 if (!is_nacl) { 338 deps += [ 339 "src/trace_processor:export_json", 340 "src/trace_processor:storage_minimal", 341 ] 342 public_deps += [ 343 "include/perfetto/ext/trace_processor:export_json", 344 "include/perfetto/trace_processor:storage", 345 ] 346 } 347 } 348 349 # TODO(altimin): this is a temp workaround around very strange link failures 350 # on win-dbg-ng buildbot. 351 if (!is_win) { 352 libtrace_processor_target_type = "source_set" 353 } else { 354 libtrace_processor_target_type = "component" 355 } 356 357 # In Chromium, we want to ensure that we don't link dynamically against sqlite 358 # (as Chromium also uses a more restricted version of sqlite which is actually 359 # shipped to the users). 360 # source_set helps us to achieve that. 361 target(libtrace_processor_target_type, "libtrace_processor") { 362 public_configs = [ "gn:public_config" ] 363 deps = [ "src/trace_processor:lib" ] 364 configs -= [ "//build/config/compiler:chromium_code" ] # nogncheck 365 configs += [ "//build/config/compiler:no_chromium_code" ] # nogncheck 366 public_deps = [ "include/perfetto/trace_processor" ] 367 } 368 component("perfetto_test_support") { 369 testonly = true 370 public_configs = [ "gn:public_config" ] 371 configs -= [ "//build/config/compiler:chromium_code" ] # nogncheck 372 configs += [ "//build/config/compiler:no_chromium_code" ] # nogncheck 373 public_deps = [ "include/perfetto/test:test_support" ] 374 deps = [ "src/tracing/test:test_support" ] 375 } 376} 377