Merge topic 'gtest-discovery-race-condition'

6680df042e GoogleTest: Avoid POST_BUILD race condition for gtest_discover_tests()

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !11357
This commit is contained in:
Brad King
2025-10-27 13:35:23 +00:00
committed by Kitware Robot
+11 -1
View File
@@ -342,7 +342,17 @@ function(gtest_discover_tests_impl)
set(discovery_extra_args "[==[${discovery_extra_args}]==]")
endif()
set(json_file "${arg_TEST_WORKING_DIR}/cmake_test_discovery.json")
# Avoid a potential race condition for the POST_BUILD case when multiple
# calls are made to gtest_discover_tests() for different targets but the same
# working directory. For PRE_TEST, we're always executing serially during the
# ctest setup phase, so there is no race condition there, but POST_BUILD can
# lead to this code path being run in parallel. Use a hash to avoid potential
# problems with very long target names.
string(SHA256 target_hash "${arg_TEST_TARGET}")
string(SUBSTRING "${target_hash}" 0 10 target_hash)
set(json_file
"${arg_TEST_WORKING_DIR}/cmake_test_discovery_${target_hash}.json"
)
# Remove json file to make sure we don't pick up an outdated one
file(REMOVE "${json_file}")