diff --git a/gui/checkthread.cpp b/gui/checkthread.cpp index d8ecca8b1c3..06821c0b136 100644 --- a/gui/checkthread.cpp +++ b/gui/checkthread.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -106,15 +107,13 @@ int CheckThread::executeCommand(std::string exe, std::vector args, CheckThread::CheckThread(ThreadResult &result) : - mResult(result), - mCppcheck(result, true, executeCommand) + mResult(result) {} -void CheckThread::check(const Settings &settings) +void CheckThread::setSettings(const Settings &settings) { mFiles.clear(); - mCppcheck.settings() = settings; - start(); + mSettings = settings; // this is a copy } void CheckThread::analyseWholeProgram(const QStringList &files, const std::string& ctuInfo) @@ -130,6 +129,9 @@ void CheckThread::run() { mState = Running; + CppCheck cppcheck(mResult, true, executeCommand); + cppcheck.settings() = std::move(mSettings); + if (!mFiles.isEmpty() || mAnalyseWholeProgram) { mAnalyseWholeProgram = false; std::string ctuInfo; @@ -139,7 +141,7 @@ void CheckThread::run() std::transform(mFiles.cbegin(), mFiles.cend(), std::back_inserter(files2), [&](const QString& file) { return FileWithDetails{file.toStdString(), 0}; }); - mCppcheck.analyseWholeProgram(mCppcheck.settings().buildDir, files2, {}, ctuInfo); + cppcheck.analyseWholeProgram(cppcheck.settings().buildDir, files2, {}, ctuInfo); mFiles.clear(); emit done(); return; @@ -148,8 +150,8 @@ void CheckThread::run() QString file = mResult.getNextFile(); while (!file.isEmpty() && mState == Running) { qDebug() << "Checking file" << file; - mCppcheck.check(FileWithDetails(file.toStdString())); - runAddonsAndTools(nullptr, file); + cppcheck.check(FileWithDetails(file.toStdString())); + runAddonsAndTools(cppcheck.settings(), nullptr, file); emit fileChecked(file); if (mState == Running) @@ -161,8 +163,8 @@ void CheckThread::run() while (fileSettings && mState == Running) { file = QString::fromStdString(fileSettings->filename()); qDebug() << "Checking file" << file; - mCppcheck.check(*fileSettings); - runAddonsAndTools(fileSettings, QString::fromStdString(fileSettings->filename())); + cppcheck.check(*fileSettings); + runAddonsAndTools(cppcheck.settings(), fileSettings, QString::fromStdString(fileSettings->filename())); emit fileChecked(file); if (mState == Running) @@ -177,7 +179,7 @@ void CheckThread::run() emit done(); } -void CheckThread::runAddonsAndTools(const FileSettings *fileSettings, const QString &fileName) +void CheckThread::runAddonsAndTools(const Settings& settings, const FileSettings *fileSettings, const QString &fileName) { for (const QString& addon : mAddonsAndTools) { if (addon == CLANG_ANALYZER || addon == CLANG_TIDY) { @@ -229,7 +231,7 @@ void CheckThread::runAddonsAndTools(const FileSettings *fileSettings, const QStr args << ("-std=" + QString::fromStdString(fileSettings->standard)); else { // TODO: pass C or C++ standard based on file type - const std::string std = mCppcheck.settings().standards.getCPP(); + const std::string std = settings.standards.getCPP(); if (!std.empty()) { args << ("-std=" + QString::fromStdString(std)); } @@ -237,7 +239,7 @@ void CheckThread::runAddonsAndTools(const FileSettings *fileSettings, const QStr QString analyzerInfoFile; - const std::string &buildDir = mCppcheck.settings().buildDir; + const std::string &buildDir = settings.buildDir; if (!buildDir.empty()) { analyzerInfoFile = QString::fromStdString(AnalyzerInformation::getAnalyzerInfoFile(buildDir, fileSettings->filename(), fileSettings->cfg)); diff --git a/gui/checkthread.h b/gui/checkthread.h index 2b2c0a5a4d0..9dcf3cc98b5 100644 --- a/gui/checkthread.h +++ b/gui/checkthread.h @@ -20,7 +20,7 @@ #ifndef CHECKTHREAD_H #define CHECKTHREAD_H -#include "cppcheck.h" +#include "settings.h" #include "suppressions.h" #include @@ -34,7 +34,6 @@ #include #include -class Settings; class ThreadResult; struct FileSettings; @@ -55,7 +54,7 @@ class CheckThread : public QThread { * * @param settings settings for cppcheck */ - void check(const Settings &settings); + void setSettings(const Settings &settings); /** * @brief Run whole program analysis @@ -130,13 +129,11 @@ class CheckThread : public QThread { std::atomic mState{Ready}; ThreadResult &mResult; - /** - * @brief Cppcheck itself - */ - CppCheck mCppcheck; + + Settings mSettings; private: - void runAddonsAndTools(const FileSettings *fileSettings, const QString &fileName); + void runAddonsAndTools(const Settings& settings, const FileSettings *fileSettings, const QString &fileName); void parseClangErrors(const QString &tool, const QString &file0, QString err); diff --git a/gui/threadhandler.cpp b/gui/threadhandler.cpp index 1ed363eda96..8fb78011f7c 100644 --- a/gui/threadhandler.cpp +++ b/gui/threadhandler.cpp @@ -109,7 +109,8 @@ void ThreadHandler::check(const Settings &settings) mThreads[i]->setAddonsAndTools(addonsAndTools); mThreads[i]->setSuppressions(mSuppressions); mThreads[i]->setClangIncludePaths(mClangIncludePaths); - mThreads[i]->check(settings); + mThreads[i]->setSettings(settings); + mThreads[i]->start(); } // Date and time when checking starts.. diff --git a/gui/threadhandler.h b/gui/threadhandler.h index addd270391a..22b3350374a 100644 --- a/gui/threadhandler.h +++ b/gui/threadhandler.h @@ -24,6 +24,7 @@ #include "threadresult.h" #include +#include #include #include