forked from qt-creator/qt-creator
ClangTools: Do not try to kill subprocesses syncronously
Task-number: QTCREATORBUG-24627 Change-Id: Iec0169335d62435c017e39f252be3d7ca470d2d4 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -58,19 +58,38 @@ static QString finishedWithBadExitCode(const QString &name, int exitCode)
|
|||||||
return ClangToolRunner::tr("%1 finished with exit code: %2.").arg(name).arg(exitCode);
|
return ClangToolRunner::tr("%1 finished with exit code: %2.").arg(name).arg(exitCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ClangToolRunner::ClangToolRunner(QObject *parent)
|
||||||
|
: QObject(parent), m_process(new QProcess)
|
||||||
|
{}
|
||||||
|
|
||||||
|
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 (Utils::HostOsInfo::isWindowsHost()) {
|
||||||
|
m_process->kill();
|
||||||
|
m_process->waitForFinished(100);
|
||||||
|
} else {
|
||||||
|
Utils::SynchronousProcess::stopProcess(*m_process);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_process->deleteLater();
|
||||||
|
}
|
||||||
|
|
||||||
void ClangToolRunner::init(const QString &outputDirPath,
|
void ClangToolRunner::init(const QString &outputDirPath,
|
||||||
const Utils::Environment &environment)
|
const Utils::Environment &environment)
|
||||||
{
|
{
|
||||||
m_outputDirPath = outputDirPath;
|
m_outputDirPath = outputDirPath;
|
||||||
QTC_CHECK(!m_outputDirPath.isEmpty());
|
QTC_CHECK(!m_outputDirPath.isEmpty());
|
||||||
|
|
||||||
m_process.setProcessChannelMode(QProcess::MergedChannels);
|
m_process->setProcessChannelMode(QProcess::MergedChannels);
|
||||||
m_process.setProcessEnvironment(environment.toProcessEnvironment());
|
m_process->setProcessEnvironment(environment.toProcessEnvironment());
|
||||||
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, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
|
connect(m_process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
|
||||||
this, &ClangToolRunner::onProcessFinished);
|
this, &ClangToolRunner::onProcessFinished);
|
||||||
connect(&m_process, &QProcess::errorOccurred, this, &ClangToolRunner::onProcessError);
|
connect(m_process, &QProcess::errorOccurred, this, &ClangToolRunner::onProcessError);
|
||||||
connect(&m_process, &QProcess::readyRead, this, &ClangToolRunner::onProcessOutput);
|
connect(m_process, &QProcess::readyRead, this, &ClangToolRunner::onProcessOutput);
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList ClangToolRunner::mainToolArguments() const
|
QStringList ClangToolRunner::mainToolArguments() const
|
||||||
@@ -96,19 +115,6 @@ bool ClangToolRunner::supportsVFSOverlay() const
|
|||||||
return it.value();
|
return it.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
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 (Utils::HostOsInfo::isWindowsHost()) {
|
|
||||||
m_process.kill();
|
|
||||||
m_process.waitForFinished(100);
|
|
||||||
} else {
|
|
||||||
Utils::SynchronousProcess::stopProcess(m_process);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static QString createOutputFilePath(const QString &dirPath, const QString &fileToAnalyze)
|
static QString createOutputFilePath(const QString &dirPath, const QString &fileToAnalyze)
|
||||||
{
|
{
|
||||||
const QString fileName = QFileInfo(fileToAnalyze).fileName();
|
const QString fileName = QFileInfo(fileToAnalyze).fileName();
|
||||||
@@ -140,7 +146,7 @@ bool ClangToolRunner::run(const QString &fileToAnalyze, const QStringList &compi
|
|||||||
m_commandLine = Utils::QtcProcess::joinArgs(QStringList(m_executable) + arguments);
|
m_commandLine = Utils::QtcProcess::joinArgs(QStringList(m_executable) + arguments);
|
||||||
|
|
||||||
qCDebug(LOG).noquote() << "Starting" << m_commandLine;
|
qCDebug(LOG).noquote() << "Starting" << m_commandLine;
|
||||||
m_process.start(m_executable, arguments);
|
m_process->start(m_executable, arguments);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,7 +176,7 @@ void ClangToolRunner::onProcessError(QProcess::ProcessError error)
|
|||||||
|
|
||||||
void ClangToolRunner::onProcessOutput()
|
void ClangToolRunner::onProcessOutput()
|
||||||
{
|
{
|
||||||
m_processOutput.append(m_process.readAll());
|
m_processOutput.append(m_process->readAll());
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ClangToolRunner::commandlineAndOutput() const
|
QString ClangToolRunner::commandlineAndOutput() const
|
||||||
@@ -179,7 +185,7 @@ QString ClangToolRunner::commandlineAndOutput() const
|
|||||||
"Process Error: %2\n"
|
"Process Error: %2\n"
|
||||||
"Output:\n%3")
|
"Output:\n%3")
|
||||||
.arg(m_commandLine,
|
.arg(m_commandLine,
|
||||||
QString::number(m_process.error()),
|
QString::number(m_process->error()),
|
||||||
Utils::SynchronousProcess::normalizeNewlines(QString::fromLocal8Bit(m_processOutput)));
|
Utils::SynchronousProcess::normalizeNewlines(QString::fromLocal8Bit(m_processOutput)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -44,7 +44,7 @@ class ClangToolRunner : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ClangToolRunner(QObject *parent = nullptr) : QObject(parent) {}
|
ClangToolRunner(QObject *parent = nullptr);
|
||||||
~ClangToolRunner() override;
|
~ClangToolRunner() override;
|
||||||
|
|
||||||
void init(const QString &outputDirPath, const Utils::Environment &environment);
|
void init(const QString &outputDirPath, const Utils::Environment &environment);
|
||||||
@@ -83,7 +83,7 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_outputDirPath;
|
QString m_outputDirPath;
|
||||||
QProcess m_process;
|
QProcess *m_process = nullptr;
|
||||||
QByteArray m_processOutput;
|
QByteArray m_processOutput;
|
||||||
|
|
||||||
QString m_name;
|
QString m_name;
|
||||||
|
Reference in New Issue
Block a user