pep8-fied cygwinccompiler module

This commit is contained in:
Tarek Ziadé 2009-06-11 09:55:09 +00:00
parent 91290b5f53
commit ff1081874a
1 changed files with 30 additions and 65 deletions

View File

@ -85,7 +85,8 @@ def get_msvcr():
class CygwinCCompiler(UnixCCompiler): class CygwinCCompiler(UnixCCompiler):
""" Handles the Cygwin port of the GNU C compiler to Windows.
"""
compiler_type = 'cygwin' compiler_type = 'cygwin'
obj_extension = ".o" obj_extension = ".o"
static_lib_extension = ".a" static_lib_extension = ".a"
@ -98,7 +99,7 @@ class CygwinCCompiler (UnixCCompiler):
UnixCCompiler.__init__(self, verbose, dry_run, force) UnixCCompiler.__init__(self, verbose, dry_run, force)
(status, details) = check_config_h() status, details = check_config_h()
self.debug_print("Python's GCC status: %s (details: %s)" % self.debug_print("Python's GCC status: %s (details: %s)" %
(status, details)) (status, details))
if status is not CONFIG_H_OK: if status is not CONFIG_H_OK:
@ -153,10 +154,8 @@ class CygwinCCompiler (UnixCCompiler):
# with MSVC 7.0 or later. # with MSVC 7.0 or later.
self.dll_libraries = get_msvcr() self.dll_libraries = get_msvcr()
# __init__ ()
def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts): def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
"""Compiles the source by spawing GCC and windres if needed."""
if ext == '.rc' or ext == '.res': if ext == '.rc' or ext == '.res':
# gcc needs '.res' and '.rc' compiled to object files !!! # gcc needs '.res' and '.rc' compiled to object files !!!
try: try:
@ -170,21 +169,11 @@ class CygwinCCompiler (UnixCCompiler):
except DistutilsExecError, msg: except DistutilsExecError, msg:
raise CompileError, msg raise CompileError, msg
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, """Link the objects."""
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):
# use separate copies, so we can modify the lists # use separate copies, so we can modify the lists
extra_preargs = copy.copy(extra_preargs or []) extra_preargs = copy.copy(extra_preargs or [])
libraries = copy.copy(libraries or []) libraries = copy.copy(libraries or [])
@ -249,42 +238,29 @@ class CygwinCCompiler (UnixCCompiler):
if not debug: if not debug:
extra_preargs.append("-s") extra_preargs.append("-s")
UnixCCompiler.link(self, UnixCCompiler.link(self, target_desc, objects, output_filename,
target_desc, output_dir, libraries, library_dirs,
objects,
output_filename,
output_dir,
libraries,
library_dirs,
runtime_library_dirs, runtime_library_dirs,
None, # export_symbols, we do this in our def-file None, # export_symbols, we do this in our def-file
debug, debug, extra_preargs, extra_postargs, build_temp,
extra_preargs,
extra_postargs,
build_temp,
target_lang) target_lang)
# link ()
# -- Miscellaneous methods ----------------------------------------- # -- Miscellaneous methods -----------------------------------------
# overwrite the one from CCompiler to support rc and res-files def object_filenames(self, source_filenames, strip_dir=0, output_dir=''):
def object_filenames (self, """Adds supports for rc and res files."""
source_filenames, if output_dir is None:
strip_dir=0, output_dir = ''
output_dir=''):
if output_dir is None: output_dir = ''
obj_names = [] obj_names = []
for src_name in source_filenames: for src_name in source_filenames:
# use normcase to make sure '.rc' is really '.rc' and not '.RC' # use normcase to make sure '.rc' is really '.rc' and not '.RC'
(base, ext) = os.path.splitext (os.path.normcase(src_name)) base, ext = os.path.splitext(os.path.normcase(src_name))
if ext not in (self.src_extensions + ['.rc','.res']): if ext not in (self.src_extensions + ['.rc','.res']):
raise UnknownFileError, \ raise UnknownFileError, \
"unknown file type '%s' (from '%s')" % \ "unknown file type '%s' (from '%s')" % (ext, src_name)
(ext, src_name)
if strip_dir: if strip_dir:
base = os.path.basename (base) base = os.path.basename (base)
if ext == '.res' or ext == '.rc': if ext in ('.res', '.rc'):
# these need to be compiled to object files # these need to be compiled to object files
obj_names.append (os.path.join(output_dir, obj_names.append (os.path.join(output_dir,
base + ext + self.obj_extension)) base + ext + self.obj_extension))
@ -293,20 +269,13 @@ class CygwinCCompiler (UnixCCompiler):
base + self.obj_extension)) base + self.obj_extension))
return obj_names return obj_names
# object_filenames ()
# class CygwinCCompiler
# the same as cygwin plus some additional parameters # the same as cygwin plus some additional parameters
class Mingw32CCompiler(CygwinCCompiler): class Mingw32CCompiler(CygwinCCompiler):
""" Handles the Mingw32 port of the GNU C compiler to Windows.
"""
compiler_type = 'mingw32' compiler_type = 'mingw32'
def __init__ (self, def __init__(self, verbose=0, dry_run=0, force=0):
verbose=0,
dry_run=0,
force=0):
CygwinCCompiler.__init__ (self, verbose, dry_run, force) CygwinCCompiler.__init__ (self, verbose, dry_run, force)
@ -342,10 +311,6 @@ class Mingw32CCompiler (CygwinCCompiler):
# with MSVC 7.0 or later. # with MSVC 7.0 or later.
self.dll_libraries = get_msvcr() self.dll_libraries = get_msvcr()
# __init__ ()
# class Mingw32CCompiler
# Because these compilers aren't configured in Python's pyconfig.h file by # Because these compilers aren't configured in Python's pyconfig.h file by
# default, we should at least warn the user if he is using a unmodified # default, we should at least warn the user if he is using a unmodified
# version. # version.