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,18 +53,48 @@ 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
61- std::string AnalyzerInformation::getFilesTxt (const std::list<std::string> &sourcefiles, const std::list<FileSettings> &fileSettings) {
95+ std::string AnalyzerInformation::getFilesTxt (const std::list<std::string> &sourcefiles, const std::list<FileSettings> &fileSettings, std::map<std::string, unsigned int > fileCount ) {
6296 std::ostringstream ret;
6397
64- std::map<std::string, unsigned int > fileCount;
65-
6698 for (const std::string &f : sourcefiles) {
6799 const std::string afile = getFilename (f);
68100 ret << afile << " .a" << (++fileCount[afile]) << sep << sep << sep << Path::simplifyPath (f) << ' \n ' ;
0 commit comments