/[escript]/release/5.2/site_scons/site_init.py
ViewVC logotype

Contents of /release/5.2/site_scons/site_init.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6692 - (show annotations)
Mon Jun 25 02:31:06 2018 UTC (2 years, 11 months ago) by jfenwick
File MIME type: text/x-python
File size: 10639 byte(s)
Fix

1
2 ##############################################################################
3 #
4 # Copyright (c) 2003-2018 by The University of Queensland
5 # http://www.uq.edu.au
6 #
7 # Primary Business: Queensland, Australia
8 # Licensed under the Apache License, version 2.0
9 # http://www.apache.org/licenses/LICENSE-2.0
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 from __future__ import print_function, division
18
19 __copyright__="""Copyright (c) 2003-2018 by The University of Queensland
20 http://www.uq.edu.au
21 Primary Business: Queensland, Australia"""
22 __license__="""Licensed under the Apache License, version 2.0
23 http://www.apache.org/licenses/LICENSE-2.0"""
24 __url__="https://launchpad.net/escript-finley"
25
26 import sys, os, time, py_compile, re, subprocess
27 from SCons.Defaults import Chmod, Copy
28 from grouptest import *
29 from extractdebbuild import *
30
31 def findLibWithHeader(env, libs, header, paths, lang='c++', try_link=True):
32 from SCons.Script.SConscript import Configure
33 inc_path=''
34 lib_path=''
35 # 'paths' may be a prefix, so look for lib and include subdirectories
36 if type(paths)==str:
37 # find the header file first
38 for i in 'include','include64','include32','inc':
39 inc=os.path.join(paths, i)
40 if os.path.isfile(os.path.join(inc, header)):
41 inc_path=inc
42 break
43 if inc_path=='':
44 raise RuntimeError('%s not found under %s'%(header,paths))
45
46 # now try to find a lib directory
47 for l in 'lib','lib64','lib32':
48 lp=os.path.join(paths, l)
49 if os.path.isdir(lp):
50 lib_path=lp
51 break
52 if lib_path=='':
53 raise RuntimeError('No lib directory found under %s'%paths)
54 else:
55 if os.path.isfile(os.path.join(paths[0], header)):
56 inc_path=paths[0]
57 else:
58 raise RuntimeError('%s not found under %s'%(header,paths[0]))
59 if os.path.isdir(paths[1]):
60 lib_path=paths[1]
61 else:
62 raise RuntimeError('%s is not a valid path.'%paths[1])
63
64 if try_link:
65 # now try the library
66 conf=Configure(env.Clone())
67 conf.env.AppendUnique(CPPPATH = [inc_path])
68 conf.env.AppendUnique(LIBPATH = [lib_path])
69 if type(libs)==str: libs=[libs]
70 if len(libs)==0: libs=['']
71 # we can't check for each library by itself since they may depend on
72 # each other, so we add all libraries to the link line and check only
73 # for one
74 conf.env.AppendUnique(LIBS = libs)
75 if not conf.CheckLibWithHeader(libs[0], header, lang):
76 conf.Finish()
77 raise RuntimeError('Unable to link against %s (paths: %s, %s)'%(libs,inc_path,lib_path))
78
79 conf.Finish()
80 return inc_path, lib_path
81
82 def detectModule(env, module):
83 from tempfile import TemporaryFile
84 p=subprocess.call([env['pythoncmd'],'-c','import %s'%module], stderr=TemporaryFile())
85 if p != 0:
86 env[module] = False
87 return False
88 env[module] = True
89 return True
90
91 def write_buildvars(env):
92 buildvars=open(os.path.join(env['libinstall'], 'buildvars'), 'w')
93 for k,v in sorted(env['buildvars'].items()):
94 buildvars.write("%s=%s\n"%(k,v))
95 buildvars.close()
96
97 def write_launcher(env):
98 reps={'%n':'${ESCRIPT_NUM_NODES}', '%p':'${ESCRIPT_NUM_PROCS}',
99 '%N':'${TOTPROC}', '%t':'${ESCRIPT_NUM_THREADS}', '%f':'${HOSTFILE}',
100 '%h':'${HOSTLIST}', '%e':'${EXPORT_ENV}', '%b':'${EXEC_CMD}'}
101 pre=env['prelaunch']
102 cmd=env['launcher']
103 post=env['postlaunch']
104 # %b should be present in launcher at least
105 if not '%b' in cmd:
106 raise RuntimeError('option "launcher" must contain %b!')
107
108 for k, v in reps.iteritems():
109 pre = pre.replace(k, v)
110 cmd = cmd.replace(k, v)
111 post = post.replace(k, v)
112 try:
113 launchscript = os.path.join(env['bininstall'], 'run-escript')
114 launcher=open(launchscript, 'w')
115 if not env['stdlocationisprefix']:
116 usestdlocation='0'
117 stdlocation='/usr/lib/python-escript'
118 else:
119 usestdlocation='1'
120 stdlocation=env['prefix']
121 for line in open('run-escript.in','r').readlines():
122 s=line.replace('@@PRELAUNCH', pre).replace('@@LAUNCH', cmd).replace('@@POSTLAUNCH', post)
123 s=s.replace('@@STDLOCATION', usestdlocation).replace('@@ESROOT',stdlocation)
124 launcher.write(s)
125 launcher.close()
126 env.Execute(Chmod(launchscript, 0o755))
127 except IOError:
128 env['warnings'].append("Error attempting to write launcher script.")
129
130 def generateTestScripts(env, TestGroups):
131 try:
132 utest=open('utest.sh','w')
133 utest.write(GroupTest.makeHeader(env['PLATFORM'], env['prefix'], False))
134 for tests in TestGroups:
135 utest.write(tests.makeString())
136 utest.write(tests.makeFooter())
137 utest.close()
138 env.Execute(Chmod('utest.sh', 0o755))
139 print("Generated utest.sh.")
140 # This version contains only python tests - I want this to be usable
141 # from a binary only install if you have the test files
142 utest=open('itest.sh','w')
143 utest.write(GroupTest.makeHeader(env['PLATFORM'], env['prefix'], True))
144 for tests in TestGroups:
145 if tests.exec_cmd=='$PYTHONRUNNER ':
146 utest.write(tests.makeString())
147 utest.write(tests.makeFooter())
148 utest.close()
149 env.Execute(Chmod('itest.sh', 0o755))
150 print("Generated itest.sh.")
151 except IOError:
152 env['warnings'].append("Error attempting to write unit test script(s).")
153
154 # delete scripts upon cleanup
155 env.Clean('target_init', 'utest.sh')
156 env.Clean('target_init', 'itest.sh')
157
158 # Code to build .pyc from .py
159 def build_py(target, source, env):
160 try:
161 py_compile.compile(str(source[0]), str(target[0]), doraise=True)
162 return 0
163 except py_compile.PyCompileError, e:
164 print(e)
165 return 1
166
167
168 # Code to run unit_test executables
169 def runUnitTest(target, source, env):
170 time_start = time.time()
171 app = str(source[0].abspath)
172 pn, sn= os.path.split(app)
173 if not os.name== "nt":
174 app = "cd "+pn+"; "+os.path.join(env['bininstall'], "run-escript")+" -bv "+os.path.join('.',sn)
175 else:
176 if env['usempi']:
177 app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\
178 "FINLEY_TEST_DATA,PATH %s"\
179 %(pn,env['ENV']['ESCRIPT_NUM_NODES'], sn)
180 else:
181 app = "cd "+ pn +" & "+sn
182 print("Executing test: " + app)
183 if not env.Execute(app):
184 open(str(target[0]),'w').write("PASSED\n")
185 else:
186 return 1
187 print("Test execution time: ", round(time.time() - time_start, 1), " seconds wall time for " + str(source[0].abspath))
188 return None
189
190 def binpath(env, name=None):
191 if not name:
192 return env['bininstall']
193 return os.path.join(env['bininstall'], name)
194
195 def runPyUnitTest(target, source, env):
196 time_start = time.time()
197 app = str(source[0].abspath)
198 pn, sn= os.path.split(app)
199 if os.name=="nt":
200 if env['usempi']:
201 app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\
202 "FINLEY_TEST_DATA,PATH %s\pythonMPIredirect.exe %s"\
203 %(pn,env['ENV']['ESCRIPT_NUM_NODES'],env['libinstall'],sn)
204 else:
205 app = "cd "+ pn +" & "+sys.executable + " " + sn
206 else:
207 skipfile = os.path.join(env['BUILD_DIR'], sn[:-3]) + ".skipped"
208 failfile = os.path.join(env['BUILD_DIR'], sn[:-3]) + ".failed"
209 try:
210 os.unlink(skipfile)
211 except Exception as e:
212 pass
213 app = "cd " + pn + "; " + binpath(env, "run-escript") + " -ov " + \
214 str(env.Dir('#').abspath) + "/tools/testrunner.py -skipfile=" + \
215 skipfile + " -failfile=" + failfile + " -exit " + sn
216 print("Executing test: ",app)
217 if env.Execute(app) == 0:
218 open(str(target[0]),'w').write("PASSED\n")
219 else:
220 return 1
221 print("Test execution time: ", round(time.time() - time_start, 1), " seconds wall time for " + str(source[0].abspath))
222 return None
223
224 def runPyExample(target, source, env):
225 time_start = time.time()
226 app = str(source[0].abspath)
227 pn, sn= os.path.split(app)
228 if os.name=="nt":
229 if env['usempi']:
230 app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\
231 "FINLEY_TEST_DATA,PATH %s\pythonMPIredirect.exe %s"\
232 %(pn,env['ENV']['ESCRIPT_NUM_NODES'],env['libinstall'],sn)
233 else:
234 app = "cd "+ pn +" & "+sys.executable + " " + sn
235 else:
236
237 app = "cd "+pn+"; pwd; "+binpath(env, "run-escript")+" -ov "+sn
238 print("Executing test: ",app)
239 if env.Execute(app) == 0:
240 open(str(target[0]),'w').write("PASSED\n")
241 else:
242 return 1
243 print("Test execution time: ", round(time.time() - time_start, 1), " seconds wall time for " + str(source[0].abspath))
244 return None
245
246 def eps2pdf(target, source, env):
247 # if env.Execute("epstopdf "+str(source[0].abspath)+" -o "+str(target[0].abspath))!=0:
248 if env.Execute("ps2pdf -dEPSCrop "+str(source[0].abspath)+" "+str(target[0].abspath))!=0:
249 return 1
250 return None
251
252 def effectiveName(inname):
253 m=re.compile("^r1i[0-9]{1,2}n[0-9]{1,2}$") # savanna names take the form r1i?n?
254 if m.match(inname):
255 return "savanna"
256 return inname
257
258 def osxlib_dep_rewrite(libname, targetdir, env):
259 if env.Execute("tools/libmover.sh %s %s"%(libname, targetdir)):
260 return 1
261 return None
262
263 def TristateVariable(key, help, default):
264 """
265 Modelled after SCons internal BoolVariable but allows three states
266 (on=1, off=0, auto=-1)
267 """
268 on_strings = ('y', 'yes', 'true', 't', '1', 'on')
269 off_strings = ('n', 'no', 'false', 'f', '0', 'off', 'none')
270 auto_strings = ('a', 'auto', 'default', 'def', '-1', '')
271
272 def _validator(key, val, env):
273 if not env[key] in (1, 0, -1):
274 raise SCons.Errors.UserError(
275 'Invalid value for tristate option %s: %s' % (key, env[key]))
276
277 def _converter(val):
278 lval = val.lower()
279 if lval in on_strings: return 1
280 if lval in off_strings: return 0
281 if lval in auto_strings: return -1
282 raise ValueError("Invalid value for tristate option: %s" % val)
283
284 return (key, '%s (yes|no|auto)' % help, default, _validator, _converter)
285

  ViewVC Help
Powered by ViewVC 1.1.26