OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 4 # BSD-style license that can be found in the LICENSE file. |
5 """Used to run pub before the SDK has been built""" | 5 """Used to run pub before the SDK has been built""" |
6 | 6 |
7 import argparse | 7 import argparse |
8 import os | 8 import os |
9 import platform | 9 import platform |
10 import subprocess | 10 import subprocess |
11 import sys | 11 import sys |
12 | 12 |
13 SCRIPT_DIR = os.path.dirname(sys.argv[0]) | 13 SCRIPT_DIR = os.path.dirname(sys.argv[0]) |
14 DART_ROOT = os.path.realpath(os.path.join(SCRIPT_DIR, '..')) | 14 DART_ROOT = os.path.realpath(os.path.join(SCRIPT_DIR, '..')) |
15 PUB_PATH = os.path.join(DART_ROOT, 'third_party/pkg/pub/bin/pub.dart') | 15 PUB_PATH = os.path.join(DART_ROOT, 'third_party/pkg/pub/bin/pub.dart') |
16 CANARY_PATH = os.path.join(DART_ROOT, 'tools', 'canary.dart') | |
17 | 16 |
18 usage = """run_pub.py --package-root=<package root>""" | 17 usage = """run_pub.py --package-root=<package root>""" |
19 | 18 |
20 def BuildArguments(): | 19 def BuildArguments(): |
21 result = argparse.ArgumentParser(usage=usage) | 20 result = argparse.ArgumentParser(usage=usage) |
22 result.add_argument("--package-root", help="package root", default=None) | 21 result.add_argument("--package-root", help="package root", default=None) |
23 result.add_argument("--dart-executable", help="dart binary", default=None) | 22 result.add_argument("--dart-executable", help="dart binary", default=None) |
24 return result | 23 return result |
25 | 24 |
26 def ProcessOptions(options, args): | 25 def ProcessOptions(options, args): |
27 return ((options.package_root != None) and | 26 return ((options.package_root != None) and |
28 (options.dart_executable != None)) | 27 (options.dart_executable != None)) |
29 | 28 |
30 def GetPrebuiltDartExecutablePath(suffix): | |
31 osdict = {'Darwin':'macos', 'Linux':'linux', 'Windows':'windows'} | |
32 system = platform.system() | |
33 executable_name = 'dart' | |
34 if system == 'Windows': | |
35 executable_name = 'dart.exe' | |
36 try: | |
37 osname = osdict[system] | |
38 except KeyError: | |
39 print >>sys.stderr, ('WARNING: platform "%s" not supported') % (system) | |
40 return None; | |
41 return os.path.join(DART_ROOT, | |
42 'tools', | |
43 'testing', | |
44 'bin', | |
45 osname, | |
46 executable_name + suffix) | |
47 | |
48 def RunPub(dart, pkg_root, args): | 29 def RunPub(dart, pkg_root, args): |
49 return subprocess.call([dart, '--package-root=' + pkg_root, PUB_PATH] + args) | 30 return subprocess.call([dart, '--package-root=' + pkg_root, PUB_PATH] + args) |
50 | 31 |
51 def TryRunningExecutable(dart_executable, pkg_root): | |
52 try: | |
53 return subprocess.call([dart_executable, | |
54 '--package-root=' + pkg_root, | |
55 CANARY_PATH]) == 42 | |
56 except: | |
57 return False; | |
58 | 32 |
59 def DisplayBootstrapWarning(): | 33 def DisplayBootstrapWarning(): |
60 print """\ | 34 print """\ |
61 | 35 |
62 | 36 |
63 WARNING: Your system cannot run the prebuilt Dart executable. Using the | 37 WARNING: Your system cannot run the checked-in Dart SDK. Using the |
64 bootstrap Dart executable will make Debug builds long. | 38 bootstrap Dart SDK will make debug builds slow. |
65 Please see Wiki for instructions on replacing prebuilt Dart executable. | 39 Please see the Wiki for instructions on replacing the checked-in Dart SDK. |
66 | 40 |
67 https://code.google.com/p/dart/wiki/ReplacingPrebuiltDartExecutable | 41 https://github.com/dart-lang/sdk/wiki/The-checked-in-SDK-in--tools |
Ivan Posva
2015/09/15 17:01:42
Why the double -- between "in" and "tools"?
Bill Hesse
2015/09/15 17:09:02
Done.
| |
68 | |
69 """ | 42 """ |
70 | 43 |
71 def FindDartExecutable(fallback_executable, package_root): | |
72 # If requested, use the bootstrap binary instead of the prebuilt | |
73 # executable. | |
74 if os.getenv('DART_USE_BOOTSTRAP_BIN') != None: | |
75 return fallback_executable | |
76 # Try to find a working prebuilt dart executable. | |
77 dart_executable = GetPrebuiltDartExecutablePath('') | |
78 if TryRunningExecutable(dart_executable, package_root): | |
79 return dart_executable | |
80 dart_executable = GetPrebuiltDartExecutablePath('-arm') | |
81 if TryRunningExecutable(dart_executable, package_root): | |
82 return dart_executable | |
83 dart_executable = GetPrebuiltDartExecutablePath('-mips') | |
84 if TryRunningExecutable(dart_executable, package_root): | |
85 return dart_executable | |
86 # If the system cannot execute a prebuilt dart executable, use the bootstrap | |
87 # executable instead. | |
88 DisplayBootstrapWarning() | |
89 return fallback_executable | |
90 | |
91 def main(): | 44 def main(): |
92 # Parse the options. | 45 # Parse the options. |
93 parser = BuildArguments() | 46 parser = BuildArguments() |
94 (options, args) = parser.parse_known_args() | 47 (options, args) = parser.parse_known_args() |
95 if not ProcessOptions(options, args): | 48 if not ProcessOptions(options, args): |
96 parser.print_help() | 49 parser.print_help() |
97 return 1 | 50 return 1 |
98 dart_executable = FindDartExecutable(options.dart_executable, | 51 DisplayBootstrapWarning() |
99 options.package_root) | 52 return RunPub(options.dart_executable, options.package_root, args) |
100 return RunPub(dart_executable, options.package_root, args) | |
101 | 53 |
102 | 54 |
103 if __name__ == '__main__': | 55 if __name__ == '__main__': |
104 sys.exit(main()) | 56 sys.exit(main()) |
OLD | NEW |