2
votes

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.

2

2 Answers

0
votes
  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).
0
votes

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.