/[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 4337 - (hide annotations)
Fri Mar 22 00:05:25 2013 UTC (6 years, 3 months ago) by caltinay
Original Path: trunk/site_scons/site_init.py
File MIME type: text/x-python
File size: 6922 byte(s)
Detect a few more byte swap/endianness headers and silence output from
'detectModule' scons helper

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

  ViewVC Help
Powered by ViewVC 1.1.26