Command and JavaScriptCommand

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

Command

A 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:

 var insaneCommand = new Command("rm", ["-r", "/"]);

The Rule item documentation shows a Command in context.

JavaScriptCommand

A JavaScriptCommand represents a chunk of JavaScript code that is run at build time. For instance:

 var cmd = new JavaScriptCommand();
 cmd.apology = "Sorry.";
 cmd.sourceCode = function() {
     console.info("I'm a rather pointless command.");
     console.info(apology);
 };

Within the source code, the special identifiers project and product (giving access to project and product properties, respectively) as well as inputs and 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 Rule item documentation shows a JavaScriptCommand in context.

Properties

Common Properties

The following properties are available in both Command and JavaScriptCommand.

PropertyTypeDefaultDescription
descriptionstringemptyA message that is displayed when the command is executed.
extendedDescriptionstringemptyA detailed description that is displayed when the command is executed.
highlightstringemptyA tag that can be used to influence how the 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:
  • "compiler" indicates that the command processes source code
  • "linker" indicates that the command links objects
  • "codegen" indicates that the command generates source code
  • "filegen" indicates that the command creates arbitrary files

All other values are mapped to the default color.

jobPoolstringemptyDetermines which job pool the command will use. An empty string, which is the default, stands for the global job pool. See here and here for more information on job pools.
silentboolfalseA flag that controls whether the description is printed. Set it to true for commands that users need not know about.

Note: If this property is false, then description must not be empty.

timeoutint-1Time limit for the command execution in seconds. If the command does not finish within the timeout, it is cancelled. In case of a 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.
This property was introduced in Qbs 1.15.

Command Properties

PropertyTypeDefaultDescription
argumentsstringListemptyThe list of arguments to invoke the command with. Explicitly setting this property overrides an argument list provided when instantiating the object.
environmentstringListemptyA 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".
maxExitCodeint0The 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.
programstringundefinedThe binary to invoke. Explicitly setting this property overrides a path provided when instantiating the object.
relevantEnvironmentVariablesstringListundefinedNames 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.
responseFileThresholdint32000 on Windows, -1 elsewhereIf this value is greater than zero and less than the length of the full command line, and if 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.
responseFileArgumentIndexint0Index 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.
responseFileUsagePrefixstringemptyThe prefix that informs program that the rest of the argument is a path to a file containing the actual command line.
stderrFilterFunctionfunctionundefinedA 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.
stdoutFilterFunctionfunctionundefinedA 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.
workingDirectorystringemptyThe program's working directory.
stdoutFilePathstringundefinedRedirects the filtered standard output content to stdoutFilePath. If stdoutFilePath is undefined, the filtered standard output is forwarded to Qbs, possibly to be printed to the console.
stderrFilePathstringundefinedRedirects the filtered standard error output content to stderrFilePath. If stderrFilePath is undefined, the filtered standard error output is forwarded to Qbs, possibly to be printed to the console.

JavaScriptCommand Properties

PropertyTypeDefaultDescription
sourceCodefunctionundefinedThe JavaScript function to execute.