blob: b783d4ac3279113514734f7a8076e57b1d467e62 [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'
Anton Hansson9709fd42018-04-03 16:52:13 +010015api_path = 'api'
16system_api_path = 'system-api'
Anton Hansson1d01a032018-04-09 10:29:37 +010017framework_sdk_target = 'sdk_phone_armv7-sdk_mac'
Alan Viverette3e57a4a2017-08-11 15:49:47 -040018support_dir = os.path.join(current_path, 'support')
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -040019androidx_dir = os.path.join(current_path, 'androidx')
Alan Viverette3e57a4a2017-08-11 15:49:47 -040020extras_dir = os.path.join(current_path, 'extras')
Alan Viverettec1c32b62017-12-20 09:40:36 -050021buildtools_dir = 'tools'
Jeff Gaston553a4372018-03-29 18:34:22 -040022jetifier_dir = os.path.join(buildtools_dir, 'jetifier', 'jetifier-standalone')
Alan Viverette95f6d362017-04-06 09:40:50 -040023
Jeff Gastona68a8d42018-03-23 14:00:13 -040024temp_dir = os.path.join(os.getcwd(), "support_tmp")
25os.chdir(os.path.dirname(os.path.dirname(os.path.realpath(sys.argv[0]))))
26git_dir = os.getcwd()
27
Jeff Gastonf12f3ce2018-03-23 16:41:24 -040028rerun_extract_deps = False
29
Alan Viverettecd3de262017-08-14 09:51:30 -040030# See go/fetch_artifact for details on this script.
Alan Viveretted4527e62017-05-11 15:03:25 -040031FETCH_ARTIFACT = '/google/data/ro/projects/android/fetch_artifact'
32
Alan Viverette95f6d362017-04-06 09:40:50 -040033maven_to_make = {
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -040034 # Support Library
35 'com.android.support:animated-vector-drawable': ['android-support-animatedvectordrawable', 'graphics/drawable'],
36 'com.android.support:appcompat-v7': ['android-support-v7-appcompat', 'v7/appcompat'],
37 'com.android.support:cardview-v7': ['android-support-v7-cardview', 'v7/cardview'],
38 'com.android.support:collections': ['android-support-collections', 'collections', 'jar'],
39 'com.android.support:customtabs': ['android-support-customtabs', 'customtabs'],
40 'com.android.support:exifinterface': ['android-support-exifinterface', 'exifinterface'],
41 'com.android.support:gridlayout-v7': ['android-support-v7-gridlayout', 'v7/gridlayout'],
42 'com.android.support:leanback-v17': ['android-support-v17-leanback', 'v17/leanback'],
43 'com.android.support:mediarouter-v7': ['android-support-v7-mediarouter', 'v7/mediarouter'],
44 'com.android.support:palette-v7': ['android-support-v7-palette', 'v7/palette'],
45 'com.android.support:percent': ['android-support-percent', 'percent'],
46 'com.android.support:preference-leanback-v17': ['android-support-v17-preference-leanback', 'v17/preference-leanback'],
47 'com.android.support:preference-v14': ['android-support-v14-preference', 'v14/preference'],
48 'com.android.support:preference-v7': ['android-support-v7-preference', 'v7/preference'],
49 'com.android.support:recommendation': ['android-support-recommendation', 'recommendation'],
50 'com.android.support:recyclerview-v7': ['android-support-v7-recyclerview', 'v7/recyclerview'],
51 'com.android.support:support-annotations': ['android-support-annotations', 'annotations', 'jar'],
52 'com.android.support:support-compat': ['android-support-compat', 'compat'],
53 'com.android.support:support-core-ui': ['android-support-core-ui', 'core-ui'],
54 'com.android.support:support-core-utils': ['android-support-core-utils', 'core-utils'],
55 'com.android.support:support-dynamic-animation': ['android-support-dynamic-animation', 'dynamic-animation'],
56 'com.android.support:support-emoji-appcompat': ['android-support-emoji-appcompat', 'emoji-appcompat'],
57 'com.android.support:support-emoji-bundled': ['android-support-emoji-bundled', 'emoji-bundled'],
58 'com.android.support:support-emoji': ['android-support-emoji', 'emoji'],
59 'com.android.support:support-fragment': ['android-support-fragment', 'fragment'],
60 'com.android.support:support-media-compat': ['android-support-media-compat', 'media-compat'],
61 'com.android.support:support-tv-provider': ['android-support-tv-provider', 'tv-provider'],
62 'com.android.support:support-v13': ['android-support-v13', 'v13'],
63 'com.android.support:support-v4': ['android-support-v4', 'v4'],
64 'com.android.support:support-vector-drawable': ['android-support-vectordrawable', 'graphics/drawable'],
65 'com.android.support:transition': ['android-support-transition', 'transition'],
66 'com.android.support:wear': ['android-support-wear', 'wear'],
Alan Viverette7bb86da2018-02-21 18:29:02 -050067
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -040068 # Support Library (28.0.0 splits + new modules)
69 'com.android.support:heifwriter': ['android-support-heifwriter', 'heifwriter'],
70 'com.android.support:webkit': ['android-support-webkit', 'webkit'],
71 'com.android.support:customview': ['android-support-customview', 'customview'],
72 'com.android.support:textclassifier': ['android-support-textclassifier', 'textclassifier'],
73 'com.android.support:swiperefreshlayout': ['android-support-swiperefreshlayout', 'swiperefreshlayout'],
74 'com.android.support:viewpager': ['android-support-viewpager', 'viewpager'],
75 'com.android.support:coordinatorlayout': ['android-support-coordinatorlayout', 'coordinatorlayout'],
76 'com.android.support:asynclayoutinflater': ['android-support-asynclayoutinflater', 'asynclayoutinflater'],
77 'com.android.support:support-content': ['android-support-support-content', 'support-content'],
78 'com.android.support:documentfile': ['android-support-documentfile', 'documentfile'],
79 'com.android.support:drawerlayout': ['android-support-drawerlayout', 'drawerlayout'],
80 'com.android.support:localbroadcastmanager': ['android-support-localbroadcastmanager', 'localbroadcastmanager'],
81 'com.android.support:print': ['android-support-print', 'print'],
82 'com.android.support:slidingpanelayout': ['android-support-slidingpanelayout', 'slidingpanelayout'],
83 'com.android.support:interpolator': ['android-support-interpolator', 'interpolator'],
84 'com.android.support:cursoradapter': ['android-support-cursoradapter', 'cursoradapter'],
85 'com.android.support:loader': ['android-support-loader', 'loader'],
86 'com.android.support:contentpaging': ['android-support-contentpaging', 'contentpaging'],
87 'com.android.support:recyclerview-selection': ['android-support-recyclerview-selection', 'recyclerview-selection'],
88 'com.android.support:car': ['android-support-car', 'car'],
89 'com.android.support:slices-core': ['android-slices-core', 'slices-core'],
90 'com.android.support:slices-view': ['android-slices-view', 'slices-view'],
91 'com.android.support:slices-builders': ['android-slices-builders', 'slices-builders'],
Alan Viverette19ecd502018-01-05 13:52:16 -050092
93 # Multidex
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -040094 'com.android.support:multidex': ['android-support-multidex', 'multidex/library'],
95 'com.android.support:multidex-instrumentation': ['android-support-multidex-instrumentation', 'multidex/instrumentation'],
Alan Viverette19ecd502018-01-05 13:52:16 -050096
97 # Constraint Layout
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -040098 'com.android.support.constraint:constraint-layout': ['android-support-constraint-layout', 'constraint-layout'],
99 'com.android.support.constraint:constraint-layout-solver': ['android-support-constraint-layout-solver', 'constraint-layout-solver'],
Alan Viverette19ecd502018-01-05 13:52:16 -0500100
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400101 # Architecture Components
Alan Viverette19ecd502018-01-05 13:52:16 -0500102 'android.arch.core:runtime': ['android-arch-core-runtime', 'arch-core/runtime'],
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400103 'android.arch.core:common': ['android-arch-core-common', 'arch-core/common'],
104 'android.arch.lifecycle:common': ['android-arch-lifecycle-common', 'arch-lifecycle/common'],
105 'android.arch.lifecycle:common-java8': ['android-arch-lifecycle-common-java8', 'arch-lifecycle/common-java8'],
106 'android.arch.lifecycle:extensions': ['android-arch-lifecycle-extensions', 'arch-lifecycle/extensions'],
107 'android.arch.lifecycle:livedata': ['android-arch-lifecycle-livedata', 'arch-lifecycle/livedata'],
108 'android.arch.lifecycle:livedata-core': ['android-arch-lifecycle-livedata-core', 'arch-lifecycle/livedata-core'],
109 'android.arch.lifecycle:runtime': ['android-arch-lifecycle-runtime', 'arch-lifecycle/runtime'],
110 'android.arch.lifecycle:viewmodel': ['android-arch-lifecycle-viewmodel', 'arch-lifecycle/viewmodel'],
111 'android.arch.paging:common': ['android-arch-paging-common', 'arch-paging/common'],
Alan Viverette19ecd502018-01-05 13:52:16 -0500112 'android.arch.paging:runtime': ['android-arch-paging-runtime', 'arch-paging/runtime'],
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400113 'android.arch.persistence:db': ['android-arch-persistence-db', 'arch-persistence/db'],
114 'android.arch.persistence:db-framework': ['android-arch-persistence-db-framework', 'arch-persistence/db-framework'],
115 'android.arch.persistence.room:common': ['android-arch-room-common', 'arch-room/common'],
116 'android.arch.persistence.room:migration': ['android-arch-room-migration', 'arch-room/migration'],
117 'android.arch.persistence.room:runtime': ['android-arch-room-runtime', 'arch-room/runtime'],
118 'android.arch.persistence.room:testing': ['android-arch-room-testing', 'arch-room/testing'],
119
120 # AndroidX
121 'androidx.slice:slice-builders': ['androidx.slice_slice-builders', 'androidx/slice/slice-builders'],
122 'androidx.slice:slice-core': ['androidx.slice_slice-core', 'androidx/slice/slice-core'],
123 'androidx.slice:slice-view': ['androidx.slice_slice-view', 'androidx/slice/slice-view'],
124 'androidx.vectordrawable:vectordrawable-animated': ['androidx.vectordrawable_vectordrawable-animated', 'androidx/vectordrawable/vectordrawable-animated'],
125 'androidx.annotation:annotation': ['androidx.annotation_annotation', 'androidx/annotation/annotation', 'jar'],
126 'androidx.asynclayoutinflater:asynclayoutinflater': ['androidx.asynclayoutinflater_asynclayoutinflater', 'androidx/asynclayoutinflater/asynclayoutinflater'],
127 'androidx.car:car': ['androidx.car_car', 'androidx/car/car'],
128 'androidx.collection:collection': ['androidx.collection_collection', 'androidx/collection/collection', 'jar'],
129 'androidx.core:core': ['androidx.core_core', 'androidx/core/core'],
130 'androidx.contentpaging:contentpaging': ['androidx.contentpaging_contentpaging', 'androidx/contentpaging/contentpaging'],
131 'androidx.coordinatorlayout:coordinatorlayout': ['androidx.coordinatorlayout_coordinatorlayout', 'androidx/coordinatorlayout/coordinatorlayout'],
132 'androidx.legacy:legacy-support-core-ui': ['androidx.legacy_legacy-support-core-ui', 'androidx/legacy/legacy-support-core-ui'],
133 'androidx.legacy:legacy-support-core-utils': ['androidx.legacy_legacy-support-core-utils', 'androidx/legacy/legacy-support-core-utils'],
134 'androidx.cursoradapter:cursoradapter': ['androidx.cursoradapter_cursoradapter', 'androidx/cursoradapter/cursoradapter'],
135 'androidx.browser:browser': ['androidx.browser_browser', 'androidx/browser/browser'],
136 'androidx.customview:customview': ['androidx.customview_customview', 'androidx/customview/customview'],
137 'androidx.documentfile:documentfile': ['androidx.documentfile_documentfile', 'androidx/documentfile/documentfile'],
138 'androidx.drawerlayout:drawerlayout': ['androidx.drawerlayout_drawerlayout', 'androidx/drawerlayout/drawerlayout'],
139 'androidx.dynamicanimation:dynamicanimation': ['androidx.dynamicanimation_dynamicanimation', 'androidx/dynamicanimation/dynamicanimation'],
140 'androidx.emoji:emoji': ['androidx.emoji_emoji', 'androidx/emoji/emoji'],
141 'androidx.emoji:emoji-appcompat': ['androidx.emoji_emoji-appcompat', 'androidx/emoji/emoji-appcompat'],
142 'androidx.emoji:emoji-bundled': ['androidx.emoji_emoji-bundled', 'androidx/emoji/emoji-bundled'],
143 'androidx.exifinterface:exifinterface': ['androidx.exifinterface_exifinterface', 'androidx/exifinterface/exifinterface'],
144 'androidx.fragment:fragment': ['androidx.fragment_fragment', 'androidx/fragment/fragment'],
145 'androidx.heifwriter:heifwriter': ['androidx.heifwriter_heifwriter', 'androidx/heifwriter/heifwriter'],
146 'androidx.interpolator:interpolator': ['androidx.interpolator_interpolator', 'androidx/interpolator/interpolator'],
147 'androidx.loader:loader': ['androidx.loader_loader', 'androidx/loader/loader'],
148 'androidx.localbroadcastmanager:localbroadcastmanager': ['androidx.localbroadcastmanager_localbroadcastmanager', 'androidx/localbroadcastmanager/localbroadcastmanager'],
149 'androidx.media:media': ['androidx.media_media', 'androidx/media/media'],
150 'androidx.percentlayout:percentlayout': ['androidx.percentlayout_percentlayout', 'androidx/percentlayout/percentlayout'],
151 'androidx.print:print': ['androidx.print_print', 'androidx/print/print'],
152 'androidx.recommendation:recommendation': ['androidx.recommendation_recommendation', 'androidx/recommendation/recommendation'],
153 'androidx.recyclerview:recyclerview-selection': ['androidx.recyclerview_recyclerview-selection', 'androidx/recyclerview/recyclerview-selection'],
154 'androidx.slidingpanelayout:slidingpanelayout': ['androidx.slidingpanelayout_slidingpanelayout', 'androidx/slidingpanelayout/slidingpanelayout'],
155 'androidx.swiperefreshlayout:swiperefreshlayout': ['androidx.swiperefreshlayout_swiperefreshlayout', 'androidx/swiperefreshlayout/swiperefreshlayout'],
156 'androidx.textclassifier:textclassifier': ['androidx.textclassifier_textclassifier', 'androidx/textclassifier/textclassifier'],
157 'androidx.transition:transition': ['androidx.transition_transition', 'androidx/transition/transition'],
158 'androidx.tvprovider:tvprovider': ['androidx.tvprovider_tvprovider', 'androidx/tvprovider/tvprovider'],
159 'androidx.legacy:legacy-support-v13': ['androidx.legacy_legacy-support-v13', 'androidx/legacy/legacy-support-v13'],
160 'androidx.legacy:legacy-preference-v14': ['androidx.legacy_legacy-preference-v14', 'androidx/legacy/legacy-preference-v14'],
161 'androidx.leanback:leanback': ['androidx.leanback_leanback', 'androidx/leanback/leanback'],
162 'androidx.leanback:leanback-preference': ['androidx.leanback_leanback-preference', 'androidx/leanback/leanback-preference'],
163 'androidx.legacy:legacy-support-v4': ['androidx.legacy_legacy-support-v4', 'androidx/legacy/legacy-support-v4'],
164 'androidx.appcompat:appcompat': ['androidx.appcompat_appcompat', 'androidx/appcompat/appcompat'],
165 'androidx.cardview:cardview': ['androidx.cardview_cardview', 'androidx/cardview/cardview'],
166 'androidx.gridlayout:gridlayout': ['androidx.gridlayout_gridlayout', 'androidx/gridlayout/gridlayout'],
167 'androidx.mediarouter:mediarouter': ['androidx.mediarouter_mediarouter', 'androidx/mediarouter/mediarouter'],
168 'androidx.palette:palette': ['androidx.palette_palette', 'androidx/palette/palette'],
169 'androidx.preference:preference': ['androidx.preference_preference', 'androidx/preference/preference'],
170 'androidx.recyclerview:recyclerview': ['androidx.recyclerview_recyclerview', 'androidx/recyclerview/recyclerview'],
171 'androidx.vectordrawable:vectordrawable': ['androidx.vectordrawable_vectordrawable', 'androidx/vectordrawable/vectordrawable'],
172 'androidx.viewpager:viewpager': ['androidx.viewpager_viewpager', 'androidx/viewpager/viewpager'],
173 'androidx.wear:wear': ['androidx.wear_wear', 'androidx/wear/wear'],
174 'androidx.webkit:webkit': ['androidx.webkit_webkit', 'androidx/webkit/webkit'],
175
176 # AndroidX for Multidex
177 'androidx.multidex:multidex': ['androidx-multidex_multidex', 'androidx/multidex/multidex'],
178 'androidx.multidex:multidex-instrumentation': ['androidx-multidex_multidex-instrumentation', 'androidx/multidex/multidex-instrumentation'],
179
180 # AndroidX for Constraint Layout
181 'androidx.constraintlayout:constraintlayout': ['androidx-constraintlayout_constraintlayout', 'androidx/constraintlayout/constraintlayout'],
182 'androidx.constraintlayout:constraintlayout-solver': ['androidx-constraintlayout_constraintlayout-solver', 'androidx/constraintlayout/constraintlayout-solver'],
183
184 # AndroidX for Architecture Components
185 'androidx.arch.core:core-common': ['androidx.arch.core_core-common', 'androidx/arch/core/core-common'],
186 'androidx.arch.core:core-runtime': ['androidx.arch.core_core-runtime', 'androidx/arch/core/core-runtime'],
187 'androidx.lifecycle:lifecycle-common': ['androidx.lifecycle_lifecycle-common', 'androidx/lifecycle/lifecycle-common'],
188 'androidx.lifecycle:lifecycle-common-java8': ['androidx.lifecycle_lifecycle-common-java8', 'androidx/lifecycle/lifecycle-common-java8'],
189 'androidx.lifecycle:lifecycle-extensions': ['androidx.lifecycle_lifecycle-extensions', 'androidx/lifecycle/lifecycle-extensions'],
190 'androidx.lifecycle:lifecycle-livedata': ['androidx.lifecycle_lifecycle-livedata', 'androidx/lifecycle/lifecycle-livedata'],
191 'androidx.lifecycle:lifecycle-livedata-core': ['androidx.lifecycle_lifecycle-livedata-core', 'androidx/lifecycle/lifecycle-livedata-core'],
192 'androidx.lifecycle:lifecycle-runtime': ['androidx.lifecycle_lifecycle-runtime', 'androidx/lifecycle/lifecycle-runtime'],
193 'androidx.lifecycle:lifecycle-viewmodel': ['androidx.lifecycle_lifecycle-viewmodel', 'androidx/lifecycle/lifecycle-viewmodel'],
194 'androidx.paging:paging-common': ['androidx.paging_paging-common', 'androidx/paging/paging-common'],
195 'androidx.paging:paging-runtime': ['androidx.paging_paging-runtime', 'androidx/paging/paging-runtime'],
196 'androidx.sqlite:sqlite': ['androidx.sqlite_sqlite', 'androidx/sqlite/sqlite'],
197 'androidx.sqlite:sqlite-framework': ['androidx.sqlite_sqlite-framework', 'androidx/sqlite/sqlite-framework'],
198 'androidx.room:room-common': ['androidx.room_room-common', 'androidx/room/room-common'],
199 'androidx.room:room-migration': ['androidx.room_room-migration', 'androidx/room/room-migration'],
200 'androidx.room:room-runtime': ['androidx.room_room-runtime', 'androidx/room/room-runtime'],
201 'androidx.room:room-testing': ['androidx.room_room-testing', 'androidx/room/room-testing'],
Allenab72f012018-01-29 18:10:23 -0800202
Alan Viverette19ecd502018-01-05 13:52:16 -0500203 # Lifecycle
Alan Viverettec7e88f12018-02-13 15:29:50 -0500204 # Missing dependencies:
205 # - auto-common
206 # - javapoet
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400207 #'android.arch.lifecycle:compiler': ['android-arch-lifecycle-compiler', 'arch-lifecycle/compiler'],
Alan Viverettec7e88f12018-02-13 15:29:50 -0500208 # Missing dependencies:
209 # - reactive-streams
210 #'android.arch.lifecycle:reactivestreams': ['android-arch-lifecycle-reactivestreams','arch-lifecycle/reactivestreams'],
Allenab72f012018-01-29 18:10:23 -0800211
Alan Viverette19ecd502018-01-05 13:52:16 -0500212 # Room
Alan Viverettec7e88f12018-02-13 15:29:50 -0500213 # Missing dependencies:
214 # - auto-common
215 # - javapoet
216 # - antlr4
217 # - kotlin-metadata
218 # - commons-codec
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400219 #'android.arch.persistence.room:compiler': ['android-arch-room-compiler', 'arch-room/compiler'],
Alan Viverettec7e88f12018-02-13 15:29:50 -0500220 # Missing dependencies:
221 # - rxjava
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400222 #'android.arch.persistence.room:rxjava2': ['android-arch-room-rxjava2', 'arch-room/rxjava2'],
Allenab72f012018-01-29 18:10:23 -0800223
Jeff Gaston6e7e7502018-04-04 00:22:45 -0400224 # Third-party dependencies
225 'com.google.android:flexbox': ['flexbox', 'flexbox'],
226
227 # Support Library Material Design Components
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400228 'com.android.support:design': ['android-support-design', 'design'],
229 'com.android.support:design-animation': ['android-support-design-animation', 'design-animation'],
230 'com.android.support:design-bottomnavigation': ['android-support-design-bottomnavigation', 'design-bottomnavigation'],
231 'com.android.support:design-bottomsheet': ['android-support-design-bottomsheet', 'design-bottomsheet'],
232 'com.android.support:design-button': ['android-support-design-button', 'design-button'],
233 'com.android.support:design-canvas': ['android-support-design-canvas', 'design-canvas'],
234 'com.android.support:design-card': ['android-support-design-card', 'design-card'],
235 'com.android.support:design-chip': ['android-support-design-chip', 'design-chip'],
236 'com.android.support:design-circularreveal': ['android-support-design-circularreveal', 'design-circularreveal'],
237 'com.android.support:design-circularreveal-cardview': ['android-support-design-circularreveal-cardview', 'design-circularreveal-cardview'],
238 'com.android.support:design-circularreveal-coordinatorlayout': ['android-support-design-circularreveal-coordinatorlayout', 'design-circularreveal-coordinatorlayout'],
239 'com.android.support:design-color': ['android-support-design-color', 'design-color'],
240 'com.android.support:design-dialog': ['android-support-design-dialog', 'design-dialog'],
241 'com.android.support:design-drawable': ['android-support-design-drawable', 'design-drawable'],
242 'com.android.support:design-expandable': ['android-support-design-expandable', 'design-expandable'],
243 'com.android.support:design-floatingactionbutton': ['android-support-design-floatingactionbutton', 'design-floatingactionbutton'],
244 'com.android.support:design-internal': ['android-support-design-internal', 'design-internal'],
245 'com.android.support:design-math': ['android-support-design-math', 'design-math'],
246 'com.android.support:design-resources': ['android-support-design-resources', 'design-resources'],
247 'com.android.support:design-ripple': ['android-support-design-ripple', 'design-ripple'],
248 'com.android.support:design-snackbar': ['android-support-design-snackbar', 'design-snackbar'],
249 'com.android.support:design-stateful': ['android-support-design-stateful', 'design-stateful'],
250 'com.android.support:design-textfield': ['android-support-design-textfield', 'design-textfield'],
251 'com.android.support:design-theme': ['android-support-design-theme', 'design-theme'],
252 'com.android.support:design-transformation': ['android-support-design-transformation', 'design-transformation'],
253 'com.android.support:design-typography': ['android-support-design-typography', 'design-typography'],
254 'com.android.support:design-widget': ['android-support-design-widget', 'design-widget'],
255 'com.android.support:design-navigation': ['android-support-design-navigation', 'design-navigation'],
256 'com.android.support:design-tabs': ['android-support-design-tabs', 'design-tabs'],
257 'com.android.support:design-bottomappbar': ['android-support-design-bottomappbar', 'design-bottomappbar'],
258 'com.android.support:design-shape': ['android-support-design-shape', 'design-shape'],
Alan Viverettea59082b2018-02-22 10:27:46 -0500259
Jeff Gastonfa7c7e82018-04-06 13:35:48 -0400260 # Androidx Material Design Components
261 'com.google.android.material:material': ['androidx.material_material', 'com/google/android/material/material'],
262
Jeff Gaston6e7e7502018-04-04 00:22:45 -0400263 # Intermediate-AndroidX Material Design Components
264 'com.android.temp.support:design': ['androidx.design_design', 'com/android/temp/support/design/design'],
265 'com.android.temp.support:design-animation': ['androidx.design_design-animation', 'com/android/temp/support/design/design-animation'],
266 'com.android.temp.support:design-bottomnavigation': ['androidx.design_design-bottomnavigation', 'com/android/temp/support/design/design-bottomnavigation'],
267 'com.android.temp.support:design-bottomsheet': ['androidx.design_design-bottomsheet', 'com/android/temp/support/design/design-bottomsheet'],
268 'com.android.temp.support:design-button': ['androidx.design_design-button', 'com/android/temp/support/design/design-button'],
269 'com.android.temp.support:design-canvas': ['androidx.design_design-canvas', 'com/android/temp/support/design/design-canvas'],
270 'com.android.temp.support:design-card': ['androidx.design_design-card', 'com/android/temp/support/design/design-card'],
271 'com.android.temp.support:design-chip': ['androidx.design_design-chip', 'com/android/temp/support/design/design-chip'],
272 'com.android.temp.support:design-circularreveal': ['androidx.design_design-circularreveal', 'com/android/temp/support/design/design-circularreveal'],
273 'com.android.temp.support:design-circularreveal-cardview': ['androidx.design_design-circularreveal-cardview', 'com/android/temp/support/design/design-circularreveal-cardview'],
274 'com.android.temp.support:design-circularreveal-coordinatorlayout': ['androidx.design_design-circularreveal-coordinatorlayout', 'com/android/temp/support/design/design-circularreveal-coordinatorlayout'],
275 'com.android.temp.support:design-color': ['androidx.design_design-color', 'com/android/temp/support/design/design-color'],
276 'com.android.temp.support:design-dialog': ['androidx.design_design-dialog', 'com/android/temp/support/design/design-dialog'],
277 'com.android.temp.support:design-drawable': ['androidx.design_design-drawable', 'com/android/temp/support/design/design-drawable'],
278 'com.android.temp.support:design-expandable': ['androidx.design_design-expandable', 'com/android/temp/support/design/design-expandable'],
279 'com.android.temp.support:design-floatingactionbutton': ['androidx.design_design-floatingactionbutton', 'com/android/temp/support/design/design-floatingactionbutton'],
280 'com.android.temp.support:design-internal': ['androidx.design_design-internal', 'com/android/temp/support/design/design-internal'],
281 'com.android.temp.support:design-math': ['androidx.design_design-math', 'com/android/temp/support/design/design-math'],
282 'com.android.temp.support:design-resources': ['androidx.design_design-resources', 'com/android/temp/support/design/design-resources'],
283 'com.android.temp.support:design-ripple': ['androidx.design_design-ripple', 'com/android/temp/support/design/design-ripple'],
284 'com.android.temp.support:design-snackbar': ['androidx.design_design-snackbar', 'com/android/temp/support/design/design-snackbar'],
285 'com.android.temp.support:design-stateful': ['androidx.design_design-stateful', 'com/android/temp/support/design/design-stateful'],
286 'com.android.temp.support:design-textfield': ['androidx.design_design-textfield', 'com/android/temp/support/design/design-textfield'],
287 'com.android.temp.support:design-theme': ['androidx.design_design-theme', 'com/android/temp/support/design/design-theme'],
288 'com.android.temp.support:design-transformation': ['androidx.design_design-transformation', 'com/android/temp/support/design/design-transformation'],
289 'com.android.temp.support:design-typography': ['androidx.design_design-typography', 'com/android/temp/support/design/design-typography'],
290 'com.android.temp.support:design-widget': ['androidx.design_design-widget', 'com/android/temp/support/design/design-widget'],
291 'com.android.temp.support:design-navigation': ['androidx.design_design-navigation', 'com/android/temp/support/design/design-navigation'],
292 'com.android.temp.support:design-tabs': ['androidx.design_design-tabs', 'com/android/temp/support/design/design-tabs'],
293 'com.android.temp.support:design-bottomappbar': ['androidx.design_design-bottomappbar', 'com/android/temp/support/design/design-bottomappbar'],
294 'com.android.temp.support:design-shape': ['androidx.design_design-shape', 'com/android/temp/support/design/design-shape'],
295
Alan Viverette95f6d362017-04-06 09:40:50 -0400296}
297
298# Always remove these files.
299blacklist_files = [
300 'annotations.zip',
301 'public.txt',
302 'R.txt',
Alan Viverette44ad4e42017-08-09 17:45:00 -0400303 'AndroidManifest.xml',
Alan Viverettef48d9b42017-08-17 14:45:46 -0400304 os.path.join('libs','noto-emoji-compat-java.jar')
Alan Viverette95f6d362017-04-06 09:40:50 -0400305]
306
Alan Viverette44ad4e42017-08-09 17:45:00 -0400307artifact_pattern = re.compile(r"^(.+?)-(\d+\.\d+\.\d+(?:-\w+\d+)?(?:-[\d.]+)*)\.(jar|aar)$")
Alan Viverette95f6d362017-04-06 09:40:50 -0400308
Alan Viverettec960cfb2017-12-04 13:09:22 -0500309
310class MavenLibraryInfo:
Jeff Gastonc302bb92018-03-23 13:53:48 -0400311 def __init__(self, key, group_id, artifact_id, version, dir, repo_dir, file):
Alan Viverettec960cfb2017-12-04 13:09:22 -0500312 self.key = key
313 self.group_id = group_id
314 self.artifact_id = artifact_id
315 self.version = version
Jeff Gastonc302bb92018-03-23 13:53:48 -0400316 self.dir = dir
Alan Viverettec960cfb2017-12-04 13:09:22 -0500317 self.repo_dir = repo_dir
318 self.file = file
319
320
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500321def print_e(*args, **kwargs):
322 print(*args, file=sys.stderr, **kwargs)
323
Alan Viverette95f6d362017-04-06 09:40:50 -0400324
325def touch(fname, times=None):
326 with open(fname, 'a'):
327 os.utime(fname, times)
328
329
Alan Viverette45837092017-05-12 14:50:53 -0400330def path(*path_parts):
331 return reduce((lambda x, y: os.path.join(x, y)), path_parts)
332
333
Alan Viverettecd3de262017-08-14 09:51:30 -0400334def flatten(list):
335 return reduce((lambda x, y: "%s %s" % (x, y)), list)
336
337
Alan Viverette45837092017-05-12 14:50:53 -0400338def rm(path):
339 if os.path.isdir(path):
340 rmtree(path)
341 elif os.path.exists(path):
342 os.remove(path)
343
344
345def mv(src_path, dst_path):
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400346 if os.path.exists(dst_path):
Alan Viverettecd3de262017-08-14 09:51:30 -0400347 rm(dst_path)
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400348 if not os.path.exists(os.path.dirname(dst_path)):
349 os.makedirs(os.path.dirname(dst_path))
Alan Viverette45837092017-05-12 14:50:53 -0400350 os.rename(src_path, dst_path)
351
352
Jeff Gastonc302bb92018-03-23 13:53:48 -0400353def detect_artifacts(maven_repo_dirs):
Alan Viveretted4527e62017-05-11 15:03:25 -0400354 maven_lib_info = {}
355
Dan Willemsen814152e2017-11-06 13:22:11 -0800356 # Find the latest revision for each artifact, remove others
Jeff Gastonc302bb92018-03-23 13:53:48 -0400357 for repo_dir in maven_repo_dirs:
Dan Willemsen814152e2017-11-06 13:22:11 -0800358 for root, dirs, files in os.walk(repo_dir):
359 for file in files:
Alan Viverettec960cfb2017-12-04 13:09:22 -0500360 if file[-4:] == ".pom":
361 # Read the POM (hack hack hack).
362 group_id = ''
363 artifact_id = ''
364 version = ''
365 file = os.path.join(root, file)
366 with open(file) as pom_file:
367 for line in pom_file:
368 if line[:11] == ' <groupId>':
369 group_id = line[11:-11]
370 elif line[:14] == ' <artifactId>':
371 artifact_id = line[14:-14]
372 elif line[:11] == ' <version>':
373 version = line[11:-11]
374 if group_id == '' or artifact_id == '' or version == '':
375 print_e('Failed to find Maven artifact data in ' + file)
376 continue
Alan Viverette95f6d362017-04-06 09:40:50 -0400377
Alan Viverettec960cfb2017-12-04 13:09:22 -0500378 # Locate the artifact.
379 artifact_file = file[:-4]
380 if os.path.exists(artifact_file + '.jar'):
381 artifact_file = artifact_file + '.jar'
382 elif os.path.exists(artifact_file + '.aar'):
383 artifact_file = artifact_file + '.aar'
384 else:
385 print_e('Failed to find artifact for ' + artifact_file)
386 continue
387
388 # Make relative to root.
389 artifact_file = artifact_file[len(root) + 1:]
390
391 # Find the mapping.
392 group_artifact = group_id + ':' + artifact_id
Jeff Gaston3e622ba2018-03-26 23:24:46 -0400393 if group_artifact in maven_to_make:
Alan Viverettec960cfb2017-12-04 13:09:22 -0500394 key = group_artifact
Jeff Gaston3e622ba2018-03-26 23:24:46 -0400395 elif artifact_id in maven_to_make:
396 key = artifact_id
Alan Viverettec960cfb2017-12-04 13:09:22 -0500397 else:
398 print_e('Failed to find artifact mapping for ' + group_artifact)
399 continue
400
401 # Store the latest version.
402 version = LooseVersion(version)
403 if key not in maven_lib_info \
404 or version > maven_lib_info[key].version:
405 maven_lib_info[key] = MavenLibraryInfo(key, group_id, artifact_id, version,
406 root, repo_dir, artifact_file)
Alan Viverette95f6d362017-04-06 09:40:50 -0400407
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400408 return maven_lib_info
409
410
Jeff Gaston1cc06092018-03-28 15:51:02 -0400411def transform_maven_repos(maven_repo_dirs, transformed_dir, extract_res=True, include_static_deps=False):
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400412 cwd = os.getcwd()
413
414 # Use a temporary working directory.
Jeff Gastonc302bb92018-03-23 13:53:48 -0400415 maven_lib_info = detect_artifacts(maven_repo_dirs)
Jeff Gastona68a8d42018-03-23 14:00:13 -0400416 working_dir = temp_dir
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400417
Alan Viverettec960cfb2017-12-04 13:09:22 -0500418 if not maven_lib_info:
419 print_e('Failed to detect artifacts')
420 return False
421
Jeff Gastonc302bb92018-03-23 13:53:48 -0400422 # extract some files (for example, AndroidManifest.xml) from any relevant artifacts
Alan Viveretted4527e62017-05-11 15:03:25 -0400423 for info in maven_lib_info.values():
Alan Viveretted8ce7222017-12-11 17:24:43 -0500424 transform_maven_lib(working_dir, info, extract_res)
Dan Willemsen814152e2017-11-06 13:22:11 -0800425
Jeff Gastonc302bb92018-03-23 13:53:48 -0400426 # generate a single Android.mk that specifies to use all of the above artifacts
Alan Viverette4ec9a172018-02-20 16:19:31 -0500427 makefile = os.path.join(working_dir, 'Android.mk')
428 with open(makefile, 'w') as f:
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400429 args = ["pom2mk", "-sdk-version", "current"]
Jeff Gaston1cc06092018-03-28 15:51:02 -0400430 if include_static_deps:
431 args.append("-static-deps")
Jeff Gaston7ec1d8f2018-03-27 00:25:12 -0400432 rewriteNames = [name for name in maven_to_make if ":" in name] + [name for name in maven_to_make if ":" not in name]
433 args.extend(["-rewrite=^" + name + "$=" + maven_to_make[name][0] for name in rewriteNames])
Jeff Gaston7ec1d8f2018-03-27 00:25:12 -0400434 args.extend(["."])
Dan Willemsen814152e2017-11-06 13:22:11 -0800435 subprocess.check_call(args, stdout=f, cwd=working_dir)
Alan Viverette95f6d362017-04-06 09:40:50 -0400436
Jeff Gastonf12f3ce2018-03-23 16:41:24 -0400437 global rerun_extract_deps
438 rerun_extract_deps = True
Alan Viverette4ec9a172018-02-20 16:19:31 -0500439
Alan Viverette95f6d362017-04-06 09:40:50 -0400440 # Replace the old directory.
Jeff Gastonc302bb92018-03-23 13:53:48 -0400441 output_dir = os.path.join(cwd, transformed_dir)
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400442 mv(working_dir, output_dir)
Alan Viverettec960cfb2017-12-04 13:09:22 -0500443 return True
Alan Viverette95f6d362017-04-06 09:40:50 -0400444
Jeff Gastonc302bb92018-03-23 13:53:48 -0400445# moves <artifact_info> (of type MavenLibraryInfo) into the appropriate part of <working_dir> , and possibly unpacks any necessary included files
Alan Viveretted8ce7222017-12-11 17:24:43 -0500446def transform_maven_lib(working_dir, artifact_info, extract_res):
Dan Willemsen814152e2017-11-06 13:22:11 -0800447 # Move library into working dir
Jeff Gaston9edf86c2018-04-18 13:45:23 -0400448 new_dir = os.path.normpath(os.path.join(working_dir, os.path.relpath(artifact_info.dir, artifact_info.repo_dir)))
Jeff Gastonc302bb92018-03-23 13:53:48 -0400449 mv(artifact_info.dir, new_dir)
Dan Willemsen814152e2017-11-06 13:22:11 -0800450
451 for dirpath, dirs, files in os.walk(new_dir):
452 for f in files:
453 if '-sources.jar' in f:
454 os.remove(os.path.join(dirpath, f))
455
Alan Viverettec960cfb2017-12-04 13:09:22 -0500456 matcher = artifact_pattern.match(artifact_info.file)
457 maven_lib_name = artifact_info.key
Alan Viveretted4527e62017-05-11 15:03:25 -0400458 maven_lib_vers = matcher.group(2)
Alan Viverettec960cfb2017-12-04 13:09:22 -0500459 maven_lib_type = artifact_info.file[-3:]
Alan Viveretted4527e62017-05-11 15:03:25 -0400460
Alan Viverettec960cfb2017-12-04 13:09:22 -0500461 make_lib_name = maven_to_make[artifact_info.key][0]
462 make_dir_name = maven_to_make[artifact_info.key][1]
Alan Viveretted4527e62017-05-11 15:03:25 -0400463
Alan Viverette129555e2018-01-30 09:57:57 -0500464 artifact_file = os.path.join(new_dir, artifact_info.file)
465
Dan Willemsen814152e2017-11-06 13:22:11 -0800466 if extract_res:
Dan Willemsen814152e2017-11-06 13:22:11 -0800467 target_dir = os.path.join(working_dir, make_dir_name)
468 if not os.path.exists(target_dir):
469 os.makedirs(target_dir)
470
471 if maven_lib_type == "aar":
Alan Viverettec960cfb2017-12-04 13:09:22 -0500472 process_aar(artifact_file, target_dir)
Alan Viveretted4527e62017-05-11 15:03:25 -0400473
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400474 with zipfile.ZipFile(artifact_file) as zip:
475 manifests_dir = os.path.join(working_dir, "manifests")
476 zip.extract("AndroidManifest.xml", os.path.join(manifests_dir, make_lib_name))
Dan Willemsend677b602017-11-08 22:13:17 -0800477
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500478 print(maven_lib_vers, ":", maven_lib_name, "->", make_lib_name)
Alan Viveretted4527e62017-05-11 15:03:25 -0400479
Alan Viverette95f6d362017-04-06 09:40:50 -0400480
Alan Viverettec960cfb2017-12-04 13:09:22 -0500481def process_aar(artifact_file, target_dir):
Alan Viverette95f6d362017-04-06 09:40:50 -0400482 # Extract AAR file to target_dir.
483 with zipfile.ZipFile(artifact_file) as zip:
484 zip.extractall(target_dir)
485
Dan Willemsen814152e2017-11-06 13:22:11 -0800486 # Remove classes.jar
Alan Viverette95f6d362017-04-06 09:40:50 -0400487 classes_jar = os.path.join(target_dir, "classes.jar")
488 if os.path.exists(classes_jar):
Dan Willemsen814152e2017-11-06 13:22:11 -0800489 os.remove(classes_jar)
Alan Viverette95f6d362017-04-06 09:40:50 -0400490
491 # Remove or preserve empty dirs.
492 for root, dirs, files in os.walk(target_dir):
493 for dir in dirs:
494 dir_path = os.path.join(root, dir)
495 if not os.listdir(dir_path):
496 os.rmdir(dir_path)
497
498 # Remove top-level cruft.
499 for file in blacklist_files:
500 file_path = os.path.join(target_dir, file)
501 if os.path.exists(file_path):
502 os.remove(file_path)
503
Alan Viverettef17c9402017-07-19 12:57:40 -0400504
Alan Viverettecd3de262017-08-14 09:51:30 -0400505def fetch_artifact(target, build_id, artifact_path):
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500506 print('Fetching %s from %s...' % (artifact_path, target))
Alan Viverettecd3de262017-08-14 09:51:30 -0400507 fetch_cmd = [FETCH_ARTIFACT, '--bid', str(build_id), '--target', target, artifact_path]
Alan Viverette45837092017-05-12 14:50:53 -0400508 try:
Alan Viverettecd3de262017-08-14 09:51:30 -0400509 subprocess.check_output(fetch_cmd, stderr=subprocess.STDOUT)
Alan Viverette45837092017-05-12 14:50:53 -0400510 except subprocess.CalledProcessError:
Jeff Gaston13e38412018-02-06 14:45:36 -0500511 print_e('FAIL: Unable to retrieve %s artifact for build ID %s' % (artifact_path, build_id))
Alan Viverettec1c32b62017-12-20 09:40:36 -0500512 print_e('Please make sure you are authenticated for build server access!')
Alan Viverette45837092017-05-12 14:50:53 -0400513 return None
514 return artifact_path
515
516
Anton Hansson1d01a032018-04-09 10:29:37 +0100517def fetch_artifacts(target, build_id, artifact_dict):
518 for artifact, target_path in artifact_dict.items():
519 artifact_path = fetch_artifact(target, build_id.url_id, artifact)
520 if not artifact_path:
521 return False
522 mv(artifact_path, target_path)
523 return True
524
525
Alan Viverette129555e2018-01-30 09:57:57 -0500526def extract_artifact(artifact_path):
Alan Viverette45837092017-05-12 14:50:53 -0400527 # Unzip the repo archive into a separate directory.
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400528 repo_dir = os.path.basename(artifact_path)[:-4]
Alan Viverette45837092017-05-12 14:50:53 -0400529 with zipfile.ZipFile(artifact_path) as zipFile:
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400530 zipFile.extractall(repo_dir)
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400531 return repo_dir
532
533
Alan Viverette7e897e22018-03-09 15:24:10 -0500534def fetch_and_extract(target, build_id, file, artifact_path=None):
535 if not artifact_path:
536 artifact_path = fetch_artifact(target, build_id, file)
Alan Viverette129555e2018-01-30 09:57:57 -0500537 if not artifact_path:
538 return None
539 return extract_artifact(artifact_path)
540
541
Alan Viverette7e897e22018-03-09 15:24:10 -0500542def update_support(target, build_id, local_file):
543 if build_id:
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400544 repo_file = 'top-of-tree-m2repository-dejetified-%s.zip' % build_id.fs_id
Alan Viverette7e897e22018-03-09 15:24:10 -0500545 repo_dir = fetch_and_extract(target, build_id.url_id, repo_file, None)
546 else:
547 repo_dir = fetch_and_extract(target, None, None, local_file)
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400548 if not repo_dir:
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500549 print_e('Failed to extract Support Library repository')
Alan Viverettef48d9b42017-08-17 14:45:46 -0400550 return False
Alan Viverette45837092017-05-12 14:50:53 -0400551
552 # Transform the repo archive into a Makefile-compatible format.
Jeff Gaston1cc06092018-03-28 15:51:02 -0400553 return transform_maven_repos([repo_dir], support_dir, extract_res=True, include_static_deps=True)
Alan Viverettec960cfb2017-12-04 13:09:22 -0500554
Alan Viverette7e897e22018-03-09 15:24:10 -0500555
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400556def update_androidx(target, target_toolkit, build_id, local_file):
557 if build_id:
558 repo_file = 'top-of-tree-m2repository-%s.zip' % build_id.fs_id
559 repo_dir = fetch_and_extract(target, build_id.url_id, repo_file, None)
560 else:
561 repo_dir = fetch_and_extract(target, None, None, local_file)
562 if not repo_dir:
563 print_e('Failed to extract AndroidX repository')
564 return False
565
566 if build_id:
567 repo_file2 = 'top-of-tree-m2repository-%s.zip' % build_id.fs_id
568 repo_dir2 = fetch_and_extract(target_toolkit, build_id.url_id, repo_file2, None)
569 else:
570 repo_dir2 = fetch_and_extract(target_toolkit, None, None, local_file)
571 if not repo_dir2:
572 print_e('Failed to extract AndroidX app-toolkit repository')
573 return False
574
575 # Transform the repo archive into a Makefile-compatible format.
576 return transform_maven_repos([repo_dir, repo_dir2], androidx_dir, extract_res=False)
577
578
Jeff Gaston782c3e32018-02-06 14:36:17 -0500579def update_jetifier(target, build_id):
580 repo_file = 'jetifier-standalone.zip'
581 repo_dir = fetch_and_extract(target, build_id.url_id, repo_file)
582 if not repo_dir:
583 print_e('Failed to extract Jetifier')
584 return False
585
586 rm(jetifier_dir)
Jeff Gaston553a4372018-03-29 18:34:22 -0400587 mv(os.path.join(repo_dir, 'jetifier-standalone'), jetifier_dir)
588 os.chmod(os.path.join(jetifier_dir, 'bin', 'jetifier-standalone'), 0o755)
Jeff Gaston782c3e32018-02-06 14:36:17 -0500589 return True
590
Alan Viverette7e897e22018-03-09 15:24:10 -0500591
Alan Viverettec960cfb2017-12-04 13:09:22 -0500592def update_toolkit(target, build_id):
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400593 repo_dir = fetch_and_extract(target, build_id.url_id, \
594 'top-of-tree-m2repository-dejetified-%s.zip' % build_id.fs_id)
Alan Viverettec960cfb2017-12-04 13:09:22 -0500595 if not repo_dir:
596 print_e('Failed to extract App Toolkit repository')
597 return False
598
599 # Transform the repo archive into a Makefile-compatible format.
Jeff Gaston1cc06092018-03-28 15:51:02 -0400600 return transform_maven_repos([repo_dir], os.path.join(extras_dir, 'app-toolkit'), extract_res=True, include_static_deps=True)
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400601
602
603def update_constraint(target, build_id):
Jeff Gaston13e38412018-02-06 14:45:36 -0500604 layout_dir = fetch_and_extract(target, build_id.url_id,
605 'com.android.support.constraint-constraint-layout-%s.zip' % build_id.fs_id)
606 solver_dir = fetch_and_extract(target, build_id.url_id,
607 'com.android.support.constraint-constraint-layout-solver-%s.zip' % build_id.fs_id)
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400608 if not layout_dir or not solver_dir:
Alan Viverettec960cfb2017-12-04 13:09:22 -0500609 print_e('Failed to extract Constraint Layout repositories')
Alan Viverettecd3de262017-08-14 09:51:30 -0400610 return False
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400611
612 # Passing False here is an inelegant solution, but it means we can replace
613 # the top-level directory without worrying about other child directories.
Jeff Gastonc302bb92018-03-23 13:53:48 -0400614 return transform_maven_repos([layout_dir, solver_dir],
Alan Viverettec960cfb2017-12-04 13:09:22 -0500615 os.path.join(extras_dir, 'constraint-layout'), extract_res=False)
Alan Viverette45837092017-05-12 14:50:53 -0400616
Jeff Gaston9edf86c2018-04-18 13:45:23 -0400617def update_constraint_x(local_file):
618 repo_dir = extract_artifact(local_file)
619 if not repo_dir:
620 print_e('Failed to extract Constraint Layout X')
621 return False
622 return transform_maven_repos([repo_dir], os.path.join(extras_dir, 'constraint-layout-x'), extract_res=False)
623
Alan Viverette45837092017-05-12 14:50:53 -0400624
Alan Viverette129555e2018-01-30 09:57:57 -0500625def update_design(file):
626 design_dir = extract_artifact(file)
627 if not design_dir:
628 print_e('Failed to extract Design Library repositories')
629 return False
630
631 # Don't bother extracting resources -- this should only be used with AAPT2.
Jeff Gastonc302bb92018-03-23 13:53:48 -0400632 return transform_maven_repos([design_dir],
Alan Viverette129555e2018-01-30 09:57:57 -0500633 os.path.join(extras_dir, 'material-design'), extract_res=False)
634
635
Jeff Gaston6e7e7502018-04-04 00:22:45 -0400636def update_material(file):
637 design_dir = extract_artifact(file)
638 if not design_dir:
639 print_e('Failed to extract intermediate-AndroidX Design Library repositories')
640 return False
641
642 # Don't bother extracting resources -- this should only be used with AAPT2.
643 return transform_maven_repos([design_dir],
644 os.path.join(extras_dir, 'material-design-x'), extract_res=False)
645
646
Anton Hansson1d01a032018-04-09 10:29:37 +0100647def extract_to(zip_file, filename, parent_path):
648 zip_path = next(filter(lambda path: filename in path, zip_file.namelist()))
Alan Viverette45837092017-05-12 14:50:53 -0400649 src_path = zip_file.extract(zip_path)
650 dst_path = path(parent_path, filename)
651 mv(src_path, dst_path)
652
653
Anton Hansson1d01a032018-04-09 10:29:37 +0100654# This is a dict from an sdk level to an "artifact dict". The artifact dict
655# maps from artifact name to the respective package it stubs.
656# TODO(hansson): standardize the artifact names and remove this dict.
657sdk_artifacts_dict = {
658 'core': {
659 'core.current.stubs.jar': 'android.jar',
660 },
661 'public': {
662 'android.test.base.stubs.jar': 'android.test.base.jar',
663 'android.test.runner.stubs.jar': 'android.test.runner.jar',
664 'android.test.mock.stubs.jar': 'android.test.mock.jar',
665 'org.apache.http.legacy.jar': 'org.apache.http.legacy.jar',
666 },
667 'system': {
668 'android_system.jar': 'android.jar',
669 'android.test.mock.stubs_system.jar': 'android.test.mock.jar',
670 }
671}
672
673
674# TODO(hansson): Remove this method once the tools support the new structure.
675def update_framework_current_legacy(build_id):
676 sdk_artifact = 'sdk-repo-darwin-platforms-%s.zip' % build_id.fs_id
677 artifact_path = fetch_artifact(framework_sdk_target, build_id.url_id, sdk_artifact)
Alan Viverette45837092017-05-12 14:50:53 -0400678 if not artifact_path:
Alan Viverettecd3de262017-08-14 09:51:30 -0400679 return False
Alan Viverette45837092017-05-12 14:50:53 -0400680
681 with zipfile.ZipFile(artifact_path) as zipFile:
682 paths = zipFile.namelist()
683
Anton Hansson9709fd42018-04-03 16:52:13 +0100684 filenames = ['android.jar', 'uiautomator.jar', 'framework.aidl',
685 'optional/android.test.base.jar', 'optional/android.test.mock.jar',
686 'optional/android.test.runner.jar']
Alan Viverette45837092017-05-12 14:50:53 -0400687
Anton Hansson9709fd42018-04-03 16:52:13 +0100688 for filename in filenames:
Anton Hansson1d01a032018-04-09 10:29:37 +0100689 extract_to(zipFile, filename, current_path)
Jiyong Parkb773d292018-01-30 23:33:19 +0900690
Anton Hansson1d01a032018-04-09 10:29:37 +0100691 # There's no system version of framework.aidl, so use the public one.
692 extract_to(zipFile, 'framework.aidl', system_path)
Jiyong Parkb773d292018-01-30 23:33:19 +0900693
Anton Hansson1d01a032018-04-09 10:29:37 +0100694 artifact_dict = {
695 'core.current.stubs.jar': path(current_path, 'core.jar'),
696 'android_system.jar': path(system_path, 'android.jar'),
697 'android.test.mock.stubs_system.jar': path(system_path, 'optional/android.test.mock.jar'),
698 }
699 return fetch_artifacts(framework_sdk_target, build_id, artifact_dict)
700
701
702def update_framework(build_id, sdk_dir):
703 for api_level in ['core', 'public', 'system']:
704 target_dir = path(sdk_dir, api_level)
705 artifact_to_filename = sdk_artifacts_dict[api_level]
706 artifact_to_path = {artifact: path(target_dir, filename)
707 for (artifact, filename) in artifact_to_filename.items()}
708
709 if not fetch_artifacts(framework_sdk_target, build_id, artifact_to_path):
710 return False
711
712 if api_level == 'public':
713 # Fetch a few artifacts from the public sdk.
714 artifact = 'sdk-repo-darwin-platforms-%s.zip' % build_id.fs_id
715 artifact_path = fetch_artifact(framework_sdk_target, build_id.url_id, artifact)
Anton Hansson9709fd42018-04-03 16:52:13 +0100716 if not artifact_path:
717 return False
Anton Hansson1d01a032018-04-09 10:29:37 +0100718
719 with zipfile.ZipFile(artifact_path) as zipFile:
720 for filename in ['android.jar', 'framework.aidl', 'uiautomator.jar']:
721 extract_to(zipFile, filename, target_dir)
Anton Hansson9709fd42018-04-03 16:52:13 +0100722
Alan Viverettecd3de262017-08-14 09:51:30 -0400723 return True
Alan Viverette45837092017-05-12 14:50:53 -0400724
725
Anton Hansson1d01a032018-04-09 10:29:37 +0100726def finalize_sdk(build_id, sdk_version):
727 target_finalize_dir = '%d' % sdk_version
Anton Hansson9709fd42018-04-03 16:52:13 +0100728
Anton Hansson1d01a032018-04-09 10:29:37 +0100729 extra_finalize_artifacts = {
730 'public_api.txt': path(target_finalize_dir, 'public/api/android.txt'),
731 'system-api.txt': path(target_finalize_dir, 'system/api/android.txt'),
Anton Hansson9709fd42018-04-03 16:52:13 +0100732 }
Anton Hansson1d01a032018-04-09 10:29:37 +0100733 return fetch_artifacts(framework_sdk_target, build_id, extra_finalize_artifacts) \
734 and update_framework(build_id, target_finalize_dir)
Anton Hansson9709fd42018-04-03 16:52:13 +0100735
Anton Hansson9709fd42018-04-03 16:52:13 +0100736
Anton Hansson1d01a032018-04-09 10:29:37 +0100737def update_framework_current(build_id):
738 return update_framework(build_id, current_path)
Anton Hansson9709fd42018-04-03 16:52:13 +0100739
740
Alan Viverettec1c32b62017-12-20 09:40:36 -0500741def update_buildtools(target, arch, build_id):
Jeff Gaston13e38412018-02-06 14:45:36 -0500742 artifact_path = fetch_and_extract(target, build_id.url_id,
743 "sdk-repo-%s-build-tools-%s.zip" % (arch, build_id.fs_id))
Alan Viverettec1c32b62017-12-20 09:40:36 -0500744 if not artifact_path:
745 return False
746
747 top_level_dir = os.listdir(artifact_path)[0]
748 src_path = os.path.join(artifact_path, top_level_dir)
749 dst_path = path(buildtools_dir, arch)
750 mv(src_path, dst_path)
751
752 # Move all top-level files to /bin and make them executable
753 bin_path = path(dst_path, 'bin')
754 top_level_files = filter(lambda e: os.path.isfile(path(dst_path, e)), os.listdir(dst_path))
755 for file in top_level_files:
756 src_file = path(dst_path, file)
757 dst_file = path(bin_path, file)
758 mv(src_file, dst_file)
759 os.chmod(dst_file, 0o755)
760
761 # Remove renderscript
762 rm(path(dst_path, 'renderscript'))
763
764 return True
765
766
Alan Viverettecd3de262017-08-14 09:51:30 -0400767def append(text, more_text):
768 if text:
769 return "%s, %s" % (text, more_text)
770 return more_text
Alan Viverette45837092017-05-12 14:50:53 -0400771
Alan Viverette95f6d362017-04-06 09:40:50 -0400772
Jeff Gaston13e38412018-02-06 14:45:36 -0500773class buildId(object):
774 def __init__(self, url_id, fs_id):
775 # id when used in build server urls
776 self.url_id = url_id
777 # id when used in build commands
778 self.fs_id = fs_id
779
Jeff Gastonb9b09052018-02-05 14:16:05 -0500780def getBuildId(args):
Jeff Gaston13e38412018-02-06 14:45:36 -0500781 # must be in the format 12345 or P12345
Jeff Gastonb9b09052018-02-05 14:16:05 -0500782 source = args.source
Jeff Gaston13e38412018-02-06 14:45:36 -0500783 number_text = source[:]
784 presubmit = False
785 if number_text.startswith("P"):
786 presubmit = True
787 number_text = number_text[1:]
788 if not number_text.isnumeric():
Alan Viverette7e897e22018-03-09 15:24:10 -0500789 return None
Jeff Gaston13e38412018-02-06 14:45:36 -0500790 url_id = source
791 fs_id = url_id
792 if presubmit:
793 fs_id = "0"
794 args.file = False
795 return buildId(url_id, fs_id)
Jeff Gastonb9b09052018-02-05 14:16:05 -0500796
Colin Cross573e1212018-02-12 14:59:52 -0800797def getFile(args):
798 source = args.source
799 if not source.isnumeric():
800 return args.source
Alan Viverette7e897e22018-03-09 15:24:10 -0500801 return None
Colin Cross573e1212018-02-12 14:59:52 -0800802
Alan Viverette4ec9a172018-02-20 16:19:31 -0500803
804def script_relative(rel_path):
Jeff Gastona68a8d42018-03-23 14:00:13 -0400805 return os.path.join(script_dir, rel_path)
Alan Viverette4ec9a172018-02-20 16:19:31 -0500806
807
Jeff Gastoncc296a82018-03-23 14:33:24 -0400808def uncommittedChangesExist():
809 try:
810 # Make sure we don't overwrite any pending changes.
811 diffCommand = "cd " + git_dir + " && git diff --quiet"
812 subprocess.check_call(diffCommand, shell=True)
813 subprocess.check_call(diffCommand + " --cached", shell=True)
814 return False
815 except subprocess.CalledProcessError:
816 return True
817
818
Jeff Gastona7fba9b2018-03-26 23:48:51 -0400819rm(temp_dir)
Alan Viveretted4527e62017-05-11 15:03:25 -0400820parser = argparse.ArgumentParser(
Alan Viverette45837092017-05-12 14:50:53 -0400821 description=('Update current prebuilts'))
Alan Viveretted4527e62017-05-11 15:03:25 -0400822parser.add_argument(
Alan Viverette129555e2018-01-30 09:57:57 -0500823 'source',
824 help='Build server build ID or local Maven ZIP file')
825parser.add_argument(
826 '-d', '--design', action="store_true",
827 help='If specified, updates only the Design Library')
Alan Viveretted4527e62017-05-11 15:03:25 -0400828parser.add_argument(
Jeff Gaston6e7e7502018-04-04 00:22:45 -0400829 '-m', '--material', action="store_true",
830 help='If specified, updates only the intermediate-AndroidX Design Library')
831parser.add_argument(
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400832 '-c', '--constraint', action="store_true",
833 help='If specified, updates only Constraint Layout')
834parser.add_argument(
Jeff Gaston9edf86c2018-04-18 13:45:23 -0400835 '--constraint_x', action="store_true",
836 help='If specified, updates Constraint Layout X')
837parser.add_argument(
Alan Viverette5bfe05b2017-06-06 14:21:29 -0400838 '-s', '--support', action="store_true",
839 help='If specified, updates only the Support Library')
Alan Viverette45837092017-05-12 14:50:53 -0400840parser.add_argument(
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400841 '-x', '--androidx', action="store_true",
842 help='If specified, updates only AndroidX')
843parser.add_argument(
Jeff Gaston782c3e32018-02-06 14:36:17 -0500844 '-j', '--jetifier', action="store_true",
845 help='If specified, updates only Jetifier')
846parser.add_argument(
Alan Viverettec960cfb2017-12-04 13:09:22 -0500847 '-t', '--toolkit', action="store_true",
848 help='If specified, updates only the App Toolkit')
849parser.add_argument(
Alan Viverette5bfe05b2017-06-06 14:21:29 -0400850 '-p', '--platform', action="store_true",
851 help='If specified, updates only the Android Platform')
Alan Viverettec1c32b62017-12-20 09:40:36 -0500852parser.add_argument(
Anton Hansson9709fd42018-04-03 16:52:13 +0100853 '-f', '--finalize_sdk', type=int,
854 help='If specified, imports the source build as the specified finalized SDK version')
855parser.add_argument(
Alan Viverettec1c32b62017-12-20 09:40:36 -0500856 '-b', '--buildtools', action="store_true",
857 help='If specified, updates only the Build Tools')
Jeff Gastoncc296a82018-03-23 14:33:24 -0400858parser.add_argument(
859 '--commit-first', action="store_true",
860 help='If specified, then if uncommited changes exist, commit before continuing')
Alan Viveretted4527e62017-05-11 15:03:25 -0400861args = parser.parse_args()
Jeff Gaston56fe2762018-02-06 14:54:37 -0500862args.file = True
Alan Viverette129555e2018-01-30 09:57:57 -0500863if not args.source:
864 parser.error("You must specify a build ID or local Maven ZIP file")
Alan Viveretted4527e62017-05-11 15:03:25 -0400865 sys.exit(1)
Alan Viverette129555e2018-01-30 09:57:57 -0500866if not (args.support or args.platform or args.constraint or args.toolkit or args.buildtools \
Anton Hansson9709fd42018-04-03 16:52:13 +0100867 or args.design or args.jetifier or args.androidx or args.material \
Jeff Gaston9edf86c2018-04-18 13:45:23 -0400868 or args.finalize_sdk or args.constraint_x):
Alan Viverettec1c32b62017-12-20 09:40:36 -0500869 parser.error("You must specify at least one target to update")
Alan Viverettecd3de262017-08-14 09:51:30 -0400870 sys.exit(1)
Jeff Gaston9edf86c2018-04-18 13:45:23 -0400871if (args.support or args.constraint or args.constraint_x or args.toolkit or args.design or args.material or args.androidx) \
Jeff Gaston6e7e7502018-04-04 00:22:45 -0400872 and which('pom2mk') is None:
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500873 parser.error("Cannot find pom2mk in path; please run lunch to set up build environment")
874 sys.exit(1)
Alan Viveretted4527e62017-05-11 15:03:25 -0400875
Jeff Gastoncc296a82018-03-23 14:33:24 -0400876if uncommittedChangesExist():
877 if args.commit_first:
878 subprocess.check_call("cd " + git_dir + " && git add -u", shell=True)
879 subprocess.check_call("cd " + git_dir + " && git commit -m 'save working state'", shell=True)
880
881if uncommittedChangesExist():
Anton Hansson10861a02018-04-06 13:57:08 +0100882 print_e('FAIL: There are uncommitted changes here. Please commit or stash before continuing, because %s will run "git reset --hard" if execution fails' % os.path.basename(__file__))
Alan Viveretted4527e62017-05-11 15:03:25 -0400883 sys.exit(1)
884
885try:
Alan Viverettecd3de262017-08-14 09:51:30 -0400886 components = None
887 if args.constraint:
Jeff Gastonb9b09052018-02-05 14:16:05 -0500888 if update_constraint('studio', getBuildId(args)):
Alan Viverettecd3de262017-08-14 09:51:30 -0400889 components = append(components, 'Constraint Layout')
890 else:
Jeff Gaston9edf86c2018-04-18 13:45:23 -0400891 print_e('Failed to update Constraint Layout, aborting...')
892 sys.exit(1)
893 if args.constraint_x:
894 if update_constraint_x(getFile(args)):
895 components = append(components, 'Constraint Layout X')
896 else:
897 print_e('Failed to update Constraint Layout X, aborting...')
Alan Viverettecd3de262017-08-14 09:51:30 -0400898 sys.exit(1)
899 if args.support:
Alan Viverette7e897e22018-03-09 15:24:10 -0500900 if update_support('support_library', getBuildId(args), getFile(args)):
Alan Viverettecd3de262017-08-14 09:51:30 -0400901 components = append(components, 'Support Library')
902 else:
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500903 print_e('Failed to update Support Library, aborting...')
Alan Viverettecd3de262017-08-14 09:51:30 -0400904 sys.exit(1)
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400905 if args.androidx:
906 if update_androidx('support_library', 'support_library_app_toolkit', \
907 getBuildId(args), getFile(args)):
908 components = append(components, 'AndroidX')
909 else:
910 print_e('Failed to update AndroidX, aborting...')
911 sys.exit(1)
Jeff Gaston782c3e32018-02-06 14:36:17 -0500912 if args.jetifier:
913 if update_jetifier('support_library', getBuildId(args)):
914 components = append(components, 'Jetifier')
915 else:
916 print_e('Failed to update Jetifier, aborting...')
917 sys.exit(1)
Alan Viverettec960cfb2017-12-04 13:09:22 -0500918 if args.toolkit:
Jeff Gastonb9b09052018-02-05 14:16:05 -0500919 if update_toolkit('support_library_app_toolkit', getBuildId(args)):
Alan Viverettec960cfb2017-12-04 13:09:22 -0500920 components = append(components, 'App Toolkit')
921 else:
922 print_e('Failed to update App Toolkit, aborting...')
923 sys.exit(1)
Alan Viverettecd3de262017-08-14 09:51:30 -0400924 if args.platform:
Anton Hansson1d01a032018-04-09 10:29:37 +0100925 build_id = getBuildId(args)
926 if update_framework_current_legacy(build_id) and update_framework_current(build_id):
Alan Viverettecd3de262017-08-14 09:51:30 -0400927 components = append(components, 'platform SDK')
928 else:
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500929 print_e('Failed to update platform SDK, aborting...')
Alan Viverettecd3de262017-08-14 09:51:30 -0400930 sys.exit(1)
Anton Hansson9709fd42018-04-03 16:52:13 +0100931 if args.finalize_sdk:
Anton Hansson1d01a032018-04-09 10:29:37 +0100932 if finalize_sdk(getBuildId(args), args.finalize_sdk):
933 subprocess.check_call(['git', 'add', "%d" % args.finalize_sdk])
Anton Hansson9709fd42018-04-03 16:52:13 +0100934 components = append(components, 'finalized SDK %d' % args.finalize_sdk)
935 else:
936 print_e('Failed to finalize SDK %d, aborting...' % args.finalize_sdk)
937 sys.exit(1)
Alan Viverette129555e2018-01-30 09:57:57 -0500938 if args.design:
Colin Cross573e1212018-02-12 14:59:52 -0800939 if update_design(getFile(args)):
Alan Viverette129555e2018-01-30 09:57:57 -0500940 components = append(components, 'Design Library')
941 else:
Jeff Gaston6e7e7502018-04-04 00:22:45 -0400942 print_e('Failed to update Design Library, aborting...')
943 sys.exit(1)
944 if args.material:
945 if update_material(getFile(args)):
946 components = append(components, 'intermediate-AndroidX Design Library')
947 else:
948 print_e('Failed to update intermediate-AndroidX Design Library, aborting...')
Alan Viverette129555e2018-01-30 09:57:57 -0500949 sys.exit(1)
Alan Viverettec1c32b62017-12-20 09:40:36 -0500950 if args.buildtools:
Jeff Gastonb9b09052018-02-05 14:16:05 -0500951 if update_buildtools('sdk_phone_armv7-sdk_mac', 'darwin', getBuildId(args)) \
952 and update_buildtools('sdk_phone_x86_64-sdk', 'linux', getBuildId(args)) \
953 and update_buildtools('sdk_phone_armv7-win_sdk', 'windows', getBuildId(args)):
Alan Viverettec1c32b62017-12-20 09:40:36 -0500954 components = append(components, 'build tools')
955 else:
956 print_e('Failed to update build tools, aborting...')
957 sys.exit(1)
Jeff Gastonf12f3ce2018-03-23 16:41:24 -0400958 if rerun_extract_deps:
Jeff Gastonb70daa92018-03-29 20:10:22 -0400959 depsfile = os.path.join(current_path, 'fix_dependencies.mk')
Jeff Gastonf12f3ce2018-03-23 16:41:24 -0400960 with open(depsfile, 'w') as f:
Jeff Gastonb70daa92018-03-29 20:10:22 -0400961 cwd=os.getcwd()
Jeff Gaston7bb93092018-04-09 18:16:27 -0400962 subprocess.check_call(
Anton Hansson10861a02018-04-06 13:57:08 +0100963 './update_prebuilts/extract_deps.py current/*/Android.mk current/extras/*/Android.mk',
Jeff Gaston7bb93092018-04-09 18:16:27 -0400964 stdout=f, cwd=cwd, shell=True)
Jeff Gastonb70daa92018-03-29 20:10:22 -0400965 subprocess.check_call(['git', 'add', depsfile])
966
Jeff Gastonf12f3ce2018-03-23 16:41:24 -0400967
Alan Viveretted4527e62017-05-11 15:03:25 -0400968
Anton Hansson9709fd42018-04-03 16:52:13 +0100969 subprocess.check_call(['git', 'add', current_path, system_path, api_path, system_api_path,
970 buildtools_dir])
Colin Cross573e1212018-02-12 14:59:52 -0800971 if not args.source.isnumeric():
Alan Viverette129555e2018-01-30 09:57:57 -0500972 src_msg = "local Maven ZIP"
973 else:
Jeff Gaston13e38412018-02-06 14:45:36 -0500974 src_msg = "build %s" % (getBuildId(args).url_id)
Alan Viverette129555e2018-01-30 09:57:57 -0500975 msg = "Import %s from %s\n\n%s" % (components, src_msg, flatten(sys.argv))
Alan Viveretted4527e62017-05-11 15:03:25 -0400976 subprocess.check_call(['git', 'commit', '-m', msg])
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500977 print('Remember to test this change before uploading it to Gerrit!')
Alan Viveretted4527e62017-05-11 15:03:25 -0400978
979finally:
980 # Revert all stray files, including the downloaded zip.
981 try:
982 with open(os.devnull, 'w') as bitbucket:
983 subprocess.check_call(['git', 'add', '-Af', '.'], stdout=bitbucket)
984 subprocess.check_call(
Jeff Gaston9edf86c2018-04-18 13:45:23 -0400985 ['git', 'commit', '-m', 'COMMIT TO REVERT - RESET ME!!!', '--allow-empty'], stdout=bitbucket)
Alan Viveretted4527e62017-05-11 15:03:25 -0400986 subprocess.check_call(['git', 'reset', '--hard', 'HEAD~1'], stdout=bitbucket)
987 except subprocess.CalledProcessError:
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500988 print_e('ERROR: Failed cleaning up, manual cleanup required!!!')