2014-04-13 13:22:12 -04:00
|
|
|
#include "revision_utils.hpp"
|
|
|
|
|
2014-09-18 18:32:27 -04:00
|
|
|
#include <cstring>
|
|
|
|
|
2014-04-13 13:22:12 -04:00
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QRegularExpression>
|
|
|
|
|
2018-05-27 07:40:12 -04:00
|
|
|
#include "scs_version.h"
|
2014-04-13 13:22:12 -04:00
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
QString revision_extract_number (QString const& s)
|
|
|
|
{
|
|
|
|
QString revision;
|
|
|
|
|
2018-05-27 07:40:12 -04:00
|
|
|
// try and match a number (hexadecimal allowed)
|
|
|
|
QRegularExpression re {R"(^[$:]\w+: (r?[\da-f]+[^$]*)\$$)"};
|
2014-04-13 13:22:12 -04:00
|
|
|
auto match = re.match (s);
|
|
|
|
if (match.hasMatch ())
|
|
|
|
{
|
2018-05-27 07:40:12 -04:00
|
|
|
revision = match.captured (1);
|
2014-04-13 13:22:12 -04:00
|
|
|
}
|
|
|
|
return revision;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-27 07:40:12 -04:00
|
|
|
QString revision (QString const& scs_rev_string)
|
2014-04-13 13:22:12 -04:00
|
|
|
{
|
|
|
|
QString result;
|
2018-05-27 07:40:12 -04:00
|
|
|
auto revision_from_scs = revision_extract_number (scs_rev_string);
|
2014-04-13 13:22:12 -04:00
|
|
|
|
|
|
|
#if defined (CMAKE_BUILD)
|
2020-10-10 08:38:15 -04:00
|
|
|
QString scs_info {":Rev: " SCS_VERSION_STR " $"};
|
2014-04-13 13:22:12 -04:00
|
|
|
|
2018-05-27 07:40:12 -04:00
|
|
|
auto revision_from_scs_info = revision_extract_number (scs_info);
|
|
|
|
if (!revision_from_scs_info.isEmpty ())
|
2014-04-13 13:22:12 -04:00
|
|
|
{
|
|
|
|
// we managed to get the revision number from svn info etc.
|
2018-05-27 07:40:12 -04:00
|
|
|
result = revision_from_scs_info;
|
2014-04-13 13:22:12 -04:00
|
|
|
}
|
2018-05-27 07:40:12 -04:00
|
|
|
else if (!revision_from_scs.isEmpty ())
|
2014-04-13 13:22:12 -04:00
|
|
|
{
|
2015-02-21 19:20:42 -05:00
|
|
|
// fall back to revision passed in if any
|
2018-05-27 07:40:12 -04:00
|
|
|
result = revision_from_scs;
|
2014-04-13 13:22:12 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// match anything
|
|
|
|
QRegularExpression re {R"(^[$:]\w+: ([^$]*)\$$)"};
|
2018-05-27 07:40:12 -04:00
|
|
|
auto match = re.match (scs_info);
|
2014-04-13 13:22:12 -04:00
|
|
|
if (match.hasMatch ())
|
|
|
|
{
|
|
|
|
result = match.captured (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
2018-05-27 07:40:12 -04:00
|
|
|
if (!revision_from_scs.isEmpty ())
|
2014-04-13 13:22:12 -04:00
|
|
|
{
|
2015-02-21 19:20:42 -05:00
|
|
|
// not CMake build so all we have is revision passed
|
2018-05-27 07:40:12 -04:00
|
|
|
result = revision_from_scs;
|
2014-04-13 13:22:12 -04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return result.trimmed ();
|
|
|
|
}
|
|
|
|
|
2015-12-24 06:41:05 -05:00
|
|
|
QString version (bool include_patch)
|
2015-02-21 19:20:42 -05:00
|
|
|
{
|
|
|
|
#if defined (CMAKE_BUILD)
|
2020-10-10 08:38:15 -04:00
|
|
|
QString v {TO_STRING__ (PROJECT_VERSION_MAJOR) "." TO_STRING__ (PROJECT_VERSION_MINOR)};
|
2015-12-24 06:41:05 -05:00
|
|
|
if (include_patch)
|
|
|
|
{
|
2020-10-10 08:38:15 -04:00
|
|
|
v += "." TO_STRING__ (PROJECT_VERSION_PATCH) + QString {BUILD_TYPE_REVISION};
|
2015-12-24 06:41:05 -05:00
|
|
|
}
|
2015-02-21 19:20:42 -05:00
|
|
|
#else
|
|
|
|
QString v {"Not for Release"};
|
|
|
|
#endif
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2014-04-13 13:22:12 -04:00
|
|
|
QString program_title (QString const& revision)
|
|
|
|
{
|
2015-02-23 10:19:41 -05:00
|
|
|
QString id {QCoreApplication::applicationName () + " v" + QCoreApplication::applicationVersion ()};
|
2020-05-06 09:38:09 -04:00
|
|
|
return id + " " + revision + " by K1JT, G4WJS, and K9AN";
|
2014-04-13 13:22:12 -04:00
|
|
|
}
|