aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@theqtcompany.com>2016-05-26 11:03:34 +0200
committerChristian Kandeler <christian.kandeler@theqtcompany.com>2016-05-27 07:03:52 +0000
commitcf0497df127fa662899133d6f5a2c98b2815c2e2 (patch)
tree45d7aad5de3960c9caeb8d5c5813f148ec67a3fa
parent756a296e7dd1a79af9de1206809c02e9e936f9b9 (diff)
PkgConfigProbe: Make sure no values are undefined in the success case.
If the probe runs successfully (i.e. "found" is true), all output properties should have defined values so that users can work on them directly rather than first having to convert "undefined" to "empty array" etc. Change-Id: I96a380480ea746cc0413553e49097f1e417b71af Reviewed-by: Jake Petroules <jake.petroules@qt.io>
-rw-r--r--share/qbs/imports/qbs/Probes/PkgConfigProbe.qbs10
-rw-r--r--tests/auto/blackbox/testdata/pkg-config-probe/dummy.pc7
-rw-r--r--tests/auto/blackbox/testdata/pkg-config-probe/pkg-config.qbs38
-rw-r--r--tests/auto/blackbox/tst_blackbox.cpp40
-rw-r--r--tests/auto/blackbox/tst_blackbox.h2
5 files changed, 89 insertions, 8 deletions
diff --git a/share/qbs/imports/qbs/Probes/PkgConfigProbe.qbs b/share/qbs/imports/qbs/Probes/PkgConfigProbe.qbs
index 1c23005b8..32465ddba 100644
--- a/share/qbs/imports/qbs/Probes/PkgConfigProbe.qbs
+++ b/share/qbs/imports/qbs/Probes/PkgConfigProbe.qbs
@@ -72,16 +72,10 @@ Probe {
p.setEnv("PKG_CONFIG_LIBDIR", libDirsToSet.join(qbs.pathListSeparator));
if (p.exec(executable, args.concat([ '--cflags' ])) === 0) {
cflags = p.readStdOut().trim();
- if (cflags === "")
- cflags = undefined;
- else
- cflags = cflags.split(/\s/);
+ cflags = cflags ? cflags.split(/\s/) : [];
if (p.exec(executable, args.concat([ '--libs' ])) === 0) {
libs = p.readStdOut().trim();
- if (libs === "")
- libs = undefined;
- else
- libs = libs.split(/\s/);
+ libs = libs ? libs.split(/\s/) : [];
if (p.exec(executable, args.concat([ '--modversion' ])) === 0) {
modversion = p.readStdOut().trim();
found = true;
diff --git a/tests/auto/blackbox/testdata/pkg-config-probe/dummy.pc b/tests/auto/blackbox/testdata/pkg-config-probe/dummy.pc
new file mode 100644
index 000000000..7bf7e2463
--- /dev/null
+++ b/tests/auto/blackbox/testdata/pkg-config-probe/dummy.pc
@@ -0,0 +1,7 @@
+Name: dummy
+Description: dummy package
+Version: 0.0.1
+
+Requires:
+Libs: -Ldummydir -ldummy
+Cflags:
diff --git a/tests/auto/blackbox/testdata/pkg-config-probe/pkg-config.qbs b/tests/auto/blackbox/testdata/pkg-config-probe/pkg-config.qbs
new file mode 100644
index 000000000..fc9ffbd2a
--- /dev/null
+++ b/tests/auto/blackbox/testdata/pkg-config-probe/pkg-config.qbs
@@ -0,0 +1,38 @@
+import qbs
+import qbs.Probes
+
+Product {
+ name: "theProduct"
+ type: ["theType"]
+
+ property string packageName
+
+ property bool probeSuccess: theProbe.found
+ property stringList libs: theProbe.libs
+ property stringList cFlags: theProbe.cflags
+ property string packageVersion: theProbe.modversion
+
+ Probes.PkgConfigProbe {
+ id: theProbe
+ name: product.packageName
+ libDirs: [path]
+ }
+
+ Transformer {
+ Artifact {
+ filePath: "dummy.out"
+ fileTags: product.type
+ }
+ prepare: {
+ var cmd = new JavaScriptCommand();
+ cmd.silent = true;
+ cmd.sourceCode = function() {
+ console.info("found: " + product.probeSuccess);
+ console.info("libs: " + JSON.stringify(product.libs));
+ console.info("cflags: " + JSON.stringify(product.cFlags));
+ console.info("version: " + product.packageVersion);
+ }
+ return [cmd];
+ }
+ }
+}
diff --git a/tests/auto/blackbox/tst_blackbox.cpp b/tests/auto/blackbox/tst_blackbox.cpp
index b7c6c2440..e1f05b534 100644
--- a/tests/auto/blackbox/tst_blackbox.cpp
+++ b/tests/auto/blackbox/tst_blackbox.cpp
@@ -1802,6 +1802,46 @@ void TestBlackbox::overrideProjectProperties()
QCOMPARE(runQbs(params), 0);
}
+void TestBlackbox::pkgConfigProbe()
+{
+ const QString exe = findExecutable(QStringList() << "pkg-config");
+ if (exe.isEmpty())
+ QSKIP("This test requires the pkg-config tool");
+
+ QDir::setCurrent(testDataDir + "/pkg-config-probe");
+
+ QFETCH(QString, packageName);
+ QFETCH(QString, found);
+ QFETCH(QString, libs);
+ QFETCH(QString, cflags);
+ QFETCH(QString, version);
+
+ QbsRunParameters params(QStringList() << ("theProduct.packageName:" + packageName));
+ QCOMPARE(runQbs(params), 0);
+ const QString stdOut = m_qbsStdout;
+ QVERIFY2(stdOut.contains("found: " + found), m_qbsStdout.constData());
+ QVERIFY2(stdOut.contains("libs: " + libs), m_qbsStdout.constData());
+ QVERIFY2(stdOut.contains("cflags: " + cflags), m_qbsStdout.constData());
+ QVERIFY2(stdOut.contains("version: " + version), m_qbsStdout.constData());
+}
+
+void TestBlackbox::pkgConfigProbe_data()
+{
+ QTest::addColumn<QString>("packageName");
+ QTest::addColumn<QString>("found");
+ QTest::addColumn<QString>("libs");
+ QTest::addColumn<QString>("cflags");
+ QTest::addColumn<QString>("version");
+
+ QTest::newRow("existing package")
+ << "dummy" << "true" << "[\"-Ldummydir\",\"-ldummy\"]" << "[]" << "0.0.1";
+
+ // Note: The array values should be "undefined", but we lose that information when
+ // converting to QVariants in the ProjectResolver.
+ QTest::newRow("non-existing package")
+ << "dummy2" << "false" << "[]" << "[]" << "undefined";
+}
+
void TestBlackbox::probeProperties()
{
QDir::setCurrent(testDataDir + "/probeProperties");
diff --git a/tests/auto/blackbox/tst_blackbox.h b/tests/auto/blackbox/tst_blackbox.h
index 6b3a5bd3a..be4c3a8fc 100644
--- a/tests/auto/blackbox/tst_blackbox.h
+++ b/tests/auto/blackbox/tst_blackbox.h
@@ -172,6 +172,8 @@ private slots:
void objcArc();
void outputArtifactAutoTagging();
void overrideProjectProperties();
+ void pkgConfigProbe();
+ void pkgConfigProbe_data();
void probeProperties();
void probeInExportedModule();
void probesInNestedModules();