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

Jake Petroules Jake.Petroules at qt.io
Wed May 18 10:07:21 CEST 2016


Hi Sebastian,

You need to give the output artifact of your Rule the cpp file tag in order it to be recognized as a C++ source file. The outputFileTags property only indicates the potential set of file tags that artifacts in the outputArtifacts script may contain (for more complex Rules where the list of artifacts may vary, the distinction is necessary); you still have to explicitly state which file tags each Artifact has. You can also use output.filePath in your prepare script instead of repeating the value of your Artifact's filePath literally. For example:

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", fileTags: ["cpp"]}]
       outputFileTags: ["cpp"]

       // Instead of outputArtifacts and outputFileTags, you could also use the following, since there is only one output Artifact:
       /*Artifact {
           filePath: FileInfo.baseName(input.filePath) + ".txt"
           fileTags: ["cpp"]
       }*/

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

   Export { Depends { name: "core" } }
}

On May 18, 2016, at 12:33 AM, Sebastian Stadelmann <s.stadelmann at aucos.de<mailto:s.stadelmann at aucos.de>> wrote:

Hi,

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?

Any help would be appreciated.

Thanks
Sebastian

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"]

       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" } }
}




_______________________________________________
QBS mailing list
QBS at qt-project.org<mailto:QBS at qt-project.org>
http://lists.qt-project.org/mailman/listinfo/qbs

--
Jake Petroules - jake.petroules at theqtcompany.com<mailto:jake.petroules at theqtcompany.com>
Consulting Services Engineer - The Qt Company
Qbs build system evangelist - qbs.io<http://qbs.io>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/qbs/attachments/20160518/5ed220c4/attachment.html>


More information about the Qbs mailing list