Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Lib/distutils/unixccompiler.py

    r10 r391  
    1414"""
    1515
    16 __revision__ = "$Id: unixccompiler.py 77378 2010-01-08 23:48:37Z tarek.ziade $"
    17 
    18 import os, sys
     16__revision__ = "$Id$"
     17
     18import os, sys, re
    1919from types import StringType, NoneType
    2020
     
    2626     DistutilsExecError, CompileError, LibError, LinkError
    2727from distutils import log
     28
     29if sys.platform == 'darwin':
     30    import _osx_support
    2831
    2932# XXX Things not currently handled:
     
    4245#     options and carry on.
    4346
    44 def _darwin_compiler_fixup(compiler_so, cc_args):
    45     """
    46     This function will strip '-isysroot PATH' and '-arch ARCH' from the
    47     compile flags if the user has specified one them in extra_compile_flags.
    48 
    49     This is needed because '-arch ARCH' adds another architecture to the
    50     build, without a way to remove an architecture. Furthermore GCC will
    51     barf if multiple '-isysroot' arguments are present.
    52     """
    53     stripArch = stripSysroot = 0
    54 
    55     compiler_so = list(compiler_so)
    56     kernel_version = os.uname()[2] # 8.4.3
    57     major_version = int(kernel_version.split('.')[0])
    58 
    59     if major_version < 8:
    60         # OSX before 10.4.0, these don't support -arch and -isysroot at
    61         # all.
    62         stripArch = stripSysroot = True
    63     else:
    64         stripArch = '-arch' in cc_args
    65         stripSysroot = '-isysroot' in cc_args
    66 
    67     if stripArch or 'ARCHFLAGS' in os.environ:
    68         while 1:
    69             try:
    70                 index = compiler_so.index('-arch')
    71                 # Strip this argument and the next one:
    72                 del compiler_so[index:index+2]
    73             except ValueError:
    74                 break
    75 
    76     if 'ARCHFLAGS' in os.environ and not stripArch:
    77         # User specified different -arch flags in the environ,
    78         # see also distutils.sysconfig
    79         compiler_so = compiler_so + os.environ['ARCHFLAGS'].split()
    80 
    81     if stripSysroot:
    82         try:
    83             index = compiler_so.index('-isysroot')
    84             # Strip this argument and the next one:
    85             del compiler_so[index:index+2]
    86         except ValueError:
    87             pass
    88 
    89     # Check if the SDK that is used during compilation actually exists,
    90     # the universal build requires the usage of a universal SDK and not all
    91     # users have that installed by default.
    92     sysroot = None
    93     if '-isysroot' in cc_args:
    94         idx = cc_args.index('-isysroot')
    95         sysroot = cc_args[idx+1]
    96     elif '-isysroot' in compiler_so:
    97         idx = compiler_so.index('-isysroot')
    98         sysroot = compiler_so[idx+1]
    99 
    100     if sysroot and not os.path.isdir(sysroot):
    101         log.warn("Compiling with an SDK that doesn't seem to exist: %s",
    102                 sysroot)
    103         log.warn("Please check your Xcode installation")
    104 
    105     return compiler_so
    10647
    10748class UnixCCompiler(CCompiler):
     
    173114        compiler_so = self.compiler_so
    174115        if sys.platform == 'darwin':
    175             compiler_so = _darwin_compiler_fixup(compiler_so, cc_args + extra_postargs)
     116            compiler_so = _osx_support.compiler_fixup(compiler_so,
     117                                                    cc_args + extra_postargs)
    176118        try:
    177119            self.spawn(compiler_so + cc_args + [src, '-o', obj] +
     
    252194
    253195                if sys.platform == 'darwin':
    254                     linker = _darwin_compiler_fixup(linker, ld_args)
     196                    linker = _osx_support.compiler_fixup(linker, ld_args)
    255197
    256198                self.spawn(linker + ld_args)
     
    306248        static_f = self.library_filename(lib, lib_type='static')
    307249
     250        if sys.platform == 'darwin':
     251            # On OSX users can specify an alternate SDK using
     252            # '-isysroot', calculate the SDK root if it is specified
     253            # (and use it further on)
     254            cflags = sysconfig.get_config_var('CFLAGS')
     255            m = re.search(r'-isysroot\s+(\S+)', cflags)
     256            if m is None:
     257                sysroot = '/'
     258            else:
     259                sysroot = m.group(1)
     260
     261
     262
    308263        for dir in dirs:
    309264            shared = os.path.join(dir, shared_f)
    310265            dylib = os.path.join(dir, dylib_f)
    311266            static = os.path.join(dir, static_f)
     267
     268            if sys.platform == 'darwin' and (
     269                dir.startswith('/System/') or (
     270                dir.startswith('/usr/') and not dir.startswith('/usr/local/'))):
     271
     272                shared = os.path.join(sysroot, dir[1:], shared_f)
     273                dylib = os.path.join(sysroot, dir[1:], dylib_f)
     274                static = os.path.join(sysroot, dir[1:], static_f)
     275
    312276            # We're second-guessing the linker here, with not much hard
    313277            # data to go on: GCC seems to prefer the shared library, so I'm
Note: See TracChangeset for help on using the changeset viewer.