From 98e6822fdf02d74e1b3e3ff4b1e7ac27138654c9 Mon Sep 17 00:00:00 2001 From: Bartosz Kosiorek Date: Wed, 13 Mar 2019 15:38:35 +0100 Subject: ExternalProject: Re-run 'git clone' when GIT_REMOTE_NAME changes --- Modules/ExternalProject.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/ExternalProject.cmake b/Modules/ExternalProject.cmake index 22e0523..5705b3a 100644 --- a/Modules/ExternalProject.cmake +++ b/Modules/ExternalProject.cmake @@ -2460,7 +2460,7 @@ function(_ep_add_download_command name) # set(repository ${git_repository}) set(module) - set(tag) + set(tag ${git_remote_name}) configure_file( "${CMAKE_ROOT}/Modules/RepositoryInfo.txt.in" "${stamp_dir}/${name}-gitinfo.txt" -- cgit v0.12 From 00b5f1a1b5f44167184e5602385986172afa7a3a Mon Sep 17 00:00:00 2001 From: Bartosz Kosiorek Date: Wed, 13 Mar 2019 15:40:24 +0100 Subject: ExternalProject: Simplify generated 'git clone' scripts Revise script generation to hard-code selected options instead of building them with logic inside the script. --- Modules/ExternalProject.cmake | 52 ++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/Modules/ExternalProject.cmake b/Modules/ExternalProject.cmake index 5705b3a..278020c 100644 --- a/Modules/ExternalProject.cmake +++ b/Modules/ExternalProject.cmake @@ -1053,11 +1053,6 @@ define_property(DIRECTORY PROPERTY "EP_UPDATE_DISCONNECTED" INHERITED ) function(_ep_write_gitclone_script script_filename source_dir git_EXECUTABLE git_repository git_tag git_remote_name git_submodules git_shallow git_progress git_config src_name work_dir gitclone_infofile gitclone_stampfile tls_verify) - if(NOT GIT_VERSION_STRING VERSION_LESS 1.7.10) - set(git_clone_shallow_options "--depth 1 --no-single-branch") - else() - set(git_clone_shallow_options "--depth 1") - endif() if(NOT GIT_VERSION_STRING VERSION_LESS 1.8.5) # Use `git checkout --` to avoid ambiguity with a local path. set(git_checkout_explicit-- "--") @@ -1067,12 +1062,30 @@ function(_ep_write_gitclone_script script_filename source_dir git_EXECUTABLE git # because that will not search for remote branch names, a common use case. set(git_checkout_explicit-- "") endif() - file(WRITE ${script_filename} -"if(\"${git_tag}\" STREQUAL \"\") - message(FATAL_ERROR \"Tag for git checkout should not be empty.\") -endif() + if("${git_tag}" STREQUAL "") + message(FATAL_ERROR "Tag for git checkout should not be empty.") + endif() -set(run 0) + set(git_clone_options) + if(git_shallow) + if(NOT GIT_VERSION_STRING VERSION_LESS 1.7.10) + list(APPEND git_clone_options "--depth 1 --no-single-branch") + else() + list(APPEND git_clone_options "--depth 1") + endif() + endif() + if(git_progress) + list(APPEND git_clone_options --progress) + endif() + foreach(config IN LISTS git_config) + list(APPEND git_clone_options --config ${config}) + endforeach() + if(NOT ${git_remote_name} STREQUAL "origin") + list(APPEND git_clone_options --origin \"${git_remote_name}\") + endif() + string (REPLACE ";" " " git_clone_options "${git_clone_options}") + file(WRITE ${script_filename} +"set(run 0) if(\"${gitclone_infofile}\" IS_NEWER_THAN \"${gitclone_stampfile}\") set(run 1) @@ -1100,29 +1113,12 @@ if(NOT \"x${tls_verify}\" STREQUAL \"x\" AND NOT tls_verify) -c http.sslVerify=false) endif() -set(git_clone_options) - -set(git_shallow \"${git_shallow}\") -if(git_shallow) - list(APPEND git_clone_options ${git_clone_shallow_options}) -endif() - -set(git_progress \"${git_progress}\") -if(git_progress) - list(APPEND git_clone_options --progress) -endif() - -set(git_config \"${git_config}\") -foreach(config IN LISTS git_config) - list(APPEND git_clone_options --config \${config}) -endforeach() - # try the clone 3 times in case there is an odd git clone issue set(error_code 1) set(number_of_tries 0) while(error_code AND number_of_tries LESS 3) execute_process( - COMMAND \"${git_EXECUTABLE}\" \${git_options} clone \${git_clone_options} --origin \"${git_remote_name}\" \"${git_repository}\" \"${src_name}\" + COMMAND \"${git_EXECUTABLE}\" \${git_options} clone ${git_clone_options} \"${git_repository}\" \"${src_name}\" WORKING_DIRECTORY \"${work_dir}\" RESULT_VARIABLE error_code ) -- cgit v0.12 From 8355665f8df5d9e1de5a50cb78d62071f55b7b43 Mon Sep 17 00:00:00 2001 From: Bartosz Kosiorek Date: Wed, 13 Mar 2019 15:41:29 +0100 Subject: ExternalProject: Drop unnecessary 'git submodule init' Since commit 79410eeb1f (ExternalProject: Initialize Git submodules recursively and on update (#16083), 2016-04-26, v3.6.0-rc1~105^2) our `git submodule update` step uses the `--init` flag. This makes the prior `git submodule init` unnecessary. --- Modules/ExternalProject.cmake | 9 --------- 1 file changed, 9 deletions(-) diff --git a/Modules/ExternalProject.cmake b/Modules/ExternalProject.cmake index 278020c..96250d3 100644 --- a/Modules/ExternalProject.cmake +++ b/Modules/ExternalProject.cmake @@ -1142,15 +1142,6 @@ if(error_code) endif() execute_process( - COMMAND \"${git_EXECUTABLE}\" \${git_options} submodule init ${git_submodules} - WORKING_DIRECTORY \"${work_dir}/${src_name}\" - RESULT_VARIABLE error_code - ) -if(error_code) - message(FATAL_ERROR \"Failed to init submodules in: '${work_dir}/${src_name}'\") -endif() - -execute_process( COMMAND \"${git_EXECUTABLE}\" \${git_options} submodule update --recursive --init ${git_submodules} WORKING_DIRECTORY \"${work_dir}/${src_name}\" RESULT_VARIABLE error_code -- cgit v0.12 From c58f5e116e0fd4fd883320812bfb052582005e90 Mon Sep 17 00:00:00 2001 From: Bartosz Kosiorek Date: Fri, 15 Mar 2019 14:14:03 +0100 Subject: ExternalProject: Extend documentation about GIT_TAG usage When GIT_SHALLOW is used, the '--depth 1 --no-single-branch' arguments are add. It means that only branch names and tags is downloaded to repository. Most Commit Hash is not working. With this commit the documentation was updated, to describe the limitation of GIT_SHALLOW. --- Modules/ExternalProject.cmake | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Modules/ExternalProject.cmake b/Modules/ExternalProject.cmake index 96250d3..4344bdb 100644 --- a/Modules/ExternalProject.cmake +++ b/Modules/ExternalProject.cmake @@ -251,6 +251,9 @@ External Project Definition The lack of such deterministic behavior makes the main project lose traceability and repeatability. + If ``GIT_SHALLOW`` is enabled then ``GIT_TAG`` works only with + branch names and tags. A commit hash is not allowed. + ``GIT_REMOTE_NAME `` The optional name of the remote. If this option is not specified, it defaults to ``origin``. -- cgit v0.12