blob: a02469f98db775f623ffd1106e94b0033c7c3989 [file] [log] [blame]
Alan Viverettef5cb0e62017-11-17 15:15:23 -05001#!/usr/bin/python3
Alan Viverette95f6d362017-04-06 09:40:50 -04002
Alan Viverettecd3de262017-08-14 09:51:30 -04003# This script is used to update platform SDK prebuilts, Support Library, and a variety of other
4# prebuilt libraries used by Android's Makefile builds. For details on how to use this script,
5# visit go/update-prebuilts.
Alan Viverette95f6d362017-04-06 09:40:50 -04006import os, sys, getopt, zipfile, re
Alan Viveretted4527e62017-05-11 15:03:25 -04007import argparse
8import subprocess
Alan Viverettef5cb0e62017-11-17 15:15:23 -05009from shutil import copyfile, rmtree, which
Alan Viveretted4527e62017-05-11 15:03:25 -040010from distutils.version import LooseVersion
Alan Viverettef5cb0e62017-11-17 15:15:23 -050011from functools import reduce
Alan Viverette95f6d362017-04-06 09:40:50 -040012
Alan Viverette45837092017-05-12 14:50:53 -040013current_path = 'current'
14system_path = 'system_current'
Alan Viverette3e57a4a2017-08-11 15:49:47 -040015support_dir = os.path.join(current_path, 'support')
16extras_dir = os.path.join(current_path, 'extras')
Alan Viverettec1c32b62017-12-20 09:40:36 -050017buildtools_dir = 'tools'
Jeff Gaston13e38412018-02-06 14:45:36 -050018jetifier_dir = os.path.join(buildtools_dir, 'jetifier')
Alan Viverette95f6d362017-04-06 09:40:50 -040019
Alan Viverettecd3de262017-08-14 09:51:30 -040020# See go/fetch_artifact for details on this script.
Alan Viveretted4527e62017-05-11 15:03:25 -040021FETCH_ARTIFACT = '/google/data/ro/projects/android/fetch_artifact'
22
Alan Viverette95f6d362017-04-06 09:40:50 -040023maven_to_make = {
Alan Viverette7e897e22018-03-09 15:24:10 -050024 'animated-vector-drawable': ['android-support-animatedvectordrawable', 'graphics/drawable'],
25 'appcompat-v7': ['android-support-v7-appcompat', 'v7/appcompat'],
26 'cardview-v7': ['android-support-v7-cardview', 'v7/cardview'],
27 'collections': ['android-support-collections', 'collections'],
28 'customtabs': ['android-support-customtabs', 'customtabs'],
29 'exifinterface': ['android-support-exifinterface', 'exifinterface'],
30 'gridlayout-v7': ['android-support-v7-gridlayout', 'v7/gridlayout'],
31 'leanback-v17': ['android-support-v17-leanback', 'v17/leanback'],
32 'mediarouter-v7': ['android-support-v7-mediarouter', 'v7/mediarouter'],
33 'palette-v7': ['android-support-v7-palette', 'v7/palette'],
34 'percent': ['android-support-percent', 'percent'],
35 'preference-leanback-v17': ['android-support-v17-preference-leanback', 'v17/preference-leanback'],
36 'preference-v14': ['android-support-v14-preference', 'v14/preference'],
37 'preference-v7': ['android-support-v7-preference', 'v7/preference'],
38 'recommendation': ['android-support-recommendation', 'recommendation'],
39 'recyclerview-v7': ['android-support-v7-recyclerview', 'v7/recyclerview'],
40 'support-annotations': ['android-support-annotations', 'annotations', 'jar'],
41 'support-compat': ['android-support-compat', 'compat'],
42 'support-core-ui': ['android-support-core-ui', 'core-ui'],
43 'support-core-utils': ['android-support-core-utils', 'core-utils'],
44 'support-dynamic-animation': ['android-support-dynamic-animation', 'dynamic-animation'],
45 'support-emoji-appcompat': ['android-support-emoji-appcompat', 'emoji-appcompat'],
46 'support-emoji-bundled': ['android-support-emoji-bundled', 'emoji-bundled'],
47 'support-emoji': ['android-support-emoji', 'emoji'],
48 'support-fragment': ['android-support-fragment', 'fragment'],
49 'support-media-compat': ['android-support-media-compat', 'media-compat'],
50 'support-tv-provider': ['android-support-tv-provider', 'tv-provider'],
51 'support-v13': ['android-support-v13', 'v13'],
52 'support-v4': ['android-support-v4', 'v4'],
53 'support-vector-drawable': ['android-support-vectordrawable', 'graphics/drawable'],
54 'transition': ['android-support-transition', 'transition'],
55 'wear': ['android-support-wear', 'wear'],
Alan Viverette7bb86da2018-02-21 18:29:02 -050056
Alan Viverette7e897e22018-03-09 15:24:10 -050057 # AndroidX renamed modules
58 'androidx.annotation:annotation': ['android-support-annotations', 'annotations', 'jar'],
59 'androidx.appcompat:appcompat': ['android-support-v7-appcompat', 'v7/appcompat'],
60 'androidx.browser:browser': ['android-support-customtabs', 'customtabs'],
61 'androidx.cardview:cardview': ['android-support-v7-cardview', 'v7/cardview'],
62 'androidx.collection:collection': ['android-support-collections', 'collections'],
63 'androidx.core:core': ['android-support-compat', 'compat'],
64 'androidx.dynamicanimation:dynamicanimation': ['android-support-dynamic-animation', 'dynamic-animation'],
65 'androidx.emoji:emoji-appcompat': ['android-support-emoji-appcompat', 'emoji-appcompat'],
66 'androidx.emoji:emoji-bundled': ['android-support-emoji-bundled', 'emoji-bundled'],
67 'androidx.emoji:emoji': ['android-support-emoji', 'emoji'],
68 'androidx.fragment:fragment': ['android-support-fragment', 'fragment'],
69 'androidx.gridlayout:gridlayout': ['android-support-v7-gridlayout', 'v7/gridlayout'],
70 'androidx.leanback:leanback-preference': ['android-support-v17-preference-leanback', 'v17/preference-leanback'],
71 'androidx.leanback:leanback': ['android-support-v17-leanback', 'v17/leanback'],
72 'androidx.legacy:legacy-preference-v14': ['android-support-v14-preference', 'v14/preference'],
73 'androidx.legacy:legacy-support-core-ui': ['android-support-core-ui', 'core-ui'],
74 'androidx.legacy:legacy-support-core-utils': ['android-support-core-utils', 'core-utils'],
75 'androidx.legacy:legacy-support-v13': ['android-support-v13', 'v13'],
76 'androidx.legacy:legacy-support-v4': ['android-support-v4', 'v4'],
77 'androidx.media:media': ['android-support-media-compat', 'media-compat'],
78 'androidx.mediarouter:mediarouter': ['android-support-v7-mediarouter', 'v7/mediarouter'],
79 'androidx.palette:palette': ['android-support-v7-palette', 'v7/palette'],
80 'androidx.percentlayout:percentlayout': ['android-support-percent', 'percent'],
81 'androidx.preference:preference': ['android-support-v7-preference', 'v7/preference'],
82 'androidx.recyclerview:recyclerview': ['android-support-v7-recyclerview', 'v7/recyclerview'],
83 'androidx.tvprovider:tvprovider': ['android-support-tv-provider', 'tv-provider'],
84 'androidx.vectordrawable:vectordrawable-animated': ['android-support-animatedvectordrawable', 'graphics/drawable'],
85 'androidx.vectordrawable:vectordrawable': ['android-support-vectordrawable', 'graphics/drawable'],
86
87 # AndroidX new modules
88 'heifwriter': ['android-support-heifwriter', 'heifwriter'],
89 'webkit': ['android-support-webkit', 'webkit'],
90 'customview': ['android-support-customview', 'customview'],
91 'textclassifier': ['android-support-textclassifier', 'textclassifier'],
92 'swiperefreshlayout': ['android-support-swiperefreshlayout', 'swiperefreshlayout'],
93 'viewpager': ['android-support-viewpager', 'viewpager'],
94 'coordinatorlayout': ['android-support-coordinatorlayout', 'coordinatorlayout'],
95 'asynclayoutinflater': ['android-support-asynclayoutinflater', 'asynclayoutinflater'],
96 'support-content': ['android-support-support-content', 'support-content'],
97 'documentfile': ['android-support-documentfile', 'documentfile'],
98 'drawerlayout': ['android-support-drawerlayout', 'drawerlayout'],
99 'localbroadcastmanager': ['android-support-localbroadcastmanager', 'localbroadcastmanager'],
100 'print': ['android-support-print', 'print'],
101 'slidingpanelayout': ['android-support-slidingpanelayout', 'slidingpanelayout'],
102 'interpolator': ['android-support-interpolator', 'interpolator'],
103 'cursoradapter': ['android-support-cursoradapter', 'cursoradapter'],
104 'loader': ['android-support-loader', 'loader'],
105 'contentpaging': ['android-support-contentpaging', 'contentpaging'],
106 'recyclerview-selection': ['android-support-recyclerview-selection', 'recyclerview-selection'],
Alan Viverette4ec9a172018-02-20 16:19:31 -0500107 'car': ['android-support-car', 'car'],
Alan Viverette7bb86da2018-02-21 18:29:02 -0500108
Alan Viverette19ecd502018-01-05 13:52:16 -0500109 # Slices
110 'slices-core': ['android-slices-core', 'slices-core'],
111 'slices-view': ['android-slices-view', 'slices-view'],
112 'slices-builders': ['android-slices-builders', 'slices-builders'],
113
114 # Multidex
115 'multidex': ['android-support-multidex', 'multidex/library'],
116 'multidex-instrumentation': ['android-support-multidex-instrumentation', 'multidex/instrumentation'],
117
118 # Constraint Layout
119 'constraint-layout': ['android-support-constraint-layout', 'constraint-layout'],
120 'constraint-layout-solver': ['android-support-constraint-layout-solver', 'constraint-layout-solver'],
121
122 # App Arch Core
123 'android.arch.core:runtime': ['android-arch-core-runtime', 'arch-core/runtime'],
124 'android.arch.core:common': ['android-arch-core-common', 'arch-core/common'],
Allenab72f012018-01-29 18:10:23 -0800125 'android.arch.core:testing': ['android-arch-core-testing', 'arch-core/testing'],
126
Alan Viverette19ecd502018-01-05 13:52:16 -0500127 # Paging
128 'android.arch.paging:common': ['android-arch-paging-common', 'arch-paging/common'],
129 'android.arch.paging:runtime': ['android-arch-paging-runtime', 'arch-paging/runtime'],
Allenab72f012018-01-29 18:10:23 -0800130
Alan Viverette19ecd502018-01-05 13:52:16 -0500131 # Lifecycle
Allenab72f012018-01-29 18:10:23 -0800132 'android.arch.lifecycle:livedata-core': ['android-arch-lifecycle-livedata-core', 'arch-lifecycle/livedata-core'],
133 'android.arch.lifecycle:livedata': ['android-arch-lifecycle-livedata', 'arch-lifecycle/livedata'],
134 'android.arch.lifecycle:viewmodel': ['android-arch-lifecycle-viewmodel', 'arch-lifecycle/viewmodel'],
135 'android.arch.lifecycle:extensions': ['android-arch-lifecycle-extensions', 'arch-lifecycle/extensions'],
136 'android.arch.lifecycle:runtime': ['android-arch-lifecycle-runtime', 'arch-lifecycle/runtime'],
137 'android.arch.lifecycle:common': ['android-arch-lifecycle-common', 'arch-lifecycle/common'],
138 'android.arch.lifecycle:common-java8': ['android-arch-lifecycle-common-java8', 'arch-lifecycle/common-java8'],
Alan Viverettec7e88f12018-02-13 15:29:50 -0500139 # Missing dependencies:
140 # - auto-common
141 # - javapoet
142 #'android.arch.lifecycle:compiler': ['android-arch-lifecycle-compiler', 'arch-lifecycle/compiler'],
143 # Missing dependencies:
144 # - reactive-streams
145 #'android.arch.lifecycle:reactivestreams': ['android-arch-lifecycle-reactivestreams','arch-lifecycle/reactivestreams'],
Allenab72f012018-01-29 18:10:23 -0800146
Alan Viverette19ecd502018-01-05 13:52:16 -0500147 # Persistence
148 'android.arch.persistence:db': ['android-arch-persistence-db', 'arch-persistence/db'],
149 'android.arch.persistence:db-framework': ['android-arch-persistence-db-framework', 'arch-persistence/db-framework'],
Allenab72f012018-01-29 18:10:23 -0800150
Alan Viverette19ecd502018-01-05 13:52:16 -0500151 # Room
152 'android.arch.persistence.room:common': ['android-arch-room-common', 'arch-room/common'],
Alan Viverettec7e88f12018-02-13 15:29:50 -0500153 # Missing dependencies:
154 # - auto-common
155 # - javapoet
156 # - antlr4
157 # - kotlin-metadata
158 # - commons-codec
159 #'android.arch.persistence.room:compiler': ['android-arch-room-compiler', 'arch-room/compiler'],
Alan Viverette19ecd502018-01-05 13:52:16 -0500160 'android.arch.persistence.room:runtime': ['android-arch-room-runtime', 'arch-room/runtime'],
161 'android.arch.persistence.room:migration': ['android-arch-room-migration', 'arch-room/migration'],
Alan Viverettec7e88f12018-02-13 15:29:50 -0500162 # Missing dependencies:
163 # - rxjava
164 #'android.arch.persistence.room:rxjava2': ['android-arch-room-rxjava2', 'arch-room/rxjava2'],
Alan Viverette19ecd502018-01-05 13:52:16 -0500165 'android.arch.persistence.room:testing': ['android-arch-room-testing', 'arch-room/testing'],
Allenab72f012018-01-29 18:10:23 -0800166
Alan Viverette129555e2018-01-30 09:57:57 -0500167 # Material Design Components
168 'com.google.android:flexbox': ['flexbox', 'flexbox'],
169 'design': ['android-support-design', 'design'],
170 'design-animation': ['android-support-design-animation', 'design-animation'],
171 'design-bottomnavigation': ['android-support-design-bottomnavigation', 'design-bottomnavigation'],
172 'design-bottomsheet': ['android-support-design-bottomsheet', 'design-bottomsheet'],
173 'design-button': ['android-support-design-button', 'design-button'],
174 'design-canvas': ['android-support-design-canvas', 'design-canvas'],
175 'design-card': ['android-support-design-card', 'design-card'],
176 'design-chip': ['android-support-design-chip', 'design-chip'],
177 'design-circularreveal': ['android-support-design-circularreveal', 'design-circularreveal'],
178 'design-circularreveal-cardview': ['android-support-design-circularreveal-cardview', 'design-circularreveal-cardview'],
179 'design-circularreveal-coordinatorlayout': ['android-support-design-circularreveal-coordinatorlayout', 'design-circularreveal-coordinatorlayout'],
180 'design-color': ['android-support-design-color', 'design-color'],
181 'design-dialog': ['android-support-design-dialog', 'design-dialog'],
182 'design-drawable': ['android-support-design-drawable', 'design-drawable'],
183 'design-expandable': ['android-support-design-expandable', 'design-expandable'],
184 'design-floatingactionbutton': ['android-support-design-floatingactionbutton', 'design-floatingactionbutton'],
185 'design-internal': ['android-support-design-internal', 'design-internal'],
186 'design-math': ['android-support-design-math', 'design-math'],
187 'design-resources': ['android-support-design-resources', 'design-resources'],
188 'design-ripple': ['android-support-design-ripple', 'design-ripple'],
189 'design-snackbar': ['android-support-design-snackbar', 'design-snackbar'],
190 'design-stateful': ['android-support-design-stateful', 'design-stateful'],
191 'design-textfield': ['android-support-design-textfield', 'design-textfield'],
192 'design-theme': ['android-support-design-theme', 'design-theme'],
193 'design-transformation': ['android-support-design-transformation', 'design-transformation'],
194 'design-typography': ['android-support-design-typography', 'design-typography'],
195 'design-widget': ['android-support-design-widget', 'design-widget'],
Alan Viverettea59082b2018-02-22 10:27:46 -0500196 'design-navigation': ['android-support-design-navigation', 'design-navigation'],
197 'design-tabs': ['android-support-design-tabs', 'design-tabs'],
198 'design-bottomappbar': ['android-support-design-bottomappbar', 'design-bottomappbar'],
199 'design-shape': ['android-support-design-shape', 'design-shape'],
200
Alan Viverette95f6d362017-04-06 09:40:50 -0400201}
202
203# Always remove these files.
204blacklist_files = [
205 'annotations.zip',
206 'public.txt',
207 'R.txt',
Alan Viverette44ad4e42017-08-09 17:45:00 -0400208 'AndroidManifest.xml',
Alan Viverettef48d9b42017-08-17 14:45:46 -0400209 os.path.join('libs','noto-emoji-compat-java.jar')
Alan Viverette95f6d362017-04-06 09:40:50 -0400210]
211
Alan Viverette44ad4e42017-08-09 17:45:00 -0400212artifact_pattern = re.compile(r"^(.+?)-(\d+\.\d+\.\d+(?:-\w+\d+)?(?:-[\d.]+)*)\.(jar|aar)$")
Alan Viverette95f6d362017-04-06 09:40:50 -0400213
Alan Viverettec960cfb2017-12-04 13:09:22 -0500214
215class MavenLibraryInfo:
216 def __init__(self, key, group_id, artifact_id, version, root, repo_dir, file):
217 self.key = key
218 self.group_id = group_id
219 self.artifact_id = artifact_id
220 self.version = version
221 self.root = root
222 self.repo_dir = repo_dir
223 self.file = file
224
225
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500226def print_e(*args, **kwargs):
227 print(*args, file=sys.stderr, **kwargs)
228
Alan Viverette95f6d362017-04-06 09:40:50 -0400229
230def touch(fname, times=None):
231 with open(fname, 'a'):
232 os.utime(fname, times)
233
234
Alan Viverette45837092017-05-12 14:50:53 -0400235def path(*path_parts):
236 return reduce((lambda x, y: os.path.join(x, y)), path_parts)
237
238
Alan Viverettecd3de262017-08-14 09:51:30 -0400239def flatten(list):
240 return reduce((lambda x, y: "%s %s" % (x, y)), list)
241
242
Alan Viverette45837092017-05-12 14:50:53 -0400243def rm(path):
244 if os.path.isdir(path):
245 rmtree(path)
246 elif os.path.exists(path):
247 os.remove(path)
248
249
250def mv(src_path, dst_path):
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400251 if os.path.exists(dst_path):
Alan Viverettecd3de262017-08-14 09:51:30 -0400252 rm(dst_path)
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400253 if not os.path.exists(os.path.dirname(dst_path)):
254 os.makedirs(os.path.dirname(dst_path))
Alan Viverette45837092017-05-12 14:50:53 -0400255 os.rename(src_path, dst_path)
256
257
Dan Willemsen814152e2017-11-06 13:22:11 -0800258def detect_artifacts(repo_dirs):
Alan Viveretted4527e62017-05-11 15:03:25 -0400259 maven_lib_info = {}
260
Dan Willemsen814152e2017-11-06 13:22:11 -0800261 # Find the latest revision for each artifact, remove others
262 for repo_dir in repo_dirs:
263 for root, dirs, files in os.walk(repo_dir):
264 for file in files:
Alan Viverettec960cfb2017-12-04 13:09:22 -0500265 if file[-4:] == ".pom":
266 # Read the POM (hack hack hack).
267 group_id = ''
268 artifact_id = ''
269 version = ''
270 file = os.path.join(root, file)
271 with open(file) as pom_file:
272 for line in pom_file:
273 if line[:11] == ' <groupId>':
274 group_id = line[11:-11]
275 elif line[:14] == ' <artifactId>':
276 artifact_id = line[14:-14]
277 elif line[:11] == ' <version>':
278 version = line[11:-11]
279 if group_id == '' or artifact_id == '' or version == '':
280 print_e('Failed to find Maven artifact data in ' + file)
281 continue
Alan Viverette95f6d362017-04-06 09:40:50 -0400282
Alan Viverettec960cfb2017-12-04 13:09:22 -0500283 # Locate the artifact.
284 artifact_file = file[:-4]
285 if os.path.exists(artifact_file + '.jar'):
286 artifact_file = artifact_file + '.jar'
287 elif os.path.exists(artifact_file + '.aar'):
288 artifact_file = artifact_file + '.aar'
289 else:
290 print_e('Failed to find artifact for ' + artifact_file)
291 continue
292
293 # Make relative to root.
294 artifact_file = artifact_file[len(root) + 1:]
295
296 # Find the mapping.
297 group_artifact = group_id + ':' + artifact_id
298 if artifact_id in maven_to_make:
299 key = artifact_id
300 elif group_artifact in maven_to_make:
301 key = group_artifact
302 else:
303 print_e('Failed to find artifact mapping for ' + group_artifact)
304 continue
305
306 # Store the latest version.
307 version = LooseVersion(version)
308 if key not in maven_lib_info \
309 or version > maven_lib_info[key].version:
310 maven_lib_info[key] = MavenLibraryInfo(key, group_id, artifact_id, version,
311 root, repo_dir, artifact_file)
Alan Viverette95f6d362017-04-06 09:40:50 -0400312
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400313 return maven_lib_info
314
315
Alan Viveretted8ce7222017-12-11 17:24:43 -0500316def transform_maven_repo(repo_dirs, update_dir, extract_res=True):
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400317 cwd = os.getcwd()
318
319 # Use a temporary working directory.
320 working_dir = os.path.join(cwd, 'support_tmp')
Dan Willemsen814152e2017-11-06 13:22:11 -0800321 maven_lib_info = detect_artifacts(repo_dirs)
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400322
Alan Viverettec960cfb2017-12-04 13:09:22 -0500323 if not maven_lib_info:
324 print_e('Failed to detect artifacts')
325 return False
326
Alan Viveretted4527e62017-05-11 15:03:25 -0400327 for info in maven_lib_info.values():
Alan Viveretted8ce7222017-12-11 17:24:43 -0500328 transform_maven_lib(working_dir, info, extract_res)
Dan Willemsen814152e2017-11-06 13:22:11 -0800329
Alan Viverette4ec9a172018-02-20 16:19:31 -0500330 makefile = os.path.join(working_dir, 'Android.mk')
331 with open(makefile, 'w') as f:
Alan Viverette229a53d2018-02-06 16:25:22 -0500332 args = ["pom2mk", "-static-deps", "-sdk-version", "current"]
Dan Willemsen814152e2017-11-06 13:22:11 -0800333 args.extend(["-rewrite=^" + name + "$=" + maven_to_make[name][0] for name in maven_to_make])
334 args.extend(["."])
Alan Viverette4ec9a172018-02-20 16:19:31 -0500335 args.extend(["-extra-deps=android-support-car=prebuilt-android.car-stubs"])
Dan Willemsen814152e2017-11-06 13:22:11 -0800336 subprocess.check_call(args, stdout=f, cwd=working_dir)
Alan Viverette95f6d362017-04-06 09:40:50 -0400337
Alan Viverette4ec9a172018-02-20 16:19:31 -0500338 depsfile = os.path.join(working_dir, 'fix_dependencies.mk')
339 with open(depsfile, 'w') as f:
340 args = [script_relative("extract_deps.py"), makefile]
341 subprocess.check_call(args, stdout=f, cwd=cwd)
342
Alan Viverette95f6d362017-04-06 09:40:50 -0400343 # Replace the old directory.
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400344 output_dir = os.path.join(cwd, update_dir)
345 mv(working_dir, output_dir)
Alan Viverettec960cfb2017-12-04 13:09:22 -0500346 return True
Alan Viverette95f6d362017-04-06 09:40:50 -0400347
Alan Viveretted4527e62017-05-11 15:03:25 -0400348
Alan Viveretted8ce7222017-12-11 17:24:43 -0500349def transform_maven_lib(working_dir, artifact_info, extract_res):
Dan Willemsen814152e2017-11-06 13:22:11 -0800350 # Move library into working dir
Alan Viverettec960cfb2017-12-04 13:09:22 -0500351 new_dir = os.path.join(working_dir, os.path.relpath(artifact_info.root, artifact_info.repo_dir))
352 mv(artifact_info.root, new_dir)
Dan Willemsen814152e2017-11-06 13:22:11 -0800353
354 for dirpath, dirs, files in os.walk(new_dir):
355 for f in files:
356 if '-sources.jar' in f:
357 os.remove(os.path.join(dirpath, f))
358
Alan Viverettec960cfb2017-12-04 13:09:22 -0500359 matcher = artifact_pattern.match(artifact_info.file)
360 maven_lib_name = artifact_info.key
Alan Viveretted4527e62017-05-11 15:03:25 -0400361 maven_lib_vers = matcher.group(2)
Alan Viverettec960cfb2017-12-04 13:09:22 -0500362 maven_lib_type = artifact_info.file[-3:]
Alan Viveretted4527e62017-05-11 15:03:25 -0400363
Alan Viverettec960cfb2017-12-04 13:09:22 -0500364 make_lib_name = maven_to_make[artifact_info.key][0]
365 make_dir_name = maven_to_make[artifact_info.key][1]
Alan Viveretted4527e62017-05-11 15:03:25 -0400366
Alan Viverette129555e2018-01-30 09:57:57 -0500367 artifact_file = os.path.join(new_dir, artifact_info.file)
368
Dan Willemsen814152e2017-11-06 13:22:11 -0800369 if extract_res:
Dan Willemsen814152e2017-11-06 13:22:11 -0800370 target_dir = os.path.join(working_dir, make_dir_name)
371 if not os.path.exists(target_dir):
372 os.makedirs(target_dir)
373
374 if maven_lib_type == "aar":
Alan Viverettec960cfb2017-12-04 13:09:22 -0500375 process_aar(artifact_file, target_dir)
Alan Viveretted4527e62017-05-11 15:03:25 -0400376
Alan Viveretted8ce7222017-12-11 17:24:43 -0500377 if maven_lib_type == "aar":
Dan Willemsend677b602017-11-08 22:13:17 -0800378 with zipfile.ZipFile(artifact_file) as zip:
Alan Viveretted8ce7222017-12-11 17:24:43 -0500379 manifests_dir = os.path.join(working_dir, "manifests")
380 zip.extract("AndroidManifest.xml", os.path.join(manifests_dir, make_lib_name))
Dan Willemsend677b602017-11-08 22:13:17 -0800381
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500382 print(maven_lib_vers, ":", maven_lib_name, "->", make_lib_name)
Alan Viveretted4527e62017-05-11 15:03:25 -0400383
Alan Viverette95f6d362017-04-06 09:40:50 -0400384
Alan Viverettec960cfb2017-12-04 13:09:22 -0500385def process_aar(artifact_file, target_dir):
Alan Viverette95f6d362017-04-06 09:40:50 -0400386 # Extract AAR file to target_dir.
387 with zipfile.ZipFile(artifact_file) as zip:
388 zip.extractall(target_dir)
389
Dan Willemsen814152e2017-11-06 13:22:11 -0800390 # Remove classes.jar
Alan Viverette95f6d362017-04-06 09:40:50 -0400391 classes_jar = os.path.join(target_dir, "classes.jar")
392 if os.path.exists(classes_jar):
Dan Willemsen814152e2017-11-06 13:22:11 -0800393 os.remove(classes_jar)
Alan Viverette95f6d362017-04-06 09:40:50 -0400394
395 # Remove or preserve empty dirs.
396 for root, dirs, files in os.walk(target_dir):
397 for dir in dirs:
398 dir_path = os.path.join(root, dir)
399 if not os.listdir(dir_path):
400 os.rmdir(dir_path)
401
402 # Remove top-level cruft.
403 for file in blacklist_files:
404 file_path = os.path.join(target_dir, file)
405 if os.path.exists(file_path):
406 os.remove(file_path)
407
Alan Viverettef17c9402017-07-19 12:57:40 -0400408
Alan Viverettecd3de262017-08-14 09:51:30 -0400409def fetch_artifact(target, build_id, artifact_path):
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500410 print('Fetching %s from %s...' % (artifact_path, target))
Alan Viverettecd3de262017-08-14 09:51:30 -0400411 fetch_cmd = [FETCH_ARTIFACT, '--bid', str(build_id), '--target', target, artifact_path]
Alan Viverette45837092017-05-12 14:50:53 -0400412 try:
Alan Viverettecd3de262017-08-14 09:51:30 -0400413 subprocess.check_output(fetch_cmd, stderr=subprocess.STDOUT)
Alan Viverette45837092017-05-12 14:50:53 -0400414 except subprocess.CalledProcessError:
Jeff Gaston13e38412018-02-06 14:45:36 -0500415 print_e('FAIL: Unable to retrieve %s artifact for build ID %s' % (artifact_path, build_id))
Alan Viverettec1c32b62017-12-20 09:40:36 -0500416 print_e('Please make sure you are authenticated for build server access!')
Alan Viverette45837092017-05-12 14:50:53 -0400417 return None
418 return artifact_path
419
420
Alan Viverette129555e2018-01-30 09:57:57 -0500421def extract_artifact(artifact_path):
Alan Viverette45837092017-05-12 14:50:53 -0400422 # Unzip the repo archive into a separate directory.
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400423 repo_dir = os.path.basename(artifact_path)[:-4]
Alan Viverette45837092017-05-12 14:50:53 -0400424 with zipfile.ZipFile(artifact_path) as zipFile:
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400425 zipFile.extractall(repo_dir)
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400426 return repo_dir
427
428
Alan Viverette7e897e22018-03-09 15:24:10 -0500429def fetch_and_extract(target, build_id, file, artifact_path=None):
430 if not artifact_path:
431 artifact_path = fetch_artifact(target, build_id, file)
Alan Viverette129555e2018-01-30 09:57:57 -0500432 if not artifact_path:
433 return None
434 return extract_artifact(artifact_path)
435
436
Alan Viverette7e897e22018-03-09 15:24:10 -0500437def update_support(target, build_id, local_file):
438 if build_id:
439 repo_file = 'top-of-tree-m2repository-%s.zip' % build_id.fs_id
440 repo_dir = fetch_and_extract(target, build_id.url_id, repo_file, None)
441 else:
442 repo_dir = fetch_and_extract(target, None, None, local_file)
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400443 if not repo_dir:
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500444 print_e('Failed to extract Support Library repository')
Alan Viverettef48d9b42017-08-17 14:45:46 -0400445 return False
Alan Viverette45837092017-05-12 14:50:53 -0400446
447 # Transform the repo archive into a Makefile-compatible format.
Alan Viveretted8ce7222017-12-11 17:24:43 -0500448 return transform_maven_repo([repo_dir], support_dir)
Alan Viverettec960cfb2017-12-04 13:09:22 -0500449
Alan Viverette7e897e22018-03-09 15:24:10 -0500450
Jeff Gaston782c3e32018-02-06 14:36:17 -0500451def update_jetifier(target, build_id):
452 repo_file = 'jetifier-standalone.zip'
453 repo_dir = fetch_and_extract(target, build_id.url_id, repo_file)
454 if not repo_dir:
455 print_e('Failed to extract Jetifier')
456 return False
457
458 rm(jetifier_dir)
459 mv(repo_dir, jetifier_dir)
Jeff Gaston6afb1e42018-02-07 18:58:07 -0500460 os.chmod(os.path.join(jetifier_dir, 'jetifier-standalone', 'bin', 'jetifier-standalone'), 0o755)
Jeff Gaston782c3e32018-02-06 14:36:17 -0500461 return True
462
Alan Viverette7e897e22018-03-09 15:24:10 -0500463
Alan Viverettec960cfb2017-12-04 13:09:22 -0500464def update_toolkit(target, build_id):
Jeff Gaston13e38412018-02-06 14:45:36 -0500465 repo_dir = fetch_and_extract(target, build_id.url_id, 'top-of-tree-m2repository-%s.zip' % build_id.fs_id)
Alan Viverettec960cfb2017-12-04 13:09:22 -0500466 if not repo_dir:
467 print_e('Failed to extract App Toolkit repository')
468 return False
469
470 # Transform the repo archive into a Makefile-compatible format.
471 return transform_maven_repo([repo_dir], os.path.join(extras_dir, 'app-toolkit'))
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400472
473
474def update_constraint(target, build_id):
Jeff Gaston13e38412018-02-06 14:45:36 -0500475 layout_dir = fetch_and_extract(target, build_id.url_id,
476 'com.android.support.constraint-constraint-layout-%s.zip' % build_id.fs_id)
477 solver_dir = fetch_and_extract(target, build_id.url_id,
478 'com.android.support.constraint-constraint-layout-solver-%s.zip' % build_id.fs_id)
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400479 if not layout_dir or not solver_dir:
Alan Viverettec960cfb2017-12-04 13:09:22 -0500480 print_e('Failed to extract Constraint Layout repositories')
Alan Viverettecd3de262017-08-14 09:51:30 -0400481 return False
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400482
483 # Passing False here is an inelegant solution, but it means we can replace
484 # the top-level directory without worrying about other child directories.
Alan Viverettec960cfb2017-12-04 13:09:22 -0500485 return transform_maven_repo([layout_dir, solver_dir],
486 os.path.join(extras_dir, 'constraint-layout'), extract_res=False)
Alan Viverette45837092017-05-12 14:50:53 -0400487
488
Alan Viverette129555e2018-01-30 09:57:57 -0500489def update_design(file):
490 design_dir = extract_artifact(file)
491 if not design_dir:
492 print_e('Failed to extract Design Library repositories')
493 return False
494
495 # Don't bother extracting resources -- this should only be used with AAPT2.
496 return transform_maven_repo([design_dir],
497 os.path.join(extras_dir, 'material-design'), extract_res=False)
498
499
Alan Viverette45837092017-05-12 14:50:53 -0400500def extract_to(zip_file, paths, filename, parent_path):
Alan Viverettec1c32b62017-12-20 09:40:36 -0500501 zip_path = next(filter(lambda path: filename in path, paths))
Alan Viverette45837092017-05-12 14:50:53 -0400502 src_path = zip_file.extract(zip_path)
503 dst_path = path(parent_path, filename)
504 mv(src_path, dst_path)
505
506
Alan Viverettecd3de262017-08-14 09:51:30 -0400507def update_sdk_repo(target, build_id):
Alan Viverette45837092017-05-12 14:50:53 -0400508 platform = 'darwin' if 'mac' in target else 'linux'
Alan Viverettecd3de262017-08-14 09:51:30 -0400509 artifact_path = fetch_artifact(
Jeff Gaston13e38412018-02-06 14:45:36 -0500510 target, build_id.url_id, 'sdk-repo-%s-platforms-%s.zip' % (platform, build_id.fs_id))
Alan Viverette45837092017-05-12 14:50:53 -0400511 if not artifact_path:
Alan Viverettecd3de262017-08-14 09:51:30 -0400512 return False
Alan Viverette45837092017-05-12 14:50:53 -0400513
514 with zipfile.ZipFile(artifact_path) as zipFile:
515 paths = zipFile.namelist()
516
517 extract_to(zipFile, paths, 'android.jar', current_path)
518 extract_to(zipFile, paths, 'uiautomator.jar', current_path)
519 extract_to(zipFile, paths, 'framework.aidl', current_path)
Paul Duffind891f3c2017-12-06 11:32:56 +0000520 extract_to(zipFile, paths, 'optional/android.test.base.jar', current_path)
Paul Duffin2b1a1462017-07-14 16:21:33 +0100521 extract_to(zipFile, paths, 'optional/android.test.mock.jar', current_path)
522 extract_to(zipFile, paths, 'optional/android.test.runner.jar', current_path)
Alan Viverette45837092017-05-12 14:50:53 -0400523
524 # Unclear if this is actually necessary.
525 extract_to(zipFile, paths, 'framework.aidl', system_path)
Jiyong Parkb773d292018-01-30 23:33:19 +0900526
Colin Cross4f4b9062018-02-14 10:03:19 -0800527 artifact_path = fetch_artifact(target, build_id.fs_id, 'core.current.stubs.jar')
Jiyong Parkb773d292018-01-30 23:33:19 +0900528 if not artifact_path:
529 return False
530
531 mv(artifact_path, path(current_path, 'core.jar'))
Alan Viverettecd3de262017-08-14 09:51:30 -0400532 return True
Alan Viverette45837092017-05-12 14:50:53 -0400533
534
Alan Viverettecd3de262017-08-14 09:51:30 -0400535def update_system(target, build_id):
Jeff Gaston13e38412018-02-06 14:45:36 -0500536 artifact_path = fetch_artifact(target, build_id.url_id, 'android_system.jar')
Alan Viverette45837092017-05-12 14:50:53 -0400537 if not artifact_path:
Alan Viverettecd3de262017-08-14 09:51:30 -0400538 return False
Alan Viverette45837092017-05-12 14:50:53 -0400539
540 mv(artifact_path, path(system_path, 'android.jar'))
Paul Duffin960e1ee2017-12-21 08:50:14 +0000541
Jeff Gaston13e38412018-02-06 14:45:36 -0500542 artifact_path = fetch_artifact(target, build_id.url_id, 'android.test.mock.stubs_system.jar')
Paul Duffin960e1ee2017-12-21 08:50:14 +0000543 if not artifact_path:
544 return False
545
546 mv(artifact_path, path(system_path, 'optional/android.test.mock.jar'))
547
Alan Viverettecd3de262017-08-14 09:51:30 -0400548 return True
549
550
Alan Viverettec1c32b62017-12-20 09:40:36 -0500551def update_buildtools(target, arch, build_id):
Jeff Gaston13e38412018-02-06 14:45:36 -0500552 artifact_path = fetch_and_extract(target, build_id.url_id,
553 "sdk-repo-%s-build-tools-%s.zip" % (arch, build_id.fs_id))
Alan Viverettec1c32b62017-12-20 09:40:36 -0500554 if not artifact_path:
555 return False
556
557 top_level_dir = os.listdir(artifact_path)[0]
558 src_path = os.path.join(artifact_path, top_level_dir)
559 dst_path = path(buildtools_dir, arch)
560 mv(src_path, dst_path)
561
562 # Move all top-level files to /bin and make them executable
563 bin_path = path(dst_path, 'bin')
564 top_level_files = filter(lambda e: os.path.isfile(path(dst_path, e)), os.listdir(dst_path))
565 for file in top_level_files:
566 src_file = path(dst_path, file)
567 dst_file = path(bin_path, file)
568 mv(src_file, dst_file)
569 os.chmod(dst_file, 0o755)
570
571 # Remove renderscript
572 rm(path(dst_path, 'renderscript'))
573
574 return True
575
576
Alan Viverettecd3de262017-08-14 09:51:30 -0400577def append(text, more_text):
578 if text:
579 return "%s, %s" % (text, more_text)
580 return more_text
Alan Viverette45837092017-05-12 14:50:53 -0400581
Alan Viverette95f6d362017-04-06 09:40:50 -0400582
Jeff Gaston13e38412018-02-06 14:45:36 -0500583class buildId(object):
584 def __init__(self, url_id, fs_id):
585 # id when used in build server urls
586 self.url_id = url_id
587 # id when used in build commands
588 self.fs_id = fs_id
589
Jeff Gastonb9b09052018-02-05 14:16:05 -0500590def getBuildId(args):
Jeff Gaston13e38412018-02-06 14:45:36 -0500591 # must be in the format 12345 or P12345
Jeff Gastonb9b09052018-02-05 14:16:05 -0500592 source = args.source
Jeff Gaston13e38412018-02-06 14:45:36 -0500593 number_text = source[:]
594 presubmit = False
595 if number_text.startswith("P"):
596 presubmit = True
597 number_text = number_text[1:]
598 if not number_text.isnumeric():
Alan Viverette7e897e22018-03-09 15:24:10 -0500599 return None
Jeff Gaston13e38412018-02-06 14:45:36 -0500600 url_id = source
601 fs_id = url_id
602 if presubmit:
603 fs_id = "0"
604 args.file = False
605 return buildId(url_id, fs_id)
Jeff Gastonb9b09052018-02-05 14:16:05 -0500606
Colin Cross573e1212018-02-12 14:59:52 -0800607def getFile(args):
608 source = args.source
609 if not source.isnumeric():
610 return args.source
Alan Viverette7e897e22018-03-09 15:24:10 -0500611 return None
Colin Cross573e1212018-02-12 14:59:52 -0800612
Alan Viverette4ec9a172018-02-20 16:19:31 -0500613
614def script_relative(rel_path):
615 return os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), rel_path)
616
617
Alan Viveretted4527e62017-05-11 15:03:25 -0400618parser = argparse.ArgumentParser(
Alan Viverette45837092017-05-12 14:50:53 -0400619 description=('Update current prebuilts'))
Alan Viveretted4527e62017-05-11 15:03:25 -0400620parser.add_argument(
Alan Viverette129555e2018-01-30 09:57:57 -0500621 'source',
622 help='Build server build ID or local Maven ZIP file')
623parser.add_argument(
624 '-d', '--design', action="store_true",
625 help='If specified, updates only the Design Library')
Alan Viveretted4527e62017-05-11 15:03:25 -0400626parser.add_argument(
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400627 '-c', '--constraint', action="store_true",
628 help='If specified, updates only Constraint Layout')
629parser.add_argument(
Alan Viverette5bfe05b2017-06-06 14:21:29 -0400630 '-s', '--support', action="store_true",
631 help='If specified, updates only the Support Library')
Alan Viverette45837092017-05-12 14:50:53 -0400632parser.add_argument(
Jeff Gaston782c3e32018-02-06 14:36:17 -0500633 '-j', '--jetifier', action="store_true",
634 help='If specified, updates only Jetifier')
635parser.add_argument(
Alan Viverettec960cfb2017-12-04 13:09:22 -0500636 '-t', '--toolkit', action="store_true",
637 help='If specified, updates only the App Toolkit')
638parser.add_argument(
Alan Viverette5bfe05b2017-06-06 14:21:29 -0400639 '-p', '--platform', action="store_true",
640 help='If specified, updates only the Android Platform')
Alan Viverettec1c32b62017-12-20 09:40:36 -0500641parser.add_argument(
642 '-b', '--buildtools', action="store_true",
643 help='If specified, updates only the Build Tools')
Alan Viveretted4527e62017-05-11 15:03:25 -0400644args = parser.parse_args()
Jeff Gaston56fe2762018-02-06 14:54:37 -0500645args.file = True
Alan Viverette129555e2018-01-30 09:57:57 -0500646if not args.source:
647 parser.error("You must specify a build ID or local Maven ZIP file")
Alan Viveretted4527e62017-05-11 15:03:25 -0400648 sys.exit(1)
Alan Viverette129555e2018-01-30 09:57:57 -0500649if not (args.support or args.platform or args.constraint or args.toolkit or args.buildtools \
Jeff Gaston782c3e32018-02-06 14:36:17 -0500650 or args.design or args.jetifier):
Alan Viverettec1c32b62017-12-20 09:40:36 -0500651 parser.error("You must specify at least one target to update")
Alan Viverettecd3de262017-08-14 09:51:30 -0400652 sys.exit(1)
Alan Viverettec1c32b62017-12-20 09:40:36 -0500653if (args.support or args.constraint or args.toolkit) and which('pom2mk') is None:
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500654 parser.error("Cannot find pom2mk in path; please run lunch to set up build environment")
655 sys.exit(1)
Alan Viveretted4527e62017-05-11 15:03:25 -0400656
657try:
658 # Make sure we don't overwrite any pending changes.
659 subprocess.check_call(['git', 'diff', '--quiet', '--', '**'])
660 subprocess.check_call(['git', 'diff', '--quiet', '--cached', '--', '**'])
661except subprocess.CalledProcessError:
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500662 print_e('FAIL: There are uncommitted changes here; please revert or stash')
Alan Viveretted4527e62017-05-11 15:03:25 -0400663 sys.exit(1)
664
665try:
Alan Viverettecd3de262017-08-14 09:51:30 -0400666 components = None
667 if args.constraint:
Jeff Gastonb9b09052018-02-05 14:16:05 -0500668 if update_constraint('studio', getBuildId(args)):
Alan Viverettecd3de262017-08-14 09:51:30 -0400669 components = append(components, 'Constraint Layout')
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500670 print_e('Failed to update Constraint Layout, aborting...')
Alan Viverettecd3de262017-08-14 09:51:30 -0400671 else:
672 sys.exit(1)
673 if args.support:
Alan Viverette7e897e22018-03-09 15:24:10 -0500674 if update_support('support_library', getBuildId(args), getFile(args)):
Alan Viverettecd3de262017-08-14 09:51:30 -0400675 components = append(components, 'Support Library')
676 else:
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500677 print_e('Failed to update Support Library, aborting...')
Alan Viverettecd3de262017-08-14 09:51:30 -0400678 sys.exit(1)
Jeff Gaston782c3e32018-02-06 14:36:17 -0500679 if args.jetifier:
680 if update_jetifier('support_library', getBuildId(args)):
681 components = append(components, 'Jetifier')
682 else:
683 print_e('Failed to update Jetifier, aborting...')
684 sys.exit(1)
Alan Viverettec960cfb2017-12-04 13:09:22 -0500685 if args.toolkit:
Jeff Gastonb9b09052018-02-05 14:16:05 -0500686 if update_toolkit('support_library_app_toolkit', getBuildId(args)):
Alan Viverettec960cfb2017-12-04 13:09:22 -0500687 components = append(components, 'App Toolkit')
688 else:
689 print_e('Failed to update App Toolkit, aborting...')
690 sys.exit(1)
Alan Viverettecd3de262017-08-14 09:51:30 -0400691 if args.platform:
Jeff Gastonb9b09052018-02-05 14:16:05 -0500692 if update_sdk_repo('sdk_phone_armv7-sdk_mac', getBuildId(args)) \
693 and update_system('sdk_phone_armv7-sdk_mac', getBuildId(args)):
Alan Viverettecd3de262017-08-14 09:51:30 -0400694 components = append(components, 'platform SDK')
695 else:
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500696 print_e('Failed to update platform SDK, aborting...')
Alan Viverettecd3de262017-08-14 09:51:30 -0400697 sys.exit(1)
Alan Viverette129555e2018-01-30 09:57:57 -0500698 if args.design:
Colin Cross573e1212018-02-12 14:59:52 -0800699 if update_design(getFile(args)):
Alan Viverette129555e2018-01-30 09:57:57 -0500700 components = append(components, 'Design Library')
701 else:
702 print_e('Failed to update platform SDK, aborting...')
703 sys.exit(1)
Alan Viverettec1c32b62017-12-20 09:40:36 -0500704 if args.buildtools:
Jeff Gastonb9b09052018-02-05 14:16:05 -0500705 if update_buildtools('sdk_phone_armv7-sdk_mac', 'darwin', getBuildId(args)) \
706 and update_buildtools('sdk_phone_x86_64-sdk', 'linux', getBuildId(args)) \
707 and update_buildtools('sdk_phone_armv7-win_sdk', 'windows', getBuildId(args)):
Alan Viverettec1c32b62017-12-20 09:40:36 -0500708 components = append(components, 'build tools')
709 else:
710 print_e('Failed to update build tools, aborting...')
711 sys.exit(1)
Alan Viveretted4527e62017-05-11 15:03:25 -0400712
713 # Commit all changes.
Alan Viverette45837092017-05-12 14:50:53 -0400714 subprocess.check_call(['git', 'add', current_path])
715 subprocess.check_call(['git', 'add', system_path])
Alan Viverettec1c32b62017-12-20 09:40:36 -0500716 subprocess.check_call(['git', 'add', buildtools_dir])
Colin Cross573e1212018-02-12 14:59:52 -0800717 if not args.source.isnumeric():
Alan Viverette129555e2018-01-30 09:57:57 -0500718 src_msg = "local Maven ZIP"
719 else:
Jeff Gaston13e38412018-02-06 14:45:36 -0500720 src_msg = "build %s" % (getBuildId(args).url_id)
Alan Viverette129555e2018-01-30 09:57:57 -0500721 msg = "Import %s from %s\n\n%s" % (components, src_msg, flatten(sys.argv))
Alan Viveretted4527e62017-05-11 15:03:25 -0400722 subprocess.check_call(['git', 'commit', '-m', msg])
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500723 print('Remember to test this change before uploading it to Gerrit!')
Alan Viveretted4527e62017-05-11 15:03:25 -0400724
725finally:
726 # Revert all stray files, including the downloaded zip.
727 try:
728 with open(os.devnull, 'w') as bitbucket:
729 subprocess.check_call(['git', 'add', '-Af', '.'], stdout=bitbucket)
730 subprocess.check_call(
731 ['git', 'commit', '-m', 'COMMIT TO REVERT - RESET ME!!!'], stdout=bitbucket)
732 subprocess.check_call(['git', 'reset', '--hard', 'HEAD~1'], stdout=bitbucket)
733 except subprocess.CalledProcessError:
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500734 print_e('ERROR: Failed cleaning up, manual cleanup required!!!')