CheckSourceTreeTest.cmake.in 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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("ENV{DASHBOARD_TEST_FROM_CTEST}='$ENV{DASHBOARD_TEST_FROM_CTEST}'")
  10. message("")
  11. # Is the build directory the same as or underneath the source directory?
  12. # (i.e. - is it an "in source" build?)
  13. #
  14. set(in_source_build 0)
  15. if(CMake_SOURCE_DIR STREQUAL "${CMake_BINARY_DIR}")
  16. message("build dir *is* source dir")
  17. set(in_source_build 1)
  18. else()
  19. string(LENGTH "${CMake_SOURCE_DIR}" src_len)
  20. string(LENGTH "${CMake_BINARY_DIR}" bin_len)
  21. if(bin_len GREATER src_len)
  22. math(EXPR substr_len "${src_len}+1")
  23. string(SUBSTRING "${CMake_BINARY_DIR}" 0 ${substr_len} bin_dir)
  24. if(bin_dir STREQUAL "${CMake_SOURCE_DIR}/")
  25. message("build dir is under source dir")
  26. set(in_source_build 1)
  27. endif()
  28. endif()
  29. endif()
  30. message("src_len='${src_len}'")
  31. message("bin_len='${bin_len}'")
  32. message("substr_len='${substr_len}'")
  33. message("bin_dir='${bin_dir}'")
  34. message("in_source_build='${in_source_build}'")
  35. message("")
  36. # Check with "cvs -q -n up -dP" if there are any local modifications to the
  37. # CMake source tree:
  38. #
  39. message("=============================================================================")
  40. message("Copy/paste this command to reproduce:")
  41. message("cd \"${CMake_SOURCE_DIR}\" && \"${CVS_EXECUTABLE}\" -q -n up -dP")
  42. message("")
  43. execute_process(COMMAND ${CVS_EXECUTABLE} -q -n up -dP
  44. WORKING_DIRECTORY ${CMake_SOURCE_DIR}
  45. OUTPUT_VARIABLE ov
  46. ERROR_VARIABLE ev
  47. RESULT_VARIABLE rv)
  48. message("Results of running '${CVS_EXECUTABLE} -q -n up -dP'")
  49. message("rv='${rv}'")
  50. message("ov='${ov}'")
  51. message("ev='${ev}'")
  52. message("")
  53. # Analyze cvs output:
  54. #
  55. set(additions 0)
  56. set(conflicts 0)
  57. set(modifications 0)
  58. set(nonadditions 0)
  59. if(NOT ov STREQUAL "")
  60. string(REPLACE ";" "\\\\;" lines "${ov}")
  61. string(REPLACE "\n" "E;" lines "${lines}")
  62. foreach(line ${lines})
  63. message("'${line}'")
  64. # But do not consider files that exist just because some user poked around
  65. # the file system with Windows Explorer or with the Finder from a Mac...
  66. # ('Thumbs.db' and '.DS_Store' files...)
  67. #
  68. set(consider 1)
  69. set(ignore_files_regex "^(. |.*(/|\\\\))(\\.DS_Store|Thumbs.db)E$")
  70. if(line MATCHES "${ignore_files_regex}")
  71. message(" line matches '${ignore_files_regex}' -- not considered")
  72. set(consider 0)
  73. endif()
  74. if(consider)
  75. if(line MATCHES "^A ")
  76. message(" locally added file/directory detected...")
  77. set(additions 1)
  78. endif()
  79. if(line MATCHES "^C ")
  80. message(" conflict detected...")
  81. set(conflicts 1)
  82. endif()
  83. if(line MATCHES "^M ")
  84. message(" locally modified file detected...")
  85. set(modifications 1)
  86. endif()
  87. if(line MATCHES "^\\? ")
  88. message(" locally non-added file/directory detected...")
  89. set(nonadditions 1)
  90. endif()
  91. endif()
  92. endforeach()
  93. endif()
  94. message("=============================================================================")
  95. message("additions='${additions}'")
  96. message("conflicts='${conflicts}'")
  97. message("modifications='${modifications}'")
  98. message("nonadditions='${nonadditions}'")
  99. message("")
  100. # Decide if the test passes or fails:
  101. #
  102. message("=============================================================================")
  103. if("$ENV{DASHBOARD_TEST_FROM_CTEST}" STREQUAL "")
  104. # developers are allowed to have local additions and modifications...
  105. set(is_dashboard 0)
  106. message("interactive test run")
  107. message("")
  108. else()
  109. set(is_dashboard 1)
  110. message("dashboard test run")
  111. message("")
  112. # but dashboard machines are not allowed to have local additions or modifications...
  113. if(additions)
  114. message(FATAL_ERROR "test fails: local source tree additions")
  115. endif()
  116. if(modifications)
  117. message(FATAL_ERROR "test fails: local source tree modifications")
  118. endif()
  119. #
  120. # It's a dashboard run if ctest was run with '-D ExperimentalTest' or some
  121. # other -D arg on its command line or if ctest is running a -S script to run
  122. # a dashboard... Running ctest like that sets the DASHBOARD_TEST_FROM_CTEST
  123. # env var.
  124. #
  125. endif()
  126. # ...and nobody is allowed to have local non-additions or conflicts...
  127. # Not even developers.
  128. #
  129. if(nonadditions)
  130. if(in_source_build AND is_dashboard)
  131. message("
  132. warning: test results confounded because this is an 'in-source' build - cannot
  133. distinguish between non-added files that are in-source build products and
  134. non-added source files that somebody forgot to 'cvs add'... - this is only ok
  135. if this is intentionally an in-source dashboard build... Developers should
  136. use out-of-source builds to verify a clean source tree with this test...
  137. Allowing test to pass despite the warning message...
  138. ")
  139. else()
  140. message(FATAL_ERROR "test fails: local source tree non-additions: use cvs add before committing, or remove the files from the source tree")
  141. endif()
  142. endif()
  143. if(conflicts)
  144. message(FATAL_ERROR "test fails: local source tree conflicts: resolve before committing")
  145. endif()
  146. # Still here? Good then...
  147. #
  148. message("test passes")
  149. message("")