mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-06 05:40:54 -06:00
Makefile: Fix output during parallel builds (#12991)
Replace use of separate "cmake -E cmake_progress_report" and "cmake -E cmake_echo_color" commands to report the progress and message portions of build output lines with --progress-* options to the latter to print everything with a single command. The line buffering of the stdout FILE stream should cause the whole line to be printed with one atomic write. This will avoid inter-mixing of line-wise messages from different processes during a parallel build.
This commit is contained in:
@@ -1346,8 +1346,9 @@ cmLocalUnixMakefileGenerator3
|
||||
//----------------------------------------------------------------------------
|
||||
void
|
||||
cmLocalUnixMakefileGenerator3::AppendEcho(std::vector<std::string>& commands,
|
||||
const char* text,
|
||||
EchoColor color)
|
||||
std::string const& text,
|
||||
EchoColor color,
|
||||
EchoProgress const* progress)
|
||||
{
|
||||
// Choose the color for the text.
|
||||
std::string color_name;
|
||||
@@ -1380,7 +1381,7 @@ cmLocalUnixMakefileGenerator3::AppendEcho(std::vector<std::string>& commands,
|
||||
// Echo one line at a time.
|
||||
std::string line;
|
||||
line.reserve(200);
|
||||
for(const char* c = text;; ++c)
|
||||
for(const char* c = text.c_str();; ++c)
|
||||
{
|
||||
if(*c == '\n' || *c == '\0')
|
||||
{
|
||||
@@ -1389,7 +1390,7 @@ cmLocalUnixMakefileGenerator3::AppendEcho(std::vector<std::string>& commands,
|
||||
{
|
||||
// Add a command to echo this line.
|
||||
std::string cmd;
|
||||
if(color_name.empty())
|
||||
if(color_name.empty() && !progress)
|
||||
{
|
||||
// Use the native echo command.
|
||||
cmd = "@echo ";
|
||||
@@ -1400,6 +1401,17 @@ cmLocalUnixMakefileGenerator3::AppendEcho(std::vector<std::string>& commands,
|
||||
// Use cmake to echo the text in color.
|
||||
cmd = "@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) ";
|
||||
cmd += color_name;
|
||||
if (progress)
|
||||
{
|
||||
cmd += "--progress-dir=";
|
||||
cmd += this->Convert(progress->Dir,
|
||||
cmLocalGenerator::FULL,
|
||||
cmLocalGenerator::SHELL);
|
||||
cmd += " ";
|
||||
cmd += "--progress-num=";
|
||||
cmd += progress->Arg;
|
||||
cmd += " ";
|
||||
}
|
||||
cmd += this->EscapeForShell(line);
|
||||
}
|
||||
commands.push_back(cmd);
|
||||
@@ -1408,6 +1420,9 @@ cmLocalUnixMakefileGenerator3::AppendEcho(std::vector<std::string>& commands,
|
||||
// Reset the line to emtpy.
|
||||
line = "";
|
||||
|
||||
// Progress appears only on first line.
|
||||
progress = 0;
|
||||
|
||||
// Terminate on end-of-string.
|
||||
if(*c == '\0')
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user