| OLD | NEW |
| 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 SCRIPT_DIR = os.path.dirname(sys.argv[0]) | 12 SCRIPT_DIR = os.path.dirname(sys.argv[0]) |
| 13 DART_ROOT = os.path.realpath(os.path.join(SCRIPT_DIR, '..')) | 13 DART_ROOT = os.path.realpath(os.path.join(SCRIPT_DIR, '..')) |
| 14 DART_USE_GN = "DART_USE_GN" | 14 DART_USE_GYP = "DART_USE_GYP" |
| 15 DART_DISABLE_BUILDFILES = "DART_DISABLE_BUILDFILES" | 15 DART_DISABLE_BUILDFILES = "DART_DISABLE_BUILDFILES" |
| 16 | 16 |
| 17 | 17 |
| 18 def use_gn(): | 18 def use_gyp(): |
| 19 return DART_USE_GN in os.environ | 19 return DART_USE_GYP in os.environ |
| 20 | 20 |
| 21 | 21 |
| 22 def disable_buildfiles(): | 22 def disable_buildfiles(): |
| 23 return DART_DISABLE_BUILDFILES in os.environ | 23 return DART_DISABLE_BUILDFILES in os.environ |
| 24 | 24 |
| 25 | 25 |
| 26 def execute(args): | 26 def execute(args): |
| 27 process = subprocess.Popen(args, cwd=DART_ROOT) | 27 process = subprocess.Popen(args, cwd=DART_ROOT) |
| 28 process.wait() | 28 process.wait() |
| 29 return process.returncode | 29 return process.returncode |
| 30 | 30 |
| 31 | 31 |
| 32 def run_gn(): | 32 def run_gn(options): |
| 33 gn_command = [ | 33 gn_command = [ |
| 34 'python', | 34 'python', |
| 35 os.path.join(DART_ROOT, 'tools', 'gn.py'), | 35 os.path.join(DART_ROOT, 'tools', 'gn.py'), |
| 36 '-m', 'all', | 36 '-m', 'all', |
| 37 '-a', 'all', | 37 '-a', 'all', |
| 38 ] | 38 ] |
| 39 if options.verbose: |
| 40 gn_command.append('-v') |
| 41 print ' '.join(gn_command) |
| 39 return execute(gn_command) | 42 return execute(gn_command) |
| 40 | 43 |
| 41 | 44 |
| 42 def run_gyp(): | 45 def run_gyp(options): |
| 43 gyp_command = [ | 46 gyp_command = [ |
| 44 'python', | 47 'python', |
| 45 os.path.join(DART_ROOT, 'tools', 'gyp_dart.py'), | 48 os.path.join(DART_ROOT, 'tools', 'gyp_dart.py'), |
| 46 ] | 49 ] |
| 50 if options.verbose: |
| 51 print ' '.join(gyp_command) |
| 47 return execute(gyp_command) | 52 return execute(gyp_command) |
| 48 | 53 |
| 49 | 54 |
| 50 def parse_args(args): | 55 def parse_args(args): |
| 51 args = args[1:] | 56 args = args[1:] |
| 52 parser = argparse.ArgumentParser( | 57 parser = argparse.ArgumentParser( |
| 53 description="A script to generate Dart's build files.") | 58 description="A script to generate Dart's build files.") |
| 54 | 59 |
| 55 parser.add_argument("-v", "--verbose", | 60 parser.add_argument("-v", "--verbose", |
| 56 help='Verbose output.', | 61 help='Verbose output.', |
| 57 default=False, | 62 default=False, |
| 58 action="store_true") | 63 action="store_true") |
| 59 parser.add_argument("--gn", | 64 parser.add_argument("--gn", |
| 60 help='Use GN', | 65 help='Use GN', |
| 61 default=use_gn(), | 66 default=not use_gyp(), |
| 62 action='store_true') | 67 action='store_true') |
| 63 parser.add_argument("--gyp", | 68 parser.add_argument("--gyp", |
| 64 help='Use gyp', | 69 help='Use gyp', |
| 65 default=not use_gn(), | 70 default=use_gyp(), |
| 66 action='store_true') | 71 action='store_true') |
| 67 | 72 |
| 68 options = parser.parse_args(args) | 73 options = parser.parse_args(args) |
| 69 # If gn is enabled one way or another, then disable gyp | 74 # If gyp is enabled one way or another, then disable gn |
| 70 if options.gn: | 75 if options.gyp: |
| 71 options.gyp = False | 76 options.gn = False |
| 72 return options | 77 return options |
| 73 | 78 |
| 74 | 79 |
| 75 def main(argv): | 80 def main(argv): |
| 76 # Check the environment and become a no-op if directed. | 81 # Check the environment and become a no-op if directed. |
| 77 if disable_buildfiles(): | 82 if disable_buildfiles(): |
| 78 return 0 | 83 return 0 |
| 79 options = parse_args(argv) | 84 options = parse_args(argv) |
| 80 if options.gn: | 85 if options.gn: |
| 81 return run_gn() | 86 return run_gn(options) |
| 82 else: | 87 else: |
| 83 return run_gyp() | 88 return run_gyp(options) |
| 84 | 89 |
| 85 | 90 |
| 86 if __name__ == '__main__': | 91 if __name__ == '__main__': |
| 87 sys.exit(main(sys.argv)) | 92 sys.exit(main(sys.argv)) |
| OLD | NEW |