Cleanup *.ctu-info files that are not needed anymore after analysis

This commit is contained in:
Daniel Marjamäki 2023-01-18 17:32:14 +01:00
parent 7515305581
commit f8c4354d2e
3 changed files with 21 additions and 8 deletions

View File

@ -108,13 +108,10 @@ void CheckThread::run()
if (!mFiles.isEmpty() || mAnalyseWholeProgram) { if (!mFiles.isEmpty() || mAnalyseWholeProgram) {
mAnalyseWholeProgram = false; mAnalyseWholeProgram = false;
qDebug() << "Whole program analysis"; qDebug() << "Whole program analysis";
const std::string &buildDir = mCppcheck.settings().buildDir; std::map<std::string,std::size_t> files2;
if (!buildDir.empty()) { for (const QString& file : mFiles)
std::map<std::string,std::size_t> files2; files2[file.toStdString()] = 0;
for (const QString& file : mFiles) mCppcheck.analyseWholeProgram(mCppcheck.settings().buildDir, files2);
files2[file.toStdString()] = 0;
mCppcheck.analyseWholeProgram(buildDir, files2);
}
mFiles.clear(); mFiles.clear();
emit done(); emit done();
return; return;

View File

@ -1759,8 +1759,10 @@ bool CppCheck::analyseWholeProgram()
void CppCheck::analyseWholeProgram(const std::string &buildDir, const std::map<std::string, std::size_t> &files) void CppCheck::analyseWholeProgram(const std::string &buildDir, const std::map<std::string, std::size_t> &files)
{ {
executeAddonsWholeProgram(files); executeAddonsWholeProgram(files);
if (buildDir.empty()) if (buildDir.empty()) {
removeCtuInfoFiles(files);
return; return;
}
if (mSettings.checks.isEnabled(Checks::unusedFunction)) if (mSettings.checks.isEnabled(Checks::unusedFunction))
CheckUnusedFunctions::analyseWholeProgram(this, buildDir); CheckUnusedFunctions::analyseWholeProgram(this, buildDir);
std::list<Check::FileInfo*> fileInfoList; std::list<Check::FileInfo*> fileInfoList;
@ -1821,3 +1823,14 @@ bool CppCheck::isUnusedFunctionCheckEnabled() const
{ {
return (mSettings.jobs == 1 && mSettings.checks.isEnabled(Checks::unusedFunction)); return (mSettings.jobs == 1 && mSettings.checks.isEnabled(Checks::unusedFunction));
} }
void CppCheck::removeCtuInfoFiles(const std::map<std::string, std::size_t> &files)
{
if (mSettings.buildDir.empty()) {
for (const auto& f: files) {
const std::string &dumpFileName = getDumpFileName(mSettings, f.first);
const std::string &ctuInfoFileName = getCtuInfoFileName(dumpFileName);
std::remove(ctuInfoFileName.c_str());
}
}
}

View File

@ -145,6 +145,9 @@ public:
* and if it's possible at all */ * and if it's possible at all */
bool isUnusedFunctionCheckEnabled() const; bool isUnusedFunctionCheckEnabled() const;
/** Remove *.ctu-info files */
void removeCtuInfoFiles(const std::map<std::string, std::size_t>& files);
private: private:
/** Are there "simple" rules */ /** Are there "simple" rules */
bool hasRule(const std::string &tokenlist) const; bool hasRule(const std::string &tokenlist) const;