blob: 47f9bcf6f890b6b0d5d935f9c684ca59183a1320 [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'
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -040016androidx_dir = os.path.join(current_path, 'androidx')
Alan Viverette3e57a4a2017-08-11 15:49:47 -040017extras_dir = os.path.join(current_path, 'extras')
Alan Viverettec1c32b62017-12-20 09:40:36 -050018buildtools_dir = 'tools'
Jeff Gaston553a4372018-03-29 18:34:22 -040019jetifier_dir = os.path.join(buildtools_dir, 'jetifier', 'jetifier-standalone')
Alan Viverette95f6d362017-04-06 09:40:50 -040020
Jeff Gastona68a8d42018-03-23 14:00:13 -040021temp_dir = os.path.join(os.getcwd(), "support_tmp")
22os.chdir(os.path.dirname(os.path.dirname(os.path.realpath(sys.argv[0]))))
23git_dir = os.getcwd()
24
Alan Viverettecd3de262017-08-14 09:51:30 -040025# See go/fetch_artifact for details on this script.
Alan Viveretted4527e62017-05-11 15:03:25 -040026FETCH_ARTIFACT = '/google/data/ro/projects/android/fetch_artifact'
27
Alan Viverette95f6d362017-04-06 09:40:50 -040028maven_to_make = {
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -040029 # AndroidX
Jeff Gastona0bce602018-08-24 14:05:03 -040030 'androidx.slice:slice-builders': {'name':'androidx.slice_slice-builders', 'path':'androidx/slice/slice-builders'},
31 'androidx.slice:slice-core': {'name':'androidx.slice_slice-core', 'path':'androidx/slice/slice-core'},
32 'androidx.slice:slice-view': {'name':'androidx.slice_slice-view', 'path':'androidx/slice/slice-view'},
Jeff Gaston07a3cf72018-08-24 14:16:34 -040033 'androidx.remotecallback:remotecallback': {'name':'androidx.remotecallback_remotecallback', 'path':'androidx/remotecallback/remotecallback'},
34 'androidx.remotecallback:remotecallback-processor': {'name':'androidx.remotecallback_remotecallback-processor', 'path':'androidx/remotecallback/remotecallback-processor', 'host':True},
Jeff Gastona0bce602018-08-24 14:05:03 -040035 'androidx.versionedparcelable:versionedparcelable': {'name':'androidx.versionedparcelable_versionedparcelable', 'path':'androidx/versionedparcelable'},
36 'androidx.vectordrawable:vectordrawable-animated': {'name':'androidx.vectordrawable_vectordrawable-animated', 'path':'androidx/vectordrawable/vectordrawable-animated'},
Aurimas Liutikasabaa49f2018-09-18 15:30:20 -070037 'androidx.activity:activity': {'name':'androidx.activity_activity', 'path':'androidx/activity/activity'},
Nate Myren1fa47162019-11-12 11:28:06 -080038 'androidx.activity:activity-ktx': {'name':'androidx.activity_activity-ktx', 'path':'androidx/activity/activity-ktx'},
Tony Mak0f658752019-07-19 11:11:05 +010039 'androidx.annotation:annotation': {'name':'androidx.annotation_annotation', 'path':'androidx/annotation/annotation', 'host_and_device' : True},
Jeff Gastona0bce602018-08-24 14:05:03 -040040 'androidx.asynclayoutinflater:asynclayoutinflater': {'name':'androidx.asynclayoutinflater_asynclayoutinflater', 'path':'androidx/asynclayoutinflater/asynclayoutinflater'},
41 'androidx.car:car': {'name':'androidx.car_car', 'path':'androidx/car/car'},
Roberto Perez804fbb42018-09-10 17:58:11 -070042 'androidx.car:car-cluster': {'name':'androidx.car_car-cluster', 'path':'androidx/car/car-cluster'},
Jeff Gastona0bce602018-08-24 14:05:03 -040043 'androidx.collection:collection': {'name':'androidx.collection_collection', 'path':'androidx/collection/collection'},
Nate Myren1fa47162019-11-12 11:28:06 -080044 'androidx.collection:collection-ktx': {'name':'androidx.collection_collection-ktx', 'path':'androidx/collection/collection-ktx'},
Aurimas Liutikasd9124762018-09-28 15:31:35 -070045 'androidx.concurrent:concurrent-futures': {'name':'androidx.concurrent_concurrent-futures', 'path':'androidx/concurrent/concurrent-futures'},
Aurimas Liutikas8af28d32019-06-06 14:04:01 -070046 'androidx.concurrent:concurrent-listenablefuture-callback': {'name':'androidx.concurrent_concurrent-listenablefuture-callback', 'path':'androidx/concurrent/concurrent-listenablefuture-callback'},
47 'androidx.concurrent:concurrent-listenablefuture': {'name':'androidx.concurrent_concurrent-listenablefuture', 'path':'androidx/concurrent/concurrent-listenablefuture'},
Jeff Gastona0bce602018-08-24 14:05:03 -040048 'androidx.core:core': {'name':'androidx.core_core', 'path':'androidx/core/core'},
Yvan Hsueh5efba6e2020-04-30 01:17:47 +080049 'androidx.core:core-animation': {'name':'androidx.core_core-animation', 'path':'androidx/core/core-animation'},
Nate Myren1fa47162019-11-12 11:28:06 -080050 'androidx.core:core-ktx': {'name':'androidx.core_core-ktx', 'path':'androidx/core/core-ktx'},
Jeff Gastona0bce602018-08-24 14:05:03 -040051 'androidx.contentpaging:contentpaging': {'name':'androidx.contentpaging_contentpaging', 'path':'androidx/contentpaging/contentpaging'},
52 'androidx.coordinatorlayout:coordinatorlayout': {'name':'androidx.coordinatorlayout_coordinatorlayout', 'path':'androidx/coordinatorlayout/coordinatorlayout'},
53 'androidx.legacy:legacy-support-core-ui': {'name':'androidx.legacy_legacy-support-core-ui', 'path':'androidx/legacy/legacy-support-core-ui'},
54 'androidx.legacy:legacy-support-core-utils': {'name':'androidx.legacy_legacy-support-core-utils', 'path':'androidx/legacy/legacy-support-core-utils'},
55 'androidx.cursoradapter:cursoradapter': {'name':'androidx.cursoradapter_cursoradapter', 'path':'androidx/cursoradapter/cursoradapter'},
56 'androidx.browser:browser': {'name':'androidx.browser_browser', 'path':'androidx/browser/browser'},
57 'androidx.customview:customview': {'name':'androidx.customview_customview', 'path':'androidx/customview/customview'},
58 'androidx.documentfile:documentfile': {'name':'androidx.documentfile_documentfile', 'path':'androidx/documentfile/documentfile'},
59 'androidx.drawerlayout:drawerlayout': {'name':'androidx.drawerlayout_drawerlayout', 'path':'androidx/drawerlayout/drawerlayout'},
60 'androidx.dynamicanimation:dynamicanimation': {'name':'androidx.dynamicanimation_dynamicanimation', 'path':'androidx/dynamicanimation/dynamicanimation'},
61 'androidx.emoji:emoji': {'name':'androidx.emoji_emoji', 'path':'androidx/emoji/emoji'},
62 'androidx.emoji:emoji-appcompat': {'name':'androidx.emoji_emoji-appcompat', 'path':'androidx/emoji/emoji-appcompat'},
63 'androidx.emoji:emoji-bundled': {'name':'androidx.emoji_emoji-bundled', 'path':'androidx/emoji/emoji-bundled'},
64 'androidx.exifinterface:exifinterface': {'name':'androidx.exifinterface_exifinterface', 'path':'androidx/exifinterface/exifinterface'},
65 'androidx.fragment:fragment': {'name':'androidx.fragment_fragment', 'path':'androidx/fragment/fragment'},
Nate Myren1fa47162019-11-12 11:28:06 -080066 'androidx.fragment:fragment-ktx': {'name':'androidx.fragment_fragment-ktx', 'path':'androidx/fragment/fragment-ktx'},
Jeff Gastona0bce602018-08-24 14:05:03 -040067 'androidx.heifwriter:heifwriter': {'name':'androidx.heifwriter_heifwriter', 'path':'androidx/heifwriter/heifwriter'},
68 'androidx.interpolator:interpolator': {'name':'androidx.interpolator_interpolator', 'path':'androidx/interpolator/interpolator'},
69 'androidx.loader:loader': {'name':'androidx.loader_loader', 'path':'androidx/loader/loader'},
70 'androidx.localbroadcastmanager:localbroadcastmanager': {'name':'androidx.localbroadcastmanager_localbroadcastmanager', 'path':'androidx/localbroadcastmanager/localbroadcastmanager'},
71 'androidx.media:media': {'name':'androidx.media_media', 'path':'androidx/media/media'},
Oussama Ben Abdelbaki09fffcb2019-05-13 15:11:37 -040072 'androidx.media2:media2-player': {'name':'androidx.media2_media2-player', 'path':'androidx/media2/media2-player'},
73 'androidx.media2:media2-session': {'name':'androidx.media2_media2-session', 'path':'androidx/media2/media2-session'},
74 'androidx.media2:media2-common': {'name':'androidx.media2_media2-common', 'path':'androidx/media2/media2-common'},
Jeff Gastona0bce602018-08-24 14:05:03 -040075 'androidx.media2:media2-exoplayer': {'name':'androidx.media2_media2-exoplayer', 'path':'androidx/media2/media2-exoplayer'},
Gyumin Sim1752eca2018-12-13 11:34:10 +090076 'androidx.media2:media2-widget': {'name':'androidx.media2_media2-widget', 'path':'androidx/media2/media2-widget'},
Nate Myren1fa47162019-11-12 11:28:06 -080077 'androidx.navigation:navigation-common': {'name':'androidx.navigation_navigation-common', 'path':'androidx/navigation/navigation-common'},
78 'androidx.navigation:navigation-common-ktx': {'name':'androidx.navigation_navigation-common-ktx', 'path':'androidx/navigation/navigation-common-ktx'},
79 'androidx.navigation:navigation-fragment': {'name':'androidx.navigation_navigation-fragment', 'path':'androidx/navigation/navigation-fragment'},
80 'androidx.navigation:navigation-fragment-ktx': {'name':'androidx.navigation_navigation-fragment-ktx', 'path':'androidx/navigation/navigation-fragment-ktx'},
81 'androidx.navigation:navigation-runtime': {'name':'androidx.navigation_navigation-runtime', 'path':'androidx/navigation/navigation-runtime'},
82 'androidx.navigation:navigation-runtime-ktx': {'name':'androidx.navigation_navigation-runtime-ktx', 'path':'androidx/navigation/navigation-runtime-ktx'},
83 'androidx.navigation:navigation-ui': {'name':'androidx.navigation_navigation-ui', 'path':'androidx/navigation/navigation-ui'},
84 'androidx.navigation:navigation-ui-ktx': {'name':'androidx.navigation_navigation-ui-ktx', 'path':'androidx/navigation/navigation-ui-ktx'},
Jeff Gastona0bce602018-08-24 14:05:03 -040085 'androidx.percentlayout:percentlayout': {'name':'androidx.percentlayout_percentlayout', 'path':'androidx/percentlayout/percentlayout'},
86 'androidx.print:print': {'name':'androidx.print_print', 'path':'androidx/print/print'},
87 'androidx.recommendation:recommendation': {'name':'androidx.recommendation_recommendation', 'path':'androidx/recommendation/recommendation'},
88 'androidx.recyclerview:recyclerview-selection': {'name':'androidx.recyclerview_recyclerview-selection', 'path':'androidx/recyclerview/recyclerview-selection'},
Oussama Ben Abdelbaki00f9b392019-03-18 14:45:12 -040089 'androidx.savedstate:savedstate': {'name':'androidx.savedstate_savedstate', 'path':'androidx/savedstate/savedstate'},
Jeff Gastona0bce602018-08-24 14:05:03 -040090 'androidx.slidingpanelayout:slidingpanelayout': {'name':'androidx.slidingpanelayout_slidingpanelayout', 'path':'androidx/slidingpanelayout/slidingpanelayout'},
91 'androidx.swiperefreshlayout:swiperefreshlayout': {'name':'androidx.swiperefreshlayout_swiperefreshlayout', 'path':'androidx/swiperefreshlayout/swiperefreshlayout'},
92 'androidx.textclassifier:textclassifier': {'name':'androidx.textclassifier_textclassifier', 'path':'androidx/textclassifier/textclassifier'},
93 'androidx.transition:transition': {'name':'androidx.transition_transition', 'path':'androidx/transition/transition'},
94 'androidx.tvprovider:tvprovider': {'name':'androidx.tvprovider_tvprovider', 'path':'androidx/tvprovider/tvprovider'},
95 'androidx.legacy:legacy-support-v13': {'name':'androidx.legacy_legacy-support-v13', 'path':'androidx/legacy/legacy-support-v13'},
96 'androidx.legacy:legacy-preference-v14': {'name':'androidx.legacy_legacy-preference-v14', 'path':'androidx/legacy/legacy-preference-v14'},
97 'androidx.leanback:leanback': {'name':'androidx.leanback_leanback', 'path':'androidx/leanback/leanback'},
98 'androidx.leanback:leanback-preference': {'name':'androidx.leanback_leanback-preference', 'path':'androidx/leanback/leanback-preference'},
99 'androidx.legacy:legacy-support-v4': {'name':'androidx.legacy_legacy-support-v4', 'path':'androidx/legacy/legacy-support-v4'},
100 'androidx.appcompat:appcompat': {'name':'androidx.appcompat_appcompat', 'path':'androidx/appcompat/appcompat'},
Oussama Ben Abdelbaki61551b82019-02-12 15:56:27 -0500101 'androidx.appcompat:appcompat-resources': {'name':'androidx.appcompat_appcompat-resources', 'path':'androidx/appcompat/appcompat-resources'},
Jeff Gastona0bce602018-08-24 14:05:03 -0400102 'androidx.cardview:cardview': {'name':'androidx.cardview_cardview', 'path':'androidx/cardview/cardview'},
103 'androidx.gridlayout:gridlayout': {'name':'androidx.gridlayout_gridlayout', 'path':'androidx/gridlayout/gridlayout'},
104 'androidx.mediarouter:mediarouter': {'name':'androidx.mediarouter_mediarouter', 'path':'androidx/mediarouter/mediarouter'},
105 'androidx.palette:palette': {'name':'androidx.palette_palette', 'path':'androidx/palette/palette'},
106 'androidx.preference:preference': {'name':'androidx.preference_preference', 'path':'androidx/preference/preference'},
107 'androidx.recyclerview:recyclerview': {'name':'androidx.recyclerview_recyclerview', 'path':'androidx/recyclerview/recyclerview'},
108 'androidx.vectordrawable:vectordrawable': {'name':'androidx.vectordrawable_vectordrawable', 'path':'androidx/vectordrawable/vectordrawable'},
109 'androidx.viewpager:viewpager': {'name':'androidx.viewpager_viewpager', 'path':'androidx/viewpager/viewpager'},
Fabian Kozynskie514c122020-03-04 14:41:08 -0500110 'androidx.viewpager2:viewpager2': {'name':'androidx.viewpager2_viewpager2', 'path':'androidx/viewpager2/viewpager2'},
Jeff Gastona0bce602018-08-24 14:05:03 -0400111 'androidx.wear:wear': {'name':'androidx.wear_wear', 'path':'androidx/wear/wear'},
112 'androidx.webkit:webkit': {'name':'androidx.webkit_webkit', 'path':'androidx/webkit/webkit'},
Kevin Chynb6ae85d2018-10-02 12:12:20 -0700113 'androidx.biometric:biometric': {'name':'androidx.biometric_biometric', 'path':'androidx/biometric/biometric'},
Adam He7dec9ff2020-01-27 14:05:45 -0800114 'androidx.autofill:autofill': {'name':'androidx.autofill_autofill', 'path':'androidx/autofill/autofill'},
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400115
116 # AndroidX for Multidex
Jeff Gastona0bce602018-08-24 14:05:03 -0400117 'androidx.multidex:multidex': {'name':'androidx-multidex_multidex', 'path':'androidx/multidex/multidex'},
118 'androidx.multidex:multidex-instrumentation': {'name':'androidx-multidex_multidex-instrumentation', 'path':'androidx/multidex/multidex-instrumentation'},
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400119
120 # AndroidX for Constraint Layout
Jeff Gastona0bce602018-08-24 14:05:03 -0400121 'androidx.constraintlayout:constraintlayout': {'name':'androidx-constraintlayout_constraintlayout', 'path':'androidx/constraintlayout/constraintlayout'},
122 'androidx.constraintlayout:constraintlayout-solver': {'name':'androidx-constraintlayout_constraintlayout-solver', 'path':'androidx/constraintlayout/constraintlayout-solver'},
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400123
124 # AndroidX for Architecture Components
Jeff Gastona0bce602018-08-24 14:05:03 -0400125 'androidx.arch.core:core-common': {'name':'androidx.arch.core_core-common', 'path':'androidx/arch/core/core-common'},
126 'androidx.arch.core:core-runtime': {'name':'androidx.arch.core_core-runtime', 'path':'androidx/arch/core/core-runtime'},
127 'androidx.lifecycle:lifecycle-common': {'name':'androidx.lifecycle_lifecycle-common', 'path':'androidx/lifecycle/lifecycle-common'},
128 'androidx.lifecycle:lifecycle-common-java8': {'name':'androidx.lifecycle_lifecycle-common-java8', 'path':'androidx/lifecycle/lifecycle-common-java8'},
129 'androidx.lifecycle:lifecycle-extensions': {'name':'androidx.lifecycle_lifecycle-extensions', 'path':'androidx/lifecycle/lifecycle-extensions'},
130 'androidx.lifecycle:lifecycle-livedata': {'name':'androidx.lifecycle_lifecycle-livedata', 'path':'androidx/lifecycle/lifecycle-livedata'},
Nate Myren1fa47162019-11-12 11:28:06 -0800131 'androidx.lifecycle:lifecycle-livedata-ktx': {'name':'androidx.lifecycle_lifecycle-livedata-ktx', 'path':'androidx/lifecycle/lifecycle-livedata-ktx'},
Jeff Gastona0bce602018-08-24 14:05:03 -0400132 'androidx.lifecycle:lifecycle-livedata-core': {'name':'androidx.lifecycle_lifecycle-livedata-core', 'path':'androidx/lifecycle/lifecycle-livedata-core'},
Nate Myren1fa47162019-11-12 11:28:06 -0800133 '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 -0400134 'androidx.lifecycle:lifecycle-process': {'name':'androidx.lifecycle_lifecycle-process', 'path':'androidx/lifecycle/lifecycle-process'},
135 'androidx.lifecycle:lifecycle-runtime': {'name':'androidx.lifecycle_lifecycle-runtime', 'path':'androidx/lifecycle/lifecycle-runtime'},
Nate Myren1fa47162019-11-12 11:28:06 -0800136 'androidx.lifecycle:lifecycle-runtime-ktx': {'name':'androidx.lifecycle_lifecycle-runtime-ktx', 'path':'androidx/lifecycle/lifecycle-runtime-ktx'},
Jeff Gastona0bce602018-08-24 14:05:03 -0400137 'androidx.lifecycle:lifecycle-service': {'name':'androidx.lifecycle_lifecycle-service', 'path':'androidx/lifecycle/lifecycle-service'},
138 'androidx.lifecycle:lifecycle-viewmodel': {'name':'androidx.lifecycle_lifecycle-viewmodel', 'path':'androidx/lifecycle/lifecycle-viewmodel'},
Nate Myren1fa47162019-11-12 11:28:06 -0800139 'androidx.lifecycle:lifecycle-viewmodel-ktx': {'name':'androidx.lifecycle_lifecycle-viewmodel-ktx', 'path':'androidx/lifecycle/lifecycle-viewmodel-ktx'},
Aurimas Liutikasb5836e22019-09-06 09:00:45 -0700140 'androidx.lifecycle:lifecycle-viewmodel-savedstate': {'name':'androidx.lifecycle_lifecycle-viewmodel-savedstate', 'path':'androidx/lifecycle/lifecycle-viewmodel-savedstate'},
Jeff Gastona0bce602018-08-24 14:05:03 -0400141 'androidx.paging:paging-common': {'name':'androidx.paging_paging-common', 'path':'androidx/paging/paging-common'},
Aurimas Liutikasb5836e22019-09-06 09:00:45 -0700142 'androidx.paging:paging-common-ktx': {'name':'androidx.paging_paging-common-ktx', 'path':'androidx/paging/paging-common-ktx'},
Jeff Gastona0bce602018-08-24 14:05:03 -0400143 'androidx.paging:paging-runtime': {'name':'androidx.paging_paging-runtime', 'path':'androidx/paging/paging-runtime'},
144 'androidx.sqlite:sqlite': {'name':'androidx.sqlite_sqlite', 'path':'androidx/sqlite/sqlite'},
145 'androidx.sqlite:sqlite-framework': {'name':'androidx.sqlite_sqlite-framework', 'path':'androidx/sqlite/sqlite-framework'},
Tony Mak0f658752019-07-19 11:11:05 +0100146 'androidx.room:room-common': {'name':'androidx.room_room-common', 'path':'androidx/room/room-common', 'host_and_device' : True},
147 'androidx.room:room-compiler': {'name':'androidx.room_room-compiler', 'path':'androidx/room/room-compiler', 'host' : True},
148 '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 -0400149 'androidx.room:room-runtime': {'name':'androidx.room_room-runtime', 'path':'androidx/room/room-runtime'},
150 'androidx.room:room-testing': {'name':'androidx.room_room-testing', 'path':'androidx/room/room-testing'},
Allenab72f012018-01-29 18:10:23 -0800151
Alan Viverette19ecd502018-01-05 13:52:16 -0500152 # Lifecycle
Alan Viverettec7e88f12018-02-13 15:29:50 -0500153 # Missing dependencies:
154 # - auto-common
155 # - javapoet
Jeff Gastona0bce602018-08-24 14:05:03 -0400156 #'android.arch.lifecycle:compiler': {'name':'android-arch-lifecycle-compiler', 'path':'arch-lifecycle/compiler'},
Alan Viverettec7e88f12018-02-13 15:29:50 -0500157 # Missing dependencies:
158 # - reactive-streams
Jeff Gastona0bce602018-08-24 14:05:03 -0400159 #'android.arch.lifecycle:reactivestreams': 'android-arch-lifecycle-reactivestreams','arch-lifecycle/reactivestreams',
Allenab72f012018-01-29 18:10:23 -0800160
Alan Viverette19ecd502018-01-05 13:52:16 -0500161 # Room
Alan Viverettec7e88f12018-02-13 15:29:50 -0500162 # Missing dependencies:
163 # - auto-common
164 # - javapoet
165 # - antlr4
166 # - kotlin-metadata
167 # - commons-codec
Jeff Gastona0bce602018-08-24 14:05:03 -0400168 #'android.arch.persistence.room:compiler': {'name':'android-arch-room-compiler', 'path':'arch-room/compiler'},
Alan Viverettec7e88f12018-02-13 15:29:50 -0500169 # Missing dependencies:
170 # - rxjava
Jeff Gastona0bce602018-08-24 14:05:03 -0400171 #'android.arch.persistence.room:rxjava2': {'name':'android-arch-room-rxjava2', 'path':'arch-room/rxjava2'},
Allenab72f012018-01-29 18:10:23 -0800172
Jeff Gaston6e7e7502018-04-04 00:22:45 -0400173 # Third-party dependencies
Jeff Gastona0bce602018-08-24 14:05:03 -0400174 'com.google.android:flexbox': {'name':'flexbox', 'path':'flexbox'},
Jeff Gaston6e7e7502018-04-04 00:22:45 -0400175
Jeff Gastonfa7c7e82018-04-06 13:35:48 -0400176 # Androidx Material Design Components
Jeff Gastona0bce602018-08-24 14:05:03 -0400177 'com.google.android.material:material': {'name':'com.google.android.material_material', 'path':'com/google/android/material/material'},
Alan Viverette95f6d362017-04-06 09:40:50 -0400178}
179
180# Always remove these files.
181blacklist_files = [
182 'annotations.zip',
183 'public.txt',
184 'R.txt',
Alan Viverette44ad4e42017-08-09 17:45:00 -0400185 'AndroidManifest.xml',
Alan Viverettef48d9b42017-08-17 14:45:46 -0400186 os.path.join('libs','noto-emoji-compat-java.jar')
Alan Viverette95f6d362017-04-06 09:40:50 -0400187]
188
Alan Viverette44ad4e42017-08-09 17:45:00 -0400189artifact_pattern = re.compile(r"^(.+?)-(\d+\.\d+\.\d+(?:-\w+\d+)?(?:-[\d.]+)*)\.(jar|aar)$")
Alan Viverette95f6d362017-04-06 09:40:50 -0400190
Alan Viverettec960cfb2017-12-04 13:09:22 -0500191
192class MavenLibraryInfo:
Jeff Gastonc302bb92018-03-23 13:53:48 -0400193 def __init__(self, key, group_id, artifact_id, version, dir, repo_dir, file):
Alan Viverettec960cfb2017-12-04 13:09:22 -0500194 self.key = key
195 self.group_id = group_id
196 self.artifact_id = artifact_id
197 self.version = version
Jeff Gastonc302bb92018-03-23 13:53:48 -0400198 self.dir = dir
Alan Viverettec960cfb2017-12-04 13:09:22 -0500199 self.repo_dir = repo_dir
200 self.file = file
201
202
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500203def print_e(*args, **kwargs):
204 print(*args, file=sys.stderr, **kwargs)
205
Alan Viverette95f6d362017-04-06 09:40:50 -0400206
207def touch(fname, times=None):
208 with open(fname, 'a'):
209 os.utime(fname, times)
210
211
Alan Viverette45837092017-05-12 14:50:53 -0400212def path(*path_parts):
213 return reduce((lambda x, y: os.path.join(x, y)), path_parts)
214
215
Alan Viverettecd3de262017-08-14 09:51:30 -0400216def flatten(list):
217 return reduce((lambda x, y: "%s %s" % (x, y)), list)
218
219
Alan Viverette45837092017-05-12 14:50:53 -0400220def rm(path):
221 if os.path.isdir(path):
222 rmtree(path)
223 elif os.path.exists(path):
224 os.remove(path)
225
226
227def mv(src_path, dst_path):
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400228 if os.path.exists(dst_path):
Alan Viverettecd3de262017-08-14 09:51:30 -0400229 rm(dst_path)
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400230 if not os.path.exists(os.path.dirname(dst_path)):
231 os.makedirs(os.path.dirname(dst_path))
Jiyong Park1d1c9632018-05-29 17:45:27 +0900232 for f in (glob.glob(src_path)):
233 if '*' in dst_path:
234 dst = os.path.join(os.path.dirname(dst_path), os.path.basename(f))
235 else:
236 dst = dst_path
shepshaparde4127cf2019-09-03 16:08:44 -0700237 move(f, dst)
Alan Viverette45837092017-05-12 14:50:53 -0400238
239
Jeff Gastonc302bb92018-03-23 13:53:48 -0400240def detect_artifacts(maven_repo_dirs):
Alan Viveretted4527e62017-05-11 15:03:25 -0400241 maven_lib_info = {}
242
Dan Willemsen814152e2017-11-06 13:22:11 -0800243 # Find the latest revision for each artifact, remove others
Jeff Gastonc302bb92018-03-23 13:53:48 -0400244 for repo_dir in maven_repo_dirs:
Dan Willemsen814152e2017-11-06 13:22:11 -0800245 for root, dirs, files in os.walk(repo_dir):
246 for file in files:
Alan Viverettec960cfb2017-12-04 13:09:22 -0500247 if file[-4:] == ".pom":
248 # Read the POM (hack hack hack).
249 group_id = ''
250 artifact_id = ''
251 version = ''
252 file = os.path.join(root, file)
253 with open(file) as pom_file:
254 for line in pom_file:
255 if line[:11] == ' <groupId>':
256 group_id = line[11:-11]
257 elif line[:14] == ' <artifactId>':
258 artifact_id = line[14:-14]
259 elif line[:11] == ' <version>':
260 version = line[11:-11]
261 if group_id == '' or artifact_id == '' or version == '':
262 print_e('Failed to find Maven artifact data in ' + file)
263 continue
Alan Viverette95f6d362017-04-06 09:40:50 -0400264
Alan Viverettec960cfb2017-12-04 13:09:22 -0500265 # Locate the artifact.
266 artifact_file = file[:-4]
267 if os.path.exists(artifact_file + '.jar'):
268 artifact_file = artifact_file + '.jar'
269 elif os.path.exists(artifact_file + '.aar'):
270 artifact_file = artifact_file + '.aar'
271 else:
272 print_e('Failed to find artifact for ' + artifact_file)
273 continue
274
275 # Make relative to root.
276 artifact_file = artifact_file[len(root) + 1:]
277
278 # Find the mapping.
279 group_artifact = group_id + ':' + artifact_id
Jeff Gaston3e622ba2018-03-26 23:24:46 -0400280 if group_artifact in maven_to_make:
Alan Viverettec960cfb2017-12-04 13:09:22 -0500281 key = group_artifact
Jeff Gaston3e622ba2018-03-26 23:24:46 -0400282 elif artifact_id in maven_to_make:
283 key = artifact_id
Alan Viverettec960cfb2017-12-04 13:09:22 -0500284 else:
285 print_e('Failed to find artifact mapping for ' + group_artifact)
286 continue
287
288 # Store the latest version.
289 version = LooseVersion(version)
290 if key not in maven_lib_info \
291 or version > maven_lib_info[key].version:
292 maven_lib_info[key] = MavenLibraryInfo(key, group_id, artifact_id, version,
293 root, repo_dir, artifact_file)
Alan Viverette95f6d362017-04-06 09:40:50 -0400294
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400295 return maven_lib_info
296
297
Colin Cross59b59db2018-04-24 13:58:05 -0700298def transform_maven_repos(maven_repo_dirs, transformed_dir, extract_res=True, include_static_deps=True):
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400299 cwd = os.getcwd()
300
301 # Use a temporary working directory.
Jeff Gastonc302bb92018-03-23 13:53:48 -0400302 maven_lib_info = detect_artifacts(maven_repo_dirs)
Jeff Gastona68a8d42018-03-23 14:00:13 -0400303 working_dir = temp_dir
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400304
Alan Viverettec960cfb2017-12-04 13:09:22 -0500305 if not maven_lib_info:
306 print_e('Failed to detect artifacts')
307 return False
308
Jeff Gastonc302bb92018-03-23 13:53:48 -0400309 # extract some files (for example, AndroidManifest.xml) from any relevant artifacts
Alan Viveretted4527e62017-05-11 15:03:25 -0400310 for info in maven_lib_info.values():
Alan Viveretted8ce7222017-12-11 17:24:43 -0500311 transform_maven_lib(working_dir, info, extract_res)
Dan Willemsen814152e2017-11-06 13:22:11 -0800312
Colin Cross74683bc2018-04-11 17:36:18 -0700313 # generate a single Android.bp that specifies to use all of the above artifacts
314 makefile = os.path.join(working_dir, 'Android.bp')
Alan Viverette4ec9a172018-02-20 16:19:31 -0500315 with open(makefile, 'w') as f:
Colin Cross74683bc2018-04-11 17:36:18 -0700316 args = ["pom2bp", "-sdk-version", "current"]
Jeff Gaston1cc06092018-03-28 15:51:02 -0400317 if include_static_deps:
318 args.append("-static-deps")
Jeff Gaston54868ee2018-04-25 19:43:35 -0400319 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 -0400320 args.extend(["-rewrite=^" + name + "$=" + maven_to_make[name]['name'] for name in rewriteNames])
Jeff Gaston07a3cf72018-08-24 14:16:34 -0400321 args.extend(["-rewrite=^com.squareup:javapoet$=javapoet-prebuilt-jar"])
Aurimas Liutikasd9124762018-09-28 15:31:35 -0700322 args.extend(["-rewrite=^com.google.guava:listenablefuture$=guava-listenablefuture-prebuilt-jar"])
Tony Mak0f658752019-07-19 11:11:05 +0100323 args.extend(["-rewrite=^sqlite-jdbc$=xerial-sqlite-jdbc"])
Tony Mak0f658752019-07-19 11:11:05 +0100324 args.extend(["-rewrite=^gson$=gson-prebuilt-jar"])
Sunny Goyal6667ddb2020-03-03 15:15:54 -0800325 args.extend(["-rewrite=^com.intellij:annotations$=jetbrains-annotations"])
Paul Duffin44e033b2019-04-16 11:28:13 +0100326 args.extend(["-extra-static-libs=android-support-car=prebuilt-android.car-stubs"])
Sunny Goyal6667ddb2020-03-03 15:15:54 -0800327 args.extend(["-extra-static-libs=androidx.room_room-compiler=guava-21.0"])
Jeff Gaston07a3cf72018-08-24 14:16:34 -0400328 args.extend(["-host=" + name for name in maven_to_make if maven_to_make[name].get('host')])
Tony Mak0f658752019-07-19 11:11:05 +0100329 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 -0700330 # these depend on GSON which is not in AOSP
Tony Mak0f658752019-07-19 11:11:05 +0100331 args.extend(["-exclude=android-arch-room-migration",
Colin Cross21060072018-04-24 13:52:29 -0700332 "-exclude=android-arch-room-testing"])
Jeff Gaston7ec1d8f2018-03-27 00:25:12 -0400333 args.extend(["."])
Dan Willemsen814152e2017-11-06 13:22:11 -0800334 subprocess.check_call(args, stdout=f, cwd=working_dir)
Alan Viverette95f6d362017-04-06 09:40:50 -0400335
336 # Replace the old directory.
Jeff Gastonc302bb92018-03-23 13:53:48 -0400337 output_dir = os.path.join(cwd, transformed_dir)
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400338 mv(working_dir, output_dir)
Alan Viverettec960cfb2017-12-04 13:09:22 -0500339 return True
Alan Viverette95f6d362017-04-06 09:40:50 -0400340
Jeff Gastonc302bb92018-03-23 13:53:48 -0400341# 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 -0500342def transform_maven_lib(working_dir, artifact_info, extract_res):
Dan Willemsen814152e2017-11-06 13:22:11 -0800343 # Move library into working dir
Jeff Gaston9edf86c2018-04-18 13:45:23 -0400344 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 -0400345 mv(artifact_info.dir, new_dir)
Dan Willemsen814152e2017-11-06 13:22:11 -0800346
Alan Viverettec960cfb2017-12-04 13:09:22 -0500347 matcher = artifact_pattern.match(artifact_info.file)
348 maven_lib_name = artifact_info.key
Alan Viveretted4527e62017-05-11 15:03:25 -0400349 maven_lib_vers = matcher.group(2)
Alan Viverettec960cfb2017-12-04 13:09:22 -0500350 maven_lib_type = artifact_info.file[-3:]
Alan Viveretted4527e62017-05-11 15:03:25 -0400351
Jeff Gastona0bce602018-08-24 14:05:03 -0400352 make_lib_name = maven_to_make[artifact_info.key]['name']
353 make_dir_name = maven_to_make[artifact_info.key]['path']
Alan Viveretted4527e62017-05-11 15:03:25 -0400354
Alan Viverette129555e2018-01-30 09:57:57 -0500355 artifact_file = os.path.join(new_dir, artifact_info.file)
356
Colin Cross59b59db2018-04-24 13:58:05 -0700357 if maven_lib_type == "aar":
358 if extract_res:
359 target_dir = os.path.join(working_dir, make_dir_name)
360 if not os.path.exists(target_dir):
361 os.makedirs(target_dir)
Dan Willemsen814152e2017-11-06 13:22:11 -0800362
Alan Viverettec960cfb2017-12-04 13:09:22 -0500363 process_aar(artifact_file, target_dir)
Alan Viveretted4527e62017-05-11 15:03:25 -0400364
Colin Cross59b59db2018-04-24 13:58:05 -0700365 with zipfile.ZipFile(artifact_file) as zip:
366 manifests_dir = os.path.join(working_dir, "manifests")
367 zip.extract("AndroidManifest.xml", os.path.join(manifests_dir, make_lib_name))
Dan Willemsend677b602017-11-08 22:13:17 -0800368
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500369 print(maven_lib_vers, ":", maven_lib_name, "->", make_lib_name)
Alan Viveretted4527e62017-05-11 15:03:25 -0400370
Alan Viverette95f6d362017-04-06 09:40:50 -0400371
Alan Viverettec960cfb2017-12-04 13:09:22 -0500372def process_aar(artifact_file, target_dir):
Alan Viverette95f6d362017-04-06 09:40:50 -0400373 # Extract AAR file to target_dir.
374 with zipfile.ZipFile(artifact_file) as zip:
375 zip.extractall(target_dir)
376
Dan Willemsen814152e2017-11-06 13:22:11 -0800377 # Remove classes.jar
Alan Viverette95f6d362017-04-06 09:40:50 -0400378 classes_jar = os.path.join(target_dir, "classes.jar")
379 if os.path.exists(classes_jar):
Dan Willemsen814152e2017-11-06 13:22:11 -0800380 os.remove(classes_jar)
Alan Viverette95f6d362017-04-06 09:40:50 -0400381
382 # Remove or preserve empty dirs.
383 for root, dirs, files in os.walk(target_dir):
384 for dir in dirs:
385 dir_path = os.path.join(root, dir)
386 if not os.listdir(dir_path):
387 os.rmdir(dir_path)
388
389 # Remove top-level cruft.
390 for file in blacklist_files:
391 file_path = os.path.join(target_dir, file)
392 if os.path.exists(file_path):
393 os.remove(file_path)
394
Alan Viverettef17c9402017-07-19 12:57:40 -0400395
Alan Viverettecd3de262017-08-14 09:51:30 -0400396def fetch_artifact(target, build_id, artifact_path):
Jiyong Park1d1c9632018-05-29 17:45:27 +0900397 download_to = os.path.join('.', os.path.dirname(artifact_path))
398 print('Fetching %s from %s ...' % (artifact_path, target))
399 if not os.path.exists(download_to):
400 os.makedirs(download_to)
401 fetch_cmd = [FETCH_ARTIFACT, '--bid', str(build_id), '--target', target, artifact_path,
402 download_to]
Jeff Gaston97a9b762018-10-02 15:15:12 -0400403 print("Running: " + ' '.join(fetch_cmd))
Alan Viverette45837092017-05-12 14:50:53 -0400404 try:
Alan Viverettecd3de262017-08-14 09:51:30 -0400405 subprocess.check_output(fetch_cmd, stderr=subprocess.STDOUT)
Alan Viverette45837092017-05-12 14:50:53 -0400406 except subprocess.CalledProcessError:
Jeff Gaston13e38412018-02-06 14:45:36 -0500407 print_e('FAIL: Unable to retrieve %s artifact for build ID %s' % (artifact_path, build_id))
Alan Viverettec1c32b62017-12-20 09:40:36 -0500408 print_e('Please make sure you are authenticated for build server access!')
Alan Viverette45837092017-05-12 14:50:53 -0400409 return None
410 return artifact_path
411
412
Anton Hansson1d01a032018-04-09 10:29:37 +0100413def fetch_artifacts(target, build_id, artifact_dict):
414 for artifact, target_path in artifact_dict.items():
415 artifact_path = fetch_artifact(target, build_id.url_id, artifact)
416 if not artifact_path:
417 return False
418 mv(artifact_path, target_path)
419 return True
420
421
Alan Viverette129555e2018-01-30 09:57:57 -0500422def extract_artifact(artifact_path):
Alan Viverette45837092017-05-12 14:50:53 -0400423 # Unzip the repo archive into a separate directory.
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400424 repo_dir = os.path.basename(artifact_path)[:-4]
Alan Viverette45837092017-05-12 14:50:53 -0400425 with zipfile.ZipFile(artifact_path) as zipFile:
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400426 zipFile.extractall(repo_dir)
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400427 return repo_dir
428
429
Alan Viverette7e897e22018-03-09 15:24:10 -0500430def fetch_and_extract(target, build_id, file, artifact_path=None):
431 if not artifact_path:
432 artifact_path = fetch_artifact(target, build_id, file)
Alan Viverette129555e2018-01-30 09:57:57 -0500433 if not artifact_path:
434 return None
435 return extract_artifact(artifact_path)
436
437
Jeff Gaston08a2ee42018-05-07 18:08:41 -0400438def update_androidx(target, build_id, local_file):
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400439 if build_id:
Anthony Chenacbb4872018-07-02 11:22:48 -0700440 repo_file = 'top-of-tree-m2repository-all-%s.zip' % build_id.fs_id
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400441 repo_dir = fetch_and_extract(target, build_id.url_id, repo_file, None)
442 else:
443 repo_dir = fetch_and_extract(target, None, None, local_file)
444 if not repo_dir:
445 print_e('Failed to extract AndroidX repository')
446 return False
447
Tony Mak0f658752019-07-19 11:11:05 +0100448 # Keep JavaPlugins.bp file untounched.
449 java_plugins_bp_path = os.path.join(androidx_dir, 'JavaPlugins.bp')
450 tmp_java_plugins_bp_path = os.path.join('/tmp', 'JavaPlugins.bp')
451 mv(java_plugins_bp_path, tmp_java_plugins_bp_path)
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400452
Tony Mak0f658752019-07-19 11:11:05 +0100453 # Transform the repo archive into a Makefile-compatible format.
454 if not transform_maven_repos([repo_dir], androidx_dir, extract_res=False):
455 return False
456
457 # Import JavaPlugins.bp in Android.bp.
458 makefile = os.path.join(androidx_dir, 'Android.bp')
459 with open(makefile, "a+") as f:
460 f.write('\nbuild = ["JavaPlugins.bp"]\n')
461 mv(tmp_java_plugins_bp_path, java_plugins_bp_path)
462
463 return True
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400464
Alan Viverette41dd98c2020-04-16 14:56:20 +0000465
Jeff Gaston782c3e32018-02-06 14:36:17 -0500466def update_jetifier(target, build_id):
467 repo_file = 'jetifier-standalone.zip'
468 repo_dir = fetch_and_extract(target, build_id.url_id, repo_file)
469 if not repo_dir:
470 print_e('Failed to extract Jetifier')
471 return False
472
473 rm(jetifier_dir)
Jeff Gaston553a4372018-03-29 18:34:22 -0400474 mv(os.path.join(repo_dir, 'jetifier-standalone'), jetifier_dir)
475 os.chmod(os.path.join(jetifier_dir, 'bin', 'jetifier-standalone'), 0o755)
Jeff Gaston782c3e32018-02-06 14:36:17 -0500476 return True
477
Alan Viverette7e897e22018-03-09 15:24:10 -0500478
Alan Viverette41dd98c2020-04-16 14:56:20 +0000479def update_constraint(local_file):
Jeff Gaston9edf86c2018-04-18 13:45:23 -0400480 repo_dir = extract_artifact(local_file)
481 if not repo_dir:
Alan Viverette41dd98c2020-04-16 14:56:20 +0000482 print_e('Failed to extract Constraint Layout')
Jeff Gaston9edf86c2018-04-18 13:45:23 -0400483 return False
484 return transform_maven_repos([repo_dir], os.path.join(extras_dir, 'constraint-layout-x'), extract_res=False)
485
Alan Viverette45837092017-05-12 14:50:53 -0400486
Jeff Gaston6e7e7502018-04-04 00:22:45 -0400487def update_material(file):
488 design_dir = extract_artifact(file)
489 if not design_dir:
Alan Viverette41dd98c2020-04-16 14:56:20 +0000490 print_e('Failed to extract Material Design Components')
Jeff Gaston6e7e7502018-04-04 00:22:45 -0400491 return False
492
493 # Don't bother extracting resources -- this should only be used with AAPT2.
494 return transform_maven_repos([design_dir],
495 os.path.join(extras_dir, 'material-design-x'), extract_res=False)
496
497
Anton Hansson1d01a032018-04-09 10:29:37 +0100498def update_framework(build_id, sdk_dir):
Anton Hansson83f92172020-03-26 11:12:03 +0000499 api_scope_list = ['public', 'system', 'test', 'module-lib', 'system-server']
Sundong Ahn66091f22018-08-29 18:54:28 +0900500 if sdk_dir == 'current':
501 api_scope_list.append('core')
502
503 for api_scope in api_scope_list:
Jiyong Park1d1c9632018-05-29 17:45:27 +0900504 target_dir = path(sdk_dir, api_scope)
Sundong Ahn66091f22018-08-29 18:54:28 +0900505 if api_scope == 'core':
506 artifact_to_path = {'core.current.stubs.jar': path(target_dir, 'android.jar')}
507 else:
508 artifact_to_path = {'apistubs/android/' + api_scope + '/*.jar': path(target_dir, '*')}
Anton Hansson1d01a032018-04-09 10:29:37 +0100509
510 if not fetch_artifacts(framework_sdk_target, build_id, artifact_to_path):
511 return False
512
Jiyong Park1d1c9632018-05-29 17:45:27 +0900513 if api_scope == 'public':
Anton Hansson1d01a032018-04-09 10:29:37 +0100514 # Fetch a few artifacts from the public sdk.
Sundong Ahn66091f22018-08-29 18:54:28 +0900515 artifact = 'sdk-repo-linux-platforms-%s.zip' % build_id.fs_id
Anton Hansson1d01a032018-04-09 10:29:37 +0100516 artifact_path = fetch_artifact(framework_sdk_target, build_id.url_id, artifact)
Anton Hansson9709fd42018-04-03 16:52:13 +0100517 if not artifact_path:
518 return False
Anton Hansson1d01a032018-04-09 10:29:37 +0100519
520 with zipfile.ZipFile(artifact_path) as zipFile:
Colin Crossd338d702020-07-10 19:17:54 -0700521 extra_files = [
522 'android.jar',
523 'framework.aidl',
524 'uiautomator.jar',
525 'core-for-system-modules.jar',
526 'data/annotations.zip',
527 'data/api-versions.xml']
528 for filename in extra_files:
Anton Hanssona26e4812020-03-25 12:54:39 +0000529 matches = list(filter(lambda path: filename in path, zipFile.namelist()))
530 if len(matches) != 1:
531 print_e('Expected 1 file named \'%s\' in zip %s, found %d' %
532 (filename, zipFile.filename, len(matches)))
533 return False
534 zip_path = matches[0]
535 src_path = zipFile.extract(zip_path)
536 dst_path = path(target_dir, filename)
537 mv(src_path, dst_path)
Anton Hansson9709fd42018-04-03 16:52:13 +0100538
Alan Viverettecd3de262017-08-14 09:51:30 -0400539 return True
Alan Viverette45837092017-05-12 14:50:53 -0400540
Sundong Ahncc34cc32018-07-11 15:18:47 +0900541def update_makefile(build_id):
542 template = '"%s",\n\
543 "current"'
544 makefile = os.path.join(git_dir, 'Android.bp')
545
546 with open(makefile, 'r+') as f:
547 contents = f.read().replace('"current"', template % build_id)
548 f.seek(0)
549 f.write(contents)
550
551 return True
Alan Viverette45837092017-05-12 14:50:53 -0400552
Anton Hansson1d01a032018-04-09 10:29:37 +0100553def finalize_sdk(build_id, sdk_version):
554 target_finalize_dir = '%d' % sdk_version
Anton Hansson9709fd42018-04-03 16:52:13 +0100555
Anton Hanssonaa554c02020-04-30 14:06:20 +0100556 for api_scope in ['public', 'system', 'test', 'module-lib', 'system-server']:
Sundong Ahn66091f22018-08-29 18:54:28 +0900557 artifact_to_path = {'apistubs/android/' + api_scope + '/api/*.txt':
558 path(target_finalize_dir, api_scope, 'api', '*')}
559
560 if not fetch_artifacts(framework_sdk_target, build_id, artifact_to_path):
561 return False
562
563 return update_framework(build_id, target_finalize_dir) \
Sundong Ahncc34cc32018-07-11 15:18:47 +0900564 and update_makefile(target_finalize_dir)
Anton Hansson9709fd42018-04-03 16:52:13 +0100565
Anton Hansson9709fd42018-04-03 16:52:13 +0100566
Anton Hansson1d01a032018-04-09 10:29:37 +0100567def update_framework_current(build_id):
568 return update_framework(build_id, current_path)
Anton Hansson9709fd42018-04-03 16:52:13 +0100569
570
Alan Viverettec1c32b62017-12-20 09:40:36 -0500571def update_buildtools(target, arch, build_id):
Jeff Gaston13e38412018-02-06 14:45:36 -0500572 artifact_path = fetch_and_extract(target, build_id.url_id,
573 "sdk-repo-%s-build-tools-%s.zip" % (arch, build_id.fs_id))
Alan Viverettec1c32b62017-12-20 09:40:36 -0500574 if not artifact_path:
575 return False
576
577 top_level_dir = os.listdir(artifact_path)[0]
578 src_path = os.path.join(artifact_path, top_level_dir)
579 dst_path = path(buildtools_dir, arch)
580 mv(src_path, dst_path)
581
582 # Move all top-level files to /bin and make them executable
583 bin_path = path(dst_path, 'bin')
584 top_level_files = filter(lambda e: os.path.isfile(path(dst_path, e)), os.listdir(dst_path))
585 for file in top_level_files:
586 src_file = path(dst_path, file)
587 dst_file = path(bin_path, file)
588 mv(src_file, dst_file)
589 os.chmod(dst_file, 0o755)
590
Colin Cross6673ceb2021-02-12 13:14:14 -0800591 # Make the files under lld-bin executable
592 lld_bin_files = os.listdir(os.path.join(dst_path, 'lld-bin'))
593 for file in lld_bin_files:
594 os.chmod(os.path.join(dst_path, 'lld-bin', file), 0o755)
595
Alan Viverettec1c32b62017-12-20 09:40:36 -0500596 # Remove renderscript
597 rm(path(dst_path, 'renderscript'))
598
599 return True
600
601
Alan Viverettecd3de262017-08-14 09:51:30 -0400602def append(text, more_text):
603 if text:
604 return "%s, %s" % (text, more_text)
605 return more_text
Alan Viverette45837092017-05-12 14:50:53 -0400606
Alan Viverette95f6d362017-04-06 09:40:50 -0400607
Jeff Gaston13e38412018-02-06 14:45:36 -0500608class buildId(object):
609 def __init__(self, url_id, fs_id):
610 # id when used in build server urls
611 self.url_id = url_id
612 # id when used in build commands
613 self.fs_id = fs_id
614
Jeff Gastonb9b09052018-02-05 14:16:05 -0500615def getBuildId(args):
Jeff Gaston13e38412018-02-06 14:45:36 -0500616 # must be in the format 12345 or P12345
Jeff Gastonb9b09052018-02-05 14:16:05 -0500617 source = args.source
Jeff Gaston13e38412018-02-06 14:45:36 -0500618 number_text = source[:]
619 presubmit = False
620 if number_text.startswith("P"):
621 presubmit = True
622 number_text = number_text[1:]
623 if not number_text.isnumeric():
Alan Viverette7e897e22018-03-09 15:24:10 -0500624 return None
Jeff Gaston13e38412018-02-06 14:45:36 -0500625 url_id = source
626 fs_id = url_id
627 if presubmit:
628 fs_id = "0"
629 args.file = False
630 return buildId(url_id, fs_id)
Jeff Gastonb9b09052018-02-05 14:16:05 -0500631
Colin Cross573e1212018-02-12 14:59:52 -0800632def getFile(args):
633 source = args.source
634 if not source.isnumeric():
635 return args.source
Alan Viverette7e897e22018-03-09 15:24:10 -0500636 return None
Colin Cross573e1212018-02-12 14:59:52 -0800637
Alan Viverette4ec9a172018-02-20 16:19:31 -0500638
639def script_relative(rel_path):
Jeff Gastona68a8d42018-03-23 14:00:13 -0400640 return os.path.join(script_dir, rel_path)
Alan Viverette4ec9a172018-02-20 16:19:31 -0500641
642
Jeff Gastoncc296a82018-03-23 14:33:24 -0400643def uncommittedChangesExist():
644 try:
645 # Make sure we don't overwrite any pending changes.
646 diffCommand = "cd " + git_dir + " && git diff --quiet"
647 subprocess.check_call(diffCommand, shell=True)
648 subprocess.check_call(diffCommand + " --cached", shell=True)
649 return False
650 except subprocess.CalledProcessError:
651 return True
652
653
Jeff Gastona7fba9b2018-03-26 23:48:51 -0400654rm(temp_dir)
Alan Viveretted4527e62017-05-11 15:03:25 -0400655parser = argparse.ArgumentParser(
Alan Viverette45837092017-05-12 14:50:53 -0400656 description=('Update current prebuilts'))
Alan Viveretted4527e62017-05-11 15:03:25 -0400657parser.add_argument(
Alan Viverette129555e2018-01-30 09:57:57 -0500658 'source',
659 help='Build server build ID or local Maven ZIP file')
660parser.add_argument(
Jeff Gaston6e7e7502018-04-04 00:22:45 -0400661 '-m', '--material', action="store_true",
Alan Viverette41dd98c2020-04-16 14:56:20 +0000662 help='If specified, updates only Material Design Components')
Jeff Gaston6e7e7502018-04-04 00:22:45 -0400663parser.add_argument(
Alan Viverette3e57a4a2017-08-11 15:49:47 -0400664 '-c', '--constraint', action="store_true",
665 help='If specified, updates only Constraint Layout')
666parser.add_argument(
Jeff Gaston782c3e32018-02-06 14:36:17 -0500667 '-j', '--jetifier', action="store_true",
668 help='If specified, updates only Jetifier')
669parser.add_argument(
Alan Viverette5bfe05b2017-06-06 14:21:29 -0400670 '-p', '--platform', action="store_true",
671 help='If specified, updates only the Android Platform')
Alan Viverettec1c32b62017-12-20 09:40:36 -0500672parser.add_argument(
Anton Hansson9709fd42018-04-03 16:52:13 +0100673 '-f', '--finalize_sdk', type=int,
674 help='If specified, imports the source build as the specified finalized SDK version')
675parser.add_argument(
Alan Viverettec1c32b62017-12-20 09:40:36 -0500676 '-b', '--buildtools', action="store_true",
677 help='If specified, updates only the Build Tools')
Jeff Gastoncc296a82018-03-23 14:33:24 -0400678parser.add_argument(
Alan Viverette41dd98c2020-04-16 14:56:20 +0000679 '-x', '--androidx', action="store_true",
680 help='If specified, updates only the Jetpack (androidx) libraries excluding those covered by other arguments')
Jeff Gaston41fd5e62018-04-25 17:02:02 -0400681parser.add_argument(
Jeff Gastoncc296a82018-03-23 14:33:24 -0400682 '--commit-first', action="store_true",
683 help='If specified, then if uncommited changes exist, commit before continuing')
Alan Viveretted4527e62017-05-11 15:03:25 -0400684args = parser.parse_args()
Jeff Gaston56fe2762018-02-06 14:54:37 -0500685args.file = True
Alan Viverette129555e2018-01-30 09:57:57 -0500686if not args.source:
687 parser.error("You must specify a build ID or local Maven ZIP file")
Alan Viveretted4527e62017-05-11 15:03:25 -0400688 sys.exit(1)
Alan Viverette41dd98c2020-04-16 14:56:20 +0000689if not (args.platform or args.buildtools \
690 or args.jetifier or args.androidx or args.material \
691 or args.finalize_sdk or args.constraint):
Alan Viverettec1c32b62017-12-20 09:40:36 -0500692 parser.error("You must specify at least one target to update")
Alan Viverettecd3de262017-08-14 09:51:30 -0400693 sys.exit(1)
Alan Viverette41dd98c2020-04-16 14:56:20 +0000694if (args.constraint or args.material or args.androidx) \
Colin Cross74683bc2018-04-11 17:36:18 -0700695 and which('pom2bp') is None:
Louis Pullen-Freilich61bb70e2019-04-09 16:15:32 +0100696 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 -0500697 sys.exit(1)
Alan Viveretted4527e62017-05-11 15:03:25 -0400698
Jeff Gastoncc296a82018-03-23 14:33:24 -0400699if uncommittedChangesExist():
700 if args.commit_first:
701 subprocess.check_call("cd " + git_dir + " && git add -u", shell=True)
702 subprocess.check_call("cd " + git_dir + " && git commit -m 'save working state'", shell=True)
703
704if uncommittedChangesExist():
Anton Hansson10861a02018-04-06 13:57:08 +0100705 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 -0400706 sys.exit(1)
707
708try:
Alan Viverettecd3de262017-08-14 09:51:30 -0400709 components = None
710 if args.constraint:
Jeff Gaston9edf86c2018-04-18 13:45:23 -0400711 if update_constraint_x(getFile(args)):
712 components = append(components, 'Constraint Layout X')
713 else:
714 print_e('Failed to update Constraint Layout X, aborting...')
Alan Viverettecd3de262017-08-14 09:51:30 -0400715 sys.exit(1)
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400716 if args.androidx:
Jeff Gaston17ccf8f2018-08-29 11:33:19 -0400717 if update_androidx('androidx', \
Jeff Gastonbbd6bfc2018-03-27 17:35:49 -0400718 getBuildId(args), getFile(args)):
719 components = append(components, 'AndroidX')
720 else:
721 print_e('Failed to update AndroidX, aborting...')
722 sys.exit(1)
Jeff Gaston782c3e32018-02-06 14:36:17 -0500723 if args.jetifier:
Jeff Gaston17ccf8f2018-08-29 11:33:19 -0400724 if update_jetifier('androidx', getBuildId(args)):
Jeff Gaston782c3e32018-02-06 14:36:17 -0500725 components = append(components, 'Jetifier')
726 else:
727 print_e('Failed to update Jetifier, aborting...')
728 sys.exit(1)
Anton Hanssonbe15e8c2018-04-26 17:35:45 +0100729 if args.platform or args.finalize_sdk:
Anton Hansson87654c42018-04-26 15:19:42 +0100730 if update_framework_current(getBuildId(args)):
Alan Viverettecd3de262017-08-14 09:51:30 -0400731 components = append(components, 'platform SDK')
732 else:
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500733 print_e('Failed to update platform SDK, aborting...')
Alan Viverettecd3de262017-08-14 09:51:30 -0400734 sys.exit(1)
Anton Hansson9709fd42018-04-03 16:52:13 +0100735 if args.finalize_sdk:
Anton Hanssonbe15e8c2018-04-26 17:35:45 +0100736 n = args.finalize_sdk
737 if finalize_sdk(getBuildId(args), n):
738 # We commit the finalized dir separately from the current sdk update.
739 msg = "Import final sdk version %d from build %s" % (n, getBuildId(args).url_id)
740 subprocess.check_call(['git', 'add', '%d' % n])
Sundong Ahncc34cc32018-07-11 15:18:47 +0900741 subprocess.check_call(['git', 'add', 'Android.bp'])
Anton Hanssonbe15e8c2018-04-26 17:35:45 +0100742 subprocess.check_call(['git', 'commit', '-m', msg])
Anton Hansson9709fd42018-04-03 16:52:13 +0100743 else:
Anton Hanssonbe15e8c2018-04-26 17:35:45 +0100744 print_e('Failed to finalize SDK %d, aborting...' % n)
Anton Hansson9709fd42018-04-03 16:52:13 +0100745 sys.exit(1)
Jeff Gaston6e7e7502018-04-04 00:22:45 -0400746 if args.material:
747 if update_material(getFile(args)):
748 components = append(components, 'intermediate-AndroidX Design Library')
749 else:
750 print_e('Failed to update intermediate-AndroidX Design Library, aborting...')
Alan Viverette129555e2018-01-30 09:57:57 -0500751 sys.exit(1)
Alan Viverettec1c32b62017-12-20 09:40:36 -0500752 if args.buildtools:
Jeff Gastonb9b09052018-02-05 14:16:05 -0500753 if update_buildtools('sdk_phone_armv7-sdk_mac', 'darwin', getBuildId(args)) \
754 and update_buildtools('sdk_phone_x86_64-sdk', 'linux', getBuildId(args)) \
755 and update_buildtools('sdk_phone_armv7-win_sdk', 'windows', getBuildId(args)):
Alan Viverettec1c32b62017-12-20 09:40:36 -0500756 components = append(components, 'build tools')
757 else:
758 print_e('Failed to update build tools, aborting...')
759 sys.exit(1)
Jeff Gastonb70daa92018-03-29 20:10:22 -0400760
Jeff Gastonf12f3ce2018-03-23 16:41:24 -0400761
Alan Viveretted4527e62017-05-11 15:03:25 -0400762
Colin Cross941d9802018-05-03 21:37:57 -0700763 subprocess.check_call(['git', 'add', current_path, buildtools_dir])
Colin Cross573e1212018-02-12 14:59:52 -0800764 if not args.source.isnumeric():
Alan Viverette129555e2018-01-30 09:57:57 -0500765 src_msg = "local Maven ZIP"
766 else:
Jeff Gaston13e38412018-02-06 14:45:36 -0500767 src_msg = "build %s" % (getBuildId(args).url_id)
Alan Viverette129555e2018-01-30 09:57:57 -0500768 msg = "Import %s from %s\n\n%s" % (components, src_msg, flatten(sys.argv))
Alan Viveretted4527e62017-05-11 15:03:25 -0400769 subprocess.check_call(['git', 'commit', '-m', msg])
Anton Hanssonbe15e8c2018-04-26 17:35:45 +0100770 if args.finalize_sdk:
771 print('NOTE: Created two commits:')
772 subprocess.check_call(['git', 'log', '-2', '--oneline'])
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500773 print('Remember to test this change before uploading it to Gerrit!')
Alan Viveretted4527e62017-05-11 15:03:25 -0400774
775finally:
776 # Revert all stray files, including the downloaded zip.
777 try:
778 with open(os.devnull, 'w') as bitbucket:
779 subprocess.check_call(['git', 'add', '-Af', '.'], stdout=bitbucket)
780 subprocess.check_call(
Jeff Gaston9edf86c2018-04-18 13:45:23 -0400781 ['git', 'commit', '-m', 'COMMIT TO REVERT - RESET ME!!!', '--allow-empty'], stdout=bitbucket)
Alan Viveretted4527e62017-05-11 15:03:25 -0400782 subprocess.check_call(['git', 'reset', '--hard', 'HEAD~1'], stdout=bitbucket)
783 except subprocess.CalledProcessError:
Alan Viverettef5cb0e62017-11-17 15:15:23 -0500784 print_e('ERROR: Failed cleaning up, manual cleanup required!!!')