Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(358)

Side by Side Diff: tools/generate_buildfiles.py

Issue 2871683002: [infra] Cleanup buildfile generation scripts a bit (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tools/gn.py » ('j') | tools/gn.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2016 The Dart project authors. All rights reserved. 2 # Copyright 2016 The Dart project authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import argparse 6 import argparse
7 import os 7 import os
8 import subprocess 8 import subprocess
9 import sys 9 import sys
10 import utils 10 import utils
11 11
12 HOST_OS = utils.GuessOS() 12 HOST_OS = utils.GuessOS()
13 SCRIPT_DIR = os.path.dirname(sys.argv[0]) 13 SCRIPT_DIR = os.path.dirname(sys.argv[0])
14 DART_ROOT = os.path.realpath(os.path.join(SCRIPT_DIR, '..')) 14 DART_ROOT = os.path.realpath(os.path.join(SCRIPT_DIR, '..'))
15 DART_USE_GYP = "DART_USE_GYP" 15 DART_USE_GYP = "DART_USE_GYP"
16 DART_DISABLE_BUILDFILES = "DART_DISABLE_BUILDFILES" 16 DART_DISABLE_BUILDFILES = "DART_DISABLE_BUILDFILES"
17 17
18 18
19 def use_gyp(): 19 def UseGyp():
20 return DART_USE_GYP in os.environ 20 return DART_USE_GYP in os.environ
21 21
22 22
23 def disable_buildfiles(): 23 def DisableBuildfiles():
24 return DART_DISABLE_BUILDFILES in os.environ 24 return DART_DISABLE_BUILDFILES in os.environ
25 25
26 26
27 def execute(args): 27 def Execute(args):
28 process = subprocess.Popen(args, cwd=DART_ROOT) 28 process = subprocess.Popen(args, cwd=DART_ROOT)
29 process.wait() 29 process.wait()
30 return process.returncode 30 return process.returncode
31 31
32 32
33 def run_android_gn(options): 33 def RunAndroidGn(options):
34 if not HOST_OS in ['linux', 'macos']: 34 if not HOST_OS in ['linux', 'macos']:
35 return 0 35 return 0
36 gn_command = [ 36 gn_command = [
37 'python', 37 'python',
38 os.path.join(DART_ROOT, 'tools', 'gn.py'), 38 os.path.join(DART_ROOT, 'tools', 'gn.py'),
39 '-m', 'all', 39 '-m', 'all',
40 '-a', 'arm,arm64', 40 '-a', 'arm,arm64',
41 '--os', 'android', 41 '--os', 'android',
42 ] 42 ]
43 if options.verbose: 43 if options.verbose:
44 gn_command.append('-v') 44 gn_command.append('-v')
45 print ' '.join(gn_command) 45 print ' '.join(gn_command)
46 return execute(gn_command) 46 return Execute(gn_command)
47 47
48 48
49 def run_host_gn(options): 49 def RunHostGn(options):
50 gn_command = [ 50 gn_command = [
51 'python', 51 'python',
52 os.path.join(DART_ROOT, 'tools', 'gn.py'), 52 os.path.join(DART_ROOT, 'tools', 'gn.py'),
53 '-m', 'all', 53 '-m', 'all',
54 '-a', 'all', 54 '-a', 'all',
55 ] 55 ]
56 if options.verbose: 56 if options.verbose:
57 gn_command.append('-v') 57 gn_command.append('-v')
58 print ' '.join(gn_command) 58 print ' '.join(gn_command)
59 return execute(gn_command) 59 return Execute(gn_command)
60 60
61 61
62 def run_gn(options): 62 def RunGn(options):
63 status = run_host_gn(options) 63 status = RunHostGn(options)
64 if status != 0: 64 if status != 0:
65 return status 65 return status
66 return run_android_gn(options) 66 return RunAndroidGn(options)
67 67
68 68
69 def run_gyp(options): 69 def RunGyp(options):
70 gyp_command = [ 70 gyp_command = [
71 'python', 71 'python',
72 os.path.join(DART_ROOT, 'tools', 'gyp_dart.py'), 72 os.path.join(DART_ROOT, 'tools', 'gyp_dart.py'),
73 ] 73 ]
74 if options.verbose: 74 if options.verbose:
75 print ' '.join(gyp_command) 75 print ' '.join(gyp_command)
76 return execute(gyp_command) 76 return Execute(gyp_command)
77 77
78 78
79 def parse_args(args): 79 def ParseArgs(args):
80 args = args[1:] 80 args = args[1:]
81 parser = argparse.ArgumentParser( 81 parser = argparse.ArgumentParser(
82 description="A script to generate Dart's build files.") 82 description="A script to generate Dart's build files.")
83 83
84 parser.add_argument("-v", "--verbose", 84 parser.add_argument("-v", "--verbose",
85 help='Verbose output.', 85 help='Verbose output.',
86 default=False, 86 default=False,
87 action="store_true") 87 action="store_true")
88 parser.add_argument("--gn", 88 parser.add_argument("--gn",
89 help='Use GN', 89 help='Use GN',
90 default=not use_gyp(), 90 default=not UseGyp(),
91 action='store_true') 91 action='store_true')
92 parser.add_argument("--gyp", 92 parser.add_argument("--gyp",
93 help='Use gyp', 93 help='Use gyp',
94 default=use_gyp(), 94 default=UseGyp(),
95 action='store_true') 95 action='store_true')
96 96
97 options = parser.parse_args(args) 97 options = parser.parse_args(args)
98 # If gyp is enabled one way or another, then disable gn 98 # If gyp is enabled one way or another, then disable gn
99 if options.gyp: 99 if options.gyp:
100 options.gn = False 100 options.gn = False
101 return options 101 return options
102 102
103 103
104 def main(argv): 104 def main(argv):
105 # Check the environment and become a no-op if directed. 105 # Check the environment and become a no-op if directed.
106 if disable_buildfiles(): 106 if DisableBuildfiles():
107 return 0 107 return 0
108 options = parse_args(argv) 108 options = ParseArgs(argv)
109 if options.gn: 109 if options.gn:
110 return run_gn(options) 110 return RunGn(options)
111 else: 111 else:
112 return run_gyp(options) 112 return RunGyp(options)
113 113
114 114
115 if __name__ == '__main__': 115 if __name__ == '__main__':
116 sys.exit(main(sys.argv)) 116 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « no previous file | tools/gn.py » ('j') | tools/gn.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698