aboutsummaryrefslogtreecommitdiff
path: root/tools/test_aosp_jar.py
blob: 79a584a9ee63b4df3dbacc32ea13fea005d992a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/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.

# Test prebuilt AOSP jar files: compile with D8 and run dex2out to validate

from __future__ import print_function
from glob import glob
from itertools import chain
from os.path import join
import argparse
import os
import subprocess
import sys

import gradle

import utils

REPLAY_SCRIPT_DIR = join(utils.REPO_ROOT, 'third_party',
    'android_cts_baseline', 'dx_replay')
REPLAY_SCRIPT = join(REPLAY_SCRIPT_DIR, 'replay_script.py')
OUT_DIR = join(REPLAY_SCRIPT_DIR, 'out')

def parse_arguments():
  parser = argparse.ArgumentParser(
      description = 'Run D8 (CompatDX) and dex2oat on prebuilt AOSP jars.')
  parser.add_argument('--no-build', default = False, action = 'store_true')
  return parser.parse_args()

def Main():

  utils.check_java_version()
  args = parse_arguments()

  if not args.no_build:
    gradle.RunGradle(['CompatDx'])

  cmd = [REPLAY_SCRIPT, 'java', '-jar', utils.COMPATDX_JAR]
  utils.PrintCmd(cmd)
  subprocess.check_call(cmd)

  # collect dex files below OUT_DIR
  dex_files = (chain.from_iterable(glob(join(x[0], '*.dex'))
      for x in os.walk(OUT_DIR)))

  for dex_file in dex_files:
      utils.verify_with_dex2oat(dex_file)


if __name__ == '__main__':
  sys.exit(Main())