Boost logo

Boost-Build :

Subject: Re: [Boost-build] Understanding generated files / targets.
From: Phillip Seaver (phil_at_[hidden])
Date: 2014-09-18 15:25:39


On 7/28/14 12:18 AM, Tom wrote:
> Steven Watanabe <watanabesj <at> gmail.com> writes:
>
>> On 07/27/2014 12:42 PM, Tom wrote:
>>> I am trying to generate a C++ source (or header) file containing
>>> versioning information generated from 'git describe'. This has become
>>> necessary as we have moved to git and a branched development model and
>>> modifying a version file manually is a non-starter (due to conflicts
>>> on merg) in this development model. We will be driving the version
>>> number in binaries by tags in revision control.
>>>
>>> This is challenging mainly in that the generated file depends on state
>>> not known (or knowable) by Boost.Build as opposed to a normal file
>>> transformation. This results in either not generating the file when
>>> it should be (a tag is checked out or a file is edited which do not
>>> affect the code handling the version number, then the build is run) or
>>> in rebuilding things when it is not actually necessary (which causes
>>> all tests to be re-run for example).
>> If you can use the print module to generate the file,
>> then it automatically checks whether the content has
>> changed. (See b2 --help print for information on
>> how to use it)
> Steven,
>
> That worked really well, I wish I knew that little trick before :)
>
> It took a little while for me to get it right, so I've included a minimal
> Jamroot that shows how it was done for others that might need
> something like this.
>
> Thanks!
> Tom
>
> # Jamroot
> import print ;
>
> explicit generated ;
> exe generated : generated.cpp ;
> explicit generated.cpp ;
> make generated.cpp : : @generate-file ;
> rule generate-file ( target : sources * : properties * )
> {
> print.output $(target) ;
> print.text "int main() { return 0; }
> " : true ;
> }

I'm trying to do something similar. If the file wouldn't change, it
doesn't get updated, right? Does that mean the lib or exe that depends
on it doesn't get recompiled as well? (which is what I would want). Or
does everything get recompiled?

It doesn't work with my older boost-build (~10 months old), so I haven't
been able to test it. It will find an action but not a rule named in
the 'make' options, at least in my experiments. It could be because the
rule is in a file I import (as is the 'make' usage).

If that doesn't work the way I would like (nothing gets rebuilt if the
generated file wouldn't change, is there a way to do that?

Thanks,

Phillip


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