blob: e08c1411693358461ae260c92318b4943c1a8e5b [file] [log] [blame]
Mathias Rav3fb4a3a2018-05-29 15:41:36 +02001#!/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
6'''
7Build r8lib.jar using src/main/keep.txt and test that d8_api_usage_sample.jar
8works with the minified R8.
9'''
10
11import argparse
12import os
13import subprocess
14import toolhelper
15import utils
16
17parser = argparse.ArgumentParser(description=__doc__.strip(),
18 formatter_class=argparse.RawTextHelpFormatter)
19
20SAMPLE_JAR = os.path.join(utils.REPO_ROOT, 'tests/d8_api_usage_sample.jar')
21KEEP_RULES = os.path.join(utils.REPO_ROOT, 'src/main/keep.txt')
22R8LIB_JAR = os.path.join(utils.LIBS, 'r8lib.jar')
23R8LIB_MAP_FILE = os.path.join(utils.LIBS, 'r8lib-map.txt')
24
25API_LEVEL = 26
26ANDROID_JAR = 'third_party/android_jar/lib-v%s/android.jar' % API_LEVEL
27
28
29def build_r8lib():
30 toolhelper.run(
31 'r8',
32 ('--release',
33 '--classfile',
34 '--lib', utils.RT_JAR,
35 utils.R8_JAR,
36 '--output', R8LIB_JAR,
37 '--pg-conf', KEEP_RULES,
38 '--pg-map-output', R8LIB_MAP_FILE))
39
40
41def test_d8sample():
42 with utils.TempDir() as path:
43 args = ['java', '-cp', '%s:%s' % (R8LIB_JAR, SAMPLE_JAR),
44 'com.android.tools.apiusagesample.D8ApiUsageSample',
45 '--output', path,
46 '--min-api', str(API_LEVEL),
47 '--lib', ANDROID_JAR,
48 '--classpath', utils.R8_JAR,
49 '--main-dex-list', '/dev/null',
50 os.path.join(utils.BUILD, 'test/examples/hello.jar')]
51 utils.PrintCmd(args)
52 subprocess.check_call(args)
53
54
55def main():
56 # Handle --help
57 parser.parse_args()
58
59 build_r8lib()
60 test_d8sample()
61
62
63if __name__ == '__main__':
64 main()