9 from lit
.formats
import ShTest
10 from lit
.llvm
import llvm_config
11 from lit
.llvm
.subst
import FindTool
12 from lit
.llvm
.subst
import ToolSubst
16 def _get_lldb_init_path(config
):
17 return os
.path
.join(config
.test_exec_root
, "lit-lldb-init-quiet")
20 def _disallow(config
, execName
):
22 echo '*** Do not use \'{0}\' in tests; use \'%''{0}\'. ***' &&
25 config
.substitutions
.append((" {0} ".format(execName
), warning
.format(execName
)))
28 def get_lldb_args(config
, suffix
=""):
30 if "remote-linux" in config
.available_features
:
33 '"platform select remote-linux"',
35 f
'"platform connect {config.lldb_platform_url}"',
37 if config
.lldb_platform_working_dir
:
38 dir = posixpath
.join(f
"{config.lldb_platform_working_dir}", "shell")
40 dir += posixpath
.join(dir, f
"{suffix}")
43 f
'"platform shell mkdir -p {dir}"',
45 f
'"platform settings -w {dir}"',
47 lldb_args
+= ["--no-lldbinit", "-S", _get_lldb_init_path(config
)]
51 class ShTestLldb(ShTest
):
53 self
, execute_external
=False, extra_substitutions
=[], preamble_commands
=[]
55 super().__init
__(execute_external
, extra_substitutions
, preamble_commands
)
57 def execute(self
, test
, litConfig
):
58 # Run each Shell test in a separate directory (on remote).
60 # Find directory change command in %lldb substitution.
61 for i
, t
in enumerate(test
.config
.substitutions
):
62 if re
.match(t
[0], "%lldb"):
64 if '-O "platform settings -w ' in cmd
:
65 # If command is present, it is added by get_lldb_args.
66 # Replace the path with the tests' path in suite.
69 # -O "platform shell mkdir -p /home/user/shell"
70 # -O "platform settings -w /home/user/shell" ...
73 # -O "platform shell mkdir -p /home/user/shell/SymbolFile/Breakpad/inline-record.test"
74 # -O "platform settings -w /home/user/shell/SymbolFile/Breakpad/inline-record.test" ...
75 args_def
= " ".join(get_lldb_args(test
.config
))
76 args_unique
= " ".join(
79 posixpath
.join(*test
.path_in_suite
),
82 test
.config
.substitutions
[i
] = (
84 cmd
.replace(args_def
, args_unique
),
87 return super().execute(test
, litConfig
)
90 def use_lldb_substitutions(config
):
91 # Set up substitutions for primary tools. These tools must come from config.lldb_tools_dir
92 # which is basically the build output directory. We do not want to find these in path or
93 # anywhere else, since they are specifically the programs which are actually being tested.
95 dsname
= "debugserver" if platform
.system() in ["Darwin"] else "lldb-server"
96 dsargs
= [] if platform
.system() in ["Darwin"] else ["gdbserver"]
98 build_script
= os
.path
.dirname(__file__
)
99 build_script
= os
.path
.join(build_script
, "build.py")
100 build_script_args
= [
103 "--compiler=clang" if config
.enable_remote
else "--compiler=any"
104 ), # Default to best compiler
105 "--arch=" + str(config
.lldb_bitness
),
107 if config
.lldb_lit_tools_dir
:
108 build_script_args
.append("--tools-dir={0}".format(config
.lldb_lit_tools_dir
))
109 if config
.lldb_tools_dir
:
110 build_script_args
.append("--tools-dir={0}".format(config
.lldb_tools_dir
))
111 if config
.llvm_libs_dir
:
112 build_script_args
.append("--libs-dir={0}".format(config
.llvm_libs_dir
))
113 if config
.objc_gnustep_dir
:
114 build_script_args
.append(
115 '--objc-gnustep-dir="{0}"'.format(config
.objc_gnustep_dir
)
117 if config
.cmake_sysroot
:
118 build_script_args
.append("--sysroot={0}".format(config
.cmake_sysroot
))
120 lldb_init
= _get_lldb_init_path(config
)
125 command
=FindTool("lldb"),
126 extra_args
=get_lldb_args(config
),
131 command
=FindTool("lldb"),
132 extra_args
=["-S", lldb_init
],
137 command
=FindTool("lldb"),
138 extra_args
=["--no-lldbinit"],
143 command
=FindTool("lldb-server"),
149 command
=FindTool(dsname
),
155 command
=FindTool("lldb-server"),
156 extra_args
=["platform"],
162 "%build", command
="'" + sys
.executable
+ "'", extra_args
=build_script_args
166 _disallow(config
, "lldb")
167 _disallow(config
, "lldb-server")
168 _disallow(config
, "debugserver")
169 _disallow(config
, "platformserver")
171 llvm_config
.add_tool_substitutions(primary_tools
, [config
.lldb_tools_dir
])
174 def _use_msvc_substitutions(config
):
175 # If running from a Visual Studio Command prompt (e.g. vcvars), this will
176 # detect the include and lib paths, and find cl.exe and link.exe and create
177 # substitutions for each of them that explicitly specify /I and /L paths
178 cl
= lit
.util
.which("cl")
183 # Don't use lit.util.which() for link.exe: In `git bash`, it will pick
184 # up /usr/bin/link (another name for ln).
185 link
= os
.path
.join(os
.path
.dirname(cl
), "link.exe")
188 link
= '"' + link
+ '"'
189 includes
= os
.getenv("INCLUDE", "").split(";")
190 libs
= os
.getenv("LIB", "").split(";")
192 config
.available_features
.add("msvc")
193 compiler_flags
= ['"/I{}"'.format(x
) for x
in includes
if os
.path
.exists(x
)]
194 linker_flags
= ['"/LIBPATH:{}"'.format(x
) for x
in libs
if os
.path
.exists(x
)]
197 ToolSubst("%msvc_cl", command
=cl
, extra_args
=compiler_flags
),
198 ToolSubst("%msvc_link", command
=link
, extra_args
=linker_flags
),
200 llvm_config
.add_tool_substitutions(tools
)
204 def use_support_substitutions(config
):
205 # Set up substitutions for support tools. These tools can be overridden at the CMake
206 # level (by specifying -DLLDB_LIT_TOOLS_DIR), installed, or as a last resort, we can use
207 # the just-built version.
208 if config
.enable_remote
:
209 host_flags
= ["--target=" + config
.target_triple
]
211 host_flags
= ["--target=" + config
.host_triple
]
212 if platform
.system() in ["Darwin"]:
214 out
= subprocess
.check_output(["xcrun", "--show-sdk-path"]).strip()
219 sdk_path
= lit
.util
.to_string(out
)
220 llvm_config
.lit_config
.note("using SDKROOT: %r" % sdk_path
)
221 host_flags
+= ["-isysroot", sdk_path
]
222 elif sys
.platform
!= "win32":
223 host_flags
+= ["-pthread"]
225 if sys
.platform
.startswith("netbsd"):
226 # needed e.g. to use freshly built libc++
228 "-L" + config
.llvm_libs_dir
,
229 "-Wl,-rpath," + config
.llvm_libs_dir
,
232 # The clang module cache is used for building inferiors.
233 host_flags
+= ["-fmodules-cache-path={}".format(config
.clang_module_cache
)]
235 if config
.cmake_sysroot
:
236 host_flags
+= ["--sysroot={}".format(config
.cmake_sysroot
)]
238 if config
.enable_remote
and config
.has_libcxx
:
240 "-L{}".format(config
.libcxx_libs_dir
),
244 host_flags
= " ".join(host_flags
)
245 config
.substitutions
.append(("%clang_host", "%clang " + host_flags
))
246 config
.substitutions
.append(("%clangxx_host", "%clangxx " + host_flags
))
247 config
.substitutions
.append(
248 ("%clang_cl_host", "%clang_cl --target=" + config
.host_triple
)
251 additional_tool_dirs
= []
252 if config
.lldb_lit_tools_dir
:
253 additional_tool_dirs
.append(config
.lldb_lit_tools_dir
)
255 llvm_config
.use_clang(
256 additional_flags
=["--target=specify-a-target-or-use-a-_host-substitution"],
257 additional_tool_dirs
=additional_tool_dirs
,
262 if sys
.platform
== "win32":
263 _use_msvc_substitutions(config
)
265 have_lld
= llvm_config
.use_lld(
266 additional_tool_dirs
=additional_tool_dirs
, required
=False, use_installed
=True
269 config
.available_features
.add("lld")
282 additional_tool_dirs
+= [config
.lldb_tools_dir
, config
.llvm_tools_dir
]
283 llvm_config
.add_tool_substitutions(support_tools
, additional_tool_dirs
)
285 _disallow(config
, "clang")