Chromium Code Reviews| 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 """Deploy domokit.github.io""" | |
| 7 | |
| 8 # NOTE: Requires that download_material_design_icons to have been run from | |
| 9 # $build_dir/gen/dart-dpkg/sky. | |
| 10 | |
| 6 import argparse | 11 import argparse |
| 7 import logging | 12 import logging |
| 8 import os | 13 import os |
| 9 import shutil | 14 import shutil |
| 10 import subprocess | 15 import subprocess |
| 16 import urllib2; | |
| 11 | 17 |
| 12 from mopy.paths import Paths | 18 from mopy.paths import Paths |
| 13 | 19 |
| 14 | 20 |
| 15 def git_revision(): | 21 def git_revision(): |
| 16 return subprocess.check_output(['git', 'rev-parse', 'HEAD']).strip() | 22 return subprocess.check_output(['git', 'rev-parse', 'HEAD']).strip() |
| 17 | 23 |
| 18 | 24 |
| 19 def mojo_filter(path): | 25 def mojo_filter(path): |
| 20 if not os.path.isfile(path): | 26 if not os.path.isfile(path): |
| 21 return False | 27 return False |
| 22 _, ext = os.path.splitext(path) | 28 _, ext = os.path.splitext(path) |
| 23 if ext != '.mojo': | 29 if ext != '.mojo': |
| 24 return False | 30 return False |
| 25 return 'apptests' not in os.path.basename(path) | 31 return 'apptests' not in os.path.basename(path) |
| 26 | 32 |
| 27 | 33 |
| 28 def gen_filter(path): | 34 def gen_filter(path): |
| 29 if os.path.isdir(path): | 35 if os.path.isdir(path): |
| 30 return True | 36 return True |
| 31 _, ext = os.path.splitext(path) | 37 _, ext = os.path.splitext(path) |
| 32 # Don't include all .dart, just .mojom.dart. | 38 # Don't include all .dart, just .mojom.dart. |
| 33 return ext == '.sky' or path.endswith('.mojom.dart') | 39 return ext == '.sky' or path.endswith('.mojom.dart') |
| 34 | 40 |
| 35 | 41 |
| 42 def examples_filter(path): | |
| 43 if os.path.isdir(path): | |
| 44 return True | |
| 45 return 'packages' != os.path.basename(path) | |
| 46 | |
| 47 | |
| 36 def sky_or_dart_filter(path): | 48 def sky_or_dart_filter(path): |
| 37 if os.path.isdir(path): | 49 if os.path.isdir(path): |
| 38 return True | 50 return True |
| 39 _, ext = os.path.splitext(path) | 51 _, ext = os.path.splitext(path) |
| 40 # .dart includes '.mojom.dart' | 52 # .dart includes '.mojom.dart' |
| 41 return ext == '.sky' or ext == '.dart' | 53 return ext == '.sky' or ext == '.dart' |
| 42 | 54 |
| 43 | 55 |
| 44 def assets_filter(path): | 56 def assets_filter(path): |
| 45 if os.path.isdir(path): | 57 if os.path.isdir(path): |
| 46 return True | 58 return True |
| 47 if os.path.basename(os.path.dirname(path)) != '2x_web': | 59 if os.path.basename(os.path.dirname(path)) != '2x_web': |
| 48 return False | 60 return False |
| 49 # We only use the 18 and 24s for now. | 61 # We only use the 18 and 24s for now. |
| 50 return '18dp' in path or '24dp' in path | 62 return '18dp' in path or '24dp' in path |
| 51 | 63 |
| 52 | 64 |
| 53 def copy(from_root, to_root, filter_func=None): | 65 def packages_filter(path): |
| 66 if 'packages/sky/assets/material-design-icons/' in path: | |
| 67 return assets_filter(path) | |
| 68 return True | |
| 69 | |
| 70 | |
| 71 def copy(from_root, to_root, filter_func=None, followlinks=False): | |
| 54 if os.path.exists(to_root): | 72 if os.path.exists(to_root): |
| 55 shutil.rmtree(to_root) | 73 shutil.rmtree(to_root) |
| 56 os.makedirs(to_root) | 74 os.makedirs(to_root) |
| 57 | 75 |
| 58 for root, dirs, files in os.walk(from_root): | 76 for root, dirs, files in os.walk(from_root, followlinks=followlinks): |
| 59 # filter_func expects paths not names, so wrap it to make them absolute. | 77 # filter_func expects paths not names, so wrap it to make them absolute. |
| 60 wrapped_filter = None | 78 wrapped_filter = None |
| 61 if filter_func: | 79 if filter_func: |
| 62 wrapped_filter = lambda name: filter_func(os.path.join(root, name)) | 80 wrapped_filter = lambda name: filter_func(os.path.join(root, name)) |
| 63 | 81 |
| 64 for name in filter(wrapped_filter, files): | 82 for name in filter(wrapped_filter, files): |
| 65 from_path = os.path.join(root, name) | 83 from_path = os.path.join(root, name) |
| 66 root_rel_path = os.path.relpath(from_path, from_root) | 84 root_rel_path = os.path.relpath(from_path, from_root) |
| 67 to_path = os.path.join(to_root, root_rel_path) | 85 to_path = os.path.join(to_root, root_rel_path) |
| 68 to_dir = os.path.dirname(to_path) | 86 to_dir = os.path.dirname(to_path) |
| 69 if not os.path.exists(to_dir): | 87 if not os.path.exists(to_dir): |
| 70 os.makedirs(to_dir) | 88 os.makedirs(to_dir) |
| 71 shutil.copyfile(from_path, to_path) | 89 shutil.copyfile(from_path, to_path) |
| 72 | 90 |
| 73 dirs[:] = filter(wrapped_filter, dirs) | 91 dirs[:] = filter(wrapped_filter, dirs) |
| 74 | 92 |
| 93 | |
| 75 def main(): | 94 def main(): |
| 76 logging.basicConfig(level=logging.WARN) | 95 logging.basicConfig(level=logging.WARN) |
| 77 parser = argparse.ArgumentParser(description='Deploy a new build of mojo.') | 96 parser = argparse.ArgumentParser(description='Deploy a new build of mojo.') |
| 78 parser.add_argument('deploy_root', type=str) | 97 parser.add_argument('deploy_root', type=str) |
| 79 args = parser.parse_args() | 98 args = parser.parse_args() |
| 80 | 99 |
| 81 # Always use android release? | 100 # Always use android release? |
| 82 rel_build_dir = os.path.join('out', 'android_Release') | 101 rel_build_dir = os.path.join('out', 'android_Release') |
| 83 build_dir = os.path.join(Paths().src_root, rel_build_dir) | 102 build_dir = os.path.join(Paths().src_root, rel_build_dir) |
| 84 paths = Paths(build_dir=build_dir) | 103 paths = Paths(build_dir=build_dir) |
| 104 dart_pkg_dir = os.path.join(paths.build_dir, 'gen', 'dart-pkg') | |
| 105 sky_pkg_dir = os.path.join(dart_pkg_dir, 'sky') | |
| 106 dart_pkg_packages_dir = os.path.join(dart_pkg_dir, 'packages') | |
| 107 | |
| 108 # Verify that material-design-icons have been downloaded. | |
| 109 icons_dir = os.path.join(dart_pkg_packages_dir, | |
| 110 'sky/assets/material-design-icons') | |
| 111 if not os.path.isdir(icons_dir): | |
|
eseidel
2015/05/19 20:51:12
Seems easier to just run it than complain. :p
Cutch
2015/05/19 21:01:53
Done.
| |
| 112 print('ERROR: You must run `download_material_design_icons` in `%s` ' | |
| 113 'before running this script.' % sky_pkg_dir) | |
| 114 return -1 | |
| 85 | 115 |
| 86 def deploy_path(rel_path): | 116 def deploy_path(rel_path): |
| 87 return os.path.join(args.deploy_root, rel_path) | 117 return os.path.join(args.deploy_root, rel_path) |
| 88 | 118 |
| 89 def src_path(rel_path): | 119 def src_path(rel_path): |
| 90 return os.path.join(paths.src_root, rel_path) | 120 return os.path.join(paths.src_root, rel_path) |
| 91 | 121 |
| 122 # Copy all .mojo files into mojo/ | |
| 92 copy(paths.build_dir, deploy_path('mojo'), mojo_filter) | 123 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 | 124 |
| 96 # TODO(eseidel): All of these should be removed and package: sky includes | 125 # Copy sky/examples into examples/ |
| 97 # used instead. | 126 copy(src_path('sky/examples'), deploy_path('examples'), examples_filter) |
| 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 | 127 |
| 128 # Copy apks into / | |
| 105 shutil.copy(os.path.join(paths.build_dir, 'apks', 'MojoShell.apk'), | 129 shutil.copy(os.path.join(paths.build_dir, 'apks', 'MojoShell.apk'), |
| 106 args.deploy_root) | 130 args.deploy_root) |
| 107 shutil.copy(os.path.join(paths.build_dir, 'apks', 'MojoShortcuts.apk'), | 131 shutil.copy(os.path.join(paths.build_dir, 'apks', 'MojoShortcuts.apk'), |
| 108 args.deploy_root) | 132 args.deploy_root) |
| 109 | 133 |
| 134 # Deep copy packages/. This follows symlinks and flattens them. | |
| 110 packages_root = deploy_path('packages') | 135 packages_root = deploy_path('packages') |
| 111 if os.path.exists(packages_root): | 136 copy(dart_pkg_packages_dir, packages_root, packages_filter, True) |
| 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 | 137 |
| 138 # Write out license. | |
| 121 with open(deploy_path('LICENSES.sky'), 'w') as license_file: | 139 with open(deploy_path('LICENSES.sky'), 'w') as license_file: |
| 122 subprocess.check_call([src_path('tools/licenses.py'), 'credits'], | 140 subprocess.check_call([src_path('tools/licenses.py'), 'credits'], |
| 123 stdout=license_file) | 141 stdout=license_file) |
| 124 | 142 |
| 125 | 143 # Run git commands. |
| 126 subprocess.check_call(['git', 'add', '.'], cwd=args.deploy_root) | 144 subprocess.check_call(['git', 'add', '.'], cwd=args.deploy_root) |
| 127 subprocess.check_call([ | 145 subprocess.check_call([ |
| 128 'git', 'commit', | 146 'git', 'commit', |
| 129 '-m', '%s from %s' % (rel_build_dir, git_revision()) | 147 '-m', '%s from %s' % (rel_build_dir, git_revision()) |
| 130 ], cwd=args.deploy_root) | 148 ], cwd=args.deploy_root) |
| 131 | 149 |
| 132 | 150 |
| 133 if __name__ == '__main__': | 151 if __name__ == '__main__': |
| 134 main() | 152 main() |
| OLD | NEW |