Browse Source

Autogen: Tests: Refactor the QtAutogenRebuild rccDepends test

Refactors the QtAutogenRebuild rccDepends test script
to be more readable.
Sebastian Holtermann 8 years ago
parent
commit
3c77515e13

+ 100 - 60
Tests/QtAutogenRerun/rccDepends.cmake

@@ -1,14 +1,15 @@
-# When a file listed in a .qrc file changes the target must be rebuilt
+# When a .qrc or a file listed in a .qrc file changes,
+# the target must be rebuilt
 set(timeformat "%Y%j%H%M%S")
-set(rccDependsSrcDir "${CMAKE_CURRENT_SOURCE_DIR}/rccDepends")
-set(rccDependsBinDir "${CMAKE_CURRENT_BINARY_DIR}/rccDepends")
+set(rccDepSD "${CMAKE_CURRENT_SOURCE_DIR}/rccDepends")
+set(rccDepBD "${CMAKE_CURRENT_BINARY_DIR}/rccDepends")
 
 # Initial build
-configure_file(${rccDependsSrcDir}/res1a.qrc.in ${rccDependsBinDir}/res1.qrc COPYONLY)
-configure_file(${rccDependsSrcDir}/res2a.qrc.in ${rccDependsBinDir}/res2.qrc.in COPYONLY)
+configure_file(${rccDepSD}/resPlainA.qrc.in ${rccDepBD}/resPlain.qrc COPYONLY)
+configure_file(${rccDepSD}/resGenA.qrc.in ${rccDepBD}/resGen.qrc.in COPYONLY)
 try_compile(RCC_DEPENDS
-  "${rccDependsBinDir}"
-  "${rccDependsSrcDir}"
+  "${rccDepBD}"
+  "${rccDepSD}"
   rccDepends
   CMAKE_FLAGS "-DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}"
               "-DQT_TEST_VERSION=${QT_TEST_VERSION}"
@@ -18,74 +19,113 @@ try_compile(RCC_DEPENDS
 if (NOT RCC_DEPENDS)
   message(SEND_ERROR "Initial build of rccDepends failed. Output: ${output}")
 endif()
-# Get name of the output binary
-file(STRINGS "${rccDependsBinDir}/target.txt" targetList ENCODING UTF-8)
-list(GET targetList 0 rccDependsBin)
 
-file(TIMESTAMP "${rccDependsBin}" timeBegin "${timeformat}")
-# Sleep, touch regular qrc input file, rebuild and compare timestamp
-execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) # Ensure that the timestamp will change.
-execute_process(COMMAND "${CMAKE_COMMAND}" -E touch "${rccDependsBinDir}/res1/input.txt")
-execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${rccDependsBinDir}" RESULT_VARIABLE result)
+# 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}")
+
+
+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)
+execute_process(COMMAND "${CMAKE_COMMAND}" -E touch "${rccDepBD}/resPlain/input.txt")
+execute_process(COMMAND "${CMAKE_COMMAND}" -E touch "${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()
-file(TIMESTAMP "${rccDependsBin}" timeStep1 "${timeformat}")
-if (NOT timeStep1 GREATER timeBegin)
-  message(SEND_ERROR "File (${rccDependsBin}) should have changed in the first step!")
+# - Acquire binary timestamps after the build
+file(TIMESTAMP "${rccDepBinPlain}" rdPlainAfter "${timeformat}")
+file(TIMESTAMP "${rccDepBinGen}" rdGenAfter "${timeformat}")
+# - Test if timestamps changed
+if (NOT rdPlainAfter GREATER rdPlainBefore)
+  message(SEND_ERROR "Plain .qrc binary ${rccDepBinPlain}) should have changed!")
 endif()
-# Sleep, update regular qrc file, rebuild and compare timestamp
-execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) # Ensure that the timestamp will change.
-configure_file(${rccDependsSrcDir}/res1b.qrc.in ${rccDependsBinDir}/res1.qrc COPYONLY)
-execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${rccDependsBinDir}" RESULT_VARIABLE result)
+if (NOT rdGenAfter GREATER rdGenBefore)
+  message(SEND_ERROR "GENERATED .qrc binary ${rccDepBinGen} should have changed!")
+endif()
+
+
+message("Changing a 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)
+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()
-file(TIMESTAMP "${rccDependsBin}" timeStep2 "${timeformat}")
-if (NOT timeStep2 GREATER timeStep1)
-  message(SEND_ERROR "File (${rccDependsBin}) should have changed in the second step!")
+# - Acquire binary timestamps after the build
+file(TIMESTAMP "${rccDepBinPlain}" rdPlainAfter "${timeformat}")
+file(TIMESTAMP "${rccDepBinGen}" rdGenAfter "${timeformat}")
+# - 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()
-# Sleep, touch regular qrc newly added input file, rebuild and compare timestamp
-execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) # Ensure that the timestamp will change.
-execute_process(COMMAND "${CMAKE_COMMAND}" -E touch "${rccDependsBinDir}/res1/inputAdded.txt")
-execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${rccDependsBinDir}" RESULT_VARIABLE result)
+
+
+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)
+execute_process(COMMAND "${CMAKE_COMMAND}" -E touch "${rccDepBD}/resPlain/inputAdded.txt")
+execute_process(COMMAND "${CMAKE_COMMAND}" -E touch "${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()
-file(TIMESTAMP "${rccDependsBin}" timeStep3 "${timeformat}")
-if (NOT timeStep3 GREATER timeStep2)
-  message(SEND_ERROR "File (${rccDependsBin}) should have changed in the third step!")
+# - Acquire binary timestamps after the build
+file(TIMESTAMP "${rccDepBinPlain}" rdPlainAfter "${timeformat}")
+file(TIMESTAMP "${rccDepBinGen}" rdGenAfter "${timeformat}")
+# - Test if timestamps changed
+if (NOT rdPlainAfter GREATER rdPlainBefore)
+  message(SEND_ERROR "Plain .qrc binary ${rccDepBinPlain}) should have changed!")
 endif()
-# Sleep, touch generated qrc input file, rebuild and compare timestamp
-execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) # Ensure that the timestamp will change.
-execute_process(COMMAND "${CMAKE_COMMAND}" -E touch "${rccDependsBinDir}/res2/input.txt")
-execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${rccDependsBinDir}" RESULT_VARIABLE result)
-if (result)
-  message(SEND_ERROR "Fifth build of rccDepends failed.")
+if (NOT rdGenAfter GREATER rdGenBefore)
+  message(SEND_ERROR "GENERATED .qrc binary ${rccDepBinGen} should have changed!")
 endif()
