0

My question is simple, I want to manipulate the files stringList of a product from a Rule. I tried to use product.files.push(file), product.files.append(file), but neither solution worked for me.

thank you for your help.

EDIT: I created a module which invoke repc (QtRemoteObjects .rep files compiler), this compiler take as input a .rep file and generate a .h file. I need to include the generated .h file in my project so I can inherit from the types defined in it. here is the module code :

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];
        }
    }
}

this is why I want a way to automatically add this .h generated file to the qbs project.

Houss_gc
  • 727
  • 5
  • 27

1 Answers1

1

You can't, and you shouldn't. The files property contains source files. Everything that rules create is by definition not a source file. Please explain what you are trying to achieve; then we can suggest ways to do it correctly.

  • I still haven't understood why you want the generated file to appear in your files list. You can simply include the (possibly not yet generated) header file in your sources and use it. If you actually intend to add it to your project (i.e. check it into your repository), then you should manually add it to the project file (and remove the .rep file). But I have a suspicion that this is not what you want to do. – Christian Kandeler Jul 13 '17 at 13:15
  • OK, I see so there is no effect on the qtcreator code completion or analysis if the header file don't appear on the project files list. Actually yes I am adding it by hand to check it into the git repository. – Houss_gc Jul 13 '17 at 14:50
  • In your module, set cpp.includePaths to the path where you create the header artifact, and it will work. – Christian Kandeler Jul 14 '17 at 08:31
  • Ok, it will be more correct than copying the file from there to the source directory then having a conflict error. – Houss_gc Jul 14 '17 at 08:45