Skip to content

Commit 7d7212c

Browse files
committed
--cppcheck-build-dir: generate unique analyzeinfo filenames when source files have same names
1 parent 3b57273 commit 7d7212c

3 files changed

Lines changed: 29 additions & 2 deletions

File tree

cli/cmdlineparser.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,11 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
120120
return true;
121121
}
122122

123-
else if (std::strncmp(argv[i], "--cppcheck-build-dir=", 21) == 0)
124-
_settings->buildDir = argv[i] + 21;
123+
else if (std::strncmp(argv[i], "--cppcheck-build-dir=", 21) == 0) {
124+
_settings->buildDir = Path::fromNativeSeparators(argv[i] + 21);
125+
if (_settings->buildDir.back() == '/')
126+
_settings->buildDir.erase(_settings->buildDir.size() - 1U);
127+
}
125128

126129
// Flag used for various purposes during debugging
127130
else if (std::strcmp(argv[i], "--debug") == 0)

cli/cppcheckexecutor.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,14 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck, int /*argc*/, const cha
802802
reportErr(ErrorLogger::ErrorMessage::getXMLHeader(settings.xml_version));
803803
}
804804

805+
if (!settings.buildDir.empty()) {
806+
const std::string filename(settings.buildDir + "/files.txt");
807+
std::ofstream fout(filename.c_str());
808+
for (std::map<std::string, std::size_t>::const_iterator f = _files.begin(); f != _files.end(); ++f) {
809+
fout << f->first << '\n';
810+
}
811+
}
812+
805813
unsigned int returnValue = 0;
806814
if (settings.jobs == 1) {
807815
// Single process

lib/analyzerinfo.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "analyzerinfo.h"
2020
#include "path.h"
2121
#include <tinyxml2.h>
22+
#include <sstream>
2223

2324
AnalyzerInformation::AnalyzerInformation() {}
2425
AnalyzerInformation::~AnalyzerInformation()
@@ -60,6 +61,21 @@ static bool skipAnalysis(const std::string &analyzerInfoFile, unsigned long long
6061

6162
std::string AnalyzerInformation::getAnalyzerInfoFile(const std::string &buildDir, const std::string &sourcefile)
6263
{
64+
const std::string files(buildDir + "/files.txt");
65+
std::ifstream fin(files.c_str());
66+
if (fin.is_open()) {
67+
int id = 1;
68+
std::string line;
69+
while (std::getline(fin,line)) {
70+
if (line == sourcefile) {
71+
std::ostringstream ostr;
72+
ostr << buildDir << '/' << id << ".analyzeinfo";
73+
return ostr.str();
74+
}
75+
id++;
76+
}
77+
}
78+
6379
std::string filename = Path::fromNativeSeparators(buildDir);
6480
if (filename.back() != '/')
6581
filename += '/';

0 commit comments

Comments
 (0)