[Numpy-svn] r4365 - branches/numpy.scons/numpy/distutils/scons/checkers

numpy-svn@scip... numpy-svn@scip...
Wed Oct 31 07:45:02 CDT 2007


Author: cdavid
Date: 2007-10-31 07:44:57 -0500 (Wed, 31 Oct 2007)
New Revision: 4365

Modified:
   branches/numpy.scons/numpy/distutils/scons/checkers/custom_checkers.py
   branches/numpy.scons/numpy/distutils/scons/checkers/perflib.py
   branches/numpy.scons/numpy/distutils/scons/checkers/support.py
Log:
Refactor meta checkers.

Modified: branches/numpy.scons/numpy/distutils/scons/checkers/custom_checkers.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/checkers/custom_checkers.py	2007-10-31 10:47:18 UTC (rev 4364)
+++ branches/numpy.scons/numpy/distutils/scons/checkers/custom_checkers.py	2007-10-31 12:44:57 UTC (rev 4365)
@@ -12,7 +12,7 @@
 
 from numpy.distutils.scons.fortran_scons import CheckF77Mangling, CheckF77Clib
 
-from numpy.distutils.scons.configuration import opt_info, add_info
+from numpy.distutils.scons.configuration import add_info
 
 from perflib import CheckMKL, CheckATLAS, CheckSunperf, CheckAccelerate
 from support import check_include_and_run
@@ -25,6 +25,8 @@
     siteconfig, cfgfiles = get_config()
     (cpppath, libs, libpath), found = get_config_from_section(siteconfig, section)
     if found:
+        raise NotImplementedError("FIXME: siteconfig for cblas")
+        # XXX: adapt this to libperf refactor
         headers = ['cblas.h']
         linkflags = []
         cflags = []
@@ -35,86 +37,100 @@
             return st
     else:
         if sys.platform == 'darwin':
-            st = CheckAccelerate(context, autoadd)
+            st, opts = CheckAccelerate(context, autoadd)
             if st:
-                add_info(env, 'cblas', opt_info('Accelerate'))
+                add_info(env, 'cblas', opts)
                 return st
-            st = CheckVeclib(context, autoadd)
-            if st:
-                add_info(env, 'cblas', opt_info('vecLib'))
-                return st
+            #st, opts = CheckVeclib(context, autoadd)
+            #if st:
+            #    add_info(env, 'cblas', opt_info('vecLib'))
+            #    return st
 
-            add_info(env, 'cblas', opt_info(''))
+            add_info(env, 'cblas', 'Def numpy implementation used')
             return 0
             
         else:
             # Check MKL, then ATLAS, then Sunperf
             st, opts = CheckMKL(context, autoadd)
             if st:
-                add_info(env, 'cblas', opt_info('mkl'))
+                add_info(env, 'cblas', opts)
                 return st
-            st = CheckATLAS(context, autoadd)
+            st, opts = CheckATLAS(context, autoadd)
             if st:
-                add_info(env, 'cblas', opt_info('atlas'))
+                add_info(env, 'cblas', opts)
                 return st
-            st = CheckSunperf(context, autoadd)
+            st, opts = CheckSunperf(context, autoadd)
             if st:
-                add_info(env, 'cblas', opt_info('sunperf'))
+                add_info(env, 'cblas', opts)
                 return st
 
-            add_info(env, 'cblas', opt_info(''))
+            add_info(env, 'cblas', 'Def numpy implementation used')
             return 0
 
 def CheckLAPACK(context, autoadd = 1):
-    # XXX: this whole thing is ugly. Think more about how to combine checkers
-    # in 'meta checker' like this.
-    if sys.platform == 'nt':
-        import warnings
-        warning.warn('FIXME: LAPACK checks not implemented yet on win32')
-        return 0
+    # If section lapack is in site.cfg, use those options. Otherwise, use default
+    section = "lapack"
+    siteconfig, cfgfiles = get_config()
+    (cpppath, libs, libpath), found = get_config_from_section(siteconfig, section)
+    if found:
+        raise NotImplementedError("FIXME: siteconfig for lapack")
+        # XXX: adapt this to libperf refactor
+        headers = ['cblas.h']
+        linkflags = []
+        cflags = []
+        st = check_include_and_run(context, 'CBLAS', [], headers, cblas_src,
+                                      libs, libpath, linkflags, cflags, autoadd)
+        if st:
+            add_info(env, 'cblas', opt_info('cblas', site = 1))
+            return st
     else:
