Commit f6cbb02b authored by Brad King's avatar Brad King Committed by Kitware Robot

Merge topic 'ExternalProject-optimize-git'

c58f5e11 ExternalProject: Extend documentation about GIT_TAG usage
8355665f ExternalProject: Drop unnecessary 'git submodule init'
00b5f1a1 ExternalProject: Simplify generated 'git clone' scripts
98e6822f ExternalProject: Re-run 'git clone' when GIT_REMOTE_NAME changes
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !3095
parents 23874e40 c58f5e11
......@@ -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 <name>``
The optional name of the remote. If this option is not specified, it
defaults to ``origin``.
......@@ -1053,11 +1056,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 <tree-ish> --` to avoid ambiguity with a local path.
set(git_checkout_explicit-- "--")
......@@ -1067,12 +1065,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 +1116,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
)
......@@ -1145,15 +1144,6 @@ if(error_code)
message(FATAL_ERROR \"Failed to checkout tag: '${git_tag}'\")
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}\"
......@@ -2460,7 +2450,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"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment