diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2019-07-22 15:51:50 +0200 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2019-08-14 11:44:51 +0000 |
commit | 18a3b64ab07ade6bfc9bb068956beed2032d9b58 (patch) | |
tree | 7bcb18c36f05508457074d783197cdd3f37f9fd6 /tests | |
parent | 5320c8578b600081d9c5174f4024b726c5bdefa0 (diff) |
C++: Add support for clang on Windows
This is about clang in "mingw mode", not clang-cl.
When targeting Windows, clang is a lot like mingw, so factor out the
common parts into a new base module.
Testing uncovered a number of invalid assumptions in our autotests,
which are also fixed in this patch. In addition, minor adjustments had
to be made to the Qt.core module and to the qbscore lib.
Change-Id: I73085dc62a65e2a9d0397cf234c8641989246f22
Reviewed-by: Ivan Komissarov <ABBAPOH@gmail.com>
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'tests')
11 files changed, 108 insertions, 16 deletions
diff --git a/tests/auto/api/testdata/infinite-loop-process/infinite-loop.qbs b/tests/auto/api/testdata/infinite-loop-process/infinite-loop.qbs index f0de12df1..f4ea8bf83 100644 --- a/tests/auto/api/testdata/infinite-loop-process/infinite-loop.qbs +++ b/tests/auto/api/testdata/infinite-loop-process/infinite-loop.qbs @@ -4,12 +4,21 @@ Project { consoleApplication: true // suppress bundle generation files: "main.cpp" name: "infinite-loop" + cpp.cxxLanguageVersion: "c++11" + Properties { + condition: qbs.toolchain.contains("gcc") + cpp.driverFlags: "-pthread" + } } Product { type: "mytype" name: "caller" Depends { name: "infinite-loop" } + Depends { + name: "cpp" // Make sure build environment is set up properly. + condition: qbs.hostOS.contains("windows") && qbs.toolchain.contains("gcc") + } Rule { inputsFromDependencies: "application" outputFileTags: "mytype" diff --git a/tests/auto/api/testdata/link-staticlibs-dynamiclibs/link-staticlibs-dynamiclibs.qbs b/tests/auto/api/testdata/link-staticlibs-dynamiclibs/link-staticlibs-dynamiclibs.qbs index eade97126..d7ed6c862 100644 --- a/tests/auto/api/testdata/link-staticlibs-dynamiclibs/link-staticlibs-dynamiclibs.qbs +++ b/tests/auto/api/testdata/link-staticlibs-dynamiclibs/link-staticlibs-dynamiclibs.qbs @@ -11,6 +11,13 @@ Project { files: [ "static1.cpp" ] Depends { name: "cpp" } Depends { name: "dynamic1" } + + Probe { + id: osCheck + property bool isNormalUnix: qbs.targetOS.contains("unix") + && !qbs.targetOS.contains("darwin") + configure: { console.info("is normal unix: " + (isNormalUnix ? "yes" : "no")); } + } } DynamicLibrary { diff --git a/tests/auto/api/testdata/timeout-process/timeout.qbs b/tests/auto/api/testdata/timeout-process/timeout.qbs index 3f79dce96..bdf6833fd 100644 --- a/tests/auto/api/testdata/timeout-process/timeout.qbs +++ b/tests/auto/api/testdata/timeout-process/timeout.qbs @@ -5,12 +5,20 @@ Project { files: "main.cpp" name: "infinite-loop" cpp.cxxLanguageVersion: "c++11" + Properties { + condition: qbs.toolchain.contains("gcc") + cpp.driverFlags: "-pthread" + } } Product { type: "product-under-test" name: "caller" Depends { name: "infinite-loop" } + Depends { + name: "cpp" // Make sure build environment is set up properly. + condition: qbs.hostOS.contains("windows") && qbs.toolchain.contains("gcc") + } Rule { inputsFromDependencies: "application" outputFileTags: "product-under-test" diff --git a/tests/auto/api/tst_api.cpp b/tests/auto/api/tst_api.cpp index 1a98f5f21..36a98fdaa 100644 --- a/tests/auto/api/tst_api.cpp +++ b/tests/auto/api/tst_api.cpp @@ -1556,9 +1556,13 @@ void TestApi::linkStaticAndDynamicLibs() BuildDescriptionReceiver bdr; qbs::BuildOptions options; options.setEchoMode(qbs::CommandEchoModeCommandLine); + m_logSink->output.clear(); const qbs::ErrorInfo errorInfo = doBuildProject("link-staticlibs-dynamiclibs", &bdr, nullptr, nullptr, options); VERIFY_NO_ERROR(errorInfo); + const bool isNormalUnix = m_logSink->output.contains("is normal unix: yes"); + const bool isNotNormalUnix = m_logSink->output.contains("is normal unix: no"); + QVERIFY2(isNormalUnix != isNotNormalUnix, qPrintable(m_logSink->output)); // The dependencies libdynamic1.so and libstatic2.a must not appear in the link command for the // executable. The -rpath-link line for libdynamic1.so must be there. @@ -1575,12 +1579,7 @@ void TestApi::linkStaticAndDynamicLibs() } } QVERIFY(!appLinkCmd.isEmpty()); - std::string targetPlatform = buildProfile.value("qbs.targetPlatform") - .toString().toStdString(); - std::vector<std::string> targetOS = qbs::Internal::HostOsInfo::canonicalOSIdentifiers( - targetPlatform); - if (!qbs::Internal::contains(targetOS, "darwin") - && !qbs::Internal::contains(targetOS, "windows")) { + if (isNormalUnix) { const std::regex rpathLinkRex("-rpath-link=\\S*/" + relativeProductBuildDir("dynamic2").toStdString()); const auto ln = appLinkCmd.toStdString(); @@ -2861,7 +2860,7 @@ void TestApi::timeout() QVERIFY(waitForFinished(buildJob.get(), testTimeoutInMsecs())); QVERIFY(buildJob->error().hasError()); const auto errorString = buildJob->error().toString(); - QVERIFY(errorString.contains("cancel")); + QVERIFY2(errorString.contains("cancel"), qPrintable(errorString)); QVERIFY(errorString.contains("timeout")); } diff --git a/tests/auto/blackbox/testdata/autotest-timeout/autotests-timeout.qbs b/tests/auto/blackbox/testdata/autotest-timeout/autotests-timeout.qbs index 270fc9eaf..d4f01895f 100644 --- a/tests/auto/blackbox/testdata/autotest-timeout/autotests-timeout.qbs +++ b/tests/auto/blackbox/testdata/autotest-timeout/autotests-timeout.qbs @@ -4,7 +4,16 @@ Project { type: ["application", "autotest"] Depends { name: "autotest" } cpp.cxxLanguageVersion: "c++11" + Properties { + condition: qbs.toolchain.contains("gcc") + cpp.driverFlags: "-pthread" + } files: "test-main.cpp" } - AutotestRunner {} + AutotestRunner { + Depends { + name: "cpp" // Make sure build environment is set up properly. + condition: qbs.hostOS.contains("windows") && qbs.toolchain.contains("gcc") + } + } } diff --git a/tests/auto/blackbox/testdata/autotest-with-dependencies/autotest-with-dependencies.qbs b/tests/auto/blackbox/testdata/autotest-with-dependencies/autotest-with-dependencies.qbs index 92d5ec6dd..7ae6cef73 100644 --- a/tests/auto/blackbox/testdata/autotest-with-dependencies/autotest-with-dependencies.qbs +++ b/tests/auto/blackbox/testdata/autotest-with-dependencies/autotest-with-dependencies.qbs @@ -21,6 +21,10 @@ Project { } AutotestRunner { + Depends { + name: "cpp" // Make sure build environment is set up properly. + condition: qbs.hostOS.contains("windows") && qbs.toolchain.contains("gcc") + } arguments: FileInfo.joinPaths(qbs.installRoot, qbs.installPrefix, "bin") auxiliaryInputs: "test-helper" } diff --git a/tests/auto/blackbox/testdata/autotests/autotests.qbs b/tests/auto/blackbox/testdata/autotests/autotests.qbs index a2c2646dc..10334156e 100644 --- a/tests/auto/blackbox/testdata/autotests/autotests.qbs +++ b/tests/auto/blackbox/testdata/autotests/autotests.qbs @@ -1,4 +1,9 @@ Project { references: ["test1", "test2", "test3"] - AutotestRunner {} + AutotestRunner { + Depends { + name: "cpp" // Make sure build environment is set up properly. + condition: qbs.hostOS.contains("windows") && qbs.toolchain.contains("gcc") + } + } } diff --git a/tests/auto/blackbox/testdata/lexyacc/one-grammar/one-grammar.qbs b/tests/auto/blackbox/testdata/lexyacc/one-grammar/one-grammar.qbs index 61f76f4be..6cd334247 100644 --- a/tests/auto/blackbox/testdata/lexyacc/one-grammar/one-grammar.qbs +++ b/tests/auto/blackbox/testdata/lexyacc/one-grammar/one-grammar.qbs @@ -8,6 +8,23 @@ CppApplication { cpp.cxxLanguageVersion: "c++11" cpp.minimumMacosVersion: "10.7" consoleApplication: true + Probe { + id: pathCheck + property string theDir: { + if (qbs.targetOS.contains("windows")) { + if (qbs.toolchain.contains("mingw")) + return cpp.toolchainInstallPath; + if (qbs.toolchain.contains("clang") && qbs.sysroot) + return qbs.sysroot + "/bin"; + } + } + configure: { + if (theDir) + console.info("add to PATH: " + theDir); + found = true; + } + } + files: [ "lexer.l", "parser.y", diff --git a/tests/auto/blackbox/testdata/separate-debug-info/separate-debug-info.qbs b/tests/auto/blackbox/testdata/separate-debug-info/separate-debug-info.qbs index 48bdff904..0b16d1984 100644 --- a/tests/auto/blackbox/testdata/separate-debug-info/separate-debug-info.qbs +++ b/tests/auto/blackbox/testdata/separate-debug-info/separate-debug-info.qbs @@ -4,6 +4,15 @@ Project { type: ["application"] files: ["main.cpp"] cpp.separateDebugInformation: true + + Probe { + id: osProbe + property stringList targetOS: qbs.targetOS + configure: { + console.info("is windows: " + (targetOS.contains("windows") ? "yes" : "no")); + console.info("is darwin: " + (targetOS.contains("darwin") ? "yes" : "no")); + } + } } DynamicLibrary { Depends { name: "cpp" } diff --git a/tests/auto/blackbox/testdata/setup-run-environment/setup-run-environment.qbs b/tests/auto/blackbox/testdata/setup-run-environment/setup-run-environment.qbs index b5ac8b289..d2d47b767 100644 --- a/tests/auto/blackbox/testdata/setup-run-environment/setup-run-environment.qbs +++ b/tests/auto/blackbox/testdata/setup-run-environment/setup-run-environment.qbs @@ -61,6 +61,16 @@ Project { bundle.isBundle: false } + // Testing shows that clang (8.0) does not find dynamic libraries via + // the -L<dir> and -l<libname> mechanism unless the name is "lib<libname>.a". + Properties { + condition: qbs.hostOS.contains("windows") && qbs.toolchain.contains("clang") + cpp.dynamicLibraryPrefix: "lib" + cpp.dynamicLibraryImportSuffix: ".a" + } + cpp.dynamicLibraryPrefix: original + cpp.dynamicLibraryImportSuffix: original + install: true installImportLib: true installDir: "lib4" @@ -91,8 +101,9 @@ Project { property string fullInstallPrefix: FileInfo.joinPaths(qbs.installRoot, qbs.installPrefix) property string lib3FilePath: FileInfo.joinPaths(fullInstallPrefix, "lib3", - cpp.dynamicLibraryPrefix + "lib3" + (qbs.toolchain.contains("msvc") - ? ".lib" : cpp.dynamicLibrarySuffix)) + cpp.dynamicLibraryPrefix + "lib3" + (qbs.targetOS.contains("windows") + ? cpp.dynamicLibraryImportSuffix + : cpp.dynamicLibrarySuffix)) cpp.dynamicLibraries: [lib3FilePath, "lib4"] cpp.libraryPaths: FileInfo.joinPaths(fullInstallPrefix, "lib4") } diff --git a/tests/auto/blackbox/tst_blackbox.cpp b/tests/auto/blackbox/tst_blackbox.cpp index edc2b51c8..31a5a92ae 100644 --- a/tests/auto/blackbox/tst_blackbox.cpp +++ b/tests/auto/blackbox/tst_blackbox.cpp @@ -1806,14 +1806,17 @@ void TestBlackbox::separateDebugInfo() { QDir::setCurrent(testDataDir + "/separate-debug-info"); QCOMPARE(runQbs(QbsRunParameters(QStringList("qbs.debugInformation:true"))), 0); + const bool isWindows = m_qbsStdout.contains("is windows: yes"); + const bool isNotWindows = m_qbsStdout.contains("is windows: no"); + QVERIFY(isWindows != isNotWindows); + const bool isDarwin = m_qbsStdout.contains("is darwin: yes"); + const bool isNotDarwin = m_qbsStdout.contains("is darwin: no"); + QVERIFY(isDarwin != isNotDarwin); const SettingsPtr s = settings(); Profile buildProfile(profileName(), s.get()); QStringList toolchain = buildProfile.value("qbs.toolchain").toStringList(); - std::string targetPlatform = buildProfile.value("qbs.targetPlatform").toString().toStdString(); - std::vector<std::string> targetOS = HostOsInfo::canonicalOSIdentifiers(targetPlatform); - if (qbs::Internal::contains(targetOS, "darwin") - || (targetPlatform.empty() && HostOsInfo::isMacosHost())) { + if (isDarwin) { QVERIFY(directoryExists(relativeProductBuildDir("app1") + "/app1.app.dSYM")); QVERIFY(regularFileExists(relativeProductBuildDir("app1") + "/app1.app.dSYM/Contents/Info.plist")); @@ -1878,7 +1881,6 @@ void TestBlackbox::separateDebugInfo() .entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries).size(), 1); QVERIFY(regularFileExists(relativeProductBuildDir("bar5") + "/bar5.bundle.dwarf")); } else if (toolchain.contains("gcc")) { - const bool isWindows = qbs::Internal::contains(targetOS, "windows"); const QString exeSuffix = isWindows ? ".exe" : ""; const QString dllPrefix = isWindows ? "" : "lib"; const QString dllSuffix = isWindows ? ".dll" : ".so"; @@ -4354,6 +4356,18 @@ void TestBlackbox::lexyacc() QCOMPARE(runQbs(), 0); const QString parserBinary = relativeExecutableFilePath("one-grammar"); QProcess p; + const QByteArray magicString = "add to PATH: "; + const int magicStringIndex = m_qbsStdout.indexOf(magicString); + if (magicStringIndex != -1) { + const int newLineIndex = m_qbsStdout.indexOf('\n', magicStringIndex); + QVERIFY(newLineIndex != -1); + const int dirIndex = magicStringIndex + magicString.length(); + const QString dir = QString::fromLocal8Bit(m_qbsStdout.mid(dirIndex, + newLineIndex - dirIndex)); + QProcessEnvironment env; + env.insert("PATH", dir); + p.setProcessEnvironment(env); + } p.start(parserBinary); QVERIFY2(p.waitForStarted(), qPrintable(p.errorString())); p.write("a && b || c && !d"); |