Zachary Turner | b6355cc | 2018-11-02 17:49:01 +0000 | [diff] [blame] | 1 | # -*- Python -*- |
| 2 | |
| 3 | import os |
| 4 | import sys |
| 5 | import re |
| 6 | import platform |
| 7 | import subprocess |
| 8 | |
| 9 | |
| 10 | import lit.util |
| 11 | import lit.formats |
| 12 | from lit.llvm import llvm_config |
| 13 | from lit.llvm.subst import FindTool |
| 14 | from lit.llvm.subst import ToolSubst |
| 15 | |
| 16 | # name: The name of this test suite. |
| 17 | config.name = 'LLDB' |
| 18 | |
| 19 | # testFormat: The test format to use to interpret tests. |
| 20 | config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell) |
| 21 | |
| 22 | # suffixes: A list of file extensions to treat as test files. This is overriden |
| 23 | # by individual lit.local.cfg files in the test subdirectories. |
| 24 | config.suffixes = ['.test', '.cpp', '.s'] |
| 25 | |
| 26 | # excludes: A list of directories to exclude from the testsuite. The 'Inputs' |
| 27 | # subdirectories contain auxiliary inputs for various tests in their parent |
| 28 | # directories. |
| 29 | config.excludes = ['Inputs', 'CMakeLists.txt', 'README.txt', 'LICENSE.txt'] |
| 30 | |
| 31 | # test_source_root: The root path where tests are located. |
| 32 | config.test_source_root = os.path.dirname(__file__) |
| 33 | |
| 34 | # test_exec_root: The root path where tests should be run. |
| 35 | config.test_exec_root = os.path.join(config.lldb_obj_root, 'lit') |
| 36 | |
| 37 | # Tweak the PATH to include the tools dir. |
| 38 | llvm_config.with_system_environment('PATH') |
| 39 | llvm_config.with_environment('PATH', config.lldb_tools_dir, append_path=True) |
| 40 | llvm_config.with_environment('PATH', config.llvm_tools_dir, append_path=True) |
| 41 | |
| 42 | llvm_config.with_environment('LD_LIBRARY_PATH', config.lldb_libs_dir, append_path=True) |
| 43 | llvm_config.with_environment('LD_LIBRARY_PATH', config.llvm_libs_dir, append_path=True) |
| 44 | llvm_config.with_system_environment('LD_LIBRARY_PATH', append_path=True) |
| 45 | |
| 46 | |
| 47 | llvm_config.use_default_substitutions() |
| 48 | |
| 49 | if platform.system() in ['Darwin']: |
| 50 | debugserver = lit.util.which('debugserver', config.lldb_tools_dir) |
| 51 | else: |
| 52 | debugserver = lit.util.which('lldb-server', config.lldb_tools_dir) |
| 53 | lldb = "%s -S %s/lit-lldb-init" % (lit.util.which('lldb', config.lldb_tools_dir), |
| 54 | config.test_source_root) |
| 55 | |
| 56 | lldbmi = lit.util.which('lldb-mi', config.lldb_tools_dir) |
| 57 | if lldbmi: |
| 58 | config.available_features.add('lldb-mi') |
| 59 | |
| 60 | config.cc = llvm_config.use_llvm_tool(config.cc, required=True) |
| 61 | config.cxx = llvm_config.use_llvm_tool(config.cxx, required=True) |
| 62 | |
| 63 | if platform.system() in ['Darwin']: |
| 64 | try: |
| 65 | out = subprocess.check_output(['xcrun', '--show-sdk-path']).strip() |
| 66 | res = 0 |
| 67 | except OSError: |
| 68 | res = -1 |
| 69 | if res == 0 and out: |
| 70 | sdk_path = lit.util.to_string(out) |
| 71 | lit_config.note('using SDKROOT: %r' % sdk_path) |
| 72 | config.cc += " -isysroot %s" % sdk_path |
| 73 | config.cxx += " -isysroot %s" % sdk_path |
| 74 | |
| 75 | if platform.system() in ['OpenBSD']: |
| 76 | config.cc += " -pthread" |
| 77 | config.cxx += " -pthread" |
| 78 | |
| 79 | config.substitutions.append(('%cc', config.cc)) |
| 80 | config.substitutions.append(('%cxx', config.cxx)) |
| 81 | |
| 82 | if lldbmi: |
| 83 | config.substitutions.append(('%lldbmi', lldbmi + " --synchronous")) |
| 84 | config.substitutions.append(('%lldb', lldb)) |
| 85 | |
| 86 | if debugserver is not None: |
| 87 | if platform.system() in ['Darwin']: |
| 88 | config.substitutions.append(('%debugserver', debugserver)) |
| 89 | else: |
| 90 | config.substitutions.append(('%debugserver', debugserver + ' gdbserver')) |
| 91 | |
| 92 | tools = ['lldb-test', 'yaml2obj', 'obj2yaml', 'llvm-pdbutil'] |
| 93 | llvm_config.add_tool_substitutions(tools, [config.llvm_tools_dir, config.lldb_tools_dir]) |
| 94 | |
| 95 | if re.match(r'^arm(hf.*-linux)|(.*-linux-gnuabihf)', config.target_triple): |
| 96 | config.available_features.add("armhf-linux") |
| 97 | |
| 98 | print("config.cc = {}".format(config.cc)) |
| 99 | if re.match(r'icc', config.cc): |
| 100 | config.available_features.add("compiler-icc") |
| 101 | elif re.match(r'clang', config.cc): |
| 102 | config.available_features.add("compiler-clang") |
| 103 | elif re.match(r'gcc', config.cc): |
| 104 | config.available_features.add("compiler-gcc") |
| 105 | elif re.match(r'cl', config.cc): |
| 106 | config.available_features.add("compiler-msvc") |
| 107 | |
| 108 | if config.have_lld: |
| 109 | config.available_features.add("lld") |
| 110 | |
| 111 | def calculate_arch_features(arch_string): |
| 112 | # This will add a feature such as x86, arm, mips, etc for each built |
| 113 | # target |
| 114 | features = [] |
| 115 | for arch in arch_string.split(): |
| 116 | features.append(arch.lower()) |
| 117 | return features |
| 118 | |
| 119 | # Run llvm-config and add automatically add features for whether we have |
| 120 | # assertions enabled, whether we are in debug mode, and what targets we |
| 121 | # are built for. |
| 122 | llvm_config.feature_config( |
| 123 | [('--assertion-mode', {'ON': 'asserts'}), |
| 124 | ('--build-mode', {'DEBUG': 'debug'}), |
| 125 | ('--targets-built', calculate_arch_features) |
| 126 | ]) |