/[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 3580 - (hide annotations)
Tue Sep 6 00:31:35 2011 UTC (7 years, 10 months ago) by gross
File MIME type: text/x-python
File size: 5020 byte(s)
error handeling for python compilation improved.
1 ksteube 1810
2     ########################################################
3     #
4 jfenwick 2881 # Copyright (c) 2003-2010 by University of Queensland
5 ksteube 1810 # Earth Systems Science Computational Center (ESSCC)
6     # http://www.uq.edu.au/esscc
7     #
8     # Primary Business: Queensland, Australia
9     # Licensed under the Open Software License version 3.0
10     # http://www.opensource.org/licenses/osl-3.0.php
11     #
12     ########################################################
13    
14 jfenwick 2881 __copyright__="""Copyright (c) 2003-2010 by University of Queensland
15 ksteube 1810 Earth Systems Science Computational Center (ESSCC)
16     http://www.uq.edu.au/esscc
17     Primary Business: Queensland, Australia"""
18     __license__="""Licensed under the Open Software License version 3.0
19     http://www.opensource.org/licenses/osl-3.0.php"""
20 jfenwick 2344 __url__="https://launchpad.net/escript-finley"
21 ksteube 1810
22 jfenwick 2388 import sys, os, time, glob, fnmatch, types, py_compile, re
23 elspeth 645
24 caltinay 3212 def findLibWithHeader(env, libs, header, paths, lang='c'):
25 caltinay 3214 from SCons.Script.SConscript import Configure
26 caltinay 3212 inc_path=''
27     lib_path=''
28     # 'paths' may be a prefix, so look for lib and include subdirectories
29     if type(paths)==str:
30     # find the header file first
31     for i in 'include','include64','include32','inc':
32     inc=os.path.join(paths, i)
33     if os.path.isfile(os.path.join(inc, header)):
34     inc_path=inc
35     break
36     if inc_path=='':
37     raise RuntimeError('%s not found under %s'%(header,paths))
38    
39     # now try to find a lib directory
40     for l in 'lib','lib64','lib32':
41     lp=os.path.join(paths, l)
42     if os.path.isdir(lp):
43     lib_path=lp
44     break
45     if lib_path=='':
46     raise RuntimeError('No lib directory found under %s'%paths)
47     else:
48     if os.path.isfile(os.path.join(paths[0], header)):
49     inc_path=paths[0]
50     else:
51     raise RuntimeError('%s not found under %s'%(header,paths[0]))
52     if os.path.isdir(paths[1]):
53     lib_path=paths[1]
54     else:
55     raise RuntimeError('%s is not a valid path.'%paths[1])
56    
57     # now try the library
58 caltinay 3229 conf=Configure(env.Clone())
59 caltinay 3212 conf.env.AppendUnique(CPPPATH = [inc_path])
60     conf.env.AppendUnique(LIBPATH = [lib_path])
61     if type(libs)==str: libs=[libs]
62 caltinay 3214 # we can't check for each library by itself since they may depend on each
63     # other, so we add all libraries to the link line and check only for one
64     conf.env.AppendUnique(LIBS = libs)
65     if not conf.CheckLibWithHeader(libs[0], header, lang):
66     conf.Finish()
67     raise RuntimeError('Unable to link against %s (paths: %s, %s)'%(libs,inc_path,lib_path))
68 caltinay 3212
69     conf.Finish()
70     return inc_path, lib_path
71    
72 gross 3580
73 jgs 268 # Code to build .pyc from .py
74     def build_py(target, source, env):
75 gross 3580 try:
76     py_compile.compile(str(source[0]), str(target[0]), doraise=True)
77     return 0
78     except py_compile.PyCompileError as e:
79     print e
80     return 1
81    
82 jgs 297
83     # Code to run unit_test executables
84     def runUnitTest(target, source, env):
85 ksteube 1312 time_start = time.time()
86     app = str(source[0].abspath)
87 gross 2502 pn, sn= os.path.split(app)
88 gross 2363 if not os.name== "nt":
89 caltinay 3376 app = "cd "+pn+"; "+os.path.join(env['bininstall'], "run-escript")+" -bv "+os.path.join('.',sn)
90 gross 2416 else:
91     if env['usempi']:
92 trankine 2629 app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\
93 gross 2423 "FINLEY_TEST_DATA,PYVISI_TEST_DATA_ROOT,PYVISI_WORKDIR,PATH %s"\
94 gross 2502 %(pn,env['ENV']['ESCRIPT_NUM_NODES'], sn)
95     else:
96 trankine 2629 app = "cd "+ pn +" & "+sn
97 ksteube 1312 print "Executing test: " + app
98     if not env.Execute(app):
99 jgs 297 open(str(target[0]),'w').write("PASSED\n")
100 ksteube 1312 else:
101     return 1
102     print "Test execution time: ", round(time.time() - time_start, 1), " seconds wall time for " + str(source[0].abspath)
103     return None
104 cochrane 370
105 robwdcock 682 def runPyUnitTest(target, source, env):
106 ksteube 1312 time_start = time.time()
107     app = str(source[0].abspath)
108 gross 2502 pn, sn= os.path.split(app)
109 gross 2363 if os.name== "nt":
110 gross 2416 if env['usempi']:
111 trankine 2629 app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\
112 gross 2423 "FINLEY_TEST_DATA,PYVISI_TEST_DATA_ROOT,PYVISI_WORKDIR,PATH %s\pythonMPIredirect.exe %s"\
113 gross 2502 %(pn,env['ENV']['ESCRIPT_NUM_NODES'],env['libinstall'],sn)
114 gross 2416 else:
115 trankine 2629 app = "cd "+ pn +" & "+sys.executable + " " + sn
116 ksteube 1312 else:
117 caltinay 3376 app = "cd "+pn+"; "+os.path.join(env['bininstall'], "run-escript")+" -ov "+sn
118 gross 2502 print "Executing test: ",app
119 gross 1374 if env.Execute(app) == 0:
120 ksteube 1312 open(str(target[0]),'w').write("PASSED\n")
121     else:
122     return 1
123     print "Test execution time: ", round(time.time() - time_start, 1), " seconds wall time for " + str(source[0].abspath)
124     return None
125 phornby 1233
126 jfenwick 2387 def eps2pdf(target, source, env):
127 jfenwick 3053 # if env.Execute("epstopdf "+str(source[0].abspath)+" -o "+str(target[0].abspath))!=0:
128 caltinay 3270 if env.Execute("ps2pdf -dEPSCrop "+str(source[0].abspath)+" "+str(target[0].abspath))!=0:
129 jfenwick 2387 return 1
130 jfenwick 2388 return None
131    
132     def effectiveName(inname):
133     m=re.compile("^r1i[0-9]{1,2}n[0-9]{1,2}$") # savanna names take the form r1i?n?
134     if m.match(inname):
135 jfenwick 3047 return "savanna"
136 jfenwick 2388 return inname

  ViewVC Help
Powered by ViewVC 1.1.26