OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # |
| 3 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. |
| 6 |
| 7 """Utility for updating third_party packages used in the Mojo Dart SDK""" |
| 8 |
| 9 import argparse |
| 10 import errno |
| 11 import json |
| 12 import os |
| 13 import shutil |
| 14 import subprocess |
| 15 import sys |
| 16 |
| 17 SCRIPT_DIR = os.path.dirname(sys.argv[0]) |
| 18 |
| 19 def check_for_pubspec_yaml(): |
| 20 return os.path.exists(os.path.join(SCRIPT_DIR, 'pubspec.yaml')) |
| 21 |
| 22 def change_directory(directory): |
| 23 return os.chdir(directory) |
| 24 |
| 25 def remove_existing_packages(base_path): |
| 26 print('Removing all package directories under %s' % base_path) |
| 27 for child in os.listdir(base_path): |
| 28 path = os.path.join(base_path, child) |
| 29 if os.path.isdir(path): |
| 30 print('Removing %s ' % path) |
| 31 shutil.rmtree(path) |
| 32 |
| 33 def pub_get(pub_exe): |
| 34 return subprocess.check_output([pub_exe, 'get']) |
| 35 |
| 36 def copy_packages(base_path): |
| 37 packages_path = os.path.join(base_path, 'packages') |
| 38 for package in os.listdir(packages_path): |
| 39 lib_path = os.path.realpath(os.path.join(packages_path, package)) |
| 40 package_path = os.path.normpath(os.path.join(lib_path, '..')) |
| 41 destinaton_path = os.path.join(base_path, package) |
| 42 print('Copying %s to %s' % (package_path, destinaton_path)) |
| 43 shutil.copytree(package_path, destinaton_path) |
| 44 |
| 45 def cleanup(base_path): |
| 46 shutil.rmtree(os.path.join(base_path, 'packages'), True) |
| 47 shutil.rmtree(os.path.join(base_path, '.pub'), True) |
| 48 os.remove(os.path.join(base_path, '.packages')) |
| 49 |
| 50 def main(): |
| 51 parser = argparse.ArgumentParser(description='Update third_party packages') |
| 52 parser.add_argument('--pub-exe', |
| 53 action='store', |
| 54 metavar='pub_exe', |
| 55 help='Path to the pub executable', |
| 56 default='../../../../third_party/dart-sdk/dart-sdk/bin/pub
') |
| 57 |
| 58 args = parser.parse_args() |
| 59 if not check_for_pubspec_yaml(): |
| 60 print('Error could not find pubspec.yaml') |
| 61 return 1 |
| 62 |
| 63 remove_existing_packages(SCRIPT_DIR) |
| 64 change_directory(SCRIPT_DIR) |
| 65 print('Running pub get') |
| 66 pub_get(args.pub_exe) |
| 67 copy_packages(SCRIPT_DIR) |
| 68 print('Cleaning up') |
| 69 cleanup(SCRIPT_DIR) |
| 70 |
| 71 if __name__ == '__main__': |
| 72 sys.exit(main()) |
OLD | NEW |