From: Anirudha Bose Date: Wed, 25 May 2016 22:09:22 +0000 (+0530) Subject: pybind: Check presence of rados headers and libraries in setup.py X-Git-Tag: ses5-milestone5~486^2~9 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=fc27e9488112e4045fa756f3c42506bde01d0576;p=ceph.git pybind: Check presence of rados headers and libraries in setup.py Signed-off-by: Anirudha Bose --- diff --git a/src/pybind/rados/setup.py b/src/pybind/rados/setup.py index 6f9fe6fea4f..76686c92fdc 100755 --- a/src/pybind/rados/setup.py +++ b/src/pybind/rados/setup.py @@ -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 + + 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')