Browse Source

Merge topic 'test-rerun-cmake'

7f2dc8dc configure_file: Test that CMake re-runs on input change or output missing
daf95a38 try_compile: Test that CMake re-runs on input change
Brad King 11 years ago
parent
commit
33daec1ae9

+ 1 - 0
Tests/RunCMake/configure_file/RerunCMake-rerun-stderr.txt

@@ -0,0 +1 @@
+^Running CMake on RerunCMake$

+ 3 - 0
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

+ 1 - 0
Tests/RunCMake/configure_file/RerunCMake-stderr.txt

@@ -0,0 +1 @@
+^Running CMake on RerunCMake$

+ 3 - 0
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

+ 8 - 0
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)

+ 34 - 0
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()

+ 1 - 0
Tests/RunCMake/try_compile/RerunCMake-nowork-ninja-no-console-stdout.txt

@@ -0,0 +1 @@
+^ninja: no work to do\.$

+ 5 - 0
Tests/RunCMake/try_compile/RerunCMake-rerun-ninja-no-console-stdout.txt

@@ -0,0 +1,5 @@
+Running CMake on RerunCMake
+FALSE
+-- Configuring done
+-- Generating done
+-- Build files have been written to: .*/Tests/RunCMake/try_compile/RerunCMake-build

+ 2 - 0
Tests/RunCMake/try_compile/RerunCMake-rerun-stderr.txt

@@ -0,0 +1,2 @@
+^Running CMake on RerunCMake
+FALSE$

+ 3 - 0
Tests/RunCMake/try_compile/RerunCMake-rerun-stdout.txt

@@ -0,0 +1,3 @@
+-- Configuring done
+-- Generating done
+-- Build files have been written to: .*/Tests/RunCMake/try_compile/RerunCMake-build

+ 2 - 0
Tests/RunCMake/try_compile/RerunCMake-stderr.txt

@@ -0,0 +1,2 @@
+^Running CMake on RerunCMake
+TRUE$

+ 3 - 0
Tests/RunCMake/try_compile/RerunCMake-stdout.txt

@@ -0,0 +1,3 @@
+-- Configuring done
+-- Generating done
+-- Build files have been written to: .*/Tests/RunCMake/try_compile/RerunCMake-build

+ 7 - 0
Tests/RunCMake/try_compile/RerunCMake.cmake

@@ -0,0 +1,7 @@
+message("Running CMake on RerunCMake") # write to stderr if cmake reruns
+enable_language(C)
+try_compile(res
+  "${CMAKE_CURRENT_BINARY_DIR}"
+  SOURCES "${CMAKE_CURRENT_BINARY_DIR}/TryCompileInput.c"
+  )
+message("${res}")

+ 33 - 0
Tests/RunCMake/try_compile/RunCMakeTest.cmake

@@ -17,3 +17,36 @@ run_cmake(NonSourceCopyFile)
 run_cmake(NonSourceCompileDefinitions)
 
 run_cmake(CMP0056)
+
+if(RunCMake_GENERATOR MATCHES "Make|Ninja")
+  # 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_tc  "${RunCMake_TEST_BINARY_DIR}/TryCompileInput.c")
+  file(WRITE "${in_tc}" "int main(void) { return 0; }\n")
+
+  # Older Ninja keeps all rerun output on stdout
+  set(ninja "")
+  if(RunCMake_GENERATOR STREQUAL "Ninja")
+    execute_process(COMMAND ${RunCMake_MAKE_PROGRAM} --version
+      OUTPUT_VARIABLE ninja_version OUTPUT_STRIP_TRAILING_WHITESPACE)
+    if(ninja_version VERSION_LESS 1.5)
+      set(ninja -ninja-no-console)
+    endif()
+  endif()
+
+  message(STATUS "RerunCMake: first configuration...")
+  run_cmake(RerunCMake)
+  run_cmake_command(RerunCMake-nowork${ninja} ${CMAKE_COMMAND} --build .)
+
+  execute_process(COMMAND ${CMAKE_COMMAND} -E sleep 1) # handle 1s resolution
+  message(STATUS "RerunCMake: modify try_compile input...")
+  file(WRITE "${in_tc}" "does-not-compile\n")
+  run_cmake_command(RerunCMake-rerun${ninja} ${CMAKE_COMMAND} --build .)
+  run_cmake_command(RerunCMake-nowork${ninja} ${CMAKE_COMMAND} --build .)
+
+  unset(RunCMake_TEST_BINARY_DIR)
+  unset(RunCMake_TEST_NO_CLEAN)
+endif()