-
-
Notifications
You must be signed in to change notification settings - Fork 320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Substitution of special attributes of special variables like $SOURCE
does not work in builder calls
#4660
Comments
Command
?)(Command
?)
Just to wrap up, at this point, the value of >>> eval('SOURCE.filebase', {}, {'SOURCE': 'foo'})
Traceback (most recent call last):
File "<input>", line 1, in <module>
eval('SOURCE.filebase', {}, {'SOURCE': 'foo'})
File "<string>", line 1, in <module>
AttributeError: 'str' object has no attribute 'filebase' |
Command
?)$SOURCE
does not work in builder calls
A workaround is to use File(), like this:
It should work. |
To update the details a bit: it's not actually a string. It's a The current proposal is to update the User Guide to give the guidance above, and leave this issue open for a while longer, in case anyone is motivated to dig a bit further. |
The User Guide uses an example (in the Command chapter) of making a target name out of the source name, a special attribute, and concaetenation with a new suffix. The special attribute part is not something that has been introduced. Some searching suggests it's never actually described in the User Guide, though .file, .abspath and .srcdir are used in examples. The attribute used, .basename, doesn't actually exist - there's a .base (and also a .filebase. Furthermmore, the substitution suggested doesn't work. Expansion of special variables like $SOURCE into nodes is deferred - see the docstring of SCons.Subst.NLWrapper - so the internal expansion ends up trying to lookup the attribute on a string, which fails with an AttributeError. The way the user guide entry is written, it was not actually evaluated: it was described as an <scons_example>, but an incomplete one, and since there was no corresponding <scons_output> the problem was not detected. The changes fix up the example to have it use an existing attribute and do File() on the source, and add a sidebar to provide a bit of an explanation so this isn't just "magic". A subsequent example (that I added) is dropped as it doesn't add enough value, and actually causing the evaluation to be run is added to the final example of the chapter - the troublesom example was ex3, and wasn't set up to ever be executed by the doc machinery, so the failure wasn't spotted; now it can be shown to be working correctly. This finally fixes SCons#2905, which was closed in 2018 as having been addressed, though the non-working example actually remained. The issue is also mentioned in SCons#4660, which is not resolved by changing the docs - leaving that open, at least for the time being. Signed-off-by: Mats Wichmann <[email protected]>
The User Guide uses an example (in the Command chapter) of making a target name out of the source name, a special attribute, and concatenation with a new suffix. The special attribute part is not something that has been introduced. Some searching suggests it's never actually described in the User Guide, though .file, .abspath and .srcdir are used in examples. The attribute used, .basename, doesn't actually exist - there's a .base and a .filebase. Furthermore, the substitution suggested doesn't work. Expansion of special variables like $SOURCE into nodes is deferred - see the docstring of SCons.Subst.NLWrapper - so the internal expansion ends up trying to lookup the attribute on a string, which fails with an AttributeError. The way the user guide entry is written, it was not actually evaluated: it was described as an <scons_example>, but an incomplete one, and since there was no corresponding <scons_output> the problem was not detected. The changes fix up the example to have it use an existing attribute (.base) and do File() on the source, and add a sidebar to provide a bit of an explanation so this isn't just "magic". A subsequent example (ex4, which I added) is dropped as it doesn't add enough value by itself, and the final example (formerly ex5, renamed to ex3) now includes this substitution so it's actually run by the doc machinery, and can be seen to be working correctly. This finally fixes SCons#2905, which was closed in 2018 as having been addressed, though the non-working example actually remained. The issue is also mentioned in SCons#4660, which is not resolved by changing the docs - leaving that open, at least for the time being. Signed-off-by: Mats Wichmann <[email protected]>
This topic was previously raised in #2905, which was closed in 2018 without apparently having been really resolved. This issue is created because of a fresh mention.
The User Guide claims that you can do substitutions on
SOURCE
andTARGET
in sources and targets, in the chapter about theCommand
builder:https://scons.org/doc/production/HTML/scons-user.html#chap-builders-commands
Specifically:
Besides that SCons variables don't have a special attribute
basename
, this fails even iffilebase
(which is documented) is used. You get deep into a chain of calls, and eventuallyStringSubber.expand
fails because it tries toeval
the string to be substituted and because of the apparent attribute access in there, you get anAttributeError
:At this point, the call trace looks like this:
Everything at this point looks as one might expect. The string to sub is
'${SOURCE.filebase}'
, the code has extracted the relevant part so thekey
variable is'SOURCE.filebase'
,lvars
has the right values for the special variables in it:But the attempt to evaluate it fails:
A few lines prior to that line, there was an attempt to detect a period in the string, but then nothing is done with that information until later. That initial check is here:
scons/SCons/Subst.py
Line 373 in 01f77b1
The text was updated successfully, but these errors were encountered: