[QBS] Referencing Rule properties

Dennis Tomas den.t at gmx.de
Fri Aug 5 18:45:53 CEST 2016


Am 05.08.2016 um 13:55 schrieb Christian Kandeler:
> On 08/05/2016 01:40 PM, Dennis Tomas wrote:
>> Am 02.08.2016 um 12:29 schrieb Christian Kandeler:
>>> On 08/01/2016 10:24 AM, Dennis Tomas wrote:
>>>> Am 01.08.2016 um 09:20 schrieb Christian Kandeler:
>>>>> On 07/29/2016 09:05 PM, Dennis Tomas wrote:
>>>>>> Rule {
>>>>>>     property string fileName: "resources"
>>>>>>     multiplex: true
>>>>>>     Artifact {
>>>>>>         filePath: baseName + ".qrc" // ReferenceError
>>>>>>         fileTags: ["qrc"]
>>>>>>     }
>>>>>>     prepare: {
>>>>>> [...]
>>>>>>     }
>>>>>> }
>>>>>>
>>>>>> I get a ReferenceError as marked above. Is there a way to somehow
>>>>>> reference baseName from the Artifact's filePath property?
>>>>>
>>>>> Have you tried parent.baseName?
>>>>>
>>>> Yes, this also results in a ReferenceError.
>>>
>>> Ah yes. That's because the filePath property is evaluated in a
>>> different context and at a later stage (so that you can refer to
>>> "inputs", for instance). This means your approach cannot work as is;
>>> you'll have to look for a different way to set your output file name.
>>> There are lots of possibilities; for instance, you could derive it
>>> from the name of the first input artifact. It just has to be unique.
>>>
>> In my case it's not sufficient for the name to be unique, because I have
>> to reference it when using the Q_INIT_RESOURCE macro.
>
> In that case, I suggest that you represent the qrc files as products 
> and let your rule derive the file name from product.targetName.
>
Thanks. Now I have a custom product item Qrc.qbs:

StaticLibrary {

     property stringList inputs

     Rule {
         inputs: product.inputs
         Artifact {
             filePath: product.targetName + ".qrc"
             fileTags: ["qrc"]
         }
         prepare: {
[...]
         }
     }
     Depends { name: "Qt.core" }
}

and extend it in translations.qbs and qml.qbs:

Qrc {
     name: "foo-translations"
     files: ["translations/*.ts"]
     inputs: ["qm"]
}

Qrc {
     name: "foo-qml"
     Group {
         files: "qml/**"
         fileTags: ["qml"]
     }
     inputs: ["qml"]
}

The product foo depends on foo-translations and foo-qml. It works, but 
I'd really like it to be less verbose (I have a large number of products 
in my project, each having one or more resource files to be generated).
I've hacked Qbs to make the rule available to the output artifact and 
the prepare function: 
https://github.com/dtomas/qbs/commit/716cc901b124903866a3ba1370e1085804342d8d
What do you think of it?

Regards,
Dennis



More information about the Qbs mailing list