blob: e21dc7d22d8ef5d93a27c3c99f5a242d10d6cd49 [file] [log] [blame]
Ian Zerny4a2d5992018-11-08 11:42:07 +01001#!/usr/bin/env python
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
6import optparse
7import os
8import subprocess
9import sys
10
11import utils
12
13LINUX_DIR = os.path.join(utils.TOOLS_DIR, 'linux')
14
15VERSIONS = [
16 'default',
Ian Zerny4269d592019-01-16 10:40:38 +010017 '9.0.0',
18 '8.1.0',
Ian Zerny4a2d5992018-11-08 11:42:07 +010019 '7.0.0',
20 '6.0.1',
Ian Zerny08cd3862018-11-27 13:00:02 +010021 '5.1.1',
Ian Zerny4a2d5992018-11-08 11:42:07 +010022]
23
24DIRS = {
25 'default': 'art',
Ian Zerny4269d592019-01-16 10:40:38 +010026 '9.0.0': 'art-9.0.0',
27 '8.1.0': 'art-8.1.0',
Ian Zerny4a2d5992018-11-08 11:42:07 +010028 '7.0.0': 'art-7.0.0',
29 '6.0.1': 'art-6.0.1',
30 '5.1.1': 'art-5.1.1',
31}
32
33PRODUCTS = {
34 'default': 'angler',
Ian Zerny4269d592019-01-16 10:40:38 +010035 '9.0.0': 'marlin',
36 '8.1.0': 'marlin',
Ian Zerny4a2d5992018-11-08 11:42:07 +010037 '7.0.0': 'angler',
38 '6.0.1': 'angler',
39 '5.1.1': 'mako',
40}
41
Ian Zerny08cd3862018-11-27 13:00:02 +010042ARCHS = {
43 'default': 'arm64',
Ian Zerny4269d592019-01-16 10:40:38 +010044 '9.0.0': 'arm64',
45 '8.1.0': 'arm64',
Ian Zerny08cd3862018-11-27 13:00:02 +010046 '7.0.0': 'arm64',
47 '6.0.1': 'arm64',
48 '5.1.1': 'arm',
49}
50
Ian Zerny4269d592019-01-16 10:40:38 +010051VERBOSE_OPTIONS = [
52 'verifier',
53 'compiler',
54 'gc',
55 'jit',
56 'jni',
57 'class',
58 'all',
59]
60
Ian Zerny4a2d5992018-11-08 11:42:07 +010061def ParseOptions():
62 parser = optparse.OptionParser()
63 parser.add_option('--version',
64 help='Version of dex2oat. (defaults to latest, eg, tools/linux/art).',
65 choices=VERSIONS,
66 default='default')
67 parser.add_option('--all',
68 help='Run dex2oat on all possible versions',
69 default=False,
70 action='store_true')
71 parser.add_option('--output',
72 help='Where to place the output oat (defaults to no output / temp file).',
73 default=None)
Ian Zerny4269d592019-01-16 10:40:38 +010074 parser.add_option('--verbose',
75 help='Enable verbose dex2oat logging.',
76 choices=VERBOSE_OPTIONS,
77 default=None)
Ian Zerny4a2d5992018-11-08 11:42:07 +010078 return parser.parse_args()
79
80def Main():
81 (options, args) = ParseOptions()
82 if len(args) != 1:
83 print "Can only take a single dex/zip/jar/apk file as input."
84 return 1
85 if options.all and options.output:
86 print "Can't write output when running all versions."
87 return 1
88 dexfile = args[0]
89 oatfile = options.output
90 versions = VERSIONS if options.all else [options.version]
Ian Zerny4269d592019-01-16 10:40:38 +010091 verbose = [options.verbose] if options.verbose else []
92 if 'all' in verbose:
93 verbose = [x for x in VERBOSE_OPTIONS if x is not 'all']
Ian Zerny4a2d5992018-11-08 11:42:07 +010094 for version in versions:
Ian Zerny4269d592019-01-16 10:40:38 +010095 run(dexfile, oatfile, version, verbose)
Ian Zerny4a2d5992018-11-08 11:42:07 +010096 print
97 return 0
98
Ian Zerny4269d592019-01-16 10:40:38 +010099def run(dexfile, oatfile=None, version='default', verbose=[]):
Ian Zerny4a2d5992018-11-08 11:42:07 +0100100 # dex2oat accepts non-existent dex files, check here instead
101 if not os.path.exists(dexfile):
102 raise Exception('DEX file not found: "{}"'.format(dexfile))
103 with utils.TempDir() as temp:
104 if not oatfile:
105 oatfile = os.path.join(temp, "out.oat")
106 base = os.path.join(LINUX_DIR, DIRS[version])
107 product = PRODUCTS[version]
Ian Zerny08cd3862018-11-27 13:00:02 +0100108 arch = ARCHS[version]
Ian Zerny4a2d5992018-11-08 11:42:07 +0100109 cmd = [
110 os.path.join(base, 'bin', 'dex2oat'),
Ian Zerny08cd3862018-11-27 13:00:02 +0100111 '--android-root=' + os.path.join(base, 'product', product, 'system'),
Ian Zerny4a2d5992018-11-08 11:42:07 +0100112 '--runtime-arg',
113 '-Xnorelocate',
Ian Zerny4a2d5992018-11-08 11:42:07 +0100114 '--dex-file=' + dexfile,
115 '--oat-file=' + oatfile,
Ian Zerny08cd3862018-11-27 13:00:02 +0100116 '--instruction-set=' + arch,
Ian Zerny4a2d5992018-11-08 11:42:07 +0100117 ]
Ian Zerny4269d592019-01-16 10:40:38 +0100118 for flag in verbose:
119 cmd += ['--runtime-arg', '-verbose:' + flag]
Ian Zerny4a2d5992018-11-08 11:42:07 +0100120 env = {"LD_LIBRARY_PATH": os.path.join(base, 'lib')}
121 utils.PrintCmd(cmd)
122 subprocess.check_call(cmd, env = env)
123
124if __name__ == '__main__':
125 sys.exit(Main())