blob: 6dd38686dadf3031bdc7e9eb99f6be0bd36b379f [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'
Anton Hansson9709fd42018-04-03 16:52:13 +010014api_path = 'api'
15system_api_path = 'system-api'
Anton Hansson1d01a032018-04-09 10:29:37 +010016framework_sdk_target = 'sdk_phone_armv7-sdk_mac'
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
Alan Viverettecd3de262017-08-14 09:51:30 -040027# See go/fetch_artifact for details on this script.
Alan Viveretted4527e62017-05-11 15:03:25 -040028FETCH_ARTIFACT = '/google/data/ro/projects/android/fetch_artifact'
29
Alan Viverette95f6d362017-04-06 09:40:50 -040030maven_to_make = {
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -040031 # Support Library
32 'com.android.support:animated-vector-drawable': ['android-support-animatedvectordrawable', 'graphics/drawable'],
33 'com.android.support:appcompat-v7': ['android-support-v7-appcompat', 'v7/appcompat'],
34 'com.android.support:cardview-v7': ['android-support-v7-cardview', 'v7/cardview'],
35 'com.android.support:collections': ['android-support-collections', 'collections', 'jar'],
36 'com.android.support:customtabs': ['android-support-customtabs', 'customtabs'],
37 'com.android.support:exifinterface': ['android-support-exifinterface', 'exifinterface'],
38 'com.android.support:gridlayout-v7': ['android-support-v7-gridlayout', 'v7/gridlayout'],
39 'com.android.support:leanback-v17': ['android-support-v17-leanback', 'v17/leanback'],
40 'com.android.support:mediarouter-v7': ['android-support-v7-mediarouter', 'v7/mediarouter'],
41 'com.android.support:palette-v7': ['android-support-v7-palette', 'v7/palette'],
42 'com.android.support:percent': ['android-support-percent', 'percent'],
43 'com.android.support:preference-leanback-v17': ['android-support-v17-preference-leanback', 'v17/preference-leanback'],
44 'com.android.support:preference-v14': ['android-support-v14-preference', 'v14/preference'],
45 'com.android.support:preference-v7': ['android-support-v7-preference', 'v7/preference'],
46 'com.android.support:recommendation': ['android-support-recommendation', 'recommendation'],
47 'com.android.support:recyclerview-v7': ['android-support-v7-recyclerview', 'v7/recyclerview'],
48 'com.android.support:support-annotations': ['android-support-annotations', 'annotations', 'jar'],
49 'com.android.support:support-compat': ['android-support-compat', 'compat'],
50 'com.android.support:support-core-ui': ['android-support-core-ui', 'core-ui'],
51 'com.android.support:support-core-utils': ['android-support-core-utils', 'core-utils'],
52 'com.android.support:support-dynamic-animation': ['android-support-dynamic-animation', 'dynamic-animation'],
53 'com.android.support:support-emoji-appcompat': ['android-support-emoji-appcompat', 'emoji-appcompat'],
54 'com.android.support:support-emoji-bundled': ['android-support-emoji-bundled', 'emoji-bundled'],
55 'com.android.support:support-emoji': ['android-support-emoji', 'emoji'],
56 'com.android.support:support-fragment': ['android-support-fragment', 'fragment'],
57 'com.android.support:support-media-compat': ['android-support-media-compat', 'media-compat'],
58 'com.android.support:support-tv-provider': ['android-support-tv-provider', 'tv-provider'],
59 'com.android.support:support-v13': ['android-support-v13', 'v13'],
60 'com.android.support:support-v4': ['android-support-v4', 'v4'],
61 'com.android.support:support-vector-drawable': ['android-support-vectordrawable', 'graphics/drawable'],
62 'com.android.support:transition': ['android-support-transition', 'transition'],
63 'com.android.support:wear': ['android-support-wear', 'wear'],
Alan Viverette7bb86da2018-02-21 18:29:02 -050064
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -040065 # Support Library (28.0.0 splits + new modules)
66 'com.android.support:heifwriter': ['android-support-heifwriter', 'heifwriter'],
67 'com.android.support:webkit': ['android-support-webkit', 'webkit'],
68 'com.android.support:customview': ['android-support-customview', 'customview'],
69 'com.android.support:textclassifier': ['android-support-textclassifier', 'textclassifier'],
70 'com.android.support:swiperefreshlayout': ['android-support-swiperefreshlayout', 'swiperefreshlayout'],
71 'com.android.support:viewpager': ['android-support-viewpager', 'viewpager'],
72 'com.android.support:coordinatorlayout': ['android-support-coordinatorlayout', 'coordinatorlayout'],
73 'com.android.support:asynclayoutinflater': ['android-support-asynclayoutinflater', 'asynclayoutinflater'],
74 'com.android.support:support-content': ['android-support-support-content', 'support-content'],
75 'com.android.support:documentfile': ['android-support-documentfile', 'documentfile'],
76 'com.android.support:drawerlayout': ['android-support-drawerlayout', 'drawerlayout'],
77 'com.android.support:localbroadcastmanager': ['android-support-localbroadcastmanager', 'localbroadcastmanager'],
78 'com.android.support:print': ['android-support-print', 'print'],
79 'com.android.support:slidingpanelayout': ['android-support-slidingpanelayout', 'slidingpanelayout'],
80 'com.android.support:interpolator': ['android-support-interpolator', 'interpolator'],
81 'com.android.support:cursoradapter': ['android-support-cursoradapter', 'cursoradapter'],
82 'com.android.support:loader': ['android-support-loader', 'loader'],
83 'com.android.support:contentpaging': ['android-support-contentpaging', 'contentpaging'],
84 'com.android.support:recyclerview-selection': ['android-support-recyclerview-selection', 'recyclerview-selection'],
85 'com.android.support:car': ['android-support-car', 'car'],
86 'com.android.support:slices-core': ['android-slices-core', 'slices-core'],
87 'com.android.support:slices-view': ['android-slices-view', 'slices-view'],
88 'com.android.support:slices-builders': ['android-slices-builders', 'slices-builders'],
Alan Viverette19ecd502018-01-05 13:52:16 -050089
90 # Multidex
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -040091 'com.android.support:multidex': ['android-support-multidex', 'multidex/library'],
92 'com.android.support:multidex-instrumentation': ['android-support-multidex-instrumentation', 'multidex/instrumentation'],
Alan Viverette19ecd502018-01-05 13:52:16 -050093
94 # Constraint Layout
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -040095 'com.android.support.constraint:constraint-layout': ['android-support-constraint-layout', 'constraint-layout'],
96 'com.android.support.constraint:constraint-layout-solver': ['android-support-constraint-layout-solver', 'constraint-layout-solver'],
Alan Viverette19ecd502018-01-05 13:52:16 -050097
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -040098 # Architecture Components
Alan Viverette19ecd502018-01-05 13:52:16 -050099 'android.arch.core:runtime': ['android-arch-core-runtime', 'arch-core/runtime'],
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400100 'android.arch.core:common': ['android-arch-core-common', 'arch-core/common'],
101 'android.arch.lifecycle:common': ['android-arch-lifecycle-common', 'arch-lifecycle/common'],
102 'android.arch.lifecycle:common-java8': ['android-arch-lifecycle-common-java8', 'arch-lifecycle/common-java8'],
103 'android.arch.lifecycle:extensions': ['android-arch-lifecycle-extensions', 'arch-lifecycle/extensions'],
104 'android.arch.lifecycle:livedata': ['android-arch-lifecycle-livedata', 'arch-lifecycle/livedata'],
105 'android.arch.lifecycle:livedata-core': ['android-arch-lifecycle-livedata-core', 'arch-lifecycle/livedata-core'],
106 'android.arch.lifecycle:runtime': ['android-arch-lifecycle-runtime', 'arch-lifecycle/runtime'],
107 'android.arch.lifecycle:viewmodel': ['android-arch-lifecycle-viewmodel', 'arch-lifecycle/viewmodel'],
108 'android.arch.paging:common': ['android-arch-paging-common', 'arch-paging/common'],
Alan Viverette19ecd502018-01-05 13:52:16 -0500109 'android.arch.paging:runtime': ['android-arch-paging-runtime', 'arch-paging/runtime'],
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400110 'android.arch.persistence:db': ['android-arch-persistence-db', 'arch-persistence/db'],
111 'android.arch.persistence:db-framework': ['android-arch-persistence-db-framework', 'arch-persistence/db-framework'],
112 'android.arch.persistence.room:common': ['android-arch-room-common', 'arch-room/common'],
113 'android.arch.persistence.room:migration': ['android-arch-room-migration', 'arch-room/migration'],
114 'android.arch.persistence.room:runtime': ['android-arch-room-runtime', 'arch-room/runtime'],
115 'android.arch.persistence.room:testing': ['android-arch-room-testing', 'arch-room/testing'],
116
117 # AndroidX
118 'androidx.slice:slice-builders': ['androidx.slice_slice-builders', 'androidx/slice/slice-builders'],
119 'androidx.slice:slice-core': ['androidx.slice_slice-core', 'androidx/slice/slice-core'],
120 'androidx.slice:slice-view': ['androidx.slice_slice-view', 'androidx/slice/slice-view'],
121 'androidx.vectordrawable:vectordrawable-animated': ['androidx.vectordrawable_vectordrawable-animated', 'androidx/vectordrawable/vectordrawable-animated'],
122 'androidx.annotation:annotation': ['androidx.annotation_annotation', 'androidx/annotation/annotation', 'jar'],
123 'androidx.asynclayoutinflater:asynclayoutinflater': ['androidx.asynclayoutinflater_asynclayoutinflater', 'androidx/asynclayoutinflater/asynclayoutinflater'],
124 'androidx.car:car': ['androidx.car_car', 'androidx/car/car'],
125 'androidx.collection:collection': ['androidx.collection_collection', 'androidx/collection/collection', 'jar'],
126 'androidx.core:core': ['androidx.core_core', 'androidx/core/core'],
127 'androidx.contentpaging:contentpaging': ['androidx.contentpaging_contentpaging', 'androidx/contentpaging/contentpaging'],
128 'androidx.coordinatorlayout:coordinatorlayout': ['androidx.coordinatorlayout_coordinatorlayout', 'androidx/coordinatorlayout/coordinatorlayout'],
129 'androidx.legacy:legacy-support-core-ui': ['androidx.legacy_legacy-support-core-ui', 'androidx/legacy/legacy-support-core-ui'],
130 'androidx.legacy:legacy-support-core-utils': ['androidx.legacy_legacy-support-core-utils', 'androidx/legacy/legacy-support-core-utils'],
131 'androidx.cursoradapter:cursoradapter': ['androidx.cursoradapter_cursoradapter', 'androidx/cursoradapter/cursoradapter'],
132 'androidx.browser:browser': ['androidx.browser_browser', 'androidx/browser/browser'],
133 'androidx.customview:customview': ['androidx.customview_customview', 'androidx/customview/customview'],
134 'androidx.documentfile:documentfile': ['androidx.documentfile_documentfile', 'androidx/documentfile/documentfile'],
135 'androidx.drawerlayout:drawerlayout': ['androidx.drawerlayout_drawerlayout', 'androidx/drawerlayout/drawerlayout'],
136 'androidx.dynamicanimation:dynamicanimation': ['androidx.dynamicanimation_dynamicanimation', 'androidx/dynamicanimation/dynamicanimation'],
137 'androidx.emoji:emoji': ['androidx.emoji_emoji', 'androidx/emoji/emoji'],
138 'androidx.emoji:emoji-appcompat': ['androidx.emoji_emoji-appcompat', 'androidx/emoji/emoji-appcompat'],
139 'androidx.emoji:emoji-bundled': ['androidx.emoji_emoji-bundled', 'androidx/emoji/emoji-bundled'],
140 'androidx.exifinterface:exifinterface': ['androidx.exifinterface_exifinterface', 'androidx/exifinterface/exifinterface'],
141 'androidx.fragment:fragment': ['androidx.fragment_fragment', 'androidx/fragment/fragment'],
142 'androidx.heifwriter:heifwriter': ['androidx.heifwriter_heifwriter', 'androidx/heifwriter/heifwriter'],
143 'androidx.interpolator:interpolator': ['androidx.interpolator_interpolator', 'androidx/interpolator/interpolator'],
144 'androidx.loader:loader': ['androidx.loader_loader', 'androidx/loader/loader'],
145 'androidx.localbroadcastmanager:localbroadcastmanager': ['androidx.localbroadcastmanager_localbroadcastmanager', 'androidx/localbroadcastmanager/localbroadcastmanager'],
146 'androidx.media:media': ['androidx.media_media', 'androidx/media/media'],
147 'androidx.percentlayout:percentlayout': ['androidx.percentlayout_percentlayout', 'androidx/percentlayout/percentlayout'],
148 'androidx.print:print': ['androidx.print_print', 'androidx/print/print'],
149 'androidx.recommendation:recommendation': ['androidx.recommendation_recommendation', 'androidx/recommendation/recommendation'],
150 'androidx.recyclerview:recyclerview-selection': ['androidx.recyclerview_recyclerview-selection', 'androidx/recyclerview/recyclerview-selection'],
151 'androidx.slidingpanelayout:slidingpanelayout': ['androidx.slidingpanelayout_slidingpanelayout', 'androidx/slidingpanelayout/slidingpanelayout'],
152 'androidx.swiperefreshlayout:swiperefreshlayout': ['androidx.swiperefreshlayout_swiperefreshlayout', 'androidx/swiperefreshlayout/swiperefreshlayout'],
153 'androidx.textclassifier:textclassifier': ['androidx.textclassifier_textclassifier', 'androidx/textclassifier/textclassifier'],
154 'androidx.transition:transition': ['androidx.transition_transition', 'androidx/transition/transition'],
155 'androidx.tvprovider:tvprovider': ['androidx.tvprovider_tvprovider', 'androidx/tvprovider/tvprovider'],
156 'androidx.legacy:legacy-support-v13': ['androidx.legacy_legacy-support-v13', 'androidx/legacy/legacy-support-v13'],
157 'androidx.legacy:legacy-preference-v14': ['androidx.legacy_legacy-preference-v14', 'androidx/legacy/legacy-preference-v14'],
158 'androidx.leanback:leanback': ['androidx.leanback_leanback', 'androidx/leanback/leanback'],
159 'androidx.leanback:leanback-preference': ['androidx.leanback_leanback-preference', 'androidx/leanback/leanback-preference'],
160 'androidx.legacy:legacy-support-v4': ['androidx.legacy_legacy-support-v4', 'androidx/legacy/legacy-support-v4'],
161 'androidx.appcompat:appcompat': ['androidx.appcompat_appcompat', 'androidx/appcompat/appcompat'],
162 'androidx.cardview:cardview': ['androidx.cardview_cardview', 'androidx/cardview/cardview'],
163 'androidx.gridlayout:gridlayout': ['androidx.gridlayout_gridlayout', 'androidx/gridlayout/gridlayout'],
164 'androidx.mediarouter:mediarouter': ['androidx.mediarouter_mediarouter', 'androidx/mediarouter/mediarouter'],
165 'androidx.palette:palette': ['androidx.palette_palette', 'androidx/palette/palette'],
166 'androidx.preference:preference': ['androidx.preference_preference', 'androidx/preference/preference'],
167 'androidx.recyclerview:recyclerview': ['androidx.recyclerview_recyclerview', 'androidx/recyclerview/recyclerview'],
168 'androidx.vectordrawable:vectordrawable': ['androidx.vectordrawable_vectordrawable', 'androidx/vectordrawable/vectordrawable'],
169 'androidx.viewpager:viewpager': ['androidx.viewpager_viewpager', 'androidx/viewpager/viewpager'],
170 'androidx.wear:wear': ['androidx.wear_wear', 'androidx/wear/wear'],
171 'androidx.webkit:webkit': ['androidx.webkit_webkit', 'androidx/webkit/webkit'],
172
173 # AndroidX for Multidex
174 'androidx.multidex:multidex': ['androidx-multidex_multidex', 'androidx/multidex/multidex'],
175 'androidx.multidex:multidex-instrumentation': ['androidx-multidex_multidex-instrumentation', 'androidx/multidex/multidex-instrumentation'],
176
177 # AndroidX for Constraint Layout
178 'androidx.constraintlayout:constraintlayout': ['androidx-constraintlayout_constraintlayout', 'androidx/constraintlayout/constraintlayout'],
179 'androidx.constraintlayout:constraintlayout-solver': ['androidx-constraintlayout_constraintlayout-solver', 'androidx/constraintlayout/constraintlayout-solver'],
180
181 # AndroidX for Architecture Components
182 'androidx.arch.core:core-common': ['androidx.arch.core_core-common', 'androidx/arch/core/core-common'],
183 'androidx.arch.core:core-runtime': ['androidx.arch.core_core-runtime', 'androidx/arch/core/core-runtime'],
184 'androidx.lifecycle:lifecycle-common': ['androidx.lifecycle_lifecycle-common', 'androidx/lifecycle/lifecycle-common'],
185 'androidx.lifecycle:lifecycle-common-java8': ['androidx.lifecycle_lifecycle-common-java8', 'androidx/lifecycle/lifecycle-common-java8'],
186 'androidx.lifecycle:lifecycle-extensions': ['androidx.lifecycle_lifecycle-extensions', 'androidx/lifecycle/lifecycle-extensions'],
187 'androidx.lifecycle:lifecycle-livedata': ['androidx.lifecycle_lifecycle-livedata', 'androidx/lifecycle/lifecycle-livedata'],
188 'androidx.lifecycle:lifecycle-livedata-core': ['androidx.lifecycle_lifecycle-livedata-core', 'androidx/lifecycle/lifecycle-livedata-core'],
189 'androidx.lifecycle:lifecycle-runtime': ['androidx.lifecycle_lifecycle-runtime', 'androidx/lifecycle/lifecycle-runtime'],
190 'androidx.lifecycle:lifecycle-viewmodel': ['androidx.lifecycle_lifecycle-viewmodel', 'androidx/lifecycle/lifecycle-viewmodel'],
191 'androidx.paging:paging-common': ['androidx.paging_paging-common', 'androidx/paging/paging-common'],
192 'androidx.paging:paging-runtime': ['androidx.paging_paging-runtime', 'androidx/paging/paging-runtime'],
193 'androidx.sqlite:sqlite': ['androidx.sqlite_sqlite', 'androidx/sqlite/sqlite'],
194 'androidx.sqlite:sqlite-framework': ['androidx.sqlite_sqlite-framework', 'androidx/sqlite/sqlite-framework'],
195 'androidx.room:room-common': ['androidx.room_room-common', 'androidx/room/room-common'],
196 'androidx.room:room-migration': ['androidx.room_room-migration', 'androidx/room/room-migration'],
197 'androidx.room:room-runtime': ['androidx.room_room-runtime', 'androidx/room/room-runtime'],
198 'androidx.room:room-testing': ['androidx.room_room-testing', 'androidx/room/room-testing'],
Allenab72f012018-01-29 18:10:23 -0800199
Alan Viverette19ecd502018-01-05 13:52:16 -0500200 # Lifecycle
Alan Viverettec7e88f12018-02-13 15:29:50 -0500201 # Missing dependencies:
202 # - auto-common
203 # - javapoet
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400204 #'android.arch.lifecycle:compiler': ['android-arch-lifecycle-compiler', 'arch-lifecycle/compiler'],
Alan Viverettec7e88f12018-02-13 15:29:50 -0500205 # Missing dependencies:
206 # - reactive-streams
207 #'android.arch.lifecycle:reactivestreams': ['android-arch-lifecycle-reactivestreams','arch-lifecycle/reactivestreams'],
Allenab72f012018-01-29 18:10:23 -0800208
Alan Viverette19ecd502018-01-05 13:52:16 -0500209 # Room
Alan Viverettec7e88f12018-02-13 15:29:50 -0500210 # Missing dependencies:
211 # - auto-common
212 # - javapoet
213 # - antlr4
214 # - kotlin-metadata
215 # - commons-codec
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400216 #'android.arch.persistence.room:compiler': ['android-arch-room-compiler', 'arch-room/compiler'],
Alan Viverettec7e88f12018-02-13 15:29:50 -0500217 # Missing dependencies:
218 # - rxjava
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400219 #'android.arch.persistence.room:rxjava2': ['android-arch-room-rxjava2', 'arch-room/rxjava2'],
Allenab72f012018-01-29 18:10:23 -0800220
Jeff Gaston6e7e7502018-04-04 00:22:45 -0400221 # Third-party dependencies
222 'com.google.android:flexbox': ['flexbox', 'flexbox'],
223
224 # Support Library Material Design Components
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400225 'com.android.support:design': ['android-support-design', 'design'],
226 'com.android.support:design-animation': ['android-support-design-animation', 'design-animation'],
227 'com.android.support:design-bottomnavigation': ['android-support-design-bottomnavigation', 'design-bottomnavigation'],
228 'com.android.support:design-bottomsheet': ['android-support-design-bottomsheet', 'design-bottomsheet'],
229 'com.android.support:design-button': ['android-support-design-button', 'design-button'],
230 'com.android.support:design-canvas': ['android-support-design-canvas', 'design-canvas'],
231 'com.android.support:design-card': ['android-support-design-card', 'design-card'],
232 'com.android.support:design-chip': ['android-support-design-chip', 'design-chip'],
233 'com.android.support:design-circularreveal': ['android-support-design-circularreveal', 'design-circularreveal'],
234 'com.android.support:design-circularreveal-cardview': ['android-support-design-circularreveal-cardview', 'design-circularreveal-cardview'],
235 'com.android.support:design-circularreveal-coordinatorlayout': ['android-support-design-circularreveal-coordinatorlayout', 'design-circularreveal-coordinatorlayout'],
236 'com.android.support:design-color': ['android-support-design-color', 'design-color'],
237 'com.android.support:design-dialog': ['android-support-design-dialog', 'design-dialog'],
238 'com.android.support:design-drawable': ['android-support-design-drawable', 'design-drawable'],
239 'com.android.support:design-expandable': ['android-support-design-expandable', 'design-expandable'],
240 'com.android.support:design-floatingactionbutton': ['android-support-design-floatingactionbutton', 'design-floatingactionbutton'],
241 'com.android.support:design-internal': ['android-support-design-internal', 'design-internal'],
242 'com.android.support:design-math': ['android-support-design-math', 'design-math'],
243 'com.android.support:design-resources': ['android-support-design-resources', 'design-resources'],
244 'com.android.support:design-ripple': ['android-support-design-ripple', 'design-ripple'],
245 'com.android.support:design-snackbar': ['android-support-design-snackbar', 'design-snackbar'],
246 'com.android.support:design-stateful': ['android-support-design-stateful', 'design-stateful'],
247 'com.android.support:design-textfield': ['android-support-design-textfield', 'design-textfield'],
248 'com.android.support:design-theme': ['android-support-design-theme', 'design-theme'],
249 'com.android.support:design-transformation': ['android-support-design-transformation', 'design-transformation'],
250 'com.android.support:design-typography': ['android-support-design-typography', 'design-typography'],
251 'com.android.support:design-widget': ['android-support-design-widget', 'design-widget'],
252 'com.android.support:design-navigation': ['android-support-design-navigation', 'design-navigation'],
253 'com.android.support:design-tabs': ['android-support-design-tabs', 'design-tabs'],
254 'com.android.support:design-bottomappbar': ['android-support-design-bottomappbar', 'design-bottomappbar'],
255 'com.android.support:design-shape': ['android-support-design-shape', 'design-shape'],
Alan Viverettea59082b2018-02-22 10:27:46 -0500256
Jeff Gastonfa7c7e82018-04-06 13:35:48 -0400257 # Androidx Material Design Components
258 'com.google.android.material:material': ['androidx.material_material', 'com/google/android/material/material'],
259
Jeff Gaston6e7e7502018-04-04 00:22:45 -0400260 # Intermediate-AndroidX Material Design Components
261 'com.android.temp.support:design': ['androidx.design_design', 'com/android/temp/support/design/design'],
262 'com.android.temp.support:design-animation': ['androidx.design_design-animation', 'com/android/temp/support/design/design-animation'],
263 'com.android.temp.support:design-bottomnavigation': ['androidx.design_design-bottomnavigation', 'com/android/temp/support/design/design-bottomnavigation'],
264 'com.android.temp.support:design-bottomsheet': ['androidx.design_design-bottomsheet', 'com/android/temp/support/design/design-bottomsheet'],
265 'com.android.temp.support:design-button': ['androidx.design_design-button', 'com/android/temp/support/design/design-button'],
266 'com.android.temp.support:design-canvas': ['androidx.design_design-canvas', 'com/android/temp/support/design/design-canvas'],
267 'com.android.temp.support:design-card': ['androidx.design_design-card', 'com/android/temp/support/design/design-card'],
268 'com.android.temp.support:design-chip': ['androidx.design_design-chip', 'com/android/temp/support/design/design-chip'],
269 'com.android.temp.support:design-circularreveal': ['androidx.design_design-circularreveal', 'com/android/temp/support/design/design-circularreveal'],
270 'com.android.temp.support:design-circularreveal-cardview': ['androidx.design_design-circularreveal-cardview', 'com/android/temp/support/design/design-circularreveal-cardview'],
271 'com.android.temp.support:design-circularreveal-coordinatorlayout': ['androidx.design_design-circularreveal-coordinatorlayout', 'com/android/temp/support/design/design-circularreveal-coordinatorlayout'],
272 'com.android.temp.support:design-color': ['androidx.design_design-color', 'com/android/temp/support/design/design-color'],
273 'com.android.temp.support:design-dialog': ['androidx.design_design-dialog', 'com/android/temp/support/design/design-dialog'],
274 'com.android.temp.support:design-drawable': ['androidx.design_design-drawable', 'com/android/temp/support/design/design-drawable'],
275 'com.android.temp.support:design-expandable': ['androidx.design_design-expandable', 'com/android/temp/support/design/design-expandable'],
276 'com.android.temp.support:design-floatingactionbutton': ['androidx.design_design-floatingactionbutton', 'com/android/temp/support/design/design-floatingactionbutton'],
277 'com.android.temp.support:design-internal': ['androidx.design_design-internal', 'com/android/temp/support/design/design-internal'],
278 'com.android.temp.support:design-math': ['androidx.design_design-math', 'com/android/temp/support/design/design-math'],
279 'com.android.temp.support:design-resources': ['androidx.design_design-resources', 'com/android/temp/support/design/design-resources'],
280 'com.android.temp.support:design-ripple': ['androidx.design_design-ripple', 'com/android/temp/support/design/design-ripple'],
281 'com.android.temp.support:design-snackbar': ['androidx.design_design-snackbar', 'com/android/temp/support/design/design-snackbar'],
282 'com.android.temp.support:design-stateful': ['androidx.design_design-stateful', 'com/android/temp/support/design/design-stateful'],
283 'com.android.temp.support:design-textfield': ['androidx.design_design-textfield', 'com/android/temp/support/design/design-textfield'],
284 'com.android.temp.support:design-theme': ['androidx.design_design-theme', 'com/android/temp/support/design/design-theme'],
285 'com.android.temp.support:design-transformation': ['androidx.design_design-transformation', 'com/android/temp/support/design/design-transformation'],
286 'com.android.temp.support:design-typography': ['androidx.design_design-typography', 'com/android/temp/support/design/design-typography'],
287 'com.android.temp.support:design-widget': ['androidx.design_design-widget', 'com/android/temp/support/design/design-widget'],
288 'com.android.temp.support:design-navigation': ['androidx.design_design-navigation', 'com/android/temp/support/design/design-navigation'],
289 'com.android.temp.support:design-tabs': ['androidx.design_design-tabs', 'com/android/temp/support/design/design-tabs'],
290 'com.android.temp.support:design-bottomappbar': ['androidx.design_design-bottomappbar', 'com/android/temp/support/design/design-bottomappbar'],
291 'com.android.temp.support:design-shape': ['androidx.design_design-shape', 'com/android/temp/support/design/design-shape'],
292
Alan Viverette95f6d362017-04-06 09:40:50 -0400293}
294
295# Always remove these files.
296blacklist_files = [
297 'annotations.zip',
298 'public.txt',
299 'R.txt',
Alan Viverette44ad4e42017-08-09 17:45:00 -0400300 'AndroidManifest.xml',
Alan Viverettef48d9b42017-08-17 14:45:46 -0400301 os.path.join('libs','noto-emoji-compat-java.jar')
Alan Viverette95f6d362017-04-06 09:40:50 -0400302]
303
Alan Viverette44ad4e42017-08-09 17:45:00 -0400304artifact_pattern = re.compile(r"^(.+?)-(\d+\.\d+\.\d+(?:-\w+\d+)?(?:-[\d.]+)*)\.(jar|aar)$")
Alan Viverette95f6d362017-04-06 09:40:50 -0400305
Alan Viverettec960cfb2017-12-04 13:09:22 -0500306
307class MavenLibraryInfo:
Jeff Gastonc302bb92018-03-23 13:53:48 -0400308 def __init__(self, key, group_id, artifact_id, version, dir, repo_dir, file):
Alan Viverettec960cfb2017-12-04 13:09:22 -0500309 self.key = key
310 self.group_id = group_id
311 self.artifact_id = artifact_id
312 self.version = version
Jeff Gastonc302bb92018-03-23 13:53:48 -0400313 self.dir = dir
Alan Viverettec960cfb2017-12-04 13:09:22 -0500314 self.repo_dir = repo_dir
315 self.file = file
316
317
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500318def print_e(*args, **kwargs):
319 print(*args, file=sys.stderr, **kwargs)
320
Alan Viverette95f6d362017-04-06 09:40:50 -0400321
322def touch(fname, times=None):
323 with open(fname, 'a'):
324 os.utime(fname, times)
325
326
Alan Viverette45837092017-05-12 14:50:53 -0400327def path(*path_parts):
328 return reduce((lambda x, y: os.path.join(x, y)), path_parts)
329
330
Alan Viverettecd3de262017-08-14 09:51:30 -0400331def flatten(list):
332 return reduce((lambda x, y: "%s %s" % (x, y)), list)
333
334
Alan Viverette45837092017-05-12 14:50:53 -0400335def rm(path):
336 if os.path.isdir(path):
337 rmtree(path)
338 elif os.path.exists(path):
339 os.remove(path)
340
341
342def mv(src_path, dst_path):
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400343 if os.path.exists(dst_path):
Alan Viverettecd3de262017-08-14 09:51:30 -0400344 rm(dst_path)
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400345 if not os.path.exists(os.path.dirname(dst_path)):
346 os.makedirs(os.path.dirname(dst_path))
Alan Viverette45837092017-05-12 14:50:53 -0400347 os.rename(src_path, dst_path)
348
349
Jeff Gastonc302bb92018-03-23 13:53:48 -0400350def detect_artifacts(maven_repo_dirs):
Alan Viveretted4527e62017-05-11 15:03:25 -0400351 maven_lib_info = {}
352
Dan Willemsen814152e2017-11-06 13:22:11 -0800353 # Find the latest revision for each artifact, remove others
Jeff Gastonc302bb92018-03-23 13:53:48 -0400354 for repo_dir in maven_repo_dirs:
Dan Willemsen814152e2017-11-06 13:22:11 -0800355 for root, dirs, files in os.walk(repo_dir):
356 for file in files:
Alan Viverettec960cfb2017-12-04 13:09:22 -0500357 if file[-4:] == ".pom":
358 # Read the POM (hack hack hack).
359 group_id = ''
360 artifact_id = ''
361 version = ''
362 file = os.path.join(root, file)
363 with open(file) as pom_file:
364 for line in pom_file:
365 if line[:11] == ' <groupId>':
366 group_id = line[11:-11]
367 elif line[:14] == ' <artifactId>':
368 artifact_id = line[14:-14]
369 elif line[:11] == ' <version>':
370 version = line[11:-11]
371 if group_id == '' or artifact_id == '' or version == '':
372 print_e('Failed to find Maven artifact data in ' + file)
373 continue
Alan Viverette95f6d362017-04-06 09:40:50 -0400374
Alan Viverettec960cfb2017-12-04 13:09:22 -0500375 # Locate the artifact.
376 artifact_file = file[:-4]
377 if os.path.exists(artifact_file + '.jar'):
378 artifact_file = artifact_file + '.jar'
379 elif os.path.exists(artifact_file + '.aar'):
380 artifact_file = artifact_file + '.aar'
381 else:
382 print_e('Failed to find artifact for ' + artifact_file)
383 continue
384
385 # Make relative to root.
386 artifact_file = artifact_file[len(root) + 1:]
387
388 # Find the mapping.
389 group_artifact = group_id + ':' + artifact_id
Jeff Gaston3e622ba2018-03-26 23:24:46 -0400390 if group_artifact in maven_to_make:
Alan Viverettec960cfb2017-12-04 13:09:22 -0500391 key = group_artifact
Jeff Gaston3e622ba2018-03-26 23:24:46 -0400392 elif artifact_id in maven_to_make:
393 key = artifact_id
Alan Viverettec960cfb2017-12-04 13:09:22 -0500394 else:
395 print_e('Failed to find artifact mapping for ' + group_artifact)
396 continue
397
398 # Store the latest version.
399 version = LooseVersion(version)
400 if key not in maven_lib_info \
401 or version > maven_lib_info[key].version:
402 maven_lib_info[key] = MavenLibraryInfo(key, group_id, artifact_id, version,
403 root, repo_dir, artifact_file)
Alan Viverette95f6d362017-04-06 09:40:50 -0400404
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400405 return maven_lib_info
406
407
Colin Cross59b59db2018-04-24 13:58:05 -0700408def transform_maven_repos(maven_repo_dirs, transformed_dir, extract_res=True, include_static_deps=True):
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400409 cwd = os.getcwd()
410
411 # Use a temporary working directory.
Jeff Gastonc302bb92018-03-23 13:53:48 -0400412 maven_lib_info = detect_artifacts(maven_repo_dirs)
Jeff Gastona68a8d42018-03-23 14:00:13 -0400413 working_dir = temp_dir
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400414
Alan Viverettec960cfb2017-12-04 13:09:22 -0500415 if not maven_lib_info:
416 print_e('Failed to detect artifacts')
417 return False
418
Jeff Gastonc302bb92018-03-23 13:53:48 -0400419 # extract some files (for example, AndroidManifest.xml) from any relevant artifacts
Alan Viveretted4527e62017-05-11 15:03:25 -0400420 for info in maven_lib_info.values():
Alan Viveretted8ce7222017-12-11 17:24:43 -0500421 transform_maven_lib(working_dir, info, extract_res)
Dan Willemsen814152e2017-11-06 13:22:11 -0800422
Colin Cross74683bc2018-04-11 17:36:18 -0700423 # generate a single Android.bp that specifies to use all of the above artifacts
424 makefile = os.path.join(working_dir, 'Android.bp')
Alan Viverette4ec9a172018-02-20 16:19:31 -0500425 with open(makefile, 'w') as f:
Colin Cross74683bc2018-04-11 17:36:18 -0700426 args = ["pom2bp", "-sdk-version", "current"]
Jeff Gaston1cc06092018-03-28 15:51:02 -0400427 if include_static_deps:
428 args.append("-static-deps")
Jeff Gaston54868ee2018-04-25 19:43:35 -0400429 rewriteNames = sorted([name for name in maven_to_make if ":" in name] + [name for name in maven_to_make if ":" not in name])
Jeff Gaston7ec1d8f2018-03-27 00:25:12 -0400430 args.extend(["-rewrite=^" + name + "$=" + maven_to_make[name][0] for name in rewriteNames])
Jeff Gaston9bb25db2018-04-23 14:26:28 -0400431 args.extend(["-extra-deps=android-support-car=prebuilt-android.car-stubs"])
Colin Cross21060072018-04-24 13:52:29 -0700432 # these depend on GSON which is not in AOSP
433 args.extend(["-exclude=androidx.room_room-migration",
434 "-exclude=androidx.room_room-testing",
435 "-exclude=android-arch-room-migration",
436 "-exclude=android-arch-room-testing"])
Jeff Gaston7ec1d8f2018-03-27 00:25:12 -0400437 args.extend(["."])
Dan Willemsen814152e2017-11-06 13:22:11 -0800438 subprocess.check_call(args, stdout=f, cwd=working_dir)
Alan Viverette95f6d362017-04-06 09:40:50 -0400439
440 # 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
Colin Cross59b59db2018-04-24 13:58:05 -0700466 if maven_lib_type == "aar":
467 if extract_res:
468 target_dir = os.path.join(working_dir, make_dir_name)
469 if not os.path.exists(target_dir):
470 os.makedirs(target_dir)
Dan Willemsen814152e2017-11-06 13:22:11 -0800471
Alan Viverettec960cfb2017-12-04 13:09:22 -0500472 process_aar(artifact_file, target_dir)
Alan Viveretted4527e62017-05-11 15:03:25 -0400473
Colin Cross59b59db2018-04-24 13:58:05 -0700474 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.
Colin Cross59b59db2018-04-24 13:58:05 -0700553 return transform_maven_repos([repo_dir], support_dir, extract_res=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.
Colin Cross59b59db2018-04-24 13:58:05 -0700600 return transform_maven_repos([repo_dir], os.path.join(extras_dir, 'app-toolkit'), extract_res=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
Anton Hansson1d01a032018-04-09 10:29:37 +0100674def update_framework(build_id, sdk_dir):
675 for api_level in ['core', 'public', 'system']:
676 target_dir = path(sdk_dir, api_level)
677 artifact_to_filename = sdk_artifacts_dict[api_level]
678 artifact_to_path = {artifact: path(target_dir, filename)
679 for (artifact, filename) in artifact_to_filename.items()}
680
681 if not fetch_artifacts(framework_sdk_target, build_id, artifact_to_path):
682 return False
683
684 if api_level == 'public':
685 # Fetch a few artifacts from the public sdk.
686 artifact = 'sdk-repo-darwin-platforms-%s.zip' % build_id.fs_id
687 artifact_path = fetch_artifact(framework_sdk_target, build_id.url_id, artifact)
Anton Hansson9709fd42018-04-03 16:52:13 +0100688 if not artifact_path:
689 return False
Anton Hansson1d01a032018-04-09 10:29:37 +0100690
691 with zipfile.ZipFile(artifact_path) as zipFile:
692 for filename in ['android.jar', 'framework.aidl', 'uiautomator.jar']:
693 extract_to(zipFile, filename, target_dir)
Anton Hansson9709fd42018-04-03 16:52:13 +0100694
Alan Viverettecd3de262017-08-14 09:51:30 -0400695 return True
Alan Viverette45837092017-05-12 14:50:53 -0400696
697
Anton Hansson1d01a032018-04-09 10:29:37 +0100698def finalize_sdk(build_id, sdk_version):
699 target_finalize_dir = '%d' % sdk_version
Anton Hansson9709fd42018-04-03 16:52:13 +0100700
Anton Hansson1d01a032018-04-09 10:29:37 +0100701 extra_finalize_artifacts = {
702 'public_api.txt': path(target_finalize_dir, 'public/api/android.txt'),
703 'system-api.txt': path(target_finalize_dir, 'system/api/android.txt'),
Anton Hansson9709fd42018-04-03 16:52:13 +0100704 }
Anton Hansson1d01a032018-04-09 10:29:37 +0100705 return fetch_artifacts(framework_sdk_target, build_id, extra_finalize_artifacts) \
706 and update_framework(build_id, target_finalize_dir)
Anton Hansson9709fd42018-04-03 16:52:13 +0100707
Anton Hansson9709fd42018-04-03 16:52:13 +0100708
Anton Hansson1d01a032018-04-09 10:29:37 +0100709def update_framework_current(build_id):
710 return update_framework(build_id, current_path)
Anton Hansson9709fd42018-04-03 16:52:13 +0100711
712
Alan Viverettec1c32b62017-12-20 09:40:36 -0500713def update_buildtools(target, arch, build_id):
Jeff Gaston13e38412018-02-06 14:45:36 -0500714 artifact_path = fetch_and_extract(target, build_id.url_id,
715 "sdk-repo-%s-build-tools-%s.zip" % (arch, build_id.fs_id))
Alan Viverettec1c32b62017-12-20 09:40:36 -0500716 if not artifact_path:
717 return False
718
719 top_level_dir = os.listdir(artifact_path)[0]
720 src_path = os.path.join(artifact_path, top_level_dir)
721 dst_path = path(buildtools_dir, arch)
722 mv(src_path, dst_path)
723
724 # Move all top-level files to /bin and make them executable
725 bin_path = path(dst_path, 'bin')
726 top_level_files = filter(lambda e: os.path.isfile(path(dst_path, e)), os.listdir(dst_path))
727 for file in top_level_files:
728 src_file = path(dst_path, file)
729 dst_file = path(bin_path, file)
730 mv(src_file, dst_file)
731 os.chmod(dst_file, 0o755)
732
733 # Remove renderscript
734 rm(path(dst_path, 'renderscript'))
735
736 return True
737
738
Alan Viverettecd3de262017-08-14 09:51:30 -0400739def append(text, more_text):
740 if text:
741 return "%s, %s" % (text, more_text)
742 return more_text
Alan Viverette45837092017-05-12 14:50:53 -0400743
Alan Viverette95f6d362017-04-06 09:40:50 -0400744
Jeff Gaston13e38412018-02-06 14:45:36 -0500745class buildId(object):
746 def __init__(self, url_id, fs_id):
747 # id when used in build server urls
748 self.url_id = url_id
749 # id when used in build commands
750 self.fs_id = fs_id
751
Jeff Gastonb9b09052018-02-05 14:16:05 -0500752def getBuildId(args):
Jeff Gaston13e38412018-02-06 14:45:36 -0500753 # must be in the format 12345 or P12345
Jeff Gastonb9b09052018-02-05 14:16:05 -0500754 source = args.source
Jeff Gaston13e38412018-02-06 14:45:36 -0500755 number_text = source[:]
756 presubmit = False
757 if number_text.startswith("P"):
758 presubmit = True
759 number_text = number_text[1:]
760 if not number_text.isnumeric():
Alan Viverette7e897e22018-03-09 15:24:10 -0500761 return None
Jeff Gaston13e38412018-02-06 14:45:36 -0500762 url_id = source
763 fs_id = url_id
764 if presubmit:
765 fs_id = "0"
766 args.file = False
767 return buildId(url_id, fs_id)
Jeff Gastonb9b09052018-02-05 14:16:05 -0500768
Colin Cross573e1212018-02-12 14:59:52 -0800769def getFile(args):
770 source = args.source
771 if not source.isnumeric():
772 return args.source
Alan Viverette7e897e22018-03-09 15:24:10 -0500773 return None
Colin Cross573e1212018-02-12 14:59:52 -0800774
Alan Viverette4ec9a172018-02-20 16:19:31 -0500775
776def script_relative(rel_path):
Jeff Gastona68a8d42018-03-23 14:00:13 -0400777 return os.path.join(script_dir, rel_path)
Alan Viverette4ec9a172018-02-20 16:19:31 -0500778
779
Jeff Gastoncc296a82018-03-23 14:33:24 -0400780def uncommittedChangesExist():
781 try:
782 # Make sure we don't overwrite any pending changes.
783 diffCommand = "cd " + git_dir + " && git diff --quiet"
784 subprocess.check_call(diffCommand, shell=True)
785 subprocess.check_call(diffCommand + " --cached", shell=True)
786 return False
787 except subprocess.CalledProcessError:
788 return True
789
790
Jeff Gastona7fba9b2018-03-26 23:48:51 -0400791rm(temp_dir)
Alan Viveretted4527e62017-05-11 15:03:25 -0400792parser = argparse.ArgumentParser(
Alan Viverette45837092017-05-12 14:50:53 -0400793 description=('Update current prebuilts'))
Alan Viveretted4527e62017-05-11 15:03:25 -0400794parser.add_argument(
Alan Viverette129555e2018-01-30 09:57:57 -0500795 'source',
796 help='Build server build ID or local Maven ZIP file')
797parser.add_argument(
798 '-d', '--design', action="store_true",
799 help='If specified, updates only the Design Library')
Alan Viveretted4527e62017-05-11 15:03:25 -0400800parser.add_argument(
Jeff Gaston6e7e7502018-04-04 00:22:45 -0400801 '-m', '--material', action="store_true",
802 help='If specified, updates only the intermediate-AndroidX Design Library')
803parser.add_argument(
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400804 '-c', '--constraint', action="store_true",
805 help='If specified, updates only Constraint Layout')
806parser.add_argument(
Jeff Gaston9edf86c2018-04-18 13:45:23 -0400807 '--constraint_x', action="store_true",
808 help='If specified, updates Constraint Layout X')
809parser.add_argument(
Jeff Gaston782c3e32018-02-06 14:36:17 -0500810 '-j', '--jetifier', action="store_true",
811 help='If specified, updates only Jetifier')
812parser.add_argument(
Alan Viverette5bfe05b2017-06-06 14:21:29 -0400813 '-p', '--platform', action="store_true",
814 help='If specified, updates only the Android Platform')
Alan Viverettec1c32b62017-12-20 09:40:36 -0500815parser.add_argument(
Anton Hansson9709fd42018-04-03 16:52:13 +0100816 '-f', '--finalize_sdk', type=int,
817 help='If specified, imports the source build as the specified finalized SDK version')
818parser.add_argument(
Alan Viverettec1c32b62017-12-20 09:40:36 -0500819 '-b', '--buildtools', action="store_true",
820 help='If specified, updates only the Build Tools')
Jeff Gastoncc296a82018-03-23 14:33:24 -0400821parser.add_argument(
Jeff Gaston41fd5e62018-04-25 17:02:02 -0400822 '--stx', action="store_true",
823 help='If specified, updates Support Library, Androidx, and App Toolkit (that is, all artifacts built from frameworks/support)')
824parser.add_argument(
Jeff Gastoncc296a82018-03-23 14:33:24 -0400825 '--commit-first', action="store_true",
826 help='If specified, then if uncommited changes exist, commit before continuing')
Alan Viveretted4527e62017-05-11 15:03:25 -0400827args = parser.parse_args()
Jeff Gaston41fd5e62018-04-25 17:02:02 -0400828if args.stx:
829 args.support = args.toolkit = args.androidx = True
830else:
831 args.support = args.toolkit = args.androidx = False
Jeff Gaston56fe2762018-02-06 14:54:37 -0500832args.file = True
Alan Viverette129555e2018-01-30 09:57:57 -0500833if not args.source:
834 parser.error("You must specify a build ID or local Maven ZIP file")
Alan Viveretted4527e62017-05-11 15:03:25 -0400835 sys.exit(1)
Alan Viverette129555e2018-01-30 09:57:57 -0500836if not (args.support or args.platform or args.constraint or args.toolkit or args.buildtools \
Anton Hansson9709fd42018-04-03 16:52:13 +0100837 or args.design or args.jetifier or args.androidx or args.material \
Jeff Gaston9edf86c2018-04-18 13:45:23 -0400838 or args.finalize_sdk or args.constraint_x):
Alan Viverettec1c32b62017-12-20 09:40:36 -0500839 parser.error("You must specify at least one target to update")
Alan Viverettecd3de262017-08-14 09:51:30 -0400840 sys.exit(1)
Jeff Gaston9edf86c2018-04-18 13:45:23 -0400841if (args.support or args.constraint or args.constraint_x or args.toolkit or args.design or args.material or args.androidx) \
Colin Cross74683bc2018-04-11 17:36:18 -0700842 and which('pom2bp') is None:
843 parser.error("Cannot find pom2bp in path; please run lunch to set up build environment")
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500844 sys.exit(1)
Alan Viveretted4527e62017-05-11 15:03:25 -0400845
Jeff Gastoncc296a82018-03-23 14:33:24 -0400846if uncommittedChangesExist():
847 if args.commit_first:
848 subprocess.check_call("cd " + git_dir + " && git add -u", shell=True)
849 subprocess.check_call("cd " + git_dir + " && git commit -m 'save working state'", shell=True)
850
851if uncommittedChangesExist():
Anton Hansson10861a02018-04-06 13:57:08 +0100852 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 -0400853 sys.exit(1)
854
855try:
Alan Viverettecd3de262017-08-14 09:51:30 -0400856 components = None
857 if args.constraint:
Jeff Gastonb9b09052018-02-05 14:16:05 -0500858 if update_constraint('studio', getBuildId(args)):
Alan Viverettecd3de262017-08-14 09:51:30 -0400859 components = append(components, 'Constraint Layout')
860 else:
Jeff Gaston9edf86c2018-04-18 13:45:23 -0400861 print_e('Failed to update Constraint Layout, aborting...')
862 sys.exit(1)
863 if args.constraint_x:
864 if update_constraint_x(getFile(args)):
865 components = append(components, 'Constraint Layout X')
866 else:
867 print_e('Failed to update Constraint Layout X, aborting...')
Alan Viverettecd3de262017-08-14 09:51:30 -0400868 sys.exit(1)
869 if args.support:
Alan Viverette7e897e22018-03-09 15:24:10 -0500870 if update_support('support_library', getBuildId(args), getFile(args)):
Alan Viverettecd3de262017-08-14 09:51:30 -0400871 components = append(components, 'Support Library')
872 else:
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500873 print_e('Failed to update Support Library, aborting...')
Alan Viverettecd3de262017-08-14 09:51:30 -0400874 sys.exit(1)
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400875 if args.androidx:
876 if update_androidx('support_library', 'support_library_app_toolkit', \
877 getBuildId(args), getFile(args)):
878 components = append(components, 'AndroidX')
879 else:
880 print_e('Failed to update AndroidX, aborting...')
881 sys.exit(1)
Jeff Gaston782c3e32018-02-06 14:36:17 -0500882 if args.jetifier:
883 if update_jetifier('support_library', getBuildId(args)):
884 components = append(components, 'Jetifier')
885 else:
886 print_e('Failed to update Jetifier, aborting...')
887 sys.exit(1)
Alan Viverettec960cfb2017-12-04 13:09:22 -0500888 if args.toolkit:
Jeff Gastonb9b09052018-02-05 14:16:05 -0500889 if update_toolkit('support_library_app_toolkit', getBuildId(args)):
Alan Viverettec960cfb2017-12-04 13:09:22 -0500890 components = append(components, 'App Toolkit')
891 else:
892 print_e('Failed to update App Toolkit, aborting...')
893 sys.exit(1)
Anton Hanssonbe15e8c2018-04-26 17:35:45 +0100894 if args.platform or args.finalize_sdk:
Anton Hansson87654c42018-04-26 15:19:42 +0100895 if update_framework_current(getBuildId(args)):
Alan Viverettecd3de262017-08-14 09:51:30 -0400896 components = append(components, 'platform SDK')
897 else:
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500898 print_e('Failed to update platform SDK, aborting...')
Alan Viverettecd3de262017-08-14 09:51:30 -0400899 sys.exit(1)
Anton Hansson9709fd42018-04-03 16:52:13 +0100900 if args.finalize_sdk:
Anton Hanssonbe15e8c2018-04-26 17:35:45 +0100901 n = args.finalize_sdk
902 if finalize_sdk(getBuildId(args), n):
903 # We commit the finalized dir separately from the current sdk update.
904 msg = "Import final sdk version %d from build %s" % (n, getBuildId(args).url_id)
905 subprocess.check_call(['git', 'add', '%d' % n])
906 subprocess.check_call(['git', 'commit', '-m', msg])
Anton Hansson9709fd42018-04-03 16:52:13 +0100907 else:
Anton Hanssonbe15e8c2018-04-26 17:35:45 +0100908 print_e('Failed to finalize SDK %d, aborting...' % n)
Anton Hansson9709fd42018-04-03 16:52:13 +0100909 sys.exit(1)
Alan Viverette129555e2018-01-30 09:57:57 -0500910 if args.design:
Colin Cross573e1212018-02-12 14:59:52 -0800911 if update_design(getFile(args)):
Alan Viverette129555e2018-01-30 09:57:57 -0500912 components = append(components, 'Design Library')
913 else:
Jeff Gaston6e7e7502018-04-04 00:22:45 -0400914 print_e('Failed to update Design Library, aborting...')
915 sys.exit(1)
916 if args.material:
917 if update_material(getFile(args)):
918 components = append(components, 'intermediate-AndroidX Design Library')
919 else:
920 print_e('Failed to update intermediate-AndroidX Design Library, aborting...')
Alan Viverette129555e2018-01-30 09:57:57 -0500921 sys.exit(1)
Alan Viverettec1c32b62017-12-20 09:40:36 -0500922 if args.buildtools:
Jeff Gastonb9b09052018-02-05 14:16:05 -0500923 if update_buildtools('sdk_phone_armv7-sdk_mac', 'darwin', getBuildId(args)) \
924 and update_buildtools('sdk_phone_x86_64-sdk', 'linux', getBuildId(args)) \
925 and update_buildtools('sdk_phone_armv7-win_sdk', 'windows', getBuildId(args)):
Alan Viverettec1c32b62017-12-20 09:40:36 -0500926 components = append(components, 'build tools')
927 else:
928 print_e('Failed to update build tools, aborting...')
929 sys.exit(1)
Jeff Gastonb70daa92018-03-29 20:10:22 -0400930
Jeff Gastonf12f3ce2018-03-23 16:41:24 -0400931
Alan Viveretted4527e62017-05-11 15:03:25 -0400932
Colin Cross941d9802018-05-03 21:37:57 -0700933 subprocess.check_call(['git', 'add', current_path, buildtools_dir])
Colin Cross573e1212018-02-12 14:59:52 -0800934 if not args.source.isnumeric():
Alan Viverette129555e2018-01-30 09:57:57 -0500935 src_msg = "local Maven ZIP"
936 else:
Jeff Gaston13e38412018-02-06 14:45:36 -0500937 src_msg = "build %s" % (getBuildId(args).url_id)
Alan Viverette129555e2018-01-30 09:57:57 -0500938 msg = "Import %s from %s\n\n%s" % (components, src_msg, flatten(sys.argv))
Alan Viveretted4527e62017-05-11 15:03:25 -0400939 subprocess.check_call(['git', 'commit', '-m', msg])
Anton Hanssonbe15e8c2018-04-26 17:35:45 +0100940 if args.finalize_sdk:
941 print('NOTE: Created two commits:')
942 subprocess.check_call(['git', 'log', '-2', '--oneline'])
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500943 print('Remember to test this change before uploading it to Gerrit!')
Alan Viveretted4527e62017-05-11 15:03:25 -0400944
945finally:
946 # Revert all stray files, including the downloaded zip.
947 try:
948 with open(os.devnull, 'w') as bitbucket:
949 subprocess.check_call(['git', 'add', '-Af', '.'], stdout=bitbucket)
950 subprocess.check_call(
Jeff Gaston9edf86c2018-04-18 13:45:23 -0400951 ['git', 'commit', '-m', 'COMMIT TO REVERT - RESET ME!!!', '--allow-empty'], stdout=bitbucket)
Alan Viveretted4527e62017-05-11 15:03:25 -0400952 subprocess.check_call(['git', 'reset', '--hard', 'HEAD~1'], stdout=bitbucket)
953 except subprocess.CalledProcessError:
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500954 print_e('ERROR: Failed cleaning up, manual cleanup required!!!')