Getting the scons root directory

I need to run two programs sequentially as part of a custom builder.

One of them is a program in which I am stuck and cannot deal with absolute / relative paths, so I need to use the chdir=1 option for Builder so that its actions are executed in the same directory as the target.

The second is the script, which is located in the tools subdirectory of the project; The SConstruct file is at the root of the project. I need to create an action to run this script, and I am having problems because I have neither an absolute path to the project, nor a relative path from the directory where the target is back to the tools subdirectory where the script is located. If I could somehow get the absolute path to the root directory of my project, I would be configured, I could just concatenate `tools / myscript.bar 'and do it.

Here is what I have, more or less:

 env['BUILDERS']['FooBar'] = Builder(action = [ 'c:/bin/foo.exe ${SOURCE.filebase}', 'c:/bin/bar-interpreter.exe myscript.bar ${SOURCE.filebase}', ], chdir=1); 

The problem is that I need to change the action in question so that I can find "myscript.bar", something like:

 env['BUILDERS']['FooBar'] = Builder(action = [ 'c:/bin/foo.exe ${SOURCE.filebase}', 'c:/bin/bar-interpreter.exe $PATHTOHERE/tools/myscript.bar ${SOURCE.filebase}', ], chdir=1); 

It seems so simple, but I can't figure out how to do it.

+7
scons
source share
2 answers

Grrr. It's simple; it seems to work.

 env['BUILD_ROOT'] = Dir('.'); Builder(action = ['somecmd ${BUILD_ROOT.abspath}/tools/myscript.bar ...']); 
+3
source share

You must use "#" to indicate the top of the source directory.

 print Dir('#').abspath 

This version works if you also use the catalog option . For example, in SConstruct :

 SConscript('main.scons', variant_dir="build") 

Then in main.scons :

 print Dir('.').abspath print Dir('#').abspath 

The first will print /path/to/project/build , while the second will show the correct /path/to/project .

+17
source share

All Articles