]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
build: Allow use of Clang to build Python extensions under Fedora 28
authorAdam C. Emerson <aemerson@redhat.com>
Fri, 4 May 2018 05:31:57 +0000 (01:31 -0400)
committerAdam C. Emerson <aemerson@redhat.com>
Tue, 8 May 2018 17:57:58 +0000 (13:57 -0400)
Fedora builds Python with hardening flags that are unsupported by
Clang. Python insists on building extensions with all the flags it was
given, not just ones relevant to finding Python libraries and
includes.

Ended up monkey patching customize_compiler to pull out the offending
flags when Clang is in use.

Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
src/pybind/cephfs/setup.py
src/pybind/rados/setup.py
src/pybind/rbd/setup.py
src/pybind/rgw/setup.py

index 6533f41ee5332677afac293aa52f3b5f7c1f5b09..1f95005537ca5ffff99e9264a22ad7b52932fd42 100755 (executable)
@@ -9,7 +9,30 @@ import tempfile
 import textwrap
 from distutils.ccompiler import new_compiler
 from distutils.errors import CompileError, LinkError
-from distutils.sysconfig import customize_compiler
+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'))]
+    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
 
 if not pkgutil.find_loader('setuptools'):
     from distutils.core import setup
@@ -35,17 +58,15 @@ def get_python_flags():
 
     python_config = python + '-config'
 
-    for cflag in subprocess.check_output(
-            [python_config, "--cflags"]
-    ).strip().decode('utf-8').split():
+    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 subprocess.check_output(
-            [python_config, "--ldflags"]
-    ).strip().decode('utf-8').split():
+    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'):
@@ -86,7 +107,7 @@ def check_sanity():
         fp.write(dummy_prog)
 
     compiler = new_compiler()
-    customize_compiler(compiler)
+    distutils.sysconfig.customize_compiler(compiler)
 
     if {'MAKEFLAGS', 'MFLAGS', 'MAKELEVEL'}.issubset(set(os.environ.keys())):
         # The setup.py has been invoked by a top-level Ceph make.
index ef7c307c737ae488aee407767bcd73857d355303..c708c3e145df859f792359b06f5594bfc073e826 100755 (executable)
@@ -17,7 +17,30 @@ else:
 
 from distutils.ccompiler import new_compiler
 from distutils.errors import CompileError, LinkError
-from distutils.sysconfig import customize_compiler
+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'))]
+    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
 
 # PEP 440 versioning of the Rados package on PyPI
 # Bump this version, after every changeset
@@ -35,17 +58,15 @@ def get_python_flags():
 
     python_config = python + '-config'
 
-    for cflag in subprocess.check_output(
-            [python_config, "--cflags"]
-    ).strip().decode('utf-8').split():
+    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 subprocess.check_output(
-            [python_config, "--ldflags"]
-    ).strip().decode('utf-8').split():
+    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'):
@@ -85,7 +106,7 @@ def check_sanity():
         fp.write(dummy_prog)
 
     compiler = new_compiler()
-    customize_compiler(compiler)
+    distutils.sysconfig.customize_compiler(compiler)
 
     if {'MAKEFLAGS', 'MFLAGS', 'MAKELEVEL'}.issubset(set(os.environ.keys())):
         # The setup.py has been invoked by a top-level Ceph make.
index bcf96f261cf17b1a30c4ac62af337b0786f9947b..8dd5c12a8ece15385e0d0ed079b292a4222a218e 100755 (executable)
@@ -9,7 +9,30 @@ import tempfile
 import textwrap
 from distutils.ccompiler import new_compiler
 from distutils.errors import CompileError, LinkError
-from distutils.sysconfig import customize_compiler
+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'))]
+    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
 
 if not pkgutil.find_loader('setuptools'):
     from distutils.core import setup
@@ -35,17 +58,15 @@ def get_python_flags():
 
     python_config = python + '-config'
 
-    for cflag in subprocess.check_output(
-            [python_config, "--cflags"]
-    ).strip().decode('utf-8').split():
+    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 subprocess.check_output(
-            [python_config, "--ldflags"]
-    ).strip().decode('utf-8').split():
+    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'):
@@ -85,7 +106,7 @@ def check_sanity():
         fp.write(dummy_prog)
 
     compiler = new_compiler()
-    customize_compiler(compiler)
+    distutils.sysconfig.customize_compiler(compiler)
 
     if {'MAKEFLAGS', 'MFLAGS', 'MAKELEVEL'}.issubset(set(os.environ.keys())):
         # The setup.py has been invoked by a top-level Ceph make.
index f14f30c89660331cea556fe6f40ecfd0956730f3..4ee4f491ba51e4ada2dadff6d8d8e574cd539e0c 100755 (executable)
@@ -9,7 +9,33 @@ import tempfile
 import textwrap
 from distutils.ccompiler import new_compiler
 from distutils.errors import CompileError, LinkError
-from distutils.sysconfig import customize_compiler
+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'))]
+    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)
+
+# See what you made me do?
+
+distutils.sysconfig.customize_compiler = monkey_with_compiler
+
+import distutils.core
 
 if not pkgutil.find_loader('setuptools'):
     from distutils.core import setup
@@ -23,7 +49,6 @@ else:
 
 __version__ = '2.0.0'
 
-
 def get_python_flags():
     cflags = {'I': [], 'extras': []}
     ldflags = {'l': [], 'L': [], 'extras': []}
@@ -35,17 +60,15 @@ def get_python_flags():
 
     python_config = python + '-config'
 
-    for cflag in subprocess.check_output(
-            [python_config, "--cflags"]
-    ).strip().decode('utf-8').split():
+    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 subprocess.check_output(
-            [python_config, "--ldflags"]
-    ).strip().decode('utf-8').split():
+    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'):
@@ -85,7 +108,7 @@ def check_sanity():
         fp.write(dummy_prog)
 
     compiler = new_compiler()
-    customize_compiler(compiler)
+    distutils.sysconfig.customize_compiler(compiler)
 
     if {'MAKEFLAGS', 'MFLAGS', 'MAKELEVEL'}.issubset(set(os.environ.keys())):
         # The setup.py has been invoked by a top-level Ceph make.