[Qbs] Dynamic generation of the resource file

Карелин Павел hkarel at yandex.ru
Fri Oct 8 09:45:58 CEST 2021


Hi.

Ivan, only now have "reached the hands" to see your decision. Everything 
turned out, the only thing at first I created two separate rules 
(according to the rule for each group). It looked like a flaw. However, 
then I figured out how to make a universal rule. See comment-section 
"Variant 1" and "Variant 2" in the attached file.

Denis, Ivan, thank you for your help in solving this problem!

BR, Pavel


03.10.2021 13:07, Иван Комиссаров пишет:
> In Qbs, you can set properties for individual files using Group item:
>
> Qt.core.resourceFileBaseName: "trigrams"
> Group {
> fileTagsFilter: [«qrc_input1»] // trigrams-map in your example
>     fileTags: ["qt.core.resource_data»]
> Qt.core.resourcePrefix: «prefix1"
> }
>
> Group {
> fileTagsFilter: [«qrc_input2»]
>     fileTags: ["qt.core.resource_data»]
> Qt.core.resourcePrefix: «prefix2"
> }
>
> Looking into Qt.core code, it supports multiple prefixes like that. 
> Multiple qrc files in one Product are not supported though - this can 
> be implemented, but no one needed this so far.
>
> Ivan
>
>> 2 окт. 2021 г., в 17:01, Карелин Павел <hkarel at yandex.ru 
>> <mailto:hkarel at yandex.ru>> написал(а):
>>
>> Denis, if you can suggest how to generate a second resource file - I 
>> will only be glad.
>>
>> Now I assume that the name of the dynamic resource file depends on 
>> the parameters
>>   Qt.core.resourceFileBaseName: "trigrams"
>>   Qt.core.resourcePrefix: "trigrams"
>>
>> And I don't understand how to specify another file name.
>>
>> --
>> Pavel
>>
>> 02.10.2021 09:17, Denis Shienkov пишет:
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/qbs/attachments/20211008/fdda2801/attachment.html>
-------------- next part --------------
import qbs
import qbs.FileInfo
import QbsUtl
import ProbExt

Product {
    name: "Processing"
    targetName: "fns-processing"
    condition: true

    type: "application"
    destinationDirectory: "./bin"

    Depends { name: "cpp" }
    Depends { name: "lib.sodium" }
    Depends { name: "lib.onnxruntime" }
    Depends { name: "Commands" }
    Depends { name: "PProto" }
    Depends { name: "RapidJson" }
    Depends { name: "SharedLib" }
    Depends { name: "Yaml" }
    Depends { name: "Qt"; submodules: ["core", "network"] }

    Depends { productTypes: ["appl-encryptor"] }

    lib.onnxruntime.version: project.onnxruntimeVersion

    lib.sodium.enabled: project.useSodium
    lib.sodium.version: project.sodiumVersion
    //lib.sodium.dynamicLibraries: project.useSodium ? original : []

    ProbExt.LibValidationProbe {
        id: libValidationProbe
        checkingLibs: [
            lib.sodium
           ,lib.onnxruntime
        ]
    }

    cpp.defines: project.cppDefines
    cpp.cxxFlags: project.cxxFlags
    cpp.cxxLanguageVersion: project.cxxLanguageVersion

    cpp.includePaths: [
        "./",
        "../",
        project.buildDirectory,
    ]

    cpp.systemIncludePaths: QbsUtl.concatPaths(
         Qt.core.cpp.includePaths // Декларация для подавления Qt warning-ов
        ,"/usr/include/python3.8"
        ,lib.sodium.includePath
        ,lib.onnxruntime.includePath
     )

    cpp.rpaths: QbsUtl.concatPaths(
        lib.sodium.libraryPath
       ,lib.onnxruntime.libraryPath
       ,"$ORIGIN/../lib"
    )

    cpp.libraryPaths: QbsUtl.concatPaths(
        lib.sodium.libraryPath
       ,lib.onnxruntime.libraryPath
    )

    cpp.dynamicLibraries: QbsUtl.concatPaths(
        "pthread"
       ,"python3.8"
       ,lib.sodium.dynamicLibraries
       ,lib.onnxruntime.dynamicLibraries
    )

    Group {
          name: "resources"
          files: [
              "processing.qrc",
          ]
    }

    Group {
        name: "encription"
        fileTags: "encription"
        files: FileInfo.joinPaths(project.sourceDirectory, "python/*")
    }
    Group {
        name: "encription2"
        fileTags: "encription2"
        files: "/var/opt/fns-processing/models/test-model.onnx"
    }

    Group {
        fileTagsFilter: ["encript-resource"]
        fileTags: ["qt.core.resource_data"]
        Qt.core.resourcePrefix: "encription"
    }
    Group {
        fileTagsFilter: ["encript-resource2"]
        fileTags: ["qt.core.resource_data"]
        Qt.core.resourcePrefix: "encription2"
    }
    //Qt.core.resourceFileBaseName: "encription"

    files: [
        "processing.cpp",
        "processing_appl.cpp",
        "processing_appl.h",
    ]

//    //--- Variant 1 ---
//    Rule {
//        id: idencript
//        explicitlyDependsOnFromDependencies: ["appl-encryptor"]

//        inputs: ["encription"]

//        Artifact {
//            fileTags: ["encript-resource"]
//            filePath: FileInfo.joinPaths(project.buildDirectory, "encription", input.baseName + ".enc")
//        }
//        prepare: {
//            var runUtl = explicitlyDependsOn["appl-encryptor"][0].filePath;
//            var keyDir = project.buildDirectory;
//            var outputFile = FileInfo.joinPaths(project.buildDirectory, "encription", input.baseName + ".enc");

//            var cmd = new Command(runUtl, [keyDir, input.filePath, outputFile]);
//            cmd.description = "data encription";
//            cmd.highlight = "filegen";
//            return cmd;
//        }
//    }

//    Rule {
//        id: idencript2
//        explicitlyDependsOnFromDependencies: ["appl-encryptor"]

//        inputs: ["encription2"]

//        Artifact {
//            fileTags: ["encript-resource2"]
//            filePath: FileInfo.joinPaths(project.buildDirectory, "encription", input.baseName + ".enc")
//        }
//        prepare: {
//            var runUtl = explicitlyDependsOn["appl-encryptor"][0].filePath;
//            var keyDir = project.buildDirectory;
//            var outputFile = FileInfo.joinPaths(project.buildDirectory, "encription", input.baseName + ".enc");

//            var cmd = new Command(runUtl, [keyDir, input.filePath, outputFile]);
//            cmd.description = "data encription";
//            cmd.highlight = "filegen";
//            return cmd;
//        }
//    }

    //--- Variant 2 ---
    Rule {
        explicitlyDependsOnFromDependencies: ["appl-encryptor"]

        inputs: ["encription", "encription2"]
        outputFileTags: ["encript-resource", "encript-resource2"]
        outputArtifacts: {
            if (input.fileTags.contains("encription")) {
                return [{
                    fileTags: ["encript-resource"],
                    filePath: FileInfo.joinPaths(project.buildDirectory, "encription", input.baseName + ".enc")
                }];
            }
            else {
                return [{
                    fileTags: ["encript-resource2"],
                    filePath: FileInfo.joinPaths(project.buildDirectory, "encription", input.baseName + ".enc")
                }];
            }
        }

        prepare: {
            var runUtl = explicitlyDependsOn["appl-encryptor"][0].filePath;
            var keyDir = project.buildDirectory;
            var outputFile = FileInfo.joinPaths(project.buildDirectory, "encription", input.baseName + ".enc");

            var cmd = new Command(runUtl, [keyDir, input.filePath, outputFile]);
            cmd.description = "data encription";
            cmd.highlight = "filegen";
            return cmd;
        }
     }

//    property var test: {
//        console.info("=== cpp.dynamicLibraries ===");
//        console.info(cpp.dynamicLibraries);
//    }

}


More information about the Qbs mailing list