From 2c3232affa587c25383185c75fd26a84114341bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 29 Oct 2016 22:40:44 +0200 Subject: [PATCH] cppcheck-build-dir: Use settings and cppcheck version in checksum so results will be recalculated if cppcheck is upgraded or there is significant changes on the command line. --- lib/cppcheck.cpp | 13 ++++++++++++- lib/preprocessor.cpp | 3 ++- lib/preprocessor.h | 9 ++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 9410a0a56..679d18558 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -138,8 +138,19 @@ unsigned int CppCheck::processFile(const std::string& filename, const std::strin preprocessor.removeComments(); if (!_settings.buildDir.empty()) { + // Get toolinfo + std::string toolinfo; + toolinfo += CPPCHECK_VERSION_STRING; + toolinfo += _settings.isEnabled("warning") ? 'w' : ' '; + toolinfo += _settings.isEnabled("style") ? 's' : ' '; + toolinfo += _settings.isEnabled("performance") ? 'p' : ' '; + toolinfo += _settings.isEnabled("portability") ? 'p' : ' '; + toolinfo += _settings.isEnabled("information") ? 'i' : ' '; + toolinfo += _settings.userDefines; + + // Calculate checksum so it can be compared with old checksum / future checksums + const unsigned int checksum = preprocessor.calculateChecksum(tokens1, toolinfo); std::list errors; - unsigned int checksum = preprocessor.calculateChecksum(tokens1); if (!analyzerInformation.analyzeFile(_settings.buildDir, filename, checksum, &errors)) { while (!errors.empty()) { reportErr(errors.front()); diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 36d8714b2..15dc68944 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -864,9 +864,10 @@ static std::uint32_t crc32(const std::string &data) return crc ^ ~0U; } -unsigned int Preprocessor::calculateChecksum(const simplecpp::TokenList &tokens1) const +unsigned int Preprocessor::calculateChecksum(const simplecpp::TokenList &tokens1, const std::string &toolinfo) const { std::ostringstream ostr; + ostr << toolinfo << '\n'; for (const simplecpp::Token *tok = tokens1.cfront(); tok; tok = tok->next) { if (!tok->comment) ostr << tok->str; diff --git a/lib/preprocessor.h b/lib/preprocessor.h index e95341268..f81c08be2 100644 --- a/lib/preprocessor.h +++ b/lib/preprocessor.h @@ -160,7 +160,14 @@ public: bool validateCfg(const std::string &cfg, const std::list ¯oUsageList); void validateCfgError(const std::string &file, const unsigned int line, const std::string &cfg, const std::string ¯o); - unsigned int calculateChecksum(const simplecpp::TokenList &tokens1) const; + /** + * Calculate CRC32 checksum. Using toolinfo, tokens1, filedata. + * + * @param tokens1 Sourcefile tokens + * @param toolinfo Arbitrary extra toolinfo + * @return CRC32 checksum + */ + unsigned int calculateChecksum(const simplecpp::TokenList &tokens1, const std::string &toolinfo) const; private: