aboutsummaryrefslogtreecommitdiffstats
path: root/doc/reference/items/module.qdoc
blob: c91fd08fd13fc3faebbdad8ba571f4f6ec87d041 (plain)
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
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of the Qt Build Suite.
**
** 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 http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file.  Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights.  These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
/*!
    \contentspage list-of-items.html
    \previouspage loadablemodule-item.html
    \page module-item.html
    \nextpage probe-item.html
    \ingroup list-of-items

    \title Module Item
    \brief Represents a collection of properties and items that can be loaded into a product.

    A \c Module item is a collection of properties and language items that are used for building a
    product if the product has a \l{Depends Item}{dependency} on the module.
    The following (somewhat artificial) module pre-processes text files by removing certain
    characters from them:

    \code
    import qbs
    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.moduleProperty("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 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.

    How you make your own modules available to \QBS is explained
    \l{Custom Modules and Items}{here}.

    \section1 Module Properties

    \table
        \header
            \li Property
            \li Type
            \li Default
            \li Description
        \row
            \li additionalProductFileTags
            \li string list
            \li empty list
            \li The elements of this list will be added to the \c type property of a product
                that has a dependency on the module.
        \row
            \li condition
            \li bool
            \li \c true
            \li Controls whether the module is enabled. If this property is \c false, the
                surrounding \c Module item will not be considered in the module look-up.
        \row
            \li present
            \li bool
            \li \c true
            \li This property is read-only. Its value is \c false if and only if the respective
                \c Depends item had its \c required property set to \c false and the module was
                not found.
        \row
            \li setupBuildEnvironment
            \li script
            \li \c undefined
            \li Script for setting up the environment in which the project is built.
            Use the \c putEnv, \c getEnv, and \c unsetEnv functions to alter the environment.
            The return value of this script is ignored.
        \row
            \li setupRunEnvironment
            \li script
            \li \c setupBuildEnvironment
            \li Script for setting up the environment in which the project is run.
        \row
            \li validate
            \li script
            \li \c undefined
            \li 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.
    \endtable
*/