Dan Albert | b434402 | 2015-10-14 14:41:54 -0700 | [diff] [blame] | 1 | # |
| 2 | # Copyright (C) 2015 The Android Open Source Project |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # |
| 16 | from __future__ import print_function |
| 17 | |
| 18 | import argparse |
| 19 | import os |
| 20 | import subprocess |
| 21 | import sys |
| 22 | |
| 23 | |
| 24 | THIS_DIR = os.path.dirname(os.path.realpath(__file__)) |
| 25 | ANDROID_DIR = os.path.realpath(os.path.join(THIS_DIR, '../..')) |
| 26 | |
| 27 | |
| 28 | class ArgParser(argparse.ArgumentParser): |
| 29 | def __init__(self): |
| 30 | super(ArgParser, self).__init__() |
| 31 | self.add_argument( |
| 32 | '--compiler', choices=('clang', 'gcc'), default='clang') |
| 33 | self.add_argument( |
| 34 | '--bitness', choices=(32, 64), type=int, default=32) |
| 35 | self.add_argument('--host', action='store_true') |
| 36 | |
| 37 | |
| 38 | def gen_test_config(bitness, compiler, host): |
| 39 | testconfig_mk_path = os.path.join(THIS_DIR, 'buildcmds/testconfig.mk') |
| 40 | with open(testconfig_mk_path, 'w') as test_config: |
| 41 | if compiler == 'clang': |
| 42 | print('LOCAL_CLANG := true', file=test_config) |
| 43 | elif compiler == 'gcc': |
| 44 | print('LOCAL_CLANG := false', file=test_config) |
| 45 | |
| 46 | if bitness == 32: |
| 47 | print('LOCAL_MULTILIB := 32', file=test_config) |
| 48 | elif bitness == 64: |
| 49 | print('LOCAL_MULTILIB := 64', file=test_config) |
| 50 | |
| 51 | if compiler == 'clang': |
| 52 | print('LOCAL_CXX := $(LOCAL_PATH)/buildcmdscc $(CLANG_CXX)', |
| 53 | file=test_config) |
| 54 | else: |
| 55 | if host: |
| 56 | prefix = 'HOST_' |
| 57 | else: |
| 58 | prefix = 'TARGET_' |
| 59 | print('LOCAL_CXX := $(LOCAL_PATH)/buildcmdscc ' |
| 60 | '$($(LOCAL_2ND_ARCH_VAR_PREFIX){}CXX)'.format(prefix), |
| 61 | file=test_config) |
| 62 | |
| 63 | if host: |
| 64 | print('include $(BUILD_HOST_EXECUTABLE)', file=test_config) |
| 65 | else: |
| 66 | print('include $(BUILD_EXECUTABLE)', file=test_config) |
| 67 | |
| 68 | |
| 69 | def mmm(path): |
| 70 | makefile = os.path.join(path, 'Android.mk') |
| 71 | main_mk = 'build/core/main.mk' |
| 72 | |
| 73 | env = dict(os.environ) |
| 74 | env['ONE_SHOT_MAKEFILE'] = makefile |
| 75 | env['LIBCXX_TESTING'] = 'true' |
| 76 | cmd = ['make', '-C', ANDROID_DIR, '-f', main_mk, 'all_modules'] |
| 77 | subprocess.check_call(cmd, env=env) |
| 78 | |
| 79 | |
| 80 | def gen_build_cmds(bitness, compiler, host): |
| 81 | gen_test_config(bitness, compiler, host) |
| 82 | mmm(os.path.join(THIS_DIR, 'buildcmds')) |
| 83 | |
| 84 | |
| 85 | def main(): |
| 86 | args, lit_args = ArgParser().parse_known_args() |
| 87 | lit_path = os.path.join(ANDROID_DIR, 'external/llvm/utils/lit/lit.py') |
| 88 | gen_build_cmds(args.bitness, args.compiler, args.host) |
| 89 | |
| 90 | mode_str = 'host' if args.host else 'device' |
| 91 | android_mode_arg = '--param=android_mode=' + mode_str |
| 92 | test_path = os.path.join(THIS_DIR, 'test') |
| 93 | |
| 94 | lit_args = ['-sv', android_mode_arg] + lit_args |
| 95 | cmd = ['python', lit_path] + lit_args + [test_path] |
| 96 | sys.exit(subprocess.call(cmd)) |
| 97 | |
| 98 | |
| 99 | if __name__ == '__main__': |
| 100 | main() |