コード例 #1
0
ファイル: run_on_as_app.py プロジェクト: singhaditya28/r8
def ExtractMarker(apk, temp_dir, options):
    r8_jar = os.path.join(temp_dir, 'r8.jar')
    r8lib_jar = os.path.join(temp_dir, 'r8lib.jar')

    # Use the copy of r8.jar or r8lib.jar if one is there.
    if os.path.isfile(r8_jar):
        cmd = [
            jdk.GetJavaExecutable(), '-ea', '-jar', r8_jar, 'extractmarker',
            apk
        ]
    elif os.path.isfile(r8lib_jar):
        cmd = [
            jdk.GetJavaExecutable(), '-ea', '-cp', r8lib_jar,
            'com.android.tools.r8.ExtractMarker', apk
        ]
    else:
        script = os.path.join(utils.TOOLS_DIR, 'extractmarker.py')
        cmd = ['python', script, apk]

    utils.PrintCmd(cmd, quiet=options.quiet)
    stdout = subprocess.check_output(cmd)

    # Return the last line.
    lines = stdout.strip().splitlines()
    assert len(lines) >= 1
    return lines[-1]
コード例 #2
0
def main():
    args = sys.argv[1:]
    if len(args) == 0:
        gradle.RunGradle(['r8lib'])
        r8lib = utils.R8LIB_JAR
        r8map = utils.R8LIB + '.map'
    elif len(args) == 2:
        r8lib = args[0]
        r8map = args[1]
    elif len(args) == 1 and args[0] == '--help':
        print(
            'Usage: test_self_retrace.py [<path-to-r8lib-jar> <path-to-r8lib-map]'
        )
        print('If the path is missing the script builds and uses ' +
              utils.R8LIB_JAR)
        return
    else:
        raise Exception("Only two argument allowed, see '--help'.")

    # Run 'r8 --help' which throws an exception.
    cmd = [
        jdk.GetJavaExecutable(), '-cp', r8lib, 'com.android.tools.r8.R8',
        '--help'
    ]
    os.environ["R8_THROW_EXCEPTION_FOR_TESTING_RETRACE"] = "1"
    utils.PrintCmd(cmd)
    p = subprocess.Popen(cmd, stderr=subprocess.PIPE)
    _, stacktrace = p.communicate()
    assert (p.returncode != 0)
    assert (EXCEPTION_LINE in stacktrace)
    # r8lib must be minified, original class names must not be present.
    assert ('SelfRetraceTest' not in stacktrace)

    # Run the retrace tool.
    cmd = [jdk.GetJavaExecutable(), '-jar', utils.RETRACE_JAR, r8map]
    utils.PrintCmd(cmd)
    p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
    retrace_stdout, _ = p.communicate(stacktrace)
    assert p.returncode == 0
    retrace_lines = retrace_stdout.splitlines()
    line_index = -1
    for line in retrace_lines:
        if line_index < 0:
            if 'java.lang.RuntimeException' in line:
                assert (EXCEPTION_LINE in line)
                line_index = 0
        else:
            assert EXPECTED_LINES[line_index] in line
            line_index += 1
            if line_index >= len(EXPECTED_LINES):
                break
    assert (line_index >= 0)
コード例 #3
0
def generate_jar_with_desugar_configuration(configuration, implementation,
                                            conversions, destination):
    with utils.TempDir() as tmp_dir:
        # Add conversion classes.
        with zipfile.ZipFile(conversions, 'r') as conversions_zip:
            conversions_zip.extractall(tmp_dir)

        # Add configuration
        configuration_dir = join(tmp_dir, 'META-INF', 'desugar', 'd8')
        makedirs(configuration_dir)
        copyfile(configuration, join(configuration_dir, 'desugar.json'))

        # Add lint configuartion.
        lint_dir = join(configuration_dir, 'lint')
        makedirs(lint_dir)
        cmd = [
            jdk.GetJavaExecutable(), '-cp', utils.R8_JAR,
            'com.android.tools.r8.GenerateLintFiles', configuration,
            implementation, lint_dir
        ]
        utils.PrintCmd(cmd)
        subprocess.check_call(cmd)

        make_archive(destination, 'zip', tmp_dir)
        move(destination + '.zip', destination)
