/[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 370 by cochrane, Fri Dec 16 00:52:34 2005 UTC trunk/site_scons/site_init.py revision 4300 by caltinay, Mon Mar 11 00:50:19 2013 UTC
# Line 1  Line 1 
 # Extensions to Scons  
1    
2  import py_compile  ##############################################################################
3  import sys  #
4  import os  # Copyright (c) 2003-2013 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-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    from SCons.Defaults import Chmod
25    from grouptest import *
26    
27    def findLibWithHeader(env, libs, header, paths, lang='c'):
28        from SCons.Script.SConscript import Configure
29        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        conf=Configure(env.Clone())
62        conf.env.AppendUnique(CPPPATH = [inc_path])
63        conf.env.AppendUnique(LIBPATH = [lib_path])
64        if type(libs)==str: libs=[libs]
65        # 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    
72        conf.Finish()
73        return inc_path, lib_path
74    
75    def detectModule(env, module):
76        p=subprocess.call([env['pythoncmd'],'-c','import %s'%module])
77        if p != 0:
78            env[module] = False
79            return False
80        env[module] = True
81        return True
82    
83    def write_buildvars(env):
84        buildvars=open(os.path.join(env['libinstall'], 'buildvars'), 'w')
85        for k,v in sorted(env['buildvars'].items()):
86            buildvars.write("%s=%s\n"%(k,v))
87        buildvars.close()
88    
89    def generateTestScripts(env, TestGroups):
90        try:
91            utest=open('utest.sh','w')
92            utest.write(GroupTest.makeHeader(env['PLATFORM'], env['prefix'], False))
93            for tests in TestGroups:
94                utest.write(tests.makeString())
95            utest.close()
96            env.Execute(Chmod('utest.sh', 0o755))
97            print("Generated utest.sh.")
98            # This version contains only python tests - I want this to be usable
99            # from a binary only install if you have the test files
100            utest=open('itest.sh','w')
101            utest.write(GroupTest.makeHeader(env['PLATFORM'], env['prefix'], True))
102            for tests in TestGroups:
103              if tests.exec_cmd=='$PYTHONRUNNER ':
104                utest.write(tests.makeString())
105            utest.close()
106            env.Execute(Chmod('itest.sh', 0o755))
107            print("Generated itest.sh.")        
108        except IOError:
109            env['warnings'].append("Error attempting to write unit test script(s).")
110    
111        # delete scripts upon cleanup
112        env.Clean('target_init', 'utest.sh')
113        env.Clean('target_init', 'itest.sh')
114    
115        # Make sure that the escript wrapper is in place
116        if not os.path.isfile(os.path.join(env['bininstall'], 'run-escript')):
117            print("Copying escript wrapper.")
118            Execute(Copy(os.path.join(env['bininstall'],'run-escript'), 'bin/run-escript'))
119    
120  # Code to build .pyc from .py  # Code to build .pyc from .py
121  def build_py(target, source, env):  def build_py(target, source, env):
122    py_compile.compile(str(source[0]), str(target[0]))      try:
123    return None         py_compile.compile(str(source[0]), str(target[0]), doraise=True)
124           return 0
125        except py_compile.PyCompileError, e:
126           print e
127           return 1
128    
129    
130  # Code to run unit_test executables  # Code to run unit_test executables
131  def runUnitTest(target, source, env):  def runUnitTest(target, source, env):
132      time_start = time.time()
133    app = str(source[0].abspath)    app = str(source[0].abspath)
134    if not os.system(app):    pn, sn= os.path.split(app)
135      if not os.name== "nt":
136         app = "cd "+pn+"; "+os.path.join(env['bininstall'], "run-escript")+" -bv "+os.path.join('.',sn)
137      else:
138          if env['usempi']:
139              app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\
140                "FINLEY_TEST_DATA,PYVISI_TEST_DATA_ROOT,PYVISI_WORKDIR,PATH %s"\
141                %(pn,env['ENV']['ESCRIPT_NUM_NODES'], sn)
142          else:
143               app = "cd "+ pn +" & "+sn
144      print "Executing test: " + app
145      if not env.Execute(app):
146      open(str(target[0]),'w').write("PASSED\n")      open(str(target[0]),'w').write("PASSED\n")
147    else:    else:
148      return 1      return 1
149      print "Test execution time: ", round(time.time() - time_start, 1), " seconds wall time for " + str(source[0].abspath)
150    return None    return None
151    
152  # code to build epydoc docs  def runPyUnitTest(target, source, env):
153  def build_epydoc(target, source, env):     time_start = time.time()
154      # get where I am currently, just as a reference     app = str(source[0].abspath)
155      pwd = os.getcwd()     pn, sn= os.path.split(app)
156       if os.name== "nt":
157      # get the full path of the runepydoc script         if env['usempi']:
158      runepydoc = str(source[0].abspath)             app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\
159                  "FINLEY_TEST_DATA,PYVISI_TEST_DATA_ROOT,PYVISI_WORKDIR,PATH %s\pythonMPIredirect.exe %s"\
160      # use this path to work out where the doc directory is                %(pn,env['ENV']['ESCRIPT_NUM_NODES'],env['libinstall'],sn)
161      dirs = runepydoc.split('/')         else:
162      dirs = dirs[:-3] # trim the last two entries: this is now the doc dir path             app = "cd "+ pn +" & "+sys.executable + " " + sn
163      docdir = '/'.join(dirs) # this is the backwards python way to do it     else:
164      # (I'm feeling in a perl mood today...)       app = "cd "+pn+"; "+os.path.join(env['bininstall'], "run-escript")+" -ov "+sn
165       print "Executing test: ",app
166      # change into the relevant dir     if env.Execute(app) == 0:
167      os.chdir(docdir)        open(str(target[0]),'w').write("PASSED\n")
168       else:
169      # run the epydoc script       return 1
170      if not os.system(runepydoc):     print "Test execution time: ", round(time.time() - time_start, 1), " seconds wall time for " + str(source[0].abspath)
171      os.chdir(pwd)     return None
172      open(str(target[0]), 'w').write("Documentation built\n")  
173      else:  def eps2pdf(target, source, env):
174      return 1  #   if env.Execute("epstopdf "+str(source[0].abspath)+" -o "+str(target[0].abspath))!=0:
175      return None     if env.Execute("ps2pdf -dEPSCrop "+str(source[0].abspath)+" "+str(target[0].abspath))!=0:
176           return 1
177  # build doxygen docs     return None
178  def build_doxygen(target, source, env):  
179      # get where I am currently, just as a reference  def effectiveName(inname):
180      pwd = os.getcwd()     m=re.compile("^r1i[0-9]{1,2}n[0-9]{1,2}$")   # savanna names take the form r1i?n?
181       if m.match(inname):
182      # get the full path of the rundoxygen script      return "savanna"
183      rundoxygen = str(source[0].abspath)     return inname
   
     # 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.370  
changed lines
  Added in v.4300

  ViewVC Help
Powered by ViewVC 1.1.26