/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** 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.

/*!
    \contentspage reference.html
    \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.
    \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
*/
