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