[Scons-users] Correct way to expand path variables
Gary Oberbrunner
garyo at oberbrunner.com
Mon Oct 14 13:01:32 EDT 2013
On Mon, Oct 14, 2013 at 12:10 PM, Henry Gomersall <heng at cantab.net> wrote:
> On 14/10/13 15:35, Gary Oberbrunner wrote:
>
>> Hi Henry; use env.subst(str, target, source). You may also need to call
>> env.str2nodes.
>>
>
> That doesn't seem to do as expected, though I'm not quite sure whether I'm
> missing something:
>
> In src/SConscript:
> env.AppendUnique(JINJA_**TEMPLATE_SEARCHPATH=['#foo', 'bar'])
>
> in the scanner function:
> print env.subst(env['JINJA_TEMPLATE_**SEARCHPATH'])
>
> outputs:
> ['#foo', 'bar']
> rather than
> ['foo', 'src/bar']
>
That's as expected -- env.subst() just substitutes variables. You could do
env.subst('$JINJA_TEMPLATE_SEARCH_PATH') for instance; or if any of the
elements of that search path contain $-variables, you need subst() to
substitute them. Turning those into Nodes (File or Dir) is done with
str2nodes; it should also handle #-expansion. Or of course you can just
call Dir() on each element.
Once you do that, note that when reading the SConscript in src (during read
time, not build time) the current dir is src/, so 'bar' is the expected
string value of that Dir node if you ask for it then. (Later, in the build
phase, the current dir is always the top dir, so the relative path to that
node will be src/bar, or variantdir/bar if you are using variants.)
--
Gary
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://four.pairlist.net/pipermail/scons-users/attachments/20131014/9c851530/attachment.htm
More information about the Scons-users
mailing list