コード例 #4
0
def run_retrace(options, temp):
    if options.download_benchmarks:
        download_benchmarks()
    if options.retracer == 'r8':
        retracer_args = [
            '-cp', utils.R8LIB_JAR, 'com.android.tools.r8.retrace.Retrace'
        ]
    elif options.retracer == 'proguard':
        retracer_args = ['-jar', proguard.getRetraceJar()]
    elif options.retracer == 'remapper':
        retracer_args = [
            '-jar',
            os.path.join(utils.THIRD_PARTY, 'remapper', 'remapper_deploy.jar')
        ]
    else:
        assert False, "Unexpected retracer " + options.retracer
    retrace_args = [jdk.GetJavaExecutable()] + retracer_args + [
        os.path.join(utils.THIRD_PARTY, 'retrace_benchmark', 'r8lib.jar.map'),
        os.path.join(utils.THIRD_PARTY, 'retrace_benchmark', 'stacktrace.txt')
    ]
    utils.PrintCmd(retrace_args)
    t0 = time.time()
    subprocess.check_call(retrace_args)
    t1 = time.time()
    if options.print_runtimeraw:
        print('{}(RunTimeRaw): {} ms'.format(options.print_runtimeraw,
                                             1000.0 * (t1 - t0)))
コード例 #5
0
def getCmd(args, version=DEFAULT, jvmArgs=None):
    cmd = []
    if jvmArgs:
        cmd.extend(jvmArgs)
    cmd.extend([jdk.GetJavaExecutable(), '-jar', getJar(version)])
    cmd.extend(args)
    return cmd
コード例 #6
0
ファイル: test_framework.py プロジェクト: singhaditya28/r8
def Main():
  args = parse_arguments()
  if args.golem:
    golem.link_third_party()
  utils.check_java_version()
  output_dir = args.output
  with utils.TempDir() as temp_dir:

    if not output_dir:
      output_dir = temp_dir

    xmx = None
    if args.tool == 'dx':
      tool_file = DX_JAR
      tool_args = ['--dex', '--output=' + output_dir, '--multi-dex',
                   '--min-sdk-version=' + MIN_SDK_VERSION]
      xmx = '-Xmx1600m'
    else:
      tool_file = utils.D8_JAR
      tool_args = ['--output', output_dir, '--min-api', MIN_SDK_VERSION]
      if args.tool == 'd8-release':
        tool_args.append('--release')
      xmx = '-Xmx600m'

    cmd = []

    track_memory_file = None
    if args.print_memoryuse:
      track_memory_file = os.path.join(output_dir, utils.MEMORY_USE_TMP_FILE)
      cmd.extend(['tools/track_memory.sh', track_memory_file])

    if tool_file.endswith('.jar'):
      assert xmx is not None
      cmd.extend([jdk.GetJavaExecutable(), xmx, '-jar'])

    cmd.extend([tool_file] + tool_args + [FRAMEWORK_JAR])

    utils.PrintCmd(cmd)

    t0 = time.time()
    subprocess.check_call(cmd)
    dt = time.time() - t0

    if args.print_memoryuse:
      print('{}-Total(MemoryUse): {}'
          .format(args.name, utils.grep_memoryuse(track_memory_file)))

    dex_files = [f for f in glob(os.path.join(output_dir, '*.dex'))]
    code_size = 0
    for dex_file in dex_files:
      code_size += os.path.getsize(dex_file)

    print('{}-Total(RunTimeRaw): {} ms'
      .format(args.name, 1000.0 * dt))

    print('{}-Total(CodeSize): {}'
      .format(args.name, code_size))

    utils.print_dexsegments(args.name, dex_files)
コード例 #7
0
ファイル: proguard.py プロジェクト: singhaditya28/r8
def run(args, track_memory_file = None, stdout=None, stderr=None):
  cmd = []
  if track_memory_file:
    cmd.extend(['tools/track_memory.sh', track_memory_file])
  cmd.extend([jdk.GetJavaExecutable(), '-jar', PROGUARD_JAR])
  cmd.extend(args)
  utils.PrintCmd(cmd)
  subprocess.call(cmd, stdout=stdout, stderr=stderr)
コード例 #8
0
def getR8Version(path):
    cmd = [
        jdk.GetJavaExecutable(), '-cp', path, 'com.android.tools.r8.R8',
        '--version'
    ]
    output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
    # output is on form 'R8 <version>' so we just strip of 'R8 '.
    return output.splitlines()[0][3:]
コード例 #9
0
ファイル: utils.py プロジェクト: 4455jkjh/r8
def getR8Version(path):
    cmd = [
        jdk.GetJavaExecutable(), '-cp', path, 'com.android.tools.r8.R8',
        '--version'
    ]
    output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
    # output is of the form 'R8 <version> (with additional info)'
    # so we split on '('; clean up tailing spaces; and strip off 'R8 '.
    return output.split('(')[0].strip()[3:]
コード例 #10
0
ファイル: toolhelper.py プロジェクト: 4455jkjh/r8
def run(tool,
        args,
        build=None,
        debug=True,
        profile=False,
        track_memory_file=None,
        extra_args=None,
        stderr=None,
        stdout=None,
        return_stdout=False,
        timeout=0,
        quiet=False,
        cmd_prefix=None):
    cmd = []
    if cmd_prefix:
        cmd.extend(cmd_prefix)
    if build is None:
        build, args = extract_build_from_args(args)
    if build:
        gradle.RunGradle(['r8lib' if tool.startswith('r8lib') else 'r8'])
    if track_memory_file:
        cmd.extend(['tools/track_memory.sh', track_memory_file])
    cmd.append(jdk.GetJavaExecutable())
    if extra_args:
        cmd.extend(extra_args)
    if debug:
        cmd.append('-ea')
    if profile:
        cmd.append('-agentlib:hprof=cpu=samples,interval=1,depth=8')
    if tool == 'r8lib-d8':
        cmd.extend(['-cp', utils.R8LIB_JAR, 'com.android.tools.r8.D8'])
    elif tool == 'r8lib-r8':
        cmd.extend(['-cp', utils.R8LIB_JAR, 'com.android.tools.r8.R8'])
    else:
        cmd.extend(['-jar', utils.R8_JAR, tool])
    lib, args = extract_lib_from_args(args)
    if lib:
        cmd.extend(["--lib", lib])
    cmd.extend(args)
    utils.PrintCmd(cmd, quiet=quiet)
    if timeout > 0:
        kill = lambda process: process.kill()
        proc = subprocess.Popen(cmd,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE)
        timer = Timer(timeout, kill, [proc])
        try:
            timer.start()
            stdout, stderr = proc.communicate()
        finally:
            timer.cancel()
        return stdout if return_stdout else proc.returncode
    else:
        if return_stdout:
            return subprocess.check_output(cmd)
        return subprocess.call(cmd, stdout=stdout, stderr=stderr)
コード例 #11
0
def check_java_version():
    cmd = [jdk.GetJavaExecutable(), '-version']
    output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
    m = re.search('openjdk version "([^"]*)"', output)
    if m is None:
        raise Exception("Can't check java version: no version string in output"
                        " of 'java -version': '{}'".format(output))
    version = m.groups(0)[0]
    m = re.search('google', version)
    if m is not None:
        raise Exception("Do not use google JVM for benchmarking: " + version)
コード例 #12
0
ファイル: test_helloexample.py プロジェクト: singhaditya28/r8
def GetCompilerPrefix(tool, mode, output, input, lib, extra, noopt):
    return [
        jdk.GetJavaExecutable(),
        '-jar',
        utils.R8_JAR if tool == 'r8' else utils.D8_JAR,
        '--output',
        output,
        '--lib',
        lib,
        '--debug' if noopt else '--release',
        input,
    ] + ([] if mode == 'cf' else ['--min-api', '21']) + extra
