Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can a Qbs build Rule use a product

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?

like image 717
Johannes Matokic Avatar asked Mar 23 '23 12:03

Johannes Matokic


1 Answers

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;
        }
    }
}
like image 77
Johannes Matokic Avatar answered Apr 26 '23 21:04

Johannes Matokic