From 7f2dc8dc54fa6486423477dd673725bc40d3fdeb Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 23 Jan 2015 10:02:04 -0500 Subject: configure_file: Test that CMake re-runs on input change or output missing With the Makefile generators we expect that touching or modifying the input file of a configure_file, or removing its output, will cause CMake to re-run on the next build. Extend the RunCMake.configure_file test with a case covering this. Also check that CMake does not re-run if nothing has changed. --- .../configure_file/RerunCMake-rerun-stderr.txt | 1 + .../configure_file/RerunCMake-rerun-stdout.txt | 3 ++ .../RunCMake/configure_file/RerunCMake-stderr.txt | 1 + .../RunCMake/configure_file/RerunCMake-stdout.txt | 3 ++ Tests/RunCMake/configure_file/RerunCMake.cmake | 8 +++++ Tests/RunCMake/configure_file/RunCMakeTest.cmake | 34 ++++++++++++++++++++++ 6 files changed, 50 insertions(+) create mode 100644 Tests/RunCMake/configure_file/RerunCMake-rerun-stderr.txt create mode 100644 Tests/RunCMake/configure_file/RerunCMake-rerun-stdout.txt create mode 100644 Tests/RunCMake/configure_file/RerunCMake-stderr.txt create mode 100644 Tests/RunCMake/configure_file/RerunCMake-stdout.txt create mode 100644 Tests/RunCMake/configure_file/RerunCMake.cmake diff --git a/Tests/RunCMake/configure_file/RerunCMake-rerun-stderr.txt b/Tests/RunCMake/configure_file/RerunCMake-rerun-stderr.txt new file mode 100644 index 0000000..26e07b6 --- /dev/null +++ b/Tests/RunCMake/configure_file/RerunCMake-rerun-stderr.txt @@ -0,0 +1 @@ +^Running CMake on RerunCMake$ diff --git a/Tests/RunCMake/configure_file/RerunCMake-rerun-stdout.txt b/Tests/RunCMake/configure_file/RerunCMake-rerun-stdout.txt new file mode 100644 index 0000000..34c873c --- /dev/null +++ b/Tests/RunCMake/configure_file/RerunCMake-rerun-stdout.txt @@ -0,0 +1,3 @@ +-- Configuring done +-- Generating done +-- Build files have been written to: .*/Tests/RunCMake/configure_file/RerunCMake-build diff --git a/Tests/RunCMake/configure_file/RerunCMake-stderr.txt b/Tests/RunCMake/configure_file/RerunCMake-stderr.txt new file mode 100644 index 0000000..26e07b6 --- /dev/null +++ b/Tests/RunCMake/configure_file/RerunCMake-stderr.txt @@ -0,0 +1 @@ +^Running CMake on RerunCMake$ diff --git a/Tests/RunCMake/configure_file/RerunCMake-stdout.txt b/Tests/RunCMake/configure_file/RerunCMake-stdout.txt new file mode 100644 index 0000000..34c873c --- /dev/null +++ b/Tests/RunCMake/configure_file/RerunCMake-stdout.txt @@ -0,0 +1,3 @@ +-- Configuring done +-- Generating done +-- Build files have been written to: .*/Tests/RunCMake/configure_file/RerunCMake-build diff --git a/Tests/RunCMake/configure_file/RerunCMake.cmake b/Tests/RunCMake/configure_file/RerunCMake.cmake new file mode 100644 index 0000000..890cc1f --- /dev/null +++ b/Tests/RunCMake/configure_file/RerunCMake.cmake @@ -0,0 +1,8 @@ +message("Running CMake on RerunCMake") # write to stderr if cmake reruns +configure_file( + "${CMAKE_CURRENT_BINARY_DIR}/ConfigureFileInput.txt.in" + "${CMAKE_CURRENT_BINARY_DIR}/ConfigureFileOutput.txt" + @ONLY + ) +# make sure CMakeCache.txt is newer than ConfigureFileOutput.txt +execute_process(COMMAND ${CMAKE_COMMAND} -E sleep 1) diff --git a/Tests/RunCMake/configure_file/RunCMakeTest.cmake b/Tests/RunCMake/configure_file/RunCMakeTest.cmake index c010256..489652b 100644 --- a/Tests/RunCMake/configure_file/RunCMakeTest.cmake +++ b/Tests/RunCMake/configure_file/RunCMakeTest.cmake @@ -7,3 +7,37 @@ run_cmake(UTF16BE-BOM) run_cmake(UTF32LE-BOM) run_cmake(UTF32BE-BOM) run_cmake(UnknownArg) + +if(RunCMake_GENERATOR MATCHES "Make") + # Use a single build tree for a few tests without cleaning. + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/RerunCMake-build) + set(RunCMake_TEST_NO_CLEAN 1) + file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") + file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") + set(in_conf "${RunCMake_TEST_BINARY_DIR}/ConfigureFileInput.txt.in") + file(WRITE "${in_conf}" "1") + + message(STATUS "RerunCMake: first configuration...") + run_cmake(RerunCMake) + run_cmake_command(RerunCMake-nowork ${CMAKE_COMMAND} --build .) + + execute_process(COMMAND ${CMAKE_COMMAND} -E sleep 1) # handle 1s resolution + message(STATUS "RerunCMake: touch configure_file input...") + file(WRITE "${in_conf}" "1") + run_cmake_command(RerunCMake-rerun ${CMAKE_COMMAND} --build .) + run_cmake_command(RerunCMake-nowork ${CMAKE_COMMAND} --build .) + + execute_process(COMMAND ${CMAKE_COMMAND} -E sleep 1) # handle 1s resolution + message(STATUS "RerunCMake: modify configure_file input...") + file(WRITE "${in_conf}" "2") + run_cmake_command(RerunCMake-rerun ${CMAKE_COMMAND} --build .) + run_cmake_command(RerunCMake-nowork ${CMAKE_COMMAND} --build .) + + message(STATUS "RerunCMake: remove configure_file output...") + file(REMOVE "${RunCMake_TEST_BINARY_DIR}/ConfigureFileOutput.txt") + run_cmake_command(RerunCMake-rerun ${CMAKE_COMMAND} --build .) + run_cmake_command(RerunCMake-nowork ${CMAKE_COMMAND} --build .) + + unset(RunCMake_TEST_BINARY_DIR) + unset(RunCMake_TEST_NO_CLEAN) +endif() -- cgit v0.12