From 7d7212c4658e773edfec7116c5898548e423d1c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 14 Nov 2016 20:50:08 +0100 Subject: [PATCH] --cppcheck-build-dir: generate unique analyzeinfo filenames when source files have same names --- cli/cmdlineparser.cpp | 7 +++++-- cli/cppcheckexecutor.cpp | 8 ++++++++ lib/analyzerinfo.cpp | 16 ++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index f8e618fa8..9eac99066 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -120,8 +120,11 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[]) return true; } - else if (std::strncmp(argv[i], "--cppcheck-build-dir=", 21) == 0) - _settings->buildDir = argv[i] + 21; + else if (std::strncmp(argv[i], "--cppcheck-build-dir=", 21) == 0) { + _settings->buildDir = Path::fromNativeSeparators(argv[i] + 21); + if (_settings->buildDir.back() == '/') + _settings->buildDir.erase(_settings->buildDir.size() - 1U); + } // Flag used for various purposes during debugging else if (std::strcmp(argv[i], "--debug") == 0) diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index f3a94b1f9..400c3ed63 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -802,6 +802,14 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck, int /*argc*/, const cha reportErr(ErrorLogger::ErrorMessage::getXMLHeader(settings.xml_version)); } + if (!settings.buildDir.empty()) { + const std::string filename(settings.buildDir + "/files.txt"); + std::ofstream fout(filename.c_str()); + for (std::map::const_iterator f = _files.begin(); f != _files.end(); ++f) { + fout << f->first << '\n'; + } + } + unsigned int returnValue = 0; if (settings.jobs == 1) { // Single process diff --git a/lib/analyzerinfo.cpp b/lib/analyzerinfo.cpp index ba1d798ee..74522f4dd 100644 --- a/lib/analyzerinfo.cpp +++ b/lib/analyzerinfo.cpp @@ -19,6 +19,7 @@ #include "analyzerinfo.h" #include "path.h" #include +#include AnalyzerInformation::AnalyzerInformation() {} AnalyzerInformation::~AnalyzerInformation() @@ -60,6 +61,21 @@ static bool skipAnalysis(const std::string &analyzerInfoFile, unsigned long long std::string AnalyzerInformation::getAnalyzerInfoFile(const std::string &buildDir, const std::string &sourcefile) { + const std::string files(buildDir + "/files.txt"); + std::ifstream fin(files.c_str()); + if (fin.is_open()) { + int id = 1; + std::string line; + while (std::getline(fin,line)) { + if (line == sourcefile) { + std::ostringstream ostr; + ostr << buildDir << '/' << id << ".analyzeinfo"; + return ostr.str(); + } + id++; + } + } + std::string filename = Path::fromNativeSeparators(buildDir); if (filename.back() != '/') filename += '/';