コード例 #13
0
ファイル: build_r8lib.py プロジェクト: singhaditya28/r8
def test_d8sample(paths):
  with utils.TempDir() as path:
    args = [jdk.GetJavaExecutable(),
            '-cp', '%s:%s' % (SAMPLE_JAR, ":".join(paths)),
            'com.android.tools.apiusagesample.D8ApiUsageSample',
            '--output', path,
            '--min-api', str(API_LEVEL),
            '--lib', utils.get_android_jar(API_LEVEL),
            '--classpath', utils.R8_JAR,
            '--main-dex-list', '/dev/null',
            os.path.join(utils.BUILD, 'test/examples/hello.jar')]
    utils.PrintCmd(args)
    subprocess.check_call(args)
コード例 #14
0
def run(args, build=True):
  if build:
    gradle.RunGradle(['copyMavenDeps'])
  cmd = []
  cmd.append(jdk.GetJavaExecutable())
  cp = ":".join([os.path.join(utils.REPO_ROOT, 'build/deps/asm-7.1.jar'),
                 os.path.join(utils.REPO_ROOT, 'build/deps/asm-util-7.1.jar')])
  cmd.extend(['-cp', cp])
  cmd.append('org.objectweb.asm.util.ASMifier')
  cmd.extend(args)
  utils.PrintCmd(cmd)
  result = subprocess.check_output(cmd)
  print(result)
  return result
コード例 #15
0
def RebuildAppWithShrinker(
    app, apk, apk_dest, proguard_config_file, shrinker, min_sdk, compile_sdk,
    options, temp_dir, main_dex_rules):
  assert 'r8' in shrinker
  assert apk_dest.endswith('.apk')

  print('Rebuilding {} with {}'.format(app.name, shrinker))

  # Compile given APK with shrinker to temporary zip file.
  android_jar = utils.get_android_jar(compile_sdk)
  r8_jar = os.path.join(
      temp_dir, 'r8lib.jar' if IsMinifiedR8(shrinker) else 'r8.jar')
  zip_dest = apk_dest[:-4] + '.zip'

  # TODO(christofferqa): Entry point should be CompatProguard if the shrinker
  # is 'r8'.
  entry_point = 'com.android.tools.r8.R8'

  cmd = ([jdk.GetJavaExecutable()] +
         (['-ea:com.android.tools.r8...']
          if not options.disable_assertions
          else []) +
         ['-cp', r8_jar, entry_point,
         '--release', '--min-api', str(min_sdk),
         '--pg-conf', proguard_config_file,
         '--lib', android_jar,
         '--output', zip_dest,
         apk] +
         (['--no-desugaring']
         if app.legacy_desugaring or app.compatibility == '1.7'
         else []))

  for android_optional_jar in utils.get_android_optional_jars(compile_sdk):
    cmd.append('--lib')
    cmd.append(android_optional_jar)

  if main_dex_rules:
    cmd.append('--main-dex-rules')
    cmd.append(main_dex_rules)

  utils.RunCmd(
    cmd, quiet=options.quiet, logging=IsLoggingEnabledFor(app, options))

  # Make a copy of the given APK, move the newly generated dex files into the
  # copied APK, and then sign the APK.
  apk_masseur.masseur(
      apk, dex=zip_dest, resources='META-INF/services/*', out=apk_dest,
      quiet=options.quiet, logging=IsLoggingEnabledFor(app, options),
      keystore=options.keystore)
