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

Side by Side Diff: sky/tools/deploy_sdk.py

Issue 1143333006: Remove deploy_sdk.py and mojo_demo.py (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 7 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 unified diff | Download patch
« no previous file with comments | « mojo/tools/mojo_demo.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 from datetime import datetime
8 import logging
9 import os
10 import shutil
11 import subprocess
12 import sys
13
14 # Generates the sky_sdk from the template at sky/sdk.
15
16 # This script has a split personality of both making our deployment sdk
17 # as well as being a required part of developing locally, since all
18 # of our framework assumes it's working from the SDK.
19
20 SKY_TOOLS_DIR = os.path.dirname(os.path.abspath(__file__))
21 SKY_DIR = os.path.dirname(SKY_TOOLS_DIR)
22 SRC_ROOT = os.path.dirname(SKY_DIR)
23
24 DEFAULT_REL_BUILD_DIR = os.path.join('out', 'android_Release')
25
26 def git_revision():
27 return subprocess.check_output(['git', 'rev-parse', 'HEAD']).strip()
28
29
30 def gen_filter(path):
31 if os.path.isdir(path):
32 return True
33 _, ext = os.path.splitext(path)
34 # Don't include all .dart, just .mojom.dart.
35 return path.endswith('.mojom.dart')
36
37
38 def dart_filter(path):
39 if os.path.isdir(path):
40 return True
41 _, ext = os.path.splitext(path)
42 # .dart includes '.mojom.dart'
43 return ext == '.dart'
44
45
46 def ensure_dir_exists(path):
47 if not os.path.exists(path):
48 os.makedirs(path)
49
50
51 def copy(from_root, to_root, filter_func=None):
52 assert os.path.exists(from_root), "%s does not exist!" % from_root
53 if os.path.isfile(from_root):
54 ensure_dir_exists(os.path.dirname(to_root))
55 shutil.copy(from_root, to_root)
56 return
57
58 ensure_dir_exists(to_root)
59
60 for root, dirs, files in os.walk(from_root):
61 # filter_func expects paths not names, so wrap it to make them absolute.
62 wrapped_filter = None
63 if filter_func:
64 wrapped_filter = lambda name: filter_func(os.path.join(root, name))
65
66 for name in filter(wrapped_filter, files):
67 from_path = os.path.join(root, name)
68 root_rel_path = os.path.relpath(from_path, from_root)
69 to_path = os.path.join(to_root, root_rel_path)
70 to_dir = os.path.dirname(to_path)
71 if not os.path.exists(to_dir):
72 os.makedirs(to_dir)
73 shutil.copy(from_path, to_path)
74
75 dirs[:] = filter(wrapped_filter, dirs)
76
77
78 def link(from_root, to_root, filter_func=None):
79 ensure_dir_exists(os.path.dirname(to_root))
80 os.symlink(from_root, to_root)
81
82
83 def make_relative_symlink(source, link_name):
84 rel_source = os.path.relpath(source, os.path.dirname(link_name))
85 os.symlink(rel_source, link_name)
86
87
88 def confirm(prompt):
89 response = raw_input('%s [N]|y: ' % prompt)
90 return response and response.lower() == 'y'
91
92
93 def delete_all_non_hidden_files_in_directory(root, non_interactive=False):
94 to_delete = [os.path.join(root, p)
95 for p in os.listdir(root) if not p.startswith('.')]
96 if not to_delete:
97 return
98 if not non_interactive:
99 prompt = 'This will delete everything in %s:\n%s\nAre you sure?' % (
100 root, '\n'.join(to_delete))
101 if not confirm(prompt):
102 print 'User aborted.'
103 sys.exit(2)
104
105 for path in to_delete:
106 if os.path.isdir(path) and not os.path.islink(path):
107 shutil.rmtree(path)
108 else:
109 os.remove(path)
110
111
112 def main():
113 logging.basicConfig(level=logging.WARN)
114 parser = argparse.ArgumentParser(description='Deploy a new sky_sdk.')
115 parser.add_argument('sdk_root', type=str)
116 parser.add_argument('--build-dir', action='store', type=str,
117 default=os.path.join(SRC_ROOT, DEFAULT_REL_BUILD_DIR))
118 parser.add_argument('--extra-mojom-dir', action='append',
119 type=str,
120 dest='extra_mojom_dirs',
121 metavar='EXTRA_MOJOM_DIR',
122 help='Extra root directory for mojom packages. '
123 'Can be specified multiple times.',
124 default=[])
125 parser.add_argument('--non-interactive', action='store_true')
126 parser.add_argument('--dev-environment', action='store_true')
127 parser.add_argument('--commit', action='store_true')
128 parser.add_argument('--fake-pub-get-into', action='store', type=str)
129 args = parser.parse_args()
130
131 build_dir = os.path.abspath(args.build_dir)
132 sdk_root = os.path.abspath(args.sdk_root)
133
134 print 'Building SDK from %s into %s' % (build_dir, sdk_root)
135 start_time = datetime.now()
136
137 # These are separate ideas but don't need a separate flag yet.
138 use_links = args.dev_environment
139 skip_apks = args.dev_environment
140 should_commit = args.commit
141 generate_licenses = not args.dev_environment
142
143 # We save a bunch of time in --dev-environment mode by symlinking whole
144 # directories when possible. Any names which conflict with generated
145 # directories can't be symlinked and must be copied.
146 copy_or_link = link if use_links else copy
147
148 def sdk_path(rel_path):
149 return os.path.join(sdk_root, rel_path)
150
151 def src_path(rel_path):
152 return os.path.join(SRC_ROOT, rel_path)
153
154 ensure_dir_exists(sdk_root)
155 delete_all_non_hidden_files_in_directory(sdk_root, args.non_interactive)
156
157 # Manually clear sdk_root above to avoid deleting dot-files.
158 copy(src_path('sky/sdk'), sdk_root)
159
160 copy_or_link(src_path('sky/examples'), sdk_path('examples'))
161
162 # Sky package
163 copy_or_link(src_path('sky/framework'), sdk_path('packages/sky/lib/framework '))
164 copy_or_link(src_path('sky/assets'), sdk_path('packages/sky/lib/assets'))
165
166 # Sky SDK additions:
167 copy_or_link(src_path('sky/engine/bindings/builtin.dart'),
168 sdk_path('packages/sky/sdk_additions/dart_sky_builtins.dart'))
169 bindings_path = os.path.join(build_dir, 'gen/sky/bindings')
170 # dart_sky.dart has many supporting files:
171 copy(bindings_path, sdk_path('packages/sky/sdk_additions'),
172 dart_filter)
173
174 # Mojo package, lots of overlap with gen, must be copied:
175 copy(src_path('mojo/public'), sdk_path('packages/mojo/lib/public'),
176 dart_filter)
177
178 # By convention the generated .mojom.dart files in a pub package
179 # go under $PACKAGE/lib/mojom.
180 # The mojo package owns all the .mojom.dart files that are not in the 'sky'
181 # mojom module.
182 def non_sky_gen_filter(path):
183 if os.path.isdir(path) and path.endswith('sky'):
184 return False
185 return gen_filter(path)
186 mojo_package_mojom_dir = sdk_path('packages/mojo/lib/mojom')
187 copy(os.path.join(build_dir, 'gen/dart-gen/mojom'), mojo_package_mojom_dir,
188 non_sky_gen_filter)
189
190 # The Sky package owns the .mojom.dart files in the 'sky' mojom module.
191 def sky_gen_filter(path):
192 if os.path.isfile(path) and not os.path.dirname(path).endswith('sky'):
193 return False
194 return gen_filter(path)
195 sky_package_mojom_dir = sdk_path('packages/sky/lib/mojom')
196 copy(os.path.join(build_dir, 'gen/dart-gen/mojom'), sky_package_mojom_dir,
197 sky_gen_filter)
198
199 # Mojo SDK additions:
200 copy_or_link(src_path('mojo/public/dart/bindings.dart'),
201 sdk_path('packages/mojo/sdk_additions/dart_mojo_bindings.dart'))
202 copy_or_link(src_path('mojo/public/dart/core.dart'),
203 sdk_path('packages/mojo/sdk_additions/dart_mojo_core.dart'))
204
205 if not skip_apks:
206 ensure_dir_exists(sdk_path('packages/sky/apks'))
207 shutil.copy(os.path.join(build_dir, 'apks', 'SkyDemo.apk'),
208 sdk_path('packages/sky/apks'))
209
210 if generate_licenses:
211 with open(sdk_path('LICENSES.sky'), 'w') as license_file:
212 subprocess.check_call([src_path('tools/licenses.py'), 'credits'],
213 stdout=license_file)
214
215 copy_or_link(src_path('AUTHORS'), sdk_path('packages/mojo/AUTHORS'))
216 copy_or_link(src_path('LICENSE'), sdk_path('packages/mojo/LICENSE'))
217 copy_or_link(src_path('AUTHORS'), sdk_path('packages/sky/AUTHORS'))
218 copy_or_link(src_path('LICENSE'), sdk_path('packages/sky/LICENSE'))
219
220 if args.fake_pub_get_into:
221 packages_dir = os.path.abspath(args.fake_pub_get_into)
222 ensure_dir_exists(packages_dir)
223 make_relative_symlink(sdk_path('packages/mojo/lib'),
224 os.path.join(packages_dir, 'mojo'))
225 make_relative_symlink(sdk_path('packages/sky/lib'),
226 os.path.join(packages_dir, 'sky'))
227
228 mojom_dirs = [ mojo_package_mojom_dir, sky_package_mojom_dir ]
229 mojom_dirs += args.extra_mojom_dirs
230 for mojom_dir in mojom_dirs:
231 copy(mojom_dir, os.path.join(packages_dir, 'mojom'), gen_filter)
232
233 if should_commit:
234 # Kinda a hack to make a prettier build dir for the commit:
235 script_path = os.path.relpath(os.path.abspath(__file__), SRC_ROOT)
236 rel_build_dir = os.path.relpath(build_dir, SRC_ROOT)
237 revision = git_revision()
238 commit_url = "https://github.com/domokit/mojo/commit/%s" % revision
239 pattern = """Autogenerated from %s
240 Using %s and build output from %s.
241 """
242 commit_message = pattern % (commit_url, script_path, rel_build_dir)
243 subprocess.check_call(['git', 'add', '.'], cwd=sdk_root)
244 subprocess.check_call([
245 'git', 'commit',
246 '-m', commit_message
247 ], cwd=sdk_root)
248
249 time_delta = datetime.now() - start_time
250 print 'SDK built at %s in %ss' % (sdk_root, time_delta.total_seconds())
251
252
253 if __name__ == '__main__':
254 main()
OLDNEW
« no previous file with comments | « mojo/tools/mojo_demo.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698