/[escript]/branches/postrelease-csirofixes/site_scons/site_init.py
ViewVC logotype

Diff of /branches/postrelease-csirofixes/site_scons/site_init.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/scons/scons_extensions.py revision 297 by jgs, Fri Dec 2 04:57:48 2005 UTC trunk/site_scons/site_init.py revision 3580 by gross, Tue Sep 6 00:31:35 2011 UTC
# Line 1  Line 1 
 # Extensions to Scons  
1    
2  import py_compile  ########################################################
3  import sys  #
4  import os  # Copyright (c) 2003-2010 by University of Queensland
5    # Earth Systems Science Computational Center (ESSCC)
6    # http://www.uq.edu.au/esscc
7    #
8    # Primary Business: Queensland, Australia
9    # Licensed under the Open Software License version 3.0
10    # http://www.opensource.org/licenses/osl-3.0.php
11    #
12    ########################################################
13    
14    __copyright__="""Copyright (c) 2003-2010 by University of Queensland
15    Earth Systems Science Computational Center (ESSCC)
16    http://www.uq.edu.au/esscc
17    Primary Business: Queensland, Australia"""
18    __license__="""Licensed under the Open Software License version 3.0
19    http://www.opensource.org/licenses/osl-3.0.php"""
20    __url__="https://launchpad.net/escript-finley"
21    
22    import sys, os, time, glob, fnmatch, types, py_compile, re
23    
24    def findLibWithHeader(env, libs, header, paths, lang='c'):
25        from SCons.Script.SConscript import Configure
26        inc_path=''
27        lib_path=''
28        # 'paths' may be a prefix, so look for lib and include subdirectories
29        if type(paths)==str:
30            # find the header file first
31            for i in 'include','include64','include32','inc':
32                inc=os.path.join(paths, i)
33                if os.path.isfile(os.path.join(inc, header)):
34                    inc_path=inc
35                    break
36            if inc_path=='':
37                raise RuntimeError('%s not found under %s'%(header,paths))
38    
39            # now try to find a lib directory
40            for l in 'lib','lib64','lib32':
41                lp=os.path.join(paths, l)
42                if os.path.isdir(lp):
43                    lib_path=lp
44                    break
45            if lib_path=='':
46                raise RuntimeError('No lib directory found under %s'%paths)
47        else:
48            if os.path.isfile(os.path.join(paths[0], header)):
49                inc_path=paths[0]
50            else:
51                raise RuntimeError('%s not found under %s'%(header,paths[0]))
52            if os.path.isdir(paths[1]):
53                lib_path=paths[1]
54            else:
55                raise RuntimeError('%s is not a valid path.'%paths[1])
56    
57        # now try the library
58        conf=Configure(env.Clone())
59        conf.env.AppendUnique(CPPPATH = [inc_path])
60        conf.env.AppendUnique(LIBPATH = [lib_path])
61        if type(libs)==str: libs=[libs]
62        # we can't check for each library by itself since they may depend on each
63        # other, so we add all libraries to the link line and check only for one
64        conf.env.AppendUnique(LIBS = libs)
65        if not conf.CheckLibWithHeader(libs[0], header, lang):
66            conf.Finish()
67            raise RuntimeError('Unable to link against %s (paths: %s, %s)'%(libs,inc_path,lib_path))
68    
69        conf.Finish()
70        return inc_path, lib_path
71    
72    
73  # Code to build .pyc from .py  # Code to build .pyc from .py
74  def build_py(target, source, env):  def build_py(target, source, env):
75    py_compile.compile(str(source[0]), str(target[0]))      try:
76    return None         py_compile.compile(str(source[0]), str(target[0]), doraise=True)
77           return 0
78        except py_compile.PyCompileError as e:
79           print e
80           return 1
81          
82    
83  # Code to run unit_test executables  # Code to run unit_test executables
84  def runUnitTest(target, source, env):  def runUnitTest(target, source, env):
85      time_start = time.time()
86    app = str(source[0].abspath)    app = str(source[0].abspath)
87    if not os.system(app):    pn, sn= os.path.split(app)
88      if not os.name== "nt":
89         app = "cd "+pn+"; "+os.path.join(env['bininstall'], "run-escript")+" -bv "+os.path.join('.',sn)
90      else:
91          if env['usempi']:
92              app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\
93                "FINLEY_TEST_DATA,PYVISI_TEST_DATA_ROOT,PYVISI_WORKDIR,PATH %s"\
94                %(pn,env['ENV']['ESCRIPT_NUM_NODES'], sn)
95          else:
96               app = "cd "+ pn +" & "+sn
97      print "Executing test: " + app
98      if not env.Execute(app):
99      open(str(target[0]),'w').write("PASSED\n")      open(str(target[0]),'w').write("PASSED\n")
100      else:
101        return 1
102      print "Test execution time: ", round(time.time() - time_start, 1), " seconds wall time for " + str(source[0].abspath)
103    return None    return None
104    
105    def runPyUnitTest(target, source, env):
106       time_start = time.time()
107       app = str(source[0].abspath)
108       pn, sn= os.path.split(app)
109       if os.name== "nt":
110           if env['usempi']:
111               app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\
112                  "FINLEY_TEST_DATA,PYVISI_TEST_DATA_ROOT,PYVISI_WORKDIR,PATH %s\pythonMPIredirect.exe %s"\
113                  %(pn,env['ENV']['ESCRIPT_NUM_NODES'],env['libinstall'],sn)
114           else:
115               app = "cd "+ pn +" & "+sys.executable + " " + sn
116       else:
117         app = "cd "+pn+"; "+os.path.join(env['bininstall'], "run-escript")+" -ov "+sn
118       print "Executing test: ",app
119       if env.Execute(app) == 0:
120          open(str(target[0]),'w').write("PASSED\n")
121       else:
122         return 1
123       print "Test execution time: ", round(time.time() - time_start, 1), " seconds wall time for " + str(source[0].abspath)
124       return None
125    
126    def eps2pdf(target, source, env):
127    #   if env.Execute("epstopdf "+str(source[0].abspath)+" -o "+str(target[0].abspath))!=0:
128       if env.Execute("ps2pdf -dEPSCrop "+str(source[0].abspath)+" "+str(target[0].abspath))!=0:
129           return 1
130       return None
131    
132    def effectiveName(inname):
133       m=re.compile("^r1i[0-9]{1,2}n[0-9]{1,2}$")   # savanna names take the form r1i?n?
134       if m.match(inname):
135        return "savanna"
136       return inname

Legend:
Removed from v.297  
changed lines
  Added in v.3580

  ViewVC Help
Powered by ViewVC 1.1.26