summarylogtreecommitdiffstats
path: root/0092-distutils-get_versions-fixes.patch
blob: 8a0f671ae8026a27edc5642179113a9d674f042a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
From 985a20ad50a309a528397ec6f43cf15f848c2797 Mon Sep 17 00:00:00 2001
From: Christoph Reiter <reiter.christoph@gmail.com>
Date: Tue, 21 Sep 2021 21:14:31 +0200
Subject: [PATCH 092/N] distutils: get_versions() fixes
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Co-authored-by: Алексей <alexey.pawlow@gmail.com>
Co-authored-by: Christoph Reiter <reiter.christoph@gmail.com>
---
 Lib/distutils/cygwinccompiler.py | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/Lib/distutils/cygwinccompiler.py b/Lib/distutils/cygwinccompiler.py
index 5b281e2..fba3485 100644
--- a/Lib/distutils/cygwinccompiler.py
+++ b/Lib/distutils/cygwinccompiler.py
@@ -56,6 +56,7 @@ 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
 
 def get_msvcr():
     """Include the appropriate MSVC runtime library if Python was built
@@ -371,7 +372,7 @@ def check_config_h():
         return (CONFIG_H_UNCERTAIN,
                 "couldn't read '%s': %s" % (fn, exc.strerror))
 
-RE_VERSION = re.compile(br'(\d+\.\d+(\.\d+)*)')
+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.
@@ -400,7 +401,16 @@ def get_versions():
 
     If not possible it returns None for it.
     """
-    commands = ['gcc -dumpversion', 'ld -v', 'dllwrap --version']
+    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_cygwingcc():
-- 
2.33.0