blob: 34c33b7bf5a99356448f70a76d8b31668d8aa8b0 [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
Jiyong Park1d1c9632018-05-29 17:45:27 +09008import glob
Alan Viveretted4527e62017-05-11 15:03:25 -04009import subprocess
shepshaparde4127cf2019-09-03 16:08:44 -070010from shutil import copyfile, rmtree, which, move
Alan Viveretted4527e62017-05-11 15:03:25 -040011from distutils.version import LooseVersion
Alan Viverettef5cb0e62017-11-17 15:15:23 -050012from functools import reduce
Alan Viverette95f6d362017-04-06 09:40:50 -040013
Alan Viverette45837092017-05-12 14:50:53 -040014current_path = 'current'
Oussama Ben Abdelbaki66db0a42019-05-08 16:41:15 -040015framework_sdk_target = 'sdk_phone_armv7-win_sdk'
Alan Viverette3e57a4a2017-08-11 15:49:47 -040016support_dir = os.path.join(current_path, 'support')
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -040017androidx_dir = os.path.join(current_path, 'androidx')
Alan Viverette3e57a4a2017-08-11 15:49:47 -040018extras_dir = os.path.join(current_path, 'extras')
Alan Viverettec1c32b62017-12-20 09:40:36 -050019buildtools_dir = 'tools'
Jeff Gaston553a4372018-03-29 18:34:22 -040020jetifier_dir = os.path.join(buildtools_dir, 'jetifier', 'jetifier-standalone')
Alan Viverette95f6d362017-04-06 09:40:50 -040021
Jeff Gastona68a8d42018-03-23 14:00:13 -040022temp_dir = os.path.join(os.getcwd(), "support_tmp")
23os.chdir(os.path.dirname(os.path.dirname(os.path.realpath(sys.argv[0]))))
24git_dir = os.getcwd()
25
Alan Viverettecd3de262017-08-14 09:51:30 -040026# See go/fetch_artifact for details on this script.
Alan Viveretted4527e62017-05-11 15:03:25 -040027FETCH_ARTIFACT = '/google/data/ro/projects/android/fetch_artifact'
28
Alan Viverette95f6d362017-04-06 09:40:50 -040029maven_to_make = {
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -040030 # Support Library
Jeff Gastona0bce602018-08-24 14:05:03 -040031 'com.android.support:animated-vector-drawable': {'name':'android-support-animatedvectordrawable', 'path':'graphics/drawable'},
32 'com.android.support:appcompat-v7': {'name':'android-support-v7-appcompat', 'path':'v7/appcompat'},
33 'com.android.support:cardview-v7': {'name':'android-support-v7-cardview', 'path':'v7/cardview'},
34 'com.android.support:collections': {'name':'android-support-collections', 'path':'collections'},
35 'com.android.support:customtabs': {'name':'android-support-customtabs', 'path':'customtabs'},
36 'com.android.support:exifinterface': {'name':'android-support-exifinterface', 'path':'exifinterface'},
37 'com.android.support:gridlayout-v7': {'name':'android-support-v7-gridlayout', 'path':'v7/gridlayout'},
38 'com.android.support:leanback-v17': {'name':'android-support-v17-leanback', 'path':'v17/leanback'},
39 'com.android.support:mediarouter-v7': {'name':'android-support-v7-mediarouter', 'path':'v7/mediarouter'},
40 'com.android.support:palette-v7': {'name':'android-support-v7-palette', 'path':'v7/palette'},
41 'com.android.support:percent': {'name':'android-support-percent', 'path':'percent'},
42 'com.android.support:preference-leanback-v17': {'name':'android-support-v17-preference-leanback', 'path':'v17/preference-leanback'},
43 'com.android.support:preference-v14': {'name':'android-support-v14-preference', 'path':'v14/preference'},
44 'com.android.support:preference-v7': {'name':'android-support-v7-preference', 'path':'v7/preference'},
45 'com.android.support:recommendation': {'name':'android-support-recommendation', 'path':'recommendation'},
46 'com.android.support:recyclerview-v7': {'name':'android-support-v7-recyclerview', 'path':'v7/recyclerview'},
47 'com.android.support:support-annotations': {'name':'android-support-annotations', 'path':'annotations'},
48 'com.android.support:support-compat': {'name':'android-support-compat', 'path':'compat'},
49 'com.android.support:support-core-ui': {'name':'android-support-core-ui', 'path':'core-ui'},
50 'com.android.support:support-core-utils': {'name':'android-support-core-utils', 'path':'core-utils'},
51 'com.android.support:support-dynamic-animation': {'name':'android-support-dynamic-animation', 'path':'dynamic-animation'},
52 'com.android.support:support-emoji-appcompat': {'name':'android-support-emoji-appcompat', 'path':'emoji-appcompat'},
53 'com.android.support:support-emoji-bundled': {'name':'android-support-emoji-bundled', 'path':'emoji-bundled'},
54 'com.android.support:support-emoji': {'name':'android-support-emoji', 'path':'emoji'},
55 'com.android.support:support-fragment': {'name':'android-support-fragment', 'path':'fragment'},
56 'com.android.support:support-media-compat': {'name':'android-support-media-compat', 'path':'media-compat'},
57 'com.android.support:support-tv-provider': {'name':'android-support-tv-provider', 'path':'tv-provider'},
58 'com.android.support:support-v13': {'name':'android-support-v13', 'path':'v13'},
59 'com.android.support:support-v4': {'name':'android-support-v4', 'path':'v4'},
60 'com.android.support:support-vector-drawable': {'name':'android-support-vectordrawable', 'path':'graphics/drawable'},
61 'com.android.support:transition': {'name':'android-support-transition', 'path':'transition'},
62 'com.android.support:wear': {'name':'android-support-wear', 'path':'wear'},
Alan Viverette7bb86da2018-02-21 18:29:02 -050063
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -040064 # Support Library (28.0.0 splits + new modules)
Jeff Gastona0bce602018-08-24 14:05:03 -040065 'com.android.support:heifwriter': {'name':'android-support-heifwriter', 'path':'heifwriter'},
66 'com.android.support:webkit': {'name':'android-support-webkit', 'path':'webkit'},
67 'com.android.support:customview': {'name':'android-support-customview', 'path':'customview'},
68 'com.android.support:textclassifier': {'name':'android-support-textclassifier', 'path':'textclassifier'},
69 'com.android.support:swiperefreshlayout': {'name':'android-support-swiperefreshlayout', 'path':'swiperefreshlayout'},
70 'com.android.support:viewpager': {'name':'android-support-viewpager', 'path':'viewpager'},
71 'com.android.support:coordinatorlayout': {'name':'android-support-coordinatorlayout', 'path':'coordinatorlayout'},
72 'com.android.support:asynclayoutinflater': {'name':'android-support-asynclayoutinflater', 'path':'asynclayoutinflater'},
73 'com.android.support:support-content': {'name':'android-support-support-content', 'path':'support-content'},
74 'com.android.support:documentfile': {'name':'android-support-documentfile', 'path':'documentfile'},
75 'com.android.support:drawerlayout': {'name':'android-support-drawerlayout', 'path':'drawerlayout'},
76 'com.android.support:localbroadcastmanager': {'name':'android-support-localbroadcastmanager', 'path':'localbroadcastmanager'},
77 'com.android.support:print': {'name':'android-support-print', 'path':'print'},
78 'com.android.support:slidingpanelayout': {'name':'android-support-slidingpanelayout', 'path':'slidingpanelayout'},
79 'com.android.support:interpolator': {'name':'android-support-interpolator', 'path':'interpolator'},
80 'com.android.support:cursoradapter': {'name':'android-support-cursoradapter', 'path':'cursoradapter'},
81 'com.android.support:loader': {'name':'android-support-loader', 'path':'loader'},
82 'com.android.support:contentpaging': {'name':'android-support-contentpaging', 'path':'contentpaging'},
83 'com.android.support:recyclerview-selection': {'name':'android-support-recyclerview-selection', 'path':'recyclerview-selection'},
84 'com.android.support:car': {'name':'android-support-car', 'path':'car'},
85 'com.android.support:slices-core': {'name':'android-slices-core', 'path':'slices-core'},
86 'com.android.support:slices-view': {'name':'android-slices-view', 'path':'slices-view'},
87 'com.android.support:slices-builders': {'name':'android-slices-builders', 'path':'slices-builders'},
88 'com.android.support:versionedparcelable': {'name':'android-versionedparcelable', 'path':'versionedparcelable'},
Alan Viverette19ecd502018-01-05 13:52:16 -050089
90 # Multidex
Jeff Gastona0bce602018-08-24 14:05:03 -040091 'com.android.support:multidex': {'name':'android-support-multidex', 'path':'multidex/library'},
92 'com.android.support:multidex-instrumentation': {'name':'android-support-multidex-instrumentation', 'path':'multidex/instrumentation'},
Alan Viverette19ecd502018-01-05 13:52:16 -050093
94 # Constraint Layout
Jeff Gastona0bce602018-08-24 14:05:03 -040095 'com.android.support.constraint:constraint-layout': {'name':'android-support-constraint-layout', 'path':'constraint-layout'},
96 'com.android.support.constraint:constraint-layout-solver': {'name':'android-support-constraint-layout-solver', 'path':'constraint-layout-solver'},
Alan Viverette19ecd502018-01-05 13:52:16 -050097
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -040098 # Architecture Components
Jeff Gastona0bce602018-08-24 14:05:03 -040099 'android.arch.core:runtime': {'name':'android-arch-core-runtime', 'path':'arch-core/runtime'},
100 'android.arch.core:common': {'name':'android-arch-core-common', 'path':'arch-core/common'},
101 'android.arch.lifecycle:common': {'name':'android-arch-lifecycle-common', 'path':'arch-lifecycle/common'},
102 'android.arch.lifecycle:common-java8': {'name':'android-arch-lifecycle-common-java8', 'path':'arch-lifecycle/common-java8'},
103 'android.arch.lifecycle:extensions': {'name':'android-arch-lifecycle-extensions', 'path':'arch-lifecycle/extensions'},
104 'android.arch.lifecycle:livedata': {'name':'android-arch-lifecycle-livedata', 'path':'arch-lifecycle/livedata'},
105 'android.arch.lifecycle:livedata-core': {'name':'android-arch-lifecycle-livedata-core', 'path':'arch-lifecycle/livedata-core'},
106 'android.arch.lifecycle:process': {'name':'android-arch-lifecycle-process', 'path':'arch-lifecycle/process'},
107 'android.arch.lifecycle:runtime': {'name':'android-arch-lifecycle-runtime', 'path':'arch-lifecycle/runtime'},
108 'android.arch.lifecycle:service': {'name':'android-arch-lifecycle-service', 'path':'arch-lifecycle/service'},
109 'android.arch.lifecycle:viewmodel': {'name':'android-arch-lifecycle-viewmodel', 'path':'arch-lifecycle/viewmodel'},
110 'android.arch.paging:common': {'name':'android-arch-paging-common', 'path':'arch-paging/common'},
111 'android.arch.paging:runtime': {'name':'android-arch-paging-runtime', 'path':'arch-paging/runtime'},
112 'android.arch.persistence:db': {'name':'android-arch-persistence-db', 'path':'arch-persistence/db'},
113 'android.arch.persistence:db-framework': {'name':'android-arch-persistence-db-framework', 'path':'arch-persistence/db-framework'},
114 'android.arch.persistence.room:common': {'name':'android-arch-room-common', 'path':'arch-room/common'},
115 'android.arch.persistence.room:migration': {'name':'android-arch-room-migration', 'path':'arch-room/migration'},
116 'android.arch.persistence.room:runtime': {'name':'android-arch-room-runtime', 'path':'arch-room/runtime'},
117 'android.arch.persistence.room:testing': {'name':'android-arch-room-testing', 'path':'arch-room/testing'},
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400118
119 # AndroidX
Jeff Gastona0bce602018-08-24 14:05:03 -0400120 'androidx.slice:slice-builders': {'name':'androidx.slice_slice-builders', 'path':'androidx/slice/slice-builders'},
121 'androidx.slice:slice-core': {'name':'androidx.slice_slice-core', 'path':'androidx/slice/slice-core'},
122 'androidx.slice:slice-view': {'name':'androidx.slice_slice-view', 'path':'androidx/slice/slice-view'},
Jeff Gaston07a3cf72018-08-24 14:16:34 -0400123 'androidx.remotecallback:remotecallback': {'name':'androidx.remotecallback_remotecallback', 'path':'androidx/remotecallback/remotecallback'},
124 'androidx.remotecallback:remotecallback-processor': {'name':'androidx.remotecallback_remotecallback-processor', 'path':'androidx/remotecallback/remotecallback-processor', 'host':True},
Jeff Gastona0bce602018-08-24 14:05:03 -0400125 'androidx.versionedparcelable:versionedparcelable': {'name':'androidx.versionedparcelable_versionedparcelable', 'path':'androidx/versionedparcelable'},
126 'androidx.vectordrawable:vectordrawable-animated': {'name':'androidx.vectordrawable_vectordrawable-animated', 'path':'androidx/vectordrawable/vectordrawable-animated'},
Aurimas Liutikasabaa49f2018-09-18 15:30:20 -0700127 'androidx.activity:activity': {'name':'androidx.activity_activity', 'path':'androidx/activity/activity'},
Nate Myren1fa47162019-11-12 11:28:06 -0800128 'androidx.activity:activity-ktx': {'name':'androidx.activity_activity-ktx', 'path':'androidx/activity/activity-ktx'},
Tony Mak0f658752019-07-19 11:11:05 +0100129 'androidx.annotation:annotation': {'name':'androidx.annotation_annotation', 'path':'androidx/annotation/annotation', 'host_and_device' : True},
Jeff Gastona0bce602018-08-24 14:05:03 -0400130 'androidx.asynclayoutinflater:asynclayoutinflater': {'name':'androidx.asynclayoutinflater_asynclayoutinflater', 'path':'androidx/asynclayoutinflater/asynclayoutinflater'},
131 'androidx.car:car': {'name':'androidx.car_car', 'path':'androidx/car/car'},
Roberto Perez804fbb42018-09-10 17:58:11 -0700132 'androidx.car:car-cluster': {'name':'androidx.car_car-cluster', 'path':'androidx/car/car-cluster'},
Jeff Gastona0bce602018-08-24 14:05:03 -0400133 'androidx.collection:collection': {'name':'androidx.collection_collection', 'path':'androidx/collection/collection'},
Nate Myren1fa47162019-11-12 11:28:06 -0800134 'androidx.collection:collection-ktx': {'name':'androidx.collection_collection-ktx', 'path':'androidx/collection/collection-ktx'},
Aurimas Liutikasd9124762018-09-28 15:31:35 -0700135 'androidx.concurrent:concurrent-futures': {'name':'androidx.concurrent_concurrent-futures', 'path':'androidx/concurrent/concurrent-futures'},
Aurimas Liutikas8af28d32019-06-06 14:04:01 -0700136 'androidx.concurrent:concurrent-listenablefuture-callback': {'name':'androidx.concurrent_concurrent-listenablefuture-callback', 'path':'androidx/concurrent/concurrent-listenablefuture-callback'},
137 'androidx.concurrent:concurrent-listenablefuture': {'name':'androidx.concurrent_concurrent-listenablefuture', 'path':'androidx/concurrent/concurrent-listenablefuture'},
Jeff Gastona0bce602018-08-24 14:05:03 -0400138 'androidx.core:core': {'name':'androidx.core_core', 'path':'androidx/core/core'},
Yvan Hsueh5efba6e2020-04-30 01:17:47 +0800139 'androidx.core:core-animation': {'name':'androidx.core_core-animation', 'path':'androidx/core/core-animation'},
Nate Myren1fa47162019-11-12 11:28:06 -0800140 'androidx.core:core-ktx': {'name':'androidx.core_core-ktx', 'path':'androidx/core/core-ktx'},
Jeff Gastona0bce602018-08-24 14:05:03 -0400141 'androidx.contentpaging:contentpaging': {'name':'androidx.contentpaging_contentpaging', 'path':'androidx/contentpaging/contentpaging'},
142 'androidx.coordinatorlayout:coordinatorlayout': {'name':'androidx.coordinatorlayout_coordinatorlayout', 'path':'androidx/coordinatorlayout/coordinatorlayout'},
143 'androidx.legacy:legacy-support-core-ui': {'name':'androidx.legacy_legacy-support-core-ui', 'path':'androidx/legacy/legacy-support-core-ui'},
144 'androidx.legacy:legacy-support-core-utils': {'name':'androidx.legacy_legacy-support-core-utils', 'path':'androidx/legacy/legacy-support-core-utils'},
145 'androidx.cursoradapter:cursoradapter': {'name':'androidx.cursoradapter_cursoradapter', 'path':'androidx/cursoradapter/cursoradapter'},
146 'androidx.browser:browser': {'name':'androidx.browser_browser', 'path':'androidx/browser/browser'},
147 'androidx.customview:customview': {'name':'androidx.customview_customview', 'path':'androidx/customview/customview'},
148 'androidx.documentfile:documentfile': {'name':'androidx.documentfile_documentfile', 'path':'androidx/documentfile/documentfile'},
149 'androidx.drawerlayout:drawerlayout': {'name':'androidx.drawerlayout_drawerlayout', 'path':'androidx/drawerlayout/drawerlayout'},
150 'androidx.dynamicanimation:dynamicanimation': {'name':'androidx.dynamicanimation_dynamicanimation', 'path':'androidx/dynamicanimation/dynamicanimation'},
151 'androidx.emoji:emoji': {'name':'androidx.emoji_emoji', 'path':'androidx/emoji/emoji'},
152 'androidx.emoji:emoji-appcompat': {'name':'androidx.emoji_emoji-appcompat', 'path':'androidx/emoji/emoji-appcompat'},
153 'androidx.emoji:emoji-bundled': {'name':'androidx.emoji_emoji-bundled', 'path':'androidx/emoji/emoji-bundled'},
154 'androidx.exifinterface:exifinterface': {'name':'androidx.exifinterface_exifinterface', 'path':'androidx/exifinterface/exifinterface'},
155 'androidx.fragment:fragment': {'name':'androidx.fragment_fragment', 'path':'androidx/fragment/fragment'},
Nate Myren1fa47162019-11-12 11:28:06 -0800156 'androidx.fragment:fragment-ktx': {'name':'androidx.fragment_fragment-ktx', 'path':'androidx/fragment/fragment-ktx'},
Jeff Gastona0bce602018-08-24 14:05:03 -0400157 'androidx.heifwriter:heifwriter': {'name':'androidx.heifwriter_heifwriter', 'path':'androidx/heifwriter/heifwriter'},
158 'androidx.interpolator:interpolator': {'name':'androidx.interpolator_interpolator', 'path':'androidx/interpolator/interpolator'},
159 'androidx.loader:loader': {'name':'androidx.loader_loader', 'path':'androidx/loader/loader'},
160 'androidx.localbroadcastmanager:localbroadcastmanager': {'name':'androidx.localbroadcastmanager_localbroadcastmanager', 'path':'androidx/localbroadcastmanager/localbroadcastmanager'},
161 'androidx.media:media': {'name':'androidx.media_media', 'path':'androidx/media/media'},
Oussama Ben Abdelbaki09fffcb2019-05-13 15:11:37 -0400162 'androidx.media2:media2-player': {'name':'androidx.media2_media2-player', 'path':'androidx/media2/media2-player'},
163 'androidx.media2:media2-session': {'name':'androidx.media2_media2-session', 'path':'androidx/media2/media2-session'},
164 'androidx.media2:media2-common': {'name':'androidx.media2_media2-common', 'path':'androidx/media2/media2-common'},
Jeff Gastona0bce602018-08-24 14:05:03 -0400165 'androidx.media2:media2-exoplayer': {'name':'androidx.media2_media2-exoplayer', 'path':'androidx/media2/media2-exoplayer'},
Gyumin Sim1752eca2018-12-13 11:34:10 +0900166 'androidx.media2:media2-widget': {'name':'androidx.media2_media2-widget', 'path':'androidx/media2/media2-widget'},
Nate Myren1fa47162019-11-12 11:28:06 -0800167 'androidx.navigation:navigation-common': {'name':'androidx.navigation_navigation-common', 'path':'androidx/navigation/navigation-common'},
168 'androidx.navigation:navigation-common-ktx': {'name':'androidx.navigation_navigation-common-ktx', 'path':'androidx/navigation/navigation-common-ktx'},
169 'androidx.navigation:navigation-fragment': {'name':'androidx.navigation_navigation-fragment', 'path':'androidx/navigation/navigation-fragment'},
170 'androidx.navigation:navigation-fragment-ktx': {'name':'androidx.navigation_navigation-fragment-ktx', 'path':'androidx/navigation/navigation-fragment-ktx'},
171 'androidx.navigation:navigation-runtime': {'name':'androidx.navigation_navigation-runtime', 'path':'androidx/navigation/navigation-runtime'},
172 'androidx.navigation:navigation-runtime-ktx': {'name':'androidx.navigation_navigation-runtime-ktx', 'path':'androidx/navigation/navigation-runtime-ktx'},
173 'androidx.navigation:navigation-ui': {'name':'androidx.navigation_navigation-ui', 'path':'androidx/navigation/navigation-ui'},
174 'androidx.navigation:navigation-ui-ktx': {'name':'androidx.navigation_navigation-ui-ktx', 'path':'androidx/navigation/navigation-ui-ktx'},
Jeff Gastona0bce602018-08-24 14:05:03 -0400175 'androidx.percentlayout:percentlayout': {'name':'androidx.percentlayout_percentlayout', 'path':'androidx/percentlayout/percentlayout'},
176 'androidx.print:print': {'name':'androidx.print_print', 'path':'androidx/print/print'},
177 'androidx.recommendation:recommendation': {'name':'androidx.recommendation_recommendation', 'path':'androidx/recommendation/recommendation'},
178 'androidx.recyclerview:recyclerview-selection': {'name':'androidx.recyclerview_recyclerview-selection', 'path':'androidx/recyclerview/recyclerview-selection'},
Oussama Ben Abdelbaki00f9b392019-03-18 14:45:12 -0400179 'androidx.savedstate:savedstate': {'name':'androidx.savedstate_savedstate', 'path':'androidx/savedstate/savedstate'},
Jeff Gastona0bce602018-08-24 14:05:03 -0400180 'androidx.slidingpanelayout:slidingpanelayout': {'name':'androidx.slidingpanelayout_slidingpanelayout', 'path':'androidx/slidingpanelayout/slidingpanelayout'},
181 'androidx.swiperefreshlayout:swiperefreshlayout': {'name':'androidx.swiperefreshlayout_swiperefreshlayout', 'path':'androidx/swiperefreshlayout/swiperefreshlayout'},
182 'androidx.textclassifier:textclassifier': {'name':'androidx.textclassifier_textclassifier', 'path':'androidx/textclassifier/textclassifier'},
183 'androidx.transition:transition': {'name':'androidx.transition_transition', 'path':'androidx/transition/transition'},
184 'androidx.tvprovider:tvprovider': {'name':'androidx.tvprovider_tvprovider', 'path':'androidx/tvprovider/tvprovider'},
185 'androidx.legacy:legacy-support-v13': {'name':'androidx.legacy_legacy-support-v13', 'path':'androidx/legacy/legacy-support-v13'},
186 'androidx.legacy:legacy-preference-v14': {'name':'androidx.legacy_legacy-preference-v14', 'path':'androidx/legacy/legacy-preference-v14'},
187 'androidx.leanback:leanback': {'name':'androidx.leanback_leanback', 'path':'androidx/leanback/leanback'},
188 'androidx.leanback:leanback-preference': {'name':'androidx.leanback_leanback-preference', 'path':'androidx/leanback/leanback-preference'},
189 'androidx.legacy:legacy-support-v4': {'name':'androidx.legacy_legacy-support-v4', 'path':'androidx/legacy/legacy-support-v4'},
190 'androidx.appcompat:appcompat': {'name':'androidx.appcompat_appcompat', 'path':'androidx/appcompat/appcompat'},
Oussama Ben Abdelbaki61551b82019-02-12 15:56:27 -0500191 'androidx.appcompat:appcompat-resources': {'name':'androidx.appcompat_appcompat-resources', 'path':'androidx/appcompat/appcompat-resources'},
Jeff Gastona0bce602018-08-24 14:05:03 -0400192 'androidx.cardview:cardview': {'name':'androidx.cardview_cardview', 'path':'androidx/cardview/cardview'},
193 'androidx.gridlayout:gridlayout': {'name':'androidx.gridlayout_gridlayout', 'path':'androidx/gridlayout/gridlayout'},
194 'androidx.mediarouter:mediarouter': {'name':'androidx.mediarouter_mediarouter', 'path':'androidx/mediarouter/mediarouter'},
195 'androidx.palette:palette': {'name':'androidx.palette_palette', 'path':'androidx/palette/palette'},
196 'androidx.preference:preference': {'name':'androidx.preference_preference', 'path':'androidx/preference/preference'},
197 'androidx.recyclerview:recyclerview': {'name':'androidx.recyclerview_recyclerview', 'path':'androidx/recyclerview/recyclerview'},
198 'androidx.vectordrawable:vectordrawable': {'name':'androidx.vectordrawable_vectordrawable', 'path':'androidx/vectordrawable/vectordrawable'},
199 'androidx.viewpager:viewpager': {'name':'androidx.viewpager_viewpager', 'path':'androidx/viewpager/viewpager'},
Fabian Kozynskie514c122020-03-04 14:41:08 -0500200 'androidx.viewpager2:viewpager2': {'name':'androidx.viewpager2_viewpager2', 'path':'androidx/viewpager2/viewpager2'},
Jeff Gastona0bce602018-08-24 14:05:03 -0400201 'androidx.wear:wear': {'name':'androidx.wear_wear', 'path':'androidx/wear/wear'},
202 'androidx.webkit:webkit': {'name':'androidx.webkit_webkit', 'path':'androidx/webkit/webkit'},
Kevin Chynb6ae85d2018-10-02 12:12:20 -0700203 'androidx.biometric:biometric': {'name':'androidx.biometric_biometric', 'path':'androidx/biometric/biometric'},
Adam He7dec9ff2020-01-27 14:05:45 -0800204 'androidx.autofill:autofill': {'name':'androidx.autofill_autofill', 'path':'androidx/autofill/autofill'},
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400205
206 # AndroidX for Multidex
Jeff Gastona0bce602018-08-24 14:05:03 -0400207 'androidx.multidex:multidex': {'name':'androidx-multidex_multidex', 'path':'androidx/multidex/multidex'},
208 'androidx.multidex:multidex-instrumentation': {'name':'androidx-multidex_multidex-instrumentation', 'path':'androidx/multidex/multidex-instrumentation'},
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400209
210 # AndroidX for Constraint Layout
Jeff Gastona0bce602018-08-24 14:05:03 -0400211 'androidx.constraintlayout:constraintlayout': {'name':'androidx-constraintlayout_constraintlayout', 'path':'androidx/constraintlayout/constraintlayout'},
212 'androidx.constraintlayout:constraintlayout-solver': {'name':'androidx-constraintlayout_constraintlayout-solver', 'path':'androidx/constraintlayout/constraintlayout-solver'},
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400213
214 # AndroidX for Architecture Components
Jeff Gastona0bce602018-08-24 14:05:03 -0400215 'androidx.arch.core:core-common': {'name':'androidx.arch.core_core-common', 'path':'androidx/arch/core/core-common'},
216 'androidx.arch.core:core-runtime': {'name':'androidx.arch.core_core-runtime', 'path':'androidx/arch/core/core-runtime'},
217 'androidx.lifecycle:lifecycle-common': {'name':'androidx.lifecycle_lifecycle-common', 'path':'androidx/lifecycle/lifecycle-common'},
218 'androidx.lifecycle:lifecycle-common-java8': {'name':'androidx.lifecycle_lifecycle-common-java8', 'path':'androidx/lifecycle/lifecycle-common-java8'},
219 'androidx.lifecycle:lifecycle-extensions': {'name':'androidx.lifecycle_lifecycle-extensions', 'path':'androidx/lifecycle/lifecycle-extensions'},
220 'androidx.lifecycle:lifecycle-livedata': {'name':'androidx.lifecycle_lifecycle-livedata', 'path':'androidx/lifecycle/lifecycle-livedata'},
Nate Myren1fa47162019-11-12 11:28:06 -0800221 'androidx.lifecycle:lifecycle-livedata-ktx': {'name':'androidx.lifecycle_lifecycle-livedata-ktx', 'path':'androidx/lifecycle/lifecycle-livedata-ktx'},
Jeff Gastona0bce602018-08-24 14:05:03 -0400222 'androidx.lifecycle:lifecycle-livedata-core': {'name':'androidx.lifecycle_lifecycle-livedata-core', 'path':'androidx/lifecycle/lifecycle-livedata-core'},
Nate Myren1fa47162019-11-12 11:28:06 -0800223 'androidx.lifecycle:lifecycle-livedata-core-ktx': {'name':'androidx.lifecycle_lifecycle-livedata-core-ktx', 'path':'androidx/lifecycle/lifecycle-livedata-core-ktx'},
Jeff Gastona0bce602018-08-24 14:05:03 -0400224 'androidx.lifecycle:lifecycle-process': {'name':'androidx.lifecycle_lifecycle-process', 'path':'androidx/lifecycle/lifecycle-process'},
225 'androidx.lifecycle:lifecycle-runtime': {'name':'androidx.lifecycle_lifecycle-runtime', 'path':'androidx/lifecycle/lifecycle-runtime'},
Nate Myren1fa47162019-11-12 11:28:06 -0800226 'androidx.lifecycle:lifecycle-runtime-ktx': {'name':'androidx.lifecycle_lifecycle-runtime-ktx', 'path':'androidx/lifecycle/lifecycle-runtime-ktx'},
Jeff Gastona0bce602018-08-24 14:05:03 -0400227 'androidx.lifecycle:lifecycle-service': {'name':'androidx.lifecycle_lifecycle-service', 'path':'androidx/lifecycle/lifecycle-service'},
228 'androidx.lifecycle:lifecycle-viewmodel': {'name':'androidx.lifecycle_lifecycle-viewmodel', 'path':'androidx/lifecycle/lifecycle-viewmodel'},
Nate Myren1fa47162019-11-12 11:28:06 -0800229 'androidx.lifecycle:lifecycle-viewmodel-ktx': {'name':'androidx.lifecycle_lifecycle-viewmodel-ktx', 'path':'androidx/lifecycle/lifecycle-viewmodel-ktx'},
Aurimas Liutikasb5836e22019-09-06 09:00:45 -0700230 'androidx.lifecycle:lifecycle-viewmodel-savedstate': {'name':'androidx.lifecycle_lifecycle-viewmodel-savedstate', 'path':'androidx/lifecycle/lifecycle-viewmodel-savedstate'},
Jeff Gastona0bce602018-08-24 14:05:03 -0400231 'androidx.paging:paging-common': {'name':'androidx.paging_paging-common', 'path':'androidx/paging/paging-common'},
Aurimas Liutikasb5836e22019-09-06 09:00:45 -0700232 'androidx.paging:paging-common-ktx': {'name':'androidx.paging_paging-common-ktx', 'path':'androidx/paging/paging-common-ktx'},
Jeff Gastona0bce602018-08-24 14:05:03 -0400233 'androidx.paging:paging-runtime': {'name':'androidx.paging_paging-runtime', 'path':'androidx/paging/paging-runtime'},
234 'androidx.sqlite:sqlite': {'name':'androidx.sqlite_sqlite', 'path':'androidx/sqlite/sqlite'},
235 'androidx.sqlite:sqlite-framework': {'name':'androidx.sqlite_sqlite-framework', 'path':'androidx/sqlite/sqlite-framework'},
Tony Mak0f658752019-07-19 11:11:05 +0100236 'androidx.room:room-common': {'name':'androidx.room_room-common', 'path':'androidx/room/room-common', 'host_and_device' : True},
237 'androidx.room:room-compiler': {'name':'androidx.room_room-compiler', 'path':'androidx/room/room-compiler', 'host' : True},
238 'androidx.room:room-migration': {'name':'androidx.room_room-migration', 'path':'androidx/room/room-migration', 'host_and_device' : True},
Jeff Gastona0bce602018-08-24 14:05:03 -0400239 'androidx.room:room-runtime': {'name':'androidx.room_room-runtime', 'path':'androidx/room/room-runtime'},
240 'androidx.room:room-testing': {'name':'androidx.room_room-testing', 'path':'androidx/room/room-testing'},
Allenab72f012018-01-29 18:10:23 -0800241
Alan Viverette19ecd502018-01-05 13:52:16 -0500242 # Lifecycle
Alan Viverettec7e88f12018-02-13 15:29:50 -0500243 # Missing dependencies:
244 # - auto-common
245 # - javapoet
Jeff Gastona0bce602018-08-24 14:05:03 -0400246 #'android.arch.lifecycle:compiler': {'name':'android-arch-lifecycle-compiler', 'path':'arch-lifecycle/compiler'},
Alan Viverettec7e88f12018-02-13 15:29:50 -0500247 # Missing dependencies:
248 # - reactive-streams
Jeff Gastona0bce602018-08-24 14:05:03 -0400249 #'android.arch.lifecycle:reactivestreams': 'android-arch-lifecycle-reactivestreams','arch-lifecycle/reactivestreams',
Allenab72f012018-01-29 18:10:23 -0800250
Alan Viverette19ecd502018-01-05 13:52:16 -0500251 # Room
Alan Viverettec7e88f12018-02-13 15:29:50 -0500252 # Missing dependencies:
253 # - auto-common
254 # - javapoet
255 # - antlr4
256 # - kotlin-metadata
257 # - commons-codec
Jeff Gastona0bce602018-08-24 14:05:03 -0400258 #'android.arch.persistence.room:compiler': {'name':'android-arch-room-compiler', 'path':'arch-room/compiler'},
Alan Viverettec7e88f12018-02-13 15:29:50 -0500259 # Missing dependencies:
260 # - rxjava
Jeff Gastona0bce602018-08-24 14:05:03 -0400261 #'android.arch.persistence.room:rxjava2': {'name':'android-arch-room-rxjava2', 'path':'arch-room/rxjava2'},
Allenab72f012018-01-29 18:10:23 -0800262
Jeff Gaston6e7e7502018-04-04 00:22:45 -0400263 # Third-party dependencies
Jeff Gastona0bce602018-08-24 14:05:03 -0400264 'com.google.android:flexbox': {'name':'flexbox', 'path':'flexbox'},
Jeff Gaston6e7e7502018-04-04 00:22:45 -0400265
266 # Support Library Material Design Components
Jeff Gastona0bce602018-08-24 14:05:03 -0400267 'com.android.support:design': {'name':'android-support-design', 'path':'design'},
268 'com.android.support:design-animation': {'name':'android-support-design-animation', 'path':'design-animation'},
269 'com.android.support:design-bottomnavigation': {'name':'android-support-design-bottomnavigation', 'path':'design-bottomnavigation'},
270 'com.android.support:design-bottomsheet': {'name':'android-support-design-bottomsheet', 'path':'design-bottomsheet'},
271 'com.android.support:design-button': {'name':'android-support-design-button', 'path':'design-button'},
272 'com.android.support:design-canvas': {'name':'android-support-design-canvas', 'path':'design-canvas'},
273 'com.android.support:design-card': {'name':'android-support-design-card', 'path':'design-card'},
274 'com.android.support:design-chip': {'name':'android-support-design-chip', 'path':'design-chip'},
275 'com.android.support:design-circularreveal': {'name':'android-support-design-circularreveal', 'path':'design-circularreveal'},
276 'com.android.support:design-circularreveal-cardview': {'name':'android-support-design-circularreveal-cardview', 'path':'design-circularreveal-cardview'},
277 'com.android.support:design-circularreveal-coordinatorlayout': {'name':'android-support-design-circularreveal-coordinatorlayout', 'path':'design-circularreveal-coordinatorlayout'},
278 'com.android.support:design-color': {'name':'android-support-design-color', 'path':'design-color'},
279 'com.android.support:design-dialog': {'name':'android-support-design-dialog', 'path':'design-dialog'},
280 'com.android.support:design-drawable': {'name':'android-support-design-drawable', 'path':'design-drawable'},
281 'com.android.support:design-expandable': {'name':'android-support-design-expandable', 'path':'design-expandable'},
282 'com.android.support:design-floatingactionbutton': {'name':'android-support-design-floatingactionbutton', 'path':'design-floatingactionbutton'},
283 'com.android.support:design-internal': {'name':'android-support-design-internal', 'path':'design-internal'},
284 'com.android.support:design-math': {'name':'android-support-design-math', 'path':'design-math'},
285 'com.android.support:design-resources': {'name':'android-support-design-resources', 'path':'design-resources'},
286 'com.android.support:design-ripple': {'name':'android-support-design-ripple', 'path':'design-ripple'},
287 'com.android.support:design-snackbar': {'name':'android-support-design-snackbar', 'path':'design-snackbar'},
288 'com.android.support:design-stateful': {'name':'android-support-design-stateful', 'path':'design-stateful'},
289 'com.android.support:design-textfield': {'name':'android-support-design-textfield', 'path':'design-textfield'},
290 'com.android.support:design-theme': {'name':'android-support-design-theme', 'path':'design-theme'},
291 'com.android.support:design-transformation': {'name':'android-support-design-transformation', 'path':'design-transformation'},
292 'com.android.support:design-typography': {'name':'android-support-design-typography', 'path':'design-typography'},
293 'com.android.support:design-widget': {'name':'android-support-design-widget', 'path':'design-widget'},
294 'com.android.support:design-navigation': {'name':'android-support-design-navigation', 'path':'design-navigation'},
295 'com.android.support:design-tabs': {'name':'android-support-design-tabs', 'path':'design-tabs'},
296 'com.android.support:design-bottomappbar': {'name':'android-support-design-bottomappbar', 'path':'design-bottomappbar'},
297 'com.android.support:design-shape': {'name':'android-support-design-shape', 'path':'design-shape'},
Alan Viverettea59082b2018-02-22 10:27:46 -0500298
Jeff Gastonfa7c7e82018-04-06 13:35:48 -0400299 # Androidx Material Design Components
Jeff Gastona0bce602018-08-24 14:05:03 -0400300 'com.google.android.material:material': {'name':'com.google.android.material_material', 'path':'com/google/android/material/material'},
Alan Viverette95f6d362017-04-06 09:40:50 -0400301}
302
303# Always remove these files.
304blacklist_files = [
305 'annotations.zip',
306 'public.txt',
307 'R.txt',
Alan Viverette44ad4e42017-08-09 17:45:00 -0400308 'AndroidManifest.xml',
Alan Viverettef48d9b42017-08-17 14:45:46 -0400309 os.path.join('libs','noto-emoji-compat-java.jar')
Alan Viverette95f6d362017-04-06 09:40:50 -0400310]
311
Alan Viverette44ad4e42017-08-09 17:45:00 -0400312artifact_pattern = re.compile(r"^(.+?)-(\d+\.\d+\.\d+(?:-\w+\d+)?(?:-[\d.]+)*)\.(jar|aar)$")
Alan Viverette95f6d362017-04-06 09:40:50 -0400313
Alan Viverettec960cfb2017-12-04 13:09:22 -0500314
315class MavenLibraryInfo:
Jeff Gastonc302bb92018-03-23 13:53:48 -0400316 def __init__(self, key, group_id, artifact_id, version, dir, repo_dir, file):
Alan Viverettec960cfb2017-12-04 13:09:22 -0500317 self.key = key
318 self.group_id = group_id
319 self.artifact_id = artifact_id
320 self.version = version
Jeff Gastonc302bb92018-03-23 13:53:48 -0400321 self.dir = dir
Alan Viverettec960cfb2017-12-04 13:09:22 -0500322 self.repo_dir = repo_dir
323 self.file = file
324
325
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500326def print_e(*args, **kwargs):
327 print(*args, file=sys.stderr, **kwargs)
328
Alan Viverette95f6d362017-04-06 09:40:50 -0400329
330def touch(fname, times=None):
331 with open(fname, 'a'):
332 os.utime(fname, times)
333
334
Alan Viverette45837092017-05-12 14:50:53 -0400335def path(*path_parts):
336 return reduce((lambda x, y: os.path.join(x, y)), path_parts)
337
338
Alan Viverettecd3de262017-08-14 09:51:30 -0400339def flatten(list):
340 return reduce((lambda x, y: "%s %s" % (x, y)), list)
341
342
Alan Viverette45837092017-05-12 14:50:53 -0400343def rm(path):
344 if os.path.isdir(path):
345 rmtree(path)
346 elif os.path.exists(path):
347 os.remove(path)
348
349
350def mv(src_path, dst_path):
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400351 if os.path.exists(dst_path):
Alan Viverettecd3de262017-08-14 09:51:30 -0400352 rm(dst_path)
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400353 if not os.path.exists(os.path.dirname(dst_path)):
354 os.makedirs(os.path.dirname(dst_path))
Jiyong Park1d1c9632018-05-29 17:45:27 +0900355 for f in (glob.glob(src_path)):
356 if '*' in dst_path:
357 dst = os.path.join(os.path.dirname(dst_path), os.path.basename(f))
358 else:
359 dst = dst_path
shepshaparde4127cf2019-09-03 16:08:44 -0700360 move(f, dst)
Alan Viverette45837092017-05-12 14:50:53 -0400361
362
Jeff Gastonc302bb92018-03-23 13:53:48 -0400363def detect_artifacts(maven_repo_dirs):
Alan Viveretted4527e62017-05-11 15:03:25 -0400364 maven_lib_info = {}
365
Dan Willemsen814152e2017-11-06 13:22:11 -0800366 # Find the latest revision for each artifact, remove others
Jeff Gastonc302bb92018-03-23 13:53:48 -0400367 for repo_dir in maven_repo_dirs:
Dan Willemsen814152e2017-11-06 13:22:11 -0800368 for root, dirs, files in os.walk(repo_dir):
369 for file in files:
Alan Viverettec960cfb2017-12-04 13:09:22 -0500370 if file[-4:] == ".pom":
371 # Read the POM (hack hack hack).
372 group_id = ''
373 artifact_id = ''
374 version = ''
375 file = os.path.join(root, file)
376 with open(file) as pom_file:
377 for line in pom_file:
378 if line[:11] == ' <groupId>':
379 group_id = line[11:-11]
380 elif line[:14] == ' <artifactId>':
381 artifact_id = line[14:-14]
382 elif line[:11] == ' <version>':
383 version = line[11:-11]
384 if group_id == '' or artifact_id == '' or version == '':
385 print_e('Failed to find Maven artifact data in ' + file)
386 continue
Alan Viverette95f6d362017-04-06 09:40:50 -0400387
Alan Viverettec960cfb2017-12-04 13:09:22 -0500388 # Locate the artifact.
389 artifact_file = file[:-4]
390 if os.path.exists(artifact_file + '.jar'):
391 artifact_file = artifact_file + '.jar'
392 elif os.path.exists(artifact_file + '.aar'):
393 artifact_file = artifact_file + '.aar'
394 else:
395 print_e('Failed to find artifact for ' + artifact_file)
396 continue
397
398 # Make relative to root.
399 artifact_file = artifact_file[len(root) + 1:]
400
401 # Find the mapping.
402 group_artifact = group_id + ':' + artifact_id
Jeff Gaston3e622ba2018-03-26 23:24:46 -0400403 if group_artifact in maven_to_make:
Alan Viverettec960cfb2017-12-04 13:09:22 -0500404 key = group_artifact
Jeff Gaston3e622ba2018-03-26 23:24:46 -0400405 elif artifact_id in maven_to_make:
406 key = artifact_id
Alan Viverettec960cfb2017-12-04 13:09:22 -0500407 else:
408 print_e('Failed to find artifact mapping for ' + group_artifact)
409 continue
410
411 # Store the latest version.
412 version = LooseVersion(version)
413 if key not in maven_lib_info \
414 or version > maven_lib_info[key].version:
415 maven_lib_info[key] = MavenLibraryInfo(key, group_id, artifact_id, version,
416 root, repo_dir, artifact_file)
Alan Viverette95f6d362017-04-06 09:40:50 -0400417
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400418 return maven_lib_info
419
420
Colin Cross59b59db2018-04-24 13:58:05 -0700421def transform_maven_repos(maven_repo_dirs, transformed_dir, extract_res=True, include_static_deps=True):
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400422 cwd = os.getcwd()
423
424 # Use a temporary working directory.
Jeff Gastonc302bb92018-03-23 13:53:48 -0400425 maven_lib_info = detect_artifacts(maven_repo_dirs)
Jeff Gastona68a8d42018-03-23 14:00:13 -0400426 working_dir = temp_dir
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400427
Alan Viverettec960cfb2017-12-04 13:09:22 -0500428 if not maven_lib_info:
429 print_e('Failed to detect artifacts')
430 return False
431
Jeff Gastonc302bb92018-03-23 13:53:48 -0400432 # extract some files (for example, AndroidManifest.xml) from any relevant artifacts
Alan Viveretted4527e62017-05-11 15:03:25 -0400433 for info in maven_lib_info.values():
Alan Viveretted8ce7222017-12-11 17:24:43 -0500434 transform_maven_lib(working_dir, info, extract_res)
Dan Willemsen814152e2017-11-06 13:22:11 -0800435
Colin Cross74683bc2018-04-11 17:36:18 -0700436 # generate a single Android.bp that specifies to use all of the above artifacts
437 makefile = os.path.join(working_dir, 'Android.bp')
Alan Viverette4ec9a172018-02-20 16:19:31 -0500438 with open(makefile, 'w') as f:
Colin Cross74683bc2018-04-11 17:36:18 -0700439 args = ["pom2bp", "-sdk-version", "current"]
Jeff Gaston1cc06092018-03-28 15:51:02 -0400440 if include_static_deps:
441 args.append("-static-deps")
Jeff Gaston54868ee2018-04-25 19:43:35 -0400442 rewriteNames = sorted([name for name in maven_to_make if ":" in name] + [name for name in maven_to_make if ":" not in name])
Jeff Gastona0bce602018-08-24 14:05:03 -0400443 args.extend(["-rewrite=^" + name + "$=" + maven_to_make[name]['name'] for name in rewriteNames])
Jeff Gaston07a3cf72018-08-24 14:16:34 -0400444 args.extend(["-rewrite=^com.squareup:javapoet$=javapoet-prebuilt-jar"])
Aurimas Liutikasd9124762018-09-28 15:31:35 -0700445 args.extend(["-rewrite=^com.google.guava:listenablefuture$=guava-listenablefuture-prebuilt-jar"])
Tony Mak0f658752019-07-19 11:11:05 +0100446 args.extend(["-rewrite=^sqlite-jdbc$=xerial-sqlite-jdbc"])
Tony Mak0f658752019-07-19 11:11:05 +0100447 args.extend(["-rewrite=^gson$=gson-prebuilt-jar"])
Sunny Goyal6667ddb2020-03-03 15:15:54 -0800448 args.extend(["-rewrite=^com.intellij:annotations$=jetbrains-annotations"])
Paul Duffin44e033b2019-04-16 11:28:13 +0100449 args.extend(["-extra-static-libs=android-support-car=prebuilt-android.car-stubs"])
Sunny Goyal6667ddb2020-03-03 15:15:54 -0800450 args.extend(["-extra-static-libs=androidx.room_room-compiler=guava-21.0"])
Jeff Gaston07a3cf72018-08-24 14:16:34 -0400451 args.extend(["-host=" + name for name in maven_to_make if maven_to_make[name].get('host')])
Tony Mak0f658752019-07-19 11:11:05 +0100452 args.extend(["-host-and-device=" + name for name in maven_to_make if maven_to_make[name].get('host_and_device')])
Colin Cross21060072018-04-24 13:52:29 -0700453 # these depend on GSON which is not in AOSP
Tony Mak0f658752019-07-19 11:11:05 +0100454 args.extend(["-exclude=android-arch-room-migration",
Colin Cross21060072018-04-24 13:52:29 -0700455 "-exclude=android-arch-room-testing"])
Jeff Gaston7ec1d8f2018-03-27 00:25:12 -0400456 args.extend(["."])
Dan Willemsen814152e2017-11-06 13:22:11 -0800457 subprocess.check_call(args, stdout=f, cwd=working_dir)
Alan Viverette95f6d362017-04-06 09:40:50 -0400458
459 # Replace the old directory.
Jeff Gastonc302bb92018-03-23 13:53:48 -0400460 output_dir = os.path.join(cwd, transformed_dir)
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400461 mv(working_dir, output_dir)
Alan Viverettec960cfb2017-12-04 13:09:22 -0500462 return True
Alan Viverette95f6d362017-04-06 09:40:50 -0400463
Jeff Gastonc302bb92018-03-23 13:53:48 -0400464# 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 -0500465def transform_maven_lib(working_dir, artifact_info, extract_res):
Dan Willemsen814152e2017-11-06 13:22:11 -0800466 # Move library into working dir
Jeff Gaston9edf86c2018-04-18 13:45:23 -0400467 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 -0400468 mv(artifact_info.dir, new_dir)
Dan Willemsen814152e2017-11-06 13:22:11 -0800469
Alan Viverettec960cfb2017-12-04 13:09:22 -0500470 matcher = artifact_pattern.match(artifact_info.file)
471 maven_lib_name = artifact_info.key
Alan Viveretted4527e62017-05-11 15:03:25 -0400472 maven_lib_vers = matcher.group(2)
Alan Viverettec960cfb2017-12-04 13:09:22 -0500473 maven_lib_type = artifact_info.file[-3:]
Alan Viveretted4527e62017-05-11 15:03:25 -0400474
Jeff Gastona0bce602018-08-24 14:05:03 -0400475 make_lib_name = maven_to_make[artifact_info.key]['name']
476 make_dir_name = maven_to_make[artifact_info.key]['path']
Alan Viveretted4527e62017-05-11 15:03:25 -0400477
Alan Viverette129555e2018-01-30 09:57:57 -0500478 artifact_file = os.path.join(new_dir, artifact_info.file)
479
Colin Cross59b59db2018-04-24 13:58:05 -0700480 if maven_lib_type == "aar":
481 if extract_res:
482 target_dir = os.path.join(working_dir, make_dir_name)
483 if not os.path.exists(target_dir):
484 os.makedirs(target_dir)
Dan Willemsen814152e2017-11-06 13:22:11 -0800485
Alan Viverettec960cfb2017-12-04 13:09:22 -0500486 process_aar(artifact_file, target_dir)
Alan Viveretted4527e62017-05-11 15:03:25 -0400487
Colin Cross59b59db2018-04-24 13:58:05 -0700488 with zipfile.ZipFile(artifact_file) as zip:
489 manifests_dir = os.path.join(working_dir, "manifests")
490 zip.extract("AndroidManifest.xml", os.path.join(manifests_dir, make_lib_name))
Dan Willemsend677b602017-11-08 22:13:17 -0800491
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500492 print(maven_lib_vers, ":", maven_lib_name, "->", make_lib_name)
Alan Viveretted4527e62017-05-11 15:03:25 -0400493
Alan Viverette95f6d362017-04-06 09:40:50 -0400494
Alan Viverettec960cfb2017-12-04 13:09:22 -0500495def process_aar(artifact_file, target_dir):
Alan Viverette95f6d362017-04-06 09:40:50 -0400496 # Extract AAR file to target_dir.
497 with zipfile.ZipFile(artifact_file) as zip:
498 zip.extractall(target_dir)
499
Dan Willemsen814152e2017-11-06 13:22:11 -0800500 # Remove classes.jar
Alan Viverette95f6d362017-04-06 09:40:50 -0400501 classes_jar = os.path.join(target_dir, "classes.jar")
502 if os.path.exists(classes_jar):
Dan Willemsen814152e2017-11-06 13:22:11 -0800503 os.remove(classes_jar)
Alan Viverette95f6d362017-04-06 09:40:50 -0400504
505 # Remove or preserve empty dirs.
506 for root, dirs, files in os.walk(target_dir):
507 for dir in dirs:
508 dir_path = os.path.join(root, dir)
509 if not os.listdir(dir_path):
510 os.rmdir(dir_path)
511
512 # Remove top-level cruft.
513 for file in blacklist_files:
514 file_path = os.path.join(target_dir, file)
515 if os.path.exists(file_path):
516 os.remove(file_path)
517
Alan Viverettef17c9402017-07-19 12:57:40 -0400518
Alan Viverettecd3de262017-08-14 09:51:30 -0400519def fetch_artifact(target, build_id, artifact_path):
Jiyong Park1d1c9632018-05-29 17:45:27 +0900520 download_to = os.path.join('.', os.path.dirname(artifact_path))
521 print('Fetching %s from %s ...' % (artifact_path, target))
522 if not os.path.exists(download_to):
523 os.makedirs(download_to)
524 fetch_cmd = [FETCH_ARTIFACT, '--bid', str(build_id), '--target', target, artifact_path,
525 download_to]
Jeff Gaston97a9b762018-10-02 15:15:12 -0400526 print("Running: " + ' '.join(fetch_cmd))
Alan Viverette45837092017-05-12 14:50:53 -0400527 try:
Alan Viverettecd3de262017-08-14 09:51:30 -0400528 subprocess.check_output(fetch_cmd, stderr=subprocess.STDOUT)
Alan Viverette45837092017-05-12 14:50:53 -0400529 except subprocess.CalledProcessError:
Jeff Gaston13e38412018-02-06 14:45:36 -0500530 print_e('FAIL: Unable to retrieve %s artifact for build ID %s' % (artifact_path, build_id))
Alan Viverettec1c32b62017-12-20 09:40:36 -0500531 print_e('Please make sure you are authenticated for build server access!')
Alan Viverette45837092017-05-12 14:50:53 -0400532 return None
533 return artifact_path
534
535
Anton Hansson1d01a032018-04-09 10:29:37 +0100536def fetch_artifacts(target, build_id, artifact_dict):
537 for artifact, target_path in artifact_dict.items():
538 artifact_path = fetch_artifact(target, build_id.url_id, artifact)
539 if not artifact_path:
540 return False
541 mv(artifact_path, target_path)
542 return True
543
544
Alan Viverette129555e2018-01-30 09:57:57 -0500545def extract_artifact(artifact_path):
Alan Viverette45837092017-05-12 14:50:53 -0400546 # Unzip the repo archive into a separate directory.
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400547 repo_dir = os.path.basename(artifact_path)[:-4]
Alan Viverette45837092017-05-12 14:50:53 -0400548 with zipfile.ZipFile(artifact_path) as zipFile:
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400549 zipFile.extractall(repo_dir)
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400550 return repo_dir
551
552
Alan Viverette7e897e22018-03-09 15:24:10 -0500553def fetch_and_extract(target, build_id, file, artifact_path=None):
554 if not artifact_path:
555 artifact_path = fetch_artifact(target, build_id, file)
Alan Viverette129555e2018-01-30 09:57:57 -0500556 if not artifact_path:
557 return None
558 return extract_artifact(artifact_path)
559
560
Alan Viverette7e897e22018-03-09 15:24:10 -0500561def update_support(target, build_id, local_file):
562 if build_id:
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400563 repo_file = 'top-of-tree-m2repository-dejetified-%s.zip' % build_id.fs_id
Alan Viverette7e897e22018-03-09 15:24:10 -0500564 repo_dir = fetch_and_extract(target, build_id.url_id, repo_file, None)
565 else:
566 repo_dir = fetch_and_extract(target, None, None, local_file)
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400567 if not repo_dir:
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500568 print_e('Failed to extract Support Library repository')
Alan Viverettef48d9b42017-08-17 14:45:46 -0400569 return False
Alan Viverette45837092017-05-12 14:50:53 -0400570
571 # Transform the repo archive into a Makefile-compatible format.
Colin Cross59b59db2018-04-24 13:58:05 -0700572 return transform_maven_repos([repo_dir], support_dir, extract_res=True)
Alan Viverettec960cfb2017-12-04 13:09:22 -0500573
Alan Viverette7e897e22018-03-09 15:24:10 -0500574
Jeff Gaston08a2ee42018-05-07 18:08:41 -0400575def update_androidx(target, build_id, local_file):
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400576 if build_id:
Anthony Chenacbb4872018-07-02 11:22:48 -0700577 repo_file = 'top-of-tree-m2repository-all-%s.zip' % build_id.fs_id
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400578 repo_dir = fetch_and_extract(target, build_id.url_id, repo_file, None)
579 else:
580 repo_dir = fetch_and_extract(target, None, None, local_file)
581 if not repo_dir:
582 print_e('Failed to extract AndroidX repository')
583 return False
584
Tony Mak0f658752019-07-19 11:11:05 +0100585 # Keep JavaPlugins.bp file untounched.
586 java_plugins_bp_path = os.path.join(androidx_dir, 'JavaPlugins.bp')
587 tmp_java_plugins_bp_path = os.path.join('/tmp', 'JavaPlugins.bp')
588 mv(java_plugins_bp_path, tmp_java_plugins_bp_path)
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400589
Tony Mak0f658752019-07-19 11:11:05 +0100590 # Transform the repo archive into a Makefile-compatible format.
591 if not transform_maven_repos([repo_dir], androidx_dir, extract_res=False):
592 return False
593
594 # Import JavaPlugins.bp in Android.bp.
595 makefile = os.path.join(androidx_dir, 'Android.bp')
596 with open(makefile, "a+") as f:
597 f.write('\nbuild = ["JavaPlugins.bp"]\n')
598 mv(tmp_java_plugins_bp_path, java_plugins_bp_path)
599
600 return True
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400601
Jeff Gaston782c3e32018-02-06 14:36:17 -0500602def update_jetifier(target, build_id):
603 repo_file = 'jetifier-standalone.zip'
604 repo_dir = fetch_and_extract(target, build_id.url_id, repo_file)
605 if not repo_dir:
606 print_e('Failed to extract Jetifier')
607 return False
608
609 rm(jetifier_dir)
Jeff Gaston553a4372018-03-29 18:34:22 -0400610 mv(os.path.join(repo_dir, 'jetifier-standalone'), jetifier_dir)
611 os.chmod(os.path.join(jetifier_dir, 'bin', 'jetifier-standalone'), 0o755)
Jeff Gaston782c3e32018-02-06 14:36:17 -0500612 return True
613
Alan Viverette7e897e22018-03-09 15:24:10 -0500614
Jeff Gastondb739a22018-06-26 14:12:22 -0400615def update_constraint(target, build_id, local_file):
616 if build_id:
617 layout_dir = fetch_and_extract(target, build_id.url_id,
618 'com.android.support.constraint-constraint-layout-%s.zip' % build_id.fs_id)
619 solver_dir = fetch_and_extract(target, build_id.url_id,
620 'com.android.support.constraint-constraint-layout-solver-%s.zip' % build_id.fs_id)
621 if not layout_dir or not solver_dir:
622 print_e('Failed to extract Constraint Layout repositories')
Alan Viverettecd3de262017-08-14 09:51:30 -0400623 return False
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400624
Jeff Gastondb739a22018-06-26 14:12:22 -0400625 dirs = [layout_dir, solver_dir]
626 else:
627 repo_dir = extract_artifact(local_file)
628 if not repo_dir:
629 print_e('Failed to extract Constraint Layout')
630 return False
631 dirs = [repo_dir]
632
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400633 # Passing False here is an inelegant solution, but it means we can replace
634 # the top-level directory without worrying about other child directories.
Jeff Gastondb739a22018-06-26 14:12:22 -0400635 return transform_maven_repos(dirs,
Alan Viverettec960cfb2017-12-04 13:09:22 -0500636 os.path.join(extras_dir, 'constraint-layout'), extract_res=False)
Alan Viverette45837092017-05-12 14:50:53 -0400637
Jeff Gaston9edf86c2018-04-18 13:45:23 -0400638def update_constraint_x(local_file):
639 repo_dir = extract_artifact(local_file)
640 if not repo_dir:
641 print_e('Failed to extract Constraint Layout X')
642 return False
643 return transform_maven_repos([repo_dir], os.path.join(extras_dir, 'constraint-layout-x'), extract_res=False)
644
Alan Viverette45837092017-05-12 14:50:53 -0400645
Alan Viverette129555e2018-01-30 09:57:57 -0500646def update_design(file):
647 design_dir = extract_artifact(file)
648 if not design_dir:
649 print_e('Failed to extract Design Library repositories')
650 return False
651
652 # Don't bother extracting resources -- this should only be used with AAPT2.
Jeff Gastonc302bb92018-03-23 13:53:48 -0400653 return transform_maven_repos([design_dir],
Alan Viverette129555e2018-01-30 09:57:57 -0500654 os.path.join(extras_dir, 'material-design'), extract_res=False)
655
656
Jeff Gaston6e7e7502018-04-04 00:22:45 -0400657def update_material(file):
658 design_dir = extract_artifact(file)
659 if not design_dir:
660 print_e('Failed to extract intermediate-AndroidX Design Library repositories')
661 return False
662
663 # Don't bother extracting resources -- this should only be used with AAPT2.
664 return transform_maven_repos([design_dir],
665 os.path.join(extras_dir, 'material-design-x'), extract_res=False)
666
667
Anton Hansson1d01a032018-04-09 10:29:37 +0100668def update_framework(build_id, sdk_dir):
Anton Hansson83f92172020-03-26 11:12:03 +0000669 api_scope_list = ['public', 'system', 'test', 'module-lib', 'system-server']
Sundong Ahn66091f22018-08-29 18:54:28 +0900670 if sdk_dir == 'current':
671 api_scope_list.append('core')
672
673 for api_scope in api_scope_list:
Jiyong Park1d1c9632018-05-29 17:45:27 +0900674 target_dir = path(sdk_dir, api_scope)
Sundong Ahn66091f22018-08-29 18:54:28 +0900675 if api_scope == 'core':
676 artifact_to_path = {'core.current.stubs.jar': path(target_dir, 'android.jar')}
677 else:
678 artifact_to_path = {'apistubs/android/' + api_scope + '/*.jar': path(target_dir, '*')}
Anton Hansson1d01a032018-04-09 10:29:37 +0100679
680 if not fetch_artifacts(framework_sdk_target, build_id, artifact_to_path):
681 return False
682
Jiyong Park1d1c9632018-05-29 17:45:27 +0900683 if api_scope == 'public':
Anton Hansson1d01a032018-04-09 10:29:37 +0100684 # Fetch a few artifacts from the public sdk.
Sundong Ahn66091f22018-08-29 18:54:28 +0900685 artifact = 'sdk-repo-linux-platforms-%s.zip' % build_id.fs_id
Anton Hansson1d01a032018-04-09 10:29:37 +0100686 artifact_path = fetch_artifact(framework_sdk_target, build_id.url_id, artifact)
Anton Hansson9709fd42018-04-03 16:52:13 +0100687 if not artifact_path:
688 return False
Anton Hansson1d01a032018-04-09 10:29:37 +0100689
690 with zipfile.ZipFile(artifact_path) as zipFile:
Colin Cross504be3b2020-07-10 19:17:54 -0700691 extra_files = [
692 'android.jar',
693 'framework.aidl',
694 'uiautomator.jar',
695 'core-for-system-modules.jar',
696 'data/annotations.zip',
697 'data/api-versions.xml']
698 for filename in extra_files:
Anton Hanssona26e4812020-03-25 12:54:39 +0000699 matches = list(filter(lambda path: filename in path, zipFile.namelist()))
700 if len(matches) != 1:
701 print_e('Expected 1 file named \'%s\' in zip %s, found %d' %
702 (filename, zipFile.filename, len(matches)))
703 return False
704 zip_path = matches[0]
705 src_path = zipFile.extract(zip_path)
706 dst_path = path(target_dir, filename)
707 mv(src_path, dst_path)
Anton Hansson9709fd42018-04-03 16:52:13 +0100708
Alan Viverettecd3de262017-08-14 09:51:30 -0400709 return True
Alan Viverette45837092017-05-12 14:50:53 -0400710
Sundong Ahncc34cc32018-07-11 15:18:47 +0900711def update_makefile(build_id):
712 template = '"%s",\n\
713 "current"'
714 makefile = os.path.join(git_dir, 'Android.bp')
715
716 with open(makefile, 'r+') as f:
717 contents = f.read().replace('"current"', template % build_id)
718 f.seek(0)
719 f.write(contents)
720
721 return True
Alan Viverette45837092017-05-12 14:50:53 -0400722
Anton Hansson1d01a032018-04-09 10:29:37 +0100723def finalize_sdk(build_id, sdk_version):
724 target_finalize_dir = '%d' % sdk_version
Anton Hansson9709fd42018-04-03 16:52:13 +0100725
Anton Hanssonaa554c02020-04-30 14:06:20 +0100726 for api_scope in ['public', 'system', 'test', 'module-lib', 'system-server']:
Sundong Ahn66091f22018-08-29 18:54:28 +0900727 artifact_to_path = {'apistubs/android/' + api_scope + '/api/*.txt':
728 path(target_finalize_dir, api_scope, 'api', '*')}
729
730 if not fetch_artifacts(framework_sdk_target, build_id, artifact_to_path):
731 return False
732
733 return update_framework(build_id, target_finalize_dir) \
Sundong Ahncc34cc32018-07-11 15:18:47 +0900734 and update_makefile(target_finalize_dir)
Anton Hansson9709fd42018-04-03 16:52:13 +0100735
Anton Hansson9709fd42018-04-03 16:52:13 +0100736
Anton Hansson1d01a032018-04-09 10:29:37 +0100737def update_framework_current(build_id):
738 return update_framework(build_id, current_path)
Anton Hansson9709fd42018-04-03 16:52:13 +0100739
740
Alan Viverettec1c32b62017-12-20 09:40:36 -0500741def update_buildtools(target, arch, build_id):
Jeff Gaston13e38412018-02-06 14:45:36 -0500742 artifact_path = fetch_and_extract(target, build_id.url_id,
743 "sdk-repo-%s-build-tools-%s.zip" % (arch, build_id.fs_id))
Alan Viverettec1c32b62017-12-20 09:40:36 -0500744 if not artifact_path:
745 return False
746
747 top_level_dir = os.listdir(artifact_path)[0]
748 src_path = os.path.join(artifact_path, top_level_dir)
749 dst_path = path(buildtools_dir, arch)
750 mv(src_path, dst_path)
751
752 # Move all top-level files to /bin and make them executable
753 bin_path = path(dst_path, 'bin')
754 top_level_files = filter(lambda e: os.path.isfile(path(dst_path, e)), os.listdir(dst_path))
755 for file in top_level_files:
756 src_file = path(dst_path, file)
757 dst_file = path(bin_path, file)
758 mv(src_file, dst_file)
759 os.chmod(dst_file, 0o755)
760
761 # Remove renderscript
762 rm(path(dst_path, 'renderscript'))
763
764 return True
765
766
Alan Viverettecd3de262017-08-14 09:51:30 -0400767def append(text, more_text):
768 if text:
769 return "%s, %s" % (text, more_text)
770 return more_text
Alan Viverette45837092017-05-12 14:50:53 -0400771
Alan Viverette95f6d362017-04-06 09:40:50 -0400772
Jeff Gaston13e38412018-02-06 14:45:36 -0500773class buildId(object):
774 def __init__(self, url_id, fs_id):
775 # id when used in build server urls
776 self.url_id = url_id
777 # id when used in build commands
778 self.fs_id = fs_id
779
Jeff Gastonb9b09052018-02-05 14:16:05 -0500780def getBuildId(args):
Jeff Gaston13e38412018-02-06 14:45:36 -0500781 # must be in the format 12345 or P12345
Jeff Gastonb9b09052018-02-05 14:16:05 -0500782 source = args.source
Jeff Gaston13e38412018-02-06 14:45:36 -0500783 number_text = source[:]
784 presubmit = False
785 if number_text.startswith("P"):
786 presubmit = True
787 number_text = number_text[1:]
788 if not number_text.isnumeric():
Alan Viverette7e897e22018-03-09 15:24:10 -0500789 return None
Jeff Gaston13e38412018-02-06 14:45:36 -0500790 url_id = source
791 fs_id = url_id
792 if presubmit:
793 fs_id = "0"
794 args.file = False
795 return buildId(url_id, fs_id)
Jeff Gastonb9b09052018-02-05 14:16:05 -0500796
Colin Cross573e1212018-02-12 14:59:52 -0800797def getFile(args):
798 source = args.source
799 if not source.isnumeric():
800 return args.source
Alan Viverette7e897e22018-03-09 15:24:10 -0500801 return None
Colin Cross573e1212018-02-12 14:59:52 -0800802
Alan Viverette4ec9a172018-02-20 16:19:31 -0500803
804def script_relative(rel_path):
Jeff Gastona68a8d42018-03-23 14:00:13 -0400805 return os.path.join(script_dir, rel_path)
Alan Viverette4ec9a172018-02-20 16:19:31 -0500806
807
Jeff Gastoncc296a82018-03-23 14:33:24 -0400808def uncommittedChangesExist():
809 try:
810 # Make sure we don't overwrite any pending changes.
811 diffCommand = "cd " + git_dir + " && git diff --quiet"
812 subprocess.check_call(diffCommand, shell=True)
813 subprocess.check_call(diffCommand + " --cached", shell=True)
814 return False
815 except subprocess.CalledProcessError:
816 return True
817
818
Jeff Gastona7fba9b2018-03-26 23:48:51 -0400819rm(temp_dir)
Alan Viveretted4527e62017-05-11 15:03:25 -0400820parser = argparse.ArgumentParser(
Alan Viverette45837092017-05-12 14:50:53 -0400821 description=('Update current prebuilts'))
Alan Viveretted4527e62017-05-11 15:03:25 -0400822parser.add_argument(
Alan Viverette129555e2018-01-30 09:57:57 -0500823 'source',
824 help='Build server build ID or local Maven ZIP file')
825parser.add_argument(
826 '-d', '--design', action="store_true",
827 help='If specified, updates only the Design Library')
Alan Viveretted4527e62017-05-11 15:03:25 -0400828parser.add_argument(
Jeff Gaston6e7e7502018-04-04 00:22:45 -0400829 '-m', '--material', action="store_true",
830 help='If specified, updates only the intermediate-AndroidX Design Library')
831parser.add_argument(
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400832 '-c', '--constraint', action="store_true",
833 help='If specified, updates only Constraint Layout')
834parser.add_argument(
Jeff Gaston9edf86c2018-04-18 13:45:23 -0400835 '--constraint_x', action="store_true",
836 help='If specified, updates Constraint Layout X')
837parser.add_argument(
Jeff Gaston782c3e32018-02-06 14:36:17 -0500838 '-j', '--jetifier', action="store_true",
839 help='If specified, updates only Jetifier')
840parser.add_argument(
Alan Viverette5bfe05b2017-06-06 14:21:29 -0400841 '-p', '--platform', action="store_true",
842 help='If specified, updates only the Android Platform')
Alan Viverettec1c32b62017-12-20 09:40:36 -0500843parser.add_argument(
Anton Hansson9709fd42018-04-03 16:52:13 +0100844 '-f', '--finalize_sdk', type=int,
845 help='If specified, imports the source build as the specified finalized SDK version')
846parser.add_argument(
Alan Viverettec1c32b62017-12-20 09:40:36 -0500847 '-b', '--buildtools', action="store_true",
848 help='If specified, updates only the Build Tools')
Jeff Gastoncc296a82018-03-23 14:33:24 -0400849parser.add_argument(
Jeff Gaston41fd5e62018-04-25 17:02:02 -0400850 '--stx', action="store_true",
Jeff Gaston08a2ee42018-05-07 18:08:41 -0400851 help='If specified, updates Support Library and Androidx (that is, all artifacts built from frameworks/support)')
Jeff Gaston41fd5e62018-04-25 17:02:02 -0400852parser.add_argument(
Jeff Gastoncc296a82018-03-23 14:33:24 -0400853 '--commit-first', action="store_true",
854 help='If specified, then if uncommited changes exist, commit before continuing')
Alan Viveretted4527e62017-05-11 15:03:25 -0400855args = parser.parse_args()
Jeff Gaston41fd5e62018-04-25 17:02:02 -0400856if args.stx:
Jeff Gaston26cdb232018-07-09 20:21:58 -0400857 args.androidx = True
Jeff Gaston41fd5e62018-04-25 17:02:02 -0400858else:
Jeff Gaston26cdb232018-07-09 20:21:58 -0400859 args.androidx = False
860args.support = False
Jeff Gaston56fe2762018-02-06 14:54:37 -0500861args.file = True
Alan Viverette129555e2018-01-30 09:57:57 -0500862if not args.source:
863 parser.error("You must specify a build ID or local Maven ZIP file")
Alan Viveretted4527e62017-05-11 15:03:25 -0400864 sys.exit(1)
Jeff Gaston08a2ee42018-05-07 18:08:41 -0400865if not (args.support or args.platform or args.constraint or args.buildtools \
Anton Hansson9709fd42018-04-03 16:52:13 +0100866 or args.design or args.jetifier or args.androidx or args.material \
Jeff Gaston9edf86c2018-04-18 13:45:23 -0400867 or args.finalize_sdk or args.constraint_x):
Alan Viverettec1c32b62017-12-20 09:40:36 -0500868 parser.error("You must specify at least one target to update")
Alan Viverettecd3de262017-08-14 09:51:30 -0400869 sys.exit(1)
Jeff Gaston08a2ee42018-05-07 18:08:41 -0400870if (args.support or args.constraint or args.constraint_x or args.design or args.material or args.androidx) \
Colin Cross74683bc2018-04-11 17:36:18 -0700871 and which('pom2bp') is None:
Louis Pullen-Freilich61bb70e2019-04-09 16:15:32 +0100872 parser.error("Cannot find pom2bp in path; please run lunch to set up build environment. You may also need to run 'm pom2bp' if it hasn't been built already.")
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500873 sys.exit(1)
Alan Viveretted4527e62017-05-11 15:03:25 -0400874
Jeff Gastoncc296a82018-03-23 14:33:24 -0400875if uncommittedChangesExist():
876 if args.commit_first:
877 subprocess.check_call("cd " + git_dir + " && git add -u", shell=True)
878 subprocess.check_call("cd " + git_dir + " && git commit -m 'save working state'", shell=True)
879
880if uncommittedChangesExist():
Anton Hansson10861a02018-04-06 13:57:08 +0100881 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 -0400882 sys.exit(1)
883
884try:
Alan Viverettecd3de262017-08-14 09:51:30 -0400885 components = None
886 if args.constraint:
Jeff Gastondb739a22018-06-26 14:12:22 -0400887 if update_constraint('studio', getBuildId(args), getFile(args)):
Alan Viverettecd3de262017-08-14 09:51:30 -0400888 components = append(components, 'Constraint Layout')
889 else:
Jeff Gaston9edf86c2018-04-18 13:45:23 -0400890 print_e('Failed to update Constraint Layout, aborting...')
891 sys.exit(1)
892 if args.constraint_x:
893 if update_constraint_x(getFile(args)):
894 components = append(components, 'Constraint Layout X')
895 else:
896 print_e('Failed to update Constraint Layout X, aborting...')
Alan Viverettecd3de262017-08-14 09:51:30 -0400897 sys.exit(1)
898 if args.support:
Jeff Gaston17ccf8f2018-08-29 11:33:19 -0400899 if update_support('androidx', getBuildId(args), getFile(args)):
Alan Viverettecd3de262017-08-14 09:51:30 -0400900 components = append(components, 'Support Library')
901 else:
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500902 print_e('Failed to update Support Library, aborting...')
Alan Viverettecd3de262017-08-14 09:51:30 -0400903 sys.exit(1)
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400904 if args.androidx:
Jeff Gaston17ccf8f2018-08-29 11:33:19 -0400905 if update_androidx('androidx', \
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400906 getBuildId(args), getFile(args)):
907 components = append(components, 'AndroidX')
908 else:
909 print_e('Failed to update AndroidX, aborting...')
910 sys.exit(1)
Jeff Gaston782c3e32018-02-06 14:36:17 -0500911 if args.jetifier:
Jeff Gaston17ccf8f2018-08-29 11:33:19 -0400912 if update_jetifier('androidx', getBuildId(args)):
Jeff Gaston782c3e32018-02-06 14:36:17 -0500913 components = append(components, 'Jetifier')
914 else:
915 print_e('Failed to update Jetifier, aborting...')
916 sys.exit(1)
Anton Hanssonbe15e8c2018-04-26 17:35:45 +0100917 if args.platform or args.finalize_sdk:
Anton Hansson87654c42018-04-26 15:19:42 +0100918 if update_framework_current(getBuildId(args)):
Alan Viverettecd3de262017-08-14 09:51:30 -0400919 components = append(components, 'platform SDK')
920 else:
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500921 print_e('Failed to update platform SDK, aborting...')
Alan Viverettecd3de262017-08-14 09:51:30 -0400922 sys.exit(1)
Anton Hansson9709fd42018-04-03 16:52:13 +0100923 if args.finalize_sdk:
Anton Hanssonbe15e8c2018-04-26 17:35:45 +0100924 n = args.finalize_sdk
925 if finalize_sdk(getBuildId(args), n):
926 # We commit the finalized dir separately from the current sdk update.
927 msg = "Import final sdk version %d from build %s" % (n, getBuildId(args).url_id)
928 subprocess.check_call(['git', 'add', '%d' % n])
Sundong Ahncc34cc32018-07-11 15:18:47 +0900929 subprocess.check_call(['git', 'add', 'Android.bp'])
Anton Hanssonbe15e8c2018-04-26 17:35:45 +0100930 subprocess.check_call(['git', 'commit', '-m', msg])
Anton Hansson9709fd42018-04-03 16:52:13 +0100931 else:
Anton Hanssonbe15e8c2018-04-26 17:35:45 +0100932 print_e('Failed to finalize SDK %d, aborting...' % n)
Anton Hansson9709fd42018-04-03 16:52:13 +0100933 sys.exit(1)
Alan Viverette129555e2018-01-30 09:57:57 -0500934 if args.design:
Colin Cross573e1212018-02-12 14:59:52 -0800935 if update_design(getFile(args)):
Alan Viverette129555e2018-01-30 09:57:57 -0500936 components = append(components, 'Design Library')
937 else:
Jeff Gaston6e7e7502018-04-04 00:22:45 -0400938 print_e('Failed to update Design Library, aborting...')
939 sys.exit(1)
940 if args.material:
941 if update_material(getFile(args)):
942 components = append(components, 'intermediate-AndroidX Design Library')
943 else:
944 print_e('Failed to update intermediate-AndroidX Design Library, aborting...')
Alan Viverette129555e2018-01-30 09:57:57 -0500945 sys.exit(1)
Alan Viverettec1c32b62017-12-20 09:40:36 -0500946 if args.buildtools:
Jeff Gastonb9b09052018-02-05 14:16:05 -0500947 if update_buildtools('sdk_phone_armv7-sdk_mac', 'darwin', getBuildId(args)) \
948 and update_buildtools('sdk_phone_x86_64-sdk', 'linux', getBuildId(args)) \
949 and update_buildtools('sdk_phone_armv7-win_sdk', 'windows', getBuildId(args)):
Alan Viverettec1c32b62017-12-20 09:40:36 -0500950 components = append(components, 'build tools')
951 else:
952 print_e('Failed to update build tools, aborting...')
953 sys.exit(1)
Jeff Gastonb70daa92018-03-29 20:10:22 -0400954
Jeff Gastonf12f3ce2018-03-23 16:41:24 -0400955
Alan Viveretted4527e62017-05-11 15:03:25 -0400956
Colin Cross941d9802018-05-03 21:37:57 -0700957 subprocess.check_call(['git', 'add', current_path, buildtools_dir])
Colin Cross573e1212018-02-12 14:59:52 -0800958 if not args.source.isnumeric():
Alan Viverette129555e2018-01-30 09:57:57 -0500959 src_msg = "local Maven ZIP"
960 else:
Jeff Gaston13e38412018-02-06 14:45:36 -0500961 src_msg = "build %s" % (getBuildId(args).url_id)
Alan Viverette129555e2018-01-30 09:57:57 -0500962 msg = "Import %s from %s\n\n%s" % (components, src_msg, flatten(sys.argv))
Alan Viveretted4527e62017-05-11 15:03:25 -0400963 subprocess.check_call(['git', 'commit', '-m', msg])
Anton Hanssonbe15e8c2018-04-26 17:35:45 +0100964 if args.finalize_sdk:
965 print('NOTE: Created two commits:')
966 subprocess.check_call(['git', 'log', '-2', '--oneline'])
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500967 print('Remember to test this change before uploading it to Gerrit!')
Alan Viveretted4527e62017-05-11 15:03:25 -0400968
969finally:
970 # Revert all stray files, including the downloaded zip.
971 try:
972 with open(os.devnull, 'w') as bitbucket:
973 subprocess.check_call(['git', 'add', '-Af', '.'], stdout=bitbucket)
974 subprocess.check_call(
Jeff Gaston9edf86c2018-04-18 13:45:23 -0400975 ['git', 'commit', '-m', 'COMMIT TO REVERT - RESET ME!!!', '--allow-empty'], stdout=bitbucket)
Alan Viveretted4527e62017-05-11 15:03:25 -0400976 subprocess.check_call(['git', 'reset', '--hard', 'HEAD~1'], stdout=bitbucket)
977 except subprocess.CalledProcessError:
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500978 print_e('ERROR: Failed cleaning up, manual cleanup required!!!')