diff --git a/cmake/px4_git.cmake b/cmake/px4_git.cmake index e818a1f5d9c..2d53aff023e 100644 --- a/cmake/px4_git.cmake +++ b/cmake/px4_git.cmake @@ -38,12 +38,45 @@ endif(px4_git_included) set(px4_git_included true) # Check all submodules once per configure, whether the build started from -# make, an IDE or CMake directly. +# make, an IDE or CMake directly. Builds that configure at the same time check +# them one at a time: git can't fetch submodules twice at once. +execute_process( + COMMAND git rev-parse --git-common-dir + WORKING_DIRECTORY ${PX4_SOURCE_DIR} + OUTPUT_VARIABLE px4_git_dir + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET + ) +# No lock where check_submodules.sh exits at once (GIT_SUBMODULES_ARE_EVIL). A +# lock that can't be taken, such as in a read-only git directory, or after the +# timeout, only warns: the check then runs without it, as before the lock. +set(px4_submodules_lock) +if(px4_git_dir AND "$ENV{GIT_SUBMODULES_ARE_EVIL}" STREQUAL "") + get_filename_component(px4_git_dir ${px4_git_dir} ABSOLUTE BASE_DIR ${PX4_SOURCE_DIR}) + set(px4_submodules_lock ${px4_git_dir}/px4_submodules.lock) + # file(LOCK) fails the configure when it can't create the lock file, whatever its RESULT_VARIABLE + execute_process( + COMMAND ${CMAKE_COMMAND} -E touch ${px4_submodules_lock} + RESULT_VARIABLE px4_submodules_lock_result + OUTPUT_QUIET + ERROR_QUIET + ) + if(px4_submodules_lock_result EQUAL 0) + file(LOCK ${px4_submodules_lock} GUARD FILE TIMEOUT 1800 RESULT_VARIABLE px4_submodules_lock_result) + endif() + if(NOT px4_submodules_lock_result STREQUAL "0") + message(WARNING "Could not lock ${px4_submodules_lock} (${px4_submodules_lock_result}): checking the submodules without the lock") + set(px4_submodules_lock) + endif() +endif() execute_process( COMMAND Tools/check_submodules.sh ${PX4_GIT_SUBMODULES} WORKING_DIRECTORY ${PX4_SOURCE_DIR} RESULT_VARIABLE check_submodules_result ) +if(px4_submodules_lock) + file(LOCK ${px4_submodules_lock} RELEASE) +endif() if(NOT check_submodules_result EQUAL 0) message(FATAL_ERROR "Tools/check_submodules.sh failed") endif()