Re: matching source and target's behavior between func and cmd actions
Gary Granger <[email protected]>
| Newsgroups | gmane.comp.programming.tools.scons.user |
|---|---|
| Message-ID | <[email protected]> |
I think you have a couple options. You can use the abspath
method of node objects to get the equivalent of $SOURCES.abspath,
or you can use the cmdstr keyword parameter when creating the
Action object for the Builder. The Builder constructor implicitly
creates an Action object from it's arguments, but you can replace
that with an explicit Action object with a custom cmdstr. The
example below shows both:
def task(source, target, env):
print('S1: %s T1: %s' % (" ".join([s.abspath for s in source]), target[0].abspath))
bld = Builder(action = '@echo S: $SOURCES.abspath T: $TARGET.abspath')
bld1 = Builder(action = Action(task, cmdstr="S1: $SOURCES.abspath T1: $TARGET.abspath"))
env = Environment(BUILDERS = {'Foo' : bld, 'Foo1' : bld1})
env.Foo('a/vb/c/aaa',['/dev/null','v','b'])
env.Foo1('a/vb/c/aaa1',['/dev/null','v','b'])
I tried using this in the task() function:
print(env.subst("S1: $SOURCES.abspath T1: $TARGET.abspath"))
...but of course SOURCES and TARGET variables do not exist in env
at that point, so that doesn't work. I think I've wished more
than once that it did. So the only options I know about are the
ones above, and they produce this output:
scons -C /tmp/test .
scons: Entering directory `/tmp/test'
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
S: /dev/null /tmp/test/v /tmp/test/b T: /tmp/test/a/vb/c/aaa
S1: /dev/null /tmp/test/v /tmp/test/b T1: /tmp/test/a/vb/c/aaa1
S1: /dev/null /tmp/test/v /tmp/test/b T1: /tmp/test/a/vb/c/aaa1
scons: done building targets.
Is that what you're after?
gary
On 6/20/20 3:19 AM, daggs wrote:
Greetings.
given this example:
def task(source, target, env):
print('S1: %s T1: %s' % (source[0], target[0]))
bld = Builder(action = '@echo S: $SOURCES.abspath T: $TARGET.abspath')
bld1 = Builder(action = task)
env = Environment(BUILDERS = {'Foo' : bld, 'Foo1' : bld1})
env.Foo('a/vb/c/aaa',['/dev/null','v','b'])
env.Foo1('a/vb/c/aaa1',['/dev/null','v','b'])
which produces this output:
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
S: /dev/null /tmp/test/v /tmp/test/b T: /tmp/test/a/vb/c/aaa
task(["a/vb/c/aaa1"], ["/dev/null", "v", "b"])
S1: /dev/null T1: a/vb/c/aaa1
scons: done building targets.
is there a simple way to change bld1 to behave the same as bld?
I'd assume this can be done using **kwargs but it seems like it won't be simple
Thanks,
Dagg.
_______________________________________________
Scons-users mailing list
[email protected]
https://pairlist4.pair.net/mailman/listinfo/scons-users
_______________________________________________
Scons-users mailing list
[email protected]
https://pairlist4.pair.net/mailman/listinfo/scons-users