def run(self): try: fin_num = 0 while True: badnews = self.feedback_q.get() if badnews is None: break if badnews == "Done": fin_num += 1 elif badnews == "QueueEmpty": EdkLogger.debug(EdkLogger.DEBUG_9, "Worker %s: %s" % (os.getpid(), badnews)) self.TerminateWorkers() else: EdkLogger.debug(EdkLogger.DEBUG_9, "Worker %s: %s" % (os.getpid(), badnews)) self.Status = False self.TerminateWorkers() if fin_num == len(self.autogen_workers): self.clearQueue() for w in self.autogen_workers: w.join() break except Exception: return
def CallExtenalBPDGTool(ToolPath, VpdFileName): assert ToolPath is not None, "Invalid parameter ToolPath" assert VpdFileName is not None and os.path.exists( VpdFileName), "Invalid parameter VpdFileName" OutputDir = os.path.dirname(VpdFileName) FileName = os.path.basename(VpdFileName) BaseName, ext = os.path.splitext(FileName) OutputMapFileName = os.path.join(OutputDir, "%s.map" % BaseName) OutputBinFileName = os.path.join(OutputDir, "%s.bin" % BaseName) try: PopenObject = subprocess.Popen(' '.join([ ToolPath, '-o', OutputBinFileName, '-m', OutputMapFileName, '-q', '-f', VpdFileName ]), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) except Exception as X: EdkLogger.error("BPDG", BuildToolError.COMMAND_FAILURE, ExtraData=str(X)) (out, error) = PopenObject.communicate() print(out.decode()) while PopenObject.returncode is None: PopenObject.wait() if PopenObject.returncode != 0: EdkLogger.debug(EdkLogger.DEBUG_1, "Fail to call BPDG tool", str(error)) EdkLogger.error("BPDG", BuildToolError.COMMAND_FAILURE, "Fail to execute BPDG tool with exit code: %d, the error message is: \n %s" % \ (PopenObject.returncode, str(error))) return PopenObject.returncode
def Query(self, Model): SqlCommand = """select ID, Value1, Value2, Value3, Arch, BelongsToItem, BelongsToFile, StartLine from %s where Model = %s and Enabled > -1""" % (self.Table, Model) EdkLogger.debug(4, "SqlCommand: %s" % SqlCommand) self.Cur.execute(SqlCommand) return self.Cur.fetchall()
def Insert(self, *Args): self.ID = self.ID + self._ID_STEP_ if self.ID >= (self.IdBase + self._ID_MAX_): self.ID = self.IdBase + self._ID_STEP_ Values = ", ".join(str(Arg) for Arg in Args) SqlCommand = "insert into %s values(%s, %s)" % (self.Table, self.ID, Values) EdkLogger.debug(EdkLogger.DEBUG_5, SqlCommand) self.Cur.execute(SqlCommand) return self.ID
def IsIntegrity(self): Result = False try: TimeStamp = self.MetaFile.TimeStamp if not self.CurrentContent: Result = False else: Result = self.CurrentContent[-1][0] < 0 except Exception as Exc: EdkLogger.debug(EdkLogger.DEBUG_5, str(Exc)) return False return Result
def SearchImageID(ImageFileObject, FileList): if FileList == []: return ImageFileObject for File in FileList: if os.path.isfile(File): Lines = open(File, 'r') for Line in Lines: ImageIdList = IMAGE_TOKEN.findall(Line) for ID in ImageIdList: EdkLogger.debug(EdkLogger.DEBUG_5, "Found ImageID identifier: " + ID) ImageFileObject.SetImageIDReferenced(ID)
def Create(self, NewTable=True): if NewTable: self.Drop() if self.Temporary: SqlCommand = """create temp table IF NOT EXISTS %s (%s)""" % ( self.Table, self._COLUMN_) else: SqlCommand = """create table IF NOT EXISTS %s (%s)""" % ( self.Table, self._COLUMN_) EdkLogger.debug(EdkLogger.DEBUG_8, SqlCommand) self.Cur.execute(SqlCommand) self.ID = self.GetId()
def __init__(self, Expression, ModuleType, Optimize=False): self.ModuleType = ModuleType self.Phase = gType2Phase[ModuleType] if isinstance(Expression, type([])): self.ExpressionString = " ".join(Expression) self.TokenList = Expression else: self.ExpressionString = Expression self.GetExpressionTokenList() self.PostfixNotation = [] self.OpcodeList = [] self.GetPostfixNotation() self.ValidateOpcode() EdkLogger.debug(EdkLogger.DEBUG_8, repr(self)) if Optimize: self.Optimize() EdkLogger.debug(EdkLogger.DEBUG_8, "\n Optimized: " + repr(self))
def SearchString(UniObjectClass, FileList, IsCompatibleMode): if FileList == []: return UniObjectClass for File in FileList: try: if os.path.isfile(File): Lines = open(File, 'r') for Line in Lines: for StrName in STRING_TOKEN.findall(Line): EdkLogger.debug(EdkLogger.DEBUG_5, "Found string identifier: " + StrName) UniObjectClass.SetStringReferenced(StrName) except: EdkLogger.error("UnicodeStringGather", AUTOGEN_ERROR, "SearchString: Error while processing file", File=File, RaiseError=False) raise UniObjectClass.ReToken() return UniObjectClass
def _OverridePcd(self, ToPcd, FromPcd, Module="", Msg="", Library=""): # # in case there's PCDs coming from FDF file, which have no type given. # at this point, ToPcd.Type has the type found from dependent # package # TokenCName = ToPcd.TokenCName for PcdItem in self.MixedPcd: if (ToPcd.TokenCName, ToPcd.TokenSpaceGuidCName) in self.MixedPcd[PcdItem]: TokenCName = PcdItem[0] break if FromPcd is not None: if ToPcd.Pending and FromPcd.Type: ToPcd.Type = FromPcd.Type elif ToPcd.Type and FromPcd.Type\ and ToPcd.Type != FromPcd.Type and ToPcd.Type in FromPcd.Type: if ToPcd.Type.strip() == TAB_PCDS_DYNAMIC_EX: ToPcd.Type = FromPcd.Type elif ToPcd.Type and FromPcd.Type \ and ToPcd.Type != FromPcd.Type: if Library: Module = str(Module) + " 's library file (" + str( Library) + ")" EdkLogger.error("build", OPTION_CONFLICT, "Mismatched PCD type", ExtraData="%s.%s is used as [%s] in module %s, but as [%s] in %s."\ % (ToPcd.TokenSpaceGuidCName, TokenCName, ToPcd.Type, Module, FromPcd.Type, Msg), File=self.MetaFile) if FromPcd.MaxDatumSize: ToPcd.MaxDatumSize = FromPcd.MaxDatumSize ToPcd.MaxSizeUserSet = FromPcd.MaxDatumSize if FromPcd.DefaultValue: ToPcd.DefaultValue = FromPcd.DefaultValue if FromPcd.TokenValue: ToPcd.TokenValue = FromPcd.TokenValue if FromPcd.DatumType: ToPcd.DatumType = FromPcd.DatumType if FromPcd.SkuInfoList: ToPcd.SkuInfoList = FromPcd.SkuInfoList if FromPcd.UserDefinedDefaultStoresFlag: ToPcd.UserDefinedDefaultStoresFlag = FromPcd.UserDefinedDefaultStoresFlag # Add Flexible PCD format parse if ToPcd.DefaultValue: try: ToPcd.DefaultValue = ValueExpressionEx( ToPcd.DefaultValue, ToPcd.DatumType, self._GuidDict)(True) except BadExpression as Value: EdkLogger.error( 'Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s", %s' % (ToPcd.TokenSpaceGuidCName, ToPcd.TokenCName, ToPcd.DefaultValue, Value), File=self.MetaFile) # check the validation of datum IsValid, Cause = CheckPcdDatum(ToPcd.DatumType, ToPcd.DefaultValue) if not IsValid: EdkLogger.error('build', FORMAT_INVALID, Cause, File=self.MetaFile, ExtraData="%s.%s" % (ToPcd.TokenSpaceGuidCName, TokenCName)) ToPcd.validateranges = FromPcd.validateranges ToPcd.validlists = FromPcd.validlists ToPcd.expressions = FromPcd.expressions ToPcd.CustomAttribute = FromPcd.CustomAttribute if FromPcd is not None and ToPcd.DatumType == TAB_VOID and not ToPcd.MaxDatumSize: EdkLogger.debug(EdkLogger.DEBUG_9, "No MaxDatumSize specified for PCD %s.%s" \ % (ToPcd.TokenSpaceGuidCName, TokenCName)) Value = ToPcd.DefaultValue if not Value: ToPcd.MaxDatumSize = '1' elif Value[0] == 'L': ToPcd.MaxDatumSize = str((len(Value) - 2) * 2) elif Value[0] == '{': ToPcd.MaxDatumSize = str(len(Value.split(','))) else: ToPcd.MaxDatumSize = str(len(Value) - 1) # apply default SKU for dynamic PCDS if specified one is not available if (ToPcd.Type in PCD_DYNAMIC_TYPE_SET or ToPcd.Type in PCD_DYNAMIC_EX_TYPE_SET) \ and not ToPcd.SkuInfoList: if self.Platform.SkuName in self.Platform.SkuIds: SkuName = self.Platform.SkuName else: SkuName = TAB_DEFAULT ToPcd.SkuInfoList = { SkuName: SkuInfoClass(SkuName, self.Platform.SkuIds[SkuName][0], '', '', '', '', '', ToPcd.DefaultValue) }
def Exec(self, SqlCommand): EdkLogger.debug(4, "SqlCommand: %s" % SqlCommand) self.Cur.execute(SqlCommand) RecordSet = self.Cur.fetchall() EdkLogger.debug(4, "RecordSet: %s" % RecordSet) return RecordSet
def DebugLogger(Level, msg): EdkLogger.debug(Level, msg)
def run(self): try: taskname = "Init" with self.file_lock: try: self.data_pipe = MemoryDataPipe() self.data_pipe.load(self.data_pipe_file_path) except: self.feedback_q.put(taskname + ":" + "load data pipe %s failed." % self.data_pipe_file_path) EdkLogger.LogClientInitialize(self.log_q) loglevel = self.data_pipe.Get("LogLevel") if not loglevel: loglevel = EdkLogger.INFO EdkLogger.SetLevel(loglevel) target = self.data_pipe.Get("P_Info").get("Target") toolchain = self.data_pipe.Get("P_Info").get("ToolChain") archlist = self.data_pipe.Get("P_Info").get("ArchList") active_p = self.data_pipe.Get("P_Info").get("ActivePlatform") workspacedir = self.data_pipe.Get("P_Info").get("WorkspaceDir") PackagesPath = os.getenv("PACKAGES_PATH") mws.setWs(workspacedir, PackagesPath) self.Wa = WorkSpaceInfo( workspacedir,active_p,target,toolchain,archlist ) self.Wa._SrcTimeStamp = self.data_pipe.Get("Workspace_timestamp") GlobalData.gGlobalDefines = self.data_pipe.Get("G_defines") GlobalData.gCommandLineDefines = self.data_pipe.Get("CL_defines") GlobalData.gCommandMaxLength = self.data_pipe.Get('gCommandMaxLength') os.environ._data = self.data_pipe.Get("Env_Var") GlobalData.gWorkspace = workspacedir GlobalData.gDisableIncludePathCheck = False GlobalData.gFdfParser = self.data_pipe.Get("FdfParser") GlobalData.gDatabasePath = self.data_pipe.Get("DatabasePath") GlobalData.gUseHashCache = self.data_pipe.Get("UseHashCache") GlobalData.gBinCacheSource = self.data_pipe.Get("BinCacheSource") GlobalData.gBinCacheDest = self.data_pipe.Get("BinCacheDest") GlobalData.gPlatformHashFile = self.data_pipe.Get("PlatformHashFile") GlobalData.gModulePreMakeCacheStatus = dict() GlobalData.gModuleMakeCacheStatus = dict() GlobalData.gHashChainStatus = dict() GlobalData.gCMakeHashFile = dict() GlobalData.gModuleHashFile = dict() GlobalData.gFileHashDict = dict() GlobalData.gEnableGenfdsMultiThread = self.data_pipe.Get("EnableGenfdsMultiThread") GlobalData.gPlatformFinalPcds = self.data_pipe.Get("gPlatformFinalPcds") GlobalData.file_lock = self.file_lock CommandTarget = self.data_pipe.Get("CommandTarget") pcd_from_build_option = [] for pcd_tuple in self.data_pipe.Get("BuildOptPcd"): pcd_id = ".".join((pcd_tuple[0],pcd_tuple[1])) if pcd_tuple[2].strip(): pcd_id = ".".join((pcd_id,pcd_tuple[2])) pcd_from_build_option.append("=".join((pcd_id,pcd_tuple[3]))) GlobalData.BuildOptionPcd = pcd_from_build_option module_count = 0 FfsCmd = self.data_pipe.Get("FfsCommand") if FfsCmd is None: FfsCmd = {} GlobalData.FfsCmd = FfsCmd PlatformMetaFile = self.GetPlatformMetaFile(self.data_pipe.Get("P_Info").get("ActivePlatform"), self.data_pipe.Get("P_Info").get("WorkspaceDir")) while True: if self.error_event.is_set(): break module_count += 1 try: module_file,module_root,module_path,module_basename,module_originalpath,module_arch,IsLib = self.module_queue.get_nowait() except Empty: EdkLogger.debug(EdkLogger.DEBUG_9, "Worker %s: %s" % (os.getpid(), "Fake Empty.")) time.sleep(0.01) continue if module_file is None: EdkLogger.debug(EdkLogger.DEBUG_9, "Worker %s: %s" % (os.getpid(), "Worker get the last item in the queue.")) self.feedback_q.put("QueueEmpty") time.sleep(0.01) continue modulefullpath = os.path.join(module_root,module_file) taskname = " : ".join((modulefullpath,module_arch)) module_metafile = PathClass(module_file,module_root) if module_path: module_metafile.Path = module_path if module_basename: module_metafile.BaseName = module_basename if module_originalpath: module_metafile.OriginalPath = PathClass(module_originalpath,module_root) arch = module_arch target = self.data_pipe.Get("P_Info").get("Target") toolchain = self.data_pipe.Get("P_Info").get("ToolChain") Ma = ModuleAutoGen(self.Wa,module_metafile,target,toolchain,arch,PlatformMetaFile,self.data_pipe) Ma.IsLibrary = IsLib # SourceFileList calling sequence impact the makefile string sequence. # Create cached SourceFileList here to unify its calling sequence for both # CanSkipbyPreMakeCache and CreateCodeFile/CreateMakeFile. RetVal = Ma.SourceFileList if GlobalData.gUseHashCache and not GlobalData.gBinCacheDest and CommandTarget in [None, "", "all"]: try: CacheResult = Ma.CanSkipbyPreMakeCache() except: CacheResult = False self.feedback_q.put(taskname) if CacheResult: self.cache_q.put((Ma.MetaFile.Path, Ma.Arch, "PreMakeCache", True)) continue else: self.cache_q.put((Ma.MetaFile.Path, Ma.Arch, "PreMakeCache", False)) Ma.CreateCodeFile(False) Ma.CreateMakeFile(False,GenFfsList=FfsCmd.get((Ma.MetaFile.Path, Ma.Arch),[])) Ma.CreateAsBuiltInf() if GlobalData.gBinCacheSource and CommandTarget in [None, "", "all"]: try: CacheResult = Ma.CanSkipbyMakeCache() except: CacheResult = False self.feedback_q.put(taskname) if CacheResult: self.cache_q.put((Ma.MetaFile.Path, Ma.Arch, "MakeCache", True)) continue else: self.cache_q.put((Ma.MetaFile.Path, Ma.Arch, "MakeCache", False)) except Exception as e: EdkLogger.debug(EdkLogger.DEBUG_9, "Worker %s: %s" % (os.getpid(), str(e))) self.feedback_q.put(taskname) finally: EdkLogger.debug(EdkLogger.DEBUG_9, "Worker %s: %s" % (os.getpid(), "Done")) self.feedback_q.put("Done") self.cache_q.put("CacheDone")
def UpdateIdentifierBelongsToFunction_disabled(self): EdkLogger.verbose( "Update 'BelongsToFunction' for Identifiers started ...") SqlCommand = """select ID, BelongsToFile, StartLine, EndLine, Model from Identifier""" EdkLogger.debug(4, "SqlCommand: %s" % SqlCommand) self.Cur.execute(SqlCommand) Records = self.Cur.fetchall() for Record in Records: IdentifierID = Record[0] BelongsToFile = Record[1] StartLine = Record[2] EndLine = Record[3] Model = Record[4] # # Check whether an identifier belongs to a function # EdkLogger.debug(4, "For common identifiers ... ") SqlCommand = """select ID from Function where StartLine < %s and EndLine > %s and BelongsToFile = %s""" % (StartLine, EndLine, BelongsToFile) EdkLogger.debug(4, "SqlCommand: %s" % SqlCommand) self.Cur.execute(SqlCommand) IDs = self.Cur.fetchall() for ID in IDs: SqlCommand = """Update Identifier set BelongsToFunction = %s where ID = %s""" % ( ID[0], IdentifierID) EdkLogger.debug(4, "SqlCommand: %s" % SqlCommand) self.Cur.execute(SqlCommand) # # Check whether the identifier is a function header # EdkLogger.debug(4, "For function headers ... ") if Model == DataClass.MODEL_IDENTIFIER_COMMENT: SqlCommand = """select ID from Function where StartLine = %s + 1 and BelongsToFile = %s""" % (EndLine, BelongsToFile) EdkLogger.debug(4, "SqlCommand: %s" % SqlCommand) self.Cur.execute(SqlCommand) IDs = self.Cur.fetchall() for ID in IDs: SqlCommand = """Update Identifier set BelongsToFunction = %s, Model = %s where ID = %s""" % ( ID[0], DataClass.MODEL_IDENTIFIER_FUNCTION_HEADER, IdentifierID) EdkLogger.debug(4, "SqlCommand: %s" % SqlCommand) self.Cur.execute(SqlCommand) EdkLogger.verbose( "Update 'BelongsToFunction' for Identifiers ... DONE")
def Exec(self, SqlCommand): EdkLogger.debug(EdkLogger.DEBUG_5, SqlCommand) self.Cur.execute(SqlCommand) RecordSet = self.Cur.fetchall() return RecordSet