Søren Gjesse | 6d1934f | 2017-11-09 10:00:24 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file |
| 3 | # for details. All rights reserved. Use of this source code is governed by a |
| 4 | # BSD-style license that can be found in the LICENSE file. |
| 5 | |
| 6 | import argparse |
| 7 | import gradle |
| 8 | import os |
Søren Gjesse | 6d1934f | 2017-11-09 10:00:24 +0100 | [diff] [blame] | 9 | from shutil import copyfile |
Mads Ager | 14d9b07 | 2017-11-20 13:42:55 +0100 | [diff] [blame] | 10 | import sys |
| 11 | import tempfile |
| 12 | import utils |
| 13 | import urllib |
| 14 | |
Rico Wind | 03463d3 | 2018-01-22 10:44:00 +0100 | [diff] [blame] | 15 | BUILD_ROOT = "http://storage.googleapis.com/r8-releases/raw/" |
| 16 | MASTER_BUILD_ROOT = "%smaster/" % BUILD_ROOT |
| 17 | |
Tamas Kenez | 4f3fe5a | 2018-12-14 14:37:30 +0100 | [diff] [blame] | 18 | JAR_TARGETS_MAP = { |
| 19 | 'full': [ |
Tamas Kenez | 4f3fe5a | 2018-12-14 14:37:30 +0100 | [diff] [blame] | 20 | (utils.R8, 'r8-master'), |
| 21 | (utils.COMPATDX, 'compatdx-master'), |
| 22 | (utils.COMPATPROGUARD, 'compatproguard-master'), |
| 23 | ], |
| 24 | 'lib': [ |
| 25 | (utils.R8LIB, 'r8-master'), |
| 26 | (utils.COMPATDXLIB, 'compatdx-master'), |
| 27 | (utils.COMPATPROGUARDLIB, 'compatproguard-master'), |
| 28 | ], |
| 29 | } |
| 30 | |
Mads Ager | 12a56bc | 2017-11-27 11:51:25 +0100 | [diff] [blame] | 31 | OTHER_TARGETS = ["LICENSE"] |
Søren Gjesse | 6d1934f | 2017-11-09 10:00:24 +0100 | [diff] [blame] | 32 | |
| 33 | def parse_arguments(): |
| 34 | parser = argparse.ArgumentParser( |
| 35 | description = 'Build and copy jars to an Android tree.') |
| 36 | parser.add_argument('android_root', nargs=1, |
| 37 | help='Android checkout root.') |
Mads Ager | 14d9b07 | 2017-11-20 13:42:55 +0100 | [diff] [blame] | 38 | parser.add_argument('--commit_hash', default=None, help='Commit hash') |
Rico Wind | 03463d3 | 2018-01-22 10:44:00 +0100 | [diff] [blame] | 39 | parser.add_argument('--version', default=None, help='The version to download') |
Tamas Kenez | 4f3fe5a | 2018-12-14 14:37:30 +0100 | [diff] [blame] | 40 | parser.add_argument( |
| 41 | '--targets', |
| 42 | required=True, |
| 43 | choices=['full', 'lib'], |
| 44 | help="Use 'full' to download the full, non-optimized jars (legacy" + |
Morten Krogh-Jespersen | 87da12f | 2019-01-22 10:32:32 +0100 | [diff] [blame] | 45 | " behaviour) and 'lib' for the R8-processed, optimized jars.", |
Tamas Kenez | 4f3fe5a | 2018-12-14 14:37:30 +0100 | [diff] [blame] | 46 | ) |
| 47 | parser.add_argument( |
| 48 | '--maps', |
| 49 | action='store_true', |
| 50 | help="Download proguard maps for jars, use only with '--target lib'.", |
| 51 | ) |
Søren Gjesse | 6d1934f | 2017-11-09 10:00:24 +0100 | [diff] [blame] | 52 | return parser.parse_args() |
| 53 | |
Tamas Kenez | 4f3fe5a | 2018-12-14 14:37:30 +0100 | [diff] [blame] | 54 | def copy_targets(root, target_root, srcs, dests, maps=False): |
Tamas Kenez | 03ab76f | 2018-12-07 14:33:25 +0100 | [diff] [blame] | 55 | assert len(srcs) == len(dests) |
Mads Ager | 12a56bc | 2017-11-27 11:51:25 +0100 | [diff] [blame] | 56 | for i in range(len(srcs)): |
| 57 | src = os.path.join(root, srcs[i]) |
| 58 | dest = os.path.join(target_root, 'prebuilts', 'r8', dests[i]) |
Mads Ager | 14d9b07 | 2017-11-20 13:42:55 +0100 | [diff] [blame] | 59 | print 'Copying: ' + src + ' -> ' + dest |
| 60 | copyfile(src, dest) |
Tamas Kenez | 4f3fe5a | 2018-12-14 14:37:30 +0100 | [diff] [blame] | 61 | if maps: |
| 62 | print 'Copying: ' + src + '.map -> ' + dest + '.map' |
| 63 | copyfile(src + '.map', dest + '.map') |
Mads Ager | 14d9b07 | 2017-11-20 13:42:55 +0100 | [diff] [blame] | 64 | |
Tamas Kenez | 4f3fe5a | 2018-12-14 14:37:30 +0100 | [diff] [blame] | 65 | def copy_jar_targets(root, target_root, jar_targets, maps): |
| 66 | srcs = map((lambda t: t[0] + '.jar'), jar_targets) |
| 67 | dests = map((lambda t: t[1] + '.jar'), jar_targets) |
| 68 | copy_targets(root, target_root, srcs, dests, maps=maps) |
Mads Ager | 12a56bc | 2017-11-27 11:51:25 +0100 | [diff] [blame] | 69 | |
| 70 | def copy_other_targets(root, target_root): |
| 71 | copy_targets(root, target_root, OTHER_TARGETS, OTHER_TARGETS) |
| 72 | |
Rico Wind | 03463d3 | 2018-01-22 10:44:00 +0100 | [diff] [blame] | 73 | def download_hash(root, commit_hash, target): |
Mads Ager | 12a56bc | 2017-11-27 11:51:25 +0100 | [diff] [blame] | 74 | url = MASTER_BUILD_ROOT + commit_hash + '/' + target |
Rico Wind | 03463d3 | 2018-01-22 10:44:00 +0100 | [diff] [blame] | 75 | download_target(root, url, target) |
| 76 | |
| 77 | def download_version(root, version, target): |
| 78 | url = BUILD_ROOT + version + '/' + target |
| 79 | download_target(root, url, target) |
| 80 | |
| 81 | def download_target(root, url, target): |
Mads Ager | 12a56bc | 2017-11-27 11:51:25 +0100 | [diff] [blame] | 82 | download_path = os.path.join(root, target) |
| 83 | print 'Downloading: ' + url + ' -> ' + download_path |
Tamas Kenez | 6b5d3b8 | 2018-02-05 12:02:20 +0100 | [diff] [blame] | 84 | result = urllib.urlretrieve(url, download_path) |
| 85 | if 'X-GUploader-Request-Result: success' not in str(result[1]): |
| 86 | raise IOError('Failed to download ' + url) |
Mads Ager | 12a56bc | 2017-11-27 11:51:25 +0100 | [diff] [blame] | 87 | |
Søren Gjesse | 6d1934f | 2017-11-09 10:00:24 +0100 | [diff] [blame] | 88 | def Main(): |
| 89 | args = parse_arguments() |
Tamas Kenez | 4f3fe5a | 2018-12-14 14:37:30 +0100 | [diff] [blame] | 90 | if args.maps and args.targets != 'lib': |
| 91 | raise Exception("Use '--maps' only with '--targets lib.") |
Mads Ager | 14d9b07 | 2017-11-20 13:42:55 +0100 | [diff] [blame] | 92 | target_root = args.android_root[0] |
Tamas Kenez | 4f3fe5a | 2018-12-14 14:37:30 +0100 | [diff] [blame] | 93 | jar_targets = JAR_TARGETS_MAP[args.targets] |
Rico Wind | 03463d3 | 2018-01-22 10:44:00 +0100 | [diff] [blame] | 94 | if args.commit_hash == None and args.version == None: |
Tamas Kenez | 4f3fe5a | 2018-12-14 14:37:30 +0100 | [diff] [blame] | 95 | gradle.RunGradle(map(lambda t: t[0], jar_targets)) |
| 96 | copy_jar_targets(utils.LIBS, target_root, jar_targets, args.maps) |
Mads Ager | 12a56bc | 2017-11-27 11:51:25 +0100 | [diff] [blame] | 97 | copy_other_targets(utils.GENERATED_LICENSE_DIR, target_root) |
Mads Ager | 14d9b07 | 2017-11-20 13:42:55 +0100 | [diff] [blame] | 98 | else: |
Rico Wind | 03463d3 | 2018-01-22 10:44:00 +0100 | [diff] [blame] | 99 | assert args.commit_hash == None or args.version == None |
Tamas Kenez | 4f3fe5a | 2018-12-14 14:37:30 +0100 | [diff] [blame] | 100 | targets = map((lambda t: t[0] + '.jar'), jar_targets) + OTHER_TARGETS |
Mads Ager | 14d9b07 | 2017-11-20 13:42:55 +0100 | [diff] [blame] | 101 | with utils.TempDir() as root: |
Mads Ager | 12a56bc | 2017-11-27 11:51:25 +0100 | [diff] [blame] | 102 | for target in targets: |
Rico Wind | 03463d3 | 2018-01-22 10:44:00 +0100 | [diff] [blame] | 103 | if args.commit_hash: |
| 104 | download_hash(root, args.commit_hash, target) |
Tamas Kenez | 4f3fe5a | 2018-12-14 14:37:30 +0100 | [diff] [blame] | 105 | if args.maps and target not in OTHER_TARGETS: |
| 106 | download_hash(root, args.commit_hash, target + '.map') |
Rico Wind | 03463d3 | 2018-01-22 10:44:00 +0100 | [diff] [blame] | 107 | else: |
| 108 | assert args.version |
| 109 | download_version(root, args.version, target) |
Tamas Kenez | 4f3fe5a | 2018-12-14 14:37:30 +0100 | [diff] [blame] | 110 | if args.maps and target not in OTHER_TARGETS: |
| 111 | download_version(root, args.version, target + '.map') |
| 112 | copy_jar_targets(root, target_root, jar_targets, args.maps) |
Mads Ager | 12a56bc | 2017-11-27 11:51:25 +0100 | [diff] [blame] | 113 | copy_other_targets(root, target_root) |
Søren Gjesse | 6d1934f | 2017-11-09 10:00:24 +0100 | [diff] [blame] | 114 | |
| 115 | if __name__ == '__main__': |
| 116 | sys.exit(Main()) |