mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-21 04:45:31 +08:00
New schema for the 4th segment of the swift version number
Based on a count of the number of commits since any of the first 3 segments were changed.
This commit is contained in:
@@ -24,14 +24,7 @@ include(config.pri)
|
|||||||
# Version number
|
# Version number
|
||||||
################################
|
################################
|
||||||
|
|
||||||
setSwiftConfig(version.full, $$swiftConfig(version.major).$$swiftConfig(version.minor).$$swiftConfig(version.micro))
|
include(version.pri)
|
||||||
|
|
||||||
!win32 {
|
|
||||||
VER_MAJ = $$swiftConfig(version.major)
|
|
||||||
VER_MIN = $$swiftConfig(version.minor)
|
|
||||||
VER_MIC = $$swiftConfig(version.micro)
|
|
||||||
VERSION = $$swiftConfig(version.full)
|
|
||||||
}
|
|
||||||
|
|
||||||
################################
|
################################
|
||||||
# QMake options
|
# QMake options
|
||||||
|
|||||||
31
mkspecs/features/version.pri
Normal file
31
mkspecs/features/version.pri
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
win32: GIT_BIN = $$system($$(SYSTEMROOT)\system32\where git 2> nul)
|
||||||
|
else: GIT_BIN = $$system(which git 2> /dev/null)
|
||||||
|
|
||||||
|
# Count the number of commits since the version number was changed
|
||||||
|
defineReplace(gitRevCount) {
|
||||||
|
!exists(../../default.json): error(default.json missing)
|
||||||
|
CONFIG_LOG = $$system(git log --format=%H ../../default.json)
|
||||||
|
for(sha, CONFIG_LOG) {
|
||||||
|
jsonBlob = $$system(git show $${sha}:../../default.json)
|
||||||
|
parseJson(jsonBlob, jsonData)
|
||||||
|
v = $${jsonData.version.major}.$${jsonData.version.minor}.$${jsonData.version.micro}
|
||||||
|
equals(v, $$swiftConfig(version.full)): BASE_COMMIT = $$sha
|
||||||
|
}
|
||||||
|
return($$system(git rev-list --count HEAD $$system_quote(^$$BASE_COMMIT)))
|
||||||
|
}
|
||||||
|
|
||||||
|
setSwiftConfig(version.full, $$swiftConfig(version.major).$$swiftConfig(version.minor).$$swiftConfig(version.micro))
|
||||||
|
|
||||||
|
!win32 {
|
||||||
|
VER_MAJ = $$swiftConfig(version.major)
|
||||||
|
VER_MIN = $$swiftConfig(version.minor)
|
||||||
|
VER_PAT = $$swiftConfig(version.micro)
|
||||||
|
VERSION = $$swiftConfig(version.full)
|
||||||
|
}
|
||||||
|
|
||||||
|
!isEmpty(GIT_BIN) {
|
||||||
|
isEmpty(VER_REV) {
|
||||||
|
VER_REV = $$gitRevCount()
|
||||||
|
cache(VER_REV)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -266,25 +266,36 @@ class Builder:
|
|||||||
self.make_cmd = self._get_make_cmd()
|
self.make_cmd = self._get_make_cmd()
|
||||||
self.version = self.__get_swift_version()
|
self.version = self.__get_swift_version()
|
||||||
|
|
||||||
|
def __get_config_file(self):
|
||||||
|
return path.abspath(path.join(self._get_swift_source_path(), 'default')) + '.json';
|
||||||
|
|
||||||
def __get_swift_version(self):
|
def __get_swift_version(self):
|
||||||
config_file = path.abspath(path.join(self._get_swift_source_path(), 'default')) + '.json'
|
return self.__get_swift_version_base() + '.' + str(self.__get_rev_count())
|
||||||
f = open(config_file)
|
|
||||||
|
def __get_swift_version_base(self):
|
||||||
|
f = open(self.__get_config_file())
|
||||||
config_json = json.load(f)
|
config_json = json.load(f)
|
||||||
f.close()
|
f.close()
|
||||||
version_major = config_json['version']['major']
|
version_major = config_json['version']['major']
|
||||||
version_minor = config_json['version']['minor']
|
version_minor = config_json['version']['minor']
|
||||||
version_micro = config_json['version']['micro']
|
version_micro = config_json['version']['micro']
|
||||||
|
return '.'.join([str(version_major), str(version_minor), str(version_micro)])
|
||||||
|
|
||||||
# Converted from swift's CBuildConfig::lastCommitTimestampAsVersionSegment
|
def __get_rev_count(self):
|
||||||
last_commit_timestamp = int(self.__get_last_commit_timestamp())
|
this_version = self.__get_swift_version_base()
|
||||||
year_offset = 201000000000
|
config_log = subprocess.check_output(['git', 'log', '--format=%H', self.__get_config_file()])
|
||||||
last_commit_timestamp = last_commit_timestamp - year_offset
|
for sha in config_log.decode("utf-8").split():
|
||||||
version = '.'.join([str(version_major), str(version_minor), str(version_micro), str(last_commit_timestamp)])
|
json_data = subprocess.check_output(['git', 'show', sha + ':default.json'])
|
||||||
return version
|
config_json = json.loads(json_data.decode("utf-8"))
|
||||||
|
version_major = config_json['version']['major']
|
||||||
def __get_last_commit_timestamp(self):
|
version_minor = config_json['version']['minor']
|
||||||
out = subprocess.check_output(['git', 'log', '-1', '--date=format:"%Y%m%d%H%M"', '--pretty=format:%cd'])
|
version_micro = config_json['version']['micro']
|
||||||
return out.decode("utf-8").strip('"')
|
if this_version == '.'.join([str(version_major), str(version_minor), str(version_micro)]):
|
||||||
|
base_commit = sha
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
count = subprocess.check_output(['git', 'rev-list', '--count', 'HEAD', '^' + base_commit])
|
||||||
|
return int(count.decode("utf-8"))
|
||||||
|
|
||||||
def __upload_symbol_files(self, symbols_package):
|
def __upload_symbol_files(self, symbols_package):
|
||||||
print('Uploading symbols')
|
print('Uploading symbols')
|
||||||
|
|||||||
@@ -27,10 +27,10 @@ else: GIT_BIN = $$system(which git 2> /dev/null)
|
|||||||
|
|
||||||
isEmpty(GIT_BIN) {
|
isEmpty(GIT_BIN) {
|
||||||
GIT_HEAD_SHA1="<unknown>"
|
GIT_HEAD_SHA1="<unknown>"
|
||||||
GIT_COMMIT_TS="0"
|
GIT_REV_COUNT=0
|
||||||
} else {
|
} else {
|
||||||
GIT_HEAD_SHA1=$$system(git rev-parse --short HEAD)
|
GIT_HEAD_SHA1=$$system(git rev-parse --short HEAD)
|
||||||
GIT_COMMIT_TS=$$system(git log -1 --date=format:'%Y%m%d%H%M' --pretty=format:%cd)
|
GIT_REV_COUNT=$$VER_REV
|
||||||
}
|
}
|
||||||
|
|
||||||
load(common_post)
|
load(common_post)
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ namespace BlackConfig
|
|||||||
|
|
||||||
const QVersionNumber &CBuildConfig::getVersion()
|
const QVersionNumber &CBuildConfig::getVersion()
|
||||||
{
|
{
|
||||||
static const QVersionNumber v { versionMajor(), versionMinor(), versionMicro(), lastCommitTimestampAsVersionSegment(lastCommitTimestamp()) };
|
static const QVersionNumber v { versionMajor(), versionMinor(), versionMicro(), versionRevision() };
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,61 +176,6 @@ namespace BlackConfig
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
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().simplified(), "MMM d yyyy hh:mm:ss");
|
|
||||||
dt.setOffsetFromUtc(0);
|
|
||||||
return dt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const QDateTime &CBuildConfig::buildTimestamp()
|
|
||||||
{
|
|
||||||
// Mar 27 2017 20:17:06
|
|
||||||
static const QDateTime dt = Private::buildTimestampImpl();
|
|
||||||
return dt;
|
|
||||||
}
|
|
||||||
|
|
||||||
int CBuildConfig::lastCommitTimestampAsVersionSegment(const QDateTime &lastCommitTimestamp)
|
|
||||||
{
|
|
||||||
if (lastCommitTimestamp.isValid())
|
|
||||||
{
|
|
||||||
const QString bts = lastCommitTimestamp.toString("yyyyMMddHHmm");
|
|
||||||
bool ok;
|
|
||||||
const long long lctsll = bts.toLongLong(&ok); // at least 64bit
|
|
||||||
if (!ok) { return 0; }
|
|
||||||
// now we have to converto int
|
|
||||||
// max 2147483647 (2^31 - 1)
|
|
||||||
// 1MMddHHmm (years since 2010)
|
|
||||||
const long long yearOffset = 201000000000;
|
|
||||||
const int lctsInt = static_cast<int>(lctsll - yearOffset);
|
|
||||||
return lctsInt;
|
|
||||||
}
|
|
||||||
return 0; // intentionally 0 => 0.7.3.0 <-
|
|
||||||
}
|
|
||||||
|
|
||||||
int CBuildConfig::buildTimestampAsVersionSegment(const QDateTime &buildTimestamp)
|
|
||||||
{
|
|
||||||
if (buildTimestamp.isValid())
|
|
||||||
{
|
|
||||||
const QString bts = buildTimestamp.toString("yyyyMMddHHmm");
|
|
||||||
bool ok;
|
|
||||||
const long long btsll = bts.toLongLong(&ok); // at least 64bit
|
|
||||||
if (!ok) { return 0; }
|
|
||||||
// now we have to convert to int, otherwise we would fail 2021
|
|
||||||
// max 2147483647 (2^31 - 1)
|
|
||||||
// yyMMddHHmm (years since 2010)
|
|
||||||
// yyyyMMddHHmm
|
|
||||||
const long long yearOffset = 201000000000;
|
|
||||||
const int btsInt = static_cast<int>(btsll - yearOffset);
|
|
||||||
return btsInt;
|
|
||||||
}
|
|
||||||
return 0; // intentionally 0 => 0.7.3.0 <-
|
|
||||||
}
|
|
||||||
|
|
||||||
const QStringList &CBuildConfig::getBuildAbiParts()
|
const QStringList &CBuildConfig::getBuildAbiParts()
|
||||||
{
|
{
|
||||||
static const QStringList parts = QSysInfo::buildAbi().split('-');
|
static const QStringList parts = QSysInfo::buildAbi().split('-');
|
||||||
|
|||||||
@@ -118,12 +118,6 @@ namespace BlackConfig
|
|||||||
//! Returns SHA-1 of git HEAD at build time
|
//! Returns SHA-1 of git HEAD at build time
|
||||||
static const QString &gitHeadSha1();
|
static const QString &gitHeadSha1();
|
||||||
|
|
||||||
//! Timestamp of the last commit (NOT the authored timestamp)
|
|
||||||
static const QDateTime &lastCommitTimestamp(); // defined in buildconfig_gen.cpp.in
|
|
||||||
|
|
||||||
//! Build timestamp
|
|
||||||
static const QDateTime &buildTimestamp();
|
|
||||||
|
|
||||||
//! Returns the build date and time as string
|
//! Returns the build date and time as string
|
||||||
static const QString &buildDateAndTime();
|
static const QString &buildDateAndTime();
|
||||||
|
|
||||||
@@ -139,15 +133,9 @@ namespace BlackConfig
|
|||||||
//! Version as QVersionNumber plus platform info
|
//! Version as QVersionNumber plus platform info
|
||||||
static const QString &getVersionStringPlatform();
|
static const QString &getVersionStringPlatform();
|
||||||
|
|
||||||
//! Turns last commit timestamp into a version number
|
|
||||||
static int lastCommitTimestampAsVersionSegment(const QDateTime &lastCommitTimestamp);
|
|
||||||
|
|
||||||
//! Build ABI parts as in http://doc.qt.io/qt-5/qsysinfo.html#buildAbi
|
//! Build ABI parts as in http://doc.qt.io/qt-5/qsysinfo.html#buildAbi
|
||||||
static const QStringList &getBuildAbiParts();
|
static const QStringList &getBuildAbiParts();
|
||||||
|
|
||||||
//! Turn build timestamp into 4th version segment
|
|
||||||
static int buildTimestampAsVersionSegment(const QDateTime &buildTimestamp);
|
|
||||||
|
|
||||||
//! Whether this swift application is build as 32 or 64bit application
|
//! Whether this swift application is build as 32 or 64bit application
|
||||||
//! \returns 32, 64 or -1 (in case no info is possible)
|
//! \returns 32, 64 or -1 (in case no info is possible)
|
||||||
static int buildWordSize();
|
static int buildWordSize();
|
||||||
@@ -161,6 +149,9 @@ namespace BlackConfig
|
|||||||
|
|
||||||
//! Patch version
|
//! Patch version
|
||||||
static constexpr int versionMicro(); // defined in buildconfig_gen.inc.in
|
static constexpr int versionMicro(); // defined in buildconfig_gen.inc.in
|
||||||
|
|
||||||
|
//! Revision version
|
||||||
|
static int versionRevision(); // defined in buildconfig_gen.cpp.in
|
||||||
};
|
};
|
||||||
} // ns
|
} // ns
|
||||||
|
|
||||||
|
|||||||
@@ -37,18 +37,4 @@ const QString &BlackConfig::CBuildConfig::gitHeadSha1()
|
|||||||
return gitHeadSha1;
|
return gitHeadSha1;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Private
|
int BlackConfig::CBuildConfig::versionRevision() { return $$GIT_REV_COUNT; }
|
||||||
{
|
|
||||||
const QDateTime lastCommitTimestampImpl()
|
|
||||||
{
|
|
||||||
QDateTime dt = QDateTime::fromString(\"$$GIT_COMMIT_TS\", \"yyyyMMddHHmm\");
|
|
||||||
dt.setTimeSpec(Qt::UTC);
|
|
||||||
return dt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const QDateTime &BlackConfig::CBuildConfig::lastCommitTimestamp()
|
|
||||||
{
|
|
||||||
static const QDateTime dt = Private::lastCommitTimestampImpl();
|
|
||||||
return dt;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -223,31 +223,10 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
if (filename.isEmpty()) { return {}; }
|
if (filename.isEmpty()) { return {}; }
|
||||||
|
|
||||||
// swift-installer-linux-64-0.7.3_2017-03-25_11-24-50.run
|
// swiftinstaller-linux-64-0.9.2.123.run
|
||||||
thread_local const QRegularExpression firstSegments("\\d+\\.\\d+\\.\\d+");
|
thread_local const QRegularExpression regex { R"(\d+\.\d+\.\d+\.\d+)" };
|
||||||
const QRegularExpressionMatch firstSegmentsMatch = firstSegments.match(filename);
|
const QRegularExpressionMatch match = regex.match(filename);
|
||||||
if (!firstSegmentsMatch.hasMatch())
|
return match.captured();
|
||||||
{
|
|
||||||
return {}; // no version, invalid
|
|
||||||
}
|
|
||||||
QString v = firstSegmentsMatch.captured(0); // first 3 segments, like 0.9.3
|
|
||||||
if (!v.endsWith('.')) { v += '.'; }
|
|
||||||
|
|
||||||
thread_local const QRegularExpression ts1("\\d{4}.?\\d{2}.?\\d{2}.?\\d{2}.?\\d{2}.?\\d{2}");
|
|
||||||
const QRegularExpressionMatch ts1Match = ts1.match(filename);
|
|
||||||
if (!ts1Match.hasMatch())
|
|
||||||
{
|
|
||||||
// version without timestamp
|
|
||||||
v += "0";
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QString versionTimestampString = digitOnlyString(ts1Match.captured(0));
|
|
||||||
const QDateTime versionTimestamp = fromStringUtc(versionTimestampString, "yyyyMMddHHmmss");
|
|
||||||
const QString lastSegment = QString::number(CBuildConfig::buildTimestampAsVersionSegment(versionTimestamp));
|
|
||||||
|
|
||||||
v += lastSegment;
|
|
||||||
return v;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CArtifact::ArtifactType CArtifact::stringToType(const QString &str)
|
CArtifact::ArtifactType CArtifact::stringToType(const QString &str)
|
||||||
@@ -273,10 +252,9 @@ namespace BlackMisc
|
|||||||
|
|
||||||
QString CArtifact::trim4thSegment(const QString &seg)
|
QString CArtifact::trim4thSegment(const QString &seg)
|
||||||
{
|
{
|
||||||
// yyyyMMddHHmmss (14): offset is 2010xxxxx
|
// old schema: yMMddHHmm (9)
|
||||||
if (seg.length() <= 13) { return seg; }
|
if (seg.length() >= 9) { return QStringLiteral("0"); }
|
||||||
const int fs = CBuildConfig::buildTimestampAsVersionSegment(fromStringUtc(seg, "yyyyMMddHHmmss"));
|
return seg;
|
||||||
return QString::number(fs);
|
|
||||||
}
|
}
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -87,17 +87,7 @@ namespace XSwiftBus
|
|||||||
|
|
||||||
std::string CService::getVersionNumber() const
|
std::string CService::getVersionNumber() const
|
||||||
{
|
{
|
||||||
std::string version(XSWIFTBUS_VERSION);
|
return XSWIFTBUS_VERSION;
|
||||||
const std::string lastCommitTs(GIT_COMMIT_TS);
|
|
||||||
|
|
||||||
const long long lctsll = std::stoll(lastCommitTs); // at least 64bit
|
|
||||||
// now we have to converto int
|
|
||||||
// max 2147483647 (2^31 - 1)
|
|
||||||
// 1MMddHHmm (years since 2010)
|
|
||||||
const long long yearOffset = 201000000000;
|
|
||||||
const int lctsInt = static_cast<int>(lctsll - yearOffset);
|
|
||||||
version = version + "." + std::to_string(lctsInt);
|
|
||||||
return version;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string CService::getCommitHash() const
|
std::string CService::getCommitHash() const
|
||||||
|
|||||||
@@ -72,19 +72,7 @@ DEFINES += XPLM210=1
|
|||||||
DEFINES += XPMP_CLIENT_NAME=\\\"xswiftbus\\\"
|
DEFINES += XPMP_CLIENT_NAME=\\\"xswiftbus\\\"
|
||||||
DEFINES += XPMP_CLIENT_LONGNAME=\\\"xswiftbus\\\"
|
DEFINES += XPMP_CLIENT_LONGNAME=\\\"xswiftbus\\\"
|
||||||
|
|
||||||
win32: GIT_BIN = $$system($$(SYSTEMROOT)\system32\where git 2> nul)
|
DEFINES += XSWIFTBUS_VERSION=\\\"$$swiftConfig(version.full).$$VER_REV\\\"
|
||||||
else: GIT_BIN = $$system(which git 2> /dev/null)
|
|
||||||
|
|
||||||
isEmpty(GIT_BIN) {
|
|
||||||
GIT_HEAD_SHA1="<unknown>"
|
|
||||||
GIT_COMMIT_TS="0"
|
|
||||||
} else {
|
|
||||||
GIT_HEAD_SHA1=$$system(git rev-parse --short HEAD)
|
|
||||||
GIT_COMMIT_TS=$$system(git log -1 --date=format:'%Y%m%d%H%M' --pretty=format:%cd)
|
|
||||||
}
|
|
||||||
|
|
||||||
DEFINES += XSWIFTBUS_VERSION=\\\"$$swiftConfig(version.full)\\\"
|
|
||||||
DEFINES += GIT_COMMIT_TS=\\\"$$GIT_COMMIT_TS\\\"
|
|
||||||
|
|
||||||
isEmpty(XSWIFTBUS_COMMIT): error(Missing XSWIFTBUS_COMMIT variable)
|
isEmpty(XSWIFTBUS_COMMIT): error(Missing XSWIFTBUS_COMMIT variable)
|
||||||
DEFINES += XSWIFTBUS_COMMIT=\\\"$$XSWIFTBUS_COMMIT\\\"
|
DEFINES += XSWIFTBUS_COMMIT=\\\"$$XSWIFTBUS_COMMIT\\\"
|
||||||
|
|||||||
Reference in New Issue
Block a user