Primiano Tucci | 34bc559 | 2021-02-19 17:53:36 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 2 | # Copyright (C) 2017 The Android Open Source Project |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | # This tool translates a collection of BUILD.gn files into a mostly equivalent |
| 17 | # Android.bp file for the Android Soong build system. The input to the tool is a |
| 18 | # JSON description of the GN build definition generated with the following |
| 19 | # command: |
| 20 | # |
| 21 | # gn desc out --format=json --all-toolchains "//*" > desc.json |
| 22 | # |
| 23 | # The tool is then given a list of GN labels for which to generate Android.bp |
| 24 | # build rules. The dependencies for the GN labels are squashed to the generated |
| 25 | # Android.bp target, except for actions which get their own genrule. Some |
| 26 | # libraries are also mapped to their Android equivalents -- see |builtin_deps|. |
| 27 | |
| 28 | import argparse |
| 29 | import json |
| 30 | import os |
| 31 | import re |
| 32 | import sys |
Lalit Maganti | 27b00af | 2022-12-17 01:20:38 +0000 | [diff] [blame] | 33 | from typing import Dict |
Lalit Maganti | 921a3d6 | 2022-12-17 14:28:50 +0000 | [diff] [blame] | 34 | from typing import List |
| 35 | from typing import Optional |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 36 | |
Sami Kyostila | 3c88a1d | 2019-05-22 18:29:42 +0100 | [diff] [blame] | 37 | import gn_utils |
Lalit Maganti | 921a3d6 | 2022-12-17 14:28:50 +0000 | [diff] [blame] | 38 | from gn_utils import GnParser |
Sami Kyostila | 3c88a1d | 2019-05-22 18:29:42 +0100 | [diff] [blame] | 39 | |
Matthew Clarkson | 9a5dfa5 | 2019-10-03 09:54:04 +0100 | [diff] [blame] | 40 | from compat import itervalues |
| 41 | |
Florian Mayer | 246c142 | 2019-09-18 15:40:38 +0100 | [diff] [blame] | 42 | ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| 43 | |
Sami Kyostila | b27619f | 2017-12-13 19:22:16 +0000 | [diff] [blame] | 44 | # Arguments for the GN output directory. |
Primiano Tucci | 9c41165 | 2019-08-27 07:13:59 +0200 | [diff] [blame] | 45 | gn_args = ' '.join([ |
| 46 | 'is_debug=false', |
Primiano Tucci | 7e05fc1 | 2019-08-27 17:29:47 +0200 | [diff] [blame] | 47 | 'is_perfetto_build_generator=true', |
Primiano Tucci | 9c41165 | 2019-08-27 07:13:59 +0200 | [diff] [blame] | 48 | 'perfetto_build_with_android=true', |
| 49 | 'target_cpu="arm"', |
| 50 | 'target_os="android"', |
| 51 | ]) |
Sami Kyostila | b27619f | 2017-12-13 19:22:16 +0000 | [diff] [blame] | 52 | |
Primiano Tucci | 02c1176 | 2019-08-30 00:57:59 +0200 | [diff] [blame] | 53 | # Default targets to translate to the blueprint file. |
| 54 | default_targets = [ |
| 55 | '//:libperfetto_client_experimental', |
| 56 | '//:libperfetto', |
| 57 | '//:perfetto_integrationtests', |
| 58 | '//:perfetto_unittests', |
| 59 | '//protos/perfetto/trace:perfetto_trace_protos', |
| 60 | '//src/android_internal:libperfetto_android_internal', |
Lalit Maganti | 52f1336 | 2023-01-23 16:38:01 +0000 | [diff] [blame] | 61 | '//src/base:perfetto_base_default_platform', |
Daniele Di Proietto | ec4864e | 2022-12-14 17:32:38 +0000 | [diff] [blame] | 62 | '//src/shared_lib:libperfetto_c', |
Primiano Tucci | 02c1176 | 2019-08-30 00:57:59 +0200 | [diff] [blame] | 63 | '//src/perfetto_cmd:perfetto', |
| 64 | '//src/perfetto_cmd:trigger_perfetto', |
| 65 | '//src/profiling/memory:heapprofd_client', |
Florian Mayer | 23f7937 | 2020-06-16 14:37:06 +0200 | [diff] [blame] | 66 | '//src/profiling/memory:heapprofd_client_api', |
Florian Mayer | 72e8736 | 2020-12-11 19:37:25 +0000 | [diff] [blame] | 67 | '//src/profiling/memory:heapprofd_api_noop', |
Primiano Tucci | 02c1176 | 2019-08-30 00:57:59 +0200 | [diff] [blame] | 68 | '//src/profiling/memory:heapprofd', |
Florian Mayer | 50f07a6 | 2020-07-15 17:15:58 +0100 | [diff] [blame] | 69 | '//src/profiling/memory:heapprofd_standalone_client', |
Ryan Savitski | 462b5db | 2019-11-20 19:06:46 +0000 | [diff] [blame] | 70 | '//src/profiling/perf:traced_perf', |
Primiano Tucci | 02c1176 | 2019-08-30 00:57:59 +0200 | [diff] [blame] | 71 | '//src/traced/probes:traced_probes', |
| 72 | '//src/traced/service:traced', |
Lalit Maganti | e0986f3 | 2020-09-17 15:35:47 +0100 | [diff] [blame] | 73 | '//src/trace_processor:trace_processor_shell', |
Steven Terrell | 3137bbe | 2024-03-22 18:55:56 +0000 | [diff] [blame] | 74 | '//src/trace_redaction:trace_redactor', |
Primiano Tucci | fbf4a73 | 2019-12-11 00:32:15 +0000 | [diff] [blame] | 75 | '//test/cts:perfetto_cts_deps', |
Lalit Maganti | 9782f49 | 2020-01-10 18:13:13 +0000 | [diff] [blame] | 76 | '//test/cts:perfetto_cts_jni_deps', |
Primiano Tucci | cbbe480 | 2020-02-20 13:19:11 +0000 | [diff] [blame] | 77 | '//test:perfetto_gtest_logcat_printer', |
Daniele Di Proietto | 5567443 | 2023-06-02 10:46:53 +0000 | [diff] [blame] | 78 | '//test:perfetto_end_to_end_integrationtests', |
Daniele Di Proietto | 2e6c106 | 2022-09-14 13:52:19 +0000 | [diff] [blame] | 79 | '//test/vts:perfetto_vts_deps', |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 80 | ] |
| 81 | |
| 82 | # Host targets |
| 83 | ipc_plugin = '//src/ipc/protoc_plugin:ipc_plugin(%s)' % gn_utils.HOST_TOOLCHAIN |
| 84 | protozero_plugin = '//src/protozero/protoc_plugin:protozero_plugin(%s)' % ( |
| 85 | gn_utils.HOST_TOOLCHAIN) |
Primiano Tucci | 57dd66b | 2019-10-15 23:09:04 +0100 | [diff] [blame] | 86 | cppgen_plugin = '//src/protozero/protoc_plugin:cppgen_plugin(%s)' % ( |
| 87 | gn_utils.HOST_TOOLCHAIN) |
| 88 | |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 89 | default_targets += [ |
Hector Dearman | a9545e5 | 2022-05-17 12:23:25 +0100 | [diff] [blame] | 90 | '//src/traceconv:traceconv(%s)' % gn_utils.HOST_TOOLCHAIN, |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 91 | protozero_plugin, |
| 92 | ipc_plugin, |
Primiano Tucci | 02c1176 | 2019-08-30 00:57:59 +0200 | [diff] [blame] | 93 | ] |
| 94 | |
Primiano Tucci | 02c1176 | 2019-08-30 00:57:59 +0200 | [diff] [blame] | 95 | # Defines a custom init_rc argument to be applied to the corresponding output |
| 96 | # blueprint target. |
| 97 | target_initrc = { |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 98 | '//src/traced/service:traced': {'perfetto.rc'}, |
| 99 | '//src/profiling/memory:heapprofd': {'heapprofd.rc'}, |
Ryan Savitski | 29082bf | 2020-02-12 15:13:51 +0000 | [diff] [blame] | 100 | '//src/profiling/perf:traced_perf': {'traced_perf.rc'}, |
Primiano Tucci | 02c1176 | 2019-08-30 00:57:59 +0200 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | target_host_supported = [ |
Hector Dearman | 04cfac7 | 2019-09-24 22:05:55 +0100 | [diff] [blame] | 104 | '//:libperfetto', |
Michael Eastwood | 6cbbff1 | 2021-12-09 15:34:35 -0800 | [diff] [blame] | 105 | '//:libperfetto_client_experimental', |
Lalit Maganti | e0986f3 | 2020-09-17 15:35:47 +0100 | [diff] [blame] | 106 | '//protos/perfetto/trace:perfetto_trace_protos', |
Daniele Di Proietto | ec4864e | 2022-12-14 17:32:38 +0000 | [diff] [blame] | 107 | '//src/shared_lib:libperfetto_c', |
Ryan Savitski | e65c405 | 2022-03-24 18:22:19 +0000 | [diff] [blame] | 108 | '//src/trace_processor:demangle', |
Lalit Maganti | e0986f3 | 2020-09-17 15:35:47 +0100 | [diff] [blame] | 109 | '//src/trace_processor:trace_processor_shell', |
A. Cody Schuffelen | 3c82a54 | 2023-05-22 20:11:25 -0700 | [diff] [blame] | 110 | '//src/traced/probes:traced_probes', |
A. Cody Schuffelen | bf63694 | 2023-05-17 18:34:33 -0700 | [diff] [blame] | 111 | '//src/traced/service:traced', |
Primiano Tucci | 02c1176 | 2019-08-30 00:57:59 +0200 | [diff] [blame] | 112 | ] |
| 113 | |
Michael Eastwood | 6cbbff1 | 2021-12-09 15:34:35 -0800 | [diff] [blame] | 114 | target_vendor_available = [ |
| 115 | '//:libperfetto_client_experimental', |
| 116 | ] |
| 117 | |
Nikita Putikhin | 94e30a0 | 2023-11-22 14:16:47 +0100 | [diff] [blame] | 118 | target_product_available = [ |
| 119 | '//:libperfetto_client_experimental', |
| 120 | ] |
| 121 | |
Lalit Maganti | d7afbb1 | 2022-03-28 15:12:24 +0100 | [diff] [blame] | 122 | # Proto target groups which will be made public. |
| 123 | proto_groups = { |
Kean Mariotti | 487a539 | 2024-04-18 06:58:29 +0000 | [diff] [blame] | 124 | 'trace': { |
Kean Mariotti | 34af6df | 2024-03-07 10:11:15 +0000 | [diff] [blame] | 125 | 'types': ['lite'], |
Kean Mariotti | 487a539 | 2024-04-18 06:58:29 +0000 | [diff] [blame] | 126 | 'targets': [ |
| 127 | '//protos/perfetto/trace:non_minimal_source_set', |
| 128 | '//protos/perfetto/trace:minimal_source_set', |
| 129 | ] |
| 130 | }, |
Kean Mariotti | 34af6df | 2024-03-07 10:11:15 +0000 | [diff] [blame] | 131 | 'winscope': { |
| 132 | 'types': ['filegroup'], |
| 133 | 'targets': [ |
| 134 | '//protos/perfetto/trace:non_minimal_source_set', |
| 135 | '//protos/perfetto/trace/android:winscope_extensions:source_set', |
| 136 | ] |
| 137 | }, |
Kean Mariotti | 487a539 | 2024-04-18 06:58:29 +0000 | [diff] [blame] | 138 | 'config': { |
| 139 | 'types': ['lite'], |
| 140 | 'targets': [ |
| 141 | '//protos/perfetto/config:source_set', |
| 142 | ] |
| 143 | }, |
Lalit Maganti | d7afbb1 | 2022-03-28 15:12:24 +0100 | [diff] [blame] | 144 | } |
| 145 | |
Daniele Di Proietto | cb42600 | 2023-02-16 12:14:38 +0000 | [diff] [blame] | 146 | needs_libfts = [ |
| 147 | '//:perfetto_unittests', |
| 148 | '//src/trace_processor:trace_processor_shell', |
| 149 | '//src/traceconv:traceconv', |
| 150 | ] |
| 151 | |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 152 | # All module names are prefixed with this string to avoid collisions. |
| 153 | module_prefix = 'perfetto_' |
| 154 | |
| 155 | # Shared libraries which are directly translated to Android system equivalents. |
Primiano Tucci | a364520 | 2020-08-03 16:28:18 +0200 | [diff] [blame] | 156 | shared_library_allowlist = [ |
Hector Dearman | 64f2e05 | 2019-12-04 20:51:14 +0000 | [diff] [blame] | 157 | 'android', |
Hector Dearman | 92d7d11 | 2019-12-05 15:19:57 +0000 | [diff] [blame] | 158 | 'android.hardware.atrace@1.0', |
| 159 | 'android.hardware.health@2.0', |
Jack Wu | 40d043b | 2022-11-24 20:54:45 +0800 | [diff] [blame] | 160 | 'android.hardware.health-V2-ndk', |
Hector Dearman | 92d7d11 | 2019-12-05 15:19:57 +0000 | [diff] [blame] | 161 | 'android.hardware.power.stats@1.0', |
Hector Dearman | ae979e0 | 2023-03-13 16:13:30 +0000 | [diff] [blame] | 162 | 'android.hardware.power.stats-V1-cpp', |
Primiano Tucci | 676f0cc | 2018-12-03 20:03:26 +0100 | [diff] [blame] | 163 | 'base', |
Sami Kyostila | b5b7169 | 2018-01-12 12:16:44 +0000 | [diff] [blame] | 164 | 'binder', |
Raymond Chiu | 8c4d9a2 | 2021-02-23 19:59:10 +0000 | [diff] [blame] | 165 | 'binder_ndk', |
Hector Dearman | 92d7d11 | 2019-12-05 15:19:57 +0000 | [diff] [blame] | 166 | 'cutils', |
Primiano Tucci | 676f0cc | 2018-12-03 20:03:26 +0100 | [diff] [blame] | 167 | 'hidlbase', |
| 168 | 'hidltransport', |
| 169 | 'hwbinder', |
Ryan Savitski | 53ca60b | 2019-06-03 13:04:40 +0100 | [diff] [blame] | 170 | 'incident', |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 171 | 'log', |
Sami Kyostila | b5b7169 | 2018-01-12 12:16:44 +0000 | [diff] [blame] | 172 | 'services', |
Hector Dearman | 92d7d11 | 2019-12-05 15:19:57 +0000 | [diff] [blame] | 173 | 'statssocket', |
Hector Dearman | ae979e0 | 2023-03-13 16:13:30 +0000 | [diff] [blame] | 174 | 'tracingproxy', |
Primiano Tucci | edf099c | 2018-01-08 18:27:56 +0000 | [diff] [blame] | 175 | 'utils', |
Hector Dearman | ff7abd4 | 2023-03-22 19:11:35 +0000 | [diff] [blame] | 176 | 'statspull', |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 177 | ] |
| 178 | |
Hector Dearman | 92d7d11 | 2019-12-05 15:19:57 +0000 | [diff] [blame] | 179 | # Static libraries which are directly translated to Android system equivalents. |
Primiano Tucci | a364520 | 2020-08-03 16:28:18 +0200 | [diff] [blame] | 180 | static_library_allowlist = [ |
Hector Dearman | 92d7d11 | 2019-12-05 15:19:57 +0000 | [diff] [blame] | 181 | 'statslog_perfetto', |
| 182 | ] |
| 183 | |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 184 | # Name of the module which settings such as compiler flags for all other |
| 185 | # modules. |
| 186 | defaults_module = module_prefix + 'defaults' |
| 187 | |
| 188 | # Location of the project in the Android source tree. |
| 189 | tree_path = 'external/perfetto' |
| 190 | |
Lalit Maganti | 3b09a3f | 2020-09-14 13:28:44 +0100 | [diff] [blame] | 191 | # Path for the protobuf sources in the standalone build. |
| 192 | buildtools_protobuf_src = '//buildtools/protobuf/src' |
| 193 | |
| 194 | # Location of the protobuf src dir in the Android source tree. |
| 195 | android_protobuf_src = 'external/protobuf/src' |
| 196 | |
Primiano Tucci | edf099c | 2018-01-08 18:27:56 +0000 | [diff] [blame] | 197 | # Compiler flags which are passed through to the blueprint. |
Primiano Tucci | a364520 | 2020-08-03 16:28:18 +0200 | [diff] [blame] | 198 | cflag_allowlist = r'^-DPERFETTO.*$' |
Primiano Tucci | edf099c | 2018-01-08 18:27:56 +0000 | [diff] [blame] | 199 | |
Florian Mayer | 3d5e7e6 | 2018-01-19 15:22:46 +0000 | [diff] [blame] | 200 | # Compiler defines which are passed through to the blueprint. |
Lalit Maganti | fa957e7 | 2023-03-16 18:22:23 +0000 | [diff] [blame] | 201 | define_allowlist = r'^(GOOGLE_PROTO.*)|(ZLIB_.*)|(USE_MMAP)$' |
Florian Mayer | 3d5e7e6 | 2018-01-19 15:22:46 +0000 | [diff] [blame] | 202 | |
Primiano Tucci | 8e62744 | 2019-08-28 07:58:38 +0200 | [diff] [blame] | 203 | # The directory where the generated perfetto_build_flags.h will be copied into. |
| 204 | buildflags_dir = 'include/perfetto/base/build_configs/android_tree' |
| 205 | |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 206 | def enumerate_data_deps(): |
| 207 | with open(os.path.join(ROOT_DIR, 'tools', 'test_data.txt')) as f: |
| 208 | lines = f.readlines() |
| 209 | for line in (line.strip() for line in lines if not line.startswith('#')): |
Andrew Shulaev | 576054d | 2020-01-23 13:44:51 +0000 | [diff] [blame] | 210 | assert os.path.exists(line), 'file %s should exist' % line |
Primiano Tucci | 0269116 | 2020-01-21 13:30:13 +0000 | [diff] [blame] | 211 | if line.startswith('test/data/'): |
Lalit Maganti | 9c2318c | 2021-05-20 16:21:41 +0100 | [diff] [blame] | 212 | # Skip test data files that require GCS. They are only for benchmarks. |
| 213 | # We don't run benchmarks in the android tree. |
| 214 | continue |
Primiano Tucci | 17e8ae9 | 2021-05-17 17:40:50 +0100 | [diff] [blame] | 215 | if line.endswith('/.'): |
| 216 | yield line[:-1] + '**/*' |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 217 | else: |
| 218 | yield line |
| 219 | |
| 220 | |
Florian Mayer | b6a921f | 2018-10-18 18:55:23 +0100 | [diff] [blame] | 221 | # Additional arguments to apply to Android.bp rules. |
| 222 | additional_args = { |
Florian Mayer | 23f7937 | 2020-06-16 14:37:06 +0200 | [diff] [blame] | 223 | 'heapprofd_client_api': [ |
Florian Mayer | 23f7937 | 2020-06-16 14:37:06 +0200 | [diff] [blame] | 224 | ('static_libs', {'libasync_safe'}), |
Florian Mayer | 33159f7 | 2020-07-01 13:41:32 +0100 | [diff] [blame] | 225 | # heapprofd_client_api MUST NOT have global constructors. Because it |
| 226 | # is loaded in an __attribute__((constructor)) of libc, we cannot |
| 227 | # guarantee that the global constructors get run before it is used. |
| 228 | ('cflags', {'-Wglobal-constructors', '-Werror=global-constructors'}), |
Florian Mayer | 2131e36 | 2020-07-15 16:30:35 +0100 | [diff] [blame] | 229 | ('version_script', 'src/profiling/memory/heapprofd_client_api.map.txt'), |
Florian Mayer | 7ed3a95 | 2021-01-08 10:55:25 +0000 | [diff] [blame] | 230 | ('stubs', { |
Lalit Maganti | 9c2318c | 2021-05-20 16:21:41 +0100 | [diff] [blame] | 231 | 'versions': ['S'], |
| 232 | 'symbol_file': 'src/profiling/memory/heapprofd_client_api.map.txt', |
Florian Mayer | 5d09f5e | 2021-02-19 14:59:49 +0000 | [diff] [blame] | 233 | }), |
| 234 | ('export_include_dirs', {'src/profiling/memory/include'}), |
| 235 | ], |
| 236 | 'heapprofd_api_noop': [ |
| 237 | ('version_script', 'src/profiling/memory/heapprofd_client_api.map.txt'), |
| 238 | ('stubs', { |
Lalit Maganti | 9c2318c | 2021-05-20 16:21:41 +0100 | [diff] [blame] | 239 | 'versions': ['S'], |
| 240 | 'symbol_file': 'src/profiling/memory/heapprofd_client_api.map.txt', |
Florian Mayer | 5d09f5e | 2021-02-19 14:59:49 +0000 | [diff] [blame] | 241 | }), |
| 242 | ('export_include_dirs', {'src/profiling/memory/include'}), |
Florian Mayer | 23f7937 | 2020-06-16 14:37:06 +0200 | [diff] [blame] | 243 | ], |
Primiano Tucci | 676f0cc | 2018-12-03 20:03:26 +0100 | [diff] [blame] | 244 | 'heapprofd_client': [ |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 245 | ('include_dirs', {'bionic/libc'}), |
| 246 | ('static_libs', {'libasync_safe'}), |
Primiano Tucci | 676f0cc | 2018-12-03 20:03:26 +0100 | [diff] [blame] | 247 | ], |
Florian Mayer | 50f07a6 | 2020-07-15 17:15:58 +0100 | [diff] [blame] | 248 | 'heapprofd_standalone_client': [ |
| 249 | ('static_libs', {'libasync_safe'}), |
| 250 | ('version_script', 'src/profiling/memory/heapprofd_client_api.map.txt'), |
Florian Mayer | 5d09f5e | 2021-02-19 14:59:49 +0000 | [diff] [blame] | 251 | ('export_include_dirs', {'src/profiling/memory/include'}), |
Florian Mayer | 23b75a4 | 2020-07-30 15:21:25 +0100 | [diff] [blame] | 252 | ('stl', 'libc++_static'), |
Florian Mayer | 50f07a6 | 2020-07-15 17:15:58 +0100 | [diff] [blame] | 253 | ], |
Ryan Savitski | 703bcab | 2019-12-18 14:38:14 +0000 | [diff] [blame] | 254 | 'perfetto_unittests': [ |
| 255 | ('data', set(enumerate_data_deps())), |
| 256 | ('include_dirs', {'bionic/libc/kernel'}), |
| 257 | ], |
Florian Mayer | ac4f496 | 2020-09-15 10:03:22 +0100 | [diff] [blame] | 258 | 'perfetto_integrationtests': [ |
Lalit Maganti | 9c2318c | 2021-05-20 16:21:41 +0100 | [diff] [blame] | 259 | ('test_suites', {'general-tests'}), |
| 260 | ('test_config', 'PerfettoIntegrationTests.xml'), |
Florian Mayer | ac4f496 | 2020-09-15 10:03:22 +0100 | [diff] [blame] | 261 | ], |
Lalit Maganti | d7afbb1 | 2022-03-28 15:12:24 +0100 | [diff] [blame] | 262 | 'libperfetto_android_internal': [('static_libs', {'libhealthhalutils'}),], |
Lalit Maganti | cdda911 | 2019-11-27 14:19:49 +0000 | [diff] [blame] | 263 | 'trace_processor_shell': [ |
Lalit Maganti | 9c2318c | 2021-05-20 16:21:41 +0100 | [diff] [blame] | 264 | ('strip', { |
| 265 | 'all': True |
| 266 | }), |
| 267 | ('host', { |
| 268 | 'stl': 'libc++_static', |
| 269 | 'dist': { |
| 270 | 'targets': ['sdk_repo'] |
| 271 | }, |
| 272 | }), |
Lalit Maganti | cdda911 | 2019-11-27 14:19:49 +0000 | [diff] [blame] | 273 | ], |
Jiyong Park | d5ea011 | 2020-04-28 18:22:00 +0900 | [diff] [blame] | 274 | 'libperfetto_client_experimental': [ |
Lalit Maganti | 9c2318c | 2021-05-20 16:21:41 +0100 | [diff] [blame] | 275 | ('apex_available', { |
Nikita Putikhin | 94e30a0 | 2023-11-22 14:16:47 +0100 | [diff] [blame] | 276 | '//apex_available:platform', '//apex_available:anyapex' |
Lalit Maganti | 9c2318c | 2021-05-20 16:21:41 +0100 | [diff] [blame] | 277 | }), |
Ryan Zuklie | 101f1b7 | 2022-10-25 16:22:07 -0700 | [diff] [blame] | 278 | ('min_sdk_version', '30'), |
Lalit Maganti | 9c2318c | 2021-05-20 16:21:41 +0100 | [diff] [blame] | 279 | ('shared_libs', {'liblog'}), |
| 280 | ('export_include_dirs', {'include', buildflags_dir}), |
Jiyong Park | d5ea011 | 2020-04-28 18:22:00 +0900 | [diff] [blame] | 281 | ], |
Daniele Di Proietto | ec4864e | 2022-12-14 17:32:38 +0000 | [diff] [blame] | 282 | 'libperfetto_c': [ |
| 283 | ('min_sdk_version', '30'), |
| 284 | ('export_include_dirs', {'include'}), |
| 285 | ('cflags', {'-DPERFETTO_SHLIB_SDK_IMPLEMENTATION'}), |
| 286 | ], |
Jiyong Park | d5ea011 | 2020-04-28 18:22:00 +0900 | [diff] [blame] | 287 | 'perfetto_trace_protos': [ |
Lalit Maganti | 9c2318c | 2021-05-20 16:21:41 +0100 | [diff] [blame] | 288 | ('apex_available', { |
| 289 | '//apex_available:platform', 'com.android.art', |
| 290 | 'com.android.art.debug' |
| 291 | }), |
| 292 | ('min_sdk_version', 'S'), |
Jiyong Park | d5ea011 | 2020-04-28 18:22:00 +0900 | [diff] [blame] | 293 | ], |
Lalit Maganti | 9c2318c | 2021-05-20 16:21:41 +0100 | [diff] [blame] | 294 | 'libperfetto': [('export_include_dirs', {'include', buildflags_dir}),], |
Daniele Di Proietto | e806806 | 2024-02-16 17:54:03 +0000 | [diff] [blame] | 295 | 'perfetto': [('required', {'perfetto_persistent_cfg.pbtxt'}),], |
Florian Mayer | b6a921f | 2018-10-18 18:55:23 +0100 | [diff] [blame] | 296 | } |
| 297 | |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 298 | |
Lalit Maganti | 52f1336 | 2023-01-23 16:38:01 +0000 | [diff] [blame] | 299 | def enable_base_platform(module): |
| 300 | module.srcs.add(':perfetto_base_default_platform') |
| 301 | |
| 302 | |
Primiano Tucci | fbf4a73 | 2019-12-11 00:32:15 +0000 | [diff] [blame] | 303 | def enable_gtest_and_gmock(module): |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 304 | module.static_libs.add('libgmock') |
Primiano Tucci | fbf4a73 | 2019-12-11 00:32:15 +0000 | [diff] [blame] | 305 | module.static_libs.add('libgtest') |
Primiano Tucci | cbbe480 | 2020-02-20 13:19:11 +0000 | [diff] [blame] | 306 | if module.name != 'perfetto_gtest_logcat_printer': |
| 307 | module.whole_static_libs.add('perfetto_gtest_logcat_printer') |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 308 | |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 309 | |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 310 | def enable_protobuf_full(module): |
Lalit Maganti | a97798d | 2020-09-16 17:40:57 +0100 | [diff] [blame] | 311 | if module.type == 'cc_binary_host': |
| 312 | module.static_libs.add('libprotobuf-cpp-full') |
Lalit Maganti | e0986f3 | 2020-09-17 15:35:47 +0100 | [diff] [blame] | 313 | elif module.host_supported: |
| 314 | module.host.static_libs.add('libprotobuf-cpp-full') |
| 315 | module.android.shared_libs.add('libprotobuf-cpp-full') |
Lalit Maganti | a97798d | 2020-09-16 17:40:57 +0100 | [diff] [blame] | 316 | else: |
| 317 | module.shared_libs.add('libprotobuf-cpp-full') |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 318 | |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 319 | |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 320 | def enable_protobuf_lite(module): |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 321 | module.shared_libs.add('libprotobuf-cpp-lite') |
| 322 | |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 323 | |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 324 | def enable_protoc_lib(module): |
Lalit Maganti | 3d415ec | 2019-10-23 17:53:17 +0100 | [diff] [blame] | 325 | if module.type == 'cc_binary_host': |
| 326 | module.static_libs.add('libprotoc') |
| 327 | else: |
| 328 | module.shared_libs.add('libprotoc') |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 329 | |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 330 | |
Florian Mayer | a2fae26 | 2018-08-31 12:10:01 -0700 | [diff] [blame] | 331 | def enable_libunwindstack(module): |
Florian Mayer | 50f07a6 | 2020-07-15 17:15:58 +0100 | [diff] [blame] | 332 | if module.name != 'heapprofd_standalone_client': |
| 333 | module.shared_libs.add('libunwindstack') |
| 334 | module.shared_libs.add('libprocinfo') |
| 335 | module.shared_libs.add('libbase') |
| 336 | else: |
| 337 | module.static_libs.add('libunwindstack') |
| 338 | module.static_libs.add('libprocinfo') |
| 339 | module.static_libs.add('libbase') |
| 340 | module.static_libs.add('liblzma') |
| 341 | module.static_libs.add('libdexfile_support') |
Lalit Maganti | d7afbb1 | 2022-03-28 15:12:24 +0100 | [diff] [blame] | 342 | module.runtime_libs.add('libdexfile') # libdexfile_support dependency |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 343 | |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 344 | |
| 345 | def enable_libunwind(module): |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 346 | # libunwind is disabled on Darwin so we cannot depend on it. |
| 347 | pass |
| 348 | |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 349 | |
Lalit Maganti | 17aa273 | 2019-02-08 15:47:26 +0000 | [diff] [blame] | 350 | def enable_sqlite(module): |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 351 | if module.type == 'cc_binary_host': |
Michael Hoisie | 3e19351 | 2023-11-18 08:13:49 +0000 | [diff] [blame] | 352 | module.static_libs.add('libsqlite_static_noicu') |
Marcin Oczeretko | 1662f18 | 2022-08-18 10:29:46 +0100 | [diff] [blame] | 353 | module.static_libs.add('sqlite_ext_percentile') |
Lalit Maganti | e0986f3 | 2020-09-17 15:35:47 +0100 | [diff] [blame] | 354 | elif module.host_supported: |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 355 | # Copy what the sqlite3 command line tool does. |
| 356 | module.android.shared_libs.add('libsqlite') |
Victor Chang | d0d6590 | 2022-03-10 11:54:27 +0000 | [diff] [blame] | 357 | module.android.shared_libs.add('libicu') |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 358 | module.android.shared_libs.add('liblog') |
| 359 | module.android.shared_libs.add('libutils') |
Marcin Oczeretko | 1662f18 | 2022-08-18 10:29:46 +0100 | [diff] [blame] | 360 | module.android.static_libs.add('sqlite_ext_percentile') |
Michael Hoisie | 3e19351 | 2023-11-18 08:13:49 +0000 | [diff] [blame] | 361 | module.host.static_libs.add('libsqlite_static_noicu') |
Marcin Oczeretko | 1662f18 | 2022-08-18 10:29:46 +0100 | [diff] [blame] | 362 | module.host.static_libs.add('sqlite_ext_percentile') |
Lalit Maganti | e0986f3 | 2020-09-17 15:35:47 +0100 | [diff] [blame] | 363 | else: |
| 364 | module.shared_libs.add('libsqlite') |
Victor Chang | d0d6590 | 2022-03-10 11:54:27 +0000 | [diff] [blame] | 365 | module.shared_libs.add('libicu') |
Lalit Maganti | e0986f3 | 2020-09-17 15:35:47 +0100 | [diff] [blame] | 366 | module.shared_libs.add('liblog') |
| 367 | module.shared_libs.add('libutils') |
Marcin Oczeretko | 1662f18 | 2022-08-18 10:29:46 +0100 | [diff] [blame] | 368 | module.static_libs.add('sqlite_ext_percentile') |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 369 | |
Lalit Maganti | 17aa273 | 2019-02-08 15:47:26 +0000 | [diff] [blame] | 370 | |
Hector Dearman | e0b993f | 2019-05-24 18:48:16 +0100 | [diff] [blame] | 371 | def enable_zlib(module): |
Lalit Maganti | 3d415ec | 2019-10-23 17:53:17 +0100 | [diff] [blame] | 372 | if module.type == 'cc_binary_host': |
| 373 | module.static_libs.add('libz') |
Lalit Maganti | e0986f3 | 2020-09-17 15:35:47 +0100 | [diff] [blame] | 374 | elif module.host_supported: |
| 375 | module.android.shared_libs.add('libz') |
| 376 | module.host.static_libs.add('libz') |
Lalit Maganti | 3d415ec | 2019-10-23 17:53:17 +0100 | [diff] [blame] | 377 | else: |
| 378 | module.shared_libs.add('libz') |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 379 | |
Hector Dearman | e0b993f | 2019-05-24 18:48:16 +0100 | [diff] [blame] | 380 | |
Ryan Savitski | 56bc0c6 | 2020-01-27 13:50:02 +0000 | [diff] [blame] | 381 | def enable_uapi_headers(module): |
| 382 | module.include_dirs.add('bionic/libc/kernel') |
| 383 | |
Lalit Maganti | 9c2318c | 2021-05-20 16:21:41 +0100 | [diff] [blame] | 384 | |
Florian Mayer | 682f05a | 2020-08-11 10:16:54 +0100 | [diff] [blame] | 385 | def enable_bionic_libc_platform_headers_on_android(module): |
| 386 | module.header_libs.add('bionic_libc_platform_headers') |
| 387 | |
Ryan Savitski | 56bc0c6 | 2020-01-27 13:50:02 +0000 | [diff] [blame] | 388 | |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 389 | # Android equivalents for third-party libraries that the upstream project |
| 390 | # depends on. |
| 391 | builtin_deps = { |
Lalit Maganti | 9c2318c | 2021-05-20 16:21:41 +0100 | [diff] [blame] | 392 | '//gn:default_deps': |
| 393 | lambda x: None, |
| 394 | '//gn:gtest_main': |
| 395 | lambda x: None, |
| 396 | '//gn:protoc': |
| 397 | lambda x: None, |
Lalit Maganti | 52f1336 | 2023-01-23 16:38:01 +0000 | [diff] [blame] | 398 | '//gn:base_platform': |
| 399 | enable_base_platform, |
Lalit Maganti | 9c2318c | 2021-05-20 16:21:41 +0100 | [diff] [blame] | 400 | '//gn:gtest_and_gmock': |
| 401 | enable_gtest_and_gmock, |
| 402 | '//gn:libunwind': |
| 403 | enable_libunwind, |
| 404 | '//gn:protobuf_full': |
| 405 | enable_protobuf_full, |
| 406 | '//gn:protobuf_lite': |
| 407 | enable_protobuf_lite, |
| 408 | '//gn:protoc_lib': |
| 409 | enable_protoc_lib, |
| 410 | '//gn:libunwindstack': |
| 411 | enable_libunwindstack, |
| 412 | '//gn:sqlite': |
| 413 | enable_sqlite, |
| 414 | '//gn:zlib': |
| 415 | enable_zlib, |
| 416 | '//gn:bionic_kernel_uapi_headers': |
| 417 | enable_uapi_headers, |
Florian Mayer | 682f05a | 2020-08-11 10:16:54 +0100 | [diff] [blame] | 418 | '//src/profiling/memory:bionic_libc_platform_headers_on_android': |
Lalit Maganti | 9c2318c | 2021-05-20 16:21:41 +0100 | [diff] [blame] | 419 | enable_bionic_libc_platform_headers_on_android, |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | # ---------------------------------------------------------------------------- |
| 423 | # End of configuration. |
| 424 | # ---------------------------------------------------------------------------- |
| 425 | |
| 426 | |
| 427 | class Error(Exception): |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 428 | pass |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 429 | |
| 430 | |
| 431 | class ThrowingArgumentParser(argparse.ArgumentParser): |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 432 | |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 433 | def __init__(self, context): |
| 434 | super(ThrowingArgumentParser, self).__init__() |
| 435 | self.context = context |
| 436 | |
| 437 | def error(self, message): |
| 438 | raise Error('%s: %s' % (self.context, message)) |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 439 | |
| 440 | |
Lalit Maganti | edace41 | 2019-06-18 13:28:28 +0100 | [diff] [blame] | 441 | def write_blueprint_key_value(output, name, value, sort=True): |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 442 | """Writes a Blueprint key-value pair to the output""" |
Lalit Maganti | edace41 | 2019-06-18 13:28:28 +0100 | [diff] [blame] | 443 | |
Lalit Maganti | d7afbb1 | 2022-03-28 15:12:24 +0100 | [diff] [blame] | 444 | if isinstance(value, bool): |
| 445 | if value: |
| 446 | output.append(' %s: true,' % name) |
| 447 | else: |
| 448 | output.append(' %s: false,' % name) |
| 449 | return |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 450 | if not value: |
| 451 | return |
| 452 | if isinstance(value, set): |
| 453 | value = sorted(value) |
| 454 | if isinstance(value, list): |
Colin Cross | 8417233 | 2021-09-14 16:41:33 -0700 | [diff] [blame] | 455 | output.append(' %s: [' % name) |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 456 | for item in sorted(value) if sort else value: |
Colin Cross | 8417233 | 2021-09-14 16:41:33 -0700 | [diff] [blame] | 457 | output.append(' "%s",' % item) |
| 458 | output.append(' ],') |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 459 | return |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 460 | if isinstance(value, Target): |
| 461 | value.to_string(output) |
| 462 | return |
Lalit Maganti | cdda911 | 2019-11-27 14:19:49 +0000 | [diff] [blame] | 463 | if isinstance(value, dict): |
| 464 | kv_output = [] |
| 465 | for k, v in value.items(): |
| 466 | write_blueprint_key_value(kv_output, k, v) |
| 467 | |
Colin Cross | 8417233 | 2021-09-14 16:41:33 -0700 | [diff] [blame] | 468 | output.append(' %s: {' % name) |
Lalit Maganti | cdda911 | 2019-11-27 14:19:49 +0000 | [diff] [blame] | 469 | for line in kv_output: |
Colin Cross | 8417233 | 2021-09-14 16:41:33 -0700 | [diff] [blame] | 470 | output.append(' %s' % line) |
| 471 | output.append(' },') |
Lalit Maganti | cdda911 | 2019-11-27 14:19:49 +0000 | [diff] [blame] | 472 | return |
Colin Cross | 8417233 | 2021-09-14 16:41:33 -0700 | [diff] [blame] | 473 | output.append(' %s: "%s",' % (name, value)) |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 474 | |
Lalit Maganti | edace41 | 2019-06-18 13:28:28 +0100 | [diff] [blame] | 475 | |
| 476 | class Target(object): |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 477 | """A target-scoped part of a module""" |
Lalit Maganti | edace41 | 2019-06-18 13:28:28 +0100 | [diff] [blame] | 478 | |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 479 | def __init__(self, name): |
| 480 | self.name = name |
| 481 | self.shared_libs = set() |
| 482 | self.static_libs = set() |
Primiano Tucci | cbbe480 | 2020-02-20 13:19:11 +0000 | [diff] [blame] | 483 | self.whole_static_libs = set() |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 484 | self.cflags = set() |
Florian Mayer | 637513a | 2020-12-04 19:15:49 +0000 | [diff] [blame] | 485 | self.dist = dict() |
| 486 | self.strip = dict() |
Lalit Maganti | e0986f3 | 2020-09-17 15:35:47 +0100 | [diff] [blame] | 487 | self.stl = None |
Lalit Maganti | edace41 | 2019-06-18 13:28:28 +0100 | [diff] [blame] | 488 | |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 489 | def to_string(self, output): |
| 490 | nested_out = [] |
| 491 | self._output_field(nested_out, 'shared_libs') |
| 492 | self._output_field(nested_out, 'static_libs') |
Primiano Tucci | cbbe480 | 2020-02-20 13:19:11 +0000 | [diff] [blame] | 493 | self._output_field(nested_out, 'whole_static_libs') |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 494 | self._output_field(nested_out, 'cflags') |
Lalit Maganti | e0986f3 | 2020-09-17 15:35:47 +0100 | [diff] [blame] | 495 | self._output_field(nested_out, 'stl') |
Florian Mayer | 637513a | 2020-12-04 19:15:49 +0000 | [diff] [blame] | 496 | self._output_field(nested_out, 'dist') |
| 497 | self._output_field(nested_out, 'strip') |
Lalit Maganti | edace41 | 2019-06-18 13:28:28 +0100 | [diff] [blame] | 498 | |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 499 | if nested_out: |
Colin Cross | 8417233 | 2021-09-14 16:41:33 -0700 | [diff] [blame] | 500 | output.append(' %s: {' % self.name) |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 501 | for line in nested_out: |
Colin Cross | 8417233 | 2021-09-14 16:41:33 -0700 | [diff] [blame] | 502 | output.append(' %s' % line) |
| 503 | output.append(' },') |
Lalit Maganti | edace41 | 2019-06-18 13:28:28 +0100 | [diff] [blame] | 504 | |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 505 | def _output_field(self, output, name, sort=True): |
| 506 | value = getattr(self, name) |
| 507 | return write_blueprint_key_value(output, name, value, sort) |
| 508 | |
Lalit Maganti | edace41 | 2019-06-18 13:28:28 +0100 | [diff] [blame] | 509 | |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 510 | class Module(object): |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 511 | """A single module (e.g., cc_binary, cc_test) in a blueprint.""" |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 512 | |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 513 | def __init__(self, mod_type, name, gn_target): |
Lalit Maganti | 01f9b05 | 2022-12-17 01:21:13 +0000 | [diff] [blame] | 514 | assert (gn_target) |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 515 | self.type = mod_type |
| 516 | self.gn_target = gn_target |
| 517 | self.name = name |
| 518 | self.srcs = set() |
Lalit Maganti | 921a3d6 | 2022-12-17 14:28:50 +0000 | [diff] [blame] | 519 | self.main: Optional[str] = None |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 520 | self.comment = 'GN: ' + gn_utils.label_without_toolchain(gn_target) |
| 521 | self.shared_libs = set() |
| 522 | self.static_libs = set() |
Primiano Tucci | cbbe480 | 2020-02-20 13:19:11 +0000 | [diff] [blame] | 523 | self.whole_static_libs = set() |
Martin Stjernholm | be2411d | 2021-08-26 21:15:10 +0100 | [diff] [blame] | 524 | self.runtime_libs = set() |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 525 | self.tools = set() |
Lalit Maganti | 921a3d6 | 2022-12-17 14:28:50 +0000 | [diff] [blame] | 526 | self.cmd: Optional[str] = None |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 527 | self.host_supported = False |
Michael Eastwood | 6cbbff1 | 2021-12-09 15:34:35 -0800 | [diff] [blame] | 528 | self.vendor_available = False |
Nikita Putikhin | 94e30a0 | 2023-11-22 14:16:47 +0100 | [diff] [blame] | 529 | self.product_available = False |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 530 | self.init_rc = set() |
| 531 | self.out = set() |
| 532 | self.export_include_dirs = set() |
| 533 | self.generated_headers = set() |
| 534 | self.export_generated_headers = set() |
| 535 | self.defaults = set() |
| 536 | self.cflags = set() |
| 537 | self.include_dirs = set() |
| 538 | self.header_libs = set() |
| 539 | self.required = set() |
| 540 | self.user_debug_flag = False |
Lalit Maganti | 921a3d6 | 2022-12-17 14:28:50 +0000 | [diff] [blame] | 541 | self.tool_files: Optional[List[str]] = None |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 542 | self.android = Target('android') |
| 543 | self.host = Target('host') |
Daniele Di Proietto | cb42600 | 2023-02-16 12:14:38 +0000 | [diff] [blame] | 544 | self.musl = Target('musl') |
Lalit Maganti | 921a3d6 | 2022-12-17 14:28:50 +0000 | [diff] [blame] | 545 | self.lto: Optional[bool] = None |
Lalit Maganti | cdda911 | 2019-11-27 14:19:49 +0000 | [diff] [blame] | 546 | self.stl = None |
| 547 | self.dist = dict() |
Lalit Maganti | accd64b | 2020-03-16 19:54:10 +0000 | [diff] [blame] | 548 | self.strip = dict() |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 549 | self.data = set() |
Jiyong Park | d5ea011 | 2020-04-28 18:22:00 +0900 | [diff] [blame] | 550 | self.apex_available = set() |
Primiano Tucci | 39097c5 | 2021-03-04 09:58:06 +0000 | [diff] [blame] | 551 | self.min_sdk_version = None |
Lalit Maganti | d7afbb1 | 2022-03-28 15:12:24 +0100 | [diff] [blame] | 552 | self.proto = dict() |
Pablo Gamito | 40e6e68 | 2023-12-04 12:04:33 +0000 | [diff] [blame] | 553 | self.output_extension: Optional[str] = None |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 554 | # The genrule_XXX below are properties that must to be propagated back |
| 555 | # on the module(s) that depend on the genrule. |
| 556 | self.genrule_headers = set() |
| 557 | self.genrule_srcs = set() |
| 558 | self.genrule_shared_libs = set() |
Florian Mayer | 2131e36 | 2020-07-15 16:30:35 +0100 | [diff] [blame] | 559 | self.version_script = None |
Florian Mayer | ac4f496 | 2020-09-15 10:03:22 +0100 | [diff] [blame] | 560 | self.test_suites = set() |
Florian Mayer | ab23f44 | 2021-02-09 15:37:45 +0000 | [diff] [blame] | 561 | self.test_config = None |
Florian Mayer | 7ed3a95 | 2021-01-08 10:55:25 +0000 | [diff] [blame] | 562 | self.stubs = {} |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 563 | |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 564 | def to_string(self, output): |
| 565 | if self.comment: |
| 566 | output.append('// %s' % self.comment) |
| 567 | output.append('%s {' % self.type) |
| 568 | self._output_field(output, 'name') |
| 569 | self._output_field(output, 'srcs') |
| 570 | self._output_field(output, 'shared_libs') |
| 571 | self._output_field(output, 'static_libs') |
Primiano Tucci | cbbe480 | 2020-02-20 13:19:11 +0000 | [diff] [blame] | 572 | self._output_field(output, 'whole_static_libs') |
Martin Stjernholm | be2411d | 2021-08-26 21:15:10 +0100 | [diff] [blame] | 573 | self._output_field(output, 'runtime_libs') |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 574 | self._output_field(output, 'tools') |
| 575 | self._output_field(output, 'cmd', sort=False) |
Lalit Maganti | d7afbb1 | 2022-03-28 15:12:24 +0100 | [diff] [blame] | 576 | if self.host_supported: |
| 577 | self._output_field(output, 'host_supported') |
| 578 | if self.vendor_available: |
| 579 | self._output_field(output, 'vendor_available') |
Nikita Putikhin | 94e30a0 | 2023-11-22 14:16:47 +0100 | [diff] [blame] | 580 | if self.product_available: |
| 581 | self._output_field(output, 'product_available') |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 582 | self._output_field(output, 'init_rc') |
| 583 | self._output_field(output, 'out') |
| 584 | self._output_field(output, 'export_include_dirs') |
| 585 | self._output_field(output, 'generated_headers') |
| 586 | self._output_field(output, 'export_generated_headers') |
| 587 | self._output_field(output, 'defaults') |
| 588 | self._output_field(output, 'cflags') |
| 589 | self._output_field(output, 'include_dirs') |
| 590 | self._output_field(output, 'header_libs') |
| 591 | self._output_field(output, 'required') |
Lalit Maganti | cdda911 | 2019-11-27 14:19:49 +0000 | [diff] [blame] | 592 | self._output_field(output, 'dist') |
Lalit Maganti | accd64b | 2020-03-16 19:54:10 +0000 | [diff] [blame] | 593 | self._output_field(output, 'strip') |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 594 | self._output_field(output, 'tool_files') |
| 595 | self._output_field(output, 'data') |
Lalit Maganti | cdda911 | 2019-11-27 14:19:49 +0000 | [diff] [blame] | 596 | self._output_field(output, 'stl') |
Jiyong Park | d5ea011 | 2020-04-28 18:22:00 +0900 | [diff] [blame] | 597 | self._output_field(output, 'apex_available') |
Primiano Tucci | 39097c5 | 2021-03-04 09:58:06 +0000 | [diff] [blame] | 598 | self._output_field(output, 'min_sdk_version') |
Florian Mayer | 2131e36 | 2020-07-15 16:30:35 +0100 | [diff] [blame] | 599 | self._output_field(output, 'version_script') |
Florian Mayer | ac4f496 | 2020-09-15 10:03:22 +0100 | [diff] [blame] | 600 | self._output_field(output, 'test_suites') |
Florian Mayer | ab23f44 | 2021-02-09 15:37:45 +0000 | [diff] [blame] | 601 | self._output_field(output, 'test_config') |
Florian Mayer | 7ed3a95 | 2021-01-08 10:55:25 +0000 | [diff] [blame] | 602 | self._output_field(output, 'stubs') |
Lalit Maganti | d7afbb1 | 2022-03-28 15:12:24 +0100 | [diff] [blame] | 603 | self._output_field(output, 'proto') |
Lalit Maganti | 3dc8e30 | 2022-12-01 20:32:46 +0000 | [diff] [blame] | 604 | self._output_field(output, 'main') |
Pablo Gamito | 40e6e68 | 2023-12-04 12:04:33 +0000 | [diff] [blame] | 605 | self._output_field(output, 'output_extension') |
Lalit Maganti | d8b1a1d | 2018-05-23 14:41:43 +0100 | [diff] [blame] | 606 | |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 607 | target_out = [] |
| 608 | self._output_field(target_out, 'android') |
| 609 | self._output_field(target_out, 'host') |
Daniele Di Proietto | cb42600 | 2023-02-16 12:14:38 +0000 | [diff] [blame] | 610 | self._output_field(target_out, 'musl') |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 611 | if target_out: |
Colin Cross | 8417233 | 2021-09-14 16:41:33 -0700 | [diff] [blame] | 612 | output.append(' target: {') |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 613 | for line in target_out: |
Colin Cross | 8417233 | 2021-09-14 16:41:33 -0700 | [diff] [blame] | 614 | output.append(' %s' % line) |
| 615 | output.append(' },') |
Lalit Maganti | edace41 | 2019-06-18 13:28:28 +0100 | [diff] [blame] | 616 | |
Colin Cross | 162b48e | 2021-09-14 17:01:50 -0700 | [diff] [blame] | 617 | if self.user_debug_flag: |
Colin Cross | 8417233 | 2021-09-14 16:41:33 -0700 | [diff] [blame] | 618 | output.append(' product_variables: {') |
Colin Cross | 162b48e | 2021-09-14 17:01:50 -0700 | [diff] [blame] | 619 | output.append(' debuggable: {') |
| 620 | output.append( |
| 621 | ' cflags: ["-DPERFETTO_BUILD_WITH_ANDROID_USERDEBUG"],') |
| 622 | output.append(' },') |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 623 | output.append(' },') |
Colin Cross | 8417233 | 2021-09-14 16:41:33 -0700 | [diff] [blame] | 624 | if self.lto is not None: |
| 625 | output.append(' target: {') |
| 626 | output.append(' android: {') |
| 627 | output.append(' lto: {') |
Lalit Maganti | d7afbb1 | 2022-03-28 15:12:24 +0100 | [diff] [blame] | 628 | output.append(' thin: %s,' % |
| 629 | 'true' if self.lto else 'false') |
Colin Cross | 8417233 | 2021-09-14 16:41:33 -0700 | [diff] [blame] | 630 | output.append(' },') |
| 631 | output.append(' },') |
| 632 | output.append(' },') |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 633 | output.append('}') |
| 634 | output.append('') |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 635 | |
Lalit Maganti | e0986f3 | 2020-09-17 15:35:47 +0100 | [diff] [blame] | 636 | def add_android_static_lib(self, lib): |
| 637 | if self.type == 'cc_binary_host': |
| 638 | raise Exception('Adding Android static lib for host tool is unsupported') |
| 639 | elif self.host_supported: |
| 640 | self.android.static_libs.add(lib) |
| 641 | else: |
| 642 | self.static_libs.add(lib) |
| 643 | |
Lalit Maganti | e0986f3 | 2020-09-17 15:35:47 +0100 | [diff] [blame] | 644 | def add_android_shared_lib(self, lib): |
| 645 | if self.type == 'cc_binary_host': |
| 646 | raise Exception('Adding Android shared lib for host tool is unsupported') |
| 647 | elif self.host_supported: |
| 648 | self.android.shared_libs.add(lib) |
| 649 | else: |
| 650 | self.shared_libs.add(lib) |
| 651 | |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 652 | def _output_field(self, output, name, sort=True): |
| 653 | value = getattr(self, name) |
| 654 | return write_blueprint_key_value(output, name, value, sort) |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 655 | |
| 656 | |
| 657 | class Blueprint(object): |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 658 | """In-memory representation of an Android.bp file.""" |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 659 | |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 660 | def __init__(self): |
Lalit Maganti | 27b00af | 2022-12-17 01:20:38 +0000 | [diff] [blame] | 661 | self.modules: Dict[str, Module] = {} |
| 662 | self.gn_target_to_module: Dict[str, Module] = {} |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 663 | |
Lalit Maganti | 27b00af | 2022-12-17 01:20:38 +0000 | [diff] [blame] | 664 | def add_module(self, module: Module): |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 665 | """Adds a new module to the blueprint, replacing any existing module |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 666 | with the same name. |
| 667 | |
| 668 | Args: |
| 669 | module: Module instance. |
| 670 | """ |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 671 | self.modules[module.name] = module |
Lalit Maganti | 27b00af | 2022-12-17 01:20:38 +0000 | [diff] [blame] | 672 | self.gn_target_to_module[module.gn_target] = module |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 673 | |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 674 | def to_string(self, output): |
| 675 | for m in sorted(itervalues(self.modules), key=lambda m: m.name): |
| 676 | m.to_string(output) |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 677 | |
| 678 | |
Lalit Maganti | 921a3d6 | 2022-12-17 14:28:50 +0000 | [diff] [blame] | 679 | def label_to_module_name(label: str): |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 680 | """Turn a GN label (e.g., //:perfetto_tests) into a module name.""" |
| 681 | # If the label is explicibly listed in the default target list, don't prefix |
| 682 | # its name and return just the target name. This is so tools like |
Hector Dearman | a9545e5 | 2022-05-17 12:23:25 +0100 | [diff] [blame] | 683 | # "traceconv" stay as such in the Android tree. |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 684 | label_without_toolchain = gn_utils.label_without_toolchain(label) |
| 685 | if label in default_targets or label_without_toolchain in default_targets: |
| 686 | return label_without_toolchain.split(':')[-1] |
Primiano Tucci | 02c1176 | 2019-08-30 00:57:59 +0200 | [diff] [blame] | 687 | |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 688 | module = re.sub(r'^//:?', '', label_without_toolchain) |
| 689 | module = re.sub(r'[^a-zA-Z0-9_]', '_', module) |
| 690 | if not module.startswith(module_prefix): |
| 691 | return module_prefix + module |
| 692 | return module |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 693 | |
| 694 | |
Lalit Maganti | 921a3d6 | 2022-12-17 14:28:50 +0000 | [diff] [blame] | 695 | def is_supported_source_file(name: str): |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 696 | """Returns True if |name| can appear in a 'srcs' list.""" |
| 697 | return os.path.splitext(name)[1] in ['.c', '.cc', '.proto'] |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 698 | |
| 699 | |
Lalit Maganti | 921a3d6 | 2022-12-17 14:28:50 +0000 | [diff] [blame] | 700 | def create_proto_modules(blueprint: Blueprint, gn: GnParser, |
| 701 | target: GnParser.Target): |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 702 | """Generate genrules for a proto GN target. |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 703 | |
| 704 | GN actions are used to dynamically generate files during the build. The |
| 705 | Soong equivalent is a genrule. This function turns a specific kind of |
| 706 | genrule which turns .proto files into source and header files into a pair |
Sami Kyostila | 71625d7 | 2017-12-18 10:29:49 +0000 | [diff] [blame] | 707 | equivalent genrules. |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 708 | |
| 709 | Args: |
| 710 | blueprint: Blueprint instance which is being generated. |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 711 | target: gn_utils.Target object. |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 712 | |
| 713 | Returns: |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 714 | The source_genrule module. |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 715 | """ |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 716 | assert (target.type == 'proto_library') |
Lalit Maganti | 117272f | 2020-09-11 14:01:18 +0100 | [diff] [blame] | 717 | |
Lalit Maganti | 921a3d6 | 2022-12-17 14:28:50 +0000 | [diff] [blame] | 718 | # We don't generate any targets for source_set proto modules because |
| 719 | # they will be inlined into other modules if required. |
| 720 | if target.proto_plugin == 'source_set': |
| 721 | return None |
| 722 | |
Lalit Maganti | 117272f | 2020-09-11 14:01:18 +0100 | [diff] [blame] | 723 | tools = {'aprotoc'} |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 724 | cpp_out_dir = '$(genDir)/%s/' % tree_path |
Lalit Maganti | 117272f | 2020-09-11 14:01:18 +0100 | [diff] [blame] | 725 | target_module_name = label_to_module_name(target.name) |
| 726 | |
| 727 | # In GN builds the proto path is always relative to the output directory |
| 728 | # (out/tmp.xxx). |
Primiano Tucci | 3aa027d | 2019-11-22 21:43:43 +0000 | [diff] [blame] | 729 | cmd = ['mkdir -p %s &&' % cpp_out_dir, '$(location aprotoc)'] |
Lalit Maganti | 117272f | 2020-09-11 14:01:18 +0100 | [diff] [blame] | 730 | cmd += ['--proto_path=%s' % tree_path] |
| 731 | |
Spandan Das | 34f1b98 | 2023-10-13 23:24:01 +0000 | [diff] [blame] | 732 | tool_files = set() |
Lalit Maganti | 3b09a3f | 2020-09-14 13:28:44 +0100 | [diff] [blame] | 733 | if buildtools_protobuf_src in target.proto_paths: |
| 734 | cmd += ['--proto_path=%s' % android_protobuf_src] |
Spandan Das | 34f1b98 | 2023-10-13 23:24:01 +0000 | [diff] [blame] | 735 | # Add `google/protobuf/descriptor.proto` to implicit deps |
| 736 | tool_files.add(':libprotobuf-internal-descriptor-proto') |
Lalit Maganti | 3b09a3f | 2020-09-14 13:28:44 +0100 | [diff] [blame] | 737 | |
Lalit Maganti | 117272f | 2020-09-11 14:01:18 +0100 | [diff] [blame] | 738 | # Descriptor targets only generate a single target. |
| 739 | if target.proto_plugin == 'descriptor': |
| 740 | out = '{}.bin'.format(target_module_name) |
| 741 | |
Lalit Maganti | fe422eb | 2020-11-12 14:00:09 +0000 | [diff] [blame] | 742 | cmd += ['--descriptor_set_out=$(out)'] |
Lalit Maganti | 117272f | 2020-09-11 14:01:18 +0100 | [diff] [blame] | 743 | cmd += ['$(in)'] |
| 744 | |
| 745 | descriptor_module = Module('genrule', target_module_name, target.name) |
| 746 | descriptor_module.cmd = ' '.join(cmd) |
Lalit Maganti | 921a3d6 | 2022-12-17 14:28:50 +0000 | [diff] [blame] | 747 | descriptor_module.out.add(out) |
Lalit Maganti | 117272f | 2020-09-11 14:01:18 +0100 | [diff] [blame] | 748 | descriptor_module.tools = tools |
| 749 | blueprint.add_module(descriptor_module) |
| 750 | |
Lalit Maganti | fe422eb | 2020-11-12 14:00:09 +0000 | [diff] [blame] | 751 | # Recursively extract the .proto files of all the dependencies and |
| 752 | # add them to srcs. |
Lalit Maganti | d7afbb1 | 2022-03-28 15:12:24 +0100 | [diff] [blame] | 753 | descriptor_module.srcs.update( |
| 754 | gn_utils.label_to_path(src) for src in target.sources) |
Spandan Das | 34f1b98 | 2023-10-13 23:24:01 +0000 | [diff] [blame] | 755 | # Add the tool_files to srcs so that they get copied if this action is |
| 756 | # sandboxed in Soong. |
| 757 | # Add to `srcs` instead of `tool_files` (the latter will require a |
| 758 | # --proto_path that depends on Soong's sandbox implementation.) |
| 759 | descriptor_module.srcs.update( |
| 760 | src for src in tool_files) |
Lalit Maganti | 01f9b05 | 2022-12-17 01:21:13 +0000 | [diff] [blame] | 761 | for dep in target.transitive_proto_deps(): |
| 762 | current_target = gn.get_target(dep.name) |
Lalit Maganti | fe422eb | 2020-11-12 14:00:09 +0000 | [diff] [blame] | 763 | descriptor_module.srcs.update( |
| 764 | gn_utils.label_to_path(src) for src in current_target.sources) |
Lalit Maganti | fe422eb | 2020-11-12 14:00:09 +0000 | [diff] [blame] | 765 | |
Lalit Maganti | 117272f | 2020-09-11 14:01:18 +0100 | [diff] [blame] | 766 | return descriptor_module |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 767 | |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 768 | # We create two genrules for each proto target: one for the headers and |
| 769 | # another for the sources. This is because the module that depends on the |
| 770 | # generated files needs to declare two different types of dependencies -- |
| 771 | # source files in 'srcs' and headers in 'generated_headers' -- and it's not |
| 772 | # valid to generate .h files from a source dependency and vice versa. |
Spandan Das | 34f1b98 | 2023-10-13 23:24:01 +0000 | [diff] [blame] | 773 | # |
| 774 | # We create an additional filegroup for .proto |
| 775 | # The .proto filegroup will be added to `tool_files` of rdeps so that the |
| 776 | # genrules can be sandboxed. |
| 777 | |
Spandan Das | 34f1b98 | 2023-10-13 23:24:01 +0000 | [diff] [blame] | 778 | for proto_dep in target.proto_deps().union(target.transitive_proto_deps()): |
| 779 | tool_files.add(":" + label_to_module_name(proto_dep.name)) |
| 780 | |
| 781 | filegroup_module = Module('filegroup', target_module_name, target.name) |
| 782 | filegroup_module.srcs.update( |
| 783 | gn_utils.label_to_path(src) for src in target.sources) |
| 784 | blueprint.add_module(filegroup_module) |
| 785 | |
Lalit Maganti | 117272f | 2020-09-11 14:01:18 +0100 | [diff] [blame] | 786 | source_module_name = target_module_name + '_gen' |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 787 | source_module = Module('genrule', source_module_name, target.name) |
Spandan Das | 34f1b98 | 2023-10-13 23:24:01 +0000 | [diff] [blame] | 788 | # Add the "root" .proto filegroup to srcs |
| 789 | source_module.srcs = set([':' + target_module_name]) |
| 790 | # Add the tool_files to srcs so that they get copied if this action is |
| 791 | # sandboxed in Soong. |
| 792 | # Add to `srcs` instead of `tool_files` (the latter will require a |
| 793 | # --proto_path that depends on Soong's sandbox implementation.) |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 794 | source_module.srcs.update( |
Spandan Das | 34f1b98 | 2023-10-13 23:24:01 +0000 | [diff] [blame] | 795 | src for src in tool_files) |
| 796 | blueprint.add_module(source_module) |
Primiano Tucci | 20b760c | 2018-01-19 12:36:12 +0000 | [diff] [blame] | 797 | |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 798 | header_module = Module('genrule', source_module_name + '_headers', |
| 799 | target.name) |
| 800 | blueprint.add_module(header_module) |
| 801 | header_module.srcs = set(source_module.srcs) |
Primiano Tucci | 20b760c | 2018-01-19 12:36:12 +0000 | [diff] [blame] | 802 | |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 803 | # TODO(primiano): at some point we should remove this. This was introduced |
| 804 | # by aosp/1108421 when adding "protos/" to .proto include paths, in order to |
| 805 | # avoid doing multi-repo changes and allow old clients in the android tree |
| 806 | # to still do the old #include "perfetto/..." rather than |
| 807 | # #include "protos/perfetto/...". |
| 808 | header_module.export_include_dirs = {'.', 'protos'} |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 809 | |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 810 | source_module.genrule_srcs.add(':' + source_module.name) |
| 811 | source_module.genrule_headers.add(header_module.name) |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 812 | |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 813 | if target.proto_plugin == 'proto': |
Primiano Tucci | 3aa027d | 2019-11-22 21:43:43 +0000 | [diff] [blame] | 814 | suffixes = ['pb'] |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 815 | source_module.genrule_shared_libs.add('libprotobuf-cpp-lite') |
Primiano Tucci | 7b6a788 | 2020-01-20 22:34:31 +0000 | [diff] [blame] | 816 | cmd += ['--cpp_out=lite=true:' + cpp_out_dir] |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 817 | elif target.proto_plugin == 'protozero': |
| 818 | suffixes = ['pbzero'] |
| 819 | plugin = create_modules_from_target(blueprint, gn, protozero_plugin) |
Lalit Maganti | 921a3d6 | 2022-12-17 14:28:50 +0000 | [diff] [blame] | 820 | assert (plugin) |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 821 | tools.add(plugin.name) |
| 822 | cmd += ['--plugin=protoc-gen-plugin=$(location %s)' % plugin.name] |
| 823 | cmd += ['--plugin_out=wrapper_namespace=pbzero:' + cpp_out_dir] |
Primiano Tucci | 57dd66b | 2019-10-15 23:09:04 +0100 | [diff] [blame] | 824 | elif target.proto_plugin == 'cppgen': |
| 825 | suffixes = ['gen'] |
| 826 | plugin = create_modules_from_target(blueprint, gn, cppgen_plugin) |
Lalit Maganti | 921a3d6 | 2022-12-17 14:28:50 +0000 | [diff] [blame] | 827 | assert (plugin) |
Primiano Tucci | 57dd66b | 2019-10-15 23:09:04 +0100 | [diff] [blame] | 828 | tools.add(plugin.name) |
| 829 | cmd += ['--plugin=protoc-gen-plugin=$(location %s)' % plugin.name] |
Primiano Tucci | e8020f9 | 2019-11-26 13:24:01 +0000 | [diff] [blame] | 830 | cmd += ['--plugin_out=wrapper_namespace=gen:' + cpp_out_dir] |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 831 | elif target.proto_plugin == 'ipc': |
Primiano Tucci | 3aa027d | 2019-11-22 21:43:43 +0000 | [diff] [blame] | 832 | suffixes = ['ipc'] |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 833 | plugin = create_modules_from_target(blueprint, gn, ipc_plugin) |
Lalit Maganti | 921a3d6 | 2022-12-17 14:28:50 +0000 | [diff] [blame] | 834 | assert (plugin) |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 835 | tools.add(plugin.name) |
| 836 | cmd += ['--plugin=protoc-gen-plugin=$(location %s)' % plugin.name] |
Primiano Tucci | e8020f9 | 2019-11-26 13:24:01 +0000 | [diff] [blame] | 837 | cmd += ['--plugin_out=wrapper_namespace=gen:' + cpp_out_dir] |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 838 | else: |
| 839 | raise Error('Unsupported proto plugin: %s' % target.proto_plugin) |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 840 | |
Spandan Das | 34f1b98 | 2023-10-13 23:24:01 +0000 | [diff] [blame] | 841 | cmd += ['$(locations :%s)' % target_module_name] |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 842 | source_module.cmd = ' '.join(cmd) |
| 843 | header_module.cmd = source_module.cmd |
| 844 | source_module.tools = tools |
| 845 | header_module.tools = tools |
Primiano Tucci | 20b760c | 2018-01-19 12:36:12 +0000 | [diff] [blame] | 846 | |
Spandan Das | 34f1b98 | 2023-10-13 23:24:01 +0000 | [diff] [blame] | 847 | |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 848 | for sfx in suffixes: |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 849 | source_module.out.update('%s/%s' % |
| 850 | (tree_path, src.replace('.proto', '.%s.cc' % sfx)) |
Spandan Das | 34f1b98 | 2023-10-13 23:24:01 +0000 | [diff] [blame] | 851 | for src in filegroup_module.srcs) |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 852 | header_module.out.update('%s/%s' % |
| 853 | (tree_path, src.replace('.proto', '.%s.h' % sfx)) |
Spandan Das | 34f1b98 | 2023-10-13 23:24:01 +0000 | [diff] [blame] | 854 | for src in filegroup_module.srcs) |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 855 | return source_module |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 856 | |
Sami Kyostila | 3c88a1d | 2019-05-22 18:29:42 +0100 | [diff] [blame] | 857 | |
Lalit Maganti | 921a3d6 | 2022-12-17 14:28:50 +0000 | [diff] [blame] | 858 | def create_tp_tables_module(blueprint: Blueprint, gn: GnParser, |
| 859 | target: GnParser.Target): |
Lalit Maganti | 3dc8e30 | 2022-12-01 20:32:46 +0000 | [diff] [blame] | 860 | bp_module_name = label_to_module_name(target.name) |
| 861 | bp_binary_module_name = f'{bp_module_name}_binary' |
| 862 | srcs = [gn_utils.label_to_path(src) for src in target.sources] |
| 863 | |
Lalit Maganti | 921a3d6 | 2022-12-17 14:28:50 +0000 | [diff] [blame] | 864 | binary_module = Module('python_binary_host', bp_binary_module_name, |
| 865 | target.name) |
Lalit Maganti | 01f9b05 | 2022-12-17 01:21:13 +0000 | [diff] [blame] | 866 | for dep in target.non_proto_or_source_set_deps(): |
| 867 | binary_module.srcs.update([ |
| 868 | gn_utils.label_to_path(src) for src in gn.get_target(dep.name).sources |
| 869 | ]) |
Lalit Maganti | 3dc8e30 | 2022-12-01 20:32:46 +0000 | [diff] [blame] | 870 | binary_module.srcs.update(srcs) |
| 871 | binary_module.srcs.add('tools/gen_tp_table_headers.py') |
| 872 | binary_module.main = 'tools/gen_tp_table_headers.py' |
| 873 | blueprint.add_module(binary_module) |
| 874 | |
| 875 | module = Module('genrule', bp_module_name, target.name) |
| 876 | module.tools = set([ |
| 877 | bp_binary_module_name, |
| 878 | ]) |
| 879 | module.cmd = ' '.join([ |
| 880 | f'$(location {bp_binary_module_name})', |
| 881 | '--gen-dir=$(genDir)', |
Lalit Maganti | 3df8a7e | 2023-04-25 14:18:17 +0100 | [diff] [blame] | 882 | '--relative-input-dir=external/perfetto', |
Lalit Maganti | 3dc8e30 | 2022-12-01 20:32:46 +0000 | [diff] [blame] | 883 | '--inputs', |
| 884 | '$(in)', |
Lalit Maganti | 3dc8e30 | 2022-12-01 20:32:46 +0000 | [diff] [blame] | 885 | ]) |
| 886 | module.out.update(target.outputs) |
| 887 | module.genrule_headers.add(module.name) |
| 888 | module.srcs.update(srcs) |
| 889 | blueprint.add_module(module) |
| 890 | |
| 891 | return module |
| 892 | |
| 893 | |
Lalit Maganti | 01f9b05 | 2022-12-17 01:21:13 +0000 | [diff] [blame] | 894 | def create_amalgamated_sql_module(blueprint: Blueprint, gn: GnParser, |
| 895 | target: GnParser.Target): |
Anna Mayzner | cc18bfd | 2022-11-03 14:05:19 +0000 | [diff] [blame] | 896 | bp_module_name = label_to_module_name(target.name) |
Lalit Maganti | 358a7e4 | 2022-11-09 15:16:21 +0000 | [diff] [blame] | 897 | |
| 898 | def find_arg(name): |
| 899 | for i, arg in enumerate(target.args): |
| 900 | if arg.startswith(f'--{name}'): |
| 901 | return target.args[i + 1] |
| 902 | |
| 903 | namespace = find_arg('namespace') |
Lalit Maganti | 358a7e4 | 2022-11-09 15:16:21 +0000 | [diff] [blame] | 904 | |
Anna Mayzner | cc18bfd | 2022-11-03 14:05:19 +0000 | [diff] [blame] | 905 | module = Module('genrule', bp_module_name, target.name) |
| 906 | module.tool_files = [ |
| 907 | 'tools/gen_amalgamated_sql.py', |
| 908 | ] |
| 909 | module.cmd = ' '.join([ |
| 910 | '$(location tools/gen_amalgamated_sql.py)', |
Lalit Maganti | 358a7e4 | 2022-11-09 15:16:21 +0000 | [diff] [blame] | 911 | f'--namespace={namespace}', |
Lalit Maganti | 358a7e4 | 2022-11-09 15:16:21 +0000 | [diff] [blame] | 912 | '--cpp-out=$(out)', |
Anna Mayzner | cc18bfd | 2022-11-03 14:05:19 +0000 | [diff] [blame] | 913 | '$(in)', |
| 914 | ]) |
| 915 | module.genrule_headers.add(module.name) |
| 916 | module.out.update(target.outputs) |
Lalit Maganti | 358a7e4 | 2022-11-09 15:16:21 +0000 | [diff] [blame] | 917 | |
Lalit Maganti | 3361985 | 2022-12-17 01:22:36 +0000 | [diff] [blame] | 918 | for dep in target.transitive_deps: |
Rasika Navarange | c3634b4 | 2023-11-14 19:45:04 +0000 | [diff] [blame] | 919 | # Use globs for the chrome stdlib so the file does not need to be |
| 920 | # regenerated in autoroll CLs. |
| 921 | if dep.name.startswith( |
| 922 | '//src/trace_processor/perfetto_sql/stdlib/chrome:chrome_sql'): |
| 923 | module.srcs.add('src/trace_processor/perfetto_sql/stdlib/chrome/**/*.sql') |
| 924 | continue |
Lalit Maganti | 358a7e4 | 2022-11-09 15:16:21 +0000 | [diff] [blame] | 925 | module.srcs.update( |
Lalit Maganti | 01f9b05 | 2022-12-17 01:21:13 +0000 | [diff] [blame] | 926 | [gn_utils.label_to_path(src) for src in gn.get_target(dep.name).inputs]) |
Anna Mayzner | cc18bfd | 2022-11-03 14:05:19 +0000 | [diff] [blame] | 927 | blueprint.add_module(module) |
| 928 | return module |
Sami Kyostila | 3c88a1d | 2019-05-22 18:29:42 +0100 | [diff] [blame] | 929 | |
Lalit Maganti | 358a7e4 | 2022-11-09 15:16:21 +0000 | [diff] [blame] | 930 | |
Lalit Maganti | 921a3d6 | 2022-12-17 14:28:50 +0000 | [diff] [blame] | 931 | def create_cc_proto_descriptor_module(blueprint: Blueprint, |
| 932 | target: GnParser.Target): |
Lalit Maganti | 3b09a3f | 2020-09-14 13:28:44 +0100 | [diff] [blame] | 933 | bp_module_name = label_to_module_name(target.name) |
| 934 | module = Module('genrule', bp_module_name, target.name) |
Lalit Maganti | 117272f | 2020-09-11 14:01:18 +0100 | [diff] [blame] | 935 | module.tool_files = [ |
| 936 | 'tools/gen_cc_proto_descriptor.py', |
| 937 | ] |
| 938 | module.cmd = ' '.join([ |
Lalit Maganti | 9c2318c | 2021-05-20 16:21:41 +0100 | [diff] [blame] | 939 | '$(location tools/gen_cc_proto_descriptor.py)', '--gen_dir=$(genDir)', |
| 940 | '--cpp_out=$(out)', '$(in)' |
Lalit Maganti | 117272f | 2020-09-11 14:01:18 +0100 | [diff] [blame] | 941 | ]) |
| 942 | module.genrule_headers.add(module.name) |
| 943 | module.srcs.update( |
Lalit Maganti | 01f9b05 | 2022-12-17 01:21:13 +0000 | [diff] [blame] | 944 | ':' + label_to_module_name(dep.name) for dep in target.proto_deps()) |
Hector Dearman | 2483893 | 2022-07-06 21:57:58 +0100 | [diff] [blame] | 945 | module.srcs.update( |
| 946 | gn_utils.label_to_path(src) |
| 947 | for src in target.inputs |
| 948 | if "tmp.gn_utils" not in src) |
Lalit Maganti | 117272f | 2020-09-11 14:01:18 +0100 | [diff] [blame] | 949 | module.out.update(target.outputs) |
| 950 | blueprint.add_module(module) |
| 951 | return module |
| 952 | |
| 953 | |
Lalit Maganti | 01f9b05 | 2022-12-17 01:21:13 +0000 | [diff] [blame] | 954 | def create_gen_version_module(blueprint: Blueprint, target: GnParser.Target, |
| 955 | bp_module_name: str): |
Primiano Tucci | ec59013 | 2020-11-16 14:16:44 +0100 | [diff] [blame] | 956 | module = Module('genrule', bp_module_name, gn_utils.GEN_VERSION_TARGET) |
| 957 | script_path = gn_utils.label_to_path(target.script) |
| 958 | module.genrule_headers.add(bp_module_name) |
Lalit Maganti | 9c2318c | 2021-05-20 16:21:41 +0100 | [diff] [blame] | 959 | module.tool_files = [script_path] |
Primiano Tucci | ec59013 | 2020-11-16 14:16:44 +0100 | [diff] [blame] | 960 | module.out.update(target.outputs) |
| 961 | module.srcs.update(gn_utils.label_to_path(src) for src in target.inputs) |
| 962 | module.cmd = ' '.join([ |
Lalit Maganti | 9c2318c | 2021-05-20 16:21:41 +0100 | [diff] [blame] | 963 | 'python3 $(location %s)' % script_path, '--no_git', |
| 964 | '--changelog=$(location CHANGELOG)', '--cpp_out=$(out)' |
Primiano Tucci | ec59013 | 2020-11-16 14:16:44 +0100 | [diff] [blame] | 965 | ]) |
| 966 | blueprint.add_module(module) |
| 967 | return module |
| 968 | |
| 969 | |
Lalit Maganti | 01f9b05 | 2022-12-17 01:21:13 +0000 | [diff] [blame] | 970 | def create_proto_group_modules(blueprint, gn: GnParser, module_name: str, |
Kean Mariotti | 487a539 | 2024-04-18 06:58:29 +0000 | [diff] [blame] | 971 | group): |
| 972 | target_names = group['targets'] |
| 973 | module_types = group['types'] |
| 974 | module_sources = set() |
Lalit Maganti | d7afbb1 | 2022-03-28 15:12:24 +0100 | [diff] [blame] | 975 | |
| 976 | for name in target_names: |
| 977 | target = gn.get_target(name) |
Kean Mariotti | 487a539 | 2024-04-18 06:58:29 +0000 | [diff] [blame] | 978 | module_sources.update(gn_utils.label_to_path(src) for src in target.sources) |
Lalit Maganti | 01f9b05 | 2022-12-17 01:21:13 +0000 | [diff] [blame] | 979 | for dep_label in target.transitive_proto_deps(): |
| 980 | dep = gn.get_target(dep_label.name) |
Kean Mariotti | 487a539 | 2024-04-18 06:58:29 +0000 | [diff] [blame] | 981 | module_sources.update(gn_utils.label_to_path(src) for src in dep.sources) |
Lalit Maganti | d7afbb1 | 2022-03-28 15:12:24 +0100 | [diff] [blame] | 982 | |
Kean Mariotti | 487a539 | 2024-04-18 06:58:29 +0000 | [diff] [blame] | 983 | for type in module_types: |
| 984 | if type == 'filegroup': |
| 985 | name = label_to_module_name(module_name) + '_filegroup_proto' |
| 986 | module = Module('filegroup', name, name) |
| 987 | module.comment = f'''GN: [{', '.join(target_names)}]''' |
| 988 | module.srcs = module_sources |
| 989 | blueprint.add_module(module) |
| 990 | elif type == 'lite': |
| 991 | name = label_to_module_name(module_name) + '_java_protos' |
| 992 | module = Module('java_library', name, name) |
| 993 | module.comment = f'''GN: [{', '.join(target_names)}]''' |
| 994 | module.proto = {'type': 'lite', 'canonical_path_from_root': False} |
| 995 | module.srcs = module_sources |
| 996 | blueprint.add_module(module) |
| 997 | else: |
| 998 | raise Error('Unhandled proto group type: {}'.format(group.type)) |
Lalit Maganti | d7afbb1 | 2022-03-28 15:12:24 +0100 | [diff] [blame] | 999 | |
| 1000 | |
Lalit Maganti | 921a3d6 | 2022-12-17 14:28:50 +0000 | [diff] [blame] | 1001 | def _get_cflags(target: GnParser.Target): |
Primiano Tucci | a364520 | 2020-08-03 16:28:18 +0200 | [diff] [blame] | 1002 | cflags = {flag for flag in target.cflags if re.match(cflag_allowlist, flag)} |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1003 | cflags |= set("-D%s" % define |
| 1004 | for define in target.defines |
Primiano Tucci | a364520 | 2020-08-03 16:28:18 +0200 | [diff] [blame] | 1005 | if re.match(define_allowlist, define)) |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1006 | return cflags |
Florian Mayer | 3d5e7e6 | 2018-01-19 15:22:46 +0000 | [diff] [blame] | 1007 | |
| 1008 | |
Lalit Maganti | 921a3d6 | 2022-12-17 14:28:50 +0000 | [diff] [blame] | 1009 | def create_modules_from_target(blueprint: Blueprint, gn: GnParser, |
| 1010 | gn_target_name: str) -> Optional[Module]: |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1011 | """Generate module(s) for a given GN target. |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 1012 | |
| 1013 | Given a GN target name, generate one or more corresponding modules into a |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1014 | blueprint. The only case when this generates >1 module is proto libraries. |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 1015 | |
| 1016 | Args: |
| 1017 | blueprint: Blueprint instance which is being generated. |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1018 | gn: gn_utils.GnParser object. |
| 1019 | gn_target_name: GN target for module generation. |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 1020 | """ |
Lalit Maganti | 27b00af | 2022-12-17 01:20:38 +0000 | [diff] [blame] | 1021 | if gn_target_name in blueprint.gn_target_to_module: |
| 1022 | return blueprint.gn_target_to_module[gn_target_name] |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1023 | |
Lalit Maganti | 27b00af | 2022-12-17 01:20:38 +0000 | [diff] [blame] | 1024 | target = gn.get_target(gn_target_name) |
| 1025 | bp_module_name = label_to_module_name(gn_target_name) |
Lalit Maganti | 9c2318c | 2021-05-20 16:21:41 +0100 | [diff] [blame] | 1026 | name_without_toolchain = gn_utils.label_without_toolchain(target.name) |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1027 | if target.type == 'executable': |
| 1028 | if target.toolchain == gn_utils.HOST_TOOLCHAIN: |
| 1029 | module_type = 'cc_binary_host' |
| 1030 | elif target.testonly: |
| 1031 | module_type = 'cc_test' |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 1032 | else: |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1033 | module_type = 'cc_binary' |
| 1034 | module = Module(module_type, bp_module_name, gn_target_name) |
| 1035 | elif target.type == 'static_library': |
| 1036 | module = Module('cc_library_static', bp_module_name, gn_target_name) |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1037 | elif target.type == 'shared_library': |
| 1038 | module = Module('cc_library_shared', bp_module_name, gn_target_name) |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1039 | elif target.type == 'source_set': |
| 1040 | module = Module('filegroup', bp_module_name, gn_target_name) |
| 1041 | elif target.type == 'group': |
| 1042 | # "group" targets are resolved recursively by gn_utils.get_target(). |
| 1043 | # There's nothing we need to do at this level for them. |
| 1044 | return None |
| 1045 | elif target.type == 'proto_library': |
| 1046 | module = create_proto_modules(blueprint, gn, target) |
Lalit Maganti | 117272f | 2020-09-11 14:01:18 +0100 | [diff] [blame] | 1047 | if module is None: |
| 1048 | return None |
| 1049 | elif target.type == 'action': |
Lalit Maganti | 358a7e4 | 2022-11-09 15:16:21 +0000 | [diff] [blame] | 1050 | if target.custom_action_type == 'sql_amalgamation': |
| 1051 | return create_amalgamated_sql_module(blueprint, gn, target) |
Lalit Maganti | 3dc8e30 | 2022-12-01 20:32:46 +0000 | [diff] [blame] | 1052 | if target.custom_action_type == 'tp_tables': |
| 1053 | return create_tp_tables_module(blueprint, gn, target) |
Lalit Maganti | 358a7e4 | 2022-11-09 15:16:21 +0000 | [diff] [blame] | 1054 | |
Lalit Maganti | b417ff2 | 2022-11-09 15:45:02 +0000 | [diff] [blame] | 1055 | if target.custom_action_type == 'cc_proto_descriptor': |
Lalit Maganti | 3b09a3f | 2020-09-14 13:28:44 +0100 | [diff] [blame] | 1056 | module = create_cc_proto_descriptor_module(blueprint, target) |
Lalit Maganti | 358a7e4 | 2022-11-09 15:16:21 +0000 | [diff] [blame] | 1057 | elif name_without_toolchain == gn_utils.GEN_VERSION_TARGET: |
Primiano Tucci | ec59013 | 2020-11-16 14:16:44 +0100 | [diff] [blame] | 1058 | module = create_gen_version_module(blueprint, target, bp_module_name) |
Hector Dearman | a1d7524 | 2020-10-02 09:47:24 +0100 | [diff] [blame] | 1059 | else: |
| 1060 | raise Error('Unhandled action: {}'.format(target.name)) |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1061 | else: |
| 1062 | raise Error('Unknown target %s (%s)' % (target.name, target.type)) |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 1063 | |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1064 | blueprint.add_module(module) |
Lalit Maganti | 9c2318c | 2021-05-20 16:21:41 +0100 | [diff] [blame] | 1065 | module.host_supported = (name_without_toolchain in target_host_supported) |
Michael Eastwood | 6cbbff1 | 2021-12-09 15:34:35 -0800 | [diff] [blame] | 1066 | module.vendor_available = (name_without_toolchain in target_vendor_available) |
Nikita Putikhin | 94e30a0 | 2023-11-22 14:16:47 +0100 | [diff] [blame] | 1067 | module.product_available = (name_without_toolchain in target_product_available) |
Lalit Maganti | 921a3d6 | 2022-12-17 14:28:50 +0000 | [diff] [blame] | 1068 | module.init_rc.update(target_initrc.get(target.name, [])) |
Spandan Das | 34f1b98 | 2023-10-13 23:24:01 +0000 | [diff] [blame] | 1069 | if target.type != 'proto_library': |
| 1070 | # proto_library embeds a "root" filegroup in its srcs. |
| 1071 | # Skip to prevent adding dups |
| 1072 | module.srcs.update( |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1073 | gn_utils.label_to_path(src) |
| 1074 | for src in target.sources |
| 1075 | if is_supported_source_file(src)) |
Primiano Tucci | 6067e73 | 2018-01-08 16:19:40 +0000 | [diff] [blame] | 1076 | |
Daniele Di Proietto | cb42600 | 2023-02-16 12:14:38 +0000 | [diff] [blame] | 1077 | if name_without_toolchain in needs_libfts: |
| 1078 | module.musl.static_libs.add('libfts') |
| 1079 | |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1080 | if target.type in gn_utils.LINKER_UNIT_TYPES: |
| 1081 | module.cflags.update(_get_cflags(target)) |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 1082 | |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1083 | module_is_compiled = module.type not in ('genrule', 'filegroup') |
| 1084 | if module_is_compiled: |
| 1085 | # Don't try to inject library/source dependencies into genrules or |
| 1086 | # filegroups because they are not compiled in the traditional sense. |
Lalit Maganti | 921a3d6 | 2022-12-17 14:28:50 +0000 | [diff] [blame] | 1087 | module.defaults.update([defaults_module]) |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1088 | for lib in target.libs: |
| 1089 | # Generally library names should be mangled as 'libXXX', unless they |
Yifan Hong | 0011c63 | 2021-12-02 18:37:21 -0800 | [diff] [blame] | 1090 | # are HAL libraries (e.g., android.hardware.health@2.0) or AIDL c++ / NDK |
Raymond Chiu | 8c4d9a2 | 2021-02-23 19:59:10 +0000 | [diff] [blame] | 1091 | # libraries (e.g. "android.hardware.power.stats-V1-cpp") |
Yifan Hong | 0011c63 | 2021-12-02 18:37:21 -0800 | [diff] [blame] | 1092 | android_lib = lib if '@' in lib or "-cpp" in lib or "-ndk" in lib \ |
| 1093 | else 'lib' + lib |
Primiano Tucci | a364520 | 2020-08-03 16:28:18 +0200 | [diff] [blame] | 1094 | if lib in shared_library_allowlist: |
Lalit Maganti | e0986f3 | 2020-09-17 15:35:47 +0100 | [diff] [blame] | 1095 | module.add_android_shared_lib(android_lib) |
Primiano Tucci | a364520 | 2020-08-03 16:28:18 +0200 | [diff] [blame] | 1096 | if lib in static_library_allowlist: |
Lalit Maganti | e0986f3 | 2020-09-17 15:35:47 +0100 | [diff] [blame] | 1097 | module.add_android_static_lib(android_lib) |
Lalit Maganti | c5bcd79 | 2018-01-12 18:38:11 +0000 | [diff] [blame] | 1098 | |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1099 | # If the module is a static library, export all the generated headers. |
| 1100 | if module.type == 'cc_library_static': |
| 1101 | module.export_generated_headers = module.generated_headers |
Ryan Savitski | e65beca | 2019-01-29 18:29:13 +0000 | [diff] [blame] | 1102 | |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1103 | # Merge in additional hardcoded arguments. |
| 1104 | for key, add_val in additional_args.get(module.name, []): |
| 1105 | curr = getattr(module, key) |
| 1106 | if add_val and isinstance(add_val, set) and isinstance(curr, set): |
| 1107 | curr.update(add_val) |
Lalit Maganti | cdda911 | 2019-11-27 14:19:49 +0000 | [diff] [blame] | 1108 | elif isinstance(add_val, str) and (not curr or isinstance(curr, str)): |
Lalit Maganti | 3d415ec | 2019-10-23 17:53:17 +0100 | [diff] [blame] | 1109 | setattr(module, key, add_val) |
Florian Mayer | ac4f496 | 2020-09-15 10:03:22 +0100 | [diff] [blame] | 1110 | elif isinstance(add_val, bool) and (not curr or isinstance(curr, bool)): |
| 1111 | setattr(module, key, add_val) |
Lalit Maganti | cdda911 | 2019-11-27 14:19:49 +0000 | [diff] [blame] | 1112 | elif isinstance(add_val, dict) and isinstance(curr, dict): |
| 1113 | curr.update(add_val) |
Lalit Maganti | e0986f3 | 2020-09-17 15:35:47 +0100 | [diff] [blame] | 1114 | elif isinstance(add_val, dict) and isinstance(curr, Target): |
| 1115 | curr.__dict__.update(add_val) |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1116 | else: |
Florian Mayer | 5d09f5e | 2021-02-19 14:59:49 +0000 | [diff] [blame] | 1117 | raise Error('Unimplemented type %r of additional_args: %r' % |
| 1118 | (type(add_val), key)) |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1119 | |
| 1120 | # dep_name is an unmangled GN target name (e.g. //foo:bar(toolchain)). |
Lalit Maganti | 01f9b05 | 2022-12-17 01:21:13 +0000 | [diff] [blame] | 1121 | all_deps = target.non_proto_or_source_set_deps() |
| 1122 | all_deps |= target.transitive_source_set_deps() |
| 1123 | all_deps |= target.transitive_proto_deps() |
| 1124 | for dep in all_deps: |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1125 | # If the dependency refers to a library which we can replace with an |
| 1126 | # Android equivalent, stop recursing and patch the dependency in. |
| 1127 | # Don't recurse into //buildtools, builtin_deps are intercepted at |
| 1128 | # the //gn:xxx level. |
Lalit Maganti | 01f9b05 | 2022-12-17 01:21:13 +0000 | [diff] [blame] | 1129 | dep_name = dep.name |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1130 | if dep_name.startswith('//buildtools'): |
| 1131 | continue |
| 1132 | |
| 1133 | # Ignore the dependency on the gen_buildflags genrule. That is run |
| 1134 | # separately in this generator and the generated file is copied over |
| 1135 | # into the repo (see usage of |buildflags_dir| in this script). |
| 1136 | if dep_name.startswith(gn_utils.BUILDFLAGS_TARGET): |
| 1137 | continue |
| 1138 | |
| 1139 | dep_module = create_modules_from_target(blueprint, gn, dep_name) |
| 1140 | |
| 1141 | # For filegroups and genrule, recurse but don't apply the deps. |
| 1142 | if not module_is_compiled: |
| 1143 | continue |
| 1144 | |
| 1145 | # |builtin_deps| override GN deps with Android-specific ones. See the |
| 1146 | # config in the top of this file. |
| 1147 | if gn_utils.label_without_toolchain(dep_name) in builtin_deps: |
| 1148 | builtin_deps[gn_utils.label_without_toolchain(dep_name)](module) |
| 1149 | continue |
| 1150 | |
| 1151 | # Don't recurse in any other //gn dep if not handled by builtin_deps. |
| 1152 | if dep_name.startswith('//gn:'): |
| 1153 | continue |
| 1154 | |
| 1155 | if dep_module is None: |
| 1156 | continue |
| 1157 | if dep_module.type == 'cc_library_shared': |
| 1158 | module.shared_libs.add(dep_module.name) |
| 1159 | elif dep_module.type == 'cc_library_static': |
| 1160 | module.static_libs.add(dep_module.name) |
| 1161 | elif dep_module.type == 'filegroup': |
| 1162 | module.srcs.add(':' + dep_module.name) |
| 1163 | elif dep_module.type == 'genrule': |
| 1164 | module.generated_headers.update(dep_module.genrule_headers) |
| 1165 | module.srcs.update(dep_module.genrule_srcs) |
| 1166 | module.shared_libs.update(dep_module.genrule_shared_libs) |
Primiano Tucci | e094eec | 2020-03-18 16:58:21 +0000 | [diff] [blame] | 1167 | elif dep_module.type == 'cc_binary': |
| 1168 | continue # Ignore executables deps (used by cmdline integration tests). |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1169 | else: |
| 1170 | raise Error('Unknown dep %s (%s) for target %s' % |
| 1171 | (dep_module.name, dep_module.type, module.name)) |
| 1172 | |
| 1173 | return module |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 1174 | |
| 1175 | |
Lalit Maganti | 921a3d6 | 2022-12-17 14:28:50 +0000 | [diff] [blame] | 1176 | def create_blueprint_for_targets(gn: GnParser, targets: List[str]): |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1177 | """Generate a blueprint for a list of GN targets.""" |
| 1178 | blueprint = Blueprint() |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 1179 | |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1180 | # Default settings used by all modules. |
| 1181 | defaults = Module('cc_defaults', defaults_module, '//gn:default_deps') |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 1182 | |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1183 | # We have to use include_dirs passing the path relative to the android tree. |
| 1184 | # This is because: (i) perfetto_cc_defaults is used also by |
| 1185 | # test/**/Android.bp; (ii) if we use local_include_dirs instead, paths |
| 1186 | # become relative to the Android.bp that *uses* cc_defaults (not the one |
| 1187 | # that defines it).s |
| 1188 | defaults.include_dirs = { |
Florian Mayer | 5d09f5e | 2021-02-19 14:59:49 +0000 | [diff] [blame] | 1189 | tree_path, tree_path + '/include', tree_path + '/' + buildflags_dir, |
| 1190 | tree_path + '/src/profiling/memory/include' |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1191 | } |
Lalit Maganti | 921a3d6 | 2022-12-17 14:28:50 +0000 | [diff] [blame] | 1192 | defaults.cflags.update([ |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1193 | '-Wno-error=return-type', |
| 1194 | '-Wno-sign-compare', |
| 1195 | '-Wno-sign-promo', |
| 1196 | '-Wno-unused-parameter', |
| 1197 | '-fvisibility=hidden', |
| 1198 | '-O2', |
Lalit Maganti | 921a3d6 | 2022-12-17 14:28:50 +0000 | [diff] [blame] | 1199 | ]) |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1200 | defaults.user_debug_flag = True |
| 1201 | defaults.lto = True |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 1202 | |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1203 | blueprint.add_module(defaults) |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1204 | for target in targets: |
| 1205 | create_modules_from_target(blueprint, gn, target) |
| 1206 | return blueprint |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 1207 | |
| 1208 | |
| 1209 | def main(): |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1210 | parser = argparse.ArgumentParser( |
| 1211 | description='Generate Android.bp from a GN description.') |
| 1212 | parser.add_argument( |
| 1213 | '--check-only', |
| 1214 | help='Don\'t keep the generated files', |
| 1215 | action='store_true') |
| 1216 | parser.add_argument( |
| 1217 | '--desc', |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 1218 | help='GN description (e.g., gn desc out --format=json --all-toolchains "//*"' |
| 1219 | ) |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1220 | parser.add_argument( |
| 1221 | '--extras', |
| 1222 | help='Extra targets to include at the end of the Blueprint file', |
| 1223 | default=os.path.join(gn_utils.repo_root(), 'Android.bp.extras'), |
| 1224 | ) |
| 1225 | parser.add_argument( |
| 1226 | '--output', |
| 1227 | help='Blueprint file to create', |
| 1228 | default=os.path.join(gn_utils.repo_root(), 'Android.bp'), |
| 1229 | ) |
| 1230 | parser.add_argument( |
| 1231 | 'targets', |
| 1232 | nargs=argparse.REMAINDER, |
| 1233 | help='Targets to include in the blueprint (e.g., "//:perfetto_tests")') |
| 1234 | args = parser.parse_args() |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 1235 | |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1236 | if args.desc: |
| 1237 | with open(args.desc) as f: |
| 1238 | desc = json.load(f) |
| 1239 | else: |
| 1240 | desc = gn_utils.create_build_description(gn_args) |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 1241 | |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1242 | gn = gn_utils.GnParser(desc) |
Lalit Maganti | 921a3d6 | 2022-12-17 14:28:50 +0000 | [diff] [blame] | 1243 | blueprint = create_blueprint_for_targets(gn, args.targets or default_targets) |
Alexander Timin | 129c37c | 2021-04-08 19:17:59 +0000 | [diff] [blame] | 1244 | project_root = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) |
| 1245 | tool_name = os.path.relpath(os.path.abspath(__file__), project_root) |
Primiano Tucci | 916f4e5 | 2020-10-16 20:40:33 +0200 | [diff] [blame] | 1246 | |
| 1247 | # TODO(primiano): enable this on Android after the TODO in |
| 1248 | # perfetto_component.gni is fixed. |
| 1249 | # Check for ODR violations |
| 1250 | # for target_name in default_targets: |
Lalit Maganti | 9c2318c | 2021-05-20 16:21:41 +0100 | [diff] [blame] | 1251 | # checker = gn_utils.ODRChecker(gn, target_name) |
Primiano Tucci | 916f4e5 | 2020-10-16 20:40:33 +0200 | [diff] [blame] | 1252 | |
Lalit Maganti | d7afbb1 | 2022-03-28 15:12:24 +0100 | [diff] [blame] | 1253 | # Add any proto groups to the blueprint. |
Kean Mariotti | 487a539 | 2024-04-18 06:58:29 +0000 | [diff] [blame] | 1254 | for name, group in proto_groups.items(): |
| 1255 | create_proto_group_modules(blueprint, gn, name, group) |
Lalit Maganti | d7afbb1 | 2022-03-28 15:12:24 +0100 | [diff] [blame] | 1256 | |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1257 | output = [ |
| 1258 | """// Copyright (C) 2017 The Android Open Source Project |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 1259 | // |
| 1260 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 1261 | // you may not use this file except in compliance with the License. |
| 1262 | // You may obtain a copy of the License at |
| 1263 | // |
| 1264 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 1265 | // |
| 1266 | // Unless required by applicable law or agreed to in writing, software |
| 1267 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 1268 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 1269 | // See the License for the specific language governing permissions and |
| 1270 | // limitations under the License. |
| 1271 | // |
| 1272 | // This file is automatically generated by %s. Do not edit. |
Alexander Timin | 129c37c | 2021-04-08 19:17:59 +0000 | [diff] [blame] | 1273 | """ % (tool_name) |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1274 | ] |
| 1275 | blueprint.to_string(output) |
| 1276 | with open(args.extras, 'r') as r: |
| 1277 | for line in r: |
| 1278 | output.append(line.rstrip("\n\r")) |
Primiano Tucci | 9c41165 | 2019-08-27 07:13:59 +0200 | [diff] [blame] | 1279 | |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1280 | out_files = [] |
Primiano Tucci | 9c41165 | 2019-08-27 07:13:59 +0200 | [diff] [blame] | 1281 | |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1282 | # Generate the Android.bp file. |
| 1283 | out_files.append(args.output + '.swp') |
| 1284 | with open(out_files[-1], 'w') as f: |
| 1285 | f.write('\n'.join(output)) |
Florian Mayer | bbbd1ff | 2020-10-23 13:25:13 +0100 | [diff] [blame] | 1286 | # Text files should have a trailing EOL. |
| 1287 | f.write('\n') |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 1288 | |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1289 | # Generate the perfetto_build_flags.h file. |
| 1290 | out_files.append(os.path.join(buildflags_dir, 'perfetto_build_flags.h.swp')) |
| 1291 | gn_utils.gen_buildflags(gn_args, out_files[-1]) |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 1292 | |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1293 | # Either check the contents or move the files to their final destination. |
| 1294 | return gn_utils.check_or_commit_generated_files(out_files, args.check_only) |
Primiano Tucci | 9c41165 | 2019-08-27 07:13:59 +0200 | [diff] [blame] | 1295 | |
| 1296 | |
Sami Kyostila | 865d1d3 | 2017-12-12 18:37:04 +0000 | [diff] [blame] | 1297 | if __name__ == '__main__': |
Primiano Tucci | f0d7ef8 | 2019-10-04 15:35:24 +0100 | [diff] [blame] | 1298 | sys.exit(main()) |