Commit dd07ebb4 authored by Tarek Ziadé's avatar Tarek Ziadé

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)
........
parent 47137250
...@@ -7,6 +7,8 @@ extensions ASAP).""" ...@@ -7,6 +7,8 @@ extensions ASAP)."""
__revision__ = "$Id$" __revision__ = "$Id$"
import sys, os, re import sys, os, re
from warnings import warn
from distutils.core import Command from distutils.core import Command
from distutils.errors import * from distutils.errors import *
from distutils.sysconfig import customize_compiler, get_python_version from distutils.sysconfig import customize_compiler, get_python_version
...@@ -112,6 +114,35 @@ class build_ext(Command): ...@@ -112,6 +114,35 @@ class build_ext(Command):
"list available compilers", show_compilers), "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): def initialize_options(self):
self.extensions = None self.extensions = None
self.build_lib = None self.build_lib = None
...@@ -310,38 +341,38 @@ class build_ext(Command): ...@@ -310,38 +341,38 @@ class build_ext(Command):
# Setup the CCompiler object that we'll use to do all the # Setup the CCompiler object that we'll use to do all the
# compiling and linking # compiling and linking
self.compiler = new_compiler(compiler=None, self.compiler_obj = new_compiler(compiler=self.compiler,
verbose=self.verbose, verbose=self.verbose,
dry_run=self.dry_run, dry_run=self.dry_run,
force=self.force) 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 # If we are cross-compiling, init the compiler now (if we are not
# cross-compiling, init would not hurt, but people may rely on # cross-compiling, init would not hurt, but people may rely on
# late initialization of compiler even if they shouldn't...) # late initialization of compiler even if they shouldn't...)
if os.name == 'nt' and self.plat_name != get_platform(): 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 # And make sure that any compile/link-related options (which might
# come from the command-line or from the setup script) are set in # come from the command-line or from the setup script) are set in
# that CCompiler object -- that way, they automatically apply to # that CCompiler object -- that way, they automatically apply to
# all compiling and linking done here. # all compiling and linking done here.
if self.include_dirs is not None: 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: if self.define is not None:
# 'define' option is a list of (name,value) tuples # 'define' option is a list of (name,value) tuples
for (name, value) in self.define: 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: if self.undef is not None:
for macro in self.undef: for macro in self.undef:
self.compiler.undefine_macro(macro) self.compiler_obj.undefine_macro(macro)
if self.libraries is not None: 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: 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: 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: 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. # Now actually compile and link everything.
self.build_extensions() self.build_extensions()
...@@ -502,13 +533,13 @@ class build_ext(Command): ...@@ -502,13 +533,13 @@ class build_ext(Command):
for undef in ext.undef_macros: for undef in ext.undef_macros:
macros.append((undef,)) macros.append((undef,))
objects = self.compiler.compile(sources, objects = self.compiler_obj.compile(sources,
output_dir=self.build_temp, output_dir=self.build_temp,
macros=macros, macros=macros,
include_dirs=ext.include_dirs, include_dirs=ext.include_dirs,
debug=self.debug, debug=self.debug,
extra_postargs=extra_args, extra_postargs=extra_args,
depends=ext.depends) depends=ext.depends)
# XXX -- this is a Vile HACK! # XXX -- this is a Vile HACK!
# #
...@@ -529,9 +560,9 @@ class build_ext(Command): ...@@ -529,9 +560,9 @@ class build_ext(Command):
extra_args = ext.extra_link_args or [] extra_args = ext.extra_link_args or []
# Detect target language, if not provided # 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, objects, ext_path,
libraries=self.get_libraries(ext), libraries=self.get_libraries(ext),
library_dirs=ext.library_dirs, library_dirs=ext.library_dirs,
...@@ -698,7 +729,7 @@ class build_ext(Command): ...@@ -698,7 +729,7 @@ class build_ext(Command):
# Append '_d' to the python import library on debug builds. # Append '_d' to the python import library on debug builds.
if sys.platform == "win32": if sys.platform == "win32":
from distutils.msvccompiler import MSVCCompiler from distutils.msvccompiler import MSVCCompiler
if not isinstance(self.compiler, MSVCCompiler): if not isinstance(self.compiler_obj, MSVCCompiler):
template = "python%d%d" template = "python%d%d"
if self.debug: if self.debug:
template = template + '_d' template = template + '_d'
......
...@@ -3,6 +3,9 @@ import os ...@@ -3,6 +3,9 @@ import os
import tempfile import tempfile
import shutil import shutil
from io import StringIO from io import StringIO
import warnings
from test.support import check_warnings
from test.support import captured_stdout
from distutils.core import Extension, Distribution from distutils.core import Extension, Distribution
from distutils.command.build_ext import build_ext from distutils.command.build_ext import build_ext
...@@ -395,6 +398,17 @@ class BuildExtTestCase(TempdirManager, ...@@ -395,6 +398,17 @@ class BuildExtTestCase(TempdirManager,
wanted = os.path.join(curdir, 'twisted', 'runner', 'portmap.so') wanted = os.path.join(curdir, 'twisted', 'runner', 'portmap.so')
self.assertEquals(wanted, path) 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(): def test_suite():
src = _get_source_filename() src = _get_source_filename()
if not os.path.exists(src): if not os.path.exists(src):
......
...@@ -878,6 +878,9 @@ Core and Builtins ...@@ -878,6 +878,9 @@ Core and Builtins
Library Library
------- -------
- Issue #6377: Enabled the compiler option, and deprecate its usage as an
attribute.
- Issue #6413: Fixed the log level in distutils.dist for announce. - Issue #6413: Fixed the log level in distutils.dist for announce.
- Issue #6403: Fixed package path usage in build_ext. - Issue #6403: Fixed package path usage in build_ext.
......
This diff is collapsed.
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