summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMarc-André Lemburg <mal@egenix.com>2001-02-19 09:20:04 (GMT)
committerMarc-André Lemburg <mal@egenix.com>2001-02-19 09:20:04 (GMT)
commit636b90638a0b26331bf0dc8bd3d16b334126cbb1 (patch)
treef3b00fc9715354a0b41bcf444e24b7b260436537 /Lib
parent373d151666da7201453412e5a3f03db345c512aa (diff)
downloadcpython-636b90638a0b26331bf0dc8bd3d16b334126cbb1.zip
cpython-636b90638a0b26331bf0dc8bd3d16b334126cbb1.tar.gz
cpython-636b90638a0b26331bf0dc8bd3d16b334126cbb1.tar.bz2
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.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/distutils/ccompiler.py48
1 files changed, 40 insertions, 8 deletions
diff --git a/Lib/distutils/ccompiler.py b/Lib/distutils/ccompiler.py
index 5e0b328..0a30640 100644
--- a/Lib/distutils/ccompiler.py
+++ b/Lib/distutils/ccompiler.py
@@ -7,7 +7,7 @@ for the Distutils compiler abstraction model."""
__revision__ = "$Id$"
-import sys, os
+import sys, os, re
from types import *
from copy import copy
from distutils.errors import *
@@ -835,12 +835,44 @@ class CCompiler:
# class CCompiler
-# Map a platform ('posix', 'nt') to the default compiler type for
-# that platform.
-default_compiler = { 'posix': 'unix',
- 'nt': 'msvc',
- 'mac': 'mwerks',
- }
+# 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
@@ -896,7 +928,7 @@ def new_compiler (plat=None,
try:
if compiler is None:
- compiler = default_compiler[plat]
+ compiler = get_default_compiler(plat)
(module_name, class_name, long_description) = compiler_class[compiler]
except KeyError: