[Scons-users] Writing a command that always succeeds

Jason Kenny dragon512 at live.com
Tue Jun 14 23:23:20 EDT 2016


So env.subst() is how I tend to do it. I have abused the subst() system in
Parts for example to allow me to pass data between different components.
This for example allows me to auto fill in the LIBS variable for example
with dependent components libraries that are exported. This ca be very
convient as in cases like this you can change the library name and all the
components that depend on it get the new name, vs having to replace the
string directly as is common in Make or Raw SCons. 

There are quirks with using Subst() to much I should warn you however, more
so when you add more complex objects such as lists. Also if you want to use
an object to assist in the adding logic to subst() you have to make sure the
Environment is setup with the object correctly. Depending on how large your
build is this can get tricky. I for one Parts made a patter I called mappers
and have Parts auto load them, to prevent issues/mistakes by the user.

So for a more exact example here is a object that given a path make it
absolute

class abspath_mapper(object):
    ''' Allows for an easy expanding value as directory or files'''
    def __init__(self,value):
          self.value = value
    def __call__(self, target, source, env, for_signature):
        if self.value[0] == '$':
            return env.Entry(env.subst(self.value)).abspath
        return env.Entry(env.subst("${"+self.value+"}")).abspath

Nothing to crazy minus this returns a Node object vs a string.

To set this up you can add it to the constructor when you create a new
Environment or you can just add it on later via Replace(...) or via setting
it directly. Ie..

Env.Replace(ABSPATH=abspath_mapper)
Or 
Env[ABSPATH=abspath_mapper]

You can then call it directly like:

Path=Env.subst("${ABSPATH('.')}")

However if you have an Action setup to process some command string it should
call Subst for you as the builder actions run in executor object that sets
up special value such as $SOURCES and $TARGETS so they exist in the
environment when it call subst(). 
You can modify your builder to use its own subprocess call, or setup your
own SPAWN override. Do this would allow you to set state in a env to keep
track of pass or fail. Or you could just make your own global object that
you build know how to write to.

Jason

-----Original Message-----
From: Scons-users [mailto:scons-users-bounces at scons.org] On Behalf Of Stefan
Seefeld
Sent: Tuesday, June 14, 2016 8:34 PM
To: scons-users at scons.org
Subject: Re: [Scons-users] Writing a command that always succeeds

On 12.06.2016 21:55, Jason Kenny wrote:
> Ya... in the Main pages you can find this:
>
> Action('$CC -c -o $TARGET $SOURCES')
>
> # Doesn't print the line being executed.
> Action('@build $TARGET $SOURCES')
>
> # Ignores return value
> Action('-build $TARGET $SOURCES')
>
> Hope this helps

It does indeed, thanks. However, using this I realize it isn't quite what I
need:
I want a way to run tests, such that the entire build status doesn't depend
on whether any single test passed or failed. Yet I do want to handle the
test status (so I can report 'PASS' / 'FAIL').

I figure the best way to achieve this is to write my own python function
executing the tests in a subprocess.
However, now I'm faced with a slightly different problem: I want to run
different commands, such as `$SOURCE` in the simplest case, or `$PYTHON
$SOURCE` in a slightly advanced case. How can I explicitly substitute the
variables used in these strings so I can pass this down to
subprocess.call() ?

The documentation explains how certain variables are automatically
substituted by SCons when a command / action is executed. But I didn't find
any hint at how to perform the substitution myself (using
env.subst() ?) when I provide my custom python function.

Thanks,
        Stefan

-- 

      ...ich hab' noch einen Koffer in Berlin...

_______________________________________________
Scons-users mailing list
Scons-users at scons.org
https://pairlist4.pair.net/mailman/listinfo/scons-users


More information about the Scons-users mailing list