X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=site_scons%2Fsite_init.py;h=0121a242ae47b32c03ebcfcca49ae475b504b7b2;hb=HEAD;hp=a8d5c42454bc93c2ece5a0100bd512a9bf2346c0;hpb=10858293dfae5b97842f48022f0d34e9e53a18fc;p=senf.git diff --git a/site_scons/site_init.py b/site_scons/site_init.py index a8d5c42..0121a24 100644 --- a/site_scons/site_init.py +++ b/site_scons/site_init.py @@ -1,25 +1,53 @@ import os.path, SCons +import inspect +import sys -# SCons is at #/scons/scons-/engine/SCons/__init__.py +# SCons is at #/tools/scons-/engine/SCons/__init__.py # site_init is at #/site_scons/site_init.py -sconsbase = os.path.join(os.path.dirname(os.path.dirname(__file__)),"scons") -sconsbase = os.path.abspath(os.path.join(sconsbase, sorted(os.listdir(sconsbase))[-1])) +sconsbase = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath( + inspect.currentframe().f_code.co_filename))),"tools") +sconsbase = os.path.join( + sconsbase,sorted((f for f in os.listdir(sconsbase) if f.startswith("scons-")))[-1]) sconsengine = os.path.join(sconsbase, 'engine') -sconsscript = os.path.join(os.path.join(sconsbase, 'script'),'scons') +sconsscript = os.path.join(sconsbase, 'script', 'scons') -if os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(SCons.__file__)))) != sconsbase: +if os.path.dirname(os.path.dirname(os.path.abspath(SCons.__file__))) != sconsengine: import os, sys, SCons.Util SCons.Util.display("scons: Switching version") + + # BEGIN HACK + # This is really ugly. SCons has already switched into the + # top-level directory when this code is executed. To make 'scons + # -u ' work, we need to switch back into the orgiginal + # startup dir. This directory however is only available in a local + # variable called 'target_top' in SCons.Script.Main._main. + # + # We walk the stack to find a local variable called + # 'target_top'. If we can't find it (could really only happen if + # the SCons.Main code is changed considerably), we output a + # warning, that '-u' will probably fail (we re-start scons from + # the top-level directory, relative targets therefore will not + # work) frame = sys._getframe() - marker = [] - target_top = marker + target_top = marker = [] while frame and target_top is marker: - target_top = frame.f_locals.get('target_top',marker) frame = frame.f_back + if frame : target_top = frame.f_locals.get('target_top',marker) if target_top is marker: - SCons.Util.display("scons: WARNING: scons -u will fail") - elif target_top is not None: - os.chdir(target_top) + SCons.Util.display("scons: WARNING: scons -u will probably fail") + if not target_top: + target_top = '.' + if frame: + cdir = frame.f_locals.get('cdir', '.') + # END HACK + + os.chdir(target_top) + cdir = os.path.normpath(cdir) + if cdir.startswith('../'): + SCons.Util.display("scons: WARNING: failed to undo -C option") + elif cdir != '.' and not cdir.startswith('/'): + os.chdir('/'.join(('..' for _ in cdir.split('/')))) os.environ['SCONS_LIB_DIR'] = sconsengine - os.execv(sconsscript, sys.argv) + os.execv(sys.executable, [sconsscript] + sys.argv) +