[QBS] Some questions about modules creating

Christian Kandeler christian.kandeler at qt.io
Mon May 9 09:28:14 CEST 2016


On 05/07/2016 04:14 PM, Алексей Шашев wrote:
> Hi, there. I need help with modules creating.
>
> 1) I'm trying to make the rule independent of configure, I mean "debug"
> or "release". For example I have archives containing *.h and *.cpp
> files. I wrote:
>
> Module
> {
>      property string outputPath: product.sourceDirectory + "/generated"

You should never generate any files in the source directory. Of course, 
if you plan to use your module in your own personal project only, you 
can do whatever you want, but in general this is a no-go.

>      FileTagger {
>          patterns: "*.7z"
>          fileTags: ["unpack7z"]
>      }
>
>      Rule {
>          id: extractor7z
>          inputs: ["unpack7z"]
>
>          Artifact {
>              filePath: product.moduleProperty("extractor7z","outputPath")  +
>                        "/" + input.baseDir

No, artifacts cannot be directories. You need to use the outputArtifacts 
property; see doc.qt.io/qbs/rule-item.html. In the code there, you call 
7z, listing all the files in the package, and create a list of artifacts 
from that information.

>              fileTags: "unpacked"
>          }
>
>          condition: {
>              return true;

This is the default.

>          }
>
>          prepare: {
>              var cmdFunc = function() {
>                  if ( !File.exists(output.filePath) ||
>                      File.lastModified(output.filePath) <
> File.lastModified(input.filePath))


No, no, no. The build system does this for you! The code in the next 
block is all you need.

>                  {
>                      var args = [];
>                      args.push("x");
>                      args.push("-y");
>                      args.push("-o" + output.filePath);
>                      args.push(input.filePath);
>                      var cmd = new Command("7z", args);
>
>                      return cmd;
>                  }
>                  else
>                  {
>                      var cmd = new JavaScriptCommand();
>                      cmd.sourceCode = function() {
>                          print("Do nothing...");
>                      }
>                      return cmd;
>                  }
>              }
>
>              var cmd = cmdFunc();
>              cmd.description = "extracting " + input.fileName;
>              cmd.highlight = "extractor 7z";
>
>              return cmd;
>          }
>
>      }
> }
>
> It works but I'm not sure that it's good idea. Does right way to do it
> exist?
>
> And if I update archive I get warning "WARNING: Cannot remove
> '/home/hokum/progs/qbs-test/hello_world_project/test_unpack/generated/archives'."
> What does it mean?

This is because qbs does not expect this file to be a directory; see above.

> May be archive is not good example, but in reality I want to get
> external dependencies from another source control systems and network
> shares. Product will have special files with path to external dependencies.
>
> 2) What does "id" property of Rule Item mean?

Ids are a QML concept. You can refer to the instances of an item via 
this property. It is not technically needed for rules, but you can use 
it as a sort of documentation.

> 3) I can't understand how module "cpp" works. Only CppModule.qbs
> contains Module Item, other qbs files contain UnixGCC Item, CppModule
> Item.

All of these items are Modules. You might want to read up on item 
inheritance in Qml.

> I guess Module Item from CppModule.qbs describes general
> properties of module "cpp" and the condition property of Item defines
> which Item will work.

Yes.

> But I had tried to do it and I got error "Module mymodule could not be loaded".

You'll need to provide a specific (minimal but complete) example for me 
to give a useful comment.


Christian



More information about the Qbs mailing list