jtdx/revision_utils.cpp

89 lines
2.1 KiB
C++
Raw Normal View History

2020-02-21 11:05:07 +02:00
#include "revision_utils.hpp"
#include <cstring>
#include <QCoreApplication>
#include <QRegularExpression>
2020-02-21 13:54:27 +02:00
#include "scs_version.h"
2020-02-21 11:05:07 +02:00
namespace
{
QString revision_extract_number (QString const& s)
{
QString revision;
2020-03-04 10:15:55 +02:00
// try and match a number (hexadecimal allowed)
QRegularExpression re {R"(^[$:]\w+: (r?[\da-f]+[^$]*)\$$)"};
2020-02-21 11:05:07 +02:00
auto match = re.match (s);
if (match.hasMatch ())
{
2020-03-04 10:15:55 +02:00
revision = match.captured (1);
2020-02-21 11:05:07 +02:00
}
return revision;
}
}
2020-03-04 10:15:55 +02:00
QString revision (QString const& scs_rev_string)
2020-02-21 11:05:07 +02:00
{
QString result;
2020-03-04 10:15:55 +02:00
auto revision_from_scs = revision_extract_number (scs_rev_string);
2020-02-21 11:05:07 +02:00
#if defined (CMAKE_BUILD)
2020-03-04 10:15:55 +02:00
QString scs_info {":Rev: " WSJTX_STRINGIZE (SCS_VERSION) " $"};
2020-02-21 11:05:07 +02:00
2020-03-04 10:15:55 +02:00
auto revision_from_scs_info = revision_extract_number (scs_info);
if (!revision_from_scs_info.isEmpty ())
2020-02-21 11:05:07 +02:00
{
// we managed to get the revision number from svn info etc.
2020-03-04 10:15:55 +02:00
result = revision_from_scs_info;
2020-02-21 11:05:07 +02:00
}
2020-03-04 10:15:55 +02:00
else if (!revision_from_scs.isEmpty ())
2020-02-21 11:05:07 +02:00
{
// fall back to revision passed in if any
2020-03-04 10:15:55 +02:00
result = revision_from_scs;
2020-02-21 11:05:07 +02:00
}
else
{
// match anything
QRegularExpression re {R"(^[$:]\w+: ([^$]*)\$$)"};
2020-03-04 10:15:55 +02:00
auto match = re.match (scs_info);
2020-02-21 11:05:07 +02:00
if (match.hasMatch ())
{
result = match.captured (1);
}
}
#else
2020-03-04 10:15:55 +02:00
if (!revision_from_scs.isEmpty ())
2020-02-21 11:05:07 +02:00
{
// not CMake build so all we have is revision passed
2020-03-04 10:15:55 +02:00
result = revision_from_scs;
2020-02-21 11:05:07 +02:00
}
#endif
return result.trimmed ();
}
QString version (bool include_patch)
{
#if defined (CMAKE_BUILD)
QString v {WSJTX_STRINGIZE (WSJTX_VERSION_MAJOR) "." WSJTX_STRINGIZE (WSJTX_VERSION_MINOR)};
if (include_patch)
{
v += "." WSJTX_STRINGIZE (WSJTX_VERSION_PATCH)
# if defined (WSJTX_RC)
+ "-rc" WSJTX_STRINGIZE (WSJTX_RC)
# endif
;
}
#else
QString v {"Not for Release"};
#endif
return v;
}
QString program_title (QString const& revision)
{
2020-03-04 10:15:55 +02:00
QString id {QCoreApplication::applicationName () + " by HF community v" + QCoreApplication::applicationVersion ()};
return id + " " + revision + ", derivative work based on WSJT-X by K1JT";
2020-02-21 11:05:07 +02:00
}