Boost logo

Boost-Build :

Subject: Re: [Boost-build] How to use generators to CPP and LIB
From: Vladimir Prus (ghost_at_[hidden])
Date: 2009-01-30 13:10:57


On Friday 30 January 2009 20:29:06 Alexander Sack wrote:
> On Fri, Jan 30, 2009 at 12:21 PM, Vladimir Prus <ghost_at_[hidden]> wrote:
> > On Friday 30 January 2009 20:19:25 Alexander Sack wrote:
> >> On Fri, Jan 30, 2009 at 11:10 AM, Vladimir Prus <ghost_at_[hidden]> wrote:
> >> > On Thursday 29 January 2009 15:09:33 Duncan Rance wrote:
> >> >> Hi there,
> >> >>
> >> >> I am trying to do something with generators but I'm stuck. I'd really
> >> >> appreciate some help.
> >> >>
> >> >> What I've got so far is, in a module called resources.jam, something
> >> >> like this:
> >> >>
> >> >> type.register RESTXT : txt ;
> >> >> generators.register-standard resources.genenumh : RESTXT : H ;
> >> >> generators.register-standard resources.pkgdata : RESTXT : LIB ;
> >> >>
> >> >> What I need to do is use a .txt file to produce a header file and a
> >> >> static library. The header file is to be used in a few places,
> >> >> including the code used to create the LIB. But there's more to go in
> >> >> the LIB than just the header. If you're interested, I'm using ICU's
> >> >> resource bundling tools
> >> >> (http://www.icu-project.org/userguide/ResourceManagement.html)
> >> >>
> >> >> As you can probably imagine, there is an ambiguity between
> >> >> builtin.lib-generator and resources.pkgdata.
> >> >>
> >> >> How can I do this in boost build?
> >> >
> >> > I don't think there's a way to resolve this ambiguity without introducing
> >> > custom generator class.
> >> >
> >> > I suggest you resolve the ambiguity using generators.override, in
> >> > favour of your new generator. Your generator, however, should
> >> > check if the source type is RESTXT. If so, it should build whatever you
> >> > need. If the source type is different, it should call generators.construct
> >> > for LIB target again, so that builtin generator does his job.
> >> >
> >> > I also recommend using some more specific extension than .txt
> >>
> >> After reading Volodya's email, I just realized is you are trying to
> >> register one generator for two types! Well one work around is the
> >> name the same file with two different extensions which would allow two
> >> different simpler generators no?
> >
> > The generator selection process does not use the types of the *sources*.
>
> Good to know. So how does the generator match then? I would assume
> strictly file name?

generators.construct is asked to create a target of specific type from
source sources. First, generators registered for that type are collected.
Then, for each generator we check if required properties of that generator
are present in build properties. E.g. gcc.link generator has <toolset>gcc
is required properties, so it is discarded if we are building for msvc.
Third, generator overrides, as specified with generator.override function
are processed. At the end, we have one, or several generators. The 'run'
method of every generator is called. If there's exactly one invocation that
returns something, we're done. Otherwise, we report ambiguity.

There's one detail that a generator can only be used once in a chain of
transformations. So, if there's resource-lib generator and builtin.lib
generator who both produce LIB, and resource-lib overrode builtin.lib and
is selected and then calls generators.construct again, with the LIB
target type, then resource-lib generator won't be considered this
time.

> > I think one other approach is to create new type RESOURCE-LIB, derived
> > from LIB, and register a generator creating RESOURCE-LIB. Then, given:
> >
> > resource-lib a : a.txt ;
> >
> > there will be no ambiguity.
>
> Will the generators chain in the correct order though?

Yes. The generators for the base type will be only considered if there are
no generators for the resource-lib type.

> Wow, well that is a very powerful capability of Boost-Build -
> generator inheritance. Volodya, there should be some example of this
> in the Boost documentation cause that is very cool and I believe not
> so uncommon.

I'll try.

- 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