Boost logo

Boost-Build :

Subject: [Boost-build] How to stop dependency propagation on unmodified generated targets
From: Pavel Machyniak (machyniak_at_[hidden])
Date: 2012-05-16 09:55:10


Hi,

On each build I need to generate some output from the tool that has to
be run always (getting SVN revision of the project and embedding it in
product version). Output from this tool is not written, if it already
exists and is the same. This way dependent files do not have to be rebuild.

Simple scenario - lets generate header file with minutes of current time:

### jamfile.jam ###
always gen.h ;
make gen.h : : @make-h ;
actions make-h
{
    gen.py "$(<)"
}

---
### gen.py ###
import sys
from datetime import datetime
# write output file if differs
def writeIfChanged( file, content ):
    try:
        with open( file, 'r' ) as f:
            old = f.read()
    except IOError:
        old = ""
    if content != old:
        print( 'writing ' + file )
        with open( file, 'w' ) as f:
            f.write( content )
    return
writeIfChanged( sys.argv[1], '#define AAA ' + str(datetime.now().minute) )
---
Now I need to build target that is dependent on the generated target.
### jamfile.jam cont. ###
exe test : test.cpp : <implicit-dependency>gen.h ;
### test.cpp ###
#include "gen.h"
int main( int, char ** ) { return AAA; }
---
However this target is always rebuilt, because it is dependent on ALWAYS
generated target, even if the generated output does not change. Can this
be avoided?
Thanks,
Pavel Machyniak

Boost-Build list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk