CMake: Split build output into lines before parsing

This amends commit b15d1951a2, where we moved the line splitting into
the output parsers, but overlooked that the CMakeBuildStep does
additional line-based parsing. As a result, the stdout -> stderr
redirection for ninja output was broken.

Change-Id: Iafbbce9a3f9c0383812a9e4c129c1d94fa907b73
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Christian Kandeler
2020-05-26 14:34:52 +02:00
parent 9c3d4dcc88
commit 301a388982
2 changed files with 37 additions and 25 deletions

View File

@@ -268,33 +268,45 @@ QString CMakeBuildStep::defaultBuildTarget() const
return allTarget(); return allTarget();
} }
void CMakeBuildStep::stdOutput(const QString &line) void CMakeBuildStep::stdOutput(const QString &output)
{ {
if (m_percentProgress.indexIn(line) != -1) { int offset = 0;
AbstractProcessStep::stdOutput(line); while (offset != -1) {
bool ok = false; const int newlinePos = output.indexOf('\n', offset);
int percent = m_percentProgress.cap(1).toInt(&ok); QString line;
if (ok) if (newlinePos == -1) {
emit progress(percent, QString()); line = output.mid(offset);
return; offset = -1;
} else if (m_ninjaProgress.indexIn(line) != -1) { } else {
AbstractProcessStep::stdOutput(line); line = output.mid(offset, newlinePos - offset + 1);
m_useNinja = true; offset = newlinePos + 1;
bool ok = false;
int done = m_ninjaProgress.cap(1).toInt(&ok);
if (ok) {
int all = m_ninjaProgress.cap(2).toInt(&ok);
if (ok && all != 0) {
const int percent = static_cast<int>(100.0 * done/all);
emit progress(percent, QString());
}
} }
return; if (m_percentProgress.indexIn(line) != -1) {
AbstractProcessStep::stdOutput(line);
bool ok = false;
int percent = m_percentProgress.cap(1).toInt(&ok);
if (ok)
emit progress(percent, QString());
continue;
} else if (m_ninjaProgress.indexIn(line) != -1) {
AbstractProcessStep::stdOutput(line);
m_useNinja = true;
bool ok = false;
int done = m_ninjaProgress.cap(1).toInt(&ok);
if (ok) {
int all = m_ninjaProgress.cap(2).toInt(&ok);
if (ok && all != 0) {
const int percent = static_cast<int>(100.0 * done/all);
emit progress(percent, QString());
}
}
continue;
}
if (m_useNinja)
AbstractProcessStep::stdError(line);
else
AbstractProcessStep::stdOutput(line);
} }
if (m_useNinja)
AbstractProcessStep::stdError(line);
else
AbstractProcessStep::stdOutput(line);
} }
QString CMakeBuildStep::buildTarget() const QString CMakeBuildStep::buildTarget() const

View File

@@ -77,7 +77,7 @@ protected:
bool fromMap(const QVariantMap &map) override; bool fromMap(const QVariantMap &map) override;
// For parsing [ 76%] // For parsing [ 76%]
void stdOutput(const QString &line) override; void stdOutput(const QString &output) override;
private: private:
void ctor(ProjectExplorer::BuildStepList *bsl); void ctor(ProjectExplorer::BuildStepList *bsl);