llvm.org GIT mirror llvm / ccf5494 utils / gn / secondary / llvm / test / BUILD.gn
ccf5494

Tree @ccf5494 (Download .tar.gz)

BUILD.gn @ccf5494raw · history · blame

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",

    # 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 {
    assert(false, "unimplemented host_cpu " + host_cpu)
  }

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

  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-isel-fuzzer",
    "//llvm/tools/llvm-jitlink",
    "//llvm/tools/llvm-link",
    "//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-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"
}