Skip to content

Commit e92b2c7

Browse files
committed
small fix
1 parent 67ba67a commit e92b2c7

3 files changed

Lines changed: 42 additions & 9 deletions

File tree

‎gui/mainwindow.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ void MainWindow::doAnalyzeProject(ImportProject p, const bool checkLib, const bo
630630
if (!checkSettings.buildDir.empty()) {
631631
checkSettings.loadSummaries();
632632
std::list<std::string> sourcefiles;
633-
AnalyzerInformation::writeFilesTxt(checkSettings.buildDir, sourcefiles, p.fileSettings);
633+
AnalyzerInformation::writeFilesTxt(checkSettings.buildDir, sourcefiles, p.fileSettings, !recheckFiles.isEmpty());
634634
}
635635

636636
//mThread->SetanalyzeProject(true);
@@ -708,7 +708,7 @@ void MainWindow::doAnalyzeFiles(const QStringList &files, const bool checkLib, c
708708
if (!checkSettings.buildDir.empty()) {
709709
checkSettings.loadSummaries();
710710
const auto& sourcefiles = toStdStringList<std::list<std::string>>(fileNames);
711-
AnalyzerInformation::writeFilesTxt(checkSettings.buildDir, sourcefiles, {});
711+
AnalyzerInformation::writeFilesTxt(checkSettings.buildDir, sourcefiles, {}, partialRecheck);
712712
}
713713

714714
mThread->setCheckFiles(true);

‎lib/analyzerinfo.cpp‎

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@
2424
#include "utils.h"
2525

2626
#include <array>
27+
#include <cstdlib>
2728
#include <cstring>
2829
#include <exception>
2930
#include <iostream>
3031
#include <map>
32+
#include <set>
3133
#include <sstream>
3234
#include <stdexcept>
3335
#include <utility>
@@ -51,11 +53,43 @@ static std::string getFilename(const std::string &fullpath)
5153
return fullpath.substr(pos1,pos2);
5254
}
5355

54-
void AnalyzerInformation::writeFilesTxt(const std::string &buildDir, const std::list<std::string> &sourcefiles, const std::list<FileSettings> &fileSettings)
56+
void AnalyzerInformation::writeFilesTxt(const std::string &buildDir, const std::list<std::string> &sourcefiles, const std::list<FileSettings> &fileSettings, bool merge)
5557
{
5658
const std::string filesTxt(buildDir + "/files.txt");
59+
60+
std::string keptLines;
61+
std::map<std::string, unsigned int> fileCount;
62+
63+
if (merge) {
64+
std::set<std::string> current;
65+
for (const std::string &f : sourcefiles)
66+
current.insert(Path::simplifyPath(f));
67+
for (const FileSettings &fs : fileSettings)
68+
current.insert(Path::simplifyPath(fs.filename()));
69+
70+
std::ifstream fin(filesTxt);
71+
std::string line;
72+
while (std::getline(fin, line)) {
73+
Info info;
74+
if (!info.parse(line))
75+
continue;
76+
if (current.count(info.sourceFile))
77+
continue;
78+
keptLines += line + '\n';
79+
80+
const std::string::size_type dotA = info.afile.rfind(".a");
81+
if (dotA != std::string::npos) {
82+
const std::string base = info.afile.substr(0, dotA);
83+
const unsigned int n = std::strtoul(info.afile.c_str() + dotA + 2, nullptr, 10);
84+
unsigned int &count = fileCount[base];
85+
count = std::max(count, n);
86+
}
87+
}
88+
}
89+
5790
std::ofstream fout(filesTxt);
58-
fout << getFilesTxt(sourcefiles, fileSettings);
91+
fout << keptLines;
92+
fout << getFilesTxt(sourcefiles, fileSettings, fileCount);
5993
}
6094

6195
void AnalyzerInformation::writeIncludes(const std::set<std::string> &files)
@@ -120,11 +154,9 @@ void AnalyzerInformation::writeHash(std::size_t hash)
120154
}
121155
}
122156

123-
std::string AnalyzerInformation::getFilesTxt(const std::list<std::string> &sourcefiles, const std::list<FileSettings> &fileSettings) {
157+
std::string AnalyzerInformation::getFilesTxt(const std::list<std::string> &sourcefiles, const std::list<FileSettings> &fileSettings, std::map<std::string, unsigned int> fileCount) {
124158
std::ostringstream ret;
125159

126-
std::map<std::string, unsigned int> fileCount;
127-
128160
for (const std::string &f : sourcefiles) {
129161
const std::string afile = getFilename(f);
130162
ret << afile << ".a" << (++fileCount[afile]) << sep << sep << sep << Path::simplifyPath(f) << '\n';

‎lib/analyzerinfo.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <fstream>
2828
#include <functional>
2929
#include <list>
30+
#include <map>
3031
#include <set>
3132
#include <string>
3233

@@ -58,7 +59,7 @@ class CPPCHECKLIB AnalyzerInformation {
5859
public:
5960
~AnalyzerInformation();
6061

61-
static void writeFilesTxt(const std::string &buildDir, const std::list<std::string> &sourcefiles, const std::list<FileSettings> &fileSettings);
62+
static void writeFilesTxt(const std::string &buildDir, const std::list<std::string> &sourcefiles, const std::list<FileSettings> &fileSettings, bool merge = false);
6263

6364
/** Close current TU.analyzerinfo file */
6465
void close();
@@ -89,7 +90,7 @@ class CPPCHECKLIB AnalyzerInformation {
8990
static std::string processFilesTxt(const std::string& buildDir, const std::function<void(const char* checkattr, const tinyxml2::XMLElement* e, const Info& filesTxtInfo)>& handler, bool debug = false);
9091

9192
protected:
92-
static std::string getFilesTxt(const std::list<std::string> &sourcefiles, const std::list<FileSettings> &fileSettings);
93+
static std::string getFilesTxt(const std::list<std::string> &sourcefiles, const std::list<FileSettings> &fileSettings, std::map<std::string, unsigned int> fileCount = {});
9394

9495
static std::string getAnalyzerInfoFileFromFilesTxt(std::istream& filesTxt, const std::string &sourcefile, const std::string &cfg, size_t fsFileId);
9596

0 commit comments

Comments
 (0)