[prev in list] [next in list] [prev in thread] [next in thread] 

List:       boost-build
Subject:    Re: [Boost-build] How to specify build order so I can use
From:       Steve Soule <sts11dbxr () gmail ! com>
Date:       2010-04-24 17:23:53
Message-ID: 4BD32929.5090604 () gmail ! com
[Download RAW message or body]

On 04/23/2010 06:10 PM, Steve Soule wrote:
> 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
>     else
>         mv svn_version_tmp.hpp src/svn_version.hpp
>     fi
> }
> 
> 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?

Well, apparently all I had to do was sleep on it, because I had no
trouble figuring it out this morning.  Sorry for wasting everyone's
time.  In case anyone's interested, here's my solution (greatly simplified):

cur_ver = [ SHELL "echo '\"'`svnversion`'\"'" ] ;
old_ver = [ SHELL "cat src/svn_version.hpp" ] ;
if $(cur_ver) != $(old_ver)
{
    import notfile ;
    notfile write_svn_version : @write_svn_version_action ;
    actions write_svn_version_action
    {
        echo '"'`svnversion`'"' >src/svn_version.hpp
    }
}
else
{
    alias write_svn_version ;
}

obj src/svn_version : src/svn_version.cpp : <dependency>write_svn_version ;

exe vprogram : [ glob src/*.cpp : src/svn_version.cpp ] ;

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost-build
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic