CTestUpdateGIT.cmake.in 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. # This script drives creation of a git repository and checks
  2. # that CTest can update from it.
  3. #-----------------------------------------------------------------------------
  4. # Test in a directory next to this script.
  5. get_filename_component(TOP "${CMAKE_CURRENT_LIST_FILE}" PATH)
  6. string(APPEND TOP "/@CTestUpdateGIT_DIR@")
  7. set(UPDATE_EXTRA Updated{module})
  8. # Include code common to all update tests.
  9. include("@CMAKE_CURRENT_SOURCE_DIR@/CTestUpdateCommon.cmake")
  10. #-----------------------------------------------------------------------------
  11. # Report git tools in use.
  12. message("Using GIT tools:")
  13. set(GIT "@GIT_EXECUTABLE@")
  14. message(" git = ${GIT}")
  15. set(AUTHOR_CONFIG "[user]
  16. \tname = Test Author
  17. \temail = testauthor@cmake.org
  18. ")
  19. #-----------------------------------------------------------------------------
  20. # Initialize the testing directory.
  21. message("Creating test directory...")
  22. init_testing()
  23. if(UNIX)
  24. set(src "@CMAKE_CURRENT_SOURCE_DIR@")
  25. configure_file(${src}/CTestUpdateGIT.sh.in ${TOP}/git.sh @ONLY)
  26. set(GIT ${TOP}/git.sh)
  27. endif()
  28. #-----------------------------------------------------------------------------
  29. # Create the repository.
  30. message("Creating repository...")
  31. file(MAKE_DIRECTORY ${TOP}/repo.git)
  32. run_child(
  33. WORKING_DIRECTORY ${TOP}/repo.git
  34. COMMAND ${GIT} --bare init
  35. )
  36. file(REMOVE_RECURSE ${TOP}/repo.git/hooks)
  37. # Create submodule repository.
  38. message("Creating submodule...")
  39. file(MAKE_DIRECTORY ${TOP}/module.git)
  40. run_child(
  41. WORKING_DIRECTORY ${TOP}/module.git
  42. COMMAND ${GIT} --bare init
  43. )
  44. file(REMOVE_RECURSE ${TOP}/module.git/hooks)
  45. run_child(WORKING_DIRECTORY ${TOP}
  46. COMMAND ${GIT} clone module.git module
  47. )
  48. file(REMOVE_RECURSE ${TOP}/module/.git/hooks)
  49. file(APPEND ${TOP}/module/.git/config "
  50. ${AUTHOR_CONFIG}")
  51. create_content(module)
  52. run_child(WORKING_DIRECTORY ${TOP}/module
  53. COMMAND ${GIT} add .
  54. )
  55. run_child(WORKING_DIRECTORY ${TOP}/module
  56. COMMAND ${GIT} commit -m "Initial content"
  57. )
  58. run_child(WORKING_DIRECTORY ${TOP}/module
  59. COMMAND ${GIT} push origin master:refs/heads/master
  60. )
  61. #-----------------------------------------------------------------------------
  62. # Import initial content into the repository.
  63. message("Importing content...")
  64. # Import the content into the repository.
  65. run_child(WORKING_DIRECTORY ${TOP}
  66. COMMAND ${GIT} clone repo.git import
  67. )
  68. file(REMOVE_RECURSE ${TOP}/import/.git/hooks)
  69. file(APPEND ${TOP}/import/.git/config "
  70. ${AUTHOR_CONFIG}")
  71. create_content(import)
  72. file(WRITE ${TOP}/import/HEAD "HEAD\n")
  73. file(WRITE ${TOP}/import/master "master\n")
  74. run_child(WORKING_DIRECTORY ${TOP}/import
  75. COMMAND ${GIT} add .
  76. )
  77. run_child(WORKING_DIRECTORY ${TOP}/import
  78. COMMAND ${GIT} config core.safecrlf false
  79. )
  80. run_child(WORKING_DIRECTORY ${TOP}/import
  81. COMMAND ${GIT} submodule add ../module.git module
  82. )
  83. run_child(WORKING_DIRECTORY ${TOP}/import
  84. COMMAND ${GIT} commit -m "Initial content"
  85. )
  86. run_child(WORKING_DIRECTORY ${TOP}/import
  87. COMMAND ${GIT} push origin master:refs/heads/master
  88. )
  89. #-----------------------------------------------------------------------------
  90. # Modify the submodule.
  91. change_content(module)
  92. run_child(WORKING_DIRECTORY ${TOP}/module
  93. COMMAND ${GIT} add -u
  94. )
  95. run_child(WORKING_DIRECTORY ${TOP}/module
  96. COMMAND ${GIT} commit -m "Changed content"
  97. )
  98. run_child(WORKING_DIRECTORY ${TOP}/module
  99. COMMAND ${GIT} push origin master:refs/heads/master
  100. )
  101. #-----------------------------------------------------------------------------
  102. # Create a working tree.
  103. message("Checking out revision 1...")
  104. run_child(
  105. WORKING_DIRECTORY ${TOP}
  106. COMMAND ${GIT} clone repo.git user-source
  107. )
  108. file(REMOVE_RECURSE ${TOP}/user-source/.git/hooks)
  109. file(APPEND ${TOP}/user-source/.git/config "${AUTHOR_CONFIG}")
  110. run_child(
  111. WORKING_DIRECTORY ${TOP}/user-source
  112. COMMAND ${GIT} submodule init
  113. )
  114. run_child(
  115. WORKING_DIRECTORY ${TOP}/user-source
  116. COMMAND ${GIT} submodule update
  117. )
  118. # Save the first revision name.
  119. execute_process(
  120. WORKING_DIRECTORY ${TOP}/user-source
  121. COMMAND ${GIT} rev-parse HEAD
  122. OUTPUT_VARIABLE revision1
  123. OUTPUT_STRIP_TRAILING_WHITESPACE
  124. )
  125. #-----------------------------------------------------------------------------
  126. # Create an empty commit.
  127. message("Creating empty commit...")
  128. run_child(
  129. WORKING_DIRECTORY ${TOP}/user-source
  130. COMMAND ${GIT} commit --allow-empty -m "Empty commit"
  131. )
  132. #-----------------------------------------------------------------------------
  133. # Make changes in the working tree.
  134. message("Changing content...")
  135. update_content(user-source files_added files_removed dirs_added)
  136. if(dirs_added)
  137. run_child(
  138. WORKING_DIRECTORY ${TOP}/user-source
  139. COMMAND ${GIT} add -- ${dirs_added}
  140. )
  141. endif()
  142. run_child(
  143. WORKING_DIRECTORY ${TOP}/user-source
  144. COMMAND ${GIT} add -- ${files_added}
  145. )
  146. run_child(
  147. WORKING_DIRECTORY ${TOP}/user-source
  148. COMMAND ${GIT} rm -- ${files_removed}
  149. )
  150. run_child(WORKING_DIRECTORY ${TOP}/user-source/module
  151. COMMAND ${GIT} checkout master --
  152. )
  153. run_child(
  154. WORKING_DIRECTORY ${TOP}/user-source
  155. COMMAND ${GIT} add -u
  156. )
  157. #-----------------------------------------------------------------------------
  158. # Commit the changes to the repository.
  159. message("Committing revision 2...")
  160. run_child(
  161. WORKING_DIRECTORY ${TOP}/user-source
  162. COMMAND ${GIT} commit -m "Changed content"
  163. )
  164. run_child(
  165. WORKING_DIRECTORY ${TOP}/user-source
  166. COMMAND ${GIT} push origin
  167. )
  168. #-----------------------------------------------------------------------------
  169. # Make changes in the working tree.
  170. message("Changing content again...")
  171. change_content(user-source)
  172. run_child(
  173. WORKING_DIRECTORY ${TOP}/user-source
  174. COMMAND ${GIT} add -u
  175. )
  176. #-----------------------------------------------------------------------------
  177. # Commit the changes to the repository.
  178. message("Committing revision 3...")
  179. run_child(
  180. WORKING_DIRECTORY ${TOP}/user-source
  181. COMMAND ${GIT} commit -m "Changed content again"
  182. )
  183. run_child(
  184. WORKING_DIRECTORY ${TOP}/user-source
  185. COMMAND ${GIT} push origin
  186. )
  187. #-----------------------------------------------------------------------------
  188. # Go back to before the changes so we can test updating.
  189. macro(rewind_source src_dir)
  190. message("Backing up to revision 1...")
  191. run_child(
  192. WORKING_DIRECTORY ${TOP}/${src_dir}
  193. COMMAND ${GIT} reset --hard ${revision1}
  194. )
  195. run_child(
  196. WORKING_DIRECTORY ${TOP}/${src_dir}
  197. COMMAND ${GIT} submodule update
  198. )
  199. endmacro()
  200. rewind_source(user-source)
  201. # Make sure pull does not try to rebase (which does not work with
  202. # modified files) even if ~/.gitconfig sets "branch.master.rebase".
  203. run_child(
  204. WORKING_DIRECTORY ${TOP}/user-source
  205. COMMAND ${GIT} config branch.master.rebase false
  206. )
  207. # Create a modified file.
  208. modify_content(user-source)
  209. #-----------------------------------------------------------------------------
  210. # Test updating the user work directory with the command-line interface.
  211. message("Running CTest Dashboard Command Line...")
  212. # Create the user build tree.
  213. create_build_tree(user-source user-binary)
  214. file(APPEND ${TOP}/user-binary/CTestConfiguration.ini
  215. "# GIT command configuration
  216. UpdateCommand: ${GIT}
  217. ")
  218. # Run the dashboard command line interface.
  219. set(UPDATE_NO_MODIFIED 1)
  220. run_dashboard_command_line(user-binary)
  221. set(UPDATE_NO_MODIFIED 0)
  222. rewind_source(user-source)
  223. modify_content(user-source)
  224. message("Running CTest Dashboard Command Line (custom update)...")
  225. # Create the user build tree.
  226. create_build_tree(user-source user-binary-custom)
  227. file(APPEND ${TOP}/user-binary-custom/CTestConfiguration.ini
  228. "# GIT command configuration
  229. UpdateCommand: ${GIT}
  230. GITUpdateCustom: ${GIT};pull;origin;master
  231. ")
  232. # Run the dashboard command line interface.
  233. run_dashboard_command_line(user-binary-custom)
  234. #-----------------------------------------------------------------------------
  235. # Test initial checkout and update with a dashboard script.
  236. message("Running CTest Dashboard Script...")
  237. create_dashboard_script(dash-binary
  238. "# git command configuration
  239. set(CTEST_GIT_COMMAND \"${GIT}\")
  240. set(CTEST_GIT_UPDATE_OPTIONS)
  241. execute_process(
  242. WORKING_DIRECTORY \"${TOP}\"
  243. COMMAND \"${GIT}\" clone repo.git dash-source
  244. )
  245. # Test .git file.
  246. file(RENAME \"${TOP}/dash-source/.git\" \"${TOP}/dash-source/repo.git\")
  247. file(WRITE \"${TOP}/dash-source/.git\" \"gitdir: repo.git\n\")
  248. execute_process(
  249. WORKING_DIRECTORY \"${TOP}/dash-source\"
  250. COMMAND \"${GIT}\" reset --hard ${revision1}
  251. )
  252. execute_process(
  253. WORKING_DIRECTORY \"${TOP}/dash-source\"
  254. COMMAND \"${GIT}\" submodule init
  255. )
  256. execute_process(
  257. WORKING_DIRECTORY \"${TOP}/dash-source\"
  258. COMMAND \"${GIT}\" submodule update
  259. )
  260. ")
  261. # Run the dashboard script with CTest.
  262. run_dashboard_script(dash-binary)
  263. rewind_source(dash-source)
  264. #-----------------------------------------------------------------------------
  265. # Test custom update with a dashboard script.
  266. message("Running CTest Dashboard Script (custom update)...")
  267. create_dashboard_script(dash-binary-custom
  268. "# git command configuration
  269. set(CTEST_GIT_COMMAND \"${GIT}\")
  270. set(CTEST_GIT_UPDATE_OPTIONS)
  271. set(CTEST_GIT_UPDATE_CUSTOM \${CTEST_GIT_COMMAND} pull origin master)
  272. ")
  273. # Run the dashboard script with CTest.
  274. run_dashboard_script(dash-binary-custom)
  275. rewind_source(dash-source)
  276. #-----------------------------------------------------------------------------
  277. # Test no update with a dashboard script.
  278. message("Running CTest Dashboard Script (No update)...")
  279. create_dashboard_script(dash-binary-no-update
  280. "# git command configuration
  281. set(CTEST_GIT_COMMAND \"${GIT}\")
  282. set(CTEST_UPDATE_VERSION_ONLY TRUE)
  283. ")
  284. # Run the dashboard script with CTest.
  285. set(NO_UPDATE 1)
  286. run_dashboard_script(dash-binary-no-update)
  287. unset(NO_UPDATE)
  288. rewind_source(dash-source)
  289. #-----------------------------------------------------------------------------
  290. # Test ctest_update(QUIET)
  291. message("Running CTest Dashboard Script (update quietly)...")
  292. set(ctest_update_args QUIET)
  293. create_dashboard_script(dash-binary-quiet
  294. "# git command configuration
  295. set(CTEST_GIT_COMMAND \"${GIT}\")
  296. set(CTEST_GIT_UPDATE_OPTIONS)
  297. set(CTEST_GIT_UPDATE_CUSTOM \${CTEST_GIT_COMMAND} pull origin master)
  298. ")
  299. unset(ctest_update_args)
  300. # Run the dashboard script with CTest.
  301. run_dashboard_script(dash-binary-quiet)
  302. # Make sure the output seems quiet.
  303. if("${OUTPUT}" MATCHES "Updating the repository")
  304. message(FATAL_ERROR "Found 'Updating the repository' in quiet output")
  305. endif()
  306. #-----------------------------------------------------------------------------
  307. # Test ctest_update(RETURN_VALUE) on failure
  308. message("Running CTest Dashboard Script (fail to update)...")
  309. set(ctest_update_check [[
  310. if(NOT ret LESS 0)
  311. message(FATAL_ERROR "ctest_update incorrectly succeeded with ${ret}")
  312. endif()
  313. ]])
  314. create_dashboard_script(dash-binary-fail
  315. "set(CTEST_GIT_COMMAND \"update-command-does-not-exist\")
  316. ")
  317. unset(ctest_update_check)
  318. # Run the dashboard script with CTest.
  319. set(FAIL_UPDATE 1)
  320. run_dashboard_script(dash-binary-fail)
  321. unset(FAIL_UPDATE)