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.

This commit is contained in:
Daniel Marjamäki 2016-10-29 22:40:44 +02:00
parent bc32ccc894
commit 2c3232affa
3 changed files with 22 additions and 3 deletions

View File

@ -138,8 +138,19 @@ unsigned int CppCheck::processFile(const std::string& filename, const std::strin
preprocessor.removeComments(); preprocessor.removeComments();
if (!_settings.buildDir.empty()) { 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<ErrorLogger::ErrorMessage> errors; std::list<ErrorLogger::ErrorMessage> errors;
unsigned int checksum = preprocessor.calculateChecksum(tokens1);
if (!analyzerInformation.analyzeFile(_settings.buildDir, filename, checksum, &errors)) { if (!analyzerInformation.analyzeFile(_settings.buildDir, filename, checksum, &errors)) {
while (!errors.empty()) { while (!errors.empty()) {
reportErr(errors.front()); reportErr(errors.front());

View File

@ -864,9 +864,10 @@ static std::uint32_t crc32(const std::string &data)
return crc ^ ~0U; 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; std::ostringstream ostr;
ostr << toolinfo << '\n';
for (const simplecpp::Token *tok = tokens1.cfront(); tok; tok = tok->next) { for (const simplecpp::Token *tok = tokens1.cfront(); tok; tok = tok->next) {
if (!tok->comment) if (!tok->comment)
ostr << tok->str; ostr << tok->str;

View File

@ -160,7 +160,14 @@ public:
bool validateCfg(const std::string &cfg, const std::list<simplecpp::MacroUsage> &macroUsageList); bool validateCfg(const std::string &cfg, const std::list<simplecpp::MacroUsage> &macroUsageList);
void validateCfgError(const std::string &file, const unsigned int line, const std::string &cfg, const std::string &macro); void validateCfgError(const std::string &file, const unsigned int line, const std::string &cfg, const std::string &macro);
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: private: