]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph.in: detect paths in out of tree build
authorJohn Spray <john.spray@redhat.com>
Mon, 3 Aug 2015 23:10:47 +0000 (00:10 +0100)
committerJohn Spray <john.spray@redhat.com>
Mon, 10 Aug 2015 13:09:00 +0000 (14:09 +0100)
a la what we currently do for PYTHONPATH
and LD_LIBRARY_PATH, but for cmake out
of tree builds.

Signed-off-by: John Spray <john.spray@redhat.com>
src/ceph.in

index 3178ba155c672098e5dd9eb97cca14dabb583334..c6c7c498511b7bea645a7e0aefc0e1907aa028b2 100755 (executable)
@@ -35,9 +35,10 @@ MYPATH = os.path.abspath(__file__)
 MYDIR = os.path.dirname(MYPATH)
 DEVMODEMSG = '*** DEVELOPER MODE: setting PATH, PYTHONPATH and LD_LIBRARY_PATH ***'
 
-if MYDIR.endswith('src') and \
-   os.path.exists(os.path.join(MYDIR, '.libs')) and \
-   os.path.exists(os.path.join(MYDIR, 'pybind')):
+def respawn_in_path(lib_path, pybind_path):
+    execv_cmd = ['python']
+    if 'CEPH_DBG' in os.environ:
+        execv_cmd += ['-mpdb']
 
     if platform.system() == "Darwin":
         lib_path_var = "DYLD_LIBRARY_PATH"
@@ -45,23 +46,48 @@ if MYDIR.endswith('src') and \
         lib_path_var = "LD_LIBRARY_PATH"
 
     py_binary = os.environ.get("PYTHON", "python")
-    MYLIBPATH = os.path.join(MYDIR, '.libs')
-    execv_cmd = ['python']
-    if 'CEPH_DBG' in os.environ:
-        execv_cmd += ['-mpdb']
+
     if lib_path_var in os.environ:
-        if MYLIBPATH not in os.environ[lib_path_var]:
-            os.environ[lib_path_var] += ':' + MYLIBPATH
+        if lib_path not in os.environ[lib_path_var]:
+            os.environ[lib_path_var] += ':' + lib_path
             print >> sys.stderr, DEVMODEMSG
             os.execvp(py_binary, execv_cmd + sys.argv)
     else:
-        os.environ[lib_path_var] = MYLIBPATH
+        os.environ[lib_path_var] = lib_path
         print >> sys.stderr, DEVMODEMSG
         os.execvp(py_binary, execv_cmd + sys.argv)
-    sys.path.insert(0, os.path.join(MYDIR, 'pybind'))
+    sys.path.insert(0, os.path.join(MYDIR, pybind_path))
+
+if MYDIR.endswith('src') and \
+   os.path.exists(os.path.join(MYDIR, '.libs')) and \
+   os.path.exists(os.path.join(MYDIR, 'pybind')):
+
+    respawn_in_path(os.path.join(MYDIR, '.libs'), "pybind")
     if os.environ.has_key('PATH') and MYDIR not in os.environ['PATH']:
         os.environ['PATH'] += ':' + MYDIR
 
+elif os.path.exists(os.path.join(os.getcwd(), "CMakeCache.txt")) \
+     and os.path.exists(os.path.join(os.getcwd(), "init-ceph")):
+    src_path = None
+    for l in open("./CMakeCache.txt").readlines():
+        if l.startswith("Ceph_SOURCE_DIR:STATIC="):
+            src_path = l.split("=")[1].strip()
+
+    if src_path is None:
+        # Huh, maybe we're not really in a cmake environment?
+        pass
+    else:
+        # Developer mode, but in a cmake build dir instead of the src dir
+        lib_path = os.path.join(os.getcwd(), "src")
+        pybind_path = os.path.join(src_path, "src", "pybind")
+        respawn_in_path(lib_path, pybind_path)
+
+    sys.path.insert(0, os.path.join(MYDIR, pybind_path))
+
+    # Add src/ to path for e.g. ceph-conf
+    if os.environ.has_key('PATH') and lib_path not in os.environ['PATH']:
+        os.environ['PATH'] += ':' + lib_path
+
 import argparse
 import errno
 import json