From 44ed436c7912bedd8ed781eda725d39d2c41863b Mon Sep 17 00:00:00 2001 From: John Spray Date: Tue, 4 Aug 2015 00:10:47 +0100 Subject: [PATCH] ceph.in: detect paths in out of tree build a la what we currently do for PYTHONPATH and LD_LIBRARY_PATH, but for cmake out of tree builds. Signed-off-by: John Spray --- src/ceph.in | 48 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/src/ceph.in b/src/ceph.in index 3178ba155c672..c6c7c498511b7 100755 --- a/src/ceph.in +++ b/src/ceph.in @@ -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 -- 2.39.5