reference, declarationdefinition
definition → references, declarations, derived classes, virtual overrides
reference to multiple definitions → definitions
unreferenced
    1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133
  134
  135
  136
  137
  138
  139
  140
  141
  142
  143
  144
  145
  146
  147
  148
  149
  150
  151
  152
  153
  154
  155
  156
  157
  158
  159
  160
  161
  162
  163
  164
  165
  166
  167
  168
  169
  170
  171
  172
  173
  174
  175
  176
  177
  178
  179
  180
  181
  182
  183
  184
  185
  186
  187
  188
  189
  190
  191
  192
  193
  194
  195
  196
  197
  198
  199
  200
  201
  202
  203
  204
  205
  206
  207
  208
  209
  210
  211
  212
  213
  214
  215
  216
  217
  218
  219
  220
  221
  222
  223
  224
  225
  226
  227
  228
  229
  230
  231
  232
  233
  234
  235
  236
  237
  238
  239
  240
  241
  242
  243
  244
  245
  246
  247
  248
  249
  250
  251
  252
  253
  254
  255
  256
  257
  258
  259
  260
  261
  262
  263
  264
  265
  266
  267
  268
  269
  270
  271
  272
  273
  274
  275
  276
  277
  278
  279
  280
  281
  282
  283
  284
  285
  286
  287
  288
  289
  290
  291
  292
  293
  294
  295
  296
  297
  298
  299
  300
  301
  302
  303
  304
  305
  306
  307
import("//llvm/lib/DebugInfo/PDB/enable_dia.gni")
import("//llvm/lib/Target/targets_string.gni")
import("//llvm/triples.gni")
import("//llvm/utils/gn/build/buildflags.gni")
import("//llvm/utils/gn/build/libs/pthread/enable.gni")
import("//llvm/utils/gn/build/libs/xar/enable.gni")
import("//llvm/utils/gn/build/libs/xml/enable.gni")
import("//llvm/utils/gn/build/libs/zlib/enable.gni")
import("//llvm/utils/gn/build/write_cmake_config.gni")
import("llvm_lit_site_cfg_files.gni")

template("write_lit_config") {
  write_cmake_config(target_name) {
    input = invoker.input
    output = invoker.output
    values = [
      "LIT_SITE_CFG_IN_HEADER=## Autogenerated from $input, do not edit",
      "ENABLE_SHARED=0",
      "LLVM_BINARY_DIR=" +
          rebase_path(get_label_info("//llvm", "target_out_dir")),
      "LLVM_SOURCE_DIR=" + rebase_path("//llvm"),
      "LLVM_TOOLS_DIR=" + rebase_path("$root_out_dir/bin"),
    ]
    if (host_os == "win") {
      # See comment for Windows solink in llvm/utils/gn/build/toolchain/BUILD.gn
      values += [ "SHLIBDIR=" + rebase_path("$root_out_dir/bin") ]
    } else {
      values += [ "SHLIBDIR=" + rebase_path("$root_out_dir/lib") ]
    }
    values += invoker.extra_values
  }
}

