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

Side by Side Diff: roll.py

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 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
« no previous file with comments | « quiver/pubspec.yaml ('k') | smoke/lib/codegen/generator.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 """Helper for updating snapshot of Observatory dependencies"""
6
7 import argparse
8 import errno
9 import os
10 import platform
11 import shutil
12 import subprocess
13 import sys
14 import tempfile
15 import urllib
16 import urlparse
17
18 SELF_PACKAGE_NAME = 'observatory'
19 SCRIPT_DIR = os.path.dirname(sys.argv[0])
20
21 def check_for_pubspec_yaml(directory):
22 return os.path.exists(os.path.join(directory, 'pubspec.yaml'))
23
24 def run_pub_get(directory):
25 os.chdir(directory)
26 print('Running pub get in %s' % directory)
27 subprocess.check_output(['pub', 'get'])
28
29 def get_package_name(package_config):
30 return package_config.split(':', 1)[0]
31
32 def get_package_path(package_config):
33 return os.path.abspath(
34 os.path.join(
35 urlparse.urlparse(
36 urllib.unquote(
37 package_config.split(':', 1)[1])).path.strip(),
38 '..'))
39
40 def snapshot_package(src, dst):
41 shutil.copytree(src, dst)
42
43 def update_packages(src, dst):
44 print('Deleting %s' % dst)
45 try:
46 shutil.rmtree(dst)
47 except OSError as e:
48 if e.errno != errno.ENOENT:
49 raise e
50 pass
51 with open(src) as f:
52 packages = f.read().splitlines()
53 print('Snapshotting packages into %s' % dst)
54 for package_config in packages:
55 if package_config.startswith('#'):
56 # Skip comments.
57 continue
58 package_name = get_package_name(package_config)
59 if package_name == SELF_PACKAGE_NAME:
60 # Skip self.
61 continue
62 package_dir = get_package_path(package_config)
63 print('Snapshotting package %s' % package_name)
64 snapshot_package(package_dir, os.path.join(dst, package_name))
65
66
67 def rewrite_pubspec_yaml(packages_src, yaml_src, yaml_dst):
68 with open(yaml_src) as f:
69 yaml = f.read().splitlines()
70 yaml = [line for line in yaml if line.strip()]
71 yaml.insert(0, '# Generated file DO NOT EDIT')
72 yaml.append('dependency_overrides:')
73 with open(packages_src) as f:
74 packages = f.read().splitlines()
75 for package_config in packages:
76 if package_config.startswith('#'):
77 # Skip comments.
78 continue
79 package_name = get_package_name(package_config)
80 if package_name == SELF_PACKAGE_NAME:
81 # Skip self.
82 continue
83 yaml.append(' %s:' % package_name)
84 yaml.append(
85 ' path: ../../third_party/observatory_pub_packages/packages/%s'
86 % package_name)
87 yaml.append('')
88 print('!!! Update Observatory pubspec.yaml in sdk source tree')
89 with open(yaml_dst, 'w') as f:
90 f.write('\n'.join(yaml))
91
92 def main():
93 parser = argparse.ArgumentParser(
94 description='Updating snapshot of Observatory dependencies')
95 parser.add_argument(
96 '--dart-sdk-src',
97 action='store',
98 metavar='dart_sdk_src',
99 help='Path to dart/sdk',
100 default='~/workspace/dart/sdk')
101 args = parser.parse_args()
102 args.dart_sdk_src = os.path.abspath(os.path.expanduser(args.dart_sdk_src))
103 observatory_dir = os.path.join(args.dart_sdk_src, 'runtime', 'observatory')
104
105 if not check_for_pubspec_yaml(SCRIPT_DIR):
106 print('Error could not find pubspec.yaml next to roll.py')
107 return 1
108
109 if not check_for_pubspec_yaml(observatory_dir):
110 print('Error could not find Observatory source.')
111 return 1
112
113 yaml_src = os.path.abspath(os.path.join(SCRIPT_DIR, 'pubspec.yaml'))
114 yaml_dst = os.path.abspath(os.path.join(observatory_dir, 'pubspec.yaml'))
115
116 packages_dst = os.path.abspath(os.path.join(SCRIPT_DIR, 'packages'))
117
118 temp_dir = tempfile.mkdtemp();
119 try:
120 shutil.copyfile(os.path.join(SCRIPT_DIR, 'pubspec.yaml'),
121 os.path.join(temp_dir, 'pubspec.yaml'))
122 packages_src = os.path.join(temp_dir, '.packages')
123 run_pub_get(temp_dir)
124 update_packages(packages_src, packages_dst)
125 rewrite_pubspec_yaml(packages_src, yaml_src, yaml_dst)
126 finally:
127 shutil.rmtree(temp_dir)
128
129 if __name__ == '__main__':
130 sys.exit(main());
OLDNEW
« no previous file with comments | « quiver/pubspec.yaml ('k') | smoke/lib/codegen/generator.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698