- Qbs Manual
- Rule Item
- Qt Build Suite 1.4.2

QtApplication Item StaticLibrary Item

# Rule Item

A multiplex rule creates one transformer that takes all input artifacts with the matching input file tag and creates one or more artifacts (e.g. C++ linker). A simplex rule creates one transformer per matching input file (e.g. C++ compiler). As a real-world example of a simplex rule, here is a simplified version of Qbs' rule for transforming C++ sources into object files using gcc:

    Rule {
        id: compiler
        inputs: ['cpp']
        auxiliaryInputs: ['hpp']

        Artifact {
            fileTags: ['obj']
            filePath: '.obj/' + qbs.getHash(input.baseDir) + '/' + input.fileName + '.o'
        }

        prepare: {
            var args = [];
            if (product.moduleProperty('cpp', 'debugInformation'))
                args.push('-g');
            var warnings = product.moduleProperty('cpp', 'warningLevel')
            if (warnings === 'none')
                args.push('-w');
            if (warnings === 'all') {
                args.push('-Wall');
                args.push('-Wextra');
            }
            if (product.moduleProperty('cpp', 'treatWarningsAsErrors'))
                args.push('-Werror');
            var includePaths = product.moduleProperties('cpp', 'includePaths');
            for (i in includePaths)
                args.push('-I' + includePaths[i]);
            var defines = product.moduleProperties('cpp', 'defines');
            for (i in defines)
                args.push('-D' + defines[i]);
            args.push('-c');
            args.push(input.filePath);
            args.push('-o');
            args.push(output.filePath);
            var compilerPath = ModUtils.moduleProperty(product, 'compilerPath');
            var cmd = new Command(compilerPath, args);
            cmd.description = 'compiling ' + input.fileName;
            cmd.highlight = 'compiler';
            return cmd;
        }
    }

## Rule Properties

Property | Type | Default | Description
--- | --- | --- | ---
multiplex | bool | false | Determines whether this is a multiplex rule.
inputs | string list | undefined | File tags the input artifacts must match. All output artifacts will depend on all artifacts in the product with the given input file tags. Also these artifacts are available in the inputs variable of the prepare script.
auxiliaryInputs | string list | undefined | A list of file tags. This rule will be dependent on every other rule and transformer that produces artifacts that are compatible with auxiliaryInputs. Unlike inputs, the property auxiliaryInputs has no effect on the content of the inputs variable in the prepare script.
excludedAuxiliaryInputs | string list | undefined | A list of file tags. Connections to rules that produce these file tags are prevented. This property has no effect on the content of the inputs variable in the prepare script.
inputsFromDependencies | string list | undefined | File tags the artifacts of product dependencies must match. For example, the product foo might appear as follows in the current product:
            Depends {
                name: "foo"
            }
All artifacts of foo that match the given file tags will appear in the inputs variable of the prepare script. Also, each output artifact of this rule will be dependent on those artifacts.
outputArtifacts | array of objects | undefined | An array of output artifacts, specified as JavaScript objects. Example:
            outputArtifacts: [{filePath: "myfile.txt", fileTags: ["foo", "bar"]}]
For a description of the possible properties, see the documentation of the Artifact item. Output artifacts can be specified either by `Rule.outputArtifacts` or by `Artifact` items. Use `Rule.outputArtifacts` if the set of outputs is not fixed but dependent on the input's content. The user may set the property `explicitlyDependsOn` on artifact objects, which is similar to `Rule.explicitlyDependsOn`.
outputFileTags | string list | undefined | If output artifacts are specified by `Rule.outputArtifacts`, then `Rule.outputFileTags` must be a list of file tags the rule potentially produces.
condition | bool | true | If true, the rule is enabled, otherwise it does nothing.
explicitlyDependsOn | string list | undefined | Each artifact that matches the file tags in explicitlyDependsOn is added to the dependencies of each output node.
prepare | script | undefined | Script that prepares the commands to transform the inputs to outputs. The code in this script is treated as a function with the signature `function(project, product, inputs, outputs, input, output)`. The argument `input` is `undefined` if there's more than one input artifact for this rule. Similarly, `output` is only defined if there's exactly one output artifact.

QtApplication Item StaticLibrary Item