diff options
Diffstat (limited to 'Tests/QtAutogen/RerunMocPlugin/CMakeLists.txt')
-rw-r--r-- | Tests/QtAutogen/RerunMocPlugin/CMakeLists.txt | 151 |
1 files changed, 93 insertions, 58 deletions
diff --git a/Tests/QtAutogen/RerunMocPlugin/CMakeLists.txt b/Tests/QtAutogen/RerunMocPlugin/CMakeLists.txt index b83e994..6ab9538 100644 --- a/Tests/QtAutogen/RerunMocPlugin/CMakeLists.txt +++ b/Tests/QtAutogen/RerunMocPlugin/CMakeLists.txt @@ -9,10 +9,53 @@ include("../AutogenCoreTest.cmake") add_executable(dummy dummy.cpp) # Utility variables -set(timeformat "%Y%j%H%M%S") +set(timeformat "%Y.%j.%H.%M%S") set(mocPlugSrcDir "${CMAKE_CURRENT_SOURCE_DIR}/MocPlugin") set(mocPlugBinDir "${CMAKE_CURRENT_BINARY_DIR}/MocPlugin") +# Utility macros +macro(sleep) + message(STATUS "Sleeping for a few seconds.") + execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) +endmacro() + +macro(rebuild buildName) + message(STATUS "Starting build ${buildName}.") + execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${mocPlugBinDir}" RESULT_VARIABLE result) + if (result) + message(FATAL_ERROR "Build ${buildName} failed.") + else() + message(STATUS "Build ${buildName} finished.") + endif() +endmacro() + +macro(require_change PLG) + if (pl${PLG}After VERSION_GREATER pl${PLG}Before) + message(STATUS "As expected the file ${pl${PLG}File} changed.") + else() + message(SEND_ERROR + "Unexpectedly the file ${pl${PLG}File} did not change!\nTimestamp pre: ${pl${PLG}Before}\nTimestamp aft: ${pl${PLG}After}\n") + endif() +endmacro() + +macro(require_change_not PLG) + if (pl${PLG}After VERSION_GREATER pl${PLG}Before) + message(SEND_ERROR + "Unexpectedly the file ${pl${PLG}File} changed!\nTimestamp pre: ${pl${PLG}Before}\nTimestamp aft: ${pl${PLG}After}\n") + else() + message(STATUS "As expected the file ${pl${PLG}File} did not change.") + endif() +endmacro() + +macro(acquire_timestamps When) + file(TIMESTAMP "${plAFile}" plA${When} "${timeformat}") + file(TIMESTAMP "${plBFile}" plB${When} "${timeformat}") + file(TIMESTAMP "${plCFile}" plC${When} "${timeformat}") + file(TIMESTAMP "${plDFile}" plD${When} "${timeformat}") + file(TIMESTAMP "${plEFile}" plE${When} "${timeformat}") +endmacro() + + # Initial build try_compile(MOC_PLUGIN "${mocPlugBinDir}" @@ -24,83 +67,75 @@ try_compile(MOC_PLUGIN OUTPUT_VARIABLE output ) if (NOT MOC_PLUGIN) - message(SEND_ERROR "Initial build of mocPlugin failed. Output: ${output}") + message(FATAL_ERROR "Initial build of mocPlugin failed. Output: ${output}") endif() +# Get names of the output binaries find_library(plAFile "PlugA" PATHS "${mocPlugBinDir}/Debug" "${mocPlugBinDir}" NO_DEFAULT_PATH) find_library(plBFile "PlugB" PATHS "${mocPlugBinDir}/Debug" "${mocPlugBinDir}" NO_DEFAULT_PATH) find_library(plCFile "PlugC" PATHS "${mocPlugBinDir}/Debug" "${mocPlugBinDir}" NO_DEFAULT_PATH) find_library(plDFile "PlugD" PATHS "${mocPlugBinDir}/Debug" "${mocPlugBinDir}" NO_DEFAULT_PATH) find_library(plEFile "PlugE" PATHS "${mocPlugBinDir}/Debug" "${mocPlugBinDir}" NO_DEFAULT_PATH) +# To avoid a race condition where the library has the same timestamp +# as a source file and therefore gets rebuild +# - sleep to ensure a timestamp change +# - touch library to ensure it has a new timestamp +acquire_timestamps(Before) +sleep() +message(STATUS "Touching library files to ensure new timestamps") +file(TOUCH_NOCREATE "${plAFile}" "${plBFile}" "${plCFile}" "${plDFile}" "${plEFile}") +acquire_timestamps(After) +require_change(A) +require_change(B) +require_change(C) +require_change(D) +require_change(E) + + # - Ensure that the timestamp will change. # - Change the json files referenced by Q_PLUGIN_METADATA # - Rebuild -file(TIMESTAMP "${plAFile}" plABefore "${timeformat}") -file(TIMESTAMP "${plBFile}" plBBefore "${timeformat}") -file(TIMESTAMP "${plCFile}" plCBefore "${timeformat}") -file(TIMESTAMP "${plDFile}" plDBefore "${timeformat}") -file(TIMESTAMP "${plEFile}" plEBefore "${timeformat}") - -execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) +acquire_timestamps(Before) +sleep() +message(STATUS "Changing json files") configure_file("${mocPlugSrcDir}/jsonIn/StyleD.json" "${mocPlugBinDir}/jsonFiles/StyleC.json") configure_file("${mocPlugSrcDir}/jsonIn/StyleE.json" "${mocPlugBinDir}/jsonFiles/sub/StyleD.json") configure_file("${mocPlugSrcDir}/jsonIn/StyleC.json" "${mocPlugBinDir}/jsonFiles/StyleE.json") -execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${mocPlugBinDir}") - -file(TIMESTAMP "${plAFile}" plAAfter "${timeformat}") -file(TIMESTAMP "${plBFile}" plBAfter "${timeformat}") -file(TIMESTAMP "${plCFile}" plCAfter "${timeformat}") -file(TIMESTAMP "${plDFile}" plDAfter "${timeformat}") -file(TIMESTAMP "${plEFile}" plEAfter "${timeformat}") - -if (plAAfter GREATER plABefore) - message(SEND_ERROR "file (${plAFile}) should not have changed!") -endif() -if (plBAfter GREATER plBBefore) - message(SEND_ERROR "file (${plBFile}) should not have changed!") -endif() -if (NOT plCAfter GREATER plCBefore) - message(SEND_ERROR "file (${plCFile}) should have changed!") -endif() -if (NOT plDAfter GREATER plDBefore) - message(SEND_ERROR "file (${plDFile}) should have changed!") -endif() -if (NOT plEAfter GREATER plEBefore) - # There's a bug in Ninja on Windows - # https://gitlab.kitware.com/cmake/cmake/issues/16776 - if(NOT ("${CMAKE_GENERATOR}" MATCHES "Ninja")) - message(SEND_ERROR "file (${plEFile}) should have changed!") - endif() +sleep() +rebuild(2) +acquire_timestamps(After) +# Test changes +require_change_not(A) +require_change_not(B) +require_change(C) +require_change(D) +# There's a bug in Ninja on Windows: +# https://gitlab.kitware.com/cmake/cmake/issues/16776 +if(NOT ("${CMAKE_GENERATOR}" MATCHES "Ninja")) + require_change(E) endif() + # - Ensure that the timestamp will change. # - Change the json files referenced by A_CUSTOM_MACRO # - Rebuild -file(TIMESTAMP "${plCFile}" plCBefore "${timeformat}") -file(TIMESTAMP "${plDFile}" plDBefore "${timeformat}") -file(TIMESTAMP "${plEFile}" plEBefore "${timeformat}") - -execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1) +acquire_timestamps(Before) +sleep() +message(STATUS "Changing json files") configure_file("${mocPlugSrcDir}/jsonIn/StyleE.json" "${mocPlugBinDir}/jsonFiles/StyleC_Custom.json") configure_file("${mocPlugSrcDir}/jsonIn/StyleC.json" "${mocPlugBinDir}/jsonFiles/sub/StyleD_Custom.json") configure_file("${mocPlugSrcDir}/jsonIn/StyleD.json" "${mocPlugBinDir}/jsonFiles/StyleE_Custom.json") -execute_process(COMMAND "${CMAKE_COMMAND}" --build . WORKING_DIRECTORY "${mocPlugBinDir}") - -file(TIMESTAMP "${plCFile}" plCAfter "${timeformat}") -file(TIMESTAMP "${plDFile}" plDAfter "${timeformat}") -file(TIMESTAMP "${plEFile}" plEAfter "${timeformat}") - -if (NOT plCAfter GREATER plCBefore) - message(SEND_ERROR "file (${plCFile}) should have changed!") -endif() -if (NOT plDAfter GREATER plDBefore) - message(SEND_ERROR "file (${plDFile}) should have changed!") -endif() -if (NOT plEAfter GREATER plEBefore) - # There's a bug in Ninja on Windows - # https://gitlab.kitware.com/cmake/cmake/issues/16776 - if(NOT ("${CMAKE_GENERATOR}" MATCHES "Ninja")) - message(SEND_ERROR "file (${plEFile}) should have changed!") - endif() +sleep() +rebuild(3) +acquire_timestamps(After) +# Test changes +require_change_not(A) +require_change_not(B) +require_change(C) +require_change(D) +# There's a bug in Ninja on Windows +# https://gitlab.kitware.com/cmake/cmake/issues/16776 +if(NOT ("${CMAKE_GENERATOR}" MATCHES "Ninja")) + require_change(E) endif() |