[PATCH] setup.py: fix C extension compilation issue with OS X 10.9 and Xcode 5.1

Kent Frazier kentfrazier at gmail.com
Tue Apr 15 16:33:41 CDT 2014


# HG changeset patch
# User Kent Frazier <kentfrazier at gmail.com>
# Date 1397593632 14400
#      Tue Apr 15 16:27:12 2014 -0400
# Node ID 7e50af3ecb436f3dcd8f856e6d244d458675a62c
# Parent  76f68595ff8e5616a79dd79e962a97cc9ba58713
setup.py: fix C extension compilation issue with OS X 10.9 and Xcode 5.1

diff -r 76f68595ff8e -r 7e50af3ecb43 setup.py
--- a/setup.py	Mon Apr 14 15:14:02 2014 -0400
+++ b/setup.py	Tue Apr 15 16:27:12 2014 -0400
@@ -61,6 +61,7 @@
             "Couldn't import standard bz2 (incomplete Python install).")
 
 import os, subprocess, time
+import re
 import shutil
 import tempfile
 from distutils import log
@@ -73,7 +74,7 @@
 from distutils.spawn import spawn, find_executable
 from distutils import cygwinccompiler
 from distutils.errors import CCompilerError, DistutilsExecError
-from distutils.sysconfig import get_python_inc
+from distutils.sysconfig import get_python_inc, get_config_var
 from distutils.version import StrictVersion
 
 convert2to3 = '--c2to3' in sys.argv
@@ -505,22 +506,36 @@
     setupversion = version.split('+', 1)[0]
 
 if sys.platform == 'darwin' and os.path.exists('/usr/bin/xcodebuild'):
-    # XCode 4.0 dropped support for ppc architecture, which is hardcoded in
-    # distutils.sysconfig
     version = runcmd(['/usr/bin/xcodebuild', '-version'], {})[0].splitlines()
     if version:
         version = version[0]
         xcode4 = (version.startswith('Xcode') and
                   StrictVersion(version.split()[1]) >= StrictVersion('4.0'))
+        xcode51 = re.match(r'^Xcode\s+5\.1\.', version) is not None
     else:
         # xcodebuild returns empty on OS X Lion with XCode 4.3 not
         # installed, but instead with only command-line tools. Assume
         # that only happens on >= Lion, thus no PPC support.
         xcode4 = True
+        xcode51 = False
 
+    # XCode 4.0 dropped support for ppc architecture, which is hardcoded in
+    # distutils.sysconfig
     if xcode4:
         os.environ['ARCHFLAGS'] = ''
 
+    # XCode 5.1 changes clang such that it now fails to compile if the
+    # -mno-fused-madd flag is passed, but the version of Python shipped with
+    # OS X 10.9 Mavericks includes this flag. This causes problems in all
+    # C extension modules, and a bug has been filed upstream at
+    # http://bugs.python.org/issue21244. We also need to patch this here
+    # so Mercurial can continue to compile in the meantime.
+    if xcode51:
+        cflags = get_config_var('CFLAGS')
+        if re.search(r'-mno-fused-madd\b', cflags) is not None:
+            os.environ['CFLAGS'] = (
+                os.environ.get('CFLAGS', '') + ' -Qunused-arguments')
+
 setup(name='mercurial',
       version=setupversion,
       author='Matt Mackall and many others',


More information about the Mercurial-devel mailing list