source: branches/testScripts/NBbuildConfig.py @ 686

Last change on this file since 686 was 686, checked in by jpfasano, 13 years ago

Moved to computing of the vpath directory to the top of the function

  • Property svn:eol-style set to native
File size: 12.3 KB
Line 
1#! /usr/bin/env python
2
3import os
4import sys
5
6import NBlogMessages
7import NBemail
8import NBosCommand
9import NBsvnCommand
10import NBcheckResult
11
12#---------------------------------------------------------------------
13# Keep history so same project is not repeatedly getting code from
14# subversion repository.
15#---------------------------------------------------------------------
16SVN_HISTORY = []
17THIRD_PARTY_HISTORY = []
18
19#------------------------------------------------------------------------
20#  Given a configuration, build and test it.
21#
22#  configuration['project']= name of project.
23#   examples: "Clp", "Ipopt"
24#
25#  configuration['rootDir']= root directory of nightlyBuild.
26#   This is where the project will be checked out from svn, and
27#   where the code will be compiled.  This directory must already
28#   exist.  If the testing requires, it needs to contain Netlib & miplib3
29#
30#  configuration['svnVersion']= svn version to be built.
31#   Examples are: "trunk", "stable/3.2", "releases/3.3.3"
32#
33#  configuration['noThirdParty']=True or False (optional). If False
34#   then 3rd party code will be used. If not specified then 3rd part
35#   code will be skipped.
36#
37#  configuration['configOptions']: Parameters to be passed to configure.
38#   The -C option and the options for skipping 3rd party code do not
39#   need to be specified.  These will be generated by this function.
40#   There are two types of configOptions to be specified.
41#  configuration['configOptions']['unique']= These are options that
42#   distinguish different build configurations.  These options are used
43#   to generate the vpath directory name where the code will be built.
44#   Examples are: "", "--enable-debug" "--enable-parrallel"
45#  configuration['configOptions']['invariant']= These are options that
46#   that are the same for every build configuration so they don't need
47#   to be part of the vpath directory name.
48#   Example: 'CXX="g++ -m64" LDFLAGS=-lstdc++'
49#
50#  configuration['SkipProjects']= List of COIN projects to skip (exclude)
51#    from the build.
52#    examples: "Ipopt", "Ipopt DyLP"
53#
54#  configuration['checkMakeTest']= function to be called to determine
55#    if "make test" ran correctly
56#
57#  configuration['unitTest']= undefined or dictionary D where
58#    D['path']= relative path were unitTest is to be run from.
59#    D['command']= command to be issued to run unitTest
60#    D['checkUnitTest']= function to be called to determine if unitTest
61#       ran correctly.
62#------------------------------------------------------------------------
63def run(configuration) :
64  NBlogMessages.writeMessage( configuration['project'] )
65
66  # Create svn checkout target directory name
67  svnVersionFlattened=configuration['svnVersion'].replace('/','-')
68
69  #---------------------------------------------------------------------
70  # Create names of directory where source is located and
71  # and were object, libs and executables are located (vpath).
72  # To compute vpath directory, the ./configure options need to be
73  # generated.
74  #---------------------------------------------------------------------
75  projectBaseDir=os.path.join(configuration['rootDir'],configuration['project'])
76  projectCheckOutDir=os.path.join(projectBaseDir,svnVersionFlattened)
77
78  vpathDir=''
79
80  if 'SkipProjects' in configuration :
81    vpathDir+="No"+configuration['SkipProjects']
82  if 'noThirdParty' in configuration : 
83    if configuration['noThirdParty'] :
84      vpathDir+='-NoThirdParty'
85  vpathDir=svnVersionFlattened+\
86          configuration['configOptions']['unique']+\
87          vpathDir
88  vpathDir=vpathDir.replace(' ','')
89  vpathDir=vpathDir.replace('"','')
90  vpathDir=vpathDir.replace("'",'')
91  vpathDir=vpathDir.replace('--enable','')
92  if vpathDir==svnVersionFlattened : vpathDir+='-default'
93
94  fullVpathDir = os.path.join(projectBaseDir,vpathDir)
95
96  #---------------------------------------------------------------------
97  # Create the vpath directory if it doesn't exist
98  # and remove file that indicates prior run tested ok.
99  #---------------------------------------------------------------------
100  if not os.path.isdir(fullVpathDir) : 
101    os.makedirs(fullVpathDir)
102  os.chdir(fullVpathDir)
103  if os.path.isfile('NBallTestsPassed') : os.remove('NBallTestsPassed')
104
105  #---------------------------------------------------------------------
106  # svn checkout or update the project
107  #---------------------------------------------------------------------
108  # Don't get source from subversion if previously done
109  if projectCheckOutDir not in SVN_HISTORY :
110    if not os.path.isdir(projectBaseDir) :
111      os.makedirs(projectBaseDir)
112    if not os.path.isdir(projectCheckOutDir) :
113      svnCmd='svn ' +\
114           'checkout ' +\
115           'https://projects.coin-or.org/svn/'+configuration['project']+'/'+configuration['svnVersion']+\
116           ' '+svnVersionFlattened
117      if NBsvnCommand.run(svnCmd,projectBaseDir,configuration['project'])!='OK' :
118        return
119    else :
120      svnCmd='svn update'
121      if NBsvnCommand.run(svnCmd,projectCheckOutDir,configuration['project'])!='OK' :
122        return
123    SVN_HISTORY.append(projectCheckOutDir)
124  else :
125    NBlogMessages.writeMessage('  Skipping an "svn update"')
126
127  #---------------------------------------------------------------------
128  # If there are third party apps, then get these apps
129  #---------------------------------------------------------------------
130  if 'noThirdParty' in configuration :
131    if not configuration['noThirdParty'] :
132      thirdPartyBaseDir=os.path.join(projectCheckOutDir,'ThirdParty')
133      if os.path.isdir(thirdPartyBaseDir) :
134        if thirdPartyBaseDir not in THIRD_PARTY_HISTORY :
135          THIRD_PARTY_HISTORY.append(thirdPartyBaseDir)
136          thirdPartyDirs = os.listdir(thirdPartyBaseDir)
137          for d in thirdPartyDirs :
138            thirdPartyDir=os.path.join(thirdPartyBaseDir,d)
139            install3rdPartyCmd=os.path.join(".","get."+d)
140            os.chdir(thirdPartyDir)
141            # If the install command has been updated since the last
142            # install, then do a new install
143            if os.path.isfile('NBinstalldone') :
144              if NBosCommand.newer(install3rdPartyCmd,'NBinstalldone') :
145                os.remove('NBinstalldone')
146            if not os.path.isfile('NBinstalldone') :
147              if os.path.isfile(install3rdPartyCmd) :
148                NBlogMessages.writeMessage('  '+install3rdPartyCmd)
149                installReturn = NBosCommand.run(install3rdPartyCmd)
150                if installReturn['returnCode'] :
151                  NBlogMessages.writeMsg('  warning: Install of 3rd party code in '+thirdPartyDir+' returned '+installReturn['returnCode'])
152                else :
153                  f=open('NBinstalldone','w')
154                  f.close()
155                stdoutfile=open(thirdPartyDir+'/NBstdout','w')
156                stdoutfile.write(installReturn['stdout'])
157                stdoutfile.close()
158                stderrfile=open(thirdPartyDir+'/NBstderr','w')
159                stderrfile.write(installReturn['stderr'])
160                stderrfile.close()
161            else :
162              NBlogMessages.writeMessage('  skipped a new download of '+d)
163        else :
164          NBlogMessages.writeMessage('  Skipped a new download into '+thirdPartyBaseDir)
165
166  #---------------------------------------------------------------------
167  # Source is now available, so now it is time to run config
168  #---------------------------------------------------------------------
169  skipOptions=''
170
171  if 'SkipProjects' in configuration :
172    skipOptions+=configuration['SkipProjects']
173
174  # If needed create option for skipping 3rd party code
175  needSkip3PartySkipOptions=False
176  if 'noThirdParty' not in configuration : 
177    needSkip3PartySkipOptions=True
178  elif configuration['noThirdParty'] :
179    needSkip3PartySkipOptions=True
180  if needSkip3PartySkipOptions :
181    thirdPartyBaseDir=os.path.join(projectCheckOutDir,'ThirdParty')
182    if os.path.isdir(thirdPartyBaseDir) :
183      thirdPartyDirs = os.listdir(thirdPartyBaseDir)
184      for d in thirdPartyDirs :
185        skipOptions+=' ThirdParty/'+d
186
187  if skipOptions!='' :
188    skipOptions=' COIN_SKIP_PROJECTS="'+skipOptions+'"'
189
190  os.chdir(fullVpathDir)
191  NBlogMessages.writeMessage('  Current directory: '+fullVpathDir)
192 
193  # Assemble all config options together and create config command
194  configOptions ="-C "+configuration['configOptions']['unique']
195  configOptions+=configuration['configOptions']['unique']
196  configOptions+=configuration['configOptions']['invariant']
197  configOptions+=skipOptions
198  configCmd = os.path.join(projectCheckOutDir,"configure "+configOptions)
199
200
201
202  # If config was previously run, then no need to run again.
203  if NBcheckResult.didConfigRunOK() :
204    NBlogMessages.writeMessage("  configure previously ran. Not rerunning.")
205  else :
206    NBlogMessages.writeMessage("  "+configCmd)
207
208    # Finally run config
209    result=NBosCommand.run(configCmd)
210    stdoutfile=open('NBconfig.stdout','w')
211    stdoutfile.write(result['stdout'])
212    stdoutfile.close()
213    stderrfile=open('NBconfig.stderr','w')
214    stderrfile.write(result['stderr'])
215    stderrfile.close()
216
217    # Check if configure worked
218    if result['returnCode'] != 0 :
219        error_msg = result
220        # Add contents of log file to message
221        logFileName = 'config.log'
222        if os.path.isfile(logFileName) :
223          logFilePtr = open(logFileName,'r')
224          error_msg['config.log']  = "config.log contains: \n" 
225          error_msg['config.log'] += logFilePtr.read()
226          logFilePtr.close()
227        NBemail.sendCmdMsgs(configuration['project'],error_msg,configCmd)
228        return
229
230  #---------------------------------------------------------------------
231  # Run make part of build
232  #---------------------------------------------------------------------
233  NBlogMessages.writeMessage( '  make' )
234  result=NBosCommand.run('make')
235  stdoutfile=open('NBmake.stdout','w')
236  stdoutfile.write(result['stdout'])
237  stdoutfile.close()
238  stderrfile=open('NBmake.stderr','w')
239  stderrfile.write(result['stderr'])
240  stderrfile.close()
241
242  # Check if make worked
243  if result['returnCode'] != 0 :
244    NBemail.sendCmdMsgs(configuration['project'],result,'make')
245    return
246
247  #---------------------------------------------------------------------
248  # Run 'make test' part of build
249  #---------------------------------------------------------------------
250  NBlogMessages.writeMessage( '  make test' )
251  result=NBosCommand.run('make test')
252  stdoutfile=open('NBmaketest.stdout','w')
253  stdoutfile.write(result['stdout'])
254  stdoutfile.close()
255  stderrfile=open('NBmaketest.stderr','w')
256  stderrfile.write(result['stderr'])
257  stderrfile.close()
258
259  # Check if 'make test' worked
260  didMakeTestFail=configuration['checkMakeTest'](result,configuration['project'],"make test")
261  if didMakeTestFail :
262    result['make test']=didMakeTestFail
263    NBemail.sendCmdMsgs(configuration['project'],result,"make test")
264    return
265
266  #---------------------------------------------------------------------
267  # Run unitTest if available and different from 'make test'
268  #---------------------------------------------------------------------
269  if "unitTest" in configuration :
270    unitTestRelPath=configuration['unitTest']['path']
271    unitTestPath = os.path.join(fullVpathDir,unitTestRelPath)
272    os.chdir(unitTestPath)
273    NBlogMessages.writeMessage('  Current directory: '+unitTestPath)
274
275    unitTestCmdTemplate=configuration['unitTest']['command']
276
277    dataBaseDir=os.path.join(configuration['rootDir'],'Data')
278    netlibDir=os.path.join(dataBaseDir,'Netlib')
279    miplib3Dir=os.path.join(dataBaseDir,'miplib3')
280
281    unitTestCmd=unitTestCmdTemplate.replace('_NETLIBDIR_',netlibDir)
282    unitTestCmd=unitTestCmd.replace('_MIPLIB3DIR_',miplib3Dir)
283
284    NBlogMessages.writeMessage( '  '+unitTestCmd )
285    result=NBosCommand.run(unitTestCmd)
286    stdoutfile=open('NBunittest.stdout','w')
287    stdoutfile.write(result['stdout'])
288    stdoutfile.close()
289    stderrfile=open('NBunittest.stderr','w')
290    stderrfile.write(result['stderr'])
291    stderrfile.close()
292
293    didUnitTestFail=configuration['unitTest']['checkUnitTest'](result,configuration['project'],unitTestCmdTemplate)
294    if didUnitTestFail :
295      result['unitTest']=didUnitTestFail
296      NBemail.sendCmdMsgs(p,result,unitTestCmd)
297      return
298
299
300  #---------------------------------------------------------------------
301  # Everything build and all tests passed.
302  #---------------------------------------------------------------------
303  #os.chdir(fullVpathDir)
304  #f=open('NBallTestsPassed','w')
305  #f.close()
Note: See TracBrowser for help on using the repository browser.