Hello, Ioan.

20.09.2016 12:35, Ioan Calin Borcoman пишет:
Adding to both the module and the project using it:

   Depends { name: "Qt"; submodules: ["core", "network"]}

didn't solve the problem, unfortunately.

I have reported this as https://bugreports.qt.io/browse/QBS-1021.

Regarding your suggestion b), how can I do it? I haven't seen any qbs
examples returning multiple executables for the same rule. Also, from
what I understand, the "wsdl_foo.h" should be tagged as "hpp", while
the "wsdl_foo.cpp" as "cpp". Is my understanding correct? Can I do
this using a single rule? How?
I also had a similar problem on generation the soap- cpp/h files. I managed to solve this problem. I have attached an example of his QBS-module. Perhaps he will prompt you how to solve the problem.

Thank you,

Ioan

On Tue, Sep 20, 2016 at 3:51 AM, Christian Kandeler
<christian.kande...@qt.io> wrote:
Ioan Calin Borcoman <ibo...@gmail.com> wrote:

I'm trying to write a module that generates wsdl_foo.h and
wsdl_foo.cpp from foo.wsdl, using KDSoap's kdwsdl2cpp
(https://github.com/KDAB/KDSoap).

After it is generated, the wsdl_foo.h should be parsed by moc, as it
contains an QObject based class.
The problem is that moc is sometimes called and sometimes isn't. If I
delete the build tree and try to run qbs from scratch, the moc is not
run and the build fails.

But if I touch my kdsoap.qbs module, even if I don't change anything
in it, and then run again qbs, the moc is run and my project builds.
Two observations:
a) Your module does not have a Qt dependency. Does your product have one?
b) (Probably unrelated to your problem) It is confusing (though not technically 
wrong) that you declare two rules. You should have only one rule that creates 
two commands.

If your answer to a) is "yes", then please file a bug at bugreports.qt.io and 
attach a complete (i.e. including source files), but minimal project.


Christian
_______________________________________________
QBS mailing list
QBS@qt-project.org
http://lists.qt-project.org/mailman/listinfo/qbs
_______________________________________________
QBS mailing list
QBS@qt-project.org
http://lists.qt-project.org/mailman/listinfo/qbs

--
Best regards,
Pavel Karelin.

import qbs
import qbs.File
import qbs.TextFile
import qbs.ModUtils


