aboutsummaryrefslogtreecommitdiffstats
path: root/doc/reference/commands.qdoc
blob: d33acc4d9c4c9f006fdc72c64c7b916b523db5c0 (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
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
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** 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 Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/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 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/

// TODO: "\c" markup is used for all properties in table due to QTBUG-35505.

/*!
    \contentspage reference.html
    \page commands.html

    \title Command and JavaScriptCommand
    \brief Types of commands to be used in rules and transformers

    A \e command is what \QBS executes at build time. It is represented in the language by an object
    of type \c Command, which runs a process, or \c JavaScriptCommand, which executes arbitrary
    JavaScript code. A command is always created in the prepare script of a \c Rule or
    \c Transformer.

    \section1 Command

    A \c Command represents a process that will be invoked at build time. Its constructor
    arguments are the binary to run and a list of command-line arguments. For instance:
    \code
        var insaneCommand = new Command("rm", ["-r", "/"]);
    \endcode
    The \l{Rule Item} documentation shows a \c Command in context.

    \section1 JavaScriptCommand

    A \c JavaScriptCommand represents a chunk of JavaScript code that is run at build time.
    For instance:
    \code
        var cmd = new JavaScriptCommand();
        cmd.apology = "Sorry.";
        cmd.sourceCode = function() {
            print("I'm a rather pointless command.");
            print(apology);
        };
    \endcode

    Within the source code, the special identifiers \c project and \c product
    (giving access to project and product properties, respectively) as well as \c inputs and
    \c outputs are available. As the example shows, arbitrary properties can be set on the command
    object and then used within the source code. This technique is typically used to forward values
    from the prepare script to the command.
    The \l{Transformer Item} documentation shows a \c JavaScriptCommand in context.

    \section1 Properties

    \section2 Common Properties
    The following properties are available in both \c Command and \c JavaScriptCommand.

    \table
    \header
        \li Property
        \li Type
        \li Default
        \li Description
    \row
        \li \c description
        \li string
        \li empty
        \li A message that is displayed when the command is executed.
    \row
        \li \c highlight
        \li string
        \li empty
        \li A tag that can be used to influence how the \c description is displayed. In principle,
            the values are arbitrary. The \QBS command-line tool understands the following values and
            maps them to different colors if the output device is a terminal:
            \list
                \li "compiler" indicates that the command processes source code
                \li "linker" indicates that the command links objects
                \li "codegen" indicates that the command generates source code
                \li "filegen" indicates that the command creates arbitrary files
            \endlist
            All other values are mapped to the default color.
    \row
        \li \c silent
        \li bool
        \li false
        \li A flag that controls whether the \c description is printed. Set it to \c true for commands that
            users need not know about. \note If this property is \c false, then \c description must
            not be empty.
    \endtable

    \section2 Command Properties

    \table
    \header
        \li Property
        \li Type
        \li Default
        \li Description
    \row
        \li \c arguments
        \li stringList
        \li empty
        \li The list of arguments to invoke the command with. Explicitly setting this property
            overrides an argument list provided when instantiating the object.
    \row
        \li \c environment
        \li stringList
        \li empty
        \li A list of environment variables that are added to the common build environment.
            They are provided as a list of strings in the form "varName=value".
    \row
        \li \c maxExitCode
        \li int
        \li 0
        \li The maximum exit code from the process to interpret as success. Setting this should
            rarely be necessary, as all well-behaved applications use values other than zero
            to indicate failure.
    \row
        \li \c program
        \li string
        \li undefined
        \li The binary to invoke. Explicitly setting this property overrides a path provided when
            instantiating the object.
    \row
        \li \c responseFileThreshold
        \li int
        \li 32000 on Windows, -1 elsewhere
        \li If this value is greater than zero and less than the length of the full command line,
            and if \c responseFileUsagePrefix is not empty, the contents of the command line are
            moved to a temporary file, whose path becomes the entire contents of the
            argument list. The program is then supposed to read the full argument list from that
            file. This mechanism is mainly useful to work around Windows limitations regarding
            the maximum length of the command line and will only work with programs that explicitly
            support it.
    \row
        \li \c responseFileUsagePrefix
        \li string
        \li empty
        \li The prefix that informs \c program that the rest of the argument
            is a path to a file containing the actual command line.
    \row
        \li \c stderrFilterFunction
        \li function
        \li undefined
        \li A function that takes as input the command's actual standard error output and returns a string
            that is presented to the user as the command's standard error output.
            If it is not set, the output is shown unfiltered.
    \row
        \li \c stdoutFilterFunction
        \li function
        \li undefined
        \li A function that takes as input the command's actual standard output and returns a string
            that is presented to the user as the command's standard output.
            If it is not set, the output is shown unfiltered.
    \row
        \li \c workingDirectory
        \li string
        \li empty
        \li The program's working directory.
    \endtable

    \section2 JavaScriptCommand Properties

    \table
    \header
        \li Property
        \li Type
        \li Default
        \li Description
    \row
        \li \c sourceCode
        \li function
        \li undefined
        \li The JavaScript function to execute.
    \endtable
*/