From c68593455698f3d8d498b7c0f35b4e0b1bf9d0c7 Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Wed, 10 Nov 2021 08:19:25 +0100 Subject: [PATCH] Update Python --- .../0118-Prefer-sysconfig.python_build.patch | 25 ++ ...move-checks-for-ancient-gcc-binutils.patch | 260 ++++++++++++++++++ ...CC-env-var-before-passing-to-subproc.patch | 36 +++ mingw-w64-python/PKGBUILD | 17 +- 4 files changed, 334 insertions(+), 4 deletions(-) create mode 100644 mingw-w64-python/0118-Prefer-sysconfig.python_build.patch create mode 100644 mingw-w64-python/0119-distutils-remove-checks-for-ancient-gcc-binutils.patch create mode 100644 mingw-w64-python/0120-distutils-split-CC-env-var-before-passing-to-subproc.patch diff --git a/mingw-w64-python/0118-Prefer-sysconfig.python_build.patch b/mingw-w64-python/0118-Prefer-sysconfig.python_build.patch new file mode 100644 index 0000000000..19fc7c6ea8 --- /dev/null +++ b/mingw-w64-python/0118-Prefer-sysconfig.python_build.patch @@ -0,0 +1,25 @@ +From ac9f30ac5c47c7f54306c1f8fc5d4d05b9d78386 Mon Sep 17 00:00:00 2001 +From: Long Nguyen +Date: Fri, 1 Oct 2021 07:28:36 +0700 +Subject: [PATCH 118/N] Prefer sysconfig.python_build + +--- + Lib/distutils/command/build_ext.py | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/Lib/distutils/command/build_ext.py b/Lib/distutils/command/build_ext.py +index 1598735..82a21d2 100644 +--- a/Lib/distutils/command/build_ext.py ++++ b/Lib/distutils/command/build_ext.py +@@ -219,7 +219,7 @@ class build_ext(Command): + # For extensions under Cygwin, Python's library directory must be + # appended to library_dirs + if sys.platform[:6] == 'cygwin' or self.plat_name.startswith(('mingw')): +- if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")): ++ if not sysconfig.python_build: + # building third party extensions + config_dir_name = os.path.basename(sysconfig.get_config_var('LIBPL')) + self.library_dirs.append(os.path.join(sys.prefix, "lib", +-- +2.33.0 + diff --git a/mingw-w64-python/0119-distutils-remove-checks-for-ancient-gcc-binutils.patch b/mingw-w64-python/0119-distutils-remove-checks-for-ancient-gcc-binutils.patch new file mode 100644 index 0000000000..4d7cd687bf --- /dev/null +++ b/mingw-w64-python/0119-distutils-remove-checks-for-ancient-gcc-binutils.patch @@ -0,0 +1,260 @@ +From 8ec77b61a8c33a8096882be9edfe0b23c4c62e2c Mon Sep 17 00:00:00 2001 +From: Christoph Reiter +Date: Sun, 7 Nov 2021 23:06:13 +0100 +Subject: [PATCH 119/N] distutils: remove checks for ancient gcc/binutils + +The versions checked here are 20 years old. Also dllwrap +has started to emit a deprecation warning in the latest release +spamming the build logs. + +Fixes #54 +--- + Lib/distutils/cygwinccompiler.py | 123 +++----------------- + Lib/distutils/tests/test_cygwinccompiler.py | 36 +----- + 2 files changed, 15 insertions(+), 144 deletions(-) + +diff --git a/Lib/distutils/cygwinccompiler.py b/Lib/distutils/cygwinccompiler.py +index 6a40e80..2804f69 100644 +--- a/Lib/distutils/cygwinccompiler.py ++++ b/Lib/distutils/cygwinccompiler.py +@@ -50,15 +50,13 @@ cygwin in no-cygwin mode). + import os + import sys + import copy +-import re + + from distutils.unixccompiler import UnixCCompiler + from distutils.file_util import write_file + from distutils.errors import (DistutilsExecError, CCompilerError, + CompileError, UnknownFileError) +-from distutils.version import LooseVersion + from distutils.spawn import find_executable +-from subprocess import Popen, PIPE, check_output ++from subprocess import Popen, check_output + + def get_msvcr(): + """Include the appropriate MSVC runtime library if Python was built +@@ -115,33 +113,8 @@ class CygwinCCompiler(UnixCCompiler): + self.cc = os.environ.get('CC', 'gcc') + self.cxx = os.environ.get('CXX', 'g++') + +- if ('gcc' in self.cc): # Start gcc workaround +- self.gcc_version, self.ld_version, self.dllwrap_version = \ +- get_versions() +- self.debug_print(self.compiler_type + ": gcc %s, ld %s, dllwrap %s\n" % +- (self.gcc_version, +- self.ld_version, +- self.dllwrap_version) ) +- +- # ld_version >= "2.10.90" and < "2.13" should also be able to use +- # gcc -mdll instead of dllwrap +- # Older dllwraps had own version numbers, newer ones use the +- # same as the rest of binutils ( also ld ) +- # dllwrap 2.10.90 is buggy +- if self.ld_version >= "2.10.90": +- self.linker_dll = self.cc +- else: +- self.linker_dll = "dllwrap" +- +- # ld_version >= "2.13" support -shared so use it instead of +- # -mdll -static +- if self.ld_version >= "2.13": +- shared_option = "-shared" +- else: +- shared_option = "-mdll -static" +- else: # Assume linker is up to date +- self.linker_dll = self.cc +- shared_option = "-shared" ++ self.linker_dll = self.cc ++ shared_option = "-shared" + + self.set_executables(compiler='%s -mcygwin -O -Wall' % self.cc, + compiler_so='%s -mcygwin -mdll -O -Wall' % self.cc, +@@ -150,17 +123,9 @@ class CygwinCCompiler(UnixCCompiler): + linker_so=('%s -mcygwin %s' % + (self.linker_dll, shared_option))) + +- # cygwin and mingw32 need different sets of libraries +- if ('gcc' in self.cc and self.gcc_version == "2.91.57"): +- # cygwin shouldn't need msvcrt, but without the dlls will crash +- # (gcc version 2.91.57) -- perhaps something about initialization +- self.dll_libraries=["msvcrt"] +- self.warn( +- "Consider upgrading to a newer version of gcc") +- else: +- # Include the appropriate MSVC runtime library if Python was built +- # with MSVC 7.0 or later. +- self.dll_libraries = get_msvcr() ++ # Include the appropriate MSVC runtime library if Python was built ++ # with MSVC 7.0 or later. ++ self.dll_libraries = get_msvcr() + + def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts): + """Compiles the source by spawning GCC and windres if needed.""" +@@ -244,24 +209,17 @@ class CygwinCCompiler(UnixCCompiler): + + # next add options for def-file and to creating import libraries + +- # dllwrap uses different options than gcc/ld +- if self.linker_dll == "dllwrap": +- extra_preargs.extend(["--output-lib", lib_file]) +- # for dllwrap we have to use a special option +- extra_preargs.extend(["--def", def_file]) +- # we use gcc/ld here and can be sure ld is >= 2.9.10 +- else: +- # doesn't work: bfd_close build\...\libfoo.a: Invalid operation +- #extra_preargs.extend(["-Wl,--out-implib,%s" % lib_file]) +- # for gcc/ld the def-file is specified as any object files +- objects.append(def_file) ++ # doesn't work: bfd_close build\...\libfoo.a: Invalid operation ++ #extra_preargs.extend(["-Wl,--out-implib,%s" % lib_file]) ++ # for gcc/ld the def-file is specified as any object files ++ objects.append(def_file) + + #end: if ((export_symbols is not None) and + # (target_desc != self.EXECUTABLE or self.linker_dll == "gcc")): + + # who wants symbols and a many times larger output file + # should explicitly switch the debug mode on +- # otherwise we let dllwrap/ld strip the output file ++ # otherwise we let ld strip the output file + # (On my machine: 10KiB < stripped_file < ??100KiB + # unstripped_file = stripped_file + XXX KiB + # ( XXX=254 for a typical python extension)) +@@ -314,19 +272,7 @@ class Mingw32CCompiler(CygwinCCompiler): + + CygwinCCompiler.__init__ (self, verbose, dry_run, force) + +- # ld_version >= "2.13" support -shared so use it instead of +- # -mdll -static +- if ('gcc' in self.cc and self.ld_version < "2.13"): +- shared_option = "-mdll -static" +- else: +- shared_option = "-shared" +- +- # A real mingw32 doesn't need to specify a different entry point, +- # but cygwin 2.91.57 in no-cygwin-mode needs it. +- if ('gcc' in self.cc and self.gcc_version <= "2.91.57"): +- entry_point = '--entry _DllMain@12' +- else: +- entry_point = '' ++ shared_option = "-shared" + + if is_cygwincc(self.cc): + raise CCompilerError( +@@ -336,9 +282,8 @@ class Mingw32CCompiler(CygwinCCompiler): + compiler_so='%s -mdll -O2 -Wall' % self.cc, + compiler_cxx='%s -O2 -Wall' % self.cxx, + linker_exe='%s' % self.cc, +- linker_so='%s %s %s' +- % (self.linker_dll, shared_option, +- entry_point)) ++ linker_so='%s %s' ++ % (self.linker_dll, shared_option)) + # Maybe we should also append -mthreads, but then the finished + # dlls need another dll (mingwm10.dll see Mingw32 docs) + # (-mthreads: Support thread-safe exception handling on `Mingw32') +@@ -405,46 +350,6 @@ def check_config_h(): + return (CONFIG_H_UNCERTAIN, + "couldn't read '%s': %s" % (fn, exc.strerror)) + +-RE_VERSION = re.compile(br'[\D\s]*(\d+\.\d+(\.\d+)*)[\D\s]*') +- +-def _find_exe_version(cmd): +- """Find the version of an executable by running `cmd` in the shell. +- +- If the command is not found, or the output does not match +- `RE_VERSION`, returns None. +- """ +- executable = cmd.split()[0] +- if find_executable(executable) is None: +- return None +- from subprocess import Popen, PIPE +- out = Popen(cmd, shell=True, stdout=PIPE).stdout +- try: +- out_string = out.read() +- finally: +- out.close() +- result = RE_VERSION.search(out_string) +- if result is None: +- return None +- # LooseVersion works with strings +- # so we need to decode our bytes +- return LooseVersion(result.group(1).decode()) +- +-def get_versions(): +- """ Try to find out the versions of gcc, ld and dllwrap. +- +- If not possible it returns None for it. +- """ +- gcc = os.environ.get('CC') or 'gcc' +- ld = 'ld' +- out = Popen(gcc+' --print-prog-name ld', shell=True, stdout=PIPE).stdout +- try: +- ld = test=str(out.read(),encoding='utf-8').strip() +- finally: +- out.close() +- dllwrap = os.environ.get('DLLWRAP') or 'dllwrap' +- # MinGW64 doesn't have i686-w64-mingw32-ld, so instead we ask gcc. +- commands = [gcc+' -dumpversion', ld+' -v', dllwrap+' --version'] +- return tuple([_find_exe_version(cmd) for cmd in commands]) + + def is_cygwincc(cc): + '''Try to determine if the compiler that would be used is from cygwin.''' +diff --git a/Lib/distutils/tests/test_cygwinccompiler.py b/Lib/distutils/tests/test_cygwinccompiler.py +index 9dc869d..f525ab4 100644 +--- a/Lib/distutils/tests/test_cygwinccompiler.py ++++ b/Lib/distutils/tests/test_cygwinccompiler.py +@@ -8,7 +8,7 @@ from test.support import run_unittest + from distutils import cygwinccompiler + from distutils.cygwinccompiler import (check_config_h, + CONFIG_H_OK, CONFIG_H_NOTOK, +- CONFIG_H_UNCERTAIN, get_versions, ++ CONFIG_H_UNCERTAIN, + get_msvcr) + from distutils.tests import support + +@@ -81,40 +81,6 @@ class CygwinCCompilerTestCase(support.TempdirManager, + self.write_file(self.python_h, 'xxx __GNUC__ xxx') + self.assertEqual(check_config_h()[0], CONFIG_H_OK) + +- def test_get_versions(self): +- +- # get_versions calls distutils.spawn.find_executable on +- # 'gcc', 'ld' and 'dllwrap' +- self.assertEqual(get_versions(), (None, None, None)) +- +- # Let's fake we have 'gcc' and it returns '3.4.5' +- self._exes['gcc'] = b'gcc (GCC) 3.4.5 (mingw special)\nFSF' +- res = get_versions() +- self.assertEqual(str(res[0]), '3.4.5') +- +- # and let's see what happens when the version +- # doesn't match the regular expression +- # (\d+\.\d+(\.\d+)*) +- self._exes['gcc'] = b'very strange output' +- res = get_versions() +- self.assertEqual(res[0], None) +- +- # same thing for ld +- self._exes['ld'] = b'GNU ld version 2.17.50 20060824' +- res = get_versions() +- self.assertEqual(str(res[1]), '2.17.50') +- self._exes['ld'] = b'@(#)PROGRAM:ld PROJECT:ld64-77' +- res = get_versions() +- self.assertEqual(res[1], None) +- +- # and dllwrap +- self._exes['dllwrap'] = b'GNU dllwrap 2.17.50 20060824\nFSF' +- res = get_versions() +- self.assertEqual(str(res[2]), '2.17.50') +- self._exes['dllwrap'] = b'Cheese Wrap' +- res = get_versions() +- self.assertEqual(res[2], None) +- + def test_get_msvcr(self): + + # none +-- +2.33.0 + diff --git a/mingw-w64-python/0120-distutils-split-CC-env-var-before-passing-to-subproc.patch b/mingw-w64-python/0120-distutils-split-CC-env-var-before-passing-to-subproc.patch new file mode 100644 index 0000000000..a37e703902 --- /dev/null +++ b/mingw-w64-python/0120-distutils-split-CC-env-var-before-passing-to-subproc.patch @@ -0,0 +1,36 @@ +From 8736112bab36bc8f0612f33237f64473640ff3b8 Mon Sep 17 00:00:00 2001 +From: Christoph Reiter +Date: Sun, 7 Nov 2021 23:12:10 +0100 +Subject: [PATCH 120/N] distutils: split CC env var before passing to + subprocess + +In case CC="ccache gcc" then subprocess would interpret it as one command +and fail to find it. Instead split the command line into separate arguments. + +Fixes #53 +--- + Lib/distutils/cygwinccompiler.py | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/Lib/distutils/cygwinccompiler.py b/Lib/distutils/cygwinccompiler.py +index 2804f69..6e22555 100644 +--- a/Lib/distutils/cygwinccompiler.py ++++ b/Lib/distutils/cygwinccompiler.py +@@ -50,6 +50,7 @@ cygwin in no-cygwin mode). + import os + import sys + import copy ++import shlex + + from distutils.unixccompiler import UnixCCompiler + from distutils.file_util import write_file +@@ -353,5 +354,5 @@ def check_config_h(): + + def is_cygwincc(cc): + '''Try to determine if the compiler that would be used is from cygwin.''' +- out_string = check_output([cc, '-dumpmachine']) ++ out_string = check_output(shlex.split(cc) + ['-dumpmachine']) + return out_string.strip().endswith(b'cygwin') +-- +2.33.0 + diff --git a/mingw-w64-python/PKGBUILD b/mingw-w64-python/PKGBUILD index 87bb52fd66..b678fc4964 100644 --- a/mingw-w64-python/PKGBUILD +++ b/mingw-w64-python/PKGBUILD @@ -22,7 +22,7 @@ else pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}${_pybasever}") fi pkgver=${_pybasever}.7 -pkgrel=2 +pkgrel=3 pkgdesc="A high-level scripting language (mingw-w64)" arch=('any') mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64') @@ -164,7 +164,10 @@ source=("https://www.python.org/ftp/python/${pkgver%rc?}/Python-${pkgver}.tar.xz 0114-Commit-regenerated-importlib.patch 0115-CI-test-the-build-and-add-some-mingw-specific-tests.patch 0116-decimal-backport-build-fixes.patch - 0117-smoketests-test-that-_decimal-exists.patch) + 0117-smoketests-test-that-_decimal-exists.patch + 0118-Prefer-sysconfig.python_build.patch + 0119-distutils-remove-checks-for-ancient-gcc-binutils.patch + 0120-distutils-split-CC-env-var-before-passing-to-subproc.patch) # Helper macros to help make tasks easier # apply_patch_with_msg() { @@ -294,7 +297,10 @@ prepare() { 0114-Commit-regenerated-importlib.patch \ 0115-CI-test-the-build-and-add-some-mingw-specific-tests.patch \ 0116-decimal-backport-build-fixes.patch \ - 0117-smoketests-test-that-_decimal-exists.patch + 0117-smoketests-test-that-_decimal-exists.patch \ + 0118-Prefer-sysconfig.python_build.patch \ + 0119-distutils-remove-checks-for-ancient-gcc-binutils.patch \ + 0120-distutils-split-CC-env-var-before-passing-to-subproc.patch autoreconf -vfi } @@ -507,4 +513,7 @@ sha256sums=('f8145616e68c00041d1a6399b76387390388f8359581abc24432bb969b5e3c57' '14251dcc7b776b2640941f675be4449addb598537b522c4e574f9a4bc37c65c1' 'e4d481bc25f6386c6da99e2cbe058b21bc0c68bf8f01c73d3adf60e98f5a506d' '0e0766e3aece0a9cfa8e4e0e6592d6f5082ffc686b6b195a3fdb942b5b24ec29' - '169b29cb4eb9177938d66b99234a83d5efcc5b0b759d4e1b9ef2acb357e11a15') + '169b29cb4eb9177938d66b99234a83d5efcc5b0b759d4e1b9ef2acb357e11a15' + 'ec20783cbc4aeae655b89231576db46adccec6d093fbc801e1c55e18f5a51430' + '5eb1e6ef13febff71607a0727996f405c7ef5fbf2ee6a434ebed9f9eaf6cd109' + 'd971e1ab6e69ec44780bc264aa499f7fcd11500f77d90261519c67a1131d8c7b')