mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-14 02:08:27 +08:00
Merge topic 'message-color'
0a0a0f8a74
cmMessenger: Color messages to terminal by typebceb8e2ed2
cmMessenger: Pass title inside a metadata structure Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !6105
This commit is contained in:
4
Help/release/dev/message-color.rst
Normal file
4
Help/release/dev/message-color.rst
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
message-color
|
||||||
|
-------------
|
||||||
|
|
||||||
|
* Messages printed to a terminal now may be colored by message type.
|
@@ -638,6 +638,7 @@ set(SRCS
|
|||||||
cmMathCommand.h
|
cmMathCommand.h
|
||||||
cmMessageCommand.cxx
|
cmMessageCommand.cxx
|
||||||
cmMessageCommand.h
|
cmMessageCommand.h
|
||||||
|
cmMessageMetadata.h
|
||||||
cmOptionCommand.cxx
|
cmOptionCommand.cxx
|
||||||
cmOptionCommand.h
|
cmOptionCommand.h
|
||||||
cmOutputRequiredFilesCommand.cxx
|
cmOutputRequiredFilesCommand.cxx
|
||||||
|
@@ -19,6 +19,8 @@
|
|||||||
#include "cmWorkingDirectory.h"
|
#include "cmWorkingDirectory.h"
|
||||||
#include "cmake.h"
|
#include "cmake.h"
|
||||||
|
|
||||||
|
struct cmMessageMetadata;
|
||||||
|
|
||||||
cmCTestBuildAndTestHandler::cmCTestBuildAndTestHandler()
|
cmCTestBuildAndTestHandler::cmCTestBuildAndTestHandler()
|
||||||
{
|
{
|
||||||
this->BuildTwoConfig = false;
|
this->BuildTwoConfig = false;
|
||||||
@@ -125,7 +127,7 @@ public:
|
|||||||
: CM(cm)
|
: CM(cm)
|
||||||
{
|
{
|
||||||
cmSystemTools::SetMessageCallback(
|
cmSystemTools::SetMessageCallback(
|
||||||
[&s](const std::string& msg, const char* /*unused*/) {
|
[&s](const std::string& msg, const cmMessageMetadata& /* unused */) {
|
||||||
s += msg;
|
s += msg;
|
||||||
s += "\n";
|
s += "\n";
|
||||||
});
|
});
|
||||||
|
@@ -19,6 +19,7 @@
|
|||||||
#include "cmCursesStandardIncludes.h"
|
#include "cmCursesStandardIncludes.h"
|
||||||
#include "cmDocumentation.h"
|
#include "cmDocumentation.h"
|
||||||
#include "cmDocumentationEntry.h" // IWYU pragma: keep
|
#include "cmDocumentationEntry.h" // IWYU pragma: keep
|
||||||
|
#include "cmMessageMetadata.h"
|
||||||
#include "cmState.h"
|
#include "cmState.h"
|
||||||
#include "cmStringAlgorithms.h"
|
#include "cmStringAlgorithms.h"
|
||||||
#include "cmSystemTools.h"
|
#include "cmSystemTools.h"
|
||||||
@@ -181,8 +182,8 @@ int main(int argc, char const* const* argv)
|
|||||||
return msg;
|
return msg;
|
||||||
};
|
};
|
||||||
cmSystemTools::SetMessageCallback(
|
cmSystemTools::SetMessageCallback(
|
||||||
[&](const std::string& message, const char* title) {
|
[&](const std::string& message, const cmMessageMetadata& md) {
|
||||||
myform->AddError(cleanMessage(message), title);
|
myform->AddError(cleanMessage(message), md.title);
|
||||||
});
|
});
|
||||||
cmSystemTools::SetStderrCallback([&](const std::string& message) {
|
cmSystemTools::SetStderrCallback([&](const std::string& message) {
|
||||||
myform->AddError(cleanMessage(message), "");
|
myform->AddError(cleanMessage(message), "");
|
||||||
|
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
#include "cmExternalMakefileProjectGenerator.h"
|
#include "cmExternalMakefileProjectGenerator.h"
|
||||||
#include "cmGlobalGenerator.h"
|
#include "cmGlobalGenerator.h"
|
||||||
|
#include "cmMessageMetadata.h"
|
||||||
#include "cmState.h"
|
#include "cmState.h"
|
||||||
#include "cmStringAlgorithms.h"
|
#include "cmStringAlgorithms.h"
|
||||||
#include "cmSystemTools.h"
|
#include "cmSystemTools.h"
|
||||||
@@ -37,8 +38,8 @@ QCMake::QCMake(QObject* p)
|
|||||||
cmSystemTools::SetRunCommandHideConsole(true);
|
cmSystemTools::SetRunCommandHideConsole(true);
|
||||||
|
|
||||||
cmSystemTools::SetMessageCallback(
|
cmSystemTools::SetMessageCallback(
|
||||||
[this](std::string const& msg, const char* title) {
|
[this](std::string const& msg, const cmMessageMetadata& md) {
|
||||||
this->messageCallback(msg, title);
|
this->messageCallback(msg, md.title);
|
||||||
});
|
});
|
||||||
cmSystemTools::SetStdoutCallback(
|
cmSystemTools::SetStdoutCallback(
|
||||||
[this](std::string const& msg) { this->stdoutCallback(msg); });
|
[this](std::string const& msg) { this->stdoutCallback(msg); });
|
||||||
|
11
Source/cmMessageMetadata.h
Normal file
11
Source/cmMessageMetadata.h
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||||
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "cmsys/Terminal.h"
|
||||||
|
|
||||||
|
struct cmMessageMetadata
|
||||||
|
{
|
||||||
|
const char* title = nullptr;
|
||||||
|
int desiredColor = cmsysTerminal_Color_Normal;
|
||||||
|
};
|
@@ -3,6 +3,7 @@
|
|||||||
#include "cmMessenger.h"
|
#include "cmMessenger.h"
|
||||||
|
|
||||||
#include "cmDocumentationFormatter.h"
|
#include "cmDocumentationFormatter.h"
|
||||||
|
#include "cmMessageMetadata.h"
|
||||||
#include "cmStringAlgorithms.h"
|
#include "cmStringAlgorithms.h"
|
||||||
#include "cmSystemTools.h"
|
#include "cmSystemTools.h"
|
||||||
|
|
||||||
@@ -12,6 +13,8 @@
|
|||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
#include "cmsys/Terminal.h"
|
||||||
|
|
||||||
MessageType cmMessenger::ConvertMessageType(MessageType t) const
|
MessageType cmMessenger::ConvertMessageType(MessageType t) const
|
||||||
{
|
{
|
||||||
bool warningsAsErrors;
|
bool warningsAsErrors;
|
||||||
@@ -84,6 +87,21 @@ static bool printMessagePreamble(MessageType t, std::ostream& msg)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int getMessageColor(MessageType t)
|
||||||
|
{
|
||||||
|
switch (t) {
|
||||||
|
case MessageType::INTERNAL_ERROR:
|
||||||
|
case MessageType::FATAL_ERROR:
|
||||||
|
case MessageType::AUTHOR_ERROR:
|
||||||
|
return cmsysTerminal_Color_ForegroundRed;
|
||||||
|
case MessageType::AUTHOR_WARNING:
|
||||||
|
case MessageType::WARNING:
|
||||||
|
return cmsysTerminal_Color_ForegroundYellow;
|
||||||
|
default:
|
||||||
|
return cmsysTerminal_Color_Normal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void printMessageText(std::ostream& msg, std::string const& text)
|
void printMessageText(std::ostream& msg, std::string const& text)
|
||||||
{
|
{
|
||||||
msg << ":\n";
|
msg << ":\n";
|
||||||
@@ -120,12 +138,16 @@ void displayMessage(MessageType t, std::ostringstream& msg)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Output the message.
|
// Output the message.
|
||||||
|
cmMessageMetadata md;
|
||||||
|
md.desiredColor = getMessageColor(t);
|
||||||
if (t == MessageType::FATAL_ERROR || t == MessageType::INTERNAL_ERROR ||
|
if (t == MessageType::FATAL_ERROR || t == MessageType::INTERNAL_ERROR ||
|
||||||
t == MessageType::DEPRECATION_ERROR || t == MessageType::AUTHOR_ERROR) {
|
t == MessageType::DEPRECATION_ERROR || t == MessageType::AUTHOR_ERROR) {
|
||||||
cmSystemTools::SetErrorOccured();
|
cmSystemTools::SetErrorOccured();
|
||||||
cmSystemTools::Message(msg.str(), "Error");
|
md.title = "Error";
|
||||||
|
cmSystemTools::Message(msg.str(), md);
|
||||||
} else {
|
} else {
|
||||||
cmSystemTools::Message(msg.str(), "Warning");
|
md.title = "Warning";
|
||||||
|
cmSystemTools::Message(msg.str(), md);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -19,6 +19,7 @@
|
|||||||
#include <cm3p/uv.h>
|
#include <cm3p/uv.h>
|
||||||
|
|
||||||
#include "cmDuration.h"
|
#include "cmDuration.h"
|
||||||
|
#include "cmMessageMetadata.h"
|
||||||
#include "cmProcessOutput.h"
|
#include "cmProcessOutput.h"
|
||||||
#include "cmRange.h"
|
#include "cmRange.h"
|
||||||
#include "cmStringAlgorithms.h"
|
#include "cmStringAlgorithms.h"
|
||||||
@@ -262,9 +263,16 @@ void cmSystemTools::Stdout(const std::string& s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void cmSystemTools::Message(const std::string& m, const char* title)
|
void cmSystemTools::Message(const std::string& m, const char* title)
|
||||||
|
{
|
||||||
|
cmMessageMetadata md;
|
||||||
|
md.title = title;
|
||||||
|
Message(m, md);
|
||||||
|
}
|
||||||
|
|
||||||
|
void cmSystemTools::Message(const std::string& m, const cmMessageMetadata& md)
|
||||||
{
|
{
|
||||||
if (s_MessageCallback) {
|
if (s_MessageCallback) {
|
||||||
s_MessageCallback(m, title);
|
s_MessageCallback(m, md);
|
||||||
} else {
|
} else {
|
||||||
std::cerr << m << std::endl;
|
std::cerr << m << std::endl;
|
||||||
}
|
}
|
||||||
|
@@ -19,6 +19,8 @@
|
|||||||
#include "cmDuration.h"
|
#include "cmDuration.h"
|
||||||
#include "cmProcessOutput.h"
|
#include "cmProcessOutput.h"
|
||||||
|
|
||||||
|
struct cmMessageMetadata;
|
||||||
|
|
||||||
/** \class cmSystemTools
|
/** \class cmSystemTools
|
||||||
* \brief A collection of useful functions for CMake.
|
* \brief A collection of useful functions for CMake.
|
||||||
*
|
*
|
||||||
@@ -40,7 +42,8 @@ public:
|
|||||||
/** Map help document name to file name. */
|
/** Map help document name to file name. */
|
||||||
static std::string HelpFileName(cm::string_view);
|
static std::string HelpFileName(cm::string_view);
|
||||||
|
|
||||||
using MessageCallback = std::function<void(const std::string&, const char*)>;
|
using MessageCallback =
|
||||||
|
std::function<void(const std::string&, const cmMessageMetadata&)>;
|
||||||
/**
|
/**
|
||||||
* Set the function used by GUIs to display error messages
|
* Set the function used by GUIs to display error messages
|
||||||
* Function gets passed: message as a const char*,
|
* Function gets passed: message as a const char*,
|
||||||
@@ -57,6 +60,7 @@ public:
|
|||||||
* Display a message.
|
* Display a message.
|
||||||
*/
|
*/
|
||||||
static void Message(const std::string& m, const char* title = nullptr);
|
static void Message(const std::string& m, const char* title = nullptr);
|
||||||
|
static void Message(const std::string& m, const cmMessageMetadata& md);
|
||||||
|
|
||||||
using OutputCallback = std::function<void(std::string const&)>;
|
using OutputCallback = std::function<void(std::string const&)>;
|
||||||
|
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <climits>
|
#include <climits>
|
||||||
|
#include <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
@@ -23,6 +24,7 @@
|
|||||||
#include "cmDocumentationEntry.h" // IWYU pragma: keep
|
#include "cmDocumentationEntry.h" // IWYU pragma: keep
|
||||||
#include "cmGlobalGenerator.h"
|
#include "cmGlobalGenerator.h"
|
||||||
#include "cmMakefile.h"
|
#include "cmMakefile.h"
|
||||||
|
#include "cmMessageMetadata.h"
|
||||||
#include "cmProperty.h"
|
#include "cmProperty.h"
|
||||||
#include "cmState.h"
|
#include "cmState.h"
|
||||||
#include "cmStateTypes.h"
|
#include "cmStateTypes.h"
|
||||||
@@ -37,6 +39,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "cmsys/Encoding.hxx"
|
#include "cmsys/Encoding.hxx"
|
||||||
|
#include "cmsys/Terminal.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
#ifndef CMAKE_BOOTSTRAP
|
#ifndef CMAKE_BOOTSTRAP
|
||||||
@@ -147,10 +150,12 @@ std::string cmakemainGetStack(cmake* cm)
|
|||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmakemainMessageCallback(const std::string& m, const char* /*unused*/,
|
void cmakemainMessageCallback(const std::string& m,
|
||||||
cmake* cm)
|
const cmMessageMetadata& md, cmake* cm)
|
||||||
{
|
{
|
||||||
std::cerr << m << cmakemainGetStack(cm) << std::endl;
|
cmsysTerminal_cfprintf(md.desiredColor, stderr, "%s", m.c_str());
|
||||||
|
fflush(stderr); // stderr is buffered in some cases.
|
||||||
|
std::cerr << cmakemainGetStack(cm) << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmakemainProgressCallback(const std::string& m, float prog, cmake* cm)
|
void cmakemainProgressCallback(const std::string& m, float prog, cmake* cm)
|
||||||
@@ -343,8 +348,8 @@ int do_cmake(int ac, char const* const* av)
|
|||||||
cm.SetHomeDirectory("");
|
cm.SetHomeDirectory("");
|
||||||
cm.SetHomeOutputDirectory("");
|
cm.SetHomeOutputDirectory("");
|
||||||
cmSystemTools::SetMessageCallback(
|
cmSystemTools::SetMessageCallback(
|
||||||
[&cm](const std::string& msg, const char* title) {
|
[&cm](const std::string& msg, const cmMessageMetadata& md) {
|
||||||
cmakemainMessageCallback(msg, title, &cm);
|
cmakemainMessageCallback(msg, md, &cm);
|
||||||
});
|
});
|
||||||
cm.SetProgressCallback([&cm](const std::string& msg, float prog) {
|
cm.SetProgressCallback([&cm](const std::string& msg, float prog) {
|
||||||
cmakemainProgressCallback(msg, prog, &cm);
|
cmakemainProgressCallback(msg, prog, &cm);
|
||||||
@@ -626,8 +631,8 @@ int do_build(int ac, char const* const* av)
|
|||||||
|
|
||||||
cmake cm(cmake::RoleInternal, cmState::Project);
|
cmake cm(cmake::RoleInternal, cmState::Project);
|
||||||
cmSystemTools::SetMessageCallback(
|
cmSystemTools::SetMessageCallback(
|
||||||
[&cm](const std::string& msg, const char* title) {
|
[&cm](const std::string& msg, const cmMessageMetadata& md) {
|
||||||
cmakemainMessageCallback(msg, title, &cm);
|
cmakemainMessageCallback(msg, md, &cm);
|
||||||
});
|
});
|
||||||
cm.SetProgressCallback([&cm](const std::string& msg, float prog) {
|
cm.SetProgressCallback([&cm](const std::string& msg, float prog) {
|
||||||
cmakemainProgressCallback(msg, prog, &cm);
|
cmakemainProgressCallback(msg, prog, &cm);
|
||||||
@@ -859,8 +864,8 @@ int do_install(int ac, char const* const* av)
|
|||||||
cmake cm(cmake::RoleScript, cmState::Script);
|
cmake cm(cmake::RoleScript, cmState::Script);
|
||||||
|
|
||||||
cmSystemTools::SetMessageCallback(
|
cmSystemTools::SetMessageCallback(
|
||||||
[&cm](const std::string& msg, const char* title) {
|
[&cm](const std::string& msg, const cmMessageMetadata& md) {
|
||||||
cmakemainMessageCallback(msg, title, &cm);
|
cmakemainMessageCallback(msg, md, &cm);
|
||||||
});
|
});
|
||||||
cm.SetProgressCallback([&cm](const std::string& msg, float prog) {
|
cm.SetProgressCallback([&cm](const std::string& msg, float prog) {
|
||||||
cmakemainProgressCallback(msg, prog, &cm);
|
cmakemainProgressCallback(msg, prog, &cm);
|
||||||
@@ -940,8 +945,8 @@ int do_open(int ac, char const* const* av)
|
|||||||
|
|
||||||
cmake cm(cmake::RoleInternal, cmState::Unknown);
|
cmake cm(cmake::RoleInternal, cmState::Unknown);
|
||||||
cmSystemTools::SetMessageCallback(
|
cmSystemTools::SetMessageCallback(
|
||||||
[&cm](const std::string& msg, const char* title) {
|
[&cm](const std::string& msg, const cmMessageMetadata& md) {
|
||||||
cmakemainMessageCallback(msg, title, &cm);
|
cmakemainMessageCallback(msg, md, &cm);
|
||||||
});
|
});
|
||||||
cm.SetProgressCallback([&cm](const std::string& msg, float prog) {
|
cm.SetProgressCallback([&cm](const std::string& msg, float prog) {
|
||||||
cmakemainProgressCallback(msg, prog, &cm);
|
cmakemainProgressCallback(msg, prog, &cm);
|
||||||
|
Reference in New Issue
Block a user