CheckSourceTreeTest.cmake.in 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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. file(READ "${CMake_SOURCE_DIR}/CVS/Root" contents)
  86. message("=== content of CVS/Root ===")
  87. message("${contents}")
  88. message("=== end content ===")
  89. message("")
  90. file(READ "${CMake_SOURCE_DIR}/CVS/Repository" contents)
  91. message("=== content of CVS/Repository ===")
  92. message("${contents}")
  93. message("=== end content ===")
  94. message("")
  95. message("Copy/paste this command to reproduce:")
  96. message("cd \"${CMake_SOURCE_DIR}\" && \"${CVS_EXECUTABLE}\" -q -n up -dP")
  97. message("")
  98. set(cmd ${CVS_EXECUTABLE} -q -n up -dP)
  99. endif()
  100. if(is_git_checkout AND GIT_EXECUTABLE)
  101. # Check with "git status" if there are any local modifications to the
  102. # CMake source tree:
  103. #
  104. message("=============================================================================")
  105. message("This is a git checkout, using git to verify source tree....")
  106. message("")
  107. execute_process(COMMAND ${GIT_EXECUTABLE} branch -a
  108. WORKING_DIRECTORY ${CMake_SOURCE_DIR}
  109. OUTPUT_VARIABLE git_branch_output
  110. OUTPUT_STRIP_TRAILING_WHITESPACE)
  111. message("=== output of 'git branch -a' ===")
  112. message("${git_branch_output}")
  113. message("=== end output ===")
  114. message("")
  115. message("Copy/paste this command to reproduce:")
  116. message("cd \"${CMake_SOURCE_DIR}\" && \"${GIT_EXECUTABLE}\" status")
  117. message("")
  118. set(cmd ${GIT_EXECUTABLE} status)
  119. endif()
  120. if(cmd)
  121. # Use the HOME value passed in to the script for calling cvs/git so it can
  122. # find its .cvspass or user/global config settings...
  123. #
  124. set(original_ENV_HOME "$ENV{HOME}")
  125. set(ENV{HOME} "${HOME}")
  126. execute_process(COMMAND ${cmd}
  127. WORKING_DIRECTORY ${CMake_SOURCE_DIR}
  128. OUTPUT_VARIABLE ov
  129. ERROR_VARIABLE ev
  130. RESULT_VARIABLE rv)
  131. set(ENV{HOME} "${original_ENV_HOME}")
  132. if(NOT rv STREQUAL 0)
  133. message(FATAL_ERROR "error: ${cmd} attempt failed... (see output above)")
  134. endif()
  135. message("Results of running ${cmd}")
  136. message("rv='${rv}'")
  137. message("ov='${ov}'")
  138. message("ev='${ev}'")
  139. message("")
  140. else()
  141. message(FATAL_ERROR "error: no COMMAND to run to analyze source tree...")
  142. endif()
  143. # Analyze output:
  144. #
  145. if(NOT ov STREQUAL "")
  146. string(REPLACE ";" "\\\\;" lines "${ov}")
  147. string(REPLACE "\n" "E;" lines "${lines}")
  148. foreach(line ${lines})
  149. message("'${line}'")
  150. # But do not consider files that exist just because some user poked around
  151. # the file system with Windows Explorer or with the Finder from a Mac...
  152. # ('Thumbs.db' and '.DS_Store' files...)
  153. #
  154. set(consider 1)
  155. set(ignore_files_regex "^(. |.*(/|\\\\))(\\.DS_Store|Thumbs.db)E$")
  156. if(line MATCHES "${ignore_files_regex}")
  157. message(" line matches '${ignore_files_regex}' -- not considered")
  158. set(consider 0)
  159. endif()
  160. if(consider)
  161. if(is_cvs_checkout)
  162. if(line MATCHES "^A ")
  163. message(" locally added file/directory detected...")
  164. set(additions 1)
  165. endif()
  166. if(line MATCHES "^C ")
  167. message(" conflict detected...")
  168. set(conflicts 1)
  169. endif()
  170. if(line MATCHES "^M ")
  171. message(" locally modified file detected...")
  172. set(modifications 1)
  173. endif()
  174. if(line MATCHES "^\\? ")
  175. message(" locally non-added file/directory detected...")
  176. set(nonadditions 1)
  177. endif()
  178. endif()
  179. if(is_git_checkout)
  180. if(line MATCHES "^#[ \t]*modified:")
  181. message(" locally modified file detected...")
  182. set(modifications 1)
  183. endif()
  184. if(line MATCHES "^# Untracked")
  185. message(" locally non-added file/directory detected...")
  186. set(nonadditions 1)
  187. endif()
  188. endif()
  189. endif()
  190. endforeach()
  191. endif()
  192. message("=============================================================================")
  193. message("additions='${additions}'")
  194. message("conflicts='${conflicts}'")
  195. message("modifications='${modifications}'")
  196. message("nonadditions='${nonadditions}'")
  197. message("")
  198. # Decide if the test passes or fails:
  199. #
  200. message("=============================================================================")
  201. if("$ENV{DASHBOARD_TEST_FROM_CTEST}" STREQUAL "")
  202. # developers are allowed to have local additions and modifications...
  203. set(is_dashboard 0)
  204. message("interactive test run")
  205. message("")
  206. else()
  207. set(is_dashboard 1)
  208. message("dashboard test run")
  209. message("")
  210. # but dashboard machines are not allowed to have local additions or modifications...
  211. if(additions)
  212. message(FATAL_ERROR "test fails: local source tree additions")
  213. endif()
  214. if(modifications)
  215. message(FATAL_ERROR "test fails: local source tree modifications")
  216. endif()
  217. #
  218. # It's a dashboard run if ctest was run with '-D ExperimentalTest' or some
  219. # other -D arg on its command line or if ctest is running a -S script to run
  220. # a dashboard... Running ctest like that sets the DASHBOARD_TEST_FROM_CTEST
  221. # env var.
  222. #
  223. endif()
  224. # ...and nobody is allowed to have local non-additions or conflicts...
  225. # Not even developers.
  226. #
  227. if(nonadditions)
  228. if(in_source_build AND is_dashboard)
  229. message("
  230. warning: test results confounded because this is an 'in-source' build - cannot
  231. distinguish between non-added files that are in-source build products and
  232. non-added source files that somebody forgot to 'git add'... - this is only ok
  233. if this is intentionally an in-source dashboard build... Developers should
  234. use out-of-source builds to verify a clean source tree with this test...
  235. Allowing test to pass despite the warning message...
  236. ")
  237. else()
  238. message(FATAL_ERROR "test fails: local source tree non-additions: use git add before committing, or remove the files from the source tree")
  239. endif()
  240. endif()
  241. if(conflicts)
  242. message(FATAL_ERROR "test fails: local source tree conflicts: resolve before committing")
  243. endif()
  244. # Still here? Good then...
  245. #
  246. message("test passes")
  247. message("")