diff options
author | Ivan Komissarov <abbapoh@gmail.com> | 2023-05-18 02:19:35 +0300 |
---|---|---|
committer | Ivan Komissarov <abbapoh@gmail.com> | 2023-05-18 11:14:43 +0300 |
commit | 6d9cc029235e7fb686923f8bdc75c94ad2d15b55 (patch) | |
tree | c9fc36cb5e0c9d279208b2aa82a40904f233ccdb | |
parent | a6a15d0ef9d2a91af23221cabdbe454225631e09 (diff) | |
parent | 610508fcbf95b16567a17f53fd370f9b0ae3505b (diff) |
Merge branch '2.0' into master
Change-Id: I3ee32bc62c313a525fe46949a4d99f97bf2d8946
-rw-r--r-- | share/qbs/module-providers/Qt/templates/qml.js | 2 | ||||
-rw-r--r-- | share/qbs/modules/cpp/msvc.js | 26 | ||||
-rw-r--r-- | src/lib/corelib/jsextensions/utilitiesextension.cpp | 4 | ||||
-rw-r--r-- | src/lib/corelib/tools/scripttools.cpp | 22 | ||||
-rw-r--r-- | tests/auto/blackbox/testdata/whole-archive/whole-archive.qbs | 1 | ||||
-rw-r--r-- | tests/auto/language/testdata/throw.qbs | 16 | ||||
-rw-r--r-- | tests/auto/language/tst_language.cpp | 35 | ||||
-rw-r--r-- | tests/auto/language/tst_language.h | 2 |
8 files changed, 89 insertions, 19 deletions
diff --git a/share/qbs/module-providers/Qt/templates/qml.js b/share/qbs/module-providers/Qt/templates/qml.js index ad76a0d0f..38462dcf7 100644 --- a/share/qbs/module-providers/Qt/templates/qml.js +++ b/share/qbs/module-providers/Qt/templates/qml.js @@ -93,7 +93,7 @@ function getLibsForPlugin(pluginData, product) otherLibsLine = otherLibsLine.replace(/\$\$\[QT_INSTALL_PLUGINS\]/g, qtPluginDir); otherLibsLine = otherLibsLine.replace(/\$\$\[QT_INSTALL_PREFIX\]/g, qtDir); otherLibsLine = otherLibsLine.replace(/\$\$\[QT_INSTALL_QML\]/g, qtQmlPath); - otherLibs = otherLibs.concat(otherLibsLine.split(' ')); + otherLibs = otherLibs.concat(otherLibsLine.split(' ').map(FileInfo.cleanPath)); } } if (!pluginLib) diff --git a/share/qbs/modules/cpp/msvc.js b/share/qbs/modules/cpp/msvc.js index 8be4bff24..6127279fb 100644 --- a/share/qbs/modules/cpp/msvc.js +++ b/share/qbs/modules/cpp/msvc.js @@ -79,8 +79,8 @@ function hasCxx17Option(input) { // Probably this is not the earliest version to support the flag, but we have tested this one // and it's a pain to find out the exact minimum. - return Utilities.versionCompare(input.cpp.compilerVersion, "19.12.25831") >= 0 - || (input.qbs.toolchain.includes("clang-cl") && input.cpp.compilerVersionMajor >= 7); + return (input.qbs.toolchain.includes("clang-cl") && input.cpp.compilerVersionMajor >= 7) + || Utilities.versionCompare(input.cpp.compilerVersion, "19.12.25831") >= 0; } function hasZCplusPlusOption(input) @@ -92,20 +92,20 @@ function hasZCplusPlusOption(input) // clang-cl supports this option starting around-ish versions 8/9, but it // ignores this option, so this doesn't really matter // https://reviews.llvm.org/D45877 - return Utilities.versionCompare(input.cpp.compilerVersion, "19.14.26433") >= 0 - || (input.qbs.toolchain.includes("clang-cl") && input.cpp.compilerVersionMajor >= 9); + return (input.qbs.toolchain.includes("clang-cl") && input.cpp.compilerVersionMajor >= 9) + || Utilities.versionCompare(input.cpp.compilerVersion, "19.14.26433") >= 0; } function hasCxx20Option(input) { - return Utilities.versionCompare(input.cpp.compilerVersion, "19.29.30133.0") >= 0 - || (input.qbs.toolchain.includes("clang-cl") && input.cpp.compilerVersionMajor >= 13); + return (input.qbs.toolchain.includes("clang-cl") && input.cpp.compilerVersionMajor >= 13) + || Utilities.versionCompare(input.cpp.compilerVersion, "19.29.30133.0") >= 0; } function hasCVerOption(input) { - return Utilities.versionCompare(input.cpp.compilerVersion, "19.29.30138.0") >= 0 - || (input.qbs.toolchain.includes("clang-cl") && input.cpp.compilerVersionMajor >= 13); + return (input.qbs.toolchain.includes("clang-cl") && input.cpp.compilerVersionMajor >= 13) + || Utilities.versionCompare(input.cpp.compilerVersion, "19.29.30138.0") >= 0; } function supportsExternalIncludesOption(input) { @@ -124,10 +124,9 @@ function addCxxLanguageVersionFlag(input, args) { if (!cxxVersion) return; - // Visual C++ 2013, Update 3 - var hasStdOption = Utilities.versionCompare(input.cpp.compilerVersion, "18.00.30723") >= 0 - // or clang-cl - || input.qbs.toolchain.includes("clang-cl"); + // Visual C++ 2013, Update 3 or clang-cl + var hasStdOption = input.qbs.toolchain.includes("clang-cl") + || Utilities.versionCompare(input.cpp.compilerVersion, "18.00.30723") >= 0; if (!hasStdOption) return; @@ -371,7 +370,8 @@ function prepareCompiler(project, product, inputs, outputs, input, output, expli function linkerSupportsWholeArchive(product) { - return Utilities.versionCompare(product.cpp.compilerVersion, "19.0.24215.1") >= 0 + return product.qbs.toolchainType.includes("clang-cl") || + Utilities.versionCompare(product.cpp.compilerVersion, "19.0.24215.1") >= 0 } function handleDiscardProperty(product, flags) { diff --git a/src/lib/corelib/jsextensions/utilitiesextension.cpp b/src/lib/corelib/jsextensions/utilitiesextension.cpp index ea8eb0ddc..e733d618b 100644 --- a/src/lib/corelib/jsextensions/utilitiesextension.cpp +++ b/src/lib/corelib/jsextensions/utilitiesextension.cpp @@ -686,8 +686,8 @@ JSValue UtilitiesExtension::js_versionCompare(JSContext *ctx, JSValueConst, try { const auto args = getArguments<QString, QString>(ctx, "Utilities.versionCompare", argc, argv); - const auto a = Version::fromString(std::get<0>(args)); - const auto b = Version::fromString(std::get<1>(args)); + const auto a = Version::fromString(std::get<0>(args), true); + const auto b = Version::fromString(std::get<1>(args), true); return JS_NewInt32(ctx, compare(a, b)); } catch (const QString &error) { return throwError(ctx, error); } } diff --git a/src/lib/corelib/tools/scripttools.cpp b/src/lib/corelib/tools/scripttools.cpp index a9fa1955d..83005c788 100644 --- a/src/lib/corelib/tools/scripttools.cpp +++ b/src/lib/corelib/tools/scripttools.cpp @@ -44,6 +44,9 @@ #include <QtCore/qdatastream.h> #include <QtCore/qdatetime.h> +#include <QtCore/qjsonarray.h> +#include <QtCore/qjsondocument.h> +#include <QtCore/qjsonobject.h> namespace qbs { namespace Internal { @@ -90,9 +93,22 @@ JsException::~JsException() { JS_FreeValue(m_ctx, m_exception); } QString JsException::message() const { - if (JS_IsString(m_exception)) - return getJsString(m_ctx, m_exception); - return getJsStringProperty(m_ctx, m_exception, QStringLiteral("message")); + if (JS_IsError(m_ctx, m_exception)) + return getJsStringProperty(m_ctx, m_exception, QStringLiteral("message")); + const QVariant v = getJsVariant(m_ctx, m_exception); + switch (static_cast<QMetaType::Type>(v.userType())) { + case QMetaType::QVariantMap: + return QString::fromUtf8(QJsonDocument(QJsonObject::fromVariantMap(v.toMap())) + .toJson(QJsonDocument::Indented)); + case QMetaType::QStringList: + return QString::fromUtf8(QJsonDocument(QJsonArray::fromStringList(v.toStringList())) + .toJson(QJsonDocument::Indented)); + case QMetaType::QVariantList: + return QString::fromUtf8(QJsonDocument(QJsonArray::fromVariantList(v.toList())) + .toJson(QJsonDocument::Indented)); + default: + return v.toString(); + } } const QStringList JsException::stackTrace() const diff --git a/tests/auto/blackbox/testdata/whole-archive/whole-archive.qbs b/tests/auto/blackbox/testdata/whole-archive/whole-archive.qbs index ec46938ab..c138e46c0 100644 --- a/tests/auto/blackbox/testdata/whole-archive/whole-archive.qbs +++ b/tests/auto/blackbox/testdata/whole-archive/whole-archive.qbs @@ -33,6 +33,7 @@ Project { property string dummy: product.linkWholeArchive // To force probe re-execution configure: { if (!toolchain.includes("msvc") + || toolchain.includes("clang-cl") || Utilities.versionCompare(compilerVersion, "19.0.24215.1") >= 0) { console.info("can link whole archives"); } else { diff --git a/tests/auto/language/testdata/throw.qbs b/tests/auto/language/testdata/throw.qbs new file mode 100644 index 000000000..e9a97efb5 --- /dev/null +++ b/tests/auto/language/testdata/throw.qbs @@ -0,0 +1,16 @@ +Project { + property string throwType + property bool dummy: { + if (throwType === "bool") + throw true; + if (throwType === "int") + throw 43; + if (throwType === "string") + throw "an error"; + if (throwType === "list") + throw ["an", "error"]; + if (throwType === "object") + throw { result: "crash", reason: "overheating" }; + throw "type missing"; + } +} diff --git a/tests/auto/language/tst_language.cpp b/tests/auto/language/tst_language.cpp index c97b83cc1..6b7850214 100644 --- a/tests/auto/language/tst_language.cpp +++ b/tests/auto/language/tst_language.cpp @@ -65,6 +65,7 @@ #include <tools/settings.h> #include <tools/stlutils.h> +#include <QtCore/qjsonobject.h> #include <QtCore/qprocess.h> #include <algorithm> @@ -370,6 +371,40 @@ void TestLanguage::rfc1034Identifier() QCOMPARE(exceptionCaught, false); } +void TestLanguage::throwThings_data() +{ + QTest::addColumn<QString>("type"); + QTest::addColumn<QString>("result"); + QTest::addRow("bool") << "bool" << "true"; + QTest::addRow("int") << "int" << "43"; + QTest::addRow("string") << "string" << "an error"; + QTest::addRow("list") << "list" << R"([ + "an", + "error" +])"; + QTest::addRow("object") << "object" << R"({ + "reason": "overheating", + "result": "crash" +})"; +} + +void TestLanguage::throwThings() +{ + QFETCH(QString, type); + QFETCH(QString, result); + bool exceptionCaught = false; + try { + SetupProjectParameters params = defaultParameters; + params.setProjectFilePath(testProject("throw.qbs")); + params.setOverriddenValues({{"project.throwType", type}}); + m_resolver->resolve(params); + } catch (const ErrorInfo &e) { + exceptionCaught = true; + QVERIFY2(e.toString().contains(result), qPrintable(e.toString())); + } + QVERIFY(exceptionCaught); +} + void TestLanguage::conditionalDepends() { bool exceptionCaught = false; diff --git a/tests/auto/language/tst_language.h b/tests/auto/language/tst_language.h index 1229157b2..738d94c58 100644 --- a/tests/auto/language/tst_language.h +++ b/tests/auto/language/tst_language.h @@ -180,6 +180,8 @@ private slots: void qualifiedId(); void recursiveProductDependencies(); void rfc1034Identifier(); + void throwThings_data(); + void throwThings(); void useInternalProfile(); void versionCompare(); void wildcards_data(); |