[Scons-users] Should chdir in builders change $TARGET and $SOURCE relative to new directory?

Bill Deegan bill at baddogconsulting.com
Thu May 11 17:22:56 EDT 2017


A little background.
In general, we currently advise against using chdir as it breaks when
building in parallel as all threads share the same current directory.

That said, your question is a good one in that it might simplify for some
users the logic.

However what you're seeing is the defined behavior per the manpage:

"Note that scons will *not* automatically modify its expansion of
construction variables like *$TARGET* and *$SOURCE* when using the chdir
keyword argument--that is, the expanded file names will still be relative
to the top-level SConstruct directory, and consequently incorrect relative
to the chdir directory. If you use the chdir keyword argument, you will
typically need to supply a different command line using expansions like
*${TARGET.file}* and *${SOURCE.file}* to use just the filename portion of
the targets and source."

-Bill



On Thu, May 11, 2017 at 4:25 PM, Gaurav Juvekar <gauravjuvekar at gmail.com>
wrote:

> Hi,
>
> Suppose I have an SConstruct like
>
> bld = Builder(action = 'cat < $SOURCE > $TARGET')
> env = Environment(BUILDERS = {'CpBuilder': bld})
> env.CpBuilder('subdir/target.out', 'subdir/source.in', chdir = 'subdir')
>
> and my source tree like
> .
> |-- SConstruct
> `-- subdir
>     `-- source.in
>
> I would expect that the $SOURCE and $TARGET when expanded would take into
> account the chdir and $SOURCE == 'source.in' and $TARGET == 'target.out'.
> However, they still expand to 'subdir/source.in' and 'subdir/target.out'
> giving this error.
>
>
> scons: Reading SConscript files ...
> scons: done reading SConscript files.
> scons: Building targets ...
> os.chdir('subdir')
> cat < subdir/source.in > subdir/target.out
> sh: 1: cannot open subdir/source.in: No such file
> os.chdir('/tmp/ex')
> scons: *** [subdir/target.out] Error 2
> scons: building terminated because of errors.
>
>
> Is this behavior intended or should the variable expansion take into
> account chdir?
>
> --
> Regards,
> Gaurav Juvekar
> _______________________________________________
> Scons-users mailing list
> Scons-users at scons.org
> https://pairlist4.pair.net/mailman/listinfo/scons-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20170511/b69f2ad4/attachment.html>


More information about the Scons-users mailing list