mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
refs #921, support for 4 segment version number
This commit is contained in:
committed by
Mathew Sutcliffe
parent
8299552812
commit
7cd49d38d9
@@ -20,8 +20,8 @@ BLACK_CONFIG *= AssertsInRelease
|
||||
BLACK_CONFIG *= PackageInstaller
|
||||
#BLACK_CONFIG *= Static
|
||||
BLACK_CONFIG *= Doxygen
|
||||
#BLACK_CONFIG *= SwiftBeta
|
||||
#BLACK_CONFIG *= SwiftShipped
|
||||
#BLACK_CONFIG *= SwiftDevBranch
|
||||
#BLACK_CONFIG *= SwiftStableBranch
|
||||
|
||||
isEmpty(BLACK_EOL): BLACK_EOL = "20180101"
|
||||
|
||||
@@ -43,8 +43,8 @@ include(vatsim.pri)
|
||||
!contains(BLACK_CONFIG, FSX) { DEFINE_WITH_FSX = "//" }
|
||||
!contains(BLACK_CONFIG, FS9) { DEFINE_WITH_FS9 = "//" }
|
||||
!contains(BLACK_CONFIG, XPlane) { DEFINE_WITH_XPLANE = "//" }
|
||||
!contains(BLACK_CONFIG, SwiftBeta) { DEFINE_SWIFT_BETA = "//" }
|
||||
!contains(BLACK_CONFIG, SwiftShipped) { DEFINE_SWIFT_SHIPPED = "//" }
|
||||
!contains(BLACK_CONFIG, SwiftDevBranch) { DEFINE_SWIFT_DEV_BRANCH = "//" }
|
||||
!contains(BLACK_CONFIG, SwiftStableBranch) { DEFINE_SWIFT_STABLE_BRANCH = "//" }
|
||||
!contains(BLACK_CONFIG, SwiftVatsimSupport) { DEFINE_SWIFT_VATSIM_SUPPORT = "//" }
|
||||
|
||||
# Global compiler Macros
|
||||
|
||||
@@ -9,12 +9,13 @@
|
||||
|
||||
//! \cond PRIVATE
|
||||
|
||||
#include "blackconfig/buildconfig.h"
|
||||
#include "buildconfig.h"
|
||||
#include <QCoreApplication>
|
||||
#include <QDateTime>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QLocale>
|
||||
#include <QStandardPaths>
|
||||
#include <QStringList>
|
||||
#include <QtGlobal>
|
||||
@@ -302,8 +303,8 @@ namespace BlackConfig
|
||||
|
||||
bool CBuildConfig::canRunInDeveloperEnvironment()
|
||||
{
|
||||
if (CBuildConfig::isBetaTest()) { return true; }
|
||||
return !CBuildConfig::isShippedVersion();
|
||||
if (CBuildConfig::isDevBranch()) { return true; }
|
||||
return !CBuildConfig::isStableBranch();
|
||||
}
|
||||
|
||||
QString getDocumentationDirectoryImpl()
|
||||
@@ -367,29 +368,78 @@ namespace BlackConfig
|
||||
}
|
||||
}
|
||||
|
||||
const QString &BlackConfig::CBuildConfig::buildDateAndTime()
|
||||
const QString &CBuildConfig::buildDateAndTime()
|
||||
{
|
||||
static const QString buildDateAndTime( __DATE__ " " __TIME__ );
|
||||
// http://en.cppreference.com/w/cpp/preprocessor/replace#Predefined_macros
|
||||
static const QString buildDateAndTime(__DATE__ " " __TIME__);
|
||||
return buildDateAndTime;
|
||||
}
|
||||
|
||||
namespace Private
|
||||
{
|
||||
const QDateTime buildTimestampImpl()
|
||||
{
|
||||
// Mar 27 2017 20:17:06 (needs to be on english locale, otherwise fails - e.g.
|
||||
QDateTime dt = QLocale(QLocale::English).toDateTime(CBuildConfig::buildDateAndTime(), "MMM dd yyyy hh:mm:ss");
|
||||
dt.setUtcOffset(0);
|
||||
return dt;
|
||||
}
|
||||
}
|
||||
|
||||
const QDateTime &CBuildConfig::buildTimestamp()
|
||||
{
|
||||
// Mar 27 2017 20:17:06
|
||||
static const QDateTime dt = Private::buildTimestampImpl();
|
||||
return dt;
|
||||
}
|
||||
|
||||
const QString &CVersion::version()
|
||||
{
|
||||
static const QString v(versionMajorMinorPatch() + "." + QString::number(buildTimestampAsVersionSegment(CBuildConfig::buildTimestamp())));
|
||||
return v;
|
||||
}
|
||||
|
||||
const QList<int> &CVersion::getVersionParts()
|
||||
{
|
||||
static const QList<int> parts(splitIntoVersionParts(version()));
|
||||
return parts;
|
||||
}
|
||||
|
||||
bool CVersion::isNewerVersion(const QString &versionString)
|
||||
{
|
||||
if (versionString.isEmpty()) { return false; }
|
||||
if (CVersion::version() == versionString) { return false; }
|
||||
return isNewerVersion(version(), versionString);
|
||||
}
|
||||
|
||||
QList<int> newer(getVersionParts(versionString));
|
||||
QList<int> current(getVersionParts(version()));
|
||||
for (int i = 0; i < current.length(); i++)
|
||||
bool CVersion::isNewerVersion(const QString &aVersion, const QString &bVersion)
|
||||
{
|
||||
if (aVersion.isEmpty() || bVersion.isEmpty()) { return false; }
|
||||
if (aVersion == bVersion) { return true; }
|
||||
|
||||
const QList<int> aParts(splitIntoVersionParts(aVersion));
|
||||
const QList<int> bParts(splitIntoVersionParts(bVersion));
|
||||
for (int i = 0; i < bParts.length(); i++)
|
||||
{
|
||||
if (newer.length() <= i) { return false; }
|
||||
if (current.at(i) > newer.at(i)) { return false; }
|
||||
if (current.at(i) < newer.at(i)) { return true; }
|
||||
if (aParts.length() <= i) { return true; }
|
||||
if (bParts.at(i) > aParts.at(i)) { return true; }
|
||||
if (bParts.at(i) < aParts.at(i)) { return false; }
|
||||
// same, try next part
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QList<int> CVersion::getVersionParts(const QString &versionString)
|
||||
int CVersion::buildTimestampAsVersionSegment(const QDateTime &buildTimestamp)
|
||||
{
|
||||
if (buildTimestamp.isValid())
|
||||
{
|
||||
static const qint64 dt2017 = QDateTime::fromString("20170101000000", "yyyyMMddHHmmss").toMSecsSinceEpoch();
|
||||
const qint64 msSinceEpoch = buildTimestamp.toMSecsSinceEpoch();
|
||||
const qint64 msSinceSwiftEpoch = msSinceEpoch - dt2017;
|
||||
return msSinceSwiftEpoch / 1000; // accuraccy second should be enough, and is shorter
|
||||
}
|
||||
return 0; // intentionally 0 and not zero => 0.7.3.0 <-
|
||||
}
|
||||
|
||||
QList<int> CVersion::splitIntoVersionParts(const QString &versionString)
|
||||
{
|
||||
const QStringList parts = versionString.split('.');
|
||||
QList<int> partsInt;
|
||||
|
||||
@@ -13,10 +13,8 @@
|
||||
#define BLACKCONFIG_BUILDCONFIG_H
|
||||
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
|
||||
class QDateTime;
|
||||
class QStringList;
|
||||
#include <QStringList>
|
||||
#include <QDateTime>
|
||||
|
||||
namespace BlackConfig
|
||||
{
|
||||
@@ -60,15 +58,15 @@ namespace BlackConfig
|
||||
//! Release build?
|
||||
static bool isReleaseBuild();
|
||||
|
||||
//! Beta test?
|
||||
static bool isBetaTest(); // defined in buildconfig_gen.cpp.in
|
||||
//! DEV. branch?
|
||||
static bool isDevBranch(); // defined in buildconfig_gen.cpp.in
|
||||
|
||||
//! STABLE branch?
|
||||
static bool isStableBranch(); // defined in buildconfig_gen.cpp.in
|
||||
|
||||
//! Can run in dev. environment?
|
||||
static bool canRunInDeveloperEnvironment();
|
||||
|
||||
//! Shipped version?
|
||||
static bool isShippedVersion(); // defined in buildconfig_gen.cpp.in
|
||||
|
||||
//! Vatsim enabled version?
|
||||
static bool isVatsimVersion(); // defined in buildconfig_gen.cpp.in
|
||||
|
||||
@@ -154,6 +152,9 @@ namespace BlackConfig
|
||||
//! Returns SHA-1 of git HEAD at build time
|
||||
static const QString &gitHeadSha1();
|
||||
|
||||
//! Build timestamp
|
||||
static const QDateTime &buildTimestamp();
|
||||
|
||||
//! Returns the build date and time as string
|
||||
static const QString &buildDateAndTime();
|
||||
};
|
||||
@@ -162,24 +163,36 @@ namespace BlackConfig
|
||||
class CVersion
|
||||
{
|
||||
public:
|
||||
//! Version info
|
||||
static const QString &version(); // defined in buildconfig_gen.cpp.in
|
||||
//! Version info 3 segments e.g. 0.8.3
|
||||
static const QString &versionMajorMinorPatch(); // defined in buildconfig_gen.cpp.in
|
||||
|
||||
//! Version major
|
||||
static int versionMajor();
|
||||
//! Version info 4 segments e.g. 0.8.3.12131
|
||||
static const QString &version();
|
||||
|
||||
//! Version minor
|
||||
static int versionMinor();
|
||||
//! 4 Parts of the version
|
||||
static const QList<int> &getVersionParts();
|
||||
|
||||
//! Version patch
|
||||
static int versionPatch();
|
||||
//! Major version
|
||||
static int versionMajor(); // defined in buildconfig_gen.cpp.in
|
||||
|
||||
//! Is the given string representing a newer version?
|
||||
//! Minor version
|
||||
static int versionMinor(); // defined in buildconfig_gen.cpp.in
|
||||
|
||||
//! Patch version
|
||||
static int versionPatch(); // defined in buildconfig_gen.cpp.in
|
||||
|
||||
//! Is the given string representing a newer version (newer than "me")?
|
||||
static bool isNewerVersion(const QString &versionString);
|
||||
|
||||
//! Is the bVersion newer?
|
||||
static bool isNewerVersion(const QString &aVersion, const QString &bVersion);
|
||||
|
||||
//! Turns build timestamp into a version number
|
||||
static int buildTimestampAsVersionSegment(const QDateTime &buildTimestamp);
|
||||
|
||||
private:
|
||||
//! Parts of version string 1.0.2
|
||||
static QList<int> getVersionParts(const QString &versionString);
|
||||
//! Parts of version string 1.0.2.1234123
|
||||
static QList<int> splitIntoVersionParts(const QString &versionString);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -22,8 +22,8 @@ $$DEFINE_WITH_FSX#define WITH_FSX
|
||||
$$DEFINE_WITH_P3D#define WITH_P3D
|
||||
$$DEFINE_WITH_FS9#define WITH_FS9
|
||||
$$DEFINE_WITH_XPLANE#define WITH_XPLANE
|
||||
$$DEFINE_SWIFT_BETA#define SWIFT_BETA
|
||||
$$DEFINE_SWIFT_SHIPPED#define SWIFT_SHIPPED
|
||||
$$DEFINE_SWIFT_DEV_BRANCH#define SWIFT_DEV_BRANCH
|
||||
$$DEFINE_SWIFT_STABLE_BRANCH#define SWIFT_STABLE_BRANCH
|
||||
$$DEFINE_SWIFT_VATSIM_SUPPORT#define SWIFT_VATSIM_SUPPORT
|
||||
|
||||
bool BlackConfig::CBuildConfig::isCompiledWithBlackCore()
|
||||
@@ -98,18 +98,18 @@ bool BlackConfig::CBuildConfig::isCompiledWithGui()
|
||||
#endif
|
||||
}
|
||||
|
||||
bool BlackConfig::CBuildConfig::isBetaTest()
|
||||
bool BlackConfig::CBuildConfig::isDevBranch()
|
||||
{
|
||||
#ifdef SWIFT_BETA
|
||||
#ifdef SWIFT_DEV_BRANCH
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool BlackConfig::CBuildConfig::isShippedVersion()
|
||||
bool BlackConfig::CBuildConfig::isStableBranch()
|
||||
{
|
||||
#ifdef SWIFT_SHIPPED
|
||||
#ifdef SWIFT_STABLE_BRANCH
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
@@ -151,7 +151,7 @@ const QString &BlackConfig::CBuildConfig::gitHeadSha1()
|
||||
return gitHeadSha1;
|
||||
}
|
||||
|
||||
const QString &BlackConfig::CVersion::version()
|
||||
const QString &BlackConfig::CVersion::versionMajorMinorPatch()
|
||||
{
|
||||
static const QString version(\"$$BLACK_VERSION\");
|
||||
Q_ASSERT(!version.isEmpty());
|
||||
|
||||
@@ -122,7 +122,7 @@ namespace BlackMisc
|
||||
m_stream << " " << QSysInfo::currentCpuArchitecture() << endl;
|
||||
|
||||
m_stream << "Built from revision " << BlackConfig::CBuildConfig::gitHeadSha1();
|
||||
m_stream << " on " << BlackConfig::CBuildConfig::buildDateAndTime() << endl;
|
||||
m_stream << " on " << BlackConfig::CBuildConfig::buildTimestamp().toString() << endl;
|
||||
|
||||
m_stream << "Built with Qt " << QT_VERSION_STR;
|
||||
m_stream << " and running with Qt " << qVersion();
|
||||
|
||||
Reference in New Issue
Block a user