From 634587e322296580dc16b00d689268e1de5827cc Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 27 Jan 2022 15:18:08 -0500 Subject: message: Restore explicit flushing of messages on stderr In the `cmake` command-line tool, the `message()` command with no message mode argument prints the message stderr using the C++ `cerr` stream. Since commit 0a0a0f8a74 (cmMessenger: Color messages to terminal by type, 2021-05-18, v3.21.0-rc1~146^2) and an update by commit c7a8c9c811 (cmMessenger: Revert to non-color messages on Windows, 2021-07-20, v3.21.1~15^2), we print the newline at the end of the message using just `\n`. We've now observed some cases of output on stdout and stderr getting jumbled when the two go to the same file descriptor. Previously the newline was printed with `endl`, which implicitly flushes. Flush explicitly to restore that behavior. Fixes: #23155 --- Source/cmakemain.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index 64d93df..95ad320 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -161,11 +161,11 @@ void cmakemainMessageCallback(const std::string& m, // cannot use it to print messages. Another implementation will // be needed to print colored messages on Windows. static_cast(md); - std::cerr << m << cmakemainGetStack(cm) << "\n"; + std::cerr << m << cmakemainGetStack(cm) << '\n' << std::flush; #else cmsysTerminal_cfprintf(md.desiredColor, stderr, "%s", m.c_str()); fflush(stderr); // stderr is buffered in some cases. - std::cerr << cmakemainGetStack(cm) << "\n"; + std::cerr << cmakemainGetStack(cm) << '\n' << std::flush; #endif } -- cgit v0.12