/[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

trunk/scons/scons_extensions.py revision 2629 by trankine, Tue Aug 25 06:39:26 2009 UTC branches/4.0fordebian/site_scons/site_init.py revision 5577 by jfenwick, Fri Apr 3 05:26:15 2015 UTC
# Line 1  Line 1 
1    
2  ########################################################  ##############################################################################
3  #  #
4  # Copyright (c) 2003-2009 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-2009 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 SCons.Script.SConscript import SConsEnvironment  from grouptest import *
27    from extractdebbuild import *
28    
29    def findLibWithHeader(env, libs, header, paths, lang='c++'):
30        from SCons.Script.SConscript import Configure
31        inc_path=''
32        lib_path=''
33        # 'paths' may be a prefix, so look for lib and include subdirectories
34        if type(paths)==str:
35            # find the header file first
36            for i in 'include','include64','include32','inc':
37                inc=os.path.join(paths, i)
38                if os.path.isfile(os.path.join(inc, header)):
39                    inc_path=inc
40                    break
41            if inc_path=='':
42                raise RuntimeError('%s not found under %s'%(header,paths))
43    
44            # now try to find a lib directory
45            for l in 'lib','lib64','lib32':
46                lp=os.path.join(paths, l)
47                if os.path.isdir(lp):
48                    lib_path=lp
49                    break
50            if lib_path=='':
51                raise RuntimeError('No lib directory found under %s'%paths)
52        else:
53            if os.path.isfile(os.path.join(paths[0], header)):
54                inc_path=paths[0]
55            else:
56                raise RuntimeError('%s not found under %s'%(header,paths[0]))
57            if os.path.isdir(paths[1]):
58                lib_path=paths[1]
59            else:
60                raise RuntimeError('%s is not a valid path.'%paths[1])
61    
62        # now try the library
63        conf=Configure(env.Clone())
64        conf.env.AppendUnique(CPPPATH = [inc_path])
65        conf.env.AppendUnique(LIBPATH = [lib_path])
66        if type(libs)==str: libs=[libs]
67        if len(libs)==0: libs=['']
68        # we can't check for each library by itself since they may depend on each
69        # other, so we add all libraries to the link line and check only for one
70        conf.env.AppendUnique(LIBS = libs)
71        if not conf.CheckLibWithHeader(libs[0], header, lang):
72            conf.Finish()
73            raise RuntimeError('Unable to link against %s (paths: %s, %s)'%(libs,inc_path,lib_path))
74    
75        conf.Finish()
76        return inc_path, lib_path
77    
78    def detectModule(env, module):
79        from tempfile import TemporaryFile
80        p=subprocess.call([env['pythoncmd'],'-c','import %s'%module], stderr=TemporaryFile())
81        if p != 0:
82            env[module] = False
83            return False
84        env[module] = True
85        return True
86    
87    def write_buildvars(env):
88        buildvars=open(os.path.join(env['libinstall'], 'buildvars'), 'w')
89        for k,v in sorted(env['buildvars'].items()):
90            buildvars.write("%s=%s\n"%(k,v))
91        buildvars.close()
92    
93    def write_launcher(env):
94        reps={'%n':'${ESCRIPT_NUM_NODES}', '%p':'${ESCRIPT_NUM_PROCS}',
95              '%N':'${TOTPROC}', '%t':'${ESCRIPT_NUM_THREADS}', '%f':'${HOSTFILE}',
96              '%h':'${HOSTLIST}', '%e':'${EXPORT_ENV}', '%b':'${EXEC_CMD}'}
97        pre=env['prelaunch']
98        cmd=env['launcher']
99        post=env['postlaunch']
100        # %b should be present in launcher at least
101        if not '%b' in cmd:
102            raise RuntimeError('option "launcher" must contain %b!')
103    
104        for k, v in reps.iteritems():
105            pre = pre.replace(k, v)
106            cmd = cmd.replace(k, v)
107            post = post.replace(k, v)
108        try:
109            launchscript = os.path.join(env['bininstall'], 'run-escript')
110            launcher=open(launchscript, 'w')
111            for line in open('run-escript.in','r').readlines():
112                launcher.write(line.replace('@@PRELAUNCH', pre).replace('@@LAUNCH', cmd).replace('@@POSTLAUNCH', post))
113            launcher.close()
114            env.Execute(Chmod(launchscript, 0o755))
115        except IOError:
116            env['warnings'].append("Error attempting to write launcher script.")
117    
118    def generateTestScripts(env, TestGroups):
119        try:
120            utest=open('utest.sh','w')
121            utest.write(GroupTest.makeHeader(env['PLATFORM'], env['prefix'], False))
122            for tests in TestGroups:
123                utest.write(tests.makeString())
124            utest.close()
125            env.Execute(Chmod('utest.sh', 0o755))
126            print("Generated utest.sh.")
127            # This version contains only python tests - I want this to be usable
128            # from a binary only install if you have the test files
129            utest=open('itest.sh','w')
130            utest.write(GroupTest.makeHeader(env['PLATFORM'], env['prefix'], True))
131            for tests in TestGroups:
132              if tests.exec_cmd=='$PYTHONRUNNER ':
133                utest.write(tests.makeString())
134            utest.close()
135            env.Execute(Chmod('itest.sh', 0o755))
136            print("Generated itest.sh.")        
137        except IOError:
138            env['warnings'].append("Error attempting to write unit test script(s).")
139    
140        # delete scripts upon cleanup
141        env.Clean('target_init', 'utest.sh')
142        env.Clean('target_init', 'itest.sh')
143    
144  # Code to build .pyc from .py  # Code to build .pyc from .py
145  def build_py(target, source, env):  def build_py(target, source, env):
146      py_compile.compile(str(source[0]), str(target[0]))      try:
147      return 0         py_compile.compile(str(source[0]), str(target[0]), doraise=True)
148           return 0
149        except py_compile.PyCompileError, e:
150           print e
151           return 1
152    
153    
154  # Code to run unit_test executables  # Code to run unit_test executables
155  def runUnitTest(target, source, env):  def runUnitTest(target, source, env):
# Line 34  def runUnitTest(target, source, env): Line 157  def runUnitTest(target, source, env):
157    app = str(source[0].abspath)    app = str(source[0].abspath)
158    pn, sn= os.path.split(app)    pn, sn= os.path.split(app)
159    if not os.name== "nt":    if not os.name== "nt":
160       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)
161    else:    else:
162        if env['usempi']:        if env['usempi']:
163            app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\            app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\
164              "FINLEY_TEST_DATA,PYVISI_TEST_DATA_ROOT,PYVISI_WORKDIR,PATH %s"\              "FINLEY_TEST_DATA,PATH %s"\
165              %(pn,env['ENV']['ESCRIPT_NUM_NODES'], sn)              %(pn,env['ENV']['ESCRIPT_NUM_NODES'], sn)
166        else:        else:
167             app = "cd "+ pn +" & "+sn             app = "cd "+ pn +" & "+sn
# Line 50  def runUnitTest(target, source, env): Line 173  def runUnitTest(target, source, env):
173    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)
174    return None    return None
175    
176    def binpath(env, name=None):
177        if not name:
178            return env['bininstall']
179        return os.path.join(env['bininstall'], name)
180    
181  def runPyUnitTest(target, source, env):  def runPyUnitTest(target, source, env):
182     time_start = time.time()     time_start = time.time()
183     app = str(source[0].abspath)     app = str(source[0].abspath)
184     pn, sn= os.path.split(app)     pn, sn= os.path.split(app)
185     if os.name== "nt":     if os.name=="nt":
186           if env['usempi']:
187               app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\
188                  "FINLEY_TEST_DATA,PATH %s\pythonMPIredirect.exe %s"\
189                  %(pn,env['ENV']['ESCRIPT_NUM_NODES'],env['libinstall'],sn)
190           else:
191               app = "cd "+ pn +" & "+sys.executable + " " + sn
192       else:
193         skipfile = os.path.join(env['BUILD_DIR'], sn[:-3]) + ".skipped"
194         try:
195             os.unlink(skipfile)
196         except Exception as e:
197            pass
198         app = "cd "+pn+"; "+binpath(env, "run-escript")+" -ov "+binpath(env,
199                "../tools/testrunner.py")+" -outputfile="+skipfile+" "+sn
200       print "Executing test: ",app
201       if env.Execute(app) == 0:
202          open(str(target[0]),'w').write("PASSED\n")
203       else:
204         return 1
205       print "Test execution time: ", round(time.time() - time_start, 1), " seconds wall time for " + str(source[0].abspath)
206       return None
207    
208    def runPyExample(target, source, env):
209       time_start = time.time()
210       app = str(source[0].abspath)
211       pn, sn= os.path.split(app)
212       if os.name=="nt":
213         if env['usempi']:         if env['usempi']:
214             app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\             app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\
215                "FINLEY_TEST_DATA,PYVISI_TEST_DATA_ROOT,PYVISI_WORKDIR,PATH %s\pythonMPIredirect.exe %s"\                "FINLEY_TEST_DATA,PATH %s\pythonMPIredirect.exe %s"\
216                %(pn,env['ENV']['ESCRIPT_NUM_NODES'],env['libinstall'],sn)                %(pn,env['ENV']['ESCRIPT_NUM_NODES'],env['libinstall'],sn)
217         else:         else:
218             app = "cd "+ pn +" & "+sys.executable + " " + sn             app = "cd "+ pn +" & "+sys.executable + " " + sn
219     else:     else:
220       app = "cd "+pn+"; "+os.path.join(env['bininstall'],"escript")+" -ov "+sn      
221         app = "cd "+pn+"; pwd; "+binpath(env, "run-escript")+" -ov "+sn
222     print "Executing test: ",app     print "Executing test: ",app
223     if env.Execute(app) == 0:     if env.Execute(app) == 0:
224        open(str(target[0]),'w').write("PASSED\n")        open(str(target[0]),'w').write("PASSED\n")
# Line 72  def runPyUnitTest(target, source, env): Line 228  def runPyUnitTest(target, source, env):
228     return None     return None
229    
230  def eps2pdf(target, source, env):  def eps2pdf(target, source, env):
231     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:
232         return 1     if env.Execute("ps2pdf -dEPSCrop "+str(source[0].abspath)+" "+str(target[0].abspath))!=0:
233           return 1
234     return None     return None
235    
236  def effectiveName(inname):  def effectiveName(inname):
237     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?
238     if m.match(inname):      if m.match(inname):
239      return "service0"          return "savanna"
240     return inname      return inname

Legend:
Removed from v.2629  
changed lines
  Added in v.5577

  ViewVC Help
Powered by ViewVC 1.1.26