[Numpy-svn] r4410 - in branches/numpy.scons/numpy: distutils/scons/checkers scons_fake

numpy-svn@scip... numpy-svn@scip...
Wed Nov 7 05:14:35 CST 2007


Author: cdavid
Date: 2007-11-07 05:14:25 -0600 (Wed, 07 Nov 2007)
New Revision: 4410

Modified:
   branches/numpy.scons/numpy/distutils/scons/checkers/custom_checkers.py
   branches/numpy.scons/numpy/distutils/scons/checkers/perflib.py
   branches/numpy.scons/numpy/scons_fake/setup.py
   branches/numpy.scons/numpy/scons_fake/setupscons.py
Log:
Proper support for unsperf: since xlic_lib=sunperf does not work for shared libraries, hack to get link options from verbose link

Modified: branches/numpy.scons/numpy/distutils/scons/checkers/custom_checkers.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/checkers/custom_checkers.py	2007-11-07 09:55:10 UTC (rev 4409)
+++ branches/numpy.scons/numpy/distutils/scons/checkers/custom_checkers.py	2007-11-07 11:14:25 UTC (rev 4410)
@@ -87,14 +87,14 @@
                     add_info(env, 'cblas', res)
                 return st
 
-            # # Check Sunperf
-            # st, res = CheckSunperf(context, autoadd)
-            # if st:
-            #     st = check_include_and_run(context, 'CBLAS (Sunperf)', res.cfgopts,
-            #                                [], cblas_src, autoadd)
-            #     if st:
-            #         add_info(env, 'cblas', res)
-            #     return st
+            # Check Sunperf
+            st, res = CheckSunperf(context, autoadd)
+            if st:
+                st = check_include_and_run(context, 'CBLAS (Sunperf)', res.cfgopts,
+                                           [], cblas_src, autoadd)
+                if st:
+                    add_info(env, 'cblas', res)
+                return st
 
             add_info(env, 'cblas', 'Def numpy implementation used')
             return 0

Modified: branches/numpy.scons/numpy/distutils/scons/checkers/perflib.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/checkers/perflib.py	2007-11-07 09:55:10 UTC (rev 4409)
+++ branches/numpy.scons/numpy/distutils/scons/checkers/perflib.py	2007-11-07 11:14:25 UTC (rev 4410)
@@ -10,6 +10,7 @@
 import re
 import os
 from os.path import join as pjoin
+from copy import deepcopy
 
 from numpy.distutils.system_info import default_lib_dirs
 from numpy.distutils.scons.core.libinfo import get_config_from_section, get_config
