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

Manuel Naranjo naranjo.manuel at gmail.com
Mon Jul 22 07:44:16 EDT 2013


There's nothing wrong with the inspect version, just that there could be
a more elegant solution. As a matter of fact I use the inspct version a
lot with tools I have developed as or some reason with Scons __file__ is
not reliable.

-Manuel


> Are you using a variant dir? Do you want the directory of the SConcript

> file or the variant dir one? pwd and Scons are reporting the same

> directory. If you are using a variant-dir and you want the path to the

> variant-dir version then take out the srcnode() piece.

>

> -Manuel

>

>

>> 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

>> _______________________________________________

>> Scons-users mailing list

>> Scons-users at scons.org

>> http://four.pairlist.net/mailman/listinfo/scons-users

>>

>




More information about the Scons-users mailing list