[Qbs] Need help with setting up a code generator

Ola Røer Thorsen ola at silentwings.no
Tue Dec 12 10:30:18 CET 2017


Thanks a lot for the help, Christian!

2017-12-11 13:27 GMT+01:00 Christian Kandeler <christian.kandeler at qt.io>:

>     Group {
>         name: "header inputs"
>         files: ["dir1/*.h"]
>         fileTags: ["generator.in.headers"]
>     }
>     Group {
>         name: "template inputs"
>         prefix: "dir2/"
>         files: ["*.tpl", "*.h", "*.cpp]
>         fileTags: ["generator.in.templates"]
>     }
>
>
Is there some way to debug-print the contents of these groups as I go along
writing the qbs file?


>     Rule {
>         // See https://doc.qt.io/qbs/rule-item.html for details.
>         multiplex: true // Probably. Not entirely clear from your
> description
>

Yes multiplex seems to be the correct option here.


>         inputs: ["generator.in.headers", "generator.in.templates"]
>
>         // I assume the number of output files is dynamic and depends on
>         // the number and/or contents of the input files.
>         outputFileTags: ["h", "cpp"]
>         outputArtifacts: {
>             // The following two are arrays of artifact objects.
>             // Their file paths are available via the filePath property.
>             var headerInputs = inputs["generator.in.headers"];
>             var templateInputs = inputs["generator.in.templates"];
>
>             var outList = [];
>             // Do what you need to do here to calculate the output
>             // from the input artifacts. The return value is a list of
>             // objects with properties filePath and fileTags.
>             return outList;
>         }
>

Does this mean I need to know the exact list of files the code generator
outputs before it is run? Normally I'd only know that after having run the
code generator and look into it's output directory.

Currently I'm trying to print the contents of headerInputs and
templateInputs like this,

            var headerInputs = inputs["generator.in.headers"];
            var templateInputs = inputs["generator.in.templates"];

            console.warn("headerInputs: " + headerInputs);
            console.warn("templateInputs: " + templateInputs);

But the output says "headerInputs: undefined" and "templateInputs:
undefined"


>         prepare: {
>             var generatorArgs = [];
>             // Generate the command-line arguments for the generator tool
>             // from the inputs and outputs variables.
>             var cmd = new Command("generator", generatorArgs);
>             cmd.description = "Running generator";
>             return [cmd];
>         }
>
>
I've hit some issue with the argument list/array. One of my argument
strings contain a wildcard '*', which casues that string to be wrapped with
'.

            var generatorArgs = [
                        product.sourceDirectory + "/api/some*files.h"),
                        "-o", product.buildDirectory + "/gen/",
                    ];

The actual command line has the first string wrapped in ' ' because of the
* in the string (wildcards are used for the input to the generator tool).
The code generator doesn't cope with the wrapping in '' (neither will "ls"
or any other command). Here is the resulting command line:

/home/xxxxx/bin/generator '/home/xxx/api/some*files.h' -o
/home/xxx/build-xxx-Desktop_Qt_5_10_0_GCC_64bit-Debug/qtc_Desktop_Qt_5_10_0_GCC_64bit_Debug/xxx.3a7a69e5/gen/

Why does the Command object add the '' around strings with * in them, and
is there some way to avoid that?

Best regards,
Ola
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/qbs/attachments/20171212/3b5cde2d/attachment.html>


More information about the Qbs mailing list