-file(TIMESTAMP "${rccDependsBin}" timeStep4 "${timeformat}")
-if (NOT timeStep4 GREATER timeStep3)
-  message(SEND_ERROR "File (${rccDependsBin}) should have changed in the fourth step!")
-endif()
-# Sleep, update generated qrc file, rebuild and compare timestamp
-execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) # Ensure that the timestamp will change.
-configure_file(${rccDependsSrcDir}/res2b.qrc.in ${rccDependsBinDir}/res2.qrc.in COPYONLY)
-execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${rccDependsBinDir}" RESULT_VARIABLE result)
+
+
+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 "Sixth build of rccDepends failed.")
-endif()
-file(TIMESTAMP "${rccDependsBin}" timeStep5 "${timeformat}")
-if (NOT timeStep5 GREATER timeStep4)
-  message(SEND_ERROR "File (${rccDependsBin}) should have changed in the fitfh step!")
+  message(SEND_ERROR "Fifth build of rccDepends failed.")
 endif()
-# Sleep, touch generated qrc newly added input file, rebuild and compare timestamp
-execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) # Ensure that the timestamp will change.
-execute_process(COMMAND "${CMAKE_COMMAND}" -E touch "${rccDependsBinDir}/res2/inputAdded.txt")
-execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${rccDependsBinDir}" RESULT_VARIABLE result)
-if (result)
-  message(SEND_ERROR "Seventh build of rccDepends failed.")
+# - Acquire binary timestamps after the build
+file(TIMESTAMP "${rccDepBinPlain}" rdPlainAfter "${timeformat}")
+file(TIMESTAMP "${rccDepBinGen}" rdGenAfter "${timeformat}")
+# - Test if timestamps changed
+if (rdPlainAfter GREATER rdPlainBefore)
+  message(SEND_ERROR "Plain .qrc binary ${rccDepBinPlain}) should NOT have changed!")
 endif()
