sbsv2/raptor/python/raptor_make.py
branchwip
changeset 29 ee00c00df073
parent 5 593a8820b912
child 118 375b7128e900
equal deleted inserted replaced
28:6983dbbe3d70 29:ee00c00df073
    18 
    18 
    19 import hashlib
    19 import hashlib
    20 import os
    20 import os
    21 import random
    21 import random
    22 import raptor
    22 import raptor
       
    23 import raptor_timing
    23 import raptor_utilities
    24 import raptor_utilities
    24 import raptor_version
    25 import raptor_version
    25 import raptor_data
    26 import raptor_data
    26 import re
    27 import re
    27 import subprocess
    28 import subprocess
    28 import time
    29 import time
    29 from raptor_makefile import *
    30 from raptor_makefile import *
    30 import raptor_version
       
    31 import traceback
    31 import traceback
    32 import sys
    32 import sys
    33 
    33 
    34 # raptor_make module classes
    34 # raptor_make module classes
    35 
    35 
   133 		else:
   133 		else:
   134 			talon_settings="""
   134 			talon_settings="""
   135 USE_TALON:=
   135 USE_TALON:=
   136 
   136 
   137 """
   137 """
   138 		
   138 
       
   139 
       
   140 		timing_start = "$(info " + \
       
   141 				raptor_timing.Timing.custom_string(tag = "start",
       
   142 				object_type = "makefile", task = "parse",
       
   143 				key = "$(THIS_FILENAME)",
       
   144 				time="$(shell date +%s.%N)").rstrip("\n") + ")"
       
   145 				
       
   146 		timing_end = "$(info " + \
       
   147 				raptor_timing.Timing.custom_string(tag = "end",
       
   148 				object_type = "makefile", task = "parse",
       
   149 				key = "$(THIS_FILENAME)",
       
   150 				time="$(shell date +%s.%N)").rstrip("\n") + ")"
       
   151 
   139 
   152 
   140 		self.makefile_prologue = """
   153 		self.makefile_prologue = """
       
   154 
   141 # generated by %s %s
   155 # generated by %s %s
   142 
   156 
   143 HOSTPLATFORM:=%s
   157 HOSTPLATFORM:=%s
   144 HOSTPLATFORM_DIR:=%s
   158 HOSTPLATFORM_DIR:=%s
   145 OSTYPE:=%s
   159 OSTYPE:=%s
   146 FLMHOME:=%s
   160 FLMHOME:=%s
   147 SHELL:=%s
   161 SHELL:=%s
       
   162 THIS_FILENAME:=$(firstword $(MAKEFILE_LIST))
   148 
   163 
   149 %s
   164 %s
   150 
   165 
   151 include %s
   166 include %s
   152 
   167 
   157 			 str(self.raptor.systemFLM),
   172 			 str(self.raptor.systemFLM),
   158 			 self.shellpath,
   173 			 self.shellpath,
   159 			 talon_settings,
   174 			 talon_settings,
   160 			 self.raptor.systemFLM.Append('globals.mk') )
   175 			 self.raptor.systemFLM.Append('globals.mk') )
   161 
   176 
   162 
   177 		# Only output timings if requested on CLI
   163 		self.makefile_epilogue = """
   178 		if self.raptor.timing:
       
   179 			self.makefile_prologue += "\n# Print Start-time of Makefile parsing\n" \
       
   180 					+ timing_start + "\n\n"
       
   181 	
       
   182 	
       
   183 			self.makefile_epilogue = "\n\n# Print End-time of Makefile parsing\n" \
       
   184 				+ timing_end + "\n"
       
   185 		else:
       
   186 			self.makefile_epilogue = ""
       
   187 
       
   188 		self.makefile_epilogue += """
   164 
   189 
   165 include %s
   190 include %s
   166 
   191 
   167 """ 			% (self.raptor.systemFLM.Append('final.mk') )
   192 """ 			% (self.raptor.systemFLM.Append('final.mk') )
   168 
   193 
   363 		# Files should be deleted in the opposite order to the order
   388 		# Files should be deleted in the opposite order to the order
   364 		# they were built. So reverse file order if cleaning
   389 		# they were built. So reverse file order if cleaning
   365 		if clean_flag:
   390 		if clean_flag:
   366 			fileName_list.reverse()
   391 			fileName_list.reverse()
   367 
   392 
       
   393 		# Report number of makefiles to be built
       
   394 		self.raptor.InfoDiscovery(object_type = "makefile", count = len(fileName_list))
       
   395 
   368 		# Process each file in turn
   396 		# Process each file in turn
   369 		for makefile in fileName_list:
   397 		for makefile in fileName_list:
   370 			if not os.path.exists(makefile):
   398 			if not os.path.exists(makefile):
   371 				self.raptor.Info("Skipping makefile %s", makefile)
   399 				self.raptor.Info("Skipping makefile %s", makefile)
   372 				continue
   400 				continue
   429 			# execute the build.
   457 			# execute the build.
   430 			# the actual call differs between Windows and Unix.
   458 			# the actual call differs between Windows and Unix.
   431 			# bufsize=1 means "line buffered"
   459 			# bufsize=1 means "line buffered"
   432 			#
   460 			#
   433 			try:
   461 			try:
       
   462 				# Time the build
       
   463 				self.raptor.InfoStartTime(object_type = "makefile",
       
   464 						task = "build", key = str(makefile))
       
   465 				
   434 				makeenv=os.environ.copy()
   466 				makeenv=os.environ.copy()
   435 				if self.usetalon:
   467 				if self.usetalon:
   436 					makeenv['TALON_RECIPEATTRIBUTES']="none"
   468 					makeenv['TALON_RECIPEATTRIBUTES']="none"
   437 					makeenv['TALON_SHELL']=self.talonshell
   469 					makeenv['TALON_SHELL']=self.talonshell
   438 					makeenv['TALON_BUILDID']=str(self.buildID)
   470 					makeenv['TALON_BUILDID']=str(self.buildID)
   456 					self.raptor.out.write(line)
   488 					self.raptor.out.write(line)
   457 
   489 
   458 				# should be done now
   490 				# should be done now
   459 				returncode = p.wait()
   491 				returncode = p.wait()
   460 
   492 
       
   493 				# Report end-time of the build
       
   494 				self.raptor.InfoEndTime(object_type = "makefile",
       
   495 						task = "build", key = str(makefile))
   461 
   496 
   462 				if returncode != 0  and not self.raptor.keepGoing:
   497 				if returncode != 0  and not self.raptor.keepGoing:
   463 					self.Tidy()
   498 					self.Tidy()
   464 					return False
   499 					return False
   465 
   500 
   466 			except Exception,e:
   501 			except Exception,e:
   467 				self.raptor.Error("Exception '%s' during '%s'", str(e), command)
   502 				self.raptor.Error("Exception '%s' during '%s'", str(e), command)
   468 				self.Tidy()
   503 				self.Tidy()
       
   504 				# Still report end-time of the build
       
   505 				self.raptor.InfoEnd(object_type = "Building", task = "Makefile",
       
   506 						key = str(makefile))
   469 				return False
   507 				return False
   470 
   508 
   471 		# run any shutdown script
   509 		# run any shutdown script
   472 		if self.shutdownCommand != None and self.shutdownCommand != "":
   510 		if self.shutdownCommand != None and self.shutdownCommand != "":
   473 			self.raptor.Info("Running %s", self.shutdownCommand)
   511 			self.raptor.Info("Running %s", self.shutdownCommand)