Unify the way the MSVC compiler is detected

And do it only once in __init__ instead of different ways
and in different places.
This commit is contained in:
Steve Lacy 2011-06-06 14:30:47 -07:00 committed by Daniele Varrazzo
parent c826446ff8
commit ef18915396

View File

@ -53,10 +53,7 @@ from distutils.command.build_ext import build_ext
from distutils.sysconfig import get_python_inc
from distutils.ccompiler import get_default_compiler
from distutils.util import get_platform
try:
from distutils.msvc9compiler import MSVCCompiler
except ImportError:
MSVCCompiler = None
try:
from distutils.command.build_py import build_py_2to3 as build_py
except ImportError:
@ -242,6 +239,9 @@ class psycopg_build_ext(build_ext):
def __init__(self, *args, **kwargs):
build_ext.__init__(self, *args, **kwargs)
self.pg_config = PostgresConfig()
compiler_name = self.get_compiler_name().lower()
self.compiler_is_msvc = compiler_name.startswith('msvc')
self.compiler_is_mingw = compiler_name.startswith('mingw')
def initialize_options(self):
build_ext.initialize_options(self)
@ -271,7 +271,7 @@ class psycopg_build_ext(build_ext):
def get_export_symbols(self, extension):
# Fix MSVC seeing two of the same export symbols.
if self.get_compiler_name().lower().startswith('msvc'):
if self.compiler_is_msvc:
return []
else:
return build_ext.get_export_symbols(self, extension)
@ -281,7 +281,7 @@ class psycopg_build_ext(build_ext):
# For Python versions that use MSVC compiler 2008, re-insert the
# manifest into the resulting .pyd file.
if MSVCCompiler and isinstance(self.compiler, MSVCCompiler):
if self.compiler_is_msvc:
platform = get_platform()
# Default to the x86 manifest
manifest = '_psycopg.vc9.x86.manifest'
@ -301,10 +301,7 @@ class psycopg_build_ext(build_ext):
# Add compiler-specific arguments:
extra_compiler_args = []
compiler_name = self.get_compiler_name().lower()
compiler_is_msvc = compiler_name.startswith('msvc')
compiler_is_mingw = compiler_name.startswith('mingw')
if compiler_is_mingw:
if self.compiler_is_mingw:
# Default MinGW compilation of Python extensions on Windows uses
# only -O:
extra_compiler_args.append('-O3')
@ -332,7 +329,7 @@ class psycopg_build_ext(build_ext):
self.libraries.append("ws2_32")
self.libraries.append("advapi32")
if compiler_is_msvc:
if self.compiler_is_msvc:
# MSVC requires an explicit "libpq"
self.libraries.remove("pq")
self.libraries.append("secur32")