Morten Krogh-Jespersen | 017a700 | 2019-01-10 14:14:17 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # Copyright (c) 2019, 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 | |
Morten Krogh-Jespersen | a6f0f2f | 2019-01-17 13:57:39 +0100 | [diff] [blame] | 6 | import archive |
| 7 | import argparse |
Ian Zerny | 3f54e22 | 2019-02-12 10:51:17 +0100 | [diff] [blame] | 8 | import jdk |
Morten Krogh-Jespersen | 017a700 | 2019-01-10 14:14:17 +0100 | [diff] [blame] | 9 | import subprocess |
| 10 | import sys |
Morten Krogh-Jespersen | a6f0f2f | 2019-01-17 13:57:39 +0100 | [diff] [blame] | 11 | import tempfile |
Morten Krogh-Jespersen | 017a700 | 2019-01-10 14:14:17 +0100 | [diff] [blame] | 12 | import utils |
| 13 | |
Morten Krogh-Jespersen | a6f0f2f | 2019-01-17 13:57:39 +0100 | [diff] [blame] | 14 | def parse_arguments(): |
| 15 | parser = argparse.ArgumentParser( |
| 16 | description = 'R8lib wrapper for retrace tool.') |
| 17 | parser.add_argument( |
| 18 | '-c', |
| 19 | '--commit_hash', |
| 20 | help='Commit hash to download r8lib map file for.', |
| 21 | default=None) |
| 22 | parser.add_argument( |
| 23 | '--version', |
| 24 | help='Version to download r8lib map file for.', |
| 25 | default=None) |
| 26 | parser.add_argument( |
Morten Krogh-Jespersen | 08701bf | 2019-12-02 21:31:04 +0100 | [diff] [blame] | 27 | '--tag', |
| 28 | help='Tag to download r8lib map file for.', |
| 29 | default=None) |
| 30 | parser.add_argument( |
Morten Krogh-Jespersen | a6f0f2f | 2019-01-17 13:57:39 +0100 | [diff] [blame] | 31 | '--map', |
| 32 | help='Path to r8lib map.', |
| 33 | default=utils.R8LIB_JAR + '.map') |
| 34 | parser.add_argument( |
| 35 | '--stacktrace', |
| 36 | help='Path to stacktrace file.', |
| 37 | default=None) |
| 38 | return parser.parse_args() |
| 39 | |
| 40 | |
Morten Krogh-Jespersen | 08701bf | 2019-12-02 21:31:04 +0100 | [diff] [blame] | 41 | def find_version_or_hash_from_tag(tag_or_hash): |
| 42 | info = subprocess.check_output([ |
| 43 | 'git', |
| 44 | 'show', |
| 45 | tag_or_hash, |
| 46 | '-s', |
| 47 | '--format=oneline']).splitlines()[-1].split() |
| 48 | # The info should be on the following form [hash,"Version",version] |
| 49 | if len(info) == 3 and len(info[0]) == 40 and info[1] == "Version": |
| 50 | return info[2] |
| 51 | return None |
| 52 | |
| 53 | |
Morten Krogh-Jespersen | 017a700 | 2019-01-10 14:14:17 +0100 | [diff] [blame] | 54 | def main(): |
Morten Krogh-Jespersen | a6f0f2f | 2019-01-17 13:57:39 +0100 | [diff] [blame] | 55 | args = parse_arguments() |
Morten Krogh-Jespersen | 08701bf | 2019-12-02 21:31:04 +0100 | [diff] [blame] | 56 | if args.tag: |
| 57 | hash_or_version = find_version_or_hash_from_tag(args.tag) |
| 58 | else: |
| 59 | hash_or_version = args.commit_hash or args.version |
Ian Zerny | 5ffa58f | 2020-02-26 08:37:14 +0100 | [diff] [blame] | 60 | return run(args.map, hash_or_version, args.stacktrace, args.commit_hash is not None) |
| 61 | |
| 62 | def run(r8lib_map_path, hash_or_version, stacktrace, is_hash): |
Morten Krogh-Jespersen | 08701bf | 2019-12-02 21:31:04 +0100 | [diff] [blame] | 63 | if hash_or_version: |
Morten Krogh-Jespersen | a6f0f2f | 2019-01-17 13:57:39 +0100 | [diff] [blame] | 64 | download_path = archive.GetUploadDestination( |
Morten Krogh-Jespersen | 08701bf | 2019-12-02 21:31:04 +0100 | [diff] [blame] | 65 | hash_or_version, |
Morten Krogh-Jespersen | a6f0f2f | 2019-01-17 13:57:39 +0100 | [diff] [blame] | 66 | 'r8lib.jar.map', |
Ian Zerny | 5ffa58f | 2020-02-26 08:37:14 +0100 | [diff] [blame] | 67 | is_hash) |
Morten Krogh-Jespersen | a6f0f2f | 2019-01-17 13:57:39 +0100 | [diff] [blame] | 68 | if utils.file_exists_on_cloud_storage(download_path): |
| 69 | r8lib_map_path = tempfile.NamedTemporaryFile().name |
| 70 | utils.download_file_from_cloud_storage(download_path, r8lib_map_path) |
| 71 | else: |
Morten Krogh-Jespersen | 08701bf | 2019-12-02 21:31:04 +0100 | [diff] [blame] | 72 | print('Could not find map file from argument: %s.' % hash_or_version) |
Morten Krogh-Jespersen | a6f0f2f | 2019-01-17 13:57:39 +0100 | [diff] [blame] | 73 | return 1 |
| 74 | |
Ian Zerny | 3f54e22 | 2019-02-12 10:51:17 +0100 | [diff] [blame] | 75 | retrace_args = [ |
Morten Krogh-Jespersen | 89a5b06 | 2020-01-07 14:50:40 +0100 | [diff] [blame] | 76 | jdk.GetJavaExecutable(), |
| 77 | '-cp', |
| 78 | utils.R8LIB_JAR, |
| 79 | 'com.android.tools.r8.retrace.Retrace', |
| 80 | r8lib_map_path |
Ian Zerny | 3f54e22 | 2019-02-12 10:51:17 +0100 | [diff] [blame] | 81 | ] |
Morten Krogh-Jespersen | 89a5b06 | 2020-01-07 14:50:40 +0100 | [diff] [blame] | 82 | |
Ian Zerny | 5ffa58f | 2020-02-26 08:37:14 +0100 | [diff] [blame] | 83 | if stacktrace: |
| 84 | retrace_args.append(stacktrace) |
Morten Krogh-Jespersen | a6f0f2f | 2019-01-17 13:57:39 +0100 | [diff] [blame] | 85 | |
| 86 | return subprocess.call(retrace_args) |
| 87 | |
Morten Krogh-Jespersen | 017a700 | 2019-01-10 14:14:17 +0100 | [diff] [blame] | 88 | |
| 89 | if __name__ == '__main__': |
| 90 | sys.exit(main()) |