Introduce explicit add_unittest_with_input_files target for tests that use llvm::getInputFileDirectory()

Using llvm::getInputFileDirectory() in unit tests is discouraged, so require an explicit opt-in.
This way, cmake also writes ~60 fewer unused files to disk.

Differential Revision: https://reviews.llvm.org/D52095

llvm-svn: 342248
This commit is contained in:
Nico Weber 2018-09-14 17:34:46 +00:00
parent 66945cf6e3
commit 1739dbf6a6
3 changed files with 14 additions and 6 deletions

View File

@ -1113,11 +1113,6 @@ function(add_unittest test_suite test_name)
# API for all shared libaries loaded by this executable.
target_link_libraries(${test_name} PRIVATE gtest_main gtest ${LLVM_PTHREAD_LIB})
set(LLVM_UNITTEST_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
configure_file(
${LLVM_MAIN_SRC_DIR}/unittests/unittest.cfg.in
${CMAKE_CURRENT_BINARY_DIR}/llvm.srcdir.txt)
add_dependencies(${test_suite} ${test_name})
get_target_property(test_suite_folder ${test_suite} FOLDER)
if (NOT ${test_suite_folder} STREQUAL "NOTFOUND")
@ -1125,6 +1120,16 @@ function(add_unittest test_suite test_name)
endif ()
endfunction()
# Use for test binaries that call llvm::getInputFileDirectory(). Use of this
# is discouraged.
function(add_unittest_with_input_files test_suite test_name)
set(LLVM_UNITTEST_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
configure_file(
${LLVM_MAIN_SRC_DIR}/unittests/unittest.cfg.in
${CMAKE_CURRENT_BINARY_DIR}/llvm.srcdir.txt)
add_unittest(${test_suite} ${test_name} ${ARGN})
endfunction()
# Generic support for adding a benchmark.
function(add_benchmark benchmark_name)

View File

@ -4,6 +4,9 @@ set_target_properties(UnitTests PROPERTIES FOLDER "Tests")
function(add_llvm_unittest test_dirname)
add_unittest(UnitTests ${test_dirname} ${ARGN})
endfunction()
function(add_llvm_unittest_with_input_files test_dirname)
add_unittest_with_input_files(UnitTests ${test_dirname} ${ARGN})
endfunction()
add_subdirectory(ADT)
add_subdirectory(Analysis)

View File

@ -4,7 +4,7 @@ set(LLVM_LINK_COMPONENTS
DebugInfoPDB
)
add_llvm_unittest(DebugInfoPDBTests
add_llvm_unittest_with_input_files(DebugInfoPDBTests
HashTableTest.cpp
NativeSymbolReuseTest.cpp
StringTableBuilderTest.cpp