From e85146297708e59a41a463e1bd390d1e9de4d49c Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Mon, 22 Oct 2018 13:13:49 +0800 Subject: [PATCH] ceph.in: extract get_cmake_variables() so it can be reused Signed-off-by: Kefu Chai --- src/ceph.in | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/ceph.in b/src/ceph.in index 07461856917..82d6239486c 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? -- 2.39.5