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