From: Kefu Chai Date: Mon, 22 Oct 2018 05:13:49 +0000 (+0800) Subject: ceph.in: extract get_cmake_variables() X-Git-Tag: v14.1.0~1119^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e85146297708e59a41a463e1bd390d1e9de4d49c;p=ceph.git ceph.in: extract get_cmake_variables() so it can be reused Signed-off-by: Kefu Chai --- diff --git a/src/ceph.in b/src/ceph.in index 074618569171..82d6239486cb 100755 --- a/src/ceph.in +++ b/src/ceph.in @@ -98,12 +98,23 @@ def get_pythonlib_dir(): """Returns the name of a distutils build directory""" return "lib.{version[0]}".format(version=sys.version_info) + +def get_cmake_variables(names): + vars = dict((name, None) for name in names) + for line in open(os.path.join(MYPDIR, "CMakeCache.txt")): + # parse lines like "WITH_ASAN:BOOL=ON" + for name in names: + if line.startswith("{}:".format(name)): + vars[name] = line.split("=")[1].strip() + break + if all(vars.itervalues()): + break + return vars + + if os.path.exists(os.path.join(MYPDIR, "CMakeCache.txt")) \ and os.path.exists(os.path.join(MYPDIR, "bin/init-ceph")): - src_path = None - for l in open(os.path.join(MYPDIR, "CMakeCache.txt")): - if l.startswith("ceph_SOURCE_DIR:STATIC="): - src_path = l.split("=")[1].strip() + src_path = get_cmake_variables(["ceph_SOURCE_DIR"])["ceph_SOURCE_DIR"] if src_path is None: # Huh, maybe we're not really in a cmake environment?