From 034a1967a6b6f847a2698ff810625d1e4e232762 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Tue, 1 Dec 2020 17:52:56 +0100 Subject: [PATCH] Initialize missing submodules if a supermodule is present When fetching dependencies, the submodule directory might not exist or might be empty. If so, try to initialize the submodule before trying to add the worktree. Change-Id: Ie4d6ec483ac9ea3f9207d5ab4cea34d6e0fb2921 Reviewed-by: Alexandru Croitor (cherry picked from commit 21fea13125ff9d1ce80e23381a09a4c442fb50fe) Reviewed-by: Qt Cherry-pick Bot --- cmake/QtTopLevelHelpers.cmake | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cmake/QtTopLevelHelpers.cmake b/cmake/QtTopLevelHelpers.cmake index abc72507..920378c3 100644 --- a/cmake/QtTopLevelHelpers.cmake +++ b/cmake/QtTopLevelHelpers.cmake @@ -182,6 +182,21 @@ function(qt_internal_get_dependency dependent dependency) string(SUBSTRING "${git_stdout}" 0 ${index} remote) message(DEBUG "Will clone from ${remote}") + if(EXISTS "${gitdir}.gitmodules" AND NOT EXISTS "${gitdir}${dependency}/.git") + # super repo exists, but the submodule we need does not - try to initialize + message(NOTICE "Initializing submodule '${dependency}' from ${gitdir}") + execute_process( + COMMAND "git" "submodule" "update" "--init" "${dependency}" + WORKING_DIRECTORY "${gitdir}" + RESULT_VARIABLE git_result + ${swallow_output} + ) + if (git_result) + # ignore errors, fall back to an independent clone instead + message(WARNING "Failed to initialize submodule '${dependency}' from ${gitdir}") + endif() + endif() + if(EXISTS "${gitdir}${dependency}") # for the module we want, there seems to be a clone parallel to what we have message(NOTICE "Adding worktree for ${dependency} from ${gitdir}${dependency}")