write_lit_config("lit_site_cfg") {
  input = "//llvm/test/lit.site.cfg.py.in"
  output = llvm_lit_site_cfg_file
  extra_values = [
    "BUILD_SHARED_LIBS=0",

    # Only used by the Go bindings tests, or if LLVM_USE_SANITIZER includes
    # asan and the host OS is macOS. The GN build currently never uses
    # LLVM_USE_SANITIZER.  (See also CMAKE_CXX_COMPILER in clang/test/BUILD.gn.)
    "HOST_CC=cc",

    # Only used by the Go bindings tests, or if LLVM_USE_SANITIZER includes
    # lsan and the host OS is macOS. The GN build currently never uses
    # LLVM_USE_SANITIZER.  (See also CMAKE_CXX_COMPILER in clang/test/BUILD.gn.)
    "HOST_CXX=c++",

    # Only used by the Go bindings tests, and for detecting a 32-bit build
    # and in a belt-and-suspenders check for detecting 32-bit host builds.
    # (That check also checks LLVM_HOST_TRIPLE.)
    "HOST_LDFLAGS=",

    "LLVM_ENABLE_FFI=0",
    "LLVM_HAVE_OPT_VIEWER_MODULES=0",
    "LLVM_HOST_TRIPLE=$llvm_current_triple",
    "LLVM_LIBRARY_DIR=" + rebase_path("$root_out_dir/lib"),
    "LLVM_LINK_LLVM_DYLIB=0",
    "LLVM_LIT_TOOLS_DIR=",  # Intentionally empty, matches cmake build.
    "LLVM_NATIVE_ARCH=$native_target",
    "LLVM_USE_INTEL_JITEVENTS=0",
    "LLVM_USE_SANITIZER=",
    "PYTHON_EXECUTABLE=$python_path",
    "TARGETS_TO_BUILD=$llvm_targets_to_build_string",
    "TARGET_TRIPLE=$llvm_target_triple",

    "LLVM_LIBCXX_USED=0",

    # No bindings are implemented in the GN build.
    "LLVM_BINDINGS=",

    "GO_EXECUTABLE=",
    "LLVM_INCLUDE_GO_TESTS=0",

    "HAVE_OCAMLOPT=0",
    "HAVE_OCAML_OUNIT=0",
    "OCAMLFIND=OCAMLFIND-NOTFOUND",
    "OCAMLFLAGS=",
    "LLVM_BUILD_EXAMPLES=0",
  ]

  if (host_cpu == "x64") {
    extra_values += [ "HOST_ARCH=x86_64" ]
  } else if (host_cpu == "ppc64") {
    extra_values += [ "HOST_ARCH=powerpc64le" ]
  } else {
    assert(false, "unimplemented host_cpu " + host_cpu)
  }

  if (host_os == "win") {
    extra_values += [ "EXEEXT=.exe" ]
  } else {
    extra_values += [ "EXEEXT=" ]
  }

  if (host_os == "win") {
    extra_values += [ "LLVM_ENABLE_PLUGINS=0" ]
  } else {
    extra_values += [ "LLVM_ENABLE_PLUGINS=1" ]
  }

  if (host_os == "mac") {
    extra_values += [ "SHLIBEXT=.dylib" ]
  } else if (host_os == "win") {
    extra_values += [ "SHLIBEXT=.dll" ]
  } else {
    extra_values += [ "SHLIBEXT=.so" ]
  }

  if (host_os == "freebsd") {
    extra_values += [ "HOST_OS=FreeBSD" ]
  } else if (host_os == "mac") {
    extra_values += [ "HOST_OS=Darwin" ]
  } else if (host_os == "linux") {
    extra_values += [ "HOST_OS=Linux" ]
  } else if (host_os == "win") {
    extra_values += [ "HOST_OS=Windows" ]
  } else {
    assert(false, "unsupported host_os " + host_os)
  }
  if (host_os == "linux") {
    # lit.cfg.py's have_ld_plugin_support() checks for "gold" in --version,
    # so just claim that ld is gold on Linux.  The function also checks if
    # LLVMgold.so exists, but since that target isn't hooked up yet in the GN
    # build the LLVMgold.so tests currently don't run anywhere in the GN build.
    extra_values += [ "GOLD_EXECUTABLE=ld" ]
  } else {
    extra_values += [ "GOLD_EXECUTABLE=" ]
  }
  if (host_os == "mac") {
    extra_values += [ "LD64_EXECUTABLE=ld" ]
  } else {
    extra_values += [ "LD64_EXECUTABLE=" ]
  }

  if (llvm_enable_assertions) {
    extra_values += [ "ENABLE_ASSERTIONS=1" ]
  } else {
    extra_values += [ "ENABLE_ASSERTIONS=0" ]  # Must be 0.
  }

  if (llvm_enable_libxar) {
    extra_values += [ "HAVE_LIBXAR=1" ]
  } else {
    extra_values += [ "HAVE_LIBXAR=0" ]  # Must be 0.
  }

  if (llvm_enable_dia_sdk) {
    extra_values += [ "LLVM_ENABLE_DIA_SDK=1" ]
  } else {
    extra_values += [ "LLVM_ENABLE_DIA_SDK=0" ]  # Must be 0.
  }

  if (llvm_enable_libxml2) {
    extra_values += [ "LLVM_LIBXML2_ENABLED=1" ]
  } else {
    extra_values += [ "LLVM_LIBXML2_ENABLED=0" ]  # Must be 0.
  }

  if (llvm_enable_threads) {
    extra_values += [ "LLVM_ENABLE_THREADS=1" ]
  } else {
    extra_values += [ "LLVM_ENABLE_THREADS=0" ]  # Must be 0.
  }

  if (llvm_enable_zlib) {
    extra_values += [ "HAVE_LIBZ=1" ]
  } else {
    extra_values += [ "HAVE_LIBZ=0" ]  # Must be 0.
  }
}

write_lit_config("lit_unit_site_cfg") {
  input = "//llvm/test/Unit/lit.site.cfg.py.in"
  output = llvm_lit_unit_site_cfg_file
  extra_values = [ "LLVM_BUILD_MODE=." ]
}