Module {
    id: gsoap
    condition: true

    Depends { name: "cpp" }

    property string namespace: undefined
    property string modulePath: ""
    property string importPath: ""
    property string soapcpp2: ""
    property bool   debug: false

    property string generatedFilesDir: {
        return product.buildDirectory + "/." + (namespace === undefined ? "soap" : namespace);
    }

    property string includePaths: {
        return generatedFilesDir;
    }

    PropertyOptions {
        name: "namespace"
        description: "Определяет имя пространства имен для функций soap-движка."
    }
    PropertyOptions {
        name: "modulePath"
        description: "Директория расположения файлов stdsoap2.h, stdsoap2.cpp"
    }
    PropertyOptions {
        name: "importPath"
        description: "Директория расположения файлов импорта gsoap"
    }
    PropertyOptions {
        name: "soapcpp2"
        description: "Утилита soapcpp2"
    }
    PropertyOptions {
        name: "debug"
        description: "Сборка в режиме отладки"
    }
    PropertyOptions {
        name: "generatedFilesDir"
        description: "Директория размещения сгенерированных файлов, так же \
                      в эту директорию копируются файлы stdsoap2.h, stdsoap2.cpp"
    }

    cpp.defines: {
        var def = [
            "WITH_COOKIES",
            "WITH_GZIP",
            "WITH_OPENSSL",
        ];

        if (debug === true)
            def.push("SOAP_DEBUG");

        return def;
    }

    cpp.includePaths: {
        return this.includePaths;
    }

    validate: {
        var validator = new ModUtils.PropertyValidator("gsoap");
        //validator.setRequiredProperty("namespace", namespace);
        validator.setRequiredProperty("modulePath", modulePath);
        validator.setRequiredProperty("importPath", importPath);
        validator.setRequiredProperty("soapcpp2", soapcpp2);
        validator.validate();

        if (!File.exists(modulePath + "/stdsoap2.h"))
            throw "Base soap-header file not found: " + modulePath + "/stdsoap2.h";

        if (!File.exists(modulePath + "/stdsoap2.cpp"))
            throw "Base soap-source file not found: " + modulePath + "/stdsoap2.cpp";
    }

     //FileTagger {
     //    patterns: ["*.wsdl"]
     //    fileTags: ["wsdl"]
     //}

    FileTagger {
        patterns: "*.soap.h"
        fileTags: ["soap"]
    }

    Rule {
        inputs: ["soap"]
        outputFileTags: ["cpp", "hpp"]
        outputArtifacts: {
            var generatedFilesDir = ModUtils.moduleProperty(product, "generatedFilesDir");
            var namespace = ModUtils.moduleProperty(product, "namespace");
            if (namespace === undefined)
                namespace = "soap";

            var cxxFlags = [
                //"-Wno-unused-function",
                //"-Wno-unused-but-set-variable",
                //"-Wno-unused-parameter",
                //"-Wno-sequence-point",
                //"-Wno-literal-suffix",
                //"-Wno-sizeof-pointer-memaccess",
                "-w",
            ]

            var result = [
                {
                    filePath: generatedFilesDir + "/stdsoap2.h",
                    fileTags: ["hpp"],
                    cpp: {
                        cxxFlags: cxxFlags
                    }
                },{
                    filePath: generatedFilesDir + "/stdsoap2.cpp",
                    fileTags: ["cpp"],
                    cpp: {
                        cxxFlags: cxxFlags
                    }
                },{
                    filePath: generatedFilesDir + "/" + namespace + "C.cpp",
                    fileTags: ["cpp"],
                    cpp: {
                        cxxFlags: cxxFlags
                    }
//                },{
//                    filePath: generatedFilesDir + "/" + namespace + "Client.cpp",
//                    fileTags: ["cpp"],
//                    cpp: {
//                        cxxFlags: cxxFlags
//                    }
                },{
                    filePath: generatedFilesDir + "/" + namespace + "Server.cpp",
                    fileTags: ["cpp"],
                    cpp: {
                        cxxFlags: cxxFlags
                    }
                },{
                    filePath: generatedFilesDir + "/" + namespace + "H.h",
                    fileTags: ["hpp"],
                    cpp: {
                        cxxFlags: cxxFlags
                    }
                },{
                    filePath: generatedFilesDir + "/" + namespace + "Stub.h",
                    fileTags: ["hpp"],
                    cpp: {
                        cxxFlags: cxxFlags
                    }
                }
            ];

            return result;
        }

        prepare: {
            var commands = [];

            var cmd = new JavaScriptCommand();
            cmd.silent = true;
            cmd.sourceCode = function() {
                var generatedFilesDir = ModUtils.moduleProperty(product, "generatedFilesDir");
                var modulePath = ModUtils.moduleProperty(product, "modulePath");

                if (!File.exists(generatedFilesDir + "/stdsoap2.h"))
                    File.copy(modulePath + "/stdsoap2.h", generatedFilesDir + "/stdsoap2.h");

                if (!File.exists(generatedFilesDir + "/stdsoap2.cpp"))
                    File.copy(modulePath + "/stdsoap2.cpp", generatedFilesDir + "/stdsoap2.cpp");
            }
            commands.push(cmd);

            var namespace = ModUtils.moduleProperty(product, "namespace");
            var importPath = ModUtils.moduleProperty(product, "importPath");
            var generatedFilesDir = ModUtils.moduleProperty(product, "generatedFilesDir");

            //'/opt/gsoap/2.7.12/bin/soapcpp2 -x -L -S  -I xmlapi/import -d xmlapi xmlapi/api3.h'
            //var args = ["-C", "-w", "-x", "-n", "-L"];
            var args = ["-x", "-L"];

            if (namespace !== undefined) {
                args.push("-q");
                args.push(namespace);
            }

            args.push("-I");
            args.push(importPath);

            args.push("-d");
            args.push(generatedFilesDir);

            //args.push(product.sourceDirectory + "/" + "hybrid-api.soap.h")
            args.push(input.filePath);

            var soapcpp2 = ModUtils.moduleProperty(product, "soapcpp2");
            cmd = new Command(soapcpp2, args);

            cmd.description = "soap generation: ";
            cmd.highlight = "codegen";
            commands.push(cmd);

            if (namespace !== undefined) {
                cmd = new JavaScriptCommand();
                cmd.silent = true;
                // ??? cmd.sourceFileName = outputs["c"][0].filePath;
                // ??? cmd.headerFileName = outputs["hpp"] ? outputs["hpp"][0].filePath : "";
                cmd.sourceCode = function() {
                    var namespace = ModUtils.moduleProperty(product, "namespace");
                    var generatedFilesDir = ModUtils.moduleProperty(product, "generatedFilesDir");

                    var file = new TextFile(generatedFilesDir + "/" + namespace + ".nsmap", TextFile.ReadOnly);
                    var text = file.readAll();
                    file.close();

                    text = text.replace(/struct\s+Namespace/, "struct " + namespace + "::Namespace");

                    var file = new TextFile(generatedFilesDir + "/" + namespace + ".nsmap.h", TextFile.WriteOnly);
                    file.write(text);
                    file.close();
                };
                commands.push(cmd);
            }

            return commands;
        }
    }

} // Module
_______________________________________________
QBS mailing list
QBS@qt-project.org
http://lists.qt-project.org/mailman/listinfo/qbs

Reply via email to