PolicyCheckTest.cmake 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. # Check the CMake source tree for suspicious policy introdcutions...
  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("")
  10. # If this does not appear to be a git checkout, just pass the test here
  11. # and now. (Do not let the test fail if it is run in a tree *exported* from a
  12. # repository or unpacked from a .zip file source installer...)
  13. #
  14. set(is_git_checkout 0)
  15. if(EXISTS "${CMake_SOURCE_DIR}/.git")
  16. set(is_git_checkout 1)
  17. endif()
  18. message("is_git_checkout='${is_git_checkout}'")
  19. message("")
  20. if(NOT is_git_checkout)
  21. message("source tree is not a git checkout... test passes by early return...")
  22. return()
  23. endif()
  24. # If no GIT_EXECUTABLE, see if we can figure out which git was used
  25. # for the ctest_update step on this dashboard...
  26. #
  27. if(is_git_checkout AND NOT GIT_EXECUTABLE)
  28. set(ctest_ini_file "")
  29. set(exe "")
  30. # Use the old name:
  31. if(EXISTS "${CMake_BINARY_DIR}/DartConfiguration.tcl")
  32. set(ctest_ini_file "${CMake_BINARY_DIR}/DartConfiguration.tcl")
  33. endif()
  34. # But if it exists, prefer the new name:
  35. if(EXISTS "${CMake_BINARY_DIR}/CTestConfiguration.ini")
  36. set(ctest_ini_file "${CMake_BINARY_DIR}/CTestConfiguration.ini")
  37. endif()
  38. # If there is a ctest ini file, read the update command or git command
  39. # from it:
  40. #
  41. if(ctest_ini_file)
  42. file(STRINGS "${ctest_ini_file}" line REGEX "^GITCommand: (.*)$")
  43. string(REGEX REPLACE "^GITCommand: (.*)$" "\\1" line "${line}")
  44. if("${line}" MATCHES "^\"")
  45. string(REGEX REPLACE "^\"([^\"]+)\" *.*$" "\\1" line "${line}")
  46. else()
  47. string(REGEX REPLACE "^([^ ]+) *.*$" "\\1" line "${line}")
  48. endif()
  49. set(exe "${line}")
  50. if("${exe}" STREQUAL "GITCOMMAND-NOTFOUND")
  51. set(exe "")
  52. endif()
  53. if(exe)
  54. message("info: GIT_EXECUTABLE set by 'GITCommand:' from '${ctest_ini_file}'")
  55. endif()
  56. if(NOT exe)
  57. file(STRINGS "${ctest_ini_file}" line REGEX "^UpdateCommand: (.*)$")
  58. string(REGEX REPLACE "^UpdateCommand: (.*)$" "\\1" line "${line}")
  59. if("${line}" MATCHES "^\"")
  60. string(REGEX REPLACE "^\"([^\"]+)\" *.*$" "\\1" line "${line}")
  61. else()
  62. string(REGEX REPLACE "^([^ ]+) *.*$" "\\1" line "${line}")
  63. endif()
  64. set(exe "${line}")
  65. if("${exe}" STREQUAL "GITCOMMAND-NOTFOUND")
  66. set(exe "")
  67. endif()
  68. if(exe)
  69. message("info: GIT_EXECUTABLE set by 'UpdateCommand:' from '${ctest_ini_file}'")
  70. endif()
  71. endif()
  72. else()
  73. message("info: no DartConfiguration.tcl or CTestConfiguration.ini file...")
  74. endif()
  75. # If we have still not grokked the exe, look in the Update.xml file to see
  76. # if we can parse it from there...
  77. #
  78. if(NOT exe)
  79. file(GLOB_RECURSE update_xml_file "${CMake_BINARY_DIR}/Testing/Update.xml")
  80. if(update_xml_file)
  81. file(STRINGS "${update_xml_file}" line
  82. REGEX "^.*<UpdateCommand>(.*)</UpdateCommand>$" LIMIT_COUNT 1)
  83. string(REPLACE "&quot\;" "\"" line "${line}")
  84. string(REGEX REPLACE "^.*<UpdateCommand>(.*)</UpdateCommand>$" "\\1" line "${line}")
  85. if("${line}" MATCHES "^\"")
  86. string(REGEX REPLACE "^\"([^\"]+)\" *.*$" "\\1" line "${line}")
  87. else()
  88. string(REGEX REPLACE "^([^ ]+) *.*$" "\\1" line "${line}")
  89. endif()
  90. if(line)
  91. set(exe "${line}")
  92. endif()
  93. if(exe)
  94. message("info: GIT_EXECUTABLE set by '<UpdateCommand>' from '${update_xml_file}'")
  95. endif()
  96. else()
  97. message("info: no Update.xml file...")
  98. endif()
  99. endif()
  100. if(exe)
  101. set(GIT_EXECUTABLE "${exe}")
  102. message("GIT_EXECUTABLE='${GIT_EXECUTABLE}'")
  103. message("")
  104. if(NOT EXISTS "${GIT_EXECUTABLE}")
  105. message(FATAL_ERROR "GIT_EXECUTABLE does not exist...")
  106. endif()
  107. else()
  108. message(FATAL_ERROR "could not determine GIT_EXECUTABLE...")
  109. endif()
  110. endif()
  111. if(is_git_checkout AND GIT_EXECUTABLE)
  112. # Check with "git grep" if there are any unacceptable cmPolicies additions
  113. #
  114. message("=============================================================================")
  115. message("This is a git checkout, using git grep to verify no unacceptable policies")
  116. message("are being introduced....")
  117. message("")
  118. execute_process(COMMAND ${GIT_EXECUTABLE} grep -En "[0-9][0-9][0-9][0-9][0-9].*cmPolicies"
  119. WORKING_DIRECTORY ${CMake_SOURCE_DIR}
  120. OUTPUT_VARIABLE grep_output
  121. OUTPUT_STRIP_TRAILING_WHITESPACE)
  122. message("=== output of 'git grep -En \"[0-9][0-9][0-9][0-9][0-9].*cmPolicies\"' ===")
  123. message("${grep_output}")
  124. message("=== end output ===")
  125. message("")
  126. if(NOT "${grep_output}" STREQUAL "")
  127. message(FATAL_ERROR "git grep output is non-empty...
  128. New CMake policies must be introduced in a non-date-based version number.
  129. Send email to the cmake-developers list to figure out what the target
  130. version number for this policy should be...")
  131. endif()
  132. endif()
  133. # Still here? Good then...
  134. #
  135. message("test passes")
  136. message("")