diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2020-11-13 16:58:02 +0100 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2020-11-17 16:40:45 +0100 |
commit | c47432eda3c723e01b8b41878d954a1b69a62f7e (patch) | |
tree | 1acd2113fcff6b349ece3ec41cad0b448a6b420c /cmake | |
parent | f8b8a9a59f8f7eced57e9d68e86f11073eba20a8 (diff) |
Make syncing script capable of setting up new worktrees and clones
For missing dependencies, create worktrees from existing clones if
found, otherwise clone from the same remote.
Change-Id: Ie624e6c1b3f621dce43ee8cc7f06ce469851285b
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/QtTopLevelHelpers.cmake | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/cmake/QtTopLevelHelpers.cmake b/cmake/QtTopLevelHelpers.cmake index b5ce1e8a..42f01a14 100644 --- a/cmake/QtTopLevelHelpers.cmake +++ b/cmake/QtTopLevelHelpers.cmake @@ -144,6 +144,67 @@ function(qt_internal_checkout module revision) ) endfunction() +# clones or creates a worktree for $dependency, using the source of $dependent +function(qt_internal_get_dependency dependent dependency) + set(gitdir "") + set(remote "") + + # try to read the worktree source + execute_process( + COMMAND "git" "rev-parse" "--git-dir" + WORKING_DIRECTORY "./${dependent}" + RESULT_VARIABLE git_result + OUTPUT_VARIABLE git_stdout + ERROR_VARIABLE git_stderr + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + string(FIND "${git_stdout}" "${module}" index) + string(SUBSTRING "${git_stdout}" 0 ${index} gitdir) + message(DEBUG "Will look for clones in ${gitdir}") + + execute_process( + COMMAND "git" "remote" "get-url" "origin" + WORKING_DIRECTORY "./${dependent}" + RESULT_VARIABLE git_result + OUTPUT_VARIABLE git_stdout + ERROR_VARIABLE git_stderr + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + string(FIND "${git_stdout}" "${dependent}.git" index) + string(SUBSTRING "${git_stdout}" 0 ${index} remote) + message(DEBUG "Will clone from ${remote}") + + if(EXISTS "${gitdir}${dependency}") + # for the module we want, there seems to be a clone parallel to what we have + message(DEBUG "Adding worktree for ${dependency} from ${gitdir}${dependency}") + execute_process( + COMMAND "git" "worktree" "add" "${CMAKE_CURRENT_SOURCE_DIR}/${dependency}" + WORKING_DIRECTORY "${gitdir}/${dependency}" + RESULT_VARIABLE git_result + OUTPUT_VARIABLE git_stdout + ERROR_VARIABLE git_stderr + ) + if (git_result) + message(WARNING "${git_stdout}") + message(FATAL_ERROR "Failed to create worktree for '${dependency}': ${git_stderr}") + endif() + else() + # we don't find the existing clone, so clone from the saame remote + message(DEBUG "Cloning ${dependency} from ${remote}${dependency}.git") + execute_process( + COMMAND "git" "clone" "${remote}${dependency}.git" + WORKING_DIRECTORY "." + RESULT_VARIABLE git_result + OUTPUT_VARIABLE git_stdout + ERROR_VARIABLE git_stderr + ) + if (git_result) + message(WARNING "${git_stdout}") + message(FATAL_ERROR "Failed to clone '${dependency}': ${git_stderr}") + endif() + endif() +endfunction() + # evaluates the dependencies for $module, and checks all dependencies # out so that it is a consistent set function(qt_internal_sync_to module) @@ -192,6 +253,11 @@ function(qt_internal_sync_to module) continue() endif() + if(NOT EXISTS "./${dependency}") + message(DEBUG "No worktree for '${dependency}' found in '${CMAKE_CURRENT_SOURCE_DIR}'") + qt_internal_get_dependency("${module}" "${dependency}") + endif() + execute_process( COMMAND "git" "rev-parse" "HEAD" WORKING_DIRECTORY "./${dependency}" |