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

Unified Diff: sky/tools/deploy_sdk.py

Issue 990493002: Make package: work like Dart expects in preparation for a Sky SDK (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Works Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: sky/tools/deploy_sdk.py
diff --git a/sky/tools/deploy_sdk.py b/sky/tools/deploy_sdk.py
new file mode 100755
index 0000000000000000000000000000000000000000..110451e984f335dbaa3283b3cc175bed7028cd51
--- /dev/null
+++ b/sky/tools/deploy_sdk.py
@@ -0,0 +1,175 @@
+#!/usr/bin/env python
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import argparse
+import logging
+import os
+import shutil
+import subprocess
+import sys
+
+SKY_TOOLS_DIR = os.path.dirname(os.path.abspath(__file__))
+SKY_DIR = os.path.dirname(SKY_TOOLS_DIR)
+SRC_ROOT = os.path.dirname(SKY_DIR)
+
+
+def git_revision():
+ return subprocess.check_output(['git', 'rev-parse', 'HEAD']).strip()
+
+
+def mojo_filter(path):
+ if not os.path.isfile(path):
+ return False
+ _, ext = os.path.splitext(path)
+ if ext != '.mojo':
+ return False
+ return 'apptests' not in os.path.basename(path)
abarth-chromium 2015/03/13 20:38:02 Delete?
+
+
+def gen_filter(path):
+ if os.path.isdir(path):
+ return True
+ _, ext = os.path.splitext(path)
+ # Don't include all .dart, just .mojom.dart.
+ return path.endswith('.mojom.dart')
+
+def dart_filter(path):
+ if os.path.isdir(path):
+ return True
+ _, ext = os.path.splitext(path)
+ # .dart includes '.mojom.dart'
+ return ext == '.dart'
+
+
+def sky_or_dart_filter(path):
+ if os.path.isdir(path):
+ return True
+ _, ext = os.path.splitext(path)
+ # .dart includes '.mojom.dart'
+ return ext == '.sky' or ext == '.dart'
+
+
+def ensure_dir_exists(path):
+ if not os.path.exists(path):
+ os.makedirs(path)
+
+
+def copy(from_root, to_root, filter_func=None):
+ ensure_dir_exists(to_root)
+
+ for root, dirs, files in os.walk(from_root):
+ # filter_func expects paths not names, so wrap it to make them absolute.
+ wrapped_filter = None
+ if filter_func:
+ wrapped_filter = lambda name: filter_func(os.path.join(root, name))
+
+ for name in filter(wrapped_filter, files):
+ from_path = os.path.join(root, name)
+ root_rel_path = os.path.relpath(from_path, from_root)
+ to_path = os.path.join(to_root, root_rel_path)
+ to_dir = os.path.dirname(to_path)
+ if not os.path.exists(to_dir):
+ os.makedirs(to_dir)
+ shutil.copy(from_path, to_path)
+
+ dirs[:] = filter(wrapped_filter, dirs)
+
+
+def confirm(prompt):
+ response = raw_input('%s [N]|y: ' % prompt)
+ return response and response.lower() == 'y'
+
+
+def delete_all_non_hidden_files_in_directory(root, force=False):
+ to_delete = [os.path.join(root, p)
+ for p in os.listdir(root) if not p.startswith('.')]
+ if not to_delete:
+ return
+ if not force:
+ prompt = 'This will delete everything in %s:\n%s\nAre you sure?' % (
+ root, '\n'.join(to_delete))
+ if not confirm(prompt):
+ print 'User aborted.'
+ sys.exit(2)
+
+ for path in to_delete:
+ if os.path.isdir(path):
+ shutil.rmtree(path)
+ else:
+ os.remove(path)
+
+
+def main():
+ logging.basicConfig(level=logging.WARN)
+ parser = argparse.ArgumentParser(description='Deploy a new sky_sdk.')
+ parser.add_argument('sdk_root', type=str)
+ parser.add_argument('-f', '--force', action='store_true')
+ parser.add_argument('--commit', action='store_true')
+ parser.add_argument('--skip-apks', action='store_true')
+ parser.add_argument('--fake-pub-get-into', action='store', type=str)
+ args = parser.parse_args()
+
+ # Always use android release?
+ rel_build_dir = os.path.join('out', 'android_Release')
+ build_dir = os.path.join(SRC_ROOT, rel_build_dir)
+ sdk_root = os.path.abspath(args.sdk_root)
+
+ def sdk_path(rel_path):
+ return os.path.join(sdk_root, rel_path)
+
+ def src_path(rel_path):
+ return os.path.join(SRC_ROOT, rel_path)
+
+ ensure_dir_exists(sdk_root)
+ delete_all_non_hidden_files_in_directory(sdk_root, args.force)
+
+ # Manually clear sdk_root above to avoid deleting dot-files.
+ copy(src_path('sky/sdk'), sdk_root)
+
+ copy(src_path('sky/examples'), sdk_path('examples'),
+ sky_or_dart_filter)
+
+ # Sky package
+ copy(src_path('sky/framework'), sdk_path('packages/sky/lib/framework'),
+ sky_or_dart_filter)
+ copy(src_path('sky/assets'), sdk_path('packages/sky/lib/assets'))
+ copy(src_path('sky/sdk/tools/sky'), sdk_path('packages/sky/bin/sky'))
+ copy(os.path.join(build_dir, 'gen/sky'), sdk_path('packages/sky/lib'),
+ gen_filter)
+
+ # Mojo package
+ copy(src_path('mojo/public'), sdk_path('packages/mojo/lib/public'), dart_filter)
+ copy(os.path.join(build_dir, 'gen/mojo'), sdk_path('packages/mojo/lib'),
+ gen_filter)
+
+
+ if not args.skip_apks:
+ ensure_dir_exists(sdk_path('apks'))
+ shutil.copy(os.path.join(build_dir, 'apks', 'SkyShell.apk'),
+ sdk_path('apks'))
+
+
+ with open(sdk_path('LICENSES.sky'), 'w') as license_file:
+ subprocess.check_call([src_path('tools/licenses.py'), 'credits'],
+ stdout=license_file)
+
+ if args.fake_pub_get_into:
+ packages_dir = os.path.abspath(args.fake_pub_get_into)
+ ensure_dir_exists(packages_dir)
+ os.symlink(sdk_path('packages/mojo/lib'),
+ os.path.join(packages_dir, 'mojo'))
+ os.symlink(sdk_path('packages/sky/lib'),
+ os.path.join(packages_dir, 'sky'))
+
+ if args.commit:
+ subprocess.check_call(['git', 'add', '.'], cwd=sdk_root)
+ subprocess.check_call([
+ 'git', 'commit',
+ '-m', '%s from %s' % (rel_build_dir, git_revision())
+ ], cwd=sdk_root)
+
+
+if __name__ == '__main__':
+ main()

Powered by Google App Engine
This is Rietveld 408576698