CTestUpdateCommon.cmake 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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()
  16. endfunction()
  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()
  29. message(" found ${UPDATE_XML_FILE}")
  30. set(max_update_xml_size 16384)
  31. # Read entries from the Update.xml file
  32. set(types "Updated|Modified|Conflicting")
  33. file(STRINGS ${TOP}/${UPDATE_XML_FILE} UPDATE_XML_ENTRIES
  34. REGEX "<(${types}|FullName)>"
  35. LIMIT_INPUT ${max_update_xml_size}
  36. )
  37. string(REGEX REPLACE
  38. "[ \t]*<(${types})>[ \t]*;[ \t]*<FullName>([^<]*)</FullName>"
  39. "\\1{\\2}" UPDATE_XML_ENTRIES "${UPDATE_XML_ENTRIES}")
  40. # Compare expected and actual entries
  41. set(EXTRA "${UPDATE_XML_ENTRIES}")
  42. list(REMOVE_ITEM EXTRA ${ARGN} ${UPDATE_EXTRA} ${UPDATE_MAYBE})
  43. set(MISSING "${ARGN}" ${UPDATE_EXTRA})
  44. list(REMOVE_ITEM MISSING ${UPDATE_XML_ENTRIES})
  45. if(NOT UPDATE_NOT_GLOBAL)
  46. set(rev_elements Revision PriorRevision ${UPDATE_GLOBAL_ELEMENTS})
  47. string(REPLACE ";" "|" rev_regex "${rev_elements}")
  48. set(rev_regex "^\t<(${rev_regex})>[^<\n]+</(${rev_regex})>$")
  49. file(STRINGS ${TOP}/${UPDATE_XML_FILE} UPDATE_XML_REVISIONS
  50. REGEX "${rev_regex}"
  51. LIMIT_INPUT ${max_update_xml_size}
  52. )
  53. foreach(r IN LISTS UPDATE_XML_REVISIONS)
  54. string(REGEX REPLACE "${rev_regex}" "\\1" element "${r}")
  55. set(element_${element} 1)
  56. endforeach()
  57. foreach(element ${rev_elements})
  58. if(NOT element_${element})
  59. list(APPEND MISSING "global <${element}> element")
  60. endif()
  61. endforeach()
  62. endif()
  63. # Report the result
  64. set(MSG "")
  65. if(MISSING)
  66. # List the missing entries
  67. set(MSG "${MSG}Update.xml is missing expected entries:\n")
  68. foreach(f ${MISSING})
  69. set(MSG "${MSG} ${f}\n")
  70. endforeach()
  71. else()
  72. # Success
  73. message(" no entries missing from Update.xml")
  74. endif()
  75. # Report the result
  76. if(EXTRA)
  77. # List the extra entries
  78. set(MSG "${MSG}Update.xml has extra unexpected entries:\n")
  79. foreach(f ${EXTRA})
  80. set(MSG "${MSG} ${f}\n")
  81. endforeach()
  82. else()
  83. # Success
  84. message(" no extra entries in Update.xml")
  85. endif()
  86. if(MSG)
  87. # Provide the log file
  88. file(GLOB UPDATE_LOG_FILE
  89. ${TOP}/${build}/Testing/Temporary/LastUpdate*.log)
  90. if(UPDATE_LOG_FILE)
  91. file(READ ${UPDATE_LOG_FILE} UPDATE_LOG LIMIT ${max_update_xml_size})
  92. string(REGEX REPLACE "\n" "\n " UPDATE_LOG "${UPDATE_LOG}")
  93. set(MSG "${MSG}Update log:\n ${UPDATE_LOG}")
  94. else()
  95. set(MSG "${MSG}No update log found!")
  96. endif()
  97. # Display the error message
  98. message(FATAL_ERROR "${MSG}")
  99. endif()
  100. endfunction()
  101. #-----------------------------------------------------------------------------
  102. # Function to create initial content.
  103. function(create_content dir)
  104. file(MAKE_DIRECTORY ${TOP}/${dir})
  105. # An example CTest project configuration file.
  106. file(WRITE ${TOP}/${dir}/CTestConfig.cmake
  107. "# CTest Configuration File
  108. set(CTEST_PROJECT_NAME TestProject)
  109. set(CTEST_NIGHTLY_START_TIME \"21:00:00 EDT\")
  110. ")
  111. # Some other files.
  112. file(WRITE ${TOP}/${dir}/foo.txt "foo\n")
  113. file(WRITE ${TOP}/${dir}/bar.txt "bar\n")
  114. endfunction()
  115. #-----------------------------------------------------------------------------
  116. # Function to update content.
  117. function(update_content dir added_var removed_var dirs_var)
  118. file(APPEND ${TOP}/${dir}/foo.txt "foo line 2\n")
  119. file(WRITE ${TOP}/${dir}/zot.txt "zot\n")
  120. file(REMOVE ${TOP}/${dir}/bar.txt)
  121. file(MAKE_DIRECTORY ${TOP}/${dir}/subdir)
  122. file(WRITE ${TOP}/${dir}/subdir/foo.txt "foo\n")
  123. file(WRITE ${TOP}/${dir}/subdir/bar.txt "bar\n")
  124. set(${dirs_var} subdir PARENT_SCOPE)
  125. set(${added_var} zot.txt subdir/foo.txt subdir/bar.txt PARENT_SCOPE)
  126. set(${removed_var} bar.txt PARENT_SCOPE)
  127. endfunction()
  128. #-----------------------------------------------------------------------------
  129. # Function to change existing files
  130. function(change_content dir)
  131. file(APPEND ${TOP}/${dir}/foo.txt "foo line 3\n")
  132. file(APPEND ${TOP}/${dir}/subdir/foo.txt "foo line 2\n")
  133. endfunction()
  134. #-----------------------------------------------------------------------------
  135. # Function to create local modifications before update
  136. function(modify_content dir)
  137. file(APPEND ${TOP}/${dir}/CTestConfig.cmake "# local modification\n")
  138. endfunction()
  139. #-----------------------------------------------------------------------------
  140. # Function to write CTestConfiguration.ini content.
  141. function(create_build_tree src_dir bin_dir)
  142. file(MAKE_DIRECTORY ${TOP}/${bin_dir})
  143. file(WRITE ${TOP}/${bin_dir}/CTestConfiguration.ini
  144. "# CTest Configuration File
  145. SourceDirectory: ${TOP}/${src_dir}
  146. BuildDirectory: ${TOP}/${bin_dir}
  147. Site: test.site
  148. BuildName: user-test
  149. ")
  150. endfunction()
  151. #-----------------------------------------------------------------------------
  152. # Function to write the dashboard test script.
  153. function(create_dashboard_script bin_dir custom_text)
  154. # Write the dashboard script.
  155. file(WRITE ${TOP}/${bin_dir}.cmake
  156. "# CTest Dashboard Script
  157. set(CTEST_DASHBOARD_ROOT \"${TOP}\")
  158. set(CTEST_SITE test.site)
  159. set(CTEST_BUILD_NAME dash-test)
  160. set(CTEST_SOURCE_DIRECTORY \${CTEST_DASHBOARD_ROOT}/dash-source)
  161. set(CTEST_BINARY_DIRECTORY \${CTEST_DASHBOARD_ROOT}/${bin_dir})
  162. ${custom_text}
  163. # Start a dashboard and run the update step
  164. ctest_start(Experimental)
  165. ctest_update(SOURCE \${CTEST_SOURCE_DIRECTORY})
  166. ")
  167. endfunction()
  168. #-----------------------------------------------------------------------------
  169. # Function to run the dashboard through the command line
  170. function(run_dashboard_command_line bin_dir)
  171. run_child(
  172. WORKING_DIRECTORY ${TOP}/${bin_dir}
  173. COMMAND ${CMAKE_CTEST_COMMAND} -M Experimental -T Start -T Update
  174. )
  175. # Verify the updates reported by CTest.
  176. list(APPEND UPDATE_MAYBE Updated{subdir})
  177. set(_modified Modified{CTestConfig.cmake})
  178. if(UPDATE_NO_MODIFIED)
  179. set(_modified "")
  180. endif()
  181. check_updates(${bin_dir}
  182. Updated{foo.txt}
  183. Updated{bar.txt}
  184. Updated{zot.txt}
  185. Updated{subdir/foo.txt}
  186. Updated{subdir/bar.txt}
  187. ${_modified}
  188. )
  189. endfunction()
  190. #-----------------------------------------------------------------------------
  191. # Function to run the dashboard through a script
  192. function(run_dashboard_script bin_dir)
  193. run_child(
  194. WORKING_DIRECTORY ${TOP}
  195. COMMAND ${CMAKE_CTEST_COMMAND} -S ${bin_dir}.cmake -V
  196. )
  197. # Verify the updates reported by CTest.
  198. list(APPEND UPDATE_MAYBE Updated{subdir})
  199. check_updates(${bin_dir}
  200. Updated{foo.txt}
  201. Updated{bar.txt}
  202. Updated{zot.txt}
  203. Updated{subdir/foo.txt}
  204. Updated{subdir/bar.txt}
  205. )
  206. endfunction()
  207. #-----------------------------------------------------------------------------
  208. # Function to initialize the testing directory.
  209. function(init_testing)
  210. file(REMOVE_RECURSE ${TOP})
  211. file(MAKE_DIRECTORY ${TOP})
  212. endfunction()