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;
if (settings.useSingleJob()) {
// Single process
SingleExecutor executor(cppcheck, mFiles, settings, *this);
SingleExecutor executor(cppcheck, mFiles, settings, settings.nomsg, *this);
returnValue = executor.check();
} else {
#if defined(THREADING_MODEL_THREAD)
ThreadExecutor executor(mFiles, settings, *this);
ThreadExecutor executor(mFiles, settings, settings.nomsg, *this);
#elif defined(THREADING_MODEL_FORK)
ProcessExecutor executor(mFiles, settings, *this);
ProcessExecutor executor(mFiles, settings, settings.nomsg, *this);
#endif
returnValue = executor.check();
}

View File

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

View File

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

View File

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

View File

@ -27,6 +27,7 @@
class Settings;
class ErrorLogger;
class Suppressions;
/// @addtogroup CLI
/// @{
@ -37,7 +38,7 @@ class ErrorLogger;
*/
class ProcessExecutor : public Executor {
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() override;
void operator=(const ProcessExecutor &) = delete;

View File

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

View File

@ -28,11 +28,12 @@
class ErrorLogger;
class Settings;
class CppCheck;
class Suppressions;
class SingleExecutor : public Executor
{
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() override;
void operator=(const SingleExecutor &) = delete;

View File

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

View File

@ -27,6 +27,7 @@
class Settings;
class ErrorLogger;
class Suppressions;
/// @addtogroup CLI
/// @{
@ -37,7 +38,7 @@ class ErrorLogger;
*/
class ThreadExecutor : public Executor {
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() override;
void operator=(const ThreadExecutor &) = delete;

View File

@ -82,7 +82,7 @@ private:
if (opt.plistOutput)
settings.plistOutput = opt.plistOutput;
// 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;
scopedfiles.reserve(filemap.size());
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();
// 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());
}

View File

@ -206,7 +206,7 @@ private:
if (!suppression.empty()) {
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;
scopedfiles.reserve(files.size());
for (std::map<std::string, std::string>::const_iterator i = f.cbegin(); i != f.cend(); ++i)
@ -233,7 +233,7 @@ private:
if (!suppression.empty()) {
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;
scopedfiles.reserve(files.size());
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()) {
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;
scopedfiles.reserve(files.size());
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)
settings1.plistOutput = opt.plistOutput;
// 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;
scopedfiles.reserve(filemap.size());
for (std::map<std::string, std::size_t>::const_iterator i = filemap.cbegin(); i != filemap.cend(); ++i)