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:
parent
e422262877
commit
d39fbaf4d7
1 changed files with 4 additions and 3 deletions
|
|
@ -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.")
|
||||
|
|
|
|||
Loading…
Reference in a new issue