Skip to content

Commit

Permalink
ExternalProject: Refresh and restore patch to avoid deleting the clones
Browse files Browse the repository at this point in the history
  • Loading branch information
drdanz committed Mar 19, 2019
1 parent 3df72ef commit 582b5bc
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 25 deletions.
111 changes: 87 additions & 24 deletions cmake-next/proposed/ExternalProject.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1099,14 +1099,6 @@ if(NOT run)
return()
endif()
execute_process(
COMMAND \${CMAKE_COMMAND} -E remove_directory \"${source_dir}\"
RESULT_VARIABLE error_code
)
if(error_code)
message(FATAL_ERROR \"Failed to remove directory: '${source_dir}'\")
endif()
set(git_options)
# disable cert checking if explicitly told not to do it
Expand All @@ -1116,23 +1108,94 @@ if(NOT \"x${tls_verify}\" STREQUAL \"x\" AND NOT tls_verify)
-c http.sslVerify=false)
endif()
# 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} \"${git_repository}\" \"${src_name}\"
WORKING_DIRECTORY \"${work_dir}\"
RESULT_VARIABLE error_code
)
math(EXPR number_of_tries \"\${number_of_tries} + 1\")
endwhile()
if(number_of_tries GREATER 1)
message(STATUS \"Had to git clone more than once:
\${number_of_tries} times.\")
if(EXISTS \"${source_dir}\")
if(NOT IS_DIRECTORY \"${source_dir}\")
# FIXME Perhaps support symbolic links?
message(FATAL_ERROR \"\\\"${source_dir}\\\" exists and is not a git repository. Remove it and try again\")
elseif(NOT IS_DIRECTORY \"${source_dir}/.git\")
file(GLOB files \"${source_dir}/*\")
list(LENGTH files nfiles)
if(nfiles)
message(FATAL_ERROR \"\\\"${source_dir}\\\" folder exists and is not a git repository. Remove it and try again\")
endif()
else()
# Already initialized git repository: no need to clone again
execute_process(
COMMAND \"${git_EXECUTABLE}\" config --local --get remote.origin.url
WORKING_DIRECTORY \"${work_dir}/${src_name}\"
OUTPUT_VARIABLE origin_url
RESULT_VARIABLE error_code
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(error_code)
message(FATAL_ERROR \"Failed to get origin remote url in: '${work_dir}/${src_name}'\")
endif()
if(\"\${origin_url}\" STREQUAL \"${git_repository}\")
message(STATUS \"Avoiding repeated git clone, repository already exists\")
return()
else()
string(TIMESTAMP now \"%Y%m%d%H%M%S\")
message(WARNING \"Repository URL is different. Renaming 'origin' remote to 'origin.\${now}'\")
execute_process(
COMMAND \"${git_EXECUTABLE}\" remote rename origin origin.\${now}
WORKING_DIRECTORY \"${work_dir}/${src_name}\"
RESULT_VARIABLE error_code
)
if(error_code)
message(FATAL_ERROR \"Failed to rename remote in: '${work_dir}/${src_name}'\")
endif()
execute_process(
COMMAND \"${git_EXECUTABLE}\" remote add origin \"${git_repository}\"
WORKING_DIRECTORY \"${work_dir}/${src_name}\"
RESULT_VARIABLE error_code
)
if(error_code)
message(FATAL_ERROR \"Failed to add origin remote in: '${work_dir}/${src_name}'\")
endif()
# try the fetch 3 times incase there is an odd git fetch 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} fetch \${git_clone_options} origin
WORKING_DIRECTORY \"${work_dir}/${src_name}\"
RESULT_VARIABLE error_code
)
math(EXPR number_of_tries \"\${number_of_tries} + 1\")
endwhile()
if(number_of_tries GREATER 1)
message(STATUS \"Had to git fetch more than once:
\${number_of_tries} times.\")
endif()
if(error_code)
message(FATAL_ERROR \"Failed to fetch in: '${work_dir}/${src_name}'\")
endif()
endif()
endif()
endif()
if(error_code)
message(FATAL_ERROR \"Failed to clone repository: '${git_repository}'\")
# Now perform the clone if still required
if(NOT IS_DIRECTORY \"${source_dir}/.git\")
# 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} \"${git_repository}\" \"${src_name}\"
WORKING_DIRECTORY \"${work_dir}\"
RESULT_VARIABLE error_code
)
math(EXPR number_of_tries \"\${number_of_tries} + 1\")
endwhile()
if(number_of_tries GREATER 1)
message(STATUS \"Had to git clone more than once:
\${number_of_tries} times.\")
endif()
if(error_code)
message(FATAL_ERROR \"Failed to clone repository: '${git_repository}'\")
endif()
endif()
execute_process(
Expand Down
2 changes: 1 addition & 1 deletion modules/YCMEPHelper.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ set(__YCMEPHELPER_INCLUDED TRUE)

# Files downloaded during YCM bootstrap
set(_ycm_CMakeParseArguments_sha1sum 0c4d3f7ed248145cbeb67cbd6fd7190baf2e4517)
set(_ycm_ExternalProject_sha1sum 824483b96f959497397955983fb5b4b789abff53)
set(_ycm_ExternalProject_sha1sum 62ed9b37172e01fd13f356d8a4a6a599d7aed054)

# Files in all projects that need to bootstrap YCM
set(_ycm_IncludeUrl_sha1sum 921a037133255d01b644c16f19494cb08d98c462)
Expand Down

0 comments on commit 582b5bc

Please sign in to comment.