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