2013-06-18 36 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的問題在於,如果輸入集中的單個文件發生更改,則所有輸入工件都將被重新處理。在我的情況下,這相當耗時。