Re: matching source and target's behavior between func and cmd actions

daggs <[email protected]>
Newsgroups gmane.comp.programming.tools.scons.user
Message-ID <trinity-f60f1f6e-2932-49ef-98e7-a8595c8bd66f-1592719764301@3c-app-mailcom-bs10>
Greetings Bill,

lets look at this example:

env = Environment()

env.Command('foo.out', 'foo.in', "sed 's/x/y/' < $SOURCE > $TARGET")

this allows easy parsing of $SOURCE and $TARGET including the .dirname, .path and .abspath.e.g. I can run every shell cmd.

but I need to have more flexibility such as defining env vars (long line of key=val before the cmd isn't acceptable) and output redirection.

also there is a siotuation where I need to select an env to run the script from a set of two.

so I wrote a builder that allows be such flexibility but it resulted in ability to use the above input.

that is what I'm trying to do.

Thanks,

Dagg.

Sent: Saturday, June 20, 2020 at 11:09 PM

From: "Bill Deegan" <[email protected]>

To: "SCons users mailing list" <[email protected]>

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

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 <[email protected] > 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" <[email protected] >

To: "SCons users mailing list" <[email protected] >, "daggs" <[email protected] >

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 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

_______________________________________________ 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.