Skip to content

Commit

Permalink
ceph.in: detect paths in out of tree build
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
John Spray committed Aug 3, 2015
1 parent 21708df commit 3c2ea3f
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions src/ceph.in
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,53 @@ 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"
else:
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 os.environ.has_key('PATH') and MYDIR not in os.environ['PATH']:
os.environ['PATH'] += ':' + MYDIR

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")

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)

import argparse
import errno
import json
Expand Down

0 comments on commit 3c2ea3f

Please sign in to comment.