From 61b03a0d9cb319173766383216deee74fd6d800e Mon Sep 17 00:00:00 2001 From: Alexander Lohnau Date: Sat, 7 Sep 2024 11:31:22 +0200 Subject: [PATCH] Make tests work when clang library is different from system default If we have found the clang folder, we can resolve the executable from there. In my case, I was compiling against clang16, but my system default was clang 14. The stacktrace is really confusing and hard to understand. Using the absolute path makes the log also better to understand and to reproduce the test results. --- ClazyTests.generated.cmake | 5 ++++- cmake/FindLLVM.cmake | 13 +++++++++++++ dev-scripts/generate.py | 5 ++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/ClazyTests.generated.cmake b/ClazyTests.generated.cmake index 204f0e5b..49b0f69e 100644 --- a/ClazyTests.generated.cmake +++ b/ClazyTests.generated.cmake @@ -2,8 +2,11 @@ macro(add_clazy_test name) add_test(NAME ${name} COMMAND python3 run_tests.py ${name} --verbose WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests/) + if (CLANG_EXECUTABLE_PATH) + set(CLANG_CXX_TEST "CLANGXX=${CLANG_EXECUTABLE_PATH};") + endif() set_property(TEST ${name} PROPERTY - ENVIRONMENT "CLAZYPLUGIN_CXX=$;CLAZYSTANDALONE_CXX=$;$<$:CLAZY_HAS_FILESYSTEM=>" + ENVIRONMENT "${CLANG_CXX_TEST}CLAZYPLUGIN_CXX=$;CLAZYSTANDALONE_CXX=$;$<$:CLAZY_HAS_FILESYSTEM=>" ) endmacro() diff --git a/cmake/FindLLVM.cmake b/cmake/FindLLVM.cmake index a1fd9e3f..da02e006 100644 --- a/cmake/FindLLVM.cmake +++ b/cmake/FindLLVM.cmake @@ -117,6 +117,19 @@ if (LLVM_FOUND) OUTPUT_STRIP_TRAILING_WHITESPACE ) + execute_process( + COMMAND ${LLVM_CONFIG_EXECUTABLE} --bindir + OUTPUT_VARIABLE LLVM_BIN_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + set(CLANG_EXECUTABLE_PATH "${LLVM_BIN_DIR}/clang") + if(EXISTS ${CLANG_EXECUTABLE_PATH}) + message(STATUS "Clang found: ${CLANG_EXECUTABLE_PATH}") + set(CLANG_EXECUTABLE ${CLANG_EXECUTABLE_PATH}) + else() + message(WARNING "Clang not found in LLVM bin directory: ${LLVM_BIN_DIR}") + endif() + # potentially add include dir from binary dir for non-installed LLVM execute_process( COMMAND ${LLVM_CONFIG_EXECUTABLE} --src-root diff --git a/dev-scripts/generate.py b/dev-scripts/generate.py index 2678aaba..11fc5bfc 100755 --- a/dev-scripts/generate.py +++ b/dev-scripts/generate.py @@ -468,8 +468,11 @@ def generate_ctest(checks): contents = """# This file was autogenerated by running: ./dev-scripts/generate.py --generate\n macro(add_clazy_test name) add_test(NAME ${name} COMMAND python3 run_tests.py ${name} --verbose WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests/) + if (CLANG_EXECUTABLE_PATH) + set(CLANG_CXX_TEST "CLANGXX=${CLANG_EXECUTABLE_PATH};") + endif() set_property(TEST ${name} PROPERTY - ENVIRONMENT "CLAZYPLUGIN_CXX=$;CLAZYSTANDALONE_CXX=$;$<$:CLAZY_HAS_FILESYSTEM=>" + ENVIRONMENT "${CLANG_CXX_TEST}CLAZYPLUGIN_CXX=$;CLAZYSTANDALONE_CXX=$;$<$:CLAZY_HAS_FILESYSTEM=>" ) endmacro()\n """ -- GitLab