Skip to content

Inject DLL paths on TestFoundation #3146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Tests/Foundation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,14 @@ add_custom_command(TARGET TestFoundation POST_BUILD
COMMAND
${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:FoundationXML> ${CMAKE_BINARY_DIR}/TestFoundation.app)

cmake_path(GET CMAKE_Swift_COMPILER PARENT_PATH Swift_LIBRARY_PATH)
# NOTE(stevapple): Path separator ; is passed as ? because it conflicts with CMake's list separator
xctest_discover_tests(TestFoundation
COMMAND
${CMAKE_BINARY_DIR}/TestFoundation.app/TestFoundation${CMAKE_EXECUTABLE_SUFFIX}
WORKING_DIRECTORY
${CMAKE_BINARY_DIR}/TestFoundation.app
PROPERTIES
ENVIRONMENT
LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/TestFoundation.app:$<TARGET_LINKER_FILE_DIR:XCTest>:$<TARGET_LINKER_FILE_DIR:dispatch>:$<TARGET_LINKER_FILE_DIR:swiftDispatch>:$<TARGET_LINKER_FILE_DIR:BlocksRuntime>)
LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/TestFoundation.app:$<TARGET_LINKER_FILE_DIR:XCTest>:$<TARGET_LINKER_FILE_DIR:dispatch>:$<TARGET_LINKER_FILE_DIR:swiftDispatch>:$<TARGET_LINKER_FILE_DIR:BlocksRuntime>
DLL_LIBRARY_PATH=${Swift_LIBRARY_PATH}?${CMAKE_BINARY_DIR}/bin?$<TARGET_FILE_DIR:XCTest>?$<TARGET_FILE_DIR:dispatch>?$<TARGET_FILE_DIR:swiftDispatch>?$<TARGET_FILE_DIR:BlocksRuntime>)
19 changes: 17 additions & 2 deletions cmake/modules/XCTestAddTests.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
set(properties ${TEST_PROPERTIES})
set(properties "${TEST_PROPERTIES}")
set(script)
set(tests)
set(dll_library_path)

function(add_command NAME)
set(_args "")
Expand All @@ -21,7 +22,7 @@ if(NOT EXISTS "${TEST_EXECUTABLE}")
)
endif()
# We need to figure out if some environment is needed to run the test listing.
cmake_parse_arguments("_properties" "" "ENVIRONMENT" "" ${properties})
cmake_parse_arguments("_properties" "" "" "ENVIRONMENT" ${properties})
if(_properties_ENVIRONMENT)
foreach(_env ${_properties_ENVIRONMENT})
string(REGEX REPLACE "([a-zA-Z0-9_]+)=(.*)" "\\1" _key "${_env}")
Expand All @@ -31,6 +32,13 @@ if(_properties_ENVIRONMENT)
endif()
endforeach()
endif()
# Set Path to avoid DLL missing
if (DEFINED ENV{DLL_LIBRARY_PATH} AND CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
string(REPLACE "?" ";" dll_library_path "$ENV{DLL_LIBRARY_PATH}")
set(ENV{Path} "${dll_library_path};$ENV{Path}")
string(REPLACE ";" "\\\\;" dll_library_path "${dll_library_path}")
endif()

execute_process(
COMMAND "${TEST_EXECUTABLE}" --list-tests
WORKING_DIRECTORY "${TEST_WORKING_DIR}"
Expand Down Expand Up @@ -75,6 +83,13 @@ foreach(line ${output})
WORKING_DIRECTORY "${TEST_WORKING_DIR}"
${properties}
)
if (NOT "${dll_library_path}" STREQUAL "")
add_command(set_tests_properties
"${pretty_target}"
PROPERTIES
ENVIRONMENT "Path=${dll_library_path}"
)
endif()
list(APPEND tests "${pretty_target}")
else()
message(FATAL_ERROR
Expand Down