blob: c485ed2e5cd047485f3c9d87889affa611d7ffaf [file] [log] [blame]
#!/usr/bin/env python
# Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
# Run ProGuard and the DX or CompatDX (= D8) tool on GmsCore V10.
from __future__ import print_function
from glob import glob
from os import makedirs
from os.path import exists, join, splitext
from subprocess import check_call
import argparse
import fnmatch
import gmscore_data
import jdk
import os
import stat
import sys
import time
import gmail_data
import gmscore_data
import golem
import proguard
import utils
import youtube_data
APPS = ['gmscore', 'youtube']
DX_JAR = join(utils.REPO_ROOT, 'tools', 'linux', 'dx', 'framework', 'dx.jar')
def parse_arguments(argv):
parser = argparse.ArgumentParser(
description = 'Run ProGuard and the DX tool on GmsCore V10.')
parser.add_argument('--app', required = True, choices = APPS)
help = 'Output directory for the DX tool.',
default = os.getcwd())
help = 'Use CompatDx (D8) instead of DX.',
default = False,
action = 'store_true')
help = 'Link in third party dependencies.',
default = False,
action = 'store_true')
metavar = 'BENCHMARKNAME',
help = 'Print the line \'<BENCHMARKNAME>(RunTimeRaw): <elapsed>' +
' ms\' at the end where <elapsed> is the elapsed time in' +
' milliseconds.')
help='Print the line \'<BENCHMARKNAME>(MemoryUse):' +
' <mem>\' at the end where <mem> is the peak' +
' peak resident set size (VmHWM) in bytes.')
metavar = 'BENCHMARKNAME',
help = 'Print the sizes of individual dex segments as ' +
'\'<BENCHMARKNAME>-<segment>(CodeSize): <bytes>\'')
return parser.parse_args(argv)
def Main(argv):
options = parse_arguments(argv)
if options.golem:
outdir = options.out
if == 'gmscore':
version = 'v10'
data = gmscore_data
base = data.V10_BASE
elif == 'youtube':
version = '12.22'
data = youtube_data
base = data.V12_22_BASE
raise Exception('Unexpected')
args = ['-forceprocessing']
if not outdir.endswith('.zip') and not outdir.endswith('.jar') \
and not exists(outdir):
values_deploy = data.VERSIONS[version]['deploy']
values_proguarded = data.VERSIONS[version]['proguarded']
assert 'pgconf' in values_deploy
for pgconf in values_deploy['pgconf']:
args.extend(['@' + pgconf])
# find seeds file
inputs = data.VERSIONS[version]['proguarded']['inputs']
assert len(inputs) == 1
basename_wo_ext = splitext(os.path.basename(inputs[0]))[0]
seeds_filename = basename_wo_ext + '.seeds'
seeds_files = []
for root, dirnames, filenames in os.walk(join(base, 'blaze-out')):
for filename in fnmatch.filter(filenames, seeds_filename):
seeds_files.append(os.path.join(root, filename))
assert len(seeds_files) == 1
seeds_path = seeds_files[0]
proguarded_jar_path = splitext(seeds_path)[0] + '.jar'
# Remove write-protection from seeds file. The seeds file is an output of
# ProGuard so it aborts if this is not writeable.
st = os.stat(seeds_path)
st.st_mode | stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH)
t0 = time.time()
proguard_memoryuse = None
with utils.TempDir() as temp:
track_memory_file = None
if options.print_memoryuse:
track_memory_file = join(temp, utils.MEMORY_USE_TMP_FILE)
track_memory_file = track_memory_file,
stdout=open(os.devnull, 'w'))
if options.print_memoryuse:
proguard_memoryuse = utils.grep_memoryuse(track_memory_file)
# run dex on the result
if options.compatdx:
jar = utils.COMPATDX_JAR
jar = DX_JAR
with utils.TempDir() as temp:
track_memory_file = None
cmd = []
if options.print_memoryuse:
track_memory_file = join(temp, utils.MEMORY_USE_TMP_FILE)
cmd.extend(['tools/', track_memory_file])
cmd.extend([jdk.GetJavaExecutable(), '-jar', jar, '--multi-dex',
'--output=' + outdir])
if 'min-api' in values_proguarded:
cmd.append('--min-sdk-version=' + values_proguarded['min-api'])
cmd.extend(['--dex', proguarded_jar_path])
if options.print_memoryuse:
dx_memoryuse = utils.grep_memoryuse(track_memory_file)
print('{}(MemoryUse): {}'
max(proguard_memoryuse, dx_memoryuse)))
if options.print_runtimeraw:
print('{}(RunTimeRaw): {} ms'
.format(options.print_runtimeraw, 1000.0 * (time.time() - t0)))
if options.print_dexsegments:
dex_files = glob(os.path.join(outdir, '*.dex'))
utils.print_dexsegments(options.print_dexsegments, dex_files)
if __name__ == '__main__':