Commit 54b37808 authored by Tarek Ziadé's avatar Tarek Ziadé

Fixed #6377: distutils compiler switch ignored (and added a deprecation...

Fixed #6377: distutils compiler switch ignored (and added a deprecation warning if compiler is not used as supposed = a string option)
parent 6770846e
......@@ -8,6 +8,8 @@ __revision__ = "$Id$"
import sys, os, string, re
from types import *
from warnings import warn
from distutils.core import Command
from distutils.errors import *
from distutils.sysconfig import customize_compiler, get_python_version
......@@ -113,6 +115,36 @@ 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
......@@ -311,38 +343,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,
self.compiler_obj = new_compiler(compiler=self.compiler,
verbose=self.verbose,
dry_run=self.dry_run,
force=self.force)
customize_compiler(self.compiler)
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()
......@@ -504,7 +536,7 @@ class build_ext (Command):
for undef in ext.undef_macros:
macros.append((undef,))
objects = self.compiler.compile(sources,
objects = self.compiler_obj.compile(sources,
output_dir=self.build_temp,
macros=macros,
include_dirs=ext.include_dirs,
......@@ -531,9 +563,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,
......@@ -712,7 +744,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'
......
......@@ -3,6 +3,9 @@ import os
import tempfile
import shutil
from StringIO import StringIO
import warnings
from test.test_support import check_warnings
from test.test_support import captured_stdout
from distutils.core import Extension, Distribution
from distutils.command.build_ext import build_ext
......@@ -395,6 +398,17 @@ class BuildExtTestCase(support.TempdirManager,
wanted = os.path.join(curdir, 'twisted', 'runner', 'portmap.so')
self.assertEquals(wanted, path)
def test_compiler_deprecation_warning(self):
dist = Distribution()
cmd = build_ext(dist)
with check_warnings() as w:
warnings.simplefilter("always")
cmd.compiler = object()
self.assertEquals(len(w.warnings), 1)
cmd.compile = 'unix'
self.assertEquals(len(w.warnings), 1)
def test_suite():
src = _get_source_filename()
if not os.path.exists(src):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment