From b87795e04f0d2e00dee33346dba0e0c40710519b Mon Sep 17 00:00:00 2001 From: stevenknight Date: Thu, 11 Apr 2002 18:24:32 +0000 Subject: [PATCH] Change to SConscript directory when reading it. (Steve Leblanc) git-svn-id: http://scons.tigris.org/svn/scons/trunk@327 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- doc/man/scons.1 | 22 ++++++++++++++++++++++ src/CHANGES.txt | 4 ++++ src/engine/SCons/Script/SConscript.py | 15 +++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/doc/man/scons.1 b/doc/man/scons.1 index b3ed1413..543a259c 100644 --- a/doc/man/scons.1 +++ b/doc/man/scons.1 @@ -1347,6 +1347,28 @@ SConscript('dir/SConscript') foo = SConscript('subdir/SConscript', "env") .EE +.TP +.RI SConscriptChdir( value ) +When a non-negative +.I value +is specified, +this instructs +.B scons +to change its working directory (chdir) +to the directory in which each subsidiary +configure (SConscript) file lives. +Note that you may enable and disable +this ability by calling +.R SConscriptChdir() +multiple times: + +.ES +SConscriptChdir(1) +SConscript('foo/SConscript') # will chdir to foo +SConscriptChdir(0) +SConscript('bar/SConscript') # will not chdir to bar +.EE + .TP .RI SetCommandHandler( function ) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 5fb3c009..f7de1c83 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -20,6 +20,10 @@ RELEASE 0.07 - - Man page: Add a hierarchical libraries + Program example. + From Steve Leblanc: + + - Add the SConscriptChdir() method. + From Anthony Roach: - Fix --debug=tree when used with directory targets. diff --git a/src/engine/SCons/Script/SConscript.py b/src/engine/SCons/Script/SConscript.py index 55520150..eb1a13e9 100644 --- a/src/engine/SCons/Script/SConscript.py +++ b/src/engine/SCons/Script/SConscript.py @@ -38,6 +38,7 @@ import SCons.Node import SCons.Node.FS import SCons.Util +import os import string import sys @@ -48,6 +49,13 @@ arguments = {} # global exports set by Export(): global_exports = {} +# chdir flag +sconscript_chdir = 0 + +def SConscriptChdir(flag): + global sconscript_chdir + sconscript_chdir = flag + def _scons_add_args(alist): global arguments for arg in alist: @@ -98,6 +106,7 @@ def SConscript(script, exports=[]): # push: stack.append(Frame(exports)) + old_dir = None try: # call: if script == "-": @@ -108,6 +117,9 @@ def SConscript(script, exports=[]): if script.exists(): file = open(str(script), "r") SCons.Node.FS.default_fs.chdir(script.dir) + if sconscript_chdir: + old_dir = os.getcwd() + os.chdir(str(script.dir)) exec file in stack[-1].globals else: sys.stderr.write("Ignoring missing SConscript '%s'\n" % script.path) @@ -115,6 +127,8 @@ def SConscript(script, exports=[]): # pop: frame = stack.pop() SCons.Node.FS.default_fs.chdir(frame.prev_dir) + if old_dir: + os.chdir(old_dir) return frame.retval @@ -188,6 +202,7 @@ def BuildDefaultGlobals(): globals['Return'] = Return globals['Scanner'] = SCons.Scanner.Base globals['SConscript'] = SConscript + globals['SConscriptChdir'] = SConscriptChdir globals['SetCommandHandler'] = SCons.Action.SetCommandHandler globals['WhereIs'] = SCons.Util.WhereIs return globals -- 2.26.2