Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 1 | #!/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 | |
Tamas Kenez | fc34cd8 | 2017-07-13 12:43:57 +0200 | [diff] [blame] | 6 | from __future__ import print_function |
Tamas Kenez | 02bff03 | 2017-07-18 12:13:58 +0200 | [diff] [blame] | 7 | from glob import glob |
Rico Wind | b57bbc1 | 2018-09-20 19:23:32 +0200 | [diff] [blame] | 8 | import copy |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 9 | import optparse |
| 10 | import os |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 11 | import sys |
Tamas Kenez | f2ee2a3 | 2017-06-21 10:30:20 +0200 | [diff] [blame] | 12 | import time |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 13 | |
Søren Gjesse | 5ecb04a | 2017-06-13 09:44:32 +0200 | [diff] [blame] | 14 | import gmail_data |
Ian Zerny | 877c186 | 2017-07-06 11:12:26 +0200 | [diff] [blame] | 15 | import gmscore_data |
Rico Wind | 1f4172c | 2018-09-06 16:29:03 +0200 | [diff] [blame] | 16 | import golem |
Christoffer Quist Adamsen | a2a5877 | 2018-10-03 09:47:46 +0200 | [diff] [blame] | 17 | import nest_data |
Mathias Rav | dd6a6de | 2018-05-18 10:18:33 +0200 | [diff] [blame] | 18 | import toolhelper |
Ian Zerny | 877c186 | 2017-07-06 11:12:26 +0200 | [diff] [blame] | 19 | import utils |
| 20 | import youtube_data |
Rico Wind | 86bfc83 | 2018-09-18 07:48:21 +0200 | [diff] [blame] | 21 | import chrome_data |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 22 | |
| 23 | TYPES = ['dex', 'deploy', 'proguarded'] |
Christoffer Quist Adamsen | a2a5877 | 2018-10-03 09:47:46 +0200 | [diff] [blame] | 24 | APPS = ['gmscore', 'nest', 'youtube', 'gmail', 'chrome'] |
Tamas Kenez | a730a7e | 2018-12-10 15:02:28 +0100 | [diff] [blame] | 25 | COMPILERS = ['d8', 'r8', 'r8lib-r8', 'r8lib-d8'] |
| 26 | R8_COMPILERS = ['r8', 'r8lib-r8'] |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 27 | |
Tamas Kenez | 5b1c585 | 2017-07-21 13:38:33 +0200 | [diff] [blame] | 28 | def ParseOptions(argv): |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 29 | result = optparse.OptionParser() |
Søren Gjesse | 932881f | 2017-06-13 10:43:36 +0200 | [diff] [blame] | 30 | result.add_option('--compiler', |
Rico Wind | b57bbc1 | 2018-09-20 19:23:32 +0200 | [diff] [blame] | 31 | help='The compiler to use', |
Tamas Kenez | 5b1c585 | 2017-07-21 13:38:33 +0200 | [diff] [blame] | 32 | choices=COMPILERS) |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 33 | result.add_option('--app', |
Rico Wind | b57bbc1 | 2018-09-20 19:23:32 +0200 | [diff] [blame] | 34 | help='What app to run on', |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 35 | choices=APPS) |
Rico Wind | b57bbc1 | 2018-09-20 19:23:32 +0200 | [diff] [blame] | 36 | result.add_option('--run-all', |
| 37 | help='Compile all possible combinations', |
| 38 | default=False, |
| 39 | action='store_true') |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 40 | result.add_option('--type', |
Tamas Kenez | 3fdaabd | 2017-06-15 13:05:12 +0200 | [diff] [blame] | 41 | help='Default for R8: deploy, for D8: proguarded', |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 42 | choices=TYPES) |
| 43 | result.add_option('--out', |
Rico Wind | b57bbc1 | 2018-09-20 19:23:32 +0200 | [diff] [blame] | 44 | help='Where to place the output', |
Rico Wind | e9485ba | 2018-10-01 07:04:16 +0200 | [diff] [blame] | 45 | default=utils.BUILD) |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 46 | result.add_option('--no-build', |
Rico Wind | b57bbc1 | 2018-09-20 19:23:32 +0200 | [diff] [blame] | 47 | help='Run without building first', |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 48 | default=False, |
| 49 | action='store_true') |
Rico Wind | 1f4172c | 2018-09-06 16:29:03 +0200 | [diff] [blame] | 50 | result.add_option('--golem', |
Rico Wind | b57bbc1 | 2018-09-20 19:23:32 +0200 | [diff] [blame] | 51 | help='Running on golem, do not build or download', |
Rico Wind | 1f4172c | 2018-09-06 16:29:03 +0200 | [diff] [blame] | 52 | default=False, |
| 53 | action='store_true') |
Rico Wind | 139eece | 2018-09-25 09:42:09 +0200 | [diff] [blame] | 54 | result.add_option('--ignore-java-version', |
| 55 | help='Do not check java version', |
| 56 | default=False, |
| 57 | action='store_true') |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 58 | result.add_option('--no-libraries', |
Rico Wind | b57bbc1 | 2018-09-20 19:23:32 +0200 | [diff] [blame] | 59 | help='Do not pass in libraries, even if they exist in conf', |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 60 | default=False, |
| 61 | action='store_true') |
| 62 | result.add_option('--no-debug', |
| 63 | help='Run without debug asserts.', |
| 64 | default=False, |
| 65 | action='store_true') |
| 66 | result.add_option('--version', |
Rico Wind | b57bbc1 | 2018-09-20 19:23:32 +0200 | [diff] [blame] | 67 | help='The version of the app to run') |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 68 | result.add_option('-k', |
| 69 | help='Override the default ProGuard keep rules') |
Tamas Kenez | 139acc1 | 2017-06-14 17:14:58 +0200 | [diff] [blame] | 70 | result.add_option('--compiler-flags', |
| 71 | help='Additional option(s) for the compiler. ' + |
| 72 | 'If passing several options use a quoted string.') |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 73 | result.add_option('--r8-flags', |
Tamas Kenez | 139acc1 | 2017-06-14 17:14:58 +0200 | [diff] [blame] | 74 | help='Additional option(s) for the compiler. ' + |
Tamas Kenez | fc34cd8 | 2017-07-13 12:43:57 +0200 | [diff] [blame] | 75 | 'Same as --compiler-flags, keeping it for backward' |
| 76 | ' compatibility. ' + |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 77 | 'If passing several options use a quoted string.') |
Tamas Kenez | fc34cd8 | 2017-07-13 12:43:57 +0200 | [diff] [blame] | 78 | # TODO(tamaskenez) remove track-memory-to-file as soon as we updated golem |
| 79 | # to use --print-memoryuse instead |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 80 | result.add_option('--track-memory-to-file', |
| 81 | help='Track how much memory the jvm is using while ' + |
| 82 | ' compiling. Output to the specified file.') |
| 83 | result.add_option('--profile', |
| 84 | help='Profile R8 run.', |
| 85 | default=False, |
| 86 | action='store_true') |
| 87 | result.add_option('--dump-args-file', |
| 88 | help='Dump a file with the arguments for the specified ' + |
| 89 | 'configuration. For use as a @<file> argument to perform ' + |
| 90 | 'the run.') |
Tamas Kenez | f2ee2a3 | 2017-06-21 10:30:20 +0200 | [diff] [blame] | 91 | result.add_option('--print-runtimeraw', |
| 92 | metavar='BENCHMARKNAME', |
Tamas Kenez | 02bff03 | 2017-07-18 12:13:58 +0200 | [diff] [blame] | 93 | help='Print the line \'<BENCHMARKNAME>(RunTimeRaw):' + |
| 94 | ' <elapsed> ms\' at the end where <elapsed> is' + |
| 95 | ' the elapsed time in milliseconds.') |
Tamas Kenez | fc34cd8 | 2017-07-13 12:43:57 +0200 | [diff] [blame] | 96 | result.add_option('--print-memoryuse', |
| 97 | metavar='BENCHMARKNAME', |
Tamas Kenez | 02bff03 | 2017-07-18 12:13:58 +0200 | [diff] [blame] | 98 | help='Print the line \'<BENCHMARKNAME>(MemoryUse):' + |
| 99 | ' <mem>\' at the end where <mem> is the peak' + |
| 100 | ' peak resident set size (VmHWM) in bytes.') |
| 101 | result.add_option('--print-dexsegments', |
| 102 | metavar='BENCHMARKNAME', |
| 103 | help='Print the sizes of individual dex segments as ' + |
| 104 | '\'<BENCHMARKNAME>-<segment>(CodeSize): <bytes>\'') |
Tamas Kenez | 5b1c585 | 2017-07-21 13:38:33 +0200 | [diff] [blame] | 105 | return result.parse_args(argv) |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 106 | |
Søren Gjesse | 5945958 | 2018-04-06 10:12:45 +0200 | [diff] [blame] | 107 | # Most apps have the -printmapping, -printseeds and -printusage in the |
| 108 | # Proguard configuration. However we don't want to write these files |
| 109 | # in the locations specified. Instead generate an auxiliary Proguard |
| 110 | # configuration placing these two output files together with the dex |
| 111 | # output. |
Søren Gjesse | 3a5aed9 | 2017-06-14 15:36:02 +0200 | [diff] [blame] | 112 | def GenerateAdditionalProguardConfiguration(temp, outdir): |
| 113 | name = "output.config" |
Tamas Kenez | fc34cd8 | 2017-07-13 12:43:57 +0200 | [diff] [blame] | 114 | with open(os.path.join(temp, name), 'w') as f: |
| 115 | f.write('-printmapping ' + os.path.join(outdir, 'proguard.map') + "\n") |
| 116 | f.write('-printseeds ' + os.path.join(outdir, 'proguard.seeds') + "\n") |
Søren Gjesse | 5945958 | 2018-04-06 10:12:45 +0200 | [diff] [blame] | 117 | f.write('-printusage ' + os.path.join(outdir, 'proguard.usage') + "\n") |
Tamas Kenez | fc34cd8 | 2017-07-13 12:43:57 +0200 | [diff] [blame] | 118 | return os.path.abspath(f.name) |
Søren Gjesse | 3a5aed9 | 2017-06-14 15:36:02 +0200 | [diff] [blame] | 119 | |
Rico Wind | 3f9302b | 2018-09-21 08:53:09 +0200 | [diff] [blame] | 120 | # Please add bug number for disabled permutations and please explicitly |
| 121 | # do Bug: #BUG in the commit message of disabling to ensure re-enabling |
| 122 | DISABLED_PERMUTATIONS = [ |
Ian Zerny | d459b5f | 2018-10-03 06:46:21 +0200 | [diff] [blame] | 123 | # (app, version, type), e.g., ('gmail', '180826.15', 'deploy'), |
Rico Wind | 3f9302b | 2018-09-21 08:53:09 +0200 | [diff] [blame] | 124 | ] |
| 125 | |
Rico Wind | b57bbc1 | 2018-09-20 19:23:32 +0200 | [diff] [blame] | 126 | def get_permutations(): |
| 127 | data_providers = { |
| 128 | 'gmscore': gmscore_data, |
Christoffer Quist Adamsen | a2a5877 | 2018-10-03 09:47:46 +0200 | [diff] [blame] | 129 | 'nest': nest_data, |
Rico Wind | b57bbc1 | 2018-09-20 19:23:32 +0200 | [diff] [blame] | 130 | 'youtube': youtube_data, |
| 131 | 'chrome': chrome_data, |
| 132 | 'gmail': gmail_data |
| 133 | } |
| 134 | # Check to ensure that we add all variants here. |
| 135 | assert len(APPS) == len(data_providers) |
| 136 | for app, data in data_providers.iteritems(): |
| 137 | for version in data.VERSIONS: |
| 138 | for type in data.VERSIONS[version]: |
Rico Wind | 3f9302b | 2018-09-21 08:53:09 +0200 | [diff] [blame] | 139 | if (app, version, type) not in DISABLED_PERMUTATIONS: |
Tamas Kenez | a730a7e | 2018-12-10 15:02:28 +0100 | [diff] [blame] | 140 | for use_r8lib in [False, True]: |
| 141 | yield app, version, type, use_r8lib |
Rico Wind | b57bbc1 | 2018-09-20 19:23:32 +0200 | [diff] [blame] | 142 | |
| 143 | def run_all(options, args): |
| 144 | # Args will be destroyed |
| 145 | assert len(args) == 0 |
Tamas Kenez | a730a7e | 2018-12-10 15:02:28 +0100 | [diff] [blame] | 146 | for name, version, type, use_r8lib in get_permutations(): |
Rico Wind | b57bbc1 | 2018-09-20 19:23:32 +0200 | [diff] [blame] | 147 | compiler = 'r8' if type == 'deploy' else 'd8' |
Tamas Kenez | a730a7e | 2018-12-10 15:02:28 +0100 | [diff] [blame] | 148 | if use_r8lib: |
| 149 | compiler = 'r8lib-' + compiler |
| 150 | print('Executing %s with %s %s %s' % (compiler, name, version, type)) |
| 151 | |
Rico Wind | b57bbc1 | 2018-09-20 19:23:32 +0200 | [diff] [blame] | 152 | fixed_options = copy.copy(options) |
| 153 | fixed_options.app = name |
| 154 | fixed_options.version = version |
| 155 | fixed_options.compiler = compiler |
| 156 | fixed_options.type = type |
| 157 | exit_code = run_with_options(fixed_options, []) |
| 158 | if exit_code != 0: |
| 159 | print('Failed %s %s %s with %s' % (name, version, type, compiler)) |
| 160 | exit(exit_code) |
| 161 | |
Tamas Kenez | 5b1c585 | 2017-07-21 13:38:33 +0200 | [diff] [blame] | 162 | def main(argv): |
Tamas Kenez | 5b1c585 | 2017-07-21 13:38:33 +0200 | [diff] [blame] | 163 | (options, args) = ParseOptions(argv) |
Rico Wind | 139eece | 2018-09-25 09:42:09 +0200 | [diff] [blame] | 164 | if not options.ignore_java_version: |
| 165 | utils.check_java_version() |
| 166 | |
Rico Wind | b57bbc1 | 2018-09-20 19:23:32 +0200 | [diff] [blame] | 167 | if options.run_all: |
| 168 | return run_all(options, args) |
| 169 | return run_with_options(options, args) |
| 170 | |
| 171 | def run_with_options(options, args): |
| 172 | app_provided_pg_conf = False; |
Rico Wind | 1f4172c | 2018-09-06 16:29:03 +0200 | [diff] [blame] | 173 | if options.golem: |
| 174 | golem.link_third_party() |
Rico Wind | 9bd3f5f | 2018-10-01 10:53:18 +0200 | [diff] [blame] | 175 | options.out = os.getcwd() |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 176 | outdir = options.out |
| 177 | data = None |
| 178 | if options.app == 'gmscore': |
| 179 | options.version = options.version or 'v9' |
| 180 | data = gmscore_data |
Christoffer Quist Adamsen | a2a5877 | 2018-10-03 09:47:46 +0200 | [diff] [blame] | 181 | elif options.app == 'nest': |
| 182 | options.version = options.version or '20180926' |
| 183 | data = nest_data |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 184 | elif options.app == 'youtube': |
Søren Gjesse | cc33fb4 | 2017-06-09 10:25:08 +0200 | [diff] [blame] | 185 | options.version = options.version or '12.22' |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 186 | data = youtube_data |
Rico Wind | 86bfc83 | 2018-09-18 07:48:21 +0200 | [diff] [blame] | 187 | elif options.app == 'chrome': |
| 188 | options.version = options.version or 'default' |
| 189 | data = chrome_data |
Søren Gjesse | 5ecb04a | 2017-06-13 09:44:32 +0200 | [diff] [blame] | 190 | elif options.app == 'gmail': |
| 191 | options.version = options.version or '170604.16' |
| 192 | data = gmail_data |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 193 | else: |
Tamas Kenez | 5b1c585 | 2017-07-21 13:38:33 +0200 | [diff] [blame] | 194 | raise Exception("You need to specify '--app={}'".format('|'.join(APPS))) |
| 195 | |
| 196 | if options.compiler not in COMPILERS: |
| 197 | raise Exception("You need to specify '--compiler={}'" |
| 198 | .format('|'.join(COMPILERS))) |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 199 | |
| 200 | if not options.version in data.VERSIONS.keys(): |
Tamas Kenez | fc34cd8 | 2017-07-13 12:43:57 +0200 | [diff] [blame] | 201 | print('No version {} for application {}' |
| 202 | .format(options.version, options.app)) |
| 203 | print('Valid versions are {}'.format(data.VERSIONS.keys())) |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 204 | return 1 |
| 205 | |
| 206 | version = data.VERSIONS[options.version] |
| 207 | |
Tamas Kenez | 3fdaabd | 2017-06-15 13:05:12 +0200 | [diff] [blame] | 208 | if not options.type: |
Tamas Kenez | a730a7e | 2018-12-10 15:02:28 +0100 | [diff] [blame] | 209 | options.type = 'deploy' if options.compiler in R8_COMPILERS \ |
Tamas Kenez | 3fdaabd | 2017-06-15 13:05:12 +0200 | [diff] [blame] | 210 | else 'proguarded' |
| 211 | |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 212 | if options.type not in version: |
Tamas Kenez | fc34cd8 | 2017-07-13 12:43:57 +0200 | [diff] [blame] | 213 | print('No type {} for version {}'.format(options.type, options.version)) |
| 214 | print('Valid types are {}'.format(version.keys())) |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 215 | return 1 |
| 216 | values = version[options.type] |
| 217 | inputs = None |
Tamas Kenez | fc34cd8 | 2017-07-13 12:43:57 +0200 | [diff] [blame] | 218 | # For R8 'deploy' the JAR is located using the Proguard configuration |
Christoffer Quist Adamsen | a2a5877 | 2018-10-03 09:47:46 +0200 | [diff] [blame] | 219 | # -injars option. For chrome and nest we don't have the injars in the |
| 220 | # proguard files. |
Tamas Kenez | a730a7e | 2018-12-10 15:02:28 +0100 | [diff] [blame] | 221 | if 'inputs' in values and (options.compiler not in R8_COMPILERS |
Rico Wind | 86bfc83 | 2018-09-18 07:48:21 +0200 | [diff] [blame] | 222 | or options.type != 'deploy' |
Christoffer Quist Adamsen | a2a5877 | 2018-10-03 09:47:46 +0200 | [diff] [blame] | 223 | or options.app == 'chrome' |
| 224 | or options.app == 'nest'): |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 225 | inputs = values['inputs'] |
| 226 | |
| 227 | args.extend(['--output', outdir]) |
Ian Zerny | 877c186 | 2017-07-06 11:12:26 +0200 | [diff] [blame] | 228 | if 'min-api' in values: |
| 229 | args.extend(['--min-api', values['min-api']]) |
Søren Gjesse | 932881f | 2017-06-13 10:43:36 +0200 | [diff] [blame] | 230 | |
Søren Gjesse | 8ae55eb | 2018-09-28 11:11:36 +0200 | [diff] [blame] | 231 | if 'main-dex-list' in values: |
| 232 | args.extend(['--main-dex-list', values['main-dex-list']]) |
| 233 | |
Tamas Kenez | a730a7e | 2018-12-10 15:02:28 +0100 | [diff] [blame] | 234 | if options.compiler in R8_COMPILERS: |
Søren Gjesse | 932881f | 2017-06-13 10:43:36 +0200 | [diff] [blame] | 235 | if 'pgconf' in values and not options.k: |
| 236 | for pgconf in values['pgconf']: |
| 237 | args.extend(['--pg-conf', pgconf]) |
Søren Gjesse | da2ac8d | 2017-06-22 14:14:36 +0200 | [diff] [blame] | 238 | app_provided_pg_conf = True |
Søren Gjesse | 932881f | 2017-06-13 10:43:36 +0200 | [diff] [blame] | 239 | if options.k: |
| 240 | args.extend(['--pg-conf', options.k]) |
Søren Gjesse | c801ecc | 2017-08-03 13:40:06 +0200 | [diff] [blame] | 241 | if 'maindexrules' in values: |
| 242 | for rules in values['maindexrules']: |
| 243 | args.extend(['--main-dex-rules', rules]) |
Søren Gjesse | 932881f | 2017-06-13 10:43:36 +0200 | [diff] [blame] | 244 | |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 245 | if not options.no_libraries and 'libraries' in values: |
| 246 | for lib in values['libraries']: |
| 247 | args.extend(['--lib', lib]) |
| 248 | |
Tamas Kenez | fc34cd8 | 2017-07-13 12:43:57 +0200 | [diff] [blame] | 249 | if not outdir.endswith('.zip') and not outdir.endswith('.jar') \ |
| 250 | and not os.path.exists(outdir): |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 251 | os.makedirs(outdir) |
| 252 | |
Søren Gjesse | 8ae55eb | 2018-09-28 11:11:36 +0200 | [diff] [blame] | 253 | # Additional flags for the compiler from the configuration file. |
| 254 | if 'flags' in values: |
| 255 | args.extend(values['flags'].split(' ')) |
Tamas Kenez | a730a7e | 2018-12-10 15:02:28 +0100 | [diff] [blame] | 256 | if options.compiler in R8_COMPILERS: |
Søren Gjesse | 932881f | 2017-06-13 10:43:36 +0200 | [diff] [blame] | 257 | if 'r8-flags' in values: |
| 258 | args.extend(values['r8-flags'].split(' ')) |
Tamas Kenez | 139acc1 | 2017-06-14 17:14:58 +0200 | [diff] [blame] | 259 | |
Søren Gjesse | 8ae55eb | 2018-09-28 11:11:36 +0200 | [diff] [blame] | 260 | # Additional flags for the compiler from the command line. |
Tamas Kenez | 139acc1 | 2017-06-14 17:14:58 +0200 | [diff] [blame] | 261 | if options.compiler_flags: |
| 262 | args.extend(options.compiler_flags.split(' ')) |
| 263 | if options.r8_flags: |
| 264 | args.extend(options.r8_flags.split(' ')) |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 265 | |
| 266 | if inputs: |
| 267 | args.extend(inputs) |
| 268 | |
Tamas Kenez | f2ee2a3 | 2017-06-21 10:30:20 +0200 | [diff] [blame] | 269 | t0 = time.time() |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 270 | if options.dump_args_file: |
| 271 | with open(options.dump_args_file, 'w') as args_file: |
| 272 | args_file.writelines([arg + os.linesep for arg in args]) |
| 273 | else: |
Tamas Kenez | fc34cd8 | 2017-07-13 12:43:57 +0200 | [diff] [blame] | 274 | with utils.TempDir() as temp: |
| 275 | if options.print_memoryuse and not options.track_memory_to_file: |
| 276 | options.track_memory_to_file = os.path.join(temp, |
| 277 | utils.MEMORY_USE_TMP_FILE) |
Tamas Kenez | a730a7e | 2018-12-10 15:02:28 +0100 | [diff] [blame] | 278 | if options.compiler in R8_COMPILERS and app_provided_pg_conf: |
Mathias Rav | dd6a6de | 2018-05-18 10:18:33 +0200 | [diff] [blame] | 279 | # Ensure that output of -printmapping and -printseeds go to the output |
| 280 | # location and not where the app Proguard configuration places them. |
| 281 | if outdir.endswith('.zip') or outdir.endswith('.jar'): |
| 282 | pg_outdir = os.path.dirname(outdir) |
| 283 | else: |
| 284 | pg_outdir = outdir |
| 285 | additional_pg_conf = GenerateAdditionalProguardConfiguration( |
| 286 | temp, os.path.abspath(pg_outdir)) |
| 287 | args.extend(['--pg-conf', additional_pg_conf]) |
Rico Wind | 1f4172c | 2018-09-06 16:29:03 +0200 | [diff] [blame] | 288 | build = not options.no_build and not options.golem |
Christoffer Quist Adamsen | 21c6660 | 2018-08-09 16:22:54 +0200 | [diff] [blame] | 289 | exit_code = toolhelper.run(options.compiler, args, |
Rico Wind | 1f4172c | 2018-09-06 16:29:03 +0200 | [diff] [blame] | 290 | build=build, |
Mathias Rav | dd6a6de | 2018-05-18 10:18:33 +0200 | [diff] [blame] | 291 | debug=not options.no_debug, |
| 292 | profile=options.profile, |
Mathias Rav | a4042f5 | 2018-05-23 09:58:58 +0200 | [diff] [blame] | 293 | track_memory_file=options.track_memory_to_file) |
Christoffer Quist Adamsen | 21c6660 | 2018-08-09 16:22:54 +0200 | [diff] [blame] | 294 | if exit_code != 0: |
| 295 | return exit_code |
| 296 | |
Tamas Kenez | fc34cd8 | 2017-07-13 12:43:57 +0200 | [diff] [blame] | 297 | if options.print_memoryuse: |
| 298 | print('{}(MemoryUse): {}' |
| 299 | .format(options.print_memoryuse, |
| 300 | utils.grep_memoryuse(options.track_memory_to_file))) |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 301 | |
Tamas Kenez | f2ee2a3 | 2017-06-21 10:30:20 +0200 | [diff] [blame] | 302 | if options.print_runtimeraw: |
| 303 | print('{}(RunTimeRaw): {} ms' |
| 304 | .format(options.print_runtimeraw, 1000.0 * (time.time() - t0))) |
| 305 | |
Tamas Kenez | 02bff03 | 2017-07-18 12:13:58 +0200 | [diff] [blame] | 306 | if options.print_dexsegments: |
| 307 | dex_files = glob(os.path.join(outdir, '*.dex')) |
| 308 | utils.print_dexsegments(options.print_dexsegments, dex_files) |
Rico Wind | b57bbc1 | 2018-09-20 19:23:32 +0200 | [diff] [blame] | 309 | return 0 |
Tamas Kenez | 02bff03 | 2017-07-18 12:13:58 +0200 | [diff] [blame] | 310 | |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 311 | if __name__ == '__main__': |
Tamas Kenez | 5b1c585 | 2017-07-21 13:38:33 +0200 | [diff] [blame] | 312 | sys.exit(main(sys.argv[1:])) |