CheckSourceTreeTest.cmake.in 11 KB

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