diff options
author | Tarek Ziadé <ziade.tarek@gmail.com> | 2009-07-06 12:50:46 (GMT) |
---|---|---|
committer | Tarek Ziadé <ziade.tarek@gmail.com> | 2009-07-06 12:50:46 (GMT) |
commit | e670e5ad5b7ef6b464fb264b688d96b9b9f71b53 (patch) | |
tree | 4a52ae3ccded74c2facfc124a6bdfb88aaa53663 | |
parent | f5b8ea9128fbafaf60c2de31a314f008819c48aa (diff) | |
download | cpython-e670e5ad5b7ef6b464fb264b688d96b9b9f71b53.zip cpython-e670e5ad5b7ef6b464fb264b688d96b9b9f71b53.tar.gz cpython-e670e5ad5b7ef6b464fb264b688d96b9b9f71b53.tar.bz2 |
Fixed #6377: distutils compiler switch ignored (and added a deprecation warning if compiler is not used as supposed = a string option)
-rw-r--r-- | Lib/distutils/command/build_ext.py | 78 | ||||
-rw-r--r-- | Lib/distutils/tests/test_build_ext.py | 14 | ||||
-rw-r--r-- | Misc/NEWS | 3 | ||||
-rw-r--r-- | setup.py | 94 |
4 files changed, 121 insertions, 68 deletions
diff --git a/Lib/distutils/command/build_ext.py b/Lib/distutils/command/build_ext.py index 96bd68b..be37313 100644 --- a/Lib/distutils/command/build_ext.py +++ b/Lib/distutils/command/build_ext.py @@ -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, - 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() @@ -504,13 +536,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! # @@ -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' diff --git a/Lib/distutils/tests/test_build_ext.py b/Lib/distutils/tests/test_build_ext.py index 2ecead3..afd0df3 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 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): @@ -347,6 +347,9 @@ Core and Builtins 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 #3392: The subprocess communicate() method no longer fails in select() @@ -184,7 +184,7 @@ class PyBuildExt(build_ext): if compiler is not None: (ccshared,cflags) = sysconfig.get_config_vars('CCSHARED','CFLAGS') args['compiler_so'] = compiler + ' ' + ccshared + ' ' + cflags - self.compiler.set_executables(**args) + self.compiler_obj.set_executables(**args) build_ext.build_extensions(self) @@ -299,8 +299,8 @@ class PyBuildExt(build_ext): def detect_modules(self): # Ensure that /usr/local is always used - add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib') - add_dir_to_list(self.compiler.include_dirs, '/usr/local/include') + add_dir_to_list(self.compiler_obj.library_dirs, '/usr/local/lib') + add_dir_to_list(self.compiler_obj.include_dirs, '/usr/local/include') # Add paths specified in the environment variables LDFLAGS and # CPPFLAGS for header and library files. @@ -309,9 +309,9 @@ class PyBuildExt(build_ext): # the environment variable is not set even though the value were passed # into configure and stored in the Makefile (issue found on OS X 10.3). for env_var, arg_name, dir_list in ( - ('LDFLAGS', '-R', self.compiler.runtime_library_dirs), - ('LDFLAGS', '-L', self.compiler.library_dirs), - ('CPPFLAGS', '-I', self.compiler.include_dirs)): + ('LDFLAGS', '-R', self.compiler_obj.runtime_library_dirs), + ('LDFLAGS', '-L', self.compiler_obj.library_dirs), + ('CPPFLAGS', '-I', self.compiler_obj.include_dirs)): env_val = sysconfig.get_config_var(env_var) if env_val: # To prevent optparse from raising an exception about any @@ -337,9 +337,9 @@ class PyBuildExt(build_ext): add_dir_to_list(dir_list, directory) if os.path.normpath(sys.prefix) != '/usr': - add_dir_to_list(self.compiler.library_dirs, + add_dir_to_list(self.compiler_obj.library_dirs, sysconfig.get_config_var("LIBDIR")) - add_dir_to_list(self.compiler.include_dirs, + add_dir_to_list(self.compiler_obj.include_dirs, sysconfig.get_config_var("INCLUDEDIR")) try: @@ -350,11 +350,11 @@ class PyBuildExt(build_ext): # lib_dirs and inc_dirs are used to search for files; # if a file is found in one of those directories, it can # be assumed that no additional -I,-L directives are needed. - lib_dirs = self.compiler.library_dirs + [ + lib_dirs = self.compiler_obj.library_dirs + [ '/lib64', '/usr/lib64', '/lib', '/usr/lib', ] - inc_dirs = self.compiler.include_dirs + ['/usr/include'] + inc_dirs = self.compiler_obj.include_dirs + ['/usr/include'] exts = [] missing = [] @@ -545,7 +545,7 @@ class PyBuildExt(build_ext): missing.extend(['imageop']) # readline - do_readline = self.compiler.find_library_file(lib_dirs, 'readline') + do_readline = self.compiler_obj.find_library_file(lib_dirs, 'readline') if platform == 'darwin': # and os.uname()[2] < '9.': # MacOSX 10.4 has a broken readline. Don't try to build # the readline module unless the user has installed a fixed @@ -566,17 +566,17 @@ class PyBuildExt(build_ext): readline_extra_link_args = () readline_libs = ['readline'] - if self.compiler.find_library_file(lib_dirs, - 'ncursesw'): + if self.compiler_obj.find_library_file(lib_dirs, + 'ncursesw'): readline_libs.append('ncursesw') - elif self.compiler.find_library_file(lib_dirs, - 'ncurses'): + elif self.compiler_obj.find_library_file(lib_dirs, + 'ncurses'): readline_libs.append('ncurses') - elif self.compiler.find_library_file(lib_dirs, 'curses'): + elif self.compiler_obj.find_library_file(lib_dirs, 'curses'): readline_libs.append('curses') - elif self.compiler.find_library_file(lib_dirs + - ['/usr/lib/termcap'], - 'termcap'): + elif self.compiler_obj.find_library_file(lib_dirs + + ['/usr/lib/termcap'], + 'termcap'): readline_libs.append('termcap') exts.append( Extension('readline', ['readline.c'], library_dirs=['/usr/lib/termcap'], @@ -588,7 +588,7 @@ class PyBuildExt(build_ext): if platform not in ['mac']: # crypt module. - if self.compiler.find_library_file(lib_dirs, 'crypt'): + if self.compiler_obj.find_library_file(lib_dirs, 'crypt'): libs = ['crypt'] else: libs = [] @@ -615,7 +615,7 @@ class PyBuildExt(build_ext): ['/usr/kerberos/include']) if krb5_h: ssl_incs += krb5_h - ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs, + ssl_libs = find_library_file(self.compiler_obj, 'ssl',lib_dirs, ['/usr/local/ssl/lib', '/usr/contrib/ssl/lib/' ] ) @@ -840,7 +840,7 @@ class PyBuildExt(build_ext): for dblib in (('db-%d.%d' % db_ver), ('db%d%d' % db_ver), ('db%d' % db_ver[0])): - dblib_file = self.compiler.find_library_file( + dblib_file = self.compiler_obj.find_library_file( db_dirs_to_check + lib_dirs, dblib ) if dblib_file: dblib_dir = [ os.path.abspath(os.path.dirname(dblib_file)) ] @@ -924,7 +924,7 @@ class PyBuildExt(build_ext): os.path.join(sqlite_incdir, '..', '..', 'lib64'), os.path.join(sqlite_incdir, '..', '..', 'lib'), ] - sqlite_libfile = self.compiler.find_library_file( + sqlite_libfile = self.compiler_obj.find_library_file( sqlite_dirs_to_check + lib_dirs, 'sqlite3') if sqlite_libfile: sqlite_libdir = [os.path.abspath(os.path.dirname(sqlite_libfile))] @@ -1014,7 +1014,8 @@ class PyBuildExt(build_ext): if cand == "ndbm": if find_file("ndbm.h", inc_dirs, []) is not None: # Some systems have -lndbm, others don't - if self.compiler.find_library_file(lib_dirs, 'ndbm'): + if self.compiler_obj.find_library_file(lib_dirs, + 'ndbm'): ndbm_libs = ['ndbm'] else: ndbm_libs = [] @@ -1027,9 +1028,10 @@ class PyBuildExt(build_ext): break elif cand == "gdbm": - if self.compiler.find_library_file(lib_dirs, 'gdbm'): + if self.compiler_obj.find_library_file(lib_dirs, 'gdbm'): gdbm_libs = ['gdbm'] - if self.compiler.find_library_file(lib_dirs, 'gdbm_compat'): + if self.compiler_obj.find_library_file(lib_dirs, + 'gdbm_compat'): gdbm_libs.append('gdbm_compat') if find_file("gdbm/ndbm.h", inc_dirs, []) is not None: print "building dbm using gdbm" @@ -1068,7 +1070,7 @@ class PyBuildExt(build_ext): missing.append('dbm') # Anthony Baxter's gdbm module. GNU dbm(3) will require -lgdbm: - if (self.compiler.find_library_file(lib_dirs, 'gdbm')): + if (self.compiler_obj.find_library_file(lib_dirs, 'gdbm')): exts.append( Extension('gdbm', ['gdbmmodule.c'], libraries = ['gdbm'] ) ) else: @@ -1086,7 +1088,7 @@ class PyBuildExt(build_ext): # Sun yellow pages. Some systems have the functions in libc. if platform not in ['cygwin', 'atheos', 'qnx6']: - if (self.compiler.find_library_file(lib_dirs, 'nsl')): + if (self.compiler_obj.find_library_file(lib_dirs, 'nsl')): libs = ['nsl'] else: libs = [] @@ -1100,24 +1102,24 @@ class PyBuildExt(build_ext): # Curses support, requiring the System V version of curses, often # provided by the ncurses library. panel_library = 'panel' - if (self.compiler.find_library_file(lib_dirs, 'ncursesw')): + if (self.compiler_obj.find_library_file(lib_dirs, 'ncursesw')): curses_libs = ['ncursesw'] # Bug 1464056: If _curses.so links with ncursesw, # _curses_panel.so must link with panelw. panel_library = 'panelw' exts.append( Extension('_curses', ['_cursesmodule.c'], libraries = curses_libs) ) - elif (self.compiler.find_library_file(lib_dirs, 'ncurses')): + elif (self.compiler_obj.find_library_file(lib_dirs, 'ncurses')): curses_libs = ['ncurses'] exts.append( Extension('_curses', ['_cursesmodule.c'], libraries = curses_libs) ) - elif (self.compiler.find_library_file(lib_dirs, 'curses') + elif (self.compiler_obj.find_library_file(lib_dirs, 'curses') and platform != 'darwin'): # OSX has an old Berkeley curses, not good enough for # the _curses module. - if (self.compiler.find_library_file(lib_dirs, 'terminfo')): + if (self.compiler_obj.find_library_file(lib_dirs, 'terminfo')): curses_libs = ['curses', 'terminfo'] - elif (self.compiler.find_library_file(lib_dirs, 'termcap')): + elif (self.compiler_obj.find_library_file(lib_dirs, 'termcap')): curses_libs = ['curses', 'termcap'] else: curses_libs = ['curses'] @@ -1129,7 +1131,7 @@ class PyBuildExt(build_ext): # If the curses module is enabled, check for the panel module if (module_enabled(exts, '_curses') and - self.compiler.find_library_file(lib_dirs, panel_library)): + self.compiler_obj.find_library_file(lib_dirs, panel_library)): exts.append( Extension('_curses_panel', ['_curses_panel.c'], libraries = [panel_library] + curses_libs) ) else: @@ -1162,7 +1164,7 @@ class PyBuildExt(build_ext): version = line.split()[2] break if version >= version_req: - if (self.compiler.find_library_file(lib_dirs, 'z')): + if (self.compiler_obj.find_library_file(lib_dirs, 'z')): if sys.platform == "darwin": zlib_extra_link_args = ('-Wl,-search_paths_first',) else: @@ -1194,7 +1196,7 @@ class PyBuildExt(build_ext): extra_link_args = extra_link_args) ) # Gustavo Niemeyer's bz2 module. - if (self.compiler.find_library_file(lib_dirs, 'bz2')): + if (self.compiler_obj.find_library_file(lib_dirs, 'bz2')): if sys.platform == "darwin": bz2_extra_link_args = ('-Wl,-search_paths_first',) else: @@ -1539,8 +1541,10 @@ class PyBuildExt(build_ext): tcllib = tklib = tcl_includes = tk_includes = None for version in ['8.5', '85', '8.4', '84', '8.3', '83', '8.2', '82', '8.1', '81', '8.0', '80']: - tklib = self.compiler.find_library_file(lib_dirs, 'tk' + version) - tcllib = self.compiler.find_library_file(lib_dirs, 'tcl' + version) + tklib = self.compiler_obj.find_library_file(lib_dirs, + 'tk' + version) + tcllib = self.compiler_obj.find_library_file(lib_dirs, + 'tcl' + version) if tklib and tcllib: # Exit the loop when we've found the Tcl/Tk libraries break @@ -1598,12 +1602,12 @@ class PyBuildExt(build_ext): return # Check for BLT extension - if self.compiler.find_library_file(lib_dirs + added_lib_dirs, - 'BLT8.0'): + if self.compiler_obj.find_library_file(lib_dirs + added_lib_dirs, + 'BLT8.0'): defs.append( ('WITH_BLT', 1) ) libs.append('BLT8.0') - elif self.compiler.find_library_file(lib_dirs + added_lib_dirs, - 'BLT'): + elif self.compiler_obj.find_library_file(lib_dirs + added_lib_dirs, + 'BLT'): defs.append( ('WITH_BLT', 1) ) libs.append('BLT') @@ -1657,7 +1661,7 @@ class PyBuildExt(build_ext): ]] # Add .S (preprocessed assembly) to C compiler source extensions. - self.compiler.src_extensions.append('.S') + self.compiler_obj.src_extensions.append('.S') include_dirs = [os.path.join(ffi_srcdir, 'include'), os.path.join(ffi_srcdir, 'powerpc')] @@ -1702,7 +1706,7 @@ class PyBuildExt(build_ext): ffi_srcdir = os.path.join(fficonfig['ffi_srcdir'], 'src') # Add .S (preprocessed assembly) to C compiler source extensions. - self.compiler.src_extensions.append('.S') + self.compiler_obj.src_extensions.append('.S') include_dirs = [os.path.join(ffi_builddir, 'include'), ffi_builddir, ffi_srcdir] @@ -1780,7 +1784,7 @@ class PyBuildExt(build_ext): ffi_lib = None if ffi_inc is not None: for lib_name in ('ffi_convenience', 'ffi_pic', 'ffi'): - if (self.compiler.find_library_file(lib_dirs, lib_name)): + if (self.compiler_obj.find_library_file(lib_dirs, lib_name)): ffi_lib = lib_name break |