2021-04-15 10:10:20 +00:00
|
|
|
#!/usr/bin/env python3
|
2016-10-05 21:07:22 +00:00
|
|
|
# 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
|
|
|
|
|
2017-05-07 06:52:23 +00:00
|
|
|
HOST_OS = utils.GuessOS()
|
2016-10-05 21:07:22 +00:00
|
|
|
SCRIPT_DIR = os.path.dirname(sys.argv[0])
|
|
|
|
DART_ROOT = os.path.realpath(os.path.join(SCRIPT_DIR, '..'))
|
2016-11-15 20:54:49 +00:00
|
|
|
DART_DISABLE_BUILDFILES = "DART_DISABLE_BUILDFILES"
|
2016-10-05 21:07:22 +00:00
|
|
|
|
|
|
|
|
2017-05-08 19:31:41 +00:00
|
|
|
def DisableBuildfiles():
|
2019-08-05 20:34:31 +00:00
|
|
|
return DART_DISABLE_BUILDFILES in os.environ
|
2016-11-15 20:54:49 +00:00
|
|
|
|
|
|
|
|
2017-05-08 19:31:41 +00:00
|
|
|
def Execute(args):
|
2019-08-05 20:34:31 +00:00
|
|
|
process = subprocess.Popen(args, cwd=DART_ROOT)
|
|
|
|
process.wait()
|
|
|
|
return process.returncode
|
2016-10-05 21:07:22 +00:00
|
|
|
|
|
|
|
|
2017-05-08 19:31:41 +00:00
|
|
|
def RunAndroidGn(options):
|
2019-08-05 20:34:31 +00:00
|
|
|
if not HOST_OS in ['linux', 'macos']:
|
|
|
|
return 0
|
|
|
|
gn_command = [
|
2021-04-15 10:10:20 +00:00
|
|
|
'python3',
|
2019-08-05 20:34:31 +00:00
|
|
|
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)
|
2017-05-07 06:52:23 +00:00
|
|
|
|
|
|
|
|
2017-05-09 16:47:49 +00:00
|
|
|
def RunCrossGn(options):
|
2019-08-05 20:34:31 +00:00
|
|
|
if HOST_OS != 'linux':
|
|
|
|
return 0
|
|
|
|
gn_command = [
|
2021-04-15 10:10:20 +00:00
|
|
|
'python3',
|
2019-08-05 20:34:31 +00:00
|
|
|
os.path.join(DART_ROOT, 'tools', 'gn.py'),
|
|
|
|
'-m',
|
|
|
|
'all',
|
|
|
|
'-a',
|
2019-10-27 18:18:29 +00:00
|
|
|
'arm,arm64',
|
2019-08-05 20:34:31 +00:00
|
|
|
]
|
|
|
|
if options.verbose:
|
|
|
|
gn_command.append('-v')
|
|
|
|
print(' '.join(gn_command))
|
|
|
|
return Execute(gn_command)
|
2017-05-09 16:47:49 +00:00
|
|
|
|
|
|
|
|
2017-05-08 19:31:41 +00:00
|
|
|
def RunHostGn(options):
|
2019-08-05 20:34:31 +00:00
|
|
|
gn_command = [
|
2021-04-15 10:10:20 +00:00
|
|
|
'python3',
|
2019-08-05 20:34:31 +00:00
|
|
|
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)
|
2016-10-05 21:07:22 +00:00
|
|
|
|
|
|
|
|
2017-05-08 19:31:41 +00:00
|
|
|
def RunGn(options):
|
2019-08-05 20:34:31 +00:00
|
|
|
status = RunHostGn(options)
|
|
|
|
if status != 0:
|
|
|
|
return status
|
|
|
|
status = RunCrossGn(options)
|
|
|
|
if status != 0:
|
|
|
|
return status
|
|
|
|
return RunAndroidGn(options)
|
2017-05-07 06:52:23 +00:00
|
|
|
|
|
|
|
|
2017-05-08 19:31:41 +00:00
|
|
|
def ParseArgs(args):
|
2019-08-05 20:34:31 +00:00
|
|
|
args = args[1:]
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description="A script to generate Dart's build files.")
|
2016-10-05 21:07:22 +00:00
|
|
|
|
2019-08-05 20:34:31 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"-v",
|
|
|
|
"--verbose",
|
|
|
|
help='Verbose output.',
|
|
|
|
default=False,
|
|
|
|
action="store_true")
|
2017-08-05 05:19:26 +00:00
|
|
|
|
2019-08-05 20:34:31 +00:00
|
|
|
return parser.parse_args(args)
|
2016-10-05 21:07:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
def main(argv):
|
2019-08-05 20:34:31 +00:00
|
|
|
# Check the environment and become a no-op if directed.
|
|
|
|
if DisableBuildfiles():
|
|
|
|
return 0
|
|
|
|
options = ParseArgs(argv)
|
|
|
|
RunGn(options)
|
2016-10-05 21:07:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(main(sys.argv))
|