/[escript]/trunk/site_scons/site_init.py
ViewVC logotype

Annotation of /trunk/site_scons/site_init.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5589 - (hide annotations)
Wed Apr 22 03:13:44 2015 UTC (4 years, 2 months ago) by jfenwick
File MIME type: text/x-python
File size: 9090 byte(s)
Changes brought across from the debian preparation branch.


1 ksteube 1810
2 jfenwick 3981 ##############################################################################
3 ksteube 1810 #
4 jfenwick 5448 # Copyright (c) 2003-2015 by University of Queensland
5 jfenwick 3981 # http://www.uq.edu.au
6 ksteube 1810 #
7     # Primary Business: Queensland, Australia
8     # Licensed under the Open Software License version 3.0
9     # http://www.opensource.org/licenses/osl-3.0.php
10     #
11 jfenwick 3981 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 jfenwick 4657 # Development 2012-2013 by School of Earth Sciences
13     # Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 jfenwick 3981 #
15     ##############################################################################
16 ksteube 1810
17 jfenwick 5448 __copyright__="""Copyright (c) 2003-2015 by University of Queensland
18 jfenwick 3981 http://www.uq.edu.au
19 ksteube 1810 Primary Business: Queensland, Australia"""
20     __license__="""Licensed under the Open Software License version 3.0
21     http://www.opensource.org/licenses/osl-3.0.php"""
22 jfenwick 2344 __url__="https://launchpad.net/escript-finley"
23 ksteube 1810
24 caltinay 3975 import sys, os, time, py_compile, re, subprocess
25 jfenwick 4323 from SCons.Defaults import Chmod, Copy
26 caltinay 4295 from grouptest import *
27 jfenwick 5589 from extractdebbuild import *
28 elspeth 645
29 caltinay 4520 def findLibWithHeader(env, libs, header, paths, lang='c++'):
30 caltinay 3214 from SCons.Script.SConscript import Configure
31 caltinay 3212 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 caltinay 3229 conf=Configure(env.Clone())
64 caltinay 3212 conf.env.AppendUnique(CPPPATH = [inc_path])
65     conf.env.AppendUnique(LIBPATH = [lib_path])
66     if type(libs)==str: libs=[libs]
67 caltinay 5045 if len(libs)==0: libs=['']
68 caltinay 3214 # 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 caltinay 3212
75     conf.Finish()
76     return inc_path, lib_path
77    
78 caltinay 3975 def detectModule(env, module):
79 caltinay 4337 from tempfile import TemporaryFile
80     p=subprocess.call([env['pythoncmd'],'-c','import %s'%module], stderr=TemporaryFile())
81 caltinay 4300 if p != 0:
82     env[module] = False
83     return False
84 caltinay 4295 env[module] = True
85 caltinay 3975 return True
86 gross 3580
87 caltinay 4295 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 caltinay 5266 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 caltinay 4295 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 sshaw 5522 utest.write(tests.makeFooter())
125 caltinay 4295 utest.close()
126     env.Execute(Chmod('utest.sh', 0o755))
127     print("Generated utest.sh.")
128     # This version contains only python tests - I want this to be usable
129     # from a binary only install if you have the test files
130     utest=open('itest.sh','w')
131     utest.write(GroupTest.makeHeader(env['PLATFORM'], env['prefix'], True))
132     for tests in TestGroups:
133     if tests.exec_cmd=='$PYTHONRUNNER ':
134     utest.write(tests.makeString())
135     utest.close()
136     env.Execute(Chmod('itest.sh', 0o755))
137     print("Generated itest.sh.")
138     except IOError:
139     env['warnings'].append("Error attempting to write unit test script(s).")
140    
141     # delete scripts upon cleanup
142     env.Clean('target_init', 'utest.sh')
143     env.Clean('target_init', 'itest.sh')
144    
145 jgs 268 # Code to build .pyc from .py
146     def build_py(target, source, env):
147 gross 3580 try:
148     py_compile.compile(str(source[0]), str(target[0]), doraise=True)
149     return 0
150 gross 3581 except py_compile.PyCompileError, e:
151 gross 3580 print e
152     return 1
153 jgs 297
154 caltinay 4295
155 jgs 297 # Code to run unit_test executables
156     def runUnitTest(target, source, env):
157 ksteube 1312 time_start = time.time()
158     app = str(source[0].abspath)
159 gross 2502 pn, sn= os.path.split(app)
160 gross 2363 if not os.name== "nt":
161 caltinay 3376 app = "cd "+pn+"; "+os.path.join(env['bininstall'], "run-escript")+" -bv "+os.path.join('.',sn)
162 gross 2416 else:
163     if env['usempi']:
164 trankine 2629 app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\
165 caltinay 4520 "FINLEY_TEST_DATA,PATH %s"\
166 gross 2502 %(pn,env['ENV']['ESCRIPT_NUM_NODES'], sn)
167     else:
168 trankine 2629 app = "cd "+ pn +" & "+sn
169 ksteube 1312 print "Executing test: " + app
170     if not env.Execute(app):
171 jgs 297 open(str(target[0]),'w').write("PASSED\n")
172 ksteube 1312 else:
173     return 1
174     print "Test execution time: ", round(time.time() - time_start, 1), " seconds wall time for " + str(source[0].abspath)
175     return None
176 cochrane 370
177 sshaw 5017 def binpath(env, name=None):
178     if not name:
179     return env['bininstall']
180     return os.path.join(env['bininstall'], name)
181    
182 robwdcock 682 def runPyUnitTest(target, source, env):
183 ksteube 1312 time_start = time.time()
184     app = str(source[0].abspath)
185 gross 2502 pn, sn= os.path.split(app)
186 caltinay 4520 if os.name=="nt":
187 gross 2416 if env['usempi']:
188 trankine 2629 app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\
189 caltinay 4520 "FINLEY_TEST_DATA,PATH %s\pythonMPIredirect.exe %s"\
190 gross 2502 %(pn,env['ENV']['ESCRIPT_NUM_NODES'],env['libinstall'],sn)
191 gross 2416 else:
192 trankine 2629 app = "cd "+ pn +" & "+sys.executable + " " + sn
193 ksteube 1312 else:
194 caltinay 5229 skipfile = os.path.join(env['BUILD_DIR'], sn[:-3]) + ".skipped"
195 sshaw 5521 failfile = os.path.join(env['BUILD_DIR'], sn[:-3]) + ".failed"
196 sshaw 5022 try:
197     os.unlink(skipfile)
198     except Exception as e:
199     pass
200 sshaw 5017 app = "cd "+pn+"; "+binpath(env, "run-escript")+" -ov "+binpath(env,
201 sshaw 5521 "../tools/testrunner.py")+" -skipfile="+skipfile+" "+"-failfile="+failfile+" "+"-exit "+sn
202 gross 2502 print "Executing test: ",app
203 gross 1374 if env.Execute(app) == 0:
204 ksteube 1312 open(str(target[0]),'w').write("PASSED\n")
205     else:
206     return 1
207     print "Test execution time: ", round(time.time() - time_start, 1), " seconds wall time for " + str(source[0].abspath)
208     return None
209 phornby 1233
210 sshaw 5017 def runPyExample(target, source, env):
211     time_start = time.time()
212     app = str(source[0].abspath)
213     pn, sn= os.path.split(app)
214     if os.name=="nt":
215     if env['usempi']:
216     app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\
217     "FINLEY_TEST_DATA,PATH %s\pythonMPIredirect.exe %s"\
218     %(pn,env['ENV']['ESCRIPT_NUM_NODES'],env['libinstall'],sn)
219     else:
220     app = "cd "+ pn +" & "+sys.executable + " " + sn
221     else:
222    
223     app = "cd "+pn+"; pwd; "+binpath(env, "run-escript")+" -ov "+sn
224     print "Executing test: ",app
225     if env.Execute(app) == 0:
226     open(str(target[0]),'w').write("PASSED\n")
227     else:
228     return 1
229     print "Test execution time: ", round(time.time() - time_start, 1), " seconds wall time for " + str(source[0].abspath)
230     return None
231    
232 jfenwick 2387 def eps2pdf(target, source, env):
233 jfenwick 3053 # if env.Execute("epstopdf "+str(source[0].abspath)+" -o "+str(target[0].abspath))!=0:
234 caltinay 3270 if env.Execute("ps2pdf -dEPSCrop "+str(source[0].abspath)+" "+str(target[0].abspath))!=0:
235 sshaw 4576 return 1
236 jfenwick 2388 return None
237    
238     def effectiveName(inname):
239 sshaw 4576 m=re.compile("^r1i[0-9]{1,2}n[0-9]{1,2}$") # savanna names take the form r1i?n?
240 caltinay 4520 if m.match(inname):
241     return "savanna"
242     return inname

  ViewVC Help
Powered by ViewVC 1.1.26