mirror of
https://github.com/cpm-cmake/CPM.cmake.git
synced 2025-11-23 04:37:43 -05:00
CPMAddPackage fails if the SOURCE_DIR directory is deleted. (#370)
* Fixed: Deleted SOURCE_DIR directory would abort just after git stash save --quiet;--include-untracked * Fixed: Review comments * Added: Integration test for deleted SOURCE_DIR with FetchContent * Fixed: Review comments * Fixed: Review comments
This commit is contained in:
committed by
GitHub
parent
5961f9f9fb
commit
ede60451a9
@@ -650,6 +650,20 @@ function(CPMAddPackage)
|
||||
list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS DOWNLOAD_COMMAND ${CPM_ARGS_DOWNLOAD_COMMAND})
|
||||
elseif(DEFINED CPM_ARGS_SOURCE_DIR)
|
||||
list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS SOURCE_DIR ${CPM_ARGS_SOURCE_DIR})
|
||||
if(NOT IS_ABSOLUTE ${CPM_ARGS_SOURCE_DIR})
|
||||
# Expand `CPM_ARGS_SOURCE_DIR` relative path. This is important because EXISTS doesn't work
|
||||
# for relative paths.
|
||||
get_filename_component(
|
||||
source_directory ${CPM_ARGS_SOURCE_DIR} REALPATH BASE_DIR ${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
else()
|
||||
set(source_directory ${CPM_ARGS_SOURCE_DIR})
|
||||
endif()
|
||||
if(NOT EXISTS ${source_directory})
|
||||
string(TOLOWER ${CPM_ARGS_NAME} lower_case_name)
|
||||
# remove timestamps so CMake will re-download the dependency
|
||||
file(REMOVE_RECURSE "${CPM_FETCHCONTENT_BASE_DIR}/${lower_case_name}-subbuild")
|
||||
endif()
|
||||
elseif(CPM_SOURCE_CACHE AND NOT CPM_ARGS_NO_CACHE)
|
||||
string(TOLOWER ${CPM_ARGS_NAME} lower_case_name)
|
||||
set(origin_parameters ${CPM_ARGS_UNPARSED_ARGUMENTS})
|
||||
|
||||
36
test/integration/test_remove_source_dir.rb
Normal file
36
test/integration/test_remove_source_dir.rb
Normal file
@@ -0,0 +1,36 @@
|
||||
require_relative './lib'
|
||||
|
||||
class RemoveSourceDir < IntegrationTest
|
||||
def test_remove_source_dir
|
||||
prj = make_project 'using-adder'
|
||||
|
||||
prj.create_lists_from_default_template package: <<~PACK
|
||||
CPMAddPackage(
|
||||
NAME testpack-adder
|
||||
GITHUB_REPOSITORY cpm-cmake/testpack-adder
|
||||
VERSION 1.0.0
|
||||
OPTIONS "ADDER_BUILD_TESTS OFF"
|
||||
SOURCE_DIR testpack-adder
|
||||
)
|
||||
PACK
|
||||
|
||||
# configure and build
|
||||
assert_success prj.configure
|
||||
assert_success prj.build
|
||||
|
||||
# source_dir is populated
|
||||
assert_true File.exist?(File.join(prj.bin_dir, 'testpack-adder'))
|
||||
|
||||
# source_dir is deleted by user
|
||||
FileUtils.remove_dir(File.join(prj.bin_dir, 'testpack-adder'), true)
|
||||
assert_false File.exist?(File.join(prj.bin_dir, 'testpack-adder'))
|
||||
|
||||
# configure and build with missing source_dir to fetch new content
|
||||
assert_success prj.configure
|
||||
assert_success prj.build
|
||||
|
||||
# source_dir is populated
|
||||
assert_true File.exist?(File.join(prj.bin_dir, 'testpack-adder'))
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user