blob: ce22c25180e8a1cf64ae86e06303672f2003a99a [file] [log] [blame]
Zachary Turnercba522d2018-11-19 16:41:31 +00001import os
Zachary Turner58db03a2018-11-19 15:12:34 +00002import platform
3import subprocess
4import sys
5
6import lit.util
7from lit.llvm import llvm_config
8from lit.llvm.subst import FindTool
9from lit.llvm.subst import ToolSubst
10
11def use_lldb_substitutions(config):
12 # Set up substitutions for primary tools. These tools must come from config.lldb_tools_dir
13 # which is basically the build output directory. We do not want to find these in path or
14 # anywhere else, since they are specifically the programs which are actually being tested.
15
16 dsname = 'debugserver' if platform.system() in ['Darwin'] else 'lldb-server'
17 dsargs = [] if platform.system() in ['Darwin'] else ['gdbserver']
18 lldbmi = ToolSubst('%lldbmi',
19 command=FindTool('lldb-mi'),
20 extra_args=['--synchronous'],
21 unresolved='ignore')
22 primary_tools = [
23 ToolSubst('%lldb',
24 command=FindTool('lldb'),
25 extra_args=['-S',
26 os.path.join(config.test_source_root,
27 'lit-lldb-init')]),
28 lldbmi,
29 ToolSubst('%debugserver',
30 command=FindTool(dsname),
31 extra_args=dsargs,
32 unresolved='ignore'),
33 'lldb-test'
34 ]
35
36 llvm_config.add_tool_substitutions(primary_tools,
37 [config.lldb_tools_dir])
38 if lldbmi.was_resolved:
39 config.available_features.add('lldb-mi')
40
41def _use_msvc_substitutions(config):
42 # If running from a Visual Studio Command prompt (e.g. vcvars), this will
43 # detect the include and lib paths, and find cl.exe and link.exe and create
44 # substitutions for each of them that explicitly specify /I and /L paths
Zachary Turner47066bd2018-11-19 16:47:06 +000045 cl = lit.util.which('cl')
46 link = lit.util.which('link')
Zachary Turner58db03a2018-11-19 15:12:34 +000047
48 if not cl or not link:
49 return
50
Zachary Turner47066bd2018-11-19 16:47:06 +000051 cl = '"' + cl + '"'
52 link = '"' + link + '"'
Zachary Turner58db03a2018-11-19 15:12:34 +000053 includes = os.getenv('INCLUDE', '').split(';')
54 libs = os.getenv('LIB', '').split(';')
55
56 config.available_features.add('msvc')
57 compiler_flags = ['"/I{}"'.format(x) for x in includes if os.path.exists(x)]
58 linker_flags = ['"/LIBPATH:{}"'.format(x) for x in libs if os.path.exists(x)]
59
60 tools = [
61 ToolSubst('%msvc_cl', command=cl, extra_args=compiler_flags),
62 ToolSubst('%msvc_link', command=link, extra_args=linker_flags)]
63 llvm_config.add_tool_substitutions(tools)
64 return
65
66def use_support_substitutions(config):
67 # Set up substitutions for support tools. These tools can be overridden at the CMake
68 # level (by specifying -DLLDB_LIT_TOOLS_DIR), installed, or as a last resort, we can use
69 # the just-built version.
70 flags = []
71 if platform.system() in ['Darwin']:
72 try:
73 out = subprocess.check_output(['xcrun', '--show-sdk-path']).strip()
74 res = 0
75 except OSError:
76 res = -1
77 if res == 0 and out:
78 sdk_path = lit.util.to_string(out)
79 lit_config.note('using SDKROOT: %r' % sdk_path)
80 flags = ['-isysroot', sdk_path]
81 elif platform.system() in ['OpenBSD']:
82 flags = ['-pthread']
83
84
85 additional_tool_dirs=[]
86 if config.lldb_lit_tools_dir:
87 additional_tool_dirs.append(config.lldb_lit_tools_dir)
88
89 llvm_config.use_clang(additional_flags=flags,
90 additional_tool_dirs=additional_tool_dirs,
91 required=True)
92
93 if sys.platform == 'win32':
94 _use_msvc_substitutions(config)
95
96 have_lld = llvm_config.use_lld(additional_tool_dirs=additional_tool_dirs,
97 required=False)
98 if have_lld:
99 config.available_features.add('lld')
100
101
102 support_tools = ['yaml2obj', 'obj2yaml', 'llvm-pdbutil',
103 'llvm-mc', 'llvm-readobj', 'llvm-objdump',
104 'llvm-objcopy']
105 additional_tool_dirs += [config.lldb_tools_dir, config.llvm_tools_dir]
106 llvm_config.add_tool_substitutions(support_tools, additional_tool_dirs)