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