| 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 """Helper for building and deploying Observatory""" | 5 """Helper for building and deploying Observatory""" |
| 6 | 6 |
| 7 import argparse | 7 import argparse |
| 8 import os | 8 import os |
| 9 import platform | 9 import platform |
| 10 import shutil | 10 import shutil |
| 11 import subprocess | 11 import subprocess |
| 12 import sys | 12 import sys |
| 13 import utils |
| 13 | 14 |
| 14 SCRIPT_DIR = os.path.dirname(sys.argv[0]) | 15 SCRIPT_DIR = os.path.dirname(sys.argv[0]) |
| 15 DART_ROOT = os.path.realpath(os.path.join(SCRIPT_DIR, '..')) | 16 DART_ROOT = os.path.realpath(os.path.join(SCRIPT_DIR, '..')) |
| 16 RUN_PUB = os.path.join(DART_ROOT, 'tools/run_pub.py') | 17 RUN_PUB = os.path.join(DART_ROOT, 'tools/run_pub.py') |
| 17 IGNORE_PATTERNS = shutil.ignore_patterns( | 18 IGNORE_PATTERNS = shutil.ignore_patterns( |
| 18 '*.map', | 19 '*.map', |
| 19 '*.concat.js', | 20 '*.concat.js', |
| 20 '*.scriptUrls', | 21 '*.scriptUrls', |
| 21 '*.precompiled.js', | 22 '*.precompiled.js', |
| 22 'main.*', | 23 'main.*', |
| 23 'unittest*', | 24 'unittest*', |
| 24 '*_buildLogs*', | 25 '*_buildLogs*', |
| 25 '*.log', | 26 '*.log', |
| 26 '*~') | 27 '*~') |
| 27 | 28 |
| 28 usage = """obs_tool.py [options]""" | 29 usage = """obs_tool.py [options]""" |
| 29 | 30 |
| 30 def GetDartSdkPubExecutablePath(): | |
| 31 osdict = {'Darwin':'mac', 'Linux':'linux', 'Windows':'win'} | |
| 32 system = platform.system() | |
| 33 executable_name = 'pub' | |
| 34 if system == 'Windows': | |
| 35 executable_name = 'pub.bat' | |
| 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 'sdks', | |
| 44 osname, | |
| 45 'dart-sdk', | |
| 46 'bin', | |
| 47 executable_name) | |
| 48 | |
| 49 def BuildArguments(): | 31 def BuildArguments(): |
| 50 result = argparse.ArgumentParser(usage=usage) | 32 result = argparse.ArgumentParser(usage=usage) |
| 51 result.add_argument("--package-root", help="package root", default=None) | 33 result.add_argument("--package-root", help="package root", default=None) |
| 52 result.add_argument("--dart-executable", help="dart executable", default=None) | 34 result.add_argument("--dart-executable", help="dart executable", default=None) |
| 53 result.add_argument("--pub-executable", help="pub executable", default=None) | 35 result.add_argument("--pub-executable", help="pub executable", default=None) |
| 54 result.add_argument("--directory", help="observatory root", default=None) | 36 result.add_argument("--directory", help="observatory root", default=None) |
| 55 result.add_argument("--command", help="[get, build, deploy]", default=None) | 37 result.add_argument("--command", help="[get, build, deploy]", default=None) |
| 56 result.add_argument("--silent", help="silence all output", default=False) | 38 result.add_argument("--silent", help="silence all output", default=False) |
| 57 result.add_argument("--sdk", help="Use prebuilt sdk", default=False) | 39 result.add_argument("--sdk", help="Use prebuilt sdk", default=False) |
| 58 return result | 40 return result |
| 59 | 41 |
| 60 def ProcessOptions(options, args): | 42 def ProcessOptions(options, args): |
| 61 # Required options. | 43 # Required options. |
| 62 if (options.command == None) or (options.directory == None): | 44 if (options.command == None) or (options.directory == None): |
| 63 return False | 45 return False |
| 64 # If we have a pub executable, we are running from the dart-sdk. | 46 # If we have a pub executable, we are running from the dart-sdk. |
| 65 if (options.pub_executable != None): | 47 if (options.pub_executable != None): |
| 66 return True | 48 return True |
| 67 if (options.sdk != None): | 49 if (options.sdk != None): |
| 68 # Use the checked in pub executable by default. | 50 # Use the checked in pub executable by default. |
| 69 options.pub_executable = GetDartSdkPubExecutablePath() | 51 options.pub_executable = utils.CheckedInPubPath() |
| 70 return True | 52 return True |
| 71 # Otherwise, we need a dart executable and a package root. | 53 # Otherwise, we need a dart executable and a package root. |
| 72 return ((options.package_root != None) and | 54 return ((options.package_root != None) and |
| 73 (options.dart_executable != None)) | 55 (options.dart_executable != None)) |
| 74 | 56 |
| 75 def ChangeDirectory(directory): | 57 def ChangeDirectory(directory): |
| 76 os.chdir(directory); | 58 os.chdir(directory); |
| 77 | 59 |
| 78 def PubGet(dart_executable, pub_executable, pkg_root, silent): | 60 def PubGet(dart_executable, pub_executable, pkg_root, silent): |
| 79 # Always remove pubspec.lock before running 'pub get'. | 61 # Always remove pubspec.lock before running 'pub get'. |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 if (options.pub_executable != None): | 152 if (options.pub_executable != None): |
| 171 options.pub_executable = os.path.abspath(options.pub_executable) | 153 options.pub_executable = os.path.abspath(options.pub_executable) |
| 172 if len(args) == 1: | 154 if len(args) == 1: |
| 173 args[0] = os.path.abspath(args[0]) | 155 args[0] = os.path.abspath(args[0]) |
| 174 # Pub must be run from the project's root directory. | 156 # Pub must be run from the project's root directory. |
| 175 ChangeDirectory(options.directory) | 157 ChangeDirectory(options.directory) |
| 176 return ExecuteCommand(options, args) | 158 return ExecuteCommand(options, args) |
| 177 | 159 |
| 178 if __name__ == '__main__': | 160 if __name__ == '__main__': |
| 179 sys.exit(main()); | 161 sys.exit(main()); |
| OLD | NEW |