• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_main" ]
50    all_targets += [ "src/bigtrace: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 += [ "src/traceconv" ]
61  if (is_cross_compiling) {
62    # In many cross-compilation scenarios (typically Android) developers expect
63    # the host version of traceconv to be available somewhere in out/, so
64    # they can convert Android traces on their dev machine. Also
65    # tools/gen_android_bp explicitly depends on the host version for the
66    # cc_binary_host("traceconv") target in Android.bp.
67    # Note that when cross-compiling the host executable will be available in
68    # out/xxx/gcc_like_host/traceconv NOT just out/xxx/traceconv.
69    all_targets += [ "src/traceconv($host_toolchain)" ]
70  }
71}
72
73if (enable_perfetto_heapprofd) {
74  all_targets += [ "src/profiling/memory:heapprofd" ]
75
76  if (is_linux && !is_android) {
77    all_targets += [ "src/profiling/memory:heapprofd_glibc_preload" ]
78  }
79  if (perfetto_build_with_android) {
80    all_targets += [
81      "src/profiling/memory:heapprofd_client",
82      "src/profiling/memory:heapprofd_client_api",
83    ]
84  }
85}
86
87if (enable_perfetto_traced_perf) {
88  all_targets += [ "src/profiling/perf:traced_perf" ]
89}
90
91if (perfetto_build_with_android) {
92  all_targets += [ "src/android_internal:libperfetto_android_internal" ]
93}
94
95if (enable_perfetto_tools) {
96  all_targets += [ "src/tools" ]
97
98  # Windows does not have an IPC implementation.
99  if (!is_win) {
100    all_targets += [ "src/websocket_bridge" ]
101  }
102}
103
104if (enable_perfetto_unittests) {
105  import("gn/perfetto_unittests.gni")
106  test("perfetto_unittests") {
107    if (is_fuchsia) {
108      additional_manifest_fragments =
109          [ "//build/config/fuchsia/test/network.shard.test-cml" ]  # nogncheck
110    }
111    deps = perfetto_unittests_targets
112  }
113  all_targets += [ ":perfetto_unittests" ]
114}
115
116if (enable_perfetto_integration_tests) {
117  import("gn/perfetto_integrationtests.gni")
118  test("perfetto_integrationtests") {
119    deps = perfetto_integrationtests_targets
120  }
121  all_targets += [
122    ":perfetto_integrationtests",
123    "examples/sdk:sdk_example",
124    "test:client_api_example",
125    "test/stress_test",
126  ]
127  if (!is_win && !is_mac) {
128    all_targets += [
129      "examples/shared_lib:example_shlib_data_source",
130      "examples/shared_lib:example_shlib_track_event",
131    ]
132  }
133}
134
135if (enable_perfetto_trace_processor_json) {
136  test("trace_processor_minimal_smoke_tests") {
137    testonly = true
138    deps = [
139      "gn:default_deps",
140      "src/trace_processor:storage_minimal_smoke_tests",
141    ]
142  }
143  all_targets += [ ":trace_processor_minimal_smoke_tests" ]
144}
145
146if (enable_perfetto_benchmarks) {
147  import("gn/perfetto_benchmarks.gni")
148  executable("perfetto_benchmarks") {
149    testonly = true
150    deps = perfetto_benchmarks_targets
151  }
152  all_targets += [ ":perfetto_benchmarks" ]
153}
154
155if (enable_perfetto_fuzzers) {
156  import("gn/perfetto_fuzzers.gni")
157  group("fuzzers") {
158    testonly = true
159    deps = perfetto_fuzzers_targets
160  }
161  all_targets += [ ":fuzzers" ]
162}
163
164# Less interesting stuff that makes sense only in the standalone build, mainly
165# compile-time checks for the CI.
166if (perfetto_build_standalone) {
167  all_targets += [
168    "test/configs",
169
170    # Used to evaluate the Python folder for Bazel script generation.
171    "python:trace_processor_py",
172
173    # For checking all generated xxx.gen.{cc,h} files without waiting for
174    # embedders to try to use them and fail.
175    "protos/perfetto/config:cpp",
176    "protos/perfetto/common:cpp",
177
178    # Used in the when updating the ftrace protos
179    "protos/perfetto/trace/ftrace:descriptor",
180
181    # Checks that the "fake" backend implementations build.
182    "src/tracing:client_api_no_backends_compile_test",
183  ]
184  if (is_linux || is_android || is_mac) {
185    all_targets += [ "src/tracebox" ]
186  }
187}
188
189if (enable_perfetto_merged_protos_check) {
190  # For syntax-checking the protos.
191  all_targets += [ "protos/perfetto/trace:merged_trace_lite" ]
192}
193
194# The CTS code is built (but not ran) also in standalone builds. This is to
195# catch refactoring breakages earlier without having to wait for treehugger.
196if (is_android && (perfetto_build_standalone || perfetto_build_with_android)) {
197  all_targets += [ "test/cts:perfetto_cts_deps" ]
198  all_targets += [ "test/vts:perfetto_vts_deps" ]
199}
200
201group("all") {
202  testonly = true  # allow to build also test targets
203  deps = all_targets
204}
205
206# This target is used when running ninja without any argument (by default would
207# build all reachable targets). This is mainly used to prevent the UI being
208# built when running ninja -C out/xxx.
209# This has effect only in standalone builds, no effect on chromium builds.
210# Chromium's "all" target depends on our "all" target above. However chromium's
211# "default" target depends on any target that we cause to be discovered by
212# depending on other GN files.
213group("default") {
214  testonly = true
215  deps = [ ":all" ]
216}
217
218# +----------------------------------------------------------------------------+
219# | Other definitions: root targets that don't belong to any other subdirectory|
220# +----------------------------------------------------------------------------+
221
222if (enable_perfetto_ui) {
223  group("ui") {
224    deps = [ "ui" ]
225  }
226}
227
228if (enable_perfetto_site) {
229  group("site") {
230    deps = [ "infra/perfetto.dev:site" ]
231  }
232}
233
234# In Android builds, we build the code of traced and traced_probes in one shared
235# library that exposes one xxx_main() for each. The executables themselves are
236# tiny shells that just invoke their own entry point into the library.
237# This is done merely for saving binary size, because the three binaries happen
238# to share a lot of code.
239# When setting monolithic_binaries=true (only supported in standalone builds)
240# it builds more conventional executables, where each binary has the full
241# implementation and no shared library dependency. This is to make dev cycles
242# on Android faster, avoiding all the LD_LIBRARY_PATH boilerplate.
243# libperfetto.so is also used for stuff that is exposed to the rest of the
244# Android tree.
245if (enable_perfetto_platform_services) {
246  if (monolithic_binaries) {
247    libperfetto_target_type = "static_library"
248  } else {
249    libperfetto_target_type = "shared_library"
250  }
251
252  target(libperfetto_target_type, "libperfetto") {
253    if (libperfetto_target_type == "static_library") {
254      complete_static_lib = true
255    }
256    deps = [
257      "gn:default_deps",
258      "src/traced/service",
259    ]
260    if (enable_perfetto_traced_probes) {
261      deps += [ "src/traced/probes" ]
262    }
263  }
264}
265
266if (!build_with_chromium) {
267  # Client library target exposed to the Android tree.
268  # Still in experimental stage and not API stable yet.
269  # See "libperfetto_client_example" (in Android.bp.extras) for an example
270  # on how to use the Perfetto Client API from the android tree.
271  static_library("libperfetto_client_experimental") {
272    complete_static_lib = true
273    public_deps = [
274      "gn:default_deps",
275      "src/tracing:client_api",
276      "src/tracing:platform_impl",
277    ]
278    sources = [ "include/perfetto/tracing.h" ]
279    assert_no_deps = [ "gn:protobuf_lite" ]
280  }
281}
282
283# TODO(primiano): there seem to be two "libperfetto" and one
284# "libperfetto_client_experimental" targets defined within this BUILD.gn file.
285# Rationalize them with eseckler@. For now seems this one is only used from
286# chromium and the other one only from the Android tree.
287if (build_with_chromium) {
288  component("libperfetto") {
289    public_configs = [ "gn:public_config" ]
290    deps = [
291      "src/trace_processor/importers/memory_tracker:graph_processor",
292      "src/tracing:client_api",
293      "src/tracing:platform_impl",
294      "src/tracing/core",
295    ]
296    configs -= [ "//build/config/compiler:chromium_code" ]  # nogncheck
297    configs += [ "//build/config/compiler:no_chromium_code" ]  # nogncheck
298    public_deps = [
299      "include/perfetto/ext/trace_processor/importers/memory_tracker",
300      "include/perfetto/ext/tracing/core",
301      "include/perfetto/tracing",
302      "protos/perfetto/common:zero",
303      "protos/perfetto/trace:zero",
304      "protos/perfetto/trace/chrome:zero",
305      "protos/perfetto/trace/etw:zero",
306      "protos/perfetto/trace/interned_data:zero",
307      "protos/perfetto/trace/profiling:zero",
308      "protos/perfetto/trace/ps:zero",
309      "protos/perfetto/trace/track_event:zero",
310    ]
311    if (enable_perfetto_ipc) {
312      deps += [
313        "src/tracing/ipc/producer",
314        "src/tracing/ipc/service",
315      ]
316      public_deps += [ "include/perfetto/ext/tracing/ipc:ipc" ]
317    }
318    if (!is_nacl) {
319      deps += [
320        "src/trace_processor:export_json",
321        "src/trace_processor:storage_minimal",
322      ]
323      public_deps += [
324        "include/perfetto/ext/trace_processor:export_json",
325        "include/perfetto/trace_processor:storage",
326      ]
327    }
328  }
329
330  # TODO(altimin): this is a temp workaround around very strange link failures
331  # on win-dbg-ng buildbot.
332  if (!is_win) {
333    libtrace_processor_target_type = "source_set"
334  } else {
335    libtrace_processor_target_type = "component"
336  }
337
338  # In Chromium, we want to ensure that we don't link dynamically against sqlite
339  # (as Chromium also uses a more restricted version of sqlite which is actually
340  # shipped to the users).
341  # source_set helps us to achieve that.
342  target(libtrace_processor_target_type, "libtrace_processor") {
343    public_configs = [ "gn:public_config" ]
344    deps = [ "src/trace_processor:lib" ]
345    configs -= [ "//build/config/compiler:chromium_code" ]  # nogncheck
346    configs += [ "//build/config/compiler:no_chromium_code" ]  # nogncheck
347    public_deps = [ "include/perfetto/trace_processor" ]
348  }
349  component("perfetto_test_support") {
350    testonly = true
351    public_configs = [ "gn:public_config" ]
352    configs -= [ "//build/config/compiler:chromium_code" ]  # nogncheck
353    configs += [ "//build/config/compiler:no_chromium_code" ]  # nogncheck
354    public_deps = [ "include/perfetto/test:test_support" ]
355    deps = [ "src/tracing/test:test_support" ]
356  }
357}
358