ClangTools: Simplify process rampdown

This is now taken care of in the desctuctor of QtcProcess itself.

Change-Id: I51e65344e6d2cae4498e292e4ad6a586c68b0539
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
hjk
2022-06-16 10:34:01 +02:00
parent 706dc654b9
commit 189fe7fab3
2 changed files with 15 additions and 37 deletions

View File

@@ -25,8 +25,6 @@
#include "clangtoolrunner.h"
#include "clangtoolsconstants.h"
#include <utils/environment.h>
#include <utils/qtcassert.h>
#include <utils/qtcprocess.h>
@@ -60,33 +58,17 @@ static QString finishedWithBadExitCode(const QString &name, int exitCode)
}
ClangToolRunner::ClangToolRunner(QObject *parent)
: QObject(parent), m_process(new QtcProcess)
: QObject(parent)
{}
ClangToolRunner::~ClangToolRunner()
{
if (m_process->state() != QProcess::NotRunning) {
// asking politly to terminate costs ~300 ms on windows so skip the courtasy and direct kill the process
if (HostOsInfo::isWindowsHost()) {
m_process->kill();
m_process->waitForFinished(100);
} else {
m_process->stop();
m_process->waitForFinished();
}
}
m_process->deleteLater();
}
void ClangToolRunner::init(const FilePath &outputDirPath, const Environment &environment)
{
m_outputDirPath = outputDirPath;
QTC_CHECK(!m_outputDirPath.isEmpty());
m_process->setEnvironment(environment);
m_process->setWorkingDirectory(m_outputDirPath); // Current clang-cl puts log file into working dir.
connect(m_process, &QtcProcess::done, this, &ClangToolRunner::onProcessDone);
m_process.setEnvironment(environment);
m_process.setWorkingDirectory(m_outputDirPath); // Current clang-cl puts log file into working dir.
connect(&m_process, &QtcProcess::done, this, &ClangToolRunner::onProcessDone);
}
QStringList ClangToolRunner::mainToolArguments() const
@@ -140,20 +122,20 @@ bool ClangToolRunner::run(const QString &fileToAnalyze, const QStringList &compi
m_commandLine = {m_executable, m_argsCreator(compilerOptions)};
qCDebug(LOG).noquote() << "Starting" << m_commandLine.toUserOutput();
m_process->setCommand(m_commandLine);
m_process->start();
m_process.setCommand(m_commandLine);
m_process.start();
return true;
}
void ClangToolRunner::onProcessDone()
{
if (m_process->result() == ProcessResult::StartFailed) {
if (m_process.result() == ProcessResult::StartFailed) {
emit finishedWithFailure(generalProcessError(m_name), commandlineAndOutput());
} else if (m_process->result() == ProcessResult::FinishedWithSuccess) {
qCDebug(LOG).noquote() << "Output:\n" << m_process->stdOut();
} else if (m_process.result() == ProcessResult::FinishedWithSuccess) {
qCDebug(LOG).noquote() << "Output:\n" << m_process.stdOut();
emit finishedWithSuccess(m_fileToAnalyze);
} else if (m_process->result() == ProcessResult::FinishedWithError) {
emit finishedWithFailure(finishedWithBadExitCode(m_name, m_process->exitCode()),
} else if (m_process.result() == ProcessResult::FinishedWithError) {
emit finishedWithFailure(finishedWithBadExitCode(m_name, m_process.exitCode()),
commandlineAndOutput());
} else { // == QProcess::CrashExit
emit finishedWithFailure(finishedDueToCrash(m_name), commandlineAndOutput());
@@ -166,8 +148,8 @@ QString ClangToolRunner::commandlineAndOutput() const
"Process Error: %2\n"
"Output:\n%3")
.arg(m_commandLine.toUserOutput())
.arg(m_process->error())
.arg(m_process->stdOut());
.arg(m_process.error())
.arg(m_process.stdOut());
}
} // namespace Internal

View File

@@ -28,13 +28,10 @@
#include "clangtoolslogfilereader.h"
#include <utils/commandline.h>
#include <QProcess>
#include <utils/qtcprocess.h>
#include <memory>
namespace Utils { class QtcProcess; }
namespace ClangTools {
namespace Internal {
@@ -46,7 +43,6 @@ class ClangToolRunner : public QObject
public:
ClangToolRunner(QObject *parent = nullptr);
~ClangToolRunner() override;
void init(const Utils::FilePath &outputDirPath, const Utils::Environment &environment);
void setName(const QString &name) { m_name = name; }
@@ -83,7 +79,7 @@ private:
private:
Utils::FilePath m_outputDirPath;
Utils::QtcProcess *m_process = nullptr;
Utils::QtcProcess m_process;
QString m_name;
Utils::FilePath m_executable;