import textwrap
from distutils.ccompiler import new_compiler
from distutils.errors import CompileError, LinkError
+from itertools import filterfalse, takewhile
import distutils.sysconfig
-unwrapped_customize = distutils.sysconfig.customize_compiler
-clang = False
-
-def filter_unsupported_flags(flags):
- if clang:
- return [f for f in flags if not (f == '-mcet' or
- f.startswith('-fcf-protection'))]
+def filter_unsupported_flags(compiler, flags):
+ args = takewhile(lambda argv: not argv.startswith('-'), [compiler] + flags)
+ if any('clang' in arg for arg in args):
+ return list(filterfalse(lambda f:
+ f in ('-mcet',
+ '-fstack-clash-protection',
+ '-fno-var-tracking-assignments',
+ '-Wno-deprecated-register',
+ '-Wno-gnu-designator') or
+ f.startswith('-fcf-protection'),
+ flags))
else:
return flags
-def monkey_with_compiler(compiler):
- unwrapped_customize(compiler)
- if compiler.compiler_type == 'unix':
- if compiler.compiler[0].find('clang') != -1:
- global clang
- clang = True
- compiler.compiler = filter_unsupported_flags(compiler.compiler)
- compiler.compiler_so = filter_unsupported_flags(
- compiler.compiler_so)
-distutils.sysconfig.customize_compiler = monkey_with_compiler
+def monkey_with_compiler(customize):
+ def patched(compiler):
+ customize(compiler)
+ if compiler.compiler_type != 'unix':
+ return
+ compiler.compiler[1:] = \
+ filter_unsupported_flags(compiler.compiler[0],
+ compiler.compiler[1:])
+ compiler.compiler_so[1:] = \
+ filter_unsupported_flags(compiler.compiler_so[0],
+ compiler.compiler_so[1:])
+ return patched
+
+
+distutils.sysconfig.customize_compiler = \
+ monkey_with_compiler(distutils.sysconfig.customize_compiler)
if not pkgutil.find_loader('setuptools'):
from distutils.core import setup
__version__ = '2.0.0'
-def get_python_flags():
- cflags = {'I': [], 'extras': []}
- ldflags = {'l': [], 'L': [], 'extras': []}
-
- if os.environ.get('VIRTUAL_ENV', None):
- python = "python"
- else:
- python = 'python' + str(sys.version_info.major) + '.' + str(sys.version_info.minor)
-
- python_config = python + '-config'
-
- for cflag in filter_unsupported_flags(subprocess.check_output(
- [python_config, "--cflags"]).strip().decode('utf-8').split()):
- if cflag.startswith('-I'):
- cflags['I'].append(cflag.replace('-I', ''))
- else:
- cflags['extras'].append(cflag)
-
- for ldflag in filter_unsupported_flags(subprocess.check_output(
- [python_config, "--ldflags"]).strip().decode('utf-8').split()):
- if ldflag.startswith('-l'):
- ldflags['l'].append(ldflag.replace('-l', ''))
- if ldflag.startswith('-L'):
- ldflags['L'].append(ldflag.replace('-L', ''))
- else:
- ldflags['extras'].append(ldflag)
-
- return {
- 'cflags': cflags,
- 'ldflags': ldflags
- }
+def get_python_flags(libs):
+ py_libs = sum((libs.split() for libs in
+ distutils.sysconfig.get_config_vars('LIBS', 'SYSLIBS')), [])
+ compiler = new_compiler()
+ distutils.sysconfig.customize_compiler(compiler)
+ return dict(
+ include_dirs=[distutils.sysconfig.get_python_inc()],
+ library_dirs=distutils.sysconfig.get_config_vars('LIBDIR', 'LIBPL'),
+ libraries=libs + [lib.replace('-l', '') for lib in py_libs],
+ extra_compile_args=filter_unsupported_flags(
+ compiler.compiler[0],
+ distutils.sysconfig.get_config_var('CFLAGS').split()),
+ extra_link_args=(distutils.sysconfig.get_config_var('LDFLAGS').split() +
+ distutils.sysconfig.get_config_var('LINKFORSHARED').split()))
def check_sanity():
compiler = new_compiler()
distutils.sysconfig.customize_compiler(compiler)
- if {'MAKEFLAGS', 'MFLAGS', 'MAKELEVEL'}.issubset(set(os.environ.keys())):
+ if 'CEPH_LIBDIR' in os.environ:
# The setup.py has been invoked by a top-level Ceph make.
# Set the appropriate CFLAGS and LDFLAGS
-
compiler.set_include_dirs([os.path.join(CEPH_SRC_DIR, 'include')])
compiler.set_library_dirs([os.environ.get('CEPH_LIBDIR')])
-
try:
compiler.define_macro('_FILE_OFFSET_BITS', '64')
def cythonize(x, **kwargs):
return x
-flags = get_python_flags()
-
setup(
name='rbd',
version=__version__,
Extension(
"rbd",
[source],
- include_dirs=flags['cflags']['I'],
- library_dirs=flags['ldflags']['L'],
- libraries=['rbd', 'rados'] + flags['ldflags']['l'],
- extra_compile_args=flags['cflags']['extras'] + flags['ldflags']['extras'],
+ **get_python_flags(['rbd', 'rados'])
)
],
+ compiler_directives={'language_level': sys.version_info.major},
build_dir=os.environ.get("CYTHON_BUILD_DIR", None),
include_path=[
os.path.join(os.path.dirname(__file__), "..", "rados")