Question

I want to use Qbs to compile an existing project. This project already contains a code-transformation-tool (my_tool) that is used heavily in this project.

So far I have (simplified):

import qbs 1.0

Project {
    Application {
        name: "my_tool"
        files: "my_tool/main.cpp"
        Depends { name: "cpp" }
    }

    Application {
        name: "my_app"
        Group {
            files: 'main.cpp.in'
            fileTags: ['cpp_in']
        }
        Depends { name: "cpp" }

        Rule {
            inputs: ["cpp_in"]
            Artifact {
                fileName: input.baseName
                fileTags: "cpp"
            }
            prepare: {

                var mytool = /* Reference to my_tool */;

                var cmd = new Command(mytool, input.fileName, output.fileName);
                cmd.description = "Generate\t" + input.baseName;
                cmd.highlight = "codegen";
                return cmd;
            }
        }
    }
}

How can I get the reference to my_tool for the command?

Was it helpful?

Solution

This answer is based on an email from Qbs author Joerg Bornemann who allowed me to cite it here.

The property usings of Rule allows to add artifacts from products dependencies to the inputs. In this case we are interested in "application" artifacts.

The list of applications could then be accessed as input.application.

Application {
    name: "my_app"
    Group {
        files: 'main.cpp.in'
        fileTags: ['cpp_in']
    }
    Depends { name: "cpp" }

    // we need this dependency to make sure that my_tool exists before building my_app
    Depends { name: "my_tool" }

    Rule {
        inputs: ["cpp_in"]
        usings: ["application"] // dependent "application" products appear in inputs
        Artifact {
            fileName: input.completeBaseName
            fileTags: "cpp"
        }
        prepare: {
            // inputs["application"] is a list of "application" products
            var mytool = inputs["application"][0].fileName;
            var cmd = new Command(mytool, [inputs["cpp_in"][0].fileName, output.fileName]);
            cmd.description = "Generate\t" + input.baseName;
            cmd.highlight = "codegen";
            return cmd;
        }
    }
}

OTHER TIPS

Unfortunately the usings property in a Rule is deprecated since QBS 1.5.0. At the moment I have the same requirement. Using a product artifact in a non multiplex Rule.

The problem with a multiplex Rule is, if a single file in the input set changes, all input artifacts will be re-processed. Which is rather time consuming in my case.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top