CTestUpdateP4.cmake.in 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. # This script drives creation of a perforce 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(P4_TOP "${TOP}")
  7. string(APPEND TOP "/@CTestUpdateP4_DIR@")
  8. # Include code common to all update tests.
  9. set(REPOSITORY_FILE_PREFIX "//ctest/")
  10. include("@CMAKE_CURRENT_SOURCE_DIR@/CTestUpdateCommon.cmake")
  11. #-----------------------------------------------------------------------------
  12. # Perforce server options
  13. set(P4_HOST localhost)
  14. set(P4_PORT 1888)
  15. #-----------------------------------------------------------------------------
  16. # Report p4 tools in use and set its defaults
  17. message("Using P4 tools:")
  18. set(P4 "@P4_EXECUTABLE@")
  19. set(P4D "@P4D_EXECUTABLE@")
  20. message(" p4 = ${P4}")
  21. message(" p4d = ${P4D}")
  22. set(P4_CLIENT -c ctest_p4)
  23. set(P4_OPTIONS -H ${P4_HOST} -p ${P4_PORT})
  24. set(P4CMD ${P4} ${P4_OPTIONS})
  25. #-----------------------------------------------------------------------------
  26. # Start the Perforce server
  27. if(UNIX)
  28. set(P4_ROOT ${P4_TOP}/perforce)
  29. message("Starting p4d on '${P4_ROOT}' listening on port ${P4_PORT}...")
  30. # Stop a previous instance of Perforce running
  31. execute_process(
  32. WORKING_DIRECTORY ${TOP}
  33. COMMAND ${P4CMD} admin stop
  34. OUTPUT_QUIET
  35. ERROR_QUIET
  36. )
  37. # Make sure we don't have a perforce directory from a previous run
  38. file(REMOVE_RECURSE ${P4_ROOT})
  39. file(MAKE_DIRECTORY ${P4_ROOT})
  40. set(P4_SERVER "nohup '${P4D}' -d -r '${P4_ROOT}'")
  41. string(APPEND P4_SERVER " -L '${P4_ROOT}/p4.log'")
  42. string(APPEND P4_SERVER " -J '${P4_ROOT}/journal'")
  43. string(APPEND P4_SERVER " -p ${P4_PORT} >/dev/null 2>&1 &")
  44. message("Server command line: ${P4_SERVER}")
  45. execute_process(
  46. COMMAND sh -c "
  47. ${P4_SERVER}
  48. for i in 1 2 3 4 5 6 7 8 9 10; do
  49. echo 'Waiting for server to start...'
  50. sleep 1
  51. if '${P4}' -H ${P4_HOST} -p ${P4_PORT} help >/dev/null 2>&1; then
  52. echo 'Server started.'
  53. exit
  54. fi
  55. done
  56. echo 'Gave up waiting for server to start.'
  57. "
  58. )
  59. endif()
  60. #-----------------------------------------------------------------------------
  61. # Initialize the testing directory.
  62. message("Creating test directory...")
  63. init_testing()
  64. #-----------------------------------------------------------------------------
  65. # Create the repository.
  66. message("Creating depot...")
  67. file(WRITE ${TOP}/depot.spec "Depot: ctest\n")
  68. file(APPEND ${TOP}/depot.spec "Type: local\n")
  69. file(APPEND ${TOP}/depot.spec "Map: ctest/...\n")
  70. run_child(
  71. WORKING_DIRECTORY ${TOP}
  72. COMMAND ${P4CMD} depot -i
  73. INPUT_FILE ${TOP}/depot.spec
  74. )
  75. #-----------------------------------------------------------------------------
  76. # Import initial content into the repository.
  77. message("Importing content...")
  78. create_content(user-source)
  79. message("Creating client spec...")
  80. file(WRITE ${TOP}/client.spec "Client: ctest_p4\n")
  81. file(APPEND ${TOP}/client.spec "Root: ${TOP}/user-source\n")
  82. file(APPEND ${TOP}/client.spec "View: //ctest/... //ctest_p4/...\n")
  83. run_child(
  84. WORKING_DIRECTORY ${TOP}/user-source
  85. COMMAND ${P4CMD} client -i
  86. INPUT_FILE ${TOP}/client.spec
  87. )
  88. # After creating the depot and the client view, all P4 commands need to
  89. # have the client spec passed to them
  90. list(APPEND P4CMD ${P4_CLIENT})
  91. message("Adding files to repository")
  92. file(GLOB_RECURSE files ${TOP}/user-source/*)
  93. foreach(filename ${files})
  94. run_child(
  95. WORKING_DIRECTORY ${TOP}/user-source
  96. COMMAND ${P4CMD} add ${filename}
  97. )
  98. endforeach()
  99. message("Submitting changes to repository")
  100. run_child(
  101. WORKING_DIRECTORY ${TOP}/user-source
  102. COMMAND ${P4CMD} submit -d "CTEST: Initial content"
  103. )
  104. message("Tagging the repository")
  105. file(WRITE ${TOP}/label.spec "Label: r1\n")
  106. file(APPEND ${TOP}/label.spec "View: //ctest/...\n")
  107. run_child(
  108. WORKING_DIRECTORY ${TOP}/user-source
  109. COMMAND ${P4CMD} label -i
  110. INPUT_FILE ${TOP}/label.spec
  111. )
  112. run_child(
  113. WORKING_DIRECTORY ${TOP}/user-source
  114. COMMAND ${P4CMD} labelsync -l r1
  115. )
  116. #-----------------------------------------------------------------------------
  117. # Make changes in the working tree.
  118. message("Changing content...")
  119. update_content(user-source files_added files_removed dirs_added)
  120. foreach(filename ${files_added})
  121. message("add: ${filename}")
  122. run_child(
  123. WORKING_DIRECTORY ${TOP}/user-source
  124. COMMAND ${P4CMD} add ${TOP}/user-source/${filename}
  125. )
  126. endforeach()
  127. foreach(filename ${files_removed})
  128. run_child(
  129. WORKING_DIRECTORY ${TOP}/user-source
  130. COMMAND ${P4CMD} delete ${TOP}/user-source/${filename}
  131. )
  132. endforeach()
  133. #-----------------------------------------------------------------------------
  134. # Commit the changes to the repository.
  135. message("Committing revision 2...")
  136. run_child(
  137. WORKING_DIRECTORY ${TOP}/user-source
  138. COMMAND ${P4CMD} submit -d "CTEST: Changed content"
  139. )
  140. #-----------------------------------------------------------------------------
  141. # Make changes in the working tree.
  142. message("Changing content again...")
  143. run_child(
  144. WORKING_DIRECTORY ${TOP}/user-source
  145. COMMAND ${P4CMD} edit //ctest/...
  146. )
  147. change_content(user-source)
  148. run_child(
  149. WORKING_DIRECTORY ${TOP}/user-source
  150. COMMAND ${P4CMD} revert -a //ctest/...
  151. )
  152. #-----------------------------------------------------------------------------
  153. # Commit the changes to the repository.
  154. message("Committing revision 3...")
  155. run_child(
  156. WORKING_DIRECTORY ${TOP}/user-source
  157. COMMAND ${P4CMD} submit -d "CTEST: Changed content again"
  158. )
  159. #-----------------------------------------------------------------------------
  160. # Go back to before the changes so we can test updating.
  161. message("Backing up to revision 1...")
  162. run_child(
  163. WORKING_DIRECTORY ${TOP}/user-source
  164. COMMAND ${P4CMD} sync @r1
  165. )
  166. # Create a modified file.
  167. run_child(
  168. WORKING_DIRECTORY ${TOP}/user-source
  169. COMMAND ${P4CMD} sync @r1
  170. )
  171. # We should p4 open any files that modify_content creates
  172. run_child(
  173. WORKING_DIRECTORY ${TOP}/user-source
  174. COMMAND ${P4CMD} open ${TOP}/user-source/CTestConfig.cmake
  175. )
  176. modify_content(user-source)
  177. #-----------------------------------------------------------------------------
  178. # Test updating the user work directory with the command-line interface.
  179. message("Running CTest Dashboard Command Line...")
  180. # Create the user build tree.
  181. create_build_tree(user-source user-binary)
  182. file(APPEND ${TOP}/user-binary/CTestConfiguration.ini
  183. "# P4 command configuration
  184. UpdateCommand: ${P4}
  185. P4Client: ctest_p4
  186. P4Options: -H ${P4_HOST} -p ${P4_PORT}
  187. ")
  188. # Run the dashboard command line interface.
  189. run_dashboard_command_line(user-binary)
  190. # Revert the modified files
  191. run_child(
  192. WORKING_DIRECTORY ${TOP}/user-source
  193. COMMAND ${P4CMD} revert ${TOP}/user-source/CTestConfig.cmake
  194. )
  195. #-----------------------------------------------------------------------------
  196. # Test initial checkout and update with a dashboard script.
  197. # Create a new client so we can check out files on a different directory
  198. message("Running CTest Dashboard Script...")
  199. message("Creating client spec...")
  200. file(WRITE ${TOP}/client2.spec "Client: ctest2_p4\n")
  201. file(APPEND ${TOP}/client2.spec "Root: ${TOP}/dash-source\n")
  202. file(APPEND ${TOP}/client2.spec "View: //ctest/... //ctest2_p4/...\n")
  203. run_child(
  204. COMMAND ${P4CMD} client -i
  205. INPUT_FILE ${TOP}/client2.spec
  206. )
  207. file(MAKE_DIRECTORY ${TOP}/dash-source)
  208. create_dashboard_script(dash-binary
  209. "# P4 command configuration
  210. set(CTEST_P4_CLIENT \"ctest2_p4\")
  211. set(CTEST_P4_OPTIONS \"-H ${P4_HOST} -p ${P4_PORT}\")
  212. set(CTEST_UPDATE_COMMAND \"${P4}\")
  213. ")
  214. # Run the dashboard script with CTest.
  215. run_dashboard_script(dash-binary)
  216. #-----------------------------------------------------------------------------
  217. # Clean up
  218. message("Shutting down p4d")
  219. run_child(
  220. WORKING_DIRECTORY ${TOP}
  221. COMMAND ${P4CMD} admin stop
  222. )