-file(TIMESTAMP "${rccDependsBin}" timeStep6 "${timeformat}")
-if (NOT timeStep6 GREATER timeStep5)
-  message(SEND_ERROR "File (${rccDependsBin}) should have changed in the sixth step!")
+if (rdGenAfter GREATER rdGenBefore)
+  message(SEND_ERROR "GENERATED .qrc binary ${rccDepBinGen} should NOT have changed!")
 endif()

+ 25 - 19
Tests/QtAutogenRerun/rccDepends/CMakeLists.txt

@@ -1,8 +1,6 @@
 cmake_minimum_required(VERSION 3.9)
 project(rccDepends CXX)
 
-set(CMAKE_AUTORCC ON)
-
 if (QT_TEST_VERSION STREQUAL 4)
   find_package(Qt4 REQUIRED)
   set(QT_CORE_TARGET Qt4::QtCore)
@@ -15,21 +13,29 @@ else()
   set(QT_CORE_TARGET Qt5::Core)
 endif()
 
-configure_file(res/input1.txt.in res1/input.txt COPYONLY)
-configure_file(res/input1.txt.in res1/inputAdded.txt COPYONLY)
-configure_file(res/input2.txt.in res2/input.txt COPYONLY)
-configure_file(res/input2.txt.in res2/inputAdded.txt COPYONLY)
-# Dependency generated qrc file
-add_custom_command(OUTPUT res2.qrc
-                   DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/res2.qrc.in
-                   COMMAND ${CMAKE_COMMAND} -E sleep 2
-                   COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/res2.qrc.in ${CMAKE_CURRENT_BINARY_DIR}/res2.qrc
-                   )
+# Enable AUTORCC for all targets
+set(CMAKE_AUTORCC ON)
+
+# Initial resource files setup
+configure_file(resPlain/input.txt.in resPlain/input.txt COPYONLY)
+configure_file(resPlain/input.txt.in resPlain/inputAdded.txt COPYONLY)
+configure_file(resGen/input.txt.in resGen/input.txt COPYONLY)
+configure_file(resGen/input.txt.in resGen/inputAdded.txt COPYONLY)
+
+# Generated qrc file with dependency
+add_custom_command(OUTPUT resGen.qrc
+  DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/resGen.qrc.in
+  COMMAND ${CMAKE_COMMAND} -E sleep 2
+  COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/resGen.qrc.in ${CMAKE_CURRENT_BINARY_DIR}/resGen.qrc)
+
+# Target that uses a plain .qrc file
+add_executable(rccDependsPlain main.cpp ${CMAKE_CURRENT_BINARY_DIR}/resPlain.qrc)
+target_link_libraries(rccDependsPlain ${QT_CORE_TARGET})
+add_custom_command(TARGET rccDependsPlain POST_BUILD COMMAND
+  ${CMAKE_COMMAND} -E echo "$<TARGET_FILE:rccDependsPlain>" > targetPlain.txt)
 
