Skip to content

Commit a5bc2f9

Browse files
authored
fixed #13388 - store active checkers in build dir (#7852)
1 parent 1a226cb commit a5bc2f9

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

cli/cppcheckexecutor.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,9 @@ namespace {
259259
if (!mSettings.outputFile.empty()) {
260260
mErrorOutput = new std::ofstream(settings.outputFile);
261261
}
262+
if (!mSettings.buildDir.empty()) {
263+
mCheckersFile = Path::join(settings.buildDir, "checkers.txt");
264+
}
262265
}
263266

264267
~StdLogger() override {
@@ -311,6 +314,25 @@ namespace {
311314
return mCtuInfo;
312315
}
313316

317+
void readActiveCheckers() {
318+
if (mCheckersFile.empty())
319+
return;
320+
321+
std::ifstream fin(mCheckersFile);
322+
if (fin.is_open())
323+
{
324+
std::set<std::string> activeCheckers;
325+
std::string line;
326+
// cppcheck-suppress accessMoved - FP
327+
while (std::getline(fin, line))
328+
{
329+
// cppcheck-suppress accessMoved - FP
330+
activeCheckers.emplace(std::move(line));
331+
}
332+
mActiveCheckers = std::move(activeCheckers);
333+
}
334+
}
335+
314336
private:
315337
/**
316338
* Information about progress is directed here. This should be
@@ -375,6 +397,11 @@ namespace {
375397
* File metrics
376398
*/
377399
std::vector<std::string> mFileMetrics;
400+
401+
/**
402+
* The file the cached active checkers are stored in
403+
*/
404+
std::string mCheckersFile;
378405
};
379406
}
380407

@@ -465,6 +492,8 @@ int CppCheckExecutor::check_internal(const Settings& settings, Suppressions& sup
465492
for (auto i = mFiles.cbegin(); i != mFiles.cend(); ++i)
466493
fileNames.emplace_back(i->path());
467494
AnalyzerInformation::writeFilesTxt(settings.buildDir, fileNames, settings.userDefines, mFileSettings);
495+
496+
stdLogger.readActiveCheckers();
468497
}
469498

470499
if (!settings.checkersReportFilename.empty())
@@ -522,6 +551,15 @@ int CppCheckExecutor::check_internal(const Settings& settings, Suppressions& sup
522551

523552
void StdLogger::writeCheckersReport(const Suppressions& supprs)
524553
{
554+
if (!mCheckersFile.empty())
555+
{
556+
std::ofstream fout(mCheckersFile);
557+
for (const auto& c : mActiveCheckers)
558+
{
559+
fout << c << std::endl;
560+
}
561+
}
562+
525563
const bool summary = mSettings.safety || mSettings.severity.isEnabled(Severity::information);
526564
const bool xmlReport = mSettings.outputFormat == Settings::OutputFormat::xml && mSettings.xml_version == 3;
527565
const bool textReport = !mSettings.checkersReportFilename.empty();

0 commit comments

Comments
 (0)