From 244ebce5781d3b775c6087f999f42e89784b2643 Mon Sep 17 00:00:00 2001 From: Vladimir Prus Date: Sat, 25 Nov 2006 18:48:12 +0000 Subject: [PATCH] New example [SVN r36176] --- v2/example/generator/Jamroot | 3 ++ v2/example/generator/README.txt | 4 ++ v2/example/generator/foo.gci | 5 +++ v2/example/generator/soap.jam | 73 +++++++++++++++++++++++++++++++++ 4 files changed, 85 insertions(+) create mode 100644 v2/example/generator/Jamroot create mode 100644 v2/example/generator/README.txt create mode 100644 v2/example/generator/foo.gci create mode 100644 v2/example/generator/soap.jam diff --git a/v2/example/generator/Jamroot b/v2/example/generator/Jamroot new file mode 100644 index 000000000..a67e24ca0 --- /dev/null +++ b/v2/example/generator/Jamroot @@ -0,0 +1,3 @@ + +import soap ; +exe foo : foo.gci : on ; \ No newline at end of file diff --git a/v2/example/generator/README.txt b/v2/example/generator/README.txt new file mode 100644 index 000000000..340b9a7bd --- /dev/null +++ b/v2/example/generator/README.txt @@ -0,0 +1,4 @@ + +This example shows how to declare a new generator class. It's necessary +when generator's logic is more complex that just running a single tool. + diff --git a/v2/example/generator/foo.gci b/v2/example/generator/foo.gci new file mode 100644 index 000000000..7d5f90dff --- /dev/null +++ b/v2/example/generator/foo.gci @@ -0,0 +1,5 @@ + +int main() +{ + return 0; +} \ No newline at end of file diff --git a/v2/example/generator/soap.jam b/v2/example/generator/soap.jam new file mode 100644 index 000000000..169a9a9da --- /dev/null +++ b/v2/example/generator/soap.jam @@ -0,0 +1,73 @@ + +# This is example of a fictional code generator tool. +# It accepts a single input of type '.gci' and produces +# either one or two outputs of type .cpp, depending +# on the value of the feature +# +# This example is loosely based on gSOAP code generator. + +import type ; +import generators ; +import feature ; +import common ; +import "class" : new ; + +type.register GCI : gci ; + +feature.feature server : off on : incidental ; + +class soap-generator : generator +{ + import "class" : new ; + + rule __init__ ( * : * ) + { + generator.__init__ $(1) : $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ; + } + + rule run ( project name ? : property-set : sources * ) + { + if ! $(sources[2]) + { + # Accept only single source. + local t = [ $(sources[1]).type ] ; + if $(t) = GCI + { + # The type is correct. + + # If no output name is specified, guess it from sources. + if ! $(name) + { + name = [ generator.determine-output-name $(sources) ] ; + } + + # Produce one output, using just copy. + local a = [ new action $(sources[1]) + : common.copy : $(property-set) ] ; + local t = [ new file-target $(name) : CPP : $(project) + : $(a) ] ; + + # If in server mode, create another output -- an + # empty file. If this were a real SOAP generator, we + # might have created a single action, and two targets + # both using that action. + local t2 ; + if [ $(property-set).get ] = "on" + { + local a = [ new action : soap.touch : $(property-set) ] ; + t2 = [ new file-target $(name)_server : CPP : $(project) + : $(a) ] ; + } + return $(t) $(t2) ; + } + } + } +} + +generators.register [ new soap-generator soap.soap : GCI : CPP ] ; + +TOUCH = [ common.file-touch-command ] ; +actions touch +{ + $(TOUCH) $(<) +}