blob: 9b78ba35c16e624b49860d9010936de103764788 [file] [log] [blame]
Zachary Turnerb6355cc2018-11-02 17:49:01 +00001# -*- Python -*-
2
3import os
4import sys
5import re
6import platform
7import subprocess
8
9
10import lit.util
11import lit.formats
12from lit.llvm import llvm_config
13from lit.llvm.subst import FindTool
14from lit.llvm.subst import ToolSubst
15
16# name: The name of this test suite.
17config.name = 'LLDB'
18
19# testFormat: The test format to use to interpret tests.
20config.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.
24config.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.
29config.excludes = ['Inputs', 'CMakeLists.txt', 'README.txt', 'LICENSE.txt']
30
31# test_source_root: The root path where tests are located.
32config.test_source_root = os.path.dirname(__file__)
33
34# test_exec_root: The root path where tests should be run.
35config.test_exec_root = os.path.join(config.lldb_obj_root, 'lit')
36
37# Tweak the PATH to include the tools dir.
38llvm_config.with_system_environment('PATH')
39llvm_config.with_environment('PATH', config.lldb_tools_dir, append_path=True)
40llvm_config.with_environment('PATH', config.llvm_tools_dir, append_path=True)
41
42llvm_config.with_environment('LD_LIBRARY_PATH', config.lldb_libs_dir, append_path=True)
43llvm_config.with_environment('LD_LIBRARY_PATH', config.llvm_libs_dir, append_path=True)
44llvm_config.with_system_environment('LD_LIBRARY_PATH', append_path=True)
45
46
47llvm_config.use_default_substitutions()
48
49if platform.system() in ['Darwin']:
50 debugserver = lit.util.which('debugserver', config.lldb_tools_dir)
51else:
52 debugserver = lit.util.which('lldb-server', config.lldb_tools_dir)
53lldb = "%s -S %s/lit-lldb-init" % (lit.util.which('lldb', config.lldb_tools_dir),
54 config.test_source_root)
55
56lldbmi = lit.util.which('lldb-mi', config.lldb_tools_dir)
57if lldbmi:
58 config.available_features.add('lldb-mi')
59
60config.cc = llvm_config.use_llvm_tool(config.cc, required=True)
61config.cxx = llvm_config.use_llvm_tool(config.cxx, required=True)
62
63if 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
75if platform.system() in ['OpenBSD']:
76 config.cc += " -pthread"
77 config.cxx += " -pthread"
78
79config.substitutions.append(('%cc', config.cc))
80config.substitutions.append(('%cxx', config.cxx))
81
82if lldbmi:
83 config.substitutions.append(('%lldbmi', lldbmi + " --synchronous"))
84config.substitutions.append(('%lldb', lldb))
85
86if 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
92tools = ['lldb-test', 'yaml2obj', 'obj2yaml', 'llvm-pdbutil']
93llvm_config.add_tool_substitutions(tools, [config.llvm_tools_dir, config.lldb_tools_dir])
94
95if re.match(r'^arm(hf.*-linux)|(.*-linux-gnuabihf)', config.target_triple):
96 config.available_features.add("armhf-linux")
97
98print("config.cc = {}".format(config.cc))
99if re.match(r'icc', config.cc):
100 config.available_features.add("compiler-icc")
101elif re.match(r'clang', config.cc):
102 config.available_features.add("compiler-clang")
103elif re.match(r'gcc', config.cc):
104 config.available_features.add("compiler-gcc")
105elif re.match(r'cl', config.cc):
106 config.available_features.add("compiler-msvc")
107
108if config.have_lld:
109 config.available_features.add("lld")
110
111def 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.
122llvm_config.feature_config(
123 [('--assertion-mode', {'ON': 'asserts'}),
124 ('--build-mode', {'DEBUG': 'debug'}),
125 ('--targets-built', calculate_arch_features)
126 ])