CheckSourceTreeTest.cmake.in 13 KB

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