mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 01:05:34 +08:00
refs #921, use QVersionNumber
* CVersion removed * remaining utility functions moved to CBuildConfig * patch version -> micro version (Qt naming) * using classes adjusted
This commit is contained in:
committed by
Mathew Sutcliffe
parent
ec297d5838
commit
f85501c7bf
@@ -375,6 +375,18 @@ namespace BlackConfig
|
||||
return buildDateAndTime;
|
||||
}
|
||||
|
||||
const QVersionNumber &CBuildConfig::getVersion()
|
||||
{
|
||||
static const QVersionNumber v { versionMajor(), versionMinor(), versionMicro(), buildTimestampAsVersionSegment(buildTimestamp()) };
|
||||
return v;
|
||||
}
|
||||
|
||||
const QString &CBuildConfig::getVersionString()
|
||||
{
|
||||
static const QString s(getVersion().toString());
|
||||
return s;
|
||||
}
|
||||
|
||||
namespace Private
|
||||
{
|
||||
const QDateTime buildTimestampImpl()
|
||||
@@ -393,41 +405,7 @@ namespace BlackConfig
|
||||
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)
|
||||
{
|
||||
return isNewerVersion(version(), versionString);
|
||||
}
|
||||
|
||||
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 (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;
|
||||
}
|
||||
|
||||
int CVersion::buildTimestampAsVersionSegment(const QDateTime &buildTimestamp)
|
||||
int CBuildConfig::buildTimestampAsVersionSegment(const QDateTime &buildTimestamp)
|
||||
{
|
||||
if (buildTimestamp.isValid())
|
||||
{
|
||||
@@ -438,19 +416,6 @@ namespace BlackConfig
|
||||
}
|
||||
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;
|
||||
for (const QString &p : parts)
|
||||
{
|
||||
bool ok = false;
|
||||
int pInt = p.toInt(&ok);
|
||||
partsInt.append(ok ? pInt : -1);
|
||||
}
|
||||
return partsInt;
|
||||
}
|
||||
} // ns
|
||||
|
||||
//! \endcond
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <QList>
|
||||
#include <QStringList>
|
||||
#include <QDateTime>
|
||||
#include <QVersionNumber>
|
||||
|
||||
namespace BlackConfig
|
||||
{
|
||||
@@ -152,26 +153,25 @@ namespace BlackConfig
|
||||
//! Returns SHA-1 of git HEAD at build time
|
||||
static const QString &gitHeadSha1();
|
||||
|
||||
//! Version info 3 segments e.g. 0.8.3
|
||||
static const QString &versionMajorMinorPatch(); // defined in buildconfig_gen.cpp.in
|
||||
|
||||
//! Build timestamp
|
||||
static const QDateTime &buildTimestamp();
|
||||
|
||||
//! Returns the build date and time as string
|
||||
static const QString &buildDateAndTime();
|
||||
};
|
||||
|
||||
//! Version
|
||||
class CVersion
|
||||
{
|
||||
public:
|
||||
//! Version info 3 segments e.g. 0.8.3
|
||||
static const QString &versionMajorMinorPatch(); // defined in buildconfig_gen.cpp.in
|
||||
//! Version as QVersionNumber
|
||||
static const QVersionNumber &getVersion();
|
||||
|
||||
//! Version info 4 segments e.g. 0.8.3.12131
|
||||
static const QString &version();
|
||||
//! Version as QVersionNumber
|
||||
static const QString &getVersionString();
|
||||
|
||||
//! 4 Parts of the version
|
||||
static const QList<int> &getVersionParts();
|
||||
//! Turns build timestamp into a version number
|
||||
static int buildTimestampAsVersionSegment(const QDateTime &buildTimestamp);
|
||||
|
||||
private:
|
||||
//! Major version
|
||||
static int versionMajor(); // defined in buildconfig_gen.cpp.in
|
||||
|
||||
@@ -179,20 +179,7 @@ namespace BlackConfig
|
||||
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.1234123
|
||||
static QList<int> splitIntoVersionParts(const QString &versionString);
|
||||
static int versionMicro(); // defined in buildconfig_gen.cpp.in
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -151,13 +151,6 @@ const QString &BlackConfig::CBuildConfig::gitHeadSha1()
|
||||
return gitHeadSha1;
|
||||
}
|
||||
|
||||
const QString &BlackConfig::CVersion::versionMajorMinorPatch()
|
||||
{
|
||||
static const QString version(\"$$BLACK_VERSION\");
|
||||
Q_ASSERT(!version.isEmpty());
|
||||
return version;
|
||||
}
|
||||
|
||||
int BlackConfig::CVersion::versionMajor() { return $$BLACK_VER_MAJ; }
|
||||
int BlackConfig::CVersion::versionMinor() { return $$BLACK_VER_MIN; }
|
||||
int BlackConfig::CVersion::versionPatch() { return $$BLACK_VER_PAT; }
|
||||
int BlackConfig::CBuildConfig::versionMajor() { return $$BLACK_VER_MAJ; }
|
||||
int BlackConfig::CBuildConfig::versionMinor() { return $$BLACK_VER_MIN; }
|
||||
int BlackConfig::CBuildConfig::versionMicro() { return $$BLACK_VER_MIC; }
|
||||
|
||||
Reference in New Issue
Block a user