CheckSourceTreeTest.cmake.in 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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("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 CVS checkout, just pass the test here and now.
  39. # (Do not let the test fail if it is run in a tree *exported* from CVS or
  40. # unpacked from a .zip file source installer...)
  41. #
  42. if(NOT EXISTS "${CMake_SOURCE_DIR}/CVS/Root")
  43. message("source tree is not a CVS checkout... test passes by early return...")
  44. return()
  45. endif()
  46. # Check with "cvs -q -n up -dP" if there are any local modifications to the
  47. # CMake source tree:
  48. #
  49. message("=============================================================================")
  50. message("Copy/paste this command to reproduce:")
  51. message("cd \"${CMake_SOURCE_DIR}\" && \"${CVS_EXECUTABLE}\" -q -n up -dP")
  52. message("")
  53. # Use the HOME value passed in to the script for calling cvs so it can find
  54. # its .cvspass and other file(s)
  55. #
  56. set(original_ENV_HOME "$ENV{HOME}")
  57. set(ENV{HOME} "${HOME}")
  58. execute_process(COMMAND ${CVS_EXECUTABLE} -q -n up -dP
  59. WORKING_DIRECTORY ${CMake_SOURCE_DIR}
  60. OUTPUT_VARIABLE ov
  61. ERROR_VARIABLE ev
  62. RESULT_VARIABLE rv)
  63. set(ENV{HOME} "${original_ENV_HOME}")
  64. message("Results of running '${CVS_EXECUTABLE} -q -n up -dP'")
  65. message("rv='${rv}'")
  66. message("ov='${ov}'")
  67. message("ev='${ev}'")
  68. message("")
  69. if(NOT rv STREQUAL 0)
  70. message(FATAL_ERROR "error: 'cvs -q -n up -dP' attempt failed... (see output above)")
  71. endif()
  72. # Analyze cvs output:
  73. #
  74. set(additions 0)
  75. set(conflicts 0)
  76. set(modifications 0)
  77. set(nonadditions 0)
  78. if(NOT ov STREQUAL "")
  79. string(REPLACE ";" "\\\\;" lines "${ov}")
  80. string(REPLACE "\n" "E;" lines "${lines}")
  81. foreach(line ${lines})
  82. message("'${line}'")
  83. # But do not consider files that exist just because some user poked around
  84. # the file system with Windows Explorer or with the Finder from a Mac...
  85. # ('Thumbs.db' and '.DS_Store' files...)
  86. #
  87. set(consider 1)
  88. set(ignore_files_regex "^(. |.*(/|\\\\))(\\.DS_Store|Thumbs.db)E$")
  89. if(line MATCHES "${ignore_files_regex}")
  90. message(" line matches '${ignore_files_regex}' -- not considered")
  91. set(consider 0)
  92. endif()
  93. if(consider)
  94. if(line MATCHES "^A ")
  95. message(" locally added file/directory detected...")
  96. set(additions 1)
  97. endif()
  98. if(line MATCHES "^C ")
  99. message(" conflict detected...")
  100. set(conflicts 1)
  101. endif()
  102. if(line MATCHES "^M ")
  103. message(" locally modified file detected...")
  104. set(modifications 1)
  105. endif()
  106. if(line MATCHES "^\\? ")
  107. message(" locally non-added file/directory detected...")
  108. set(nonadditions 1)
  109. endif()
  110. endif()
  111. endforeach()
  112. endif()
  113. message("=============================================================================")
  114. message("additions='${additions}'")
  115. message("conflicts='${conflicts}'")
  116. message("modifications='${modifications}'")
  117. message("nonadditions='${nonadditions}'")
  118. message("")
  119. # Decide if the test passes or fails:
  120. #
  121. message("=============================================================================")
  122. if("$ENV{DASHBOARD_TEST_FROM_CTEST}" STREQUAL "")
  123. # developers are allowed to have local additions and modifications...
  124. set(is_dashboard 0)
  125. message("interactive test run")
  126. message("")
  127. else()
  128. set(is_dashboard 1)
  129. message("dashboard test run")
  130. message("")
  131. # but dashboard machines are not allowed to have local additions or modifications...
  132. if(additions)
  133. message(FATAL_ERROR "test fails: local source tree additions")
  134. endif()
  135. if(modifications)
  136. message(FATAL_ERROR "test fails: local source tree modifications")
  137. endif()
  138. #
  139. # It's a dashboard run if ctest was run with '-D ExperimentalTest' or some
  140. # other -D arg on its command line or if ctest is running a -S script to run
  141. # a dashboard... Running ctest like that sets the DASHBOARD_TEST_FROM_CTEST
  142. # env var.
  143. #
  144. endif()
  145. # ...and nobody is allowed to have local non-additions or conflicts...
  146. # Not even developers.
  147. #
  148. if(nonadditions)
  149. if(in_source_build AND is_dashboard)
  150. message("
  151. warning: test results confounded because this is an 'in-source' build - cannot
  152. distinguish between non-added files that are in-source build products and
  153. non-added source files that somebody forgot to 'cvs add'... - this is only ok
  154. if this is intentionally an in-source dashboard build... Developers should
  155. use out-of-source builds to verify a clean source tree with this test...
  156. Allowing test to pass despite the warning message...
  157. ")
  158. else()
  159. message(FATAL_ERROR "test fails: local source tree non-additions: use cvs add before committing, or remove the files from the source tree")
  160. endif()
  161. endif()
  162. if(conflicts)
  163. message(FATAL_ERROR "test fails: local source tree conflicts: resolve before committing")
  164. endif()
  165. # Still here? Good then...
  166. #
  167. message("test passes")
  168. message("")