[Scons-users] matching source and target's behavior between func and cmd actions

Bill Deegan bill at baddogconsulting.com
Sat Jun 20 16:09:50 EDT 2020


Dagg,

Perhaps if you explain the actual task rather than the straw task you're
trying to do that might fill in enough context to help provide a good
answer.
Often straw tasks will waste time because the straw task is not
sufficiently detail to replicate the actual task.

-Bill

On Sat, Jun 20, 2020 at 10:52 AM daggs <daggs at gmx.com> wrote:

> Greetings Gary,
>
> that helps me in this specific case but not in the more general case as I
> might want to use .dirname or pass the cmd.
>
> I thought of using regex replace like this:
> def task(source, target, env):
>     print(env['cmd'])
>     new_cmd = re.sub("\$TARGET", env['cmd'], 'aaa')
>     print('['+new_cmd+']')
>
> but for the following cmd:
> ${SOURCE}<=>$SOURCE<=>${SOURCES}<=>$SOURCES<=>${TARGET}<=>$TARGET<=>$SOURCES.dirname<=>${SOURCE}.dirname<=>$TARGET.abspath
> I get this output:
> [aaa]
>
> I must be doing something wrong, thing is, I can't figure out what.
> ideas?
>
> Thanks,
>
> Dagg.
>
> *Sent:* Saturday, June 20, 2020 at 8:19 PM
> *From:* "Gary Granger" <granger at ucar.edu>
> *To:* "SCons users mailing list" <scons-users at scons.org>, "daggs" <
> daggs at gmx.com>
> *Subject:* Re: [Scons-users] matching source and target's behavior
> between func and cmd actions
>
> 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 listScons-users at scons.orghttps://pairlist4.pair.net/mailman/listinfo/scons-users
>
> _______________________________________________
> Scons-users mailing list
> Scons-users at scons.org
> https://pairlist4.pair.net/mailman/listinfo/scons-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20200620/5161448e/attachment-0001.html>


More information about the Scons-users mailing list