Skip to content

Commit

Permalink
pybind: Check presence of rados headers and libraries in setup.py
Browse files Browse the repository at this point in the history
Signed-off-by: Anirudha Bose <[email protected]>
  • Loading branch information
onyb committed Jun 19, 2016
1 parent 7b04e7f commit fc27e94
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/pybind/rados/setup.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit fc27e94

Please sign in to comment.