2

I want to make a module to use the QtRO repc compiler to produce .h files from .rep files.

I coded the module but when I try to load it in an application product it does not load and disable the product.

the modules are in C:\Users\User\qt\qbs

Qbs Module replica.qbs:

import qbs

Module {
    property bool source: true
    FileTagger {
        patterns: "*.rep"
        fileTags: ["rep"]
    }
    Rule {
       inputs: ["rep"]
       Artifact {
           fileTags: ["txt_output"]
       }
       prepare: {
           var cmd = new Command();
           cmd.program = "repc.exe";
           if source {
               cmd.arguments = ["-i", "rep", "-o", "source", input.filePath];
           } else {
               cmd.arguments = ["-i", "rep", "-o", "replica", input.filePath];
           }
           console.log("repc on : ", input.filePath);
           return [cmd];
       }
    }
}

product.qbs:

import qbs

Application {
    name: "ServiceExposer"
    Depends { name: "cpp" }
    Depends { name: "Qt.core" }
    Depends { name: "Qt.remoteobjects" }
    Depends { name: "replica" }
    files: [
        "main.cpp",
        "service_exposer.rep"
    ]
}

project.qbs:

import qbs

Project {
    references: ["ServiceExposer/ServiceExposer.qbs"]
    qbsSearchPaths: "C:\Users\User\qt\qbs"
}

I don't see where I made the mistake.

Thank you in advance for your help.

Houss_gc
  • 727
  • 5
  • 27

2 Answers2

0

I managed to make it work after digging a little more in the doc and source code, I share with you the working module.

This module when imported if there are any .rep files (QtRO (remote objects)) module remote object definition) in your project, it will invoke the repc compiler and compile them and put the resulting .h file in your source directory.

Still not complete, I didn't find a way to manipulate the files property of the Product Item to add the .h to it automatically.

import qbs
import qbs.FileInfo

Module {
    FileTagger {
        patterns: ["*.rep"]
        fileTags: ["repc-rep"]
    }
    Rule {
        inputs: ["repc-rep"]
        Artifact {
            filePath: repc_" + FileInfo.baseName(input.fileName) + "_source.h"
            fileTags: ["cpp"]
        }
        prepare: {
            var cmd = new Command();
            cmd.description = "repc " + input.fileName;
            cmd.program = "repc.exe"
            cmd.arguments = ["-i", "rep", "-o", "source", 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];
        }
    }
}

In order to this module to work, the repc.exe must be in your path.

Any suggestion are welcomed.

Houss_gc
  • 727
  • 5
  • 27
0
  1. If it's a header file, why do you give it the "cpp" tag? Shouldn't it be "hpp"?
  2. What is the reason you are putting the file into the source directory? Do you plan on adding it to your repository? Normally, build artifacts (no matter whether they are binaries or human-readable files) should be located inside the build directory as not to "pollute" the source tree.
  3. You did not mention in what way the module does not work for you now, so it's hard to diagnose the problem. You should mention what you expected to happen and what happened instead (giving the concrete error message, if there is one).
  • @Chritian Kandeler - I'didn't know that an hpp tag exist, I put inside the source directory so I can reference it form other classes. The working version is in my answer to this same post. When it didn't work qtcreator just disable the project and don't tell me what was wrong in my module. – Houss_gc Jul 13 '17 at 07:51
  • @Chritian Kandeler - I didn't want to put this in a new post, what is a multiplex rule ? what does it mean ? and what does mean when the qbs tell you that there is conflict in rules and rule is not multiplex. – Houss_gc Jul 13 '17 at 18:38
  • I did fix it, it was that the moc is finding to files with the .h extension which are the same (one generated by repc in the build directory and the one I am copying in the source directory), I had to modify my module to remove the one in the build directory. – Houss_gc Jul 14 '17 at 08:43