Alan Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 1 | #!/usr/bin/python3 |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 2 | |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 3 | # 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 Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 6 | import os, sys, getopt, zipfile, re |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 7 | import argparse |
Jiyong Park | 1d1c963 | 2018-05-29 17:45:27 +0900 | [diff] [blame] | 8 | import glob |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 9 | import subprocess |
shepshapard | e4127cf | 2019-09-03 16:08:44 -0700 | [diff] [blame] | 10 | from shutil import copyfile, rmtree, which, move |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 11 | from distutils.version import LooseVersion |
Alan Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 12 | from functools import reduce |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 13 | |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 14 | current_path = 'current' |
Andy Wickham | c3c99af | 2020-10-26 20:47:58 +0000 | [diff] [blame] | 15 | framework_sdk_target = 'sdk_phone_armv7-win_sdk' |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 16 | androidx_dir = os.path.join(current_path, 'androidx') |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 17 | extras_dir = os.path.join(current_path, 'extras') |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 18 | buildtools_dir = 'tools' |
Jeff Gaston | 553a437 | 2018-03-29 18:34:22 -0400 | [diff] [blame] | 19 | jetifier_dir = os.path.join(buildtools_dir, 'jetifier', 'jetifier-standalone') |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 20 | |
Jeff Gaston | a68a8d4 | 2018-03-23 14:00:13 -0400 | [diff] [blame] | 21 | temp_dir = os.path.join(os.getcwd(), "support_tmp") |
| 22 | os.chdir(os.path.dirname(os.path.dirname(os.path.realpath(sys.argv[0])))) |
| 23 | git_dir = os.getcwd() |
| 24 | |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 25 | # See go/fetch_artifact for details on this script. |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 26 | FETCH_ARTIFACT = '/google/data/ro/projects/android/fetch_artifact' |
Jeff Sharkey | abe16df | 2021-05-25 10:09:03 -0600 | [diff] [blame] | 27 | FETCH_ARTIFACT_BEYOND_CORP = '/usr/bin/fetch_artifact' |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 28 | |
Alan Viverette | 0723aff | 2021-08-31 17:07:47 +0000 | [diff] [blame] | 29 | # Leave map blank to automatically populate name and path: |
| 30 | # - Name format is MAVEN.replaceAll(':','_') |
| 31 | # - Path format is MAVEN.replaceAll(':','/').replaceAll('.','/') |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 32 | maven_to_make = { |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 33 | # AndroidX |
Alan Viverette | f3c1272 | 2021-08-30 19:50:33 +0000 | [diff] [blame] | 34 | 'androidx.benchmark:benchmark-macro': { }, |
| 35 | 'androidx.benchmark:benchmark-macro-junit4': { }, |
| 36 | 'androidx.benchmark:benchmark-common': { }, |
| 37 | 'androidx.benchmark:benchmark-junit4': { }, |
| 38 | 'androidx.tracing:tracing': { }, |
| 39 | 'androidx.tracing:tracing-ktx': { }, |
| 40 | 'androidx.slice:slice-builders': { }, |
| 41 | 'androidx.slice:slice-core': { }, |
| 42 | 'androidx.slice:slice-view': { }, |
| 43 | 'androidx.remotecallback:remotecallback': { }, |
Alan Viverette | 0723aff | 2021-08-31 17:07:47 +0000 | [diff] [blame] | 44 | 'androidx.remotecallback:remotecallback-processor': {'host':True}, |
| 45 | 'androidx.versionedparcelable:versionedparcelable': { }, |
Alan Viverette | f3c1272 | 2021-08-30 19:50:33 +0000 | [diff] [blame] | 46 | 'androidx.vectordrawable:vectordrawable-animated': { }, |
| 47 | 'androidx.activity:activity': { }, |
| 48 | 'androidx.activity:activity-ktx': { }, |
Alan Viverette | 0723aff | 2021-08-31 17:07:47 +0000 | [diff] [blame] | 49 | 'androidx.annotation:annotation': {'host_and_device':True}, |
Alan Viverette | f3c1272 | 2021-08-30 19:50:33 +0000 | [diff] [blame] | 50 | 'androidx.annotation:annotation-experimental': { }, |
| 51 | 'androidx.asynclayoutinflater:asynclayoutinflater': { }, |
| 52 | 'androidx.collection:collection': { }, |
| 53 | 'androidx.collection:collection-ktx': { }, |
| 54 | 'androidx.concurrent:concurrent-futures': { }, |
| 55 | 'androidx.concurrent:concurrent-listenablefuture-callback': { }, |
| 56 | 'androidx.concurrent:concurrent-listenablefuture': { }, |
| 57 | 'androidx.core:core': { }, |
| 58 | 'androidx.core:core-animation': { }, |
| 59 | 'androidx.core:core-ktx': { }, |
| 60 | 'androidx.contentpaging:contentpaging': { }, |
| 61 | 'androidx.coordinatorlayout:coordinatorlayout': { }, |
| 62 | 'androidx.legacy:legacy-support-core-ui': { }, |
| 63 | 'androidx.legacy:legacy-support-core-utils': { }, |
| 64 | 'androidx.cursoradapter:cursoradapter': { }, |
| 65 | 'androidx.browser:browser': { }, |
| 66 | 'androidx.customview:customview': { }, |
| 67 | 'androidx.documentfile:documentfile': { }, |
| 68 | 'androidx.drawerlayout:drawerlayout': { }, |
| 69 | 'androidx.dynamicanimation:dynamicanimation': { }, |
| 70 | 'androidx.emoji:emoji': { }, |
| 71 | 'androidx.emoji:emoji-appcompat': { }, |
| 72 | 'androidx.emoji:emoji-bundled': { }, |
| 73 | 'androidx.emoji2:emoji2': { }, |
| 74 | 'androidx.emoji2:emoji2-views-helper': { }, |
| 75 | 'androidx.exifinterface:exifinterface': { }, |
| 76 | 'androidx.fragment:fragment': { }, |
| 77 | 'androidx.fragment:fragment-ktx': { }, |
| 78 | 'androidx.heifwriter:heifwriter': { }, |
| 79 | 'androidx.interpolator:interpolator': { }, |
| 80 | 'androidx.loader:loader': { }, |
| 81 | 'androidx.localbroadcastmanager:localbroadcastmanager': { }, |
| 82 | 'androidx.media:media': { }, |
| 83 | 'androidx.media2:media2-player': { }, |
| 84 | 'androidx.media2:media2-session': { }, |
| 85 | 'androidx.media2:media2-common': { }, |
| 86 | 'androidx.media2:media2-exoplayer': { }, |
| 87 | 'androidx.media2:media2-widget': { }, |
| 88 | 'androidx.navigation:navigation-common': { }, |
| 89 | 'androidx.navigation:navigation-common-ktx': { }, |
| 90 | 'androidx.navigation:navigation-fragment': { }, |
| 91 | 'androidx.navigation:navigation-fragment-ktx': { }, |
| 92 | 'androidx.navigation:navigation-runtime': { }, |
| 93 | 'androidx.navigation:navigation-runtime-ktx': { }, |
| 94 | 'androidx.navigation:navigation-ui': { }, |
| 95 | 'androidx.navigation:navigation-ui-ktx': { }, |
| 96 | 'androidx.percentlayout:percentlayout': { }, |
| 97 | 'androidx.print:print': { }, |
| 98 | 'androidx.recommendation:recommendation': { }, |
| 99 | 'androidx.recyclerview:recyclerview-selection': { }, |
| 100 | 'androidx.savedstate:savedstate': { }, |
| 101 | 'androidx.savedstate:savedstate-ktx': { }, |
| 102 | 'androidx.slidingpanelayout:slidingpanelayout': { }, |
| 103 | 'androidx.swiperefreshlayout:swiperefreshlayout': { }, |
| 104 | 'androidx.textclassifier:textclassifier': { }, |
| 105 | 'androidx.transition:transition': { }, |
| 106 | 'androidx.tvprovider:tvprovider': { }, |
| 107 | 'androidx.legacy:legacy-support-v13': { }, |
| 108 | 'androidx.legacy:legacy-preference-v14': { }, |
| 109 | 'androidx.leanback:leanback': { }, |
| 110 | 'androidx.leanback:leanback-preference': { }, |
| 111 | 'androidx.legacy:legacy-support-v4': { }, |
| 112 | 'androidx.appcompat:appcompat': { }, |
| 113 | 'androidx.appcompat:appcompat-resources': { }, |
| 114 | 'androidx.cardview:cardview': { }, |
| 115 | 'androidx.gridlayout:gridlayout': { }, |
| 116 | 'androidx.mediarouter:mediarouter': { }, |
| 117 | 'androidx.palette:palette': { }, |
| 118 | 'androidx.preference:preference': { }, |
| 119 | 'androidx.recyclerview:recyclerview': { }, |
| 120 | 'androidx.vectordrawable:vectordrawable': { }, |
| 121 | 'androidx.viewpager:viewpager': { }, |
| 122 | 'androidx.viewpager2:viewpager2': { }, |
| 123 | 'androidx.wear:wear': { }, |
| 124 | 'androidx.wear:wear-ongoing': { }, |
| 125 | 'androidx.webkit:webkit': { }, |
| 126 | 'androidx.biometric:biometric': { }, |
| 127 | 'androidx.autofill:autofill': { }, |
| 128 | 'androidx.appsearch:appsearch': { }, |
Alan Viverette | 0723aff | 2021-08-31 17:07:47 +0000 | [diff] [blame] | 129 | 'androidx.appsearch:appsearch-local-storage': {'name':'androidx.appsearch_appsearch_local_storage'}, |
| 130 | 'androidx.appsearch:appsearch-platform-storage': { }, |
| 131 | 'androidx.appsearch:appsearch-compiler': {'name':'androidx.appsearch_appsearch-compiler', 'host':True}, |
Alan Viverette | f3c1272 | 2021-08-30 19:50:33 +0000 | [diff] [blame] | 132 | 'androidx.car.app:app': { }, |
| 133 | 'androidx.car.app:app-automotive': { }, |
| 134 | 'androidx.car.app:app-testing': { }, |
| 135 | 'androidx.startup:startup-runtime': { }, |
| 136 | 'androidx.window:window': { }, |
| 137 | 'androidx.resourceinspection:resourceinspection-annotation': { }, |
| 138 | 'androidx.profileinstaller:profileinstaller': { }, |
Aurimas Liutikas | 6e87bbf | 2021-07-30 10:04:05 -0700 | [diff] [blame] | 139 | |
Alan Viverette | f44e2f9 | 2021-08-31 17:26:26 +0000 | [diff] [blame] | 140 | # AndroidX for Compose |
| 141 | 'androidx.compose.compiler:compiler-hosted': { }, |
| 142 | 'androidx.compose.runtime:runtime': { }, |
| 143 | 'androidx.compose.runtime:runtime-saveable': { }, |
| 144 | 'androidx.compose.foundation:foundation': { }, |
| 145 | 'androidx.compose.foundation:foundation-layout': { }, |
| 146 | 'androidx.compose.foundation:foundation-text': { }, |
| 147 | 'androidx.compose.ui:ui': { }, |
| 148 | 'androidx.compose.ui:ui-geometry': { }, |
| 149 | 'androidx.compose.ui:ui-graphics': { }, |
| 150 | 'androidx.compose.ui:ui-text': { }, |
| 151 | 'androidx.compose.ui:ui-unit': { }, |
| 152 | 'androidx.compose.ui:ui-util': { }, |
| 153 | 'androidx.compose.animation:animation-core': { }, |
| 154 | 'androidx.compose.animation:animation': { }, |
| 155 | 'androidx.compose.material:material-icons-core': { }, |
| 156 | 'androidx.compose.material:material-ripple': { }, |
| 157 | 'androidx.compose.material:material': { }, |
| 158 | 'androidx.activity:activity-compose': { }, |
| 159 | |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 160 | # AndroidX for Multidex |
Alan Viverette | 0723aff | 2021-08-31 17:07:47 +0000 | [diff] [blame] | 161 | 'androidx.multidex:multidex': { }, |
| 162 | 'androidx.multidex:multidex-instrumentation': { }, |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 163 | |
| 164 | # AndroidX for Constraint Layout |
Alan Viverette | 0723aff | 2021-08-31 17:07:47 +0000 | [diff] [blame] | 165 | 'androidx.constraintlayout:constraintlayout': {'name':'androidx-constraintlayout_constraintlayout'}, |
| 166 | 'androidx.constraintlayout:constraintlayout-solver': {'name':'androidx-constraintlayout_constraintlayout-solver'}, |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 167 | |
| 168 | # AndroidX for Architecture Components |
Alan Viverette | f3c1272 | 2021-08-30 19:50:33 +0000 | [diff] [blame] | 169 | 'androidx.arch.core:core-common': { }, |
| 170 | 'androidx.arch.core:core-runtime': { }, |
| 171 | 'androidx.lifecycle:lifecycle-common': { }, |
| 172 | 'androidx.lifecycle:lifecycle-common-java8': { }, |
| 173 | 'androidx.lifecycle:lifecycle-extensions': { }, |
| 174 | 'androidx.lifecycle:lifecycle-livedata': { }, |
| 175 | 'androidx.lifecycle:lifecycle-livedata-ktx': { }, |
| 176 | 'androidx.lifecycle:lifecycle-livedata-core': { }, |
| 177 | 'androidx.lifecycle:lifecycle-livedata-core-ktx': { }, |
| 178 | 'androidx.lifecycle:lifecycle-process': { }, |
| 179 | 'androidx.lifecycle:lifecycle-runtime': { }, |
| 180 | 'androidx.lifecycle:lifecycle-runtime-ktx': { }, |
| 181 | 'androidx.lifecycle:lifecycle-service': { }, |
| 182 | 'androidx.lifecycle:lifecycle-viewmodel': { }, |
| 183 | 'androidx.lifecycle:lifecycle-viewmodel-ktx': { }, |
| 184 | 'androidx.lifecycle:lifecycle-viewmodel-savedstate': { }, |
| 185 | 'androidx.paging:paging-common': { }, |
| 186 | 'androidx.paging:paging-common-ktx': { }, |
| 187 | 'androidx.paging:paging-runtime': { }, |
| 188 | 'androidx.sqlite:sqlite': { }, |
| 189 | 'androidx.sqlite:sqlite-framework': { }, |
Alan Viverette | 0723aff | 2021-08-31 17:07:47 +0000 | [diff] [blame] | 190 | 'androidx.room:room-common': {'host_and_device':True}, |
| 191 | 'androidx.room:room-compiler': {'host':True}, |
| 192 | 'androidx.room:room-migration': {'host_and_device':True}, |
Alan Viverette | f3c1272 | 2021-08-30 19:50:33 +0000 | [diff] [blame] | 193 | 'androidx.room:room-runtime': { }, |
| 194 | 'androidx.room:room-testing': { }, |
Alan Viverette | 0723aff | 2021-08-31 17:07:47 +0000 | [diff] [blame] | 195 | 'androidx.room:room-compiler-processing': {'host':True}, |
Alan Viverette | f3c1272 | 2021-08-30 19:50:33 +0000 | [diff] [blame] | 196 | 'androidx.work:work-runtime': { }, |
| 197 | 'androidx.work:work-runtime-ktx': { }, |
| 198 | 'androidx.work:work-testing': { }, |
Allen | ab72f01 | 2018-01-29 18:10:23 -0800 | [diff] [blame] | 199 | |
Alan Viverette | 19ecd50 | 2018-01-05 13:52:16 -0500 | [diff] [blame] | 200 | # Lifecycle |
Alan Viverette | c7e88f1 | 2018-02-13 15:29:50 -0500 | [diff] [blame] | 201 | # Missing dependencies: |
| 202 | # - auto-common |
| 203 | # - javapoet |
Jeff Gaston | a0bce60 | 2018-08-24 14:05:03 -0400 | [diff] [blame] | 204 | #'android.arch.lifecycle:compiler': {'name':'android-arch-lifecycle-compiler', 'path':'arch-lifecycle/compiler'}, |
Alan Viverette | c7e88f1 | 2018-02-13 15:29:50 -0500 | [diff] [blame] | 205 | # Missing dependencies: |
| 206 | # - reactive-streams |
Jeff Gaston | a0bce60 | 2018-08-24 14:05:03 -0400 | [diff] [blame] | 207 | #'android.arch.lifecycle:reactivestreams': 'android-arch-lifecycle-reactivestreams','arch-lifecycle/reactivestreams', |
Allen | ab72f01 | 2018-01-29 18:10:23 -0800 | [diff] [blame] | 208 | |
Alan Viverette | 19ecd50 | 2018-01-05 13:52:16 -0500 | [diff] [blame] | 209 | # Room |
Alan Viverette | c7e88f1 | 2018-02-13 15:29:50 -0500 | [diff] [blame] | 210 | # Missing dependencies: |
| 211 | # - auto-common |
| 212 | # - javapoet |
| 213 | # - antlr4 |
| 214 | # - kotlin-metadata |
| 215 | # - commons-codec |
Jeff Gaston | a0bce60 | 2018-08-24 14:05:03 -0400 | [diff] [blame] | 216 | #'android.arch.persistence.room:compiler': {'name':'android-arch-room-compiler', 'path':'arch-room/compiler'}, |
Alan Viverette | c7e88f1 | 2018-02-13 15:29:50 -0500 | [diff] [blame] | 217 | # Missing dependencies: |
| 218 | # - rxjava |
Jeff Gaston | a0bce60 | 2018-08-24 14:05:03 -0400 | [diff] [blame] | 219 | #'android.arch.persistence.room:rxjava2': {'name':'android-arch-room-rxjava2', 'path':'arch-room/rxjava2'}, |
Allen | ab72f01 | 2018-01-29 18:10:23 -0800 | [diff] [blame] | 220 | |
Jeff Gaston | 6e7e750 | 2018-04-04 00:22:45 -0400 | [diff] [blame] | 221 | # Third-party dependencies |
Jeff Gaston | a0bce60 | 2018-08-24 14:05:03 -0400 | [diff] [blame] | 222 | 'com.google.android:flexbox': {'name':'flexbox', 'path':'flexbox'}, |
Jeff Gaston | 6e7e750 | 2018-04-04 00:22:45 -0400 | [diff] [blame] | 223 | |
Jeff Gaston | fa7c7e8 | 2018-04-06 13:35:48 -0400 | [diff] [blame] | 224 | # Androidx Material Design Components |
Alan Viverette | f3c1272 | 2021-08-30 19:50:33 +0000 | [diff] [blame] | 225 | 'com.google.android.material:material': { }, |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 226 | } |
| 227 | |
Alan Viverette | f3c1272 | 2021-08-30 19:50:33 +0000 | [diff] [blame] | 228 | |
| 229 | def name_for_artifact(group_artifact): |
| 230 | return group_artifact.replace(':','_') |
| 231 | |
| 232 | |
| 233 | def path_for_artifact(group_artifact): |
| 234 | return group_artifact.replace('.','/').replace(':','/') |
| 235 | |
| 236 | |
| 237 | # Add automatic entries to maven_to_make. |
| 238 | for key in maven_to_make: |
| 239 | if ('name' not in maven_to_make[key]): |
| 240 | maven_to_make[key]['name'] = name_for_artifact(key) |
| 241 | if ('path' not in maven_to_make[key]): |
| 242 | maven_to_make[key]['path'] = path_for_artifact(key) |
| 243 | |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 244 | # Always remove these files. |
| 245 | blacklist_files = [ |
| 246 | 'annotations.zip', |
| 247 | 'public.txt', |
| 248 | 'R.txt', |
Alan Viverette | 44ad4e4 | 2017-08-09 17:45:00 -0400 | [diff] [blame] | 249 | 'AndroidManifest.xml', |
Alan Viverette | f48d9b4 | 2017-08-17 14:45:46 -0400 | [diff] [blame] | 250 | os.path.join('libs','noto-emoji-compat-java.jar') |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 251 | ] |
| 252 | |
Alan Viverette | 44ad4e4 | 2017-08-09 17:45:00 -0400 | [diff] [blame] | 253 | artifact_pattern = re.compile(r"^(.+?)-(\d+\.\d+\.\d+(?:-\w+\d+)?(?:-[\d.]+)*)\.(jar|aar)$") |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 254 | |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 255 | |
| 256 | class MavenLibraryInfo: |
Jeff Gaston | c302bb9 | 2018-03-23 13:53:48 -0400 | [diff] [blame] | 257 | def __init__(self, key, group_id, artifact_id, version, dir, repo_dir, file): |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 258 | self.key = key |
| 259 | self.group_id = group_id |
| 260 | self.artifact_id = artifact_id |
| 261 | self.version = version |
Jeff Gaston | c302bb9 | 2018-03-23 13:53:48 -0400 | [diff] [blame] | 262 | self.dir = dir |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 263 | self.repo_dir = repo_dir |
| 264 | self.file = file |
| 265 | |
| 266 | |
Alan Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 267 | def print_e(*args, **kwargs): |
| 268 | print(*args, file=sys.stderr, **kwargs) |
| 269 | |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 270 | |
| 271 | def touch(fname, times=None): |
| 272 | with open(fname, 'a'): |
| 273 | os.utime(fname, times) |
| 274 | |
| 275 | |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 276 | def path(*path_parts): |
| 277 | return reduce((lambda x, y: os.path.join(x, y)), path_parts) |
| 278 | |
| 279 | |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 280 | def flatten(list): |
| 281 | return reduce((lambda x, y: "%s %s" % (x, y)), list) |
| 282 | |
| 283 | |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 284 | def rm(path): |
| 285 | if os.path.isdir(path): |
| 286 | rmtree(path) |
| 287 | elif os.path.exists(path): |
| 288 | os.remove(path) |
| 289 | |
| 290 | |
| 291 | def mv(src_path, dst_path): |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 292 | if os.path.exists(dst_path): |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 293 | rm(dst_path) |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 294 | if not os.path.exists(os.path.dirname(dst_path)): |
| 295 | os.makedirs(os.path.dirname(dst_path)) |
Jiyong Park | 1d1c963 | 2018-05-29 17:45:27 +0900 | [diff] [blame] | 296 | for f in (glob.glob(src_path)): |
| 297 | if '*' in dst_path: |
| 298 | dst = os.path.join(os.path.dirname(dst_path), os.path.basename(f)) |
| 299 | else: |
| 300 | dst = dst_path |
shepshapard | e4127cf | 2019-09-03 16:08:44 -0700 | [diff] [blame] | 301 | move(f, dst) |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 302 | |
| 303 | |
Jeff Gaston | c302bb9 | 2018-03-23 13:53:48 -0400 | [diff] [blame] | 304 | def detect_artifacts(maven_repo_dirs): |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 305 | maven_lib_info = {} |
| 306 | |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 307 | # Find the latest revision for each artifact, remove others |
Jeff Gaston | c302bb9 | 2018-03-23 13:53:48 -0400 | [diff] [blame] | 308 | for repo_dir in maven_repo_dirs: |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 309 | for root, dirs, files in os.walk(repo_dir): |
| 310 | for file in files: |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 311 | if file[-4:] == ".pom": |
| 312 | # Read the POM (hack hack hack). |
| 313 | group_id = '' |
| 314 | artifact_id = '' |
| 315 | version = '' |
| 316 | file = os.path.join(root, file) |
| 317 | with open(file) as pom_file: |
| 318 | for line in pom_file: |
| 319 | if line[:11] == ' <groupId>': |
| 320 | group_id = line[11:-11] |
| 321 | elif line[:14] == ' <artifactId>': |
| 322 | artifact_id = line[14:-14] |
| 323 | elif line[:11] == ' <version>': |
| 324 | version = line[11:-11] |
| 325 | if group_id == '' or artifact_id == '' or version == '': |
| 326 | print_e('Failed to find Maven artifact data in ' + file) |
| 327 | continue |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 328 | |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 329 | # Locate the artifact. |
| 330 | artifact_file = file[:-4] |
| 331 | if os.path.exists(artifact_file + '.jar'): |
| 332 | artifact_file = artifact_file + '.jar' |
| 333 | elif os.path.exists(artifact_file + '.aar'): |
| 334 | artifact_file = artifact_file + '.aar' |
| 335 | else: |
| 336 | print_e('Failed to find artifact for ' + artifact_file) |
| 337 | continue |
| 338 | |
| 339 | # Make relative to root. |
| 340 | artifact_file = artifact_file[len(root) + 1:] |
| 341 | |
| 342 | # Find the mapping. |
| 343 | group_artifact = group_id + ':' + artifact_id |
Jeff Gaston | 3e622ba | 2018-03-26 23:24:46 -0400 | [diff] [blame] | 344 | if group_artifact in maven_to_make: |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 345 | key = group_artifact |
Jeff Gaston | 3e622ba | 2018-03-26 23:24:46 -0400 | [diff] [blame] | 346 | elif artifact_id in maven_to_make: |
| 347 | key = artifact_id |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 348 | else: |
Alan Viverette | f3c1272 | 2021-08-30 19:50:33 +0000 | [diff] [blame] | 349 | print('Failed to find artifact mapping for ' + group_artifact + ', using default') |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 350 | continue |
| 351 | |
| 352 | # Store the latest version. |
| 353 | version = LooseVersion(version) |
| 354 | if key not in maven_lib_info \ |
| 355 | or version > maven_lib_info[key].version: |
| 356 | maven_lib_info[key] = MavenLibraryInfo(key, group_id, artifact_id, version, |
| 357 | root, repo_dir, artifact_file) |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 358 | |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 359 | return maven_lib_info |
| 360 | |
| 361 | |
Colin Cross | 59b59db | 2018-04-24 13:58:05 -0700 | [diff] [blame] | 362 | def transform_maven_repos(maven_repo_dirs, transformed_dir, extract_res=True, include_static_deps=True): |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 363 | cwd = os.getcwd() |
| 364 | |
| 365 | # Use a temporary working directory. |
Jeff Gaston | c302bb9 | 2018-03-23 13:53:48 -0400 | [diff] [blame] | 366 | maven_lib_info = detect_artifacts(maven_repo_dirs) |
Jeff Gaston | a68a8d4 | 2018-03-23 14:00:13 -0400 | [diff] [blame] | 367 | working_dir = temp_dir |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 368 | |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 369 | if not maven_lib_info: |
| 370 | print_e('Failed to detect artifacts') |
| 371 | return False |
| 372 | |
Jeff Gaston | c302bb9 | 2018-03-23 13:53:48 -0400 | [diff] [blame] | 373 | # extract some files (for example, AndroidManifest.xml) from any relevant artifacts |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 374 | for info in maven_lib_info.values(): |
Alan Viverette | d8ce722 | 2017-12-11 17:24:43 -0500 | [diff] [blame] | 375 | transform_maven_lib(working_dir, info, extract_res) |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 376 | |
Colin Cross | 74683bc | 2018-04-11 17:36:18 -0700 | [diff] [blame] | 377 | # generate a single Android.bp that specifies to use all of the above artifacts |
| 378 | makefile = os.path.join(working_dir, 'Android.bp') |
Alan Viverette | 4ec9a17 | 2018-02-20 16:19:31 -0500 | [diff] [blame] | 379 | with open(makefile, 'w') as f: |
Anton Hansson | bd2021c | 2021-04-06 19:21:34 +0000 | [diff] [blame] | 380 | args = ["pom2bp"] |
Aurimas Liutikas | 6e87bbf | 2021-07-30 10:04:05 -0700 | [diff] [blame] | 381 | args.extend(["-sdk-version", "31"]) |
Anton Hansson | bd2021c | 2021-04-06 19:21:34 +0000 | [diff] [blame] | 382 | args.extend(["-default-min-sdk-version", "24"]) |
Jeff Gaston | 1cc0609 | 2018-03-28 15:51:02 -0400 | [diff] [blame] | 383 | if include_static_deps: |
| 384 | args.append("-static-deps") |
Jeff Gaston | 54868ee | 2018-04-25 19:43:35 -0400 | [diff] [blame] | 385 | rewriteNames = sorted([name for name in maven_to_make if ":" in name] + [name for name in maven_to_make if ":" not in name]) |
Jeff Gaston | a0bce60 | 2018-08-24 14:05:03 -0400 | [diff] [blame] | 386 | args.extend(["-rewrite=^" + name + "$=" + maven_to_make[name]['name'] for name in rewriteNames]) |
Colin Cross | 5542fc2 | 2021-04-14 11:36:46 -0700 | [diff] [blame] | 387 | args.extend(["-rewrite=^auto-common$=auto_common"]) |
| 388 | args.extend(["-rewrite=^auto-value-annotations$=auto_value_annotations"]) |
Aurimas Liutikas | 6e87bbf | 2021-07-30 10:04:05 -0700 | [diff] [blame] | 389 | args.extend(["-rewrite=^com.google.auto.value:auto-value$=auto_value_plugin"]) |
Dustin Lam | da15cd4 | 2020-04-01 19:06:23 -0700 | [diff] [blame] | 390 | args.extend(["-rewrite=^monitor$=androidx.test.monitor"]) |
| 391 | args.extend(["-rewrite=^rules$=androidx.test.rules"]) |
| 392 | args.extend(["-rewrite=^runner$=androidx.test.runner"]) |
Aurimas Liutikas | 6e87bbf | 2021-07-30 10:04:05 -0700 | [diff] [blame] | 393 | args.extend(["-rewrite=^androidx.test:core$=androidx.test.core"]) |
Yiqun Wu | 9e020fe | 2020-11-18 21:16:08 +0000 | [diff] [blame] | 394 | args.extend(["-rewrite=^com.squareup:javapoet$=javapoet"]) |
Aurimas Liutikas | d912476 | 2018-09-28 15:31:35 -0700 | [diff] [blame] | 395 | args.extend(["-rewrite=^com.google.guava:listenablefuture$=guava-listenablefuture-prebuilt-jar"]) |
Tony Mak | 0f65875 | 2019-07-19 11:11:05 +0100 | [diff] [blame] | 396 | args.extend(["-rewrite=^sqlite-jdbc$=xerial-sqlite-jdbc"]) |
Tony Mak | 0f65875 | 2019-07-19 11:11:05 +0100 | [diff] [blame] | 397 | args.extend(["-rewrite=^gson$=gson-prebuilt-jar"]) |
Sunny Goyal | 6667ddb | 2020-03-03 15:15:54 -0800 | [diff] [blame] | 398 | args.extend(["-rewrite=^com.intellij:annotations$=jetbrains-annotations"]) |
Aurimas Liutikas | 6e87bbf | 2021-07-30 10:04:05 -0700 | [diff] [blame] | 399 | args.extend(["-rewrite=^javax.annotation:javax.annotation-api$=javax-annotation-api-prebuilt-host-jar"]) |
| 400 | args.extend(["-rewrite=^org.robolectric:robolectric$=Robolectric_all-target"]) |
Alan Viverette | f44e2f9 | 2021-08-31 17:26:26 +0000 | [diff] [blame] | 401 | args.extend(["-rewrite=^org.jetbrains.kotlin:kotlin-stdlib-common$=kotlin-stdlib"]) |
Aurimas Liutikas | 6e87bbf | 2021-07-30 10:04:05 -0700 | [diff] [blame] | 402 | args.extend(["-rewrite=^org.jetbrains.kotlinx:kotlinx-coroutines-core$=kotlinx_coroutines"]) |
| 403 | args.extend(["-rewrite=^org.jetbrains.kotlinx:kotlinx-coroutines-android$=kotlinx_coroutines_android"]) |
| 404 | args.extend(["-rewrite=^org.jetbrains.kotlinx:kotlinx-metadata-jvm$=kotlinx_metadata_jvm"]) |
Sunny Goyal | 6667ddb | 2020-03-03 15:15:54 -0800 | [diff] [blame] | 405 | args.extend(["-extra-static-libs=androidx.room_room-compiler=guava-21.0"]) |
Jeff Gaston | 07a3cf7 | 2018-08-24 14:16:34 -0400 | [diff] [blame] | 406 | args.extend(["-host=" + name for name in maven_to_make if maven_to_make[name].get('host')]) |
Tony Mak | 0f65875 | 2019-07-19 11:11:05 +0100 | [diff] [blame] | 407 | args.extend(["-host-and-device=" + name for name in maven_to_make if maven_to_make[name].get('host_and_device')]) |
Colin Cross | 2106007 | 2018-04-24 13:52:29 -0700 | [diff] [blame] | 408 | # these depend on GSON which is not in AOSP |
Tony Mak | 0f65875 | 2019-07-19 11:11:05 +0100 | [diff] [blame] | 409 | args.extend(["-exclude=android-arch-room-migration", |
Colin Cross | 2106007 | 2018-04-24 13:52:29 -0700 | [diff] [blame] | 410 | "-exclude=android-arch-room-testing"]) |
Jeff Gaston | 7ec1d8f | 2018-03-27 00:25:12 -0400 | [diff] [blame] | 411 | args.extend(["."]) |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 412 | subprocess.check_call(args, stdout=f, cwd=working_dir) |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 413 | |
| 414 | # Replace the old directory. |
Jeff Gaston | c302bb9 | 2018-03-23 13:53:48 -0400 | [diff] [blame] | 415 | output_dir = os.path.join(cwd, transformed_dir) |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 416 | mv(working_dir, output_dir) |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 417 | return True |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 418 | |
Jeff Gaston | c302bb9 | 2018-03-23 13:53:48 -0400 | [diff] [blame] | 419 | # moves <artifact_info> (of type MavenLibraryInfo) into the appropriate part of <working_dir> , and possibly unpacks any necessary included files |
Alan Viverette | d8ce722 | 2017-12-11 17:24:43 -0500 | [diff] [blame] | 420 | def transform_maven_lib(working_dir, artifact_info, extract_res): |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 421 | # Move library into working dir |
Jeff Gaston | 9edf86c | 2018-04-18 13:45:23 -0400 | [diff] [blame] | 422 | new_dir = os.path.normpath(os.path.join(working_dir, os.path.relpath(artifact_info.dir, artifact_info.repo_dir))) |
Jeff Gaston | c302bb9 | 2018-03-23 13:53:48 -0400 | [diff] [blame] | 423 | mv(artifact_info.dir, new_dir) |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 424 | |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 425 | matcher = artifact_pattern.match(artifact_info.file) |
| 426 | maven_lib_name = artifact_info.key |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 427 | maven_lib_vers = matcher.group(2) |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 428 | maven_lib_type = artifact_info.file[-3:] |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 429 | |
Alan Viverette | f3c1272 | 2021-08-30 19:50:33 +0000 | [diff] [blame] | 430 | group_artifact = artifact_info.key |
| 431 | make_lib_name = maven_to_make[group_artifact]['name'] |
| 432 | make_dir_name = maven_to_make[group_artifact]['path'] |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 433 | |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 434 | artifact_file = os.path.join(new_dir, artifact_info.file) |
| 435 | |
Colin Cross | 59b59db | 2018-04-24 13:58:05 -0700 | [diff] [blame] | 436 | if maven_lib_type == "aar": |
| 437 | if extract_res: |
| 438 | target_dir = os.path.join(working_dir, make_dir_name) |
| 439 | if not os.path.exists(target_dir): |
| 440 | os.makedirs(target_dir) |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 441 | |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 442 | process_aar(artifact_file, target_dir) |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 443 | |
Colin Cross | 59b59db | 2018-04-24 13:58:05 -0700 | [diff] [blame] | 444 | with zipfile.ZipFile(artifact_file) as zip: |
| 445 | manifests_dir = os.path.join(working_dir, "manifests") |
| 446 | zip.extract("AndroidManifest.xml", os.path.join(manifests_dir, make_lib_name)) |
Dan Willemsen | d677b60 | 2017-11-08 22:13:17 -0800 | [diff] [blame] | 447 | |
Alan Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 448 | print(maven_lib_vers, ":", maven_lib_name, "->", make_lib_name) |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 449 | |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 450 | |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 451 | def process_aar(artifact_file, target_dir): |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 452 | # Extract AAR file to target_dir. |
| 453 | with zipfile.ZipFile(artifact_file) as zip: |
| 454 | zip.extractall(target_dir) |
| 455 | |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 456 | # Remove classes.jar |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 457 | classes_jar = os.path.join(target_dir, "classes.jar") |
| 458 | if os.path.exists(classes_jar): |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 459 | os.remove(classes_jar) |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 460 | |
| 461 | # Remove or preserve empty dirs. |
| 462 | for root, dirs, files in os.walk(target_dir): |
| 463 | for dir in dirs: |
| 464 | dir_path = os.path.join(root, dir) |
| 465 | if not os.listdir(dir_path): |
| 466 | os.rmdir(dir_path) |
| 467 | |
| 468 | # Remove top-level cruft. |
| 469 | for file in blacklist_files: |
| 470 | file_path = os.path.join(target_dir, file) |
| 471 | if os.path.exists(file_path): |
| 472 | os.remove(file_path) |
| 473 | |
Alan Viverette | f17c940 | 2017-07-19 12:57:40 -0400 | [diff] [blame] | 474 | |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 475 | def fetch_artifact(target, build_id, artifact_path): |
Jeff Sharkey | abe16df | 2021-05-25 10:09:03 -0600 | [diff] [blame] | 476 | global args |
Jiyong Park | 1d1c963 | 2018-05-29 17:45:27 +0900 | [diff] [blame] | 477 | download_to = os.path.join('.', os.path.dirname(artifact_path)) |
| 478 | print('Fetching %s from %s ...' % (artifact_path, target)) |
| 479 | if not os.path.exists(download_to): |
| 480 | os.makedirs(download_to) |
Jeff Sharkey | abe16df | 2021-05-25 10:09:03 -0600 | [diff] [blame] | 481 | if args.beyond_corp: |
| 482 | fetch_cmd = [FETCH_ARTIFACT_BEYOND_CORP, '--use_oauth2', |
| 483 | '--bid', str(build_id), '--target', target, artifact_path, download_to] |
| 484 | else: |
| 485 | fetch_cmd = [FETCH_ARTIFACT, |
| 486 | '--bid', str(build_id), '--target', target, artifact_path, download_to] |
Jeff Gaston | 97a9b76 | 2018-10-02 15:15:12 -0400 | [diff] [blame] | 487 | print("Running: " + ' '.join(fetch_cmd)) |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 488 | try: |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 489 | subprocess.check_output(fetch_cmd, stderr=subprocess.STDOUT) |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 490 | except subprocess.CalledProcessError: |
Jeff Gaston | 13e3841 | 2018-02-06 14:45:36 -0500 | [diff] [blame] | 491 | print_e('FAIL: Unable to retrieve %s artifact for build ID %s' % (artifact_path, build_id)) |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 492 | print_e('Please make sure you are authenticated for build server access!') |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 493 | return None |
| 494 | return artifact_path |
| 495 | |
| 496 | |
Anton Hansson | 1d01a03 | 2018-04-09 10:29:37 +0100 | [diff] [blame] | 497 | def fetch_artifacts(target, build_id, artifact_dict): |
| 498 | for artifact, target_path in artifact_dict.items(): |
| 499 | artifact_path = fetch_artifact(target, build_id.url_id, artifact) |
| 500 | if not artifact_path: |
| 501 | return False |
| 502 | mv(artifact_path, target_path) |
| 503 | return True |
| 504 | |
| 505 | |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 506 | def extract_artifact(artifact_path): |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 507 | # Unzip the repo archive into a separate directory. |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 508 | repo_dir = os.path.basename(artifact_path)[:-4] |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 509 | with zipfile.ZipFile(artifact_path) as zipFile: |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 510 | zipFile.extractall(repo_dir) |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 511 | return repo_dir |
| 512 | |
| 513 | |
Alan Viverette | 7e897e2 | 2018-03-09 15:24:10 -0500 | [diff] [blame] | 514 | def fetch_and_extract(target, build_id, file, artifact_path=None): |
| 515 | if not artifact_path: |
| 516 | artifact_path = fetch_artifact(target, build_id, file) |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 517 | if not artifact_path: |
| 518 | return None |
| 519 | return extract_artifact(artifact_path) |
| 520 | |
| 521 | |
Jeff Gaston | 08a2ee4 | 2018-05-07 18:08:41 -0400 | [diff] [blame] | 522 | def update_androidx(target, build_id, local_file): |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 523 | if build_id: |
Anthony Chen | acbb487 | 2018-07-02 11:22:48 -0700 | [diff] [blame] | 524 | repo_file = 'top-of-tree-m2repository-all-%s.zip' % build_id.fs_id |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 525 | repo_dir = fetch_and_extract(target, build_id.url_id, repo_file, None) |
| 526 | else: |
| 527 | repo_dir = fetch_and_extract(target, None, None, local_file) |
| 528 | if not repo_dir: |
| 529 | print_e('Failed to extract AndroidX repository') |
| 530 | return False |
| 531 | |
Tony Mak | 0f65875 | 2019-07-19 11:11:05 +0100 | [diff] [blame] | 532 | # Keep JavaPlugins.bp file untounched. |
| 533 | java_plugins_bp_path = os.path.join(androidx_dir, 'JavaPlugins.bp') |
| 534 | tmp_java_plugins_bp_path = os.path.join('/tmp', 'JavaPlugins.bp') |
| 535 | mv(java_plugins_bp_path, tmp_java_plugins_bp_path) |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 536 | |
Tony Mak | 0f65875 | 2019-07-19 11:11:05 +0100 | [diff] [blame] | 537 | # Transform the repo archive into a Makefile-compatible format. |
| 538 | if not transform_maven_repos([repo_dir], androidx_dir, extract_res=False): |
| 539 | return False |
| 540 | |
| 541 | # Import JavaPlugins.bp in Android.bp. |
| 542 | makefile = os.path.join(androidx_dir, 'Android.bp') |
| 543 | with open(makefile, "a+") as f: |
| 544 | f.write('\nbuild = ["JavaPlugins.bp"]\n') |
| 545 | mv(tmp_java_plugins_bp_path, java_plugins_bp_path) |
| 546 | |
| 547 | return True |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 548 | |
Alan Viverette | 6dc4575 | 2020-04-16 14:56:20 +0000 | [diff] [blame] | 549 | |
Jeff Gaston | 782c3e3 | 2018-02-06 14:36:17 -0500 | [diff] [blame] | 550 | def update_jetifier(target, build_id): |
| 551 | repo_file = 'jetifier-standalone.zip' |
| 552 | repo_dir = fetch_and_extract(target, build_id.url_id, repo_file) |
| 553 | if not repo_dir: |
| 554 | print_e('Failed to extract Jetifier') |
| 555 | return False |
| 556 | |
| 557 | rm(jetifier_dir) |
Jeff Gaston | 553a437 | 2018-03-29 18:34:22 -0400 | [diff] [blame] | 558 | mv(os.path.join(repo_dir, 'jetifier-standalone'), jetifier_dir) |
| 559 | os.chmod(os.path.join(jetifier_dir, 'bin', 'jetifier-standalone'), 0o755) |
Jeff Gaston | 782c3e3 | 2018-02-06 14:36:17 -0500 | [diff] [blame] | 560 | return True |
| 561 | |
Alan Viverette | 7e897e2 | 2018-03-09 15:24:10 -0500 | [diff] [blame] | 562 | |
Alan Viverette | 6dc4575 | 2020-04-16 14:56:20 +0000 | [diff] [blame] | 563 | def update_constraint(local_file): |
Jeff Gaston | 9edf86c | 2018-04-18 13:45:23 -0400 | [diff] [blame] | 564 | repo_dir = extract_artifact(local_file) |
| 565 | if not repo_dir: |
Alan Viverette | 6dc4575 | 2020-04-16 14:56:20 +0000 | [diff] [blame] | 566 | print_e('Failed to extract Constraint Layout') |
Jeff Gaston | 9edf86c | 2018-04-18 13:45:23 -0400 | [diff] [blame] | 567 | return False |
| 568 | return transform_maven_repos([repo_dir], os.path.join(extras_dir, 'constraint-layout-x'), extract_res=False) |
| 569 | |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 570 | |
Jeff Gaston | 6e7e750 | 2018-04-04 00:22:45 -0400 | [diff] [blame] | 571 | def update_material(file): |
| 572 | design_dir = extract_artifact(file) |
| 573 | if not design_dir: |
Alan Viverette | 6dc4575 | 2020-04-16 14:56:20 +0000 | [diff] [blame] | 574 | print_e('Failed to extract Material Design Components') |
Jeff Gaston | 6e7e750 | 2018-04-04 00:22:45 -0400 | [diff] [blame] | 575 | return False |
| 576 | |
| 577 | # Don't bother extracting resources -- this should only be used with AAPT2. |
| 578 | return transform_maven_repos([design_dir], |
| 579 | os.path.join(extras_dir, 'material-design-x'), extract_res=False) |
| 580 | |
| 581 | |
Anton Hansson | 1d01a03 | 2018-04-09 10:29:37 +0100 | [diff] [blame] | 582 | def update_framework(build_id, sdk_dir): |
Anton Hansson | 83f9217 | 2020-03-26 11:12:03 +0000 | [diff] [blame] | 583 | api_scope_list = ['public', 'system', 'test', 'module-lib', 'system-server'] |
Sundong Ahn | 66091f2 | 2018-08-29 18:54:28 +0900 | [diff] [blame] | 584 | if sdk_dir == 'current': |
| 585 | api_scope_list.append('core') |
| 586 | |
| 587 | for api_scope in api_scope_list: |
Jiyong Park | 1d1c963 | 2018-05-29 17:45:27 +0900 | [diff] [blame] | 588 | target_dir = path(sdk_dir, api_scope) |
Sundong Ahn | 66091f2 | 2018-08-29 18:54:28 +0900 | [diff] [blame] | 589 | if api_scope == 'core': |
| 590 | artifact_to_path = {'core.current.stubs.jar': path(target_dir, 'android.jar')} |
| 591 | else: |
| 592 | artifact_to_path = {'apistubs/android/' + api_scope + '/*.jar': path(target_dir, '*')} |
Anton Hansson | 1d01a03 | 2018-04-09 10:29:37 +0100 | [diff] [blame] | 593 | |
| 594 | if not fetch_artifacts(framework_sdk_target, build_id, artifact_to_path): |
| 595 | return False |
| 596 | |
Jiyong Park | 1d1c963 | 2018-05-29 17:45:27 +0900 | [diff] [blame] | 597 | if api_scope == 'public': |
Anton Hansson | 1d01a03 | 2018-04-09 10:29:37 +0100 | [diff] [blame] | 598 | # Fetch a few artifacts from the public sdk. |
Sundong Ahn | 66091f2 | 2018-08-29 18:54:28 +0900 | [diff] [blame] | 599 | artifact = 'sdk-repo-linux-platforms-%s.zip' % build_id.fs_id |
Anton Hansson | 1d01a03 | 2018-04-09 10:29:37 +0100 | [diff] [blame] | 600 | artifact_path = fetch_artifact(framework_sdk_target, build_id.url_id, artifact) |
Anton Hansson | 9709fd4 | 2018-04-03 16:52:13 +0100 | [diff] [blame] | 601 | if not artifact_path: |
| 602 | return False |
Anton Hansson | 1d01a03 | 2018-04-09 10:29:37 +0100 | [diff] [blame] | 603 | |
| 604 | with zipfile.ZipFile(artifact_path) as zipFile: |
Colin Cross | d338d70 | 2020-07-10 19:17:54 -0700 | [diff] [blame] | 605 | extra_files = [ |
| 606 | 'android.jar', |
| 607 | 'framework.aidl', |
| 608 | 'uiautomator.jar', |
| 609 | 'core-for-system-modules.jar', |
| 610 | 'data/annotations.zip', |
| 611 | 'data/api-versions.xml'] |
| 612 | for filename in extra_files: |
Anton Hansson | a26e481 | 2020-03-25 12:54:39 +0000 | [diff] [blame] | 613 | matches = list(filter(lambda path: filename in path, zipFile.namelist())) |
| 614 | if len(matches) != 1: |
| 615 | print_e('Expected 1 file named \'%s\' in zip %s, found %d' % |
| 616 | (filename, zipFile.filename, len(matches))) |
| 617 | return False |
| 618 | zip_path = matches[0] |
| 619 | src_path = zipFile.extract(zip_path) |
| 620 | dst_path = path(target_dir, filename) |
| 621 | mv(src_path, dst_path) |
Anton Hansson | 9709fd4 | 2018-04-03 16:52:13 +0100 | [diff] [blame] | 622 | |
Anton Hansson | 73be151 | 2021-06-24 10:56:05 +0100 | [diff] [blame] | 623 | # Filtered API DB is currently only available for "public" |
| 624 | fetch_artifacts(framework_sdk_target, build_id, {'api-versions-public-filtered.xml': path(target_dir, 'data/api-versions-filtered.xml')}) |
| 625 | |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 626 | return True |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 627 | |
Sundong Ahn | cc34cc3 | 2018-07-11 15:18:47 +0900 | [diff] [blame] | 628 | def update_makefile(build_id): |
| 629 | template = '"%s",\n\ |
| 630 | "current"' |
| 631 | makefile = os.path.join(git_dir, 'Android.bp') |
| 632 | |
| 633 | with open(makefile, 'r+') as f: |
| 634 | contents = f.read().replace('"current"', template % build_id) |
| 635 | f.seek(0) |
| 636 | f.write(contents) |
| 637 | |
| 638 | return True |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 639 | |
Anton Hansson | 1d01a03 | 2018-04-09 10:29:37 +0100 | [diff] [blame] | 640 | def finalize_sdk(build_id, sdk_version): |
| 641 | target_finalize_dir = '%d' % sdk_version |
Anton Hansson | 9709fd4 | 2018-04-03 16:52:13 +0100 | [diff] [blame] | 642 | |
Anton Hansson | aa554c0 | 2020-04-30 14:06:20 +0100 | [diff] [blame] | 643 | for api_scope in ['public', 'system', 'test', 'module-lib', 'system-server']: |
Sundong Ahn | 66091f2 | 2018-08-29 18:54:28 +0900 | [diff] [blame] | 644 | artifact_to_path = {'apistubs/android/' + api_scope + '/api/*.txt': |
| 645 | path(target_finalize_dir, api_scope, 'api', '*')} |
| 646 | |
| 647 | if not fetch_artifacts(framework_sdk_target, build_id, artifact_to_path): |
| 648 | return False |
| 649 | |
| 650 | return update_framework(build_id, target_finalize_dir) \ |
Sundong Ahn | cc34cc3 | 2018-07-11 15:18:47 +0900 | [diff] [blame] | 651 | and update_makefile(target_finalize_dir) |
Anton Hansson | 9709fd4 | 2018-04-03 16:52:13 +0100 | [diff] [blame] | 652 | |
Anton Hansson | 9709fd4 | 2018-04-03 16:52:13 +0100 | [diff] [blame] | 653 | |
Anton Hansson | 1d01a03 | 2018-04-09 10:29:37 +0100 | [diff] [blame] | 654 | def update_framework_current(build_id): |
| 655 | return update_framework(build_id, current_path) |
Anton Hansson | 9709fd4 | 2018-04-03 16:52:13 +0100 | [diff] [blame] | 656 | |
| 657 | |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 658 | def update_buildtools(target, arch, build_id): |
Jeff Gaston | 13e3841 | 2018-02-06 14:45:36 -0500 | [diff] [blame] | 659 | artifact_path = fetch_and_extract(target, build_id.url_id, |
| 660 | "sdk-repo-%s-build-tools-%s.zip" % (arch, build_id.fs_id)) |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 661 | if not artifact_path: |
| 662 | return False |
| 663 | |
| 664 | top_level_dir = os.listdir(artifact_path)[0] |
| 665 | src_path = os.path.join(artifact_path, top_level_dir) |
| 666 | dst_path = path(buildtools_dir, arch) |
Colin Cross | 20648d3 | 2021-02-12 13:30:51 -0800 | [diff] [blame] | 667 | |
| 668 | # There are a few libraries that have been manually added to the |
| 669 | # build tools, copy them from the destination back to the source |
| 670 | # before the destination is overwritten. |
| 671 | files_to_save = ( |
| 672 | 'lib64/libconscrypt_openjdk_jni.dylib', |
| 673 | 'lib64/libconscrypt_openjdk_jni.so', |
| 674 | 'bin/lib64/libwinpthread-1.dll', |
| 675 | ) |
| 676 | for file in files_to_save: |
| 677 | src_file = os.path.join(dst_path, file) |
| 678 | dst_file = os.path.join(src_path, file) |
| 679 | if os.path.exists(dst_path): |
| 680 | mv(src_file, dst_file) |
| 681 | |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 682 | mv(src_path, dst_path) |
| 683 | |
| 684 | # Move all top-level files to /bin and make them executable |
| 685 | bin_path = path(dst_path, 'bin') |
| 686 | top_level_files = filter(lambda e: os.path.isfile(path(dst_path, e)), os.listdir(dst_path)) |
| 687 | for file in top_level_files: |
| 688 | src_file = path(dst_path, file) |
| 689 | dst_file = path(bin_path, file) |
| 690 | mv(src_file, dst_file) |
| 691 | os.chmod(dst_file, 0o755) |
| 692 | |
Colin Cross | 6673ceb | 2021-02-12 13:14:14 -0800 | [diff] [blame] | 693 | # Make the files under lld-bin executable |
| 694 | lld_bin_files = os.listdir(os.path.join(dst_path, 'lld-bin')) |
| 695 | for file in lld_bin_files: |
| 696 | os.chmod(os.path.join(dst_path, 'lld-bin', file), 0o755) |
| 697 | |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 698 | # Remove renderscript |
| 699 | rm(path(dst_path, 'renderscript')) |
| 700 | |
| 701 | return True |
| 702 | |
| 703 | |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 704 | def append(text, more_text): |
| 705 | if text: |
| 706 | return "%s, %s" % (text, more_text) |
| 707 | return more_text |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 708 | |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 709 | |
Jeff Gaston | 13e3841 | 2018-02-06 14:45:36 -0500 | [diff] [blame] | 710 | class buildId(object): |
| 711 | def __init__(self, url_id, fs_id): |
| 712 | # id when used in build server urls |
| 713 | self.url_id = url_id |
| 714 | # id when used in build commands |
| 715 | self.fs_id = fs_id |
| 716 | |
Jeff Gaston | b9b0905 | 2018-02-05 14:16:05 -0500 | [diff] [blame] | 717 | def getBuildId(args): |
Jeff Gaston | 13e3841 | 2018-02-06 14:45:36 -0500 | [diff] [blame] | 718 | # must be in the format 12345 or P12345 |
Jeff Gaston | b9b0905 | 2018-02-05 14:16:05 -0500 | [diff] [blame] | 719 | source = args.source |
Jeff Gaston | 13e3841 | 2018-02-06 14:45:36 -0500 | [diff] [blame] | 720 | number_text = source[:] |
| 721 | presubmit = False |
| 722 | if number_text.startswith("P"): |
| 723 | presubmit = True |
| 724 | number_text = number_text[1:] |
| 725 | if not number_text.isnumeric(): |
Alan Viverette | 7e897e2 | 2018-03-09 15:24:10 -0500 | [diff] [blame] | 726 | return None |
Jeff Gaston | 13e3841 | 2018-02-06 14:45:36 -0500 | [diff] [blame] | 727 | url_id = source |
| 728 | fs_id = url_id |
| 729 | if presubmit: |
| 730 | fs_id = "0" |
| 731 | args.file = False |
| 732 | return buildId(url_id, fs_id) |
Jeff Gaston | b9b0905 | 2018-02-05 14:16:05 -0500 | [diff] [blame] | 733 | |
Colin Cross | 573e121 | 2018-02-12 14:59:52 -0800 | [diff] [blame] | 734 | def getFile(args): |
| 735 | source = args.source |
| 736 | if not source.isnumeric(): |
| 737 | return args.source |
Alan Viverette | 7e897e2 | 2018-03-09 15:24:10 -0500 | [diff] [blame] | 738 | return None |
Colin Cross | 573e121 | 2018-02-12 14:59:52 -0800 | [diff] [blame] | 739 | |
Alan Viverette | 4ec9a17 | 2018-02-20 16:19:31 -0500 | [diff] [blame] | 740 | |
| 741 | def script_relative(rel_path): |
Jeff Gaston | a68a8d4 | 2018-03-23 14:00:13 -0400 | [diff] [blame] | 742 | return os.path.join(script_dir, rel_path) |
Alan Viverette | 4ec9a17 | 2018-02-20 16:19:31 -0500 | [diff] [blame] | 743 | |
| 744 | |
Jeff Gaston | cc296a8 | 2018-03-23 14:33:24 -0400 | [diff] [blame] | 745 | def uncommittedChangesExist(): |
| 746 | try: |
| 747 | # Make sure we don't overwrite any pending changes. |
| 748 | diffCommand = "cd " + git_dir + " && git diff --quiet" |
| 749 | subprocess.check_call(diffCommand, shell=True) |
| 750 | subprocess.check_call(diffCommand + " --cached", shell=True) |
| 751 | return False |
| 752 | except subprocess.CalledProcessError: |
| 753 | return True |
| 754 | |
| 755 | |
Jeff Gaston | a7fba9b | 2018-03-26 23:48:51 -0400 | [diff] [blame] | 756 | rm(temp_dir) |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 757 | parser = argparse.ArgumentParser( |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 758 | description=('Update current prebuilts')) |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 759 | parser.add_argument( |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 760 | 'source', |
| 761 | help='Build server build ID or local Maven ZIP file') |
| 762 | parser.add_argument( |
Jeff Gaston | 6e7e750 | 2018-04-04 00:22:45 -0400 | [diff] [blame] | 763 | '-m', '--material', action="store_true", |
Alan Viverette | 6dc4575 | 2020-04-16 14:56:20 +0000 | [diff] [blame] | 764 | help='If specified, updates only Material Design Components') |
Jeff Gaston | 6e7e750 | 2018-04-04 00:22:45 -0400 | [diff] [blame] | 765 | parser.add_argument( |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 766 | '-c', '--constraint', action="store_true", |
| 767 | help='If specified, updates only Constraint Layout') |
| 768 | parser.add_argument( |
Jeff Gaston | 782c3e3 | 2018-02-06 14:36:17 -0500 | [diff] [blame] | 769 | '-j', '--jetifier', action="store_true", |
| 770 | help='If specified, updates only Jetifier') |
| 771 | parser.add_argument( |
Alan Viverette | 5bfe05b | 2017-06-06 14:21:29 -0400 | [diff] [blame] | 772 | '-p', '--platform', action="store_true", |
| 773 | help='If specified, updates only the Android Platform') |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 774 | parser.add_argument( |
Anton Hansson | 9709fd4 | 2018-04-03 16:52:13 +0100 | [diff] [blame] | 775 | '-f', '--finalize_sdk', type=int, |
| 776 | help='If specified, imports the source build as the specified finalized SDK version') |
| 777 | parser.add_argument( |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 778 | '-b', '--buildtools', action="store_true", |
| 779 | help='If specified, updates only the Build Tools') |
Jeff Gaston | cc296a8 | 2018-03-23 14:33:24 -0400 | [diff] [blame] | 780 | parser.add_argument( |
Alan Viverette | 6dc4575 | 2020-04-16 14:56:20 +0000 | [diff] [blame] | 781 | '-x', '--androidx', action="store_true", |
| 782 | help='If specified, updates only the Jetpack (androidx) libraries excluding those covered by other arguments') |
Jeff Gaston | 41fd5e6 | 2018-04-25 17:02:02 -0400 | [diff] [blame] | 783 | parser.add_argument( |
Jeff Gaston | cc296a8 | 2018-03-23 14:33:24 -0400 | [diff] [blame] | 784 | '--commit-first', action="store_true", |
| 785 | help='If specified, then if uncommited changes exist, commit before continuing') |
Jeff Sharkey | abe16df | 2021-05-25 10:09:03 -0600 | [diff] [blame] | 786 | parser.add_argument( |
| 787 | '--beyond-corp', action="store_true", |
| 788 | help='If specified, then fetch artifacts with tooling that works on BeyondCorp devices') |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 789 | args = parser.parse_args() |
Jeff Gaston | 56fe276 | 2018-02-06 14:54:37 -0500 | [diff] [blame] | 790 | args.file = True |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 791 | if not args.source: |
| 792 | parser.error("You must specify a build ID or local Maven ZIP file") |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 793 | sys.exit(1) |
Alan Viverette | 6dc4575 | 2020-04-16 14:56:20 +0000 | [diff] [blame] | 794 | if not (args.platform or args.buildtools \ |
| 795 | or args.jetifier or args.androidx or args.material \ |
| 796 | or args.finalize_sdk or args.constraint): |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 797 | parser.error("You must specify at least one target to update") |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 798 | sys.exit(1) |
Alan Viverette | 6dc4575 | 2020-04-16 14:56:20 +0000 | [diff] [blame] | 799 | if (args.constraint or args.material or args.androidx) \ |
Colin Cross | 74683bc | 2018-04-11 17:36:18 -0700 | [diff] [blame] | 800 | and which('pom2bp') is None: |
Louis Pullen-Freilich | 61bb70e | 2019-04-09 16:15:32 +0100 | [diff] [blame] | 801 | 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 Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 802 | sys.exit(1) |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 803 | |
Jeff Gaston | cc296a8 | 2018-03-23 14:33:24 -0400 | [diff] [blame] | 804 | if uncommittedChangesExist(): |
| 805 | if args.commit_first: |
| 806 | subprocess.check_call("cd " + git_dir + " && git add -u", shell=True) |
| 807 | subprocess.check_call("cd " + git_dir + " && git commit -m 'save working state'", shell=True) |
| 808 | |
| 809 | if uncommittedChangesExist(): |
Anton Hansson | 10861a0 | 2018-04-06 13:57:08 +0100 | [diff] [blame] | 810 | 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 Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 811 | sys.exit(1) |
| 812 | |
| 813 | try: |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 814 | components = None |
| 815 | if args.constraint: |
Jeff Gaston | 9edf86c | 2018-04-18 13:45:23 -0400 | [diff] [blame] | 816 | if update_constraint_x(getFile(args)): |
| 817 | components = append(components, 'Constraint Layout X') |
| 818 | else: |
| 819 | print_e('Failed to update Constraint Layout X, aborting...') |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 820 | sys.exit(1) |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 821 | if args.androidx: |
Jeff Gaston | 17ccf8f | 2018-08-29 11:33:19 -0400 | [diff] [blame] | 822 | if update_androidx('androidx', \ |
Jeff Gaston | bbd6bfc | 2018-03-27 17:35:49 -0400 | [diff] [blame] | 823 | getBuildId(args), getFile(args)): |
| 824 | components = append(components, 'AndroidX') |
| 825 | else: |
| 826 | print_e('Failed to update AndroidX, aborting...') |
| 827 | sys.exit(1) |
Jeff Gaston | 782c3e3 | 2018-02-06 14:36:17 -0500 | [diff] [blame] | 828 | if args.jetifier: |
Jeff Gaston | 17ccf8f | 2018-08-29 11:33:19 -0400 | [diff] [blame] | 829 | if update_jetifier('androidx', getBuildId(args)): |
Jeff Gaston | 782c3e3 | 2018-02-06 14:36:17 -0500 | [diff] [blame] | 830 | components = append(components, 'Jetifier') |
| 831 | else: |
| 832 | print_e('Failed to update Jetifier, aborting...') |
| 833 | sys.exit(1) |
Anton Hansson | be15e8c | 2018-04-26 17:35:45 +0100 | [diff] [blame] | 834 | if args.platform or args.finalize_sdk: |
Anton Hansson | 87654c4 | 2018-04-26 15:19:42 +0100 | [diff] [blame] | 835 | if update_framework_current(getBuildId(args)): |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 836 | components = append(components, 'platform SDK') |
| 837 | else: |
Alan Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 838 | print_e('Failed to update platform SDK, aborting...') |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 839 | sys.exit(1) |
Anton Hansson | 9709fd4 | 2018-04-03 16:52:13 +0100 | [diff] [blame] | 840 | if args.finalize_sdk: |
Anton Hansson | be15e8c | 2018-04-26 17:35:45 +0100 | [diff] [blame] | 841 | n = args.finalize_sdk |
| 842 | if finalize_sdk(getBuildId(args), n): |
| 843 | # We commit the finalized dir separately from the current sdk update. |
| 844 | msg = "Import final sdk version %d from build %s" % (n, getBuildId(args).url_id) |
| 845 | subprocess.check_call(['git', 'add', '%d' % n]) |
Sundong Ahn | cc34cc3 | 2018-07-11 15:18:47 +0900 | [diff] [blame] | 846 | subprocess.check_call(['git', 'add', 'Android.bp']) |
Anton Hansson | be15e8c | 2018-04-26 17:35:45 +0100 | [diff] [blame] | 847 | subprocess.check_call(['git', 'commit', '-m', msg]) |
Anton Hansson | 9709fd4 | 2018-04-03 16:52:13 +0100 | [diff] [blame] | 848 | else: |
Anton Hansson | be15e8c | 2018-04-26 17:35:45 +0100 | [diff] [blame] | 849 | print_e('Failed to finalize SDK %d, aborting...' % n) |
Anton Hansson | 9709fd4 | 2018-04-03 16:52:13 +0100 | [diff] [blame] | 850 | sys.exit(1) |
Jeff Gaston | 6e7e750 | 2018-04-04 00:22:45 -0400 | [diff] [blame] | 851 | if args.material: |
| 852 | if update_material(getFile(args)): |
| 853 | components = append(components, 'intermediate-AndroidX Design Library') |
| 854 | else: |
| 855 | print_e('Failed to update intermediate-AndroidX Design Library, aborting...') |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 856 | sys.exit(1) |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 857 | if args.buildtools: |
Jeff Gaston | b9b0905 | 2018-02-05 14:16:05 -0500 | [diff] [blame] | 858 | if update_buildtools('sdk_phone_armv7-sdk_mac', 'darwin', getBuildId(args)) \ |
| 859 | and update_buildtools('sdk_phone_x86_64-sdk', 'linux', getBuildId(args)) \ |
| 860 | and update_buildtools('sdk_phone_armv7-win_sdk', 'windows', getBuildId(args)): |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 861 | components = append(components, 'build tools') |
| 862 | else: |
| 863 | print_e('Failed to update build tools, aborting...') |
| 864 | sys.exit(1) |
Jeff Gaston | b70daa9 | 2018-03-29 20:10:22 -0400 | [diff] [blame] | 865 | |
Jeff Gaston | f12f3ce | 2018-03-23 16:41:24 -0400 | [diff] [blame] | 866 | |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 867 | |
Colin Cross | 941d980 | 2018-05-03 21:37:57 -0700 | [diff] [blame] | 868 | subprocess.check_call(['git', 'add', current_path, buildtools_dir]) |
Colin Cross | 573e121 | 2018-02-12 14:59:52 -0800 | [diff] [blame] | 869 | if not args.source.isnumeric(): |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 870 | src_msg = "local Maven ZIP" |
| 871 | else: |
Jeff Gaston | 13e3841 | 2018-02-06 14:45:36 -0500 | [diff] [blame] | 872 | src_msg = "build %s" % (getBuildId(args).url_id) |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 873 | msg = "Import %s from %s\n\n%s" % (components, src_msg, flatten(sys.argv)) |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 874 | subprocess.check_call(['git', 'commit', '-m', msg]) |
Anton Hansson | be15e8c | 2018-04-26 17:35:45 +0100 | [diff] [blame] | 875 | if args.finalize_sdk: |
| 876 | print('NOTE: Created two commits:') |
| 877 | subprocess.check_call(['git', 'log', '-2', '--oneline']) |
Alan Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 878 | print('Remember to test this change before uploading it to Gerrit!') |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 879 | |
| 880 | finally: |
| 881 | # Revert all stray files, including the downloaded zip. |
| 882 | try: |
| 883 | with open(os.devnull, 'w') as bitbucket: |
| 884 | subprocess.check_call(['git', 'add', '-Af', '.'], stdout=bitbucket) |
| 885 | subprocess.check_call( |
Jeff Gaston | 9edf86c | 2018-04-18 13:45:23 -0400 | [diff] [blame] | 886 | ['git', 'commit', '-m', 'COMMIT TO REVERT - RESET ME!!!', '--allow-empty'], stdout=bitbucket) |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 887 | subprocess.check_call(['git', 'reset', '--hard', 'HEAD~1'], stdout=bitbucket) |
| 888 | except subprocess.CalledProcessError: |
Alan Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 889 | print_e('ERROR: Failed cleaning up, manual cleanup required!!!') |