# This target should contain all dependencies of check-llvm.
# //:default depends on it, so that ninja's default target builds all
# prerequisites for check-llvm but doesn't run check-llvm itself.
group("test") {
  deps = [
    ":lit_site_cfg",
    ":lit_unit_site_cfg",

    # Because llvm/tools/llvm-config/BUILD.gn calls llvm-build to generate
    # LibraryDependencies.inc, llvm-config expects these libraries to exist
    # even though nothing but unittests depends on them.  Add explicit
    # dependencies to make sure the libaries exist on disk when llvm-config's
    # lit tests run.
    "//llvm/lib/LineEditor",
    "//llvm/lib/Testing/Support",
    "//llvm/tools/bugpoint",
    "//llvm/tools/dsymutil",
    "//llvm/tools/llc",
    "//llvm/tools/lli",
    "//llvm/tools/lli/ChildTarget:lli-child-target",
    "//llvm/tools/llvm-ar:symlinks",
    "//llvm/tools/llvm-as",
    "//llvm/tools/llvm-bcanalyzer",
    "//llvm/tools/llvm-c-test",
    "//llvm/tools/llvm-cat",
    "//llvm/tools/llvm-cfi-verify",
    "//llvm/tools/llvm-cov",
    "//llvm/tools/llvm-cvtres",
    "//llvm/tools/llvm-cxxdump",
    "//llvm/tools/llvm-cxxfilt",
    "//llvm/tools/llvm-cxxmap",
    "//llvm/tools/llvm-diff",
    "//llvm/tools/llvm-dis",
    "//llvm/tools/llvm-dwarfdump",
    "//llvm/tools/llvm-dwp",
    "//llvm/tools/llvm-elfabi",
    "//llvm/tools/llvm-exegesis",
    "//llvm/tools/llvm-extract",
    "//llvm/tools/llvm-ifs",
    "//llvm/tools/llvm-isel-fuzzer",
    "//llvm/tools/llvm-jitlink",
    "//llvm/tools/llvm-link",
    "//llvm/tools/llvm-lipo",
    "//llvm/tools/llvm-lto",
    "//llvm/tools/llvm-lto2",
    "//llvm/tools/llvm-mc",
    "//llvm/tools/llvm-mca",
    "//llvm/tools/llvm-modextract",
    "//llvm/tools/llvm-mt",
    "//llvm/tools/llvm-nm",
    "//llvm/tools/llvm-objcopy:symlinks",
    "//llvm/tools/llvm-objdump",
    "//llvm/tools/llvm-opt-fuzzer",
    "//llvm/tools/llvm-opt-report",
    "//llvm/tools/llvm-pdbutil",
    "//llvm/tools/llvm-profdata",
    "//llvm/tools/llvm-rc",
    "//llvm/tools/llvm-readobj:symlinks",
    "//llvm/tools/llvm-reduce",
    "//llvm/tools/llvm-rtdyld",
    "//llvm/tools/llvm-size",
    "//llvm/tools/llvm-split",
    "//llvm/tools/llvm-strings",
    "//llvm/tools/llvm-symbolizer:symlinks",
    "//llvm/tools/llvm-undname",
    "//llvm/tools/llvm-xray",
    "//llvm/tools/lto",
    "//llvm/tools/obj2yaml",
    "//llvm/tools/opt",
    "//llvm/tools/sancov",
    "//llvm/tools/sanstats",
    "//llvm/tools/verify-uselistorder",
    "//llvm/tools/yaml2obj",
    "//llvm/unittests",
    "//llvm/utils/FileCheck",
    "//llvm/utils/TableGen:llvm-tblgen",
    "//llvm/utils/count",
    "//llvm/utils/llvm-lit",
    "//llvm/utils/not",

    # llvm-config wants libgtest_main.a to exist at runtime when run as in
    # its tests, but nothing in the tree depends on them.
    "//llvm/utils/unittest/UnitTestMain:gtest_main",
    "//llvm/utils/yaml-bench",
  ]
  if (host_os != "win") {
    # loadable_modules don't work on Windows.
    # FIXME: In the CMake build, ENABLE_SHARED makes them work somehow
    # (but they're off by default there too).
    deps += [
      "//llvm/lib/Transforms/Hello",
      "//llvm/tools/bugpoint-passes",
    ]
  }

  # FIXME: llvm_build_examples
  testonly = true
}

action("check-llvm") {
  script = "$root_out_dir/bin/llvm-lit"
  if (host_os == "win") {
    script += ".py"
  }
  args = [
    "-sv",
    "--param",
    "llvm_site_config=" + rebase_path(llvm_lit_site_cfg_file, root_out_dir),
    "--param",
    "llvm_unit_site_config=" +
        rebase_path(llvm_lit_unit_site_cfg_file, root_out_dir),
    rebase_path(".", root_out_dir),
  ]
  outputs = [
    "$target_gen_dir/run-lit",  # Non-existing, so that ninja runs it each time.
  ]

  # Since check-llvm is always dirty, //:default doesn't depend on it so that
  # it's not part of the default ninja target.  Hence, check-llvm shouldn't
  # have any deps except :test. so that the default target is sure to build
  # all the deps.
  deps = [
    ":test",
  ]
  testonly = true

  pool = "//:console"
}