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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5577 - (hide annotations)
Fri Apr 3 05:26:15 2015 UTC (4 years, 2 months ago) by jfenwick
File MIME type: text/x-python
File size: 8949 byte(s)
Fixes to make us more lintian compliant (copied across from private git)
1 ksteube 1810
2 jfenwick 3981 ##############################################################################
3 ksteube 1810 #
4 jfenwick 4657 # Copyright (c) 2003-2014 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 4657 __copyright__="""Copyright (c) 2003-2014 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 5577 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     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 jgs 268 # Code to build .pyc from .py
145     def build_py(target, source, env):
146 gross 3580 try:
147     py_compile.compile(str(source[0]), str(target[0]), doraise=True)
148     return 0
149 gross 3581 except py_compile.PyCompileError, e:
150 gross 3580 print e
151     return 1
152 jgs 297
153 caltinay 4295
154 jgs 297 # Code to run unit_test executables
155     def runUnitTest(target, source, env):
156 ksteube 1312 time_start = time.time()
157     app = str(source[0].abspath)
158 gross 2502 pn, sn= os.path.split(app)
159 gross 2363 if not os.name== "nt":
160 caltinay 3376 app = "cd "+pn+"; "+os.path.join(env['bininstall'], "run-escript")+" -bv "+os.path.join('.',sn)
161 gross 2416 else:
162     if env['usempi']:
163 trankine 2629 app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\
164 caltinay 4520 "FINLEY_TEST_DATA,PATH %s"\
165 gross 2502 %(pn,env['ENV']['ESCRIPT_NUM_NODES'], sn)
166     else:
167 trankine 2629 app = "cd "+ pn +" & "+sn
168 ksteube 1312 print "Executing test: " + app
169     if not env.Execute(app):
170 jgs 297 open(str(target[0]),'w').write("PASSED\n")
171 ksteube 1312 else:
172     return 1
173     print "Test execution time: ", round(time.time() - time_start, 1), " seconds wall time for " + str(source[0].abspath)
174     return None
175 cochrane 370
176 sshaw 5017 def binpath(env, name=None):
177     if not name:
178     return env['bininstall']
179     return os.path.join(env['bininstall'], name)
180    
181 robwdcock 682 def runPyUnitTest(target, source, env):
182 ksteube 1312 time_start = time.time()
183     app = str(source[0].abspath)
184 gross 2502 pn, sn= os.path.split(app)
185 caltinay 4520 if os.name=="nt":
186 gross 2416 if env['usempi']:
187 trankine 2629 app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\
188 caltinay 4520 "FINLEY_TEST_DATA,PATH %s\pythonMPIredirect.exe %s"\
189 gross 2502 %(pn,env['ENV']['ESCRIPT_NUM_NODES'],env['libinstall'],sn)
190 gross 2416 else:
191 trankine 2629 app = "cd "+ pn +" & "+sys.executable + " " + sn
192 ksteube 1312 else:
193 caltinay 5229 skipfile = os.path.join(env['BUILD_DIR'], sn[:-3]) + ".skipped"
194 sshaw 5022 try:
195     os.unlink(skipfile)
196     except Exception as e:
197     pass
198 sshaw 5017 app = "cd "+pn+"; "+binpath(env, "run-escript")+" -ov "+binpath(env,
199 sshaw 5022 "../tools/testrunner.py")+" -outputfile="+skipfile+" "+sn
200 gross 2502 print "Executing test: ",app
201 gross 1374 if env.Execute(app) == 0:
202 ksteube 1312 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 phornby 1233
208 sshaw 5017 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']:
214     app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\
215     "FINLEY_TEST_DATA,PATH %s\pythonMPIredirect.exe %s"\
216     %(pn,env['ENV']['ESCRIPT_NUM_NODES'],env['libinstall'],sn)
217     else:
218     app = "cd "+ pn +" & "+sys.executable + " " + sn
219     else:
220    
221     app = "cd "+pn+"; pwd; "+binpath(env, "run-escript")+" -ov "+sn
222     print "Executing test: ",app
223     if env.Execute(app) == 0:
224     open(str(target[0]),'w').write("PASSED\n")
225     else:
226     return 1
227     print "Test execution time: ", round(time.time() - time_start, 1), " seconds wall time for " + str(source[0].abspath)
228     return None
229    
230 jfenwick 2387 def eps2pdf(target, source, env):
231 jfenwick 3053 # if env.Execute("epstopdf "+str(source[0].abspath)+" -o "+str(target[0].abspath))!=0:
232 caltinay 3270 if env.Execute("ps2pdf -dEPSCrop "+str(source[0].abspath)+" "+str(target[0].abspath))!=0:
233 sshaw 4576 return 1
234 jfenwick 2388 return None
235    
236     def effectiveName(inname):
237 sshaw 4576 m=re.compile("^r1i[0-9]{1,2}n[0-9]{1,2}$") # savanna names take the form r1i?n?
238 caltinay 4520 if m.match(inname):
239     return "savanna"
240     return inname

  ViewVC Help
Powered by ViewVC 1.1.26