Boost logo

Boost-Build :

Subject: [Boost-build] How to specify build order so I can use svnversion?
From: Steve Soule (sts11dbxr_at_[hidden])
Date: 2010-04-23 20:10:39

I'm working on a project where the svn version number of my source code
needs to be embedded in the executable (so that it can be viewed by the
user). The "svnversion" command produces this svn version number. I
need to put the output of svnversion in a source file that is compiled
into the executable.

I need to figure out how to make Boost Build do this correctly. The svn
version number doesn't change very often--perhaps one in one hundred
builds. So most of the time, the Jam code for including the svn version
should not result in rebuilding anything.

I've spent all day trying to figure this out. The best I've come up
with so far is the following Jamroot.jam (greatly simplified):

exe vprogram : [ glob src/*.cpp ] ;
import notfile ;
notfile write_svn_version : @write_svn_version_action ;
actions write_svn_version_action
    echo '"'`svnversion`'"' >svn_version_tmp.hpp
    if diff -N svn_version_tmp.hpp src/svn_version.hpp >/dev/null; then
        rm svn_version_tmp.hpp
        mv svn_version_tmp.hpp src/svn_version.hpp

Effectively, this makes bjam check the output of svnversion; if the
output has changed, it replaces the file src/svn_version.hpp with the
new version.

This works fine except for one problem: the write_svn_version target is
built after the vprogram target, so the executable is built using the
svn version from the last build rather than this build. All I have to
do is remember to run bjam twice, and the result is correct, and
practically no unnecessary rebuilding takes place.

However, I might forget to execute bjam twice, so I would really like to
know how to make bjam build the write_svn_version target before the
vprogram target.

I've spent all day working on this, and I've tried dozens of different
things. Most of the things I've tried have resulted in creating a
dependency between vprogram and write_svn_version. Because the
write_svn_version target is always out-of-date, if any target depends on
it, that target is always rebuilt. In many of my attempts, every source
file in vprogram is rebuilt, even though nothing needs to be. I don't
think it makes sense for vprogram to depend on write_svn_version.

It seems like the solution should be simple. There should be an easy
way to tell Boost Build to build write_svn_version before vprogram
(without creating a dependency). But I haven't been able to find
anything in the documentation. I'm stumped.

What is the solution?

Boost-Build list run by bdawes at, david.abrahams at, gregod at, cpdaniel at, john at