diff options
author | Ivan Komissarov <abbapoh@gmail.com> | 2021-10-31 18:22:02 +0300 |
---|---|---|
committer | Ivan Komissarov <ABBAPOH@gmail.com> | 2021-11-03 10:47:44 +0000 |
commit | b297983257872e8c8dfe3975dde661c6a6cbe423 (patch) | |
tree | d78931a333440a118c5d7a6fef861aefde9b94c2 | |
parent | 11c8784cfded938a6e658e6450ae1e91685e0c82 (diff) | |
download | qbs-b297983257872e8c8dfe3975dde661c6a6cbe423.tar.gz |
Implement providing Qt libs via pkg-config
Change-Id: I2675968a6e11ffea2e7d44fbfbd1a77018999a4b
Reviewed-by: Kai Dohmen <psykai1993@googlemail.com>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
7 files changed, 95 insertions, 1 deletions
diff --git a/share/qbs/module-providers/qbspkgconfig.qbs b/share/qbs/module-providers/qbspkgconfig.qbs index 261758026..0de3be776 100644 --- a/share/qbs/module-providers/qbspkgconfig.qbs +++ b/share/qbs/module-providers/qbspkgconfig.qbs @@ -45,6 +45,8 @@ import qbs.PkgConfig import qbs.Process import qbs.TextFile +import "Qt/setup-qt.js" as SetupQt + ModuleProvider { property string executableFilePath property stringList extraPaths @@ -59,10 +61,11 @@ ModuleProvider { relativeSearchPaths: { + function exeSuffix(qbs) { return qbs.hostOS.contains("windows") ? ".exe" : ""; } + // we need Probes in Providers... function getPkgConfigExecutable(qbs) { function splitNonEmpty(s, c) { return s.split(c).filter(function(e) { return e; }) } - function exeSuffix(qbs) { return qbs.hostOS.contains("windows") ? ".exe" : ""; } var pathValue = Environment.getEnv("PATH"); if (!pathValue) @@ -168,6 +171,32 @@ ModuleProvider { } } + function setupQt(pkg) { + var packageName = pkg.baseFileName; + if (packageName === "QtCore" + || packageName === "Qt5Core" + || packageName === "Qt6Core") { + var hostBins = pkg.variables["host_bins"]; + if (!hostBins) { + if (packageName === "QtCore") { // Qt4 does not have host_bins + var mocLocation = pkg.variables["moc_location"]; + if (!mocLocation) { + console.warn("No moc_location variable in " + packageName); + return; + } + hostBins = FileInfo.path(mocLocation); + } else { + console.warn("No host_bins variable in " + packageName); + return; + } + } + var suffix = exeSuffix(qbs); + var qmakePaths = [FileInfo.joinPaths(hostBins, "qmake" + suffix)]; + var qtProviderDir = FileInfo.joinPaths(path, "Qt"); + SetupQt.doSetup(qmakePaths, outputBaseDir, qtProviderDir, qbs); + } + } + var moduleMapping = { "protobuf": "protobuflib", "grpc++": "grpcpp" @@ -183,6 +212,10 @@ ModuleProvider { brokenPackages.push(pkg); continue; } + if (packageName.startsWith("Qt")) { + setupQt(pkg); + continue; + } var moduleName = moduleMapping[packageName] ? moduleMapping[packageName] : getModuleName(packageName); diff --git a/tests/auto/blackbox/testdata-qt/pkgconfig-qt/dump-libpath.qbs b/tests/auto/blackbox/testdata-qt/pkgconfig-qt/dump-libpath.qbs new file mode 100644 index 000000000..9aa1c5d17 --- /dev/null +++ b/tests/auto/blackbox/testdata-qt/pkgconfig-qt/dump-libpath.qbs @@ -0,0 +1,6 @@ +QtApplication { + files: "main.cpp" + property bool test: { + console.info("libPath="+Qt.core.libPath) + } +} diff --git a/tests/auto/blackbox/testdata-qt/pkgconfig-qt/main.cpp b/tests/auto/blackbox/testdata-qt/pkgconfig-qt/main.cpp new file mode 100644 index 000000000..237c8ce18 --- /dev/null +++ b/tests/auto/blackbox/testdata-qt/pkgconfig-qt/main.cpp @@ -0,0 +1 @@ +int main() {} diff --git a/tests/auto/blackbox/testdata-qt/pkgconfig-qt/module-providers/dummyProvider.qbs b/tests/auto/blackbox/testdata-qt/pkgconfig-qt/module-providers/dummyProvider.qbs new file mode 100644 index 000000000..6ed2ca82e --- /dev/null +++ b/tests/auto/blackbox/testdata-qt/pkgconfig-qt/module-providers/dummyProvider.qbs @@ -0,0 +1,3 @@ +ModuleProvider { + relativeSearchPaths: "" +} diff --git a/tests/auto/blackbox/testdata-qt/pkgconfig-qt/pkgconfig-qt.qbs b/tests/auto/blackbox/testdata-qt/pkgconfig-qt/pkgconfig-qt.qbs new file mode 100644 index 000000000..a1d8d8974 --- /dev/null +++ b/tests/auto/blackbox/testdata-qt/pkgconfig-qt/pkgconfig-qt.qbs @@ -0,0 +1,6 @@ +QtApplication { + name: "p" + files: "main.cpp" + qbsSearchPaths: "." + qbsModuleProviders: "qbspkgconfig" +} diff --git a/tests/auto/blackbox/tst_blackboxqt.cpp b/tests/auto/blackbox/tst_blackboxqt.cpp index 53fadc490..1702d4ad6 100644 --- a/tests/auto/blackbox/tst_blackboxqt.cpp +++ b/tests/auto/blackbox/tst_blackboxqt.cpp @@ -298,6 +298,49 @@ void TestBlackboxQt::pkgconfig() QSKIP("pkgconfig or Qt not found"); } +void TestBlackboxQt::pkgconfigQt() +{ + QFETCH(QStringList, arguments); + QFETCH(bool, success); + + QDir::setCurrent(testDataDir + "/pkgconfig-qt"); + rmDirR(relativeBuildDir()); + + QbsRunParameters dumpParams("resolve", {"-f", "dump-libpath.qbs"}); + QCOMPARE(runQbs(dumpParams), 0); + auto lines = QString::fromUtf8(m_qbsStdout).split('\n'); + const QString needle = "libPath="; + qbs::Internal::removeIf( + lines, [&needle](const auto &line) { return !line.startsWith(needle); }); + QCOMPARE(lines.size(), 1); + const auto libPath = lines[0].mid(needle.size()); + const auto prefix = QFileInfo(libPath).path(); + const auto pkgConfigPath = libPath + "/pkgconfig/"; + if (!QFileInfo(pkgConfigPath).exists()) + QSKIP("No *.pc files found"); + + rmDirR(relativeBuildDir()); + QbsRunParameters params("build", {"-f", "pkgconfig-qt.qbs"}); + // need to override prefix for the downloaded Qt + params.environment.insert("PKG_CONFIG_QT5CORE_PREFIX", prefix); + params.arguments << "moduleProviders.qbspkgconfig.extraPaths:" + pkgConfigPath; + params.arguments << arguments; + + QCOMPARE(runQbs(params) == 0, success); + + if (!success) + QVERIFY(m_qbsStderr.contains("Dependency 'Qt.core' not found for product 'p'")); +} + +void TestBlackboxQt::pkgconfigQt_data() +{ + QTest::addColumn<QStringList>("arguments"); + QTest::addColumn<bool>("success"); + QTest::newRow("pkgconfig") << QStringList() << true; + QTest::newRow("dummy") + << QStringList({"products.p.qbsModuleProviders:dummyProvider"}) << false; +} + void TestBlackboxQt::pluginMetaData() { QDir::setCurrent(testDataDir + "/plugin-meta-data"); diff --git a/tests/auto/blackbox/tst_blackboxqt.h b/tests/auto/blackbox/tst_blackboxqt.h index 820df26d9..dfc024a3e 100644 --- a/tests/auto/blackbox/tst_blackboxqt.h +++ b/tests/auto/blackbox/tst_blackboxqt.h @@ -58,6 +58,8 @@ private slots: void mocCompilerDefines(); void mocSameFileName(); void pkgconfig(); + void pkgconfigQt(); + void pkgconfigQt_data(); void pluginMetaData(); void pluginSupport_data(); void pluginSupport(); |