2016-10-05 21:07:22 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# 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
|
|
|
|
|
|
|
|
SCRIPT_DIR = os.path.dirname(sys.argv[0])
|
|
|
|
DART_ROOT = os.path.realpath(os.path.join(SCRIPT_DIR, '..'))
|
2017-01-06 23:35:54 +00:00
|
|
|
DART_USE_GYP = "DART_USE_GYP"
|
2016-11-15 20:54:49 +00:00
|
|
|
DART_DISABLE_BUILDFILES = "DART_DISABLE_BUILDFILES"
|
2016-10-05 21:07:22 +00:00
|
|
|
|
|
|
|
|
2017-01-06 23:35:54 +00:00
|
|
|
def use_gyp():
|
|
|
|
return DART_USE_GYP in os.environ
|
2016-10-05 21:07:22 +00:00
|
|
|
|
|
|
|
|
2016-11-15 20:54:49 +00:00
|
|
|
def disable_buildfiles():
|
|
|
|
return DART_DISABLE_BUILDFILES in os.environ
|
|
|
|
|
|
|
|
|
2016-10-05 21:07:22 +00:00
|
|
|
def execute(args):
|
|
|
|
process = subprocess.Popen(args, cwd=DART_ROOT)
|
|
|
|
process.wait()
|
|
|
|
return process.returncode
|
|
|
|
|
|
|
|
|
2017-01-06 23:35:54 +00:00
|
|
|
def run_gn(options):
|
2016-10-05 21:07:22 +00:00
|
|
|
gn_command = [
|
|
|
|
'python',
|
|
|
|
os.path.join(DART_ROOT, 'tools', 'gn.py'),
|
|
|
|
'-m', 'all',
|
|
|
|
'-a', 'all',
|
|
|
|
]
|
2017-01-06 23:35:54 +00:00
|
|
|
if options.verbose:
|
|
|
|
gn_command.append('-v')
|
|
|
|
print ' '.join(gn_command)
|
2016-10-05 21:07:22 +00:00
|
|
|
return execute(gn_command)
|
|
|
|
|
|
|
|
|
2017-01-06 23:35:54 +00:00
|
|
|
def run_gyp(options):
|
2016-10-05 21:07:22 +00:00
|
|
|
gyp_command = [
|
|
|
|
'python',
|
|
|
|
os.path.join(DART_ROOT, 'tools', 'gyp_dart.py'),
|
|
|
|
]
|
2017-01-06 23:35:54 +00:00
|
|
|
if options.verbose:
|
|
|
|
print ' '.join(gyp_command)
|
2016-10-05 21:07:22 +00:00
|
|
|
return execute(gyp_command)
|
|
|
|
|
|
|
|
|
|
|
|
def parse_args(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")
|
|
|
|
parser.add_argument("--gn",
|
|
|
|
help='Use GN',
|
2017-01-06 23:35:54 +00:00
|
|
|
default=not use_gyp(),
|
2016-10-05 21:07:22 +00:00
|
|
|
action='store_true')
|
|
|
|
parser.add_argument("--gyp",
|
|
|
|
help='Use gyp',
|
2017-01-06 23:35:54 +00:00
|
|
|
default=use_gyp(),
|
2016-10-05 21:07:22 +00:00
|
|
|
action='store_true')
|
|
|
|
|
|
|
|
options = parser.parse_args(args)
|
2017-01-06 23:35:54 +00:00
|
|
|
# If gyp is enabled one way or another, then disable gn
|
|
|
|
if options.gyp:
|
|
|
|
options.gn = False
|
2016-10-05 21:07:22 +00:00
|
|
|
return options
|
|
|
|
|
|
|
|
|
|
|
|
def main(argv):
|
2016-11-15 20:54:49 +00:00
|
|
|
# Check the environment and become a no-op if directed.
|
|
|
|
if disable_buildfiles():
|
|
|
|
return 0
|
2016-10-05 21:07:22 +00:00
|
|
|
options = parse_args(argv)
|
|
|
|
if options.gn:
|
2017-01-06 23:35:54 +00:00
|
|
|
return run_gn(options)
|
2016-10-05 21:07:22 +00:00
|
|
|
else:
|
2017-01-06 23:35:54 +00:00
|
|
|
return run_gyp(options)
|
2016-10-05 21:07:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(main(sys.argv))
|