Re: [QBS] Get property from parent project
On 05/22/2014 04:19 PM, olivier musse wrote: Property inheritance is really nice and simple. Thanks for this important information. I have succeed to verify it, but then have another question : How can I detect in the sub project if the property is already set at an higher level project. Project { property string myprop:val1 Project{ myprop: {here set to val2 if not already existing} } } This is not possible, due to how QML works. Your second line is a binding, which you can only use if a property was already declared. This information is static, and an error will be thrown if you use myprop on the left-hand side of a binding if no such property exists. Ok I understand, but at least, suppose the property exists, can I check if is it empty and do something in this case. BR Olivier ___ QBS mailing list QBS@qt-project.org http://lists.qt-project.org/mailman/listinfo/qbs
Re: [QBS] Get property from parent project
On 05/22/2014 06:07 PM, Tim Hutt wrote: Product { property string foo: baz Rule { prepare: { var a = product.foo; Sure it does. We use that all the time. Try again ;) Here is a full example that I just tested: $ cat project.qbs import qbs Product { type: foo Group { files: foo.txt fileTags: foo-source } property string foo: baz Rule { inputs: foo-source Artifact { fileName: foo.out fileTags: foo } prepare: { var a = product.foo; var cmd = new JavaScriptCommand(); cmd.silent = true; cmd.a = a; cmd.sourceCode = function() { print(a); } return cmd; } } } $ qbs -q baz $ Christian ___ QBS mailing list QBS@qt-project.org http://lists.qt-project.org/mailman/listinfo/qbs
Re: [QBS] Get property from parent project
Ah it seems to work now, weird. I may have typo'd project instead of product. Also, good news! I have found a reliable way to trigger the qbs-isn't-updated bug: 1. Create a new C++ QBS project in QtCreator. 2. Rename main.cpp to foo.txt 3. Paste this in the QBS file: import qbs Product { type: foo Group { files: foo.txt fileTags: foo-source } property string foo: baz Rule { inputs: foo-source Artifact { fileName: foo.out fileTags: foo } prepare: { foobar; var a = product.foo; var cmd = new JavaScriptCommand(); cmd.silent = true; cmd.a = a; cmd.sourceCode = function() { console.log(a); } return cmd; } } } 4. Try and build it, it will say foobar not found (or whatever). 5. Change foobar to foobar2, but DON'T SAVE THE QBS FILE! 6. Now right-click on the project in the project pane and select rebuilt. 7. Lo! It still says 'foobar not found', not foobar2. 8. Now change it to foobar3, and this time save the QBS file before building. 9. Rebuild. It will still say 'foobar not found'. Perhaps some kind of race condition between QtCreator saving the file for a rebuild (because I have the save all files before building option enabled) and QBS checking the timestamps (or whatever it does). Cheers, Tim On 23 May 2014 08:28, Christian Kandeler christian.kande...@digia.comwrote: On 05/22/2014 06:07 PM, Tim Hutt wrote: Product { property string foo: baz Rule { prepare: { var a = product.foo; Sure it does. We use that all the time. Try again ;) Here is a full example that I just tested: $ cat project.qbs import qbs Product { type: foo Group { files: foo.txt fileTags: foo-source } property string foo: baz Rule { inputs: foo-source Artifact { fileName: foo.out fileTags: foo } prepare: { var a = product.foo; var cmd = new JavaScriptCommand(); cmd.silent = true; cmd.a = a; cmd.sourceCode = function() { print(a); } return cmd; } } } $ qbs -q baz $ Christian ___ QBS mailing list QBS@qt-project.org http://lists.qt-project.org/mailman/listinfo/qbs ___ QBS mailing list QBS@qt-project.org http://lists.qt-project.org/mailman/listinfo/qbs
Re: [QBS] Get property from parent project
On 22-May-14 16:14, Christian Kandeler wrote: On 05/22/2014 04:00 PM, Tim Hutt wrote: Relatedly, how can I access properties from a Rule's prepare script? E.g. this does not work - it thinks foo is not defined. Rule { property string foo: baz prepare: { var /a = foo;/ Yeah, Rules (much like Artifacts) are not first-class items in that they don't really support adding custom properties in a meaningful way (i.e. you can't access them later from prepare scripts). Maybe that is worth changing. Jörg, what's your opinion on this? I recommend to not make the properties of the Rule item visible in Rule.prepare for the following reasons: 1. The variable inputs that is available in Rule.prepare clashes with the property Rule.inputs. 2. Making the other properties visible doesn't come for free. You'd need special cases. E.g. should prepare be visible in prepare? 3. The gain is questionable. What's the advantage compared to defining variables at the start of the script or defining the properties outside the Rule item? BR, Joerg ___ QBS mailing list QBS@qt-project.org http://lists.qt-project.org/mailman/listinfo/qbs
Re: [QBS] Get property from parent project
On 05/23/2014 11:05 AM, Tim Hutt wrote: I have found a reliable way to trigger the qbs-isn't-updated bug: 1. Create a new C++ QBS project in QtCreator. 2. Rename main.cpp to foo.txt 3. Paste this in the QBS file: import qbs Product { type: foo Group { files: foo.txt fileTags: foo-source } property string foo: baz Rule { inputs: foo-source Artifact { fileName: foo.out fileTags: foo } prepare: { foobar; var a = product.foo; var cmd = new JavaScriptCommand(); cmd.silent = true; cmd.a = a; cmd.sourceCode = function() { console.log(a); } return cmd; } } } 4. Try and build it, it will say foobar not found (or whatever). 5. Change foobar to foobar2, but DON'T SAVE THE QBS FILE! 6. Now right-click on the project in the project pane and select rebuilt. 7. Lo! It still says 'foobar not found', not foobar2. 8. Now change it to foobar3, and this time save the QBS file before building. 9. Rebuild. It will still say 'foobar not found'. Perhaps some kind of race condition between QtCreator saving the file for a rebuild (because I have the save all files before building option enabled) and QBS checking the timestamps (or whatever it does). Yes, that is indeed the reason. See https://bugreports.qt-project.org/browse/QBS-596. Thanks for the report. I have never seen this problem because I always save my files manually. Christian ___ QBS mailing list QBS@qt-project.org http://lists.qt-project.org/mailman/listinfo/qbs
Re: [QBS] Get property from parent project
On 05/22/2014 01:26 PM, olivier musse wrote: I have a project with subproject and so on. When in a product or a subproject, how to access parent project properties. Sometimes it seems to be project.MyProperty, sometimes MyProperty Is there any documentation to clarify this point? Simple: Project properties are inherited by sub-projects. If you use the property outside of a Project item, you need to access it via the magic project property. As an example Project { property string myprop1 : val1 product{ property string myproductprop Depends{name:project.myprop1} //in this case seems the project prefix is needed Yes, because you are not directly in a Project item. myproductprop:myprop1 //in this case with project prefix it does not work and seems to works without it No, I don't think so. If you are sure about it, please file a bug report and attach the complete project. Christian ___ QBS mailing list QBS@qt-project.org http://lists.qt-project.org/mailman/listinfo/qbs
Re: [QBS] Get property from parent project
Relatedly, how can I access properties from a Rule's prepare script? E.g. this does not work - it thinks foo is not defined. Rule { property string foo: baz prepare: { var *a = foo;* On 22 May 2014 12:40, Christian Kandeler christian.kande...@digia.comwrote: On 05/22/2014 01:26 PM, olivier musse wrote: I have a project with subproject and so on. When in a product or a subproject, how to access parent project properties. Sometimes it seems to be project.MyProperty, sometimes MyProperty Is there any documentation to clarify this point? Simple: Project properties are inherited by sub-projects. If you use the property outside of a Project item, you need to access it via the magic project property. As an example Project { property string myprop1 : val1 product{ property string myproductprop Depends{name:project.myprop1} //in this case seems the project prefix is needed Yes, because you are not directly in a Project item. myproductprop:myprop1 //in this case with project prefix it does not work and seems to works without it No, I don't think so. If you are sure about it, please file a bug report and attach the complete project. Christian ___ QBS mailing list QBS@qt-project.org http://lists.qt-project.org/mailman/listinfo/qbs ___ QBS mailing list QBS@qt-project.org http://lists.qt-project.org/mailman/listinfo/qbs
Re: [QBS] Get property from parent project
On 05/22/2014 04:00 PM, Tim Hutt wrote: Relatedly, how can I access properties from a Rule's prepare script? E.g. this does not work - it thinks foo is not defined. Rule { property string foo: baz prepare: { var /a = foo;/ / / Yeah, Rules (much like Artifacts) are not first-class items in that they don't really support adding custom properties in a meaningful way (i.e. you can't access them later from prepare scripts). Maybe that is worth changing. Jörg, what's your opinion on this? Christian ___ QBS mailing list QBS@qt-project.org http://lists.qt-project.org/mailman/listinfo/qbs
Re: [QBS] Get property from parent project
Christian, The bug I was talking about (project prefix) is in a Rule artifact. I do something like (separated in multiple files but the same hierarchy) Project{ property string myProp:val Project{ Product{ Rule{ inputs:['myinputs'] Artifact { fileName:project.myProp } } } This seems to work on my side but should not according to your answer to Tim. Regards Olivier On 05/22/2014 04:00 PM, Tim Hutt wrote: Relatedly, how can I access properties from a Rule's prepare script? E.g. this does not work - it thinks foo is not defined. Rule { property string foo: baz prepare: { var /a = foo;/ / / Yeah, Rules (much like Artifacts) are not first-class items in that they don't really support adding custom properties in a meaningful way (i.e. you can't access them later from prepare scripts). Maybe that is worth changing. Jörg, what's your opinion on this? Christian ___ QBS mailing list QBS@qt-project.org http://lists.qt-project.org/mailman/listinfo/qbs ___ QBS mailing list QBS@qt-project.org http://lists.qt-project.org/mailman/listinfo/qbs
Re: [QBS] Get property from parent project
On 05/22/2014 04:19 PM, olivier musse wrote: Property inheritance is really nice and simple. Thanks for this important information. I have succeed to verify it, but then have another question : How can I detect in the sub project if the property is already set at an higher level project. Project { property string myprop:val1 Project{ myprop: {here set to val2 if not already existing} } } This is not possible, due to how QML works. Your second line is a binding, which you can only use if a property was already declared. This information is static, and an error will be thrown if you use myprop on the left-hand side of a binding if no such property exists. About the prefix usage, I think this is not a bug in qbs. In fact, i'm working with qbs plugin in qcreator and have noticed that often, modifications in qbs files are not taken into account. I need to close qcreator, delete the build dir and .qbs.user file and reopen my project for my modif to be taken into account. The bug was a false alarm due to this qbs plugin bug. If this is Creator 3.1, then please file a bug and attach an example project and a description how to reproduce. I do not observe such problems in my daily work. Christian ___ QBS mailing list QBS@qt-project.org http://lists.qt-project.org/mailman/listinfo/qbs
Re: [QBS] Get property from parent project
On 05/22/2014 04:35 PM, olivier musse wrote: Christian, The bug I was talking about (project prefix) is in a Rule artifact. I do something like (separated in multiple files but the same hierarchy) Project{ property string myProp:val Project{ Product{ Rule{ inputs:['myinputs'] Artifact { fileName:project.myProp } } } This seems to work on my side but should not according to your answer to Tim. Why? There is no property declared in the Rule item in your example. Christian ___ QBS mailing list QBS@qt-project.org http://lists.qt-project.org/mailman/listinfo/qbs
Re: [QBS] Get property from parent project
I can reproduce this issue in many case. it's often happen. 2014-05-22 22:41 GMT+08:00 Christian Kandeler christian.kande...@digia.com : About the prefix usage, I think this is not a bug in qbs. In fact, i'm working with qbs plugin in qcreator and have noticed that often, modifications in qbs files are not taken into account. I need to close qcreator, delete the build dir and .qbs.user file and reopen my project for my modif to be taken into account. The bug was a false alarm due to this qbs plugin bug. If this is Creator 3.1, then please file a bug and attach an example project and a description how to reproduce. I do not observe such problems in my daily work. -- Best Regards YuchenI ___ QBS mailing list QBS@qt-project.org http://lists.qt-project.org/mailman/listinfo/qbs