From d63dd8d081a6fcd0715cd13f26df59fb831769d2 Mon Sep 17 00:00:00 2001 From: "Iain R. Learmonth" Date: Sun, 18 Oct 2015 18:51:00 +0100 Subject: Imported Upstream version 1.5.0 --- revision_utils.cpp | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 revision_utils.cpp (limited to 'revision_utils.cpp') diff --git a/revision_utils.cpp b/revision_utils.cpp new file mode 100644 index 00000000..fe31beb7 --- /dev/null +++ b/revision_utils.cpp @@ -0,0 +1,83 @@ +#include "revision_utils.hpp" + +#include + +#include +#include + +#include "svnversion.h" + +namespace +{ + QString revision_extract_number (QString const& s) + { + QString revision; + + // try and match a number + QRegularExpression re {R"(^[$:]\w+: (\d+[^$]*)\$$)"}; + auto match = re.match (s); + if (match.hasMatch ()) + { + revision = 'r' + match.captured (1); + } + return revision; + } +} + +QString revision (QString const& svn_rev_string) +{ + QString result; + auto revision_from_svn = revision_extract_number (svn_rev_string); + +#if defined (CMAKE_BUILD) + QString svn_info {":Rev: " WSJTX_STRINGIZE (SVNVERSION) " $"}; + + auto revision_from_svn_info = revision_extract_number (svn_info); + if (!revision_from_svn_info.isEmpty ()) + { + // we managed to get the revision number from svn info etc. + result = revision_from_svn_info; + } + else if (!revision_from_svn.isEmpty ()) + { + // fall back to revision passed in if any + result = revision_from_svn; + } + else + { + // match anything + QRegularExpression re {R"(^[$:]\w+: ([^$]*)\$$)"}; + auto match = re.match (svn_info); + if (match.hasMatch ()) + { + result = match.captured (1); + } + } +#else + if (!revision_from_svn.isEmpty ()) + { + // not CMake build so all we have is revision passed + result = revision_from_svn; + } +#endif + return result.trimmed (); +} + +QString version () +{ +#if defined (CMAKE_BUILD) + QString v {WSJTX_STRINGIZE (WSJTX_VERSION_MAJOR) "." WSJTX_STRINGIZE (WSJTX_VERSION_MINOR) "." WSJTX_STRINGIZE (WSJTX_VERSION_PATCH)}; +# if defined (WSJTX_RC) + v += "-rc" WSJTX_STRINGIZE (WSJTX_RC); +# endif +#else + QString v {"Not for Release"}; +#endif + return v; +} + +QString program_title (QString const& revision) +{ + QString id {QCoreApplication::applicationName () + " v" + QCoreApplication::applicationVersion ()}; + return id + " " + revision + " by K1JT"; +} -- cgit v1.2.3