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

Diff of /trunk/site_scons/site_init.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/scons/scons_extensions.py revision 707 by gross, Wed Apr 12 23:58:02 2006 UTC trunk/site_scons/site_init.py revision 4154 by jfenwick, Tue Jan 22 09:30:23 2013 UTC
# Line 1  Line 1 
1    
2  #          Copyright 2006 by ACcESS MNRF                    ##############################################################################
3  #                                                            #
4  #              http://www.access.edu.au                      # Copyright (c) 2003-2013 by University of Queensland
5  #       Primary Business: Queensland, Australia              # http://www.uq.edu.au
6  #  Licensed under the Open Software License version 3.0      #
7  #     http://www.opensource.org/licenses/osl-3.0.php        # 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  # Extensions to Scons  # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12    # Development since 2012 by School of Earth Sciences
13  import py_compile  #
14  import sys  ##############################################################################
15  import os  
16    __copyright__="""Copyright (c) 2003-2013 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  # Code to build .pyc from .py
86  def build_py(target, source, env):  def build_py(target, source, env):
87    py_compile.compile(str(source[0]), str(target[0]))      try:
88    return None         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  # Code to run unit_test executables
96  def runUnitTest(target, source, env):  def runUnitTest(target, source, env):
97      time_start = time.time()
98    app = str(source[0].abspath)    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):    if not env.Execute(app):
111      open(str(target[0]),'w').write("PASSED\n")      open(str(target[0]),'w').write("PASSED\n")
112    else:    else:
113      return 1      return 1
114      print "Test execution time: ", round(time.time() - time_start, 1), " seconds wall time for " + str(source[0].abspath)
115    return None    return None
116    
117  def runPyUnitTest(target, source, env):  def runPyUnitTest(target, source, env):
118     app = 'python '+str(source[0].abspath)     time_start = time.time()
119     if not env.Execute(app):     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")        open(str(target[0]),'w').write("PASSED\n")
133     else:     else:
134       return 1       return 1
135       print "Test execution time: ", round(time.time() - time_start, 1), " seconds wall time for " + str(source[0].abspath)
136     return None     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 build_epydoc(target, source, env):  def effectiveName(inname):
145      # get where I am currently, just as a reference     m=re.compile("^r1i[0-9]{1,2}n[0-9]{1,2}$")   # savanna names take the form r1i?n?
146      pwd = os.getcwd()     if m.match(inname):
147        return "savanna"
148      # get the full path of the runepydoc script     return inname
     runepydoc = str(source[0].abspath)  
   
     # use this path to work out where the doc directory is  
     dirs = runepydoc.split('/')  
     dirs = dirs[:-3] # trim the last two entries: this is now the doc dir path  
     docdir = '/'.join(dirs) # this is the backwards python way to do it  
     # (I'm feeling in a perl mood today...)  
   
     # change into the relevant dir  
     os.chdir(docdir)  
   
     # run the epydoc script  
     if not os.system(runepydoc):  
     os.chdir(pwd)  
     open(str(target[0]), 'w').write("Documentation built\n")  
     else:  
     return 1  
     return None  
   
 # build doxygen docs  
 def build_doxygen(target, source, env):  
     # get where I am currently, just as a reference  
     pwd = os.getcwd()  
   
     # get the full path of the rundoxygen script  
     rundoxygen = str(source[0].abspath)  
   
     # use this path to work out where the doc directory is  
     dirs = rundoxygen.split('/')  
     dirs = dirs[:-2] # trim the last two entries: this is now the doc dir path  
     docdir = '/'.join(dirs) # this is the backwards python way to do it  
     # (I'm feeling in a perl mood today...)  
   
     # change into the relevant dir  
     os.chdir(docdir)  
   
     # run the doxygen script  
     if not os.system(rundoxygen):  
     os.chdir(pwd)  
     open(str(target[0]), 'w').write("Documentation built\n")  
     else:  
     return 1  
     return None  

Legend:
Removed from v.707  
changed lines
  Added in v.4154

  ViewVC Help
Powered by ViewVC 1.1.26