CheckSourceTreeTest.cmake.in 11 KB

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