1818 HAVE_CYTHON = False
1919
2020
21- def get_debug_option ():
21+ def get_distutils_option (option , commands ):
22+ """
23+ Returns the value of the given distutils option. If the option is not
24+ set, returns None.
25+
26+ Parameters
27+ ----------
28+ option : str
29+ The name of the option
30+
31+ commands : list of str
32+ The list of commands on which this option is available
33+ """
2234 # Pre-parse the Distutils command-line options and config files to
23- # determine whether or not the --debug option was set.
24- # Normally the only options that allow the debug option are build,
25- # build_ext, and build_clib. So for the sake of generality it's best to
26- # just use the build command.
35+ # if the option is set.
2736 dist = Distribution ()
2837 try :
2938 dist .parse_config_files ()
@@ -32,22 +41,23 @@ def get_debug_option():
3241 # Let distutils handle this itself
3342 return None
3443
35- debug_build_cmds = ['build' , 'build_ext' , 'build_clib' ]
36-
37- # First ensure that one of the commands that accepts --debug is being run
38- for cmd in debug_build_cmds :
44+ for cmd in commands :
3945 if cmd in dist .commands :
4046 break
4147 else :
4248 return None
4349
44- for cmd in debug_build_cmds :
50+ for cmd in commands :
4551 cmd_opts = dist .get_option_dict (cmd )
46- if 'debug' in cmd_opts :
47- debug = bool (cmd_opts ['debug' ][1 ])
48- break
52+ if option in cmd_opts :
53+ return cmd_opts [option ][1 ]
4954 else :
50- debug = False
55+ return None
56+
57+
58+ def get_debug_option ():
59+ debug = bool (get_distutils_option (
60+ 'debug' , ['build' , 'build_ext' , 'build_clib' ]))
5161
5262 try :
5363 from astropy .version import debug as current_debug
@@ -148,6 +158,40 @@ def get_numpy_include_path():
148158 return numpy_include
149159
150160
161+ def adjust_compiler ():
162+ """
163+ This function detects broken compilers and switches to another. If
164+ the environment variable CC is explicitly set, or a compiler is
165+ specified on the commandline, no override is performed -- the purpose
166+ here is to only override a default compiler.
167+
168+ The specific compilers with problems are:
169+ - The default compiler in XCode-4.2, llvm-gcc-4.2,
170+ segfaults when compiling wcslib.
171+
172+ The set of broken compilers can be updated by changing the
173+ compiler_mapping variable.
174+ """
175+ if 'CC' in os .environ :
176+ return
177+
178+ if get_distutils_option (
179+ 'compiler' , ['build' , 'build_ext' , 'build_clib' ]) is not None :
180+ return
181+
182+ from distutils import ccompiler
183+ import subprocess
184+
185+ compiler_mapping = {
186+ 'i686-apple-darwin11-llvm-gcc-4.2' : 'clang'
187+ }
188+
189+ c = ccompiler .new_compiler ()
190+ output = subprocess .check_output (c .compiler + ['--version' ])
191+ version = output .split ()[0 ]
192+ if version in compiler_mapping :
193+ os .environ ['CC' ] = compiler_mapping [version ]
194+
151195
152196################################################################################
153197# Backport of importlib.import_module from 3.x. This backport was provided by
0 commit comments