source: branches/testScripts/NBbuildConfig.py @ 681

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

Added svn property svn:eol-style native

  • Property svn:eol-style set to native
File size: 11.2 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  # svn checkout or update the project
71  #---------------------------------------------------------------------
72  projectBaseDir=os.path.join(configuration['rootDir'],configuration['project'])
73  projectCheckOutDir=os.path.join(projectBaseDir,svnVersionFlattened)
74
75  # Don't get source from subversion if previously done
76  if projectCheckOutDir not in SVN_HISTORY :
77    if not os.path.isdir(projectBaseDir) :
78      os.makedirs(projectBaseDir)
79    if not os.path.isdir(projectCheckOutDir) :
80      svnCmd='svn ' +\
81           'checkout ' +\
82           'https://projects.coin-or.org/svn/'+configuration['project']+'/'+configuration['svnVersion']+\
83           ' '+svnVersionFlattened
84      if NBsvnCommand.run(svnCmd,projectBaseDir,configuration['project'])!='OK' :
85        return
86    else :
87      svnCmd='svn update'
88      if NBsvnCommand.run(svnCmd,projectCheckOutDir,configuration['project'])!='OK' :
89        return
90    SVN_HISTORY.append(projectCheckOutDir)
91  else :
92    NBlogMessages.writeMessage('  Skipping an "svn update"')
93
94  #---------------------------------------------------------------------
95  # If there are third party apps, then get these apps
96  #---------------------------------------------------------------------
97  if 'noThirdParty' in configuration :
98    if not configuration['noThirdParty'] :
99      thirdPartyBaseDir=os.path.join(projectCheckOutDir,'ThirdParty')
100      if os.path.isdir(thirdPartyBaseDir) :
101        if thirdPartyBaseDir not in THIRD_PARTY_HISTORY :
102          THIRD_PARTY_HISTORY.append(thirdPartyBaseDir)
103          thirdPartyDirs = os.listdir(thirdPartyBaseDir)
104          for d in thirdPartyDirs :
105            thirdPartyDir=os.path.join(thirdPartyBaseDir,d)
106            install3rdPartyCmd=os.path.join(".","get."+d)
107            os.chdir(thirdPartyDir)
108            # If the install command has been updated since the last
109            # install, then do a new install
110            if os.path.isfile('NBinstalldone') :
111              if NBosCommand.newer(install3rdPartyCmd,'NBinstalldone') :
112                os.remove('NBinstalldone')
113            if not os.path.isfile('NBinstalldone') :
114              if os.path.isfile(install3rdPartyCmd) :
115                NBlogMessages.writeMessage('  '+install3rdPartyCmd)
116                installReturn = NBosCommand.run(install3rdPartyCmd)
117                if installReturn['returnCode'] :
118                  NBlogMessages.writeMsg('  warning: Install of 3rd party code in '+thirdPartyDir+' returned '+installReturn['returnCode'])
119                else :
120                  f=open('NBinstalldone','w')
121                  f.close()
122                stdoutfile=open(thirdPartyDir+'/NBstdout','w')
123                stdoutfile.write(installReturn['stdout'])
124                stdoutfile.close()
125                stderrfile=open(thirdPartyDir+'/NBstderr','w')
126                stderrfile.write(installReturn['stderr'])
127                stderrfile.close()
128            else :
129              NBlogMessages.writeMessage('  skipped a new download of '+d)
130        else :
131          NBlogMessages.writeMessage('  Skipped a new download into '+thirdPartyBaseDir)
132
133  #---------------------------------------------------------------------
134  # Source is now available, so now it is time to run config
135  #---------------------------------------------------------------------
136  skipOptions=''
137  vpathDir=''
138
139  if 'SkipProjects' in configuration :
140    skipOptions+=configuration['SkipProjects']
141
142  # If needed create option for skipping 3rd party code
143  needSkip3PartySkipOptions=False
144  if 'noThirdParty' not in configuration : 
145    needSkip3PartySkipOptions=True
146  elif configuration['noThirdParty'] :
147    needSkip3PartySkipOptions=True
148    vpathDir='-NoThirdParty'
149  if needSkip3PartySkipOptions :
150    thirdPartyBaseDir=os.path.join(projectCheckOutDir,'ThirdParty')
151    if os.path.isdir(thirdPartyBaseDir) :
152      thirdPartyDirs = os.listdir(thirdPartyBaseDir)
153      for d in thirdPartyDirs :
154        skipOptions+=' ThirdParty/'+d
155
156  if skipOptions!='' :
157    skipOptions=' COIN_SKIP_PROJECTS="'+skipOptions+'"'
158
159  # Determine the build directory, and make sure it exists   
160  vpathDir=svnVersionFlattened+\
161          configuration['configOptions']['unique']+\
162          vpathDir
163  vpathDir=vpathDir.replace(' ','')
164  vpathDir=vpathDir.replace('"','')
165  vpathDir=vpathDir.replace("'",'')
166  vpathDir=vpathDir.replace('--enable','')
167  if vpathDir==svnVersionFlattened : vpathDir+='-default'
168
169  fullVpathDir = os.path.join(projectBaseDir,vpathDir)
170  if not os.path.isdir(fullVpathDir) : 
171    os.makedirs(fullVpathDir)
172  os.chdir(fullVpathDir)
173  NBlogMessages.writeMessage('  Current directory: '+fullVpathDir)
174
175  # Assemble all config options together and create config command
176  configOptions ="-C "+configuration['configOptions']['unique']
177  configOptions+=configuration['configOptions']['unique']
178  configOptions+=configuration['configOptions']['invariant']
179  configOptions+=skipOptions
180  configCmd = os.path.join(projectCheckOutDir,"configure "+configOptions)
181
182
183
184  # If config was previously run, then no need to run again.
185  if NBcheckResult.didConfigRunOK() :
186    NBlogMessages.writeMessage("  configure previously ran. Not rerunning.")
187  else :
188    NBlogMessages.writeMessage("  "+configCmd)
189
190    # Finally run config
191    result=NBosCommand.run(configCmd)
192    stdoutfile=open('NBconfig.stdout','w')
193    stdoutfile.write(result['stdout'])
194    stdoutfile.close()
195    stderrfile=open('NBconfig.stderr','w')
196    stderrfile.write(result['stderr'])
197    stderrfile.close()
198
199    # Check if configure worked
200    if result['returnCode'] != 0 :
201        error_msg = result
202        # Add contents of log file to message
203        logFileName = 'config.log'
204        if os.path.isfile(logFileName) :
205          logFilePtr = open(logFileName,'r')
206          error_msg['config.log']  = "config.log contains: \n" 
207          error_msg['config.log'] += logFilePtr.read()
208          logFilePtr.close()
209        NBemail.sendCmdMsgs(configuration['project'],error_msg,configCmd)
210        return
211
212  #---------------------------------------------------------------------
213  # Run make part of build
214  #---------------------------------------------------------------------
215  NBlogMessages.writeMessage( '  make' )
216  result=NBosCommand.run('make')
217  stdoutfile=open('NBmake.stdout','w')
218  stdoutfile.write(result['stdout'])
219  stdoutfile.close()
220  stderrfile=open('NBmake.stderr','w')
221  stderrfile.write(result['stderr'])
222  stderrfile.close()
223
224  # Check if make worked
225  if result['returnCode'] != 0 :
226    NBemail.sendCmdMsgs(configuration['project'],result,'make')
227    return
228
229  #---------------------------------------------------------------------
230  # Run 'make test' part of build
231  #---------------------------------------------------------------------
232  NBlogMessages.writeMessage( '  make test' )
233  result=NBosCommand.run('make test')
234  stdoutfile=open('NBmaketest.stdout','w')
235  stdoutfile.write(result['stdout'])
236  stdoutfile.close()
237  stderrfile=open('NBmaketest.stderr','w')
238  stderrfile.write(result['stderr'])
239  stderrfile.close()
240
241  # Check if 'make test' worked
242  didMakeTestFail=configuration['checkMakeTest'](result,configuration['project'],"make test")
243  if didMakeTestFail :
244    result['make test']=didMakeTestFail
245    NBemail.sendCmdMsgs(configuration['project'],result,"make test")
246    return
247
248  #---------------------------------------------------------------------
249  # Run unitTest if available and different from 'make test'
250  #---------------------------------------------------------------------
251  if "unitTest" in configuration :
252    unitTestRelPath=configuration['unitTest']['path']
253    unitTestPath = os.path.join(fullVpathDir,unitTestRelPath)
254    os.chdir(unitTestPath)
255    NBlogMessages.writeMessage('  Current directory: '+unitTestPath)
256
257    unitTestCmdTemplate=configuration['unitTest']['command']
258
259    dataBaseDir=os.path.join(configuration['rootDir'],'Data')
260    netlibDir=os.path.join(dataBaseDir,'Netlib')
261    miplib3Dir=os.path.join(dataBaseDir,'miplib3')
262
263    unitTestCmd=unitTestCmdTemplate.replace('_NETLIBDIR_',netlibDir)
264    unitTestCmd=unitTestCmd.replace('_MIPLIB3DIR_',miplib3Dir)
265
266    NBlogMessages.writeMessage( '  '+unitTestCmd )
267    result=NBosCommand.run(unitTestCmd)
268    stdoutfile=open('NBunittest.stdout','w')
269    stdoutfile.write(result['stdout'])
270    stdoutfile.close()
271    stderrfile=open('NBunittest.stderr','w')
272    stderrfile.write(result['stderr'])
273    stderrfile.close()
274
275    didUnitTestFail=configuration['unitTest']['checkUnitTest'](result,configuration['project'],unitTestCmdTemplate)
276    if didUnitTestFail :
277      result['unitTest']=didUnitTestFail
278      NBemail.sendCmdMsgs(p,result,unitTestCmd)
279      return
280
Note: See TracBrowser for help on using the repository browser.