/[escript]/branches/postrelease-csirofixes/site_scons/site_init.py
ViewVC logotype

Annotation of /branches/postrelease-csirofixes/site_scons/site_init.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4919 - (hide annotations)
Wed Apr 30 06:25:55 2014 UTC (5 years, 1 month ago) by jfenwick
Original Path: release/3.4.2/site_scons/site_init.py
File MIME type: text/x-python
File size: 6931 byte(s)
Because we've got to!

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 elspeth 645
28 caltinay 4520 def findLibWithHeader(env, libs, header, paths, lang='c++'):
29 caltinay 3214 from SCons.Script.SConscript import Configure
30 caltinay 3212 inc_path=''
31     lib_path=''
32     # 'paths' may be a prefix, so look for lib and include subdirectories
33     if type(paths)==str:
34     # find the header file first
35     for i in 'include','include64','include32','inc':
36     inc=os.path.join(paths, i)
37     if os.path.isfile(os.path.join(inc, header)):
38     inc_path=inc
39     break
40     if inc_path=='':
41     raise RuntimeError('%s not found under %s'%(header,paths))
42    
43     # now try to find a lib directory
44     for l in 'lib','lib64','lib32':
45     lp=os.path.join(paths, l)
46     if os.path.isdir(lp):
47     lib_path=lp
48     break
49     if lib_path=='':
50     raise RuntimeError('No lib directory found under %s'%paths)
51     else:
52     if os.path.isfile(os.path.join(paths[0], header)):
53     inc_path=paths[0]
54     else:
55     raise RuntimeError('%s not found under %s'%(header,paths[0]))
56     if os.path.isdir(paths[1]):
57     lib_path=paths[1]
58     else:
59     raise RuntimeError('%s is not a valid path.'%paths[1])
60    
61     # now try the library
62 caltinay 3229 conf=Configure(env.Clone())
63 caltinay 3212 conf.env.AppendUnique(CPPPATH = [inc_path])
64     conf.env.AppendUnique(LIBPATH = [lib_path])
65     if type(libs)==str: libs=[libs]
66 caltinay 3214 # we can't check for each library by itself since they may depend on each
67     # other, so we add all libraries to the link line and check only for one
68     conf.env.AppendUnique(LIBS = libs)
69     if not conf.CheckLibWithHeader(libs[0], header, lang):
70     conf.Finish()
71     raise RuntimeError('Unable to link against %s (paths: %s, %s)'%(libs,inc_path,lib_path))
72 caltinay 3212
73     conf.Finish()
74     return inc_path, lib_path
75    
76 caltinay 3975 def detectModule(env, module):
77 caltinay 4337 from tempfile import TemporaryFile
78     p=subprocess.call([env['pythoncmd'],'-c','import %s'%module], stderr=TemporaryFile())
79 caltinay 4300 if p != 0:
80     env[module] = False
81     return False
82 caltinay 4295 env[module] = True
83 caltinay 3975 return True
84 gross 3580
85 caltinay 4295 def write_buildvars(env):
86     buildvars=open(os.path.join(env['libinstall'], 'buildvars'), 'w')
87     for k,v in sorted(env['buildvars'].items()):
88     buildvars.write("%s=%s\n"%(k,v))
89     buildvars.close()
90    
91     def generateTestScripts(env, TestGroups):
92     try:
93     utest=open('utest.sh','w')
94     utest.write(GroupTest.makeHeader(env['PLATFORM'], env['prefix'], False))
95     for tests in TestGroups:
96     utest.write(tests.makeString())
97     utest.close()
98     env.Execute(Chmod('utest.sh', 0o755))
99     print("Generated utest.sh.")
100     # This version contains only python tests - I want this to be usable
101     # from a binary only install if you have the test files
102     utest=open('itest.sh','w')
103     utest.write(GroupTest.makeHeader(env['PLATFORM'], env['prefix'], True))
104     for tests in TestGroups:
105     if tests.exec_cmd=='$PYTHONRUNNER ':
106     utest.write(tests.makeString())
107     utest.close()
108     env.Execute(Chmod('itest.sh', 0o755))
109     print("Generated itest.sh.")
110     except IOError:
111     env['warnings'].append("Error attempting to write unit test script(s).")
112    
113     # delete scripts upon cleanup
114     env.Clean('target_init', 'utest.sh')
115     env.Clean('target_init', 'itest.sh')
116    
117     # Make sure that the escript wrapper is in place
118     if not os.path.isfile(os.path.join(env['bininstall'], 'run-escript')):
119     print("Copying escript wrapper.")
120 jfenwick 4323 env.Execute(Copy(os.path.join(env['bininstall'],'run-escript'), 'bin/run-escript'))
121 caltinay 4295
122 jgs 268 # Code to build .pyc from .py
123     def build_py(target, source, env):
124 gross 3580 try:
125     py_compile.compile(str(source[0]), str(target[0]), doraise=True)
126     return 0
127 gross 3581 except py_compile.PyCompileError, e:
128 gross 3580 print e
129     return 1
130 jgs 297
131 caltinay 4295
132 jgs 297 # Code to run unit_test executables
133     def runUnitTest(target, source, env):
134 ksteube 1312 time_start = time.time()
135     app = str(source[0].abspath)
136 gross 2502 pn, sn= os.path.split(app)
137 gross 2363 if not os.name== "nt":
138 caltinay 3376 app = "cd "+pn+"; "+os.path.join(env['bininstall'], "run-escript")+" -bv "+os.path.join('.',sn)
139 gross 2416 else:
140     if env['usempi']:
141 trankine 2629 app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\
142 caltinay 4520 "FINLEY_TEST_DATA,PATH %s"\
143 gross 2502 %(pn,env['ENV']['ESCRIPT_NUM_NODES'], sn)
144     else:
145 trankine 2629 app = "cd "+ pn +" & "+sn
146 ksteube 1312 print "Executing test: " + app
147     if not env.Execute(app):
148 jgs 297 open(str(target[0]),'w').write("PASSED\n")
149 ksteube 1312 else:
150     return 1
151     print "Test execution time: ", round(time.time() - time_start, 1), " seconds wall time for " + str(source[0].abspath)
152     return None
153 cochrane 370
154 robwdcock 682 def runPyUnitTest(target, source, env):
155 ksteube 1312 time_start = time.time()
156     app = str(source[0].abspath)
157 gross 2502 pn, sn= os.path.split(app)
158 caltinay 4520 if os.name=="nt":
159 gross 2416 if env['usempi']:
160 trankine 2629 app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\
161 caltinay 4520 "FINLEY_TEST_DATA,PATH %s\pythonMPIredirect.exe %s"\
162 gross 2502 %(pn,env['ENV']['ESCRIPT_NUM_NODES'],env['libinstall'],sn)
163 gross 2416 else:
164 trankine 2629 app = "cd "+ pn +" & "+sys.executable + " " + sn
165 ksteube 1312 else:
166 caltinay 3376 app = "cd "+pn+"; "+os.path.join(env['bininstall'], "run-escript")+" -ov "+sn
167 gross 2502 print "Executing test: ",app
168 gross 1374 if env.Execute(app) == 0:
169 ksteube 1312 open(str(target[0]),'w').write("PASSED\n")
170     else:
171     return 1
172     print "Test execution time: ", round(time.time() - time_start, 1), " seconds wall time for " + str(source[0].abspath)
173     return None
174 phornby 1233
175 jfenwick 2387 def eps2pdf(target, source, env):
176 jfenwick 3053 # if env.Execute("epstopdf "+str(source[0].abspath)+" -o "+str(target[0].abspath))!=0:
177 caltinay 3270 if env.Execute("ps2pdf -dEPSCrop "+str(source[0].abspath)+" "+str(target[0].abspath))!=0:
178 sshaw 4576 return 1
179 jfenwick 2388 return None
180    
181     def effectiveName(inname):
182 sshaw 4576 m=re.compile("^r1i[0-9]{1,2}n[0-9]{1,2}$") # savanna names take the form r1i?n?
183 caltinay 4520 if m.match(inname):
184     return "savanna"
185     return inname

  ViewVC Help
Powered by ViewVC 1.1.26