forked from dart-lang/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_buildfiles.py
executable file
·113 lines (91 loc) · 2.4 KB
/
generate_buildfiles.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env python3
# Copyright 2016 The Dart project 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 os
import subprocess
import sys
import utils
HOST_OS = utils.GuessOS()
SCRIPT_DIR = os.path.dirname(sys.argv[0])
DART_ROOT = os.path.realpath(os.path.join(SCRIPT_DIR, '..'))
DART_DISABLE_BUILDFILES = "DART_DISABLE_BUILDFILES"
def DisableBuildfiles():
return DART_DISABLE_BUILDFILES in os.environ
def Execute(args):
process = subprocess.Popen(args, cwd=DART_ROOT)
process.wait()
return process.returncode
def RunAndroidGn(options):
if not HOST_OS in ['linux', 'macos']:
return 0
gn_command = [
'python3',
os.path.join(DART_ROOT, 'tools', 'gn.py'),
'-m',
'all',
'-a',
'arm,arm64',
'--os',
'android',
]
if options.verbose:
gn_command.append('-v')
print(' '.join(gn_command))
return Execute(gn_command)
def RunCrossGn(options):
if HOST_OS != 'linux':
return 0
gn_command = [
'python3',
os.path.join(DART_ROOT, 'tools', 'gn.py'),
'-m',
'all',
'-a',
'arm,arm64',
]
if options.verbose:
gn_command.append('-v')
print(' '.join(gn_command))
return Execute(gn_command)
def RunHostGn(options):
gn_command = [
'python3',
os.path.join(DART_ROOT, 'tools', 'gn.py'),
'-m',
'all',
'-a',
'all',
]
if options.verbose:
gn_command.append('-v')
print(' '.join(gn_command))
return Execute(gn_command)
def RunGn(options):
status = RunHostGn(options)
if status != 0:
return status
status = RunCrossGn(options)
if status != 0:
return status
return RunAndroidGn(options)
def ParseArgs(args):
args = args[1:]
parser = argparse.ArgumentParser(
description="A script to generate Dart's build files.")
parser.add_argument(
"-v",
"--verbose",
help='Verbose output.',
default=False,
action="store_true")
return parser.parse_args(args)
def main(argv):
# Check the environment and become a no-op if directed.
if DisableBuildfiles():
return 0
options = ParseArgs(argv)
RunGn(options)
if __name__ == '__main__':
sys.exit(main(sys.argv))