|
| 1 | +#!/usr/bin/env python |
| 2 | +# Copyright 2015 The Chromium Authors. All rights reserved. |
| 3 | +# Use of this source code is governed by a BSD-style license that can be |
| 4 | +# found in the LICENSE file. |
| 5 | + |
| 6 | +import argparse |
| 7 | +import subprocess |
| 8 | +import sys |
| 9 | +import os |
| 10 | + |
| 11 | +def get_out_dir(args): |
| 12 | + target_dir = 'Release' |
| 13 | + if args.debug: |
| 14 | + target_dir = 'Debug' |
| 15 | + if args.target_os == 'android': |
| 16 | + target_dir = 'android_' + target_dir |
| 17 | + elif args.target_os == 'ios': |
| 18 | + target_dir = 'ios_' + target_dir |
| 19 | + return os.path.join('out', target_dir) |
| 20 | + |
| 21 | +def to_command_line(gn_args): |
| 22 | + def merge(key, value): |
| 23 | + if type(value) is bool: |
| 24 | + return "%s=%s" % (key, "true" if value else "false") |
| 25 | + return "%s=\"%s\"" % (key, value) |
| 26 | + return [merge(x, y) for x, y in gn_args.iteritems()] |
| 27 | + |
| 28 | +def to_gn_args(args): |
| 29 | + gn_args = {} |
| 30 | + |
| 31 | + gn_args["is_debug"] = args.debug |
| 32 | + gn_args["is_clang"] = args.target_os not in ['android'] |
| 33 | + |
| 34 | + # TODO(abarth): Add support for goma. |
| 35 | + gn_args["use_goma"] = False |
| 36 | + |
| 37 | + if args.target_os == 'android': |
| 38 | + gn_args["target_os"] = "android" |
| 39 | + elif args.target_os == 'ios': |
| 40 | + gn_args["target_os"] = "ios" |
| 41 | + gn_args["ios_deployment_target"] = "7.0" |
| 42 | + gn_args["clang_use_chrome_plugins"] = False |
| 43 | + if config.simulator: |
| 44 | + gn_args["use_libjpeg_turbo"] = False |
| 45 | + gn_args["use_ios_simulator"] = config.simulator |
| 46 | + else: |
| 47 | + gn_args["use_aura"] = False |
| 48 | + gn_args["use_glib"] = False |
| 49 | + gn_args["use_system_harfbuzz"] = False |
| 50 | + |
| 51 | + if args.target_os in ['android', 'ios']: |
| 52 | + gn_args["target_cpu"] = 'arm' |
| 53 | + else: |
| 54 | + gn_args["target_cpu"] = 'x64' |
| 55 | + return gn_args |
| 56 | + |
| 57 | + |
| 58 | +def main(): |
| 59 | + parser = argparse.ArgumentParser(description='A script run` gn gen`.') |
| 60 | + parser.add_argument('--debug', default=True) |
| 61 | + parser.add_argument('--target-os', type=str) |
| 62 | + parser.add_argument('--android', dest='target_os', action='store_const', const='android') |
| 63 | + parser.add_argument('--ios', dest='target_os', action='store_const', const='ios') |
| 64 | + parser.add_argument('--simulator', default=False) |
| 65 | + args = parser.parse_args() |
| 66 | + |
| 67 | + command = ['gn', 'gen', '--check'] |
| 68 | + gn_args = to_command_line(to_gn_args(args)) |
| 69 | + out_dir = get_out_dir(args) |
| 70 | + command.append(out_dir) |
| 71 | + command.append('--args=%s' % ' '.join(gn_args)) |
| 72 | + return subprocess.call(command) |
| 73 | + |
| 74 | + |
| 75 | +if __name__ == '__main__': |
| 76 | + sys.exit(main()) |
0 commit comments