/**************************************************************************** ** ** 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$ ** ****************************************************************************/ /*! \contentspage list-of-language-items.html \previouspage Group \nextpage Parameter \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 that are used for building a product if the product has a \l{Depends}{dependency} on the module. The following (somewhat artificial) module pre-processes text files by removing certain characters from them. The module's name is \c{txt_processor}. \code 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 = product.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; } } } \endcode And this is how a \l{Product} would use the module: \code Product { type: "processed-txt" Depends { name: "txt_processor" } txt_processor.unwantedCharacters: ["\r"] files: [ "file1.raw", "file2.raw" ] } \endcode Of course, normally the pre-processed files would not be the target artifacts of the product, but rather serve as inputs to a different rule that will often come from a different module. For more information about how you make your own modules available to \QBS, see \l{Custom Modules and Items}. \section1 Special Property Values For every property defined in a module, \QBS provides the following special built-in values: \list \li \l base \li \l original \li \l outer \endlist \section2 \c base This value is useful when making use of inheritance. It stands for the value of the respective property in the item one level up in the inheritance chain. For instance: \code Product { // defined in MyProduct.qbs Depends { name: "mymodule" } mymodule.someProperty: ["value1"] } ------ some other file ------ MyProduct { mymodule.someProperty: base.concat(["value2"]) // => ["value1", "value2"] } \endcode \section2 \c original This is the value of the property in the module itself (possibly overridden from a profile or the command line). Use it to set a module property conditionally: \code Module { // This is mymodule property string aProperty: "z" } ---------- Product { Depends { name: "mymodule" } Depends { name: "myothermodule" } mymodule.aProperty: myothermodule.anotherProperty === "x" ? "y" : original // => "y" if myothermodule.anotherProperty is "x", "z" otherwise \endcode \section2 \c outer This value is used in nested items, where it refers to the value of the respective property in the surrounding item. It is only valid in \l{Group} and \l{Properties} items: \code Product { Depends { name: "mymodule" } mymodule.someProperty: ["value1"] Group { name: "special files" files: ["somefile1", "somefile2"] mymodule.someProperty: outer.concat(["value"]) // => ["value1", "value2"] } } \endcode \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. */