]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind: Check presence of rados headers and libraries in setup.py
authorAnirudha Bose <ani07nov@gmail.com>
Wed, 25 May 2016 22:09:22 +0000 (03:39 +0530)
committerAnirudha Bose <ani07nov@gmail.com>
Sun, 19 Jun 2016 14:48:41 +0000 (20:18 +0530)
Signed-off-by: Anirudha Bose <ani07nov@gmail.com>
src/pybind/rados/setup.py

index 6f9fe6fea4f6881878e3b73f263583413fd4a07d..76686c92fdc0e5ea4f7b196dde63782b73ca4a38 100755 (executable)
@@ -1,10 +1,18 @@
 # Largely taken from
 # https://blog.kevin-brown.com/programming/2014/09/24/combining-autotools-and-setuptools.html
+from __future__ import print_function
+
 import os
+import shutil
 import subprocess
 import sys
+import tempfile
+import textwrap
+from distutils.ccompiler import new_compiler
 from distutils.core import setup
+from distutils.errors import CompileError, LinkError
 from distutils.extension import Extension
+from distutils.sysconfig import customize_compiler
 
 from Cython.Build import cythonize
 
@@ -61,6 +69,52 @@ def get_python_flags():
     }
 
 
+def check_sanity():
+    """
+    Test if development headers and library for rados is available by compiling a dummy C program.
+    """
+
+    tmp_dir = tempfile.mkdtemp(dir=os.path.dirname(__file__))
+    tmp_file = os.path.join(tmp_dir, 'rados_dummy.c')
+
+    with open(tmp_file, 'w') as fp:
+        dummy_prog = textwrap.dedent("""
+        #include <rados/librados.h>
+
+        int main(void) {
+            rados_t cluster;
+            rados_create(&cluster, NULL);
+            return 0;
+        }
+        """)
+        fp.write(dummy_prog)
+
+    compiler = new_compiler()
+    customize_compiler(compiler)
+
+    try:
+        compiler.link_executable(
+            compiler.compile([tmp_file]),
+            os.path.join(tmp_dir, 'rados_dummy'),
+            libraries=['rados'],
+            output_dir=tmp_dir
+        )
+
+    except CompileError:
+        print('\nCompile Error: RADOS development headers not found', file=sys.stderr)
+        return False
+    except LinkError:
+        print('\nLink Error: RADOS library not found', file=sys.stderr)
+        return False
+    else:
+        return True
+    finally:
+        shutil.rmtree(tmp_dir)
+
+
+if not check_sanity():
+    sys.exit(1)
+
 # Disable cythonification if we're not really building anything
 if (len(sys.argv) >= 2 and
         any(i in sys.argv[1:] for i in ('--help', 'clean', 'egg_info', '--version')