source: branches/testScripts/nightlyBuildMod.py @ 652

Last change on this file since 652 was 641, checked in by kmartin, 12 years ago

add nightlyBuildMod.py that uses vpath builds

  • Property svn:executable set to *
File size: 10.4 KB
Line 
1#! /usr/bin/env python
2
3import os
4import sys
5import distutils.dir_util
6
7
8import NBuserConfig
9import NBprojectConfig
10import NBlogMessages
11import NBemail
12import NBosCommand
13import NBsvnCommand
14import NBcheckResult
15
16# TODO:
17#   -Get some information about the platform and put this in email failure message.
18#   -Implement Kipp's vpath (delete vpath instead of 'make distclean').
19#   -Don't do build if 'svn update' doesn't change anything and prior test was OK.
20#     (no need to re-run if nothing has changed since prior run)
21#   -Build both trunk and latest stable
22#   -Build both optimized and debug (or have a set of config-site scripts to test?)
23
24
25
26
27#------------------------------------------------------------------------
28#  Main Program Starts Here 
29#------------------------------------------------------------------------
30
31#------------------------------------------------------------------------
32#  If needed create the top level directory
33#------------------------------------------------------------------------
34if not os.path.isdir(NBuserConfig.NIGHTLY_BUILD_ROOT_DIR) :
35  os.makedirs(NBuserConfig.NIGHTLY_BUILD_ROOT_DIR)
36os.chdir(NBuserConfig.NIGHTLY_BUILD_ROOT_DIR)
37
38#------------------------------------------------------------------------
39#  Get the data directories if they don't already exist
40#------------------------------------------------------------------------
41dataBaseDir=os.path.join(NBuserConfig.NIGHTLY_BUILD_ROOT_DIR,'Data')
42if not os.path.isdir(dataBaseDir) :
43  os.makedirs(dataBaseDir)
44dataDirs=['Netlib','miplib3']
45for d in dataDirs :
46  dataDir=os.path.join(dataBaseDir,d)
47  if not os.path.isdir(dataDir) :
48    svnCmd=os.path.join(NBuserConfig.SVNPATH_PREFIX,'svn') + ' checkout https://projects.coin-or.org/svn/Data/releases/1.0.0/'+d+' '+d
49    if NBsvnCommand.run(svnCmd,dataBaseDir,'Data')!='OK' :
50      sys.exit(1)
51    result=NBosCommand.run('find '+d+' -name \*.gz -print | xargs gzip -d')
52netlibDir=os.path.join(dataBaseDir,'Netlib')
53miplib3Dir=os.path.join(dataBaseDir,'miplib3')
54
55#------------------------------------------------------------------------
56# Loop once for each project
57#------------------------------------------------------------------------
58for p in NBuserConfig.PROJECTS:
59  NBlogMessages.writeMessage( p )
60
61  #---------------------------------------------------------------------
62  # svn checkout or update the project
63  #---------------------------------------------------------------------
64  projectBaseDir=os.path.join(NBuserConfig.NIGHTLY_BUILD_ROOT_DIR,p)
65  projectCheckOutDir=os.path.join(projectBaseDir,'trunk')
66  if not os.path.isdir(projectBaseDir) :
67    os.makedirs(projectBaseDir)
68  if not os.path.isdir(projectCheckOutDir) :
69    svnCmd=os.path.join(NBuserConfig.SVNPATH_PREFIX,'svn') + ' checkout https://projects.coin-or.org/svn/'+p+'/trunk trunk'
70    if NBsvnCommand.run(svnCmd,projectBaseDir,p)!='OK' :
71      continue
72  else :
73    svnCmd=os.path.join(NBuserConfig.SVNPATH_PREFIX,'svn') + ' update'
74    if NBsvnCommand.run(svnCmd,projectCheckOutDir,p)!='OK' :
75      continue
76
77  #---------------------------------------------------------------------
78  # If there is are third part apps, then get these apps
79  #---------------------------------------------------------------------
80  if NBuserConfig.DOWNLOAD_3RD_PARTY :
81    thirdPartyBaseDir=os.path.join(projectCheckOutDir,'ThirdParty')
82    if os.path.isdir(thirdPartyBaseDir) :
83      thirdPartyDirs = os.listdir(thirdPartyBaseDir)
84      for d in thirdPartyDirs :
85        thirdPartyDir=os.path.join(thirdPartyBaseDir,d)
86        install3rdPartyCmd=os.path.join(".","get."+d)
87        os.chdir(thirdPartyDir)
88        if os.path.isfile(install3rdPartyCmd) :
89          NBlogMessages.writeMessage('  '+install3rdPartyCmd)
90          NBosCommand.run(install3rdPartyCmd)
91 
92  #---------------------------------------------------------------------
93  # Should probably run make 'distclean' to do a build from scrath
94  # or delete the VPATH directory when there is one
95  #---------------------------------------------------------------------
96
97
98  #---------------------------------------------------------------------
99  # Loop over each vpath directory
100  #---------------------------------------------------------------------
101  kount = 0
102  for v in NBuserConfig.VPATH_DIRS:
103    NBlogMessages.writeMessage( v )
104    #---------------------------------------------------------------------
105    # connect to the project directory
106    #---------------------------------------------------------------------
107    os.chdir( projectBaseDir)
108    vpathDir = os.path.join(projectBaseDir, v)
109    print vpathDir
110    #---------------------------------------------------------------------
111    # if the vpath directory is there, delete it and create a new one
112    # otherwise create it
113    #---------------------------------------------------------------------
114    if os.path.isdir( vpathDir) :
115      distutils.dir_util.remove_tree( vpathDir)
116      os.mkdir( vpathDir)
117    else :
118      os.mkdir( vpathDir)
119    #---------------------------------------------------------------------
120    # connect to the vpath directory
121    #---------------------------------------------------------------------
122    os.chdir( vpathDir)
123   
124    #---------------------------------------------------------------------
125    # run configure part of build
126    # first get the configure options
127    #---------------------------------------------------------------------
128
129    configCmd = os.path.join(projectCheckOutDir, NBuserConfig.VPATH_CONFIG_ARGS[ kount])
130    kount = kount + 1
131    if NBcheckResult.didConfigRunOK() :
132      NBlogMessages.writeMessage("  '"+configCmd+"' previously ran. Not rerunning")
133    else :
134      NBlogMessages.writeMessage('  '+configCmd)
135      result=NBosCommand.run(configCmd)
136   
137      # Check if configure worked
138      if result['returnCode'] != 0 :
139        error_msg = result
140        # Add contents of log file to message
141        logFileName = 'config.log'
142        if os.path.isfile(logFileName) :
143          logFilePtr = open(logFileName,'r')
144          error_msg['config.log']  = "config.log contains: \n" 
145          error_msg['config.log'] += logFilePtr.read()
146          logFilePtr.close()
147        NBemail.sendCmdMsgs(p,error_msg,configCmd)
148        continue
149    #---------------------------------------------------------------------
150    # Run make part of build
151    #---------------------------------------------------------------------
152    NBlogMessages.writeMessage( '  make' )
153    result=NBosCommand.run('make')
154   
155    # Check if make worked
156    if result['returnCode'] != 0 :
157      NBemail.sendCmdMsgs(p,result,'make')
158      continue
159
160    #---------------------------------------------------------------------
161    # Run 'make test' part of build
162    #---------------------------------------------------------------------
163    NBlogMessages.writeMessage( '  make test' )
164    result=NBosCommand.run('make test')
165   
166    # Check if 'make test' worked
167    if NBcheckResult.didTestFail(result,p,"make test") :
168      NBemail.sendCmdMsgs(p,result,"make test")
169      continue
170
171    #---------------------------------------------------------------------
172    # Run unitTest if available and different from 'make test'
173    #---------------------------------------------------------------------
174    if NBprojectConfig.UNITTEST_CMD.has_key(p) :
175      unitTestPath = os.path.join(projectCheckOutDir,NBprojectConfig.UNITTEST_DIR[p])
176      os.chdir(unitTestPath)
177
178      unitTestCmdTemplate=NBprojectConfig.UNITTEST_CMD[p]
179      unitTestCmd=unitTestCmdTemplate.replace('_NETLIBDIR_',netlibDir)
180      unitTestCmd=unitTestCmd.replace('_MIPLIB3DIR_',miplib3Dir)
181
182      NBlogMessages.writeMessage( '  '+unitTestCmd )
183      result=NBosCommand.run(unitTestCmd)
184   
185      if NBcheckResult.didTestFail(result,p,unitTestCmdTemplate) :
186        NBemail.sendCmdMsgs(p,result,unitTestCmd)
187        continue
188
189  # For testing purposes only do first successful project
190  #break
191
192NBlogMessages.writeMessage( "nightlyBuild.py Finished" )
193
194sys.exit(0)
195
196
197# START KIPP
198#----------------------------------------------------------------------
199# CONFIG FILE PATH:
200#   path to the config file for the build
201#   done. If the directory does not exist, it will be created.
202#   this should have all of the user specific data
203#   it should have values for
204#   NIGHTLY_BUILD_ROOT
205#   NBuserConfig.SMTP_SERVER_NAME
206#   NBuserConfig.SMTP_SERVER_PORT
207#   NBuserConfig.SMTP_SSL_SERVER
208#   NBuserConfig.SMTP_USER_NAME
209#   NBuserConfig.SMTP_PASSWORD_FILENAME = '/home/jp/bin/smtpPwFile'
210#   NBuserConfig.SENDER_EMAIL_ADDR='jpfasano _AT_ verizon _DOT_ net'
211#   NBuserConfig.MY_EMAIL_ADDR='jpfasano _AT_ us _DOT_ ibm _DOT_ com'
212#   
213#----------------------------------------------------------------------
214
215CONFIG_FILE_PATH = '/Users/kmartin/Documents/files/configDir/'
216CONFIG_FILENAME = 'config.txt'
217
218
219# Get configFile data
220
221configFile = os.path.join(os.path.dirname( CONFIG_FILE_PATH),
222                                 os.path.basename(CONFIG_FILENAME ))
223if os.path.isfile(  configFile) :
224  pwFilePtr = open(configFile ,'r')
225  d = pwFilePtr.readlines()
226  # do pwFilePtr.read() to get a string object
227  # we have a list object
228  print d[0]
229  print d[1]
230  # make a dictionary
231  config_dic = {}
232
233  #smtppass  = pwFilePtr.read().strip()
234  pwFilePtr.close()
235else :
236  #NBlogMessages.writeMessage( "Failure reading pwFileName=" + CONFIG_FILENAME )
237  #print cmdMsgs
238  sys.exit( 1)
239sys.exit( 0)
240
241
242
243# START KIPP
244#----------------------------------------------------------------------
245#   path to the config file for the build
246#   get the user dependent variables
247# CONFIG FILE PATH:
248#   it should have values for
249#   NIGHTLY_BUILD_ROOT
250#   NBuserConfig.SMTP_SERVER_NAME
251#   NBuserConfig.SMTP_SERVER_PORT
252#   NBuserConfig.SMTP_SSL_SERVER
253#   NBuserConfig.SMTP_USER_NAME
254#   NBuserConfig.SMTP_PASSWORD_FILENAME
255#   NBuserConfig.SENDER_EMAIL_ADDR
256#   NBuserConfig.MY_EMAIL_ADDR
257#   
258#----------------------------------------------------------------------
259
260CONFIG_FILE_PATH = '/Users/kmartin/Documents/files/configDir/'
261CONFIG_FILENAME = 'config.txt'
262
263
264# Get configFile data
265
266configFile = os.path.join(os.path.dirname( CONFIG_FILE_PATH),
267                                 os.path.basename(CONFIG_FILENAME ))
268if os.path.isfile(  configFile) :
269  pwFilePtr = open(configFile ,'r')
270  d = pwFilePtr.readlines()
271  # do pwFilePtr.read() to get a string object
272  # we have a list object
273  print d[0]
274  print d[1]
275  # make a dictionary
276  config_dic = {}
277
278  #smtppass  = pwFilePtr.read().strip()
279  pwFilePtr.close()
280else :
281  #NBlogMessages.writeMessage( "Failure reading pwFileName=" + CONFIG_FILENAME )
282  #print cmdMsgs
283  sys.exit( 1)
284sys.exit( 0)
285
286# END KIPP
Note: See TracBrowser for help on using the repository browser.