pass `Suppressions` separately from `const Settings` into executors (#5278)

This commit is contained in:
Oliver Stöneberg 2023-08-07 18:39:57 +02:00 committed by GitHub
parent de8b4150a8
commit a17f6e89d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 29 additions and 24 deletions

View File

@ -285,13 +285,13 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck)
unsigned int returnValue = 0; unsigned int returnValue = 0;
if (settings.useSingleJob()) { if (settings.useSingleJob()) {
// Single process // Single process
SingleExecutor executor(cppcheck, mFiles, settings, *this); SingleExecutor executor(cppcheck, mFiles, settings, settings.nomsg, *this);
returnValue = executor.check(); returnValue = executor.check();
} else { } else {
#if defined(THREADING_MODEL_THREAD) #if defined(THREADING_MODEL_THREAD)
ThreadExecutor executor(mFiles, settings, *this); ThreadExecutor executor(mFiles, settings, settings.nomsg, *this);
#elif defined(THREADING_MODEL_FORK) #elif defined(THREADING_MODEL_FORK)
ProcessExecutor executor(mFiles, settings, *this); ProcessExecutor executor(mFiles, settings, settings.nomsg, *this);
#endif #endif
returnValue = executor.check(); returnValue = executor.check();
} }

View File

@ -27,8 +27,8 @@
#include <sstream> // IWYU pragma: keep #include <sstream> // IWYU pragma: keep
#include <utility> #include <utility>
Executor::Executor(const std::map<std::string, std::size_t> &files, Settings &settings, ErrorLogger &errorLogger) Executor::Executor(const std::map<std::string, std::size_t> &files, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger)
: mFiles(files), mSettings(settings), mErrorLogger(errorLogger) : mFiles(files), mSettings(settings), mSuppressions(suppressions), mErrorLogger(errorLogger)
{} {}
Executor::~Executor() Executor::~Executor()
@ -36,7 +36,7 @@ Executor::~Executor()
bool Executor::hasToLog(const ErrorMessage &msg) bool Executor::hasToLog(const ErrorMessage &msg)
{ {
if (!mSettings.nomsg.isSuppressed(msg)) if (!mSuppressions.isSuppressed(msg))
{ {
std::string errmsg = msg.toString(mSettings.verbose); std::string errmsg = msg.toString(mSettings.verbose);

View File

@ -28,6 +28,7 @@
class Settings; class Settings;
class ErrorLogger; class ErrorLogger;
class ErrorMessage; class ErrorMessage;
class Suppressions;
/// @addtogroup CLI /// @addtogroup CLI
/// @{ /// @{
@ -38,7 +39,7 @@ class ErrorMessage;
*/ */
class Executor { class Executor {
public: public:
Executor(const std::map<std::string, std::size_t> &files, Settings &settings, ErrorLogger &errorLogger); Executor(const std::map<std::string, std::size_t> &files, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger);
virtual ~Executor(); virtual ~Executor();
Executor(const Executor &) = delete; Executor(const Executor &) = delete;
@ -65,7 +66,8 @@ protected:
bool hasToLog(const ErrorMessage &msg); bool hasToLog(const ErrorMessage &msg);
const std::map<std::string, std::size_t> &mFiles; const std::map<std::string, std::size_t> &mFiles;
Settings &mSettings; const Settings &mSettings;
Suppressions &mSuppressions;
ErrorLogger &mErrorLogger; ErrorLogger &mErrorLogger;
private: private:

View File

@ -61,8 +61,8 @@ enum class Color;
using std::memset; using std::memset;
ProcessExecutor::ProcessExecutor(const std::map<std::string, std::size_t> &files, Settings &settings, ErrorLogger &errorLogger) ProcessExecutor::ProcessExecutor(const std::map<std::string, std::size_t> &files, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger)
: Executor(files, settings, errorLogger) : Executor(files, settings, suppressions, errorLogger)
{ {
assert(mSettings.jobs > 1); assert(mSettings.jobs > 1);
} }
@ -391,7 +391,7 @@ void ProcessExecutor::reportInternalChildErr(const std::string &childname, const
"cppcheckError", "cppcheckError",
Certainty::normal); Certainty::normal);
if (!mSettings.nomsg.isSuppressed(errmsg)) if (!mSuppressions.isSuppressed(errmsg))
mErrorLogger.reportErr(errmsg); mErrorLogger.reportErr(errmsg);
} }

View File

@ -27,6 +27,7 @@
class Settings; class Settings;
class ErrorLogger; class ErrorLogger;
class Suppressions;
/// @addtogroup CLI /// @addtogroup CLI
/// @{ /// @{
@ -37,7 +38,7 @@ class ErrorLogger;
*/ */
class ProcessExecutor : public Executor { class ProcessExecutor : public Executor {
public: public:
ProcessExecutor(const std::map<std::string, std::size_t> &files, Settings &settings, ErrorLogger &errorLogger); ProcessExecutor(const std::map<std::string, std::size_t> &files, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger);
ProcessExecutor(const ProcessExecutor &) = delete; ProcessExecutor(const ProcessExecutor &) = delete;
~ProcessExecutor() override; ~ProcessExecutor() override;
void operator=(const ProcessExecutor &) = delete; void operator=(const ProcessExecutor &) = delete;

View File

@ -30,8 +30,8 @@
class ErrorLogger; class ErrorLogger;
SingleExecutor::SingleExecutor(CppCheck &cppcheck, const std::map<std::string, std::size_t> &files, Settings &settings, ErrorLogger &errorLogger) SingleExecutor::SingleExecutor(CppCheck &cppcheck, const std::map<std::string, std::size_t> &files, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger)
: Executor(files, settings, errorLogger) : Executor(files, settings, suppressions, errorLogger)
, mCppcheck(cppcheck) , mCppcheck(cppcheck)
{ {
assert(mSettings.jobs == 1); assert(mSettings.jobs == 1);

View File

@ -28,11 +28,12 @@
class ErrorLogger; class ErrorLogger;
class Settings; class Settings;
class CppCheck; class CppCheck;
class Suppressions;
class SingleExecutor : public Executor class SingleExecutor : public Executor
{ {
public: public:
SingleExecutor(CppCheck &cppcheck, const std::map<std::string, std::size_t> &files, Settings &settings, ErrorLogger &errorLogger); SingleExecutor(CppCheck &cppcheck, const std::map<std::string, std::size_t> &files, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger);
SingleExecutor(const SingleExecutor &) = delete; SingleExecutor(const SingleExecutor &) = delete;
~SingleExecutor() override; ~SingleExecutor() override;
void operator=(const SingleExecutor &) = delete; void operator=(const SingleExecutor &) = delete;

View File

@ -40,8 +40,8 @@
enum class Color; enum class Color;
ThreadExecutor::ThreadExecutor(const std::map<std::string, std::size_t> &files, Settings &settings, ErrorLogger &errorLogger) ThreadExecutor::ThreadExecutor(const std::map<std::string, std::size_t> &files, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger)
: Executor(files, settings, errorLogger) : Executor(files, settings, suppressions, errorLogger)
{ {
assert(mSettings.jobs > 1); assert(mSettings.jobs > 1);
} }

View File

@ -27,6 +27,7 @@
class Settings; class Settings;
class ErrorLogger; class ErrorLogger;
class Suppressions;
/// @addtogroup CLI /// @addtogroup CLI
/// @{ /// @{
@ -37,7 +38,7 @@ class ErrorLogger;
*/ */
class ThreadExecutor : public Executor { class ThreadExecutor : public Executor {
public: public:
ThreadExecutor(const std::map<std::string, std::size_t> &files, Settings &settings, ErrorLogger &errorLogger); ThreadExecutor(const std::map<std::string, std::size_t> &files, const Settings &settings, Suppressions &suppressions, ErrorLogger &errorLogger);
ThreadExecutor(const ThreadExecutor &) = delete; ThreadExecutor(const ThreadExecutor &) = delete;
~ThreadExecutor() override; ~ThreadExecutor() override;
void operator=(const ThreadExecutor &) = delete; void operator=(const ThreadExecutor &) = delete;

View File

@ -82,7 +82,7 @@ private:
if (opt.plistOutput) if (opt.plistOutput)
settings.plistOutput = opt.plistOutput; settings.plistOutput = opt.plistOutput;
// TODO: test with settings.project.fileSettings; // TODO: test with settings.project.fileSettings;
ProcessExecutor executor(filemap, settings, *this); ProcessExecutor executor(filemap, settings, settings.nomsg, *this);
std::vector<std::unique_ptr<ScopedFile>> scopedfiles; std::vector<std::unique_ptr<ScopedFile>> scopedfiles;
scopedfiles.reserve(filemap.size()); scopedfiles.reserve(filemap.size());
for (std::map<std::string, std::size_t>::const_iterator i = filemap.cbegin(); i != filemap.cend(); ++i) for (std::map<std::string, std::size_t>::const_iterator i = filemap.cbegin(); i != filemap.cend(); ++i)

View File

@ -117,7 +117,7 @@ private:
filemap.clear(); filemap.clear();
// TODO: test with settings.project.fileSettings; // TODO: test with settings.project.fileSettings;
SingleExecutor executor(cppcheck, filemap, settings, *this); SingleExecutor executor(cppcheck, filemap, settings, settings.nomsg, *this);
ASSERT_EQUALS(result, executor.check()); ASSERT_EQUALS(result, executor.check());
} }

View File

@ -206,7 +206,7 @@ private:
if (!suppression.empty()) { if (!suppression.empty()) {
EXPECT_EQ("", settings.nomsg.addSuppressionLine(suppression)); EXPECT_EQ("", settings.nomsg.addSuppressionLine(suppression));
} }
SingleExecutor executor(cppCheck, files, settings, *this); SingleExecutor executor(cppCheck, files, settings, settings.nomsg, *this);
std::vector<std::unique_ptr<ScopedFile>> scopedfiles; std::vector<std::unique_ptr<ScopedFile>> scopedfiles;
scopedfiles.reserve(files.size()); scopedfiles.reserve(files.size());
for (std::map<std::string, std::string>::const_iterator i = f.cbegin(); i != f.cend(); ++i) for (std::map<std::string, std::string>::const_iterator i = f.cbegin(); i != f.cend(); ++i)
@ -233,7 +233,7 @@ private:
if (!suppression.empty()) { if (!suppression.empty()) {
EXPECT_EQ("", settings.nomsg.addSuppressionLine(suppression)); EXPECT_EQ("", settings.nomsg.addSuppressionLine(suppression));
} }
ThreadExecutor executor(files, settings, *this); ThreadExecutor executor(files, settings, settings.nomsg, *this);
std::vector<std::unique_ptr<ScopedFile>> scopedfiles; std::vector<std::unique_ptr<ScopedFile>> scopedfiles;
scopedfiles.reserve(files.size()); scopedfiles.reserve(files.size());
for (std::map<std::string, std::size_t>::const_iterator i = files.cbegin(); i != files.cend(); ++i) for (std::map<std::string, std::size_t>::const_iterator i = files.cbegin(); i != files.cend(); ++i)
@ -261,7 +261,7 @@ private:
if (!suppression.empty()) { if (!suppression.empty()) {
EXPECT_EQ("", settings.nomsg.addSuppressionLine(suppression)); EXPECT_EQ("", settings.nomsg.addSuppressionLine(suppression));
} }
ProcessExecutor executor(files, settings, *this); ProcessExecutor executor(files, settings, settings.nomsg, *this);
std::vector<std::unique_ptr<ScopedFile>> scopedfiles; std::vector<std::unique_ptr<ScopedFile>> scopedfiles;
scopedfiles.reserve(files.size()); scopedfiles.reserve(files.size());
for (std::map<std::string, std::size_t>::const_iterator i = files.cbegin(); i != files.cend(); ++i) for (std::map<std::string, std::size_t>::const_iterator i = files.cbegin(); i != files.cend(); ++i)

View File

@ -83,7 +83,7 @@ private:
if (opt.plistOutput) if (opt.plistOutput)
settings1.plistOutput = opt.plistOutput; settings1.plistOutput = opt.plistOutput;
// TODO: test with settings.project.fileSettings; // TODO: test with settings.project.fileSettings;
ThreadExecutor executor(filemap, settings1, *this); ThreadExecutor executor(filemap, settings1, settings1.nomsg, *this);
std::vector<std::unique_ptr<ScopedFile>> scopedfiles; std::vector<std::unique_ptr<ScopedFile>> scopedfiles;
scopedfiles.reserve(filemap.size()); scopedfiles.reserve(filemap.size());
for (std::map<std::string, std::size_t>::const_iterator i = filemap.cbegin(); i != filemap.cend(); ++i) for (std::map<std::string, std::size_t>::const_iterator i = filemap.cbegin(); i != filemap.cend(); ++i)