Boost logo

Boost-Build :

From: Klaus Nowikow (e8827661_at_[hidden])
Date: 2006-07-24 06:30:21

I wrote myself a template-processor ruleset just like the "verbatim"
example in the docs. The difference is that I want to generate, for
example, a *.cpp file from one template file and a *.rc file from another.

What I got so far looks like this and works quite good:

import generators ;
import toolset : flags ;
import feature : feature ;
import type ;

rule init ( )

type.register RCTPL : rc_t ;
type.register CPPTPL : cpp_t ;

generators.register-standard template.rc : RCTPL : RC ;
generators.register-standard template.cpp : CPPTPL : CPP ;

feature substitute : : free ; # e.g. <substitute>foo=bar
flags template.rc SUBSTITUTES <substitute> ;
flags template.rc INCLUDES <include> ;
flags template.cpp SUBSTITUTES <substitute> ;
flags template.cpp INCLUDES <include> ;

rule template.rc ( target : sources * : properties * )
     process-template $(target) : $(sources[1]) ;

rule template.cpp ( target : sources * : properties * )
     process-template $(target) : $(sources[1]) ;

actions process-template
     python -i$(>:W) -o$(<:W) -I"$(INCLUDES:W)" "$(SUBSTITUTES)"

As you can see, I registered two different generators for generating
*.rc and *.cpp files from *.rc_t and *.cpp_t files,
respectively. Both generators just call the actions from
"process-template". (in fact I have more than two generators, but I
shortened the code a bit)

Is there a way to register just one generator for all template processings,
so that I could generate a file "" from "", for
example, without having to create another generator for "bar" templates?

I searched through the sources a bit and found that "rule register" in
generators.jam adds the new generator to a list of generators for the
respective target types ( <code>
for local t in [ sequence.unique [ $(g).target-types ] ]
     .generators.$(t) += $(g) ;
</code>), which is then used to determine the correct generator for a given
source/target type pair. And this implies that the source/target type pair
must be known when register is called.
So I don't think that would be easily doable. Or is it?



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