【问题标题】:How can a Qbs build Rule use a productQbs 构建规则如何使用产品
【发布时间】:2013-06-18 16:08:54
【问题描述】:

我想使用 Qbs 来编译一个现有的项目。这个项目已经包含了一个在这个项目中大量使用的代码转换工具(my_tool)。

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

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 引用?

【问题讨论】:

  • 还没有标签'qbs'...

标签: qt build-system qbs


【解决方案1】:

此答案基于 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;
        }
    }
}

【讨论】:

    【解决方案2】:

    不幸的是,自 QBS 1.5.0 起,Rule 中的 usings 属性已被弃用。目前我有同样的要求。在复用Rule中使用产品工件。

    多路复用Rule 的问题是,如果输入集中的单个文件发生更改,所有输入工件都将被重新处理。就我而言,这相当耗时。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 1970-01-01
      • 2015-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多