Refactor compile() method implementations.

Always use _setup_compile() to do the grunt work of processing
arguments, figuring out which files to compile, and emitting debug
messages for files that are up-to-date.

Use _get_cc_args() when possible.
This commit is contained in:
Jeremy Hylton 2002-06-13 17:28:18 +00:00
parent 6864d30dfe
commit 1bba31d9a2
5 changed files with 173 additions and 267 deletions

View File

@ -80,23 +80,13 @@ class BCPPCompiler(CCompiler) :
# -- Worker methods ------------------------------------------------ # -- Worker methods ------------------------------------------------
def compile (self, def compile(self, sources,
sources, output_dir=None, macros=None, include_dirs=None, debug=0,
output_dir=None, extra_preargs=None, extra_postargs=None, depends=None):
macros=None,
include_dirs=None,
debug=0,
extra_preargs=None,
extra_postargs=None):
(output_dir, macros, include_dirs) = \ macros, objects, extra_postargs, pp_opts, build = \
self._fix_compile_args (output_dir, macros, include_dirs) self._setup_compile(output_dir, macros, include_dirs, sources,
(objects, skip_sources) = self._prep_compile (sources, output_dir) depends, extra_postargs)
if extra_postargs is None:
extra_postargs = []
pp_opts = gen_preprocess_options (macros, include_dirs)
compile_opts = extra_preargs or [] compile_opts = extra_preargs or []
compile_opts.append ('-c') compile_opts.append ('-c')
if debug: if debug:
@ -104,15 +94,12 @@ class BCPPCompiler(CCompiler) :
else: else:
compile_opts.extend (self.compile_options) compile_opts.extend (self.compile_options)
for i in range (len (sources)): for obj, (src, ext) in build.items():
src = sources[i] ; obj = objects[i] # XXX why do the normpath here?
ext = (os.path.splitext (src))[1]
if skip_sources[src]:
log.debug("skipping %s (%s up-to-date)", src, obj)
else:
src = os.path.normpath(src) src = os.path.normpath(src)
obj = os.path.normpath(obj) obj = os.path.normpath(obj)
# XXX _setup_compile() did a mkpath() too but before the normpath.
# Is it possible to skip the normpath?
self.mkpath(os.path.dirname(obj)) self.mkpath(os.path.dirname(obj))
if ext == '.res': if ext == '.res':

View File

