| 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 | |
| 12 from mopy.paths import Paths | |
| 13 | |
| 14 | |
| 15 def git_revision(): | |
| 16 return subprocess.check_output(['git', 'rev-parse', 'HEAD']).strip() | |
| 17 | |
| 18 | |
| 19 def mojo_filter(path): | |
| 20 if not os.path.isfile(path): | |
| 21 return False | |
| 22 _, ext = os.path.splitext(path) | |
| 23 if ext != '.mojo': | |
| 24 return False | |
| 25 return 'apptests' not in os.path.basename(path) | |
| 26 | |
| 27 | |
| 28 def gen_filter(path): | |
| 29 if os.path.isdir(path): | |
| 30 return True | |
| 31 _, ext = os.path.splitext(path) | |
| 32 # Don't include all .dart, just .mojom.dart. | |
| 33 return ext == '.sky' or path.endswith('.mojom.dart') | |
| 34 | |
| 35 | |
| 36 def sky_or_dart_filter(path): | |
| 37 if os.path.isdir(path): | |
| 38 return True | |
| 39 _, ext = os.path.splitext(path) | |
| 40 # .dart includes '.mojom.dart' | |
| 41 return ext == '.sky' or ext == '.dart' | |
| 42 | |
| 43 | |
| 44 def assets_filter(path): | |
| 45 if os.path.isdir(path): | |
| 46 return True | |
| 47 if os.path.basename(os.path.dirname(path)) != '2x_web': | |
| 48 return False | |
| 49 # We only use the 18 and 24s for now. | |
| 50 return '18dp' in path or '24dp' in path | |
| 51 | |
| 52 | |
| 53 def copy(from_root, to_root, filter_func=None): | |
| 54 if os.path.exists(to_root): | |
| 55 shutil.rmtree(to_root) | |
| 56 os.makedirs(to_root) | |
| 57 | |
| 58 for root, dirs, files in os.walk(from_root): | |
| 59 # filter_func expects paths not names, so wrap it to make them absolute. | |
| 60 wrapped_filter = None | |
| 61 if filter_func: | |
| 62 wrapped_filter = lambda name: filter_func(os.path.join(root, name)) | |
| 63 | |
| 64 for name in filter(wrapped_filter, files): | |
| 65 from_path = os.path.join(root, name) | |
| 66 root_rel_path = os.path.relpath(from_path, from_root) | |
| 67 to_path = os.path.join(to_root, root_rel_path) | |
| 68 to_dir = os.path.dirname(to_path) | |
| 69 if not os.path.exists(to_dir): | |
| 70 os.makedirs(to_dir) | |
| 71 shutil.copyfile(from_path, to_path) | |
| 72 | |
| 73 dirs[:] = filter(wrapped_filter, dirs) | |
| 74 | |
| 75 def main(): | |
| 76 logging.basicConfig(level=logging.WARN) | |
| 77 parser = argparse.ArgumentParser(description='Deploy a new build of mojo.') | |
| 78 parser.add_argument('deploy_root', type=str) | |
| 79 args = parser.parse_args() | |
| 80 | |
| 81 # Always use android release? | |
| 82 rel_build_dir = os.path.join('out', 'android_Release') | |
| 83 build_dir = os.path.join(Paths().src_root, rel_build_dir) | |
| 84 paths = Paths(build_dir=build_dir) | |
| 85 | |
| 86 def deploy_path(rel_path): | |
| 87 return os.path.join(args.deploy_root, rel_path) | |
| 88 | |
| 89 def src_path(rel_path): | |
| 90 return os.path.join(paths.src_root, rel_path) | |
| 91 | |
| 92 copy(paths.build_dir, deploy_path('mojo'), mojo_filter) | |
| 93 copy(src_path('mojo/public'), deploy_path('mojo/public'), | |
| 94 sky_or_dart_filter) | |
| 95 | |
| 96 # TODO(eseidel): All of these should be removed and package: sky includes | |
| 97 # used instead. | |
| 98 copy(src_path('sky/examples'), deploy_path('sky/examples'), | |
| 99 sky_or_dart_filter) | |
| 100 copy(src_path('sky/framework'), deploy_path('sky/framework'), | |
| 101 sky_or_dart_filter) | |
| 102 copy(os.path.join(paths.build_dir, 'gen'), deploy_path('gen'), gen_filter) | |
| 103 copy(src_path('sky/assets'), deploy_path('sky/assets'), assets_filter) | |
| 104 | |
| 105 shutil.copy(os.path.join(paths.build_dir, 'apks', 'MojoShell.apk'), | |
| 106 args.deploy_root) | |
| 107 shutil.copy(os.path.join(paths.build_dir, 'apks', 'MojoShortcuts.apk'), | |
| 108 args.deploy_root) | |
| 109 | |
| 110 packages_root = deploy_path('packages') | |
| 111 if os.path.exists(packages_root): | |
| 112 shutil.rmtree(packages_root) | |
| 113 subprocess.check_call([ | |
| 114 src_path('sky/tools/deploy_sdk.py'), | |
| 115 '--non-interactive', | |
| 116 deploy_path('sky_sdk'), | |
| 117 '--fake-pub-get-into', | |
| 118 packages_root | |
| 119 ]) | |
| 120 | |
| 121 with open(deploy_path('LICENSES.sky'), 'w') as license_file: | |
| 122 subprocess.check_call([src_path('tools/licenses.py'), 'credits'], | |
| 123 stdout=license_file) | |
| 124 | |
| 125 | |
| 126 subprocess.check_call(['git', 'add', '.'], cwd=args.deploy_root) | |
| 127 subprocess.check_call([ | |
| 128 'git', 'commit', | |
| 129 '-m', '%s from %s' % (rel_build_dir, git_revision()) | |
| 130 ], cwd=args.deploy_root) | |
| 131 | |
| 132 | |
| 133 if __name__ == '__main__': | |
| 134 main() | |
| OLD | NEW |