blob: 04e06182a9ea59a403eb23ff49d0908a0e6964cc [file] [log] [blame]
Søren Gjesse6d1934f2017-11-09 10:00:24 +01001#!/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
6import argparse
7import gradle
8import os
Søren Gjesse6d1934f2017-11-09 10:00:24 +01009from shutil import copyfile
Mads Ager14d9b072017-11-20 13:42:55 +010010import sys
11import tempfile
12import utils
13import urllib
14
Rico Wind03463d32018-01-22 10:44:00 +010015BUILD_ROOT = "http://storage.googleapis.com/r8-releases/raw/"
16MASTER_BUILD_ROOT = "%smaster/" % BUILD_ROOT
17
Tamas Kenez4f3fe5a2018-12-14 14:37:30 +010018JAR_TARGETS_MAP = {
19 'full': [
Tamas Kenez4f3fe5a2018-12-14 14:37:30 +010020 (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 Ager12a56bc2017-11-27 11:51:25 +010031OTHER_TARGETS = ["LICENSE"]
Søren Gjesse6d1934f2017-11-09 10:00:24 +010032
33def 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 Ager14d9b072017-11-20 13:42:55 +010038 parser.add_argument('--commit_hash', default=None, help='Commit hash')
Rico Wind03463d32018-01-22 10:44:00 +010039 parser.add_argument('--version', default=None, help='The version to download')
Tamas Kenez4f3fe5a2018-12-14 14:37:30 +010040 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-Jespersen87da12f2019-01-22 10:32:32 +010045 " behaviour) and 'lib' for the R8-processed, optimized jars.",
Tamas Kenez4f3fe5a2018-12-14 14:37:30 +010046 )
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 Gjesse6d1934f2017-11-09 10:00:24 +010052 return parser.parse_args()
53
Tamas Kenez4f3fe5a2018-12-14 14:37:30 +010054def copy_targets(root, target_root, srcs, dests, maps=False):
Tamas Kenez03ab76f2018-12-07 14:33:25 +010055 assert len(srcs) == len(dests)
Mads Ager12a56bc2017-11-27 11:51:25 +010056 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 Ager14d9b072017-11-20 13:42:55 +010059 print 'Copying: ' + src + ' -> ' + dest
60 copyfile(src, dest)
Tamas Kenez4f3fe5a2018-12-14 14:37:30 +010061 if maps:
62 print 'Copying: ' + src + '.map -> ' + dest + '.map'
63 copyfile(src + '.map', dest + '.map')
Mads Ager14d9b072017-11-20 13:42:55 +010064
Tamas Kenez4f3fe5a2018-12-14 14:37:30 +010065def 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 Ager12a56bc2017-11-27 11:51:25 +010069
70def copy_other_targets(root, target_root):
71 copy_targets(root, target_root, OTHER_TARGETS, OTHER_TARGETS)
72
Rico Wind03463d32018-01-22 10:44:00 +010073def download_hash(root, commit_hash, target):
Mads Ager12a56bc2017-11-27 11:51:25 +010074 url = MASTER_BUILD_ROOT + commit_hash + '/' + target
Rico Wind03463d32018-01-22 10:44:00 +010075 download_target(root, url, target)
76
77def download_version(root, version, target):
78 url = BUILD_ROOT + version + '/' + target
79 download_target(root, url, target)
80
81def download_target(root, url, target):
Mads Ager12a56bc2017-11-27 11:51:25 +010082 download_path = os.path.join(root, target)
83 print 'Downloading: ' + url + ' -> ' + download_path
Tamas Kenez6b5d3b82018-02-05 12:02:20 +010084 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 Ager12a56bc2017-11-27 11:51:25 +010087
Søren Gjesse6d1934f2017-11-09 10:00:24 +010088def Main():
89 args = parse_arguments()
Tamas Kenez4f3fe5a2018-12-14 14:37:30 +010090 if args.maps and args.targets != 'lib':
91 raise Exception("Use '--maps' only with '--targets lib.")
Mads Ager14d9b072017-11-20 13:42:55 +010092 target_root = args.android_root[0]
Tamas Kenez4f3fe5a2018-12-14 14:37:30 +010093 jar_targets = JAR_TARGETS_MAP[args.targets]
Rico Wind03463d32018-01-22 10:44:00 +010094 if args.commit_hash == None and args.version == None:
Tamas Kenez4f3fe5a2018-12-14 14:37:30 +010095 gradle.RunGradle(map(lambda t: t[0], jar_targets))
96 copy_jar_targets(utils.LIBS, target_root, jar_targets, args.maps)
Mads Ager12a56bc2017-11-27 11:51:25 +010097 copy_other_targets(utils.GENERATED_LICENSE_DIR, target_root)
Mads Ager14d9b072017-11-20 13:42:55 +010098 else:
Rico Wind03463d32018-01-22 10:44:00 +010099 assert args.commit_hash == None or args.version == None
Tamas Kenez4f3fe5a2018-12-14 14:37:30 +0100100 targets = map((lambda t: t[0] + '.jar'), jar_targets) + OTHER_TARGETS
Mads Ager14d9b072017-11-20 13:42:55 +0100101 with utils.TempDir() as root:
Mads Ager12a56bc2017-11-27 11:51:25 +0100102 for target in targets:
Rico Wind03463d32018-01-22 10:44:00 +0100103 if args.commit_hash:
104 download_hash(root, args.commit_hash, target)
Tamas Kenez4f3fe5a2018-12-14 14:37:30 +0100105 if args.maps and target not in OTHER_TARGETS:
106 download_hash(root, args.commit_hash, target + '.map')
Rico Wind03463d32018-01-22 10:44:00 +0100107 else:
108 assert args.version
109 download_version(root, args.version, target)
Tamas Kenez4f3fe5a2018-12-14 14:37:30 +0100110 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 Ager12a56bc2017-11-27 11:51:25 +0100113 copy_other_targets(root, target_root)
Søren Gjesse6d1934f2017-11-09 10:00:24 +0100114
115if __name__ == '__main__':
116 sys.exit(Main())