-        env = context.env
+        if sys.platform == 'nt':
+            import warnings
+            warning.warn('FIXME: LAPACK checks not implemented yet on win32')
+            return 0
+        else:
+            env = context.env
 
-        # Get fortran stuff
-        if not env.has_key('F77_NAME_MANGLER'):
-            if not CheckF77Mangling(context):
-                return 0
-        if not env.has_key('F77_LDFLAGS'):
-            if not CheckF77Clib(context):
-                return 0
+            # Get fortran stuff
+            if not env.has_key('F77_NAME_MANGLER'):
+                if not CheckF77Mangling(context):
+                    return 0
+            if not env.has_key('F77_LDFLAGS'):
+                if not CheckF77Clib(context):
+                    return 0
 
-        # Get the mangled name of our test function
-        sgesv_string = env['F77_NAME_MANGLER']('sgesv')
-        test_src = lapack_sgesv % sgesv_string
+            # Get the mangled name of our test function
+            sgesv_string = env['F77_NAME_MANGLER']('sgesv')
+            test_src = lapack_sgesv % sgesv_string
 
-        # Check MKL
-        st = CheckMKL(context, autoadd = 1)
-        if st:
-            fdict = env.ParseFlags(context.env['F77_LDFLAGS'])
-            fdict['LIBS'].append('lapack')
-            if env.has_key('LIBS'):
-                fdict['LIBS'].extend(context.env['LIBS'])
-            if env.has_key('LIBPATH'):
-                fdict['LIBPATH'].extend(context.env['LIBPATH'])
-            st = check_include_and_run(context, 'LAPACK (MKL)', [], [],
-                    test_src, fdict['LIBS'], fdict['LIBPATH'], [], [], autoadd = 1)
-            add_info(env, 'lapack', opt_info('mkl'))
-            return st
+            # Check MKL
+            st, opts = CheckMKL(context, autoadd = 1)
+            if st:
+                fdict = env.ParseFlags(context.env['F77_LDFLAGS'])
+                fdict['LIBS'].append('lapack')
+                if env.has_key('LIBS'):
+                    fdict['LIBS'].extend(context.env['LIBS'])
+                if env.has_key('LIBPATH'):
+                    fdict['LIBPATH'].extend(context.env['LIBPATH'])
+                st = check_include_and_run(context, 'LAPACK (MKL)', [], [],
+                        test_src, fdict['LIBS'], fdict['LIBPATH'], [], [], autoadd = 1)
+                add_info(env, 'lapack', opts)
+                return st
 
-        # Check ATLAS
-        st = CheckATLAS(context, autoadd = 1)
-        if st:
-            fdict = env.ParseFlags(context.env['F77_LDFLAGS'])
-            fdict['LIBS'].append('lapack')
-            if env.has_key('LIBS'):
-                fdict['LIBS'].extend(context.env['LIBS'])
-            if env.has_key('LIBPATH'):
-                fdict['LIBPATH'].extend(context.env['LIBPATH'])
-            st = check_include_and_run(context, 'LAPACK (ATLAS)', [], [],
-                    test_src, fdict['LIBS'], fdict['LIBPATH'], [], [], autoadd = 1)
-            add_info(env, 'lapack', opt_info('atlas'))
-            # XXX: Check complete LAPACK or not
-            return st
+            # Check ATLAS
+            st, opts = CheckATLAS(context, autoadd = 1)
+            if st:
+                fdict = env.ParseFlags(context.env['F77_LDFLAGS'])
+                fdict['LIBS'].append('lapack')
+                if env.has_key('LIBS'):
+                    fdict['LIBS'].extend(context.env['LIBS'])
+                if env.has_key('LIBPATH'):
+                    fdict['LIBPATH'].extend(context.env['LIBPATH'])
+                st = check_include_and_run(context, 'LAPACK (ATLAS)', [], [],
+                        test_src, fdict['LIBS'], fdict['LIBPATH'], [], [], autoadd = 1)
+                add_info(env, 'lapack', opts)
+                # XXX: Check complete LAPACK or not
+                return st
 
     return 0
 

