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