CTestUpdateCommon.cmake 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. #-----------------------------------------------------------------------------
  2. # Function to run a child process and report output only on error.
  3. function(run_child)
  4. execute_process(${ARGN}
  5. RESULT_VARIABLE FAILED
  6. OUTPUT_VARIABLE OUTPUT
  7. ERROR_VARIABLE OUTPUT
  8. OUTPUT_STRIP_TRAILING_WHITESPACE
  9. ERROR_STRIP_TRAILING_WHITESPACE
  10. )
  11. if(FAILED)
  12. string(REGEX REPLACE "\n" "\n " OUTPUT "${OUTPUT}")
  13. message(FATAL_ERROR "Child failed (${FAILED}), output is\n ${OUTPUT}\n"
  14. "Command = [${ARGN}]\n")
  15. endif(FAILED)
  16. endfunction(run_child)
  17. #-----------------------------------------------------------------------------
  18. # Function to find the Update.xml file and check for expected entries.
  19. function(check_updates build)
  20. # Find the Update.xml file for the given build tree
  21. set(PATTERN ${TOP}/${build}/Testing/*/Update.xml)
  22. file(GLOB UPDATE_XML_FILE RELATIVE ${TOP} ${PATTERN})
  23. string(REGEX REPLACE "//Update.xml$" "/Update.xml"
  24. UPDATE_XML_FILE "${UPDATE_XML_FILE}"
  25. )
  26. if(NOT UPDATE_XML_FILE)
  27. message(FATAL_ERROR "Cannot find Update.xml with pattern\n ${PATTERN}")
  28. endif(NOT UPDATE_XML_FILE)
  29. message(" found ${UPDATE_XML_FILE}")
  30. # Read entries from the Update.xml file
  31. file(STRINGS ${TOP}/${UPDATE_XML_FILE} UPDATE_XML_ENTRIES
  32. REGEX "FullName"
  33. LIMIT_INPUT 4096
  34. )
  35. # Verify that expected entries exist
  36. set(MISSING)
  37. foreach(f ${ARGN})
  38. string(REPLACE "/" "[/\\\\]" regex "${f}")
  39. string(REPLACE "." "\\." regex "${regex}")
  40. if(NOT "${UPDATE_XML_ENTRIES}" MATCHES "<FullName>${regex}</FullName>")
  41. list(APPEND MISSING ${f})
  42. endif()
  43. endforeach(f)
  44. # Report the result
  45. if(MISSING)
  46. # List the missing entries
  47. set(MSG "Update.xml is missing an entry for:\n")
  48. foreach(f ${MISSING})
  49. set(MSG "${MSG} ${f}\n")
  50. endforeach(f)
  51. # Provide the log file
  52. file(GLOB UPDATE_LOG_FILE
  53. ${TOP}/${build}/Testing/Temporary/LastUpdate*.log)
  54. if(UPDATE_LOG_FILE)
  55. file(READ ${UPDATE_LOG_FILE} UPDATE_LOG LIMIT 4096)
  56. string(REGEX REPLACE "\n" "\n " UPDATE_LOG "${UPDATE_LOG}")
  57. set(MSG "${MSG}Update log:\n ${UPDATE_LOG}")
  58. else(UPDATE_LOG_FILE)
  59. set(MSG "${MSG}No update log found!")
  60. endif(UPDATE_LOG_FILE)
  61. # Display the error message
  62. message(FATAL_ERROR "${MSG}")
  63. else(MISSING)
  64. # Success
  65. message(" no entries missing from Update.xml")
  66. endif(MISSING)
  67. endfunction(check_updates)
  68. #-----------------------------------------------------------------------------
  69. # Function to create initial content.
  70. function(create_content dir)
  71. file(MAKE_DIRECTORY ${TOP}/${dir})
  72. # An example CTest project configuration file.
  73. file(WRITE ${TOP}/${dir}/CTestConfig.cmake
  74. "# CTest Configuration File
  75. set(CTEST_PROJECT_NAME TestProject)
  76. set(CTEST_NIGHTLY_START_TIME \"21:00:00 EDT\")
  77. ")
  78. # Some other files.
  79. file(WRITE ${TOP}/${dir}/foo.txt "foo\n")
  80. file(WRITE ${TOP}/${dir}/bar.txt "bar\n")
  81. endfunction(create_content)
  82. #-----------------------------------------------------------------------------
  83. # Function to update content.
  84. function(update_content dir added_var removed_var dirs_var)
  85. file(APPEND ${TOP}/${dir}/foo.txt "foo line 2\n")
  86. file(WRITE ${TOP}/${dir}/zot.txt "zot\n")
  87. file(REMOVE ${TOP}/${dir}/bar.txt)
  88. file(MAKE_DIRECTORY ${TOP}/${dir}/subdir)
  89. file(WRITE ${TOP}/${dir}/subdir/foo.txt "foo\n")
  90. file(WRITE ${TOP}/${dir}/subdir/bar.txt "bar\n")
  91. set(${dirs_var} subdir PARENT_SCOPE)
  92. set(${added_var} zot.txt subdir/foo.txt subdir/bar.txt PARENT_SCOPE)
  93. set(${removed_var} bar.txt PARENT_SCOPE)
  94. endfunction(update_content)
  95. #-----------------------------------------------------------------------------
  96. # Function to change existing files
  97. function(change_content dir)
  98. file(APPEND ${TOP}/${dir}/foo.txt "foo line 3\n")
  99. file(APPEND ${TOP}/${dir}/subdir/foo.txt "foo line 2\n")
  100. endfunction(change_content)
  101. #-----------------------------------------------------------------------------
  102. # Function to create local modifications before update
  103. function(modify_content dir)
  104. file(APPEND ${TOP}/${dir}/CTestConfig.cmake "# local modification\n")
  105. endfunction(modify_content)
  106. #-----------------------------------------------------------------------------
  107. # Function to write CTestConfiguration.ini content.
  108. function(create_build_tree src_dir bin_dir)
  109. file(MAKE_DIRECTORY ${TOP}/${bin_dir})
  110. file(WRITE ${TOP}/${bin_dir}/CTestConfiguration.ini
  111. "# CTest Configuration File
  112. SourceDirectory: ${TOP}/${src_dir}
  113. BuildDirectory: ${TOP}/${bin_dir}
  114. Site: test.site
  115. BuildName: user-test
  116. ")
  117. endfunction(create_build_tree)
  118. #-----------------------------------------------------------------------------
  119. # Function to write the dashboard test script.
  120. function(create_dashboard_script name custom_text)
  121. # Write the dashboard script.
  122. file(WRITE ${TOP}/dashboard.cmake
  123. "# CTest Dashboard Script
  124. set(CTEST_DASHBOARD_ROOT \"${TOP}\")
  125. set(CTEST_SITE test.site)
  126. set(CTEST_BUILD_NAME dash-test)
  127. set(CTEST_SOURCE_DIRECTORY \${CTEST_DASHBOARD_ROOT}/dash-source)
  128. set(CTEST_BINARY_DIRECTORY \${CTEST_DASHBOARD_ROOT}/dash-binary)
  129. ${custom_text}
  130. # Start a dashboard and run the update step
  131. ctest_start(Experimental)
  132. ctest_update(SOURCE \${CTEST_SOURCE_DIRECTORY})
  133. ")
  134. endfunction(create_dashboard_script)
  135. #-----------------------------------------------------------------------------
  136. # Function to run the dashboard through the command line
  137. function(run_dashboard_command_line bin_dir)
  138. run_child(
  139. WORKING_DIRECTORY ${TOP}/${bin_dir}
  140. COMMAND ${CMAKE_CTEST_COMMAND} -M Experimental -T Start -T Update
  141. )
  142. # Verify the updates reported by CTest.
  143. check_updates(${bin_dir} foo.txt bar.txt zot.txt CTestConfig.cmake
  144. subdir/foo.txt subdir/bar.txt)
  145. endfunction(run_dashboard_command_line)
  146. #-----------------------------------------------------------------------------
  147. # Function to run the dashboard through a script
  148. function(run_dashboard_script name)
  149. run_child(
  150. WORKING_DIRECTORY ${TOP}
  151. COMMAND ${CMAKE_CTEST_COMMAND} -S ${name} -V
  152. )
  153. # Verify the updates reported by CTest.
  154. check_updates(dash-binary foo.txt bar.txt zot.txt
  155. subdir/foo.txt subdir/bar.txt)
  156. endfunction(run_dashboard_script)
  157. #-----------------------------------------------------------------------------
  158. # Function to initialize the testing directory.
  159. function(init_testing)
  160. file(REMOVE_RECURSE ${TOP})
  161. file(MAKE_DIRECTORY ${TOP})
  162. endfunction(init_testing)