[Python-checkins] CVS: distutils/distutils ccompiler.py,1.22,1.23 unixccompiler.py,1.25,1.26

Greg Ward python-dev@python.org
Tue, 20 Jun 2000 19:58:49 -0700


Update of /cvsroot/python/distutils/distutils
In directory slayer.i.sourceforge.net:/tmp/cvs-serv14626

Modified Files:
	ccompiler.py unixccompiler.py 
Log Message:
Added 'preprocess()' method to CCompiler interface, and implemented
it in UnixCCompiler.  Still needs to be implemented in MSVCCompiler (and
whatever other compiler classes are lurking out there, waiting to be
checked in).

Index: ccompiler.py
===================================================================
RCS file: /cvsroot/python/distutils/distutils/ccompiler.py,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -r1.22 -r1.23
*** ccompiler.py	2000/06/07 03:00:05	1.22
--- ccompiler.py	2000/06/21 02:58:46	1.23
***************
*** 415,418 ****
--- 415,434 ----
      # (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,

Index: unixccompiler.py
===================================================================
RCS file: /cvsroot/python/distutils/distutils/unixccompiler.py,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -r1.25 -r1.26
*** unixccompiler.py	2000/05/30 02:02:49	1.25
--- unixccompiler.py	2000/06/21 02:58:46	1.26
***************
*** 22,25 ****
--- 22,26 ----
  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
***************
*** 103,106 ****
--- 104,138 ----
  
      # __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