OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright 2015 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 import argparse | |
7 import logging | |
8 import os | |
9 import shutil | |
10 import subprocess | |
11 import sys | |
12 | |
13 SKY_TOOLS_DIR = os.path.dirname(os.path.abspath(__file__)) | |
14 SKY_DIR = os.path.dirname(SKY_TOOLS_DIR) | |
15 SRC_ROOT = os.path.dirname(SKY_DIR) | |
16 | |
17 | |
18 def git_revision(): | |
19 return subprocess.check_output(['git', 'rev-parse', 'HEAD']).strip() | |
20 | |
21 | |
22 def mojo_filter(path): | |
23 if not os.path.isfile(path): | |
24 return False | |
25 _, ext = os.path.splitext(path) | |
26 if ext != '.mojo': | |
27 return False | |
28 return 'apptests' not in os.path.basename(path) | |
abarth-chromium
2015/03/13 20:38:02
Delete?
| |
29 | |
30 | |
31 def gen_filter(path): | |
32 if os.path.isdir(path): | |
33 return True | |
34 _, ext = os.path.splitext(path) | |
35 # Don't include all .dart, just .mojom.dart. | |
36 return path.endswith('.mojom.dart') | |
37 | |
38 def dart_filter(path): | |
39 if os.path.isdir(path): | |
40 return True | |
41 _, ext = os.path.splitext(path) | |
42 # .dart includes '.mojom.dart' | |
43 return ext == '.dart' | |
44 | |
45 | |
46 def sky_or_dart_filter(path): | |
47 if os.path.isdir(path): | |
48 return True | |
49 _, ext = os.path.splitext(path) | |
50 # .dart includes '.mojom.dart' | |
51 return ext == '.sky' or ext == '.dart' | |
52 | |
53 | |
54 def ensure_dir_exists(path): | |
55 if not os.path.exists(path): | |
56 os.makedirs(path) | |
57 | |
58 | |
59 def copy(from_root, to_root, filter_func=None): | |
60 ensure_dir_exists(to_root) | |
61 | |
62 for root, dirs, files in os.walk(from_root): | |
63 # filter_func expects paths not names, so wrap it to make them absolute. | |
64 wrapped_filter = None | |
65 if filter_func: | |
66 wrapped_filter = lambda name: filter_func(os.path.join(root, name)) | |
67 | |
68 for name in filter(wrapped_filter, files): | |
69 from_path = os.path.join(root, name) | |
70 root_rel_path = os.path.relpath(from_path, from_root) | |
71 to_path = os.path.join(to_root, root_rel_path) | |
72 to_dir = os.path.dirname(to_path) | |
73 if not os.path.exists(to_dir): | |
74 os.makedirs(to_dir) | |
75 shutil.copy(from_path, to_path) | |
76 | |
77 dirs[:] = filter(wrapped_filter, dirs) | |
78 | |
79 | |
80 def confirm(prompt): | |
81 response = raw_input('%s [N]|y: ' % prompt) | |
82 return response and response.lower() == 'y' | |
83 | |
84 | |
85 def delete_all_non_hidden_files_in_directory(root, force=False): | |
86 to_delete = [os.path.join(root, p) | |
87 for p in os.listdir(root) if not p.startswith('.')] | |
88 if not to_delete: | |
89 return | |
90 if not force: | |
91 prompt = 'This will delete everything in %s:\n%s\nAre you sure?' % ( | |
92 root, '\n'.join(to_delete)) | |
93 if not confirm(prompt): | |
94 print 'User aborted.' | |
95 sys.exit(2) | |
96 | |
97 for path in to_delete: | |
98 if os.path.isdir(path): | |
99 shutil.rmtree(path) | |
100 else: | |
101 os.remove(path) | |
102 | |
103 | |
104 def main(): | |
105 logging.basicConfig(level=logging.WARN) | |
106 parser = argparse.ArgumentParser(description='Deploy a new sky_sdk.') | |
107 parser.add_argument('sdk_root', type=str) | |
108 parser.add_argument('-f', '--force', action='store_true') | |
109 parser.add_argument('--commit', action='store_true') | |
110 parser.add_argument('--skip-apks', action='store_true') | |
111 parser.add_argument('--fake-pub-get-into', action='store', type=str) | |
112 args = parser.parse_args() | |
113 | |
114 # Always use android release? | |
115 rel_build_dir = os.path.join('out', 'android_Release') | |
116 build_dir = os.path.join(SRC_ROOT, rel_build_dir) | |
117 sdk_root = os.path.abspath(args.sdk_root) | |
118 | |
119 def sdk_path(rel_path): | |
120 return os.path.join(sdk_root, rel_path) | |
121 | |
122 def src_path(rel_path): | |
123 return os.path.join(SRC_ROOT, rel_path) | |
124 | |
125 ensure_dir_exists(sdk_root) | |
126 delete_all_non_hidden_files_in_directory(sdk_root, args.force) | |
127 | |
128 # Manually clear sdk_root above to avoid deleting dot-files. | |
129 copy(src_path('sky/sdk'), sdk_root) | |
130 | |
131 copy(src_path('sky/examples'), sdk_path('examples'), | |
132 sky_or_dart_filter) | |
133 | |
134 # Sky package | |
135 copy(src_path('sky/framework'), sdk_path('packages/sky/lib/framework'), | |
136 sky_or_dart_filter) | |
137 copy(src_path('sky/assets'), sdk_path('packages/sky/lib/assets')) | |
138 copy(src_path('sky/sdk/tools/sky'), sdk_path('packages/sky/bin/sky')) | |
139 copy(os.path.join(build_dir, 'gen/sky'), sdk_path('packages/sky/lib'), | |
140 gen_filter) | |
141 | |
142 # Mojo package | |
143 copy(src_path('mojo/public'), sdk_path('packages/mojo/lib/public'), dart_fil ter) | |
144 copy(os.path.join(build_dir, 'gen/mojo'), sdk_path('packages/mojo/lib'), | |
145 gen_filter) | |
146 | |
147 | |
148 if not args.skip_apks: | |
149 ensure_dir_exists(sdk_path('apks')) | |
150 shutil.copy(os.path.join(build_dir, 'apks', 'SkyShell.apk'), | |
151 sdk_path('apks')) | |
152 | |
153 | |
154 with open(sdk_path('LICENSES.sky'), 'w') as license_file: | |
155 subprocess.check_call([src_path('tools/licenses.py'), 'credits'], | |
156 stdout=license_file) | |
157 | |
158 if args.fake_pub_get_into: | |
159 packages_dir = os.path.abspath(args.fake_pub_get_into) | |
160 ensure_dir_exists(packages_dir) | |
161 os.symlink(sdk_path('packages/mojo/lib'), | |
162 os.path.join(packages_dir, 'mojo')) | |
163 os.symlink(sdk_path('packages/sky/lib'), | |
164 os.path.join(packages_dir, 'sky')) | |
165 | |
166 if args.commit: | |
167 subprocess.check_call(['git', 'add', '.'], cwd=sdk_root) | |
168 subprocess.check_call([ | |
169 'git', 'commit', | |
170 '-m', '%s from %s' % (rel_build_dir, git_revision()) | |
171 ], cwd=sdk_root) | |
172 | |
173 | |
174 if __name__ == '__main__': | |
175 main() | |
OLD | NEW |