[Python-checkins] CVS: python/dist/src/Lib/distutils ccompiler.py,1.37,1.38

M.-A. Lemburg lemburg@users.sourceforge.net
Mon, 19 Feb 2001 01:20:06 -0800


Update of /cvsroot/python/python/dist/src/Lib/distutils
In directory usw-pr-cvs1:/tmp/cvs-serv10756

Modified Files:
	ccompiler.py 
Log Message:
This patch makes the default compiler determination more flexible
and also takes the sys.platform name into account. This helps on
platforms where there are multiple possible compiler backends (the
one with which Python itself was compiled is preferred over others
in this case).

The patch uses this new technique to enable using cygwin compiler
per default for cygwin compiled Pythons.

Written by Marc-Andre Lemburg. Copyright assigned to Guido van Rossum.



Index: ccompiler.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/distutils/ccompiler.py,v
retrieving revision 1.37
retrieving revision 1.38
diff -C2 -r1.37 -r1.38
*** ccompiler.py	2001/01/16 03:10:43	1.37
--- ccompiler.py	2001/02/19 09:20:04	1.38
***************
*** 8,12 ****
  __revision__ = "$Id$"
  
! import sys, os
  from types import *
  from copy import copy
--- 8,12 ----
  __revision__ = "$Id$"
  
! import sys, os, re
  from types import *
  from copy import copy
***************
*** 836,846 ****
  
  
! # Map a platform ('posix', 'nt') to the default compiler type for
! # that platform.
! default_compiler = { 'posix': 'unix',
!                      'nt': 'msvc',
!                      'mac': 'mwerks',
!                    }
  
  # Map compiler types to (module_name, class_name) pairs -- ie. where to
  # find the code that implements an interface to this compiler.  (The module
--- 836,878 ----
  
  
! # Map a sys.platform/os.name ('posix', 'nt') to the default compiler
! # type for that platform. Keys are interpreted as re match
! # patterns. Order is important; platform mappings are preferred over
! # OS names.
! _default_compilers = (
  
+     # Platform string mappings
+     ('cygwin.*', 'cygwin'),
+     
+     # OS name mappings
+     ('posix', 'unix'),
+     ('nt', 'msvc'),
+     ('mac', 'mwerks'),
+     
+     )
+ 
+ def get_default_compiler(osname=None, platform=None):
+ 
+     """ Determine the default compiler to use for the given platform.
+ 
+         osname should be one of the standard Python OS names (i.e. the
+         ones returned by os.name) and platform the common value
+         returned by sys.platform for the platform in question.
+ 
+         The default values are os.name and sys.platform in case the
+         parameters are not given.
+ 
+     """
+     if osname is None:
+         osname = os.name
+     if platform is None:
+         platform = sys.platform
+     for pattern, compiler in _default_compilers:
+         if re.match(pattern, platform) is not None or \
+            re.match(pattern, osname) is not None:
+             return compiler
+     # Default to Unix compiler
+     return 'unix'
+ 
  # Map compiler types to (module_name, class_name) pairs -- ie. where to
  # find the code that implements an interface to this compiler.  (The module
***************
*** 897,901 ****
      try:
          if compiler is None:
!             compiler = default_compiler[plat]
          
          (module_name, class_name, long_description) = compiler_class[compiler]
--- 929,933 ----
      try:
          if compiler is None:
!             compiler = get_default_compiler(plat)
          
          (module_name, class_name, long_description) = compiler_class[compiler]