ClangTools: Don't double-buffer in ClangToolRunner

Not needed, and the only user of QtcProcess::readyRead.

Change-Id: I6ba071507f545076cf74660c20916407c3f3a551
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
hjk
2021-05-28 16:53:36 +02:00
parent 95a7dc4857
commit 0b7e71ddca
2 changed files with 11 additions and 22 deletions

View File

@@ -87,7 +87,6 @@ void ClangToolRunner::init(const QString &outputDirPath, const Environment &envi
m_process->setWorkingDirectory(m_outputDirPath); // Current clang-cl puts log file into working dir. m_process->setWorkingDirectory(m_outputDirPath); // Current clang-cl puts log file into working dir.
connect(m_process, &QtcProcess::finished, this, &ClangToolRunner::onProcessFinished); connect(m_process, &QtcProcess::finished, this, &ClangToolRunner::onProcessFinished);
connect(m_process, &QtcProcess::errorOccurred, this, &ClangToolRunner::onProcessError); connect(m_process, &QtcProcess::errorOccurred, this, &ClangToolRunner::onProcessError);
connect(m_process, &QtcProcess::readyRead, this, &ClangToolRunner::onProcessOutput);
} }
QStringList ClangToolRunner::mainToolArguments() const QStringList ClangToolRunner::mainToolArguments() const
@@ -136,7 +135,6 @@ bool ClangToolRunner::run(const QString &fileToAnalyze, const QStringList &compi
QTC_CHECK(!compilerOptions.contains(fileToAnalyze)); QTC_CHECK(!compilerOptions.contains(fileToAnalyze));
m_fileToAnalyze = fileToAnalyze; m_fileToAnalyze = fileToAnalyze;
m_processOutput.clear();
m_outputFilePath = createOutputFilePath(m_outputDirPath, fileToAnalyze); m_outputFilePath = createOutputFilePath(m_outputDirPath, fileToAnalyze);
QTC_ASSERT(!m_outputFilePath.isEmpty(), return false); QTC_ASSERT(!m_outputFilePath.isEmpty(), return false);
@@ -148,17 +146,14 @@ bool ClangToolRunner::run(const QString &fileToAnalyze, const QStringList &compi
return true; return true;
} }
void ClangToolRunner::onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus) void ClangToolRunner::onProcessFinished()
{ {
if (exitStatus == QProcess::NormalExit) { if (m_process->result() == QtcProcess::FinishedWithSuccess) {
if (exitCode == 0) { qCDebug(LOG).noquote() << "Output:\n" << m_process->stdOut();
qCDebug(LOG).noquote() << "Output:\n" << QtcProcess::normalizeNewlines( emit finishedWithSuccess(m_fileToAnalyze);
QString::fromLocal8Bit(m_processOutput)); } else if (m_process->result() == QtcProcess::FinishedWithError) {
emit finishedWithSuccess(m_fileToAnalyze); emit finishedWithFailure(finishedWithBadExitCode(m_name, m_process->exitCode()),
} else { commandlineAndOutput());
emit finishedWithFailure(finishedWithBadExitCode(m_name, exitCode),
commandlineAndOutput());
}
} else { // == QProcess::CrashExit } else { // == QProcess::CrashExit
emit finishedWithFailure(finishedDueToCrash(m_name), commandlineAndOutput()); emit finishedWithFailure(finishedDueToCrash(m_name), commandlineAndOutput());
} }
@@ -172,19 +167,14 @@ void ClangToolRunner::onProcessError(QProcess::ProcessError error)
emit finishedWithFailure(generalProcessError(m_name), commandlineAndOutput()); emit finishedWithFailure(generalProcessError(m_name), commandlineAndOutput());
} }
void ClangToolRunner::onProcessOutput()
{
m_processOutput.append(m_process->readAllStandardOutput());
}
QString ClangToolRunner::commandlineAndOutput() const QString ClangToolRunner::commandlineAndOutput() const
{ {
return tr("Command line: %1\n" return tr("Command line: %1\n"
"Process Error: %2\n" "Process Error: %2\n"
"Output:\n%3") "Output:\n%3")
.arg(m_commandLine.toUserOutput(), .arg(m_commandLine.toUserOutput())
QString::number(m_process->error()), .arg(m_process->error())
QtcProcess::normalizeNewlines(QString::fromLocal8Bit(m_processOutput))); .arg(m_process->stdOut());
} }
} // namespace Internal } // namespace Internal

View File

@@ -73,7 +73,7 @@ protected:
private: private:
void onProcessOutput(); void onProcessOutput();
void onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus); void onProcessFinished();
void onProcessError(QProcess::ProcessError error); void onProcessError(QProcess::ProcessError error);
QString commandlineAndOutput() const; QString commandlineAndOutput() const;
@@ -81,7 +81,6 @@ private:
private: private:
QString m_outputDirPath; QString m_outputDirPath;
Utils::QtcProcess *m_process = nullptr; Utils::QtcProcess *m_process = nullptr;
QByteArray m_processOutput;
QString m_name; QString m_name;
QString m_executable; QString m_executable;