@ -62,10 +62,7 @@ class CygwinCCompiler (UnixCCompiler):
shared_lib_format = "%s%s" shared_lib_format = "%s%s"
exe_extension = ".exe" exe_extension = ".exe"
def __init__ (self, def __init__ (self, verbose=0, dry_run=0, force=0):
verbose=0,
dry_run=0,
force=0):
UnixCCompiler.__init__ (self, verbose, dry_run, force) UnixCCompiler.__init__ (self, verbose, dry_run, force)
@ -74,11 +71,12 @@ class CygwinCCompiler (UnixCCompiler):
(status, details)) (status, details))
if status is not CONFIG_H_OK: if status is not CONFIG_H_OK:
self.warn( self.warn(
"Python's pyconfig.h doesn't seem to support your compiler. " + "Python's pyconfig.h doesn't seem to support your compiler. "
("Reason: %s." % details) + "Reason: %s. "
"Compiling may fail because of undefined preprocessor macros.") "Compiling may fail because of undefined preprocessor macros."
% details)
(self.gcc_version, self.ld_version, self.dllwrap_version) = \ self.gcc_version, self.ld_version, self.dllwrap_version = \
get_versions() get_versions()
self.debug_print(self.compiler_type + ": gcc %s, ld %s, dllwrap %s\n" % self.debug_print(self.compiler_type + ": gcc %s, ld %s, dllwrap %s\n" %
(self.gcc_version, (self.gcc_version,
@ -120,38 +118,16 @@ class CygwinCCompiler (UnixCCompiler):
# we put here a adapted version of it. # we put here a adapted version of it.
# (If we would call compile() in the base class, it would do some # (If we would call compile() in the base class, it would do some
# initializations a second time, this is why all is done here.) # initializations a second time, this is why all is done here.)
def compile (self, def compile(self, sources,
sources, output_dir=None, macros=None, include_dirs=None, debug=0,
output_dir=None, extra_preargs=None, extra_postargs=None, depends=None):
macros=None,
include_dirs=None,
debug=0,
extra_preargs=None,
extra_postargs=None):
(output_dir, macros, include_dirs) = \ macros, objects, extra_postargs, pp_opts, build = \
self._fix_compile_args (output_dir, macros, include_dirs) self._setup_compile(output_dir, macros, include_dirs, sources,
(objects, skip_sources) = self._prep_compile (sources, output_dir) depends, extra_postargs)
cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)
# Figure out the options for the compiler command line. for obj, (src, ext) in build.items():
pp_opts = gen_preprocess_options (macros, include_dirs)
cc_args = pp_opts + ['-c']
if debug:
cc_args[:0] = ['-g']
if extra_preargs:
cc_args[:0] = extra_preargs
if extra_postargs is None:
extra_postargs = []
# Compile all source files that weren't eliminated by
# '_prep_compile()'.
for i in range (len (sources)):
src = sources[i] ; obj = objects[i]
ext = (os.path.splitext (src))[1]
if skip_sources[src]:
log.debug("skipping %s (%s up-to-date)", src, obj)
else:
self.mkpath (os.path.dirname (obj))
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:
@ -169,9 +145,6 @@ class CygwinCCompiler (UnixCCompiler):
# Return *all* object filenames, not just the ones we just built. # Return *all* object filenames, not just the ones we just built.
return objects return objects
# compile ()
def link (self, def link (self,
target_desc, target_desc,
objects, objects,

View File

@ -81,38 +81,17 @@ class EMXCCompiler (UnixCCompiler):
# we put here a adapted version of it. # we put here a adapted version of it.
# (If we would call compile() in the base class, it would do some # (If we would call compile() in the base class, it would do some
# initializations a second time, this is why all is done here.) # initializations a second time, this is why all is done here.)
def compile (self,
sources,
output_dir=None,
macros=None,
include_dirs=None,
debug=0,
extra_preargs=None,
extra_postargs=None):
(output_dir, macros, include_dirs) = \ def compile(self, sources,
self._fix_compile_args (output_dir, macros, include_dirs) output_dir=None, macros=None, include_dirs=None, debug=0,
(objects, skip_sources) = self._prep_compile (sources, output_dir) extra_preargs=None, extra_postargs=None, depends=None):
# Figure out the options for the compiler command line. macros, objects, extra_postargs, pp_opts, build = \
pp_opts = gen_preprocess_options (macros, include_dirs) self._setup_compile(output_dir, macros, include_dirs, sources,
cc_args = pp_opts + ['-c'] depends, extra_postargs)
if debug: cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)
cc_args[:0] = ['-g']
if extra_preargs:
cc_args[:0] = extra_preargs
if extra_postargs is None:
extra_postargs = []
# Compile all source files that weren't eliminated by for obj, (src, ext) in build.items():
# '_prep_compile()'.
for i in range (len (sources)):
src = sources[i] ; obj = objects[i]
ext = (os.path.splitext (src))[1]
if skip_sources[src]:
log.debug("skipping %s (%s up-to-date)", src, obj)
else:
self.mkpath (os.path.dirname (obj))
if ext == '.rc': if ext == '.rc':
# gcc requires '.rc' compiled to binary ('.res') files !!! # gcc requires '.rc' compiled to binary ('.res') files !!!
try: try:

View File

@ -277,23 +277,14 @@ class MSVCCompiler (CCompiler) :
# object_filenames () # object_filenames ()
def compile (self, def compile(self, sources,
sources, output_dir=None, macros=None, include_dirs=None, debug=0,
output_dir=None, extra_preargs=None, extra_postargs=None, depends=None):
macros=None,
include_dirs=None,
debug=0,
extra_preargs=None,
extra_postargs=None):
(output_dir, macros, include_dirs) = \ macros, objects, extra_postargs, pp_opts, build = \
self._fix_compile_args (output_dir, macros, include_dirs) self._setup_compile(output_dir, macros, include_dirs, sources,
(objects, skip_sources) = self._prep_compile (sources, output_dir) depends, extra_postargs)
if extra_postargs is None:
extra_postargs = []
pp_opts = gen_preprocess_options (macros, include_dirs)
compile_opts = extra_preargs or [] compile_opts = extra_preargs or []
compile_opts.append ('/c') compile_opts.append ('/c')
if debug: if debug:
@ -301,15 +292,7 @@ class MSVCCompiler (CCompiler) :
else: else:
compile_opts.extend(self.compile_options) compile_opts.extend(self.compile_options)
for i in range (len (sources)): for obj, (src, ext) in build.items():
src = sources[i] ; obj = objects[i]
ext = (os.path.splitext (src))[1]
if skip_sources[src]:
log.debug("skipping %s (%s up-to-date)", src, obj)
else:
self.mkpath (os.path.dirname (obj))
if debug: if debug:
# pass the full pathname to MSVC in debug mode, # pass the full pathname to MSVC in debug mode,
# this allows the debugger to find the source file # this allows the debugger to find the source file

View File

@ -107,30 +107,14 @@ class UnixCCompiler(CCompiler):
def compile(self, sources, def compile(self, sources,
output_dir=None, macros=None, include_dirs=None, debug=0, output_dir=None, macros=None, include_dirs=None, debug=0,
extra_preargs=None, extra_postargs=None): extra_preargs=None, extra_postargs=None, depends=None):
output_dir, macros, include_dirs = \
self._fix_compile_args(output_dir, macros, include_dirs)
objects, skip_sources = self._prep_compile(sources, output_dir)
# Figure out the options for the compiler command line. macros, objects, extra_postargs, pp_opts, build = \
pp_opts = gen_preprocess_options(macros, include_dirs) self._setup_compile(output_dir, macros, include_dirs, sources,
cc_args = pp_opts + ['-c'] depends, extra_postargs)
if debug: cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)
cc_args[:0] = ['-g']
if extra_preargs:
cc_args[:0] = extra_preargs
if extra_postargs is None:
extra_postargs = []
# Compile all source files that weren't eliminated by for obj, (src, ext) in build.items():
# '_prep_compile()'.
for i in range(len(sources)):
src = sources[i]
obj = objects[i]
if skip_sources[src]:
log.debug("skipping %s (%s up-to-date)", src, obj)
else:
self.mkpath(os.path.dirname(obj))
try: try:
self.spawn(self.compiler_so + cc_args + self.spawn(self.compiler_so + cc_args +
[src, '-o', obj] + extra_postargs) [src, '-o', obj] + extra_postargs)