Skip to content

Commit 2f7362b

Browse files
lazkaAlexpux
andcommitted
distutils: get_versions() fixes
Co-authored-by: Алексей <[email protected]> Co-authored-by: Christoph Reiter <[email protected]>
1 parent ec0bd2b commit 2f7362b

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

Lib/distutils/cygwinccompiler.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
CompileError, UnknownFileError)
5757
from distutils.version import LooseVersion
5858
from distutils.spawn import find_executable
59+
from subprocess import Popen, PIPE, check_output
5960

6061
def get_msvcr():
6162
"""Include the appropriate MSVC runtime library if Python was built
@@ -371,7 +372,7 @@ def check_config_h():
371372
return (CONFIG_H_UNCERTAIN,
372373
"couldn't read '%s': %s" % (fn, exc.strerror))
373374

374-
RE_VERSION = re.compile(br'(\d+\.\d+(\.\d+)*)')
375+
RE_VERSION = re.compile(br'[\D\s]*(\d+\.\d+(\.\d+)*)[\D\s]*')
375376

376377
def _find_exe_version(cmd):
377378
"""Find the version of an executable by running `cmd` in the shell.
@@ -400,7 +401,16 @@ def get_versions():
400401
401402
If not possible it returns None for it.
402403
"""
403-
commands = ['gcc -dumpversion', 'ld -v', 'dllwrap --version']
404+
gcc = os.environ.get('CC') or 'gcc'
405+
ld = 'ld'
406+
out = Popen(gcc+' --print-prog-name ld', shell=True, stdout=PIPE).stdout
407+
try:
408+
ld = test=str(out.read(),encoding='utf-8').strip()
409+
finally:
410+
out.close()
411+
dllwrap = os.environ.get('DLLWRAP') or 'dllwrap'
412+
# MinGW64 doesn't have i686-w64-mingw32-ld, so instead we ask gcc.
413+
commands = [gcc+' -dumpversion', ld+' -v', dllwrap+' --version']
404414
return tuple([_find_exe_version(cmd) for cmd in commands])
405415

406416
def is_cygwingcc():

0 commit comments

Comments
 (0)