/[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 branches/4.0fordebian/site_scons/site_init.py revision 5566 by jfenwick, Fri Mar 27 00:35:24 2015 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 write_launcher(env):
93        reps={'%n':'${ESCRIPT_NUM_NODES}', '%p':'${ESCRIPT_NUM_PROCS}',
94              '%N':'${TOTPROC}', '%t':'${ESCRIPT_NUM_THREADS}', '%f':'${HOSTFILE}',
95              '%h':'${HOSTLIST}', '%e':'${EXPORT_ENV}', '%b':'${EXEC_CMD}'}
96        pre=env['prelaunch']
97        cmd=env['launcher']
98        post=env['postlaunch']
99        # %b should be present in launcher at least
100        if not '%b' in cmd:
101            raise RuntimeError('option "launcher" must contain %b!')
102    
103        for k, v in reps.iteritems():
104            pre = pre.replace(k, v)
105            cmd = cmd.replace(k, v)
106            post = post.replace(k, v)
107        try:
108            launchscript = os.path.join(env['bininstall'], 'run-escript')
109            launcher=open(launchscript, 'w')
110            for line in open('run-escript.in','r').readlines():
111                launcher.write(line.replace('@@PRELAUNCH', pre).replace('@@LAUNCH', cmd).replace('@@POSTLAUNCH', post))
112            launcher.close()
113            env.Execute(Chmod(launchscript, 0o755))
114        except IOError:
115            env['warnings'].append("Error attempting to write launcher script.")
116    
117    def generateTestScripts(env, TestGroups):
118        try:
119            utest=open('utest.sh','w')
120            utest.write(GroupTest.makeHeader(env['PLATFORM'], env['prefix'], False))
121            for tests in TestGroups:
122                utest.write(tests.makeString())
123            utest.close()
124            env.Execute(Chmod('utest.sh', 0o755))
125            print("Generated utest.sh.")
126            # This version contains only python tests - I want this to be usable
127            # from a binary only install if you have the test files
128            utest=open('itest.sh','w')
129            utest.write(GroupTest.makeHeader(env['PLATFORM'], env['prefix'], True))
130            for tests in TestGroups:
131              if tests.exec_cmd=='$PYTHONRUNNER ':
132                utest.write(tests.makeString())
133            utest.close()
134            env.Execute(Chmod('itest.sh', 0o755))
135            print("Generated itest.sh.")        
136        except IOError:
137            env['warnings'].append("Error attempting to write unit test script(s).")
138    
139        # delete scripts upon cleanup
140        env.Clean('target_init', 'utest.sh')
141        env.Clean('target_init', 'itest.sh')
142    
143  # Code to build .pyc from .py  # Code to build .pyc from .py
144  def build_py(target, source, env):  def build_py(target, source, env):
145      py_compile.compile(str(source[0]), str(target[0]))      try:
146      return 0         py_compile.compile(str(source[0]), str(target[0]), doraise=True)
147           return 0
148        except py_compile.PyCompileError, e:
149           print e
150           return 1
151    
152    
153  # Code to run unit_test executables  # Code to run unit_test executables
154  def runUnitTest(target, source, env):  def runUnitTest(target, source, env):
# Line 80  def runUnitTest(target, source, env): Line 156  def runUnitTest(target, source, env):
156    app = str(source[0].abspath)    app = str(source[0].abspath)
157    pn, sn= os.path.split(app)    pn, sn= os.path.split(app)
158    if not os.name== "nt":    if not os.name== "nt":
159       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)
160    else:    else:
161        if env['usempi']:        if env['usempi']:
162            app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\            app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\
163              "FINLEY_TEST_DATA,PYVISI_TEST_DATA_ROOT,PYVISI_WORKDIR,PATH %s"\              "FINLEY_TEST_DATA,PATH %s"\
164              %(pn,env['ENV']['ESCRIPT_NUM_NODES'], sn)              %(pn,env['ENV']['ESCRIPT_NUM_NODES'], sn)
165        else:        else:
166             app = "cd "+ pn +" & "+sn             app = "cd "+ pn +" & "+sn
# Line 96  def runUnitTest(target, source, env): Line 172  def runUnitTest(target, source, env):
172    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)
173    return None    return None
174    
175    def binpath(env, name=None):
176        if not name:
177            return env['bininstall']
178        return os.path.join(env['bininstall'], name)
179    
180  def runPyUnitTest(target, source, env):  def runPyUnitTest(target, source, env):
181     time_start = time.time()     time_start = time.time()
182     app = str(source[0].abspath)     app = str(source[0].abspath)
183     pn, sn= os.path.split(app)     pn, sn= os.path.split(app)
184     if os.name== "nt":     if os.name=="nt":
185           if env['usempi']:
186               app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\
187                  "FINLEY_TEST_DATA,PATH %s\pythonMPIredirect.exe %s"\
188                  %(pn,env['ENV']['ESCRIPT_NUM_NODES'],env['libinstall'],sn)
189           else:
190               app = "cd "+ pn +" & "+sys.executable + " " + sn
191       else:
192         skipfile = os.path.join(env['BUILD_DIR'], sn[:-3]) + ".skipped"
193         try:
194             os.unlink(skipfile)
195         except Exception as e:
196            pass
197         app = "cd "+pn+"; "+binpath(env, "run-escript")+" -ov "+binpath(env,
198                "../tools/testrunner.py")+" -outputfile="+skipfile+" "+sn
199       print "Executing test: ",app
200       if env.Execute(app) == 0:
201          open(str(target[0]),'w').write("PASSED\n")
202       else:
203         return 1
204       print "Test execution time: ", round(time.time() - time_start, 1), " seconds wall time for " + str(source[0].abspath)
205       return None
206    
207    def runPyExample(target, source, env):
208       time_start = time.time()
209       app = str(source[0].abspath)
210       pn, sn= os.path.split(app)
211       if os.name=="nt":
212         if env['usempi']:         if env['usempi']:
213             app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\             app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\
214                "FINLEY_TEST_DATA,PYVISI_TEST_DATA_ROOT,PYVISI_WORKDIR,PATH %s\pythonMPIredirect.exe %s"\                "FINLEY_TEST_DATA,PATH %s\pythonMPIredirect.exe %s"\
215                %(pn,env['ENV']['ESCRIPT_NUM_NODES'],env['libinstall'],sn)                %(pn,env['ENV']['ESCRIPT_NUM_NODES'],env['libinstall'],sn)
216         else:         else:
217             app = "cd "+ pn +" & "+sys.executable + " " + sn             app = "cd "+ pn +" & "+sys.executable + " " + sn
218     else:     else:
219       app = "cd "+pn+"; "+os.path.join(env['bininstall'],"escript")+" -ov "+sn      
220         app = "cd "+pn+"; pwd; "+binpath(env, "run-escript")+" -ov "+sn
221     print "Executing test: ",app     print "Executing test: ",app
222     if env.Execute(app) == 0:     if env.Execute(app) == 0:
223        open(str(target[0]),'w').write("PASSED\n")        open(str(target[0]),'w').write("PASSED\n")
# Line 119  def runPyUnitTest(target, source, env): Line 228  def runPyUnitTest(target, source, env):
228    
229  def eps2pdf(target, source, env):  def eps2pdf(target, source, env):
230  #   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:
231     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:
232         return 1         return 1
233     return None     return None
234    
235  def effectiveName(inname):  def effectiveName(inname):
236     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?
237     if m.match(inname):      if m.match(inname):
238      return "savanna"          return "savanna"
239     return inname      return inname

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

  ViewVC Help
Powered by ViewVC 1.1.26