module cleanup

This commit is contained in:
Tarek Ziadé 2010-01-11 23:41:32 +00:00
parent 69eb51697c
commit ae7731af45
1 changed files with 69 additions and 148 deletions

View File

@ -9,11 +9,12 @@ import sys
import os import os
import re import re
from distutils.errors import CompileError, LinkError, UnknownFileError from distutils.errors import (CompileError, LinkError, UnknownFileError,
DistutilsPlatformError, DistutilsModuleError)
from distutils.spawn import spawn from distutils.spawn import spawn
from distutils.file_util import move_file from distutils.file_util import move_file
from distutils.dir_util import mkpath from distutils.dir_util import mkpath
from distutils.dep_util import newer_pairwise, newer_group from distutils.dep_util import newer_group
from distutils.util import split_quoted, execute from distutils.util import split_quoted, execute
from distutils import log from distutils import log
@ -87,11 +88,7 @@ class CCompiler:
} }
language_order = ["c++", "objc", "c"] language_order = ["c++", "objc", "c"]
def __init__ (self, def __init__ (self, verbose=0, dry_run=0, force=0):
verbose=0,
dry_run=0,
force=0):
self.dry_run = dry_run self.dry_run = dry_run
self.force = force self.force = force
self.verbose = verbose self.verbose = verbose
@ -127,11 +124,7 @@ class CCompiler:
for key in self.executables.keys(): for key in self.executables.keys():
self.set_executable(key, self.executables[key]) self.set_executable(key, self.executables[key])
# __init__ ()
def set_executables(self, **args): def set_executables(self, **args):
"""Define the executables (and options for them) that will be run """Define the executables (and options for them) that will be run
to perform the various stages of compilation. The exact set of to perform the various stages of compilation. The exact set of
executables that may be specified here depends on the compiler executables that may be specified here depends on the compiler
@ -164,25 +157,20 @@ class CCompiler:
(key, self.__class__.__name__) (key, self.__class__.__name__)
self.set_executable(key, args[key]) self.set_executable(key, args[key])
# set_executables ()
def set_executable(self, key, value): def set_executable(self, key, value):
if isinstance(value, str): if isinstance(value, str):
setattr(self, key, split_quoted(value)) setattr(self, key, split_quoted(value))
else: else:
setattr(self, key, value) setattr(self, key, value)
def _find_macro(self, name): def _find_macro(self, name):
i = 0 i = 0
for defn in self.macros: for defn in self.macros:
if defn[0] == name: if defn[0] == name:
return i return i
i = i + 1 i = i + 1
return None return None
def _check_macro_definitions(self, definitions): def _check_macro_definitions(self, definitions):
"""Ensures that every element of 'definitions' is a valid macro """Ensures that every element of 'definitions' is a valid macro
definition, ie. either (name,value) 2-tuple or a (name,) tuple. Do definition, ie. either (name,value) 2-tuple or a (name,) tuple. Do
@ -218,7 +206,6 @@ class CCompiler:
defn = (name, value) defn = (name, value)
self.macros.append (defn) self.macros.append (defn)
def undefine_macro(self, name): def undefine_macro(self, name):
"""Undefine a preprocessor macro for all compilations driven by """Undefine a preprocessor macro for all compilations driven by
this compiler object. If the same macro is defined by this compiler object. If the same macro is defined by
@ -237,7 +224,6 @@ class CCompiler:
undefn = (name,) undefn = (name,)
self.macros.append (undefn) self.macros.append (undefn)
def add_include_dir(self, dir): def add_include_dir(self, dir):
"""Add 'dir' to the list of directories that will be searched for """Add 'dir' to the list of directories that will be searched for
header files. The compiler is instructed to search directories in header files. The compiler is instructed to search directories in
@ -256,7 +242,6 @@ class CCompiler:
""" """
self.include_dirs = dirs[:] self.include_dirs = dirs[:]
def add_library(self, libname): def add_library(self, libname):
"""Add 'libname' to the list of libraries that will be included in """Add 'libname' to the list of libraries that will be included in
all links driven by this compiler object. Note that 'libname' all links driven by this compiler object. Note that 'libname'
@ -297,7 +282,6 @@ class CCompiler:
""" """
self.library_dirs = dirs[:] self.library_dirs = dirs[:]
def add_runtime_library_dir(self, dir): def add_runtime_library_dir(self, dir):
"""Add 'dir' to the list of directories that will be searched for """Add 'dir' to the list of directories that will be searched for
shared libraries at runtime. shared libraries at runtime.
@ -312,7 +296,6 @@ class CCompiler:
""" """
self.runtime_library_dirs = dirs[:] self.runtime_library_dirs = dirs[:]
def add_link_object(self, object): def add_link_object(self, object):
"""Add 'object' to the list of object files (or analogues, such as """Add 'object' to the list of object files (or analogues, such as
explicitly named library files or the output of "resource explicitly named library files or the output of "resource
@ -400,7 +383,7 @@ class CCompiler:
""" """
if output_dir is None: if output_dir is None:
output_dir = self.output_dir output_dir = self.output_dir
elif type (output_dir) is not StringType: elif not isinstance(output_dir, str):
raise TypeError, "'output_dir' must be a string or None" raise TypeError, "'output_dir' must be a string or None"
if macros is None: if macros is None:
@ -420,8 +403,6 @@ class CCompiler:
return output_dir, macros, include_dirs return output_dir, macros, include_dirs
# _fix_compile_args ()
def _fix_object_args(self, objects, output_dir): def _fix_object_args(self, objects, output_dir):
"""Typecheck and fix up some arguments supplied to various methods. """Typecheck and fix up some arguments supplied to various methods.
Specifically: ensure that 'objects' is a list; if output_dir is Specifically: ensure that 'objects' is a list; if output_dir is
@ -440,7 +421,6 @@ class CCompiler:
return (objects, output_dir) return (objects, output_dir)
def _fix_lib_args(self, libraries, library_dirs, runtime_library_dirs): def _fix_lib_args(self, libraries, library_dirs, runtime_library_dirs):
"""Typecheck and fix up some of the arguments supplied to the """Typecheck and fix up some of the arguments supplied to the
'link_*' methods. Specifically: ensure that all arguments are 'link_*' methods. Specifically: ensure that all arguments are
@ -476,9 +456,6 @@ class CCompiler:
return (libraries, library_dirs, runtime_library_dirs) return (libraries, library_dirs, runtime_library_dirs)
# _fix_lib_args ()
def _need_link(self, objects, output_file): def _need_link(self, objects, output_file):
"""Return true if we need to relink the files listed in 'objects' """Return true if we need to relink the files listed in 'objects'
to recreate 'output_file'. to recreate 'output_file'.
@ -492,8 +469,6 @@ class CCompiler:
newer = newer_group (objects, output_file) newer = newer_group (objects, output_file)
return newer return newer
# _need_link ()
def detect_language(self, sources): def detect_language(self, sources):
"""Detect the language of a given file, or list of files. Uses """Detect the language of a given file, or list of files. Uses
language_map, and language_order to do the job. language_map, and language_order to do the job.
@ -514,18 +489,11 @@ class CCompiler:
pass pass
return lang return lang
# detect_language ()
# -- Worker methods ------------------------------------------------ # -- Worker methods ------------------------------------------------
# (must be implemented by subclasses) # (must be implemented by subclasses)
def preprocess (self, def preprocess(self, source, output_file=None, macros=None,
source, include_dirs=None, extra_preargs=None, extra_postargs=None):
output_file=None,
macros=None,
include_dirs=None,
extra_preargs=None,
extra_postargs=None):
"""Preprocess a single C/C++ source file, named in 'source'. """Preprocess a single C/C++ source file, named in 'source'.
Output will be written to file named 'output_file', or stdout if Output will be written to file named 'output_file', or stdout if
'output_file' not supplied. 'macros' is a list of macro 'output_file' not supplied. 'macros' is a list of macro
@ -613,12 +581,8 @@ class CCompiler:
# should implement _compile(). # should implement _compile().
pass pass
def create_static_lib (self, def create_static_lib(self, objects, output_libname, output_dir=None,
objects, debug=0, target_lang=None):
output_libname,
output_dir=None,
debug=0,
target_lang=None):
"""Link a bunch of stuff together to create a static library file. """Link a bunch of stuff together to create a static library file.
The "bunch of stuff" consists of the list of object files supplied The "bunch of stuff" consists of the list of object files supplied
as 'objects', the extra object files supplied to as 'objects', the extra object files supplied to
@ -643,26 +607,15 @@ class CCompiler:
""" """
pass pass
# values for target_desc parameter in link() # values for target_desc parameter in link()
SHARED_OBJECT = "shared_object" SHARED_OBJECT = "shared_object"
SHARED_LIBRARY = "shared_library" SHARED_LIBRARY = "shared_library"
EXECUTABLE = "executable" EXECUTABLE = "executable"
def link (self, def link(self, target_desc, objects, output_filename, output_dir=None,
target_desc, libraries=None, library_dirs=None, runtime_library_dirs=None,
objects, export_symbols=None, debug=0, extra_preargs=None,
output_filename, extra_postargs=None, build_temp=None, target_lang=None):
output_dir=None,
libraries=None,
library_dirs=None,
runtime_library_dirs=None,
export_symbols=None,
debug=0,
extra_preargs=None,
extra_postargs=None,
build_temp=None,
target_lang=None):
"""Link a bunch of stuff together to create an executable or """Link a bunch of stuff together to create an executable or
shared library file. shared library file.
@ -711,19 +664,11 @@ class CCompiler:
# Old 'link_*()' methods, rewritten to use the new 'link()' method. # Old 'link_*()' methods, rewritten to use the new 'link()' method.
def link_shared_lib (self, def link_shared_lib(self, objects, output_libname, output_dir=None,
objects, libraries=None, library_dirs=None,
output_libname, runtime_library_dirs=None, export_symbols=None,
output_dir=None, debug=0, extra_preargs=None, extra_postargs=None,
libraries=None, build_temp=None, target_lang=None):
library_dirs=None,
runtime_library_dirs=None,
export_symbols=None,
debug=0,
extra_preargs=None,
extra_postargs=None,
build_temp=None,
target_lang=None):
self.link(CCompiler.SHARED_LIBRARY, objects, self.link(CCompiler.SHARED_LIBRARY, objects,
self.library_filename(output_libname, lib_type='shared'), self.library_filename(output_libname, lib_type='shared'),
output_dir, output_dir,
@ -732,37 +677,21 @@ class CCompiler:
extra_preargs, extra_postargs, build_temp, target_lang) extra_preargs, extra_postargs, build_temp, target_lang)
def link_shared_object (self, def link_shared_object(self, objects, output_filename, output_dir=None,
objects, libraries=None, library_dirs=None,
output_filename, runtime_library_dirs=None, export_symbols=None,
output_dir=None, debug=0, extra_preargs=None, extra_postargs=None,
libraries=None, build_temp=None, target_lang=None):
library_dirs=None,
runtime_library_dirs=None,
export_symbols=None,
debug=0,
extra_preargs=None,
extra_postargs=None,
build_temp=None,
target_lang=None):
self.link(CCompiler.SHARED_OBJECT, objects, self.link(CCompiler.SHARED_OBJECT, objects,
output_filename, output_dir, output_filename, output_dir,
libraries, library_dirs, runtime_library_dirs, libraries, library_dirs, runtime_library_dirs,
export_symbols, debug, export_symbols, debug,
extra_preargs, extra_postargs, build_temp, target_lang) extra_preargs, extra_postargs, build_temp, target_lang)
def link_executable(self, objects, output_progname, output_dir=None,
def link_executable (self, libraries=None, library_dirs=None,
objects, runtime_library_dirs=None, debug=0, extra_preargs=None,
output_progname, extra_postargs=None, target_lang=None):
output_dir=None,
libraries=None,
library_dirs=None,
runtime_library_dirs=None,
debug=0,
extra_preargs=None,
extra_postargs=None,
target_lang=None):
self.link(CCompiler.EXECUTABLE, objects, self.link(CCompiler.EXECUTABLE, objects,
self.executable_filename(output_progname), output_dir, self.executable_filename(output_progname), output_dir,
libraries, library_dirs, runtime_library_dirs, None, libraries, library_dirs, runtime_library_dirs, None,
@ -792,11 +721,8 @@ class CCompiler:
""" """
raise NotImplementedError raise NotImplementedError
def has_function(self, funcname, def has_function(self, funcname, includes=None, include_dirs=None,
includes=None, libraries=None, library_dirs=None):
include_dirs=None,
libraries=None,
library_dirs=None):
"""Return a boolean indicating whether funcname is supported on """Return a boolean indicating whether funcname is supported on
the current platform. The optional arguments can be used to the current platform. The optional arguments can be used to
augment the compilation environment. augment the compilation environment.
@ -974,7 +900,6 @@ _default_compilers = (
) )
def get_default_compiler(osname=None, platform=None): def get_default_compiler(osname=None, platform=None):
""" Determine the default compiler to use for the given platform. """ Determine the default compiler to use for the given platform.
osname should be one of the standard Python OS names (i.e. the osname should be one of the standard Python OS names (i.e. the
@ -1030,11 +955,7 @@ def show_compilers():
pretty_printer.print_help("List of available compilers:") pretty_printer.print_help("List of available compilers:")
def new_compiler (plat=None, def new_compiler(plat=None, compiler=None, verbose=0, dry_run=0, force=0):
compiler=None,
verbose=0,
dry_run=0,
force=0):
"""Generate an instance of some CCompiler subclass for the supplied """Generate an instance of some CCompiler subclass for the supplied
platform/compiler combination. 'plat' defaults to 'os.name' platform/compiler combination. 'plat' defaults to 'os.name'
(eg. 'posix', 'nt'), and 'compiler' defaults to the default compiler (eg. 'posix', 'nt'), and 'compiler' defaults to the default compiler