From f8c4354d2e29fbebab2129b2e4b446fc439a633c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 18 Jan 2023 17:32:14 +0100 Subject: [PATCH] Cleanup *.ctu-info files that are not needed anymore after analysis --- gui/checkthread.cpp | 11 ++++------- lib/cppcheck.cpp | 15 ++++++++++++++- lib/cppcheck.h | 3 +++ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/gui/checkthread.cpp b/gui/checkthread.cpp index d46a75f88..14fd14bf2 100644 --- a/gui/checkthread.cpp +++ b/gui/checkthread.cpp @@ -108,13 +108,10 @@ void CheckThread::run() if (!mFiles.isEmpty() || mAnalyseWholeProgram) { mAnalyseWholeProgram = false; qDebug() << "Whole program analysis"; - const std::string &buildDir = mCppcheck.settings().buildDir; - if (!buildDir.empty()) { - std::map files2; - for (const QString& file : mFiles) - files2[file.toStdString()] = 0; - mCppcheck.analyseWholeProgram(buildDir, files2); - } + std::map files2; + for (const QString& file : mFiles) + files2[file.toStdString()] = 0; + mCppcheck.analyseWholeProgram(mCppcheck.settings().buildDir, files2); mFiles.clear(); emit done(); return; diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 58c4fa719..0cf3635d0 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -1759,8 +1759,10 @@ bool CppCheck::analyseWholeProgram() void CppCheck::analyseWholeProgram(const std::string &buildDir, const std::map &files) { executeAddonsWholeProgram(files); - if (buildDir.empty()) + if (buildDir.empty()) { + removeCtuInfoFiles(files); return; + } if (mSettings.checks.isEnabled(Checks::unusedFunction)) CheckUnusedFunctions::analyseWholeProgram(this, buildDir); std::list fileInfoList; @@ -1821,3 +1823,14 @@ bool CppCheck::isUnusedFunctionCheckEnabled() const { return (mSettings.jobs == 1 && mSettings.checks.isEnabled(Checks::unusedFunction)); } + +void CppCheck::removeCtuInfoFiles(const std::map &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()); + } + } +} diff --git a/lib/cppcheck.h b/lib/cppcheck.h index 5889b63dd..fe9c8187c 100644 --- a/lib/cppcheck.h +++ b/lib/cppcheck.h @@ -145,6 +145,9 @@ public: * and if it's possible at all */ bool isUnusedFunctionCheckEnabled() const; + /** Remove *.ctu-info files */ + void removeCtuInfoFiles(const std::map& files); + private: /** Are there "simple" rules */ bool hasRule(const std::string &tokenlist) const;