diff options
author | Christian Kandeler <christian.kandeler@digia.com> | 2013-10-22 14:59:57 +0200 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@digia.com> | 2013-10-22 17:45:37 +0200 |
commit | 3dcb37474dec023159141d83d05b72e9ecc1ae50 (patch) | |
tree | 61f5f5a63d5cebfbadc27e9b6a9f2de2e35c8412 | |
parent | dbf3facf24cb6eb3911255e0dfe6b0cb4601c523 (diff) |
Add an example to the Rule documentation.
Makes it less abstract.
Change-Id: I1ba0636afd5454ad58099e7be868f2968d338f74
Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
-rw-r--r-- | doc/reference/items/rule.qdoc | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/doc/reference/items/rule.qdoc b/doc/reference/items/rule.qdoc index 1efd82f98..56244ced6 100644 --- a/doc/reference/items/rule.qdoc +++ b/doc/reference/items/rule.qdoc @@ -41,6 +41,50 @@ one or more artifacts (e.g. C++ linker). A \e {non-multiplex rule} creates one transformer per matching input file (e.g. C++ compiler). + As a real-world example of a non-multiplex rule, here is a simplified version of qbs' rule for + transforming C++ sources into object files using gcc: + \code + Rule { + id: compiler + inputs: ['cpp'] + auxiliaryInputs: ['hpp'] + + Artifact { + fileTags: ['obj'] + fileName: '.obj/' + product.name + '/' + input.baseDir + '/' + input.fileName + '.o' + } + + prepare: { + var args = []; + if (product.moduleProperty('cpp', 'debugInformation')) + args.push('-g'); + var warnings = product.moduleProperty('cpp', 'warningLevel') + if (warnings === 'none') + args.push('-w'); + if (warnings === 'all') { + args.push('-Wall'); + args.push('-Wextra'); + } + if (product.moduleProperty('cpp', 'treatWarningsAsErrors')) + args.push('-Werror'); + var includePaths = product.moduleProperties('cpp', 'includePaths'); + for (i in includePaths) + args.push('-I' + includePaths[i]); + var defines = product.moduleProperties('cpp', 'defines'); + for (i in defines) + args.push('-D' + defines[i]); + args.push('-c'); + args.push(input.fileName); + args.push('-o'); + args.push(output.fileName); + var compilerPath = ModUtils.moduleProperty(product, 'compilerPath'); + var cmd = new Command(compilerPath, args); + cmd.description = 'compiling ' + FileInfo.fileName(input.fileName); + cmd.highlight = 'compiler'; + return cmd; + } + } + \endcode \section1 Rule Properties |