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

Side by Side 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: Made deploy_sdk 100x faster in the --dev-environment case 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 unified diff | Download patch
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 def gen_filter(path):
30 if os.path.isdir(path):
31 return True
32 _, ext = os.path.splitext(path)
33 # Don't include all .dart, just .mojom.dart.
34 return path.endswith('.mojom.dart')
35
36 def 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 == '.dart'
42
43
44 def sky_or_dart_filter(path):
45 if os.path.isdir(path):
46 return True
47 _, ext = os.path.splitext(path)
48 # .dart includes '.mojom.dart'
49 return ext == '.sky' or ext == '.dart'
50
51
52 def ensure_dir_exists(path):
53 if not os.path.exists(path):
54 os.makedirs(path)
55
56
57 def copy(from_root, to_root, filter_func=None):
58 if os.path.isfile(from_root):
59 ensure_dir_exists(os.path.dirname(to_root))
60 shutil.copy(from_root, to_root)
61 return
62
63 ensure_dir_exists(to_root)
64
65 for root, dirs, files in os.walk(from_root):
66 # filter_func expects paths not names, so wrap it to make them absolute.
67 wrapped_filter = None
68 if filter_func:
69 wrapped_filter = lambda name: filter_func(os.path.join(root, name))
70
71 for name in filter(wrapped_filter, files):
72 from_path = os.path.join(root, name)
73 root_rel_path = os.path.relpath(from_path, from_root)
74 to_path = os.path.join(to_root, root_rel_path)
75 to_dir = os.path.dirname(to_path)
76 if not os.path.exists(to_dir):
77 os.makedirs(to_dir)
78 shutil.copy(from_path, to_path)
79
80 dirs[:] = filter(wrapped_filter, dirs)
81
82
83 def link(from_root, to_root, filter_func=None):
84 ensure_dir_exists(os.path.dirname(to_root))
85 os.symlink(from_root, to_root)
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, force=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 force:
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('-f', '--force', action='store_true')
119 parser.add_argument('--dev-environment', action='store_true')
120 parser.add_argument('--fake-pub-get-into', action='store', type=str)
121 args = parser.parse_args()
122
123 build_dir = os.path.abspath(args.build_dir)
124 sdk_root = os.path.abspath(args.sdk_root)
125
126 print 'Building SDK from %s into %s' % (build_dir, sdk_root)
127 start_time = datetime.now()
128
129 # These are separate ideas but don't need a separate flag yet.
130 use_links = args.dev_environment
131 skip_apks = args.dev_environment
132 should_commit = not args.dev_environment
133 generate_licenses = not args.dev_environment
134
135 # We save a bunch of time in --dev-environment mode by symlinking whole
136 # directories when possible. Any names which conflict with generated
137 # directories can't be symlinked and must be copied.
138 copy_or_link = link if use_links else copy
139
140 def sdk_path(rel_path):
141 return os.path.join(sdk_root, rel_path)
142
143 def src_path(rel_path):
144 return os.path.join(SRC_ROOT, rel_path)
145
146 ensure_dir_exists(sdk_root)
147 delete_all_non_hidden_files_in_directory(sdk_root, args.force)
148
149 # Manually clear sdk_root above to avoid deleting dot-files.
150 copy(src_path('sky/sdk'), sdk_root)
151
152 copy_or_link(src_path('sky/examples'), sdk_path('examples'),
153 sky_or_dart_filter)
154
155 # Sky package
156 copy_or_link(src_path('sky/framework'),
157 sdk_path('packages/sky/lib/framework'), sky_or_dart_filter)
158 copy_or_link(src_path('sky/assets'), sdk_path('packages/sky/lib/assets'))
159 # Copy gen files every time for now:
160 copy(os.path.join(build_dir, 'gen/sky'),
161 sdk_path('packages/sky/lib'), gen_filter)
162
163 # Not used in the dev environment.
164 copy_or_link(src_path('sky/sdk/tools/sky'),
165 sdk_path('packages/sky/bin/sky'))
166
167 # Mojo package, lots of overlap with gen, must be copied:
168 copy(src_path('mojo/public'), sdk_path('packages/mojo/lib/public'),
169 dart_filter)
170 copy(os.path.join(build_dir, 'gen/mojo'), sdk_path('packages/mojo/lib'),
171 gen_filter)
172
173 if not skip_apks:
174 ensure_dir_exists(sdk_path('apks'))
175 shutil.copy(os.path.join(build_dir, 'apks', 'SkyShell.apk'),
176 sdk_path('apks'))
177
178 if generate_licenses:
179 with open(sdk_path('LICENSES.sky'), 'w') as license_file:
180 subprocess.check_call([src_path('tools/licenses.py'), 'credits'],
181 stdout=license_file)
182
183 if args.fake_pub_get_into:
184 packages_dir = os.path.abspath(args.fake_pub_get_into)
185 ensure_dir_exists(packages_dir)
186 os.symlink(sdk_path('packages/mojo/lib'),
187 os.path.join(packages_dir, 'mojo'))
188 os.symlink(sdk_path('packages/sky/lib'),
189 os.path.join(packages_dir, 'sky'))
190
191 if should_commit:
192 # Kinda a hack to make a prettier build dir for the commit:
193 rel_build_dir = os.path.join(os.path.split(build_dir)[-2:])
194 subprocess.check_call(['git', 'add', '.'], cwd=sdk_root)
195 subprocess.check_call([
196 'git', 'commit',
197 '-m', '%s from %s' % (rel_build_dir, git_revision())
198 ], cwd=sdk_root)
199
200 time_delta = datetime.now() - start_time
201 print 'SDK built at %s in %ss' % (sdk_root, time_delta.total_seconds())
202
203
204 if __name__ == '__main__':
205 main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698