[Python-checkins] CVS: distutils/distutils cygwinccompiler.py,1.5,1.6

Greg Ward python-dev@python.org
Sat, 12 Aug 2000 18:19:02 -0700


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

Modified Files:
	cygwinccompiler.py 
Log Message:
Overhauld 'check_config_h()': now returns a (status, details) tuple,
and is much better documented to boot.


Index: cygwinccompiler.py
===================================================================
RCS file: /cvsroot/python/distutils/distutils/cygwinccompiler.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** cygwinccompiler.py	2000/08/13 00:43:56	1.5
--- cygwinccompiler.py	2000/08/13 01:18:55	1.6
***************
*** 66,74 ****
          UnixCCompiler.__init__ (self, verbose, dry_run, force)
  
!         check_result = check_config_h()
!         self.debug_print("Python's GCC status: %s" % check_result)
!         if check_result[:2] <> "OK":
              self.warn(
!                 "Python's config.h doesn't seem to support your compiler. "
                  "Compiling may fail because of undefined preprocessor macros.")
          
--- 66,76 ----
          UnixCCompiler.__init__ (self, verbose, dry_run, force)
  
!         (status, details) = check_config_h()
!         self.debug_print("Python's GCC status: %s (details: %s)" %
!                          (status, details))
!         if status is not CONFIG_H_OK:
              self.warn(
!                 "Python's config.h doesn't seem to support your compiler.  " +
!                 ("Reason: %s." % details) +
                  "Compiling may fail because of undefined preprocessor macros.")
          
***************
*** 242,255 ****
  # version.
  
  def check_config_h():
!     """Checks if the GCC compiler is mentioned in config.h.  If it is not,
!        compiling probably doesn't work.
      """
!     # return values
!     #  "OK, python was compiled with GCC"
!     #  "OK, python's config.h mentions __GCC__"
!     #  "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
--- 244,271 ----
  # version.
  
+ CONFIG_H_OK = "ok"
+ CONFIG_H_NOTOK = "not ok"
+ CONFIG_H_UNCERTAIN = "uncertain"
+ 
  def check_config_h():
! 
!     """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__".
      """
! 
!     # XXX since this function also checks sys.version, it's not strictly a
!     # "config.h" check -- should probably be renamed...
  
      from distutils import sysconfig
***************
*** 257,282 ****
      # if sys.version contains GCC then python was compiled with
      # GCC, and the config.h file should be OK
!     if -1 == string.find(sys.version,"GCC"):
!         pass # go to the next test
!     else:
!         return "OK, python was compiled with GCC"
      
      try:
          # It would probably better to read single lines to search.
          # But we do this only once, and it is fast enough 
!         f=open(sysconfig.get_config_h_filename())
!         s=f.read()
          f.close()
          
!         # is somewhere a #ifdef __GNUC__ or something similar
!         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
          # the compiler will complain later about this file as missing
!         pass
!     return "uncertain, because we couldn't check it"
  
  def get_versions():
--- 273,301 ----
      # if sys.version contains GCC then python was compiled with
      # GCC, and the config.h file should be OK
!     if string.find(sys.version,"GCC") >= 0:
!         return (CONFIG_H_OK, "sys.version mentions 'GCC'")
      
+     fn = sysconfig.get_config_h_filename()
      try:
          # It would probably better to read single lines to search.
          # But we do this only once, and it is fast enough 
!         f = open(fn)
!         s = f.read()
          f.close()
          
!     except IOError, exc:
          # if we can't read this file, we cannot say it is wrong
          # the compiler will complain later about this file as missing
!         return (CONFIG_H_UNCERTAIN,
!                 "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():