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.
This commit is contained in:
Jeff Epler 2017-08-15 19:54:05 -05:00
parent a11c373fc7
commit 1ff41f76a4

View file

@ -61,9 +61,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.")