8 from lit
.llvm
import llvm_config
9 from lit
.llvm
.subst
import FindTool
10 from lit
.llvm
.subst
import ToolSubst
13 def _get_lldb_init_path(config
):
14 return os
.path
.join(config
.test_exec_root
, "lit-lldb-init-quiet")
17 def _disallow(config
, execName
):
19 echo '*** Do not use \'{0}\' in tests; use \'%''{0}\'. ***' &&
22 config
.substitutions
.append((" {0} ".format(execName
), warning
.format(execName
)))
25 def use_lldb_substitutions(config
):
26 # Set up substitutions for primary tools. These tools must come from config.lldb_tools_dir
27 # which is basically the build output directory. We do not want to find these in path or
28 # anywhere else, since they are specifically the programs which are actually being tested.
30 dsname
= "debugserver" if platform
.system() in ["Darwin"] else "lldb-server"
31 dsargs
= [] if platform
.system() in ["Darwin"] else ["gdbserver"]
33 build_script
= os
.path
.dirname(__file__
)
34 build_script
= os
.path
.join(build_script
, "build.py")
37 "--compiler=any", # Default to best compiler
38 "--arch=" + str(config
.lldb_bitness
),
40 if config
.lldb_lit_tools_dir
:
41 build_script_args
.append("--tools-dir={0}".format(config
.lldb_lit_tools_dir
))
42 if config
.lldb_tools_dir
:
43 build_script_args
.append("--tools-dir={0}".format(config
.lldb_tools_dir
))
44 if config
.llvm_libs_dir
:
45 build_script_args
.append("--libs-dir={0}".format(config
.llvm_libs_dir
))
46 if config
.objc_gnustep_dir
:
47 build_script_args
.append(
48 '--objc-gnustep-dir="{0}"'.format(config
.objc_gnustep_dir
)
50 if config
.cmake_sysroot
:
51 build_script_args
.append("--sysroot={0}".format(config
.cmake_sysroot
))
53 lldb_init
= _get_lldb_init_path(config
)
58 command
=FindTool("lldb"),
59 extra_args
=["--no-lldbinit", "-S", lldb_init
],
64 command
=FindTool("lldb"),
65 extra_args
=["-S", lldb_init
],
70 command
=FindTool("lldb"),
71 extra_args
=["--no-lldbinit"],
76 command
=FindTool("lldb-server"),
82 command
=FindTool(dsname
),
88 command
=FindTool("lldb-server"),
89 extra_args
=["platform"],
95 "%build", command
="'" + sys
.executable
+ "'", extra_args
=build_script_args
99 _disallow(config
, "lldb")
100 _disallow(config
, "lldb-server")
101 _disallow(config
, "debugserver")
102 _disallow(config
, "platformserver")
104 llvm_config
.add_tool_substitutions(primary_tools
, [config
.lldb_tools_dir
])
107 def _use_msvc_substitutions(config
):
108 # If running from a Visual Studio Command prompt (e.g. vcvars), this will
109 # detect the include and lib paths, and find cl.exe and link.exe and create
110 # substitutions for each of them that explicitly specify /I and /L paths
111 cl
= lit
.util
.which("cl")
116 # Don't use lit.util.which() for link.exe: In `git bash`, it will pick
117 # up /usr/bin/link (another name for ln).
118 link
= os
.path
.join(os
.path
.dirname(cl
), "link.exe")
121 link
= '"' + link
+ '"'
122 includes
= os
.getenv("INCLUDE", "").split(";")
123 libs
= os
.getenv("LIB", "").split(";")
125 config
.available_features
.add("msvc")
126 compiler_flags
= ['"/I{}"'.format(x
) for x
in includes
if os
.path
.exists(x
)]
127 linker_flags
= ['"/LIBPATH:{}"'.format(x
) for x
in libs
if os
.path
.exists(x
)]
130 ToolSubst("%msvc_cl", command
=cl
, extra_args
=compiler_flags
),
131 ToolSubst("%msvc_link", command
=link
, extra_args
=linker_flags
),
133 llvm_config
.add_tool_substitutions(tools
)
137 def use_support_substitutions(config
):
138 # Set up substitutions for support tools. These tools can be overridden at the CMake
139 # level (by specifying -DLLDB_LIT_TOOLS_DIR), installed, or as a last resort, we can use
140 # the just-built version.
141 host_flags
= ["--target=" + config
.host_triple
]
142 if platform
.system() in ["Darwin"]:
144 out
= subprocess
.check_output(["xcrun", "--show-sdk-path"]).strip()
149 sdk_path
= lit
.util
.to_string(out
)
150 llvm_config
.lit_config
.note("using SDKROOT: %r" % sdk_path
)
151 host_flags
+= ["-isysroot", sdk_path
]
152 elif sys
.platform
!= "win32":
153 host_flags
+= ["-pthread"]
155 if sys
.platform
.startswith("netbsd"):
156 # needed e.g. to use freshly built libc++
158 "-L" + config
.llvm_libs_dir
,
159 "-Wl,-rpath," + config
.llvm_libs_dir
,
162 # The clang module cache is used for building inferiors.
163 host_flags
+= ["-fmodules-cache-path={}".format(config
.clang_module_cache
)]
165 if config
.cmake_sysroot
:
166 host_flags
+= ["--sysroot={}".format(config
.cmake_sysroot
)]
168 host_flags
= " ".join(host_flags
)
169 config
.substitutions
.append(("%clang_host", "%clang " + host_flags
))
170 config
.substitutions
.append(("%clangxx_host", "%clangxx " + host_flags
))
171 config
.substitutions
.append(
172 ("%clang_cl_host", "%clang_cl --target=" + config
.host_triple
)
175 additional_tool_dirs
= []
176 if config
.lldb_lit_tools_dir
:
177 additional_tool_dirs
.append(config
.lldb_lit_tools_dir
)
179 llvm_config
.use_clang(
180 additional_flags
=["--target=specify-a-target-or-use-a-_host-substitution"],
181 additional_tool_dirs
=additional_tool_dirs
,
186 if sys
.platform
== "win32":
187 _use_msvc_substitutions(config
)
189 have_lld
= llvm_config
.use_lld(
190 additional_tool_dirs
=additional_tool_dirs
, required
=False, use_installed
=True
193 config
.available_features
.add("lld")
206 additional_tool_dirs
+= [config
.lldb_tools_dir
, config
.llvm_tools_dir
]
207 llvm_config
.add_tool_substitutions(support_tools
, additional_tool_dirs
)
209 _disallow(config
, "clang")
212 def use_lldb_repro_substitutions(config
, mode
):
213 lldb_init
= _get_lldb_init_path(config
)
217 command
=FindTool("lldb-repro"),
218 extra_args
=[mode
, "--no-lldbinit", "-S", lldb_init
],
222 command
=FindTool("lldb-repro"),
223 extra_args
=[mode
, "-S", lldb_init
],
226 llvm_config
.add_tool_substitutions(substitutions
, [config
.lldb_tools_dir
])