[Scons-users] How to find the directory of the invoking SConstruct

Hans Peter Jepsen hpj at lodam.com
Mon Jul 22 02:33:05 EDT 2013


Hi Manual

You wrote:


> Dir('#').srcnode().abspath gives you the absolute path to the SConstruct file.

>

> Dir('.').srcnode().abspath gives you the absolute path to the current

> SConscript file.


This does not work for me:

My SConstruct.py contains this:

print "Dir('#').srcnode().abspath :", Dir('#').srcnode().abspath
print "Dir('.').srcnode().abspath :", Dir('.').srcnode().abspath

# From: http://stackoverflow.com/questions/9806573/does-scons-know-in-which-directory-a-sconscript-file-resides
import os
this_sconscript_file = (lambda x:x).func_code.co_filename
BUILDDIR = os.path.dirname(this_sconscript_file)
print "BUILDDIR:", BUILDDIR

Here is what I ge when I run it:

hpj at Lodam-HPJT430s ~
$ pwd
/home/hpj

hpj at Lodam-HPJT430s ~
$ scons -f /cygdrive/c/Project/hpj_main_LFC/ControlMicro/Product/LFC100/Build/SConstruct.py
scons: Reading SConscript files ...
Dir('#').srcnode().abspath : /home/hpj
Dir('.').srcnode().abspath : /home/hpj
BUILDDIR: /cygdrive/c/Project/hpj_main_LFC/ControlMicro/Product/LFC100/Build

I am running scons under Cygwin. The version is 2.3.0.

hpj at Lodam-HPJT430s ~
$ scons --version
SCons by Steven Knight et al.:
script: v2.3.0, 2013/03/03 09:48:35, by garyo on reepicheep
engine: v2.3.0, 2013/03/03 09:48:35, by garyo on reepicheep
engine path: ['/usr/lib/scons-2.3.0/SCons']
Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 The SCons Foundation

Best regards

Hans Peter


More information about the Scons-users mailing list