[Scons-users] Variable substitution special modifiers do not appear to work with callables

Dirk Bächle tshortik at gmx.de
Sun May 17 12:52:16 EDT 2015


Hi Andrew,

On 16.05.2015 20:45, Andrew C. Morrow wrote:
>
> With SCons 2.3.4, the following SConstruct (reduced from a much larger system, so is somewhat arbitrary), unexpectedly fails with an
> error:
>
>  [...]
>
> touch generated
> scons: *** [something] AttributeError `'function' object has no attribute 'abspath'' trying to evaluate `${XXX.abspath}'
> scons: building terminated because of errors.
>
> Based on my reading of the Variable Substitution part of the SCons man page, I would expect that the abspath special modifier would
> work on any variable, but it seems it does not work when the variable is callable.
>
> Is this a bug, or is there a bit of syntactic magic I can apply to make this work?

no it's not a bug. The "Variable Substitution" section mentions the support for more general Python methods as:

"       Note that curly braces braces may also be used to enclose arbitrary
        Python code to be evaluated. (In fact, this is how the above modifiers
        are substituted, they are simply attributes of the Python objects that
        represent TARGET, SOURCES, etc.) See the section "Python Code
        Substitution" below, for more thorough examples of how this can be
        used.
"

, so you can write "${XXX}.abspath" like in your example. But if XXX is your generator function, what is it that SCons should return 
as "abspath"? It can't know this for custom defined Python methods/objects, so you have to add a "abspath" member to your 
"generator" object manually (the Node class has one defined per default for the sources/targets, which this feature mainly aims at). 
Then the substitution mechanism will work as expected...

Best regards,

Dirk



More information about the Scons-users mailing list