From 836eb107a3a4993fcbaa539879cba0af46a53ac4 Mon Sep 17 00:00:00 2001 From: Mat Sutcliffe Date: Tue, 31 Dec 2019 22:51:17 +0000 Subject: [PATCH] Smart xswiftbus compatibility check based on git commit SHA-1 This is more tolerant that the simple check based on version numbers. Different versions can be compatible if they have the same SHA-1 when considering only those files that can influence xswiftbus. --- src/plugins/simulator/xplane/simulatorxplane.cpp | 10 ++++++++-- src/plugins/simulator/xplane/xplane.pro | 3 +++ .../simulator/xplane/xswiftbusserviceproxy.cpp | 5 +++++ src/plugins/simulator/xplane/xswiftbusserviceproxy.h | 3 +++ src/xswiftbus/service.cpp | 12 ++++++++++++ src/xswiftbus/service.h | 3 +++ src/xswiftbus/version.pri | 10 ++++++++++ src/xswiftbus/xswiftbus.pro | 3 +++ swift.pro | 2 ++ 9 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 src/xswiftbus/version.pri diff --git a/src/plugins/simulator/xplane/simulatorxplane.cpp b/src/plugins/simulator/xplane/simulatorxplane.cpp index a1124a3bf..c97b46db5 100644 --- a/src/plugins/simulator/xplane/simulatorxplane.cpp +++ b/src/plugins/simulator/xplane/simulatorxplane.cpp @@ -77,11 +77,16 @@ using namespace BlackCore; namespace { - inline const QString &xswiftbusServiceName() + const QString &xswiftbusServiceName() { static const QString name("org.swift-project.xswiftbus"); return name; } + const QString &commitHash() + { + static const QString hash(XSWIFTBUS_COMMIT); + return hash; + } } namespace BlackSimPlugin @@ -1362,11 +1367,12 @@ namespace BlackSimPlugin const QString swiftVersion = CBuildConfig::getVersionString(); const QString xswiftbusVersion = service.getVersionNumber(); + const QString xswiftbusCommitHash = service.getCommitHash(); if (xswiftbusVersion.isEmpty()) { CLogMessage(this).warning(u"Could not determine which version of XSwiftBus is running. Mismatched versions might cause instability."); } - else if (swiftVersion != xswiftbusVersion) + else if (commitHash() != xswiftbusCommitHash) { CLogMessage(this).error(u"You are using an incorrect version of XSwiftBus. The version of XSwiftBus (%1) should match the version of swift (%2). Consider upgrading!") << xswiftbusVersion << swiftVersion; } diff --git a/src/plugins/simulator/xplane/xplane.pro b/src/plugins/simulator/xplane/xplane.pro index 8232d2092..4b89e87cd 100644 --- a/src/plugins/simulator/xplane/xplane.pro +++ b/src/plugins/simulator/xplane/xplane.pro @@ -21,6 +21,9 @@ HEADERS += *.h DISTFILES += simulatorxplane.json DESTDIR = $$DestRoot/bin/plugins/simulator +isEmpty(XSWIFTBUS_COMMIT): error(Missing XSWIFTBUS_COMMIT variable) +DEFINES += XSWIFTBUS_COMMIT=\\\"$$XSWIFTBUS_COMMIT\\\" + win32 { dlltarget.path = $$PREFIX/bin/plugins/simulator INSTALLS += dlltarget diff --git a/src/plugins/simulator/xplane/xswiftbusserviceproxy.cpp b/src/plugins/simulator/xplane/xswiftbusserviceproxy.cpp index 2ad8849cc..94e4876b6 100644 --- a/src/plugins/simulator/xplane/xswiftbusserviceproxy.cpp +++ b/src/plugins/simulator/xplane/xswiftbusserviceproxy.cpp @@ -43,6 +43,11 @@ namespace BlackSimPlugin return m_dbusInterface->callDBusRet(QLatin1String("getVersionNumber")); } + QString CXSwiftBusServiceProxy::getCommitHash() + { + return m_dbusInterface->callDBusRet(QLatin1String("getCommitHash")); + } + void CXSwiftBusServiceProxy::getOwnAircraftSituationDataAsync(XPlaneData *o_xplaneData) { if (!o_xplaneData) { return; } diff --git a/src/plugins/simulator/xplane/xswiftbusserviceproxy.h b/src/plugins/simulator/xplane/xswiftbusserviceproxy.h index da7438bf5..6963ee664 100644 --- a/src/plugins/simulator/xplane/xswiftbusserviceproxy.h +++ b/src/plugins/simulator/xplane/xswiftbusserviceproxy.h @@ -100,6 +100,9 @@ namespace BlackSimPlugin //! Get XSwiftBus version number QString getVersionNumber(); + //! Get SHA1 of the last commit that could influence xswiftbus + QString getCommitHash(); + //! Get own aircraft situation data void getOwnAircraftSituationDataAsync(BlackSimPlugin::XPlane::XPlaneData *o_xplaneData); diff --git a/src/xswiftbus/service.cpp b/src/xswiftbus/service.cpp index 8eee9a02a..d115791f3 100644 --- a/src/xswiftbus/service.cpp +++ b/src/xswiftbus/service.cpp @@ -58,6 +58,11 @@ namespace XSwiftBus return version; } + std::string CService::getCommitHash() const + { + return XSWIFTBUS_COMMIT; + } + void CService::addTextMessage(const std::string &text, double red, double green, double blue) { if (text.empty()) { return; } @@ -253,6 +258,13 @@ namespace XSwiftBus sendDBusReply(sender, serial, getVersionNumber()); }); } + else if (message.getMethodName() == "getCommitHash") + { + queueDBusCall([ = ]() + { + sendDBusReply(sender, serial, getCommitHash()); + }); + } else if (message.getMethodName() == "addTextMessage") { maybeSendEmptyDBusReply(wantsReply, sender, serial); diff --git a/src/xswiftbus/service.h b/src/xswiftbus/service.h index 254fb57b9..e247dd6be 100644 --- a/src/xswiftbus/service.h +++ b/src/xswiftbus/service.h @@ -62,6 +62,9 @@ namespace XSwiftBus //! Returns the XSwiftBus version number std::string getVersionNumber() const; + //! Returns the SHA1 of the last commit that could influence xswiftbus. + std::string getCommitHash() const; + //! Add a text message to the on-screen display, with RGB components in the range [0,1] void addTextMessage(const std::string &text, double red, double green, double blue); diff --git a/src/xswiftbus/version.pri b/src/xswiftbus/version.pri new file mode 100644 index 000000000..be1e35009 --- /dev/null +++ b/src/xswiftbus/version.pri @@ -0,0 +1,10 @@ +# this file is included by swift.pro in the project root + +XSWIFTBUS_DEPENDENTS = $$SourceRoot/src/xswiftbus \ + $$SourceRoot/src/blackmisc/simulation/xplane/qtfreeutils.* \ + $$SourceRoot/src/blackmisc/simulation/settings/xswiftbussettingsqtfree.* + +XSWIFTBUS_COMMIT = $$system(git log -n 1 --format=%h -- $$XSWIFTBUS_DEPENDENTS) + +# make the variable available in other files without needing to be included +cache(XSWIFTBUS_COMMIT) diff --git a/src/xswiftbus/xswiftbus.pro b/src/xswiftbus/xswiftbus.pro index a94aeec3f..44865ebd0 100644 --- a/src/xswiftbus/xswiftbus.pro +++ b/src/xswiftbus/xswiftbus.pro @@ -86,6 +86,9 @@ isEmpty(GIT_BIN) { DEFINES += XSWIFTBUS_VERSION=\\\"$$swiftConfig(version.full)\\\" DEFINES += GIT_COMMIT_TS=\\\"$$GIT_COMMIT_TS\\\" +isEmpty(XSWIFTBUS_COMMIT): error(Missing XSWIFTBUS_COMMIT variable) +DEFINES += XSWIFTBUS_COMMIT=\\\"$$XSWIFTBUS_COMMIT\\\" + # X-Plane plugins must follow a prescribed filename and directory structure. TARGET_EXT = .xpl win32:TARGET = win diff --git a/swift.pro b/swift.pro index 363c3801a..6c5bf3332 100644 --- a/swift.pro +++ b/swift.pro @@ -28,4 +28,6 @@ swiftConfig(unitTests) { include(install.pri) +include(src/xswiftbus/version.pri) + load(common_post)