Primiano Tucci | 34bc559 | 2021-02-19 17:53:36 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 2 | # Copyright (C) 2019 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 uses a collection of BUILD.gn files and build targets to generate |
| 17 | # an "amalgamated" C++ header and source file pair which compiles to an |
| 18 | # equivalent program. The tool also outputs the necessary compiler and linker |
| 19 | # flags needed to compile the resulting source code. |
| 20 | |
Sami Kyostila | 3c88a1d | 2019-05-22 18:29:42 +0100 | [diff] [blame] | 21 | from __future__ import print_function |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 22 | import argparse |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 23 | import os |
| 24 | import re |
| 25 | import shutil |
| 26 | import subprocess |
| 27 | import sys |
Sami Kyostila | 468e61d | 2019-05-23 15:54:01 +0100 | [diff] [blame] | 28 | import tempfile |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 29 | |
Sami Kyostila | 3c88a1d | 2019-05-22 18:29:42 +0100 | [diff] [blame] | 30 | import gn_utils |
| 31 | |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 32 | # Default targets to include in the result. |
Primiano Tucci | 75ae50e | 2019-08-28 13:09:55 +0200 | [diff] [blame] | 33 | # TODO(primiano): change this script to recurse into target deps when generating |
| 34 | # headers, but only for proto targets. .pbzero.h files don't include each other |
| 35 | # and we need to list targets here individually, which is unmaintainable. |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 36 | default_targets = [ |
Primiano Tucci | 658e2d6 | 2019-06-14 10:03:32 +0100 | [diff] [blame] | 37 | '//:libperfetto_client_experimental', |
Matthew Clarkson | 58a3ebb | 2019-10-11 11:29:18 +0100 | [diff] [blame] | 38 | '//include/perfetto/protozero:protozero', |
| 39 | '//protos/perfetto/config:zero', |
| 40 | '//protos/perfetto/trace:zero', |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 41 | ] |
| 42 | |
| 43 | # Arguments for the GN output directory (unless overridden from the command |
| 44 | # line). |
Primiano Tucci | 9c41165 | 2019-08-27 07:13:59 +0200 | [diff] [blame] | 45 | gn_args = ' '.join([ |
Primiano Tucci | adb22cf | 2021-11-02 22:14:39 +0000 | [diff] [blame] | 46 | 'enable_perfetto_ipc=true', |
Primiano Tucci | 9c41165 | 2019-08-27 07:13:59 +0200 | [diff] [blame] | 47 | 'is_debug=false', |
Primiano Tucci | 7e05fc1 | 2019-08-27 17:29:47 +0200 | [diff] [blame] | 48 | 'is_perfetto_build_generator=true', |
| 49 | 'is_perfetto_embedder=true', |
Primiano Tucci | adb22cf | 2021-11-02 22:14:39 +0000 | [diff] [blame] | 50 | 'perfetto_enable_git_rev_version_header=true', |
Primiano Tucci | 7e05fc1 | 2019-08-27 17:29:47 +0200 | [diff] [blame] | 51 | 'use_custom_libcxx=false', |
Primiano Tucci | 9c41165 | 2019-08-27 07:13:59 +0200 | [diff] [blame] | 52 | ]) |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 53 | |
Primiano Tucci | cb05065 | 2019-08-29 01:10:34 +0200 | [diff] [blame] | 54 | # By default, the amalgamated .h only recurses in #includes but not in the |
| 55 | # target deps. In the case of protos we want to follow deps even in lieu of |
| 56 | # direct #includes. This is because, by design, protozero headers don't |
Sami Kyostila | 02fccc1 | 2020-07-14 19:33:15 +0100 | [diff] [blame] | 57 | # include each other but rely on forward declarations. The alternative would |
Primiano Tucci | cb05065 | 2019-08-29 01:10:34 +0200 | [diff] [blame] | 58 | # be adding each proto sub-target individually (e.g. //proto/trace/gpu:zero), |
Sami Kyostila | 02fccc1 | 2020-07-14 19:33:15 +0100 | [diff] [blame] | 59 | # but doing that is unmaintainable. We also do this for cpp bindings since some |
| 60 | # tracing SDK functions depend on them (and the system tracing IPC mechanism |
| 61 | # does so too). |
| 62 | recurse_in_header_deps = '^//protos/.*(cpp|zero)$' |
Primiano Tucci | cb05065 | 2019-08-29 01:10:34 +0200 | [diff] [blame] | 63 | |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 64 | # Compiler flags which aren't filtered out. |
Primiano Tucci | a364520 | 2020-08-03 16:28:18 +0200 | [diff] [blame] | 65 | cflag_allowlist = r'^-(W.*|fno-exceptions|fPIC|std.*|fvisibility.*)$' |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 66 | |
| 67 | # Linker flags which aren't filtered out. |
Primiano Tucci | a364520 | 2020-08-03 16:28:18 +0200 | [diff] [blame] | 68 | ldflag_allowlist = r'^-()$' |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 69 | |
| 70 | # Libraries which are filtered out. |
Primiano Tucci | a364520 | 2020-08-03 16:28:18 +0200 | [diff] [blame] | 71 | lib_denylist = r'^(c|gcc_eh)$' |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 72 | |
| 73 | # Macros which aren't filtered out. |
Primiano Tucci | a364520 | 2020-08-03 16:28:18 +0200 | [diff] [blame] | 74 | define_allowlist = r'^(PERFETTO.*|GOOGLE_PROTOBUF.*)$' |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 75 | |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 76 | # Includes which will be removed from the generated source. |
| 77 | includes_to_remove = r'^(gtest).*$' |
| 78 | |
Sami Kyostila | 7e8509f | 2019-05-29 12:36:24 +0100 | [diff] [blame] | 79 | default_cflags = [ |
| 80 | # Since we're expanding header files into the generated source file, some |
| 81 | # constant may remain unused. |
| 82 | '-Wno-unused-const-variable' |
| 83 | ] |
| 84 | |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 85 | # Build flags to satisfy a protobuf (lite or full) dependency. |
| 86 | protobuf_cflags = [ |
| 87 | # Note that these point to the local copy of protobuf in buildtools. In |
| 88 | # reality the user of the amalgamated result will have to provide a path to |
| 89 | # an installed copy of the exact same version of protobuf which was used to |
| 90 | # generate the amalgamated build. |
| 91 | '-isystembuildtools/protobuf/src', |
| 92 | '-Lbuildtools/protobuf/src/.libs', |
| 93 | # We also need to disable some warnings for protobuf. |
| 94 | '-Wno-missing-prototypes', |
| 95 | '-Wno-missing-variable-declarations', |
| 96 | '-Wno-sign-conversion', |
| 97 | '-Wno-unknown-pragmas', |
| 98 | '-Wno-unused-macros', |
| 99 | ] |
| 100 | |
| 101 | # A mapping of dependencies to system libraries. Libraries in this map will not |
| 102 | # be built statically but instead added as dependencies of the amalgamated |
| 103 | # project. |
| 104 | system_library_map = { |
| 105 | '//buildtools:protobuf_full': { |
| 106 | 'libs': ['protobuf'], |
| 107 | 'cflags': protobuf_cflags, |
| 108 | }, |
| 109 | '//buildtools:protobuf_lite': { |
| 110 | 'libs': ['protobuf-lite'], |
| 111 | 'cflags': protobuf_cflags, |
| 112 | }, |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 113 | '//buildtools:protoc_lib': { |
| 114 | 'libs': ['protoc'] |
| 115 | }, |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | # ---------------------------------------------------------------------------- |
| 119 | # End of configuration. |
| 120 | # ---------------------------------------------------------------------------- |
| 121 | |
| 122 | tool_name = os.path.basename(__file__) |
Primiano Tucci | e22ffbd | 2020-01-17 01:11:31 +0000 | [diff] [blame] | 123 | project_root = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 124 | preamble = """// Copyright (C) 2019 The Android Open Source Project |
| 125 | // |
| 126 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 127 | // you may not use this file except in compliance with the License. |
| 128 | // You may obtain a copy of the License at |
| 129 | // |
| 130 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 131 | // |
| 132 | // Unless required by applicable law or agreed to in writing, software |
| 133 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 134 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 135 | // See the License for the specific language governing permissions and |
| 136 | // limitations under the License. |
| 137 | // |
| 138 | // This file is automatically generated by %s. Do not edit. |
| 139 | """ % tool_name |
| 140 | |
| 141 | |
Primiano Tucci | a364520 | 2020-08-03 16:28:18 +0200 | [diff] [blame] | 142 | def apply_denylist(denylist, items): |
| 143 | return [item for item in items if not re.match(denylist, item)] |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 144 | |
| 145 | |
Primiano Tucci | a364520 | 2020-08-03 16:28:18 +0200 | [diff] [blame] | 146 | def apply_allowlist(allowlist, items): |
| 147 | return [item for item in items if re.match(allowlist, item)] |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 148 | |
| 149 | |
Primiano Tucci | e22ffbd | 2020-01-17 01:11:31 +0000 | [diff] [blame] | 150 | def normalize_path(path): |
| 151 | path = os.path.relpath(path, project_root) |
| 152 | path = re.sub(r'^out/[^/]+/', '', path) |
| 153 | return path |
| 154 | |
| 155 | |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 156 | class Error(Exception): |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 157 | pass |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 158 | |
| 159 | |
| 160 | class DependencyNode(object): |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 161 | """A target in a GN build description along with its dependencies.""" |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 162 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 163 | def __init__(self, target_name): |
| 164 | self.target_name = target_name |
| 165 | self.dependencies = set() |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 166 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 167 | def add_dependency(self, target_node): |
| 168 | if target_node in self.dependencies: |
| 169 | return |
| 170 | self.dependencies.add(target_node) |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 171 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 172 | def iterate_depth_first(self): |
| 173 | for node in sorted(self.dependencies, key=lambda n: n.target_name): |
| 174 | for node in node.iterate_depth_first(): |
| 175 | yield node |
| 176 | if self.target_name: |
| 177 | yield self |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 178 | |
| 179 | |
| 180 | class DependencyTree(object): |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 181 | """A tree of GN build target dependencies.""" |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 182 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 183 | def __init__(self): |
| 184 | self.target_to_node_map = {} |
| 185 | self.root = self._get_or_create_node(None) |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 186 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 187 | def _get_or_create_node(self, target_name): |
| 188 | if target_name in self.target_to_node_map: |
| 189 | return self.target_to_node_map[target_name] |
| 190 | node = DependencyNode(target_name) |
| 191 | self.target_to_node_map[target_name] = node |
| 192 | return node |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 193 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 194 | def add_dependency(self, from_target, to_target): |
| 195 | from_node = self._get_or_create_node(from_target) |
| 196 | to_node = self._get_or_create_node(to_target) |
| 197 | assert from_node is not to_node |
| 198 | from_node.add_dependency(to_node) |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 199 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 200 | def iterate_depth_first(self): |
| 201 | for node in self.root.iterate_depth_first(): |
| 202 | yield node |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 203 | |
| 204 | |
| 205 | class AmalgamatedProject(object): |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 206 | """In-memory representation of an amalgamated source/header pair.""" |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 207 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 208 | def __init__(self, desc, source_deps, compute_deps_only=False): |
| 209 | """Constructor. |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 210 | |
| 211 | Args: |
| 212 | desc: JSON build description. |
| 213 | source_deps: A map of (source file, [dependency header]) which is |
| 214 | to detect which header files are included by each source file. |
Sami Kyostila | d4c857e | 2019-08-08 18:44:33 +0100 | [diff] [blame] | 215 | compute_deps_only: If True, the project will only be used to compute |
| 216 | dependency information. Use |get_source_files()| to retrieve |
| 217 | the result. |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 218 | """ |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 219 | self.desc = desc |
| 220 | self.source_deps = source_deps |
| 221 | self.header = [] |
| 222 | self.source = [] |
| 223 | self.source_defines = [] |
| 224 | # Note that we don't support multi-arg flags. |
| 225 | self.cflags = set(default_cflags) |
| 226 | self.ldflags = set() |
| 227 | self.defines = set() |
| 228 | self.libs = set() |
| 229 | self._dependency_tree = DependencyTree() |
| 230 | self._processed_sources = set() |
| 231 | self._processed_headers = set() |
| 232 | self._processed_header_deps = set() |
| 233 | self._processed_source_headers = set() # Header files included from .cc |
| 234 | self._include_re = re.compile(r'#include "(.*)"') |
| 235 | self._compute_deps_only = compute_deps_only |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 236 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 237 | def add_target(self, target_name): |
| 238 | """Include |target_name| in the amalgamated result.""" |
| 239 | self._dependency_tree.add_dependency(None, target_name) |
| 240 | self._add_target_dependencies(target_name) |
| 241 | self._add_target_flags(target_name) |
| 242 | self._add_target_headers(target_name) |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 243 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 244 | # Recurse into target deps, but only for protos. This generates headers |
Sami Kyostila | 02fccc1 | 2020-07-14 19:33:15 +0100 | [diff] [blame] | 245 | # for all the .{pbzero,gen}.h files, even if they don't #include each other. |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 246 | for _, dep in self._iterate_dep_edges(target_name): |
| 247 | if (dep not in self._processed_header_deps and |
| 248 | re.match(recurse_in_header_deps, dep)): |
| 249 | self._processed_header_deps.add(dep) |
| 250 | self.add_target(dep) |
Primiano Tucci | cb05065 | 2019-08-29 01:10:34 +0200 | [diff] [blame] | 251 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 252 | def _iterate_dep_edges(self, target_name): |
| 253 | target = self.desc[target_name] |
| 254 | for dep in target.get('deps', []): |
| 255 | # Ignore system libraries since they will be added as build-time |
| 256 | # dependencies. |
| 257 | if dep in system_library_map: |
| 258 | continue |
| 259 | # Don't descend into build action dependencies. |
| 260 | if self.desc[dep]['type'] == 'action': |
| 261 | continue |
| 262 | for sub_target, sub_dep in self._iterate_dep_edges(dep): |
| 263 | yield sub_target, sub_dep |
| 264 | yield target_name, dep |
Primiano Tucci | cb05065 | 2019-08-29 01:10:34 +0200 | [diff] [blame] | 265 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 266 | def _iterate_target_and_deps(self, target_name): |
| 267 | yield target_name |
| 268 | for _, dep in self._iterate_dep_edges(target_name): |
| 269 | yield dep |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 270 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 271 | def _add_target_dependencies(self, target_name): |
| 272 | for target, dep in self._iterate_dep_edges(target_name): |
| 273 | self._dependency_tree.add_dependency(target, dep) |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 274 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 275 | def process_dep(dep): |
| 276 | if dep in system_library_map: |
| 277 | self.libs.update(system_library_map[dep].get('libs', [])) |
| 278 | self.cflags.update(system_library_map[dep].get('cflags', [])) |
| 279 | self.defines.update(system_library_map[dep].get('defines', [])) |
| 280 | return True |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 281 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 282 | def walk_all_deps(target_name): |
| 283 | target = self.desc[target_name] |
| 284 | for dep in target.get('deps', []): |
| 285 | if process_dep(dep): |
| 286 | return |
| 287 | walk_all_deps(dep) |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 288 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 289 | walk_all_deps(target_name) |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 290 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 291 | def _filter_cflags(self, cflags): |
| 292 | # Since we want to deduplicate flags, combine two-part switches (e.g., |
| 293 | # "-foo bar") into one value ("-foobar") so we can store the result as |
| 294 | # a set. |
| 295 | result = [] |
| 296 | for flag in cflags: |
| 297 | if flag.startswith('-'): |
| 298 | result.append(flag) |
| 299 | else: |
| 300 | result[-1] += flag |
Primiano Tucci | a364520 | 2020-08-03 16:28:18 +0200 | [diff] [blame] | 301 | return apply_allowlist(cflag_allowlist, result) |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 302 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 303 | def _add_target_flags(self, target_name): |
| 304 | for target_name in self._iterate_target_and_deps(target_name): |
| 305 | target = self.desc[target_name] |
| 306 | self.cflags.update(self._filter_cflags(target.get('cflags', []))) |
| 307 | self.cflags.update(self._filter_cflags(target.get('cflags_cc', []))) |
| 308 | self.ldflags.update( |
Primiano Tucci | a364520 | 2020-08-03 16:28:18 +0200 | [diff] [blame] | 309 | apply_allowlist(ldflag_allowlist, target.get('ldflags', []))) |
| 310 | self.libs.update(apply_denylist(lib_denylist, target.get('libs', []))) |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 311 | self.defines.update( |
Primiano Tucci | a364520 | 2020-08-03 16:28:18 +0200 | [diff] [blame] | 312 | apply_allowlist(define_allowlist, target.get('defines', []))) |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 313 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 314 | def _add_target_headers(self, target_name): |
| 315 | target = self.desc[target_name] |
| 316 | if not 'sources' in target: |
| 317 | return |
| 318 | headers = [ |
| 319 | gn_utils.label_to_path(s) for s in target['sources'] if s.endswith('.h') |
| 320 | ] |
| 321 | for header in headers: |
| 322 | self._add_header(target_name, header) |
Sami Kyostila | 7e8509f | 2019-05-29 12:36:24 +0100 | [diff] [blame] | 323 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 324 | def _get_include_dirs(self, target_name): |
| 325 | include_dirs = set() |
| 326 | for target_name in self._iterate_target_and_deps(target_name): |
| 327 | target = self.desc[target_name] |
| 328 | if 'include_dirs' in target: |
| 329 | include_dirs.update( |
| 330 | [gn_utils.label_to_path(d) for d in target['include_dirs']]) |
| 331 | return include_dirs |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 332 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 333 | def _add_source_included_header(self, include_dirs, allowed_files, |
| 334 | header_name): |
Sami Kyostila | 02fccc1 | 2020-07-14 19:33:15 +0100 | [diff] [blame] | 335 | if header_name in self._processed_headers: |
| 336 | return |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 337 | if header_name in self._processed_source_headers: |
| 338 | return |
| 339 | self._processed_source_headers.add(header_name) |
| 340 | for include_dir in include_dirs: |
Matthew Clarkson | 58a3ebb | 2019-10-11 11:29:18 +0100 | [diff] [blame] | 341 | rel_path = os.path.join(include_dir, header_name) |
| 342 | full_path = os.path.join(gn_utils.repo_root(), rel_path) |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 343 | if os.path.exists(full_path): |
Matthew Clarkson | 58a3ebb | 2019-10-11 11:29:18 +0100 | [diff] [blame] | 344 | if not rel_path in allowed_files: |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 345 | return |
| 346 | with open(full_path) as f: |
Primiano Tucci | e22ffbd | 2020-01-17 01:11:31 +0000 | [diff] [blame] | 347 | self.source.append( |
| 348 | '// %s begin header: %s' % (tool_name, normalize_path(full_path))) |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 349 | self.source.extend( |
| 350 | self._process_source_includes(include_dirs, allowed_files, f)) |
| 351 | return |
| 352 | if self._compute_deps_only: |
| 353 | return |
| 354 | msg = 'Looked in %s' % ', '.join('"%s"' % d for d in include_dirs) |
| 355 | raise Error('Header file %s not found. %s' % (header_name, msg)) |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 356 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 357 | def _add_source(self, target_name, source_name): |
| 358 | if source_name in self._processed_sources: |
| 359 | return |
| 360 | self._processed_sources.add(source_name) |
| 361 | include_dirs = self._get_include_dirs(target_name) |
| 362 | deps = self.source_deps[source_name] |
Matthew Clarkson | 58a3ebb | 2019-10-11 11:29:18 +0100 | [diff] [blame] | 363 | full_path = os.path.join(gn_utils.repo_root(), source_name) |
| 364 | if not os.path.exists(full_path): |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 365 | raise Error('Source file %s not found' % source_name) |
Matthew Clarkson | 58a3ebb | 2019-10-11 11:29:18 +0100 | [diff] [blame] | 366 | with open(full_path) as f: |
Primiano Tucci | e22ffbd | 2020-01-17 01:11:31 +0000 | [diff] [blame] | 367 | self.source.append( |
| 368 | '// %s begin source: %s' % (tool_name, normalize_path(full_path))) |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 369 | try: |
| 370 | self.source.extend( |
| 371 | self._patch_source( |
Primiano Tucci | e22ffbd | 2020-01-17 01:11:31 +0000 | [diff] [blame] | 372 | source_name, self._process_source_includes( |
| 373 | include_dirs, deps, f))) |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 374 | except Error as e: |
| 375 | raise Error('Failed adding source %s: %s' % (source_name, e.message)) |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 376 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 377 | def _add_header_included_header(self, include_dirs, header_name): |
| 378 | if header_name in self._processed_headers: |
| 379 | return |
| 380 | self._processed_headers.add(header_name) |
| 381 | for include_dir in include_dirs: |
Matthew Clarkson | 58a3ebb | 2019-10-11 11:29:18 +0100 | [diff] [blame] | 382 | full_path = os.path.join(gn_utils.repo_root(), include_dir, header_name) |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 383 | if os.path.exists(full_path): |
| 384 | with open(full_path) as f: |
Primiano Tucci | e22ffbd | 2020-01-17 01:11:31 +0000 | [diff] [blame] | 385 | self.header.append( |
| 386 | '// %s begin header: %s' % (tool_name, normalize_path(full_path))) |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 387 | self.header.extend(self._process_header_includes(include_dirs, f)) |
| 388 | return |
| 389 | if self._compute_deps_only: |
| 390 | return |
| 391 | msg = 'Looked in %s' % ', '.join('"%s"' % d for d in include_dirs) |
| 392 | raise Error('Header file %s not found. %s' % (header_name, msg)) |
Sami Kyostila | 7e8509f | 2019-05-29 12:36:24 +0100 | [diff] [blame] | 393 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 394 | def _add_header(self, target_name, header_name): |
| 395 | if header_name in self._processed_headers: |
| 396 | return |
| 397 | self._processed_headers.add(header_name) |
| 398 | include_dirs = self._get_include_dirs(target_name) |
Matthew Clarkson | 58a3ebb | 2019-10-11 11:29:18 +0100 | [diff] [blame] | 399 | full_path = os.path.join(gn_utils.repo_root(), header_name) |
| 400 | if not os.path.exists(full_path): |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 401 | if self._compute_deps_only: |
| 402 | return |
| 403 | raise Error('Header file %s not found' % header_name) |
Matthew Clarkson | 58a3ebb | 2019-10-11 11:29:18 +0100 | [diff] [blame] | 404 | with open(full_path) as f: |
Primiano Tucci | e22ffbd | 2020-01-17 01:11:31 +0000 | [diff] [blame] | 405 | self.header.append( |
| 406 | '// %s begin header: %s' % (tool_name, normalize_path(full_path))) |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 407 | try: |
| 408 | self.header.extend(self._process_header_includes(include_dirs, f)) |
| 409 | except Error as e: |
| 410 | raise Error('Failed adding header %s: %s' % (header_name, e.message)) |
Sami Kyostila | 7e8509f | 2019-05-29 12:36:24 +0100 | [diff] [blame] | 411 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 412 | def _patch_source(self, source_name, lines): |
| 413 | result = [] |
| 414 | namespace = re.sub(r'[^a-z]', '_', |
| 415 | os.path.splitext(os.path.basename(source_name))[0]) |
| 416 | for line in lines: |
| 417 | # Protobuf generates an identical anonymous function into each |
| 418 | # message description. Rename all but the first occurrence to avoid |
| 419 | # duplicate symbol definitions. |
| 420 | line = line.replace('MergeFromFail', '%s_MergeFromFail' % namespace) |
| 421 | result.append(line) |
| 422 | return result |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 423 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 424 | def _process_source_includes(self, include_dirs, allowed_files, file): |
| 425 | result = [] |
| 426 | for line in file: |
| 427 | line = line.rstrip('\n') |
| 428 | m = self._include_re.match(line) |
| 429 | if not m: |
| 430 | result.append(line) |
| 431 | continue |
| 432 | elif re.match(includes_to_remove, m.group(1)): |
| 433 | result.append('// %s removed: %s' % (tool_name, line)) |
| 434 | else: |
| 435 | result.append('// %s expanded: %s' % (tool_name, line)) |
| 436 | self._add_source_included_header(include_dirs, allowed_files, |
| 437 | m.group(1)) |
| 438 | return result |
Sami Kyostila | 7e8509f | 2019-05-29 12:36:24 +0100 | [diff] [blame] | 439 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 440 | def _process_header_includes(self, include_dirs, file): |
| 441 | result = [] |
| 442 | for line in file: |
| 443 | line = line.rstrip('\n') |
| 444 | m = self._include_re.match(line) |
| 445 | if not m: |
| 446 | result.append(line) |
| 447 | continue |
| 448 | elif re.match(includes_to_remove, m.group(1)): |
| 449 | result.append('// %s removed: %s' % (tool_name, line)) |
| 450 | else: |
| 451 | result.append('// %s expanded: %s' % (tool_name, line)) |
| 452 | self._add_header_included_header(include_dirs, m.group(1)) |
| 453 | return result |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 454 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 455 | def generate(self): |
| 456 | """Prepares the output for this amalgamated project. |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 457 | |
| 458 | Call save() to persist the result. |
| 459 | """ |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 460 | assert not self._compute_deps_only |
| 461 | self.source_defines.append('// %s: predefined macros' % tool_name) |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 462 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 463 | def add_define(name): |
| 464 | # Valued macros aren't supported for now. |
| 465 | assert '=' not in name |
| 466 | self.source_defines.append('#if !defined(%s)' % name) |
| 467 | self.source_defines.append('#define %s' % name) |
| 468 | self.source_defines.append('#endif') |
| 469 | |
| 470 | for name in self.defines: |
| 471 | add_define(name) |
| 472 | for target_name, source_name in self.get_source_files(): |
| 473 | self._add_source(target_name, source_name) |
| 474 | |
| 475 | def get_source_files(self): |
| 476 | """Return a list of (target, [source file]) that describes the source |
Sami Kyostila | d4c857e | 2019-08-08 18:44:33 +0100 | [diff] [blame] | 477 | files pulled in by each target which is a dependency of this project. |
| 478 | """ |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 479 | source_files = [] |
| 480 | for node in self._dependency_tree.iterate_depth_first(): |
| 481 | target = self.desc[node.target_name] |
| 482 | if not 'sources' in target: |
| 483 | continue |
| 484 | sources = [(node.target_name, gn_utils.label_to_path(s)) |
| 485 | for s in target['sources'] |
| 486 | if s.endswith('.cc')] |
| 487 | source_files.extend(sources) |
| 488 | return source_files |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 489 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 490 | def _get_nice_path(self, prefix, format): |
| 491 | basename = os.path.basename(prefix) |
| 492 | return os.path.join( |
| 493 | os.path.relpath(os.path.dirname(prefix)), format % basename) |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 494 | |
Matthew Clarkson | 58a3ebb | 2019-10-11 11:29:18 +0100 | [diff] [blame] | 495 | def _make_directories(self, directory): |
| 496 | if not os.path.isdir(directory): |
| 497 | os.makedirs(directory) |
| 498 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 499 | def save(self, output_prefix): |
| 500 | """Save the generated header and source file pair. |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 501 | |
| 502 | Returns a message describing the output with build instructions. |
| 503 | """ |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 504 | header_file = self._get_nice_path(output_prefix, '%s.h') |
| 505 | source_file = self._get_nice_path(output_prefix, '%s.cc') |
Matthew Clarkson | 58a3ebb | 2019-10-11 11:29:18 +0100 | [diff] [blame] | 506 | self._make_directories(os.path.dirname(header_file)) |
| 507 | self._make_directories(os.path.dirname(source_file)) |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 508 | with open(header_file, 'w') as f: |
| 509 | f.write('\n'.join([preamble] + self.header + ['\n'])) |
| 510 | with open(source_file, 'w') as f: |
| 511 | include_stmt = '#include "%s"' % os.path.basename(header_file) |
| 512 | f.write('\n'.join([preamble] + self.source_defines + [include_stmt] + |
| 513 | self.source + ['\n'])) |
| 514 | build_cmd = self.get_build_command(output_prefix) |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 515 | return """Amalgamated project written to %s and %s. |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 516 | |
| 517 | Build settings: |
| 518 | - cflags: %s |
| 519 | - ldflags: %s |
| 520 | - libs: %s |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 521 | |
| 522 | Example build command: |
| 523 | |
| 524 | %s |
Primiano Tucci | e22ffbd | 2020-01-17 01:11:31 +0000 | [diff] [blame] | 525 | """ % (header_file, source_file, ' '.join(self.cflags), ' '.join(self.ldflags), |
| 526 | ' '.join(self.libs), ' '.join(build_cmd)) |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 527 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 528 | def get_build_command(self, output_prefix): |
| 529 | """Returns an example command line for building the output source.""" |
| 530 | source = self._get_nice_path(output_prefix, '%s.cc') |
| 531 | library = self._get_nice_path(output_prefix, 'lib%s.so') |
Lalit Maganti | 54afee6 | 2020-07-16 19:28:04 +0100 | [diff] [blame] | 532 | |
| 533 | if sys.platform.startswith('linux'): |
| 534 | llvm_script = os.path.join(gn_utils.repo_root(), 'gn', |
| 535 | 'standalone', 'toolchain', |
| 536 | 'linux_find_llvm.py') |
Primiano Tucci | 34bc559 | 2021-02-19 17:53:36 +0100 | [diff] [blame] | 537 | cxx = subprocess.check_output([llvm_script]).splitlines()[2].decode() |
Lalit Maganti | 54afee6 | 2020-07-16 19:28:04 +0100 | [diff] [blame] | 538 | else: |
| 539 | cxx = 'clang++' |
| 540 | |
| 541 | build_cmd = [cxx, source, '-o', library, '-shared'] + \ |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 542 | sorted(self.cflags) + sorted(self.ldflags) |
| 543 | for lib in sorted(self.libs): |
| 544 | build_cmd.append('-l%s' % lib) |
| 545 | return build_cmd |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 546 | |
| 547 | |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 548 | def main(): |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 549 | parser = argparse.ArgumentParser( |
| 550 | description='Generate an amalgamated header/source pair from a GN ' |
| 551 | 'build description.') |
| 552 | parser.add_argument( |
Matthew Clarkson | 58a3ebb | 2019-10-11 11:29:18 +0100 | [diff] [blame] | 553 | '--out', |
| 554 | help='The name of the temporary build folder in \'out\'', |
| 555 | default='tmp.gen_amalgamated.%u' % os.getpid()) |
| 556 | parser.add_argument( |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 557 | '--output', |
| 558 | help='Base name of files to create. A .cc/.h extension will be added', |
Matthew Clarkson | 58a3ebb | 2019-10-11 11:29:18 +0100 | [diff] [blame] | 559 | default=os.path.join(gn_utils.repo_root(), 'out/amalgamated/perfetto')) |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 560 | parser.add_argument( |
| 561 | '--gn_args', |
| 562 | help='GN arguments used to prepare the output directory', |
| 563 | default=gn_args) |
| 564 | parser.add_argument( |
| 565 | '--keep', |
| 566 | help='Don\'t delete the GN output directory at exit', |
| 567 | action='store_true') |
| 568 | parser.add_argument( |
| 569 | '--build', help='Also compile the generated files', action='store_true') |
| 570 | parser.add_argument( |
| 571 | '--check', help='Don\'t keep the generated files', action='store_true') |
| 572 | parser.add_argument('--quiet', help='Only report errors', action='store_true') |
| 573 | parser.add_argument( |
| 574 | '--dump-deps', |
| 575 | help='List all source files that the amalgamated output depends on', |
| 576 | action='store_true') |
| 577 | parser.add_argument( |
| 578 | 'targets', |
| 579 | nargs=argparse.REMAINDER, |
| 580 | help='Targets to include in the output (e.g., "//:libperfetto")') |
| 581 | args = parser.parse_args() |
| 582 | targets = args.targets or default_targets |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 583 | |
Hector Dearman | 762c18f | 2021-05-24 11:10:52 +0100 | [diff] [blame] | 584 | # The CHANGELOG mtime triggers the perfetto_version.gen.h genrule. This is |
Primiano Tucci | ec59013 | 2020-11-16 14:16:44 +0100 | [diff] [blame] | 585 | # to avoid emitting a stale version information in the remote case of somebody |
| 586 | # running gen_amalgamated incrementally after having moved to another commit. |
| 587 | changelog_path = os.path.join(project_root, 'CHANGELOG') |
| 588 | assert(os.path.exists(changelog_path)) |
| 589 | subprocess.check_call(['touch', '-c', changelog_path]) |
| 590 | |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 591 | output = args.output |
| 592 | if args.check: |
| 593 | output = os.path.join(tempfile.mkdtemp(), 'perfetto_amalgamated') |
| 594 | |
Matthew Clarkson | 58a3ebb | 2019-10-11 11:29:18 +0100 | [diff] [blame] | 595 | out = gn_utils.prepare_out_directory(args.gn_args, args.out) |
Matthew Clarkson | a990d95 | 2019-10-08 14:52:12 +0100 | [diff] [blame] | 596 | if not args.quiet: |
| 597 | print('Building project...') |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 598 | try: |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 599 | desc = gn_utils.load_build_description(out) |
| 600 | |
| 601 | # We need to build everything first so that the necessary header |
| 602 | # dependencies get generated. However if we are just dumping dependency |
| 603 | # information this can be skipped, allowing cross-platform operation. |
| 604 | if not args.dump_deps: |
| 605 | gn_utils.build_targets(out, targets) |
| 606 | source_deps = gn_utils.compute_source_dependencies(out) |
| 607 | project = AmalgamatedProject( |
| 608 | desc, source_deps, compute_deps_only=args.dump_deps) |
| 609 | |
| 610 | for target in targets: |
| 611 | project.add_target(target) |
| 612 | |
| 613 | if args.dump_deps: |
| 614 | source_files = [ |
| 615 | source_file for _, source_file in project.get_source_files() |
| 616 | ] |
| 617 | print('\n'.join(sorted(set(source_files)))) |
| 618 | return |
| 619 | |
| 620 | project.generate() |
| 621 | result = project.save(output) |
| 622 | if not args.quiet: |
| 623 | print(result) |
| 624 | if args.build: |
| 625 | if not args.quiet: |
| 626 | sys.stdout.write('Building amalgamated project...') |
| 627 | sys.stdout.flush() |
| 628 | subprocess.check_call(project.get_build_command(output)) |
| 629 | if not args.quiet: |
| 630 | print('done') |
| 631 | finally: |
| 632 | if not args.keep: |
| 633 | shutil.rmtree(out) |
Sami Kyostila | 468e61d | 2019-05-23 15:54:01 +0100 | [diff] [blame] | 634 | if args.check: |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 635 | shutil.rmtree(os.path.dirname(output)) |
Sami Kyostila | 468e61d | 2019-05-23 15:54:01 +0100 | [diff] [blame] | 636 | |
Sami Kyostila | 0a34b03 | 2019-05-16 18:28:48 +0100 | [diff] [blame] | 637 | |
| 638 | if __name__ == '__main__': |
Primiano Tucci | 834fdc7 | 2019-10-04 11:33:44 +0100 | [diff] [blame] | 639 | sys.exit(main()) |