コード例 #16
0
ファイル: build_r8lib.py プロジェクト: singhaditya28/r8
def test_r8cfcommand(paths):
  with utils.TempDir() as path:
    # SAMPLE_JAR and LIB_JAR should not have any classes in common, since e.g.
    # R8CommandParser should have been minified in LIB_JAR.
    # Just in case R8CommandParser is also present in LIB_JAR, we put
    # SAMPLE_JAR first on the classpath to use its version of R8CommandParser.
    args = [jdk.GetJavaExecutable(),
            '-cp', '%s:%s' % (SAMPLE_JAR, ":".join(paths)),
            'com.android.tools.r8.R8CommandParser',
            '--classfile',
            '--output', path + "/output.jar",
            '--lib', utils.RT_JAR,
            os.path.join(utils.BUILD, 'test/examples/hello.jar')]
    utils.PrintCmd(args)
    subprocess.check_call(args)
コード例 #17
0
def generate_jar_with_desugar_configuration(configuration, destination):
    with utils.TempDir() as tmp_dir:
        configuration_dir = join(tmp_dir, 'META-INF', 'desugar', 'd8')
        makedirs(configuration_dir)
        copyfile(configuration, join(configuration_dir, 'desugar.json'))

        lint_dir = join(configuration_dir, 'lint')
        makedirs(lint_dir)
        cmd = [
            jdk.GetJavaExecutable(), '-cp', utils.R8_JAR,
            'com.android.tools.r8.GenerateLintFiles', configuration, lint_dir
        ]
        utils.PrintCmd(cmd)
        subprocess.check_call(cmd)

        make_archive(destination, 'zip', tmp_dir)
        move(destination + '.zip', destination)
コード例 #18
0
def getDexSegmentSizes(dex_files):
    assert len(dex_files) > 0
    cmd = [jdk.GetJavaExecutable(), '-jar', R8_JAR, 'dexsegments']
    cmd.extend(dex_files)
    PrintCmd(cmd)
    output = subprocess.check_output(cmd)

    matches = DEX_SEGMENTS_RESULT_PATTERN.findall(output)

    if matches is None or len(matches) == 0:
        raise Exception('DexSegments failed to return any output for' \
            ' these files: {}'.format(dex_files))

    result = {}

    for match in matches:
        result[match[0]] = int(match[1])

    return result
コード例 #19
0
def getCfSegmentSizes(cfFile):
    cmd = [
        jdk.GetJavaExecutable(), '-cp', CF_SEGMENTS_TOOL,
        'com.android.tools.r8.cf_segments.MeasureLib', cfFile
    ]
    PrintCmd(cmd)
    output = subprocess.check_output(cmd)

    matches = DEX_SEGMENTS_RESULT_PATTERN.findall(output)

    if matches is None or len(matches) == 0:
        raise Exception('CfSegments failed to return any output for' \
                        ' the file: ' + cfFile)

    result = {}

    for match in matches:
        result[match[0]] = int(match[1])

    return result
コード例 #20
0
ファイル: toolhelper.py プロジェクト: mateuszkrzeszowiec/r8
def run_in_tests(tool, args, build=None, debug=True, extra_args=None):
  if build is None:
    build, args = extract_build_from_args(args)
  if build:
    gradle.RunGradle([
      'copyMavenDeps',
      'compileTestJava',
    ])
  cmd = []
  cmd.append(jdk.GetJavaExecutable())
  if extra_args:
    cmd.extend(extra_args)
  if debug:
    cmd.append('-ea')
  cmd.extend(['-cp', ':'.join([
    utils.BUILD_MAIN_DIR,
    utils.BUILD_TEST_DIR,
  ] + glob.glob('%s/*.jar' % utils.BUILD_DEPS_DIR))])
  cmd.extend([tool])
  cmd.extend(args)
  utils.PrintCmd(cmd)
  return subprocess.call(cmd)
