Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parallel builds #955

Merged
merged 4 commits into from
Sep 4, 2018
Merged

Conversation

rhaschke
Copy link
Contributor

This PR addresses an issue originally raised in catkin/catkin_tools#422, but which is actually related to the underlying catkin cmake files.

.. to allow operation across file systems
.. to sync multiple cmake processes writing to that location
@rhaschke rhaschke force-pushed the fix-parallel-builds branch from 6787656 to bbfe1a9 Compare August 29, 2018 08:23
endif()
file(RENAME "${atomic_file}" "${output}")
# sync multiple catkin cmake processes writing to that location
file(LOCK "${output_path}" DIRECTORY GUARD FUNCTION)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This signature is only available as of CMake 3.2. Please use it only conditionally.

While this ensures mutually exclusive access in CMake are any of the files generated by this function accessed in parallel from non-CMake processes?

@rhaschke
Copy link
Contributor Author

@dirk-thomas Valid point. Fixed.

if(NOT EXISTS ${output_path})
file(MAKE_DIRECTORY ${output_path})
# sync multiple catkin cmake processes writing to that location
if (CMAKE_VERSION VERSION_GREATER 3.2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition evaluates to FALSE for CMake 3.2 for which it should be TRUE.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@@ -1,9 +1,11 @@
function(atomic_configure_file input output)
set(atomic_file "${CMAKE_BINARY_DIR}/atomic_configure_file")
get_filename_component(atomic_file ${output} NAME)
set(atomic_file "${CMAKE_BINARY_DIR}/${atomic_file}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To reduce the chance of collisions if the basename of output is the same as an existing file in the binary dir please keep atomic_configure_file as a prefix to the name: set(atomic_file "${CMAKE_BINARY_DIR}/atomic_configure_file_${atomic_file}")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was changed intentionally. Using a different name than the final one, the copying needs two steps: first copying and then renaming the file at the destination location. (Remember that COPY doesn't allow for a simultaneous rename).
For me, this contradicts the atomic idea.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point - I didn't consider that. Can you place the file in a subdirectory atomic_configure_file then to minimize the chance of collisions.

@rhaschke rhaschke force-pushed the fix-parallel-builds branch from 7fabc69 to 52bc686 Compare August 31, 2018 06:06
@dirk-thomas
Copy link
Member

Thank you for the patch and for iterating on it.

@dirk-thomas dirk-thomas merged commit 4f5bcd8 into ros:kinetic-devel Sep 4, 2018
@rhaschke rhaschke deleted the fix-parallel-builds branch October 24, 2018 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants