blob: 0676cfab00a126712765186ec3e0847da9bd6095 [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'
Alan Viverette3e57a4a2017-08-11 15:49:47 -040017support_dir = os.path.join(current_path, 'support')
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -040018androidx_dir = os.path.join(current_path, 'androidx')
Alan Viverette3e57a4a2017-08-11 15:49:47 -040019extras_dir = os.path.join(current_path, 'extras')
Alan Viverettec1c32b62017-12-20 09:40:36 -050020buildtools_dir = 'tools'
Jeff Gaston553a4372018-03-29 18:34:22 -040021jetifier_dir = os.path.join(buildtools_dir, 'jetifier', 'jetifier-standalone')
Alan Viverette95f6d362017-04-06 09:40:50 -040022
Jeff Gastona68a8d42018-03-23 14:00:13 -040023temp_dir = os.path.join(os.getcwd(), "support_tmp")
24os.chdir(os.path.dirname(os.path.dirname(os.path.realpath(sys.argv[0]))))
25git_dir = os.getcwd()
26
Jeff Gastonf12f3ce2018-03-23 16:41:24 -040027rerun_extract_deps = False
28
Alan Viverettecd3de262017-08-14 09:51:30 -040029# See go/fetch_artifact for details on this script.
Alan Viveretted4527e62017-05-11 15:03:25 -040030FETCH_ARTIFACT = '/google/data/ro/projects/android/fetch_artifact'
31
Alan Viverette95f6d362017-04-06 09:40:50 -040032maven_to_make = {
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -040033 # Support Library
34 'com.android.support:animated-vector-drawable': ['android-support-animatedvectordrawable', 'graphics/drawable'],
35 'com.android.support:appcompat-v7': ['android-support-v7-appcompat', 'v7/appcompat'],
36 'com.android.support:cardview-v7': ['android-support-v7-cardview', 'v7/cardview'],
37 'com.android.support:collections': ['android-support-collections', 'collections', 'jar'],
38 'com.android.support:customtabs': ['android-support-customtabs', 'customtabs'],
39 'com.android.support:exifinterface': ['android-support-exifinterface', 'exifinterface'],
40 'com.android.support:gridlayout-v7': ['android-support-v7-gridlayout', 'v7/gridlayout'],
41 'com.android.support:leanback-v17': ['android-support-v17-leanback', 'v17/leanback'],
42 'com.android.support:mediarouter-v7': ['android-support-v7-mediarouter', 'v7/mediarouter'],
43 'com.android.support:palette-v7': ['android-support-v7-palette', 'v7/palette'],
44 'com.android.support:percent': ['android-support-percent', 'percent'],
45 'com.android.support:preference-leanback-v17': ['android-support-v17-preference-leanback', 'v17/preference-leanback'],
46 'com.android.support:preference-v14': ['android-support-v14-preference', 'v14/preference'],
47 'com.android.support:preference-v7': ['android-support-v7-preference', 'v7/preference'],
48 'com.android.support:recommendation': ['android-support-recommendation', 'recommendation'],
49 'com.android.support:recyclerview-v7': ['android-support-v7-recyclerview', 'v7/recyclerview'],
50 'com.android.support:support-annotations': ['android-support-annotations', 'annotations', 'jar'],
51 'com.android.support:support-compat': ['android-support-compat', 'compat'],
52 'com.android.support:support-core-ui': ['android-support-core-ui', 'core-ui'],
53 'com.android.support:support-core-utils': ['android-support-core-utils', 'core-utils'],
54 'com.android.support:support-dynamic-animation': ['android-support-dynamic-animation', 'dynamic-animation'],
55 'com.android.support:support-emoji-appcompat': ['android-support-emoji-appcompat', 'emoji-appcompat'],
56 'com.android.support:support-emoji-bundled': ['android-support-emoji-bundled', 'emoji-bundled'],
57 'com.android.support:support-emoji': ['android-support-emoji', 'emoji'],
58 'com.android.support:support-fragment': ['android-support-fragment', 'fragment'],
59 'com.android.support:support-media-compat': ['android-support-media-compat', 'media-compat'],
60 'com.android.support:support-tv-provider': ['android-support-tv-provider', 'tv-provider'],
61 'com.android.support:support-v13': ['android-support-v13', 'v13'],
62 'com.android.support:support-v4': ['android-support-v4', 'v4'],
63 'com.android.support:support-vector-drawable': ['android-support-vectordrawable', 'graphics/drawable'],
64 'com.android.support:transition': ['android-support-transition', 'transition'],
65 'com.android.support:wear': ['android-support-wear', 'wear'],
Alan Viverette7bb86da2018-02-21 18:29:02 -050066
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -040067 # Support Library (28.0.0 splits + new modules)
68 'com.android.support:heifwriter': ['android-support-heifwriter', 'heifwriter'],
69 'com.android.support:webkit': ['android-support-webkit', 'webkit'],
70 'com.android.support:customview': ['android-support-customview', 'customview'],
71 'com.android.support:textclassifier': ['android-support-textclassifier', 'textclassifier'],
72 'com.android.support:swiperefreshlayout': ['android-support-swiperefreshlayout', 'swiperefreshlayout'],
73 'com.android.support:viewpager': ['android-support-viewpager', 'viewpager'],
74 'com.android.support:coordinatorlayout': ['android-support-coordinatorlayout', 'coordinatorlayout'],
75 'com.android.support:asynclayoutinflater': ['android-support-asynclayoutinflater', 'asynclayoutinflater'],
76 'com.android.support:support-content': ['android-support-support-content', 'support-content'],
77 'com.android.support:documentfile': ['android-support-documentfile', 'documentfile'],
78 'com.android.support:drawerlayout': ['android-support-drawerlayout', 'drawerlayout'],
79 'com.android.support:localbroadcastmanager': ['android-support-localbroadcastmanager', 'localbroadcastmanager'],
80 'com.android.support:print': ['android-support-print', 'print'],
81 'com.android.support:slidingpanelayout': ['android-support-slidingpanelayout', 'slidingpanelayout'],
82 'com.android.support:interpolator': ['android-support-interpolator', 'interpolator'],
83 'com.android.support:cursoradapter': ['android-support-cursoradapter', 'cursoradapter'],
84 'com.android.support:loader': ['android-support-loader', 'loader'],
85 'com.android.support:contentpaging': ['android-support-contentpaging', 'contentpaging'],
86 'com.android.support:recyclerview-selection': ['android-support-recyclerview-selection', 'recyclerview-selection'],
87 'com.android.support:car': ['android-support-car', 'car'],
88 'com.android.support:slices-core': ['android-slices-core', 'slices-core'],
89 'com.android.support:slices-view': ['android-slices-view', 'slices-view'],
90 'com.android.support:slices-builders': ['android-slices-builders', 'slices-builders'],
Alan Viverette19ecd502018-01-05 13:52:16 -050091
92 # Multidex
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -040093 'com.android.support:multidex': ['android-support-multidex', 'multidex/library'],
94 'com.android.support:multidex-instrumentation': ['android-support-multidex-instrumentation', 'multidex/instrumentation'],
Alan Viverette19ecd502018-01-05 13:52:16 -050095
96 # Constraint Layout
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -040097 'com.android.support.constraint:constraint-layout': ['android-support-constraint-layout', 'constraint-layout'],
98 'com.android.support.constraint:constraint-layout-solver': ['android-support-constraint-layout-solver', 'constraint-layout-solver'],
Alan Viverette19ecd502018-01-05 13:52:16 -050099
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400100 # Architecture Components
Alan Viverette19ecd502018-01-05 13:52:16 -0500101 'android.arch.core:runtime': ['android-arch-core-runtime', 'arch-core/runtime'],
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400102 'android.arch.core:common': ['android-arch-core-common', 'arch-core/common'],
103 'android.arch.lifecycle:common': ['android-arch-lifecycle-common', 'arch-lifecycle/common'],
104 'android.arch.lifecycle:common-java8': ['android-arch-lifecycle-common-java8', 'arch-lifecycle/common-java8'],
105 'android.arch.lifecycle:extensions': ['android-arch-lifecycle-extensions', 'arch-lifecycle/extensions'],
106 'android.arch.lifecycle:livedata': ['android-arch-lifecycle-livedata', 'arch-lifecycle/livedata'],
107 'android.arch.lifecycle:livedata-core': ['android-arch-lifecycle-livedata-core', 'arch-lifecycle/livedata-core'],
108 'android.arch.lifecycle:runtime': ['android-arch-lifecycle-runtime', 'arch-lifecycle/runtime'],
109 'android.arch.lifecycle:viewmodel': ['android-arch-lifecycle-viewmodel', 'arch-lifecycle/viewmodel'],
110 'android.arch.paging:common': ['android-arch-paging-common', 'arch-paging/common'],
Alan Viverette19ecd502018-01-05 13:52:16 -0500111 'android.arch.paging:runtime': ['android-arch-paging-runtime', 'arch-paging/runtime'],
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400112 'android.arch.persistence:db': ['android-arch-persistence-db', 'arch-persistence/db'],
113 'android.arch.persistence:db-framework': ['android-arch-persistence-db-framework', 'arch-persistence/db-framework'],
114 'android.arch.persistence.room:common': ['android-arch-room-common', 'arch-room/common'],
115 'android.arch.persistence.room:migration': ['android-arch-room-migration', 'arch-room/migration'],
116 'android.arch.persistence.room:runtime': ['android-arch-room-runtime', 'arch-room/runtime'],
117 'android.arch.persistence.room:testing': ['android-arch-room-testing', 'arch-room/testing'],
118
119 # AndroidX
120 'androidx.slice:slice-builders': ['androidx.slice_slice-builders', 'androidx/slice/slice-builders'],
121 'androidx.slice:slice-core': ['androidx.slice_slice-core', 'androidx/slice/slice-core'],
122 'androidx.slice:slice-view': ['androidx.slice_slice-view', 'androidx/slice/slice-view'],
123 'androidx.vectordrawable:vectordrawable-animated': ['androidx.vectordrawable_vectordrawable-animated', 'androidx/vectordrawable/vectordrawable-animated'],
124 'androidx.annotation:annotation': ['androidx.annotation_annotation', 'androidx/annotation/annotation', 'jar'],
125 'androidx.asynclayoutinflater:asynclayoutinflater': ['androidx.asynclayoutinflater_asynclayoutinflater', 'androidx/asynclayoutinflater/asynclayoutinflater'],
126 'androidx.car:car': ['androidx.car_car', 'androidx/car/car'],
127 'androidx.collection:collection': ['androidx.collection_collection', 'androidx/collection/collection', 'jar'],
128 'androidx.core:core': ['androidx.core_core', 'androidx/core/core'],
129 'androidx.contentpaging:contentpaging': ['androidx.contentpaging_contentpaging', 'androidx/contentpaging/contentpaging'],
130 'androidx.coordinatorlayout:coordinatorlayout': ['androidx.coordinatorlayout_coordinatorlayout', 'androidx/coordinatorlayout/coordinatorlayout'],
131 'androidx.legacy:legacy-support-core-ui': ['androidx.legacy_legacy-support-core-ui', 'androidx/legacy/legacy-support-core-ui'],
132 'androidx.legacy:legacy-support-core-utils': ['androidx.legacy_legacy-support-core-utils', 'androidx/legacy/legacy-support-core-utils'],
133 'androidx.cursoradapter:cursoradapter': ['androidx.cursoradapter_cursoradapter', 'androidx/cursoradapter/cursoradapter'],
134 'androidx.browser:browser': ['androidx.browser_browser', 'androidx/browser/browser'],
135 'androidx.customview:customview': ['androidx.customview_customview', 'androidx/customview/customview'],
136 'androidx.documentfile:documentfile': ['androidx.documentfile_documentfile', 'androidx/documentfile/documentfile'],
137 'androidx.drawerlayout:drawerlayout': ['androidx.drawerlayout_drawerlayout', 'androidx/drawerlayout/drawerlayout'],
138 'androidx.dynamicanimation:dynamicanimation': ['androidx.dynamicanimation_dynamicanimation', 'androidx/dynamicanimation/dynamicanimation'],
139 'androidx.emoji:emoji': ['androidx.emoji_emoji', 'androidx/emoji/emoji'],
140 'androidx.emoji:emoji-appcompat': ['androidx.emoji_emoji-appcompat', 'androidx/emoji/emoji-appcompat'],
141 'androidx.emoji:emoji-bundled': ['androidx.emoji_emoji-bundled', 'androidx/emoji/emoji-bundled'],
142 'androidx.exifinterface:exifinterface': ['androidx.exifinterface_exifinterface', 'androidx/exifinterface/exifinterface'],
143 'androidx.fragment:fragment': ['androidx.fragment_fragment', 'androidx/fragment/fragment'],
144 'androidx.heifwriter:heifwriter': ['androidx.heifwriter_heifwriter', 'androidx/heifwriter/heifwriter'],
145 'androidx.interpolator:interpolator': ['androidx.interpolator_interpolator', 'androidx/interpolator/interpolator'],
146 'androidx.loader:loader': ['androidx.loader_loader', 'androidx/loader/loader'],
147 'androidx.localbroadcastmanager:localbroadcastmanager': ['androidx.localbroadcastmanager_localbroadcastmanager', 'androidx/localbroadcastmanager/localbroadcastmanager'],
148 'androidx.media:media': ['androidx.media_media', 'androidx/media/media'],
149 'androidx.percentlayout:percentlayout': ['androidx.percentlayout_percentlayout', 'androidx/percentlayout/percentlayout'],
150 'androidx.print:print': ['androidx.print_print', 'androidx/print/print'],
151 'androidx.recommendation:recommendation': ['androidx.recommendation_recommendation', 'androidx/recommendation/recommendation'],
152 'androidx.recyclerview:recyclerview-selection': ['androidx.recyclerview_recyclerview-selection', 'androidx/recyclerview/recyclerview-selection'],
153 'androidx.slidingpanelayout:slidingpanelayout': ['androidx.slidingpanelayout_slidingpanelayout', 'androidx/slidingpanelayout/slidingpanelayout'],
154 'androidx.swiperefreshlayout:swiperefreshlayout': ['androidx.swiperefreshlayout_swiperefreshlayout', 'androidx/swiperefreshlayout/swiperefreshlayout'],
155 'androidx.textclassifier:textclassifier': ['androidx.textclassifier_textclassifier', 'androidx/textclassifier/textclassifier'],
156 'androidx.transition:transition': ['androidx.transition_transition', 'androidx/transition/transition'],
157 'androidx.tvprovider:tvprovider': ['androidx.tvprovider_tvprovider', 'androidx/tvprovider/tvprovider'],
158 'androidx.legacy:legacy-support-v13': ['androidx.legacy_legacy-support-v13', 'androidx/legacy/legacy-support-v13'],
159 'androidx.legacy:legacy-preference-v14': ['androidx.legacy_legacy-preference-v14', 'androidx/legacy/legacy-preference-v14'],
160 'androidx.leanback:leanback': ['androidx.leanback_leanback', 'androidx/leanback/leanback'],
161 'androidx.leanback:leanback-preference': ['androidx.leanback_leanback-preference', 'androidx/leanback/leanback-preference'],
162 'androidx.legacy:legacy-support-v4': ['androidx.legacy_legacy-support-v4', 'androidx/legacy/legacy-support-v4'],
163 'androidx.appcompat:appcompat': ['androidx.appcompat_appcompat', 'androidx/appcompat/appcompat'],
164 'androidx.cardview:cardview': ['androidx.cardview_cardview', 'androidx/cardview/cardview'],
165 'androidx.gridlayout:gridlayout': ['androidx.gridlayout_gridlayout', 'androidx/gridlayout/gridlayout'],
166 'androidx.mediarouter:mediarouter': ['androidx.mediarouter_mediarouter', 'androidx/mediarouter/mediarouter'],
167 'androidx.palette:palette': ['androidx.palette_palette', 'androidx/palette/palette'],
168 'androidx.preference:preference': ['androidx.preference_preference', 'androidx/preference/preference'],
169 'androidx.recyclerview:recyclerview': ['androidx.recyclerview_recyclerview', 'androidx/recyclerview/recyclerview'],
170 'androidx.vectordrawable:vectordrawable': ['androidx.vectordrawable_vectordrawable', 'androidx/vectordrawable/vectordrawable'],
171 'androidx.viewpager:viewpager': ['androidx.viewpager_viewpager', 'androidx/viewpager/viewpager'],
172 'androidx.wear:wear': ['androidx.wear_wear', 'androidx/wear/wear'],
173 'androidx.webkit:webkit': ['androidx.webkit_webkit', 'androidx/webkit/webkit'],
174
175 # AndroidX for Multidex
176 'androidx.multidex:multidex': ['androidx-multidex_multidex', 'androidx/multidex/multidex'],
177 'androidx.multidex:multidex-instrumentation': ['androidx-multidex_multidex-instrumentation', 'androidx/multidex/multidex-instrumentation'],
178
179 # AndroidX for Constraint Layout
180 'androidx.constraintlayout:constraintlayout': ['androidx-constraintlayout_constraintlayout', 'androidx/constraintlayout/constraintlayout'],
181 'androidx.constraintlayout:constraintlayout-solver': ['androidx-constraintlayout_constraintlayout-solver', 'androidx/constraintlayout/constraintlayout-solver'],
182
183 # AndroidX for Architecture Components
184 'androidx.arch.core:core-common': ['androidx.arch.core_core-common', 'androidx/arch/core/core-common'],
185 'androidx.arch.core:core-runtime': ['androidx.arch.core_core-runtime', 'androidx/arch/core/core-runtime'],
186 'androidx.lifecycle:lifecycle-common': ['androidx.lifecycle_lifecycle-common', 'androidx/lifecycle/lifecycle-common'],
187 'androidx.lifecycle:lifecycle-common-java8': ['androidx.lifecycle_lifecycle-common-java8', 'androidx/lifecycle/lifecycle-common-java8'],
188 'androidx.lifecycle:lifecycle-extensions': ['androidx.lifecycle_lifecycle-extensions', 'androidx/lifecycle/lifecycle-extensions'],
189 'androidx.lifecycle:lifecycle-livedata': ['androidx.lifecycle_lifecycle-livedata', 'androidx/lifecycle/lifecycle-livedata'],
190 'androidx.lifecycle:lifecycle-livedata-core': ['androidx.lifecycle_lifecycle-livedata-core', 'androidx/lifecycle/lifecycle-livedata-core'],
191 'androidx.lifecycle:lifecycle-runtime': ['androidx.lifecycle_lifecycle-runtime', 'androidx/lifecycle/lifecycle-runtime'],
192 'androidx.lifecycle:lifecycle-viewmodel': ['androidx.lifecycle_lifecycle-viewmodel', 'androidx/lifecycle/lifecycle-viewmodel'],
193 'androidx.paging:paging-common': ['androidx.paging_paging-common', 'androidx/paging/paging-common'],
194 'androidx.paging:paging-runtime': ['androidx.paging_paging-runtime', 'androidx/paging/paging-runtime'],
195 'androidx.sqlite:sqlite': ['androidx.sqlite_sqlite', 'androidx/sqlite/sqlite'],
196 'androidx.sqlite:sqlite-framework': ['androidx.sqlite_sqlite-framework', 'androidx/sqlite/sqlite-framework'],
197 'androidx.room:room-common': ['androidx.room_room-common', 'androidx/room/room-common'],
198 'androidx.room:room-migration': ['androidx.room_room-migration', 'androidx/room/room-migration'],
199 'androidx.room:room-runtime': ['androidx.room_room-runtime', 'androidx/room/room-runtime'],
200 'androidx.room:room-testing': ['androidx.room_room-testing', 'androidx/room/room-testing'],
Allenab72f012018-01-29 18:10:23 -0800201
Alan Viverette19ecd502018-01-05 13:52:16 -0500202 # Lifecycle
Alan Viverettec7e88f12018-02-13 15:29:50 -0500203 # Missing dependencies:
204 # - auto-common
205 # - javapoet
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400206 #'android.arch.lifecycle:compiler': ['android-arch-lifecycle-compiler', 'arch-lifecycle/compiler'],
Alan Viverettec7e88f12018-02-13 15:29:50 -0500207 # Missing dependencies:
208 # - reactive-streams
209 #'android.arch.lifecycle:reactivestreams': ['android-arch-lifecycle-reactivestreams','arch-lifecycle/reactivestreams'],
Allenab72f012018-01-29 18:10:23 -0800210
Alan Viverette19ecd502018-01-05 13:52:16 -0500211 # Room
Alan Viverettec7e88f12018-02-13 15:29:50 -0500212 # Missing dependencies:
213 # - auto-common
214 # - javapoet
215 # - antlr4
216 # - kotlin-metadata
217 # - commons-codec
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400218 #'android.arch.persistence.room:compiler': ['android-arch-room-compiler', 'arch-room/compiler'],
Alan Viverettec7e88f12018-02-13 15:29:50 -0500219 # Missing dependencies:
220 # - rxjava
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400221 #'android.arch.persistence.room:rxjava2': ['android-arch-room-rxjava2', 'arch-room/rxjava2'],
Allenab72f012018-01-29 18:10:23 -0800222
Jeff Gaston6e7e7502018-04-04 00:22:45 -0400223 # Third-party dependencies
224 'com.google.android:flexbox': ['flexbox', 'flexbox'],
225
226 # Support Library Material Design Components
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400227 'com.android.support:design': ['android-support-design', 'design'],
228 'com.android.support:design-animation': ['android-support-design-animation', 'design-animation'],
229 'com.android.support:design-bottomnavigation': ['android-support-design-bottomnavigation', 'design-bottomnavigation'],
230 'com.android.support:design-bottomsheet': ['android-support-design-bottomsheet', 'design-bottomsheet'],
231 'com.android.support:design-button': ['android-support-design-button', 'design-button'],
232 'com.android.support:design-canvas': ['android-support-design-canvas', 'design-canvas'],
233 'com.android.support:design-card': ['android-support-design-card', 'design-card'],
234 'com.android.support:design-chip': ['android-support-design-chip', 'design-chip'],
235 'com.android.support:design-circularreveal': ['android-support-design-circularreveal', 'design-circularreveal'],
236 'com.android.support:design-circularreveal-cardview': ['android-support-design-circularreveal-cardview', 'design-circularreveal-cardview'],
237 'com.android.support:design-circularreveal-coordinatorlayout': ['android-support-design-circularreveal-coordinatorlayout', 'design-circularreveal-coordinatorlayout'],
238 'com.android.support:design-color': ['android-support-design-color', 'design-color'],
239 'com.android.support:design-dialog': ['android-support-design-dialog', 'design-dialog'],
240 'com.android.support:design-drawable': ['android-support-design-drawable', 'design-drawable'],
241 'com.android.support:design-expandable': ['android-support-design-expandable', 'design-expandable'],
242 'com.android.support:design-floatingactionbutton': ['android-support-design-floatingactionbutton', 'design-floatingactionbutton'],
243 'com.android.support:design-internal': ['android-support-design-internal', 'design-internal'],
244 'com.android.support:design-math': ['android-support-design-math', 'design-math'],
245 'com.android.support:design-resources': ['android-support-design-resources', 'design-resources'],
246 'com.android.support:design-ripple': ['android-support-design-ripple', 'design-ripple'],
247 'com.android.support:design-snackbar': ['android-support-design-snackbar', 'design-snackbar'],
248 'com.android.support:design-stateful': ['android-support-design-stateful', 'design-stateful'],
249 'com.android.support:design-textfield': ['android-support-design-textfield', 'design-textfield'],
250 'com.android.support:design-theme': ['android-support-design-theme', 'design-theme'],
251 'com.android.support:design-transformation': ['android-support-design-transformation', 'design-transformation'],
252 'com.android.support:design-typography': ['android-support-design-typography', 'design-typography'],
253 'com.android.support:design-widget': ['android-support-design-widget', 'design-widget'],
254 'com.android.support:design-navigation': ['android-support-design-navigation', 'design-navigation'],
255 'com.android.support:design-tabs': ['android-support-design-tabs', 'design-tabs'],
256 'com.android.support:design-bottomappbar': ['android-support-design-bottomappbar', 'design-bottomappbar'],
257 'com.android.support:design-shape': ['android-support-design-shape', 'design-shape'],
Alan Viverettea59082b2018-02-22 10:27:46 -0500258
Jeff Gaston6e7e7502018-04-04 00:22:45 -0400259 # Intermediate-AndroidX Material Design Components
260 'com.android.temp.support:design': ['androidx.design_design', 'com/android/temp/support/design/design'],
261 'com.android.temp.support:design-animation': ['androidx.design_design-animation', 'com/android/temp/support/design/design-animation'],
262 'com.android.temp.support:design-bottomnavigation': ['androidx.design_design-bottomnavigation', 'com/android/temp/support/design/design-bottomnavigation'],
263 'com.android.temp.support:design-bottomsheet': ['androidx.design_design-bottomsheet', 'com/android/temp/support/design/design-bottomsheet'],
264 'com.android.temp.support:design-button': ['androidx.design_design-button', 'com/android/temp/support/design/design-button'],
265 'com.android.temp.support:design-canvas': ['androidx.design_design-canvas', 'com/android/temp/support/design/design-canvas'],
266 'com.android.temp.support:design-card': ['androidx.design_design-card', 'com/android/temp/support/design/design-card'],
267 'com.android.temp.support:design-chip': ['androidx.design_design-chip', 'com/android/temp/support/design/design-chip'],
268 'com.android.temp.support:design-circularreveal': ['androidx.design_design-circularreveal', 'com/android/temp/support/design/design-circularreveal'],
269 'com.android.temp.support:design-circularreveal-cardview': ['androidx.design_design-circularreveal-cardview', 'com/android/temp/support/design/design-circularreveal-cardview'],
270 'com.android.temp.support:design-circularreveal-coordinatorlayout': ['androidx.design_design-circularreveal-coordinatorlayout', 'com/android/temp/support/design/design-circularreveal-coordinatorlayout'],
271 'com.android.temp.support:design-color': ['androidx.design_design-color', 'com/android/temp/support/design/design-color'],
272 'com.android.temp.support:design-dialog': ['androidx.design_design-dialog', 'com/android/temp/support/design/design-dialog'],
273 'com.android.temp.support:design-drawable': ['androidx.design_design-drawable', 'com/android/temp/support/design/design-drawable'],
274 'com.android.temp.support:design-expandable': ['androidx.design_design-expandable', 'com/android/temp/support/design/design-expandable'],
275 'com.android.temp.support:design-floatingactionbutton': ['androidx.design_design-floatingactionbutton', 'com/android/temp/support/design/design-floatingactionbutton'],
276 'com.android.temp.support:design-internal': ['androidx.design_design-internal', 'com/android/temp/support/design/design-internal'],
277 'com.android.temp.support:design-math': ['androidx.design_design-math', 'com/android/temp/support/design/design-math'],
278 'com.android.temp.support:design-resources': ['androidx.design_design-resources', 'com/android/temp/support/design/design-resources'],
279 'com.android.temp.support:design-ripple': ['androidx.design_design-ripple', 'com/android/temp/support/design/design-ripple'],
280 'com.android.temp.support:design-snackbar': ['androidx.design_design-snackbar', 'com/android/temp/support/design/design-snackbar'],
281 'com.android.temp.support:design-stateful': ['androidx.design_design-stateful', 'com/android/temp/support/design/design-stateful'],
282 'com.android.temp.support:design-textfield': ['androidx.design_design-textfield', 'com/android/temp/support/design/design-textfield'],
283 'com.android.temp.support:design-theme': ['androidx.design_design-theme', 'com/android/temp/support/design/design-theme'],
284 'com.android.temp.support:design-transformation': ['androidx.design_design-transformation', 'com/android/temp/support/design/design-transformation'],
285 'com.android.temp.support:design-typography': ['androidx.design_design-typography', 'com/android/temp/support/design/design-typography'],
286 'com.android.temp.support:design-widget': ['androidx.design_design-widget', 'com/android/temp/support/design/design-widget'],
287 'com.android.temp.support:design-navigation': ['androidx.design_design-navigation', 'com/android/temp/support/design/design-navigation'],
288 'com.android.temp.support:design-tabs': ['androidx.design_design-tabs', 'com/android/temp/support/design/design-tabs'],
289 'com.android.temp.support:design-bottomappbar': ['androidx.design_design-bottomappbar', 'com/android/temp/support/design/design-bottomappbar'],
290 'com.android.temp.support:design-shape': ['androidx.design_design-shape', 'com/android/temp/support/design/design-shape'],
291
Alan Viverette95f6d362017-04-06 09:40:50 -0400292}
293
294# Always remove these files.
295blacklist_files = [
296 'annotations.zip',
297 'public.txt',
298 'R.txt',
Alan Viverette44ad4e42017-08-09 17:45:00 -0400299 'AndroidManifest.xml',
Alan Viverettef48d9b42017-08-17 14:45:46 -0400300 os.path.join('libs','noto-emoji-compat-java.jar')
Alan Viverette95f6d362017-04-06 09:40:50 -0400301]
302
Alan Viverette44ad4e42017-08-09 17:45:00 -0400303artifact_pattern = re.compile(r"^(.+?)-(\d+\.\d+\.\d+(?:-\w+\d+)?(?:-[\d.]+)*)\.(jar|aar)$")
Alan Viverette95f6d362017-04-06 09:40:50 -0400304
Alan Viverettec960cfb2017-12-04 13:09:22 -0500305
306class MavenLibraryInfo:
Jeff Gastonc302bb92018-03-23 13:53:48 -0400307 def __init__(self, key, group_id, artifact_id, version, dir, repo_dir, file):
Alan Viverettec960cfb2017-12-04 13:09:22 -0500308 self.key = key
309 self.group_id = group_id
310 self.artifact_id = artifact_id
311 self.version = version
Jeff Gastonc302bb92018-03-23 13:53:48 -0400312 self.dir = dir
Alan Viverettec960cfb2017-12-04 13:09:22 -0500313 self.repo_dir = repo_dir
314 self.file = file
315
316
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500317def print_e(*args, **kwargs):
318 print(*args, file=sys.stderr, **kwargs)
319
Alan Viverette95f6d362017-04-06 09:40:50 -0400320
321def touch(fname, times=None):
322 with open(fname, 'a'):
323 os.utime(fname, times)
324
325
Alan Viverette45837092017-05-12 14:50:53 -0400326def path(*path_parts):
327 return reduce((lambda x, y: os.path.join(x, y)), path_parts)
328
329
Alan Viverettecd3de262017-08-14 09:51:30 -0400330def flatten(list):
331 return reduce((lambda x, y: "%s %s" % (x, y)), list)
332
333
Alan Viverette45837092017-05-12 14:50:53 -0400334def rm(path):
335 if os.path.isdir(path):
336 rmtree(path)
337 elif os.path.exists(path):
338 os.remove(path)
339
340
341def mv(src_path, dst_path):
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400342 if os.path.exists(dst_path):
Alan Viverettecd3de262017-08-14 09:51:30 -0400343 rm(dst_path)
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400344 if not os.path.exists(os.path.dirname(dst_path)):
345 os.makedirs(os.path.dirname(dst_path))
Alan Viverette45837092017-05-12 14:50:53 -0400346 os.rename(src_path, dst_path)
347
348
Jeff Gastonc302bb92018-03-23 13:53:48 -0400349def detect_artifacts(maven_repo_dirs):
Alan Viveretted4527e62017-05-11 15:03:25 -0400350 maven_lib_info = {}
351
Dan Willemsen814152e2017-11-06 13:22:11 -0800352 # Find the latest revision for each artifact, remove others
Jeff Gastonc302bb92018-03-23 13:53:48 -0400353 for repo_dir in maven_repo_dirs:
Dan Willemsen814152e2017-11-06 13:22:11 -0800354 for root, dirs, files in os.walk(repo_dir):
355 for file in files:
Alan Viverettec960cfb2017-12-04 13:09:22 -0500356 if file[-4:] == ".pom":
357 # Read the POM (hack hack hack).
358 group_id = ''
359 artifact_id = ''
360 version = ''
361 file = os.path.join(root, file)
362 with open(file) as pom_file:
363 for line in pom_file:
364 if line[:11] == ' <groupId>':
365 group_id = line[11:-11]
366 elif line[:14] == ' <artifactId>':
367 artifact_id = line[14:-14]
368 elif line[:11] == ' <version>':
369 version = line[11:-11]
370 if group_id == '' or artifact_id == '' or version == '':
371 print_e('Failed to find Maven artifact data in ' + file)
372 continue
Alan Viverette95f6d362017-04-06 09:40:50 -0400373
Alan Viverettec960cfb2017-12-04 13:09:22 -0500374 # Locate the artifact.
375 artifact_file = file[:-4]
376 if os.path.exists(artifact_file + '.jar'):
377 artifact_file = artifact_file + '.jar'
378 elif os.path.exists(artifact_file + '.aar'):
379 artifact_file = artifact_file + '.aar'
380 else:
381 print_e('Failed to find artifact for ' + artifact_file)
382 continue
383
384 # Make relative to root.
385 artifact_file = artifact_file[len(root) + 1:]
386
387 # Find the mapping.
388 group_artifact = group_id + ':' + artifact_id
Jeff Gaston3e622ba2018-03-26 23:24:46 -0400389 if group_artifact in maven_to_make:
Alan Viverettec960cfb2017-12-04 13:09:22 -0500390 key = group_artifact
Jeff Gaston3e622ba2018-03-26 23:24:46 -0400391 elif artifact_id in maven_to_make:
392 key = artifact_id
Alan Viverettec960cfb2017-12-04 13:09:22 -0500393 else:
394 print_e('Failed to find artifact mapping for ' + group_artifact)
395 continue
396
397 # Store the latest version.
398 version = LooseVersion(version)
399 if key not in maven_lib_info \
400 or version > maven_lib_info[key].version:
401 maven_lib_info[key] = MavenLibraryInfo(key, group_id, artifact_id, version,
402 root, repo_dir, artifact_file)
Alan Viverette95f6d362017-04-06 09:40:50 -0400403
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400404 return maven_lib_info
405
406
Jeff Gaston1cc06092018-03-28 15:51:02 -0400407def transform_maven_repos(maven_repo_dirs, transformed_dir, extract_res=True, include_static_deps=False):
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400408 cwd = os.getcwd()
409
410 # Use a temporary working directory.
Jeff Gastonc302bb92018-03-23 13:53:48 -0400411 maven_lib_info = detect_artifacts(maven_repo_dirs)
Jeff Gastona68a8d42018-03-23 14:00:13 -0400412 working_dir = temp_dir
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400413
Alan Viverettec960cfb2017-12-04 13:09:22 -0500414 if not maven_lib_info:
415 print_e('Failed to detect artifacts')
416 return False
417
Jeff Gastonc302bb92018-03-23 13:53:48 -0400418 # extract some files (for example, AndroidManifest.xml) from any relevant artifacts
Alan Viveretted4527e62017-05-11 15:03:25 -0400419 for info in maven_lib_info.values():
Alan Viveretted8ce7222017-12-11 17:24:43 -0500420 transform_maven_lib(working_dir, info, extract_res)
Dan Willemsen814152e2017-11-06 13:22:11 -0800421
Jeff Gastonc302bb92018-03-23 13:53:48 -0400422 # generate a single Android.mk that specifies to use all of the above artifacts
Alan Viverette4ec9a172018-02-20 16:19:31 -0500423 makefile = os.path.join(working_dir, 'Android.mk')
424 with open(makefile, 'w') as f:
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400425 args = ["pom2mk", "-sdk-version", "current"]
Jeff Gaston1cc06092018-03-28 15:51:02 -0400426 if include_static_deps:
427 args.append("-static-deps")
Jeff Gaston7ec1d8f2018-03-27 00:25:12 -0400428 rewriteNames = [name for name in maven_to_make if ":" in name] + [name for name in maven_to_make if ":" not in name]
429 args.extend(["-rewrite=^" + name + "$=" + maven_to_make[name][0] for name in rewriteNames])
Jeff Gaston7ec1d8f2018-03-27 00:25:12 -0400430 args.extend(["."])
Dan Willemsen814152e2017-11-06 13:22:11 -0800431 subprocess.check_call(args, stdout=f, cwd=working_dir)
Alan Viverette95f6d362017-04-06 09:40:50 -0400432
Jeff Gastonf12f3ce2018-03-23 16:41:24 -0400433 global rerun_extract_deps
434 rerun_extract_deps = True
Alan Viverette4ec9a172018-02-20 16:19:31 -0500435
Alan Viverette95f6d362017-04-06 09:40:50 -0400436 # Replace the old directory.
Jeff Gastonc302bb92018-03-23 13:53:48 -0400437 output_dir = os.path.join(cwd, transformed_dir)
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400438 mv(working_dir, output_dir)
Alan Viverettec960cfb2017-12-04 13:09:22 -0500439 return True
Alan Viverette95f6d362017-04-06 09:40:50 -0400440
Jeff Gastonc302bb92018-03-23 13:53:48 -0400441# 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 -0500442def transform_maven_lib(working_dir, artifact_info, extract_res):
Dan Willemsen814152e2017-11-06 13:22:11 -0800443 # Move library into working dir
Jeff Gastonc302bb92018-03-23 13:53:48 -0400444 new_dir = os.path.join(working_dir, os.path.relpath(artifact_info.dir, artifact_info.repo_dir))
445 mv(artifact_info.dir, new_dir)
Dan Willemsen814152e2017-11-06 13:22:11 -0800446
447 for dirpath, dirs, files in os.walk(new_dir):
448 for f in files:
449 if '-sources.jar' in f:
450 os.remove(os.path.join(dirpath, f))
451
Alan Viverettec960cfb2017-12-04 13:09:22 -0500452 matcher = artifact_pattern.match(artifact_info.file)
453 maven_lib_name = artifact_info.key
Alan Viveretted4527e62017-05-11 15:03:25 -0400454 maven_lib_vers = matcher.group(2)
Alan Viverettec960cfb2017-12-04 13:09:22 -0500455 maven_lib_type = artifact_info.file[-3:]
Alan Viveretted4527e62017-05-11 15:03:25 -0400456
Alan Viverettec960cfb2017-12-04 13:09:22 -0500457 make_lib_name = maven_to_make[artifact_info.key][0]
458 make_dir_name = maven_to_make[artifact_info.key][1]
Alan Viveretted4527e62017-05-11 15:03:25 -0400459
Alan Viverette129555e2018-01-30 09:57:57 -0500460 artifact_file = os.path.join(new_dir, artifact_info.file)
461
Dan Willemsen814152e2017-11-06 13:22:11 -0800462 if extract_res:
Dan Willemsen814152e2017-11-06 13:22:11 -0800463 target_dir = os.path.join(working_dir, make_dir_name)
464 if not os.path.exists(target_dir):
465 os.makedirs(target_dir)
466
467 if maven_lib_type == "aar":
Alan Viverettec960cfb2017-12-04 13:09:22 -0500468 process_aar(artifact_file, target_dir)
Alan Viveretted4527e62017-05-11 15:03:25 -0400469
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400470 with zipfile.ZipFile(artifact_file) as zip:
471 manifests_dir = os.path.join(working_dir, "manifests")
472 zip.extract("AndroidManifest.xml", os.path.join(manifests_dir, make_lib_name))
Dan Willemsend677b602017-11-08 22:13:17 -0800473
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500474 print(maven_lib_vers, ":", maven_lib_name, "->", make_lib_name)
Alan Viveretted4527e62017-05-11 15:03:25 -0400475
Alan Viverette95f6d362017-04-06 09:40:50 -0400476
Alan Viverettec960cfb2017-12-04 13:09:22 -0500477def process_aar(artifact_file, target_dir):
Alan Viverette95f6d362017-04-06 09:40:50 -0400478 # Extract AAR file to target_dir.
479 with zipfile.ZipFile(artifact_file) as zip:
480 zip.extractall(target_dir)
481
Dan Willemsen814152e2017-11-06 13:22:11 -0800482 # Remove classes.jar
Alan Viverette95f6d362017-04-06 09:40:50 -0400483 classes_jar = os.path.join(target_dir, "classes.jar")
484 if os.path.exists(classes_jar):
Dan Willemsen814152e2017-11-06 13:22:11 -0800485 os.remove(classes_jar)
Alan Viverette95f6d362017-04-06 09:40:50 -0400486
487 # Remove or preserve empty dirs.
488 for root, dirs, files in os.walk(target_dir):
489 for dir in dirs:
490 dir_path = os.path.join(root, dir)
491 if not os.listdir(dir_path):
492 os.rmdir(dir_path)
493
494 # Remove top-level cruft.
495 for file in blacklist_files:
496 file_path = os.path.join(target_dir, file)
497 if os.path.exists(file_path):
498 os.remove(file_path)
499
Alan Viverettef17c9402017-07-19 12:57:40 -0400500
Alan Viverettecd3de262017-08-14 09:51:30 -0400501def fetch_artifact(target, build_id, artifact_path):
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500502 print('Fetching %s from %s...' % (artifact_path, target))
Alan Viverettecd3de262017-08-14 09:51:30 -0400503 fetch_cmd = [FETCH_ARTIFACT, '--bid', str(build_id), '--target', target, artifact_path]
Alan Viverette45837092017-05-12 14:50:53 -0400504 try:
Alan Viverettecd3de262017-08-14 09:51:30 -0400505 subprocess.check_output(fetch_cmd, stderr=subprocess.STDOUT)
Alan Viverette45837092017-05-12 14:50:53 -0400506 except subprocess.CalledProcessError:
Jeff Gaston13e38412018-02-06 14:45:36 -0500507 print_e('FAIL: Unable to retrieve %s artifact for build ID %s' % (artifact_path, build_id))
Alan Viverettec1c32b62017-12-20 09:40:36 -0500508 print_e('Please make sure you are authenticated for build server access!')
Alan Viverette45837092017-05-12 14:50:53 -0400509 return None
510 return artifact_path
511
512
Alan Viverette129555e2018-01-30 09:57:57 -0500513def extract_artifact(artifact_path):
Alan Viverette45837092017-05-12 14:50:53 -0400514 # Unzip the repo archive into a separate directory.
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400515 repo_dir = os.path.basename(artifact_path)[:-4]
Alan Viverette45837092017-05-12 14:50:53 -0400516 with zipfile.ZipFile(artifact_path) as zipFile:
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400517 zipFile.extractall(repo_dir)
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400518 return repo_dir
519
520
Alan Viverette7e897e22018-03-09 15:24:10 -0500521def fetch_and_extract(target, build_id, file, artifact_path=None):
522 if not artifact_path:
523 artifact_path = fetch_artifact(target, build_id, file)
Alan Viverette129555e2018-01-30 09:57:57 -0500524 if not artifact_path:
525 return None
526 return extract_artifact(artifact_path)
527
528
Alan Viverette7e897e22018-03-09 15:24:10 -0500529def update_support(target, build_id, local_file):
530 if build_id:
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400531 repo_file = 'top-of-tree-m2repository-dejetified-%s.zip' % build_id.fs_id
Alan Viverette7e897e22018-03-09 15:24:10 -0500532 repo_dir = fetch_and_extract(target, build_id.url_id, repo_file, None)
533 else:
534 repo_dir = fetch_and_extract(target, None, None, local_file)
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400535 if not repo_dir:
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500536 print_e('Failed to extract Support Library repository')
Alan Viverettef48d9b42017-08-17 14:45:46 -0400537 return False
Alan Viverette45837092017-05-12 14:50:53 -0400538
539 # Transform the repo archive into a Makefile-compatible format.
Jeff Gaston1cc06092018-03-28 15:51:02 -0400540 return transform_maven_repos([repo_dir], support_dir, extract_res=True, include_static_deps=True)
Alan Viverettec960cfb2017-12-04 13:09:22 -0500541
Alan Viverette7e897e22018-03-09 15:24:10 -0500542
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400543def update_androidx(target, target_toolkit, build_id, local_file):
544 if build_id:
545 repo_file = 'top-of-tree-m2repository-%s.zip' % build_id.fs_id
546 repo_dir = fetch_and_extract(target, build_id.url_id, repo_file, None)
547 else:
548 repo_dir = fetch_and_extract(target, None, None, local_file)
549 if not repo_dir:
550 print_e('Failed to extract AndroidX repository')
551 return False
552
553 if build_id:
554 repo_file2 = 'top-of-tree-m2repository-%s.zip' % build_id.fs_id
555 repo_dir2 = fetch_and_extract(target_toolkit, build_id.url_id, repo_file2, None)
556 else:
557 repo_dir2 = fetch_and_extract(target_toolkit, None, None, local_file)
558 if not repo_dir2:
559 print_e('Failed to extract AndroidX app-toolkit repository')
560 return False
561
562 # Transform the repo archive into a Makefile-compatible format.
563 return transform_maven_repos([repo_dir, repo_dir2], androidx_dir, extract_res=False)
564
565
Jeff Gaston782c3e32018-02-06 14:36:17 -0500566def update_jetifier(target, build_id):
567 repo_file = 'jetifier-standalone.zip'
568 repo_dir = fetch_and_extract(target, build_id.url_id, repo_file)
569 if not repo_dir:
570 print_e('Failed to extract Jetifier')
571 return False
572
573 rm(jetifier_dir)
Jeff Gaston553a4372018-03-29 18:34:22 -0400574 mv(os.path.join(repo_dir, 'jetifier-standalone'), jetifier_dir)
575 os.chmod(os.path.join(jetifier_dir, 'bin', 'jetifier-standalone'), 0o755)
Jeff Gaston782c3e32018-02-06 14:36:17 -0500576 return True
577
Alan Viverette7e897e22018-03-09 15:24:10 -0500578
Alan Viverettec960cfb2017-12-04 13:09:22 -0500579def update_toolkit(target, build_id):
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400580 repo_dir = fetch_and_extract(target, build_id.url_id, \
581 'top-of-tree-m2repository-dejetified-%s.zip' % build_id.fs_id)
Alan Viverettec960cfb2017-12-04 13:09:22 -0500582 if not repo_dir:
583 print_e('Failed to extract App Toolkit repository')
584 return False
585
586 # Transform the repo archive into a Makefile-compatible format.
Jeff Gaston1cc06092018-03-28 15:51:02 -0400587 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 -0400588
589
590def update_constraint(target, build_id):
Jeff Gaston13e38412018-02-06 14:45:36 -0500591 layout_dir = fetch_and_extract(target, build_id.url_id,
592 'com.android.support.constraint-constraint-layout-%s.zip' % build_id.fs_id)
593 solver_dir = fetch_and_extract(target, build_id.url_id,
594 'com.android.support.constraint-constraint-layout-solver-%s.zip' % build_id.fs_id)
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400595 if not layout_dir or not solver_dir:
Alan Viverettec960cfb2017-12-04 13:09:22 -0500596 print_e('Failed to extract Constraint Layout repositories')
Alan Viverettecd3de262017-08-14 09:51:30 -0400597 return False
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400598
599 # Passing False here is an inelegant solution, but it means we can replace
600 # the top-level directory without worrying about other child directories.
Jeff Gastonc302bb92018-03-23 13:53:48 -0400601 return transform_maven_repos([layout_dir, solver_dir],
Alan Viverettec960cfb2017-12-04 13:09:22 -0500602 os.path.join(extras_dir, 'constraint-layout'), extract_res=False)
Alan Viverette45837092017-05-12 14:50:53 -0400603
604
Alan Viverette129555e2018-01-30 09:57:57 -0500605def update_design(file):
606 design_dir = extract_artifact(file)
607 if not design_dir:
608 print_e('Failed to extract Design Library repositories')
609 return False
610
611 # Don't bother extracting resources -- this should only be used with AAPT2.
Jeff Gastonc302bb92018-03-23 13:53:48 -0400612 return transform_maven_repos([design_dir],
Alan Viverette129555e2018-01-30 09:57:57 -0500613 os.path.join(extras_dir, 'material-design'), extract_res=False)
614
615
Jeff Gaston6e7e7502018-04-04 00:22:45 -0400616def update_material(file):
617 design_dir = extract_artifact(file)
618 if not design_dir:
619 print_e('Failed to extract intermediate-AndroidX Design Library repositories')
620 return False
621
622 # Don't bother extracting resources -- this should only be used with AAPT2.
623 return transform_maven_repos([design_dir],
624 os.path.join(extras_dir, 'material-design-x'), extract_res=False)
625
626
Alan Viverette45837092017-05-12 14:50:53 -0400627def extract_to(zip_file, paths, filename, parent_path):
Alan Viverettec1c32b62017-12-20 09:40:36 -0500628 zip_path = next(filter(lambda path: filename in path, paths))
Alan Viverette45837092017-05-12 14:50:53 -0400629 src_path = zip_file.extract(zip_path)
630 dst_path = path(parent_path, filename)
631 mv(src_path, dst_path)
632
633
Anton Hansson9709fd42018-04-03 16:52:13 +0100634def fetch_framework_artifacts(target, build_id, target_path, is_current_sdk):
Alan Viverette45837092017-05-12 14:50:53 -0400635 platform = 'darwin' if 'mac' in target else 'linux'
Alan Viverettecd3de262017-08-14 09:51:30 -0400636 artifact_path = fetch_artifact(
Jeff Gaston13e38412018-02-06 14:45:36 -0500637 target, build_id.url_id, 'sdk-repo-%s-platforms-%s.zip' % (platform, build_id.fs_id))
Alan Viverette45837092017-05-12 14:50:53 -0400638 if not artifact_path:
Alan Viverettecd3de262017-08-14 09:51:30 -0400639 return False
Alan Viverette45837092017-05-12 14:50:53 -0400640
641 with zipfile.ZipFile(artifact_path) as zipFile:
642 paths = zipFile.namelist()
643
Anton Hansson9709fd42018-04-03 16:52:13 +0100644 filenames = ['android.jar', 'uiautomator.jar', 'framework.aidl',
645 'optional/android.test.base.jar', 'optional/android.test.mock.jar',
646 'optional/android.test.runner.jar']
Alan Viverette45837092017-05-12 14:50:53 -0400647
Anton Hansson9709fd42018-04-03 16:52:13 +0100648 for filename in filenames:
649 extract_to(zipFile, paths, filename, target_path)
Jiyong Parkb773d292018-01-30 23:33:19 +0900650
Anton Hansson9709fd42018-04-03 16:52:13 +0100651 if is_current_sdk:
652 # There's no system version of framework.aidl, so use the public one.
653 extract_to(zipFile, paths, 'framework.aidl', system_path)
Jiyong Parkb773d292018-01-30 23:33:19 +0900654
Anton Hansson9709fd42018-04-03 16:52:13 +0100655 # We don't keep historical artifacts for these.
656 artifact_path = fetch_artifact(target, build_id.fs_id, 'core.current.stubs.jar')
657 if not artifact_path:
658 return False
659 mv(artifact_path, path(current_path, 'core.jar'))
660
Alan Viverettecd3de262017-08-14 09:51:30 -0400661 return True
Alan Viverette45837092017-05-12 14:50:53 -0400662
663
Anton Hansson9709fd42018-04-03 16:52:13 +0100664def update_sdk_repo(target, build_id):
665 return fetch_framework_artifacts(target, build_id, current_path, is_current_sdk = True)
666
667
Alan Viverettecd3de262017-08-14 09:51:30 -0400668def update_system(target, build_id):
Jeff Gaston13e38412018-02-06 14:45:36 -0500669 artifact_path = fetch_artifact(target, build_id.url_id, 'android_system.jar')
Alan Viverette45837092017-05-12 14:50:53 -0400670 if not artifact_path:
Alan Viverettecd3de262017-08-14 09:51:30 -0400671 return False
Alan Viverette45837092017-05-12 14:50:53 -0400672
673 mv(artifact_path, path(system_path, 'android.jar'))
Paul Duffin960e1ee2017-12-21 08:50:14 +0000674
Jeff Gaston13e38412018-02-06 14:45:36 -0500675 artifact_path = fetch_artifact(target, build_id.url_id, 'android.test.mock.stubs_system.jar')
Paul Duffin960e1ee2017-12-21 08:50:14 +0000676 if not artifact_path:
677 return False
678
679 mv(artifact_path, path(system_path, 'optional/android.test.mock.jar'))
680
Alan Viverettecd3de262017-08-14 09:51:30 -0400681 return True
682
683
Anton Hansson9709fd42018-04-03 16:52:13 +0100684
685def finalize_sdk(target, build_id, sdk_version):
686 target_finalize_dir = "%d" % sdk_version
687
688 artifact_to_path = {
689 'android_system.jar': path(target_finalize_dir, 'android_system.jar'),
690 'public_api.txt': path(api_path, "%d.txt" % sdk_version),
691 'system-api.txt': path(system_api_path, "%d.txt" % sdk_version),
692 }
693
694 for artifact, target_path in artifact_to_path.items():
695 artifact_path = fetch_artifact(target, build_id.url_id, artifact)
696 if not artifact_path:
697 return False
698 mv(artifact_path, target_path)
699
700 return fetch_framework_artifacts(target, build_id, target_finalize_dir, is_current_sdk = False)
701
702
Alan Viverettec1c32b62017-12-20 09:40:36 -0500703def update_buildtools(target, arch, build_id):
Jeff Gaston13e38412018-02-06 14:45:36 -0500704 artifact_path = fetch_and_extract(target, build_id.url_id,
705 "sdk-repo-%s-build-tools-%s.zip" % (arch, build_id.fs_id))
Alan Viverettec1c32b62017-12-20 09:40:36 -0500706 if not artifact_path:
707 return False
708
709 top_level_dir = os.listdir(artifact_path)[0]
710 src_path = os.path.join(artifact_path, top_level_dir)
711 dst_path = path(buildtools_dir, arch)
712 mv(src_path, dst_path)
713
714 # Move all top-level files to /bin and make them executable
715 bin_path = path(dst_path, 'bin')
716 top_level_files = filter(lambda e: os.path.isfile(path(dst_path, e)), os.listdir(dst_path))
717 for file in top_level_files:
718 src_file = path(dst_path, file)
719 dst_file = path(bin_path, file)
720 mv(src_file, dst_file)
721 os.chmod(dst_file, 0o755)
722
723 # Remove renderscript
724 rm(path(dst_path, 'renderscript'))
725
726 return True
727
728
Alan Viverettecd3de262017-08-14 09:51:30 -0400729def append(text, more_text):
730 if text:
731 return "%s, %s" % (text, more_text)
732 return more_text
Alan Viverette45837092017-05-12 14:50:53 -0400733
Alan Viverette95f6d362017-04-06 09:40:50 -0400734
Jeff Gaston13e38412018-02-06 14:45:36 -0500735class buildId(object):
736 def __init__(self, url_id, fs_id):
737 # id when used in build server urls
738 self.url_id = url_id
739 # id when used in build commands
740 self.fs_id = fs_id
741
Jeff Gastonb9b09052018-02-05 14:16:05 -0500742def getBuildId(args):
Jeff Gaston13e38412018-02-06 14:45:36 -0500743 # must be in the format 12345 or P12345
Jeff Gastonb9b09052018-02-05 14:16:05 -0500744 source = args.source
Jeff Gaston13e38412018-02-06 14:45:36 -0500745 number_text = source[:]
746 presubmit = False
747 if number_text.startswith("P"):
748 presubmit = True
749 number_text = number_text[1:]
750 if not number_text.isnumeric():
Alan Viverette7e897e22018-03-09 15:24:10 -0500751 return None
Jeff Gaston13e38412018-02-06 14:45:36 -0500752 url_id = source
753 fs_id = url_id
754 if presubmit:
755 fs_id = "0"
756 args.file = False
757 return buildId(url_id, fs_id)
Jeff Gastonb9b09052018-02-05 14:16:05 -0500758
Colin Cross573e1212018-02-12 14:59:52 -0800759def getFile(args):
760 source = args.source
761 if not source.isnumeric():
762 return args.source
Alan Viverette7e897e22018-03-09 15:24:10 -0500763 return None
Colin Cross573e1212018-02-12 14:59:52 -0800764
Alan Viverette4ec9a172018-02-20 16:19:31 -0500765
766def script_relative(rel_path):
Jeff Gastona68a8d42018-03-23 14:00:13 -0400767 return os.path.join(script_dir, rel_path)
Alan Viverette4ec9a172018-02-20 16:19:31 -0500768
769
Jeff Gastoncc296a82018-03-23 14:33:24 -0400770def uncommittedChangesExist():
771 try:
772 # Make sure we don't overwrite any pending changes.
773 diffCommand = "cd " + git_dir + " && git diff --quiet"
774 subprocess.check_call(diffCommand, shell=True)
775 subprocess.check_call(diffCommand + " --cached", shell=True)
776 return False
777 except subprocess.CalledProcessError:
778 return True
779
780
Jeff Gastona7fba9b2018-03-26 23:48:51 -0400781rm(temp_dir)
Alan Viveretted4527e62017-05-11 15:03:25 -0400782parser = argparse.ArgumentParser(
Alan Viverette45837092017-05-12 14:50:53 -0400783 description=('Update current prebuilts'))
Alan Viveretted4527e62017-05-11 15:03:25 -0400784parser.add_argument(
Alan Viverette129555e2018-01-30 09:57:57 -0500785 'source',
786 help='Build server build ID or local Maven ZIP file')
787parser.add_argument(
788 '-d', '--design', action="store_true",
789 help='If specified, updates only the Design Library')
Alan Viveretted4527e62017-05-11 15:03:25 -0400790parser.add_argument(
Jeff Gaston6e7e7502018-04-04 00:22:45 -0400791 '-m', '--material', action="store_true",
792 help='If specified, updates only the intermediate-AndroidX Design Library')
793parser.add_argument(
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400794 '-c', '--constraint', action="store_true",
795 help='If specified, updates only Constraint Layout')
796parser.add_argument(
Alan Viverette5bfe05b2017-06-06 14:21:29 -0400797 '-s', '--support', action="store_true",
798 help='If specified, updates only the Support Library')
Alan Viverette45837092017-05-12 14:50:53 -0400799parser.add_argument(
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400800 '-x', '--androidx', action="store_true",
801 help='If specified, updates only AndroidX')
802parser.add_argument(
Jeff Gaston782c3e32018-02-06 14:36:17 -0500803 '-j', '--jetifier', action="store_true",
804 help='If specified, updates only Jetifier')
805parser.add_argument(
Alan Viverettec960cfb2017-12-04 13:09:22 -0500806 '-t', '--toolkit', action="store_true",
807 help='If specified, updates only the App Toolkit')
808parser.add_argument(
Alan Viverette5bfe05b2017-06-06 14:21:29 -0400809 '-p', '--platform', action="store_true",
810 help='If specified, updates only the Android Platform')
Alan Viverettec1c32b62017-12-20 09:40:36 -0500811parser.add_argument(
Anton Hansson9709fd42018-04-03 16:52:13 +0100812 '-f', '--finalize_sdk', type=int,
813 help='If specified, imports the source build as the specified finalized SDK version')
814parser.add_argument(
Alan Viverettec1c32b62017-12-20 09:40:36 -0500815 '-b', '--buildtools', action="store_true",
816 help='If specified, updates only the Build Tools')
Jeff Gastoncc296a82018-03-23 14:33:24 -0400817parser.add_argument(
818 '--commit-first', action="store_true",
819 help='If specified, then if uncommited changes exist, commit before continuing')
Alan Viveretted4527e62017-05-11 15:03:25 -0400820args = parser.parse_args()
Jeff Gaston56fe2762018-02-06 14:54:37 -0500821args.file = True
Alan Viverette129555e2018-01-30 09:57:57 -0500822if not args.source:
823 parser.error("You must specify a build ID or local Maven ZIP file")
Alan Viveretted4527e62017-05-11 15:03:25 -0400824 sys.exit(1)
Alan Viverette129555e2018-01-30 09:57:57 -0500825if not (args.support or args.platform or args.constraint or args.toolkit or args.buildtools \
Anton Hansson9709fd42018-04-03 16:52:13 +0100826 or args.design or args.jetifier or args.androidx or args.material \
827 or args.finalize_sdk):
Alan Viverettec1c32b62017-12-20 09:40:36 -0500828 parser.error("You must specify at least one target to update")
Alan Viverettecd3de262017-08-14 09:51:30 -0400829 sys.exit(1)
Jeff Gaston6e7e7502018-04-04 00:22:45 -0400830if (args.support or args.constraint or args.toolkit or args.design or args.material) \
831 and which('pom2mk') is None:
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500832 parser.error("Cannot find pom2mk in path; please run lunch to set up build environment")
833 sys.exit(1)
Alan Viveretted4527e62017-05-11 15:03:25 -0400834
Jeff Gastoncc296a82018-03-23 14:33:24 -0400835if uncommittedChangesExist():
836 if args.commit_first:
837 subprocess.check_call("cd " + git_dir + " && git add -u", shell=True)
838 subprocess.check_call("cd " + git_dir + " && git commit -m 'save working state'", shell=True)
839
840if uncommittedChangesExist():
841 print_e('FAIL: There are uncommitted changes here. Please commit or stash before continuing, because update_current.py will run "git reset --hard" if execution fails')
Alan Viveretted4527e62017-05-11 15:03:25 -0400842 sys.exit(1)
843
844try:
Alan Viverettecd3de262017-08-14 09:51:30 -0400845 components = None
846 if args.constraint:
Jeff Gastonb9b09052018-02-05 14:16:05 -0500847 if update_constraint('studio', getBuildId(args)):
Alan Viverettecd3de262017-08-14 09:51:30 -0400848 components = append(components, 'Constraint Layout')
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500849 print_e('Failed to update Constraint Layout, aborting...')
Alan Viverettecd3de262017-08-14 09:51:30 -0400850 else:
851 sys.exit(1)
852 if args.support:
Alan Viverette7e897e22018-03-09 15:24:10 -0500853 if update_support('support_library', getBuildId(args), getFile(args)):
Alan Viverettecd3de262017-08-14 09:51:30 -0400854 components = append(components, 'Support Library')
855 else:
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500856 print_e('Failed to update Support Library, aborting...')
Alan Viverettecd3de262017-08-14 09:51:30 -0400857 sys.exit(1)
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400858 if args.androidx:
859 if update_androidx('support_library', 'support_library_app_toolkit', \
860 getBuildId(args), getFile(args)):
861 components = append(components, 'AndroidX')
862 else:
863 print_e('Failed to update AndroidX, aborting...')
864 sys.exit(1)
Jeff Gaston782c3e32018-02-06 14:36:17 -0500865 if args.jetifier:
866 if update_jetifier('support_library', getBuildId(args)):
867 components = append(components, 'Jetifier')
868 else:
869 print_e('Failed to update Jetifier, aborting...')
870 sys.exit(1)
Alan Viverettec960cfb2017-12-04 13:09:22 -0500871 if args.toolkit:
Jeff Gastonb9b09052018-02-05 14:16:05 -0500872 if update_toolkit('support_library_app_toolkit', getBuildId(args)):
Alan Viverettec960cfb2017-12-04 13:09:22 -0500873 components = append(components, 'App Toolkit')
874 else:
875 print_e('Failed to update App Toolkit, aborting...')
876 sys.exit(1)
Alan Viverettecd3de262017-08-14 09:51:30 -0400877 if args.platform:
Jeff Gastonb9b09052018-02-05 14:16:05 -0500878 if update_sdk_repo('sdk_phone_armv7-sdk_mac', getBuildId(args)) \
879 and update_system('sdk_phone_armv7-sdk_mac', getBuildId(args)):
Alan Viverettecd3de262017-08-14 09:51:30 -0400880 components = append(components, 'platform SDK')
881 else:
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500882 print_e('Failed to update platform SDK, aborting...')
Alan Viverettecd3de262017-08-14 09:51:30 -0400883 sys.exit(1)
Anton Hansson9709fd42018-04-03 16:52:13 +0100884 if args.finalize_sdk:
885 if finalize_sdk('sdk_phone_armv7-sdk_mac', getBuildId(args), args.finalize_sdk):
886 subprocess.check_call(['git', 'add', "%d" % args.finalize_sdk])
887 components = append(components, 'finalized SDK %d' % args.finalize_sdk)
888 else:
889 print_e('Failed to finalize SDK %d, aborting...' % args.finalize_sdk)
890 sys.exit(1)
Alan Viverette129555e2018-01-30 09:57:57 -0500891 if args.design:
Colin Cross573e1212018-02-12 14:59:52 -0800892 if update_design(getFile(args)):
Alan Viverette129555e2018-01-30 09:57:57 -0500893 components = append(components, 'Design Library')
894 else:
Jeff Gaston6e7e7502018-04-04 00:22:45 -0400895 print_e('Failed to update Design Library, aborting...')
896 sys.exit(1)
897 if args.material:
898 if update_material(getFile(args)):
899 components = append(components, 'intermediate-AndroidX Design Library')
900 else:
901 print_e('Failed to update intermediate-AndroidX Design Library, aborting...')
Alan Viverette129555e2018-01-30 09:57:57 -0500902 sys.exit(1)
Alan Viverettec1c32b62017-12-20 09:40:36 -0500903 if args.buildtools:
Jeff Gastonb9b09052018-02-05 14:16:05 -0500904 if update_buildtools('sdk_phone_armv7-sdk_mac', 'darwin', getBuildId(args)) \
905 and update_buildtools('sdk_phone_x86_64-sdk', 'linux', getBuildId(args)) \
906 and update_buildtools('sdk_phone_armv7-win_sdk', 'windows', getBuildId(args)):
Alan Viverettec1c32b62017-12-20 09:40:36 -0500907 components = append(components, 'build tools')
908 else:
909 print_e('Failed to update build tools, aborting...')
910 sys.exit(1)
Jeff Gastonf12f3ce2018-03-23 16:41:24 -0400911 if rerun_extract_deps:
Jeff Gastonb70daa92018-03-29 20:10:22 -0400912 depsfile = os.path.join(current_path, 'fix_dependencies.mk')
Jeff Gastonf12f3ce2018-03-23 16:41:24 -0400913 with open(depsfile, 'w') as f:
Jeff Gastonb70daa92018-03-29 20:10:22 -0400914 cwd=os.getcwd()
Anton Hansson9709fd42018-04-03 16:52:13 +0100915 subprocess.check_call(['./update_current/extract_deps.py',
916 'current/*/Android.mk',
917 'current/extras/*/Android.mk'],
918 stdout=f, cwd=cwd, shell=True)
Jeff Gastonb70daa92018-03-29 20:10:22 -0400919 subprocess.check_call(['git', 'add', depsfile])
920
Jeff Gastonf12f3ce2018-03-23 16:41:24 -0400921
Alan Viveretted4527e62017-05-11 15:03:25 -0400922
Anton Hansson9709fd42018-04-03 16:52:13 +0100923 subprocess.check_call(['git', 'add', current_path, system_path, api_path, system_api_path,
924 buildtools_dir])
Colin Cross573e1212018-02-12 14:59:52 -0800925 if not args.source.isnumeric():
Alan Viverette129555e2018-01-30 09:57:57 -0500926 src_msg = "local Maven ZIP"
927 else:
Jeff Gaston13e38412018-02-06 14:45:36 -0500928 src_msg = "build %s" % (getBuildId(args).url_id)
Alan Viverette129555e2018-01-30 09:57:57 -0500929 msg = "Import %s from %s\n\n%s" % (components, src_msg, flatten(sys.argv))
Alan Viveretted4527e62017-05-11 15:03:25 -0400930 subprocess.check_call(['git', 'commit', '-m', msg])
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500931 print('Remember to test this change before uploading it to Gerrit!')
Alan Viveretted4527e62017-05-11 15:03:25 -0400932
933finally:
934 # Revert all stray files, including the downloaded zip.
935 try:
936 with open(os.devnull, 'w') as bitbucket:
937 subprocess.check_call(['git', 'add', '-Af', '.'], stdout=bitbucket)
938 subprocess.check_call(
939 ['git', 'commit', '-m', 'COMMIT TO REVERT - RESET ME!!!'], stdout=bitbucket)
940 subprocess.check_call(['git', 'reset', '--hard', 'HEAD~1'], stdout=bitbucket)
941 except subprocess.CalledProcessError:
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500942 print_e('ERROR: Failed cleaning up, manual cleanup required!!!')