Skip to content

Commit 8ec77b6

Browse files
committed
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 python#54
1 parent ac9f30a commit 8ec77b6

File tree

2 files changed

+15
-144
lines changed

2 files changed

+15
-144
lines changed

Lib/distutils/cygwinccompiler.py

Lines changed: 14 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,13 @@
5050
import os
5151
import sys
5252
import copy
53-
import re
5453

5554
from distutils.unixccompiler import UnixCCompiler
5655
from distutils.file_util import write_file
5756
from distutils.errors import (DistutilsExecError, CCompilerError,
5857
CompileError, UnknownFileError)
59-
from distutils.version import LooseVersion
6058
from distutils.spawn import find_executable
61-
from subprocess import Popen, PIPE, check_output
59+
from subprocess import Popen, check_output
6260

6361
def get_msvcr():
6462
"""Include the appropriate MSVC runtime library if Python was built
@@ -115,33 +113,8 @@ def __init__(self, verbose=0, dry_run=0, force=0):
115113
self.cc = os.environ.get('CC', 'gcc')
116114
self.cxx = os.environ.get('CXX', 'g++')
117115

118-
if ('gcc' in self.cc): # Start gcc workaround
119-
self.gcc_version, self.ld_version, self.dllwrap_version = \
120-
get_versions()
121-
self.debug_print(self.compiler_type + ": gcc %s, ld %s, dllwrap %s\n" %
122-
(self.gcc_version,
123-
self.ld_version,
124-
self.dllwrap_version) )
125-
126-
# ld_version >= "2.10.90" and < "2.13" should also be able to use
127-
# gcc -mdll instead of dllwrap
128-
# Older dllwraps had own version numbers, newer ones use the
129-
# same as the rest of binutils ( also ld )
130-
# dllwrap 2.10.90 is buggy
131-
if self.ld_version >= "2.10.90":
132-
self.linker_dll = self.cc
133-
else:
134-
self.linker_dll = "dllwrap"
135-
136-
# ld_version >= "2.13" support -shared so use it instead of
137-
# -mdll -static
138-
if self.ld_version >= "2.13":
139-
shared_option = "-shared"
140-
else:
141-
shared_option = "-mdll -static"
142-
else: # Assume linker is up to date
143-
self.linker_dll = self.cc
144-
shared_option = "-shared"
116+
self.linker_dll = self.cc
117+
shared_option = "-shared"
145118

146119
self.set_executables(compiler='%s -mcygwin -O -Wall' % self.cc,
147120
compiler_so='%s -mcygwin -mdll -O -Wall' % self.cc,
@@ -150,17 +123,9 @@ def __init__(self, verbose=0, dry_run=0, force=0):
150123
linker_so=('%s -mcygwin %s' %
151124
(self.linker_dll, shared_option)))
152125

153-
# cygwin and mingw32 need different sets of libraries
154-
if ('gcc' in self.cc and self.gcc_version == "2.91.57"):
155-
# cygwin shouldn't need msvcrt, but without the dlls will crash
156-
# (gcc version 2.91.57) -- perhaps something about initialization
157-
self.dll_libraries=["msvcrt"]
158-
self.warn(
159-
"Consider upgrading to a newer version of gcc")
160-
else:
161-
# Include the appropriate MSVC runtime library if Python was built
162-
# with MSVC 7.0 or later.
163-
self.dll_libraries = get_msvcr()
126+
# Include the appropriate MSVC runtime library if Python was built
127+
# with MSVC 7.0 or later.
128+
self.dll_libraries = get_msvcr()
164129

165130
def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
166131
"""Compiles the source by spawning GCC and windres if needed."""
@@ -244,24 +209,17 @@ def link(self, target_desc, objects, output_filename, output_dir=None,
244209

245210
# next add options for def-file and to creating import libraries
246211

247-
# dllwrap uses different options than gcc/ld
248-
if self.linker_dll == "dllwrap":
249-
extra_preargs.extend(["--output-lib", lib_file])
250-
# for dllwrap we have to use a special option
251-
extra_preargs.extend(["--def", def_file])
252-
# we use gcc/ld here and can be sure ld is >= 2.9.10
253-
else:
254-
# doesn't work: bfd_close build\...\libfoo.a: Invalid operation
255-
#extra_preargs.extend(["-Wl,--out-implib,%s" % lib_file])
256-
# for gcc/ld the def-file is specified as any object files
257-
objects.append(def_file)
212+
# doesn't work: bfd_close build\...\libfoo.a: Invalid operation
213+
#extra_preargs.extend(["-Wl,--out-implib,%s" % lib_file])
214+
# for gcc/ld the def-file is specified as any object files
215+
objects.append(def_file)
258216

259217
#end: if ((export_symbols is not None) and
260218
# (target_desc != self.EXECUTABLE or self.linker_dll == "gcc")):
261219

262220
# who wants symbols and a many times larger output file
263221
# should explicitly switch the debug mode on
264-
# otherwise we let dllwrap/ld strip the output file
222+
# otherwise we let ld strip the output file
265223
# (On my machine: 10KiB < stripped_file < ??100KiB
266224
# unstripped_file = stripped_file + XXX KiB
267225
# ( XXX=254 for a typical python extension))
@@ -314,19 +272,7 @@ def __init__(self, verbose=0, dry_run=0, force=0):
314272

315273
CygwinCCompiler.__init__ (self, verbose, dry_run, force)
316274

317-
# ld_version >= "2.13" support -shared so use it instead of
318-
# -mdll -static
319-
if ('gcc' in self.cc and self.ld_version < "2.13"):
320-
shared_option = "-mdll -static"
321-
else:
322-
shared_option = "-shared"
323-
324-
# A real mingw32 doesn't need to specify a different entry point,
325-
# but cygwin 2.91.57 in no-cygwin-mode needs it.
326-
if ('gcc' in self.cc and self.gcc_version <= "2.91.57"):
327-
entry_point = '--entry _DllMain@12'
328-
else:
329-
entry_point = ''
275+
shared_option = "-shared"
330276

331277
if is_cygwincc(self.cc):
332278
raise CCompilerError(
@@ -336,9 +282,8 @@ def __init__(self, verbose=0, dry_run=0, force=0):
336282
compiler_so='%s -mdll -O2 -Wall' % self.cc,
337283
compiler_cxx='%s -O2 -Wall' % self.cxx,
338284
linker_exe='%s' % self.cc,
339-
linker_so='%s %s %s'
340-
% (self.linker_dll, shared_option,
341-
entry_point))
285+
linker_so='%s %s'
286+
% (self.linker_dll, shared_option))
342287
# Maybe we should also append -mthreads, but then the finished
343288
# dlls need another dll (mingwm10.dll see Mingw32 docs)
344289
# (-mthreads: Support thread-safe exception handling on `Mingw32')
@@ -405,46 +350,6 @@ def check_config_h():
405350
return (CONFIG_H_UNCERTAIN,
406351
"couldn't read '%s': %s" % (fn, exc.strerror))
407352

408-
RE_VERSION = re.compile(br'[\D\s]*(\d+\.\d+(\.\d+)*)[\D\s]*')
409-
410-
def _find_exe_version(cmd):
411-
"""Find the version of an executable by running `cmd` in the shell.
412-
413-
If the command is not found, or the output does not match
414-
`RE_VERSION`, returns None.
415-
"""
416-
executable = cmd.split()[0]
417-
if find_executable(executable) is None:
418-
return None
419-
from subprocess import Popen, PIPE
420-
out = Popen(cmd, shell=True, stdout=PIPE).stdout
421-
try:
422-
out_string = out.read()
423-
finally:
424-
out.close()
425-
result = RE_VERSION.search(out_string)
426-
if result is None:
427-
return None
428-
# LooseVersion works with strings
429-
# so we need to decode our bytes
430-
return LooseVersion(result.group(1).decode())
431-
432-
def get_versions():
433-
""" Try to find out the versions of gcc, ld and dllwrap.
434-
435-
If not possible it returns None for it.
436-
"""
437-
gcc = os.environ.get('CC') or 'gcc'
438-
ld = 'ld'
439-
out = Popen(gcc+' --print-prog-name ld', shell=True, stdout=PIPE).stdout
440-
try:
441-
ld = test=str(out.read(),encoding='utf-8').strip()
442-
finally:
443-
out.close()
444-
dllwrap = os.environ.get('DLLWRAP') or 'dllwrap'
445-
# MinGW64 doesn't have i686-w64-mingw32-ld, so instead we ask gcc.
446-
commands = [gcc+' -dumpversion', ld+' -v', dllwrap+' --version']
447-
return tuple([_find_exe_version(cmd) for cmd in commands])
448353

449354
def is_cygwincc(cc):
450355
'''Try to determine if the compiler that would be used is from cygwin.'''

Lib/distutils/tests/test_cygwinccompiler.py

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from distutils import cygwinccompiler
99
from distutils.cygwinccompiler import (check_config_h,
1010
CONFIG_H_OK, CONFIG_H_NOTOK,
11-
CONFIG_H_UNCERTAIN, get_versions,
11+
CONFIG_H_UNCERTAIN,
1212
get_msvcr)
1313
from distutils.tests import support
1414

@@ -81,40 +81,6 @@ def test_check_config_h(self):
8181
self.write_file(self.python_h, 'xxx __GNUC__ xxx')
8282
self.assertEqual(check_config_h()[0], CONFIG_H_OK)
8383

84-
def test_get_versions(self):
85-
86-
# get_versions calls distutils.spawn.find_executable on
87-
# 'gcc', 'ld' and 'dllwrap'
88-
self.assertEqual(get_versions(), (None, None, None))
89-
90-
# Let's fake we have 'gcc' and it returns '3.4.5'
91-
self._exes['gcc'] = b'gcc (GCC) 3.4.5 (mingw special)\nFSF'
92-
res = get_versions()
93-
self.assertEqual(str(res[0]), '3.4.5')
94-
95-
# and let's see what happens when the version
96-
# doesn't match the regular expression
97-
# (\d+\.\d+(\.\d+)*)
98-
self._exes['gcc'] = b'very strange output'
99-
res = get_versions()
100-
self.assertEqual(res[0], None)
101-
102-
# same thing for ld
103-
self._exes['ld'] = b'GNU ld version 2.17.50 20060824'
104-
res = get_versions()
105-
self.assertEqual(str(res[1]), '2.17.50')
106-
self._exes['ld'] = b'@(#)PROGRAM:ld PROJECT:ld64-77'
107-
res = get_versions()
108-
self.assertEqual(res[1], None)
109-
110-
# and dllwrap
111-
self._exes['dllwrap'] = b'GNU dllwrap 2.17.50 20060824\nFSF'
112-
res = get_versions()
113-
self.assertEqual(str(res[2]), '2.17.50')
114-
self._exes['dllwrap'] = b'Cheese Wrap'
115-
res = get_versions()
116-
self.assertEqual(res[2], None)
117-
11884
def test_get_msvcr(self):
11985

12086
# none

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy