2013-06-18 25 views
4

我想使用Qbs编译现有项目。这个项目已经包含了一个代码转换工具(my_tool),该工具在这个项目中被大量使用。Qbs构建规则如何使用产品

到目前为止,我已经(简体):

import qbs 1.0 

Project { 
    Application { 
     name: "my_tool" 
     files: "my_tool/main.cpp" 
     Depends { name: "cpp" } 
    } 

    Application { 
     name: "my_app" 
     Group { 
      files: 'main.cpp.in' 
      fileTags: ['cpp_in'] 
     } 
     Depends { name: "cpp" } 

     Rule { 
      inputs: ["cpp_in"] 
      Artifact { 
       fileName: input.baseName 
       fileTags: "cpp" 
      } 
      prepare: { 

       var mytool = /* Reference to my_tool */; 

       var cmd = new Command(mytool, input.fileName, output.fileName); 
       cmd.description = "Generate\t" + input.baseName; 
       cmd.highlight = "codegen"; 
       return cmd; 
      } 
     } 
    } 
} 

我怎样才能到my_tool命令的参考?

+0

Ther没有标记'qbs'尚未... –

回答

7

此答案基于来自Qbs作者Joerg Bornemann的电子邮件,他允许我在此引用它。

Rule的属性usings允许从产品相关性向输入添加工件。 在这种情况下,我们对“应用程序”工件感兴趣。

然后可以访问应用程序列表input.application

Application { 
    name: "my_app" 
    Group { 
     files: 'main.cpp.in' 
     fileTags: ['cpp_in'] 
    } 
    Depends { name: "cpp" } 

    // we need this dependency to make sure that my_tool exists before building my_app 
    Depends { name: "my_tool" } 

    Rule { 
     inputs: ["cpp_in"] 
     usings: ["application"] // dependent "application" products appear in inputs 
     Artifact { 
      fileName: input.completeBaseName 
      fileTags: "cpp" 
     } 
     prepare: { 
      // inputs["application"] is a list of "application" products 
      var mytool = inputs["application"][0].fileName; 
      var cmd = new Command(mytool, [inputs["cpp_in"][0].fileName, output.fileName]); 
      cmd.description = "Generate\t" + input.baseName; 
      cmd.highlight = "codegen"; 
      return cmd; 
     } 
    } 
} 
0

不幸的是在Ruleusings属性,因为QBS 1.5.0弃用。目前我有相同的要求。在复用Rule中使用产品工件。

Multiplex Rule的问题在于,如果输入集中的单个文件发生更改,则所有输入工件都将被重新处理。在我的情况下,这相当耗时。