CheckSourceTreeTest.cmake.in 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. # Check the CMake source tree and report anything suspicious...
  2. #
  3. message("=============================================================================")
  4. message("CTEST_FULL_OUTPUT (Avoid ctest truncation of output)")
  5. message("")
  6. message("CMake_BINARY_DIR='${CMake_BINARY_DIR}'")
  7. message("CMake_SOURCE_DIR='${CMake_SOURCE_DIR}'")
  8. message("CVS_EXECUTABLE='${CVS_EXECUTABLE}'")
  9. message("GIT_EXECUTABLE='${GIT_EXECUTABLE}'")
  10. message("HOME='${HOME}'")
  11. message("ENV{DASHBOARD_TEST_FROM_CTEST}='$ENV{DASHBOARD_TEST_FROM_CTEST}'")
  12. message("")
  13. string(REPLACE "\\" "\\\\" HOME "${HOME}")
  14. # Is the build directory the same as or underneath the source directory?
  15. # (i.e. - is it an "in source" build?)
  16. #
  17. set(in_source_build 0)
  18. if(CMake_SOURCE_DIR STREQUAL "${CMake_BINARY_DIR}")
  19. message("build dir *is* source dir")
  20. set(in_source_build 1)
  21. else()
  22. string(LENGTH "${CMake_SOURCE_DIR}" src_len)
  23. string(LENGTH "${CMake_BINARY_DIR}" bin_len)
  24. if(bin_len GREATER src_len)
  25. math(EXPR substr_len "${src_len}+1")
  26. string(SUBSTRING "${CMake_BINARY_DIR}" 0 ${substr_len} bin_dir)
  27. if(bin_dir STREQUAL "${CMake_SOURCE_DIR}/")
  28. message("build dir is under source dir")
  29. set(in_source_build 1)
  30. endif()
  31. endif()
  32. endif()
  33. message("src_len='${src_len}'")
  34. message("bin_len='${bin_len}'")
  35. message("substr_len='${substr_len}'")
  36. message("bin_dir='${bin_dir}'")
  37. message("in_source_build='${in_source_build}'")
  38. message("")
  39. # If this does not appear to be a git or CVS checkout, just pass the test here
  40. # and now. (Do not let the test fail if it is run in a tree *exported* from a
  41. # repository or unpacked from a .zip file source installer...)
  42. #
  43. set(is_git_checkout 0)
  44. if(EXISTS "${CMake_SOURCE_DIR}/.git")
  45. set(is_git_checkout 1)
  46. endif()
  47. set(is_cvs_checkout 0)
  48. if(EXISTS "${CMake_SOURCE_DIR}/CVS/Root")
  49. set(is_cvs_checkout 1)
  50. endif()
  51. message("is_git_checkout='${is_git_checkout}'")
  52. message("is_cvs_checkout='${is_cvs_checkout}'")
  53. message("")
  54. if(NOT is_cvs_checkout)
  55. if(NOT is_git_checkout)
  56. message("source tree is neither git nor CVS checkout... test passes by early return...")
  57. return()
  58. endif()
  59. endif()
  60. if(is_cvs_checkout)
  61. if(is_git_checkout)
  62. message("warning: source tree has both git *and* CVS file system bits???")
  63. # should this condition be a FATAL_ERROR test failure...?
  64. endif()
  65. endif()
  66. # This test looks for the following types of changes in the source tree:
  67. #
  68. set(additions 0)
  69. set(conflicts 0)
  70. set(modifications 0)
  71. set(nonadditions 0)
  72. # ov == output variable... conditionally filled in by either cvs or git below:
  73. #
  74. set(cmd "")
  75. set(ov "")
  76. set(ev "")
  77. set(rv "")
  78. if(is_cvs_checkout AND CVS_EXECUTABLE)
  79. # Check with "cvs -q -n up -dP" if there are any local modifications to the
  80. # CMake source tree:
  81. #
  82. message("=============================================================================")
  83. message("This is a cvs checkout, using cvs to verify source tree....")
  84. message("")
  85. execute_process(COMMAND ${CVS_EXECUTABLE} --version
  86. WORKING_DIRECTORY ${CMake_SOURCE_DIR}
  87. OUTPUT_VARIABLE version_output
  88. OUTPUT_STRIP_TRAILING_WHITESPACE)
  89. message("=== output of 'cvs --version' ===")
  90. message("${version_output}")
  91. message("=== end output ===")
  92. message("")
  93. file(READ "${CMake_SOURCE_DIR}/CVS/Root" contents)
  94. message("=== content of CVS/Root ===")
  95. message("${contents}")
  96. message("=== end content ===")
  97. message("")
  98. file(READ "${CMake_SOURCE_DIR}/CVS/Repository" contents)
  99. message("=== content of CVS/Repository ===")
  100. message("${contents}")
  101. message("=== end content ===")
  102. message("")
  103. message("Copy/paste this command to reproduce:")
  104. message("cd \"${CMake_SOURCE_DIR}\" && \"${CVS_EXECUTABLE}\" -q -n up -dP")
  105. message("")
  106. set(cmd ${CVS_EXECUTABLE} -q -n up -dP)
  107. endif()
  108. if(is_git_checkout AND GIT_EXECUTABLE)
  109. # Check with "git status" if there are any local modifications to the
  110. # CMake source tree:
  111. #
  112. message("=============================================================================")
  113. message("This is a git checkout, using git to verify source tree....")
  114. message("")
  115. execute_process(COMMAND ${GIT_EXECUTABLE} --version
  116. WORKING_DIRECTORY ${CMake_SOURCE_DIR}
  117. OUTPUT_VARIABLE version_output
  118. OUTPUT_STRIP_TRAILING_WHITESPACE)
  119. message("=== output of 'git --version' ===")
  120. message("${version_output}")
  121. message("=== end output ===")
  122. message("")
  123. execute_process(COMMAND ${GIT_EXECUTABLE} branch -a
  124. WORKING_DIRECTORY ${CMake_SOURCE_DIR}
  125. OUTPUT_VARIABLE git_branch_output
  126. OUTPUT_STRIP_TRAILING_WHITESPACE)
  127. message("=== output of 'git branch -a' ===")
  128. message("${git_branch_output}")
  129. message("=== end output ===")
  130. message("")
  131. message("Copy/paste this command to reproduce:")
  132. message("cd \"${CMake_SOURCE_DIR}\" && \"${GIT_EXECUTABLE}\" status")
  133. message("")
  134. set(cmd ${GIT_EXECUTABLE} status)
  135. endif()
  136. if(cmd)
  137. # Use the HOME value passed in to the script for calling cvs/git so it can
  138. # find its .cvspass or user/global config settings...
  139. #
  140. set(original_ENV_HOME "$ENV{HOME}")
  141. set(ENV{HOME} "${HOME}")
  142. execute_process(COMMAND ${cmd}
  143. WORKING_DIRECTORY ${CMake_SOURCE_DIR}
  144. OUTPUT_VARIABLE ov
  145. ERROR_VARIABLE ev
  146. RESULT_VARIABLE rv)
  147. set(ENV{HOME} "${original_ENV_HOME}")
  148. message("Results of running ${cmd}")
  149. message("rv='${rv}'")
  150. message("ov='${ov}'")
  151. message("ev='${ev}'")
  152. message("")
  153. if(NOT rv STREQUAL 0)
  154. if(is_git_checkout AND (rv STREQUAL "1"))
  155. # Many builds of git return "1" from a "nothing is changed" git status call...
  156. # Do not fail with an error for rv==1 with git...
  157. else()
  158. message(FATAL_ERROR "error: ${cmd} attempt failed... (see output above)")
  159. endif()
  160. endif()
  161. else()
  162. message(FATAL_ERROR "error: no COMMAND to run to analyze source tree...")
  163. endif()
  164. # Analyze output:
  165. #
  166. if(NOT ov STREQUAL "")
  167. string(REPLACE ";" "\\\\;" lines "${ov}")
  168. string(REPLACE "\n" "E;" lines "${lines}")
  169. foreach(line ${lines})
  170. message("'${line}'")
  171. # But do not consider files that exist just because some user poked around
  172. # the file system with Windows Explorer or with the Finder from a Mac...
  173. # ('Thumbs.db' and '.DS_Store' files...)
  174. #
  175. set(consider 1)
  176. set(ignore_files_regex "^(. |.*(/|\\\\))(\\.DS_Store|Thumbs.db)E$")
  177. if(line MATCHES "${ignore_files_regex}")
  178. message(" line matches '${ignore_files_regex}' -- not considered")
  179. set(consider 0)
  180. endif()
  181. if(consider)
  182. if(is_cvs_checkout)
  183. if(line MATCHES "^A ")
  184. message(" locally added file/directory detected...")
  185. set(additions 1)
  186. endif()
  187. if(line MATCHES "^C ")
  188. message(" conflict detected...")
  189. set(conflicts 1)
  190. endif()
  191. if(line MATCHES "^M ")
  192. message(" locally modified file detected...")
  193. set(modifications 1)
  194. endif()
  195. if(line MATCHES "^\\? ")
  196. message(" locally non-added file/directory detected...")
  197. set(nonadditions 1)
  198. endif()
  199. endif()
  200. if(is_git_checkout)
  201. if(line MATCHES "^#[ \t]*modified:")
  202. message(" locally modified file detected...")
  203. set(modifications 1)
  204. endif()
  205. if(line MATCHES "^# Untracked")
  206. message(" locally non-added file/directory detected...")
  207. set(nonadditions 1)
  208. endif()
  209. endif()
  210. endif()
  211. endforeach()
  212. endif()
  213. message("=============================================================================")
  214. message("additions='${additions}'")
  215. message("conflicts='${conflicts}'")
  216. message("modifications='${modifications}'")
  217. message("nonadditions='${nonadditions}'")
  218. message("")
  219. # Decide if the test passes or fails:
  220. #
  221. message("=============================================================================")
  222. if("$ENV{DASHBOARD_TEST_FROM_CTEST}" STREQUAL "")
  223. # developers are allowed to have local additions and modifications...
  224. set(is_dashboard 0)
  225. message("interactive test run")
  226. message("")
  227. else()
  228. set(is_dashboard 1)
  229. message("dashboard test run")
  230. message("")
  231. # but dashboard machines are not allowed to have local additions or modifications...
  232. if(additions)
  233. message(FATAL_ERROR "test fails: local source tree additions")
  234. endif()
  235. if(modifications)
  236. message(FATAL_ERROR "test fails: local source tree modifications")
  237. endif()
  238. #
  239. # It's a dashboard run if ctest was run with '-D ExperimentalTest' or some
  240. # other -D arg on its command line or if ctest is running a -S script to run
  241. # a dashboard... Running ctest like that sets the DASHBOARD_TEST_FROM_CTEST
  242. # env var.
  243. #
  244. endif()
  245. # ...and nobody is allowed to have local non-additions or conflicts...
  246. # Not even developers.
  247. #
  248. if(nonadditions)
  249. if(in_source_build AND is_dashboard)
  250. message("
  251. warning: test results confounded because this is an 'in-source' build - cannot
  252. distinguish between non-added files that are in-source build products and
  253. non-added source files that somebody forgot to 'git add'... - this is only ok
  254. if this is intentionally an in-source dashboard build... Developers should
  255. use out-of-source builds to verify a clean source tree with this test...
  256. Allowing test to pass despite the warning message...
  257. ")
  258. else()
  259. message(FATAL_ERROR "test fails: local source tree non-additions: use git add before committing, or remove the files from the source tree")
  260. endif()
  261. endif()
  262. if(conflicts)
  263. message(FATAL_ERROR "test fails: local source tree conflicts: resolve before committing")
  264. endif()
  265. # Still here? Good then...
  266. #
  267. message("test passes")
  268. message("")