I am creating files in a Task, the example code looks as follows:
from waflib import Task, TaskGen
def build(bld):
bld(features='write_file')
class xyz(Task.Task):
def run(self):
self.generator.path.get_bld().make_node(self.outputs[0].relpath())
@TaskGen.feature('write_file')
def make_tasks(self):
for x in range(20):
src = bld.path.find_node('wscript')
tgt = src.change_ext('.'+str(x))
tsk = self.create_task('xyz', src=src, tgt=tgt)
Now all files get placed inside the build
directory, but I want them to be placed in build\abc
. How do I do that? For normal builds, I can use a BuildContext
and specify a variant
:
from waflib.Build import BuildContext
class abc(BuildContext):
variant = 'abc'
But I can't get the BuildContext
working on that example, and setting variant
on a Task.Task
does not work.
Update
I update the example based on neuros answer:
A minimal working example with this code looks like this:
from waflib import Task, TaskGen, Configure
Configure.autoconfig = True
def configure(cnf):
cnf.path.get_src().make_node('a/wscript').write('')
def build(bld):
bld(features='write_file')
class xyz(Task.Task):
def run(self):
self.generator.path.get_bld().find_or_declare(self.outputs[0].abspath()).write('')
@TaskGen.feature('write_file')
def make_tasks(self):
srcs = bld.path.ant_glob('**/wscript', excl='build')
for src in srcs:
build_dir_of_src = src.get_bld().parent
my_sub_node = build_dir_of_src.make_node('xyz')
my_sub_node.mkdir()
tgt_basename = src.name
tgt = my_sub_node.make_node(tgt_basename)
tsk = self.create_task('xyz', src=src, tgt=tgt)
The problem is that this creates the following:
build\xyz\wscript
build\a\xyz\wscript
But I want this:
build\xyz\wscript
build\xyz\a\wscript
So I just to create the folder xyz
between build
and what ever the tgt is. So exactly the behavior of variant
in a BuildContext
.