mirror of
https://github.com/python/cpython.git
synced 2025-10-21 22:22:48 +00:00
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:
parent
6864d30dfe
commit
1bba31d9a2
5 changed files with 173 additions and 267 deletions
|
@ -80,23 +80,13 @@ class BCPPCompiler(CCompiler) :
|
|||
|
||||
# -- Worker methods ------------------------------------------------
|
||||
|
||||
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) = \
|
||||
self._fix_compile_args (output_dir, macros, include_dirs)
|
||||
(objects, skip_sources) = self._prep_compile (sources, output_dir)
|
||||
|
||||
if extra_postargs is None:
|
||||
extra_postargs = []
|
||||
|
||||
pp_opts = gen_preprocess_options (macros, include_dirs)
|
||||
def compile(self, sources,
|
||||
output_dir=None, macros=None, include_dirs=None, debug=0,
|
||||
extra_preargs=None, extra_postargs=None, depends=None):
|
||||
|
||||
macros, objects, extra_postargs, pp_opts, build = \
|
||||
self._setup_compile(output_dir, macros, include_dirs, sources,
|
||||
depends, extra_postargs)
|
||||
compile_opts = extra_preargs or []
|
||||
compile_opts.append ('-c')
|
||||
if debug:
|
||||
|
@ -104,50 +94,47 @@ class BCPPCompiler(CCompiler) :
|
|||
else:
|
||||
compile_opts.extend (self.compile_options)
|
||||
|
||||
for i in range (len (sources)):
|
||||
src = sources[i] ; obj = objects[i]
|
||||
ext = (os.path.splitext (src))[1]
|
||||
for obj, (src, ext) in build.items():
|
||||
# XXX why do the normpath here?
|
||||
src = os.path.normpath(src)
|
||||
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))
|
||||
|
||||
if skip_sources[src]:
|
||||
log.debug("skipping %s (%s up-to-date)", src, obj)
|
||||
else:
|
||||
src = os.path.normpath(src)
|
||||
obj = os.path.normpath(obj)
|
||||
self.mkpath(os.path.dirname(obj))
|
||||
|
||||
if ext == '.res':
|
||||
# This is already a binary file -- skip it.
|
||||
continue # the 'for' loop
|
||||
if ext == '.rc':
|
||||
# This needs to be compiled to a .res file -- do it now.
|
||||
try:
|
||||
self.spawn (["brcc32", "-fo", obj, src])
|
||||
except DistutilsExecError, msg:
|
||||
raise CompileError, msg
|
||||
continue # the 'for' loop
|
||||
|
||||
# The next two are both for the real compiler.
|
||||
if ext in self._c_extensions:
|
||||
input_opt = ""
|
||||
elif ext in self._cpp_extensions:
|
||||
input_opt = "-P"
|
||||
else:
|
||||
# Unknown file type -- no extra options. The compiler
|
||||
# will probably fail, but let it just in case this is a
|
||||
# file the compiler recognizes even if we don't.
|
||||
input_opt = ""
|
||||
|
||||
output_opt = "-o" + obj
|
||||
|
||||
# Compiler command line syntax is: "bcc32 [options] file(s)".
|
||||
# Note that the source file names must appear at the end of
|
||||
# the command line.
|
||||
if ext == '.res':
|
||||
# This is already a binary file -- skip it.
|
||||
continue # the 'for' loop
|
||||
if ext == '.rc':
|
||||
# This needs to be compiled to a .res file -- do it now.
|
||||
try:
|
||||
self.spawn ([self.cc] + compile_opts + pp_opts +
|
||||
[input_opt, output_opt] +
|
||||
extra_postargs + [src])
|
||||
self.spawn (["brcc32", "-fo", obj, src])
|
||||
except DistutilsExecError, msg:
|
||||
raise CompileError, msg
|
||||
continue # the 'for' loop
|
||||
|
||||
# The next two are both for the real compiler.
|
||||
if ext in self._c_extensions:
|
||||
input_opt = ""
|
||||
elif ext in self._cpp_extensions:
|
||||
input_opt = "-P"
|
||||
else:
|
||||
# Unknown file type -- no extra options. The compiler
|
||||
# will probably fail, but let it just in case this is a
|
||||
# file the compiler recognizes even if we don't.
|
||||
input_opt = ""
|
||||
|
||||
output_opt = "-o" + obj
|
||||
|
||||
# Compiler command line syntax is: "bcc32 [options] file(s)".
|
||||
# Note that the source file names must appear at the end of
|
||||
# the command line.
|
||||
try:
|
||||
self.spawn ([self.cc] + compile_opts + pp_opts +
|
||||
[input_opt, output_opt] +
|
||||
extra_postargs + [src])
|
||||
except DistutilsExecError, msg:
|
||||
raise CompileError, msg
|
||||
|
||||
return objects
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue