[Qbs] Need help with setting up a code generator

Christian Kandeler christian.kandeler at qt.io
Tue Dec 12 11:00:00 CET 2017


On Tue, 12 Dec 2017 10:30:18 +0100
Ola Røer Thorsen <ola at silentwings.no> wrote:

> Is there some way to debug-print the contents of these groups as I go along
> writing the qbs file?

You could use the status command. Or, if you are using Qt Creator, they are simply listed in the project tree.

> 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.

Then you'll have to run the tool in the outputArtifacts script already. Unless the tool has some special "dry-run" option, the actual command could then become a dummy.
The cleaner solution, assuming the tool is under your control, would be to give it such an option that prints a suitably formatted list of the outputs it would produce.

> 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);

You'd typically use JSON.stringify here.

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

That means you don't have any inputs with these tags. Double-check the spelling. There must be some sort of match though, because otherwise the rule would not have run (assuming you did not force it by setting alwaysRun or requiresInputs).
You can see all the inputs, including their file tags, by printing JSON.stringify(inputs).

> >         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"),

This looks like the wrong thing to do. If you pass some wildcard strings instead of actual files, you are circumventing the build system, as it cannot do change tracking on the expanded files.
Instead, you should only pass actual file paths derived from the rule inputs. 

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

To prevent shell expansion, as the arguments are supposed to go to the command as-is. There has not yet been a use case to opt out of this, and I don't think yours is a valid one (as explained above).


Christian



More information about the Qbs mailing list