aboutsummaryrefslogtreecommitdiffstats
path: root/share/qbs/imports/qbs/Probes/PathProbe.qbs
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@digia.com>2013-07-05 11:53:37 +0200
committerChristian Kandeler <christian.kandeler@digia.com>2013-07-05 12:07:37 +0200
commit499b6edaac181b7f4142645f18203a50a8fad576 (patch)
treed5bbefb08108d7dd95830fb2778ac4ff3711c2d4 /share/qbs/imports/qbs/Probes/PathProbe.qbs
parent1d09ab7c4161153cccf04b64272f41f36b8596d4 (diff)
Do not use an "as" specifier for URI imports.
Also rename "fileinfo" to "FileInfo" and "probes" to "Probes", to make the default name more conventional. Change-Id: I86ed29e299b8a9c2f40244c098d57a3ec8b68397 Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
Diffstat (limited to 'share/qbs/imports/qbs/Probes/PathProbe.qbs')
-rw-r--r--share/qbs/imports/qbs/Probes/PathProbe.qbs56
1 files changed, 56 insertions, 0 deletions
diff --git a/share/qbs/imports/qbs/Probes/PathProbe.qbs b/share/qbs/imports/qbs/Probes/PathProbe.qbs
new file mode 100644
index 000000000..1d8211359
--- /dev/null
+++ b/share/qbs/imports/qbs/Probes/PathProbe.qbs
@@ -0,0 +1,56 @@
+import qbs 1.0
+import qbs.File
+import qbs.Fileinfo
+import "utils.js" as Utils
+
+Probe {
+ // Inputs
+ property stringList names
+ property var nameFilter
+ property pathList pathPrefixes
+ property stringList pathSuffixes
+ property pathList platformPaths: [ '/usr', '/usr/local' ]
+ property pathList environmentPaths
+ property pathList platformEnvironmentPaths
+
+ // Output
+ property string path
+ property string filePath
+ property string fileName
+
+ configure: {
+ if (!names)
+ throw '"names" must be specified';
+ var _names = Utils.concatAll(names);
+ if (nameFilter)
+ _names = _names.map(nameFilter);
+ // FIXME: Suggest how to obtain paths from system
+ var _paths = Utils.concatAll(pathPrefixes, platformPaths);
+ // FIXME: Add getenv support
+ var envs = Utils.concatAll(platformEnvironmentPaths, environmentPaths);
+ for (var i = 0; i < envs.length; ++i) {
+ var value = qbs.getenv(envs[i]) || '';
+ if (value.length > 0)
+ _paths = _paths.concat(value.split(qbs.pathListSeparator));
+ }
+ var _suffixes = Utils.concatAll('', pathSuffixes);
+ for (i = 0; i < _names.length; ++i) {
+ for (var j = 0; j < _paths.length; ++j) {
+ for (var k = 0; k < _suffixes.length; ++k) {
+ var _filePath = FileInfo.joinPaths(_paths[j], _suffixes[k], _names[i]);
+ if (File.exists(_filePath)) {
+ found = true;
+ path = FileInfo.joinPaths(_paths[j], _suffixes[k]);
+ filePath = _filePath;
+ fileName = _names[i];
+ return;
+ }
+ }
+ }
+ }
+ found = false;
+ path = undefined;
+ filePath = undefined;
+ fileName = undefined;
+ }
+}