public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/auto-numerical-bench:master commit in: numbench/, numbench/utils/
@ 2012-04-09 18:41 Andrea Arteaga
  0 siblings, 0 replies; only message in thread
From: Andrea Arteaga @ 2012-04-09 18:41 UTC (permalink / raw
  To: gentoo-commits

commit:     70c30d0f52febbbf31821e892846862eaaa0a0a2
Author:     Andrea Arteaga <andyspiros <AT> gmail <DOT> com>
AuthorDate: Mon Apr  9 18:38:51 2012 +0000
Commit:     Andrea Arteaga <andyspiros <AT> gmail <DOT> com>
CommitDate: Mon Apr  9 18:38:51 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/auto-numerical-bench.git;a=commit;h=70c30d0f

Environment files under (root)/etc/env.d are interpreted.

---
 numbench/main.py          |    5 ++-
 numbench/utils/envread.py |   94 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 98 insertions(+), 1 deletions(-)

diff --git a/numbench/main.py b/numbench/main.py
index fd2cf05..6e9fb2c 100644
--- a/numbench/main.py
+++ b/numbench/main.py
@@ -94,7 +94,7 @@ from fnmatch import fnmatch
 from os.path import join as pjoin
 
 import benchconfig as cfg, confinput, report
-from utils import benchutils as bu, portageutils as pu
+from utils import envread, benchutils as bu, portageutils as pu
 from benchprint import Print
 
 
@@ -216,6 +216,9 @@ for tn,(name,test) in enumerate(cfg.tests.items(),1):
                 
     test['implementations'] = impls
 
+    # Automatically add environment
+    envread.envread(test)
+
     # Test every implementation
     test['results'] = {}
     if len(impls) == 0:

diff --git a/numbench/utils/envread.py b/numbench/utils/envread.py
new file mode 100644
index 0000000..126f225
--- /dev/null
+++ b/numbench/utils/envread.py
@@ -0,0 +1,94 @@
+#=====================================================
+# Copyright (C) 2012 Andrea Arteaga <andyspiros@gmail.com>
+#=====================================================
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+#
+import os, shlex
+from os.path import isfile, join as pjoin
+from ..benchconfig import libdir
+
+def transformPaths(root, value):
+    paths = value.split(':')
+    newpaths = ''
+    for p in paths:
+        if p[0] == '/':
+            newpaths += ':' + (root + p)
+        else:
+            newpaths += ':' + (p)
+    return newpaths
+        
+
+def envread(test):
+    # Set default paths
+    path = pjoin(test['root'], 'bin') + ':' +  pjoin(test['root'], 'usr/bin')
+    libpath = pjoin(test['root'], libdir)
+    addenv = dict( PATH=path, LIBRARY_PATH=libpath, LD_LIBRARY_PATH=libpath )
+    
+    # Merge environment
+    for k,v in addenv.items():
+        if test['compileenv'].has_key(k):
+            test['compileenv'][k] += ':' + v
+        else:
+            test['compileenv'][k] = v
+            
+        if test['runenv'].has_key(k):
+            test['runenv'][k] += ':' + v
+        else:
+            test['runenv'][k] = v
+
+
+    # Read environment files in (root)/etc/env.d
+    envdir = pjoin(test['root'], 'etc', 'env.d')
+    files = [pjoin(envdir, i) for i in os.listdir(envdir)]
+    files = [i for i in files if isfile(i)]
+    files.sort()
+    
+    for envf in files:
+        fs = file(envf, 'r')
+        for l in fs.readlines():
+            l = l.strip().split('=', 1)
+            vname = l[0]
+            vvalue = shlex.split(l[1])[0]
+            
+            if vname[-4:] == 'PATH':
+                # Append paths in colon-separated list
+                newpaths = transformPaths(test['root'], vvalue)
+                
+                # Compile environment
+                if test['compileenv'].has_key(vname):
+                    newvar = test['compileenv'][vname] + newpaths
+                else:
+                    newvar = newpaths[1:]
+                test['compileenv'][vname] = newvar
+                
+                # Run-time environment
+                if test['runenv'].has_key(vname):
+                    newvar = test['runenv'][vname] + newpaths
+                else:
+                    newvar = newpaths[1:]
+                test['runenv'][vname] = newvar
+                
+            else:
+                # Substitute other variables
+                test['compileenv'][vname] = vvalue
+                test['runenv'][vname] = vvalue
+        
+    # Add LDPATH to LIBRARY_PATH and LD_LIBRARY_PATH
+    if test['compileenv'].has_key('LDPATH'):
+        test['compileenv']['LIBRARY_PATH'] += ':' + test['compileenv']['LDPATH']
+        test['compileenv']['LD_LIBRARY_PATH']+= ':'+test['compileenv']['LDPATH']
+    if test['runenv'].has_key('LDPATH'):
+        test['runenv']['LIBRARY_PATH'] += ':' + test['runenv']['LDPATH']
+        test['runenv']['LD_LIBRARY_PATH'] += ':' + test['runenv']['LDPATH']



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2012-04-09 18:41 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-09 18:41 [gentoo-commits] proj/auto-numerical-bench:master commit in: numbench/, numbench/utils/ Andrea Arteaga

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox