source: branches/testScripts/NBbuildConfig.py @ 673

Last change on this file since 673 was 673, checked in by jpfasano, 12 years ago

New version of nightlyBuild (newNightlyBuild) which is supposed to
build the coin projects as configured in BUILDS currently defined in
NBprojectConfig.py

  • Property svn:executable set to *
File size: 9.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#   Examples are: "", "--enable-debug"
41#
42#  configuration['SkipProjects']= List of COIN projects to skip (exclude)
43#    from the build.
44#    examples: "Ipopt", "Ipopt DyLP"
45#
46#  configuration['checkMakeTest']= function to be called to determine
47#    if "make test" ran correctly
48#
49#  configuration['unitTest']= undefined or dictionary D where
50#    D['path']= relataive path were unitTest is to be run from.
51#    D['command']= command to be issued to run unitTest
52#    d['checkUnitTest']= function to be called to determine if unitTest
53#       ran correctly.
54#------------------------------------------------------------------------
55def run(configuration) :
56  NBlogMessages.writeMessage( configuration['project'] )
57
58  # Create svn checkout target directory name
59  svnVersionFlattened=configuration['svnVersion'].replace('/','-')
60
61  #---------------------------------------------------------------------
62  # svn checkout or update the project
63  #---------------------------------------------------------------------
64  projectBaseDir=os.path.join(configuration['rootDir'],configuration['project'])
65  projectCheckOutDir=os.path.join(projectBaseDir,svnVersionFlattened)
66
67  # Don't get source from subversion if previously done
68  if projectCheckOutDir not in SVN_HISTORY :
69    if not os.path.isdir(projectBaseDir) :
70      os.makedirs(projectBaseDir)
71    if not os.path.isdir(projectCheckOutDir) :
72      svnCmd='svn ' +\
73           'checkout ' +\
74           'https://projects.coin-or.org/svn/'+configuration['project']+'/'+configuration['svnVersion']+\
75           ' '+svnVersionFlattened
76      if NBsvnCommand.run(svnCmd,projectBaseDir,configuration['project'])!='OK' :
77        return
78    else :
79      svnCmd='svn update'
80      if NBsvnCommand.run(svnCmd,projectCheckOutDir,configuration['project'])!='OK' :
81        return
82    SVN_HISTORY.append(projectCheckOutDir)
83  else :
84    NBlogMessages.writeMessage('  Skipping an "svn update"')
85
86  #---------------------------------------------------------------------
87  # If there are third party apps, then get these apps
88  #---------------------------------------------------------------------
89  if 'noThirdParty' in configuration :
90    if not configuration['noThirdParty'] :
91      thirdPartyBaseDir=os.path.join(projectCheckOutDir,'ThirdParty')
92      if os.path.isdir(thirdPartyBaseDir) :
93        if thirdPartyBaseDir not in THIRD_PARTY_HISTORY :
94          THIRD_PARTY_HISTORY.append(thirdPartyBaseDir)
95          thirdPartyDirs = os.listdir(thirdPartyBaseDir)
96          for d in thirdPartyDirs :
97            thirdPartyDir=os.path.join(thirdPartyBaseDir,d)
98            install3rdPartyCmd=os.path.join(".","get."+d)
99            os.chdir(thirdPartyDir)
100            # If the install command has been updated since the last
101            # install, then do a new install
102            if os.path.isfile('NBinstalldone') :
103              if NBosCommand.newer(install3rdPartyCmd,'NBinstalldone') :
104                os.remove('NBinstalldone')
105            if not os.path.isfile('NBinstalldone') :
106              if os.path.isfile(install3rdPartyCmd) :
107                NBlogMessages.writeMessage('  '+install3rdPartyCmd)
108                NBosCommand.run(install3rdPartyCmd)
109                f=open('NBinstalldone','w')
110                f.close()
111            else :
112              NBlogMessages.writeMessage('  skipped a new download of '+d)
113        else :
114          NBlogMessages.writeMessage('  Skipped a new download into '+thirdPartyBaseDir)
115   
116  #---------------------------------------------------------------------
117  # Source is now available, so now it is time to run config
118  #---------------------------------------------------------------------
119  skipOptions=''
120  vpathDir=''
121
122  if 'SkipProjects' in configuration :
123    skipOptions+=configuration['SkipProjects']
124
125  # If needed create option for skipping 3rd party code
126  needSkip3PartySkipOptions=False
127  if 'noThirdParty' not in configuration : 
128    needSkip3PartySkipOptions=True
129  elif configuration['noThirdParty'] :
130    needSkip3PartySkipOptions=True
131    vpathDir='-NoThirdParty'
132  if needSkip3PartySkipOptions :
133    thirdPartyBaseDir=os.path.join(projectCheckOutDir,'ThirdParty')
134    if os.path.isdir(thirdPartyBaseDir) :
135      thirdPartyDirs = os.listdir(thirdPartyBaseDir)
136      for d in thirdPartyDirs :
137        skipOptions+=' ThirdParty/'+d
138
139  if skipOptions!='' :
140    skipOptions=' COIN_SKIP_PROJECTS="'+skipOptions+'"'
141
142  # Determine the build directory, and make sure it exists   
143  vpathDir=svnVersionFlattened+\
144          configuration['configOptions']+\
145          vpathDir
146  vpathDir=vpathDir.replace(' ','')
147  vpathDir=vpathDir.replace('--enable','')
148  if vpathDir==svnVersionFlattened : vpathDir+='-default'
149 
150  fullVpathDir = os.path.join(projectBaseDir,vpathDir)
151  if not os.path.isdir(fullVpathDir) : 
152    os.makedirs(fullVpathDir)
153  os.chdir(fullVpathDir)
154
155  # Assemble all config options together and create config command
156  configOptions="-C "+configuration['configOptions']+skipOptions
157  configCmd = os.path.join(projectCheckOutDir,"configure "+configOptions)
158
159
160
161  # If config was previously run, then no need to run again.
162  if NBcheckResult.didConfigRunOK() :
163    NBlogMessages.writeMessage("  '"+configCmd+"' previously ran. Not rerunning")
164  else :
165    NBlogMessages.writeMessage("  "+configCmd)
166    NBlogMessages.writeMessage("    in "+fullVpathDir)
167
168    # Finally run config
169    result=NBosCommand.run(configCmd)
170     
171    # Check if configure worked
172    if result['returnCode'] != 0 :
173        error_msg = result
174        # Add contents of log file to message
175        logFileName = 'config.log'
176        if os.path.isfile(logFileName) :
177          logFilePtr = open(logFileName,'r')
178          error_msg['config.log']  = "config.log contains: \n" 
179          error_msg['config.log'] += logFilePtr.read()
180          logFilePtr.close()
181        NBemail.sendCmdMsgs(configuration['project'],error_msg,configCmd)
182        return
183
184  #---------------------------------------------------------------------
185  # Run make part of build
186  #---------------------------------------------------------------------
187  NBlogMessages.writeMessage( '  make' )
188  result=NBosCommand.run('make')
189     
190  # Check if make worked
191  if result['returnCode'] != 0 :
192    NBemail.sendCmdMsgs(configuration['project'],result,'make')
193    return
194
195  #---------------------------------------------------------------------
196  # Run 'make test' part of build
197  #---------------------------------------------------------------------
198  NBlogMessages.writeMessage( '  make test' )
199  result=NBosCommand.run('make test')
200     
201  # Check if 'make test' worked
202  didMakeTestFail=configuration['checkMakeTest'](result,configuration['project'],"make test")
203  if didMakeTestFail :
204    result['make test']=didMakeTestFail
205    NBemail.sendCmdMsgs(configuration['project'],result,"make test")
206    return
207
208  #---------------------------------------------------------------------
209  # Run unitTest if available and different from 'make test'
210  #---------------------------------------------------------------------
211  if "unitTest" in configuration :
212    unitTestRelPath=configuration['unitTest']['path']
213    unitTestPath = os.path.join(fullVpathDir,unitTestRelPath)
214    os.chdir(unitTestPath)
215
216    unitTestCmdTemplate=configuration['unitTest']['command']
217
218    dataBaseDir=os.path.join(configuration['rootDir'],'Data')
219    netlibDir=os.path.join(dataBaseDir,'Netlib')
220    miplib3Dir=os.path.join(dataBaseDir,'miplib3')
221
222    unitTestCmd=unitTestCmdTemplate.replace('_NETLIBDIR_',netlibDir)
223    unitTestCmd=unitTestCmd.replace('_MIPLIB3DIR_',miplib3Dir)
224
225    NBlogMessages.writeMessage( '  '+unitTestCmd )
226    result=NBosCommand.run(unitTestCmd)
227     
228    didUnitTestFail=configuration['unitTest']['checkUnitTest'](result,configuration['project'],unitTestCmdTemplate)
229    if didUnitTestFail :
230      result['unitTest']=didUnitTestFail
231      NBemail.sendCmdMsgs(p,result,unitTestCmd)
232      return
233
Note: See TracBrowser for help on using the repository browser.