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 |
| 8 | import subprocess |
Alan Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 9 | from shutil import copyfile, rmtree, which |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 10 | from distutils.version import LooseVersion |
Alan Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 11 | from functools import reduce |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 12 | |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 13 | current_path = 'current' |
| 14 | system_path = 'system_current' |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 15 | support_dir = os.path.join(current_path, 'support') |
| 16 | extras_dir = os.path.join(current_path, 'extras') |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 17 | buildtools_dir = 'tools' |
Jeff Gaston | 13e3841 | 2018-02-06 14:45:36 -0500 | [diff] [blame] | 18 | jetifier_dir = os.path.join(buildtools_dir, 'jetifier') |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 19 | |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 20 | # See go/fetch_artifact for details on this script. |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 21 | FETCH_ARTIFACT = '/google/data/ro/projects/android/fetch_artifact' |
| 22 | |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 23 | maven_to_make = { |
Alan Viverette | 7e897e2 | 2018-03-09 15:24:10 -0500 | [diff] [blame] | 24 | 'animated-vector-drawable': ['android-support-animatedvectordrawable', 'graphics/drawable'], |
| 25 | 'appcompat-v7': ['android-support-v7-appcompat', 'v7/appcompat'], |
| 26 | 'cardview-v7': ['android-support-v7-cardview', 'v7/cardview'], |
| 27 | 'collections': ['android-support-collections', 'collections'], |
| 28 | 'customtabs': ['android-support-customtabs', 'customtabs'], |
| 29 | 'exifinterface': ['android-support-exifinterface', 'exifinterface'], |
| 30 | 'gridlayout-v7': ['android-support-v7-gridlayout', 'v7/gridlayout'], |
| 31 | 'leanback-v17': ['android-support-v17-leanback', 'v17/leanback'], |
| 32 | 'mediarouter-v7': ['android-support-v7-mediarouter', 'v7/mediarouter'], |
| 33 | 'palette-v7': ['android-support-v7-palette', 'v7/palette'], |
| 34 | 'percent': ['android-support-percent', 'percent'], |
| 35 | 'preference-leanback-v17': ['android-support-v17-preference-leanback', 'v17/preference-leanback'], |
| 36 | 'preference-v14': ['android-support-v14-preference', 'v14/preference'], |
| 37 | 'preference-v7': ['android-support-v7-preference', 'v7/preference'], |
| 38 | 'recommendation': ['android-support-recommendation', 'recommendation'], |
| 39 | 'recyclerview-v7': ['android-support-v7-recyclerview', 'v7/recyclerview'], |
| 40 | 'support-annotations': ['android-support-annotations', 'annotations', 'jar'], |
| 41 | 'support-compat': ['android-support-compat', 'compat'], |
| 42 | 'support-core-ui': ['android-support-core-ui', 'core-ui'], |
| 43 | 'support-core-utils': ['android-support-core-utils', 'core-utils'], |
| 44 | 'support-dynamic-animation': ['android-support-dynamic-animation', 'dynamic-animation'], |
| 45 | 'support-emoji-appcompat': ['android-support-emoji-appcompat', 'emoji-appcompat'], |
| 46 | 'support-emoji-bundled': ['android-support-emoji-bundled', 'emoji-bundled'], |
| 47 | 'support-emoji': ['android-support-emoji', 'emoji'], |
| 48 | 'support-fragment': ['android-support-fragment', 'fragment'], |
| 49 | 'support-media-compat': ['android-support-media-compat', 'media-compat'], |
| 50 | 'support-tv-provider': ['android-support-tv-provider', 'tv-provider'], |
| 51 | 'support-v13': ['android-support-v13', 'v13'], |
| 52 | 'support-v4': ['android-support-v4', 'v4'], |
| 53 | 'support-vector-drawable': ['android-support-vectordrawable', 'graphics/drawable'], |
| 54 | 'transition': ['android-support-transition', 'transition'], |
| 55 | 'wear': ['android-support-wear', 'wear'], |
Alan Viverette | 7bb86da | 2018-02-21 18:29:02 -0500 | [diff] [blame] | 56 | |
Alan Viverette | 7e897e2 | 2018-03-09 15:24:10 -0500 | [diff] [blame] | 57 | # AndroidX renamed modules |
| 58 | 'androidx.annotation:annotation': ['android-support-annotations', 'annotations', 'jar'], |
| 59 | 'androidx.appcompat:appcompat': ['android-support-v7-appcompat', 'v7/appcompat'], |
| 60 | 'androidx.browser:browser': ['android-support-customtabs', 'customtabs'], |
| 61 | 'androidx.cardview:cardview': ['android-support-v7-cardview', 'v7/cardview'], |
| 62 | 'androidx.collection:collection': ['android-support-collections', 'collections'], |
| 63 | 'androidx.core:core': ['android-support-compat', 'compat'], |
| 64 | 'androidx.dynamicanimation:dynamicanimation': ['android-support-dynamic-animation', 'dynamic-animation'], |
| 65 | 'androidx.emoji:emoji-appcompat': ['android-support-emoji-appcompat', 'emoji-appcompat'], |
| 66 | 'androidx.emoji:emoji-bundled': ['android-support-emoji-bundled', 'emoji-bundled'], |
| 67 | 'androidx.emoji:emoji': ['android-support-emoji', 'emoji'], |
| 68 | 'androidx.fragment:fragment': ['android-support-fragment', 'fragment'], |
| 69 | 'androidx.gridlayout:gridlayout': ['android-support-v7-gridlayout', 'v7/gridlayout'], |
| 70 | 'androidx.leanback:leanback-preference': ['android-support-v17-preference-leanback', 'v17/preference-leanback'], |
| 71 | 'androidx.leanback:leanback': ['android-support-v17-leanback', 'v17/leanback'], |
| 72 | 'androidx.legacy:legacy-preference-v14': ['android-support-v14-preference', 'v14/preference'], |
| 73 | 'androidx.legacy:legacy-support-core-ui': ['android-support-core-ui', 'core-ui'], |
| 74 | 'androidx.legacy:legacy-support-core-utils': ['android-support-core-utils', 'core-utils'], |
| 75 | 'androidx.legacy:legacy-support-v13': ['android-support-v13', 'v13'], |
| 76 | 'androidx.legacy:legacy-support-v4': ['android-support-v4', 'v4'], |
| 77 | 'androidx.media:media': ['android-support-media-compat', 'media-compat'], |
| 78 | 'androidx.mediarouter:mediarouter': ['android-support-v7-mediarouter', 'v7/mediarouter'], |
| 79 | 'androidx.palette:palette': ['android-support-v7-palette', 'v7/palette'], |
| 80 | 'androidx.percentlayout:percentlayout': ['android-support-percent', 'percent'], |
| 81 | 'androidx.preference:preference': ['android-support-v7-preference', 'v7/preference'], |
| 82 | 'androidx.recyclerview:recyclerview': ['android-support-v7-recyclerview', 'v7/recyclerview'], |
| 83 | 'androidx.tvprovider:tvprovider': ['android-support-tv-provider', 'tv-provider'], |
| 84 | 'androidx.vectordrawable:vectordrawable-animated': ['android-support-animatedvectordrawable', 'graphics/drawable'], |
| 85 | 'androidx.vectordrawable:vectordrawable': ['android-support-vectordrawable', 'graphics/drawable'], |
| 86 | |
| 87 | # AndroidX new modules |
| 88 | 'heifwriter': ['android-support-heifwriter', 'heifwriter'], |
| 89 | 'webkit': ['android-support-webkit', 'webkit'], |
| 90 | 'customview': ['android-support-customview', 'customview'], |
| 91 | 'textclassifier': ['android-support-textclassifier', 'textclassifier'], |
| 92 | 'swiperefreshlayout': ['android-support-swiperefreshlayout', 'swiperefreshlayout'], |
| 93 | 'viewpager': ['android-support-viewpager', 'viewpager'], |
| 94 | 'coordinatorlayout': ['android-support-coordinatorlayout', 'coordinatorlayout'], |
| 95 | 'asynclayoutinflater': ['android-support-asynclayoutinflater', 'asynclayoutinflater'], |
| 96 | 'support-content': ['android-support-support-content', 'support-content'], |
| 97 | 'documentfile': ['android-support-documentfile', 'documentfile'], |
| 98 | 'drawerlayout': ['android-support-drawerlayout', 'drawerlayout'], |
| 99 | 'localbroadcastmanager': ['android-support-localbroadcastmanager', 'localbroadcastmanager'], |
| 100 | 'print': ['android-support-print', 'print'], |
| 101 | 'slidingpanelayout': ['android-support-slidingpanelayout', 'slidingpanelayout'], |
| 102 | 'interpolator': ['android-support-interpolator', 'interpolator'], |
| 103 | 'cursoradapter': ['android-support-cursoradapter', 'cursoradapter'], |
| 104 | 'loader': ['android-support-loader', 'loader'], |
| 105 | 'contentpaging': ['android-support-contentpaging', 'contentpaging'], |
| 106 | 'recyclerview-selection': ['android-support-recyclerview-selection', 'recyclerview-selection'], |
Alan Viverette | 4ec9a17 | 2018-02-20 16:19:31 -0500 | [diff] [blame^] | 107 | 'car': ['android-support-car', 'car'], |
Alan Viverette | 7bb86da | 2018-02-21 18:29:02 -0500 | [diff] [blame] | 108 | |
Alan Viverette | 19ecd50 | 2018-01-05 13:52:16 -0500 | [diff] [blame] | 109 | # Slices |
| 110 | 'slices-core': ['android-slices-core', 'slices-core'], |
| 111 | 'slices-view': ['android-slices-view', 'slices-view'], |
| 112 | 'slices-builders': ['android-slices-builders', 'slices-builders'], |
| 113 | |
| 114 | # Multidex |
| 115 | 'multidex': ['android-support-multidex', 'multidex/library'], |
| 116 | 'multidex-instrumentation': ['android-support-multidex-instrumentation', 'multidex/instrumentation'], |
| 117 | |
| 118 | # Constraint Layout |
| 119 | 'constraint-layout': ['android-support-constraint-layout', 'constraint-layout'], |
| 120 | 'constraint-layout-solver': ['android-support-constraint-layout-solver', 'constraint-layout-solver'], |
| 121 | |
| 122 | # App Arch Core |
| 123 | 'android.arch.core:runtime': ['android-arch-core-runtime', 'arch-core/runtime'], |
| 124 | 'android.arch.core:common': ['android-arch-core-common', 'arch-core/common'], |
Allen | ab72f01 | 2018-01-29 18:10:23 -0800 | [diff] [blame] | 125 | 'android.arch.core:testing': ['android-arch-core-testing', 'arch-core/testing'], |
| 126 | |
Alan Viverette | 19ecd50 | 2018-01-05 13:52:16 -0500 | [diff] [blame] | 127 | # Paging |
| 128 | 'android.arch.paging:common': ['android-arch-paging-common', 'arch-paging/common'], |
| 129 | 'android.arch.paging:runtime': ['android-arch-paging-runtime', 'arch-paging/runtime'], |
Allen | ab72f01 | 2018-01-29 18:10:23 -0800 | [diff] [blame] | 130 | |
Alan Viverette | 19ecd50 | 2018-01-05 13:52:16 -0500 | [diff] [blame] | 131 | # Lifecycle |
Allen | ab72f01 | 2018-01-29 18:10:23 -0800 | [diff] [blame] | 132 | 'android.arch.lifecycle:livedata-core': ['android-arch-lifecycle-livedata-core', 'arch-lifecycle/livedata-core'], |
| 133 | 'android.arch.lifecycle:livedata': ['android-arch-lifecycle-livedata', 'arch-lifecycle/livedata'], |
| 134 | 'android.arch.lifecycle:viewmodel': ['android-arch-lifecycle-viewmodel', 'arch-lifecycle/viewmodel'], |
| 135 | 'android.arch.lifecycle:extensions': ['android-arch-lifecycle-extensions', 'arch-lifecycle/extensions'], |
| 136 | 'android.arch.lifecycle:runtime': ['android-arch-lifecycle-runtime', 'arch-lifecycle/runtime'], |
| 137 | 'android.arch.lifecycle:common': ['android-arch-lifecycle-common', 'arch-lifecycle/common'], |
| 138 | 'android.arch.lifecycle:common-java8': ['android-arch-lifecycle-common-java8', 'arch-lifecycle/common-java8'], |
Alan Viverette | c7e88f1 | 2018-02-13 15:29:50 -0500 | [diff] [blame] | 139 | # Missing dependencies: |
| 140 | # - auto-common |
| 141 | # - javapoet |
| 142 | #'android.arch.lifecycle:compiler': ['android-arch-lifecycle-compiler', 'arch-lifecycle/compiler'], |
| 143 | # Missing dependencies: |
| 144 | # - reactive-streams |
| 145 | #'android.arch.lifecycle:reactivestreams': ['android-arch-lifecycle-reactivestreams','arch-lifecycle/reactivestreams'], |
Allen | ab72f01 | 2018-01-29 18:10:23 -0800 | [diff] [blame] | 146 | |
Alan Viverette | 19ecd50 | 2018-01-05 13:52:16 -0500 | [diff] [blame] | 147 | # Persistence |
| 148 | 'android.arch.persistence:db': ['android-arch-persistence-db', 'arch-persistence/db'], |
| 149 | 'android.arch.persistence:db-framework': ['android-arch-persistence-db-framework', 'arch-persistence/db-framework'], |
Allen | ab72f01 | 2018-01-29 18:10:23 -0800 | [diff] [blame] | 150 | |
Alan Viverette | 19ecd50 | 2018-01-05 13:52:16 -0500 | [diff] [blame] | 151 | # Room |
| 152 | 'android.arch.persistence.room:common': ['android-arch-room-common', 'arch-room/common'], |
Alan Viverette | c7e88f1 | 2018-02-13 15:29:50 -0500 | [diff] [blame] | 153 | # Missing dependencies: |
| 154 | # - auto-common |
| 155 | # - javapoet |
| 156 | # - antlr4 |
| 157 | # - kotlin-metadata |
| 158 | # - commons-codec |
| 159 | #'android.arch.persistence.room:compiler': ['android-arch-room-compiler', 'arch-room/compiler'], |
Alan Viverette | 19ecd50 | 2018-01-05 13:52:16 -0500 | [diff] [blame] | 160 | 'android.arch.persistence.room:runtime': ['android-arch-room-runtime', 'arch-room/runtime'], |
| 161 | 'android.arch.persistence.room:migration': ['android-arch-room-migration', 'arch-room/migration'], |
Alan Viverette | c7e88f1 | 2018-02-13 15:29:50 -0500 | [diff] [blame] | 162 | # Missing dependencies: |
| 163 | # - rxjava |
| 164 | #'android.arch.persistence.room:rxjava2': ['android-arch-room-rxjava2', 'arch-room/rxjava2'], |
Alan Viverette | 19ecd50 | 2018-01-05 13:52:16 -0500 | [diff] [blame] | 165 | 'android.arch.persistence.room:testing': ['android-arch-room-testing', 'arch-room/testing'], |
Allen | ab72f01 | 2018-01-29 18:10:23 -0800 | [diff] [blame] | 166 | |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 167 | # Material Design Components |
| 168 | 'com.google.android:flexbox': ['flexbox', 'flexbox'], |
| 169 | 'design': ['android-support-design', 'design'], |
| 170 | 'design-animation': ['android-support-design-animation', 'design-animation'], |
| 171 | 'design-bottomnavigation': ['android-support-design-bottomnavigation', 'design-bottomnavigation'], |
| 172 | 'design-bottomsheet': ['android-support-design-bottomsheet', 'design-bottomsheet'], |
| 173 | 'design-button': ['android-support-design-button', 'design-button'], |
| 174 | 'design-canvas': ['android-support-design-canvas', 'design-canvas'], |
| 175 | 'design-card': ['android-support-design-card', 'design-card'], |
| 176 | 'design-chip': ['android-support-design-chip', 'design-chip'], |
| 177 | 'design-circularreveal': ['android-support-design-circularreveal', 'design-circularreveal'], |
| 178 | 'design-circularreveal-cardview': ['android-support-design-circularreveal-cardview', 'design-circularreveal-cardview'], |
| 179 | 'design-circularreveal-coordinatorlayout': ['android-support-design-circularreveal-coordinatorlayout', 'design-circularreveal-coordinatorlayout'], |
| 180 | 'design-color': ['android-support-design-color', 'design-color'], |
| 181 | 'design-dialog': ['android-support-design-dialog', 'design-dialog'], |
| 182 | 'design-drawable': ['android-support-design-drawable', 'design-drawable'], |
| 183 | 'design-expandable': ['android-support-design-expandable', 'design-expandable'], |
| 184 | 'design-floatingactionbutton': ['android-support-design-floatingactionbutton', 'design-floatingactionbutton'], |
| 185 | 'design-internal': ['android-support-design-internal', 'design-internal'], |
| 186 | 'design-math': ['android-support-design-math', 'design-math'], |
| 187 | 'design-resources': ['android-support-design-resources', 'design-resources'], |
| 188 | 'design-ripple': ['android-support-design-ripple', 'design-ripple'], |
| 189 | 'design-snackbar': ['android-support-design-snackbar', 'design-snackbar'], |
| 190 | 'design-stateful': ['android-support-design-stateful', 'design-stateful'], |
| 191 | 'design-textfield': ['android-support-design-textfield', 'design-textfield'], |
| 192 | 'design-theme': ['android-support-design-theme', 'design-theme'], |
| 193 | 'design-transformation': ['android-support-design-transformation', 'design-transformation'], |
| 194 | 'design-typography': ['android-support-design-typography', 'design-typography'], |
| 195 | 'design-widget': ['android-support-design-widget', 'design-widget'], |
Alan Viverette | a59082b | 2018-02-22 10:27:46 -0500 | [diff] [blame] | 196 | 'design-navigation': ['android-support-design-navigation', 'design-navigation'], |
| 197 | 'design-tabs': ['android-support-design-tabs', 'design-tabs'], |
| 198 | 'design-bottomappbar': ['android-support-design-bottomappbar', 'design-bottomappbar'], |
| 199 | 'design-shape': ['android-support-design-shape', 'design-shape'], |
| 200 | |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | # Always remove these files. |
| 204 | blacklist_files = [ |
| 205 | 'annotations.zip', |
| 206 | 'public.txt', |
| 207 | 'R.txt', |
Alan Viverette | 44ad4e4 | 2017-08-09 17:45:00 -0400 | [diff] [blame] | 208 | 'AndroidManifest.xml', |
Alan Viverette | f48d9b4 | 2017-08-17 14:45:46 -0400 | [diff] [blame] | 209 | os.path.join('libs','noto-emoji-compat-java.jar') |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 210 | ] |
| 211 | |
Alan Viverette | 44ad4e4 | 2017-08-09 17:45:00 -0400 | [diff] [blame] | 212 | 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] | 213 | |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 214 | |
| 215 | class MavenLibraryInfo: |
| 216 | def __init__(self, key, group_id, artifact_id, version, root, repo_dir, file): |
| 217 | self.key = key |
| 218 | self.group_id = group_id |
| 219 | self.artifact_id = artifact_id |
| 220 | self.version = version |
| 221 | self.root = root |
| 222 | self.repo_dir = repo_dir |
| 223 | self.file = file |
| 224 | |
| 225 | |
Alan Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 226 | def print_e(*args, **kwargs): |
| 227 | print(*args, file=sys.stderr, **kwargs) |
| 228 | |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 229 | |
| 230 | def touch(fname, times=None): |
| 231 | with open(fname, 'a'): |
| 232 | os.utime(fname, times) |
| 233 | |
| 234 | |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 235 | def path(*path_parts): |
| 236 | return reduce((lambda x, y: os.path.join(x, y)), path_parts) |
| 237 | |
| 238 | |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 239 | def flatten(list): |
| 240 | return reduce((lambda x, y: "%s %s" % (x, y)), list) |
| 241 | |
| 242 | |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 243 | def rm(path): |
| 244 | if os.path.isdir(path): |
| 245 | rmtree(path) |
| 246 | elif os.path.exists(path): |
| 247 | os.remove(path) |
| 248 | |
| 249 | |
| 250 | def mv(src_path, dst_path): |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 251 | if os.path.exists(dst_path): |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 252 | rm(dst_path) |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 253 | if not os.path.exists(os.path.dirname(dst_path)): |
| 254 | os.makedirs(os.path.dirname(dst_path)) |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 255 | os.rename(src_path, dst_path) |
| 256 | |
| 257 | |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 258 | def detect_artifacts(repo_dirs): |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 259 | maven_lib_info = {} |
| 260 | |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 261 | # Find the latest revision for each artifact, remove others |
| 262 | for repo_dir in repo_dirs: |
| 263 | for root, dirs, files in os.walk(repo_dir): |
| 264 | for file in files: |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 265 | if file[-4:] == ".pom": |
| 266 | # Read the POM (hack hack hack). |
| 267 | group_id = '' |
| 268 | artifact_id = '' |
| 269 | version = '' |
| 270 | file = os.path.join(root, file) |
| 271 | with open(file) as pom_file: |
| 272 | for line in pom_file: |
| 273 | if line[:11] == ' <groupId>': |
| 274 | group_id = line[11:-11] |
| 275 | elif line[:14] == ' <artifactId>': |
| 276 | artifact_id = line[14:-14] |
| 277 | elif line[:11] == ' <version>': |
| 278 | version = line[11:-11] |
| 279 | if group_id == '' or artifact_id == '' or version == '': |
| 280 | print_e('Failed to find Maven artifact data in ' + file) |
| 281 | continue |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 282 | |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 283 | # Locate the artifact. |
| 284 | artifact_file = file[:-4] |
| 285 | if os.path.exists(artifact_file + '.jar'): |
| 286 | artifact_file = artifact_file + '.jar' |
| 287 | elif os.path.exists(artifact_file + '.aar'): |
| 288 | artifact_file = artifact_file + '.aar' |
| 289 | else: |
| 290 | print_e('Failed to find artifact for ' + artifact_file) |
| 291 | continue |
| 292 | |
| 293 | # Make relative to root. |
| 294 | artifact_file = artifact_file[len(root) + 1:] |
| 295 | |
| 296 | # Find the mapping. |
| 297 | group_artifact = group_id + ':' + artifact_id |
| 298 | if artifact_id in maven_to_make: |
| 299 | key = artifact_id |
| 300 | elif group_artifact in maven_to_make: |
| 301 | key = group_artifact |
| 302 | else: |
| 303 | print_e('Failed to find artifact mapping for ' + group_artifact) |
| 304 | continue |
| 305 | |
| 306 | # Store the latest version. |
| 307 | version = LooseVersion(version) |
| 308 | if key not in maven_lib_info \ |
| 309 | or version > maven_lib_info[key].version: |
| 310 | maven_lib_info[key] = MavenLibraryInfo(key, group_id, artifact_id, version, |
| 311 | root, repo_dir, artifact_file) |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 312 | |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 313 | return maven_lib_info |
| 314 | |
| 315 | |
Alan Viverette | d8ce722 | 2017-12-11 17:24:43 -0500 | [diff] [blame] | 316 | def transform_maven_repo(repo_dirs, update_dir, extract_res=True): |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 317 | cwd = os.getcwd() |
| 318 | |
| 319 | # Use a temporary working directory. |
| 320 | working_dir = os.path.join(cwd, 'support_tmp') |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 321 | maven_lib_info = detect_artifacts(repo_dirs) |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 322 | |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 323 | if not maven_lib_info: |
| 324 | print_e('Failed to detect artifacts') |
| 325 | return False |
| 326 | |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 327 | for info in maven_lib_info.values(): |
Alan Viverette | d8ce722 | 2017-12-11 17:24:43 -0500 | [diff] [blame] | 328 | transform_maven_lib(working_dir, info, extract_res) |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 329 | |
Alan Viverette | 4ec9a17 | 2018-02-20 16:19:31 -0500 | [diff] [blame^] | 330 | makefile = os.path.join(working_dir, 'Android.mk') |
| 331 | with open(makefile, 'w') as f: |
Alan Viverette | 229a53d | 2018-02-06 16:25:22 -0500 | [diff] [blame] | 332 | args = ["pom2mk", "-static-deps", "-sdk-version", "current"] |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 333 | args.extend(["-rewrite=^" + name + "$=" + maven_to_make[name][0] for name in maven_to_make]) |
| 334 | args.extend(["."]) |
Alan Viverette | 4ec9a17 | 2018-02-20 16:19:31 -0500 | [diff] [blame^] | 335 | args.extend(["-extra-deps=android-support-car=prebuilt-android.car-stubs"]) |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 336 | subprocess.check_call(args, stdout=f, cwd=working_dir) |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 337 | |
Alan Viverette | 4ec9a17 | 2018-02-20 16:19:31 -0500 | [diff] [blame^] | 338 | depsfile = os.path.join(working_dir, 'fix_dependencies.mk') |
| 339 | with open(depsfile, 'w') as f: |
| 340 | args = [script_relative("extract_deps.py"), makefile] |
| 341 | subprocess.check_call(args, stdout=f, cwd=cwd) |
| 342 | |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 343 | # Replace the old directory. |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 344 | output_dir = os.path.join(cwd, update_dir) |
| 345 | mv(working_dir, output_dir) |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 346 | return True |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 347 | |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 348 | |
Alan Viverette | d8ce722 | 2017-12-11 17:24:43 -0500 | [diff] [blame] | 349 | def transform_maven_lib(working_dir, artifact_info, extract_res): |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 350 | # Move library into working dir |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 351 | new_dir = os.path.join(working_dir, os.path.relpath(artifact_info.root, artifact_info.repo_dir)) |
| 352 | mv(artifact_info.root, new_dir) |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 353 | |
| 354 | for dirpath, dirs, files in os.walk(new_dir): |
| 355 | for f in files: |
| 356 | if '-sources.jar' in f: |
| 357 | os.remove(os.path.join(dirpath, f)) |
| 358 | |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 359 | matcher = artifact_pattern.match(artifact_info.file) |
| 360 | maven_lib_name = artifact_info.key |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 361 | maven_lib_vers = matcher.group(2) |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 362 | maven_lib_type = artifact_info.file[-3:] |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 363 | |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 364 | make_lib_name = maven_to_make[artifact_info.key][0] |
| 365 | make_dir_name = maven_to_make[artifact_info.key][1] |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 366 | |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 367 | artifact_file = os.path.join(new_dir, artifact_info.file) |
| 368 | |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 369 | if extract_res: |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 370 | target_dir = os.path.join(working_dir, make_dir_name) |
| 371 | if not os.path.exists(target_dir): |
| 372 | os.makedirs(target_dir) |
| 373 | |
| 374 | if maven_lib_type == "aar": |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 375 | process_aar(artifact_file, target_dir) |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 376 | |
Alan Viverette | d8ce722 | 2017-12-11 17:24:43 -0500 | [diff] [blame] | 377 | if maven_lib_type == "aar": |
Dan Willemsen | d677b60 | 2017-11-08 22:13:17 -0800 | [diff] [blame] | 378 | with zipfile.ZipFile(artifact_file) as zip: |
Alan Viverette | d8ce722 | 2017-12-11 17:24:43 -0500 | [diff] [blame] | 379 | manifests_dir = os.path.join(working_dir, "manifests") |
| 380 | zip.extract("AndroidManifest.xml", os.path.join(manifests_dir, make_lib_name)) |
Dan Willemsen | d677b60 | 2017-11-08 22:13:17 -0800 | [diff] [blame] | 381 | |
Alan Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 382 | print(maven_lib_vers, ":", maven_lib_name, "->", make_lib_name) |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 383 | |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 384 | |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 385 | def process_aar(artifact_file, target_dir): |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 386 | # Extract AAR file to target_dir. |
| 387 | with zipfile.ZipFile(artifact_file) as zip: |
| 388 | zip.extractall(target_dir) |
| 389 | |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 390 | # Remove classes.jar |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 391 | classes_jar = os.path.join(target_dir, "classes.jar") |
| 392 | if os.path.exists(classes_jar): |
Dan Willemsen | 814152e | 2017-11-06 13:22:11 -0800 | [diff] [blame] | 393 | os.remove(classes_jar) |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 394 | |
| 395 | # Remove or preserve empty dirs. |
| 396 | for root, dirs, files in os.walk(target_dir): |
| 397 | for dir in dirs: |
| 398 | dir_path = os.path.join(root, dir) |
| 399 | if not os.listdir(dir_path): |
| 400 | os.rmdir(dir_path) |
| 401 | |
| 402 | # Remove top-level cruft. |
| 403 | for file in blacklist_files: |
| 404 | file_path = os.path.join(target_dir, file) |
| 405 | if os.path.exists(file_path): |
| 406 | os.remove(file_path) |
| 407 | |
Alan Viverette | f17c940 | 2017-07-19 12:57:40 -0400 | [diff] [blame] | 408 | |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 409 | def fetch_artifact(target, build_id, artifact_path): |
Alan Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 410 | print('Fetching %s from %s...' % (artifact_path, target)) |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 411 | fetch_cmd = [FETCH_ARTIFACT, '--bid', str(build_id), '--target', target, artifact_path] |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 412 | try: |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 413 | subprocess.check_output(fetch_cmd, stderr=subprocess.STDOUT) |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 414 | except subprocess.CalledProcessError: |
Jeff Gaston | 13e3841 | 2018-02-06 14:45:36 -0500 | [diff] [blame] | 415 | 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] | 416 | print_e('Please make sure you are authenticated for build server access!') |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 417 | return None |
| 418 | return artifact_path |
| 419 | |
| 420 | |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 421 | def extract_artifact(artifact_path): |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 422 | # Unzip the repo archive into a separate directory. |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 423 | repo_dir = os.path.basename(artifact_path)[:-4] |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 424 | with zipfile.ZipFile(artifact_path) as zipFile: |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 425 | zipFile.extractall(repo_dir) |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 426 | return repo_dir |
| 427 | |
| 428 | |
Alan Viverette | 7e897e2 | 2018-03-09 15:24:10 -0500 | [diff] [blame] | 429 | def fetch_and_extract(target, build_id, file, artifact_path=None): |
| 430 | if not artifact_path: |
| 431 | artifact_path = fetch_artifact(target, build_id, file) |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 432 | if not artifact_path: |
| 433 | return None |
| 434 | return extract_artifact(artifact_path) |
| 435 | |
| 436 | |
Alan Viverette | 7e897e2 | 2018-03-09 15:24:10 -0500 | [diff] [blame] | 437 | def update_support(target, build_id, local_file): |
| 438 | if build_id: |
| 439 | repo_file = 'top-of-tree-m2repository-%s.zip' % build_id.fs_id |
| 440 | repo_dir = fetch_and_extract(target, build_id.url_id, repo_file, None) |
| 441 | else: |
| 442 | repo_dir = fetch_and_extract(target, None, None, local_file) |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 443 | if not repo_dir: |
Alan Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 444 | print_e('Failed to extract Support Library repository') |
Alan Viverette | f48d9b4 | 2017-08-17 14:45:46 -0400 | [diff] [blame] | 445 | return False |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 446 | |
| 447 | # Transform the repo archive into a Makefile-compatible format. |
Alan Viverette | d8ce722 | 2017-12-11 17:24:43 -0500 | [diff] [blame] | 448 | return transform_maven_repo([repo_dir], support_dir) |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 449 | |
Alan Viverette | 7e897e2 | 2018-03-09 15:24:10 -0500 | [diff] [blame] | 450 | |
Jeff Gaston | 782c3e3 | 2018-02-06 14:36:17 -0500 | [diff] [blame] | 451 | def update_jetifier(target, build_id): |
| 452 | repo_file = 'jetifier-standalone.zip' |
| 453 | repo_dir = fetch_and_extract(target, build_id.url_id, repo_file) |
| 454 | if not repo_dir: |
| 455 | print_e('Failed to extract Jetifier') |
| 456 | return False |
| 457 | |
| 458 | rm(jetifier_dir) |
| 459 | mv(repo_dir, jetifier_dir) |
Jeff Gaston | 6afb1e4 | 2018-02-07 18:58:07 -0500 | [diff] [blame] | 460 | os.chmod(os.path.join(jetifier_dir, 'jetifier-standalone', 'bin', 'jetifier-standalone'), 0o755) |
Jeff Gaston | 782c3e3 | 2018-02-06 14:36:17 -0500 | [diff] [blame] | 461 | return True |
| 462 | |
Alan Viverette | 7e897e2 | 2018-03-09 15:24:10 -0500 | [diff] [blame] | 463 | |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 464 | def update_toolkit(target, build_id): |
Jeff Gaston | 13e3841 | 2018-02-06 14:45:36 -0500 | [diff] [blame] | 465 | repo_dir = fetch_and_extract(target, build_id.url_id, 'top-of-tree-m2repository-%s.zip' % build_id.fs_id) |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 466 | if not repo_dir: |
| 467 | print_e('Failed to extract App Toolkit repository') |
| 468 | return False |
| 469 | |
| 470 | # Transform the repo archive into a Makefile-compatible format. |
| 471 | return transform_maven_repo([repo_dir], os.path.join(extras_dir, 'app-toolkit')) |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 472 | |
| 473 | |
| 474 | def update_constraint(target, build_id): |
Jeff Gaston | 13e3841 | 2018-02-06 14:45:36 -0500 | [diff] [blame] | 475 | layout_dir = fetch_and_extract(target, build_id.url_id, |
| 476 | 'com.android.support.constraint-constraint-layout-%s.zip' % build_id.fs_id) |
| 477 | solver_dir = fetch_and_extract(target, build_id.url_id, |
| 478 | 'com.android.support.constraint-constraint-layout-solver-%s.zip' % build_id.fs_id) |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 479 | if not layout_dir or not solver_dir: |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 480 | print_e('Failed to extract Constraint Layout repositories') |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 481 | return False |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 482 | |
| 483 | # Passing False here is an inelegant solution, but it means we can replace |
| 484 | # the top-level directory without worrying about other child directories. |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 485 | return transform_maven_repo([layout_dir, solver_dir], |
| 486 | os.path.join(extras_dir, 'constraint-layout'), extract_res=False) |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 487 | |
| 488 | |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 489 | def update_design(file): |
| 490 | design_dir = extract_artifact(file) |
| 491 | if not design_dir: |
| 492 | print_e('Failed to extract Design Library repositories') |
| 493 | return False |
| 494 | |
| 495 | # Don't bother extracting resources -- this should only be used with AAPT2. |
| 496 | return transform_maven_repo([design_dir], |
| 497 | os.path.join(extras_dir, 'material-design'), extract_res=False) |
| 498 | |
| 499 | |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 500 | def extract_to(zip_file, paths, filename, parent_path): |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 501 | zip_path = next(filter(lambda path: filename in path, paths)) |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 502 | src_path = zip_file.extract(zip_path) |
| 503 | dst_path = path(parent_path, filename) |
| 504 | mv(src_path, dst_path) |
| 505 | |
| 506 | |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 507 | def update_sdk_repo(target, build_id): |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 508 | platform = 'darwin' if 'mac' in target else 'linux' |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 509 | artifact_path = fetch_artifact( |
Jeff Gaston | 13e3841 | 2018-02-06 14:45:36 -0500 | [diff] [blame] | 510 | target, build_id.url_id, 'sdk-repo-%s-platforms-%s.zip' % (platform, build_id.fs_id)) |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 511 | if not artifact_path: |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 512 | return False |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 513 | |
| 514 | with zipfile.ZipFile(artifact_path) as zipFile: |
| 515 | paths = zipFile.namelist() |
| 516 | |
| 517 | extract_to(zipFile, paths, 'android.jar', current_path) |
| 518 | extract_to(zipFile, paths, 'uiautomator.jar', current_path) |
| 519 | extract_to(zipFile, paths, 'framework.aidl', current_path) |
Paul Duffin | d891f3c | 2017-12-06 11:32:56 +0000 | [diff] [blame] | 520 | extract_to(zipFile, paths, 'optional/android.test.base.jar', current_path) |
Paul Duffin | 2b1a146 | 2017-07-14 16:21:33 +0100 | [diff] [blame] | 521 | extract_to(zipFile, paths, 'optional/android.test.mock.jar', current_path) |
| 522 | extract_to(zipFile, paths, 'optional/android.test.runner.jar', current_path) |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 523 | |
| 524 | # Unclear if this is actually necessary. |
| 525 | extract_to(zipFile, paths, 'framework.aidl', system_path) |
Jiyong Park | b773d29 | 2018-01-30 23:33:19 +0900 | [diff] [blame] | 526 | |
Colin Cross | 4f4b906 | 2018-02-14 10:03:19 -0800 | [diff] [blame] | 527 | artifact_path = fetch_artifact(target, build_id.fs_id, 'core.current.stubs.jar') |
Jiyong Park | b773d29 | 2018-01-30 23:33:19 +0900 | [diff] [blame] | 528 | if not artifact_path: |
| 529 | return False |
| 530 | |
| 531 | mv(artifact_path, path(current_path, 'core.jar')) |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 532 | return True |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 533 | |
| 534 | |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 535 | def update_system(target, build_id): |
Jeff Gaston | 13e3841 | 2018-02-06 14:45:36 -0500 | [diff] [blame] | 536 | artifact_path = fetch_artifact(target, build_id.url_id, 'android_system.jar') |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 537 | if not artifact_path: |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 538 | return False |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 539 | |
| 540 | mv(artifact_path, path(system_path, 'android.jar')) |
Paul Duffin | 960e1ee | 2017-12-21 08:50:14 +0000 | [diff] [blame] | 541 | |
Jeff Gaston | 13e3841 | 2018-02-06 14:45:36 -0500 | [diff] [blame] | 542 | artifact_path = fetch_artifact(target, build_id.url_id, 'android.test.mock.stubs_system.jar') |
Paul Duffin | 960e1ee | 2017-12-21 08:50:14 +0000 | [diff] [blame] | 543 | if not artifact_path: |
| 544 | return False |
| 545 | |
| 546 | mv(artifact_path, path(system_path, 'optional/android.test.mock.jar')) |
| 547 | |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 548 | return True |
| 549 | |
| 550 | |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 551 | def update_buildtools(target, arch, build_id): |
Jeff Gaston | 13e3841 | 2018-02-06 14:45:36 -0500 | [diff] [blame] | 552 | artifact_path = fetch_and_extract(target, build_id.url_id, |
| 553 | "sdk-repo-%s-build-tools-%s.zip" % (arch, build_id.fs_id)) |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 554 | if not artifact_path: |
| 555 | return False |
| 556 | |
| 557 | top_level_dir = os.listdir(artifact_path)[0] |
| 558 | src_path = os.path.join(artifact_path, top_level_dir) |
| 559 | dst_path = path(buildtools_dir, arch) |
| 560 | mv(src_path, dst_path) |
| 561 | |
| 562 | # Move all top-level files to /bin and make them executable |
| 563 | bin_path = path(dst_path, 'bin') |
| 564 | top_level_files = filter(lambda e: os.path.isfile(path(dst_path, e)), os.listdir(dst_path)) |
| 565 | for file in top_level_files: |
| 566 | src_file = path(dst_path, file) |
| 567 | dst_file = path(bin_path, file) |
| 568 | mv(src_file, dst_file) |
| 569 | os.chmod(dst_file, 0o755) |
| 570 | |
| 571 | # Remove renderscript |
| 572 | rm(path(dst_path, 'renderscript')) |
| 573 | |
| 574 | return True |
| 575 | |
| 576 | |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 577 | def append(text, more_text): |
| 578 | if text: |
| 579 | return "%s, %s" % (text, more_text) |
| 580 | return more_text |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 581 | |
Alan Viverette | 95f6d36 | 2017-04-06 09:40:50 -0400 | [diff] [blame] | 582 | |
Jeff Gaston | 13e3841 | 2018-02-06 14:45:36 -0500 | [diff] [blame] | 583 | class buildId(object): |
| 584 | def __init__(self, url_id, fs_id): |
| 585 | # id when used in build server urls |
| 586 | self.url_id = url_id |
| 587 | # id when used in build commands |
| 588 | self.fs_id = fs_id |
| 589 | |
Jeff Gaston | b9b0905 | 2018-02-05 14:16:05 -0500 | [diff] [blame] | 590 | def getBuildId(args): |
Jeff Gaston | 13e3841 | 2018-02-06 14:45:36 -0500 | [diff] [blame] | 591 | # must be in the format 12345 or P12345 |
Jeff Gaston | b9b0905 | 2018-02-05 14:16:05 -0500 | [diff] [blame] | 592 | source = args.source |
Jeff Gaston | 13e3841 | 2018-02-06 14:45:36 -0500 | [diff] [blame] | 593 | number_text = source[:] |
| 594 | presubmit = False |
| 595 | if number_text.startswith("P"): |
| 596 | presubmit = True |
| 597 | number_text = number_text[1:] |
| 598 | if not number_text.isnumeric(): |
Alan Viverette | 7e897e2 | 2018-03-09 15:24:10 -0500 | [diff] [blame] | 599 | return None |
Jeff Gaston | 13e3841 | 2018-02-06 14:45:36 -0500 | [diff] [blame] | 600 | url_id = source |
| 601 | fs_id = url_id |
| 602 | if presubmit: |
| 603 | fs_id = "0" |
| 604 | args.file = False |
| 605 | return buildId(url_id, fs_id) |
Jeff Gaston | b9b0905 | 2018-02-05 14:16:05 -0500 | [diff] [blame] | 606 | |
Colin Cross | 573e121 | 2018-02-12 14:59:52 -0800 | [diff] [blame] | 607 | def getFile(args): |
| 608 | source = args.source |
| 609 | if not source.isnumeric(): |
| 610 | return args.source |
Alan Viverette | 7e897e2 | 2018-03-09 15:24:10 -0500 | [diff] [blame] | 611 | return None |
Colin Cross | 573e121 | 2018-02-12 14:59:52 -0800 | [diff] [blame] | 612 | |
Alan Viverette | 4ec9a17 | 2018-02-20 16:19:31 -0500 | [diff] [blame^] | 613 | |
| 614 | def script_relative(rel_path): |
| 615 | return os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), rel_path) |
| 616 | |
| 617 | |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 618 | parser = argparse.ArgumentParser( |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 619 | description=('Update current prebuilts')) |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 620 | parser.add_argument( |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 621 | 'source', |
| 622 | help='Build server build ID or local Maven ZIP file') |
| 623 | parser.add_argument( |
| 624 | '-d', '--design', action="store_true", |
| 625 | help='If specified, updates only the Design Library') |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 626 | parser.add_argument( |
Alan Viverette | 3e57a4a | 2017-08-11 15:49:47 -0400 | [diff] [blame] | 627 | '-c', '--constraint', action="store_true", |
| 628 | help='If specified, updates only Constraint Layout') |
| 629 | parser.add_argument( |
Alan Viverette | 5bfe05b | 2017-06-06 14:21:29 -0400 | [diff] [blame] | 630 | '-s', '--support', action="store_true", |
| 631 | help='If specified, updates only the Support Library') |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 632 | parser.add_argument( |
Jeff Gaston | 782c3e3 | 2018-02-06 14:36:17 -0500 | [diff] [blame] | 633 | '-j', '--jetifier', action="store_true", |
| 634 | help='If specified, updates only Jetifier') |
| 635 | parser.add_argument( |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 636 | '-t', '--toolkit', action="store_true", |
| 637 | help='If specified, updates only the App Toolkit') |
| 638 | parser.add_argument( |
Alan Viverette | 5bfe05b | 2017-06-06 14:21:29 -0400 | [diff] [blame] | 639 | '-p', '--platform', action="store_true", |
| 640 | help='If specified, updates only the Android Platform') |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 641 | parser.add_argument( |
| 642 | '-b', '--buildtools', action="store_true", |
| 643 | help='If specified, updates only the Build Tools') |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 644 | args = parser.parse_args() |
Jeff Gaston | 56fe276 | 2018-02-06 14:54:37 -0500 | [diff] [blame] | 645 | args.file = True |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 646 | if not args.source: |
| 647 | 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] | 648 | sys.exit(1) |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 649 | if not (args.support or args.platform or args.constraint or args.toolkit or args.buildtools \ |
Jeff Gaston | 782c3e3 | 2018-02-06 14:36:17 -0500 | [diff] [blame] | 650 | or args.design or args.jetifier): |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 651 | parser.error("You must specify at least one target to update") |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 652 | sys.exit(1) |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 653 | if (args.support or args.constraint or args.toolkit) and which('pom2mk') is None: |
Alan Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 654 | parser.error("Cannot find pom2mk in path; please run lunch to set up build environment") |
| 655 | sys.exit(1) |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 656 | |
| 657 | try: |
| 658 | # Make sure we don't overwrite any pending changes. |
| 659 | subprocess.check_call(['git', 'diff', '--quiet', '--', '**']) |
| 660 | subprocess.check_call(['git', 'diff', '--quiet', '--cached', '--', '**']) |
| 661 | except subprocess.CalledProcessError: |
Alan Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 662 | print_e('FAIL: There are uncommitted changes here; please revert or stash') |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 663 | sys.exit(1) |
| 664 | |
| 665 | try: |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 666 | components = None |
| 667 | if args.constraint: |
Jeff Gaston | b9b0905 | 2018-02-05 14:16:05 -0500 | [diff] [blame] | 668 | if update_constraint('studio', getBuildId(args)): |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 669 | components = append(components, 'Constraint Layout') |
Alan Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 670 | print_e('Failed to update Constraint Layout, aborting...') |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 671 | else: |
| 672 | sys.exit(1) |
| 673 | if args.support: |
Alan Viverette | 7e897e2 | 2018-03-09 15:24:10 -0500 | [diff] [blame] | 674 | if update_support('support_library', getBuildId(args), getFile(args)): |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 675 | components = append(components, 'Support Library') |
| 676 | else: |
Alan Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 677 | print_e('Failed to update Support Library, aborting...') |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 678 | sys.exit(1) |
Jeff Gaston | 782c3e3 | 2018-02-06 14:36:17 -0500 | [diff] [blame] | 679 | if args.jetifier: |
| 680 | if update_jetifier('support_library', getBuildId(args)): |
| 681 | components = append(components, 'Jetifier') |
| 682 | else: |
| 683 | print_e('Failed to update Jetifier, aborting...') |
| 684 | sys.exit(1) |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 685 | if args.toolkit: |
Jeff Gaston | b9b0905 | 2018-02-05 14:16:05 -0500 | [diff] [blame] | 686 | if update_toolkit('support_library_app_toolkit', getBuildId(args)): |
Alan Viverette | c960cfb | 2017-12-04 13:09:22 -0500 | [diff] [blame] | 687 | components = append(components, 'App Toolkit') |
| 688 | else: |
| 689 | print_e('Failed to update App Toolkit, aborting...') |
| 690 | sys.exit(1) |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 691 | if args.platform: |
Jeff Gaston | b9b0905 | 2018-02-05 14:16:05 -0500 | [diff] [blame] | 692 | if update_sdk_repo('sdk_phone_armv7-sdk_mac', getBuildId(args)) \ |
| 693 | and update_system('sdk_phone_armv7-sdk_mac', getBuildId(args)): |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 694 | components = append(components, 'platform SDK') |
| 695 | else: |
Alan Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 696 | print_e('Failed to update platform SDK, aborting...') |
Alan Viverette | cd3de26 | 2017-08-14 09:51:30 -0400 | [diff] [blame] | 697 | sys.exit(1) |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 698 | if args.design: |
Colin Cross | 573e121 | 2018-02-12 14:59:52 -0800 | [diff] [blame] | 699 | if update_design(getFile(args)): |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 700 | components = append(components, 'Design Library') |
| 701 | else: |
| 702 | print_e('Failed to update platform SDK, aborting...') |
| 703 | sys.exit(1) |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 704 | if args.buildtools: |
Jeff Gaston | b9b0905 | 2018-02-05 14:16:05 -0500 | [diff] [blame] | 705 | if update_buildtools('sdk_phone_armv7-sdk_mac', 'darwin', getBuildId(args)) \ |
| 706 | and update_buildtools('sdk_phone_x86_64-sdk', 'linux', getBuildId(args)) \ |
| 707 | and update_buildtools('sdk_phone_armv7-win_sdk', 'windows', getBuildId(args)): |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 708 | components = append(components, 'build tools') |
| 709 | else: |
| 710 | print_e('Failed to update build tools, aborting...') |
| 711 | sys.exit(1) |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 712 | |
| 713 | # Commit all changes. |
Alan Viverette | 4583709 | 2017-05-12 14:50:53 -0400 | [diff] [blame] | 714 | subprocess.check_call(['git', 'add', current_path]) |
| 715 | subprocess.check_call(['git', 'add', system_path]) |
Alan Viverette | c1c32b6 | 2017-12-20 09:40:36 -0500 | [diff] [blame] | 716 | subprocess.check_call(['git', 'add', buildtools_dir]) |
Colin Cross | 573e121 | 2018-02-12 14:59:52 -0800 | [diff] [blame] | 717 | if not args.source.isnumeric(): |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 718 | src_msg = "local Maven ZIP" |
| 719 | else: |
Jeff Gaston | 13e3841 | 2018-02-06 14:45:36 -0500 | [diff] [blame] | 720 | src_msg = "build %s" % (getBuildId(args).url_id) |
Alan Viverette | 129555e | 2018-01-30 09:57:57 -0500 | [diff] [blame] | 721 | 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] | 722 | subprocess.check_call(['git', 'commit', '-m', msg]) |
Alan Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 723 | print('Remember to test this change before uploading it to Gerrit!') |
Alan Viverette | d4527e6 | 2017-05-11 15:03:25 -0400 | [diff] [blame] | 724 | |
| 725 | finally: |
| 726 | # Revert all stray files, including the downloaded zip. |
| 727 | try: |
| 728 | with open(os.devnull, 'w') as bitbucket: |
| 729 | subprocess.check_call(['git', 'add', '-Af', '.'], stdout=bitbucket) |
| 730 | subprocess.check_call( |
| 731 | ['git', 'commit', '-m', 'COMMIT TO REVERT - RESET ME!!!'], stdout=bitbucket) |
| 732 | subprocess.check_call(['git', 'reset', '--hard', 'HEAD~1'], stdout=bitbucket) |
| 733 | except subprocess.CalledProcessError: |
Alan Viverette | f5cb0e6 | 2017-11-17 15:15:23 -0500 | [diff] [blame] | 734 | print_e('ERROR: Failed cleaning up, manual cleanup required!!!') |