Oscar Benjamin added the comment:
I'm attaching three new patches following on from Eric and Christian's
suggestions:
check_mno_cywin_py27_1.patch (for Python 2.7)
check_mno_cywin_py3_1.patch (for Python 3.2 and 3.3)
check_mno_cywin_py34_1.patch (for Python 3.4)
The py27 patch now uses os.popen to avoid importing subprocess as
suggested by Eric. The other two patches are changed to use
check_output as suggested by Christian (subprocess is already imported
in 3.x).
I've retested the patches using the same setup as before and the
results are unchanged for all gcc and Python versions tested.
----------
Added file: http://bugs.python.org/file30888/check_mno_cywin_py34_1.patch
Added file: http://bugs.python.org/file30889/check_mno_cywin_py3_1.patch
Added file: http://bugs.python.org/file30890/check_mno_cywin_py27_1.patch
_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue12641>
_______________________________________
diff -r 7aab60b70f90 Lib/distutils/cygwinccompiler.py
--- a/Lib/distutils/cygwinccompiler.py Sun Jun 23 15:47:03 2013 -0700
+++ b/Lib/distutils/cygwinccompiler.py Thu Jul 11 16:59:27 2013 +0100
@@ -48,13 +48,14 @@
import os
import sys
import copy
-from subprocess import Popen, PIPE
+from subprocess import Popen, PIPE, check_output
import re
from distutils.ccompiler import gen_preprocess_options, gen_lib_options
from distutils.unixccompiler import UnixCCompiler
from distutils.file_util import write_file
-from distutils.errors import DistutilsExecError, CompileError, UnknownFileError
+from distutils.errors import (DistutilsExecError, CCompilerError,
+ CompileError, UnknownFileError)
from distutils import log
from distutils.version import LooseVersion
from distutils.spawn import find_executable
@@ -294,11 +295,15 @@
else:
entry_point = ''
- self.set_executables(compiler='gcc -mno-cygwin -O -Wall',
- compiler_so='gcc -mno-cygwin -mdll -O -Wall',
- compiler_cxx='g++ -mno-cygwin -O -Wall',
- linker_exe='gcc -mno-cygwin',
- linker_so='%s -mno-cygwin %s %s'
+ if is_cygwingcc():
+ raise CCompilerError(
+ 'Cygwin gcc cannot be used with --compiler=mingw32')
+
+ self.set_executables(compiler='gcc -O -Wall',
+ compiler_so='gcc -mdll -O -Wall',
+ compiler_cxx='g++ -O -Wall',
+ linker_exe='gcc',
+ linker_so='%s %s %s'
% (self.linker_dll, shared_option,
entry_point))
# Maybe we should also append -mthreads, but then the finished
@@ -393,3 +398,8 @@
"""
commands = ['gcc -dumpversion', 'ld -v', 'dllwrap --version']
return tuple([_find_exe_version(cmd) for cmd in commands])
+
+def is_cygwingcc():
+ '''Try to determine if the gcc that would be used is from cygwin.'''
+ out_string = check_output(['gcc', '-dumpmachine'])
+ return out_string.strip().endswith(b'cygwin')
diff -r 0762f2419494 Lib/distutils/cygwinccompiler.py
--- a/Lib/distutils/cygwinccompiler.py Sun Jun 23 23:51:44 2013 +0200
+++ b/Lib/distutils/cygwinccompiler.py Thu Jul 11 17:05:05 2013 +0100
@@ -48,7 +48,7 @@
import os
import sys
import copy
-from subprocess import Popen, PIPE
+from subprocess import Popen, PIPE, check_output
import re
from distutils.ccompiler import gen_preprocess_options, gen_lib_options
@@ -294,13 +294,18 @@
else:
entry_point = ''
- self.set_executables(compiler='gcc -mno-cygwin -O -Wall',
- compiler_so='gcc -mno-cygwin -mdll -O -Wall',
- compiler_cxx='g++ -mno-cygwin -O -Wall',
- linker_exe='gcc -mno-cygwin',
- linker_so='%s -mno-cygwin %s %s'
- % (self.linker_dll, shared_option,
- entry_point))
+ if self.gcc_version < '4' or is_cygwingcc():
+ no_cygwin = ' -mno-cygwin'
+ else:
+ no_cygwin = ''
+
+ self.set_executables(compiler='gcc%s -O -Wall' % no_cygwin,
+ compiler_so='gcc%s -mdll -O -Wall' % no_cygwin,
+ compiler_cxx='g++%s -O -Wall' % no_cygwin,
+ linker_exe='gcc%s' % no_cygwin,
+ linker_so='%s%s %s %s'
+ % (self.linker_dll, no_cygwin,
+ shared_option, entry_point))
# 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')
@@ -393,3 +398,8 @@
"""
commands = ['gcc -dumpversion', 'ld -v', 'dllwrap --version']
return tuple([_find_exe_version(cmd) for cmd in commands])
+
+def is_cygwingcc():
+ '''Try to determine if the gcc that would be used is from cygwin.'''
+ out_string = check_output(['gcc', '-dumpmachine'])
+ return out_string.strip().endswith(b'cygwin')
diff -r a7db9f505e88 Lib/distutils/cygwinccompiler.py
--- a/Lib/distutils/cygwinccompiler.py Sun Jun 23 16:12:32 2013 -0400
+++ b/Lib/distutils/cygwinccompiler.py Thu Jul 11 17:15:05 2013 +0100
@@ -319,13 +319,18 @@
else:
entry_point = ''
- self.set_executables(compiler='gcc -mno-cygwin -O -Wall',
- compiler_so='gcc -mno-cygwin -mdll -O -Wall',
- compiler_cxx='g++ -mno-cygwin -O -Wall',
- linker_exe='gcc -mno-cygwin',
- linker_so='%s -mno-cygwin %s %s'
- % (self.linker_dll, shared_option,
- entry_point))
+ if self.gcc_version < '4' or is_cygwingcc():
+ no_cygwin = ' -mno-cygwin'
+ else:
+ no_cygwin = ''
+
+ self.set_executables(compiler='gcc%s -O -Wall' % no_cygwin,
+ compiler_so='gcc%s -mdll -O -Wall' % no_cygwin,
+ compiler_cxx='g++%s -O -Wall' % no_cygwin,
+ linker_exe='gcc%s' % no_cygwin,
+ linker_so='%s%s %s %s'
+ % (self.linker_dll, no_cygwin,
+ shared_option, entry_point))
# 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')
@@ -447,3 +452,10 @@
else:
dllwrap_version = None
return (gcc_version, ld_version, dllwrap_version)
+
+def is_cygwingcc():
+ '''Try to determine if the gcc that would be used is from cygwin.'''
+ out_string = os.popen('gcc -dumpmachine').read()
+ # out_string is the target triplet cpu-vendor-os
+ # Cygwin's gcc sets the os to 'cygwin'
+ return out_string.strip().endswith('cygwin')
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com