diff options
author | Brad King <brad.king@kitware.com> | 2021-02-22 16:05:39 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2021-02-22 16:05:45 (GMT) |
commit | e9efa04d8da2b17f34a70d7b4be0d91a1c7574dc (patch) | |
tree | d97b8b6e4f1e63cc1345f4073c41654d0efa57b0 /Tests | |
parent | 33d93089ef25d39e335ccc63c9e27c91a39e7bb1 (diff) | |
parent | b0da6712439fe44d84a158dceb5f946cc30ef68a (diff) | |
download | CMake-e9efa04d8da2b17f34a70d7b4be0d91a1c7574dc.zip CMake-e9efa04d8da2b17f34a70d7b4be0d91a1c7574dc.tar.gz CMake-e9efa04d8da2b17f34a70d7b4be0d91a1c7574dc.tar.bz2 |
Merge topic 'fix-IS_NEWER_THAN-usage' into release-3.20
b0da671243 FetchContent: Don't update timestamps if files don't change
404cddb7bb ExternalProject: Fix misuse of IS_NEWER_THAN in timestamp checks
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !5825
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/RunCMake/FetchContent/RunCMakeTest.cmake | 30 | ||||
-rw-r--r-- | Tests/RunCMake/FetchContent/TimeStamps-stdout.txt | 2 | ||||
-rw-r--r-- | Tests/RunCMake/FetchContent/TimeStamps.cmake | 14 | ||||
-rw-r--r-- | Tests/RunCMake/FetchContent/TimeStampsRerun-check.cmake | 38 | ||||
-rw-r--r-- | Tests/RunCMake/FetchContent/TimeStampsRerun.cmake | 1 |
5 files changed, 85 insertions, 0 deletions
diff --git a/Tests/RunCMake/FetchContent/RunCMakeTest.cmake b/Tests/RunCMake/FetchContent/RunCMakeTest.cmake index 13013fa..d7fd009 100644 --- a/Tests/RunCMake/FetchContent/RunCMakeTest.cmake +++ b/Tests/RunCMake/FetchContent/RunCMakeTest.cmake @@ -27,6 +27,36 @@ run_cmake_with_options(ManualSourceDirectoryRelative -D "FETCHCONTENT_SOURCE_DIR_WITHPROJECT:STRING=WithProject" ) +function(run_FetchContent_TimeStamps) + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/TimeStamps) + file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") + file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") + + # First run should execute the commands + run_cmake(TimeStamps) + + # Ensure that the file checks we use in the TimeStampsRerun-check.cmake script + # will not be defeated by file systems with only one second resolution. + # The IS_NEWER_THAN check returns TRUE if the timestamps of the two files are + # the same, which has been observed where filesystems only have one second + # resolution. + set(cmpTimeStamp ${RunCMake_TEST_BINARY_DIR}/cmpTimeStamp.txt) + set(checkTimeStamp ${RunCMake_TEST_BINARY_DIR}/cmpTimeStampCheck.txt) + file(TOUCH ${cmpTimeStamp}) + file(TOUCH ${checkTimeStamp}) + if("${cmpTimeStamp}" IS_NEWER_THAN "${checkTimeStamp}") + execute_process( + COMMAND ${CMAKE_COMMAND} -E sleep 1.125 + COMMAND_ERROR_IS_FATAL LAST + ) + endif() + + # Run again with no changes, no commands should re-execute + set(RunCMake_TEST_NO_CLEAN 1) + run_cmake(TimeStampsRerun) +endfunction() +run_FetchContent_TimeStamps() + function(run_FetchContent_DirOverrides) set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/DirOverrides-build) file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") diff --git a/Tests/RunCMake/FetchContent/TimeStamps-stdout.txt b/Tests/RunCMake/FetchContent/TimeStamps-stdout.txt new file mode 100644 index 0000000..2ba1ff4 --- /dev/null +++ b/Tests/RunCMake/FetchContent/TimeStamps-stdout.txt @@ -0,0 +1,2 @@ +.* *download executed +.* *patch executed diff --git a/Tests/RunCMake/FetchContent/TimeStamps.cmake b/Tests/RunCMake/FetchContent/TimeStamps.cmake new file mode 100644 index 0000000..33874f9 --- /dev/null +++ b/Tests/RunCMake/FetchContent/TimeStamps.cmake @@ -0,0 +1,14 @@ +include(FetchContent) + +# Do nothing for an update because it would result in always re-running the +# patch step. We want to test that a patch step that only depends on the +# download step is not re-run unnecessarily. +FetchContent_Declare(customCommands + PREFIX ${CMAKE_CURRENT_BINARY_DIR} + DOWNLOAD_COMMAND "${CMAKE_COMMAND}" -E echo "download executed" + UPDATE_COMMAND "" + PATCH_COMMAND "${CMAKE_COMMAND}" -E echo "patch executed" +) + +set(FETCHCONTENT_QUIET FALSE) +FetchContent_MakeAvailable(customCommands) diff --git a/Tests/RunCMake/FetchContent/TimeStampsRerun-check.cmake b/Tests/RunCMake/FetchContent/TimeStampsRerun-check.cmake new file mode 100644 index 0000000..c12a5f4 --- /dev/null +++ b/Tests/RunCMake/FetchContent/TimeStampsRerun-check.cmake @@ -0,0 +1,38 @@ +set(cmpFile ${RunCMake_TEST_BINARY_DIR}/cmpTimeStamp.txt) +set(scriptDir ${RunCMake_TEST_BINARY_DIR}/tmp) +set(stampDir ${RunCMake_TEST_BINARY_DIR}/src/customcommands-stamp) + +set(errorMessages) +if(NOT EXISTS "${cmpFile}") + list(APPEND errorMessages " ${cmpFile} is missing") +else() + foreach(script IN ITEMS mkdirs download patch) + set(scriptFile "${scriptDir}/customcommands-${script}.cmake") + if(NOT EXISTS "${scriptFile}") + list(APPEND errorMessages " ${scriptFile} is missing") + elseif(NOT "${cmpFile}" IS_NEWER_THAN "${scriptFile}") + list(APPEND errorMessages " ${scriptFile} was unexectedly updated") + endif() + endforeach() + + # special case, not a script, has different extension + set(repoInfoFile "${scriptDir}/customcommands-download-repoinfo.txt") + if(NOT EXISTS "${repoInfoFile}") + list(APPEND errorMessages " ${repoInfoFile} is missing") + elseif(NOT "${cmpFile}" IS_NEWER_THAN "${repoInfoFile}") + list(APPEND errorMessages " ${repoInfoFile} was unexectedly updated") + endif() + + foreach(step IN ITEMS download patch) + set(stampFile "${stampDir}/customcommands-${step}") + if(NOT EXISTS "${stampFile}") + list(APPEND errorMessages " ${stampFile} is missing") + elseif(NOT "${cmpFile}" IS_NEWER_THAN "${stampFile}") + list(APPEND errorMessages " ${stampFile} was unexectedly updated") + endif() + endforeach() +endif() + +if(errorMessages) + list(JOIN errorMessages "\n" RunCMake_TEST_FAILED) +endif() diff --git a/Tests/RunCMake/FetchContent/TimeStampsRerun.cmake b/Tests/RunCMake/FetchContent/TimeStampsRerun.cmake new file mode 100644 index 0000000..e13667a --- /dev/null +++ b/Tests/RunCMake/FetchContent/TimeStampsRerun.cmake @@ -0,0 +1 @@ +include(${CMAKE_CURRENT_LIST_DIR}/TimeStamps.cmake) |