diff options
author | Craig Scott <craig.scott@crascit.com> | 2022-01-31 04:51:13 (GMT) |
---|---|---|
committer | Craig Scott <craig.scott@crascit.com> | 2022-02-01 11:31:29 (GMT) |
commit | d3477eba067c22f7b2986caa573754fd2b84c8ef (patch) | |
tree | 6814377ab0fad90e069dd997753878baca9d5208 /Tests/RunCMake | |
parent | 4b033ca0eb486fa23f58e4df2f2a7d3539ca0a3f (diff) | |
download | CMake-d3477eba067c22f7b2986caa573754fd2b84c8ef.zip CMake-d3477eba067c22f7b2986caa573754fd2b84c8ef.tar.gz CMake-d3477eba067c22f7b2986caa573754fd2b84c8ef.tar.bz2 |
ExternalProject: Rerun download on SOURCE_DIR change
Fixes: #21748
Diffstat (limited to 'Tests/RunCMake')
4 files changed, 45 insertions, 5 deletions
diff --git a/Tests/RunCMake/ExternalProject/MultiCommand.cmake b/Tests/RunCMake/ExternalProject/MultiCommand.cmake index 0849658..3e8bd94 100644 --- a/Tests/RunCMake/ExternalProject/MultiCommand.cmake +++ b/Tests/RunCMake/ExternalProject/MultiCommand.cmake @@ -1,5 +1,12 @@ include(ExternalProject) +# Force all steps to be re-run by removing timestamps from any previous run. +# This has to happen before we call ExternalProject_Add() because that command +# writes some files to the stamp directory for recording repository details. +set(STAMP_DIR ${CMAKE_BINARY_DIR}/multiCommand-prefix/src/multiCommand-stamp) +file(REMOVE_RECURSE "${STAMP_DIR}") +file(MAKE_DIRECTORY "${STAMP_DIR}") + # Verify COMMAND keyword is recognized after various *_COMMAND options ExternalProject_Add(multiCommand DOWNLOAD_COMMAND "${CMAKE_COMMAND}" -E echo "download 1" @@ -17,8 +24,3 @@ ExternalProject_Add(multiCommand INSTALL_COMMAND "${CMAKE_COMMAND}" -E echo "install 1" COMMAND "${CMAKE_COMMAND}" -E echo "install 2" ) - -# Force all steps to be re-run by removing timestamps from any previous run -ExternalProject_Get_Property(multiCommand STAMP_DIR) -file(REMOVE_RECURSE "${STAMP_DIR}") -file(MAKE_DIRECTORY "${STAMP_DIR}") diff --git a/Tests/RunCMake/ExternalProject/RunCMakeTest.cmake b/Tests/RunCMake/ExternalProject/RunCMakeTest.cmake index 48f8b23..fde384f 100644 --- a/Tests/RunCMake/ExternalProject/RunCMakeTest.cmake +++ b/Tests/RunCMake/ExternalProject/RunCMakeTest.cmake @@ -61,6 +61,23 @@ if(NOT XCODE_VERSION OR XCODE_VERSION VERSION_LESS 12) endif() run_steps_CMP0114(NEW) +function(__ep_test_source_dir_change) + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/SourceDirChange-build) + set(RunCMake_TEST_NO_CLEAN 1) + file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") + file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") + run_cmake(SourceDirChange) + run_cmake_command(SourceDirChange-build1 ${CMAKE_COMMAND} --build .) + # Because some file systems have timestamps with only one second resolution, + # we have to ensure we don't re-run the configure stage too quickly after the + # first build. Otherwise, the modified RepositoryInfo.txt files the next + # configure writes might still have the same timestamp as the previous one. + execute_process(COMMAND ${CMAKE_COMMAND} -E sleep 1.125) + run_cmake_command(SourceDirChange-change ${CMAKE_COMMAND} -DSOURCE_DIR_CHANGE=YES .) + run_cmake_command(SourceDirChange-build2 ${CMAKE_COMMAND} --build .) +endfunction() +__ep_test_source_dir_change() + # Run both cmake and build steps. We always do a clean before the # build to ensure that the download step re-runs each time. function(__ep_test_with_build testName) diff --git a/Tests/RunCMake/ExternalProject/SourceDirChange-build2-stdout.txt b/Tests/RunCMake/ExternalProject/SourceDirChange-build2-stdout.txt new file mode 100644 index 0000000..22dac9d --- /dev/null +++ b/Tests/RunCMake/ExternalProject/SourceDirChange-build2-stdout.txt @@ -0,0 +1 @@ +Download command executed diff --git a/Tests/RunCMake/ExternalProject/SourceDirChange.cmake b/Tests/RunCMake/ExternalProject/SourceDirChange.cmake new file mode 100644 index 0000000..62213cd --- /dev/null +++ b/Tests/RunCMake/ExternalProject/SourceDirChange.cmake @@ -0,0 +1,20 @@ +include(ExternalProject) + +file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/first") +file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/second") + +if("${SOURCE_DIR_CHANGE}" STREQUAL "") + set(source_dir first) +else() + set(source_dir second) +endif() + +ExternalProject_Add(source_dir_change + SOURCE_DIR "${CMAKE_BINARY_DIR}/${source_dir}" + DOWNLOAD_COMMAND "${CMAKE_COMMAND}" -E echo "Download command executed" + UPDATE_COMMAND "" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + TEST_COMMAND "" + INSTALL_COMMAND "" +) |