3 # SCons is at #/tools/scons-<v>/engine/SCons/__init__.py
4 # site_init is at #/site_scons/site_init.py
6 sconsbase = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))),"tools")
7 sconsbase = os.path.join(
8 sconsbase,sorted((f for f in os.listdir(sconsbase) if f.startswith("scons-")))[-1])
9 sconsengine = os.path.join(sconsbase, 'engine')
10 sconsscript = os.path.join(sconsbase, 'script', 'scons')
12 if os.path.dirname(os.path.dirname(os.path.abspath(SCons.__file__))) != sconsengine:
13 import os, sys, SCons.Util
14 SCons.Util.display("scons: Switching version")
17 # This is really ugly. SCons has already switched into the
18 # top-level directory when this code is executed. To make 'scons
19 # -u <target>' work, we need to switch back into the orgiginal
20 # startup dir. This directory however is only available in a local
21 # variable called 'target_top' in SCons.Script.Main._main.
23 # We walk the stack to find a local variable called
24 # 'target_top'. If we can't find it (could really only happen if
25 # the SCons.Main code is changed considerably), we output a
26 # warning, that '-u' will probably fail (we re-start scons from
27 # the top-level directory, relative targets therefore will not
29 frame = sys._getframe()
30 target_top = marker = []
31 while frame and target_top is marker:
33 if frame : target_top = frame.f_locals.get('target_top',marker)
34 if target_top is marker:
35 SCons.Util.display("scons: WARNING: scons -u <target> will probably fail")
39 cdir = frame.f_locals.get('cdir', '.')
43 cdir = os.path.normpath(cdir)
44 if cdir.startswith('../'):
45 SCons.Util.display("scons: WARNING: failed to undo -C option")
46 elif cdir != '.' and not cdir.startswith('/'):
47 os.chdir('/'.join(('..' for _ in cdir.split('/'))))
48 os.environ['SCONS_LIB_DIR'] = sconsengine
49 os.execv(sconsscript, sys.argv)