From c71a953afd02fe5fbc10d80da131d854c7b44914 Mon Sep 17 00:00:00 2001 From: sawinglogz <3787776-sawinglogz@users.noreply.gitlab.com> Date: Thu, 16 Jan 2020 11:33:39 -0500 Subject: [PATCH] Add build metadata to version string. Also update git scripts to make build metadata compliant with semantic versioning. --- oscar/update_gitinfo.bat | 2 +- oscar/update_gitinfo.sh | 2 +- oscar/version.cpp | 24 ++++++++++++++++++++++-- oscar/version.h | 15 ++++++++++++--- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/oscar/update_gitinfo.bat b/oscar/update_gitinfo.bat index 3ae5665a..ac1cb0f0 100755 --- a/oscar/update_gitinfo.bat +++ b/oscar/update_gitinfo.bat @@ -5,7 +5,7 @@ cd %DIR% for /f %%i in ('git rev-parse --abbrev-ref HEAD') do set GIT_BRANCH=%%i for /f %%i in ('git rev-parse --short HEAD') do set GIT_REVISION=%%i -git diff-index --quiet HEAD -- || set GIT_REVISION=%GIT_REVISION%+ +git diff-index --quiet HEAD -- || set GIT_REVISION=%GIT_REVISION%-plus if "%GIT_BRANCH"=="" set GIT_BRANCH="Unknown" if "%GIT_REVISION"=="" set GIT_REVISION="Unknown" diff --git a/oscar/update_gitinfo.sh b/oscar/update_gitinfo.sh index daaab8fb..bfc58044 100755 --- a/oscar/update_gitinfo.sh +++ b/oscar/update_gitinfo.sh @@ -7,7 +7,7 @@ GIT_BRANCH=`git rev-parse --abbrev-ref HEAD` GIT_REVISION=`git rev-parse --short HEAD` $(git diff-index --quiet HEAD --) if [ $? -ne 0 ]; then - GIT_REVISION="$GIT_REVISION+" # uncommitted changes + GIT_REVISION="${GIT_REVISION}-plus" # uncommitted changes fi [ -z "$GIT_BRANCH" ] && GIT_BRANCH="Unknown"; diff --git a/oscar/version.cpp b/oscar/version.cpp index 2a27a7f8..b1a957c5 100644 --- a/oscar/version.cpp +++ b/oscar/version.cpp @@ -12,7 +12,6 @@ #include #define VERSION "1.1.0-beta-1" -extern const QString VersionString = VERSION; #ifdef Q_OS_MAC const QString PlatformString = "MacOSX"; @@ -73,8 +72,9 @@ QString getPrereleaseSuffix() return suffix; } +// TODO: add preprocessor macros to build full version number including build metadata, accounting for tarball/non-git builds. -static const Version s_Version(VERSION); +static const Version s_Version(VERSION "+" + GIT_BRANCH + "-" + GIT_REVISION); const Version & getVersion() { return s_Version; @@ -96,6 +96,26 @@ const QString & Version::toString() const return mString; } + +// Alternate formatting of the version string for display or logging +const QString Version::minimalString() const +{ + return toString().section("+", 0); +} + +const QString & Version::getBuildMetadata() const +{ + return mBuild; +} + +const QString Version::displayString() const +{ + if (IsReleaseVersion()) + return minimalString(); + else + return toString(); +} + // This is application-specific interpretation of the prerelease data. const QString Version::PrereleaseType() const { diff --git a/oscar/version.h b/oscar/version.h index f787cfce..b518ef17 100644 --- a/oscar/version.h +++ b/oscar/version.h @@ -10,15 +10,13 @@ #ifndef VERSION_H #define VERSION_H -#include +#include class Version { friend class VersionTests; public: Version(const QString & version_string); - operator const QString &() const; - const QString & toString() const; const QString PrereleaseType() const; bool IsReleaseVersion() const { return mPrerelease.isEmpty(); } bool IsValid() const { return mIsValid; } @@ -27,6 +25,17 @@ public: bool operator<(const Version & b) const { return Compare(*this, b) < 0; } bool operator>(const Version & b) const { return Compare(*this, b) > 0; } + //!brief Returns the full version string, including all metadata, used in reports + operator const QString &() const; + //!brief Returns the full version string, including all metadata, used in reports + const QString & toString() const; + //!brief Returns the version string to display in the UI, without build metadata if a release version + const QString displayString() const; + //!brief Returns the version string without any build metadata + const QString minimalString() const; + //!brief Returns the build metadata + const QString & getBuildMetadata() const; + protected: const QString mString; bool mIsValid;