forked from qt-creator/qt-creator
CppcheckRunner: Connect to done() signal instead of finished()
Simplify internals a bit. Change-Id: I4871b73f605af4d56e4993b6d71bbb22b4fce27d Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -28,7 +28,6 @@
|
||||
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
|
||||
#include <coreplugin/messagemanager.h>
|
||||
|
||||
@@ -37,11 +36,9 @@ using namespace Utils;
|
||||
namespace Cppcheck {
|
||||
namespace Internal {
|
||||
|
||||
CppcheckRunner::CppcheckRunner(CppcheckTool &tool) :
|
||||
m_tool(tool),
|
||||
m_process(new Utils::QtcProcess(this))
|
||||
CppcheckRunner::CppcheckRunner(CppcheckTool &tool) : m_tool(tool)
|
||||
{
|
||||
if (Utils::HostOsInfo::hostOs() == Utils::OsTypeLinux) {
|
||||
if (HostOsInfo::hostOs() == OsTypeLinux) {
|
||||
QtcProcess getConf;
|
||||
getConf.setCommand({"getconf", {"ARG_MAX"}});
|
||||
getConf.start();
|
||||
@@ -50,17 +47,15 @@ CppcheckRunner::CppcheckRunner(CppcheckTool &tool) :
|
||||
m_maxArgumentsLength = std::max(argMax.toInt(), m_maxArgumentsLength);
|
||||
}
|
||||
|
||||
m_process->setStdOutLineCallback([this](const QString &line) {
|
||||
m_process.setStdOutLineCallback([this](const QString &line) {
|
||||
m_tool.parseOutputLine(line);
|
||||
});
|
||||
m_process->setStdErrLineCallback([this](const QString &line) {
|
||||
m_process.setStdErrLineCallback([this](const QString &line) {
|
||||
m_tool.parseErrorLine(line);
|
||||
});
|
||||
|
||||
connect(m_process, &QtcProcess::started,
|
||||
this, &CppcheckRunner::handleStarted);
|
||||
connect(m_process, &QtcProcess::finished,
|
||||
this, &CppcheckRunner::handleFinished);
|
||||
connect(&m_process, &QtcProcess::started, &m_tool, &CppcheckTool::startParsing);
|
||||
connect(&m_process, &QtcProcess::done, this, &CppcheckRunner::handleDone);
|
||||
|
||||
m_queueTimer.setSingleShot(true);
|
||||
const int checkDelayInMs = 200;
|
||||
@@ -81,18 +76,18 @@ void CppcheckRunner::reconfigure(const FilePath &binary, const QString &argument
|
||||
m_arguments = arguments;
|
||||
}
|
||||
|
||||
void CppcheckRunner::addToQueue(const Utils::FilePaths &files,
|
||||
void CppcheckRunner::addToQueue(const FilePaths &files,
|
||||
const QString &additionalArguments)
|
||||
{
|
||||
Utils::FilePaths &existing = m_queue[additionalArguments];
|
||||
FilePaths &existing = m_queue[additionalArguments];
|
||||
if (existing.isEmpty()) {
|
||||
existing = files;
|
||||
} else {
|
||||
std::copy_if(files.cbegin(), files.cend(), std::back_inserter(existing),
|
||||
[&existing](const Utils::FilePath &file) { return !existing.contains(file); });
|
||||
[&existing](const FilePath &file) { return !existing.contains(file); });
|
||||
}
|
||||
|
||||
if (m_isRunning) {
|
||||
if (m_process.isRunning()) {
|
||||
stop(existing);
|
||||
return;
|
||||
}
|
||||
@@ -100,16 +95,16 @@ void CppcheckRunner::addToQueue(const Utils::FilePaths &files,
|
||||
m_queueTimer.start();
|
||||
}
|
||||
|
||||
void CppcheckRunner::stop(const Utils::FilePaths &files)
|
||||
void CppcheckRunner::stop(const FilePaths &files)
|
||||
{
|
||||
if (!m_isRunning)
|
||||
if (!m_process.isRunning())
|
||||
return;
|
||||
|
||||
if (files.isEmpty() || m_currentFiles == files)
|
||||
m_process->kill();
|
||||
m_process.stop();
|
||||
}
|
||||
|
||||
void CppcheckRunner::removeFromQueue(const Utils::FilePaths &files)
|
||||
void CppcheckRunner::removeFromQueue(const FilePaths &files)
|
||||
{
|
||||
if (m_queue.isEmpty())
|
||||
return;
|
||||
@@ -118,21 +113,21 @@ void CppcheckRunner::removeFromQueue(const Utils::FilePaths &files)
|
||||
m_queue.clear();
|
||||
} else {
|
||||
for (auto it = m_queue.begin(), end = m_queue.end(); it != end;) {
|
||||
for (const Utils::FilePath &file : files)
|
||||
for (const FilePath &file : files)
|
||||
it.value().removeOne(file);
|
||||
it = !it.value().isEmpty() ? ++it : m_queue.erase(it);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const Utils::FilePaths &CppcheckRunner::currentFiles() const
|
||||
const FilePaths &CppcheckRunner::currentFiles() const
|
||||
{
|
||||
return m_currentFiles;
|
||||
}
|
||||
|
||||
QString CppcheckRunner::currentCommand() const
|
||||
{
|
||||
return m_process->commandLine().toUserOutput();
|
||||
return m_process.commandLine().toUserOutput();
|
||||
}
|
||||
|
||||
void CppcheckRunner::checkQueued()
|
||||
@@ -140,7 +135,7 @@ void CppcheckRunner::checkQueued()
|
||||
if (m_queue.isEmpty() || m_binary.isEmpty())
|
||||
return;
|
||||
|
||||
Utils::FilePaths files = m_queue.begin().value();
|
||||
FilePaths files = m_queue.begin().value();
|
||||
QString arguments = m_arguments + ' ' + m_queue.begin().key();
|
||||
m_currentFiles.clear();
|
||||
int argumentsLength = arguments.length();
|
||||
@@ -158,30 +153,19 @@ void CppcheckRunner::checkQueued()
|
||||
else
|
||||
m_queue.begin().value() = files;
|
||||
|
||||
m_process->setCommand(CommandLine(m_binary, arguments, CommandLine::Raw));
|
||||
m_process->start();
|
||||
m_process.setCommand(CommandLine(m_binary, arguments, CommandLine::Raw));
|
||||
m_process.start();
|
||||
}
|
||||
|
||||
void CppcheckRunner::handleStarted()
|
||||
void CppcheckRunner::handleDone()
|
||||
{
|
||||
if (m_isRunning)
|
||||
return;
|
||||
|
||||
m_isRunning = true;
|
||||
m_tool.startParsing();
|
||||
}
|
||||
|
||||
void CppcheckRunner::handleFinished()
|
||||
{
|
||||
if (m_process->error() != QProcess::FailedToStart) {
|
||||
if (m_process.result() == ProcessResult::FinishedWithSuccess)
|
||||
m_tool.finishParsing();
|
||||
} else {
|
||||
const QString message = tr("Cppcheck failed to start: \"%1\".").arg(currentCommand());
|
||||
Core::MessageManager::writeSilently(message);
|
||||
}
|
||||
else
|
||||
Core::MessageManager::writeSilently(m_process.exitMessage());
|
||||
|
||||
m_currentFiles.clear();
|
||||
m_process->close();
|
||||
m_isRunning = false;
|
||||
m_process.close();
|
||||
|
||||
if (!m_queue.isEmpty())
|
||||
checkQueued();
|
||||
|
@@ -26,12 +26,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <utils/filepath.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
|
||||
#include <QHash>
|
||||
#include <QTimer>
|
||||
|
||||
namespace Utils { class QtcProcess; }
|
||||
|
||||
namespace Cppcheck {
|
||||
namespace Internal {
|
||||
|
||||
@@ -58,18 +57,16 @@ private:
|
||||
void checkQueued();
|
||||
void readOutput();
|
||||
void readError();
|
||||
void handleStarted();
|
||||
void handleFinished();
|
||||
void handleDone();
|
||||
|
||||
CppcheckTool &m_tool;
|
||||
Utils::QtcProcess *m_process = nullptr;
|
||||
Utils::QtcProcess m_process;
|
||||
Utils::FilePath m_binary;
|
||||
QString m_arguments;
|
||||
QHash<QString, Utils::FilePaths> m_queue;
|
||||
Utils::FilePaths m_currentFiles;
|
||||
QTimer m_queueTimer;
|
||||
int m_maxArgumentsLength = 32767;
|
||||
bool m_isRunning = false;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
Reference in New Issue
Block a user