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