@@ -20,7 +21,7 @@
 from support import save_and_set, restore, ConfigOpts, ConfigRes
 
 def _check(context, name, section, defopts, headers_to_check, funcs_to_check, 
-           check_version, version_checker, autoadd):
+           check_version, version_checker, autoadd, rpath_is_libpath = True):
     """Generic implementation for perflib check.
 
     This checks for header (by compiling code including them) and symbols in
@@ -47,7 +48,8 @@
     else:
         opts = defopts
 
-    opts['rpath'] = opts['libpath']
+    if rpath_is_libpath:
+	opts['rpath'] = deepcopy(opts['libpath'])
 
     env = context.env
 
@@ -224,6 +226,11 @@
                   check_version, None, autoadd)
 
 
+from os.path import basename, dirname
+from copy import deepcopy
+from numpy.distutils.scons.core.utils import popen_wrapper
+from numpy.distutils.scons.testcode_snippets import cblas_sgemm
+
 def CheckSunperf(context, autoadd = 1, check_version = 0):
     """Checker for sunperf."""
     name    = 'Sunperf'
@@ -233,5 +240,104 @@
     headers = ['sunperf.h']
     funcs   = ['cblas_sgemm']
     
-    return _check(context, name, section, defopts, headers, funcs,
-                  check_version, None, autoadd)
+    st, res = _check(context, name, section, defopts, headers, funcs,
+                check_version, None, autoadd)
+
+    if not st:
+	return st, res
+    # We are not done: the option -xlic_lib=sunperf is not used by the linked
+    # for shared libraries, I have no idea why. So if the test is succesfull,
+    # we need more work to get the link options necessary to make the damn
+    # thing work.
+    context.Message('Getting link options of sunperf ... ')
+
+    opts = res.cfgopts
+    test_code = cblas_sgemm
+    env = context.env
+    saved = save_and_set(env, opts)
+    try:
+        st = context.TryCompile(test_code, '.c')
+    finally:
+        restore(env, saved)
+
+    if not res:
+	return context.Result('Failed !'), res
+
+    saved = save_and_set(env, opts)
+    env.Append(LINKFLAGS = '-#')
+    oldLINK = env['LINK']
+    env['LINK'] = '$CC'
+    try:
+        # XXX: does this scheme to get the program name always work ? Can
+        # we use Scons to get the target name from the object name ?
+        slast = str(context.lastTarget)
+        dir = dirname(slast)
+        test_prog = pjoin(dir, basename(slast).split('.')[0])
+    
+        cmd = context.env.subst('$LINKCOM', 
+            		    target = context.env.File(test_prog),
+            		    source = context.lastTarget)
+        st, out = popen_wrapper(cmd, merge = True)
+    finally:
+        restore(env, saved)
+        env['LINK'] = oldLINK
+    
+    # If the verbose output succeeds, parse the output
+    if not st:
+        st = 1
+        pa = floupi(out)
+        for k, v in pa.items():
+    	    opts[k].extend(deepcopy(v))
+        res = ConfigRes(name, opts, res.is_customized())
+	context.Result('Succeeded !')
+    else:
+        st = 0
+	context.Result('Failed !')
+
+    return st, res
+
+haha = r"""
+cc -o build/scons/numpy/scons_fake/checkers/.sconf/conftest_5 -xlic_lib=sunperf -# build/scons/numpy/scons_fake/checkers/.sconf/conftest_5.o
+### Note: NLSPATH = /opt/SUNWspro/prod/bin/../lib/locale/%L/LC_MESSAGES/%N.cat:/opt/SUNWspro/prod/bin/../../lib/locale/%L/LC_MESSAGES/%N.cat
+###     command line files and options (expanded):
+	### -xlic_lib=sunperf build/scons/numpy/scons_fake/checkers/.sconf/conftest_5.o -o build/scons/numpy/scons_fake/checkers/.sconf/conftest_5
+	### Note: LD_LIBRARY_PATH = <null>
+	### Note: LD_RUN_PATH = <null>
+	/usr/ccs/bin/ld /opt/SUNWspro/prod/lib/crti.o /opt/SUNWspro/prod/lib/crt1.o /opt/SUNWspro/prod/lib/values-xa.o -o build/scons/numpy/scons_fake/checkers/.sconf/conftest_5 -lsunperf -lfui -lfsu -lmtsk -lsunmath -lpicl -lm build/scons/numpy/scons_fake/checkers/.sconf/conftest_5.o -Y "P,/opt/SUNWspro/lib:/opt/SUNWspro/prod/lib:/usr/ccs/lib:/lib:/usr/lib" -Qy -R/opt/SUNWspro/lib -lc /opt/SUNWspro/prod/lib/crtn.o"""
+
+def floupi(out):
+    import shlex
+    import os
+    lexer = shlex.shlex(out, posix = True)
+    lexer.whitespace_split = True
+
+    accept_libs = ['sunperf', 'fui', 'fsu', 'mtsk', 'sunmath']
+    keep = dict(zip(['libs', 'libpath', 'rpath'], [[], [], []]))
+    t = lexer.get_token()
+    while t:
+        def parse(token):
+            if token.startswith('-l'):
+                n = token.split('-l')[1]
+                if n in accept_libs:
+                    keep['libs'].append(n)
+                t = lexer.get_token()
+            elif token.startswith('-Y'):
+                n = token
+                t = lexer.get_token()
+		if t.startswith('P,'):
+		    t = t[2:]
+                nt = t.split(os.pathsep)
+                keep['libpath'].extend(nt)
+            elif token.startswith('-Qy'):
+                n = token
+                t = lexer.get_token()
+                if t.startswith('-R'):
+                    arg = t.split('-R', 1)[1]
+                    nt = arg.split(os.pathsep)
+                    keep['rpath'].extend(nt)
+            else:
+                t = lexer.get_token()
+            return t
+        t = parse(t)
+
+    return keep

Modified: branches/numpy.scons/numpy/scons_fake/setup.py
===================================================================
--- branches/numpy.scons/numpy/scons_fake/setup.py	2007-11-07 09:55:10 UTC (rev 4409)
+++ branches/numpy.scons/numpy/scons_fake/setup.py	2007-11-07 11:14:25 UTC (rev 4410)
@@ -5,10 +5,10 @@
     from numpy.distutils.misc_util import Configuration
     config = Configuration('scons_fake',parent_package,top_path)
 
+    config.add_subpackage('checkers')
     config.add_subpackage('pyext')
     config.add_subpackage('ctypesext')
     config.add_subpackage('checklib')
-    config.add_subpackage('checkers')
     config.add_subpackage('hook')
     return config
 

Modified: branches/numpy.scons/numpy/scons_fake/setupscons.py
===================================================================
--- branches/numpy.scons/numpy/scons_fake/setupscons.py	2007-11-07 09:55:10 UTC (rev 4409)
+++ branches/numpy.scons/numpy/scons_fake/setupscons.py	2007-11-07 11:14:25 UTC (rev 4410)
@@ -5,10 +5,10 @@
     from numpy.distutils.misc_util import Configuration
     config = Configuration('scons_fake',parent_package,top_path)
 
+    config.add_subpackage('checkers')
     config.add_subpackage('pyext')
     config.add_subpackage('ctypesext')
     config.add_subpackage('checklib')
-    config.add_subpackage('checkers')
     config.add_subpackage('hook')
     return config
 



More information about the Numpy-svn mailing list