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