From 615da9373693874d4ebe431632b581a7f708d09c Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Thu, 16 Jul 2015 13:31:11 -0700 Subject: [PATCH] Add //sky/tools/gn to automate running `gn` This lets us avoid using mojob.py, which errors out because we lack a go toolchain. --- CONTRIBUTING.md | 6 ++-- sky/tools/gn | 76 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 4 deletions(-) create mode 100755 sky/tools/gn diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b06e702b8..d8b6463e4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -39,15 +39,13 @@ target. ### Android * (Only the first time) `./build/install-build-deps-android.sh` -* `./mojo/tools/mojob.py gn --android` (Note: There's currently a harmless - go-related error when running this command.) +* `./sky/tools/gn --android` * `ninja -C out/android_Debug` ### Linux * (Only the first time) `./build/install-build-deps.sh` -* `./mojo/tools/mojob.py gn` (Note: There's currently a harmless go-related - error when running this command.) +* `./sky/tools/gn` * `ninja -C out/Debug` Contributing code diff --git a/sky/tools/gn b/sky/tools/gn new file mode 100755 index 000000000..40986c70b --- /dev/null +++ b/sky/tools/gn @@ -0,0 +1,76 @@ +#!/usr/bin/env python +# Copyright 2015 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import argparse +import subprocess +import sys +import os + +def get_out_dir(args): + target_dir = 'Release' + if args.debug: + target_dir = 'Debug' + if args.target_os == 'android': + target_dir = 'android_' + target_dir + elif args.target_os == 'ios': + target_dir = 'ios_' + target_dir + return os.path.join('out', target_dir) + +def to_command_line(gn_args): + def merge(key, value): + if type(value) is bool: + return "%s=%s" % (key, "true" if value else "false") + return "%s=\"%s\"" % (key, value) + return [merge(x, y) for x, y in gn_args.iteritems()] + +def to_gn_args(args): + gn_args = {} + + gn_args["is_debug"] = args.debug + gn_args["is_clang"] = args.target_os not in ['android'] + + # TODO(abarth): Add support for goma. + gn_args["use_goma"] = False + + if args.target_os == 'android': + gn_args["target_os"] = "android" + elif args.target_os == 'ios': + gn_args["target_os"] = "ios" + gn_args["ios_deployment_target"] = "7.0" + gn_args["clang_use_chrome_plugins"] = False + if config.simulator: + gn_args["use_libjpeg_turbo"] = False + gn_args["use_ios_simulator"] = config.simulator + else: + gn_args["use_aura"] = False + gn_args["use_glib"] = False + gn_args["use_system_harfbuzz"] = False + + if args.target_os in ['android', 'ios']: + gn_args["target_cpu"] = 'arm' + else: + gn_args["target_cpu"] = 'x64' + return gn_args + + +def main(): + parser = argparse.ArgumentParser(description='A script run` gn gen`.') + parser.add_argument('--debug', default=True) + parser.add_argument('--target-os', type=str) + parser.add_argument('--android', dest='target_os', action='store_const', const='android') + parser.add_argument('--ios', dest='target_os', action='store_const', const='ios') + parser.add_argument('--simulator', default=False) + args = parser.parse_args() + + command = ['gn', 'gen', '--check'] + gn_args = to_command_line(to_gn_args(args)) + out_dir = get_out_dir(args) + command.append(out_dir) + command.append('--args=%s' % ' '.join(gn_args)) + return subprocess.call(command) + + +if __name__ == '__main__': + sys.exit(main()) -- GitLab