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