From aa980c760bd2e8c061b3b2426bc05f498f9d2167 Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Wed, 19 Feb 2014 10:04:29 +0000 Subject: [PATCH] [CMake] Add the way to run tests in standalone build. 1) Depend on llvm-config (configured in LLVM_CONFIG_PATH) to get necessary LLVM source/binary directories. 2) Add basic support for running lit tests (check-xsan commands). For now this "support" is far from what we want: * unit tests are not built currently. * lit tests use Clang/compiler-rt from LLVM build directory, not the host compiler or just-built compiler-rt libraries. We should make a choice on the way we intend ti run compiler-rt lit testsuite: a) use either Clang from LLVM build tree, or the host compiler. b) use either just-built runtimes, or the runtimes shipped with the host compiler. Using just-built runtimes is tricky - we have to know where to put them, so that Clang/GCC driver would pick them up (and not overwrite the existing runtimes). Using a host compiler instead of Clang from LLVM build tree will give us a chance to run lit tests under GCC (which already has support for several sanitizers). That is, I tend to make the following choice: if we're in a standalone compiler-rt build, use host compiler with its set of runtime libraries to run lit tests. This will effectively decouple "make compiler-rt" and "make check-compiler-rt" in a standalone build - the latter wouldn't invoke the former. Note that if we decide to fix LLVM/Clang/compiler-rt build system so that it would configure/build compiler-rt with just-built Clang (as we do in Makefile-based build), this will not be a problem - we can add a dependency to ensure that clang/compiler-rt are rebuilt before running compiler-rt tests. llvm-svn: 201656 --- compiler-rt/CMakeLists.txt | 47 ++++++++++++++++++++++++++------- compiler-rt/test/CMakeLists.txt | 12 ++++++--- 2 files changed, 45 insertions(+), 14 deletions(-) diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt index ec63259b7fc4..c5420516abd9 100644 --- a/compiler-rt/CMakeLists.txt +++ b/compiler-rt/CMakeLists.txt @@ -44,23 +44,50 @@ else() "Path where built compiler-rt libraries should be stored.") set(COMPILER_RT_INSTALL_PATH ${CMAKE_INSTALL_PREFIX} CACHE PATH "Path where built compiler-rt libraries should be installed.") - # FIXME: Rely on llvm-config instead. - set(LLVM_BUILD_DIR "" CACHE PATH "Path to LLVM build tree.") - if (NOT LLVM_BUILD_DIR) - message(FATAL_ERROR "LLVM_BUILD_DIR must be specified.") + + set(LLVM_CONFIG_PATH "" CACHE PATH "Path to llvm-config binary") + if (NOT LLVM_CONFIG_PATH) + find_program(LLVM_CONFIG_PATH "llvm-config") + if (NOT LLVM_CONFIG_PATH) + message(FATAL_ERROR "llvm-config not found: specify LLVM_CONFIG_PATH") + endif() endif() + execute_process( + COMMAND ${LLVM_CONFIG_PATH} "--obj-root" "--bindir" "--libdir" "--src-root" + RESULT_VARIABLE HAD_ERROR + OUTPUT_VARIABLE CONFIG_OUTPUT) + if (HAD_ERROR) + message(FATAL_ERROR "llvm-config failed with status ${HAD_ERROR}") + endif() + string(REGEX REPLACE "[ \t]*[\r\n]+[ \t]*" ";" CONFIG_OUTPUT ${CONFIG_OUTPUT}) + list(GET CONFIG_OUTPUT 0 LLVM_BINARY_DIR) + list(GET CONFIG_OUTPUT 1 LLVM_TOOLS_BINARY_DIR) + list(GET CONFIG_OUTPUT 2 LLVM_LIBRARY_DIR) + list(GET CONFIG_OUTPUT 3 LLVM_MAIN_SRC_DIR) + # Make use of LLVM CMake modules. - set(LLVM_CMAKE_PATH "${LLVM_BUILD_DIR}/share/llvm/cmake") + set(LLVM_CMAKE_PATH "${LLVM_BINARY_DIR}/share/llvm/cmake") list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_PATH}") # Get some LLVM variables from LLVMConfig. include("${LLVM_CMAKE_PATH}/LLVMConfig.cmake") - # Setup another LLVM variables. - # FIXME: get the following paths from llvm-config instead. - set(LLVM_TOOLS_BINARY_DIR "${LLVM_BUILD_DIR}/bin") - set(LLVM_LIBRARY_DIR "${LLVM_BUILD_DIR}/lib") - set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib) + + # Find Python interpreter. + set(Python_ADDITIONAL_VERSIONS 2.7 2.6 2.5) + include(FindPythonInterp) + if(NOT PYTHONINTERP_FOUND) + message(FATAL_ERROR " + Unable to find Python interpreter required testing. Please install Python + or specify the PYTHON_EXECUTABLE CMake variable.") + endif() + + # Define default arguments to lit. + set(LIT_ARGS_DEFAULT "-sv") + if (MSVC OR XCODE) + set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar") + endif() + set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit") endif() string(TOLOWER ${CMAKE_SYSTEM_NAME} COMPILER_RT_OS_DIR) diff --git a/compiler-rt/test/CMakeLists.txt b/compiler-rt/test/CMakeLists.txt index 1a614e0fb6d7..30735d70f65f 100644 --- a/compiler-rt/test/CMakeLists.txt +++ b/compiler-rt/test/CMakeLists.txt @@ -6,12 +6,16 @@ configure_lit_site_cfg( # add_subdirectory(BlocksRuntime) # add_subdirectory(builtins) +set(SANITIZER_COMMON_LIT_TEST_DEPS) # When ANDROID, we build tests with the host compiler (i.e. CMAKE_C_COMPILER), # and run tests with tools from the host toolchain. -if (NOT ANDROID) - set(SANITIZER_COMMON_LIT_TEST_DEPS - clang clang-headers FileCheck count not llvm-nm llvm-symbolizer - compiler-rt-headers) +if(NOT ANDROID) + if(NOT COMPILER_RT_STANDALONE_BUILD) + # Use LLVM utils and Clang from the same build tree. + list(APPEND SANITIZER_COMMON_LIT_TEST_DEPS + clang clang-headers FileCheck count not llvm-nm llvm-symbolizer + compiler-rt-headers) + endif() if(UNIX) list(APPEND SANITIZER_COMMON_LIT_TEST_DEPS SanitizerLintCheck) endif()