Make check-clang depend on the LLVM split-file utility
[lldb.git] / llvm / utils / gn / secondary / clang / test / BUILD.gn
1 import("//clang/lib/ARCMigrate/enable.gni")
2 import("//clang/lib/StaticAnalyzer/Frontend/enable.gni")
3 import("//llvm/lib/Target/targets.gni")
4 import("//llvm/triples.gni")
5 import("//llvm/utils/gn/build/libs/pthread/enable.gni")
6 import("//llvm/utils/gn/build/libs/zlib/enable.gni")
7 import("//llvm/utils/gn/build/write_cmake_config.gni")
8 import("//llvm/utils/llvm-lit/lit_path_function.gni")
9 import("clang_lit_site_cfg_files.gni")
10
11 template("write_lit_config") {
12   write_cmake_config(target_name) {
13     input = invoker.input
14     output = invoker.output
15     dir = get_path_info(output, "dir")
16     values = [
17       "LIT_SITE_CFG_IN_HEADER=" +
18           "## Autogenerated from $input, do not edit\n\n" + lit_path_function,
19       "CLANG_BINARY_DIR=" +
20           rebase_path(get_label_info("//clang", "target_out_dir"), dir),
21       "CLANG_SOURCE_DIR=" + rebase_path("//clang", dir),
22       "ENABLE_SHARED=0",
23       "LLVM_BINARY_DIR=" +
24           rebase_path(get_label_info("//llvm", "target_out_dir"), dir),
25       "LLVM_LIBS_DIR=",  # needed only for shared builds
26       "LLVM_SOURCE_DIR=" + rebase_path("//llvm", dir),
27       "LLVM_TOOLS_DIR=" + rebase_path("$root_out_dir/bin", dir),
28       "TARGET_TRIPLE=$llvm_target_triple",
29     ]
30     if (host_os == "win") {
31       # See comment for Windows solink in llvm/utils/gn/build/toolchain/BUILD.gn
32       values += [ "SHLIBDIR=" + rebase_path("$root_out_dir/bin", dir) ]
33     } else {
34       values += [ "SHLIBDIR=" + rebase_path("$root_out_dir/lib", dir) ]
35     }
36     values += invoker.extra_values
37   }
38 }
39
40 write_lit_config("lit_site_cfg") {
41   # Fully-qualified instead of relative for LIT_SITE_CFG_IN_HEADER.
42   input = "//clang/test/lit.site.cfg.py.in"
43   output = clang_lit_site_cfg_file
44   dir = get_path_info(output, "dir")
45   extra_values = [
46     "LLVM_WITH_Z3=",  # Must be empty, not 0.
47     "CLANG_BUILD_EXAMPLES=0",
48     "CLANG_DEFAULT_CXX_STDLIB=",  # Empty string means "default value" here.
49     "CLANG_DEFAULT_LINKER=",
50     "CLANG_TOOLS_DIR=" + rebase_path("$root_out_dir/bin", dir),
51     "CLANG_VENDOR_UTI=org.llvm.clang",
52
53     # This is only used if LLVM_USE_SANITIZER includes lsan and the host
54     # OS is macOS. Since the GN build currently never uses LLVM_USE_SANITIZER,
55     # this is never read.  If it's ever needed,
56     # utils/gn/build/toolchain/BUILD.gn should get the compiler from a variable
57     # that's also read here -- but that should happen after multi-toolchain
58     # builds exist, to make sure it's a toolchain var.
59     "CMAKE_CXX_COMPILER=c++",
60     "ENABLE_BACKTRACES=1",
61     "ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER=0",
62     "LLVM_HOST_TRIPLE=$llvm_current_triple",
63     "LLVM_LIT_TOOLS_DIR=",  # Intentionally empty, matches cmake build.
64     "LLVM_USE_SANITIZER=",
65     "Python3_EXECUTABLE=$python_path",
66     "USE_Z3_SOLVER=",
67   ]
68
69   if (clang_enable_arcmt) {
70     extra_values += [ "CLANG_ENABLE_ARCMT=1" ]
71   } else {
72     extra_values += [ "CLANG_ENABLE_ARCMT=0" ]
73   }
74
75   if (clang_enable_static_analyzer) {
76     extra_values += [ "CLANG_ENABLE_STATIC_ANALYZER=1" ]
77   } else {
78     extra_values += [ "CLANG_ENABLE_STATIC_ANALYZER=0" ]
79   }
80
81   if (llvm_enable_zlib) {
82     extra_values += [ "LLVM_ENABLE_ZLIB=1" ]
83   } else {
84     extra_values += [ "LLVM_ENABLE_ZLIB=0" ]  # Must be 0.
85   }
86
87   if (host_cpu == "x64") {
88     extra_values += [ "HOST_ARCH=x86_64" ]
89   } else if (host_cpu == "arm64") {
90     extra_values += [ "HOST_ARCH=arm64" ]
91   } else if (host_cpu == "ppc64") {
92     extra_values += [ "HOST_ARCH=powerpc64le" ]
93   } else {
94     assert(false, "unimplemented host_cpu " + host_cpu)
95   }
96
97   if (host_os == "mac") {
98     extra_values += [ "LLVM_PLUGIN_EXT=.dylib" ]
99   } else if (host_os == "win") {
100     extra_values += [ "LLVM_PLUGIN_EXT=.dll" ]
101   } else {
102     extra_values += [ "LLVM_PLUGIN_EXT=.so" ]
103   }
104
105   if (host_os == "win") {
106     extra_values += [ "LLVM_ENABLE_PLUGINS=0" ]
107   } else {
108     # FIXME: Analysis/plugins need global -fPIC
109     extra_values += [ "LLVM_ENABLE_PLUGINS=0" ]
110   }
111
112   if (llvm_enable_threads) {
113     extra_values += [ "LLVM_ENABLE_THREADS=1" ]
114   } else {
115     extra_values += [ "LLVM_ENABLE_THREADS=0" ]  # Must be 0.
116   }
117 }
118
119 write_lit_config("lit_unit_site_cfg") {
120   # Fully-qualified instead of relative for LIT_SITE_CFG_IN_HEADER.
121   input = "//clang/test/Unit/lit.site.cfg.py.in"
122   output = clang_lit_unit_site_cfg_file
123   extra_values = [ "LLVM_BUILD_MODE=." ]
124 }
125
126 # This target should contain all dependencies of check-clang.
127 # //:default depends on it, so that ninja's default target builds all
128 # prerequisites for check-clang but doesn't run check-clang itself.
129 group("test") {
130   deps = [
131     ":lit_site_cfg",
132     ":lit_unit_site_cfg",
133     "//clang/lib/Headers",
134     "//clang/tools/apinotes-test",
135     "//clang/tools/c-index-test",
136     "//clang/tools/clang-diff",
137     "//clang/tools/clang-format",
138     "//clang/tools/clang-import-test",
139     "//clang/tools/clang-offload-bundler",
140     "//clang/tools/clang-refactor",
141     "//clang/tools/clang-rename",
142     "//clang/tools/clang-scan-deps",
143     "//clang/tools/diagtool",
144     "//clang/tools/driver:symlinks",
145     "//clang/unittests",
146     "//clang/utils/TableGen:clang-tblgen",
147     "//clang/utils/hmaptool",
148     "//llvm/tools/llc",
149     "//llvm/tools/llvm-as",
150     "//llvm/tools/llvm-bcanalyzer",
151     "//llvm/tools/llvm-cat",
152     "//llvm/tools/llvm-config",
153     "//llvm/tools/llvm-cxxfilt",
154     "//llvm/tools/llvm-dis",
155     "//llvm/tools/llvm-dwarfdump",
156     "//llvm/tools/llvm-ifs",
157     "//llvm/tools/llvm-lto",
158     "//llvm/tools/llvm-lto2",
159     "//llvm/tools/llvm-modextract",
160     "//llvm/tools/llvm-nm:symlinks",
161     "//llvm/tools/llvm-objcopy:symlinks",
162     "//llvm/tools/llvm-objdump:symlinks",
163     "//llvm/tools/llvm-profdata",
164     "//llvm/tools/llvm-readobj:symlinks",
165     "//llvm/tools/llvm-symbolizer:symlinks",
166     "//llvm/tools/opt",
167     "//llvm/tools/split-file",
168     "//llvm/utils/FileCheck",
169     "//llvm/utils/count",
170     "//llvm/utils/llvm-lit",
171     "//llvm/utils/not",
172     "//llvm/tools/yaml2obj",
173   ]
174   if (clang_enable_arcmt) {
175     deps += [
176       "//clang/tools/arcmt-test",
177       "//clang/tools/c-arcmt-test",
178     ]
179   }
180   if (clang_enable_static_analyzer) {
181     deps += [
182       "//clang/tools/clang-check",
183       "//clang/tools/clang-extdef-mapping",
184     ]
185   }
186
187   # FIXME: clang_build_examples
188   testonly = true
189 }
190
191 action("check-clang") {
192   script = "$root_out_dir/bin/llvm-lit"
193   if (host_os == "win") {
194     script += ".py"
195   }
196   args = [
197     "-sv",
198     rebase_path(".", root_out_dir),
199   ]
200   outputs = [ "$target_gen_dir/run-lit" ]  # Non-existing, so that ninja runs it
201                                            # each time.
202
203   # Since check-clang is always dirty, //:default doesn't depend on it so that
204   # it's not part of the default ninja target.  Hence, check-clang shouldn't
205   # have any deps except :test. so that the default target is sure to build
206   # all the deps.
207   deps = [ ":test" ]
208   testonly = true
209
210   pool = "//:console"
211 }