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 non-multiplex rule creates one transformer per matching input file (e.g. C++ compiler). As a real-world example of a non-multiplex 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']
        fileName: '.obj/' + product.name + '/' + 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.fileName);
        args.push('-o');
        args.push(output.fileName);
        var compilerPath = ModUtils.moduleProperty(product, 'compilerPath');
        var cmd = new Command(compilerPath, args);
        cmd.description = 'compiling ' + FileInfo.fileName(input.fileName);
        cmd.highlight = 'compiler';
        return cmd;
    }
}

Rule Properties

PropertyTypeDefaultDescription
multiplexboolfalseDetermines whether this is a multiplex rule.
inputsstring listundefinedFile 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.
auxiliaryInputsstring listundefinedA 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.
usingsstring listundefinedFile 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.

conditionbooltrueIf true, the rule is enabled, otherwise it does nothing.
explicitlyDependsOnstring listundefinedEach artifact that matches the file tags in explicitlyDependsOn is added to the dependencies of each output node.
scannersstring listundefinedList of dependency scanner ids for this rule. The scanners are run just before the prepare script is executed.
preparescriptundefinedScript 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.