Merged revisions 73864 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

........
  r73864 | tarek.ziade | 2009-07-06 14:50:46 +0200 (Mon, 06 Jul 2009) | 1 line

  Fixed #6377: distutils compiler switch ignored (and added a deprecation warning if compiler is not used as supposed = a string option)
........
This commit is contained in:
Tarek Ziadé 2009-07-06 13:52:17 +00:00
parent 47137250ff
commit dd07ebb44a
4 changed files with 119 additions and 67 deletions

View file

@ -7,6 +7,8 @@ extensions ASAP)."""
__revision__ = "$Id$"
import sys, os, re
from warnings import warn
from distutils.core import Command
from distutils.errors import *
from distutils.sysconfig import customize_compiler, get_python_version
@ -112,6 +114,35 @@ class build_ext(Command):
"list available compilers", show_compilers),
]
# making 'compiler' a property to deprecate
# its usage as something else than a compiler type
# e.g. like a compiler instance
def __init__(self, dist):
self._compiler = None
Command.__init__(self, dist)
def __setattr__(self, name, value):
# need this to make sure setattr() (used in distutils)
# doesn't kill our property
if name == 'compiler':
self._set_compiler(value)
else:
self.__dict__[name] = value
def _set_compiler(self, compiler):
if not isinstance(compiler, str) and compiler is not None:
# we don't want to allow that anymore in the future
warn("'compiler' specify the compiler type in build_ext. "
"If you want to get the compiler object itself, "
"use 'compiler_obj'", PendingDeprecationWarning)
self._compiler = compiler
def _get_compiler(self):
return self._compiler
compiler = property(_get_compiler, _set_compiler)
def initialize_options(self):
self.extensions = None
self.build_lib = None
@ -310,38 +341,38 @@ class build_ext(Command):
# Setup the CCompiler object that we'll use to do all the
# compiling and linking
self.compiler = new_compiler(compiler=None,
verbose=self.verbose,
dry_run=self.dry_run,
force=self.force)
customize_compiler(self.compiler)
self.compiler_obj = new_compiler(compiler=self.compiler,
verbose=self.verbose,
dry_run=self.dry_run,
force=self.force)
customize_compiler(self.compiler_obj)
# If we are cross-compiling, init the compiler now (if we are not
# cross-compiling, init would not hurt, but people may rely on
# late initialization of compiler even if they shouldn't...)
if os.name == 'nt' and self.plat_name != get_platform():
self.compiler.initialize(self.plat_name)
self.compiler_obj.initialize(self.plat_name)
# And make sure that any compile/link-related options (which might
# come from the command-line or from the setup script) are set in
# that CCompiler object -- that way, they automatically apply to
# all compiling and linking done here.
if self.include_dirs is not None:
self.compiler.set_include_dirs(self.include_dirs)
self.compiler_obj.set_include_dirs(self.include_dirs)
if self.define is not None:
# 'define' option is a list of (name,value) tuples
for (name, value) in self.define:
self.compiler.define_macro(name, value)
self.compiler_obj.define_macro(name, value)
if self.undef is not None:
for macro in self.undef:
self.compiler.undefine_macro(macro)
self.compiler_obj.undefine_macro(macro)
if self.libraries is not None:
self.compiler.set_libraries(self.libraries)
self.compiler_obj.set_libraries(self.libraries)
if self.library_dirs is not None:
self.compiler.set_library_dirs(self.library_dirs)
self.compiler_obj.set_library_dirs(self.library_dirs)
if self.rpath is not None:
self.compiler.set_runtime_library_dirs(self.rpath)
self.compiler_obj.set_runtime_library_dirs(self.rpath)
if self.link_objects is not None:
self.compiler.set_link_objects(self.link_objects)
self.compiler_obj.set_link_objects(self.link_objects)
# Now actually compile and link everything.
self.build_extensions()
@ -502,13 +533,13 @@ class build_ext(Command):
for undef in ext.undef_macros:
macros.append((undef,))
objects = self.compiler.compile(sources,
output_dir=self.build_temp,
macros=macros,
include_dirs=ext.include_dirs,
debug=self.debug,
extra_postargs=extra_args,
depends=ext.depends)
objects = self.compiler_obj.compile(sources,
output_dir=self.build_temp,
macros=macros,
include_dirs=ext.include_dirs,
debug=self.debug,
extra_postargs=extra_args,
depends=ext.depends)
# XXX -- this is a Vile HACK!
#
@ -529,9 +560,9 @@ class build_ext(Command):
extra_args = ext.extra_link_args or []
# Detect target language, if not provided
language = ext.language or self.compiler.detect_language(sources)
language = ext.language or self.compiler_obj.detect_language(sources)
self.compiler.link_shared_object(
self.compiler_obj.link_shared_object(
objects, ext_path,
libraries=self.get_libraries(ext),
library_dirs=ext.library_dirs,
@ -698,7 +729,7 @@ class build_ext(Command):
# Append '_d' to the python import library on debug builds.
if sys.platform == "win32":
from distutils.msvccompiler import MSVCCompiler
if not isinstance(self.compiler, MSVCCompiler):
if not isinstance(self.compiler_obj, MSVCCompiler):
template = "python%d%d"
if self.debug:
template = template + '_d'