OLD | NEW |
| (Empty) |
1 #!/usr/bin/env python | |
2 # Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | |
3 # for details. All rights reserved. Use of this source code is governed by a | |
4 # BSD-style license that can be found in the LICENSE file. | |
5 """Used to run pub before the SDK has been built""" | |
6 | |
7 import argparse | |
8 import os | |
9 import platform | |
10 import subprocess | |
11 import sys | |
12 | |
13 SCRIPT_DIR = os.path.dirname(sys.argv[0]) | |
14 DART_ROOT = os.path.realpath(os.path.join(SCRIPT_DIR, '..')) | |
15 PUB_PATH = os.path.join(DART_ROOT, | |
16 'sdk/lib/_internal/pub_generated/bin/pub.dart') | |
17 CANARY_PATH = os.path.join(DART_ROOT, 'tools', 'canary.dart') | |
18 | |
19 usage = """run_pub.py --package-root=<package root>""" | |
20 | |
21 def BuildArguments(): | |
22 result = argparse.ArgumentParser(usage=usage) | |
23 result.add_argument("--package-root", help="package root", default=None) | |
24 result.add_argument("--dart-executable", help="dart binary", default=None) | |
25 return result | |
26 | |
27 def ProcessOptions(options, args): | |
28 return ((options.package_root != None) and | |
29 (options.dart_executable != None)) | |
30 | |
31 def GetPrebuiltDartExecutablePath(): | |
32 osdict = {'Darwin':'macos', 'Linux':'linux', 'Windows':'win32'} | |
33 system = platform.system() | |
34 try: | |
35 osname = osdict[system] | |
36 except KeyError: | |
37 print >>sys.stderr, ('WARNING: platform "%s" not supported') % (system) | |
38 return None; | |
39 return os.path.join(DART_ROOT, 'tools', 'testing', 'bin', osname, 'dart') | |
40 | |
41 def RunPub(dart, pkg_root, args): | |
42 return subprocess.call([dart, '--package-root=' + pkg_root, PUB_PATH] + args) | |
43 | |
44 def TryRunningExecutable(dart_executable, pkg_root): | |
45 return subprocess.call([dart_executable, | |
46 '--package-root=' + pkg_root, | |
47 CANARY_PATH]) == 42 | |
48 | |
49 def DisplayBootstrapWarning(): | |
50 print """\ | |
51 | |
52 | |
53 WARNING: Your system cannot run the prebuilt Dart executable. Using the | |
54 bootstrap Dart executable will make Debug builds long. | |
55 Please see Wiki for instructions on replacing prebuilt Dart executable. | |
56 | |
57 https://code.google.com/p/dart/wiki/ReplacingPrebuiltDartExecutable | |
58 | |
59 """ | |
60 | |
61 def main(): | |
62 # Parse the options. | |
63 parser = BuildArguments() | |
64 (options, args) = parser.parse_known_args() | |
65 if not ProcessOptions(options, args): | |
66 parser.print_help() | |
67 return 1 | |
68 dart_executable = GetPrebuiltDartExecutablePath() | |
69 # If the system cannot execute the prebuilt dart executable, use the bootstrap | |
70 # executable instead. | |
71 if not TryRunningExecutable(dart_executable, options.package_root): | |
72 DisplayBootstrapWarning() | |
73 dart_executable = options.dart_executable | |
74 # If requested, use the bootstrap binary instead of the prebuilt | |
75 # executable. | |
76 if os.getenv('DART_USE_BOOTSTRAP_BIN') != None: | |
77 dart_executable = options.dart_executable | |
78 return RunPub(dart_executable, options.package_root, args) | |
79 | |
80 | |
81 if __name__ == '__main__': | |
82 sys.exit(main()); | |
OLD | NEW |