/[escript]/trunk/site_scons/site_init.py
ViewVC logotype

Contents of /trunk/site_scons/site_init.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3981 - (show annotations)
Fri Sep 21 02:47:54 2012 UTC (6 years, 10 months ago) by jfenwick
File MIME type: text/x-python
File size: 5371 byte(s)
First pass of updating copyright notices
1
2 ##############################################################################
3 #
4 # Copyright (c) 2003-2012 by University of Queensland
5 # http://www.uq.edu.au
6 #
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 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 # Development since 2012 by School of Earth Sciences
13 #
14 ##############################################################################
15
16 __copyright__="""Copyright (c) 2003-2012 by University of Queensland
17 http://www.uq.edu.au
18 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 __url__="https://launchpad.net/escript-finley"
22
23 import sys, os, time, py_compile, re, subprocess
24
25 def findLibWithHeader(env, libs, header, paths, lang='c'):
26 from SCons.Script.SConscript import Configure
27 inc_path=''
28 lib_path=''
29 # 'paths' may be a prefix, so look for lib and include subdirectories
30 if type(paths)==str:
31 # find the header file first
32 for i in 'include','include64','include32','inc':
33 inc=os.path.join(paths, i)
34 if os.path.isfile(os.path.join(inc, header)):
35 inc_path=inc
36 break
37 if inc_path=='':
38 raise RuntimeError('%s not found under %s'%(header,paths))
39
40 # now try to find a lib directory
41 for l in 'lib','lib64','lib32':
42 lp=os.path.join(paths, l)
43 if os.path.isdir(lp):
44 lib_path=lp
45 break
46 if lib_path=='':
47 raise RuntimeError('No lib directory found under %s'%paths)
48 else:
49 if os.path.isfile(os.path.join(paths[0], header)):
50 inc_path=paths[0]
51 else:
52 raise RuntimeError('%s not found under %s'%(header,paths[0]))
53 if os.path.isdir(paths[1]):
54 lib_path=paths[1]
55 else:
56 raise RuntimeError('%s is not a valid path.'%paths[1])
57
58 # now try the library
59 conf=Configure(env.Clone())
60 conf.env.AppendUnique(CPPPATH = [inc_path])
61 conf.env.AppendUnique(LIBPATH = [lib_path])
62 if type(libs)==str: libs=[libs]
63 # we can't check for each library by itself since they may depend on each
64 # other, so we add all libraries to the link line and check only for one
65 conf.env.AppendUnique(LIBS = libs)
66 if not conf.CheckLibWithHeader(libs[0], header, lang):
67 conf.Finish()
68 raise RuntimeError('Unable to link against %s (paths: %s, %s)'%(libs,inc_path,lib_path))
69
70 conf.Finish()
71 return inc_path, lib_path
72
73 def detectModule(env, module):
74 if env['pythoncmd']=='python':
75 try:
76 __import__(module)
77 except ImportError:
78 return False
79 else:
80 p=subprocess.call([env['pythoncmd'],'-c','import %s'%module])
81 if p!=0:
82 return False
83 return True
84
85 # Code to build .pyc from .py
86 def build_py(target, source, env):
87 try:
88 py_compile.compile(str(source[0]), str(target[0]), doraise=True)
89 return 0
90 except py_compile.PyCompileError, e:
91 print e
92 return 1
93
94
95 # Code to run unit_test executables
96 def runUnitTest(target, source, env):
97 time_start = time.time()
98 app = str(source[0].abspath)
99 pn, sn= os.path.split(app)
100 if not os.name== "nt":
101 app = "cd "+pn+"; "+os.path.join(env['bininstall'], "run-escript")+" -bv "+os.path.join('.',sn)
102 else:
103 if env['usempi']:
104 app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\
105 "FINLEY_TEST_DATA,PYVISI_TEST_DATA_ROOT,PYVISI_WORKDIR,PATH %s"\
106 %(pn,env['ENV']['ESCRIPT_NUM_NODES'], sn)
107 else:
108 app = "cd "+ pn +" & "+sn
109 print "Executing test: " + app
110 if not env.Execute(app):
111 open(str(target[0]),'w').write("PASSED\n")
112 else:
113 return 1
114 print "Test execution time: ", round(time.time() - time_start, 1), " seconds wall time for " + str(source[0].abspath)
115 return None
116
117 def runPyUnitTest(target, source, env):
118 time_start = time.time()
119 app = str(source[0].abspath)
120 pn, sn= os.path.split(app)
121 if os.name== "nt":
122 if env['usempi']:
123 app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\
124 "FINLEY_TEST_DATA,PYVISI_TEST_DATA_ROOT,PYVISI_WORKDIR,PATH %s\pythonMPIredirect.exe %s"\
125 %(pn,env['ENV']['ESCRIPT_NUM_NODES'],env['libinstall'],sn)
126 else:
127 app = "cd "+ pn +" & "+sys.executable + " " + sn
128 else:
129 app = "cd "+pn+"; "+os.path.join(env['bininstall'], "run-escript")+" -ov "+sn
130 print "Executing test: ",app
131 if env.Execute(app) == 0:
132 open(str(target[0]),'w').write("PASSED\n")
133 else:
134 return 1
135 print "Test execution time: ", round(time.time() - time_start, 1), " seconds wall time for " + str(source[0].abspath)
136 return None
137
138 def eps2pdf(target, source, env):
139 # if env.Execute("epstopdf "+str(source[0].abspath)+" -o "+str(target[0].abspath))!=0:
140 if env.Execute("ps2pdf -dEPSCrop "+str(source[0].abspath)+" "+str(target[0].abspath))!=0:
141 return 1
142 return None
143
144 def effectiveName(inname):
145 m=re.compile("^r1i[0-9]{1,2}n[0-9]{1,2}$") # savanna names take the form r1i?n?
146 if m.match(inname):
147 return "savanna"
148 return inname

  ViewVC Help
Powered by ViewVC 1.1.26