[Scons-users] File / Dir relative paths and SConscriptChdir

RW garlicbready at googlemail.com
Thu Sep 6 16:23:40 EDT 2018


Hi,
I've got another question, this is over the use of SConscriptChdir
such as env.SConscriptChdir(0)
from what I can gather when specifying a File or Dir object or making a
call to a Command builder at least which will automatically convert a
string target to a File object.

The File / Dir object will always be relative to the current SConstruct
file.
Not relative to the originating SConstruct file (which is what I'm trying
to do)

To give an example

src1\test1.txt - empty test file
src1\test2.txt - empty test file

src1\SConstruct
```
import os

EnsureSConsVersion(3, 0, 0)

# Setup the construction env
env = Environment(ENV={'PATH': os.environ['PATH']})

# Set working directory to not change
env.SConscriptChdir(0)

# Load in an external script
SConscript('../src2/testsubscript.py', {'env': env})
```

src2\SConstruct
```
# Import the scons environment from the calling script
Import('env')

def build_test(target, source, env):
    # At this point the 'testfile.txt' will be automatically changed to a
File class by SCons

    # print the path scons thinks this file is located at
    print(target[0].path)

tgt = env.Command(File('testfile.txt'), [], build_test)
env.Default(tgt)

tgt2 = env.Command('testfile2.txt', [], build_test)
env.Default(tgt2)

# Even though SConscriptChdir is set to 0 in the originating env, File uses
the current script as it's reference point
# D:\Temp\testproject\src2\testfile.txt
# D:\Temp\testproject\src2\testfile2.txt
```

Is this expected behaviour?
perhaps SConscriptChdir only influences when calling exe's rather than the
use of File or Dir
is there some public API way of setting the current directory for File /
Dir calls?
thats not the directory of the current SConsscript
since builders wrap everything in a File automatically, it might mean I
have to make sure all file paths are absolute before hand.

Many Thanks
Richard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20180906/da413167/attachment-0001.html>


More information about the Scons-users mailing list