Explorar o código

Merge topic 'gtest-discovery-race-condition'

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

Acked-by: Kitware Robot <[email protected]>
Merge-request: !11357
Brad King hai 4 meses
pai
achega
4af712ea3b
Modificáronse 1 ficheiros con 11 adicións e 1 borrados
  1. 11 1
      Modules/GoogleTestAddTests.cmake

+ 11 - 1
Modules/GoogleTestAddTests.cmake

@@ -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}")