在产品的文件集合中添加文件

时间:2017-07-13 08:28:26

标签: qt qbs

我的问题很简单,我想从规则中操纵产品的文件stringList。我尝试使用product.files.push(file),product.files.append(file),但这两种解决方案都不适合我。

谢谢你的帮助。

修改 我创建了一个调用repc(QtRemoteObjects .rep文件编译器)的模块,该编译器将.rep文件作为输入并生成.h文件。我需要在项目中包含生成的.h文件,以便我可以继承其中定义的类型。 这是模块代码:

import qbs
import qbs.FileInfo
import qbs.File

Module {
    property bool source: true
    FileTagger {
        patterns: ["*.rep"]
        fileTags: ["repc-rep"]
    }
    Rule {
        inputs: ["repc-rep"]
        Artifact {
            filePath: {
                if (product.repc.source) {
                    return "repc_" + FileInfo.baseName(input.fileName) + "_source.h";
                } else {
                    return "repc_" + FileInfo.baseName(input.fileName) + "_replica.h";
                }
            }
            fileTags: ["hpp"]
        }
        prepare: {
            var cmd = new Command();
            cmd.description = "repc " + input.fileName;
            cmd.program = "repc.exe"
            if (product.repc.source) {
                cmd.arguments = ["-i", "rep", "-o", "source", input.filePath, output.filePath];
            } else {
                cmd.arguments = ["-i", "rep", "-o", "replica", input.filePath, output.filePath];
            }
            var cmd2 = new JavaScriptCommand();
            cmd2.silent = true;
            cmd2.sourceCode = function() {
                File.copy(output.filePath, FileInfo.path(input.filePath) + "/" + output.fileName);
            }
            return [cmd, cmd2];
        }
    }
}

这就是为什么我想要一种方法来自动将这个.h生成的文件添加到qbs项目中。

1 个答案:

答案 0 :(得分:1)

你不能,也不应该。 files属性包含源文件。根据定义,规则创建的所有内容都不是源文件。请解释一下你想要达到的目标;然后我们可以建议正确的方法。

相关问题