You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

155 lines
4.6 KiB

Simplify CMake per-source license notices Per-source copyright/license notice headers that spell out copyright holder names and years are hard to maintain and often out-of-date or plain wrong. Precise contributor information is already maintained automatically by the version control tool. Ultimately it is the receiver of a file who is responsible for determining its licensing status, and per-source notices are merely a convenience. Therefore it is simpler and more accurate for each source to have a generic notice of the license name and references to more detailed information on copyright holders and full license terms. Our `Copyright.txt` file now contains a list of Contributors whose names appeared source-level copyright notices. It also references version control history for more precise information. Therefore we no longer need to spell out the list of Contributors in each source file notice. Replace CMake per-source copyright/license notice headers with a short description of the license and links to `Copyright.txt` and online information available from "https://cmake.org/licensing". The online URL also handles cases of modules being copied out of our source into other projects, so we can drop our notices about replacing links with full license text. Run the `Utilities/Scripts/filter-notices.bash` script to perform the majority of the replacements mechanically. Manually fix up shebang lines and trailing newlines in a few files. Manually update the notices in a few files that the script does not handle.
9 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmMessageCommand.h"
  4. #include <cassert>
  5. #include "cmExecutionStatus.h"
  6. #include "cmMakefile.h"
  7. #include "cmMessageType.h"
  8. #include "cmMessenger.h"
  9. #include "cmRange.h"
  10. #include "cmStringAlgorithms.h"
  11. #include "cmSystemTools.h"
  12. #include "cmake.h"
  13. // cmLibraryCommand
  14. bool cmMessageCommand(std::vector<std::string> const& args,
  15. cmExecutionStatus& status)
  16. {
  17. if (args.empty()) {
  18. status.SetError("called with incorrect number of arguments");
  19. return false;
  20. }
  21. auto& mf = status.GetMakefile();
  22. auto i = args.cbegin();
  23. auto type = MessageType::MESSAGE;
  24. auto fatal = false;
  25. auto level = cmake::LogLevel::LOG_UNDEFINED;
  26. if (*i == "SEND_ERROR") {
  27. type = MessageType::FATAL_ERROR;
  28. level = cmake::LogLevel::LOG_ERROR;
  29. ++i;
  30. } else if (*i == "FATAL_ERROR") {
  31. fatal = true;
  32. type = MessageType::FATAL_ERROR;
  33. level = cmake::LogLevel::LOG_ERROR;
  34. ++i;
  35. } else if (*i == "WARNING") {
  36. type = MessageType::WARNING;
  37. level = cmake::LogLevel::LOG_WARNING;
  38. ++i;
  39. } else if (*i == "AUTHOR_WARNING") {
  40. if (mf.IsSet("CMAKE_SUPPRESS_DEVELOPER_ERRORS") &&
  41. !mf.IsOn("CMAKE_SUPPRESS_DEVELOPER_ERRORS")) {
  42. fatal = true;
  43. type = MessageType::AUTHOR_ERROR;
  44. level = cmake::LogLevel::LOG_ERROR;
  45. } else if (!mf.IsOn("CMAKE_SUPPRESS_DEVELOPER_WARNINGS")) {
  46. type = MessageType::AUTHOR_WARNING;
  47. level = cmake::LogLevel::LOG_WARNING;
  48. } else {
  49. return true;
  50. }
  51. ++i;
  52. } else if (*i == "STATUS") {
  53. level = cmake::LogLevel::LOG_STATUS;
  54. ++i;
  55. } else if (*i == "VERBOSE") {
  56. level = cmake::LogLevel::LOG_VERBOSE;
  57. ++i;
  58. } else if (*i == "DEBUG") {
  59. level = cmake::LogLevel::LOG_DEBUG;
  60. ++i;
  61. } else if (*i == "TRACE") {
  62. level = cmake::LogLevel::LOG_TRACE;
  63. ++i;
  64. } else if (*i == "DEPRECATION") {
  65. if (mf.IsOn("CMAKE_ERROR_DEPRECATED")) {
  66. fatal = true;
  67. type = MessageType::DEPRECATION_ERROR;
  68. level = cmake::LogLevel::LOG_ERROR;
  69. } else if (!mf.IsSet("CMAKE_WARN_DEPRECATED") ||
  70. mf.IsOn("CMAKE_WARN_DEPRECATED")) {
  71. type = MessageType::DEPRECATION_WARNING;
  72. level = cmake::LogLevel::LOG_WARNING;
  73. } else {
  74. return true;
  75. }
  76. ++i;
  77. } else if (*i == "NOTICE") {
  78. // `NOTICE` message type is going to be output to stderr
  79. level = cmake::LogLevel::LOG_NOTICE;
  80. ++i;
  81. } else {
  82. // Messages w/o any type are `NOTICE`s
  83. level = cmake::LogLevel::LOG_NOTICE;
  84. }
  85. assert("Message log level expected to be set" &&
  86. level != cmake::LogLevel::LOG_UNDEFINED);
  87. auto desiredLevel = mf.GetCMakeInstance()->GetLogLevel();
  88. assert("Expected a valid log level here" &&
  89. desiredLevel != cmake::LogLevel::LOG_UNDEFINED);
  90. // Command line option takes precedence over the cache variable
  91. if (!mf.GetCMakeInstance()->WasLogLevelSetViaCLI()) {
  92. const auto desiredLevelFromCache =
  93. cmake::StringToLogLevel(mf.GetSafeDefinition("CMAKE_MESSAGE_LOG_LEVEL"));
  94. if (desiredLevelFromCache != cmake::LogLevel::LOG_UNDEFINED) {
  95. desiredLevel = desiredLevelFromCache;
  96. }
  97. }
  98. if (desiredLevel < level) {
  99. // Suppress the message
  100. return true;
  101. }
  102. auto message = cmJoin(cmMakeRange(i, args.cend()), "");
  103. if (cmake::LogLevel::LOG_NOTICE <= level) {
  104. // Check if any indentation has requested:
  105. // `CMAKE_MESSAGE_INDENT` is a list of "padding" pieces
  106. // to be joined and prepended to the message lines.
  107. auto indent =
  108. cmJoin(cmExpandedList(mf.GetSafeDefinition("CMAKE_MESSAGE_INDENT")), "");
  109. // Make every line of the `message` indented
  110. // NOTE Can't reuse `cmDocumentationFormatter::PrintPreformatted`
  111. // here cuz it appends `\n` to the EOM ;-(
  112. cmSystemTools::ReplaceString(message, "\n", "\n" + indent);
  113. message = indent + message;
  114. }
  115. switch (level) {
  116. case cmake::LogLevel::LOG_ERROR:
  117. case cmake::LogLevel::LOG_WARNING:
  118. // we've overridden the message type, above, so display it directly
  119. mf.GetMessenger()->DisplayMessage(type, message, mf.GetBacktrace());
  120. break;
  121. case cmake::LogLevel::LOG_NOTICE:
  122. cmSystemTools::Message(message);
  123. break;
  124. case cmake::LogLevel::LOG_STATUS:
  125. case cmake::LogLevel::LOG_VERBOSE:
  126. case cmake::LogLevel::LOG_DEBUG:
  127. case cmake::LogLevel::LOG_TRACE:
  128. mf.DisplayStatus(message, -1);
  129. break;
  130. default:
  131. assert("Unexpected log level! Review the `cmMessageCommand.cxx`." &&
  132. false);
  133. break;
  134. }
  135. if (fatal) {
  136. cmSystemTools::SetFatalErrorOccured();
  137. }
  138. return true;
  139. }