Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting the scons root directory

Tags:

scons

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

One of them is a program that I'm stuck with and can't deal with absolute/relative paths so I have to use the chdir=1 option of the Builder so that its actions run in the same directory as the target.

The second is a script that is located in the tools subdirectory of the project; the SConstruct file is in the root of the project. I need to create an action to run this script, and am having trouble because I have neither the absolute path to the project, nor a relative path from the directory in which the target is located back up 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'd be all set, I could just concatenate `tools/myscript.bar' and be done with it.

Here's 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 "myscript.bar" can be found, 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);

This seems so simple but I can't figure out how.

like image 323
Jason S Avatar asked Sep 22 '09 18:09

Jason S


2 Answers

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

print Dir('#').abspath

This version works if you use a variant directory too. 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, whereas the second will show the correct /path/to/project.

like image 144
richq Avatar answered Oct 19 '22 12:10

richq


Grrr. It is simple; this seems to work.

env['BUILD_ROOT'] = Dir('.');
Builder(action = ['somecmd ${BUILD_ROOT.abspath}/tools/myscript.bar ...']);
like image 40
Jason S Avatar answered Oct 19 '22 10:10

Jason S