CTestUpdateGIT.cmake.in 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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. set(TOP "${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 = [email protected]
  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. set(REPO file://${TOP}/repo.git)
  38. # Create submodule repository.
  39. message("Creating submodule...")
  40. file(MAKE_DIRECTORY ${TOP}/module.git)
  41. run_child(
  42. WORKING_DIRECTORY ${TOP}/module.git
  43. COMMAND ${GIT} --bare init
  44. )
  45. file(REMOVE_RECURSE ${TOP}/module.git/hooks)
  46. set(MOD_REPO file://${TOP}/module.git)
  47. create_content(module)
  48. run_child(WORKING_DIRECTORY ${TOP}/module
  49. COMMAND ${GIT} init
  50. )
  51. file(REMOVE_RECURSE ${TOP}/module/.git/hooks)
  52. file(APPEND ${TOP}/module/.git/config "
  53. [remote \"origin\"]
  54. \turl = ${MOD_REPO}
  55. \tfetch = +refs/heads/*:refs/remotes/origin/*
  56. ${AUTHOR_CONFIG}")
  57. run_child(WORKING_DIRECTORY ${TOP}/module
  58. COMMAND ${GIT} add .
  59. )
  60. run_child(WORKING_DIRECTORY ${TOP}/module
  61. COMMAND ${GIT} commit -m "Initial content"
  62. )
  63. run_child(WORKING_DIRECTORY ${TOP}/module
  64. COMMAND ${GIT} push origin master:refs/heads/master
  65. )
  66. #-----------------------------------------------------------------------------
  67. # Import initial content into the repository.
  68. message("Importing content...")
  69. create_content(import)
  70. # Import the content into the repository.
  71. run_child(WORKING_DIRECTORY ${TOP}/import
  72. COMMAND ${GIT} init
  73. )
  74. file(REMOVE_RECURSE ${TOP}/import/.git/hooks)
  75. file(APPEND ${TOP}/import/.git/config "
  76. [remote \"origin\"]
  77. \turl = ${REPO}
  78. \tfetch = +refs/heads/*:refs/remotes/origin/*
  79. ${AUTHOR_CONFIG}")
  80. run_child(WORKING_DIRECTORY ${TOP}/import
  81. COMMAND ${GIT} add .
  82. )
  83. run_child(WORKING_DIRECTORY ${TOP}/import
  84. COMMAND ${GIT} submodule add ${MOD_REPO} module
  85. )
  86. run_child(WORKING_DIRECTORY ${TOP}/import
  87. COMMAND ${GIT} commit -m "Initial content"
  88. )
  89. run_child(WORKING_DIRECTORY ${TOP}/import
  90. COMMAND ${GIT} push origin master:refs/heads/master
  91. )
  92. #-----------------------------------------------------------------------------
  93. # Modify the submodule.
  94. change_content(module)
  95. run_child(WORKING_DIRECTORY ${TOP}/module
  96. COMMAND ${GIT} add -u
  97. )
  98. run_child(WORKING_DIRECTORY ${TOP}/module
  99. COMMAND ${GIT} commit -m "Changed content"
  100. )
  101. run_child(WORKING_DIRECTORY ${TOP}/module
  102. COMMAND ${GIT} push origin master:refs/heads/master
  103. )
  104. #-----------------------------------------------------------------------------
  105. # Create a working tree.
  106. message("Checking out revision 1...")
  107. run_child(
  108. WORKING_DIRECTORY ${TOP}
  109. COMMAND ${GIT} clone ${REPO} user-source
  110. )
  111. file(REMOVE_RECURSE ${TOP}/user-source/.git/hooks)
  112. file(APPEND ${TOP}/user-source/.git/config "${AUTHOR_CONFIG}")
  113. run_child(
  114. WORKING_DIRECTORY ${TOP}/user-source
  115. COMMAND ${GIT} submodule init
  116. )
  117. run_child(
  118. WORKING_DIRECTORY ${TOP}/user-source
  119. COMMAND ${GIT} submodule update
  120. )
  121. # Save the first revision name.
  122. execute_process(
  123. WORKING_DIRECTORY ${TOP}/user-source
  124. COMMAND ${GIT} rev-parse HEAD
  125. OUTPUT_VARIABLE revision1
  126. OUTPUT_STRIP_TRAILING_WHITESPACE
  127. )
  128. #-----------------------------------------------------------------------------
  129. # Create an empty commit.
  130. message("Creating empty commit...")
  131. run_child(
  132. WORKING_DIRECTORY ${TOP}/user-source
  133. COMMAND ${GIT} commit --allow-empty -m "Empty commit"
  134. )
  135. #-----------------------------------------------------------------------------
  136. # Make changes in the working tree.
  137. message("Changing content...")
  138. update_content(user-source files_added files_removed dirs_added)
  139. if(dirs_added)
  140. run_child(
  141. WORKING_DIRECTORY ${TOP}/user-source
  142. COMMAND ${GIT} add ${dirs_added}
  143. )
  144. endif(dirs_added)
  145. run_child(
  146. WORKING_DIRECTORY ${TOP}/user-source
  147. COMMAND ${GIT} add ${files_added}
  148. )
  149. run_child(
  150. WORKING_DIRECTORY ${TOP}/user-source
  151. COMMAND ${GIT} rm ${files_removed}
  152. )
  153. run_child(WORKING_DIRECTORY ${TOP}/user-source/module
  154. COMMAND ${GIT} checkout master
  155. )
  156. run_child(
  157. WORKING_DIRECTORY ${TOP}/user-source
  158. COMMAND ${GIT} add -u
  159. )
  160. #-----------------------------------------------------------------------------
  161. # Commit the changes to the repository.
  162. message("Committing revision 2...")
  163. run_child(
  164. WORKING_DIRECTORY ${TOP}/user-source
  165. COMMAND ${GIT} commit -m "Changed content"
  166. )
  167. run_child(
  168. WORKING_DIRECTORY ${TOP}/user-source
  169. COMMAND ${GIT} push origin
  170. )
  171. #-----------------------------------------------------------------------------
  172. # Make changes in the working tree.
  173. message("Changing content again...")
  174. change_content(user-source)
  175. run_child(
  176. WORKING_DIRECTORY ${TOP}/user-source
  177. COMMAND ${GIT} add -u
  178. )
  179. #-----------------------------------------------------------------------------
  180. # Commit the changes to the repository.
  181. message("Committing revision 3...")
  182. run_child(
  183. WORKING_DIRECTORY ${TOP}/user-source
  184. COMMAND ${GIT} commit -m "Changed content again"
  185. )
  186. run_child(
  187. WORKING_DIRECTORY ${TOP}/user-source
  188. COMMAND ${GIT} push origin
  189. )
  190. #-----------------------------------------------------------------------------
  191. # Go back to before the changes so we can test updating.
  192. macro(rewind_source src_dir)
  193. message("Backing up to revision 1...")
  194. run_child(
  195. WORKING_DIRECTORY ${TOP}/${src_dir}
  196. COMMAND ${GIT} reset --hard ${revision1}
  197. )
  198. run_child(
  199. WORKING_DIRECTORY ${TOP}/${src_dir}
  200. COMMAND ${GIT} submodule update
  201. )
  202. endmacro(rewind_source)
  203. rewind_source(user-source)
  204. # Make sure pull does not try to rebase (which does not work with
  205. # modified files) even if ~/.gitconfig sets "branch.master.rebase".
  206. run_child(
  207. WORKING_DIRECTORY ${TOP}/user-source
  208. COMMAND ${GIT} config branch.master.rebase false
  209. )
  210. # Create a modified file.
  211. modify_content(user-source)
  212. #-----------------------------------------------------------------------------
  213. # Test updating the user work directory with the command-line interface.
  214. message("Running CTest Dashboard Command Line...")
  215. # Create the user build tree.
  216. create_build_tree(user-source user-binary)
  217. file(APPEND ${TOP}/user-binary/CTestConfiguration.ini
  218. "# GIT command configuration
  219. UpdateCommand: ${GIT}
  220. ")
  221. # Run the dashboard command line interface.
  222. set(UPDATE_NO_MODIFIED 1)
  223. run_dashboard_command_line(user-binary)
  224. set(UPDATE_NO_MODIFIED 0)
  225. rewind_source(user-source)
  226. modify_content(user-source)
  227. message("Running CTest Dashboard Command Line (custom update)...")
  228. # Create the user build tree.
  229. create_build_tree(user-source user-binary-custom)
  230. file(APPEND ${TOP}/user-binary-custom/CTestConfiguration.ini
  231. "# GIT command configuration
  232. UpdateCommand: ${GIT}
  233. GITUpdateCustom: ${GIT};pull;origin;master
  234. ")
  235. # Run the dashboard command line interface.
  236. run_dashboard_command_line(user-binary-custom)
  237. #-----------------------------------------------------------------------------
  238. # Test initial checkout and update with a dashboard script.
  239. message("Running CTest Dashboard Script...")
  240. create_dashboard_script(dash-binary
  241. "# git command configuration
  242. set(CTEST_GIT_COMMAND \"${GIT}\")
  243. set(CTEST_GIT_UPDATE_OPTIONS)
  244. execute_process(
  245. WORKING_DIRECTORY \"${TOP}\"
  246. COMMAND \"${GIT}\" clone \"${REPO}\" dash-source
  247. )
  248. # Test .git file.
  249. file(RENAME \"${TOP}/dash-source/.git\" \"${TOP}/dash-source/repo.git\")
  250. file(WRITE \"${TOP}/dash-source/.git\" \"gitdir: repo.git\n\")
  251. execute_process(
  252. WORKING_DIRECTORY \"${TOP}/dash-source\"
  253. COMMAND \"${GIT}\" reset --hard ${revision1}
  254. )
  255. execute_process(
  256. WORKING_DIRECTORY \"${TOP}/dash-source\"
  257. COMMAND \"${GIT}\" submodule init
  258. )
  259. execute_process(
  260. WORKING_DIRECTORY \"${TOP}/dash-source\"
  261. COMMAND \"${GIT}\" submodule update
  262. )
  263. ")
  264. # Run the dashboard script with CTest.
  265. run_dashboard_script(dash-binary)
  266. rewind_source(dash-source)
  267. #-----------------------------------------------------------------------------
  268. # Test custom update with a dashboard script.
  269. message("Running CTest Dashboard Script (custom update)...")
  270. create_dashboard_script(dash-binary-custom
  271. "# git command configuration
  272. set(CTEST_GIT_COMMAND \"${GIT}\")
  273. set(CTEST_GIT_UPDATE_OPTIONS)
  274. set(CTEST_GIT_UPDATE_CUSTOM \${CTEST_GIT_COMMAND} pull origin master)
  275. ")
  276. # Run the dashboard script with CTest.
  277. run_dashboard_script(dash-binary-custom)