xref: /openbsd-src/gnu/llvm/llvm/utils/gn/secondary/clang-tools-extra/clangd/test/BUILD.gn (revision d415bd752c734aee168c4ee86ff32e8cc249eb16)
1import("//clang-tools-extra/clangd/xpc/enable.gni")
2import("//llvm/triples.gni")
3import("//llvm/utils/gn/build/libs/zlib/enable.gni")
4import("//llvm/utils/gn/build/write_cmake_config.gni")
5import("clangd_lit_site_cfg_files.gni")
6
7template("write_lit_config") {
8  write_cmake_config(target_name) {
9    input = invoker.input
10    output = invoker.output
11    values = [
12      "LIT_SITE_CFG_IN_HEADER=## Autogenerated from $input, do not edit",
13      "LLVM_LIBS_DIR=",  # needed only for shared builds
14    ]
15    if (host_os == "win") {
16      # See comment for Windows solink in llvm/utils/gn/build/toolchain/BUILD.gn
17      values += [ "SHLIBDIR=" + rebase_path("$root_out_dir/bin") ]
18    } else {
19      values += [ "SHLIBDIR=" + rebase_path("$root_out_dir/lib") ]
20    }
21    values += invoker.extra_values
22  }
23}
24
25write_lit_config("lit_site_cfg") {
26  # Fully-qualified instead of relative for LIT_SITE_CFG_IN_HEADER.
27  input = "//clang-tools-extra/clangd/test/lit.site.cfg.py.in"
28  output = clangd_lit_site_cfg_file
29
30  extra_values = [
31    "CMAKE_CURRENT_BINARY_DIR=" +
32        rebase_path(get_label_info("//clang-tools-extra/clangd/test",
33                                   "target_out_dir")),
34    "CMAKE_CURRENT_SOURCE_DIR=" +
35        rebase_path("//clang-tools-extra/clangd/test"),
36
37    "CURRENT_TOOLS_DIR=",
38    "CLANGD_ENABLE_REMOTE=0",
39    "CLANGD_TIDY_CHECKS=1",
40    "LLVM_HOST_TRIPLE=$llvm_current_triple",
41    "LLVM_LIT_TOOLS_DIR=",  # Intentionally empty, matches cmake build.
42    "LLVM_TOOLS_DIR=" + rebase_path("$root_out_dir/bin"),
43    "LLVM_TARGET_TRIPLE=$llvm_target_triple",
44    "Python3_EXECUTABLE=$python_path",
45  ]
46
47  if (clangd_build_xpc) {
48    extra_values += [ "CLANGD_BUILD_XPC=1" ]
49  } else {
50    extra_values += [ "CLANGD_BUILD_XPC=0" ]
51  }
52
53  if (llvm_enable_zlib) {
54    extra_values += [ "LLVM_ENABLE_ZLIB=1" ]
55  } else {
56    extra_values += [ "LLVM_ENABLE_ZLIB=0" ]
57  }
58}
59
60write_lit_config("lit_unit_site_cfg") {
61  # Fully-qualified instead of relative for LIT_SITE_CFG_IN_HEADER.
62  input = "//clang-tools-extra/clangd/unittests/lit.site.cfg.py.in"
63  output = clangd_lit_unit_site_cfg_file
64  extra_values = [
65    "CMAKE_CURRENT_BINARY_DIR=" +
66        rebase_path(get_label_info("//clang-tools-extra/clangd/unittests",
67                                   "target_out_dir")),
68    "CMAKE_CURRENT_SOURCE_DIR=" +
69        rebase_path("//clang-tools-extra/clangd/unittests"),
70  ]
71}
72
73# This target should contain all dependencies of check-clangd.
74# //:default depends on it, so that ninja's default target builds all
75# prerequisites for check-clang but doesn't run check-clang itself.
76group("test") {
77  deps = [
78    ":lit_site_cfg",
79    ":lit_unit_site_cfg",
80    "//clang-tools-extra/clangd/index/dex/dexp",
81    "//clang-tools-extra/clangd/indexer:clangd-indexer",
82    "//clang-tools-extra/clangd/tool:clangd",
83    "//clang-tools-extra/clangd/unittests:ClangdTests",
84    "//llvm/utils/FileCheck",
85    "//llvm/utils/llvm-lit",
86    "//llvm/utils/not",
87  ]
88  if (clangd_build_xpc) {
89    deps += [
90      "//clang-tools-extra/clangd/unittests/xpc:ClangdXpcTests",
91      "//clang-tools-extra/clangd/xpc/test-client:clangd-xpc-test-client",
92    ]
93  }
94  testonly = true
95}
96
97action("check-clangd") {
98  script = "$root_out_dir/bin/llvm-lit"
99  if (host_os == "win") {
100    script += ".py"
101  }
102  args = [
103    "-sv",
104
105    # clangd doesn't put unittest configs in test/unit like every other project.
106    # Because of that, this needs to pass two folders here, while every other
107    # project only needs to pass CMAKE_CURRENT_BINARY_DIR.
108    rebase_path(get_path_info(clangd_lit_site_cfg_file, "dir"), root_out_dir),
109    rebase_path(get_path_info(clangd_lit_unit_site_cfg_file, "dir"),
110                root_out_dir),
111  ]
112  outputs = [ "$target_gen_dir/run-lit" ]  # Non-existing, so that ninja runs it
113                                           # each time.
114
115  # Since check-clangd is always dirty, //:default doesn't depend on it so
116  # that it's not part of the default ninja target.  Hence, check-clangd
117  # shouldn't have any deps except :test. so that the default target is sure to
118  # build all the deps.
119  deps = [ ":test" ]
120  testonly = true
121
122  pool = "//:console"
123}
124