sbsv2/raptor/python/raptor_make.py
branchwip
changeset 126 7309affc5a05
parent 122 816955f04aaa
child 130 4f2ae0d78608
equal deleted inserted replaced
125:dc823469fda2 126:7309affc5a05
    28 import subprocess
    28 import subprocess
    29 import time
    29 import time
    30 from raptor_makefile import *
    30 from raptor_makefile import *
    31 import traceback
    31 import traceback
    32 import sys
    32 import sys
       
    33 from xml.sax.saxutils import escape
       
    34 
    33 
    35 
    34 # raptor_make module classes
    36 # raptor_make module classes
    35 
    37 
    36 class MakeEngine(object):
    38 class MakeEngine(object):
    37 
    39 
   401 			self.raptor.Info("Making %s", makefile)
   403 			self.raptor.Info("Making %s", makefile)
   402 			# assemble the build command line
   404 			# assemble the build command line
   403 			command = self.buildCommand
   405 			command = self.buildCommand
   404 
   406 
   405 			if self.makefileOption:
   407 			if self.makefileOption:
   406 				command += " " + self.makefileOption + " " + '"' + str(makefile) + '"'
   408 				command += " " + self.makefileOption + " " + ' "' + str(makefile) + '" '
   407 
   409 
   408 			if self.raptor.keepGoing and self.keepGoingOption:
   410 			if self.raptor.keepGoing and self.keepGoingOption:
   409 				command += " " + self.keepGoingOption
   411 				command += " " + self.keepGoingOption
   410 
   412 
   411 			if self.raptor.jobs > 1 and self.jobsOption:
   413 			if self.raptor.jobs > 1 and self.jobsOption:
   414 			# Set default options first so that they can be overridden by
   416 			# Set default options first so that they can be overridden by
   415 			# ones set by the --mo option on the raptor commandline:
   417 			# ones set by the --mo option on the raptor commandline:
   416 			command += " " + self.defaultMakeOptions
   418 			command += " " + self.defaultMakeOptions
   417 			# Can supply options on the commandline to override default settings.
   419 			# Can supply options on the commandline to override default settings.
   418 			if len(self.raptor.makeOptions) > 0:
   420 			if len(self.raptor.makeOptions) > 0:
   419 				command += " " + " ".join(self.raptor.makeOptions)
   421 				for o in self.raptor.makeOptions:
       
   422 					if o.find(";") != -1:
       
   423 						command += "  " + "'" + o + "'"
       
   424 					elif o.find("\\") != -1:
       
   425 						command += "  " + o.replace("\\","\\\\")
       
   426 					else:
       
   427 						command += "  " + o
   420 
   428 
   421 			# Switch off dependency file including?
   429 			# Switch off dependency file including?
   422 			if self.raptor.noDependInclude:
   430 			if self.raptor.noDependInclude:
   423 				command += " NO_DEPEND_INCLUDE=1"
   431 				command += " NO_DEPEND_INCLUDE=1"
   424 			
   432 			
   446 					if re.match(ignoreTargets, target):
   454 					if re.match(ignoreTargets, target):
   447 						addTargets.remove(target)
   455 						addTargets.remove(target)
   448 
   456 
   449 			if addTargets:
   457 			if addTargets:
   450 				command += " " + " ".join(addTargets)
   458 				command += " " + " ".join(addTargets)
       
   459 
       
   460 			# Send stderr to a file so that it can't mess up the log (e.g.
       
   461 			# clock skew messages from some build engines.
       
   462 			stderrfilename = makefile+'.stderr'
       
   463 			command += " 2>'%s' " % stderrfilename
   451 
   464 
   452 			# Substitute the makefile name for any occurrence of #MAKEFILE#
   465 			# Substitute the makefile name for any occurrence of #MAKEFILE#
   453 			command = command.replace("#MAKEFILE#", str(makefile))
   466 			command = command.replace("#MAKEFILE#", str(makefile))
   454 
   467 
   455 			self.raptor.Info("Executing '%s'", command)
   468 			self.raptor.Info("Executing '%s'", command)
   467 				if self.usetalon:
   480 				if self.usetalon:
   468 					makeenv['TALON_RECIPEATTRIBUTES']="none"
   481 					makeenv['TALON_RECIPEATTRIBUTES']="none"
   469 					makeenv['TALON_SHELL']=self.talonshell
   482 					makeenv['TALON_SHELL']=self.talonshell
   470 					makeenv['TALON_BUILDID']=str(self.buildID)
   483 					makeenv['TALON_BUILDID']=str(self.buildID)
   471 					makeenv['TALON_TIMEOUT']=str(self.talontimeout)
   484 					makeenv['TALON_TIMEOUT']=str(self.talontimeout)
       
   485 
   472 				if self.raptor.filesystem == "unix":
   486 				if self.raptor.filesystem == "unix":
   473 					p = subprocess.Popen([command], bufsize=65535,
   487 					p = subprocess.Popen([command], bufsize=65535,
   474 						stdout=subprocess.PIPE,
   488 						stdout=subprocess.PIPE,
   475 						stderr=subprocess.STDOUT,
   489 						stderr=subprocess.STDOUT,
   476 						close_fds=True, env=makeenv, shell=True)
   490 						close_fds=True, env=makeenv, shell=True)
   477 				else:
   491 				else:
   478 					p = subprocess.Popen(args = 
   492 					p = subprocess.Popen(args = 
   479 						[raptor_data.ToolSet.shell, '-c', command, '2>' + makefile+'.stderr'],
   493 						[raptor_data.ToolSet.shell, '-c', command],
   480 						bufsize=65535,
   494 						bufsize=65535,
   481 						stdout=subprocess.PIPE,
   495 						stdout=subprocess.PIPE,
   482 						stderr=subprocess.STDOUT,
   496 						stderr=subprocess.STDOUT,
   483 						shell = False,
   497 						shell = False,
   484 						universal_newlines=True, env=makeenv)
   498 						universal_newlines=True, env=makeenv)
   487 
   501 
   488 				line = " "
   502 				line = " "
   489 				while line:
   503 				while line:
   490 					line = stream.readline()
   504 					line = stream.readline()
   491 					self.raptor.out.write(line)
   505 					self.raptor.out.write(line)
       
   506 
       
   507 				try:
       
   508 					e = open(stderrfilename,"r")
       
   509 					for line in e:
       
   510 						self.raptor.out.write(escape(line))
       
   511 					e.close()
       
   512 				except Exception,e:
       
   513 					self.raptor.Error("Couldn't complete stderr output for %s - '%s'", str(e), command)
   492 
   514 
   493 				# should be done now
   515 				# should be done now
   494 				returncode = p.wait()
   516 				returncode = p.wait()
   495 
   517 
   496 				# Report end-time of the build
   518 				# Report end-time of the build