Skip to content

Commit bbf5ae5

Browse files
committed
index files in files.txt by FileSettings::hash
1 parent 65cc0c8 commit bbf5ae5

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed

lib/analyzerinfo.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void AnalyzerInformation::writeFilesTxt(const std::string &buildDir, const std::
6060

6161
for (const FileSettings &fs : fileSettings) {
6262
const std::string afile = getFilename(fs.filename());
63-
fout << afile << ".a" << (++fileCount[afile]) << ":" << fs.cfg << ":" << Path::simplifyPath(fs.filename()) << std::endl;
63+
fout << afile << ".a" << (++fileCount[afile]) << ":" << std::hex << fs.hash << ":" << Path::simplifyPath(fs.filename()) << std::endl;
6464
}
6565
}
6666

@@ -73,7 +73,7 @@ void AnalyzerInformation::close()
7373
}
7474
}
7575

76-
static bool skipAnalysis(const std::string &analyzerInfoFile, std::size_t hash, std::list<ErrorMessage> &errors)
76+
static bool skipAnalysis(const std::string &analyzerInfoFile, std::size_t filehash, std::list<ErrorMessage> &errors)
7777
{
7878
tinyxml2::XMLDocument doc;
7979
const tinyxml2::XMLError error = doc.LoadFile(analyzerInfoFile.c_str());
@@ -85,7 +85,7 @@ static bool skipAnalysis(const std::string &analyzerInfoFile, std::size_t hash,
8585
return false;
8686

8787
const char *attr = rootNode->Attribute("hash");
88-
if (!attr || attr != std::to_string(hash))
88+
if (!attr || attr != std::to_string(filehash))
8989
return false;
9090

9191
for (const tinyxml2::XMLElement *e = rootNode->FirstChildElement(); e; e = e->NextSiblingElement()) {
@@ -96,10 +96,10 @@ static bool skipAnalysis(const std::string &analyzerInfoFile, std::size_t hash,
9696
return true;
9797
}
9898

99-
std::string AnalyzerInformation::getAnalyzerInfoFileFromFilesTxt(std::istream& filesTxt, const std::string &sourcefile, const std::string &cfg)
99+
std::string AnalyzerInformation::getAnalyzerInfoFileFromFilesTxt(std::istream& filesTxt, const std::string &sourcefile, const std::string &cfghash)
100100
{
101101
std::string line;
102-
const std::string end(':' + cfg + ':' + Path::simplifyPath(sourcefile));
102+
const std::string end(':' + cfghash + ':' + Path::simplifyPath(sourcefile));
103103
while (std::getline(filesTxt,line)) {
104104
if (line.size() <= end.size() + 2U)
105105
continue;
@@ -110,11 +110,11 @@ std::string AnalyzerInformation::getAnalyzerInfoFileFromFilesTxt(std::istream& f
110110
return "";
111111
}
112112

113-
std::string AnalyzerInformation::getAnalyzerInfoFile(const std::string &buildDir, const std::string &sourcefile, const std::string &cfg)
113+
std::string AnalyzerInformation::getAnalyzerInfoFile(const std::string &buildDir, const std::string &sourcefile, const std::string &cfghash)
114114
{
115115
std::ifstream fin(Path::join(buildDir, "files.txt"));
116116
if (fin.is_open()) {
117-
const std::string& ret = getAnalyzerInfoFileFromFilesTxt(fin, sourcefile, cfg);
117+
const std::string& ret = getAnalyzerInfoFileFromFilesTxt(fin, sourcefile, cfghash);
118118
if (!ret.empty())
119119
return Path::join(buildDir, ret);
120120
}
@@ -128,21 +128,21 @@ std::string AnalyzerInformation::getAnalyzerInfoFile(const std::string &buildDir
128128
return Path::join(buildDir, filename) + ".analyzerinfo";
129129
}
130130

131-
bool AnalyzerInformation::analyzeFile(const std::string &buildDir, const std::string &sourcefile, const std::string &cfg, std::size_t hash, std::list<ErrorMessage> &errors)
131+
bool AnalyzerInformation::analyzeFile(const std::string &buildDir, const std::string &sourcefile, const std::string &cfgHash, std::size_t fileHash, std::list<ErrorMessage> &errors)
132132
{
133133
if (buildDir.empty() || sourcefile.empty())
134134
return true;
135135
close();
136136

137-
mAnalyzerInfoFile = AnalyzerInformation::getAnalyzerInfoFile(buildDir,sourcefile,cfg);
137+
mAnalyzerInfoFile = AnalyzerInformation::getAnalyzerInfoFile(buildDir,sourcefile,cfgHash);
138138

139-
if (skipAnalysis(mAnalyzerInfoFile, hash, errors))
139+
if (skipAnalysis(mAnalyzerInfoFile, fileHash, errors))
140140
return false;
141141

142142
mOutputStream.open(mAnalyzerInfoFile);
143143
if (mOutputStream.is_open()) {
144144
mOutputStream << "<?xml version=\"1.0\"?>\n";
145-
mOutputStream << "<analyzerinfo hash=\"" << hash << "\">\n";
145+
mOutputStream << "<analyzerinfo hash=\"" << fileHash << "\">\n";
146146
} else {
147147
mAnalyzerInfoFile.clear();
148148
}

lib/analyzerinfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class CPPCHECKLIB AnalyzerInformation {
5555

5656
/** Close current TU.analyzerinfo file */
5757
void close();
58-
bool analyzeFile(const std::string &buildDir, const std::string &sourcefile, const std::string &cfg, std::size_t hash, std::list<ErrorMessage> &errors);
58+
bool analyzeFile(const std::string &buildDir, const std::string &sourcefile, const std::string &cfgHash, std::size_t fileHash, std::list<ErrorMessage> &errors);
5959
void reportErr(const ErrorMessage &msg);
6060
void setFileInfo(const std::string &check, const std::string &fileInfo);
6161
static std::string getAnalyzerInfoFile(const std::string &buildDir, const std::string &sourcefile, const std::string &cfg);

lib/cppcheck.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ unsigned int CppCheck::check(const FileWithDetails &file)
775775
unsigned int CppCheck::check(const FileWithDetails &file, const std::string &content)
776776
{
777777
std::istringstream iss(content);
778-
return checkFile(file, "", &iss);
778+
return checkFile(file, "", "", &iss);
779779
}
780780

781781
unsigned int CppCheck::check(const FileSettings &fs)
@@ -811,7 +811,9 @@ unsigned int CppCheck::check(const FileSettings &fs)
811811
}
812812
// need to pass the externally provided ErrorLogger instead of our internal wrapper
813813
CppCheck temp(tempSettings, mSuppressions, mErrorLoggerDirect, mUseGlobalSuppressions, mExecuteCommand);
814-
const unsigned int returnValue = temp.checkFile(fs.file, fs.cfg);
814+
std::stringstream hash;
815+
hash << std::hex << fs.hash;
816+
const unsigned int returnValue = temp.checkFile(fs.file, fs.cfg, hash.str());
815817
if (mUnusedFunctionsCheck)
816818
mUnusedFunctionsCheck->updateFunctionData(*temp.mUnusedFunctionsCheck);
817819
while (!temp.mFileInfo.empty()) {
@@ -846,7 +848,7 @@ static std::size_t calculateHash(const Preprocessor& preprocessor, const simplec
846848
return preprocessor.calculateHash(tokens, toolinfo.str());
847849
}
848850

849-
unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string &cfgname, std::istream* fileStream)
851+
unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string &cfgname, std::string cfgHash, std::istream* fileStream)
850852
{
851853
// TODO: move to constructor when CppCheck no longer owns the settings
852854
if (mSettings.checks.isEnabled(Checks::unusedFunction) && !mUnusedFunctionsCheck)
@@ -995,9 +997,9 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
995997

996998
if (analyzerInformation) {
997999
// Calculate hash so it can be compared with old hash / future hashes
998-
const std::size_t hash = calculateHash(preprocessor, tokens1, mSettings, mSuppressions);
1000+
const std::size_t fileHash = calculateHash(preprocessor, tokens1, mSettings, mSuppressions);
9991001
std::list<ErrorMessage> errors;
1000-
if (!analyzerInformation->analyzeFile(mSettings.buildDir, file.spath(), cfgname, hash, errors)) {
1002+
if (!analyzerInformation->analyzeFile(mSettings.buildDir, file.spath(), cfgHash, fileHash, errors)) {
10011003
while (!errors.empty()) {
10021004
mErrorLogger.reportErr(errors.front());
10031005
errors.pop_front();
@@ -1794,7 +1796,9 @@ void CppCheck::executeAddonsWholeProgram(const std::list<FileWithDetails> &files
17941796
}
17951797

17961798
for (const auto &f: fileSettings) {
1797-
const std::string &dumpFileName = getDumpFileName(mSettings, f.filename());
1799+
std::stringstream hash;
1800+
hash << std::hex << f.hash;
1801+
const std::string &dumpFileName = getDumpFileName(mSettings, f.filename(), hash.str());
17981802
ctuInfoFiles.push_back(getCtuInfoFileName(dumpFileName));
17991803
}
18001804

lib/cppcheck.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ class CPPCHECKLIB CppCheck {
174174
* @param fileStream stream the file content can be read from
175175
* @return number of errors found
176176
*/
177-
unsigned int checkFile(const FileWithDetails& file, const std::string &cfgname, std::istream* fileStream = nullptr);
177+
unsigned int checkFile(const FileWithDetails& file, const std::string &cfgname, std::string cfgHash = "", std::istream* fileStream = nullptr);
178178

179179
/**
180180
* @brief Check normal tokens

0 commit comments

Comments
 (0)