From d39fbaf4d7f68d4b246d2ee27481b25a824a2b85 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 15 Aug 2017 19:54:05 -0500 Subject: [PATCH] sc_version_string: Use temporary names resilient against parallel builds In #359 I identify a race condition between multiple parallel invocations of cmake, which can arise naturally during ctests. Now that the file contents will not change without an intervening git commit, it is sufficient to ensure that the parallel invocations use distinct temporary file names with high probability. --- cmake/sc_version_string.cmake | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cmake/sc_version_string.cmake b/cmake/sc_version_string.cmake index 2acf43d9..e6e2501c 100644 --- a/cmake/sc_version_string.cmake +++ b/cmake/sc_version_string.cmake @@ -78,9 +78,10 @@ set(header_string "/* sc_version_string.h - written by cmake. Changes will be lo ) #don't update the file unless somethig changed -file(WRITE ${SC_VERSION_HEADER}.tmp ${header_string}) -execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SC_VERSION_HEADER}.tmp ${SC_VERSION_HEADER}) -execute_process(COMMAND ${CMAKE_COMMAND} -E remove ${SC_VERSION_HEADER}.tmp) +string(RANDOM tmpsuffix) +file(WRITE ${SC_VERSION_HEADER}.${tmpsuffix} ${header_string}) +execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SC_VERSION_HEADER}.${tmpsuffix} ${SC_VERSION_HEADER}) +execute_process(COMMAND ${CMAKE_COMMAND} -E remove ${SC_VERSION_HEADER}.${tmpsuffix}) if(NOT SC_IS_SUBBUILD) message("-- sc_version_string.h is up-to-date.")