[lit] Improve lit.Run class
[llvm-complete.git] / utils / gn / secondary / llvm / test / BUILD.gn
blob8cf979328d839a5c372527127fa382980df1bd47
1 import("//llvm/lib/DebugInfo/PDB/enable_dia.gni")
2 import("//llvm/lib/Target/targets_string.gni")
3 import("//llvm/triples.gni")
4 import("//llvm/utils/gn/build/buildflags.gni")
5 import("//llvm/utils/gn/build/libs/pthread/enable.gni")
6 import("//llvm/utils/gn/build/libs/xar/enable.gni")
7 import("//llvm/utils/gn/build/libs/xml/enable.gni")
8 import("//llvm/utils/gn/build/libs/zlib/enable.gni")
9 import("//llvm/utils/gn/build/write_cmake_config.gni")
10 import("llvm_lit_site_cfg_files.gni")
12 template("write_lit_config") {
13   write_cmake_config(target_name) {
14     input = invoker.input
15     output = invoker.output
16     values = [
17       "LIT_SITE_CFG_IN_HEADER=## Autogenerated from $input, do not edit",
18       "ENABLE_SHARED=0",
19       "LLVM_BINARY_DIR=" +
20           rebase_path(get_label_info("//llvm", "target_out_dir")),
21       "LLVM_SOURCE_DIR=" + rebase_path("//llvm"),
22       "LLVM_TOOLS_DIR=" + rebase_path("$root_out_dir/bin"),
23     ]
24     if (host_os == "win") {
25       # See comment for Windows solink in llvm/utils/gn/build/toolchain/BUILD.gn
26       values += [ "SHLIBDIR=" + rebase_path("$root_out_dir/bin") ]
27     } else {
28       values += [ "SHLIBDIR=" + rebase_path("$root_out_dir/lib") ]
29     }
30     values += invoker.extra_values
31   }
34 write_lit_config("lit_site_cfg") {
35   input = "//llvm/test/lit.site.cfg.py.in"
36   output = llvm_lit_site_cfg_file
37   extra_values = [
38     "BUILD_SHARED_LIBS=0",
40     # Only used by the Go bindings tests, or if LLVM_USE_SANITIZER includes
41     # asan and the host OS is macOS. The GN build currently never uses
42     # LLVM_USE_SANITIZER.  (See also CMAKE_CXX_COMPILER in clang/test/BUILD.gn.)
43     "HOST_CC=cc",
45     # Only used by the Go bindings tests, or if LLVM_USE_SANITIZER includes
46     # lsan and the host OS is macOS. The GN build currently never uses
47     # LLVM_USE_SANITIZER.  (See also CMAKE_CXX_COMPILER in clang/test/BUILD.gn.)
48     "HOST_CXX=c++",
50     # Only used by the Go bindings tests, and for detecting a 32-bit build
51     # and in a belt-and-suspenders check for detecting 32-bit host builds.
52     # (That check also checks LLVM_HOST_TRIPLE.)
53     "HOST_LDFLAGS=",
55     "LLVM_ENABLE_FFI=0",
56     "LLVM_HAVE_OPT_VIEWER_MODULES=0",
57     "LLVM_HOST_TRIPLE=$llvm_current_triple",
58     "LLVM_LIBRARY_DIR=" + rebase_path("$root_out_dir/lib"),
59     "LLVM_LINK_LLVM_DYLIB=0",
60     "LLVM_LIT_TOOLS_DIR=",  # Intentionally empty, matches cmake build.
61     "LLVM_NATIVE_ARCH=$native_target",
62     "LLVM_USE_INTEL_JITEVENTS=0",
63     "LLVM_USE_SANITIZER=",
64     "PYTHON_EXECUTABLE=$python_path",
65     "TARGETS_TO_BUILD=$llvm_targets_to_build_string",
66     "TARGET_TRIPLE=$llvm_target_triple",
68     "LLVM_LIBCXX_USED=0",
70     # No bindings are implemented in the GN build.
71     "LLVM_BINDINGS=",
73     "GO_EXECUTABLE=",
74     "LLVM_INCLUDE_GO_TESTS=0",
76     "HAVE_OCAMLOPT=0",
77     "HAVE_OCAML_OUNIT=0",
78     "OCAMLFIND=OCAMLFIND-NOTFOUND",
79     "OCAMLFLAGS=",
80     "LLVM_BUILD_EXAMPLES=0",
81   ]
83   if (host_cpu == "x64") {
84     extra_values += [ "HOST_ARCH=x86_64" ]
85   } else if (host_cpu == "ppc64") {
86     extra_values += [ "HOST_ARCH=powerpc64le" ]
87   } else {
88     assert(false, "unimplemented host_cpu " + host_cpu)
89   }
91   if (host_os == "win") {
92     extra_values += [ "EXEEXT=.exe" ]
93   } else {
94     extra_values += [ "EXEEXT=" ]
95   }
97   if (host_os == "win") {
98     extra_values += [ "LLVM_ENABLE_PLUGINS=0" ]
99   } else {
100     extra_values += [ "LLVM_ENABLE_PLUGINS=1" ]
101   }
103   if (host_os == "mac") {
104     extra_values += [ "SHLIBEXT=.dylib" ]
105   } else if (host_os == "win") {
106     extra_values += [ "SHLIBEXT=.dll" ]
107   } else {
108     extra_values += [ "SHLIBEXT=.so" ]
109   }
111   if (host_os == "freebsd") {
112     extra_values += [ "HOST_OS=FreeBSD" ]
113   } else if (host_os == "mac") {
114     extra_values += [ "HOST_OS=Darwin" ]
115   } else if (host_os == "linux") {
116     extra_values += [ "HOST_OS=Linux" ]
117   } else if (host_os == "win") {
118     extra_values += [ "HOST_OS=Windows" ]
119   } else {
120     assert(false, "unsupported host_os " + host_os)
121   }
122   if (host_os == "linux") {
123     # lit.cfg.py's have_ld_plugin_support() checks for "gold" in --version,
124     # so just claim that ld is gold on Linux.  The function also checks if
125     # LLVMgold.so exists, but since that target isn't hooked up yet in the GN
126     # build the LLVMgold.so tests currently don't run anywhere in the GN build.
127     extra_values += [ "GOLD_EXECUTABLE=ld" ]
128   } else {
129     extra_values += [ "GOLD_EXECUTABLE=" ]
130   }
131   if (host_os == "mac") {
132     extra_values += [ "LD64_EXECUTABLE=ld" ]
133   } else {
134     extra_values += [ "LD64_EXECUTABLE=" ]
135   }
137   if (llvm_enable_assertions) {
138     extra_values += [ "ENABLE_ASSERTIONS=1" ]
139   } else {
140     extra_values += [ "ENABLE_ASSERTIONS=0" ]  # Must be 0.
141   }
143   if (llvm_enable_libxar) {
144     extra_values += [ "HAVE_LIBXAR=1" ]
145   } else {
146     extra_values += [ "HAVE_LIBXAR=0" ]  # Must be 0.
147   }
149   if (llvm_enable_dia_sdk) {
150     extra_values += [ "LLVM_ENABLE_DIA_SDK=1" ]
151   } else {
152     extra_values += [ "LLVM_ENABLE_DIA_SDK=0" ]  # Must be 0.
153   }
155   if (llvm_enable_libxml2) {
156     extra_values += [ "LLVM_LIBXML2_ENABLED=1" ]
157   } else {
158     extra_values += [ "LLVM_LIBXML2_ENABLED=0" ]  # Must be 0.
159   }
161   if (llvm_enable_threads) {
162     extra_values += [ "LLVM_ENABLE_THREADS=1" ]
163   } else {
164     extra_values += [ "LLVM_ENABLE_THREADS=0" ]  # Must be 0.
165   }
167   if (llvm_enable_zlib) {
168     extra_values += [ "HAVE_LIBZ=1" ]
169   } else {
170     extra_values += [ "HAVE_LIBZ=0" ]  # Must be 0.
171   }
174 write_lit_config("lit_unit_site_cfg") {
175   input = "//llvm/test/Unit/lit.site.cfg.py.in"
176   output = llvm_lit_unit_site_cfg_file
177   extra_values = [ "LLVM_BUILD_MODE=." ]
180 # This target should contain all dependencies of check-llvm.
181 # //:default depends on it, so that ninja's default target builds all
182 # prerequisites for check-llvm but doesn't run check-llvm itself.
183 group("test") {
184   deps = [
185     ":lit_site_cfg",
186     ":lit_unit_site_cfg",
188     # Because llvm/tools/llvm-config/BUILD.gn calls llvm-build to generate
189     # LibraryDependencies.inc, llvm-config expects these libraries to exist
190     # even though nothing but unittests depends on them.  Add explicit
191     # dependencies to make sure the libaries exist on disk when llvm-config's
192     # lit tests run.
193     "//llvm/lib/LineEditor",
194     "//llvm/lib/Testing/Support",
195     "//llvm/tools/bugpoint",
196     "//llvm/tools/dsymutil",
197     "//llvm/tools/llc",
198     "//llvm/tools/lli",
199     "//llvm/tools/lli/ChildTarget:lli-child-target",
200     "//llvm/tools/llvm-ar:symlinks",
201     "//llvm/tools/llvm-as",
202     "//llvm/tools/llvm-bcanalyzer",
203     "//llvm/tools/llvm-c-test",
204     "//llvm/tools/llvm-cat",
205     "//llvm/tools/llvm-cfi-verify",
206     "//llvm/tools/llvm-cov",
207     "//llvm/tools/llvm-cvtres",
208     "//llvm/tools/llvm-cxxdump",
209     "//llvm/tools/llvm-cxxfilt",
210     "//llvm/tools/llvm-cxxmap",
211     "//llvm/tools/llvm-diff",
212     "//llvm/tools/llvm-dis",
213     "//llvm/tools/llvm-dwarfdump",
214     "//llvm/tools/llvm-dwp",
215     "//llvm/tools/llvm-elfabi",
216     "//llvm/tools/llvm-exegesis",
217     "//llvm/tools/llvm-extract",
218     "//llvm/tools/llvm-ifs",
219     "//llvm/tools/llvm-isel-fuzzer",
220     "//llvm/tools/llvm-jitlink",
221     "//llvm/tools/llvm-link",
222     "//llvm/tools/llvm-lipo",
223     "//llvm/tools/llvm-lto",
224     "//llvm/tools/llvm-lto2",
225     "//llvm/tools/llvm-mc",
226     "//llvm/tools/llvm-mca",
227     "//llvm/tools/llvm-modextract",
228     "//llvm/tools/llvm-mt",
229     "//llvm/tools/llvm-nm",
230     "//llvm/tools/llvm-objcopy:symlinks",
231     "//llvm/tools/llvm-objdump",
232     "//llvm/tools/llvm-opt-fuzzer",
233     "//llvm/tools/llvm-opt-report",
234     "//llvm/tools/llvm-pdbutil",
235     "//llvm/tools/llvm-profdata",
236     "//llvm/tools/llvm-rc",
237     "//llvm/tools/llvm-readobj:symlinks",
238     "//llvm/tools/llvm-reduce",
239     "//llvm/tools/llvm-rtdyld",
240     "//llvm/tools/llvm-size",
241     "//llvm/tools/llvm-split",
242     "//llvm/tools/llvm-strings",
243     "//llvm/tools/llvm-symbolizer:symlinks",
244     "//llvm/tools/llvm-undname",
245     "//llvm/tools/llvm-xray",
246     "//llvm/tools/lto",
247     "//llvm/tools/obj2yaml",
248     "//llvm/tools/opt",
249     "//llvm/tools/sancov",
250     "//llvm/tools/sanstats",
251     "//llvm/tools/verify-uselistorder",
252     "//llvm/tools/yaml2obj",
253     "//llvm/unittests",
254     "//llvm/utils/FileCheck",
255     "//llvm/utils/TableGen:llvm-tblgen",
256     "//llvm/utils/count",
257     "//llvm/utils/llvm-lit",
258     "//llvm/utils/not",
260     # llvm-config wants libgtest_main.a to exist at runtime when run as in
261     # its tests, but nothing in the tree depends on them.
262     "//llvm/utils/unittest/UnitTestMain:gtest_main",
263     "//llvm/utils/yaml-bench",
264   ]
265   if (host_os != "win") {
266     # loadable_modules don't work on Windows.
267     # FIXME: In the CMake build, ENABLE_SHARED makes them work somehow
268     # (but they're off by default there too).
269     deps += [
270       "//llvm/lib/Transforms/Hello",
271       "//llvm/tools/bugpoint-passes",
272     ]
273   }
275   # FIXME: llvm_build_examples
276   testonly = true
279 action("check-llvm") {
280   script = "$root_out_dir/bin/llvm-lit"
281   if (host_os == "win") {
282     script += ".py"
283   }
284   args = [
285     "-sv",
286     "--param",
287     "llvm_site_config=" + rebase_path(llvm_lit_site_cfg_file, root_out_dir),
288     "--param",
289     "llvm_unit_site_config=" +
290         rebase_path(llvm_lit_unit_site_cfg_file, root_out_dir),
291     rebase_path(".", root_out_dir),
292   ]
293   outputs = [
294     "$target_gen_dir/run-lit",  # Non-existing, so that ninja runs it each time.
295   ]
297   # Since check-llvm is always dirty, //:default doesn't depend on it so that
298   # it's not part of the default ninja target.  Hence, check-llvm shouldn't
299   # have any deps except :test. so that the default target is sure to build
300   # all the deps.
301   deps = [
302     ":test",
303   ]
304   testonly = true
306   pool = "//:console"