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