blob: ae7d1e66dd4988f773c93bbee1cb00a976f8dc4d [file] [log] [blame]
Ian Zernydcb172e2022-02-22 15:36:45 +01001#!/usr/bin/env python3
Søren Gjesse71a6c522018-02-21 09:21:00 +01002# 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
6import gradle
Ian Zerny3f54e222019-02-12 10:51:17 +01007import jdk
Søren Gjesse71a6c522018-02-21 09:21:00 +01008import os
9import subprocess
10import sys
11import utils
12
Søren Gjesse8644c572022-06-20 12:15:51 +020013ASM_VERSION = '9.3'
Søren Gjesse1b685792020-04-02 13:06:11 +000014ASM_JAR = 'asm-' + ASM_VERSION + '.jar'
15ASM_UTIL_JAR = 'asm-util-' + ASM_VERSION + '.jar'
16
Søren Gjesse71a6c522018-02-21 09:21:00 +010017def run(args, build=True):
18 if build:
19 gradle.RunGradle(['copyMavenDeps'])
20 cmd = []
Ian Zerny3f54e222019-02-12 10:51:17 +010021 cmd.append(jdk.GetJavaExecutable())
Søren Gjesse1b685792020-04-02 13:06:11 +000022 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 Gjesse9dde7b22018-08-28 11:28:27 +020024 cmd.extend(['-cp', cp])
Søren Gjesse71a6c522018-02-21 09:21:00 +010025 cmd.append('org.objectweb.asm.util.ASMifier')
26 cmd.extend(args)
27 utils.PrintCmd(cmd)
Søren Gjesse6f027ce2022-03-22 13:55:01 +010028 result = subprocess.check_output(cmd).decode('utf-8')
Søren Gjesse71a6c522018-02-21 09:21:00 +010029 print(result)
30 return result
31
32def main():
33 build = True
Tamas Kenez6b6bb9f2018-11-07 20:08:40 +010034 help = True
Søren Gjesse71a6c522018-02-21 09:21:00 +010035 args = []
36 for arg in sys.argv[1:]:
37 if arg in ("--build", "--no-build"):
38 build = arg == "--build"
Tamas Kenez6b6bb9f2018-11-07 20:08:40 +010039 elif arg == "--no-debug":
40 args.append("-debug")
41 elif arg in ("-help", "--help", "-debug"):
42 help = True
43 break
Søren Gjesse71a6c522018-02-21 09:21:00 +010044 else:
Tamas Kenez6b6bb9f2018-11-07 20:08:40 +010045 help = False
Søren Gjesse71a6c522018-02-21 09:21:00 +010046 args.append(arg)
Tamas Kenez6b6bb9f2018-11-07 20:08:40 +010047 if help:
Søren Gjesse6f027ce2022-03-22 13:55:01 +010048 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 Kenez6b6bb9f2018-11-07 20:08:40 +010051 return
Søren Gjesse71a6c522018-02-21 09:21:00 +010052 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
60if __name__ == '__main__':
61 sys.exit(main())