List Info

Thread: template processing ruleset for generating variable file types




template processing ruleset for generating variable file types
user name
2006-07-24 10: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:

<code>
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 template.py -i$(>:W) -o$(<:W)
-I"$(INCLUDES:W)" "$(SUBSTITUTES)"
}
</code>

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 "foo.bar" from
"foo.bar.template", 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?

Regards,

Klaus

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost-build
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )