From 9e2dd553fb0bb873f7d9943cc230178effdf465e Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Thu, 11 Aug 2011 17:34:59 +0300 Subject: [PATCH] Add "ExtraVersion" version number information. The "ExtraVersion" can be used for things like Git commit Id, release tag (version control), release date etc. If the string is empty, nothing is printed. --- cli/cppcheckexecutor.cpp | 8 +++++++- lib/cppcheck.cpp | 10 +++++++++- lib/cppcheck.h | 8 ++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index e659b7ec6..f32ca39d9 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -24,6 +24,7 @@ #include #include #include // EXIT_SUCCESS and EXIT_FAILURE +#include #include "cmdlineparser.h" #include "filelister.h" #include "path.h" @@ -50,7 +51,12 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c { if (parser.GetShowVersion() && !parser.GetShowErrorMessages()) { - std::cout << "Cppcheck " << cppcheck->version() << std::endl; + const char * extraVersion = cppcheck->extraVersion(); + if (strlen(extraVersion) > 0) + std::cout << "Cppcheck " << cppcheck->version() << " (" + << extraVersion << ")" << std::endl; + else + std::cout << "Cppcheck " << cppcheck->version() << std::endl; } if (parser.GetShowErrorMessages()) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 25f38c9d2..582d6aa18 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -35,6 +35,9 @@ #include #endif +static const char Version[] = "1.49"; +static const char ExtraVersion[] = ""; + static TimerResults S_timerResults; CppCheck::CppCheck(ErrorLogger &errorLogger, bool useGlobalSuppressions) @@ -56,7 +59,12 @@ void CppCheck::settings(const Settings ¤tSettings) const char * CppCheck::version() { - return "1.49"; + return Version; +} + +const char * CppCheck::extraVersion() +{ + return ExtraVersion; } unsigned int CppCheck::check(const std::string &path) diff --git a/lib/cppcheck.h b/lib/cppcheck.h index e1800e544..301329a95 100644 --- a/lib/cppcheck.h +++ b/lib/cppcheck.h @@ -105,6 +105,14 @@ public: */ static const char * version(); + /** + * @brief Returns extra version info as a string. + * This is for returning extra version info, like Git commit id, build + * time/date etc. + * @return extra version info, e.g. "04d42151" (Git commit id). + */ + static const char * extraVersion(); + virtual void reportStatus(unsigned int fileindex, unsigned int filecount, long sizedone, long sizetotal); /**