summaryrefslogtreecommitdiffstats
path: root/Tests
diff options
context:
space:
mode:
authorSebastian Holtermann <sebholt@xwmw.org>2019-02-13 20:08:49 (GMT)
committerSebastian Holtermann <sebholt@xwmw.org>2019-02-13 22:01:46 (GMT)
commita40864ae53ad22c369596699cc1bb791f65dc360 (patch)
tree010511ce8a13cde31ba0354cc1778eba98060b63 /Tests
parent724359489e03c1c890bea4bc6ba71ca353b048b9 (diff)
downloadCMake-a40864ae53ad22c369596699cc1bb791f65dc360.zip
CMake-a40864ae53ad22c369596699cc1bb791f65dc360.tar.gz
CMake-a40864ae53ad22c369596699cc1bb791f65dc360.tar.bz2
Autogen: Refactor RerunRccDepends test with fixed timestamp comparison
This refactors and simplifies the QtAutogen.RerunRccDepends test. Repetitive task are packed into macros. By using version strings to store file timestamps, timestamp comparison becomes more reliable. Test status and error messages are improved.
Diffstat (limited to 'Tests')
-rw-r--r--Tests/QtAutogen/RerunRccDepends/CMakeLists.txt175
1 files changed, 95 insertions, 80 deletions
diff --git a/Tests/QtAutogen/RerunRccDepends/CMakeLists.txt b/Tests/QtAutogen/RerunRccDepends/CMakeLists.txt
index 80c5cf0..1301550 100644
--- a/Tests/QtAutogen/RerunRccDepends/CMakeLists.txt
+++ b/Tests/QtAutogen/RerunRccDepends/CMakeLists.txt
@@ -3,19 +3,63 @@ project(RerunRccDepends)
include("../AutogenCoreTest.cmake")
# Tests rcc rebuilding when a resource file changes
+# When a .qrc or a file listed in a .qrc file changes,
+# the target must be rebuilt
# Dummy executable to generate a clean target
add_executable(dummy dummy.cpp)
-# When a .qrc or a file listed in a .qrc file changes,
-# the target must be rebuilt
-set(timeformat "%Y%j%H%M%S")
+# Utility variables
+set(timeformat "%Y.%j.%H.%M%S")
set(rccDepSD "${CMAKE_CURRENT_SOURCE_DIR}/RccDepends")
set(rccDepBD "${CMAKE_CURRENT_BINARY_DIR}/RccDepends")
-# Initial build
+# Utility macros
+macro(sleep)
+ message(STATUS "Sleeping for a few seconds.")
+ execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1)
+endmacro()
+
+macro(acquire_timestamps When)
+ file(TIMESTAMP "${rccDepBinPlain}" rdPlain${When} "${timeformat}")
+ file(TIMESTAMP "${rccDepBinGenerated}" rdGenerated${When} "${timeformat}")
+endmacro()
+
+macro(rebuild buildName)
+ message(STATUS "Starting build ${buildName} of rccDepends.")
+ execute_process(
+ COMMAND "${CMAKE_COMMAND}" --build .
+ WORKING_DIRECTORY "${rccDepBD}"
+ RESULT_VARIABLE result)
+ if (result)
+ message(FATAL_ERROR "Build ${buildName} of rccDepends failed.")
+ else()
+ message(STATUS "Build ${buildName} of rccDepends finished.")
+ endif()
+endmacro()
+
+macro(require_change type)
+ if (rd${type}After VERSION_GREATER rd${type}Before)
+ message(STATUS "As expected the ${type} .qrc file ${rccDepBin${type}} changed.")
+ else()
+ message(SEND_ERROR "Unexpectedly the ${type} .qrc file ${rccDepBin${type}} did not change!\nTimestamp pre: ${rd${type}Before}\nTimestamp aft: ${rd${type}After}\n")
+ endif()
+endmacro()
+
+macro(require_change_not type)
+ if (rd${type}After VERSION_GREATER rd${type}Before)
+ message(SEND_ERROR "Unexpectedly the ${type} .qrc file ${rccDepBin${type}} changed!\nTimestamp pre: ${rd${type}Before}\nTimestamp aft: ${rd${type}After}\n")
+ else()
+ message(STATUS "As expected the ${type} .qrc file ${rccDepBin${type}} did not change.")
+ endif()
+endmacro()
+
+
+# Initial configuration
configure_file(${rccDepSD}/resPlainA.qrc.in ${rccDepBD}/resPlain.qrc COPYONLY)
configure_file(${rccDepSD}/resGenA.qrc.in ${rccDepBD}/resGen.qrc.in COPYONLY)
+
+# Initial build
try_compile(RCC_DEPENDS
"${rccDepBD}"
"${rccDepSD}"
@@ -26,113 +70,84 @@ try_compile(RCC_DEPENDS
OUTPUT_VARIABLE output
)
if (NOT RCC_DEPENDS)
- message(SEND_ERROR "Initial build of rccDepends failed. Output: ${output}")
+ message(FATAL_ERROR "Initial build of rccDepends failed. Output: ${output}")
endif()
# Get name of the output binaries
file(STRINGS "${rccDepBD}/targetPlain.txt" targetListPlain ENCODING UTF-8)
file(STRINGS "${rccDepBD}/targetGen.txt" targetListGen ENCODING UTF-8)
list(GET targetListPlain 0 rccDepBinPlain)
-list(GET targetListGen 0 rccDepBinGen)
-message("Target that uses a plain .qrc file is:\n ${rccDepBinPlain}")
-message("Target that uses a GENERATED .qrc file is:\n ${rccDepBinGen}")
+list(GET targetListGen 0 rccDepBinGenerated)
+message(STATUS "Target that uses a plain .qrc file is:\n ${rccDepBinPlain}")
+message(STATUS "Target that uses a GENERATED .qrc file is:\n ${rccDepBinGenerated}")
+
+# To avoid a race condition where the binary has the same timestamp
+# as a source file and therefore gets rebuild
+# - sleep to ensure a timestamp change
+# - touch binary to ensure it has a new timestamp
+acquire_timestamps(Before)
+sleep()
+message(STATUS "Touching binary files to ensure new timestamps")
+file(TOUCH_NOCREATE "${rccDepBinPlain}" "${rccDepBinGenerated}")
+acquire_timestamps(After)
+require_change(Plain)
+require_change(Generated)
-message("Changing a resource files listed in the .qrc file")
-# - Acquire binary timestamps before the build
-file(TIMESTAMP "${rccDepBinPlain}" rdPlainBefore "${timeformat}")
-file(TIMESTAMP "${rccDepBinGen}" rdGenBefore "${timeformat}")
# - Ensure that the timestamp will change
# - Change a resource files listed in the .qrc file
# - Rebuild
-execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1)
+acquire_timestamps(Before)
+sleep()
+message(STATUS "Changing a resource file listed in the .qrc file")
file(TOUCH "${rccDepBD}/resPlain/input.txt" "${rccDepBD}/resGen/input.txt")
-execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${rccDepBD}" RESULT_VARIABLE result)
-if (result)
- message(SEND_ERROR "Second build of rccDepends failed.")
-endif()
-# - Acquire binary timestamps after the build
-file(TIMESTAMP "${rccDepBinPlain}" rdPlainAfter "${timeformat}")
-file(TIMESTAMP "${rccDepBinGen}" rdGenAfter "${timeformat}")
+sleep()
+rebuild(2)
+acquire_timestamps(After)
# - Test if timestamps changed
-if (NOT rdPlainAfter GREATER rdPlainBefore)
- message(SEND_ERROR "Plain .qrc binary ${rccDepBinPlain}) should have changed!")
-endif()
-if (NOT rdGenAfter GREATER rdGenBefore)
- message(SEND_ERROR "GENERATED .qrc binary ${rccDepBinGen} should have changed!")
-endif()
+require_change(Plain)
+require_change(Generated)
-message("Changing the .qrc file")
-# - Acquire binary timestamps before the build
-file(TIMESTAMP "${rccDepBinPlain}" rdPlainBefore "${timeformat}")
-file(TIMESTAMP "${rccDepBinGen}" rdGenBefore "${timeformat}")
# - Ensure that the timestamp will change
# - Change the .qrc file
# - Rebuild
-execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1)
+acquire_timestamps(Before)
+sleep()
+message(STATUS "Changing the .qrc file")
configure_file(${rccDepSD}/resPlainB.qrc.in ${rccDepBD}/resPlain.qrc COPYONLY)
configure_file(${rccDepSD}/resGenB.qrc.in ${rccDepBD}/resGen.qrc.in COPYONLY)
-execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${rccDepBD}" RESULT_VARIABLE result)
-if (result)
- message(SEND_ERROR "Third build of rccDepends failed.")
-endif()
-# - Acquire binary timestamps after the build
-file(TIMESTAMP "${rccDepBinPlain}" rdPlainAfter "${timeformat}")
-file(TIMESTAMP "${rccDepBinGen}" rdGenAfter "${timeformat}")
+sleep()
+rebuild(3)
+acquire_timestamps(After)
# - Test if timestamps changed
-if (NOT rdPlainAfter GREATER rdPlainBefore)
- message(SEND_ERROR "Plain .qrc binary ${rccDepBinPlain}) should have changed!")
-endif()
-if (NOT rdGenAfter GREATER rdGenBefore)
- message(SEND_ERROR "GENERATED .qrc binary ${rccDepBinGen} should have changed!")
-endif()
+require_change(Plain)
+require_change(Generated)
-message("Changing a newly added resource files listed in the .qrc file")
-# - Acquire binary timestamps before the build
-file(TIMESTAMP "${rccDepBinPlain}" rdPlainBefore "${timeformat}")
-file(TIMESTAMP "${rccDepBinGen}" rdGenBefore "${timeformat}")
# - Ensure that the timestamp will change
# - Change a newly added resource files listed in the .qrc file
# - Rebuild
-execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1)
+acquire_timestamps(Before)
+sleep()
+message(STATUS "Changing a newly added resource file listed in the .qrc file")
file(TOUCH "${rccDepBD}/resPlain/inputAdded.txt" "${rccDepBD}/resGen/inputAdded.txt")
-execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${rccDepBD}" RESULT_VARIABLE result)
-if (result)
- message(SEND_ERROR "Fourth build of rccDepends failed.")
-endif()
-# - Acquire binary timestamps after the build
-file(TIMESTAMP "${rccDepBinPlain}" rdPlainAfter "${timeformat}")
-file(TIMESTAMP "${rccDepBinGen}" rdGenAfter "${timeformat}")
+sleep()
+rebuild(4)
+acquire_timestamps(After)
# - Test if timestamps changed
-if (NOT rdPlainAfter GREATER rdPlainBefore)
- message(SEND_ERROR "Plain .qrc binary ${rccDepBinPlain}) should have changed!")
-endif()
-if (NOT rdGenAfter GREATER rdGenBefore)
- message(SEND_ERROR "GENERATED .qrc binary ${rccDepBinGen} should have changed!")
-endif()
+require_change(Plain)
+require_change(Generated)
-message("Changing nothing in the .qrc file")
-# - Acquire binary timestamps before the build
-file(TIMESTAMP "${rccDepBinPlain}" rdPlainBefore "${timeformat}")
-file(TIMESTAMP "${rccDepBinGen}" rdGenBefore "${timeformat}")
# - Ensure that the timestamp will change
# - Change nothing
# - Rebuild
-execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1)
-execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${rccDepBD}" RESULT_VARIABLE result)
-if (result)
- message(SEND_ERROR "Fifth build of rccDepends failed.")
-endif()
-# - Acquire binary timestamps after the build
-file(TIMESTAMP "${rccDepBinPlain}" rdPlainAfter "${timeformat}")
-file(TIMESTAMP "${rccDepBinGen}" rdGenAfter "${timeformat}")
+acquire_timestamps(Before)
+sleep()
+message(STATUS "Changing nothing in the .qrc file")
+rebuild(5)
+acquire_timestamps(After)
# - Test if timestamps changed
-if (rdPlainAfter GREATER rdPlainBefore)
- message(SEND_ERROR "Plain .qrc binary ${rccDepBinPlain}) should NOT have changed!")
-endif()
-if (rdGenAfter GREATER rdGenBefore)
- message(SEND_ERROR "GENERATED .qrc binary ${rccDepBinGen} should NOT have changed!")
-endif()
+require_change_not(Plain)
+require_change_not(Generated)