ExternalProject: Avoid repeated git clone operations (#12564)

By tracking a stamp file within the git clone script itself.

Avoids a 2nd git clone operation after switching from Debug
to Release builds in Visual Studio, or vice-versa.
This commit is contained in:
David Cole 2012-04-28 11:40:12 -04:00
parent d14c02434a
commit 08db81e008
1 changed files with 26 additions and 1 deletions

View File

@ -252,12 +252,23 @@ define_property(DIRECTORY PROPERTY "EP_STEP_TARGETS" INHERITED
) )
function(_ep_write_gitclone_script script_filename source_dir git_EXECUTABLE git_repository git_tag src_name work_dir) function(_ep_write_gitclone_script script_filename source_dir git_EXECUTABLE git_repository git_tag src_name work_dir gitclone_infofile gitclone_stampfile)
file(WRITE ${script_filename} file(WRITE ${script_filename}
"if(\"${git_tag}\" STREQUAL \"\") "if(\"${git_tag}\" STREQUAL \"\")
message(FATAL_ERROR \"Tag for git checkout should not be empty.\") message(FATAL_ERROR \"Tag for git checkout should not be empty.\")
endif() endif()
set(run 0)
if(\"${gitclone_infofile}\" IS_NEWER_THAN \"${gitclone_stampfile}\")
set(run 1)
endif()
if(NOT run)
message(STATUS \"Avoiding repeated git clone, stamp file is up to date: '${gitclone_stampfile}'\")
return()
endif()
execute_process( execute_process(
COMMAND \${CMAKE_COMMAND} -E remove_directory \"${source_dir}\" COMMAND \${CMAKE_COMMAND} -E remove_directory \"${source_dir}\"
RESULT_VARIABLE error_code RESULT_VARIABLE error_code
@ -302,6 +313,19 @@ if(error_code)
message(FATAL_ERROR \"Failed to update submodules in: '${work_dir}/${src_name}'\") message(FATAL_ERROR \"Failed to update submodules in: '${work_dir}/${src_name}'\")
endif() endif()
# Complete success, update the script-last-run stamp file:
#
execute_process(
COMMAND \${CMAKE_COMMAND} -E copy
\"${gitclone_infofile}\"
\"${gitclone_stampfile}\"
WORKING_DIRECTORY \"${work_dir}/${src_name}\"
RESULT_VARIABLE error_code
)
if(error_code)
message(FATAL_ERROR \"Failed to copy script-last-run stamp file: '${gitclone_stampfile}'\")
endif()
" "
) )
@ -1115,6 +1139,7 @@ function(_ep_add_download_command name)
# #
_ep_write_gitclone_script(${tmp_dir}/${name}-gitclone.cmake ${source_dir} _ep_write_gitclone_script(${tmp_dir}/${name}-gitclone.cmake ${source_dir}
${GIT_EXECUTABLE} ${git_repository} ${git_tag} ${src_name} ${work_dir} ${GIT_EXECUTABLE} ${git_repository} ${git_tag} ${src_name} ${work_dir}
${stamp_dir}/${name}-gitinfo.txt ${stamp_dir}/${name}-gitclone-lastrun.txt
) )
set(comment "Performing download step (git clone) for '${name}'") set(comment "Performing download step (git clone) for '${name}'")
set(cmd ${CMAKE_COMMAND} -P ${tmp_dir}/${name}-gitclone.cmake) set(cmd ${CMAKE_COMMAND} -P ${tmp_dir}/${name}-gitclone.cmake)