Commit c8e815fb authored by Greg Ward's avatar Greg Ward

Overhauld 'check_config_h()': now returns a (status, details) tuple,

and is much better documented to boot.
parent f2a6960d
...@@ -65,11 +65,13 @@ class CygwinCCompiler (UnixCCompiler): ...@@ -65,11 +65,13 @@ class CygwinCCompiler (UnixCCompiler):
UnixCCompiler.__init__ (self, verbose, dry_run, force) UnixCCompiler.__init__ (self, verbose, dry_run, force)
check_result = check_config_h() (status, details) = check_config_h()
self.debug_print("Python's GCC status: %s" % check_result) self.debug_print("Python's GCC status: %s (details: %s)" %
if check_result[:2] <> "OK": (status, details))
if status is not CONFIG_H_OK:
self.warn( self.warn(
"Python's config.h doesn't seem to support your compiler. " "Python's config.h doesn't seem to support your compiler. " +
("Reason: %s." % details) +
"Compiling may fail because of undefined preprocessor macros.") "Compiling may fail because of undefined preprocessor macros.")
(self.gcc_version, self.ld_version, self.dllwrap_version) = \ (self.gcc_version, self.ld_version, self.dllwrap_version) = \
...@@ -241,43 +243,60 @@ class Mingw32CCompiler (CygwinCCompiler): ...@@ -241,43 +243,60 @@ class Mingw32CCompiler (CygwinCCompiler):
# default, we should at least warn the user if he is using a unmodified # default, we should at least warn the user if he is using a unmodified
# version. # version.
CONFIG_H_OK = "ok"
CONFIG_H_NOTOK = "not ok"
CONFIG_H_UNCERTAIN = "uncertain"
def check_config_h(): def check_config_h():
"""Checks if the GCC compiler is mentioned in config.h. If it is not,
compiling probably doesn't work. """Check if the current Python installation (specifically, config.h)
appears amenable to building extensions with GCC. Returns a tuple
(status, details), where 'status' is one of the following constants:
CONFIG_H_OK
all is well, go ahead and compile
CONFIG_H_NOTOK
doesn't look good
CONFIG_H_UNCERTAIN
not sure -- unable to read config.h
'details' is a human-readable string explaining the situation.
Note there are two ways to conclude "OK": either 'sys.version' contains
the string "GCC" (implying that this Python was built with GCC), or the
installed "config.h" contains the string "__GNUC__".
""" """
# return values
# "OK, python was compiled with GCC" # XXX since this function also checks sys.version, it's not strictly a
# "OK, python's config.h mentions __GCC__" # "config.h" check -- should probably be renamed...
# "uncertain, because we couldn't check it"
# "not OK, because we didn't found __GCC__ in config.h"
# You could check check_config_h()[:2] == "OK"
from distutils import sysconfig from distutils import sysconfig
import string,sys import string,sys
# if sys.version contains GCC then python was compiled with # if sys.version contains GCC then python was compiled with
# GCC, and the config.h file should be OK # GCC, and the config.h file should be OK
if -1 == string.find(sys.version,"GCC"): if string.find(sys.version,"GCC") >= 0:
pass # go to the next test return (CONFIG_H_OK, "sys.version mentions 'GCC'")
else:
return "OK, python was compiled with GCC"
fn = sysconfig.get_config_h_filename()
try: try:
# It would probably better to read single lines to search. # It would probably better to read single lines to search.
# But we do this only once, and it is fast enough # But we do this only once, and it is fast enough
f=open(sysconfig.get_config_h_filename()) f = open(fn)
s=f.read() s = f.read()
f.close() f.close()
# is somewhere a #ifdef __GNUC__ or something similar except IOError, exc:
if -1 == string.find(s,"__GNUC__"):
return "not OK, because we didn't found __GCC__ in config.h"
else:
return "OK, python's config.h mentions __GCC__"
except IOError:
# if we can't read this file, we cannot say it is wrong # if we can't read this file, we cannot say it is wrong
# the compiler will complain later about this file as missing # the compiler will complain later about this file as missing
pass return (CONFIG_H_UNCERTAIN,
return "uncertain, because we couldn't check it" "couldn't read '%s': %s" % (fn, exc.strerror))
else:
# "config.h" contains an "#ifdef __GNUC__" or something similar
if string.find(s,"__GNUC__") >= 0:
return (CONFIG_H_OK, "'%s' mentions '__GNUC__'" % fn)
else:
return (CONFIG_H_NOTOK, "'%s' does not mention '__GNUC__'" % fn)
def get_versions(): def get_versions():
""" Try to find out the versions of gcc, ld and dllwrap. """ Try to find out the versions of gcc, ld and dllwrap.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment