summaryrefslogtreecommitdiffstats
path: root/Lib/distutils
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/distutils')
-rw-r--r--Lib/distutils/command/build_ext.py77
-rw-r--r--Lib/distutils/tests/test_build_ext.py14
2 files changed, 68 insertions, 23 deletions
diff --git a/Lib/distutils/command/build_ext.py b/Lib/distutils/command/build_ext.py
index 3045702..4a3aec2 100644
--- a/Lib/distutils/command/build_ext.py
+++ b/Lib/distutils/command/build_ext.py
@@ -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'
diff --git a/Lib/distutils/tests/test_build_ext.py b/Lib/distutils/tests/test_build_ext.py
index 6f0e230..d531293 100644
--- a/Lib/distutils/tests/test_build_ext.py
+++ b/Lib/distutils/tests/test_build_ext.py
@@ -3,6 +3,9 @@ import os
import tempfile
import shutil
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.command.build_ext import build_ext
@@ -395,6 +398,17 @@ class BuildExtTestCase(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):