source: branches/testScripts/NBbuildConfig.py @ 674

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

Tried to create a nicer vpath directory name.
Added log message to indicate current directory.

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