blob: 938f343badcc26b980466852ac706d96f668dd46 [file] [log] [blame]
Zachary Turnercba522d2018-11-19 16:41:31 +00001import os
Zachary Turnerba968c02018-12-01 00:22:21 +00002import itertools
Zachary Turner58db03a2018-11-19 15:12:34 +00003import platform
4import subprocess
5import sys
6
7import lit.util
8from lit.llvm import llvm_config
9from lit.llvm.subst import FindTool
10from lit.llvm.subst import ToolSubst
11
12def use_lldb_substitutions(config):
13 # Set up substitutions for primary tools. These tools must come from config.lldb_tools_dir
14 # which is basically the build output directory. We do not want to find these in path or
15 # anywhere else, since they are specifically the programs which are actually being tested.
16
17 dsname = 'debugserver' if platform.system() in ['Darwin'] else 'lldb-server'
18 dsargs = [] if platform.system() in ['Darwin'] else ['gdbserver']
19 lldbmi = ToolSubst('%lldbmi',
20 command=FindTool('lldb-mi'),
21 extra_args=['--synchronous'],
22 unresolved='ignore')
Zachary Turnercb6788d2018-12-04 21:48:27 +000023
24
Zachary Turnerba968c02018-12-01 00:22:21 +000025 build_script = os.path.dirname(__file__)
26 build_script = os.path.join(build_script, 'build.py')
27 build_script_args = [build_script,
28 '--compiler=any', # Default to best compiler
Zachary Turnercb6788d2018-12-04 21:48:27 +000029 '--arch=' + str(config.lldb_bitness)]
Zachary Turnerba968c02018-12-01 00:22:21 +000030 if config.lldb_lit_tools_dir:
31 build_script_args.append('--tools-dir={0}'.format(config.lldb_lit_tools_dir))
32 if config.lldb_tools_dir:
33 build_script_args.append('--tools-dir={0}'.format(config.lldb_tools_dir))
Zachary Turnercb6788d2018-12-04 21:48:27 +000034
Zachary Turner58db03a2018-11-19 15:12:34 +000035 primary_tools = [
36 ToolSubst('%lldb',
37 command=FindTool('lldb'),
38 extra_args=['-S',
39 os.path.join(config.test_source_root,
40 'lit-lldb-init')]),
41 lldbmi,
42 ToolSubst('%debugserver',
43 command=FindTool(dsname),
44 extra_args=dsargs,
45 unresolved='ignore'),
Zachary Turnerba968c02018-12-01 00:22:21 +000046 'lldb-test',
47 ToolSubst('%build',
48 command="'" + sys.executable + "'",
49 extra_args=build_script_args)
Zachary Turner58db03a2018-11-19 15:12:34 +000050 ]
51
52 llvm_config.add_tool_substitutions(primary_tools,
53 [config.lldb_tools_dir])
54 if lldbmi.was_resolved:
55 config.available_features.add('lldb-mi')
56
57def _use_msvc_substitutions(config):
58 # If running from a Visual Studio Command prompt (e.g. vcvars), this will
59 # detect the include and lib paths, and find cl.exe and link.exe and create
60 # substitutions for each of them that explicitly specify /I and /L paths
Zachary Turner47066bd2018-11-19 16:47:06 +000061 cl = lit.util.which('cl')
62 link = lit.util.which('link')
Zachary Turner58db03a2018-11-19 15:12:34 +000063
64 if not cl or not link:
65 return
66
Zachary Turner47066bd2018-11-19 16:47:06 +000067 cl = '"' + cl + '"'
68 link = '"' + link + '"'
Zachary Turner58db03a2018-11-19 15:12:34 +000069 includes = os.getenv('INCLUDE', '').split(';')
70 libs = os.getenv('LIB', '').split(';')
71
72 config.available_features.add('msvc')
73 compiler_flags = ['"/I{}"'.format(x) for x in includes if os.path.exists(x)]
74 linker_flags = ['"/LIBPATH:{}"'.format(x) for x in libs if os.path.exists(x)]
75
76 tools = [
77 ToolSubst('%msvc_cl', command=cl, extra_args=compiler_flags),
78 ToolSubst('%msvc_link', command=link, extra_args=linker_flags)]
79 llvm_config.add_tool_substitutions(tools)
80 return
81
82def use_support_substitutions(config):
83 # Set up substitutions for support tools. These tools can be overridden at the CMake
84 # level (by specifying -DLLDB_LIT_TOOLS_DIR), installed, or as a last resort, we can use
85 # the just-built version.
86 flags = []
87 if platform.system() in ['Darwin']:
88 try:
89 out = subprocess.check_output(['xcrun', '--show-sdk-path']).strip()
90 res = 0
91 except OSError:
92 res = -1
93 if res == 0 and out:
94 sdk_path = lit.util.to_string(out)
Davide Italianoff81ffd2018-11-26 17:39:20 +000095 llvm_config.lit_config.note('using SDKROOT: %r' % sdk_path)
Zachary Turner58db03a2018-11-19 15:12:34 +000096 flags = ['-isysroot', sdk_path]
Stella Stamenova839a0cb2018-11-21 20:16:06 +000097 elif platform.system() in ['OpenBSD', 'Linux']:
Zachary Turner58db03a2018-11-19 15:12:34 +000098 flags = ['-pthread']
99
100
101 additional_tool_dirs=[]
102 if config.lldb_lit_tools_dir:
103 additional_tool_dirs.append(config.lldb_lit_tools_dir)
104
105 llvm_config.use_clang(additional_flags=flags,
106 additional_tool_dirs=additional_tool_dirs,
107 required=True)
108
109 if sys.platform == 'win32':
110 _use_msvc_substitutions(config)
111
112 have_lld = llvm_config.use_lld(additional_tool_dirs=additional_tool_dirs,
113 required=False)
114 if have_lld:
115 config.available_features.add('lld')
116
117
118 support_tools = ['yaml2obj', 'obj2yaml', 'llvm-pdbutil',
119 'llvm-mc', 'llvm-readobj', 'llvm-objdump',
120 'llvm-objcopy']
121 additional_tool_dirs += [config.lldb_tools_dir, config.llvm_tools_dir]
122 llvm_config.add_tool_substitutions(support_tools, additional_tool_dirs)