Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 9b159fb

Browse files
committed
Merge pull request #7 from abarth/gn_tool
Add //sky/tools/gn to automate running `gn`
2 parents e3f2ea2 + 615da93 commit 9b159fb

File tree

2 files changed

+78
-4
lines changed

2 files changed

+78
-4
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,13 @@ target.
3939
### Android
4040

4141
* (Only the first time) `./build/install-build-deps-android.sh`
42-
* `./mojo/tools/mojob.py gn --android` (Note: There's currently a harmless
43-
go-related error when running this command.)
42+
* `./sky/tools/gn --android`
4443
* `ninja -C out/android_Debug`
4544

4645
### Linux
4746

4847
* (Only the first time) `./build/install-build-deps.sh`
49-
* `./mojo/tools/mojob.py gn` (Note: There's currently a harmless go-related
50-
error when running this command.)
48+
* `./sky/tools/gn`
5149
* `ninja -C out/Debug`
5250

5351
Contributing code

sky/tools/gn

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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

Comments
 (0)