Skip to content
Snippets Groups Projects
Commit c7a8c9c8 authored by Brad King's avatar Brad King
Browse files

cmMessenger: Revert to non-color messages on Windows

Since commit 0a0a0f8a (cmMessenger: Color messages to terminal by
type, 2021-05-18, v3.21.0-rc1~146^2) the message output no longer goes
through our custom streambuf on Windows that converts output encoding.
This can cause messages to be printed with the wrong encoding in a
Windows Console.  It also causes messages to have a mix of LF and CRLF
newlines because `stderr` converts LF to CRLF but our custom streambuf
does not.

Revert to using just `cerr` for messages on Windows.  Another approach
will be needed to achieve color output on Windows later.

Fixes: #22444
parent 31ecd371
No related branches found
No related tags found
No related merge requests found
......@@ -153,9 +153,20 @@ std::string cmakemainGetStack(cmake* cm)
void cmakemainMessageCallback(const std::string& m,
const cmMessageMetadata& md, cmake* cm)
{
#if defined(_WIN32)
// FIXME: On Windows we replace cerr's streambuf with a custom
// implementation that converts our internal UTF-8 encoding to the
// console's encoding. It also does *not* replace LF with CRLF.
// Since stderr does not convert encoding and does convert LF, we
// cannot use it to print messages. Another implementation will
// be needed to print colored messages on Windows.
static_cast<void>(md);
std::cerr << m << cmakemainGetStack(cm) << "\n";
#else
cmsysTerminal_cfprintf(md.desiredColor, stderr, "%s", m.c_str());
fflush(stderr); // stderr is buffered in some cases.
std::cerr << cmakemainGetStack(cm) << "\n";
#endif
}
void cmakemainProgressCallback(const std::string& m, float prog, cmake* cm)
......
include(RunCMake)
run_cmake_script(newline)
run_cmake(defaultmessage)
run_cmake(nomessage)
run_cmake(message-internal-warning)
......
message(STATUS "one\ntwo")
message("one\ntwo")
-- out='2d2d206f6e650a74776f0a'
-- err='6f6e650a74776f0a'
execute_process(
COMMAND "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_LIST_DIR}/newline-script.cmake"
OUTPUT_FILE newline-script-stdout.txt
ERROR_FILE newline-script-stderr.txt
)
foreach(f out err)
file(READ newline-script-std${f}.txt hex HEX)
message(STATUS "${f}='${hex}'")
endforeach()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment