Boost logo

Boost-Build :

Subject: Re: [Boost-build] Automatic version number or build-id
From: Vladimir Prus (vladimir.prus_at_[hidden])
Date: 2015-09-24 03:23:14


On 19-Sep-15 4:15 PM, Niklas Angare wrote:
> Hi,
>
> I'm trying to get Boost.Build to generate a source file at build time containing an automatically generated version
> number or build-id. I have a solution that sort of works. However it causes my exe to be rebuilt every time I invoke b2.
> I would like the source file to be generated only when the exe is built. And of course it needs to be generated every
> time the exe is built. How do I accomplish that?
>
> Are there examples of this having been done before? I would assume so but I haven't been able to find any.

Niklas,

actually, there are not good examples of this, and no full satisfactory solution exists. I attach an somewhat
passable example though.

The requirement, as it seems, is to rebuild BuildTime2.cpp whenever the main application itself is rebuild,
but not in other cases. There is an undocumented and somewhat arcane built-in called REBUILDS, which does that,
but with a number of restrictions:

- It does not operate on meta-target level or target level, but on the lowest level of targets
- It applies only to direct dependencies, so I can make buildtime2.obj be rebuilt whenever main.exe is rebuilt,
   but if I try to do so with builttime2.cpp and main.exe, things won't work - the intermediate obj won't be updated.

So, I have to:

- Declare 'obj' metatarget so that I can access to object file
- Use a 'notfile' metatarget so that I can invoke REBUILDS when we have everything

Note that:

- In my example, I put revision in the comment, since I don't know how to make windows shell produce valid C++
- Also on Windows, exe is ".exe" + ".pdb" so I need to be careful with indices.
- If I explicitly build 'hello', the magic code is not run.

With those caveats, if I touch 'hello.cpp' or 'hello2.cpp', then 'build-id.cpp' is rebuilt too. If I rerun build
without changing anything, nothing is rebuilt.

I attach Jamroot, hello.cpp is just empty main, hello2.cpp is entirely empty. Hope this helps, although it suggests
we need better way to customize build process - maybe a 'post-generate' property that can be used on any metatarget
to run custom code like this.

- Volodya




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