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
import("//clang/lib/ARCMigrate/enable.gni")
import("//clang/lib/StaticAnalyzer/Frontend/enable.gni")
import("//llvm/lib/Target/targets.gni")
import("//llvm/triples.gni")
import("//llvm/utils/gn/build/libs/pthread/enable.gni")
import("//llvm/utils/gn/build/libs/zlib/enable.gni")
import("//llvm/utils/gn/build/write_cmake_config.gni")
import("clang_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",
      "CLANG_BINARY_DIR=" +
          rebase_path(get_label_info("//clang", "target_out_dir")),
      "CLANG_SOURCE_DIR=" + rebase_path("//clang"),
      "ENABLE_SHARED=0",
      "LLVM_BINARY_DIR=" +
          rebase_path(get_label_info("//llvm", "target_out_dir")),
      "LLVM_LIBS_DIR=",  # needed only for shared builds
      "LLVM_SOURCE_DIR=" + rebase_path("//llvm"),
      "LLVM_TOOLS_DIR=" + rebase_path("$root_out_dir/bin"),
      "TARGET_TRIPLE=$llvm_target_triple",
    ]
    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") {
  # Fully-qualified instead of relative for LIT_SITE_CFG_IN_HEADER.
  input = "//clang/test/lit.site.cfg.py.in"
  output = clang_lit_site_cfg_file

  extra_values = [
    "LLVM_WITH_Z3=",  # Must be empty, not 0.
    "CLANG_BUILD_EXAMPLES=0",
    "CLANG_DEFAULT_CXX_STDLIB=",  # Empty string means "default value" here.
    "CLANG_TOOLS_DIR=" + rebase_path("$root_out_dir/bin"),

    # This is only used if LLVM_USE_SANITIZER includes lsan and the host
    # OS is macOS. Since the GN build currently never uses LLVM_USE_SANITIZER,
    # this is never read.  If it's ever needed,
    # utils/gn/build/toolchain/BUILD.gn should get the compiler from a variable
    # that's also read here -- but that should happen after multi-toolchain
    # builds exist, to make sure it's a toolchain var.
    "CMAKE_CXX_COMPILER=c++",
    "ENABLE_BACKTRACES=1",
    "ENABLE_EXPERIMENTAL_NEW_PASS_MANAGER=0",
    "LLVM_HOST_TRIPLE=$llvm_current_triple",
    "LLVM_LIT_TOOLS_DIR=",  # Intentionally empty, matches cmake build.
    "LLVM_USE_SANITIZER=",
    "PYTHON_EXECUTABLE=$python_path",
    "USE_Z3_SOLVER=",
  ]

  if (clang_enable_arcmt) {
    extra_values += [ "CLANG_ENABLE_ARCMT=1" ]
  } else {
    extra_values += [ "CLANG_ENABLE_ARCMT=0" ]
  }

  if (clang_enable_static_analyzer) {
    extra_values += [ "CLANG_ENABLE_STATIC_ANALYZER=1" ]
  } else {
    extra_values += [ "CLANG_ENABLE_STATIC_ANALYZER=0" ]
  }

  if (llvm_enable_zlib) {
    extra_values += [ "HAVE_LIBZ=1" ]
  } else {
    extra_values += [ "HAVE_LIBZ=0" ]  # Must be 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 == "mac") {
    extra_values += [ "LLVM_PLUGIN_EXT=.dylib" ]
  } else if (host_os == "win") {
    extra_values += [ "LLVM_PLUGIN_EXT=.dll" ]
  } else {
    extra_values += [ "LLVM_PLUGIN_EXT=.so" ]
  }

  if (host_os == "win") {
    extra_values += [ "LLVM_ENABLE_PLUGINS=0" ]
  } else {
    # FIXME: Analysis/plugins need global -fPIC
    extra_values += [ "LLVM_ENABLE_PLUGINS=0" ]
  }

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

write_lit_config("lit_unit_site_cfg") {
  # Fully-qualified instead of relative for LIT_SITE_CFG_IN_HEADER.
  input = "//clang/test/Unit/lit.site.cfg.py.in"
  output = clang_lit_unit_site_cfg_file
  extra_values = [ "LLVM_BUILD_MODE=." ]
}

# This target should contain all dependencies of check-clang.
# //:default depends on it, so that ninja's default target builds all
# prerequisites for check-clang but doesn't run check-clang itself.
group("test") {
  deps = [
    ":lit_site_cfg",
    ":lit_unit_site_cfg",
    "//clang/lib/Headers",
    "//clang/tools/c-index-test",
    "//clang/tools/clang-diff",
    "//clang/tools/clang-format",
    "//clang/tools/clang-import-test",
    "//clang/tools/clang-offload-bundler",
    "//clang/tools/clang-refactor",
    "//clang/tools/clang-rename",
    "//clang/tools/clang-scan-deps",
    "//clang/tools/diagtool",
    "//clang/tools/driver:symlinks",
    "//clang/unittests",
    "//clang/utils/TableGen:clang-tblgen",
    "//clang/utils/hmaptool",
    "//llvm/tools/llc",
    "//llvm/tools/llvm-as",
    "//llvm/tools/llvm-bcanalyzer",
    "//llvm/tools/llvm-cat",
    "//llvm/tools/llvm-config",
    "//llvm/tools/llvm-dis",
    "//llvm/tools/llvm-dwarfdump",
    "//llvm/tools/llvm-ifs",
    "//llvm/tools/llvm-lto",
    "//llvm/tools/llvm-lto2",
    "//llvm/tools/llvm-modextract",
    "//llvm/tools/llvm-nm:symlinks",
    "//llvm/tools/llvm-objdump:symlinks",
    "//llvm/tools/llvm-profdata",
    "//llvm/tools/llvm-readobj:symlinks",
    "//llvm/tools/llvm-symbolizer:symlinks",
    "//llvm/tools/opt",
    "//llvm/utils/FileCheck",
    "//llvm/utils/count",
    "//llvm/utils/llvm-lit",
    "//llvm/utils/not",
  ]
  if (clang_enable_arcmt) {
    deps += [
      "//clang/tools/arcmt-test",
      "//clang/tools/c-arcmt-test",
    ]
  }
  if (clang_enable_static_analyzer) {
    deps += [
      "//clang/tools/clang-check",
      "//clang/tools/clang-extdef-mapping",
    ]
  }

  # FIXME: clang_build_examples
  testonly = true
}

action("check-clang") {
  script = "$root_out_dir/bin/llvm-lit"
  if (host_os == "win") {
    script += ".py"
  }
  args = [
    "-sv",
    "--param",
    "clang_site_config=" + rebase_path(clang_lit_site_cfg_file, root_out_dir),
    "--param",
    "clang_unit_site_config=" +
        rebase_path(clang_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-clang is always dirty, //:default doesn't depend on it so that
  # it's not part of the default ninja target.  Hence, check-clang 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"
}