/[escript]/branches/4.0fordebian/site_scons/site_init.py
ViewVC logotype

Diff of /branches/4.0fordebian/site_scons/site_init.py

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

branches/domexper/site_scons/site_init.py revision 3251 by jfenwick, Thu Oct 7 04:02:30 2010 UTC trunk/site_scons/site_init.py revision 5229 by caltinay, Mon Oct 27 23:39:15 2014 UTC
# Line 1  Line 1 
1    
2  ########################################################  ##############################################################################
3  #  #
4  # Copyright (c) 2003-2010 by University of Queensland  # Copyright (c) 2003-2014 by University of Queensland
5  # Earth Systems Science Computational Center (ESSCC)  # http://www.uq.edu.au
 # http://www.uq.edu.au/esscc  
6  #  #
7  # Primary Business: Queensland, Australia  # Primary Business: Queensland, Australia
8  # Licensed under the Open Software License version 3.0  # Licensed under the Open Software License version 3.0
9  # http://www.opensource.org/licenses/osl-3.0.php  # http://www.opensource.org/licenses/osl-3.0.php
10  #  #
11  ########################################################  # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12    # Development 2012-2013 by School of Earth Sciences
13    # Development from 2014 by Centre for Geoscience Computing (GeoComp)
14    #
15    ##############################################################################
16    
17  __copyright__="""Copyright (c) 2003-2010 by University of Queensland  __copyright__="""Copyright (c) 2003-2014 by University of Queensland
18  Earth Systems Science Computational Center (ESSCC)  http://www.uq.edu.au
 http://www.uq.edu.au/esscc  
