1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
|
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qbs.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
** $QT_END_LICENSE$
**
****************************************************************************/
/*!
\previouspage JobLimit
\nextpage ModuleProvider
\qmltype Module
\inqmlmodule QbsLanguageItems
\ingroup list-of-items
\keyword QML.Module
\brief Represents a collection of properties and items that can be loaded into a product.
A Module item is a collection of properties and language items. It
contributes to building a product if the product has a
\l{Depends}{dependency} on the module. Modules may contain the following
items:
\list
\li \l{Depends}
\li \l{FileTagger}
\li \l{Group}
\li \l{JobLimit}
\li \l{Parameter}
\li \l{Probe}
\li \l{PropertyOptions}
\li \l{Rule}
\li \l{Scanner}
\endlist
When a product expresses a dependency on a module, \QBS will create an
instance of the module item in the scope of the product. The product can
then read and write properties from and to the loaded module, respectively.
Modules in different products are isolated from each other, just as products
cannot access each other's properties. However, products can use the
\l{Export} item to pass dependencies and properties of modules to other
dependent products.
The following (somewhat artificial) module pre-processes text files by removing certain
characters from them. The module's name is \c{txt_processor}.
\qml
import qbs.FileInfo
import qbs.TextFile
Module {
property stringList unwantedCharacters: []
FileTagger {
patterns: ["*.raw"]
fileTags: ["raw-txt"]
}
Rule {
inputs: ["raw-txt"]
Artifact {
filePath: FileInfo.relativePath(input.filePath, product.sourceDirectory) +
"/" + input.fileName + ".processed"
fileTags: ["processed-txt"]
}
prepare: {
var cmd = new JavaScriptCommand();
cmd.description = "Processing " + input.fileName;
cmd.sourceCode = function() {
var inFile = new TextFile(input.filePath, TextFile.ReadOnly);
var content = inFile.readAll();
inFile.close();
var unwantedChars = input.txt_processor.unwantedCharacters;
for (var c in unwantedChars)
content = content.replace(unwantedChars[c], "");
var outFile = new TextFile(output.filePath, TextFile.WriteOnly);
outFile.write(content);
outFile.close();
};
return cmd;
}
}
}
\endqml
And this is how a \l{Product} would use the module:
\qml
Product {
type: "processed-txt"
Depends { name: "txt_processor" }
txt_processor.unwantedCharacters: ["\r"]
files: [
"file1.raw",
"file2.raw"
]
}
\endqml
The resulting files are tagged with \c{processed-txt} and might be consumed
by a rule in another module. That is possible if another rule has
\c{processed-txt} in its \l{Rule::inputs}{inputs} property.
For more information about how you make your own modules available to \QBS,
see \l{Custom Modules and Items}.
\section1 Accessing Product and Module Properties
When defining a property in a module item, the right-hand side expression is
a binding. Bindings may reference other properties of:
\list
\li the current module
\li other modules that this module depends on
\li the dependent product
\endlist
Please note that this applies to bindings in modules only. Property access
in rules and other nested items is different.
\section2 Accessing Properties of the Current Module
Sibling properties in the same module can be accessed directly by their name:
\qml
Module {
property stringList windowsDefaults: ["\r"]
property stringList unwantedCharacters: windowsDefaults
}
\endqml
\section2 Properties of the Dependent Modules
When a module loads another module through a \l{Depends} element, it can
access properties of the other module through its name. Assuming there was a
module \c OtherModule with a property \c otherProperty, such an access would
look like this:
\qml
Module {
Depends { name: "OtherModule" }
property string myProperty: "something-" + OtherModule.otherProperty
}
\endqml
\section2 Accessing Properties of the Dependent Product
\qml
Module {
property bool featureEnabled:
(product.type.includes("application")) ? true : false
}
\endqml
\section2 Special Property Values
For every property defined in a module, \QBS provides the special
\l{Special Property Values#original}{original} value containing the value of the property in
the module itself (possibly overridden from a profile).
\section1 Dependency Parameters
Modules can declare dependency parameters. Those parameters can be set
within \l{Depends} items. \l{Rule}{Rules} of the module can read the
parameters of dependencies and act accordingly.
In the following example, the module \e{foo} declares the parameter
\c{ignore}. A dependency to \c{bar} then sets the parameter \c{foo.ignore}
to \c{true}. A rule in \c{foo} ignores all dependencies that have
\c{foo.ignore} set to true.
\code
Module { // Definition of module 'foo'.
Parameter { property bool ignore }
Rule {
...
prepare: {
for (i in product.dependencies) {
var dep = product.dependencies[i];
if (dep.foo.ignore)
continue;
// Do something with the dependency.
}
}
}
...
}
----------
Product {
Depends { name: "foo" }
Depends { name: "bar"; foo.ignore: true }
}
\endcode
*/
/*!
\qmlproperty stringList Module::additionalProductTypes
A list of elements that will be added to the \l{Product::type}{type}
property of a product that has a dependency on the module.
\defaultvalue \c []
*/
/*!
\qmlproperty bool Module::condition
Whether the module is enabled. If this property is \c false, the
surrounding Module item will not be considered in the module look-up.
\defaultvalue \c true
*/
/*!
\qmlproperty bool Module::present
\readonly
This property is \c false if and only if the respective \l{Depends} item had
its \l{Depends::required}{required} property set to \c false and the module
was not found.
\defaultvalue \c true
*/
/*!
\qmlproperty int Module::priority
The priority of this module instance. If there is more than one module
instance available for a module name, the module with the highest priority
is chosen.
\defaultvalue 0
*/
/*!
\qmlproperty script Module::setupBuildEnvironment
A script for setting up the environment in which a product is built.
The code in this script is treated as a function with the signature
\c{function(project, product)}.
Use the \l{Environment Service}{Environment} functions to alter the
environment.
The return value of this script is ignored.
\nodefaultvalue
*/
/*!
\qmlproperty script Module::setupRunEnvironment
A script for setting up the environment in which a product is run.
The code in this script is treated as a function with the signature
\c{function(project, product, config)}.
The \c config parameter is a list of arbitrary strings that can be passed
via the \l{run} command. The values supported by specific modules are
listed in their respective documentation.
Use the \l{Environment Service}{Environment} functions to alter the
environment.
The return value of this script is ignored.
\nodefaultvalue
*/
/*!
\qmlproperty script Module::validate
A script that is run after the module is loaded. It can be used to check
property values and throw errors in unexpected cases. The return value is
ignored.
\nodefaultvalue
*/
/*!
\qmlproperty string Module::version
The module's version. It consists of integer values separated by dots. You
can check for specific values of this property in a \l{Depends} item.
*/
|