Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)

python35: fix build on macOS

The upstream patch for distutils does not apply cleanly to Python 3.5's
sources. Fix the patch to make python35 build on macOS.

(cherry picked from commit 0bf2d63366cab1b006366831e581d52f5579090d)

authored by

Matthew Glazar and committed by
Frederik Rietdijk
ad9db2a3 6511fd01

+246 -4
+237
pkgs/development/interpreters/python/cpython/3.5/python-3.x-distutils-C++.patch
··· 1 + Source: https://bugs.python.org/file47046/python-3.x-distutils-C++.patch 2 + --- a/Lib/distutils/cygwinccompiler.py 3 + +++ b/Lib/distutils/cygwinccompiler.py 4 + @@ -125,8 +125,10 @@ 5 + # dllwrap 2.10.90 is buggy 6 + if self.ld_version >= "2.10.90": 7 + self.linker_dll = "gcc" 8 + + self.linker_dll_cxx = "g++" 9 + else: 10 + self.linker_dll = "dllwrap" 11 + + self.linker_dll_cxx = "dllwrap" 12 + 13 + # ld_version >= "2.13" support -shared so use it instead of 14 + # -mdll -static 15 + @@ -140,9 +142,13 @@ 16 + self.set_executables(compiler='gcc -mcygwin -O -Wall', 17 + compiler_so='gcc -mcygwin -mdll -O -Wall', 18 + compiler_cxx='g++ -mcygwin -O -Wall', 19 + + compiler_so_cxx='g++ -mcygwin -mdll -O -Wall', 20 + linker_exe='gcc -mcygwin', 21 + linker_so=('%s -mcygwin %s' % 22 + - (self.linker_dll, shared_option))) 23 + + (self.linker_dll, shared_option)), 24 + + linker_exe_cxx='g++ -mcygwin', 25 + + linker_so_cxx=('%s -mcygwin %s' % 26 + + (self.linker_dll_cxx, shared_option))) 27 + 28 + # cygwin and mingw32 need different sets of libraries 29 + if self.gcc_version == "2.91.57": 30 + @@ -166,8 +172,12 @@ 31 + raise CompileError(msg) 32 + else: # for other files use the C-compiler 33 + try: 34 + - self.spawn(self.compiler_so + cc_args + [src, '-o', obj] + 35 + - extra_postargs) 36 + + if self.detect_language(src) == 'c++': 37 + + self.spawn(self.compiler_so_cxx + cc_args + [src, '-o', obj] + 38 + + extra_postargs) 39 + + else: 40 + + self.spawn(self.compiler_so + cc_args + [src, '-o', obj] + 41 + + extra_postargs) 42 + except DistutilsExecError as msg: 43 + raise CompileError(msg) 44 + 45 + @@ -302,9 +312,14 @@ 46 + self.set_executables(compiler='gcc -O -Wall', 47 + compiler_so='gcc -mdll -O -Wall', 48 + compiler_cxx='g++ -O -Wall', 49 + + compiler_so_cxx='g++ -mdll -O -Wall', 50 + linker_exe='gcc', 51 + linker_so='%s %s %s' 52 + % (self.linker_dll, shared_option, 53 + + entry_point), 54 + + linker_exe_cxx='g++', 55 + + linker_so_cxx='%s %s %s' 56 + + % (self.linker_dll_cxx, shared_option, 57 + entry_point)) 58 + # Maybe we should also append -mthreads, but then the finished 59 + # dlls need another dll (mingwm10.dll see Mingw32 docs) 60 + --- a/Lib/distutils/sysconfig.py 61 + +++ b/Lib/distutils/sysconfig.py 62 + @@ -184,9 +184,11 @@ 63 + _osx_support.customize_compiler(_config_vars) 64 + _config_vars['CUSTOMIZED_OSX_COMPILER'] = 'True' 65 + 66 + - (cc, cxx, opt, cflags, ccshared, ldshared, shlib_suffix, ar, ar_flags) = \ 67 + - get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS', 68 + - 'CCSHARED', 'LDSHARED', 'SHLIB_SUFFIX', 'AR', 'ARFLAGS') 69 + + (cc, cxx, cflags, ccshared, ldshared, ldcxxshared, shlib_suffix, ar, ar_flags) = \ 70 + + get_config_vars('CC', 'CXX', 'CFLAGS', 'CCSHARED', 'LDSHARED', 'LDCXXSHARED', 71 + + 'SHLIB_SUFFIX', 'AR', 'ARFLAGS') 72 + + 73 + + cxxflags = cflags 74 + 75 + if 'CC' in os.environ: 76 + newcc = os.environ['CC'] 77 + @@ -201,19 +204,27 @@ 78 + cxx = os.environ['CXX'] 79 + if 'LDSHARED' in os.environ: 80 + ldshared = os.environ['LDSHARED'] 81 + + if 'LDCXXSHARED' in os.environ: 82 + + ldcxxshared = os.environ['LDCXXSHARED'] 83 + if 'CPP' in os.environ: 84 + cpp = os.environ['CPP'] 85 + else: 86 + cpp = cc + " -E" # not always 87 + if 'LDFLAGS' in os.environ: 88 + ldshared = ldshared + ' ' + os.environ['LDFLAGS'] 89 + + ldcxxshared = ldcxxshared + ' ' + os.environ['LDFLAGS'] 90 + if 'CFLAGS' in os.environ: 91 + - cflags = opt + ' ' + os.environ['CFLAGS'] 92 + + cflags = os.environ['CFLAGS'] 93 + ldshared = ldshared + ' ' + os.environ['CFLAGS'] 94 + + if 'CXXFLAGS' in os.environ: 95 + + cxxflags = os.environ['CXXFLAGS'] 96 + + ldcxxshared = ldcxxshared + ' ' + os.environ['CXXFLAGS'] 97 + if 'CPPFLAGS' in os.environ: 98 + cpp = cpp + ' ' + os.environ['CPPFLAGS'] 99 + cflags = cflags + ' ' + os.environ['CPPFLAGS'] 100 + + cxxflags = cxxflags + ' ' + os.environ['CPPFLAGS'] 101 + ldshared = ldshared + ' ' + os.environ['CPPFLAGS'] 102 + + ldcxxshared = ldcxxshared + ' ' + os.environ['CPPFLAGS'] 103 + if 'AR' in os.environ: 104 + ar = os.environ['AR'] 105 + if 'ARFLAGS' in os.environ: 106 + @@ -222,13 +233,17 @@ 107 + archiver = ar + ' ' + ar_flags 108 + 109 + cc_cmd = cc + ' ' + cflags 110 + + cxx_cmd = cxx + ' ' + cxxflags 111 + compiler.set_executables( 112 + preprocessor=cpp, 113 + compiler=cc_cmd, 114 + compiler_so=cc_cmd + ' ' + ccshared, 115 + - compiler_cxx=cxx, 116 + + compiler_cxx=cxx_cmd, 117 + + compiler_so_cxx=cxx_cmd + ' ' + ccshared, 118 + linker_so=ldshared, 119 + linker_exe=cc, 120 + + linker_so_cxx=ldcxxshared, 121 + + linker_exe_cxx=cxx, 122 + archiver=archiver) 123 + 124 + compiler.shared_lib_extension = shlib_suffix 125 + --- a/Lib/distutils/unixccompiler.py 126 + +++ b/Lib/distutils/unixccompiler.py 127 + @@ -52,14 +52,17 @@ 128 + # are pretty generic; they will probably have to be set by an outsider 129 + # (eg. using information discovered by the sysconfig about building 130 + # Python extensions). 131 + - executables = {'preprocessor' : None, 132 + - 'compiler' : ["cc"], 133 + - 'compiler_so' : ["cc"], 134 + - 'compiler_cxx' : ["cc"], 135 + - 'linker_so' : ["cc", "-shared"], 136 + - 'linker_exe' : ["cc"], 137 + - 'archiver' : ["ar", "-cr"], 138 + - 'ranlib' : None, 139 + + executables = {'preprocessor' : None, 140 + + 'compiler' : ["cc"], 141 + + 'compiler_so' : ["cc"], 142 + + 'compiler_cxx' : ["c++"], 143 + + 'compiler_so_cxx' : ["c++"], 144 + + 'linker_so' : ["cc", "-shared"], 145 + + 'linker_exe' : ["cc"], 146 + + 'linker_so_cxx' : ["c++", "-shared"], 147 + + 'linker_exe_cxx' : ["c++"], 148 + + 'archiver' : ["ar", "-cr"], 149 + + 'ranlib' : None, 150 + } 151 + 152 + if sys.platform[:6] == "darwin": 153 + @@ -108,12 +111,19 @@ 154 + 155 + def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts): 156 + compiler_so = self.compiler_so 157 + + compiler_so_cxx = self.compiler_so_cxx 158 + if sys.platform == 'darwin': 159 + compiler_so = _osx_support.compiler_fixup(compiler_so, 160 + cc_args + extra_postargs) 161 + + compiler_so_cxx = _osx_support.compiler_fixup(compiler_so_cxx, 162 + + cc_args + extra_postargs) 163 + try: 164 + - self.spawn(compiler_so + cc_args + [src, '-o', obj] + 165 + - extra_postargs) 166 + + if self.detect_language(src) == 'c++': 167 + + self.spawn(compiler_so_cxx + cc_args + [src, '-o', obj] + 168 + + extra_postargs) 169 + + else: 170 + + self.spawn(compiler_so + cc_args + [src, '-o', obj] + 171 + + extra_postargs) 172 + except DistutilsExecError as msg: 173 + raise CompileError(msg) 174 + 175 + @@ -171,22 +181,16 @@ 176 + ld_args.extend(extra_postargs) 177 + self.mkpath(os.path.dirname(output_filename)) 178 + try: 179 + - if target_desc == CCompiler.EXECUTABLE: 180 + - linker = self.linker_exe[:] 181 + + if target_lang == "c++": 182 + + if target_desc == CCompiler.EXECUTABLE: 183 + + linker = self.linker_exe_cxx[:] 184 + + else: 185 + + linker = self.linker_so_cxx[:] 186 + else: 187 + - linker = self.linker_so[:] 188 + - if target_lang == "c++" and self.compiler_cxx: 189 + - # skip over environment variable settings if /usr/bin/env 190 + - # is used to set up the linker's environment. 191 + - # This is needed on OSX. Note: this assumes that the 192 + - # normal and C++ compiler have the same environment 193 + - # settings. 194 + - i = 0 195 + - if os.path.basename(linker[0]) == "env": 196 + - i = 1 197 + - while '=' in linker[i]: 198 + - i += 1 199 + - linker[i] = self.compiler_cxx[i] 200 + + if target_desc == CCompiler.EXECUTABLE: 201 + + linker = self.linker_exe[:] 202 + + else: 203 + + linker = self.linker_so[:] 204 + 205 + if sys.platform == 'darwin': 206 + linker = _osx_support.compiler_fixup(linker, ld_args) 207 + --- a/Lib/_osx_support.py 208 + +++ b/Lib/_osx_support.py 209 + @@ -14,13 +14,13 @@ 210 + # configuration variables that may contain universal build flags, 211 + # like "-arch" or "-isdkroot", that may need customization for 212 + # the user environment 213 + -_UNIVERSAL_CONFIG_VARS = ('CFLAGS', 'LDFLAGS', 'CPPFLAGS', 'BASECFLAGS', 214 + - 'BLDSHARED', 'LDSHARED', 'CC', 'CXX', 215 + - 'PY_CFLAGS', 'PY_LDFLAGS', 'PY_CPPFLAGS', 216 + - 'PY_CORE_CFLAGS') 217 + +_UNIVERSAL_CONFIG_VARS = ('CFLAGS', 'CXXFLAGS', 'LDFLAGS', 'CPPFLAGS', 218 + + 'BASECFLAGS', 'BLDSHARED', 'LDSHARED', 'LDCXXSHARED', 219 + + 'CC', 'CXX', 'PY_CFLAGS', 'PY_LDFLAGS', 220 + + 'PY_CPPFLAGS', 'PY_CORE_CFLAGS') 221 + 222 + # configuration variables that may contain compiler calls 223 + -_COMPILER_CONFIG_VARS = ('BLDSHARED', 'LDSHARED', 'CC', 'CXX') 224 + +_COMPILER_CONFIG_VARS = ('BLDSHARED', 'LDSHARED', 'LDCXXSHARED', 'CC', 'CXX') 225 + 226 + # prefix added to original configuration variable names 227 + _INITPRE = '_OSX_SUPPORT_INITIAL_' 228 + --- a/Makefile.pre.in 229 + +++ b/Makefile.pre.in 230 + @@ -538,7 +538,7 @@ 231 + *\ -s*|s*) quiet="-q";; \ 232 + *) quiet="";; \ 233 + esac; \ 234 + - $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \ 235 + + $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' CFLAGS='$(PY_CFLAGS)' \ 236 + _TCLTK_INCLUDES='$(TCLTK_INCLUDES)' _TCLTK_LIBS='$(TCLTK_LIBS)' \ 237 + $(PYTHON_FOR_BUILD) $(srcdir)/setup.py $$quiet build
+9 -4
pkgs/development/interpreters/python/cpython/default.nix
··· 101 101 # Upstream distutils is calling C compiler to compile C++ code, which 102 102 # only works for GCC and Apple Clang. This makes distutils to call C++ 103 103 # compiler when needed. 104 - (fetchpatch { 105 - url = "https://bugs.python.org/file48016/python-3.x-distutils-C++.patch"; 106 - sha256 = "1h18lnpx539h5lfxyk379dxwr8m2raigcjixkf133l4xy3f4bzi2"; 107 - }) 104 + ( 105 + if isPy35 then 106 + ./3.5/python-3.x-distutils-C++.patch 107 + else 108 + fetchpatch { 109 + url = "https://bugs.python.org/file48016/python-3.x-distutils-C++.patch"; 110 + sha256 = "1h18lnpx539h5lfxyk379dxwr8m2raigcjixkf133l4xy3f4bzi2"; 111 + } 112 + ) 108 113 ]; 109 114 110 115 postPatch = ''