added Build.func to allow creating task generator using the decorator notation

Signed-off-by: Thomas Nagy <tnagy2pow10@gmail.com>
This commit is contained in:
Anthony Baire 2012-09-13 16:01:58 +02:00 committed by Thomas Nagy
parent 7895f84852
commit c5bc3197f0
1 changed files with 26 additions and 0 deletions

View File

@ -152,6 +152,32 @@ class BuildContext(Context.Context):
self.task_gen_cache_names = {} # reset the cache, each time
self.add_to_group(ret, group=kw.get('group', None))
return ret
def func(self, *k, **kw):
"""
Wrapper for creating a task generator using the decorator notation.
The the following code:
@bld.func(
target = "foo"
)
def _(tsk):
print "bar"
is equivalent to:
def bar(tsk):
print "bar"
bld(
target = "foo",
rule = bar,
)
"""
return lambda rule: self (*k, rule=rule, **kw)
def __copy__(self):
"""Implemented to prevents copies of build contexts (raises an exception)"""