19  Primary Business: Queensland, Australia"""  Primary Business: Queensland, Australia"""
20  __license__="""Licensed under the Open Software License version 3.0  __license__="""Licensed under the Open Software License version 3.0
21  http://www.opensource.org/licenses/osl-3.0.php"""  http://www.opensource.org/licenses/osl-3.0.php"""
22  __url__="https://launchpad.net/escript-finley"  __url__="https://launchpad.net/escript-finley"
23    
24  import sys, os, time, glob, fnmatch, types, py_compile, re  import sys, os, time, py_compile, re, subprocess
25    from SCons.Defaults import Chmod, Copy
26    from grouptest import *
27    
28  def findLibWithHeader(env, libs, header, paths, lang='c'):  def findLibWithHeader(env, libs, header, paths, lang='c++'):
29      from SCons.Script.SConscript import Configure      from SCons.Script.SConscript import Configure
30      inc_path=''      inc_path=''
31      lib_path=''      lib_path=''
# Line 59  def findLibWithHeader(env, libs, header, Line 63  def findLibWithHeader(env, libs, header,
63      conf.env.AppendUnique(CPPPATH = [inc_path])      conf.env.AppendUnique(CPPPATH = [inc_path])
64      conf.env.AppendUnique(LIBPATH = [lib_path])      conf.env.AppendUnique(LIBPATH = [lib_path])
65      if type(libs)==str: libs=[libs]      if type(libs)==str: libs=[libs]
66        if len(libs)==0: libs=['']
67      # we can't check for each library by itself since they may depend on each      # we can't check for each library by itself since they may depend on each
68      # other, so we add all libraries to the link line and check only for one      # other, so we add all libraries to the link line and check only for one
69      conf.env.AppendUnique(LIBS = libs)      conf.env.AppendUnique(LIBS = libs)
# Line 69  def findLibWithHeader(env, libs, header, Line 74  def findLibWithHeader(env, libs, header,
74      conf.Finish()      conf.Finish()
75      return inc_path, lib_path      return inc_path, lib_path
76    
77    def detectModule(env, module):
78        from tempfile import TemporaryFile
79        p=subprocess.call([env['pythoncmd'],'-c','import %s'%module], stderr=TemporaryFile())
80        if p != 0:
81            env[module] = False
82            return False
83        env[module] = True
84        return True
85    
86    def write_buildvars(env):
87        buildvars=open(os.path.join(env['libinstall'], 'buildvars'), 'w')
88        for k,v in sorted(env['buildvars'].items()):
89            buildvars.write("%s=%s\n"%(k,v))
90        buildvars.close()
91    
92    def generateTestScripts(env, TestGroups):
93        try:
94            utest=open('utest.sh','w')
95            utest.write(GroupTest.makeHeader(env['PLATFORM'], env['prefix'], False))
96            for tests in TestGroups:
97                utest.write(tests.makeString())
98            utest.close()
99            env.Execute(Chmod('utest.sh', 0o755))
100            print("Generated utest.sh.")
101            # This version contains only python tests - I want this to be usable
102            # from a binary only install if you have the test files
103            utest=open('itest.sh','w')
104            utest.write(GroupTest.makeHeader(env['PLATFORM'], env['prefix'], True))
105            for tests in TestGroups:
106              if tests.exec_cmd=='$PYTHONRUNNER ':
107                utest.write(tests.makeString())
108            utest.close()
109            env.Execute(Chmod('itest.sh', 0o755))
110            print("Generated itest.sh.")        
111        except IOError:
112            env['warnings'].append("Error attempting to write unit test script(s).")
113    
114        # delete scripts upon cleanup
115        env.Clean('target_init', 'utest.sh')
116        env.Clean('target_init', 'itest.sh')
117    
118        # Make sure that the escript wrapper is in place
119        if not os.path.isfile(os.path.join(env['bininstall'], 'run-escript')):
120            print("Copying escript wrapper.")
121            env.Execute(Copy(os.path.join(env['bininstall'],'run-escript'), 'bin/run-escript'))
122    
123  # Code to build .pyc from .py  # Code to build .pyc from .py
124  def build_py(target, source, env):  def build_py(target, source, env):
125      py_compile.compile(str(source[0]), str(target[0]))      try:
126      return 0         py_compile.compile(str(source[0]), str(target[0]), doraise=True)
127           return 0
128        except py_compile.PyCompileError, e:
129           print e
130           return 1
131    
132    
133  # Code to run unit_test executables  # Code to run unit_test executables
134  def runUnitTest(target, source, env):  def runUnitTest(target, source, env):
# Line 80  def runUnitTest(target, source, env): Line 136  def runUnitTest(target, source, env):
136    app = str(source[0].abspath)    app = str(source[0].abspath)
137    pn, sn= os.path.split(app)    pn, sn= os.path.split(app)
138    if not os.name== "nt":    if not os.name== "nt":
139       app = "cd "+pn+"; "+os.path.join(env['bininstall'],"escript")+" -bv "+os.path.join('.',sn)       app = "cd "+pn+"; "+os.path.join(env['bininstall'], "run-escript")+" -bv "+os.path.join('.',sn)
140    else:    else:
141        if env['usempi']:        if env['usempi']:
142            app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\            app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\
143              "FINLEY_TEST_DATA,PYVISI_TEST_DATA_ROOT,PYVISI_WORKDIR,PATH %s"\              "FINLEY_TEST_DATA,PATH %s"\
144              %(pn,env['ENV']['ESCRIPT_NUM_NODES'], sn)              %(pn,env['ENV']['ESCRIPT_NUM_NODES'], sn)
145        else:        else:
146             app = "cd "+ pn +" & "+sn             app = "cd "+ pn +" & "+sn
# Line 96  def runUnitTest(target, source, env): Line 152  def runUnitTest(target, source, env):
152    print "Test execution time: ", round(time.time() - time_start, 1), " seconds wall time for " + str(source[0].abspath)    print "Test execution time: ", round(time.time() - time_start, 1), " seconds wall time for " + str(source[0].abspath)
153    return None    return None
154    
155    def binpath(env, name=None):
156        if not name:
157            return env['bininstall']
158        return os.path.join(env['bininstall'], name)
159    
160  def runPyUnitTest(target, source, env):  def runPyUnitTest(target, source, env):
161     time_start = time.time()     time_start = time.time()
162     app = str(source[0].abspath)     app = str(source[0].abspath)
163     pn, sn= os.path.split(app)     pn, sn= os.path.split(app)
164     if os.name== "nt":     if os.name=="nt":
165           if env['usempi']:
166               app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\
167                  "FINLEY_TEST_DATA,PATH %s\pythonMPIredirect.exe %s"\
168                  %(pn,env['ENV']['ESCRIPT_NUM_NODES'],env['libinstall'],sn)
169           else:
170               app = "cd "+ pn +" & "+sys.executable + " " + sn
171       else:
172         skipfile = os.path.join(env['BUILD_DIR'], sn[:-3]) + ".skipped"
173         try:
174             os.unlink(skipfile)
175         except Exception as e:
176            pass
177         app = "cd "+pn+"; "+binpath(env, "run-escript")+" -ov "+binpath(env,
178                "../tools/testrunner.py")+" -outputfile="+skipfile+" "+sn
179       print "Executing test: ",app
180       if env.Execute(app) == 0:
181          open(str(target[0]),'w').write("PASSED\n")
182       else:
183         return 1
184       print "Test execution time: ", round(time.time() - time_start, 1), " seconds wall time for " + str(source[0].abspath)
185       return None
186    
187    def runPyExample(target, source, env):
188       time_start = time.time()
189       app = str(source[0].abspath)
190       pn, sn= os.path.split(app)
191       if os.name=="nt":
192         if env['usempi']:         if env['usempi']:
193             app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\             app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\
194                "FINLEY_TEST_DATA,PYVISI_TEST_DATA_ROOT,PYVISI_WORKDIR,PATH %s\pythonMPIredirect.exe %s"\                "FINLEY_TEST_DATA,PATH %s\pythonMPIredirect.exe %s"\
195                %(pn,env['ENV']['ESCRIPT_NUM_NODES'],env['libinstall'],sn)                %(pn,env['ENV']['ESCRIPT_NUM_NODES'],env['libinstall'],sn)
196         else:         else:
197             app = "cd "+ pn +" & "+sys.executable + " " + sn             app = "cd "+ pn +" & "+sys.executable + " " + sn
198     else:     else:
199       app = "cd "+pn+"; "+os.path.join(env['bininstall'],"escript")+" -ov "+sn      
200         app = "cd "+pn+"; pwd; "+binpath(env, "run-escript")+" -ov "+sn
201     print "Executing test: ",app     print "Executing test: ",app
202     if env.Execute(app) == 0:     if env.Execute(app) == 0:
203        open(str(target[0]),'w').write("PASSED\n")        open(str(target[0]),'w').write("PASSED\n")
# Line 119  def runPyUnitTest(target, source, env): Line 208  def runPyUnitTest(target, source, env):
208    
209  def eps2pdf(target, source, env):  def eps2pdf(target, source, env):
210  #   if env.Execute("epstopdf "+str(source[0].abspath)+" -o "+str(target[0].abspath))!=0:  #   if env.Execute("epstopdf "+str(source[0].abspath)+" -o "+str(target[0].abspath))!=0:
211     if env.Execute("ps2pdf "+str(source[0].abspath)+" "+str(target[0].abspath))!=0:     if env.Execute("ps2pdf -dEPSCrop "+str(source[0].abspath)+" "+str(target[0].abspath))!=0:
212         return 1         return 1
213     return None     return None
214    
215  def effectiveName(inname):  def effectiveName(inname):
216     m=re.compile("^r1i[0-9]{1,2}n[0-9]{1,2}$")   # savanna names take the form r1i?n?      m=re.compile("^r1i[0-9]{1,2}n[0-9]{1,2}$")  # savanna names take the form r1i?n?
217     if m.match(inname):      if m.match(inname):
218      return "savanna"          return "savanna"
219     return inname      return inname

Legend:
Removed from v.3251  
changed lines
  Added in v.5229

  ViewVC Help
Powered by ViewVC 1.1.26