[QBS] Using qbs for in-source build

Orgad Shaneh orgads at gmail.com
Tue Aug 4 22:14:54 CEST 2015


I have a code generator that transforms html (and html-related files like
css) to cpp.

The source files are located in some nested directory tree, and the
generator is in its top level (named pbuilder).

The code generator produces its artifacts in the source directory. I can't
control it (it's a closed binary executable).

I'd like to compare timestamps of the input and output file, and generate
iff the input is newer.

This is what I have so far:

import qbs 1.0

import qbs.FileInfo

Product {

    type: "html-cpp"

    Group {

        name: "Input Files"

        files: "**/*.htm*"

        fileTags: ["html"]


    Rule {

        inputs: ["html"]

        Artifact {

            fileTags: ["html-cpp"]

            filePath: FileInfo.path(input.filePath) + '/' +
FileInfo.baseName(input.filePath) + ".cpp"


        prepare: {

            var pbuilderPath = project.path + "/pbuilder";

            var cmd = new Command(pbuilderPath, input.filePath);

            cmd.description = 'pbuilding ' + input.fileName;

            cmd.highlight = 'compiler';

            return cmd;




When I execute it for the first time, it generates all the files.
Later, as long as I don't modify the qbs file or delete the build
graph, only source files that were modified are regenerated, which is

The problems I'm facing are:

   - If I delete the output file it is not regenerated (unless I
delete the build graph, which regenerates all the files)
   - If the source file is modified, but the target file has a newer
date (e.g. pbuilder was invoked from the shell), it is still
   - On the first run, I'd like to avoid regenerating up-to-date
targets. I can live with that though.
   - In my example, I simplified the generator's output. The generator
actually produces 2 files: input.c and input_v.cpp. After it finishes,
I need to rename input.c -> input.cpp (overwriting the existing one),
and delete input_v.cpp.

I'm currently using a rather ugly Makefile for this, which works quite
well, but is hard to maintain.

How can this be done correctly?

- Orgad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/qbs/attachments/20150804/2be14279/attachment.html>

More information about the Qbs mailing list