-add_executable(rccDepends
-  main.cpp
-  ${CMAKE_CURRENT_BINARY_DIR}/res1.qrc
-  ${CMAKE_CURRENT_BINARY_DIR}/res2.qrc )
-target_link_libraries(rccDepends ${QT_CORE_TARGET})
-add_custom_command(TARGET rccDepends POST_BUILD COMMAND
-  ${CMAKE_COMMAND} -E echo "$<TARGET_FILE:rccDepends>" > target.txt)
+# Target that uses a GENERATED .qrc file
+add_executable(rccDependsGen main.cpp ${CMAKE_CURRENT_BINARY_DIR}/resGen.qrc )
+target_link_libraries(rccDependsGen ${QT_CORE_TARGET})
+add_custom_command(TARGET rccDependsGen POST_BUILD COMMAND
+  ${CMAKE_COMMAND} -E echo "$<TARGET_FILE:rccDependsGen>" > targetGen.txt)

+ 0 - 1
Tests/QtAutogenRerun/rccDepends/res/input1.txt.in

@@ -1 +0,0 @@
-Res1 input.

+ 0 - 1
Tests/QtAutogenRerun/rccDepends/res/input2.txt.in

@@ -1 +0,0 @@
-Res2 input.

+ 0 - 5
Tests/QtAutogenRerun/rccDepends/res1a.qrc.in

@@ -1,5 +0,0 @@
-<RCC>
-    <qresource prefix="/Texts1">
-        <file>res1/input.txt</file>
-    </qresource>
-</RCC>

+ 0 - 6
Tests/QtAutogenRerun/rccDepends/res1b.qrc.in

@@ -1,6 +0,0 @@
-<RCC>
-    <qresource prefix="/Texts1">
-        <file>res1/input.txt</file>
-        <file alias="Added">res1/inputAdded.txt</file>
-    </qresource>
-</RCC>

+ 0 - 5
Tests/QtAutogenRerun/rccDepends/res2a.qrc.in

@@ -1,5 +0,0 @@
-<RCC>
-    <qresource prefix="/Texts2">
-        <file>res2/input.txt</file>
-    </qresource>
-</RCC>

+ 0 - 6
Tests/QtAutogenRerun/rccDepends/res2b.qrc.in

@@ -1,6 +0,0 @@
-<RCC>
-    <qresource prefix="/Texts2">
-        <file>res2/input.txt</file>
-        <file alias="Added">res2/inputAdded.txt</file>
-    </qresource>
-</RCC>

+ 1 - 0
Tests/QtAutogenRerun/rccDepends/resGen/input.txt.in

@@ -0,0 +1 @@
+Generated resource input.

+ 1 - 0
Tests/QtAutogenRerun/rccDepends/resGen/inputAdded.txt.in

@@ -0,0 +1 @@
+Generated resource input.

+ 5 - 0
Tests/QtAutogenRerun/rccDepends/resGenA.qrc.in

@@ -0,0 +1,5 @@
+<RCC>
+    <qresource prefix="/TextsGenerated">
+        <file>resGen/input.txt</file>
+    </qresource>
+</RCC>

+ 6 - 0
Tests/QtAutogenRerun/rccDepends/resGenB.qrc.in

@@ -0,0 +1,6 @@
+<RCC>
+    <qresource prefix="/TextsGenerated">
+        <file>resGen/input.txt</file>
+        <file alias="Added">resGen/inputAdded.txt</file>
+    </qresource>
+</RCC>

+ 1 - 0
Tests/QtAutogenRerun/rccDepends/resPlain/input.txt.in

@@ -0,0 +1 @@
+Plaint resource input.

+ 1 - 0
Tests/QtAutogenRerun/rccDepends/resPlain/inputAdded.txt.in

@@ -0,0 +1 @@
+Plaint resource input.

+ 5 - 0
Tests/QtAutogenRerun/rccDepends/resPlainA.qrc.in

@@ -0,0 +1,5 @@
+<RCC>
+    <qresource prefix="/TextsPlain">
+        <file>resPlain/input.txt</file>
+    </qresource>
+</RCC>

+ 6 - 0
Tests/QtAutogenRerun/rccDepends/resPlainB.qrc.in

@@ -0,0 +1,6 @@
+<RCC>
+    <qresource prefix="/TextsPlain">
+        <file>resPlain/input.txt</file>
+        <file alias="Added">resPlain/inputAdded.txt</file>
+    </qresource>
+</RCC>