aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Komissarov <ABBAPOH@gmail.com>2019-06-08 18:20:03 +0200
committerIvan Komissarov <ABBAPOH@gmail.com>2019-06-26 15:25:30 +0000
commit06f46da6c31de7d5b767da38713b11b1a117b34e (patch)
treeb23b248961c0d71943a3978969cdd1bd19361de1
parentd214864b666d3551fe25a648b82832fcbd241b2e (diff)
Add PathProbe::candidateFilter property
This property can be used to check if candidate conforms with some conditions. For example, an architecture of a shared library candidate should match the current qbs.architecture. Also, this will allow to implement support for the "text based stub libraries" (yaml files that point to a real library in a system) on macOS - instead of checking real file architecture, it should be read from .tbd file Change-Id: Ie84a3e70d883dec949440358e2f08213a8501982 Reviewed-by: Qbs CI Bot <travis-bot@weickelt.de> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io> Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
-rw-r--r--doc/reference/items/probe/path-probe.qdoc19
-rw-r--r--share/qbs/imports/qbs/Probes/GccBinaryProbe.qbs4
-rw-r--r--share/qbs/imports/qbs/Probes/NpmProbe.qbs4
-rw-r--r--share/qbs/imports/qbs/Probes/PathProbe.qbs7
-rw-r--r--share/qbs/imports/qbs/Probes/TypeScriptProbe.qbs4
-rw-r--r--share/qbs/imports/qbs/Probes/path-probe.js9
-rw-r--r--tests/auto/blackbox/testdata/path-probe/BaseApp.qbs2
-rw-r--r--tests/auto/blackbox/testdata/path-probe/candidate-filter.qbs12
-rw-r--r--tests/auto/blackbox/tst_blackbox.cpp1
9 files changed, 49 insertions, 13 deletions
diff --git a/doc/reference/items/probe/path-probe.qdoc b/doc/reference/items/probe/path-probe.qdoc
index 5b0cc1bb6..eaaee9e54 100644
--- a/doc/reference/items/probe/path-probe.qdoc
+++ b/doc/reference/items/probe/path-probe.qdoc
@@ -75,6 +75,25 @@
*/
/*!
+ \qmlproperty var PathProbe::candidateFilter
+
+ This property holds the function that can be used to filter out unsuitable candidates.
+ For example, when searching for a library, it might be necessary to check its architecture:
+ \code
+ PathProbe {
+ pathSuffixes: ["*.so", *.dll]
+ candidateFilter: {
+ function getLibraryArchitecture(file) { ... }
+ return function(file) {
+ return Utilities.isSharedLibrary(file)
+ && getLibraryArchitecture(file) == qbs.architecture;
+ }
+ }
+ }
+ \endcode
+*/
+
+/*!
\qmlproperty stringList PathProbe::names
The list of file names to search for.
diff --git a/share/qbs/imports/qbs/Probes/GccBinaryProbe.qbs b/share/qbs/imports/qbs/Probes/GccBinaryProbe.qbs
index e0ca3e654..693fb6a01 100644
--- a/share/qbs/imports/qbs/Probes/GccBinaryProbe.qbs
+++ b/share/qbs/imports/qbs/Probes/GccBinaryProbe.qbs
@@ -49,8 +49,8 @@ BinaryProbe {
configure: {
var selectors;
var _results = PathProbeConfigure.configure(
- selectors, names, nameSuffixes, nameFilter, searchPaths, pathSuffixes,
- platformSearchPaths, environmentPaths, platformEnvironmentPaths,
+ selectors, names, nameSuffixes, nameFilter, candidateFilter, searchPaths,
+ pathSuffixes, platformSearchPaths, environmentPaths, platformEnvironmentPaths,
pathListSeparator);
found = _results.found;
var resultFile = _results.files[0];
diff --git a/share/qbs/imports/qbs/Probes/NpmProbe.qbs b/share/qbs/imports/qbs/Probes/NpmProbe.qbs
index d0a77b421..f6a99e826 100644
--- a/share/qbs/imports/qbs/Probes/NpmProbe.qbs
+++ b/share/qbs/imports/qbs/Probes/NpmProbe.qbs
@@ -49,8 +49,8 @@ NodeJsProbe {
var selectors;
var results = PathProbeConfigure.configure(
- selectors, names, nameSuffixes, nameFilter, searchPaths, pathSuffixes,
- platformSearchPaths, environmentPaths, platformEnvironmentPaths,
+ selectors, names, nameSuffixes, nameFilter, candidateFilter, searchPaths,
+ pathSuffixes, platformSearchPaths, environmentPaths, platformEnvironmentPaths,
pathListSeparator);
var v = new ModUtils.EnvironmentVariable("PATH", pathListSeparator,
diff --git a/share/qbs/imports/qbs/Probes/PathProbe.qbs b/share/qbs/imports/qbs/Probes/PathProbe.qbs
index 42e3a45d4..d0edea682 100644
--- a/share/qbs/imports/qbs/Probes/PathProbe.qbs
+++ b/share/qbs/imports/qbs/Probes/PathProbe.qbs
@@ -36,6 +36,7 @@ Probe {
property stringList names
property stringList nameSuffixes
property var nameFilter
+ property var candidateFilter
property varList selectors
property pathList pathPrefixes
property pathList searchPaths
@@ -63,9 +64,9 @@ Probe {
var _searchPaths = ModUtils.concatAll(pathPrefixes, searchPaths);
var _platformSearchPaths = ModUtils.concatAll(platformPaths, platformSearchPaths);
var results = PathProbeConfigure.configure(selectors, names, nameSuffixes, nameFilter,
- _searchPaths, pathSuffixes, _platformSearchPaths,
- environmentPaths, platformEnvironmentPaths,
- pathListSeparator);
+ candidateFilter, _searchPaths, pathSuffixes,
+ _platformSearchPaths, environmentPaths,
+ platformEnvironmentPaths, pathListSeparator);
found = results.found;
allResults = results.files;
diff --git a/share/qbs/imports/qbs/Probes/TypeScriptProbe.qbs b/share/qbs/imports/qbs/Probes/TypeScriptProbe.qbs
index 5696b78c8..a35e555cc 100644
--- a/share/qbs/imports/qbs/Probes/TypeScriptProbe.qbs
+++ b/share/qbs/imports/qbs/Probes/TypeScriptProbe.qbs
@@ -59,8 +59,8 @@ BinaryProbe {
var selectors;
var results = PathProbeConfigure.configure(
- selectors, names, nameSuffixes, nameFilter, searchPaths, pathSuffixes,
- platformSearchPaths, environmentPaths, platformEnvironmentPaths,
+ selectors, names, nameSuffixes, nameFilter, candidateFilter, searchPaths,
+ pathSuffixes, platformSearchPaths, environmentPaths, platformEnvironmentPaths,
pathListSeparator);
var v = new ModUtils.EnvironmentVariable("PATH", pathListSeparator,
diff --git a/share/qbs/imports/qbs/Probes/path-probe.js b/share/qbs/imports/qbs/Probes/path-probe.js
index 9e338712f..a997f77f2 100644
--- a/share/qbs/imports/qbs/Probes/path-probe.js
+++ b/share/qbs/imports/qbs/Probes/path-probe.js
@@ -58,9 +58,9 @@ function canonicalSelectors(selectors) {
return selectors.map(mapper);
}
-function configure(selectors, names, nameSuffixes, nameFilter, searchPaths, pathSuffixes,
- platformSearchPaths, environmentPaths, platformEnvironmentPaths,
- pathListSeparator) {
+function configure(selectors, names, nameSuffixes, nameFilter, candidateFilter,
+ searchPaths, pathSuffixes, platformSearchPaths, environmentPaths,
+ platformEnvironmentPaths, pathListSeparator) {
var result = { found: false, files: [] };
if (!selectors && !names)
throw '"names" or "selectors" must be specified';
@@ -107,7 +107,8 @@ function configure(selectors, names, nameSuffixes, nameFilter, searchPaths, path
for (var k = 0; k < _suffixes.length; ++k) {
var _filePath = FileInfo.joinPaths(_paths[j], _suffixes[k], selector.names[i]);
file.candidatePaths.push(_filePath);
- if (File.exists(_filePath)) {
+ if (File.exists(_filePath)
+ && (!candidateFilter || candidateFilter(_filePath))) {
file.found = true;
file.filePath = _filePath;
diff --git a/tests/auto/blackbox/testdata/path-probe/BaseApp.qbs b/tests/auto/blackbox/testdata/path-probe/BaseApp.qbs
index 944a95a93..84c00c240 100644
--- a/tests/auto/blackbox/testdata/path-probe/BaseApp.qbs
+++ b/tests/auto/blackbox/testdata/path-probe/BaseApp.qbs
@@ -37,6 +37,7 @@ CppApplication {
property varList inputNameSuffixes
property pathList inputSearchPaths
property var inputNameFilter
+ property var inputCandidateFilter
property stringList outputFilePaths
@@ -46,6 +47,7 @@ CppApplication {
names: inputNames
nameSuffixes: inputNameSuffixes
nameFilter: inputNameFilter
+ candidateFilter: inputCandidateFilter
searchPaths: inputSearchPaths
}
diff --git a/tests/auto/blackbox/testdata/path-probe/candidate-filter.qbs b/tests/auto/blackbox/testdata/path-probe/candidate-filter.qbs
new file mode 100644
index 000000000..a65256a68
--- /dev/null
+++ b/tests/auto/blackbox/testdata/path-probe/candidate-filter.qbs
@@ -0,0 +1,12 @@
+import qbs.FileInfo
+
+BaseApp {
+ inputNames: ["tool.1", "tool.2"]
+ inputSearchPaths: "bin"
+ outputFilePaths: ["bin/tool.2"]
+ inputCandidateFilter: {
+ return function(f) {
+ return FileInfo.fileName(f) == "tool.2";
+ }
+ }
+}
diff --git a/tests/auto/blackbox/tst_blackbox.cpp b/tests/auto/blackbox/tst_blackbox.cpp
index c6acffcc9..534922112 100644
--- a/tests/auto/blackbox/tst_blackbox.cpp
+++ b/tests/auto/blackbox/tst_blackbox.cpp
@@ -2735,6 +2735,7 @@ void TestBlackbox::pathProbe_data()
QTest::newRow("mult-files-suffixes") << QString("mult-files-suffixes.qbs") << true;
QTest::newRow("mult-files-mult-suffixes") << QString("mult-files-mult-suffixes.qbs") << true;
QTest::newRow("name-filter") << QString("name-filter.qbs") << true;
+ QTest::newRow("candidate-filter") << QString("candidate-filter.qbs") << true;
}
void TestBlackbox::pathProbe()