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
|
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Copyright (C) 2019 Jochen Ulrich <jochenulrich@t-online.de>
** 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$
**
****************************************************************************/
// TODO: "\c" markup is used for all properties in table due to QTBUG-35505.
/*!
\page commands.html
\title Command and JavaScriptCommand
\brief Types of commands to be used in rules
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.
\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() {
console.info("I'm a rather pointless command.");
console.info(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{Rule} 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 extendedDescription
\li string
\li empty
\li A detailed description 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 jobPool
\li string
\li empty
\li Determines which job pool the command will use. An empty
string, which is the default, stands for the global job pool.
See \l{JobLimit}{here} and \l{job-pool-howto}{here} for more information on job pools.
\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.
\row
\li \c timeout
\li int
\li -1
\li Time limit for the command execution in seconds. If the command does not finish within
the timeout, it is cancelled. In case of a \c Command, the process is requested to
terminate. If it does not terminate within three seconds, it is killed. A value below
or equal to 0 means no timeout. \br
This property was introduced in Qbs 1.15.
\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 relevantEnvironmentVariables
\li stringList
\li undefined
\li Names of environment variables that the invoked binary considers.
If one of these variables changes in the build environment, the command will be
re-run even if the input files are still up to date.
\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 responseFileArgumentIndex
\li int
\li 0
\li Index of the first argument to include in the response file. For example this may be
used in conjunction with a compiler wrapper where the first argument (the path to the
compiler) must be included on the raw command line.
\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.
\row
\li \c stdoutFilePath
\li string
\li undefined
\li Redirects the filtered standard output content to \c stdoutFilePath. If \c stdoutFilePath is undefined,
the filtered standard output is forwarded to \QBS, possibly to be printed to the console.
\row
\li \c stderrFilePath
\li string
\li undefined
\li Redirects the filtered standard error output content to \c stderrFilePath. If \c stderrFilePath is undefined,
the filtered standard error output is forwarded to \QBS, possibly to be printed to the console.
\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
*/
|