[QBS] QBS Rule Item: Code generation with multiple output files with variable names

Christian Kandeler christian.kandeler at qt.io
Wed May 18 10:51:25 CEST 2016


On 05/18/2016 09:33 AM, Sebastian Stadelmann wrote:
> in our project we need to generates several „*.cpp“ and „*.h“ files from one input file ("*.db“).
> In the input file we define a database table structure for multiple tables and generate one cpp class
> for each table definition.
> The name of the generated cpp files is not known before we start the code generator because the name
> was defined in the input file.
> Ex.: input: customer.db
> output: parts.h, parts.cpp, orders.h, orders.cpp …
> We also generate a text file with a list of all generated files. This text file has a defined name.
>
> Is there a way to compile all generated files in the current product after running the code generator by appending the files from the
> generated text file to the product files? Or do you have any other suggestions?

Yes. You create a second rule. Its input is the generated text file. In 
the outputArtifacts script of that rule you parse the text file and 
create one artifact object per line. The command itself created by that 
rule in its prepare script can be empty (as the files already exist). 
That should be all.

> import qbs
> import qbs.FileInfo
> AucosDynamicLibrary {
>      name: "subcore"
>      Depends { name: "core" }
>      files: [
>          "*.db",
>          "*.cpp",
>          "*.h"
>      ]
>      FileTagger {
>          patterns: ["*.db"]
>          fileTags: ["db"]
>      }
>      Rule {
>          inputs: ["db"]
>          outputArtifacts: [{filePath: FileInfo.baseName(input.filePath)+".txt"}]
>          outputFileTags: ["cpp"]

Unless I completely misunderstood the problem, this file tag should not 
be "cpp", but some custom tag that serves as an input to the second rule 
mentioned above.

>
>          prepare: {
>              var awk = "awk"
>              var awkScript = project.path + "/../utils/sql/db2c++.awk";
>              var args = ["-f ", awkScript, "-v", "prifile="+FileInfo.baseName(input.filePath)+".txt",  input.filePath];
>              var cmd = new Command(awk, args);
>              cmd.workingDirectory = product.buildDirectory;
>              cmd.description = "generating C++ source";
>              return cmd;
>          }
>      }
>
>      Export { Depends { name: "core" } }
> }


Christian




More information about the Qbs mailing list