Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(187)

Side by Side Diff: tools/run_pub.py

Issue 856133002: Observatory build fixes to dart executable finding code (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 10 matching lines...) Expand all
21 def BuildArguments(): 21 def BuildArguments():
22 result = argparse.ArgumentParser(usage=usage) 22 result = argparse.ArgumentParser(usage=usage)
23 result.add_argument("--package-root", help="package root", default=None) 23 result.add_argument("--package-root", help="package root", default=None)
24 result.add_argument("--dart-executable", help="dart binary", default=None) 24 result.add_argument("--dart-executable", help="dart binary", default=None)
25 return result 25 return result
26 26
27 def ProcessOptions(options, args): 27 def ProcessOptions(options, args):
28 return ((options.package_root != None) and 28 return ((options.package_root != None) and
29 (options.dart_executable != None)) 29 (options.dart_executable != None))
30 30
31 def GetPrebuiltDartExecutablePath(): 31 def GetPrebuiltDartExecutablePath(suffix):
32 osdict = {'Darwin':'macos', 'Linux':'linux', 'Windows':'windows'} 32 osdict = {'Darwin':'macos', 'Linux':'linux', 'Windows':'windows'}
33 system = platform.system() 33 system = platform.system()
34 executable_name = 'dart' 34 executable_name = 'dart'
35 if system == 'Windows': 35 if system == 'Windows':
36 executable_name = 'dart.exe' 36 executable_name = 'dart.exe'
37 try: 37 try:
38 osname = osdict[system] 38 osname = osdict[system]
39 except KeyError: 39 except KeyError:
40 print >>sys.stderr, ('WARNING: platform "%s" not supported') % (system) 40 print >>sys.stderr, ('WARNING: platform "%s" not supported') % (system)
41 return None; 41 return None;
42 return os.path.join(DART_ROOT, 42 return os.path.join(DART_ROOT,
43 'tools', 43 'tools',
44 'testing', 44 'testing',
45 'bin', 45 'bin',
46 osname, 46 osname,
47 executable_name) 47 executable_name + suffix)
48 48
49 def RunPub(dart, pkg_root, args): 49 def RunPub(dart, pkg_root, args):
50 return subprocess.call([dart, '--package-root=' + pkg_root, PUB_PATH] + args) 50 return subprocess.call([dart, '--package-root=' + pkg_root, PUB_PATH] + args)
51 51
52 def TryRunningExecutable(dart_executable, pkg_root): 52 def TryRunningExecutable(dart_executable, pkg_root):
53 return subprocess.call([dart_executable, 53 try:
54 '--package-root=' + pkg_root, 54 return subprocess.call([dart_executable,
55 CANARY_PATH]) == 42 55 '--package-root=' + pkg_root,
56 CANARY_PATH]) == 42
57 except:
58 return False;
56 59
57 def DisplayBootstrapWarning(): 60 def DisplayBootstrapWarning():
58 print """\ 61 print """\
59 62
60 63
61 WARNING: Your system cannot run the prebuilt Dart executable. Using the 64 WARNING: Your system cannot run the prebuilt Dart executable. Using the
62 bootstrap Dart executable will make Debug builds long. 65 bootstrap Dart executable will make Debug builds long.
63 Please see Wiki for instructions on replacing prebuilt Dart executable. 66 Please see Wiki for instructions on replacing prebuilt Dart executable.
64 67
65 https://code.google.com/p/dart/wiki/ReplacingPrebuiltDartExecutable 68 https://code.google.com/p/dart/wiki/ReplacingPrebuiltDartExecutable
66 69
67 """ 70 """
68 71
72 def FindDartExecutable(fallback_executable, package_root):
73 # If requested, use the bootstrap binary instead of the prebuilt
74 # executable.
75 if os.getenv('DART_USE_BOOTSTRAP_BIN') != None:
76 return fallback_executable
77 # Try to find a working prebuilt dart executable.
78 dart_executable = GetPrebuiltDartExecutablePath('')
79 if TryRunningExecutable(dart_executable, package_root):
80 return dart_executable
81 dart_executable = GetPrebuiltDartExecutablePath('-arm')
82 if TryRunningExecutable(dart_executable, package_root):
83 return dart_executable
84 dart_executable = GetPrebuiltDartExecutablePath('-mips')
85 if TryRunningExecutable(dart_executable, package_root):
86 return dart_executable
87 # If the system cannot execute a prebuilt dart executable, use the bootstrap
88 # executable instead.
89 DisplayBootstrapWarning()
90 return fallback_executable
91
69 def main(): 92 def main():
70 # Parse the options. 93 # Parse the options.
71 parser = BuildArguments() 94 parser = BuildArguments()
72 (options, args) = parser.parse_known_args() 95 (options, args) = parser.parse_known_args()
73 if not ProcessOptions(options, args): 96 if not ProcessOptions(options, args):
74 parser.print_help() 97 parser.print_help()
75 return 1 98 return 1
76 dart_executable = GetPrebuiltDartExecutablePath() 99 dart_executable = FindDartExecutable(options.dart_executable,
77 # If the system cannot execute the prebuilt dart executable, use the bootstrap 100 options.package_root)
78 # executable instead.
79 if not TryRunningExecutable(dart_executable, options.package_root):
80 DisplayBootstrapWarning()
81 dart_executable = options.dart_executable
82 # If requested, use the bootstrap binary instead of the prebuilt
83 # executable.
84 if os.getenv('DART_USE_BOOTSTRAP_BIN') != None:
85 dart_executable = options.dart_executable
86 return RunPub(dart_executable, options.package_root, args) 101 return RunPub(dart_executable, options.package_root, args)
87 102
88 103
89 if __name__ == '__main__': 104 if __name__ == '__main__':
90 sys.exit(main()); 105 sys.exit(main());
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698