1 |
|
2 |
######################################################## |
3 |
# |
4 |
# Copyright (c) 2003-2010 by University of Queensland |
5 |
# 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 |
__copyright__="""Copyright (c) 2003-2010 by University of Queensland |
15 |
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 |
__url__="https://launchpad.net/escript-finley" |
21 |
|
22 |
import sys, os, time, glob, fnmatch, types, py_compile, re |
23 |
|
24 |
from SCons.Script.SConscript import SConsEnvironment |
25 |
|
26 |
def findLibWithHeader(env, libs, header, paths, lang='c'): |
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) |
60 |
conf.env.AppendUnique(CPPPATH = [inc_path]) |
61 |
conf.env.AppendUnique(LIBPATH = [lib_path]) |
62 |
if type(libs)==str: libs=[libs] |
63 |
for lib in libs: |
64 |
if not conf.CheckLibWithHeader(lib, header, lang): |
65 |
conf.Finish() |
66 |
raise RuntimeError('%s not found in %s, %s'%(lib,inc_path,lib_path)) |
67 |
|
68 |
conf.Finish() |
69 |
return inc_path, lib_path |
70 |
|
71 |
# Code to build .pyc from .py |
72 |
def build_py(target, source, env): |
73 |
py_compile.compile(str(source[0]), str(target[0])) |
74 |
return 0 |
75 |
|
76 |
# Code to run unit_test executables |
77 |
def runUnitTest(target, source, env): |
78 |
time_start = time.time() |
79 |
app = str(source[0].abspath) |
80 |
pn, sn= os.path.split(app) |
81 |
if not os.name== "nt": |
82 |
app = "cd "+pn+"; "+os.path.join(env['bininstall'],"escript")+" -bv "+os.path.join('.',sn) |
83 |
else: |
84 |
if env['usempi']: |
85 |
app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\ |
86 |
"FINLEY_TEST_DATA,PYVISI_TEST_DATA_ROOT,PYVISI_WORKDIR,PATH %s"\ |
87 |
%(pn,env['ENV']['ESCRIPT_NUM_NODES'], sn) |
88 |
else: |
89 |
app = "cd "+ pn +" & "+sn |
90 |
print "Executing test: " + app |
91 |
if not env.Execute(app): |
92 |
open(str(target[0]),'w').write("PASSED\n") |
93 |
else: |
94 |
return 1 |
95 |
print "Test execution time: ", round(time.time() - time_start, 1), " seconds wall time for " + str(source[0].abspath) |
96 |
return None |
97 |
|
98 |
def runPyUnitTest(target, source, env): |
99 |
time_start = time.time() |
100 |
app = str(source[0].abspath) |
101 |
pn, sn= os.path.split(app) |
102 |
if os.name== "nt": |
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\pythonMPIredirect.exe %s"\ |
106 |
%(pn,env['ENV']['ESCRIPT_NUM_NODES'],env['libinstall'],sn) |
107 |
else: |
108 |
app = "cd "+ pn +" & "+sys.executable + " " + sn |
109 |
else: |
110 |
app = "cd "+pn+"; "+os.path.join(env['bininstall'],"escript")+" -ov "+sn |
111 |
print "Executing test: ",app |
112 |
if env.Execute(app) == 0: |
113 |
open(str(target[0]),'w').write("PASSED\n") |
114 |
else: |
115 |
return 1 |
116 |
print "Test execution time: ", round(time.time() - time_start, 1), " seconds wall time for " + str(source[0].abspath) |
117 |
return None |
118 |
|
119 |
def eps2pdf(target, source, env): |
120 |
# if env.Execute("epstopdf "+str(source[0].abspath)+" -o "+str(target[0].abspath))!=0: |
121 |
if env.Execute("ps2pdf "+str(source[0].abspath)+" "+str(target[0].abspath))!=0: |
122 |
return 1 |
123 |
return None |
124 |
|
125 |
def effectiveName(inname): |
126 |
m=re.compile("^r1i[0-9]{1,2}n[0-9]{1,2}$") # savanna names take the form r1i?n? |
127 |
if m.match(inname): |
128 |
return "savanna" |
129 |
return inname |