Mathias Rav | 3fb4a3a | 2018-05-29 15:41:36 +0200 | [diff] [blame^] | 1 | #!/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 | ''' |
| 7 | Build r8lib.jar using src/main/keep.txt and test that d8_api_usage_sample.jar |
| 8 | works with the minified R8. |
| 9 | ''' |
| 10 | |
| 11 | import argparse |
| 12 | import os |
| 13 | import subprocess |
| 14 | import toolhelper |
| 15 | import utils |
| 16 | |
| 17 | parser = argparse.ArgumentParser(description=__doc__.strip(), |
| 18 | formatter_class=argparse.RawTextHelpFormatter) |
| 19 | |
| 20 | SAMPLE_JAR = os.path.join(utils.REPO_ROOT, 'tests/d8_api_usage_sample.jar') |
| 21 | KEEP_RULES = os.path.join(utils.REPO_ROOT, 'src/main/keep.txt') |
| 22 | R8LIB_JAR = os.path.join(utils.LIBS, 'r8lib.jar') |
| 23 | R8LIB_MAP_FILE = os.path.join(utils.LIBS, 'r8lib-map.txt') |
| 24 | |
| 25 | API_LEVEL = 26 |
| 26 | ANDROID_JAR = 'third_party/android_jar/lib-v%s/android.jar' % API_LEVEL |
| 27 | |
| 28 | |
| 29 | def 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 | |
| 41 | def 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 | |
| 55 | def main(): |
| 56 | # Handle --help |
| 57 | parser.parse_args() |
| 58 | |
| 59 | build_r8lib() |
| 60 | test_d8sample() |
| 61 | |
| 62 | |
| 63 | if __name__ == '__main__': |
| 64 | main() |