From 421c17fe4585d14efbd218eac3f9b81c0a6031e8 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Fri, 4 Jan 2019 17:13:33 +0000 Subject: [PATCH] [gn build] Add check-llvm target and make it work With this, check-llvm runs and passes all of clang's lit tests. It doesn't run any of its unit tests yet. This is the only change in the GN build patch series that needs a change to a file outside of llvm/utils/gn: llvm/test/tools/llvm-config/booleans.test checks the result of llvm-config --build-system for some reason, so I'm updating the test to accept "gn" as valid output in addition to "cmake". (The alternative would be to let the gn build self-identify as cmake, which seems worse.) Like with check-clang and check-lld, running just ninja -C out/gn will build all prerequisites needed to run tests, but it won't run the tests (so that the build becomes clean after one build). Running ninja -C out/gn check-llvm will build prerequisites if needed and run the tests. The check-llvm target never becomes clean and runs tests every time. Differential Revision: https://reviews.llvm.org/D56195 llvm-svn: 350410 --- llvm/utils/gn/secondary/BUILD.gn | 54 +--- .../secondary/llvm/lib/Target/targets_string.gni | 10 + llvm/utils/gn/secondary/llvm/test/BUILD.gn | 297 +++++++++++++++++++++ .../llvm/test/llvm_lit_site_cfg_files.gni | 2 + .../gn/secondary/llvm/tools/llvm-config/BUILD.gn | 16 +- .../gn/secondary/llvm/utils/llvm-lit/BUILD.gn | 7 + 6 files changed, 322 insertions(+), 64 deletions(-) create mode 100644 llvm/utils/gn/secondary/llvm/lib/Target/targets_string.gni create mode 100644 llvm/utils/gn/secondary/llvm/test/BUILD.gn create mode 100644 llvm/utils/gn/secondary/llvm/test/llvm_lit_site_cfg_files.gni diff --git a/llvm/utils/gn/secondary/BUILD.gn b/llvm/utils/gn/secondary/BUILD.gn index f318513..af8f596 100644 --- a/llvm/utils/gn/secondary/BUILD.gn +++ b/llvm/utils/gn/secondary/BUILD.gn @@ -5,60 +5,8 @@ group("default") { deps = [ "//clang/test", "//lld/test", - "//llvm/tools/bugpoint", - "//llvm/tools/dsymutil", - "//llvm/tools/lli", - "//llvm/tools/lli/ChildTarget:lli-child-target", - "//llvm/tools/llvm-c-test", - "//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-dwp", - "//llvm/tools/llvm-exegesis", - "//llvm/tools/llvm-extract", - "//llvm/tools/llvm-isel-fuzzer", - "//llvm/tools/llvm-link", - "//llvm/tools/llvm-mca", - "//llvm/tools/llvm-mt", - "//llvm/tools/llvm-opt-fuzzer", - "//llvm/tools/llvm-opt-report", - "//llvm/tools/llvm-rc", - "//llvm/tools/llvm-rtdyld", - "//llvm/tools/llvm-size", - "//llvm/tools/llvm-split", - "//llvm/tools/llvm-strings", - "//llvm/tools/llvm-undname", - "//llvm/tools/llvm-xray", - "//llvm/tools/sancov", - "//llvm/tools/sanstats", - "//llvm/tools/verify-uselistorder", - "//llvm/utils/yaml-bench", + "//llvm/test", ] - 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-func-mapping", - ] - } - 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", - ] - } testonly = true } diff --git a/llvm/utils/gn/secondary/llvm/lib/Target/targets_string.gni b/llvm/utils/gn/secondary/llvm/lib/Target/targets_string.gni new file mode 100644 index 0000000..dcf8c68 --- /dev/null +++ b/llvm/utils/gn/secondary/llvm/lib/Target/targets_string.gni @@ -0,0 +1,10 @@ +import("//llvm/lib/Target/targets.gni") + +# A single string with all built targets, separated by spaces. +llvm_targets_to_build_string = "" +foreach(target, llvm_targets_to_build) { + if (llvm_targets_to_build_string != "") { + llvm_targets_to_build_string += " " + } + llvm_targets_to_build_string += target +} diff --git a/llvm/utils/gn/secondary/llvm/test/BUILD.gn b/llvm/utils/gn/secondary/llvm/test/BUILD.gn new file mode 100644 index 0000000..48e6e3e --- /dev/null +++ b/llvm/utils/gn/secondary/llvm/test/BUILD.gn @@ -0,0 +1,297 @@ +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_lit_site_cfg_files.gni") + +template("write_lit_config") { + action(target_name) { + script = "//llvm/utils/gn/build/write_cmake_config.py" + + sources = [ + invoker.input, + ] + outputs = [ + invoker.output, + ] + args = [ + "-o", + rebase_path(outputs[0], root_out_dir), + rebase_path(sources[0], root_out_dir), + + "LIT_SITE_CFG_IN_HEADER=## Autogenerated from ${sources[0]}, 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 + args += [ "SHLIBDIR=" + rebase_path("$root_out_dir/bin") ] + } else { + args += [ "SHLIBDIR=" + rebase_path("$root_out_dir/lib") ] + } + args += invoker.extra_args + } +} + +write_lit_config("lit_site_cfg") { + input = "//llvm/test/lit.site.cfg.py.in" + output = llvm_lit_site_cfg_file + extra_args = [ + "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_host_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_TOOL_LTO_BUILD=1", # The GN build always builds //llvm/tools/lto. + "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=", + ] + + if (host_cpu == "x64") { + extra_args += [ "HOST_ARCH=x86_64" ] + } else { + assert(false, "unimplemented host_cpu " + host_cpu) + } + + if (host_os == "mac") { + extra_args += [ + "EXEEXT=", + "HOST_OS=Darwin", + "SHLIBEXT=.dylib", + ] + } else if (host_os == "linux") { + extra_args += [ + "EXEEXT=", + "HOST_OS=Linux", + "SHLIBEXT=.so", + ] + } else if (host_os == "win") { + extra_args += [ + "EXEEXT=.exe", + "HOST_OS=Windows", + "SHLIBEXT=.dll", + ] + } 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_args += [ "GOLD_EXECUTABLE=ld" ] + } else { + extra_args += [ "GOLD_EXECUTABLE=" ] + } + if (host_os == "mac") { + extra_args += [ "LD64_EXECUTABLE=ld" ] + } else { + extra_args += [ "LD64_EXECUTABLE=" ] + } + + if (llvm_enable_assertions) { + extra_args += [ "ENABLE_ASSERTIONS=1" ] + } else { + extra_args += [ "ENABLE_ASSERTIONS=0" ] # Must be 0. + } + + if (llvm_enable_libxar) { + extra_args += [ "HAVE_LIBXAR=1" ] + } else { + extra_args += [ "HAVE_LIBXAR=0" ] # Must be 0. + } + + if (llvm_enable_dia_sdk) { + extra_args += [ "LLVM_ENABLE_DIA_SDK=1" ] + } else { + extra_args += [ "LLVM_ENABLE_DIA_SDK=0" ] # Must be 0. + } + + if (llvm_enable_libxml2) { + extra_args += [ "LLVM_LIBXML2_ENABLED=1" ] + } else { + extra_args += [ "LLVM_LIBXML2_ENABLED=" ] # Must be empty. + } + + if (llvm_enable_threads) { + extra_args += [ "LLVM_ENABLE_THREADS=1" ] + } else { + extra_args += [ "LLVM_ENABLE_THREADS=0" ] # Must be 0. + } + + if (llvm_enable_zlib) { + extra_args += [ "HAVE_LIBZ=1" ] + } else { + extra_args += [ "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_args = [ "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/lib/TextAPI", + "//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-exegesis", + "//llvm/tools/llvm-extract", + "//llvm/tools/llvm-isel-fuzzer", + "//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", + "//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/utils/FileCheck", + "//llvm/utils/TableGen:llvm-tblgen", + "//llvm/utils/count", + "//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: dep on "//llvm/unittests" once it exists + # 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" +} diff --git a/llvm/utils/gn/secondary/llvm/test/llvm_lit_site_cfg_files.gni b/llvm/utils/gn/secondary/llvm/test/llvm_lit_site_cfg_files.gni new file mode 100644 index 0000000..b0f5aca --- /dev/null +++ b/llvm/utils/gn/secondary/llvm/test/llvm_lit_site_cfg_files.gni @@ -0,0 +1,2 @@ +llvm_lit_site_cfg_file = "$root_gen_dir/llvm/test/lit.site.cfg.py" +llvm_lit_unit_site_cfg_file = "$root_gen_dir/llvm/test/Unit/lit.site.cfg.py" diff --git a/llvm/utils/gn/secondary/llvm/tools/llvm-config/BUILD.gn b/llvm/utils/gn/secondary/llvm/tools/llvm-config/BUILD.gn index a798c4f..ee5bb32 100644 --- a/llvm/utils/gn/secondary/llvm/tools/llvm-config/BUILD.gn +++ b/llvm/utils/gn/secondary/llvm/tools/llvm-config/BUILD.gn @@ -1,4 +1,4 @@ -import("//llvm/lib/Target/targets.gni") +import("//llvm/lib/Target/targets_string.gni") import("//llvm/utils/gn/build/buildflags.gni") import("//llvm/utils/gn/build/libs/pthread/enable.gni") import("//llvm/utils/gn/build/libs/terminfo/enable.gni") @@ -6,14 +6,6 @@ import("//llvm/utils/gn/build/libs/xml/enable.gni") import("//llvm/utils/gn/build/libs/zlib/enable.gni") import("//llvm/version.gni") -enable_targets = "" -foreach(target, llvm_targets_to_build) { - if (enable_targets != "") { - enable_targets += " " - } - enable_targets += target -} - action("BuildVariables.inc") { script = "//llvm/utils/gn/build/write_cmake_config.py" @@ -91,7 +83,7 @@ action("BuildVariables.inc") { "LLVM_CXXFLAGS=.", # FIXME "LLVM_BUILDMODE=$build_mode", "LLVM_LIBDIR_SUFFIX=", - "LLVM_TARGETS_BUILT=$enable_targets", + "LLVM_TARGETS_BUILT=$llvm_targets_to_build_string", "LLVM_SYSTEM_LIBS=$system_libs", "LLVM_BUILD_SYSTEM=gn", "LLVM_HAS_RTTI=0", @@ -108,12 +100,14 @@ action("BuildVariables.inc") { # FIXME: It'd be nice to not depend on llvm-build on this, Depending on all the # LLVMBuild.txt files just for this seems a bit overkill. `gn desc` should # have all this information too and could be called at build time. +# When this is removed, update llvm/test/BUILD.gn to no longer have unnecessary +# deps on a couple llvm/lib/ targets. action("LibraryDependencies.inc") { script = "//llvm/utils/llvm-build/llvm-build" output = "$target_gen_dir/LibraryDependencies.inc" args = [ "--native-target=$native_target", - "--enable-targets=$enable_targets", + "--enable-targets=$llvm_targets_to_build_string", "--write-library-table=" + rebase_path(output, root_out_dir), ] outputs = [ diff --git a/llvm/utils/gn/secondary/llvm/utils/llvm-lit/BUILD.gn b/llvm/utils/gn/secondary/llvm/utils/llvm-lit/BUILD.gn index 3865824..9568cb6 100644 --- a/llvm/utils/gn/secondary/llvm/utils/llvm-lit/BUILD.gn +++ b/llvm/utils/gn/secondary/llvm/utils/llvm-lit/BUILD.gn @@ -1,5 +1,6 @@ import("//clang/test/clang_lit_site_cfg_files.gni") import("//lld/test/lld_lit_site_cfg_files.gni") +import("//llvm/test/llvm_lit_site_cfg_files.gni") action("llvm-lit") { script = "//llvm/utils/gn/build/write_cmake_config.py" @@ -32,6 +33,8 @@ action("llvm-lit") { "//clang/test:lit_unit_site_cfg", "//lld/test:lit_site_cfg", "//lld/test:lit_unit_site_cfg", + "//llvm/test:lit_site_cfg", + "//llvm/test:lit_unit_site_cfg", ] # Note: \n is converted into a newline by write_cmake_config.py, not by gn. @@ -43,6 +46,10 @@ action("llvm-lit") { rebase_path(lld_lit_site_cfg_file) + "')\n" config_map += "map_config('" + rebase_path("//lld/test/Unit/lit.cfg.py") + "', '" + rebase_path(lld_lit_unit_site_cfg_file) + "')\n" + config_map += "map_config('" + rebase_path("//llvm/test/lit.cfg.py") + + "', '" + rebase_path(llvm_lit_site_cfg_file) + "')\n" + config_map += "map_config('" + rebase_path("//llvm/test/Unit/lit.cfg.py") + + "', '" + rebase_path(llvm_lit_unit_site_cfg_file) + "')\n" args = [ "-o", -- 2.7.4