/[escript]/branches/4.0fordebian/site_scons/site_init.py
ViewVC logotype

Diff of /branches/4.0fordebian/site_scons/site_init.py

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

trunk/scons/scons_extensions.py revision 645 by elspeth, Fri Mar 24 01:10:42 2006 UTC branches/4.0fordebian/site_scons/site_init.py revision 5577 by jfenwick, Fri Apr 3 05:26:15 2015 UTC
# Line 1  Line 1 
1    
2  #          Copyright 2006 by ACcESS MNRF                    ##############################################################################
3  #                                                            #
4  #              http://www.access.edu.au                      # Copyright (c) 2003-2014 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 2012-2013 by School of Earth Sciences
13  import py_compile  # Development from 2014 by Centre for Geoscience Computing (GeoComp)
14  import sys  #
15  import os  ##############################################################################
16    
17    __copyright__="""Copyright (c) 2003-2014 by University of Queensland
18    http://www.uq.edu.au
19    Primary Business: Queensland, Australia"""
20    __license__="""Licensed under the Open Software License version 3.0
21    http://www.opensource.org/licenses/osl-3.0.php"""
22    __url__="https://launchpad.net/escript-finley"
23    
24    import sys, os, time, py_compile, re, subprocess
25    from SCons.Defaults import Chmod, Copy
26    from grouptest import *
27    from extractdebbuild import *
28    
29    def findLibWithHeader(env, libs, header, paths, lang='c++'):
30        from SCons.Script.SConscript import Configure
31        inc_path=''
32        lib_path=''
33        # 'paths' may be a prefix, so look for lib and include subdirectories
34        if type(paths)==str:
35            # find the header file first
36            for i in 'include','include64','include32','inc':
37                inc=os.path.join(paths, i)
38                if os.path.isfile(os.path.join(inc, header)):
39                    inc_path=inc
40                    break
41            if inc_path=='':
42                raise RuntimeError('%s not found under %s'%(header,paths))
43    
44            # now try to find a lib directory
45            for l in 'lib','lib64','lib32':
46                lp=os.path.join(paths, l)
47                if os.path.isdir(lp):
48                    lib_path=lp
49                    break
50            if lib_path=='':
51                raise RuntimeError('No lib directory found under %s'%paths)
52        else:
53            if os.path.isfile(os.path.join(paths[0], header)):
54                inc_path=paths[0]
55            else:
56                raise RuntimeError('%s not found under %s'%(header,paths[0]))
57            if os.path.isdir(paths[1]):
58                lib_path=paths[1]
59            else:
60                raise RuntimeError('%s is not a valid path.'%paths[1])
61    
62        # now try the library
63        conf=Configure(env.Clone())
64        conf.env.AppendUnique(CPPPATH = [inc_path])
65        conf.env.AppendUnique(LIBPATH = [lib_path])
66        if type(libs)==str: libs=[libs]
67        if len(libs)==0: libs=['']
68        # we can't check for each library by itself since they may depend on each
69        # other, so we add all libraries to the link line and check only for one
70        conf.env.AppendUnique(LIBS = libs)
71        if not conf.CheckLibWithHeader(libs[0], header, lang):
72            conf.Finish()
73            raise RuntimeError('Unable to link against %s (paths: %s, %s)'%(libs,inc_path,lib_path))
74    
75        conf.Finish()
76        return inc_path, lib_path
77    
78    def detectModule(env, module):
79        from tempfile import TemporaryFile
80        p=subprocess.call([env['pythoncmd'],'-c','import %s'%module], stderr=TemporaryFile())
81        if p != 0:
82            env[module] = False
83            return False
84        env[module] = True
85        return True
86    
87    def write_buildvars(env):
88        buildvars=open(os.path.join(env['libinstall'], 'buildvars'), 'w')
89        for k,v in sorted(env['buildvars'].items()):
90            buildvars.write("%s=%s\n"%(k,v))
91        buildvars.close()
92    
93    def write_launcher(env):
94        reps={'%n':'${ESCRIPT_NUM_NODES}', '%p':'${ESCRIPT_NUM_PROCS}',
95              '%N':'${TOTPROC}', '%t':'${ESCRIPT_NUM_THREADS}', '%f':'${HOSTFILE}',
96              '%h':'${HOSTLIST}', '%e':'${EXPORT_ENV}', '%b':'${EXEC_CMD}'}
97        pre=env['prelaunch']
98        cmd=env['launcher']
99        post=env['postlaunch']
100        # %b should be present in launcher at least
101        if not '%b' in cmd:
102            raise RuntimeError('option "launcher" must contain %b!')
103    
104        for k, v in reps.iteritems():
105            pre = pre.replace(k, v)
106            cmd = cmd.replace(k, v)
107            post = post.replace(k, v)
108        try:
109            launchscript = os.path.join(env['bininstall'], 'run-escript')
110            launcher=open(launchscript, 'w')
111            for line in open('run-escript.in','r').readlines():
112                launcher.write(line.replace('@@PRELAUNCH', pre).replace('@@LAUNCH', cmd).replace('@@POSTLAUNCH', post))
113            launcher.close()
114            env.Execute(Chmod(launchscript, 0o755))
115        except IOError:
116            env['warnings'].append("Error attempting to write launcher script.")
117    
118    def generateTestScripts(env, TestGroups):
119        try:
120            utest=open('utest.sh','w')
121            utest.write(GroupTest.makeHeader(env['PLATFORM'], env['prefix'], False))
122            for tests in TestGroups:
123                utest.write(tests.makeString())
124            utest.close()
125            env.Execute(Chmod('utest.sh', 0o755))
126            print("Generated utest.sh.")
127            # This version contains only python tests - I want this to be usable
128            # from a binary only install if you have the test files
129            utest=open('itest.sh','w')
130            utest.write(GroupTest.makeHeader(env['PLATFORM'], env['prefix'], True))
131            for tests in TestGroups:
132              if tests.exec_cmd=='$PYTHONRUNNER ':
133                utest.write(tests.makeString())
134            utest.close()
135            env.Execute(Chmod('itest.sh', 0o755))
136            print("Generated itest.sh.")        
137        except IOError:
138            env['warnings'].append("Error attempting to write unit test script(s).")
139    
140        # delete scripts upon cleanup
141        env.Clean('target_init', 'utest.sh')
142        env.Clean('target_init', 'itest.sh')
143    
144  # Code to build .pyc from .py  # Code to build .pyc from .py
145  def build_py(target, source, env):  def build_py(target, source, env):
146    py_compile.compile(str(source[0]), str(target[0]))      try:
147    return None         py_compile.compile(str(source[0]), str(target[0]), doraise=True)
148           return 0
149        except py_compile.PyCompileError, e:
150           print e
151           return 1
152    
153    
154  # Code to run unit_test executables  # Code to run unit_test executables
155  def runUnitTest(target, source, env):  def runUnitTest(target, source, env):
156      time_start = time.time()
157    app = str(source[0].abspath)    app = str(source[0].abspath)
158    if not os.system(app):    pn, sn= os.path.split(app)
159      if not os.name== "nt":
160         app = "cd "+pn+"; "+os.path.join(env['bininstall'], "run-escript")+" -bv "+os.path.join('.',sn)
161      else:
162          if env['usempi']:
163              app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\
164                "FINLEY_TEST_DATA,PATH %s"\
165                %(pn,env['ENV']['ESCRIPT_NUM_NODES'], sn)
166          else:
167               app = "cd "+ pn +" & "+sn
168      print "Executing test: " + app
169      if not env.Execute(app):
170      open(str(target[0]),'w').write("PASSED\n")      open(str(target[0]),'w').write("PASSED\n")
171    else:    else:
172      return 1      return 1
173      print "Test execution time: ", round(time.time() - time_start, 1), " seconds wall time for " + str(source[0].abspath)
174    return None    return None
175    
176  # code to build epydoc docs  def binpath(env, name=None):
177  def build_epydoc(target, source, env):      if not name:
178      # get where I am currently, just as a reference          return env['bininstall']
179      pwd = os.getcwd()      return os.path.join(env['bininstall'], name)
180    
181      # get the full path of the runepydoc script  def runPyUnitTest(target, source, env):
182      runepydoc = str(source[0].abspath)     time_start = time.time()
183       app = str(source[0].abspath)
184      # use this path to work out where the doc directory is     pn, sn= os.path.split(app)
185      dirs = runepydoc.split('/')     if os.name=="nt":
186      dirs = dirs[:-3] # trim the last two entries: this is now the doc dir path         if env['usempi']:
187      docdir = '/'.join(dirs) # this is the backwards python way to do it             app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\
188      # (I'm feeling in a perl mood today...)                "FINLEY_TEST_DATA,PATH %s\pythonMPIredirect.exe %s"\
189                  %(pn,env['ENV']['ESCRIPT_NUM_NODES'],env['libinstall'],sn)
190      # change into the relevant dir         else:
191      os.chdir(docdir)             app = "cd "+ pn +" & "+sys.executable + " " + sn
192       else:
193      # run the epydoc script       skipfile = os.path.join(env['BUILD_DIR'], sn[:-3]) + ".skipped"
194      if not os.system(runepydoc):       try:
195      os.chdir(pwd)           os.unlink(skipfile)
196      open(str(target[0]), 'w').write("Documentation built\n")       except Exception as e:
197      else:          pass
198      return 1       app = "cd "+pn+"; "+binpath(env, "run-escript")+" -ov "+binpath(env,
199      return None              "../tools/testrunner.py")+" -outputfile="+skipfile+" "+sn
200       print "Executing test: ",app
201  # build doxygen docs     if env.Execute(app) == 0:
202  def build_doxygen(target, source, env):        open(str(target[0]),'w').write("PASSED\n")
203      # get where I am currently, just as a reference     else:
204      pwd = os.getcwd()       return 1
205       print "Test execution time: ", round(time.time() - time_start, 1), " seconds wall time for " + str(source[0].abspath)
206      # get the full path of the rundoxygen script     return None
207      rundoxygen = str(source[0].abspath)  
208    def runPyExample(target, source, env):
209      # use this path to work out where the doc directory is     time_start = time.time()
210      dirs = rundoxygen.split('/')     app = str(source[0].abspath)
211      dirs = dirs[:-2] # trim the last two entries: this is now the doc dir path     pn, sn= os.path.split(app)
212      docdir = '/'.join(dirs) # this is the backwards python way to do it     if os.name=="nt":
213      # (I'm feeling in a perl mood today...)         if env['usempi']:
214               app = "cd %s & mpiexec -np %s -genvlist PYTHONPATH,OMP_NUM_THREADS,"\
215      # change into the relevant dir                "FINLEY_TEST_DATA,PATH %s\pythonMPIredirect.exe %s"\
216      os.chdir(docdir)                %(pn,env['ENV']['ESCRIPT_NUM_NODES'],env['libinstall'],sn)
217           else:
218      # run the doxygen script             app = "cd "+ pn +" & "+sys.executable + " " + sn
219      if not os.system(rundoxygen):     else:
220      os.chdir(pwd)      
221      open(str(target[0]), 'w').write("Documentation built\n")       app = "cd "+pn+"; pwd; "+binpath(env, "run-escript")+" -ov "+sn
222      else:     print "Executing test: ",app
223      return 1     if env.Execute(app) == 0:
224      return None        open(str(target[0]),'w').write("PASSED\n")
225       else:
226         return 1
227       print "Test execution time: ", round(time.time() - time_start, 1), " seconds wall time for " + str(source[0].abspath)
228       return None
229    
230    def eps2pdf(target, source, env):
231    #   if env.Execute("epstopdf "+str(source[0].abspath)+" -o "+str(target[0].abspath))!=0:
232       if env.Execute("ps2pdf -dEPSCrop "+str(source[0].abspath)+" "+str(target[0].abspath))!=0:
233           return 1
234       return None
235    
236    def effectiveName(inname):
237        m=re.compile("^r1i[0-9]{1,2}n[0-9]{1,2}$")  # savanna names take the form r1i?n?
238        if m.match(inname):
239            return "savanna"
240        return inname

Legend:
Removed from v.645  
changed lines
  Added in v.5577

  ViewVC Help
Powered by ViewVC 1.1.26