diff options
author | Jake Petroules <jake.petroules@petroules.com> | 2015-05-11 23:27:29 -0700 |
---|---|---|
committer | Jake Petroules <jake.petroules@petroules.com> | 2015-05-13 16:41:00 +0000 |
commit | fe338544dceefe0af2513fef0d621818a3f1052b (patch) | |
tree | 385d173b87980dffdcea48be13e2fbb5617a2566 | |
parent | c4bdc55cb0709dec7cd9ca570792dbd635b61c60 (diff) |
Provide access to the Qbs version from project files.
Task-number: QBS-788
Change-Id: Ie6155e519a58cbddfaa1cf18787613376d89289f
Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
-rw-r--r-- | doc/reference/modules/qbs-module.qdoc | 32 | ||||
-rw-r--r-- | share/qbs/modules/qbs/common.qbs | 6 | ||||
-rw-r--r-- | src/lib/corelib/language/moduleloader.cpp | 8 | ||||
-rw-r--r-- | tests/auto/blackbox/testdata/qbsVersion/qbs-version.qbs | 22 | ||||
-rw-r--r-- | tests/auto/blackbox/tst_blackbox.cpp | 18 | ||||
-rw-r--r-- | tests/auto/blackbox/tst_blackbox.h | 1 |
6 files changed, 87 insertions, 0 deletions
diff --git a/doc/reference/modules/qbs-module.qdoc b/doc/reference/modules/qbs-module.qdoc index cfe7be0ee..678003092 100644 --- a/doc/reference/modules/qbs-module.qdoc +++ b/doc/reference/modules/qbs-module.qdoc @@ -306,5 +306,37 @@ Holds the platform-specific separator for path list that is used in environment variables or other contexts. E.g. on Windows is this \c{";"}, on Unix derivatives \c{":"}. + + \section1 version + + \table + \row \li \b{Type:} \li \c{string} (read only) + \endtable + + Version number of \QBS as a string, i.e. "1.4.1". + + \section1 versionMajor + + \table + \row \li \b{Type:} \li \c{int} (read only) + \endtable + + Major version number of \QBS. + + \section1 versionMinor + + \table + \row \li \b{Type:} \li \c{int} (read only) + \endtable + + Minor version number of \QBS. + + \section1 versionPatch + + \table + \row \li \b{Type:} \li \c{int} (read only) + \endtable + + Patch version number of \QBS. */ diff --git a/share/qbs/modules/qbs/common.qbs b/share/qbs/modules/qbs/common.qbs index 7d3a0060d..ebf60a0b7 100644 --- a/share/qbs/modules/qbs/common.qbs +++ b/share/qbs/modules/qbs/common.qbs @@ -146,4 +146,10 @@ Module { return env; } + + // internal properties + readonly property string version: [versionMajor, versionMinor, versionPatch].join(".") + readonly property int versionMajor: undefined // set internally + readonly property int versionMinor: undefined // set internally + readonly property int versionPatch: undefined // set internally } diff --git a/src/lib/corelib/language/moduleloader.cpp b/src/lib/corelib/language/moduleloader.cpp index 176419c6b..73ea5e7fb 100644 --- a/src/lib/corelib/language/moduleloader.cpp +++ b/src/lib/corelib/language/moduleloader.cpp @@ -1126,6 +1126,14 @@ void ModuleLoader::setupBaseModulePrototype(Item *prototype) BuiltinValue::create(BuiltinValue::CanonicalArchitectureFunction)); prototype->setProperty(QLatin1String("rfc1034Identifier"), BuiltinValue::create(BuiltinValue::Rfc1034IdentifierFunction)); + + const Version qbsVersion = Version::qbsVersion(); + prototype->setProperty(QLatin1String("versionMajor"), + VariantValue::create(qbsVersion.majorVersion())); + prototype->setProperty(QLatin1String("versionMinor"), + VariantValue::create(qbsVersion.minorVersion())); + prototype->setProperty(QLatin1String("versionPatch"), + VariantValue::create(qbsVersion.patchLevel())); } static void collectItemsWithId_impl(Item *item, QList<Item *> *result) diff --git a/tests/auto/blackbox/testdata/qbsVersion/qbs-version.qbs b/tests/auto/blackbox/testdata/qbsVersion/qbs-version.qbs new file mode 100644 index 000000000..b07ee494e --- /dev/null +++ b/tests/auto/blackbox/testdata/qbsVersion/qbs-version.qbs @@ -0,0 +1,22 @@ +import qbs + +Project { + property string qbsVersion + property int qbsVersionMajor + property int qbsVersionMinor + property int qbsVersionPatch + + Product { + name: { + if (qbsVersion !== qbs.version || + qbsVersionMajor !== qbs.versionMajor || + qbsVersionMinor !== qbs.versionMinor || + qbsVersionPatch !== qbs.versionPatch) + throw("expected " + + [qbsVersion, qbsVersionMajor, qbsVersionMinor, qbsVersionPatch].join(", ") + + ", got " + + [qbs.version, qbs.versionMajor, qbs.versionMinor, qbs.versionPatch].join(", ")); + return "foo"; + } + } +} diff --git a/tests/auto/blackbox/tst_blackbox.cpp b/tests/auto/blackbox/tst_blackbox.cpp index 1f24b1a26..86e02ba54 100644 --- a/tests/auto/blackbox/tst_blackbox.cpp +++ b/tests/auto/blackbox/tst_blackbox.cpp @@ -37,6 +37,7 @@ #include <tools/installoptions.h> #include <tools/profile.h> #include <tools/settings.h> +#include <tools/version.h> #include <QLocale> #include <QRegExp> @@ -2322,4 +2323,21 @@ void TestBlackbox::testBadInterpreter() QCOMPARE(runQbs(QbsRunParameters("run", QStringList() << "-p" << "script-ok")), 0); } +void TestBlackbox::qbsVersion() +{ + const qbs::Internal::Version v = qbs::Internal::Version::qbsVersion(); + QDir::setCurrent(testDataDir + QLatin1String("/qbsVersion")); + QbsRunParameters params; + params.arguments = QStringList() + << "project.qbsVersion:" + v.toString() + << "project.qbsVersionMajor:" + QString::number(v.majorVersion()) + << "project.qbsVersionMinor:" + QString::number(v.minorVersion()) + << "project.qbsVersionPatch:" + QString::number(v.patchLevel()); + QCOMPARE(runQbs(params), 0); + + params.arguments.append("project.qbsVersionPatch:" + QString::number(v.patchLevel() + 1)); + params.expectFailure = true; + QVERIFY(runQbs(params) != 0); +} + QTEST_MAIN(TestBlackbox) diff --git a/tests/auto/blackbox/tst_blackbox.h b/tests/auto/blackbox/tst_blackbox.h index 2a5fa0f89..90914b4c9 100644 --- a/tests/auto/blackbox/tst_blackbox.h +++ b/tests/auto/blackbox/tst_blackbox.h @@ -172,6 +172,7 @@ private slots: void wildCardsAndRules(); void testLoadableModule(); void testBadInterpreter(); + void qbsVersion(); private: QByteArray m_qbsStderr; |