summaryrefslogtreecommitdiff
path: root/src/plugins/cppcheck/cppcheckrunner.cpp
diff options
context:
space:
mode:
authorJarek Kobus <jaroslaw.kobus@qt.io>2022-06-20 17:23:57 +0200
committerJarek Kobus <jaroslaw.kobus@qt.io>2022-06-21 08:16:58 +0000
commit64d52bb8c3af044f0df972068a715bd1d3b70166 (patch)
tree4b05b4f0cf134f4e232b80ca06ec86a7aa254cb9 /src/plugins/cppcheck/cppcheckrunner.cpp
parent8e22e08d21224205dbe4f34971d4a7364f69453a (diff)
downloadqt-creator-64d52bb8c3af044f0df972068a715bd1d3b70166.tar.gz
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>
Diffstat (limited to 'src/plugins/cppcheck/cppcheckrunner.cpp')
-rw-r--r--src/plugins/cppcheck/cppcheckrunner.cpp68
1 files changed, 26 insertions, 42 deletions
diff --git a/src/plugins/cppcheck/cppcheckrunner.cpp b/src/plugins/cppcheck/cppcheckrunner.cpp
index 4e4e3d4052..542631beb7 100644
--- a/src/plugins/cppcheck/cppcheckrunner.cpp
+++ b/src/plugins/cppcheck/cppcheckrunner.cpp
@@ -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();