コード例 #21
0
ファイル: retrace.py プロジェクト: mateuszkrzeszowiec/r8
def run(map_path,
        hash_or_version,
        stacktrace,
        is_hash,
        no_r8lib,
        quiet=False,
        debug=False):
    if hash_or_version:
        download_path = archive.GetUploadDestination(hash_or_version,
                                                     'r8lib.jar.map', is_hash)
        if utils.file_exists_on_cloud_storage(download_path):
            map_path = tempfile.NamedTemporaryFile().name
            utils.download_file_from_cloud_storage(download_path, map_path)
        else:
            print('Could not find map file from argument: %s.' %
                  hash_or_version)
            return 1

    retrace_args = [jdk.GetJavaExecutable()]

    if debug:
        retrace_args.append(
            '-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005'
        )

    retrace_args += [
        '-cp', utils.R8_JAR if no_r8lib else utils.R8LIB_JAR,
        'com.android.tools.r8.retrace.Retrace', map_path
    ]

    if quiet:
        retrace_args.append('--quiet')

    if stacktrace:
        retrace_args.append(stacktrace)

    utils.PrintCmd(retrace_args, quiet=quiet)
    return subprocess.call(retrace_args)
コード例 #22
0
ファイル: test_helloexample.py プロジェクト: singhaditya28/r8
def Compile(tool, output_mode, lib, extra, output_dir, noopt, temp_dir):
    output = os.path.join(output_dir, 'out.zip')
    if tool == 'd8':
        if output_mode != 'dex':
            raise ValueError('Invalid output mode for D8')
        classpath = []
        for cp_entry in extra:
            classpath.extend(['--classpath', cp_entry])
        return [
            GetCompilerPrefix(tool, output_mode, output, HELLO_JAR, lib,
                              classpath, noopt)
        ]
    # The compilation is either R8 or PG.
    # Write keep rules to a temporary file.
    rules = GetConfRules(extra, noopt)
    rules_file = os.path.join(temp_dir, 'rules.conf')
    open(rules_file, 'w').write('\n'.join(rules))
    if tool == 'r8':
        cmd = GetCompilerPrefix(tool, output_mode, output, HELLO_JAR, lib,
                                extra, noopt)
        cmd.extend(['--pg-conf', rules_file])
        if output_mode == 'cf':
            cmd.append('--classfile')
        return [cmd]
    if tool == 'pg':
        # Build PG invokation with additional rules to silence warnings.
        pg_out = output if output_mode == 'cf' \
          else os.path.join(output_dir, 'pgout.zip')
        cmds = [[
            jdk.GetJavaExecutable(), '-jar', utils.PROGUARD_JAR, '-injars',
            ':'.join([HELLO_JAR] + extra), '-libraryjars', lib, '-outjars',
            pg_out, '-dontwarn **', '@' + rules_file
        ]]
        if output_mode == 'dex':
            cmds.append(
                GetCompilerPrefix('d8', 'dex', output, pg_out, lib, [], noopt))
        return cmds
    raise ValueError('Unknown tool: ' + tool)
コード例 #23
0
ファイル: retrace.py プロジェクト: 4455jkjh/r8
def run(map_path, hash_or_version, stacktrace, is_hash, no_r8lib):
    if hash_or_version:
        download_path = archive.GetUploadDestination(hash_or_version,
                                                     'r8lib.jar.map', is_hash)
        if utils.file_exists_on_cloud_storage(download_path):
            map_path = tempfile.NamedTemporaryFile().name
            utils.download_file_from_cloud_storage(download_path, map_path)
        else:
            print('Could not find map file from argument: %s.' %
                  hash_or_version)
            return 1

    retrace_args = [
        jdk.GetJavaExecutable(), '-cp',
        utils.R8_JAR if no_r8lib else utils.R8LIB_JAR,
        'com.android.tools.r8.retrace.Retrace', map_path
    ]

    if stacktrace:
        retrace_args.append(stacktrace)

    utils.PrintCmd(retrace_args)
    return subprocess.call(retrace_args)
