[QBS] How to reuse the results of Rule execution?

Christian Kandeler Christian.Kandeler at qt.io
Tue Sep 13 21:51:38 CEST 2016


NIkolai Marchenko wrote:

> Suppose I have a rule that generates .cpp files from .proto files. These generated files are needed to be plugged in into different products in a project.
>
> When I define stuff like that in one of the products:
> Group { 
>    condition: conditionals.grpc == true
>    name: "proto"
>    files: [        "Interfaces/Auth/service.proto"    ]   
>     fileTags: ["proto", "grpc"]
> }
> these files are built OK, but then I need to EXPLICITLY mention generated results in all of the other products that need the service.grpc.pb.cc file 
> because only this exact (generating) product gets the artifact auto plugged in.

When you say "auto plugged in", I suppose you mean that the generated files are used as inputs to rules (in this case, the compiler rule). Of course, only products that know about the files can make use of them.

> Is there a way to tell another product that it needs to pick the results of this generation?

Either include the group in the other products (this will do the generation n times, though), or make a dedicated product that others can depend on.

> If I try to re-generate by plugging the group above into a second product I get a conflict "Conflicting artifacts for file path"

Then  your rule is broken. It *must* be able to deal with files of the same name in different products. Imagine a large project with lots of tools, and now imagine a compiler rule that could not deal with more than one file called main.cpp being present in the whole project...
Note that the filePath property of the Artifact item resolves relative paths using the product build directory as the base, so you really have to go out of your way to create a conflict.

> and if I mesh a product name into generated folder structure 

As mentioned above, you absolutely must do that and it comes for free.

> I get an ugly mess inmy header includes. 

Why? Are you generating headers? In that case, the module that defines your Rule needs to set cpp.includePaths accordingly, of course.


Christian


More information about the Qbs mailing list