minor fixes for clang++
[senf.git] / site_scons / site_init.py
index 45eb2bb..0121a24 100644 (file)
@@ -1,9 +1,12 @@
 import os.path, SCons
+import inspect
+import sys
 
 # SCons is at     #/tools/scons-<v>/engine/SCons/__init__.py
 # site_init is at #/site_scons/site_init.py
 
-sconsbase = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))),"tools")
+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')
@@ -36,16 +39,15 @@ if os.path.dirname(os.path.dirname(os.path.abspath(SCons.__file__))) != sconseng
     if not target_top:
         target_top = '.'
     if frame:
-        cdir = frame.f_locals.get('cdir', '')
+        cdir = frame.f_locals.get('cdir', '.')
     # END HACK
     
     os.chdir(target_top)
-    for dir in reversed(os.path.normpath(cdir).split('/')):
-        if dir == '..':
-            SCons.Utio.display("scons: WARNING: failed to undo -C option")
-            break
-        if dir == '.':
-            continue
-        os.chdir('..')
+    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)
+