コード例 #24
0
def run1(out, args, otherargs):
    with utils.TempDir() as temp:
        if out:
            temp = out
            if not os.path.exists(temp):
                os.makedirs(temp)
        dump = read_dump(args, temp)
        if not dump.program_jar():
            error("Cannot compile dump with no program classes")
        if not dump.library_jar():
            print "WARNING: Unexpected lack of library classes in dump"
        build_properties = determine_build_properties(args, dump)
        version = determine_version(args, dump)
        compiler = determine_compiler(args, dump)
        out = determine_output(args, temp)
        min_api = determine_min_api(args, build_properties)
        jar = args.r8_jar if args.r8_jar else download_distribution(
            args, version, temp)
        wrapper_dir = prepare_wrapper(jar, temp)
        cmd = [jdk.GetJavaExecutable()]
        if args.debug_agent:
            if not args.nolib:
                print "WARNING: Running debugging agent on r8lib is questionable..."
            cmd.append(
                '-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005'
            )
        if args.xmx:
            cmd.append('-Xmx' + args.xmx)
        if args.ea:
            cmd.append('-ea')
        if args.printtimes:
            cmd.append('-Dcom.android.tools.r8.printtimes=1')
        cmd.extend(['-cp', '%s:%s' % (wrapper_dir, jar)])
        if compiler == 'd8':
            cmd.append('com.android.tools.r8.D8')
        if compiler.startswith('r8'):
            cmd.append('com.android.tools.r8.utils.CompileDumpCompatR8')
        if compiler == 'r8':
            cmd.append('--compat')
        cmd.append(dump.program_jar())
        cmd.extend(['--output', out])
        for feature_jar in dump.feature_jars():
            cmd.extend([
                '--feature-jar', feature_jar,
                determine_feature_output(feature_jar, temp)
            ])
        if dump.library_jar():
            cmd.extend(['--lib', dump.library_jar()])
        if dump.classpath_jar():
            cmd.extend(['--classpath', dump.classpath_jar()])
        if compiler != 'd8' and dump.config_file():
            cmd.extend(['--pg-conf', dump.config_file()])
        if compiler != 'd8':
            cmd.extend(['--pg-map-output', '%s.map' % out])
        if min_api:
            cmd.extend(['--min-api', min_api])
        if args.threads:
            cmd.extend(['--threads', args.threads])
        cmd.extend(otherargs)
        utils.PrintCmd(cmd)
        try:
            print subprocess.check_output(cmd, stderr=subprocess.STDOUT)
            return 0
        except subprocess.CalledProcessError, e:
            print e.output
            if not args.nolib:
                stacktrace = os.path.join(temp, 'stacktrace')
                open(stacktrace, 'w+').write(e.output)
                local_map = utils.R8LIB_MAP if version == 'master' else None
                hash_or_version = None if version == 'master' else version
                print "=" * 80
                print " RETRACED OUTPUT"
                print "=" * 80
                retrace.run(local_map, hash_or_version, stacktrace,
                            is_hash(version))
            return 1
