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

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

Issue 1174683003: Resurrect deploy_sdk and make it use prepare_pub_packages.py (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Remove unsued --extra-mojom-dir arg Created 5 years, 6 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 | « no previous file | 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 SKY_TOOLS_DIR = os.path.dirname(os.path.abspath(__file__))
17 SKY_DIR = os.path.dirname(SKY_TOOLS_DIR)
18 SRC_ROOT = os.path.dirname(SKY_DIR)
19
20 DEFAULT_REL_BUILD_DIR = os.path.join('out', 'android_Release')
21
22 def git_revision():
23 return subprocess.check_output(['git', 'rev-parse', 'HEAD']).strip()
24
25
26 def ensure_dir_exists(path):
27 if not os.path.exists(path):
28 os.makedirs(path)
29
30
31 def copy(from_root, to_root, filter_func=None):
32 assert os.path.exists(from_root), "%s does not exist!" % from_root
33 if os.path.isfile(from_root):
34 ensure_dir_exists(os.path.dirname(to_root))
35 shutil.copy(from_root, to_root)
36 return
37
38 ensure_dir_exists(to_root)
39
40 for root, dirs, files in os.walk(from_root):
41 # filter_func expects paths not names, so wrap it to make them absolute.
42 wrapped_filter = None
43 if filter_func:
44 wrapped_filter = lambda name: filter_func(os.path.join(root, name))
45
46 for name in filter(wrapped_filter, files):
47 from_path = os.path.join(root, name)
48 root_rel_path = os.path.relpath(from_path, from_root)
49 to_path = os.path.join(to_root, root_rel_path)
50 to_dir = os.path.dirname(to_path)
51 if not os.path.exists(to_dir):
52 os.makedirs(to_dir)
53 shutil.copy(from_path, to_path)
54
55 dirs[:] = filter(wrapped_filter, dirs)
56
57
58 def confirm(prompt):
59 response = raw_input('%s [N]|y: ' % prompt)
60 return response and response.lower() == 'y'
61
62
63 def delete_all_non_hidden_files_in_directory(root, non_interactive=False):
64 to_delete = [os.path.join(root, p)
65 for p in os.listdir(root) if not p.startswith('.')]
66 if not to_delete:
67 return
68 if not non_interactive:
69 prompt = 'This will delete everything in %s:\n%s\nAre you sure?' % (
70 root, '\n'.join(to_delete))
71 if not confirm(prompt):
72 print 'User aborted.'
73 sys.exit(2)
74
75 for path in to_delete:
76 if os.path.isdir(path) and not os.path.islink(path):
77 shutil.rmtree(path)
78 else:
79 os.remove(path)
80
81
82 def main():
83 logging.basicConfig(level=logging.WARN)
84 parser = argparse.ArgumentParser(description='Deploy a new sky_sdk.')
85 parser.add_argument('sdk_root', type=str)
86 parser.add_argument('--build-dir', action='store', type=str,
87 default=os.path.join(SRC_ROOT, DEFAULT_REL_BUILD_DIR))
88 parser.add_argument('--non-interactive', action='store_true')
89 parser.add_argument('--commit', action='store_true')
90 args = parser.parse_args()
91
92 build_dir = os.path.abspath(args.build_dir)
93 sdk_root = os.path.abspath(args.sdk_root)
94
95 print 'Building SDK from %s into %s' % (build_dir, sdk_root)
96 start_time = datetime.now()
97
98 should_commit = args.commit
99
100 def sdk_path(rel_path):
101 return os.path.join(sdk_root, rel_path)
102
103 def src_path(rel_path):
104 return os.path.join(SRC_ROOT, rel_path)
105
106 ensure_dir_exists(sdk_root)
107 # Manually clear sdk_root above to avoid deleting dot-files.
108 delete_all_non_hidden_files_in_directory(sdk_root, args.non_interactive)
109 copy(src_path('sky/examples'), sdk_path('examples'))
110
111 copy(src_path('sky/sdk/README.md'), sdk_root)
112
113 ensure_dir_exists(sdk_path('packages'))
114 subprocess.check_call([
115 'mojo/tools/prepare_pub_packages.py',
116 '--out-dir', sdk_path('packages'),
117 'out'
118 ])
119
120 with open(sdk_path('LICENSES.sky'), 'w') as license_file:
121 subprocess.check_call([src_path('tools/licenses.py'), 'credits'],
122 stdout=license_file)
123
124 if should_commit:
125 # Kinda a hack to make a prettier build dir for the commit:
126 script_path = os.path.relpath(os.path.abspath(__file__), SRC_ROOT)
127 rel_build_dir = os.path.relpath(build_dir, SRC_ROOT)
128 revision = git_revision()
129 commit_url = "https://github.com/domokit/mojo/commit/%s" % revision
130 pattern = """Autogenerated from %s
131 Using %s and build output from %s.
132 """
133 commit_message = pattern % (commit_url, script_path, rel_build_dir)
134 subprocess.check_call(['git', 'add', '.'], cwd=sdk_root)
135 subprocess.check_call([
136 'git', 'commit',
137 '-m', commit_message
138 ], cwd=sdk_root)
139
140 time_delta = datetime.now() - start_time
141 print 'SDK built at %s in %ss' % (sdk_root, time_delta.total_seconds())
142
143
144 if __name__ == '__main__':
145 main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698