diff options
author | Ivan Komissarov <abbapoh@gmail.com> | 2023-12-21 01:02:15 +0300 |
---|---|---|
committer | Ivan Komissarov <ABBAPOH@gmail.com> | 2024-01-10 10:25:04 +0000 |
commit | 167799f31c8ca3cfd79394b6c3fe8389c7df4de1 (patch) | |
tree | 00540557d51f669a1eaa8198bc583f760ce216fb /tests/auto | |
parent | 5fcdf43b3fb4e7c5fb85cbfba7f79b1d85dae410 (diff) |
qbspkgconfig: Add support for the definePrefix option
On windows/msys, it is crucial to use autodetection for package
paths - otherwise, Qbs is not able to detect e.g. protobuf
package.
The pkg-config has the --define-prefix switch that overrides
the ${prefix} variables on the package with one based on
the .pc file locaiton. Implement similar option and set it
to true on Windows.
Also fix setting sysroot to avoid duplication of sysroot
in paths when prefix is autodetected.
Change-Id: I2754e48a96cb2e5f01ecace616188782cb5b0d7a
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/pkgconfig/testdata/lib/pkgconfig/prefix.pc | 13 | ||||
-rw-r--r-- | tests/auto/pkgconfig/tst_pkgconfig.cpp | 64 | ||||
-rw-r--r-- | tests/auto/pkgconfig/tst_pkgconfig.h | 4 |
3 files changed, 81 insertions, 0 deletions
diff --git a/tests/auto/pkgconfig/testdata/lib/pkgconfig/prefix.pc b/tests/auto/pkgconfig/testdata/lib/pkgconfig/prefix.pc new file mode 100644 index 000000000..64b980803 --- /dev/null +++ b/tests/auto/pkgconfig/testdata/lib/pkgconfig/prefix.pc @@ -0,0 +1,13 @@ +prefix=/usr +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +includedir=/usr/include +usrdir=/usrdir + +Name: Prefix test +Description: This tests prefix auto detection +Version: 1.0.0 +Requires: +Libs: -lprefix +Libs.private: -lm +Cflags: -I${includedir} diff --git a/tests/auto/pkgconfig/tst_pkgconfig.cpp b/tests/auto/pkgconfig/tst_pkgconfig.cpp index 220e54e7a..ac94e1c48 100644 --- a/tests/auto/pkgconfig/tst_pkgconfig.cpp +++ b/tests/auto/pkgconfig/tst_pkgconfig.cpp @@ -33,6 +33,7 @@ #include <tools/fileinfo.h> #include <tools/hostosinfo.h> #include <pkgconfig.h> +#include <pcparser.h> #include <jsextensions/pkgconfigjs.h> #include <QJsonArray> @@ -58,6 +59,48 @@ void TestPkgConfig::initTestCase() qPrintable(errorMessage)); } +void TestPkgConfig::fileName() +{ + QCOMPARE(qbs::Internal::fileName(""), ""); + QCOMPARE(qbs::Internal::fileName("file.txt"), "file.txt"); + QCOMPARE(qbs::Internal::fileName("/home/user/file.txt"), "file.txt"); + QCOMPARE(qbs::Internal::fileName("/"), ""); +#if defined(Q_OS_WIN) + QCOMPARE(qbs::Internal::fileName("c:file.txt"), "file.txt"); + QCOMPARE(qbs::Internal::fileName("c:"), ""); +#endif +} + +void TestPkgConfig::completeBaseName() +{ + QCOMPARE(qbs::Internal::completeBaseName(""), ""); + QCOMPARE(qbs::Internal::completeBaseName("file.txt"), "file"); + QCOMPARE(qbs::Internal::completeBaseName("archive.tar.gz"), "archive.tar"); + QCOMPARE(qbs::Internal::completeBaseName("/home/user/file.txt"), "file"); +#if defined(Q_OS_WIN) + QCOMPARE(qbs::Internal::completeBaseName("c:file.txt"), "file"); + QCOMPARE(qbs::Internal::completeBaseName("c:archive.tar.gz"), "archive.tar"); + QCOMPARE(qbs::Internal::completeBaseName("c:"), ""); +#endif +} + +void TestPkgConfig::parentPath() +{ + QCOMPARE(qbs::Internal::parentPath(""), ""); + QCOMPARE(qbs::Internal::parentPath("file.txt"), "."); + QCOMPARE(qbs::Internal::parentPath("/home/user/file.txt"), "/home/user"); + QCOMPARE(qbs::Internal::parentPath("/home/user/"), "/home/user"); + QCOMPARE(qbs::Internal::parentPath("/home"), "/"); + QCOMPARE(qbs::Internal::parentPath("/"), "/"); +#if defined(Q_OS_WIN) + QCOMPARE(qbs::Internal::parentPath("c:/folder/file.txt"), "c:/folder"); + QCOMPARE(qbs::Internal::parentPath("c:/folder/"), "c:/folder"); + QCOMPARE(qbs::Internal::parentPath("c:/folder"), "c:/"); + QCOMPARE(qbs::Internal::parentPath("c:/"), "c:/"); + QCOMPARE(qbs::Internal::parentPath("c:"), "c:"); +#endif +} + void TestPkgConfig::pkgConfig() { QFETCH(QString, pcFileName); @@ -214,4 +257,25 @@ void TestPkgConfig::benchSystem() } } +void TestPkgConfig::prefix() +{ + const auto prefixDir = m_workingDataDir; + const auto libDir = m_workingDataDir + "/lib"; + const auto includeDir = m_workingDataDir + "/include"; + const auto pkgconfigDir = libDir + "/pkgconfig"; + Options options = qbs::Internal::PkgConfigJs::convertOptions( + QProcessEnvironment::systemEnvironment(), {}); + options.definePrefix = true; + options.libDirs.push_back(pkgconfigDir.toStdString()); + PkgConfig pkgConfig(std::move(options)); + const auto &packageOr = pkgConfig.getPackage("prefix"); + QVERIFY(packageOr.isValid()); + const auto &package = packageOr.asPackage(); + QCOMPARE(package.variables.at("prefix"), prefixDir.toStdString()); + QCOMPARE(package.variables.at("exec_prefix"), prefixDir.toStdString()); + QCOMPARE(package.variables.at("libdir"), libDir.toStdString()); + QCOMPARE(package.variables.at("includedir"), includeDir.toStdString()); + QCOMPARE(package.variables.at("usrdir"), "/usrdir"); +} + QTEST_MAIN(TestPkgConfig) diff --git a/tests/auto/pkgconfig/tst_pkgconfig.h b/tests/auto/pkgconfig/tst_pkgconfig.h index 687411862..47654e1ec 100644 --- a/tests/auto/pkgconfig/tst_pkgconfig.h +++ b/tests/auto/pkgconfig/tst_pkgconfig.h @@ -41,9 +41,13 @@ public: private slots: void initTestCase(); + void fileName(); + void completeBaseName(); + void parentPath(); void pkgConfig(); void pkgConfig_data(); void benchSystem(); + void prefix(); private: const QString m_sourceDataDir; |