コード例 #25
0
def Main(argv):
    options = parse_arguments(argv)
    if options.golem:
        golem.link_third_party()
    utils.check_java_version()
    outdir = options.out

    if options.app == 'gmscore':
        version = 'v10'
        data = gmscore_data
        base = data.V10_BASE
    elif options.app == 'youtube':
        version = '12.22'
        data = youtube_data
        base = data.V12_22_BASE
    else:
        raise Exception('Unexpected')

    args = ['-forceprocessing']

    if not outdir.endswith('.zip') and not outdir.endswith('.jar') \
        and not exists(outdir):
        makedirs(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)
    os.chmod(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)
        proguard.run(args,
                     version='pg_internal',
                     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
    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.sh', 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])
        utils.PrintCmd(cmd)
        check_call(cmd)
        if options.print_memoryuse:
            dx_memoryuse = utils.grep_memoryuse(track_memory_file)
            print('{}(MemoryUse): {}'.format(
                options.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)
コード例 #26
0
def GetToolVersion(jar_path):
    # TODO(mkroghj) This would not work for r8-lib, maybe use utils.getR8Version.
    output = subprocess.check_output(
        [jdk.GetJavaExecutable(), '-jar', jar_path, '--version'])
    return output.splitlines()[0].strip()
コード例 #27
0
def run(args):
  cmd = [jdk.GetJavaExecutable()] + args
  utils.PrintCmd(cmd)
  result = subprocess.check_output(cmd)
  print result
  return result
コード例 #28
0
def run1(out, args, otherargs):
    with utils.TempDir() as temp:
        if out:
            temp = out
            if not os.path.exists(temp):
                os.makedirs(temp)
        dump = read_dump(args, temp)
        if not dump.program_jar():
            error("Cannot compile dump with no program classes")
        if not dump.library_jar():
            print("WARNING: Unexpected lack of library classes in dump")
        build_properties = determine_build_properties(args, dump)
        version = determine_version(args, dump)
        compiler = determine_compiler(args, dump)
        out = determine_output(args, temp)
        min_api = determine_min_api(args, build_properties)
        classfile = determine_class_file(args, build_properties)
        jar = args.r8_jar if args.r8_jar else download_distribution(
            args, version, temp)
        if ':' not in jar and not os.path.exists(jar):
            error("Distribution does not exist: " + jar)
        wrapper_dir = prepare_wrapper(jar, temp)
        cmd = [jdk.GetJavaExecutable()]
        if args.debug_agent:
            if not args.nolib:
                print(
                    "WARNING: Running debugging agent on r8lib is questionable..."
                )
            cmd.append(
                '-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005'
            )
        if args.xmx:
            cmd.append('-Xmx' + args.xmx)
        if args.ea:
            cmd.append('-ea')
        if args.printtimes:
            cmd.append('-Dcom.android.tools.r8.printtimes=1')
        if hasattr(args, 'properties'):
            cmd.extend(args.properties)
        cmd.extend(['-cp', '%s:%s' % (wrapper_dir, jar)])
        if compiler == 'd8':
            cmd.append('com.android.tools.r8.D8')
        if compiler.startswith('r8'):
            cmd.append('com.android.tools.r8.utils.CompileDumpCompatR8')
        if compiler == 'r8':
            cmd.append('--compat')
        # For recompilation of dumps run_on_app_dumps pass in a program jar.
        cmd.append(determine_program_jar(args, dump))
        cmd.extend(['--output', out])
        for feature_jar in dump.feature_jars():
            cmd.extend([
                '--feature-jar', feature_jar,
                determine_feature_output(feature_jar, temp)
            ])
        if dump.library_jar():
            cmd.extend(['--lib', dump.library_jar()])
        if dump.classpath_jar():
            cmd.extend(['--classpath', dump.classpath_jar()])
        if dump.desugared_library_json() and not args.disable_desugared_lib:
            cmd.extend(['--desugared-lib', dump.desugared_library_json()])
        if compiler != 'd8' and dump.config_file():
            if hasattr(args,
                       'config_file_consumer') and args.config_file_consumer:
                args.config_file_consumer(dump.config_file())
            cmd.extend(['--pg-conf', dump.config_file()])
        if dump.main_dex_rules_resource():
            cmd.extend(['--main-dex-rules', dump.main_dex_rules_resource()])
        if compiler != 'd8':
            cmd.extend(['--pg-map-output', '%s.map' % out])
        if min_api:
            cmd.extend(['--min-api', min_api])
        if classfile:
            cmd.extend(['--classfile'])
        if args.threads:
            cmd.extend(['--threads', args.threads])
        cmd.extend(otherargs)
        utils.PrintCmd(cmd)
        try:
            print(subprocess.check_output(cmd, stderr=subprocess.STDOUT))
            return 0
        except subprocess.CalledProcessError as e:
            if not args.nolib and version != 'source':
                stacktrace = os.path.join(temp, 'stacktrace')
                open(stacktrace, 'w+').write(e.output.decode('UTF-8'))
                local_map = utils.R8LIB_MAP if version == 'master' else None
                hash_or_version = None if version == 'master' else version
                print("=" * 80)
                print(" RETRACED OUTPUT")
                print("=" * 80)
                retrace.run(local_map,
                            hash_or_version,
                            stacktrace,
                            is_hash(version),
                            no_r8lib=False)
            else:
                print(e.output.decode('UTF-8'))
            return 1