2015-06-11 11:51:10 -05:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# -*- mode:Python -*-
|
|
|
|
#
|
|
|
|
# This file is part of the Coriolis Software.
|
2018-01-06 10:55:44 -06:00
|
|
|
# Copyright (c) UPMC 2015-2018, All Rights Reserved
|
2015-06-11 11:51:10 -05:00
|
|
|
#
|
|
|
|
# +-----------------------------------------------------------------+
|
|
|
|
# | C O R I O L I S |
|
2019-05-26 08:41:24 -05:00
|
|
|
# | C o r i o l i s I n s t a l l e r |
|
2015-06-11 11:51:10 -05:00
|
|
|
# | |
|
|
|
|
# | Authors : Jean-Paul Chaput |
|
|
|
|
# | E-mail : Jean-Paul.Chaput@asim.lip6.fr |
|
|
|
|
# | =============================================================== |
|
|
|
|
# | Python : "./socInstaller.py" |
|
|
|
|
# +-----------------------------------------------------------------+
|
|
|
|
#
|
|
|
|
# WARNING:
|
|
|
|
# This script has been designed only for internal use in the
|
2019-05-26 08:41:24 -05:00
|
|
|
# LIP6/CIAN department. If you want to use it you will need to
|
2015-06-11 11:51:10 -05:00
|
|
|
# change the hardwired configuration.
|
|
|
|
|
|
|
|
|
|
|
|
showTrace = True
|
|
|
|
|
|
|
|
try:
|
|
|
|
import sys
|
|
|
|
import os.path
|
|
|
|
import shutil
|
|
|
|
import optparse
|
|
|
|
import time
|
|
|
|
import traceback
|
|
|
|
import distutils.sysconfig
|
|
|
|
import subprocess
|
2015-06-14 09:23:11 -05:00
|
|
|
import socket
|
2015-06-11 11:51:10 -05:00
|
|
|
import re
|
2016-11-10 06:46:45 -06:00
|
|
|
import bz2
|
2015-06-11 11:51:10 -05:00
|
|
|
import smtplib
|
|
|
|
from email.mime.text import MIMEText
|
|
|
|
from email.mime.multipart import MIMEMultipart
|
|
|
|
from email.mime.application import MIMEApplication
|
|
|
|
except ImportError, e:
|
|
|
|
module = str(e).split()[-1]
|
|
|
|
|
|
|
|
|
|
|
|
class ErrorMessage ( Exception ):
|
|
|
|
|
|
|
|
def __init__ ( self, code, *arguments ):
|
2020-02-09 04:45:04 -06:00
|
|
|
self._code = code
|
|
|
|
self._errors = [ 'Malformed call to ErrorMessage()', '%s' % str(arguments) ]
|
|
|
|
|
|
|
|
text = None
|
|
|
|
if len(arguments) == 1:
|
|
|
|
if isinstance(arguments[0],Exception): text = str(arguments[0]).split('\n')
|
2015-06-11 11:51:10 -05:00
|
|
|
else:
|
2020-02-09 04:45:04 -06:00
|
|
|
self._errors = arguments[0]
|
|
|
|
elif len(arguments) > 1:
|
|
|
|
text = list(arguments)
|
|
|
|
|
|
|
|
if text:
|
|
|
|
self._errors = []
|
|
|
|
while len(text[0]) == 0: del text[0]
|
|
|
|
|
|
|
|
lstrip = 0
|
|
|
|
if text[0].startswith('[ERROR]'): lstrip = 8
|
|
|
|
|
|
|
|
for line in text:
|
|
|
|
if line[0:lstrip ] == ' '*lstrip or \
|
|
|
|
line[0:lstrip-1] == '[ERROR]':
|
|
|
|
self._errors += [ line[lstrip:] ]
|
|
|
|
else:
|
|
|
|
self._errors += [ line.lstrip() ]
|
|
|
|
return
|
2015-06-11 11:51:10 -05:00
|
|
|
|
|
|
|
def __str__ ( self ):
|
|
|
|
if not isinstance(self._errors,list):
|
|
|
|
return "[ERROR] %s" % self._errors
|
|
|
|
|
|
|
|
formatted = "\n"
|
|
|
|
for i in range(len(self._errors)):
|
|
|
|
if i == 0: formatted += "[ERROR] %s" % self._errors[i]
|
|
|
|
else: formatted += " %s" % self._errors[i]
|
|
|
|
if i+1 < len(self._errors): formatted += "\n"
|
|
|
|
return formatted
|
|
|
|
|
|
|
|
def addMessage ( self, message ):
|
|
|
|
if not isinstance(self._errors,list):
|
|
|
|
self._errors = [ self._errors ]
|
|
|
|
if isinstance(message,list):
|
|
|
|
for line in message:
|
|
|
|
self._errors += [ line ]
|
|
|
|
else:
|
|
|
|
self._errors += [ message ]
|
|
|
|
return
|
|
|
|
|
|
|
|
def terminate ( self ):
|
|
|
|
print self
|
|
|
|
sys.exit(self._code)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def code ( self ): return self._code
|
|
|
|
|
|
|
|
|
|
|
|
class BadBinary ( ErrorMessage ):
|
|
|
|
|
|
|
|
def __init__ ( self, binary ):
|
2020-02-09 04:45:04 -06:00
|
|
|
ErrorMessage.__init__( self, 1, "Binary not found: <%s>." % binary )
|
|
|
|
return
|
2015-06-11 11:51:10 -05:00
|
|
|
|
|
|
|
|
|
|
|
class BadReturnCode ( ErrorMessage ):
|
|
|
|
|
|
|
|
def __init__ ( self, status ):
|
2020-02-09 04:45:04 -06:00
|
|
|
ErrorMessage.__init__( self, 1, "Command returned status:%d." % status )
|
|
|
|
return
|
2015-06-11 11:51:10 -05:00
|
|
|
|
|
|
|
|
|
|
|
class Command ( object ):
|
|
|
|
|
|
|
|
def __init__ ( self, arguments, fdLog=None ):
|
2020-02-09 04:45:04 -06:00
|
|
|
self.arguments = arguments
|
|
|
|
self.fdLog = fdLog
|
|
|
|
|
|
|
|
if self.fdLog != None and not isinstance(self.fdLog,file):
|
|
|
|
print '[WARNING] Command.__init__(): <fdLog> is neither None or a file.'
|
|
|
|
return
|
2015-06-11 11:51:10 -05:00
|
|
|
|
2016-08-01 06:21:18 -05:00
|
|
|
def _argumentsToStr ( self, arguments ):
|
2020-02-09 04:45:04 -06:00
|
|
|
s = ''
|
|
|
|
for argument in arguments:
|
|
|
|
if argument.find(' ') >= 0: s += ' "' + argument + '"'
|
|
|
|
else: s += ' ' + argument
|
|
|
|
return s
|
2016-08-01 06:21:18 -05:00
|
|
|
|
|
|
|
def log ( self, text ):
|
2020-02-09 04:45:04 -06:00
|
|
|
print text[:-1]
|
|
|
|
sys.stdout.flush()
|
|
|
|
sys.stderr.flush()
|
|
|
|
if isinstance(self.fdLog,file):
|
|
|
|
self.fdLog.write( text )
|
|
|
|
self.fdLog.flush()
|
|
|
|
return
|
2016-08-01 06:21:18 -05:00
|
|
|
|
2015-06-11 11:51:10 -05:00
|
|
|
def execute ( self ):
|
2020-02-09 04:45:04 -06:00
|
|
|
global conf
|
|
|
|
sys.stdout.flush()
|
|
|
|
sys.stderr.flush()
|
|
|
|
|
|
|
|
homeDir = os.environ['HOME']
|
|
|
|
workDir = os.getcwd()
|
|
|
|
if homeDir.startswith(homeDir):
|
|
|
|
workDir = '~' + workDir[ len(homeDir) : ]
|
|
|
|
user = 'root'
|
|
|
|
if os.environ.has_key('USER'): user = os.environ['USER']
|
|
|
|
prompt = '%s@%s:%s$' % (user,conf.masterHost,workDir)
|
|
|
|
|
|
|
|
try:
|
|
|
|
self.log( '%s%s\n' % (prompt,self._argumentsToStr(self.arguments)) )
|
|
|
|
print self.arguments
|
|
|
|
child = subprocess.Popen( self.arguments, stdout=subprocess.PIPE, stderr=subprocess.STDOUT )
|
|
|
|
|
|
|
|
while True:
|
|
|
|
line = child.stdout.readline()
|
|
|
|
if not line: break
|
|
|
|
|
|
|
|
self.log( line )
|
|
|
|
except OSError, e:
|
|
|
|
raise BadBinary( self.arguments[0] )
|
|
|
|
|
|
|
|
(pid,status) = os.waitpid( child.pid, 0 )
|
|
|
|
status >>= 8
|
|
|
|
if status != 0:
|
|
|
|
raise BadReturnCode( status )
|
|
|
|
|
|
|
|
return
|
2015-06-11 11:51:10 -05:00
|
|
|
|
2016-08-01 06:21:18 -05:00
|
|
|
|
2020-02-09 04:45:04 -06:00
|
|
|
class CommandArg ( object ):
|
|
|
|
|
|
|
|
def __init__ ( self, command, wd=None, host=None, fdLog=None ):
|
|
|
|
self.command = command
|
|
|
|
self.host = host
|
|
|
|
self.wd = wd
|
|
|
|
self.fdLog = fdLog
|
|
|
|
return
|
|
|
|
|
|
|
|
def __str__ ( self ):
|
|
|
|
s = ''
|
|
|
|
if self.wd: s = 'cd %s && ' % self.wd
|
|
|
|
|
|
|
|
for i in range(len(self.command)):
|
|
|
|
if i: s += ' '
|
|
|
|
s += self.command[i]
|
|
|
|
return s
|
|
|
|
|
|
|
|
def getArgs ( self ):
|
|
|
|
if not self.host: return self.command
|
|
|
|
return [ 'ssh', self.host, str(self) ]
|
|
|
|
|
|
|
|
def execute ( self ):
|
|
|
|
if not self.host and self.wd: os.chdir( self.wd )
|
|
|
|
Command( self.getArgs(), self.fdLog ).execute()
|
|
|
|
return
|
|
|
|
|
|
|
|
|
2020-03-20 09:07:41 -05:00
|
|
|
class YosysCommand ( CommandArg ):
|
|
|
|
|
|
|
|
def __init__ ( self, yosysBin, fdLog=None ):
|
|
|
|
CommandArg.__init__ ( self, [ yosysBin ], fdLog=fdLog )
|
|
|
|
return
|
|
|
|
|
|
|
|
|
2020-02-09 04:45:04 -06:00
|
|
|
class AllianceCommand ( CommandArg ):
|
|
|
|
|
2020-02-19 17:45:52 -06:00
|
|
|
def __init__ ( self, alcBin, fdLog=None ):
|
|
|
|
CommandArg.__init__ ( self, [ alcBin ], fdLog=fdLog )
|
2020-02-09 04:45:04 -06:00
|
|
|
return
|
2015-06-11 11:51:10 -05:00
|
|
|
|
|
|
|
|
2020-02-09 04:45:04 -06:00
|
|
|
class CoriolisCommand ( CommandArg ):
|
2015-06-11 11:51:10 -05:00
|
|
|
|
2020-02-09 04:45:04 -06:00
|
|
|
def __init__ ( self, ccbBin, rootDir, threads=1, otherArgs=[], fdLog=None ):
|
|
|
|
CommandArg.__init__ ( self, [ ccbBin
|
|
|
|
, '--root='+rootDir
|
|
|
|
, '--project=coriolis'
|
|
|
|
, '--make=-j%d install' % threads
|
|
|
|
] + otherArgs
|
|
|
|
, fdLog=fdLog )
|
|
|
|
return
|
2015-06-11 11:51:10 -05:00
|
|
|
|
2020-02-09 04:45:04 -06:00
|
|
|
|
|
|
|
class BenchsCommand ( CommandArg ):
|
|
|
|
|
|
|
|
def __init__ ( self, benchsDir, fdLog=None ):
|
|
|
|
CommandArg.__init__ ( self, [ '../bin/go.sh' ], wd=benchsDir, fdLog=fdLog )
|
|
|
|
return
|
|
|
|
|
2015-06-11 11:51:10 -05:00
|
|
|
|
|
|
|
|
|
|
|
class GitRepository ( object ):
|
|
|
|
|
|
|
|
@staticmethod
|
Handling of Cell destruction in CellViewer.
* Change: In bootstrap, in socInstaler.sh, use the current version of
rapidjson.
* Change: In Hurricane, in FileWriteGzStream, complie to the latest
rapidjson headers organization.
* New: In Hurricane, in Cell, emit a new signal CellDestroyed toward the
observers (i.e. the CellViewer(s)), from _preDestroy().
* Change: In Hurricane, in CellViewer, in CellObserver::notify(), manage
the CellDestroyed case. Do not forget to remove the deleted Cell
from the viewer's history.
2016-02-23 03:48:26 -06:00
|
|
|
def getLocalRepository ( url ):
|
2020-02-09 04:45:04 -06:00
|
|
|
localRepo = url.split( '/' )[-1]
|
|
|
|
if localRepo.endswith('.git'):
|
|
|
|
localRepo = localRepo[:-4]
|
|
|
|
return localRepo
|
2015-06-11 11:51:10 -05:00
|
|
|
|
2016-08-01 06:21:18 -05:00
|
|
|
def __init__ ( self, url, cloneDir, fdLog=None ):
|
2020-02-09 04:45:04 -06:00
|
|
|
self.url = url
|
|
|
|
self.cloneDir = cloneDir
|
|
|
|
self.localRepo = GitRepository.getLocalRepository( url )
|
|
|
|
self.fdLog = fdLog
|
|
|
|
return
|
2015-06-11 11:51:10 -05:00
|
|
|
|
|
|
|
@property
|
|
|
|
def localRepoDir ( self ): return self.cloneDir+'/'+self.localRepo
|
|
|
|
|
|
|
|
def removeLocalRepo ( self ):
|
2020-02-09 04:45:04 -06:00
|
|
|
if os.path.isdir(self.localRepoDir):
|
|
|
|
print 'Removing Git local repository: <%s>' % self.localRepoDir
|
|
|
|
shutil.rmtree( self.localRepoDir )
|
|
|
|
return
|
2015-06-11 11:51:10 -05:00
|
|
|
|
|
|
|
def clone ( self ):
|
2020-02-09 04:45:04 -06:00
|
|
|
print 'Clone/pull from:', self.url
|
|
|
|
if not os.path.isdir(self.cloneDir):
|
|
|
|
os.makedirs( self.cloneDir )
|
|
|
|
|
|
|
|
if not os.path.isdir(self.localRepoDir):
|
|
|
|
os.chdir( self.cloneDir )
|
|
|
|
Command( [ 'git', 'clone', self.url ], self.fdLog ).execute()
|
|
|
|
else:
|
|
|
|
os.chdir( self.localRepoDir )
|
|
|
|
Command( [ 'git', 'pull' ], self.fdLog ).execute()
|
|
|
|
return
|
2015-06-11 11:51:10 -05:00
|
|
|
|
|
|
|
def checkout ( self, branch ):
|
2020-02-09 04:45:04 -06:00
|
|
|
os.chdir( self.localRepoDir )
|
|
|
|
Command( [ 'git', 'checkout', branch ], self.fdLog ).execute()
|
|
|
|
return
|
2015-06-11 11:51:10 -05:00
|
|
|
|
|
|
|
|
2015-06-18 07:54:45 -05:00
|
|
|
class Configuration ( object ):
|
|
|
|
|
|
|
|
PrimaryNames = \
|
2016-02-21 04:58:54 -06:00
|
|
|
[ 'sender' , 'receivers'
|
2020-02-09 04:45:04 -06:00
|
|
|
, 'coriolisRepo', 'benchsRepo' , 'supportRepos'
|
2015-06-18 07:54:45 -05:00
|
|
|
, 'homeDir' , 'masterHost'
|
2020-02-19 17:45:52 -06:00
|
|
|
, 'debugArg' , 'nightlyMode', 'dockerMode', 'chrootMode'
|
2020-02-09 04:45:04 -06:00
|
|
|
, 'rmSource' , 'rmBuild'
|
|
|
|
, 'doGit' , 'doAlliance' , 'doCoriolis', 'doBenchs', 'doSendReport'
|
2015-06-18 07:54:45 -05:00
|
|
|
, 'success' , 'rcode'
|
|
|
|
]
|
|
|
|
SecondaryNames = \
|
2020-03-20 09:07:41 -05:00
|
|
|
[ 'rootDir', 'srcDir', 'logDir', 'logs', 'fds', 'yosysBin', 'alcBin', 'ccbBin', 'benchsDir'
|
2015-06-18 07:54:45 -05:00
|
|
|
]
|
|
|
|
|
|
|
|
def __init__ ( self ):
|
2020-02-09 04:45:04 -06:00
|
|
|
self._sender = 'Jean-Paul.Chaput@soc.lip6.fr'
|
|
|
|
self._receivers = [ 'Jean-Paul.Chaput@lip6.fr', ]
|
|
|
|
self._supportRepos = [ 'http://github.com/miloyip/rapidjson' ]
|
|
|
|
self._allianceRepo = 'https://gitlab.lip6.fr/jpc/alliance.git'
|
|
|
|
self._coriolisRepo = 'https://gitlab.lip6.fr/jpc/coriolis.git'
|
|
|
|
self._benchsRepo = 'https://gitlab.lip6.fr/jpc/alliance-check-toolkit.git'
|
|
|
|
self._homeDir = os.environ['HOME']
|
|
|
|
self._debugArg = ''
|
|
|
|
self._rmSource = False
|
|
|
|
self._rmBuild = False
|
|
|
|
self._doGit = True
|
2020-03-20 09:07:41 -05:00
|
|
|
self._doYosys = False
|
2020-02-09 04:45:04 -06:00
|
|
|
self._doAlliance = False
|
2020-03-20 09:07:41 -05:00
|
|
|
self._doCoriolis = False
|
2020-02-09 04:45:04 -06:00
|
|
|
self._doBenchs = False
|
|
|
|
self._doSendReport = False
|
|
|
|
self._nightlyMode = False
|
|
|
|
self._dockerMode = False
|
2020-02-19 17:45:52 -06:00
|
|
|
self._chrootMode = None
|
2020-02-09 04:45:04 -06:00
|
|
|
self._logs = { 'alliance':None, 'coriolis':None, 'benchs':None }
|
|
|
|
self._fds = { 'alliance':None, 'coriolis':None, 'benchs':None }
|
|
|
|
self._ccbBin = None
|
|
|
|
self._benchsDir = None
|
|
|
|
self._masterHost = self._detectMasterHost()
|
|
|
|
self._success = False
|
|
|
|
self._rcode = 0
|
|
|
|
|
|
|
|
self._updateSecondaries()
|
2015-06-18 07:54:45 -05:00
|
|
|
return
|
|
|
|
|
2020-02-09 04:45:04 -06:00
|
|
|
def __setattr__ ( self, attribute, value ):
|
|
|
|
if attribute in Configuration.SecondaryNames:
|
|
|
|
print ErrorMessage( 1, 'Attempt to write in read-only attribute <%s> in Configuration.'%attribute )
|
|
|
|
return
|
|
|
|
|
|
|
|
if attribute == 'masterHost' or attribute == '_masterHost':
|
|
|
|
if value == 'lepka':
|
|
|
|
print 'Never touch the Git tree when running on <lepka>.'
|
|
|
|
self._rmSource = False
|
|
|
|
self._rmBuild = False
|
|
|
|
self._doGit = False
|
|
|
|
self._doSendReport = False
|
|
|
|
|
|
|
|
if attribute[0] == '_':
|
|
|
|
self.__dict__[attribute] = value
|
|
|
|
return
|
|
|
|
|
|
|
|
if attribute == 'homeDir': value = os.path.expanduser(value)
|
|
|
|
|
|
|
|
self.__dict__['_'+attribute] = value
|
|
|
|
self._updateSecondaries()
|
2015-06-18 07:54:45 -05:00
|
|
|
return
|
|
|
|
|
|
|
|
def __getattr__ ( self, attribute ):
|
2020-02-09 04:45:04 -06:00
|
|
|
if attribute[0] != '_': attribute = '_'+attribute
|
|
|
|
if not self.__dict__.has_key(attribute):
|
|
|
|
raise ErrorMessage( 1, 'Configuration has no attribute <%s>.'%attribute )
|
|
|
|
return self.__dict__[attribute]
|
2015-06-18 07:54:45 -05:00
|
|
|
|
|
|
|
def _updateSecondaries ( self ):
|
2020-02-09 04:45:04 -06:00
|
|
|
if self._nightlyMode:
|
|
|
|
self._rootDir = self._homeDir + '/nightly/coriolis-2.x'
|
|
|
|
else:
|
2020-02-19 17:45:52 -06:00
|
|
|
self._rootDir = self._homeDir + '/coriolis-2.x'
|
|
|
|
self._srcDir = self._rootDir + '/src'
|
|
|
|
self._logDir = self._srcDir + '/logs'
|
2020-03-20 09:07:41 -05:00
|
|
|
self._yosysBin = self._srcDir + '/' + GitRepository.getLocalRepository(self._coriolisRepo) + '/bootstrap/yosysInstaller.sh'
|
2020-02-19 17:45:52 -06:00
|
|
|
self._alcBin = self._srcDir + '/' + GitRepository.getLocalRepository(self._coriolisRepo) + '/bootstrap/allianceInstaller.sh'
|
|
|
|
self._ccbBin = self._srcDir + '/' + GitRepository.getLocalRepository(self._coriolisRepo) + '/bootstrap/ccb.py'
|
|
|
|
self._benchsDir = self._srcDir + '/' + GitRepository.getLocalRepository(self._benchsRepo ) + '/benchs'
|
|
|
|
self._masterHost = self._detectMasterHost()
|
2020-02-09 04:45:04 -06:00
|
|
|
return
|
2015-06-18 07:54:45 -05:00
|
|
|
|
|
|
|
def _detectMasterHost ( self ):
|
2020-02-19 17:45:52 -06:00
|
|
|
if self._chrootMode is None: return 'unknown'
|
|
|
|
if self._chrootMode: return 'chrooted-host'
|
|
|
|
|
2020-02-09 04:45:04 -06:00
|
|
|
masterHost = 'unknown'
|
|
|
|
hostname = socket.gethostname()
|
|
|
|
hostAddr = socket.gethostbyname(hostname)
|
|
|
|
|
|
|
|
if hostname == 'lepka' and hostAddr == '127.0.0.1':
|
|
|
|
masterHost = 'lepka'
|
|
|
|
else:
|
|
|
|
masterHost = hostname.split('.')[0]
|
|
|
|
return masterHost
|
2015-06-18 07:54:45 -05:00
|
|
|
|
|
|
|
def openLog ( self, stem ):
|
2020-02-09 04:45:04 -06:00
|
|
|
if not os.path.isdir(self._logDir):
|
|
|
|
os.makedirs( self._logDir )
|
|
|
|
|
|
|
|
index = 0
|
|
|
|
timeTag = time.strftime( "%Y.%m.%d" )
|
|
|
|
while True:
|
|
|
|
logFile = os.path.join(self._logDir,"%s-%s-%02d.log" % (stem,timeTag,index))
|
|
|
|
if not os.path.isfile(logFile):
|
|
|
|
print "Report log: <%s>" % logFile
|
|
|
|
break
|
|
|
|
index += 1
|
|
|
|
fd = open( logFile, "w" )
|
|
|
|
self._logs[stem] = logFile
|
|
|
|
self._fds [stem] = fd
|
|
|
|
return
|
2015-06-18 07:54:45 -05:00
|
|
|
|
|
|
|
def closeLogs ( self ):
|
2020-02-09 04:45:04 -06:00
|
|
|
for fd in self._fds.values():
|
|
|
|
if fd: fd.close()
|
|
|
|
return
|
2015-06-18 07:54:45 -05:00
|
|
|
|
2016-11-10 06:46:45 -06:00
|
|
|
def compressLogs ( self ):
|
2020-02-09 04:45:04 -06:00
|
|
|
for log in self._logs.values():
|
|
|
|
if not log: continue
|
|
|
|
|
|
|
|
fd = open( log, 'r' )
|
|
|
|
bzfd = bz2.BZ2File( log+'.bz2', 'w' )
|
|
|
|
|
|
|
|
for line in fd.readlines(): bzfd.write( line )
|
|
|
|
|
|
|
|
bzfd.close()
|
|
|
|
fd.close()
|
|
|
|
|
|
|
|
os.unlink( log )
|
|
|
|
return
|
2016-11-10 06:46:45 -06:00
|
|
|
|
2020-02-09 04:45:04 -06:00
|
|
|
def getCommands ( self, target ):
|
|
|
|
commands = []
|
|
|
|
|
2020-03-20 09:07:41 -05:00
|
|
|
if self.doYosys:
|
|
|
|
if not os.path.isfile( self.yosysBin ):
|
|
|
|
raise ErrorMessage( 1, [ 'Cannot find <yosysInstaller.sh>, should be here:'
|
|
|
|
, ' <%s>' % self.yosysBin
|
|
|
|
] )
|
|
|
|
commands.append( YosysCommand( self.yosysBin, fdLog=self.fds['yosys'] ) )
|
|
|
|
|
2020-02-09 04:45:04 -06:00
|
|
|
if self.doAlliance:
|
2020-02-19 17:45:52 -06:00
|
|
|
if not os.path.isfile( self.alcBin ):
|
|
|
|
raise ErrorMessage( 1, [ 'Cannot find <allianceInstaller.sh>, should be here:'
|
|
|
|
, ' <%s>' % self.alcBin
|
|
|
|
] )
|
|
|
|
commands.append( AllianceCommand( self.alcBin, fdLog=self.fds['alliance'] ) )
|
2020-02-09 04:45:04 -06:00
|
|
|
|
|
|
|
if self.doCoriolis:
|
|
|
|
if not os.path.isfile( self.ccbBin ):
|
|
|
|
raise ErrorMessage( 1, [ 'Cannot find <ccb.py>, should be here:'
|
|
|
|
, ' <%s>' % self.ccbBin
|
|
|
|
] )
|
|
|
|
|
|
|
|
otherArgs = []
|
|
|
|
if self.debugArg: otherArgs.append( self.debugArg )
|
|
|
|
|
|
|
|
if target == 'SL7_64':
|
|
|
|
otherArgs.append( '--project=support' )
|
|
|
|
commands.append( CoriolisCommand( self.ccbBin, self.rootDir, 3, otherArgs , fdLog=self.fds['coriolis'] ) )
|
|
|
|
commands.append( CoriolisCommand( self.ccbBin, self.rootDir, 1, otherArgs+['--doc'], fdLog=self.fds['coriolis'] ) )
|
|
|
|
elif target == 'SL6_64' or target == 'SL6':
|
|
|
|
otherArgs.append( '--project=support' )
|
|
|
|
otherArgs.append( '--devtoolset=8' )
|
|
|
|
commands.append( CoriolisCommand( self.ccbBin, self.rootDir, 6, otherArgs , fdLog=self.fds['coriolis'] ) )
|
|
|
|
commands.append( CoriolisCommand( self.ccbBin, self.rootDir, 1, otherArgs+['--doc'], fdLog=self.fds['coriolis'] ) )
|
2020-03-19 12:18:35 -05:00
|
|
|
elif target == 'Ubuntu18' or target == 'Debian9' or target == 'Debian10':
|
2020-02-09 11:18:42 -06:00
|
|
|
if target == 'Ubuntu18': otherArgs.append( '--qt5' )
|
|
|
|
commands.append( CoriolisCommand( self.ccbBin, self.rootDir, 3, otherArgs, fdLog=self.fds['coriolis'] ) )
|
2020-02-19 17:45:52 -06:00
|
|
|
|
|
|
|
if self.doBenchs:
|
|
|
|
commands.append( BenchsCommand( self.benchsDir, fdLog=self.fds['benchs'] ) )
|
2020-02-09 04:45:04 -06:00
|
|
|
return commands
|
2016-11-10 06:46:45 -06:00
|
|
|
|
2015-06-18 07:54:45 -05:00
|
|
|
|
|
|
|
class Report ( object ):
|
|
|
|
|
|
|
|
def __init__ ( self, conf ):
|
2020-02-09 04:45:04 -06:00
|
|
|
self.conf = conf
|
|
|
|
|
|
|
|
commaspace = ', '
|
|
|
|
date = time.strftime( "%A %d %B %Y" )
|
|
|
|
stateText = 'FAILED'
|
|
|
|
modeText = 'SoC installation'
|
|
|
|
if self.conf.success: stateText = 'SUCCESS'
|
|
|
|
if self.conf.nightlyMode: modeText = 'Nightly build'
|
|
|
|
|
|
|
|
self.message = MIMEMultipart()
|
|
|
|
self.message['Subject'] = '[%s] Coriolis %s %s' % (stateText,modeText,date)
|
|
|
|
self.message['From' ] = self.conf.sender
|
|
|
|
self.message['To' ] = commaspace.join( self.conf.receivers )
|
|
|
|
self.attachements = []
|
|
|
|
|
|
|
|
self.mainText = '\n'
|
|
|
|
self.mainText += 'Salut le Crevard,\n'
|
|
|
|
self.mainText += '\n'
|
|
|
|
if self.conf.nightlyMode:
|
|
|
|
self.mainText += 'This is the nightly build report of Coriolis.\n'
|
|
|
|
else:
|
|
|
|
self.mainText += 'SoC installer report of Coriolis.\n'
|
|
|
|
self.mainText += '%s\n' % date
|
|
|
|
self.mainText += '\n'
|
|
|
|
if self.conf.success:
|
|
|
|
self.mainText += 'Build was SUCCESSFUL\n'
|
|
|
|
else:
|
|
|
|
self.mainText += 'Build has FAILED, please have a look to the attached log file(s).\n'
|
|
|
|
self.mainText += '\n'
|
|
|
|
self.mainText += 'Complete log file(s) can be found here:\n'
|
|
|
|
return
|
2015-06-18 07:54:45 -05:00
|
|
|
|
|
|
|
def attachLog ( self, logFile ):
|
2020-02-09 04:45:04 -06:00
|
|
|
if not logFile: return
|
|
|
|
|
|
|
|
fd = open( logFile, 'rb' )
|
|
|
|
try:
|
|
|
|
fd.seek( -1024*100, os.SEEK_END )
|
|
|
|
except IOError, e:
|
|
|
|
pass
|
|
|
|
tailLines = ''
|
|
|
|
for line in fd.readlines()[1:]:
|
|
|
|
tailLines += line
|
|
|
|
fd.close()
|
|
|
|
self.mainText += ' <%s>\n' % logFile
|
|
|
|
|
|
|
|
attachement = MIMEApplication(tailLines)
|
|
|
|
attachement.add_header( 'Content-Disposition', 'attachment', filename=os.path.basename(logFile) )
|
|
|
|
|
|
|
|
self.attachements.append( attachement )
|
|
|
|
return
|
2015-06-14 09:23:11 -05:00
|
|
|
|
2015-06-18 07:54:45 -05:00
|
|
|
def send ( self ):
|
2020-02-09 04:45:04 -06:00
|
|
|
self.message.attach( MIMEText(self.mainText) )
|
|
|
|
for attachement in self.attachements:
|
|
|
|
self.message.attach( attachement )
|
|
|
|
|
|
|
|
print "Sending mail report to:"
|
|
|
|
for receiver in self.conf.receivers: print ' <%s>' % receiver
|
|
|
|
session = smtplib.SMTP( 'localhost' )
|
|
|
|
session.sendmail( self.conf.sender, self.conf.receivers, self.message.as_string() )
|
|
|
|
session.quit()
|
|
|
|
return
|
2015-06-14 09:23:11 -05:00
|
|
|
|
|
|
|
|
2015-06-11 11:51:10 -05:00
|
|
|
# -------------------------------------------------------------------
|
|
|
|
# <socInstaller> Main Part.
|
|
|
|
|
|
|
|
|
|
|
|
parser = optparse.OptionParser ()
|
2015-06-11 16:48:57 -05:00
|
|
|
parser.add_option ( "--debug" , action="store_true" , dest="debug" , help="Build a <Debug> aka (-g) version." )
|
2015-06-14 09:23:11 -05:00
|
|
|
parser.add_option ( "--no-git" , action="store_true" , dest="noGit" , help="Do not pull/update Git repositories before building." )
|
2020-03-20 09:07:41 -05:00
|
|
|
parser.add_option ( "--do-yosys" , action="store_true" , dest="doYosys" , help="Rebuild Yosys." )
|
2020-02-09 04:45:04 -06:00
|
|
|
parser.add_option ( "--do-alliance" , action="store_true" , dest="doAlliance" , help="Rebuild the Alliance tools." )
|
|
|
|
parser.add_option ( "--do-coriolis" , action="store_true" , dest="doCoriolis" , help="Rebuild the Coriolis tools." )
|
|
|
|
parser.add_option ( "--do-report" , action="store_true" , dest="doReport" , help="Send a final report." )
|
2015-06-11 16:48:57 -05:00
|
|
|
parser.add_option ( "--nightly" , action="store_true" , dest="nightly" , help="Perform a nighly build." )
|
2020-02-09 04:45:04 -06:00
|
|
|
parser.add_option ( "--docker" , action="store_true" , dest="docker" , help="Perform a build inside a docker container." )
|
2020-02-19 17:45:52 -06:00
|
|
|
parser.add_option ( "--chroot" , action="store_true" , dest="chroot" , help="Perform a build inside a chrooted environment." )
|
2015-06-14 09:23:11 -05:00
|
|
|
parser.add_option ( "--benchs" , action="store_true" , dest="benchs" , help="Run the <alliance-checker-toolkit> sanity benchs." )
|
2015-06-11 16:48:57 -05:00
|
|
|
parser.add_option ( "--rm-build" , action="store_true" , dest="rmBuild" , help="Remove the build/install directories." )
|
|
|
|
parser.add_option ( "--rm-source" , action="store_true" , dest="rmSource" , help="Remove the Git source repositories." )
|
|
|
|
parser.add_option ( "--rm-all" , action="store_true" , dest="rmAll" , help="Remove everything (source+build+install)." )
|
|
|
|
parser.add_option ( "--root" , action="store" , type="string", dest="rootDir" , help="The root directory (default: <~/coriolis-2.x/>)." )
|
2020-02-09 04:45:04 -06:00
|
|
|
parser.add_option ( "--profile" , action="store" , type="string", dest="profile" , help="The targeted OS for the build." )
|
2015-06-11 11:51:10 -05:00
|
|
|
(options, args) = parser.parse_args ()
|
|
|
|
|
2020-02-19 17:45:52 -06:00
|
|
|
|
2015-06-18 07:54:45 -05:00
|
|
|
conf = Configuration()
|
2015-06-11 11:51:10 -05:00
|
|
|
|
|
|
|
try:
|
2015-06-18 07:54:45 -05:00
|
|
|
if options.debug: conf.debugArg = '--debug'
|
|
|
|
if options.nightly: conf.nightlyMode = True
|
2020-02-09 04:45:04 -06:00
|
|
|
if options.docker: conf.dockerMode = True
|
2020-02-19 17:45:52 -06:00
|
|
|
if options.chroot: conf.chrootMode = True
|
2015-06-18 07:54:45 -05:00
|
|
|
if options.noGit: conf.doGit = False
|
2020-03-20 09:07:41 -05:00
|
|
|
if options.doYosys: conf.doYosys = True
|
2020-02-09 04:45:04 -06:00
|
|
|
if options.doAlliance: conf.doAlliance = True
|
2020-03-20 09:07:41 -05:00
|
|
|
if options.doCoriolis: conf.doCoriolis = True
|
2015-06-18 07:54:45 -05:00
|
|
|
if options.benchs: conf.doBenchs = True
|
2020-02-09 04:45:04 -06:00
|
|
|
if options.doReport: conf.doSendReport = True
|
2015-06-18 07:54:45 -05:00
|
|
|
if options.rmSource or options.rmAll: conf.rmSource = True
|
|
|
|
if options.rmBuild or options.rmAll: conf.rmBuild = True
|
|
|
|
|
2020-02-19 17:45:52 -06:00
|
|
|
|
2020-03-20 09:07:41 -05:00
|
|
|
if conf.doYosys: conf.openLog( 'yosys' )
|
2020-02-09 04:45:04 -06:00
|
|
|
if conf.doAlliance: conf.openLog( 'alliance' )
|
|
|
|
if conf.doCoriolis: conf.openLog( 'coriolis' )
|
|
|
|
if conf.doBenchs: conf.openLog( 'benchs' )
|
|
|
|
|
|
|
|
if conf.dockerMode: os.environ['USER'] = 'root'
|
2016-08-10 05:07:40 -05:00
|
|
|
|
2016-02-21 04:58:54 -06:00
|
|
|
gitSupports = []
|
|
|
|
for supportRepo in conf.supportRepos:
|
2020-03-20 09:07:41 -05:00
|
|
|
gitSupports.append( GitRepository( supportRepo, conf.srcDir+'/support' ) )
|
2020-02-09 04:45:04 -06:00
|
|
|
gitCoriolis = GitRepository( conf.coriolisRepo, conf.srcDir, conf.fds['coriolis'] )
|
|
|
|
gitBenchs = GitRepository( conf.benchsRepo , conf.srcDir, conf.fds['coriolis'] )
|
|
|
|
|
|
|
|
if conf.doAlliance:
|
2020-03-20 09:07:41 -05:00
|
|
|
gitAlliance = GitRepository( conf.allianceRepo, conf.srcDir, conf.fds['alliance'] )
|
2015-06-18 07:54:45 -05:00
|
|
|
|
|
|
|
if conf.doGit:
|
2020-03-20 09:07:41 -05:00
|
|
|
for gitSupport in gitSupports:
|
|
|
|
if conf.rmSource: gitSupport.removeLocalRepo()
|
|
|
|
gitSupport.clone()
|
2021-06-11 04:47:35 -05:00
|
|
|
if gitSupport.url.endswith('rapidjson'):
|
|
|
|
gitSupport.checkout( 'b1a4d91' )
|
2020-03-20 09:07:41 -05:00
|
|
|
|
|
|
|
if conf.doAlliance:
|
|
|
|
if conf.rmSource: gitAlliance.removeLocalRepo()
|
|
|
|
gitAlliance.clone ()
|
|
|
|
#gitAlliance.checkout( 'devel' )
|
|
|
|
|
|
|
|
if conf.doCoriolis:
|
|
|
|
if conf.rmSource: gitCoriolis.removeLocalRepo()
|
|
|
|
gitCoriolis.clone ()
|
|
|
|
gitCoriolis.checkout( 'devel' )
|
|
|
|
|
|
|
|
if conf.rmSource: gitBenchs.removeLocalRepo()
|
|
|
|
gitBenchs.clone()
|
2015-06-11 11:51:10 -05:00
|
|
|
|
2015-06-18 07:54:45 -05:00
|
|
|
if conf.rmBuild:
|
2020-03-20 09:07:41 -05:00
|
|
|
for entry in os.listdir(conf.rootDir):
|
|
|
|
if entry.startswith('Linux.'):
|
|
|
|
buildDir = conf.rootDir+'/'+entry
|
|
|
|
print 'Removing OS build directory: <%s>' % buildDir
|
|
|
|
shutil.rmtree( buildDir )
|
2015-06-11 11:51:10 -05:00
|
|
|
|
2020-02-09 04:45:04 -06:00
|
|
|
commands = conf.getCommands( options.profile )
|
|
|
|
for command in commands:
|
2020-03-20 09:07:41 -05:00
|
|
|
if command.host:
|
|
|
|
print 'Executing command on remote host <%s>:' % host
|
|
|
|
else:
|
|
|
|
print 'Executing command on *local* host:'
|
|
|
|
print ' %s' % str(command)
|
|
|
|
command.execute()
|
2015-06-11 11:51:10 -05:00
|
|
|
|
2015-06-18 07:54:45 -05:00
|
|
|
conf.closeLogs()
|
2016-11-10 06:46:45 -06:00
|
|
|
|
2015-06-18 07:54:45 -05:00
|
|
|
conf.success = True
|
2015-06-11 11:51:10 -05:00
|
|
|
|
|
|
|
except ErrorMessage, e:
|
2020-03-20 09:07:41 -05:00
|
|
|
print e
|
|
|
|
conf.closeLogs()
|
|
|
|
conf.success = False
|
|
|
|
|
|
|
|
if showTrace:
|
|
|
|
print '\nPython stack trace:'
|
|
|
|
traceback.print_tb( sys.exc_info()[2] )
|
|
|
|
conf.rcode = e.code
|
2015-06-18 07:54:45 -05:00
|
|
|
|
|
|
|
if conf.doSendReport:
|
2020-03-20 09:07:41 -05:00
|
|
|
report = Report( conf )
|
|
|
|
report.attachLog( conf.logs['coriolis' ] )
|
|
|
|
report.attachLog( conf.logs['benchs' ] )
|
|
|
|
report.send()
|
2015-06-11 11:51:10 -05:00
|
|
|
|
2016-11-10 06:46:45 -06:00
|
|
|
conf.compressLogs()
|
|
|
|
|
2015-06-18 07:54:45 -05:00
|
|
|
sys.exit( conf.rcode )
|