Skip to content

Commit

Permalink
Fix non-atomic atomic_configure_file (#1150)
Browse files Browse the repository at this point in the history
* Fix non-atomic atomic_configure_file
* Update atomic_configure_file.cmake
  • Loading branch information
zig-for authored Jul 4, 2022
1 parent cad7e91 commit 2612c4c
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions cmake/atomic_configure_file.cmake
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
function(atomic_configure_file input output)
string(RANDOM random_id)
get_filename_component(output_file_name ${output} NAME)
get_filename_component(atomic_file ${output} NAME)
set(atomic_file "${CMAKE_BINARY_DIR}/atomic_configure/${atomic_file}")
set(atomic_file "${CMAKE_BINARY_DIR}/atomic_configure/${atomic_file}.${random_id}")
configure_file("${input}" "${atomic_file}" ${ARGN})
get_filename_component(output_path ${output} PATH)
# sync multiple catkin cmake processes writing to that location
if (NOT CMAKE_VERSION VERSION_LESS 3.2)
file(LOCK "${output_path}" DIRECTORY GUARD FUNCTION)
endif()
file(COPY "${atomic_file}" DESTINATION "${output_path}")
file(RENAME "${output_path}/${output_file_name}.${random_id}" "${output_path}/${output_file_name}")
endfunction()

0 comments on commit 2612c4c

Please sign in to comment.