Ian Zerny | dcb172e | 2022-02-22 15:36:45 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Søren Gjesse | 71a6c52 | 2018-02-21 09:21:00 +0100 | [diff] [blame] | 2 | # Copyright (c) 2018, 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 gradle |
Ian Zerny | 3f54e22 | 2019-02-12 10:51:17 +0100 | [diff] [blame] | 7 | import jdk |
Søren Gjesse | 71a6c52 | 2018-02-21 09:21:00 +0100 | [diff] [blame] | 8 | import os |
| 9 | import subprocess |
| 10 | import sys |
| 11 | import utils |
| 12 | |
Søren Gjesse | 8644c57 | 2022-06-20 12:15:51 +0200 | [diff] [blame] | 13 | ASM_VERSION = '9.3' |
Søren Gjesse | 1b68579 | 2020-04-02 13:06:11 +0000 | [diff] [blame] | 14 | ASM_JAR = 'asm-' + ASM_VERSION + '.jar' |
| 15 | ASM_UTIL_JAR = 'asm-util-' + ASM_VERSION + '.jar' |
| 16 | |
Søren Gjesse | 71a6c52 | 2018-02-21 09:21:00 +0100 | [diff] [blame] | 17 | def run(args, build=True): |
| 18 | if build: |
| 19 | gradle.RunGradle(['copyMavenDeps']) |
| 20 | cmd = [] |
Ian Zerny | 3f54e22 | 2019-02-12 10:51:17 +0100 | [diff] [blame] | 21 | cmd.append(jdk.GetJavaExecutable()) |
Søren Gjesse | 1b68579 | 2020-04-02 13:06:11 +0000 | [diff] [blame] | 22 | cp = ":".join([os.path.join(utils.REPO_ROOT, 'build/deps/' + ASM_JAR), |
| 23 | os.path.join(utils.REPO_ROOT, 'build/deps/' + ASM_UTIL_JAR)]) |
Søren Gjesse | 9dde7b2 | 2018-08-28 11:28:27 +0200 | [diff] [blame] | 24 | cmd.extend(['-cp', cp]) |
Søren Gjesse | 71a6c52 | 2018-02-21 09:21:00 +0100 | [diff] [blame] | 25 | cmd.append('org.objectweb.asm.util.ASMifier') |
| 26 | cmd.extend(args) |
| 27 | utils.PrintCmd(cmd) |
Søren Gjesse | 6f027ce | 2022-03-22 13:55:01 +0100 | [diff] [blame] | 28 | result = subprocess.check_output(cmd).decode('utf-8') |
Søren Gjesse | 71a6c52 | 2018-02-21 09:21:00 +0100 | [diff] [blame] | 29 | print(result) |
| 30 | return result |
| 31 | |
| 32 | def main(): |
| 33 | build = True |
Tamas Kenez | 6b6bb9f | 2018-11-07 20:08:40 +0100 | [diff] [blame] | 34 | help = True |
Søren Gjesse | 71a6c52 | 2018-02-21 09:21:00 +0100 | [diff] [blame] | 35 | args = [] |
| 36 | for arg in sys.argv[1:]: |
| 37 | if arg in ("--build", "--no-build"): |
| 38 | build = arg == "--build" |
Tamas Kenez | 6b6bb9f | 2018-11-07 20:08:40 +0100 | [diff] [blame] | 39 | elif arg == "--no-debug": |
| 40 | args.append("-debug") |
| 41 | elif arg in ("-help", "--help", "-debug"): |
| 42 | help = True |
| 43 | break |
Søren Gjesse | 71a6c52 | 2018-02-21 09:21:00 +0100 | [diff] [blame] | 44 | else: |
Tamas Kenez | 6b6bb9f | 2018-11-07 20:08:40 +0100 | [diff] [blame] | 45 | help = False |
Søren Gjesse | 71a6c52 | 2018-02-21 09:21:00 +0100 | [diff] [blame] | 46 | args.append(arg) |
Tamas Kenez | 6b6bb9f | 2018-11-07 20:08:40 +0100 | [diff] [blame] | 47 | if help: |
Søren Gjesse | 6f027ce | 2022-03-22 13:55:01 +0100 | [diff] [blame] | 48 | print("asmifier.py [--no-build] [--no-debug] <classfile>*") |
| 49 | print(" --no-build Don't run R8 dependencies.") |
| 50 | print(" --no-debug Don't include local variable information in output.") |
Tamas Kenez | 6b6bb9f | 2018-11-07 20:08:40 +0100 | [diff] [blame] | 51 | return |
Søren Gjesse | 71a6c52 | 2018-02-21 09:21:00 +0100 | [diff] [blame] | 52 | try: |
| 53 | run(args, build) |
| 54 | except subprocess.CalledProcessError as e: |
| 55 | # In case anything relevant was printed to stdout, normally this is already |
| 56 | # on stderr. |
| 57 | print(e.output) |
| 58 | return e.returncode |
| 59 | |
| 60 | if __name__ == '__main__': |
| 61 | sys.exit(main()) |