OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import argparse | 6 import argparse |
7 from datetime import datetime | 7 from datetime import datetime |
8 import logging | 8 import logging |
9 import os | 9 import os |
10 import shutil | 10 import shutil |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 shutil.copy(from_path, to_path) | 78 shutil.copy(from_path, to_path) |
79 | 79 |
80 dirs[:] = filter(wrapped_filter, dirs) | 80 dirs[:] = filter(wrapped_filter, dirs) |
81 | 81 |
82 | 82 |
83 def link(from_root, to_root, filter_func=None): | 83 def link(from_root, to_root, filter_func=None): |
84 ensure_dir_exists(os.path.dirname(to_root)) | 84 ensure_dir_exists(os.path.dirname(to_root)) |
85 os.symlink(from_root, to_root) | 85 os.symlink(from_root, to_root) |
86 | 86 |
87 | 87 |
| 88 def make_relative_symlink(source, link_name): |
| 89 rel_source = os.path.relpath(source, os.path.dirname(link_name)) |
| 90 os.symlink(rel_source, link_name) |
| 91 |
| 92 |
88 def confirm(prompt): | 93 def confirm(prompt): |
89 response = raw_input('%s [N]|y: ' % prompt) | 94 response = raw_input('%s [N]|y: ' % prompt) |
90 return response and response.lower() == 'y' | 95 return response and response.lower() == 'y' |
91 | 96 |
92 | 97 |
93 def delete_all_non_hidden_files_in_directory(root, non_interactive=False): | 98 def delete_all_non_hidden_files_in_directory(root, non_interactive=False): |
94 to_delete = [os.path.join(root, p) | 99 to_delete = [os.path.join(root, p) |
95 for p in os.listdir(root) if not p.startswith('.')] | 100 for p in os.listdir(root) if not p.startswith('.')] |
96 if not to_delete: | 101 if not to_delete: |
97 return | 102 return |
(...skipping 12 matching lines...) Expand all Loading... |
110 | 115 |
111 | 116 |
112 def main(): | 117 def main(): |
113 logging.basicConfig(level=logging.WARN) | 118 logging.basicConfig(level=logging.WARN) |
114 parser = argparse.ArgumentParser(description='Deploy a new sky_sdk.') | 119 parser = argparse.ArgumentParser(description='Deploy a new sky_sdk.') |
115 parser.add_argument('sdk_root', type=str) | 120 parser.add_argument('sdk_root', type=str) |
116 parser.add_argument('--build-dir', action='store', type=str, | 121 parser.add_argument('--build-dir', action='store', type=str, |
117 default=os.path.join(SRC_ROOT, DEFAULT_REL_BUILD_DIR)) | 122 default=os.path.join(SRC_ROOT, DEFAULT_REL_BUILD_DIR)) |
118 parser.add_argument('--non-interactive', action='store_true') | 123 parser.add_argument('--non-interactive', action='store_true') |
119 parser.add_argument('--dev-environment', action='store_true') | 124 parser.add_argument('--dev-environment', action='store_true') |
| 125 parser.add_argument('--commit', action='store_true') |
120 parser.add_argument('--fake-pub-get-into', action='store', type=str) | 126 parser.add_argument('--fake-pub-get-into', action='store', type=str) |
121 args = parser.parse_args() | 127 args = parser.parse_args() |
122 | 128 |
123 build_dir = os.path.abspath(args.build_dir) | 129 build_dir = os.path.abspath(args.build_dir) |
124 sdk_root = os.path.abspath(args.sdk_root) | 130 sdk_root = os.path.abspath(args.sdk_root) |
125 | 131 |
126 print 'Building SDK from %s into %s' % (build_dir, sdk_root) | 132 print 'Building SDK from %s into %s' % (build_dir, sdk_root) |
127 start_time = datetime.now() | 133 start_time = datetime.now() |
128 | 134 |
129 # These are separate ideas but don't need a separate flag yet. | 135 # These are separate ideas but don't need a separate flag yet. |
130 use_links = args.dev_environment | 136 use_links = args.dev_environment |
131 skip_apks = args.dev_environment | 137 skip_apks = args.dev_environment |
132 should_commit = not args.dev_environment | 138 should_commit = args.commit |
133 generate_licenses = not args.dev_environment | 139 generate_licenses = not args.dev_environment |
134 | 140 |
135 # We save a bunch of time in --dev-environment mode by symlinking whole | 141 # We save a bunch of time in --dev-environment mode by symlinking whole |
136 # directories when possible. Any names which conflict with generated | 142 # directories when possible. Any names which conflict with generated |
137 # directories can't be symlinked and must be copied. | 143 # directories can't be symlinked and must be copied. |
138 copy_or_link = link if use_links else copy | 144 copy_or_link = link if use_links else copy |
139 | 145 |
140 def sdk_path(rel_path): | 146 def sdk_path(rel_path): |
141 return os.path.join(sdk_root, rel_path) | 147 return os.path.join(sdk_root, rel_path) |
142 | 148 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 stdout=license_file) | 200 stdout=license_file) |
195 | 201 |
196 copy_or_link(src_path('AUTHORS'), sdk_path('packages/mojo/AUTHORS')) | 202 copy_or_link(src_path('AUTHORS'), sdk_path('packages/mojo/AUTHORS')) |
197 copy_or_link(src_path('LICENSE'), sdk_path('packages/mojo/LICENSE')) | 203 copy_or_link(src_path('LICENSE'), sdk_path('packages/mojo/LICENSE')) |
198 copy_or_link(src_path('AUTHORS'), sdk_path('packages/sky/AUTHORS')) | 204 copy_or_link(src_path('AUTHORS'), sdk_path('packages/sky/AUTHORS')) |
199 copy_or_link(src_path('LICENSE'), sdk_path('packages/sky/LICENSE')) | 205 copy_or_link(src_path('LICENSE'), sdk_path('packages/sky/LICENSE')) |
200 | 206 |
201 if args.fake_pub_get_into: | 207 if args.fake_pub_get_into: |
202 packages_dir = os.path.abspath(args.fake_pub_get_into) | 208 packages_dir = os.path.abspath(args.fake_pub_get_into) |
203 ensure_dir_exists(packages_dir) | 209 ensure_dir_exists(packages_dir) |
204 os.symlink(sdk_path('packages/mojo/lib'), | 210 make_relative_symlink(sdk_path('packages/mojo/lib'), |
205 os.path.join(packages_dir, 'mojo')) | 211 os.path.join(packages_dir, 'mojo')) |
206 os.symlink(sdk_path('packages/sky/lib'), | 212 make_relative_symlink(sdk_path('packages/sky/lib'), |
207 os.path.join(packages_dir, 'sky')) | 213 os.path.join(packages_dir, 'sky')) |
208 | 214 |
209 if should_commit: | 215 if should_commit: |
210 # Kinda a hack to make a prettier build dir for the commit: | 216 # Kinda a hack to make a prettier build dir for the commit: |
211 rel_build_dir = os.path.join(os.path.split(build_dir)[-2:]) | 217 rel_build_dir = os.path.join(os.path.split(build_dir)[-2:]) |
212 subprocess.check_call(['git', 'add', '.'], cwd=sdk_root) | 218 subprocess.check_call(['git', 'add', '.'], cwd=sdk_root) |
213 subprocess.check_call([ | 219 subprocess.check_call([ |
214 'git', 'commit', | 220 'git', 'commit', |
215 '-m', '%s from %s' % (rel_build_dir, git_revision()) | 221 '-m', '%s from %s' % (rel_build_dir, git_revision()) |
216 ], cwd=sdk_root) | 222 ], cwd=sdk_root) |
217 | 223 |
218 time_delta = datetime.now() - start_time | 224 time_delta = datetime.now() - start_time |
219 print 'SDK built at %s in %ss' % (sdk_root, time_delta.total_seconds()) | 225 print 'SDK built at %s in %ss' % (sdk_root, time_delta.total_seconds()) |
220 | 226 |
221 | 227 |
222 if __name__ == '__main__': | 228 if __name__ == '__main__': |
223 main() | 229 main() |
OLD | NEW |