[Qbs] Writing a custom script by QBS

Christian Kandeler christian.kandeler at qt.io
Thu Oct 19 10:19:47 CEST 2017


On Thu, 19 Oct 2017 03:04:15 +0800
Ben Lau <xbenlau at gmail.com> wrote:

> I am still new to QBS. I am looking for a suggestion about how to write and
> run a custom script by QBS.
> 
> Besides building the binary, developers may need additional custom scripts
> for deployment, code analysis, starting a mock server for testing etc. This
> kind of task may not have a file output locally.
> 
> Can I write this kind of script by QBS?  I usually write this kind of
> script as a shell script, but it is not a cross-platform solution which
> does not work with Windows.

You should be able to use the normal mechanisms that are also used for building. Here's a sketch for for remote deployment (untested):

Product {
    name: "remote deployer"

    type: ["mydeploytarget"]

    // You typically don't want to do uploads after every build, so this product's rules are not
    // executed unless you specifically request it.
    builtByDefault: false

    // Assuming you want to upload e.g. some tar archive you've created from your build.
    Depends { name: "mypackage" }

    // These as well as the rule below would typically be moved into a dedicated module
    // for better re-usability, but it's easier to demonstrate with a self-contained
    // product.
    property string remoteUser
    property string serverName
    property string targetDir

    Rule {
        // The target type(s) of your dependency/dependencies.
        inputsFromDependencies: ["archiver.archive"] 

        Artifact {
            // Just a dummy. Does not have to get created. We should probably 
            // have syntactic sugar for this.
            filePath: "deploydummy"

            fileTags: ["mydeploytarget"]
        }

        prepare: {
            var targetString = product.remoteUser + '@' + product.serverName + '/' + product.targetDir;
            var cmd = new Command("scp", [input.filePath, targetString]);
            cmd.description = "uploading " + input.fileName;
            return [cmd];
        }
    }
}

Now this should upload your archive (possibly rebuilding if necessary):
$ qbs -p "remote deployer"


Christian



More information about the Qbs mailing list