js8call/.svn/pristine/f0/f0afeff43ba297de03eb7f9b333b62c6ac324756.svn-base

89 lines
2.0 KiB
Plaintext
Raw Normal View History

2018-02-08 21:28:33 -05:00
#include "revision_utils.hpp"
#include <cstring>
#include <QCoreApplication>
#include <QRegularExpression>
2018-08-05 11:33:30 -04:00
#include "scs_version.h"
2018-02-08 21:28:33 -05:00
namespace
{
QString revision_extract_number (QString const& s)
{
QString revision;
2018-08-05 11:33:30 -04:00
// try and match a number (hexadecimal allowed)
QRegularExpression re {R"(^[$:]\w+: (r?[\da-f]+[^$]*)\$$)"};
2018-02-08 21:28:33 -05:00
auto match = re.match (s);
if (match.hasMatch ())
{
2018-08-05 11:33:30 -04:00
revision = match.captured (1);
2018-02-08 21:28:33 -05:00
}
return revision;
}
}
2018-08-05 11:33:30 -04:00
QString revision (QString const& scs_rev_string)
2018-02-08 21:28:33 -05:00
{
QString result;
2018-08-05 11:33:30 -04:00
auto revision_from_scs = revision_extract_number (scs_rev_string);
2018-02-08 21:28:33 -05:00
#if defined (CMAKE_BUILD)
2018-08-05 11:33:30 -04:00
QString scs_info {":Rev: " WSJTX_STRINGIZE (SCS_VERSION) " $"};
2018-02-08 21:28:33 -05:00
2018-08-05 11:33:30 -04:00
auto revision_from_scs_info = revision_extract_number (scs_info);
if (!revision_from_scs_info.isEmpty ())
2018-02-08 21:28:33 -05:00
{
// we managed to get the revision number from svn info etc.
2018-08-05 11:33:30 -04:00
result = revision_from_scs_info;
2018-02-08 21:28:33 -05:00
}
2018-08-05 11:33:30 -04:00
else if (!revision_from_scs.isEmpty ())
2018-02-08 21:28:33 -05:00
{
// fall back to revision passed in if any
2018-08-05 11:33:30 -04:00
result = revision_from_scs;
2018-02-08 21:28:33 -05:00
}
else
{
// match anything
QRegularExpression re {R"(^[$:]\w+: ([^$]*)\$$)"};
2018-08-05 11:33:30 -04:00
auto match = re.match (scs_info);
2018-02-08 21:28:33 -05:00
if (match.hasMatch ())
{
result = match.captured (1);
}
}
#else
2018-08-05 11:33:30 -04:00
if (!revision_from_scs.isEmpty ())
2018-02-08 21:28:33 -05:00
{
// not CMake build so all we have is revision passed
2018-08-05 11:33:30 -04:00
result = revision_from_scs;
2018-02-08 21:28:33 -05: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)
{
QString id {QCoreApplication::applicationName () + " v" + QCoreApplication::applicationVersion ()};
return id + " " + revision + " by K1JT";
}