mirror of
https://github.com/ceph/ceph
synced 2025-02-24 11:37:37 +00:00
Merge pull request #33061 from tchaikov/wip-pybind-compiler-flags-patch
pybind: refactor monkey_with_compiler() Reviewed-By: Adam Emersen <aemerson@redhat.com>
This commit is contained in:
commit
957c8a0cf1
@ -9,34 +9,40 @@ import tempfile
|
||||
import textwrap
|
||||
from distutils.ccompiler import new_compiler
|
||||
from distutils.errors import CompileError, LinkError
|
||||
from itertools import filterfalse
|
||||
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') or
|
||||
f == '-fstack-clash-protection' or
|
||||
f == '-fno-var-tracking-assignments' or
|
||||
f == '-Wno-deprecated-register' or
|
||||
f == '-Wno-gnu-designator')]
|
||||
def filter_unsupported_flags(compiler, flags):
|
||||
if 'clang' in compiler:
|
||||
return 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
|
||||
@ -54,11 +60,14 @@ __version__ = '2.0.0'
|
||||
def get_python_flags(libs):
|
||||
py_libs = sum((libs.split() for libs in
|
||||
distutils.sysconfig.get_config_vars('LIBS', 'SYSLIBS')), [])
|
||||
compiler = new_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(distutils.sysconfig.get_config_var('CFLAGS').split()),
|
||||
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()))
|
||||
|
||||
|
@ -1,4 +1,8 @@
|
||||
from __future__ import print_function
|
||||
import distutils.sysconfig
|
||||
from distutils.errors import CompileError, LinkError
|
||||
from distutils.ccompiler import new_compiler
|
||||
from itertools import filterfalse
|
||||
|
||||
import os
|
||||
import pkgutil
|
||||
@ -8,6 +12,38 @@ import sys
|
||||
import tempfile
|
||||
import textwrap
|
||||
|
||||
|
||||
def filter_unsupported_flags(compiler, flags):
|
||||
if 'clang' in compiler:
|
||||
return 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(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
|
||||
from distutils.extension import Extension
|
||||
@ -15,36 +51,9 @@ else:
|
||||
from setuptools import setup
|
||||
from setuptools.extension import Extension
|
||||
|
||||
from distutils.ccompiler import new_compiler
|
||||
from distutils.errors import CompileError, LinkError
|
||||
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') or
|
||||
f == '-fstack-clash-protection' or
|
||||
f == '-fno-var-tracking-assignments' or
|
||||
f == '-Wno-deprecated-register' or
|
||||
f == '-Wno-gnu-designator')]
|
||||
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
|
||||
distutils.sysconfig.customize_compiler = \
|
||||
monkey_with_compiler(distutils.sysconfig.customize_compiler)
|
||||
|
||||
# PEP 440 versioning of the Rados package on PyPI
|
||||
# Bump this version, after every changeset
|
||||
@ -54,11 +63,14 @@ __version__ = '2.0.0'
|
||||
def get_python_flags(libs):
|
||||
py_libs = sum((libs.split() for libs in
|
||||
distutils.sysconfig.get_config_vars('LIBS', 'SYSLIBS')), [])
|
||||
compiler = new_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(distutils.sysconfig.get_config_var('CFLAGS').split()),
|
||||
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()))
|
||||
|
||||
|
@ -9,34 +9,40 @@ import tempfile
|
||||
import textwrap
|
||||
from distutils.ccompiler import new_compiler
|
||||
from distutils.errors import CompileError, LinkError
|
||||
from itertools import filterfalse
|
||||
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') or
|
||||
f == '-fstack-clash-protection' or
|
||||
f == '-fno-var-tracking-assignments' or
|
||||
f == '-Wno-deprecated-register' or
|
||||
f == '-Wno-gnu-designator')]
|
||||
def filter_unsupported_flags(compiler, flags):
|
||||
if 'clang' in compiler:
|
||||
return 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
|
||||
@ -54,11 +60,14 @@ __version__ = '2.0.0'
|
||||
def get_python_flags(libs):
|
||||
py_libs = sum((libs.split() for libs in
|
||||
distutils.sysconfig.get_config_vars('LIBS', 'SYSLIBS')), [])
|
||||
compiler = new_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(distutils.sysconfig.get_config_var('CFLAGS').split()),
|
||||
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()))
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
from __future__ import print_function
|
||||
import distutils.core
|
||||
|
||||
import os
|
||||
import pkgutil
|
||||
@ -11,35 +12,37 @@ from distutils.ccompiler import new_compiler
|
||||
from distutils.errors import CompileError, LinkError
|
||||
import distutils.sysconfig
|
||||
|
||||
unwrapped_customize = distutils.sysconfig.customize_compiler
|
||||
|
||||
clang = False
|
||||
def filter_unsupported_flags(compiler, flags):
|
||||
if 'clang' in compiler:
|
||||
return 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 filter_unsupported_flags(flags):
|
||||
if clang:
|
||||
return [f for f in flags if not (f == '-mcet' or
|
||||
f.startswith('-fcf-protection') or
|
||||
f == '-fstack-clash-protection' or
|
||||
f == '-fno-var-tracking-assignments' or
|
||||
f == '-Wno-deprecated-register' or
|
||||
f == '-Wno-gnu-designator')]
|
||||
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)
|
||||
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
|
||||
|
||||
# See what you made me do?
|
||||
|
||||
distutils.sysconfig.customize_compiler = monkey_with_compiler
|
||||
|
||||
import distutils.core
|
||||
distutils.sysconfig.customize_compiler = \
|
||||
monkey_with_compiler(distutils.sysconfig.customize_compiler)
|
||||
|
||||
if not pkgutil.find_loader('setuptools'):
|
||||
from distutils.core import setup
|
||||
@ -57,11 +60,14 @@ __version__ = '2.0.0'
|
||||
def get_python_flags(libs):
|
||||
py_libs = sum((libs.split() for libs in
|
||||
distutils.sysconfig.get_config_vars('LIBS', 'SYSLIBS')), [])
|
||||
compiler = new_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(distutils.sysconfig.get_config_var('CFLAGS').split()),
|
||||
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()))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user