blob: 5f563ac113997dae739de32294422c917b130dcf [file] [log] [blame]
Sami Kyostila865d1d32017-12-12 18:37:04 +00001#!/usr/bin/env python
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
28import argparse
Primiano Tucciedf099c2018-01-08 18:27:56 +000029import errno
Sami Kyostila865d1d32017-12-12 18:37:04 +000030import json
31import os
32import re
Sami Kyostilab27619f2017-12-13 19:22:16 +000033import shutil
34import subprocess
Sami Kyostila865d1d32017-12-12 18:37:04 +000035import sys
36
Sami Kyostilab27619f2017-12-13 19:22:16 +000037# Default targets to translate to the blueprint file.
Primiano Tucci4e49c022017-12-21 18:22:44 +010038default_targets = [
Primiano Tucciedf099c2018-01-08 18:27:56 +000039 '//:libtraced_shared',
Primiano Tucci4e49c022017-12-21 18:22:44 +010040 '//:perfetto_tests',
Primiano Tucci3b729102018-01-08 18:16:36 +000041 '//:perfetto',
Primiano Tucci7e2b67a2018-01-16 16:38:49 +000042 '//:perfetto_protos_lite',
Primiano Tucci4e49c022017-12-21 18:22:44 +010043 '//:traced',
Primiano Tucci6067e732018-01-08 16:19:40 +000044 '//:traced_probes',
Primiano Tucci4e49c022017-12-21 18:22:44 +010045]
Sami Kyostilab27619f2017-12-13 19:22:16 +000046
Primiano Tucci6067e732018-01-08 16:19:40 +000047# Defines a custom init_rc argument to be applied to the corresponding output
48# blueprint target.
Primiano Tucci5a304532018-01-09 14:15:43 +000049target_initrc = {
50 '//:traced': 'perfetto.rc',
51}
Primiano Tucci6067e732018-01-08 16:19:40 +000052
Sami Kyostilab27619f2017-12-13 19:22:16 +000053# Arguments for the GN output directory.
Primiano Tucciedf099c2018-01-08 18:27:56 +000054gn_args = 'target_os="android" target_cpu="arm" is_debug=false build_with_android=true'
Sami Kyostilab27619f2017-12-13 19:22:16 +000055
Sami Kyostila865d1d32017-12-12 18:37:04 +000056# All module names are prefixed with this string to avoid collisions.
57module_prefix = 'perfetto_'
58
59# Shared libraries which are directly translated to Android system equivalents.
60library_whitelist = [
61 'android',
Sami Kyostilab5b71692018-01-12 12:16:44 +000062 'binder',
Sami Kyostila865d1d32017-12-12 18:37:04 +000063 'log',
Sami Kyostilab5b71692018-01-12 12:16:44 +000064 'services',
Primiano Tucciedf099c2018-01-08 18:27:56 +000065 'utils',
Sami Kyostila865d1d32017-12-12 18:37:04 +000066]
67
68# Name of the module which settings such as compiler flags for all other
69# modules.
70defaults_module = module_prefix + 'defaults'
71
72# Location of the project in the Android source tree.
73tree_path = 'external/perfetto'
74
Primiano Tucciedf099c2018-01-08 18:27:56 +000075# Compiler flags which are passed through to the blueprint.
76cflag_whitelist = r'^-DPERFETTO.*$'
77
Sami Kyostila865d1d32017-12-12 18:37:04 +000078
79def enable_gmock(module):
80 module.static_libs.append('libgmock')
81
82
Hector Dearman3e712a02017-12-19 16:39:59 +000083def enable_gtest_prod(module):
84 module.static_libs.append('libgtest_prod')
85
86
Sami Kyostila865d1d32017-12-12 18:37:04 +000087def enable_gtest(module):
88 assert module.type == 'cc_test'
89
90
91def enable_protobuf_full(module):
92 module.shared_libs.append('libprotobuf-cpp-full')
93
94
95def enable_protobuf_lite(module):
96 module.shared_libs.append('libprotobuf-cpp-lite')
97
98
99def enable_protoc_lib(module):
100 module.shared_libs.append('libprotoc')
101
102
103def enable_libunwind(module):
Sami Kyostilafc074d42017-12-15 10:33:42 +0000104 # libunwind is disabled on Darwin so we cannot depend on it.
105 pass
Sami Kyostila865d1d32017-12-12 18:37:04 +0000106
107
108# Android equivalents for third-party libraries that the upstream project
109# depends on.
110builtin_deps = {
111 '//buildtools:gmock': enable_gmock,
112 '//buildtools:gtest': enable_gtest,
Hector Dearman3e712a02017-12-19 16:39:59 +0000113 '//gn:gtest_prod_config': enable_gtest_prod,
Sami Kyostila865d1d32017-12-12 18:37:04 +0000114 '//buildtools:gtest_main': enable_gtest,
115 '//buildtools:libunwind': enable_libunwind,
116 '//buildtools:protobuf_full': enable_protobuf_full,
117 '//buildtools:protobuf_lite': enable_protobuf_lite,
118 '//buildtools:protoc_lib': enable_protoc_lib,
119}
120
121# ----------------------------------------------------------------------------
122# End of configuration.
123# ----------------------------------------------------------------------------
124
125
126class Error(Exception):
127 pass
128
129
130class ThrowingArgumentParser(argparse.ArgumentParser):
131 def __init__(self, context):
132 super(ThrowingArgumentParser, self).__init__()
133 self.context = context
134
135 def error(self, message):
136 raise Error('%s: %s' % (self.context, message))
137
138
139class Module(object):
140 """A single module (e.g., cc_binary, cc_test) in a blueprint."""
141
142 def __init__(self, mod_type, name):
143 self.type = mod_type
144 self.name = name
145 self.srcs = []
146 self.comment = None
147 self.shared_libs = []
148 self.static_libs = []
149 self.tools = []
150 self.cmd = None
Primiano Tucci6067e732018-01-08 16:19:40 +0000151 self.init_rc = []
Sami Kyostila865d1d32017-12-12 18:37:04 +0000152 self.out = []
153 self.export_include_dirs = []
154 self.generated_headers = []
Lalit Magantic5bcd792018-01-12 18:38:11 +0000155 self.export_generated_headers = []
Sami Kyostila865d1d32017-12-12 18:37:04 +0000156 self.defaults = []
157 self.cflags = []
158 self.local_include_dirs = []
159
160 def to_string(self, output):
161 if self.comment:
162 output.append('// %s' % self.comment)
163 output.append('%s {' % self.type)
164 self._output_field(output, 'name')
165 self._output_field(output, 'srcs')
166 self._output_field(output, 'shared_libs')
167 self._output_field(output, 'static_libs')
168 self._output_field(output, 'tools')
169 self._output_field(output, 'cmd', sort=False)
Primiano Tucci6067e732018-01-08 16:19:40 +0000170 self._output_field(output, 'init_rc')
Sami Kyostila865d1d32017-12-12 18:37:04 +0000171 self._output_field(output, 'out')
172 self._output_field(output, 'export_include_dirs')
173 self._output_field(output, 'generated_headers')
Lalit Magantic5bcd792018-01-12 18:38:11 +0000174 self._output_field(output, 'export_generated_headers')
Sami Kyostila865d1d32017-12-12 18:37:04 +0000175 self._output_field(output, 'defaults')
176 self._output_field(output, 'cflags')
177 self._output_field(output, 'local_include_dirs')
178 output.append('}')
179 output.append('')
180
181 def _output_field(self, output, name, sort=True):
182 value = getattr(self, name)
183 if not value:
184 return
185 if isinstance(value, list):
186 output.append(' %s: [' % name)
187 for item in sorted(value) if sort else value:
188 output.append(' "%s",' % item)
189 output.append(' ],')
190 else:
191 output.append(' %s: "%s",' % (name, value))
192
193
194class Blueprint(object):
195 """In-memory representation of an Android.bp file."""
196
197 def __init__(self):
198 self.modules = {}
199
200 def add_module(self, module):
201 """Adds a new module to the blueprint, replacing any existing module
202 with the same name.
203
204 Args:
205 module: Module instance.
206 """
207 self.modules[module.name] = module
208
209 def to_string(self, output):
Sami Kyostilaebba0fe2017-12-19 14:01:52 +0000210 for m in sorted(self.modules.itervalues(), key=lambda m: m.name):
Sami Kyostila865d1d32017-12-12 18:37:04 +0000211 m.to_string(output)
212
213
214def label_to_path(label):
215 """Turn a GN output label (e.g., //some_dir/file.cc) into a path."""
216 assert label.startswith('//')
217 return label[2:]
218
219
220def label_to_module_name(label):
221 """Turn a GN label (e.g., //:perfetto_tests) into a module name."""
Primiano Tucci4e49c022017-12-21 18:22:44 +0100222 module = re.sub(r'^//:?', '', label)
223 module = re.sub(r'[^a-zA-Z0-9_]', '_', module)
224 if not module.startswith(module_prefix) and label not in default_targets:
Sami Kyostila865d1d32017-12-12 18:37:04 +0000225 return module_prefix + module
226 return module
227
228
229def label_without_toolchain(label):
230 """Strips the toolchain from a GN label.
231
232 Return a GN label (e.g //buildtools:protobuf(//gn/standalone/toolchain:
233 gcc_like_host) without the parenthesised toolchain part.
234 """
235 return label.split('(')[0]
236
237
238def is_supported_source_file(name):
239 """Returns True if |name| can appear in a 'srcs' list."""
240 return os.path.splitext(name)[1] in ['.c', '.cc', '.proto']
241
242
243def is_generated_by_action(desc, label):
244 """Checks if a label is generated by an action.
245
246 Returns True if a GN output label |label| is an output for any action,
247 i.e., the file is generated dynamically.
248 """
249 for target in desc.itervalues():
250 if target['type'] == 'action' and label in target['outputs']:
251 return True
252 return False
253
254
255def apply_module_dependency(blueprint, desc, module, dep_name):
256 """Recursively collect dependencies for a given module.
257
258 Walk the transitive dependencies for a GN target and apply them to a given
259 module. This effectively flattens the dependency tree so that |module|
260 directly contains all the sources, libraries, etc. in the corresponding GN
261 dependency tree.
262
263 Args:
264 blueprint: Blueprint instance which is being generated.
265 desc: JSON GN description.
266 module: Module to which dependencies should be added.
267 dep_name: GN target of the dependency.
268 """
Sami Kyostila865d1d32017-12-12 18:37:04 +0000269 # If the dependency refers to a library which we can replace with an Android
270 # equivalent, stop recursing and patch the dependency in.
271 if label_without_toolchain(dep_name) in builtin_deps:
272 builtin_deps[label_without_toolchain(dep_name)](module)
273 return
274
275 # Similarly some shared libraries are directly mapped to Android
276 # equivalents.
277 target = desc[dep_name]
278 for lib in target.get('libs', []):
279 android_lib = 'lib' + lib
280 if lib in library_whitelist and not android_lib in module.shared_libs:
281 module.shared_libs.append(android_lib)
282
283 type = target['type']
284 if type == 'action':
285 create_modules_from_target(blueprint, desc, dep_name)
286 # Depend both on the generated sources and headers -- see
287 # make_genrules_for_action.
288 module.srcs.append(':' + label_to_module_name(dep_name))
289 module.generated_headers.append(
290 label_to_module_name(dep_name) + '_headers')
Sami Kyostilaebba0fe2017-12-19 14:01:52 +0000291 elif type == 'static_library' and label_to_module_name(
292 dep_name) != module.name:
293 create_modules_from_target(blueprint, desc, dep_name)
294 module.static_libs.append(label_to_module_name(dep_name))
Primiano Tucci6067e732018-01-08 16:19:40 +0000295 elif type == 'shared_library' and label_to_module_name(
296 dep_name) != module.name:
297 module.shared_libs.append(label_to_module_name(dep_name))
Sami Kyostilaebba0fe2017-12-19 14:01:52 +0000298 elif type in ['group', 'source_set', 'executable', 'static_library'
299 ] and 'sources' in target:
Sami Kyostila865d1d32017-12-12 18:37:04 +0000300 # Ignore source files that are generated by actions since they will be
301 # implicitly added by the genrule dependencies.
302 module.srcs.extend(
303 label_to_path(src) for src in target['sources']
304 if is_supported_source_file(src)
305 and not is_generated_by_action(desc, src))
306
307
308def make_genrules_for_action(blueprint, desc, target_name):
309 """Generate genrules for a GN action.
310
311 GN actions are used to dynamically generate files during the build. The
312 Soong equivalent is a genrule. This function turns a specific kind of
313 genrule which turns .proto files into source and header files into a pair
Sami Kyostila71625d72017-12-18 10:29:49 +0000314 equivalent genrules.
Sami Kyostila865d1d32017-12-12 18:37:04 +0000315
316 Args:
317 blueprint: Blueprint instance which is being generated.
318 desc: JSON GN description.
319 target_name: GN target for genrule generation.
320
321 Returns:
322 A (source_genrule, header_genrule) module tuple.
323 """
324 target = desc[target_name]
325
326 # We only support genrules which call protoc (with or without a plugin) to
327 # turn .proto files into header and source files.
328 args = target['args']
329 if not args[0].endswith('/protoc'):
330 raise Error('Unsupported action in target %s: %s' % (target_name,
331 target['args']))
332
333 # We create two genrules for each action: one for the protobuf headers and
334 # another for the sources. This is because the module that depends on the
335 # generated files needs to declare two different types of dependencies --
336 # source files in 'srcs' and headers in 'generated_headers' -- and it's not
337 # valid to generate .h files from a source dependency and vice versa.
Sami Kyostila71625d72017-12-18 10:29:49 +0000338 source_module = Module('genrule', label_to_module_name(target_name))
Sami Kyostila865d1d32017-12-12 18:37:04 +0000339 source_module.srcs.extend(label_to_path(src) for src in target['sources'])
340 source_module.tools = ['aprotoc']
341
Sami Kyostila71625d72017-12-18 10:29:49 +0000342 header_module = Module('genrule',
Sami Kyostila865d1d32017-12-12 18:37:04 +0000343 label_to_module_name(target_name) + '_headers')
344 header_module.srcs = source_module.srcs[:]
345 header_module.tools = source_module.tools[:]
346 header_module.export_include_dirs = ['.']
347
348 # TODO(skyostil): Is there a way to avoid hardcoding the tree path here?
349 # TODO(skyostil): Find a way to avoid creating the directory.
350 cmd = [
351 'mkdir -p $(genDir)/%s &&' % tree_path, '$(location aprotoc)',
352 '--cpp_out=$(genDir)/%s' % tree_path,
353 '--proto_path=%s' % tree_path
354 ]
355 namespaces = ['pb']
356
357 parser = ThrowingArgumentParser('Action in target %s (%s)' %
358 (target_name, ' '.join(target['args'])))
359 parser.add_argument('--proto_path')
360 parser.add_argument('--cpp_out')
361 parser.add_argument('--plugin')
362 parser.add_argument('--plugin_out')
363 parser.add_argument('protos', nargs=argparse.REMAINDER)
364
365 args = parser.parse_args(args[1:])
366 if args.plugin:
367 _, plugin = os.path.split(args.plugin)
368 # TODO(skyostil): Can we detect this some other way?
369 if plugin == 'ipc_plugin':
370 namespaces.append('ipc')
371 elif plugin == 'protoc_plugin':
372 namespaces = ['pbzero']
373 for dep in target['deps']:
374 if desc[dep]['type'] != 'executable':
375 continue
376 _, executable = os.path.split(desc[dep]['outputs'][0])
377 if executable == plugin:
378 cmd += [
379 '--plugin=protoc-gen-plugin=$(location %s)' %
380 label_to_module_name(dep)
381 ]
382 source_module.tools.append(label_to_module_name(dep))
383 # Also make sure the module for the tool is generated.
384 create_modules_from_target(blueprint, desc, dep)
385 break
386 else:
387 raise Error('Unrecognized protoc plugin in target %s: %s' %
388 (target_name, args[i]))
389 if args.plugin_out:
390 plugin_args = args.plugin_out.split(':')[0]
391 cmd += ['--plugin_out=%s:$(genDir)/%s' % (plugin_args, tree_path)]
392
393 cmd += ['$(in)']
394 source_module.cmd = ' '.join(cmd)
395 header_module.cmd = source_module.cmd
396 header_module.tools = source_module.tools[:]
397
398 for ns in namespaces:
399 source_module.out += [
400 '%s/%s' % (tree_path, src.replace('.proto', '.%s.cc' % ns))
401 for src in source_module.srcs
402 ]
403 header_module.out += [
404 '%s/%s' % (tree_path, src.replace('.proto', '.%s.h' % ns))
405 for src in header_module.srcs
406 ]
407 return source_module, header_module
408
409
410def create_modules_from_target(blueprint, desc, target_name):
411 """Generate module(s) for a given GN target.
412
413 Given a GN target name, generate one or more corresponding modules into a
414 blueprint.
415
416 Args:
417 blueprint: Blueprint instance which is being generated.
418 desc: JSON GN description.
419 target_name: GN target for module generation.
420 """
421 target = desc[target_name]
422 if target['type'] == 'executable':
423 if 'host' in target['toolchain']:
424 module_type = 'cc_binary_host'
425 elif target.get('testonly'):
426 module_type = 'cc_test'
427 else:
428 module_type = 'cc_binary'
429 modules = [Module(module_type, label_to_module_name(target_name))]
430 elif target['type'] == 'action':
431 modules = make_genrules_for_action(blueprint, desc, target_name)
Sami Kyostilaebba0fe2017-12-19 14:01:52 +0000432 elif target['type'] == 'static_library':
Lalit Magantic5bcd792018-01-12 18:38:11 +0000433 module = Module('cc_library_static', label_to_module_name(target_name))
434 module.export_include_dirs = ['include']
435 modules = [module]
Primiano Tucci6067e732018-01-08 16:19:40 +0000436 elif target['type'] == 'shared_library':
437 modules = [
438 Module('cc_library_shared', label_to_module_name(target_name))
439 ]
Sami Kyostila865d1d32017-12-12 18:37:04 +0000440 else:
441 raise Error('Unknown target type: %s' % target['type'])
442
443 for module in modules:
444 module.comment = 'GN target: %s' % target_name
Primiano Tucci6067e732018-01-08 16:19:40 +0000445 if target_name in target_initrc:
446 module.init_rc = [target_initrc[target_name]]
447
Sami Kyostilaebba0fe2017-12-19 14:01:52 +0000448 # Don't try to inject library/source dependencies into genrules because
449 # they are not compiled in the traditional sense.
Sami Kyostila71625d72017-12-18 10:29:49 +0000450 if module.type != 'genrule':
Primiano Tucciedf099c2018-01-08 18:27:56 +0000451 for flag in target.get('cflags', []):
452 if re.match(cflag_whitelist, flag):
453 module.cflags.append(flag)
Sami Kyostila865d1d32017-12-12 18:37:04 +0000454 module.defaults = [defaults_module]
Sami Kyostilaebba0fe2017-12-19 14:01:52 +0000455 apply_module_dependency(blueprint, desc, module, target_name)
456 for dep in resolve_dependencies(desc, target_name):
457 apply_module_dependency(blueprint, desc, module, dep)
Sami Kyostila865d1d32017-12-12 18:37:04 +0000458
Lalit Magantic5bcd792018-01-12 18:38:11 +0000459 # If the module is a static library, export all the generated headers.
460 if module.type == 'cc_library_static':
461 module.export_generated_headers = module.generated_headers
462
Sami Kyostila865d1d32017-12-12 18:37:04 +0000463 blueprint.add_module(module)
464
465
466def resolve_dependencies(desc, target_name):
467 """Return the transitive set of dependent-on targets for a GN target.
468
469 Args:
470 blueprint: Blueprint instance which is being generated.
471 desc: JSON GN description.
472
473 Returns:
474 A set of transitive dependencies in the form of GN targets.
475 """
476
477 if label_without_toolchain(target_name) in builtin_deps:
478 return set()
479 target = desc[target_name]
480 resolved_deps = set()
481 for dep in target.get('deps', []):
482 resolved_deps.add(dep)
483 # Ignore the transitive dependencies of actions because they are
484 # explicitly converted to genrules.
485 if desc[dep]['type'] == 'action':
486 continue
Primiano Tucci6067e732018-01-08 16:19:40 +0000487 # Dependencies on shared libraries shouldn't propagate any transitive
488 # dependencies but only depend on the shared library target
489 if desc[dep]['type'] == 'shared_library':
490 continue
Sami Kyostila865d1d32017-12-12 18:37:04 +0000491 resolved_deps.update(resolve_dependencies(desc, dep))
492 return resolved_deps
493
494
495def create_blueprint_for_targets(desc, targets):
496 """Generate a blueprint for a list of GN targets."""
497 blueprint = Blueprint()
498
499 # Default settings used by all modules.
500 defaults = Module('cc_defaults', defaults_module)
501 defaults.local_include_dirs = ['include']
502 defaults.cflags = [
503 '-Wno-error=return-type',
504 '-Wno-sign-compare',
505 '-Wno-sign-promo',
506 '-Wno-unused-parameter',
Florian Mayercc424fd2018-01-15 11:19:01 +0000507 '-fvisibility=hidden',
Florian Mayerc2a38ea2018-01-19 11:48:43 +0000508 '-Oz',
Sami Kyostila865d1d32017-12-12 18:37:04 +0000509 ]
510
511 blueprint.add_module(defaults)
512 for target in targets:
513 create_modules_from_target(blueprint, desc, target)
514 return blueprint
515
516
Sami Kyostilab27619f2017-12-13 19:22:16 +0000517def repo_root():
518 """Returns an absolute path to the repository root."""
519
520 return os.path.join(
521 os.path.realpath(os.path.dirname(__file__)), os.path.pardir)
522
523
524def create_build_description():
525 """Creates the JSON build description by running GN."""
526
527 out = os.path.join(repo_root(), 'out', 'tmp.gen_android_bp')
528 try:
529 try:
530 os.makedirs(out)
531 except OSError as e:
532 if e.errno != errno.EEXIST:
533 raise
534 subprocess.check_output(
535 ['gn', 'gen', out, '--args=%s' % gn_args], cwd=repo_root())
536 desc = subprocess.check_output(
537 ['gn', 'desc', out, '--format=json', '--all-toolchains', '//*'],
538 cwd=repo_root())
539 return json.loads(desc)
540 finally:
541 shutil.rmtree(out)
542
543
Sami Kyostila865d1d32017-12-12 18:37:04 +0000544def main():
545 parser = argparse.ArgumentParser(
546 description='Generate Android.bp from a GN description.')
547 parser.add_argument(
Sami Kyostilab27619f2017-12-13 19:22:16 +0000548 '--desc',
Sami Kyostila865d1d32017-12-12 18:37:04 +0000549 help=
550 'GN description (e.g., gn desc out --format=json --all-toolchains "//*"'
551 )
552 parser.add_argument(
Lalit Magantic5bcd792018-01-12 18:38:11 +0000553 '--extras',
554 help='Extra targets to include at the end of the Blueprint file',
555 default=os.path.join(repo_root(), 'Android.bp.extras'),
556 )
557 parser.add_argument(
Sami Kyostilab27619f2017-12-13 19:22:16 +0000558 '--output',
559 help='Blueprint file to create',
560 default=os.path.join(repo_root(), 'Android.bp'),
561 )
562 parser.add_argument(
Sami Kyostila865d1d32017-12-12 18:37:04 +0000563 'targets',
564 nargs=argparse.REMAINDER,
565 help='Targets to include in the blueprint (e.g., "//:perfetto_tests")')
566 args = parser.parse_args()
567
Sami Kyostilab27619f2017-12-13 19:22:16 +0000568 if args.desc:
569 with open(args.desc) as f:
570 desc = json.load(f)
571 else:
572 desc = create_build_description()
Sami Kyostila865d1d32017-12-12 18:37:04 +0000573
Sami Kyostilab27619f2017-12-13 19:22:16 +0000574 blueprint = create_blueprint_for_targets(desc, args.targets
575 or default_targets)
Sami Kyostila865d1d32017-12-12 18:37:04 +0000576 output = [
577 """// Copyright (C) 2017 The Android Open Source Project
578//
579// Licensed under the Apache License, Version 2.0 (the "License");
580// you may not use this file except in compliance with the License.
581// You may obtain a copy of the License at
582//
583// http://www.apache.org/licenses/LICENSE-2.0
584//
585// Unless required by applicable law or agreed to in writing, software
586// distributed under the License is distributed on an "AS IS" BASIS,
587// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
588// See the License for the specific language governing permissions and
589// limitations under the License.
590//
591// This file is automatically generated by %s. Do not edit.
592""" % (__file__)
593 ]
594 blueprint.to_string(output)
Lalit Magantic5bcd792018-01-12 18:38:11 +0000595 with open(args.extras, 'r') as r:
596 for line in r:
597 output.append(line.rstrip("\n\r"))
Sami Kyostilab27619f2017-12-13 19:22:16 +0000598 with open(args.output, 'w') as f:
599 f.write('\n'.join(output))
Sami Kyostila865d1d32017-12-12 18:37:04 +0000600
601
602if __name__ == '__main__':
603 sys.exit(main())