diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2018-03-06 10:47:29 +0100 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2018-06-04 13:03:13 +0000 |
commit | b3e1e3e3b307e60924dcf3cf308488a362de88f0 (patch) | |
tree | cd0ee0824eba2693198681ee587b691ee5e28e50 /tests | |
parent | 400d9e1d66aacb2760b2190a5f10cfc3d5d359d2 (diff) |
Add module Exporter.pkgconfig
This module generates .pc files for products, optionally attempting to
derive some of the entries from the contents of the Export item.
[ChangeLog] Added new module "Exporter.pkgconfig" for creating pkg-
config metadata files.
Task-number: QBS-1232
Change-Id: Ic41e645e4462e8f85ad6c2025fb967e88d3438f9
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'tests')
14 files changed, 216 insertions, 0 deletions
diff --git a/tests/auto/blackbox/testdata/exports-pkgconfig/TheFirstLib.pc b/tests/auto/blackbox/testdata/exports-pkgconfig/TheFirstLib.pc new file mode 100644 index 000000000..6a83a6b37 --- /dev/null +++ b/tests/auto/blackbox/testdata/exports-pkgconfig/TheFirstLib.pc @@ -0,0 +1,10 @@ +prefix=/opt/the firstlib + +Name: TheFirstLib +Description: TheFirstLib +Version: 1.0 +URL: http://www.example.com/thefirstlib +Cflags: -DTheFirstLib -I"${prefix}/include" -pthread -DHAVE_INDUSTRIAL_STRENGTH_HAIR_DRYER -I/otherdir/include1 -I/otherdir/include2 +Libs: -L"${prefix}/lib" -lTheFirstLib -pthread +Requires: Qt5Core +Requires.private: SomeHelper diff --git a/tests/auto/blackbox/testdata/exports-pkgconfig/TheFirstLib_windows.pc b/tests/auto/blackbox/testdata/exports-pkgconfig/TheFirstLib_windows.pc new file mode 100644 index 000000000..3c730a0ad --- /dev/null +++ b/tests/auto/blackbox/testdata/exports-pkgconfig/TheFirstLib_windows.pc @@ -0,0 +1,10 @@ +prefix=/opt/the firstlib + +Name: TheFirstLib +Description: TheFirstLib +Version: 1.0 +URL: http://www.example.com/thefirstlib +Cflags: -DTheFirstLib -I"${prefix}/include" -DHAVE_INDUSTRIAL_STRENGTH_HAIR_DRYER -I/otherdir/include1 -I/otherdir/include2 +Libs: -L"${prefix}/lib" -lTheFirstLib +Requires: Qt5Core +Requires.private: SomeHelper diff --git a/tests/auto/blackbox/testdata/exports-pkgconfig/TheSecondLib.pc b/tests/auto/blackbox/testdata/exports-pkgconfig/TheSecondLib.pc new file mode 100644 index 000000000..baac6df44 --- /dev/null +++ b/tests/auto/blackbox/testdata/exports-pkgconfig/TheSecondLib.pc @@ -0,0 +1,6 @@ +Name: TheSecondLib +Description: The second lib +Version: 2.0 +Cflags: -I/opt/thesecondlib/include +Libs: -L/opt/thesecondlib/lib -lTheSecondLib +Requires: TheFirstLib diff --git a/tests/auto/blackbox/testdata/exports-pkgconfig/boringstaticlib.cpp b/tests/auto/blackbox/testdata/exports-pkgconfig/boringstaticlib.cpp new file mode 100644 index 000000000..559a0ecfa --- /dev/null +++ b/tests/auto/blackbox/testdata/exports-pkgconfig/boringstaticlib.cpp @@ -0,0 +1 @@ +int calculateLuckyNumber() { return 12 * 13; } diff --git a/tests/auto/blackbox/testdata/exports-pkgconfig/exports-pkgconfig.qbs b/tests/auto/blackbox/testdata/exports-pkgconfig/exports-pkgconfig.qbs new file mode 100644 index 000000000..1b1109ca7 --- /dev/null +++ b/tests/auto/blackbox/testdata/exports-pkgconfig/exports-pkgconfig.qbs @@ -0,0 +1,121 @@ +import qbs +import qbs.FileInfo + +Project { + Product { + name: "dummy" + Export { Depends { name: "TheFirstLib" } } + } + + Product { + name: "SomeHelper" + Depends { name: "Exporter.pkgconfig" } + Exporter.pkgconfig.versionEntry: "1.0" + } + StaticLibrary { + Depends { name: "cpp" } + name: "BoringStaticLib" + files: ["boringstaticlib.cpp"] + Export { + Depends { name: "cpp" } + cpp.defines: ["HAVE_INDUSTRIAL_STRENGTH_HAIR_DRYER"] + } + } + DynamicLibrary { + name: "TheFirstLib" + version: "1.0" + + Depends { name: "SomeHelper" } + Depends { name: "Exporter.pkgconfig" } + Exporter.pkgconfig.excludedDependencies: ["Qt.core", "helper3"] + Exporter.pkgconfig.requiresEntry: "Qt5Core" + Exporter.pkgconfig.urlEntry: "http://www.example.com/thefirstlib" + + Depends { name: "cpp" } + cpp.defines: ["FIRSTLIB"] + + qbs.installPrefix: "/opt/the firstlib" + + Export { + prefixMapping: [{prefix: "/somedir", replacement: "/otherdir"}] + Depends { name: "BoringStaticLib" } + Depends { name: "cpp" } + Depends { name: "Qt.core"; required: false } + Depends { name: "helper1" } + Depends { name: "helper3" } + property bool someCondition: qbs.hostOS.contains("windows") // hostOS for easier testing + property bool someOtherCondition: someCondition + Properties { + condition: !someOtherCondition + cpp.driverFlags: ["-pthread"] + } + cpp.defines: product.name + cpp.includePaths: [FileInfo.joinPaths(product.qbs.installPrefix, "include")] + Qt.core.mocName: "muck" + } + + Group { + fileTagsFilter: ["dynamiclibrary", "dynamiclibrary_import"] + qbs.install: true + qbs.installDir: "lib" + } + + Group { + name: "api_headers" + files: ["firstlib.h"] + qbs.install: true + qbs.installDir: "include" + } + + files: ["firstlib.cpp"] + } + DynamicLibrary { + name: "TheSecondLib" + version: "2.0" + + Depends { name: "Exporter.pkgconfig" } + Exporter.pkgconfig.descriptionEntry: "The second lib" + Exporter.pkgconfig.transformFunction: (function(product, moduleName, propertyName, value) { + if (moduleName === "cpp" && propertyName === "includePaths") + return value.filter(function(p) { return p !== product.sourceDirectory; }); + return value; + }) + + Depends { name: "cpp" } + cpp.defines: ["SECONDLIB"] + + Depends { name: "TheFirstLib" } + + Export { + Depends { name: "TheFirstLib" } + Depends { name: "dummy" } + Depends { name: "cpp" } + cpp.includePaths: ["/opt/thesecondlib/include", product.sourceDirectory] + property string hurz: importingProduct.name + + Rule { + property int n: 5 + Artifact { + filePath: "dummy" + fileTags: ["d1", "d2"] + cpp.warningsAreErrors: true + } + } + } + + Group { + fileTagsFilter: ["dynamiclibrary", "dynamiclibrary_import"] + qbs.install: true + qbs.installDir: "/opt/thesecondlib/lib" + } + + Group { + name: "api_headers" + files: ["secondlib.h"] + qbs.install: true + qbs.installDir: "/opt/thesecondlib/include" + } + + files: ["secondlib.cpp"] + } +} diff --git a/tests/auto/blackbox/testdata/exports-pkgconfig/firstlib.cpp b/tests/auto/blackbox/testdata/exports-pkgconfig/firstlib.cpp new file mode 100644 index 000000000..ab48afc94 --- /dev/null +++ b/tests/auto/blackbox/testdata/exports-pkgconfig/firstlib.cpp @@ -0,0 +1,3 @@ +#include "firstlib.h" + +void firstLib() { } diff --git a/tests/auto/blackbox/testdata/exports-pkgconfig/firstlib.h b/tests/auto/blackbox/testdata/exports-pkgconfig/firstlib.h new file mode 100644 index 000000000..1ccfb0868 --- /dev/null +++ b/tests/auto/blackbox/testdata/exports-pkgconfig/firstlib.h @@ -0,0 +1,9 @@ +#include "../dllexport.h" + +#ifdef FIRSTLIB +# define FIRSTLIB_EXPORT DLL_EXPORT +#else +# define FIRSTLIB_EXPORT DLL_IMPORT +#endif + +FIRSTLIB_EXPORT void firstLib(); diff --git a/tests/auto/blackbox/testdata/exports-pkgconfig/modules/helper1/helper1.qbs b/tests/auto/blackbox/testdata/exports-pkgconfig/modules/helper1/helper1.qbs new file mode 100644 index 000000000..b753ec295 --- /dev/null +++ b/tests/auto/blackbox/testdata/exports-pkgconfig/modules/helper1/helper1.qbs @@ -0,0 +1,7 @@ +import qbs + +Module { + Depends { name: "cpp" } + Depends { name: "helper2" } + cpp.includePaths: "/somedir/include1" +} diff --git a/tests/auto/blackbox/testdata/exports-pkgconfig/modules/helper2/helper2.qbs b/tests/auto/blackbox/testdata/exports-pkgconfig/modules/helper2/helper2.qbs new file mode 100644 index 000000000..9d24a812d --- /dev/null +++ b/tests/auto/blackbox/testdata/exports-pkgconfig/modules/helper2/helper2.qbs @@ -0,0 +1,6 @@ +import qbs + +Module { + Depends { name: "cpp" } + cpp.includePaths: "/somedir/include2" +} diff --git a/tests/auto/blackbox/testdata/exports-pkgconfig/modules/helper3/helper3.qbs b/tests/auto/blackbox/testdata/exports-pkgconfig/modules/helper3/helper3.qbs new file mode 100644 index 000000000..452191994 --- /dev/null +++ b/tests/auto/blackbox/testdata/exports-pkgconfig/modules/helper3/helper3.qbs @@ -0,0 +1,6 @@ +import qbs + +Module { + Depends { name: "cpp" } + cpp.includePaths: "/somedir/include3" +} diff --git a/tests/auto/blackbox/testdata/exports-pkgconfig/secondlib.cpp b/tests/auto/blackbox/testdata/exports-pkgconfig/secondlib.cpp new file mode 100644 index 000000000..e1782f576 --- /dev/null +++ b/tests/auto/blackbox/testdata/exports-pkgconfig/secondlib.cpp @@ -0,0 +1,7 @@ +#include "secondlib.h" + +#ifndef HAVE_INDUSTRIAL_STRENGTH_HAIR_DRYER +# error I CANT LIVE WITHOUT IT! +#endif + +void secondLib() { } diff --git a/tests/auto/blackbox/testdata/exports-pkgconfig/secondlib.h b/tests/auto/blackbox/testdata/exports-pkgconfig/secondlib.h new file mode 100644 index 000000000..78b52f7fe --- /dev/null +++ b/tests/auto/blackbox/testdata/exports-pkgconfig/secondlib.h @@ -0,0 +1,9 @@ +#include "../dllexport.h" + +#ifdef SECONDLIB +# define SECONDLIB_EXPORT DLL_EXPORT +#else +# define SECONDLIB_EXPORT DLL_IMPORT +#endif + +SECONDLIB_EXPORT void secondLib(); diff --git a/tests/auto/blackbox/tst_blackbox.cpp b/tests/auto/blackbox/tst_blackbox.cpp index 4f59eeeed..3293c09de 100644 --- a/tests/auto/blackbox/tst_blackbox.cpp +++ b/tests/auto/blackbox/tst_blackbox.cpp @@ -3332,6 +3332,26 @@ void TestBlackbox::exportToOutsideSearchPath() m_qbsStderr.constData()); } +void TestBlackbox::exportsPkgconfig() +{ + QDir::setCurrent(testDataDir + "/exports-pkgconfig"); + QCOMPARE(runQbs(), 0); + QFile sourcePcFile(HostOsInfo::isWindowsHost() ? "TheFirstLib_windows.pc" : "TheFirstLib.pc"); + QString generatedPcFilePath = relativeProductBuildDir("TheFirstLib") + "/TheFirstLib.pc"; + QFile generatedPcFile(generatedPcFilePath); + QVERIFY2(sourcePcFile.open(QIODevice::ReadOnly), qPrintable(sourcePcFile.errorString())); + QVERIFY2(generatedPcFile.open(QIODevice::ReadOnly), qPrintable(generatedPcFile.errorString())); + QCOMPARE(generatedPcFile.readAll().replace("\r", ""), sourcePcFile.readAll().replace("\r", "")); + sourcePcFile.close(); + generatedPcFile.close(); + sourcePcFile.setFileName("TheSecondLib.pc"); + generatedPcFilePath = relativeProductBuildDir("TheSecondLib") + "/TheSecondLib.pc"; + generatedPcFile.setFileName(generatedPcFilePath); + QVERIFY2(sourcePcFile.open(QIODevice::ReadOnly), qPrintable(sourcePcFile.errorString())); + QVERIFY2(generatedPcFile.open(QIODevice::ReadOnly), qPrintable(generatedPcFile.errorString())); + QCOMPARE(generatedPcFile.readAll(), sourcePcFile.readAll()); +} + void TestBlackbox::exportsQbs() { QDir::setCurrent(testDataDir + "/exports-qbs"); diff --git a/tests/auto/blackbox/tst_blackbox.h b/tests/auto/blackbox/tst_blackbox.h index 44c2e9ca0..e81551b26 100644 --- a/tests/auto/blackbox/tst_blackbox.h +++ b/tests/auto/blackbox/tst_blackbox.h @@ -106,6 +106,7 @@ private slots: void exportedPropertyInDisabledProduct_data(); void exportRule(); void exportToOutsideSearchPath(); + void exportsPkgconfig(); void exportsQbs(); void externalLibs(); void fileDependencies(); |