]> granicus.if.org Git - python/commitdiff
Added 'preprocess()' method to CCompiler interface, and implemented
authorGreg Ward <gward@python.net>
Wed, 21 Jun 2000 02:58:46 +0000 (02:58 +0000)
committerGreg Ward <gward@python.net>
Wed, 21 Jun 2000 02:58:46 +0000 (02:58 +0000)
it in UnixCCompiler.  Still needs to be implemented in MSVCCompiler (and
whatever other compiler classes are lurking out there, waiting to be
checked in).

Lib/distutils/ccompiler.py
Lib/distutils/unixccompiler.py

index b146f89011be4ffa528971da53706c585c28b196..53d4fa5301bf601e18769ae1430ede0906d8929f 100644 (file)
@@ -414,6 +414,22 @@ class CCompiler:
     # -- Worker methods ------------------------------------------------
     # (must be implemented by subclasses)
 
+    def preprocess (self,
+                    source,
+                    output_file=None,
+                    macros=None,
+                    include_dirs=None,
+                    extra_preargs=None,
+                    extra_postargs=None):
+        """Preprocess a single C/C++ source file, named in 'source'.
+        Output will be written to file named 'output_file', or stdout if
+        'output_file' not supplied.  'macros' is a list of macro
+        definitions as for 'compile()', which will augment the macros set
+        with 'define_macro()' and 'undefine_macro()'.  'include_dirs' is a
+        list of directory names that will be added to the default list.
+        """
+        pass
+
     def compile (self,
                  sources,
                  output_dir=None,
index 4d38e4d8c1fc83c0afea401531d8b23e9667f3e6..47d8ad6325e91649a79c403dceb908f4e7236e88 100644 (file)
@@ -21,6 +21,7 @@ import string, re, os
 from types import *
 from copy import copy
 from distutils import sysconfig
+from distutils.dep_util import newer
 from distutils.ccompiler import \
      CCompiler, gen_preprocess_options, gen_lib_options
 from distutils.errors import \
@@ -104,6 +105,37 @@ class UnixCCompiler (CCompiler):
     # __init__ ()
 
 
+    def preprocess (self,
+                    source,
+                    output_file=None,
+                    macros=None,
+                    include_dirs=None,
+                    extra_preargs=None,
+                    extra_postargs=None):
+
+        (_, macros, include_dirs) = \
+            self._fix_compile_args (None, macros, include_dirs)
+        pp_opts = gen_preprocess_options (macros, include_dirs)
+        cc_args = ['-E'] + pp_opts
+        if output_file:
+            cc_args.extend(['-o', output_file])
+        if extra_preargs:
+            cc_args[:0] = extra_preargs
+        if extra_postargs:
+            extra_postargs.extend(extra_postargs)
+
+        # We need to preprocess: either we're being forced to, or the
+        # source file is newer than the target (or the target doesn't
+        # exist).
+        if self.force or (output_file and newer(source, output_file)):
+            if output_file:
+                self.mkpath(os.path.dirname(output_file))
+            try:
+                self.spawn ([self.cc] + cc_args)
+            except DistutilsExecError, msg:
+                raise CompileError, msg
+
+
     def compile (self,
                  sources,
                  output_dir=None,