CheckSourceTreeTest.cmake.in 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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 no GIT_EXECUTABLE, see if we can figure out which git was used
  109. # for the ctest_update step on this dashboard...
  110. #
  111. if(is_git_checkout AND NOT GIT_EXECUTABLE)
  112. set(ctest_ini_file "")
  113. set(exe "")
  114. # Use the old name:
  115. if(EXISTS "${CMake_BINARY_DIR}/DartConfiguration.tcl")
  116. set(ctest_ini_file "${CMake_BINARY_DIR}/DartConfiguration.tcl")
  117. endif()
  118. # But if it exists, prefer the new name:
  119. if(EXISTS "${CMake_BINARY_DIR}/CTestConfiguration.ini")
  120. set(ctest_ini_file "${CMake_BINARY_DIR}/CTestConfiguration.ini")
  121. endif()
  122. # If there is a ctest ini file, read the update command or git command
  123. # from it:
  124. #
  125. if(ctest_ini_file)
  126. file(STRINGS "${ctest_ini_file}" lines REGEX "^GITCommand: (.*)$")
  127. string(REGEX REPLACE "^GITCommand: (.*)$" "\\1" exe "${lines}")
  128. if("${exe}" STREQUAL "GITCOMMAND-NOTFOUND")
  129. set(exe "")
  130. endif()
  131. if(NOT exe)
  132. file(STRINGS "${ctest_ini_file}" lines REGEX "^UpdateCommand: (.*)$")
  133. string(REGEX REPLACE "^UpdateCommand: (.*)$" "\\1" exe "${lines}")
  134. if("${exe}" STREQUAL "GITCOMMAND-NOTFOUND")
  135. set(exe "")
  136. endif()
  137. endif()
  138. endif()
  139. if(exe)
  140. set(GIT_EXECUTABLE "${exe}")
  141. message("info: set GIT_EXECUTABLE to '${GIT_EXECUTABLE}' based on '${ctest_ini_file}'")
  142. else()
  143. message(FATAL_ERROR "could not determine GIT_EXECUTABLE based on '${ctest_ini_file}'...")
  144. endif()
  145. endif()
  146. if(is_git_checkout AND GIT_EXECUTABLE)
  147. # Check with "git status" if there are any local modifications to the
  148. # CMake source tree:
  149. #
  150. message("=============================================================================")
  151. message("This is a git checkout, using git to verify source tree....")
  152. message("")
  153. execute_process(COMMAND ${GIT_EXECUTABLE} --version
  154. WORKING_DIRECTORY ${CMake_SOURCE_DIR}
  155. OUTPUT_VARIABLE version_output
  156. OUTPUT_STRIP_TRAILING_WHITESPACE)
  157. message("=== output of 'git --version' ===")
  158. message("${version_output}")
  159. message("=== end output ===")
  160. message("")
  161. execute_process(COMMAND ${GIT_EXECUTABLE} branch -a
  162. WORKING_DIRECTORY ${CMake_SOURCE_DIR}
  163. OUTPUT_VARIABLE git_branch_output
  164. OUTPUT_STRIP_TRAILING_WHITESPACE)
  165. message("=== output of 'git branch -a' ===")
  166. message("${git_branch_output}")
  167. message("=== end output ===")
  168. message("")
  169. execute_process(COMMAND ${GIT_EXECUTABLE} log -1
  170. WORKING_DIRECTORY ${CMake_SOURCE_DIR}
  171. OUTPUT_VARIABLE git_log_output
  172. OUTPUT_STRIP_TRAILING_WHITESPACE)
  173. message("=== output of 'git log -1' ===")
  174. message("${git_log_output}")
  175. message("=== end output ===")
  176. message("")
  177. message("Copy/paste this command to reproduce:")
  178. message("cd \"${CMake_SOURCE_DIR}\" && \"${GIT_EXECUTABLE}\" status")
  179. message("")
  180. set(cmd ${GIT_EXECUTABLE} status)
  181. endif()
  182. if(cmd)
  183. # Use the HOME value passed in to the script for calling cvs/git so it can
  184. # find its .cvspass or user/global config settings...
  185. #
  186. set(original_ENV_HOME "$ENV{HOME}")
  187. set(ENV{HOME} "${HOME}")
  188. execute_process(COMMAND ${cmd}
  189. WORKING_DIRECTORY ${CMake_SOURCE_DIR}
  190. OUTPUT_VARIABLE ov
  191. ERROR_VARIABLE ev
  192. RESULT_VARIABLE rv)
  193. set(ENV{HOME} "${original_ENV_HOME}")
  194. message("Results of running ${cmd}")
  195. message("rv='${rv}'")
  196. message("ov='${ov}'")
  197. message("ev='${ev}'")
  198. message("")
  199. if(NOT rv STREQUAL 0)
  200. if(is_git_checkout AND (rv STREQUAL "1"))
  201. # Many builds of git return "1" from a "nothing is changed" git status call...
  202. # Do not fail with an error for rv==1 with git...
  203. else()
  204. message(FATAL_ERROR "error: ${cmd} attempt failed... (see output above)")
  205. endif()
  206. endif()
  207. else()
  208. message(FATAL_ERROR "error: no COMMAND to run to analyze source tree...")
  209. endif()
  210. # Analyze output:
  211. #
  212. if(NOT ov STREQUAL "")
  213. string(REPLACE ";" "\\\\;" lines "${ov}")
  214. string(REPLACE "\n" "E;" lines "${lines}")
  215. foreach(line ${lines})
  216. message("'${line}'")
  217. # But do not consider files that exist just because some user poked around
  218. # the file system with Windows Explorer or with the Finder from a Mac...
  219. # ('Thumbs.db' and '.DS_Store' files...)
  220. #
  221. set(consider 1)
  222. set(ignore_files_regex "^(. |.*(/|\\\\))(\\.DS_Store|Thumbs.db)E$")
  223. if(line MATCHES "${ignore_files_regex}")
  224. message(" line matches '${ignore_files_regex}' -- not considered")
  225. set(consider 0)
  226. endif()
  227. if(consider)
  228. if(is_cvs_checkout)
  229. if(line MATCHES "^A ")
  230. message(" locally added file/directory detected...")
  231. set(additions 1)
  232. endif()
  233. if(line MATCHES "^C ")
  234. message(" conflict detected...")
  235. set(conflicts 1)
  236. endif()
  237. if(line MATCHES "^M ")
  238. message(" locally modified file detected...")
  239. set(modifications 1)
  240. endif()
  241. if(line MATCHES "^\\? ")
  242. message(" locally non-added file/directory detected...")
  243. set(nonadditions 1)
  244. endif()
  245. endif()
  246. if(is_git_checkout)
  247. if(line MATCHES "^#[ \t]*modified:")
  248. message(" locally modified file detected...")
  249. set(modifications 1)
  250. endif()
  251. if(line MATCHES "^# Untracked")
  252. message(" locally non-added file/directory detected...")
  253. set(nonadditions 1)
  254. endif()
  255. endif()
  256. endif()
  257. endforeach()
  258. endif()
  259. message("=============================================================================")
  260. message("additions='${additions}'")
  261. message("conflicts='${conflicts}'")
  262. message("modifications='${modifications}'")
  263. message("nonadditions='${nonadditions}'")
  264. message("")
  265. # Decide if the test passes or fails:
  266. #
  267. message("=============================================================================")
  268. if("$ENV{DASHBOARD_TEST_FROM_CTEST}" STREQUAL "")
  269. # developers are allowed to have local additions and modifications...
  270. set(is_dashboard 0)
  271. message("interactive test run")
  272. message("")
  273. else()
  274. set(is_dashboard 1)
  275. message("dashboard test run")
  276. message("")
  277. # but dashboard machines are not allowed to have local additions or modifications...
  278. if(additions)
  279. message(FATAL_ERROR "test fails: local source tree additions")
  280. endif()
  281. if(modifications)
  282. message(FATAL_ERROR "test fails: local source tree modifications")
  283. endif()
  284. #
  285. # It's a dashboard run if ctest was run with '-D ExperimentalTest' or some
  286. # other -D arg on its command line or if ctest is running a -S script to run
  287. # a dashboard... Running ctest like that sets the DASHBOARD_TEST_FROM_CTEST
  288. # env var.
  289. #
  290. endif()
  291. # ...and nobody is allowed to have local non-additions or conflicts...
  292. # Not even developers.
  293. #
  294. if(nonadditions)
  295. if(in_source_build AND is_dashboard)
  296. message("
  297. warning: test results confounded because this is an 'in-source' build - cannot
  298. distinguish between non-added files that are in-source build products and
  299. non-added source files that somebody forgot to 'git add'... - this is only ok
  300. if this is intentionally an in-source dashboard build... Developers should
  301. use out-of-source builds to verify a clean source tree with this test...
  302. Allowing test to pass despite the warning message...
  303. ")
  304. else()
  305. message(FATAL_ERROR "test fails: local source tree non-additions: use git add before committing, or remove the files from the source tree")
  306. endif()
  307. endif()
  308. if(conflicts)
  309. message(FATAL_ERROR "test fails: local source tree conflicts: resolve before committing")
  310. endif()
  311. # Still here? Good then...
  312. #
  313. message("test passes")
  314. message("")