[Qbs] Problem getting build order right when I use a header generator

Jochen Becher jochen_becher at gmx.de
Sat Jul 9 22:56:15 CEST 2022


Hi,

I have the following problem where I could not find a solution myself:

I created a new module which uses a code generator "compiler-generator"
that I wrote to create header and source files from input files. I used
the lexyacc module as a template. (see end of mail for module source)

I use that module in a product that creates a static library, like
that:

    StaticLibrary {
        name: "corelib"

        Export {
            Depends { name: "cpp" }
            cpp.includePaths: ["src", exportingProduct.buildDirectory]
        }

        Depends { name: "compgen" }
        Depends { name: "compiler-generator" }

        cpp.includePaths: [ "src", product.buildDirectory ]

        Group {
            name: "frontend-header-generator"
            fileTags: "compgen.input"
            compgen.outputTag: "hpp"
            files: [
                "src/frontend/tokens.h.in",
            ]
        }

        Group {
            name: "frontend-source-generator"
            fileTags: "compgen.input"
            compgen.outputTag: "c"
            files: [
                "src/frontend/lexer.c.in",
            ]
        }

        Group {
            name: "frontend"
            files: [
                "src/frontend/lexer.h",
                "src/frontend/parser.c",
                "src/frontend/parser.h",
            ]
        }

Building that library works fine.

But some other tools also want to use the created header file
"tokens.h". These applications (e.g., "compiler") depends on "corelib".

But the application source is compiled before the header file
"tokens.h" is generated from "tokens.h.in" and so it is missing.

What is the best way to enforce that the dependency on corelib from an
application first builds the library corelib with the generated header
and source files and THEN builds the dependend source files?

Regards, Jochen


--- the generator module "compgen.qbs" ---

import qbs
import qbs.FileInfo

Module {

    Depends { name: "cpp" }

    property string outputTag: "c"
    readonly property string outputDir: product.buildDirectory

    Rule {
        inputs: [ "compgen.input" ]
        outputFileTags: [ product.compgen.outputTag ]
        explicitlyDependsOnFromDependencies: [ "compiler-generator" ]

        Artifact {
            filePath: input.completeBaseName
            fileTags: [ product.compgen.outputTag ]
            cpp.includePaths: [].concat(input.cpp.includePaths,
FileInfo.path(input.filePath), input.compgen.outputDir)
        }

        prepare: {
            var command = explicitlyDependsOn["compiler-
generator"][0].filePath
            var arguments = [
                        "-o", output.filePath,
                        input.filePath
                    ]
            var cmd = new Command(command, arguments)
            cmd.description = "generating " + output.filePath + " from
" + input.filePath
            cmd.highlight = "codegen"
            return [ cmd ]
        }
    }
}



More information about the Qbs mailing list