Modified: branches/numpy.scons/numpy/distutils/scons/checkers/perflib.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/checkers/perflib.py	2007-10-31 10:47:18 UTC (rev 4364)
+++ branches/numpy.scons/numpy/distutils/scons/checkers/perflib.py	2007-10-31 12:44:57 UTC (rev 4365)
@@ -1,5 +1,5 @@
 #! /usr/bin/env python
-# Last Change: Wed Oct 31 07:00 PM 2007 J
+# Last Change: Wed Oct 31 08:00 PM 2007 J
 
 # This module defines checkers for performances libs providing standard API,
 # such as MKL (Intel), ATLAS, Sunperf (solaris and linux), Accelerate (Mac OS
@@ -35,6 +35,8 @@
     else:
         opts = defopts
 
+    opts['rpath'] = opts['libpath']
+
     env = context.env
 
     # Check whether the header is available (CheckHeader-like checker)
@@ -86,7 +88,7 @@
 
     return st, cfgres
 
-def _check_mkl_version(env, opts):
+def _mkl_version_checker(env, opts):
     version_code = r"""
 #include <stdio.h>
 #include <mkl.h>

Modified: branches/numpy.scons/numpy/distutils/scons/checkers/support.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/checkers/support.py	2007-10-31 10:47:18 UTC (rev 4364)
+++ branches/numpy.scons/numpy/distutils/scons/checkers/support.py	2007-10-31 12:44:57 UTC (rev 4365)
@@ -1,5 +1,5 @@
 #! /usr/bin/env python
-# Last Change: Wed Oct 31 07:00 PM 2007 J
+# Last Change: Wed Oct 31 08:00 PM 2007 J
 
 # This module defines some helper functions, to be used by high level checkers
 
@@ -133,6 +133,36 @@
         msg += ['Version is : %s' % self.version]
         return '\n'.join(msg)
 
+    def __str__(self):
+        return self.__repr__()
+
+def _check_headers(context, cpppath, cflags, headers, autoadd):          
+    """Try to compile code including the given headers."""       
+    env = context.env        
+         
+    #----------------------------        
+    # Check headers are available        
+    #----------------------------        
+    oldCPPPATH = (env.has_key('CPPPATH') and deepcopy(env['CPPPATH'])) or []         
+    oldCFLAGS = (env.has_key('CFLAGS') and deepcopy(env['CFLAGS'])) or []        
+    env.AppendUnique(CPPPATH = cpppath)          
+    env.AppendUnique(CFLAGS = cflags)        
+    # XXX: handle context        
+    hcode = ['#include <%s>' % h for h in headers]       
+         
+    # HACK: we add cpppath in the command of the source, to add dependency of        
+    # the check on the cpppath.          
+    hcode.extend(['#if 0', '%s' % cpppath, '#endif\n'])          
+    src = '\n'.join(hcode)       
+         
+    ret = context.TryCompile(src, '.c')          
+    if ret == 0 or autoadd == 0:         
+        env.Replace(CPPPATH = oldCPPPATH)        
+        env.Replace(CFLAGS = oldCFLAGS)          
+        return 0         
+        
+    return ret 
+
 def check_include_and_run(context, name, cpppath, headers, run_src, libs,
                           libpath, linkflags, cflags, autoadd = 1):
     """This is a basic implementation for generic "test include and run"
@@ -156,7 +186,7 @@
     context.Message('Checking for %s ... ' % name)
     env = context.env
 
-    ret = _check_headers(context, cpppath, cflags, headers)
+    ret = _check_headers(context, cpppath, cflags, headers, autoadd)
     if not ret:
          context.Result('Failed: %s include not found' % name)
 



More information about the Numpy-svn mailing list