[QBS] Using qbs for in-source build

2015-08-04 Thread Orgad Shaneh
Hi,

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
good.


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
regenerated.
   - 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
___
QBS mailing list
QBS@qt-project.org
http://lists.qt-project.org/mailman/listinfo/qbs


Re: [QBS] Using qbs for in-source build

2015-08-05 Thread Joerg Bornemann
On 04-Aug-15 22:14, Orgad Shaneh wrote:

>   * If I delete the output file it is not regenerated (unless I delete
> the build graph, which regenerates all the files)

The timestamps are stored in the build graph for performance reasons 
(esp. for Windows). If you mess around with the contents of the build 
dir you must pass --check-timestamps to qbs.

>   * 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 regenerated.

Probably because the target file path in your output artifact is never 
generated. You said pbuilder will generate files in the source dir.
You could add a rule "html" -> "html-copy" that copies each HTML file 
into the build dir. Then a rule "html-copy" -> "html-cpp" runs pbuilder 
in the build dir where the cpp files will end up.

>   * 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.

You can use a JavaScriptCommand for that in the "html-copy" -> 
"html-cpp" rule.


BR,

Joerg
___
QBS mailing list
QBS@qt-project.org
http://lists.qt-project.org/mailman/listinfo/qbs


Re: [QBS] Using qbs for in-source build

2015-08-05 Thread Christian Kandeler
On 08/05/2015 10:31 AM, Joerg Bornemann wrote:
> On 04-Aug-15 22:14, Orgad Shaneh wrote:
>
>>* If I delete the output file it is not regenerated (unless I delete
>>  the build graph, which regenerates all the files)
>
> The timestamps are stored in the build graph for performance reasons
> (esp. for Windows). If you mess around with the contents of the build
> dir you must pass --check-timestamps to qbs.

But note that this is merely a quick fix for the "I have screwed up" 
case. We do not recommend using it as part of your regular process.

>>* 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 regenerated.
>
> Probably because the target file path in your output artifact is never
> generated. You said pbuilder will generate files in the source dir.
> You could add a rule "html" -> "html-copy" that copies each HTML file
> into the build dir. Then a rule "html-copy" -> "html-cpp" runs pbuilder
> in the build dir where the cpp files will end up.

I think what Orgad meant is that -- much like in the scenario above -- 
he updates the output file outside of qbs. So the same answer would 
apply here.


Christian
___
QBS mailing list
QBS@qt-project.org
http://lists.qt-project.org/mailman/listinfo/qbs