def GenSourceInstance(Item, CurrentLineOfItem, ItemObj): IsValidFileFlag = False if len(Item) < 6 and len(Item) >= 1: # # File | Family | TagName | ToolCode | FeatureFlagExpr # if len(Item) == 5: # # Validate Feature Flag Express # if Item[4].strip() == '': Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING, File=CurrentLineOfItem[2], Line=CurrentLineOfItem[1], ExtraData=CurrentLineOfItem[0]) # # Validate FFE # FeatureFlagRtv = IsValidFeatureFlagExp(Item[4].strip()) if not FeatureFlagRtv[0]: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID % (FeatureFlagRtv[1]), File=CurrentLineOfItem[2], Line=CurrentLineOfItem[1], ExtraData=CurrentLineOfItem[0]) ItemObj.SetFeatureFlagExp(Item[4]) if len(Item) >= 4: if Item[3].strip() == '': ItemObj.SetToolCode(Item[3]) else: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_TOOLCODE_NOT_PERMITTED % (Item[2]), File=CurrentLineOfItem[2], Line=CurrentLineOfItem[1], ExtraData=CurrentLineOfItem[0]) if len(Item) >= 3: if Item[2].strip() == '': ItemObj.SetTagName(Item[2]) else: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_TAGNAME_NOT_PERMITTED % (Item[2]), File=CurrentLineOfItem[2], Line=CurrentLineOfItem[1], ExtraData=CurrentLineOfItem[0]) if len(Item) >= 2: if IsValidFamily(Item[1].strip()): # # To align with UDP specification. "*" is not permitted in UDP specification # if Item[1].strip() == "*": Item[1] = "" ItemObj.SetFamily(Item[1]) else: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_SOURCE_SECTION_FAMILY_INVALID % (Item[1]), File=CurrentLineOfItem[2], Line=CurrentLineOfItem[1], ExtraData=CurrentLineOfItem[0]) if len(Item) >= 1: # # Validate file name exist. # FullFileName = os.path.normpath( os.path.realpath( os.path.join(GlobalData.gINF_MODULE_DIR, Item[0]))) if not (ValidFile(FullFileName) or ValidFile(Item[0])): Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_FILELIST_EXIST % (Item[0]), File=CurrentLineOfItem[2], Line=CurrentLineOfItem[1], ExtraData=CurrentLineOfItem[0]) # # Validate file exist/format. # if IsValidPath(Item[0], GlobalData.gINF_MODULE_DIR): IsValidFileFlag = True else: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID % (Item[0]), File=CurrentLineOfItem[2], Line=CurrentLineOfItem[1], ExtraData=CurrentLineOfItem[0]) return False if IsValidFileFlag: ItemObj.SetSourceFileName(Item[0]) else: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_SOURCES_SECTION_CONTENT_ERROR, File=CurrentLineOfItem[2], Line=CurrentLineOfItem[1], ExtraData=CurrentLineOfItem[0]) return ItemObj
def IniToXml(IniFile): if not os.path.exists(IniFile): Logger.Error("UPT", FILE_NOT_FOUND, ST.ERR_TEMPLATE_NOTFOUND % IniFile) DistMap = {'ReadOnly' : '', 'RePackage' : '', 'Name' : '', 'BaseName' : '', 'GUID' : '', 'Version' : '', 'Vendor' : '', 'Date' : '', 'Copyright' : '', 'License' : '', 'Abstract' : '', 'Description' : '', 'Signature' : '', 'XmlSpecification' : '' } ToolsMap = {'Name' : '', 'Copyright' : '', 'License' : '', 'Abstract' : '', 'Description' : '', 'FileList' : []} # # Only FileList is a list: [['file1', {}], ['file2', {}], ...] # MiscMap = {'Name' : '', 'Copyright' : '', 'License' : '', 'Abstract' : '', 'Description' : '', 'FileList' : []} SectionMap = { 'DistributionHeader' : DistMap, 'ToolsHeader' : ToolsMap, 'MiscellaneousFilesHeader' : MiscMap } PathValidator = { 'ToolsHeader' : ValidateToolsFile, 'MiscellaneousFilesHeader' : ValidateMiscFile } ParsedSection = [] SectionName = '' CurrentKey = '' PreMap = None Map = None FileContent = ConvertSpecialChar(open(IniFile, 'r').readlines()) LastIndex = 0 for Index in range(0, len(FileContent)): LastIndex = Index Line = FileContent[Index].strip() if Line == '' or Line.startswith(';'): continue if Line[0] == TAB_SECTION_START and Line[-1] == TAB_SECTION_END: CurrentKey = '' SectionName = Line[1:-1].strip() if SectionName not in SectionMap: IniParseError(ST.ERR_SECTION_NAME_INVALID % SectionName, IniFile, Index+1) if SectionName in ParsedSection: IniParseError(ST.ERR_SECTION_REDEFINE % SectionName, IniFile, Index+1) else: ParsedSection.append(SectionName) Map = SectionMap[SectionName] continue if not Map: IniParseError(ST.ERR_SECTION_NAME_NONE, IniFile, Index+1) TokenList = Line.split(TAB_EQUAL_SPLIT, 1) TempKey = TokenList[0].strip() # # Value spanned multiple or same keyword appears more than one time # if len(TokenList) < 2 or TempKey not in Map: if CurrentKey == '': IniParseError(ST.ERR_KEYWORD_INVALID % TempKey, IniFile, Index+1) elif CurrentKey == 'FileList': # # Special for FileList # Valid, Cause = ParseFileList(Line, Map, CurrentKey, PathValidator[SectionName]) if not Valid: IniParseError(Cause, IniFile, Index+1) else: # # Multiple lines for one key such as license # Or if string on the left side of '=' is not a keyword # Map[CurrentKey] = ''.join([Map[CurrentKey], '\n', Line]) Valid, Cause = ValidateValues(CurrentKey, Map[CurrentKey], SectionName) if not Valid: IniParseError(Cause, IniFile, Index+1) continue if (TokenList[1].strip() == ''): IniParseError(ST.ERR_EMPTY_VALUE, IniFile, Index+1) # # A keyword found # CurrentKey = TempKey if Map[CurrentKey]: IniParseError(ST.ERR_KEYWORD_REDEFINE % CurrentKey, IniFile, Index+1) if id(Map) != id(PreMap) and Map['Copyright']: PreMap = Map Copyright = Map['Copyright'].lower() Pos = Copyright.find('copyright') if Pos == -1: IniParseError(ST.ERR_COPYRIGHT_CONTENT, IniFile, Index) if not Copyright[Pos + len('copyright'):].lstrip(' ').startswith('('): IniParseError(ST.ERR_COPYRIGHT_CONTENT, IniFile, Index) if CurrentKey == 'FileList': Valid, Cause = ParseFileList(TokenList[1], Map, CurrentKey, PathValidator[SectionName]) if not Valid: IniParseError(Cause, IniFile, Index+1) else: Map[CurrentKey] = TokenList[1].strip() Valid, Cause = ValidateValues(CurrentKey, Map[CurrentKey], SectionName) if not Valid: IniParseError(Cause, IniFile, Index+1) if id(Map) != id(PreMap) and Map['Copyright'] and 'copyright' not in Map['Copyright'].lower(): IniParseError(ST.ERR_COPYRIGHT_CONTENT, IniFile, LastIndex) # # Check mandatory keys # CheckMdtKeys(DistMap, IniFile, LastIndex, (('ToolsHeader', ToolsMap), ('MiscellaneousFilesHeader', MiscMap)) ) return CreateXml(DistMap, ToolsMap, MiscMap, IniFile)
def InfPpiParser(self, SectionString, InfSectionObject, FileName): # # Macro defined in this section # SectionMacros = {} ValueList = [] PpiList = [] CommentsList = [] CurrentLineVar = None # # Parse section content # for Line in SectionString: LineContent = Line[0] LineNo = Line[1] if LineContent.strip() == '': CommentsList = [] continue if LineContent.strip().startswith(DT.TAB_COMMENT_SPLIT): CommentsList.append(Line) continue else: # # Encounter a PPI entry # if LineContent.find(DT.TAB_COMMENT_SPLIT) > -1: CommentsList.append( (LineContent[LineContent.find(DT.TAB_COMMENT_SPLIT):], LineNo)) LineContent = \ LineContent[:LineContent.find(DT.TAB_COMMENT_SPLIT)] if LineContent != '': # # Find Macro # Name, Value = MacroParser((LineContent, LineNo), FileName, DT.MODEL_EFI_PPI, self.FileLocalMacros) if Name is not None: SectionMacros[Name] = Value ValueList = [] CommentsList = [] continue TokenList = GetSplitValueList(LineContent, DT.TAB_VALUE_SPLIT, 1) ValueList[0:len(TokenList)] = TokenList # # Replace with Local section Macro and [Defines] section Macro. # ValueList = [ InfExpandMacro(Value, (FileName, LineContent, LineNo), self.FileLocalMacros, SectionMacros) for Value in ValueList ] CurrentLineVar = (LineContent, LineNo, FileName) if len(ValueList) >= 1: PpiList.append((ValueList, CommentsList, CurrentLineVar)) ValueList = [] CommentsList = [] continue # # Current section archs # ArchList = [] LineIndex = -1 for Item in self.LastSectionHeaderContent: LineIndex = Item[3] if Item[1] not in ArchList: ArchList.append(Item[1]) if not InfSectionObject.SetPpi(PpiList, Arch=ArchList): Logger.Error('InfParser', FORMAT_INVALID, ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % ("[Ppis]"), File=FileName, Line=LineIndex)
def Parse(self): HeadComments = [] TailComments = [] #====================================================================== # CurComments may pointer to HeadComments or TailComments #====================================================================== CurComments = HeadComments CurObj = None ItemNum = 0 FromBuf = False #====================================================================== # Used to report error information if empty section found #====================================================================== Index = self._RawData.LineIndex LineStr = self._RawData.CurrentLine while not self._RawData.IsEndOfFile() or self._RawData.NextLine: if self._RawData.NextLine: #============================================================== # Have processed line in buffer #============================================================== Line = self._RawData.NextLine HeadComments.extend(self._RawData.HeadComment) TailComments.extend(self._RawData.TailComment) self._RawData.ResetNext() Comment = '' FromBuf = True else: #============================================================== # No line in buffer, read next line #============================================================== Line, Comment = CleanString(self._RawData.GetNextLine()) FromBuf = False if Line: if not FromBuf and CurObj and TailComments: #========================================================== # Set tail comments to previous statement if not empty. #========================================================== CurObj.SetTailComment(CurObj.GetTailComment() + TailComments) if not FromBuf: del TailComments[:] CurComments = TailComments Comments = [] if Comment: Comments = [(Comment, self._RawData.LineIndex)] #============================================================== # Try if last char of line has backslash #============================================================== Line, Comments = self._TryBackSlash(Line, Comments) CurComments.extend(Comments) #============================================================== # Macro found #============================================================== if Line.startswith('DEFINE '): self._MacroParser(Line) del HeadComments[:] del TailComments[:] CurComments = HeadComments continue if self._StopCurrentParsing(Line): #========================================================== # This line does not belong to this parse, # Save it, can be used by next parse #========================================================== self._RawData.SetNext(Line, HeadComments, TailComments) break Obj = self._ParseItem() ItemNum += 1 if Obj: Obj.SetHeadComment(Obj.GetHeadComment() + HeadComments) Obj.SetTailComment(Obj.GetTailComment() + TailComments) del HeadComments[:] del TailComments[:] CurObj = Obj else: CurObj = None else: if id(CurComments) == id(TailComments): #========================================================== # Check if this comment belongs to tail comment #========================================================== if not self._TailCommentStrategy(Comment): CurComments = HeadComments if Comment: CurComments.append(((Comment, self._RawData.LineIndex))) else: del CurComments[:] if self._IsStatementRequired() and ItemNum == 0: Logger.Error(TOOL_NAME, FILE_PARSE_FAILURE, File=self._RawData.Filename, Line=Index, ExtraData=ST.ERR_DECPARSE_STATEMENT_EMPTY % LineStr)
def InfSourceParser(self, SectionString, InfSectionObject, FileName): SectionMacros = {} ValueList = [] SourceList = [] StillCommentFalg = False HeaderComments = [] LineComment = None SectionContent = '' for Line in SectionString: SrcLineContent = Line[0] SrcLineNo = Line[1] if SrcLineContent.strip() == '': continue # # Found Header Comments # if SrcLineContent.strip().startswith(DT.TAB_COMMENT_SPLIT): # # Last line is comments, and this line go on. # if StillCommentFalg: HeaderComments.append(Line) SectionContent += SrcLineContent + DT.END_OF_LINE continue # # First time encounter comment # else: # # Clear original data # HeaderComments = [] HeaderComments.append(Line) StillCommentFalg = True SectionContent += SrcLineContent + DT.END_OF_LINE continue else: StillCommentFalg = False if len(HeaderComments) >= 1: LineComment = InfLineCommentObject() LineCommentContent = '' for Item in HeaderComments: LineCommentContent += Item[0] + DT.END_OF_LINE LineComment.SetHeaderComments(LineCommentContent) # # Find Tail comment. # if SrcLineContent.find(DT.TAB_COMMENT_SPLIT) > -1: TailComments = SrcLineContent[SrcLineContent. find(DT.TAB_COMMENT_SPLIT):] SrcLineContent = SrcLineContent[:SrcLineContent. find(DT.TAB_COMMENT_SPLIT)] if LineComment == None: LineComment = InfLineCommentObject() LineComment.SetTailComments(TailComments) # # Find Macro # Name, Value = MacroParser((SrcLineContent, SrcLineNo), FileName, DT.MODEL_EFI_SOURCE_FILE, self.FileLocalMacros) if Name != None: SectionMacros[Name] = Value LineComment = None HeaderComments = [] continue # # Replace with Local section Macro and [Defines] section Macro. # SrcLineContent = InfExpandMacro( SrcLineContent, (FileName, SrcLineContent, SrcLineNo), self.FileLocalMacros, SectionMacros) TokenList = GetSplitValueList(SrcLineContent, DT.TAB_VALUE_SPLIT, 4) ValueList[0:len(TokenList)] = TokenList # # Store section content string after MACRO replaced. # SectionContent += SrcLineContent + DT.END_OF_LINE SourceList.append((ValueList, LineComment, (SrcLineContent, SrcLineNo, FileName))) ValueList = [] LineComment = None TailComments = '' HeaderComments = [] continue # # Current section archs # ArchList = [] for Item in self.LastSectionHeaderContent: if Item[1] not in ArchList: ArchList.append(Item[1]) InfSectionObject.SetSupArchList(Item[1]) InfSectionObject.SetAllContent(SectionContent) if not InfSectionObject.SetSources(SourceList, Arch=ArchList): Logger.Error('InfParser', FORMAT_INVALID, ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % ("[Sources]"), File=FileName, Line=Item[3])
ReturnCode = XExcept.args[0] if Logger.GetLevel() <= Logger.DEBUG_9: Logger.Quiet(ST.MSG_PYTHON_ON % \ (python_version(), platform) + format_exc()) except KeyboardInterrupt: ReturnCode = ABORT_ERROR if Logger.GetLevel() <= Logger.DEBUG_9: Logger.Quiet(ST.MSG_PYTHON_ON % \ (python_version(), platform) + format_exc()) except OSError: pass except: Logger.Error( "\nMkPkg", CODE_ERROR, ST.ERR_UNKNOWN_FATAL_CREATING_ERR % \ Options.PackFileToCreate, ExtraData=ST.MSG_SEARCH_FOR_HELP, RaiseError=False ) Logger.Quiet(ST.MSG_PYTHON_ON % \ (python_version(), platform) + format_exc()) ReturnCode = CODE_ERROR finally: if os.path.exists(GlobalData.gCONTENT_FILE): if not ContentFileClosed: ContentFile.Close() os.remove(GlobalData.gCONTENT_FILE) return ReturnCode
def AddDPObject(self, DpObj, NewDpPkgFileName, DpPkgFileName, RePackage): try: for PkgKey in DpObj.PackageSurfaceArea.keys(): PkgGuid = PkgKey[0] PkgVersion = PkgKey[1] PkgInstallPath = PkgKey[2] self._AddPackage(PkgGuid, PkgVersion, DpObj.Header.GetGuid(), \ DpObj.Header.GetVersion(), PkgInstallPath) PkgObj = DpObj.PackageSurfaceArea[PkgKey] for ModKey in PkgObj.GetModuleDict().keys(): ModGuid = ModKey[0] ModVersion = ModKey[1] ModName = ModKey[2] ModInstallPath = ModKey[3] ModInstallPath = \ os.path.normpath(os.path.join(PkgInstallPath, ModInstallPath)) self._AddModuleInPackage(ModGuid, ModVersion, ModName, PkgGuid, \ PkgVersion, ModInstallPath) ModObj = PkgObj.GetModuleDict()[ModKey] for Dep in ModObj.GetPackageDependencyList(): DepexGuid = Dep.GetGuid() DepexVersion = Dep.GetVersion() self._AddModuleDepex(ModGuid, ModVersion, ModName, ModInstallPath, \ DepexGuid, DepexVersion) for (FilePath, Md5Sum) in PkgObj.FileList: self._AddDpFilePathList(DpObj.Header.GetGuid(), \ DpObj.Header.GetVersion(), FilePath, \ Md5Sum) for ModKey in DpObj.ModuleSurfaceArea.keys(): ModGuid = ModKey[0] ModVersion = ModKey[1] ModName = ModKey[2] ModInstallPath = ModKey[3] self._AddStandaloneModule(ModGuid, ModVersion, ModName, \ DpObj.Header.GetGuid(), \ DpObj.Header.GetVersion(), \ ModInstallPath) ModObj = DpObj.ModuleSurfaceArea[ModKey] for Dep in ModObj.GetPackageDependencyList(): DepexGuid = Dep.GetGuid() DepexVersion = Dep.GetVersion() self._AddModuleDepex(ModGuid, ModVersion, ModName, ModInstallPath, \ DepexGuid, DepexVersion) for (Path, Md5Sum) in ModObj.FileList: self._AddDpFilePathList(DpObj.Header.GetGuid(), \ DpObj.Header.GetVersion(), \ Path, Md5Sum) # # add tool/misc files # for (Path, Md5Sum) in DpObj.FileList: self._AddDpFilePathList(DpObj.Header.GetGuid(), \ DpObj.Header.GetVersion(), Path, Md5Sum) self._AddDp(DpObj.Header.GetGuid(), DpObj.Header.GetVersion(), \ NewDpPkgFileName, DpPkgFileName, RePackage) except sqlite3.IntegrityError, DetailMsg: Logger.Error("UPT", UPT_DB_UPDATE_ERROR, ST.ERR_UPT_DB_UPDATE_ERROR, ExtraData = DetailMsg )
def InfPackageParser(self, SectionString, InfSectionObject, FileName): # # Macro defined in this section # SectionMacros = {} ValueList = [] PackageList = [] StillCommentFalg = False HeaderComments = [] LineComment = None # # Parse section content # for Line in SectionString: PkgLineContent = Line[0] PkgLineNo = Line[1] if PkgLineContent.strip() == '': continue # # Find Header Comments # if PkgLineContent.strip().startswith(DT.TAB_COMMENT_SPLIT): # # Last line is comments, and this line go on. # if StillCommentFalg: HeaderComments.append(Line) continue # # First time encounter comment # else: # # Clear original data # HeaderComments = [] HeaderComments.append(Line) StillCommentFalg = True continue else: StillCommentFalg = False if len(HeaderComments) >= 1: LineComment = InfLineCommentObject() LineCommentContent = '' for Item in HeaderComments: LineCommentContent += Item[0] + DT.END_OF_LINE LineComment.SetHeaderComments(LineCommentContent) # # Find Tail comment. # if PkgLineContent.find(DT.TAB_COMMENT_SPLIT) > -1: TailComments = PkgLineContent[PkgLineContent. find(DT.TAB_COMMENT_SPLIT):] PkgLineContent = PkgLineContent[:PkgLineContent. find(DT.TAB_COMMENT_SPLIT)] if LineComment == None: LineComment = InfLineCommentObject() LineComment.SetTailComments(TailComments) # # Find Macro # Name, Value = MacroParser((PkgLineContent, PkgLineNo), FileName, DT.MODEL_META_DATA_PACKAGE, self.FileLocalMacros) if Name != None: SectionMacros[Name] = Value LineComment = None HeaderComments = [] continue TokenList = GetSplitValueList(PkgLineContent, DT.TAB_VALUE_SPLIT, 1) ValueList[0:len(TokenList)] = TokenList # # Replace with Local section Macro and [Defines] section Macro. # ValueList = [ InfExpandMacro(Value, (FileName, PkgLineContent, PkgLineNo), self.FileLocalMacros, SectionMacros, True) for Value in ValueList ] PackageList.append((ValueList, LineComment, (PkgLineContent, PkgLineNo, FileName))) ValueList = [] LineComment = None TailComments = '' HeaderComments = [] continue # # Current section archs # ArchList = [] for Item in self.LastSectionHeaderContent: if Item[1] not in ArchList: ArchList.append(Item[1]) if not InfSectionObject.SetPackages(PackageList, Arch=ArchList): Logger.Error('InfParser', FORMAT_INVALID, ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR\ %("[Packages]"), File=FileName, Line=Item[3])
def InfBinaryParser(self, SectionString, InfSectionObject, FileName): # # Macro defined in this section # SectionMacros = {} ValueList = [] # # For UI (UI, SEC_UI, UNI_UI) binaries # One and only one UI section can be included # UiBinaryList = [] # # For Version (VER, SEC_VER, UNI_VER). # One and only one VER section on be included # VerBinaryList = [] # # For other common type binaries # ComBinaryList = [] StillCommentFalg = False HeaderComments = [] LineComment = None AllSectionContent = '' # # Parse section content # for Line in SectionString: BinLineContent = Line[0] BinLineNo = Line[1] if BinLineContent.strip() == '': continue CurrentLineObj = CurrentLine() CurrentLineObj.FileName = FileName CurrentLineObj.LineString = BinLineContent CurrentLineObj.LineNo = BinLineNo # # Found Header Comments # if BinLineContent.strip().startswith(DT.TAB_COMMENT_SPLIT): # # Last line is comments, and this line go on. # if StillCommentFalg: HeaderComments.append(Line) AllSectionContent += BinLineContent + DT.END_OF_LINE continue # # First time encounter comment # else: # # Clear original data # HeaderComments = [] HeaderComments.append(Line) AllSectionContent += BinLineContent + DT.END_OF_LINE StillCommentFalg = True continue else: StillCommentFalg = False if len(HeaderComments) >= 1: LineComment = InfLineCommentObject() LineCommentContent = '' for Item in HeaderComments: LineCommentContent += Item[0] + DT.END_OF_LINE LineComment.SetHeaderComments(LineCommentContent) # # Find Tail comment. # if BinLineContent.find(DT.TAB_COMMENT_SPLIT) > -1: TailComments = BinLineContent[BinLineContent. find(DT.TAB_COMMENT_SPLIT):] BinLineContent = BinLineContent[:BinLineContent. find(DT.TAB_COMMENT_SPLIT)] if LineComment == None: LineComment = InfLineCommentObject() LineComment.SetTailComments(TailComments) # # Find Macro # MacroDef = MacroParser((BinLineContent, BinLineNo), FileName, DT.MODEL_EFI_BINARY_FILE, self.FileLocalMacros) if MacroDef[0] != None: SectionMacros[MacroDef[0]] = MacroDef[1] LineComment = None HeaderComments = [] continue # # Replace with Local section Macro and [Defines] section Macro. # LineContent = InfExpandMacro(BinLineContent, (FileName, BinLineContent, BinLineNo), self.FileLocalMacros, SectionMacros, True) AllSectionContent += LineContent + DT.END_OF_LINE TokenList = GetSplitValueList(LineContent, DT.TAB_VALUE_SPLIT, 1) ValueList[0:len(TokenList)] = TokenList # # Should equal to UI/SEC_UI/UNI_UI # ValueList[0] = ValueList[0].strip() if ValueList[0] == DT.BINARY_FILE_TYPE_UNI_UI or \ ValueList[0] == DT.BINARY_FILE_TYPE_SEC_UI or \ ValueList[0] == DT.BINARY_FILE_TYPE_UI: if len(ValueList) == 2: TokenList = GetSplitValueList(ValueList[1], DT.TAB_VALUE_SPLIT, 2) NewValueList = [] NewValueList.append(ValueList[0]) for Item in TokenList: NewValueList.append(Item) UiBinaryList.append( (NewValueList, LineComment, CurrentLineObj)) # # Should equal to VER/SEC_VER/UNI_VER # elif ValueList[0] == DT.BINARY_FILE_TYPE_UNI_VER or \ ValueList[0] == DT.BINARY_FILE_TYPE_SEC_VER or \ ValueList[0] == DT.BINARY_FILE_TYPE_VER: if len(ValueList) == 2: TokenList = GetSplitValueList(ValueList[1], DT.TAB_VALUE_SPLIT, 2) NewValueList = [] NewValueList.append(ValueList[0]) for Item in TokenList: NewValueList.append(Item) VerBinaryList.append( (NewValueList, LineComment, CurrentLineObj)) else: if len(ValueList) == 2: if ValueList[0].strip() == 'SUBTYPE_GUID': TokenList = GetSplitValueList(ValueList[1], DT.TAB_VALUE_SPLIT, 5) else: TokenList = GetSplitValueList(ValueList[1], DT.TAB_VALUE_SPLIT, 4) NewValueList = [] NewValueList.append(ValueList[0]) for Item in TokenList: NewValueList.append(Item) ComBinaryList.append( (NewValueList, LineComment, CurrentLineObj)) elif len(ValueList) == 1: NewValueList = [] NewValueList.append(ValueList[0]) ComBinaryList.append( (NewValueList, LineComment, CurrentLineObj)) ValueList = [] LineComment = None TailComments = '' HeaderComments = [] continue # # Current section archs # ArchList = [] for Item in self.LastSectionHeaderContent: if Item[1] not in ArchList: ArchList.append(Item[1]) InfSectionObject.SetSupArchList(Item[1]) InfSectionObject.SetAllContent(AllSectionContent) if not InfSectionObject.SetBinary(UiBinaryList, VerBinaryList, ComBinaryList, ArchList): Logger.Error('InfParser', FORMAT_INVALID, ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % ("[Binaries]"), File=FileName, Line=Item[3])
def AssertEnd(self, ErrorString, ErrorLineNum): self.__SkipWhitespace() if self._Index != self._StrLen: Logger.Error(TOOL_NAME, FILE_PARSE_FAILURE, File=self._File, Line=ErrorLineNum, ExtraData=ErrorString)
def GetDistributionPackage(self, WorkspaceDir, PackageList, ModuleList): # Backup WorkspaceDir Root = WorkspaceDir # # Get Packages # if PackageList: for PackageFile in PackageList: PackageFileFullPath = mws.join(Root, PackageFile) WorkspaceDir = mws.getWs(Root, PackageFile) DecObj = DecPomAlignment(PackageFileFullPath, WorkspaceDir, CheckMulDec=True) PackageObj = DecObj # # Parser inf file one bye one # ModuleInfFileList = PackageObj.GetModuleFileList() for File in ModuleInfFileList: WsRelPath = os.path.join(PackageObj.GetPackagePath(), File) WsRelPath = os.path.normpath(WsRelPath) if ModuleList and WsRelPath in ModuleList: Logger.Error("UPT", OPTION_VALUE_INVALID, ST.ERR_NOT_STANDALONE_MODULE_ERROR%\ (WsRelPath, PackageFile)) Filename = os.path.normpath\ (os.path.join(PackageObj.GetRelaPath(), File)) os.path.splitext(Filename) # # Call INF parser to generate Inf Object. # Actually, this call is not directly call, but wrapped by # Inf class in InfPomAlignment. # try: ModuleObj = InfPomAlignment( Filename, WorkspaceDir, PackageObj.GetPackagePath()) # # Add module to package # ModuleDict = PackageObj.GetModuleDict() ModuleDict[(ModuleObj.GetGuid(), \ ModuleObj.GetVersion(), \ ModuleObj.GetName(), \ ModuleObj.GetCombinePath())] = ModuleObj PackageObj.SetModuleDict(ModuleDict) except FatalError as ErrCode: if ErrCode.message == EDK1_INF_ERROR: Logger.Warn("UPT", ST.WRN_EDK1_INF_FOUND % Filename) else: raise self.PackageSurfaceArea\ [(PackageObj.GetGuid(), PackageObj.GetVersion(), \ PackageObj.GetCombinePath())] = PackageObj # # Get Modules # if ModuleList: for ModuleFile in ModuleList: ModuleFileFullPath = mws.join(Root, ModuleFile) WorkspaceDir = mws.getWs(Root, ModuleFile) try: ModuleObj = InfPomAlignment(ModuleFileFullPath, WorkspaceDir) ModuleKey = (ModuleObj.GetGuid(), ModuleObj.GetVersion(), ModuleObj.GetName(), ModuleObj.GetCombinePath()) self.ModuleSurfaceArea[ModuleKey] = ModuleObj except FatalError as ErrCode: if ErrCode.message == EDK1_INF_ERROR: Logger.Error("UPT", EDK1_INF_ERROR, ST.WRN_EDK1_INF_FOUND % ModuleFileFullPath, ExtraData=ST.ERR_NOT_SUPPORTED_SA_MODULE) else: raise # Recover WorkspaceDir WorkspaceDir = Root
def AssertChar(self, AssertChar, ErrorString, ErrorLineNum): if not self.Expect(AssertChar): Logger.Error(TOOL_NAME, FILE_PARSE_FAILURE, File=self._File, Line=ErrorLineNum, ExtraData=ErrorString)
def ParseDecComment(self): IsFileHeader = False IsBinaryHeader = False FileHeaderLineIndex = -1 BinaryHeaderLineIndex = -1 while not self._RawData.IsEndOfFile(): Line, Comment = CleanString(self._RawData.GetNextLine()) # # Header must be pure comment # if Line != '': self._RawData.UndoNextLine() break if Comment and Comment.startswith(DT.TAB_SPECIAL_COMMENT) and Comment.find(DT.TAB_HEADER_COMMENT) > 0 \ and not Comment[2:Comment.find(DT.TAB_HEADER_COMMENT)].strip(): IsFileHeader = True IsBinaryHeader = False FileHeaderLineIndex = self._RawData.LineIndex # # Get license information before '@file' # if not IsFileHeader and not IsBinaryHeader and Comment and Comment.startswith(DT.TAB_COMMENT_SPLIT) and \ DT.TAB_BINARY_HEADER_COMMENT not in Comment: self._HeadComment.append((Comment, self._RawData.LineIndex)) if Comment and IsFileHeader and \ not(Comment.startswith(DT.TAB_SPECIAL_COMMENT) \ and Comment.find(DT.TAB_BINARY_HEADER_COMMENT) > 0): self._HeadComment.append((Comment, self._RawData.LineIndex)) # # Double '#' indicates end of header comments # if (not Comment or Comment == DT.TAB_SPECIAL_COMMENT) and IsFileHeader: IsFileHeader = False continue if Comment and Comment.startswith(DT.TAB_SPECIAL_COMMENT) \ and Comment.find(DT.TAB_BINARY_HEADER_COMMENT) > 0: IsBinaryHeader = True IsFileHeader = False BinaryHeaderLineIndex = self._RawData.LineIndex if Comment and IsBinaryHeader: self.BinaryHeadComment.append( (Comment, self._RawData.LineIndex)) # # Double '#' indicates end of header comments # if (not Comment or Comment == DT.TAB_SPECIAL_COMMENT) and IsBinaryHeader: IsBinaryHeader = False break if FileHeaderLineIndex > -1 and not IsFileHeader and not IsBinaryHeader: break if FileHeaderLineIndex > BinaryHeaderLineIndex and FileHeaderLineIndex > -1 and BinaryHeaderLineIndex > -1: self._LoggerError(ST.ERR_BINARY_HEADER_ORDER) if FileHeaderLineIndex == -1: Logger.Error(TOOL_NAME, FORMAT_INVALID, ST.ERR_NO_SOURCE_HEADER, File=self._RawData.Filename) return
def _LoggerError(self, ErrorString): Logger.Error(TOOL_NAME, FILE_PARSE_FAILURE, File=self._RawData.Filename, Line = self._RawData.LineIndex, ExtraData=ErrorString + ST.ERR_DECPARSE_LINE % self._RawData.CurrentLine)
def _CallSectionParsers(self, CurrentSection, DefineSectionParsedFlag, SectionLines, InfSectionCommonDefObj, LineNo): if CurrentSection == DT.MODEL_META_DATA_DEFINE: if not DefineSectionParsedFlag: self.InfDefineParser(SectionLines, self.InfDefSection, self.FullPath, InfSectionCommonDefObj) DefineSectionParsedFlag = True else: Logger.Error("Parser", PARSER_ERROR, ST.ERR_INF_PARSER_MULTI_DEFINE_SECTION, File=self.FullPath, RaiseError=Logger.IS_RAISE_ERROR) elif CurrentSection == DT.MODEL_META_DATA_BUILD_OPTION: self.InfBuildOptionParser(SectionLines, self.InfBuildOptionSection, self.FullPath) elif CurrentSection == DT.MODEL_EFI_LIBRARY_CLASS: self.InfLibraryParser(SectionLines, self.InfLibraryClassSection, self.FullPath) elif CurrentSection == DT.MODEL_META_DATA_PACKAGE: self.InfPackageParser(SectionLines, self.InfPackageSection, self.FullPath) # # [Pcd] Sections, put it together # elif CurrentSection == DT.MODEL_PCD_FIXED_AT_BUILD or \ CurrentSection == DT.MODEL_PCD_PATCHABLE_IN_MODULE or \ CurrentSection == DT.MODEL_PCD_FEATURE_FLAG or \ CurrentSection == DT.MODEL_PCD_DYNAMIC_EX or \ CurrentSection == DT.MODEL_PCD_DYNAMIC: self.InfPcdParser(SectionLines, self.InfPcdSection, self.FullPath) elif CurrentSection == DT.MODEL_EFI_SOURCE_FILE: self.InfSourceParser(SectionLines, self.InfSourcesSection, self.FullPath) elif CurrentSection == DT.MODEL_META_DATA_USER_EXTENSION: self.InfUserExtensionParser(SectionLines, self.InfUserExtensionSection, self.FullPath) elif CurrentSection == DT.MODEL_EFI_PROTOCOL: self.InfProtocolParser(SectionLines, self.InfProtocolSection, self.FullPath) elif CurrentSection == DT.MODEL_EFI_PPI: self.InfPpiParser(SectionLines, self.InfPpiSection, self.FullPath) elif CurrentSection == DT.MODEL_EFI_GUID: self.InfGuidParser(SectionLines, self.InfGuidSection, self.FullPath) elif CurrentSection == DT.MODEL_EFI_DEPEX: self.InfDepexParser(SectionLines, self.InfDepexSection, self.FullPath) elif CurrentSection == DT.MODEL_EFI_BINARY_FILE: self.InfBinaryParser(SectionLines, self.InfBinariesSection, self.FullPath) # # Unknown section type found, raise error. # else: if len(self.SectionHeaderContent) >= 1: Logger.Error("Parser", PARSER_ERROR, ST.ERR_INF_PARSER_UNKNOWN_SECTION, File=self.FullPath, Line=LineNo, RaiseError=Logger.IS_RAISE_ERROR) else: Logger.Error("Parser", PARSER_ERROR, ST.ERR_INF_PARSER_NO_SECTION_ERROR, File=self.FullPath, Line=LineNo, RaiseError=Logger.IS_RAISE_ERROR) return DefineSectionParsedFlag
def SetPackages(self, PackageData, Arch=None): IsValidFileFlag = False SupArchList = [] for ArchItem in Arch: # # Validate Arch # if (ArchItem == '' or ArchItem is None): ArchItem = 'COMMON' SupArchList.append(ArchItem) for PackageItem in PackageData: PackageItemObj = InfPackageItem() HelpStringObj = PackageItem[1] CurrentLineOfPackItem = PackageItem[2] PackageItem = PackageItem[0] if HelpStringObj is not None: HelpString = HelpStringObj.HeaderComments + HelpStringObj.TailComments PackageItemObj.SetHelpString(HelpString) if len(PackageItem) >= 1: # # Validate file exist/format. # if IsValidPath(PackageItem[0], ''): IsValidFileFlag = True elif IsValidPath(PackageItem[0], GlobalData.gINF_MODULE_DIR): IsValidFileFlag = True elif IsValidPath(PackageItem[0], GlobalData.gWORKSPACE): IsValidFileFlag = True else: Logger.Error( "InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID % (PackageItem[0]), File=CurrentLineOfPackItem[2], Line=CurrentLineOfPackItem[1], ExtraData=CurrentLineOfPackItem[0]) return False if IsValidFileFlag: PackageItemObj.SetPackageName(PackageItem[0]) if len(PackageItem) == 2: # # Validate Feature Flag Express # if PackageItem[1].strip() == '': Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING, File=CurrentLineOfPackItem[2], Line=CurrentLineOfPackItem[1], ExtraData=CurrentLineOfPackItem[0]) # # Validate FFE # FeatureFlagRtv = IsValidFeatureFlagExp(PackageItem[1].strip()) if not FeatureFlagRtv[0]: Logger.Error( "InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID % (FeatureFlagRtv[1]), File=CurrentLineOfPackItem[2], Line=CurrentLineOfPackItem[1], ExtraData=CurrentLineOfPackItem[0]) PackageItemObj.SetFeatureFlagExp(PackageItem[1].strip()) if len(PackageItem) > 2: # # Invalid format of Package statement # Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_PACKAGE_SECTION_CONTENT_ERROR, File=CurrentLineOfPackItem[2], Line=CurrentLineOfPackItem[1], ExtraData=CurrentLineOfPackItem[0]) PackageItemObj.SetSupArchList(SupArchList) # # Determine package file name duplicate. Follow below rule: # # A package filename must not be duplicated within a [Packages] # section. Package filenames may appear in multiple architectural # [Packages] sections. A package filename listed in an # architectural [Packages] section must not be listed in the common # architectural [Packages] section. # # NOTE: This check will not report error now. # for Item in self.Packages: if Item.GetPackageName() == PackageItemObj.GetPackageName(): ItemSupArchList = Item.GetSupArchList() for ItemArch in ItemSupArchList: for PackageItemObjArch in SupArchList: if ItemArch == PackageItemObjArch: # # ST.ERR_INF_PARSER_ITEM_DUPLICATE # pass if ItemArch.upper( ) == 'COMMON' or PackageItemObjArch.upper( ) == 'COMMON': # # ST.ERR_INF_PARSER_ITEM_DUPLICATE_COMMON # pass if (PackageItemObj) in self.Packages: PackageList = self.Packages[PackageItemObj] PackageList.append(PackageItemObj) self.Packages[PackageItemObj] = PackageList else: PackageList = [] PackageList.append(PackageItemObj) self.Packages[PackageItemObj] = PackageList return True
def InfLibraryParser(self, SectionString, InfSectionObject, FileName): # # For Common INF file # if not GlobalData.gIS_BINARY_INF: # # Macro defined in this section # SectionMacros = {} ValueList = [] LibraryList = [] LibStillCommentFalg = False LibHeaderComments = [] LibLineComment = None # # Parse section content # for Line in SectionString: LibLineContent = Line[0] LibLineNo = Line[1] if LibLineContent.strip() == '': continue # # Found Header Comments # if LibLineContent.strip().startswith(DT.TAB_COMMENT_SPLIT): # # Last line is comments, and this line go on. # if LibStillCommentFalg: LibHeaderComments.append(Line) continue # # First time encounter comment # else: # # Clear original data # LibHeaderComments = [] LibHeaderComments.append(Line) LibStillCommentFalg = True continue else: LibStillCommentFalg = False if len(LibHeaderComments) >= 1: LibLineComment = InfLineCommentObject() LineCommentContent = '' for Item in LibHeaderComments: LineCommentContent += Item[0] + DT.END_OF_LINE LibLineComment.SetHeaderComments(LineCommentContent) # # Find Tail comment. # if LibLineContent.find(DT.TAB_COMMENT_SPLIT) > -1: LibTailComments = LibLineContent[LibLineContent.find(DT.TAB_COMMENT_SPLIT):] LibLineContent = LibLineContent[:LibLineContent.find(DT.TAB_COMMENT_SPLIT)] if LibLineComment is None: LibLineComment = InfLineCommentObject() LibLineComment.SetTailComments(LibTailComments) # # Find Macro # Name, Value = MacroParser((LibLineContent, LibLineNo), FileName, DT.MODEL_EFI_LIBRARY_CLASS, self.FileLocalMacros) if Name is not None: SectionMacros[Name] = Value LibLineComment = None LibHeaderComments = [] continue TokenList = GetSplitValueList(LibLineContent, DT.TAB_VALUE_SPLIT, 1) ValueList[0:len(TokenList)] = TokenList # # Replace with Local section Macro and [Defines] section Macro. # ValueList = [InfExpandMacro(Value, (FileName, LibLineContent, LibLineNo), self.FileLocalMacros, SectionMacros, True) for Value in ValueList] LibraryList.append((ValueList, LibLineComment, (LibLineContent, LibLineNo, FileName))) ValueList = [] LibLineComment = None LibTailComments = '' LibHeaderComments = [] continue # # Current section archs # KeyList = [] for Item in self.LastSectionHeaderContent: if (Item[1], Item[2]) not in KeyList: KeyList.append((Item[1], Item[2])) if not InfSectionObject.SetLibraryClasses(LibraryList, KeyList=KeyList): Logger.Error('InfParser', FORMAT_INVALID, ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % ("[Library]"), File=FileName, Line=Item[3]) # # For Binary INF # else: self.InfAsBuiltLibraryParser(SectionString, InfSectionObject, FileName)
def SetDepex(self, DepexContent, KeyList=None, CommentList=None): for KeyItem in KeyList: Arch = KeyItem[0] ModuleType = KeyItem[1] InfDepexItemIns = InfDepexItem() # # Validate Arch # if IsValidArch(Arch.strip().upper()): InfDepexItemIns.SetSupArch(Arch) else: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_DEFINE_NAME_INVALID % (Arch), File=GlobalData.gINF_MODULE_NAME, Line=KeyItem[2]) # # Validate Module Type # if ModuleType and ModuleType != 'COMMON': if ModuleType in DT.VALID_DEPEX_MODULE_TYPE_LIST: InfDepexItemIns.SetModuleType(ModuleType) else: Logger.Error( "InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_DEPEX_SECTION_MODULE_TYPE_ERROR % (ModuleType), File=GlobalData.gINF_MODULE_NAME, Line=KeyItem[2]) # # Parser content in [Depex] section. # DepexString = '' HelpString = '' # # Get Depex Expression # for Line in DepexContent: LineContent = Line[0].strip() if LineContent.find(DT.TAB_COMMENT_SPLIT) > -1: LineContent = LineContent[:LineContent. find(DT.TAB_COMMENT_SPLIT)] if LineContent: DepexString = DepexString + LineContent + DT.END_OF_LINE continue if DepexString.endswith(DT.END_OF_LINE): DepexString = DepexString[:-1] if not DepexString.strip(): continue # # Get Help Text # for HelpLine in CommentList: HelpString = HelpString + HelpLine + DT.END_OF_LINE if HelpString.endswith(DT.END_OF_LINE): HelpString = HelpString[:-1] InfDepexItemIns.SetDepexConent(DepexString) InfDepexItemIns.SetHelpString(HelpString) self.Depex.append(InfDepexItemIns) return True
def Main(Options = None): if Options == None: Logger.Error("\nMkPkg", OPTION_UNKNOWN_ERROR, ST.ERR_OPTION_NOT_FOUND) try: DataBase = GlobalData.gDB ContentFileClosed = True WorkspaceDir = GlobalData.gWORKSPACE # # Init PackFileToCreate # if not Options.PackFileToCreate: Logger.Error("\nMkPkg", OPTION_UNKNOWN_ERROR, ST.ERR_OPTION_NOT_FOUND) # # Handle if the distribution package file already exists # CheckForExistingDp(Options.PackFileToCreate) # # Check package file existing and valid # CheckFileList('.DEC', Options.PackageFileList, ST.ERR_INVALID_PACKAGE_NAME, ST.ERR_INVALID_PACKAGE_PATH) # # Check module file existing and valid # CheckFileList('.INF', Options.ModuleFileList, ST.ERR_INVALID_MODULE_NAME, ST.ERR_INVALID_MODULE_PATH) # # Get list of files that installed with RePackage attribute available # RePkgDict = DataBase.GetRePkgDict() ContentFile = PackageFile(GlobalData.gCONTENT_FILE, "w") ContentFileClosed = False # # Add temp distribution header # if Options.PackageInformationDataFile: XmlFile = IniToXml(Options.PackageInformationDataFile) DistPkg = DistributionPackageXml().FromXml(XmlFile) remove(XmlFile) # # add distribution level tool/misc files # before pack, current dir should be workspace dir, else the full # path will be in the pack file # Cwd = getcwd() chdir(WorkspaceDir) ToolObject = DistPkg.Tools MiscObject = DistPkg.MiscellaneousFiles FileList = [] if ToolObject: FileList += ToolObject.GetFileList() if MiscObject: FileList += MiscObject.GetFileList() for FileObject in FileList: # # If you have unicode file names, please convert them to byte # strings in your desired encoding before passing them to # write(). # FromFile = os.path.normpath(FileObject.GetURI()).encode('utf_8') FileFullPath = os.path.normpath(os.path.join(WorkspaceDir, FromFile)) if FileFullPath in RePkgDict: (DpGuid, DpVersion, DpName, Repackage) = RePkgDict[FileFullPath] if not Repackage: Logger.Error("\nMkPkg", UPT_REPKG_ERROR, ST.ERR_UPT_REPKG_ERROR, ExtraData=ST.MSG_REPKG_CONFLICT %\ (FileFullPath, DpGuid, DpVersion, DpName) ) else: DistPkg.Header.RePackage = True ContentFile.PackFile(FromFile) chdir(Cwd) # # Add init dp information # else: DistPkg = DistributionPackageClass() DistPkg.Header.Name = 'Distribution Package' DistPkg.Header.Guid = str(uuid4()) DistPkg.Header.Version = '1.0' DistPkg.GetDistributionPackage(WorkspaceDir, Options.PackageFileList, \ Options.ModuleFileList) FileList, MetaDataFileList = DistPkg.GetDistributionFileList() for File in FileList + MetaDataFileList: FileFullPath = os.path.normpath(os.path.join(WorkspaceDir, File)) # # check whether file was included in a distribution that can not # be repackaged # if FileFullPath in RePkgDict: (DpGuid, DpVersion, DpName, Repackage) = RePkgDict[FileFullPath] if not Repackage: Logger.Error("\nMkPkg", UPT_REPKG_ERROR, ST.ERR_UPT_REPKG_ERROR, ExtraData = \ ST.MSG_REPKG_CONFLICT %(FileFullPath, DpName, \ DpGuid, DpVersion) ) else: DistPkg.Header.RePackage = True Cwd = getcwd() chdir(WorkspaceDir) ContentFile.PackFiles(FileList) chdir(Cwd) Logger.Verbose(ST.MSG_COMPRESS_DISTRIBUTION_PKG) ContentFile.Close() ContentFileClosed = True # # Add Md5Sigature # DistPkg.Header.Signature = md5.new(open(str(ContentFile), 'rb').read()).hexdigest() # # Add current Date # DistPkg.Header.Date = str(strftime("%Y-%m-%dT%H:%M:%S", localtime())) # # Finish final dp file # DistPkgFile = PackageFile(Options.PackFileToCreate, "w") DistPkgFile.PackFile(str(ContentFile)) DistPkgXml = DistributionPackageXml() DistPkgFile.PackData(DistPkgXml.ToXml(DistPkg), GlobalData.gDESC_FILE) DistPkgFile.Close() Logger.Quiet(ST.MSG_FINISH) ReturnCode = 0 except FatalError, XExcept: ReturnCode = XExcept.args[0] if Logger.GetLevel() <= Logger.DEBUG_9: Logger.Quiet(ST.MSG_PYTHON_ON % \ (python_version(), platform) + format_exc())
def SetUserExtension(self, UserExtensionCont, IdContent=None, LineNo=None): if not UserExtensionCont or UserExtensionCont == '': return True # # IdContent is a list contain UserId and IdString # For this call the general section header parser, if no definition of # IdString/UserId, it will return 'COMMON' # for IdContentItem in IdContent: InfUserExtensionItemObj = InfUserExtensionItem() if IdContentItem[0] == 'COMMON': UserId = '' else: UserId = IdContentItem[0] if IdContentItem[1] == 'COMMON': IdString = '' else: IdString = IdContentItem[1] # # Fill UserExtensionObj members. # InfUserExtensionItemObj.SetUserId(UserId) InfUserExtensionItemObj.SetIdString(IdString) InfUserExtensionItemObj.SetContent(UserExtensionCont) InfUserExtensionItemObj.SetSupArchList(IdContentItem[2]) # for CheckItem in self.UserExtension: # if IdContentItem[0] == CheckItem[0] and IdContentItem[1] == CheckItem[1]: # if IdContentItem[2].upper() == 'COMMON' or CheckItem[2].upper() == 'COMMON': # # # # For COMMON ARCH type, do special check. # # # Logger.Error('InfParser', # ToolError.FORMAT_INVALID, # ST.ERR_INF_PARSER_UE_SECTION_DUPLICATE_ERROR%\ # (IdContentItem[0] + '.' + IdContentItem[1] + '.' + IdContentItem[2]), # File=GlobalData.gINF_MODULE_NAME, # Line=LineNo, # ExtraData=None) if self.UserExtension.has_key(IdContentItem): # # Each UserExtensions section header must have a unique set # of UserId, IdString and Arch values. # This means that the same UserId can be used in more than one # section header, provided the IdString or Arch values are # different. The same IdString values can be used in more than # one section header if the UserId or Arch values are # different. The same UserId and the same IdString can be used # in a section header if the Arch values are different in each # of the section headers. # Logger.Error('InfParser', ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_UE_SECTION_DUPLICATE_ERROR%\ (IdContentItem[0] + '.' + IdContentItem[1] + '.' + IdContentItem[2]), File=GlobalData.gINF_MODULE_NAME, Line=LineNo, ExtraData=None) else: UserExtensionList = [] UserExtensionList.append(InfUserExtensionItemObj) self.UserExtension[IdContentItem] = UserExtensionList return True
def InitDatabase(self, SkipLock = False): Logger.Verbose(ST.MSG_INIT_IPI_START) if not SkipLock: try: # # Create a dummy table, if already existed, # then UPT is already running # SqlCommand = """ create table %s ( Dummy TEXT NOT NULL, PRIMARY KEY (Dummy) )""" % self.DummyTable self.Cur.execute(SqlCommand) self.Conn.commit() except sqlite3.OperationalError: Logger.Error("UPT", UPT_ALREADY_RUNNING_ERROR, ST.ERR_UPT_ALREADY_RUNNING_ERROR ) # # Create new table # SqlCommand = """ create table IF NOT EXISTS %s ( DpGuid TEXT NOT NULL,DpVersion TEXT NOT NULL, InstallTime REAL NOT NULL, NewPkgFileName TEXT NOT NULL, PkgFileName TEXT NOT NULL, RePackage TEXT NOT NULL, PRIMARY KEY (DpGuid, DpVersion) )""" % self.DpTable self.Cur.execute(SqlCommand) SqlCommand = """ create table IF NOT EXISTS %s ( FilePath TEXT NOT NULL, DpGuid TEXT, DpVersion TEXT, Md5Sum TEXT, PRIMARY KEY (FilePath) )""" % self.DpFileListTable self.Cur.execute(SqlCommand) SqlCommand = """ create table IF NOT EXISTS %s ( PackageGuid TEXT NOT NULL, PackageVersion TEXT NOT NULL, InstallTime REAL NOT NULL, DpGuid TEXT, DpVersion TEXT, InstallPath TEXT NOT NULL, PRIMARY KEY (PackageGuid, PackageVersion, InstallPath) )""" % self.PkgTable self.Cur.execute(SqlCommand) SqlCommand = """ create table IF NOT EXISTS %s ( ModuleGuid TEXT NOT NULL, ModuleVersion TEXT NOT NULL, ModuleName TEXT NOT NULL, InstallTime REAL NOT NULL, PackageGuid TEXT, PackageVersion TEXT, InstallPath TEXT NOT NULL, PRIMARY KEY (ModuleGuid, ModuleVersion, ModuleName, InstallPath) )""" % self.ModInPkgTable self.Cur.execute(SqlCommand) SqlCommand = """ create table IF NOT EXISTS %s ( ModuleGuid TEXT NOT NULL, ModuleVersion TEXT NOT NULL, ModuleName TEXT NOT NULL, InstallTime REAL NOT NULL, DpGuid TEXT, DpVersion TEXT, InstallPath TEXT NOT NULL, PRIMARY KEY (ModuleGuid, ModuleVersion, ModuleName, InstallPath) )""" % self.StandaloneModTable self.Cur.execute(SqlCommand) SqlCommand = """ create table IF NOT EXISTS %s ( ModuleGuid TEXT NOT NULL, ModuleVersion TEXT NOT NULL, ModuleName TEXT NOT NULL, InstallPath TEXT NOT NULL, DepexGuid TEXT, DepexVersion TEXT )""" % self.ModDepexTable self.Cur.execute(SqlCommand) self.Conn.commit() Logger.Verbose(ST.MSG_INIT_IPI_FINISH)
def _GenModuleHeader(self): Logger.Debug(2, "Generate ModuleHeader ...") # # Get all defines information form InfParser Object # RecordSet = self.Parser.InfDefSection.Defines # # Should only have one ArchString Item. # ArchString = RecordSet.keys()[0] ArchList = GetSplitValueList(ArchString, ' ') ArchList = ConvertArchList(ArchList) HasCalledFlag = False # # Get data from Sdict() # ValueList = RecordSet[ArchString] self.SetFileName(self.FileName) self.SetFullPath(self.FullPath) # # The INF's filename (without the directory path or the extension) # must be used for the value of the # ModuleSurfaceArea.Header.Name element # self.SetName(os.path.splitext(os.path.basename(self.FileName))[0]) self.WorkspaceDir = " " # # CombinePath and ModulePath # CombinePath = GetRelativePath(self.FullPath, self.WorkSpace) self.SetCombinePath(CombinePath) ModulePath = os.path.split(CombinePath)[0] ModuleRelativePath = ModulePath if self.GetPackagePath() != '': ModuleRelativePath = GetRelativePath(ModulePath, self.GetPackagePath()) self.SetModulePath(ModuleRelativePath) # # For Define Seciton Items. # DefineObj = ValueList # # Convert UEFI/PI version to decimal number # if DefineObj.GetUefiSpecificationVersion() != None: __UefiVersion = DefineObj.GetUefiSpecificationVersion().GetValue() __UefiVersion = ConvertVersionToDecimal(__UefiVersion) self.SetUefiSpecificationVersion(str(__UefiVersion)) if DefineObj.GetPiSpecificationVersion() != None: __PiVersion = DefineObj.GetPiSpecificationVersion().GetValue() __PiVersion = ConvertVersionToDecimal(__PiVersion) self.SetPiSpecificationVersion(str(__PiVersion)) SpecList = DefineObj.GetSpecification() NewSpecList = [] for SpecItem in SpecList: NewSpecList.append( (SpecItem[0], ConvertVersionToDecimal(SpecItem[1]))) self.SetSpecList(NewSpecList) # # must exist items in INF define section # MODULE_TYPE/BASE_NAME/INF_VERSION/FILE_GUID/VERSION_STRING # if DefineObj.GetModuleType() == None: Logger.Error("InfParser", FORMAT_INVALID, ST.ERR_INF_PARSER_DEFINE_SECTION_MUST_ITEM_NOT_EXIST % ("MODULE_TYPE"), File=self.FullPath) else: self.SetModuleType(DefineObj.GetModuleType().GetValue()) ModuleType = DefineObj.GetModuleType().GetValue() if ModuleType: # # Drivers and applications are not allowed to have a MODULE_TYPE of "BASE". Only # libraries are permitted to a have a MODULE_TYPE of "BASE". # if len(DefineObj.LibraryClass) == 0 and ModuleType == 'BASE': Logger.Error( "InfParser", FORMAT_INVALID, ST.ERR_INF_PARSER_MODULETYPE_INVALID, File=self.FullPath, Line=DefineObj.ModuleType.CurrentLine.LineNo, ExtraData=DefineObj.ModuleType.CurrentLine.LineString) self.LibModuleTypeList.append(ModuleType) if DefineObj.GetBaseName() == None: Logger.Error("InfParser", FORMAT_INVALID, ST.ERR_INF_PARSER_DEFINE_SECTION_MUST_ITEM_NOT_EXIST % ("BASE_NAME"), File=self.FullPath) else: self.SetBaseName(DefineObj.GetBaseName().GetValue()) if DefineObj.GetModuleUniFileName(): self.UniFileClassObject = UniFileClassObject( [PathClass(DefineObj.GetModuleUniFileName())]) else: self.UniFileClassObject = None if DefineObj.GetInfVersion() == None: Logger.Error("InfParser", FORMAT_INVALID, ST.ERR_INF_PARSER_DEFINE_SECTION_MUST_ITEM_NOT_EXIST % ("INF_VERSION"), File=self.FullPath) else: self.SetVersion(DefineObj.GetInfVersion().GetValue()) if DefineObj.GetFileGuid() == None: Logger.Error("InfParser", FORMAT_INVALID, ST.ERR_INF_PARSER_DEFINE_SECTION_MUST_ITEM_NOT_EXIST % ("FILE_GUID"), File=self.FullPath) else: self.SetGuid(DefineObj.GetFileGuid().GetValue()) if DefineObj.GetVersionString() == None: # # VERSION_STRING is missing from the [Defines] section, tools must assume that the module's version is 0. # self.SetVersion('0') else: # # Get version of INF # if DefineObj.GetVersionString().GetValue() != "": # # EDK2 inf # VersionString = DefineObj.GetVersionString().GetValue() if len(VersionString) > 0: VersionString = ConvertVersionToDecimal(VersionString) self.SetVersion(VersionString) else: # # EDK1 inf # Logger.Error("Parser", PARSER_ERROR, ST.ERR_INF_PARSER_NOT_SUPPORT_EDKI_INF, ExtraData=self.FullPath, RaiseError=Logger.IS_RAISE_ERROR) # # if there is Shadow, Should judge the MODULE_TYPE in # SEC, PEI_CORE and PEIM # if DefineObj.GetShadow(): ModuleTypeValue = DefineObj.GetModuleType().GetValue() if not (ModuleTypeValue == 'SEC' or ModuleTypeValue == 'PEI_CORE' or ModuleTypeValue == 'PEIM'): Logger.Error("InfParser", FORMAT_INVALID, ST.ERR_INF_PARSER_DEFINE_SHADOW_INVALID, File=self.FullPath) if DefineObj.GetPcdIsDriver() != None: self.SetPcdIsDriver(DefineObj.GetPcdIsDriver().GetValue()) # # LIBRARY_CLASS # self._GenModuleHeaderLibClass(DefineObj, ArchList) # # CUSTOM_MAKEFILE # self.CustomMakefile = DefineObj.GetCustomMakefile() # # Externs in Defines section # Only one define section, so just call once. # if not HasCalledFlag: self._GenModuleHeaderExterns(DefineObj) HasCalledFlag = True # # each module has only one module header # self.SetSupArchList(ArchList) # # Get Hob/BootMode/EventList information # self._GenSpecialComments() # # put all define statement into user-extension sections # DefinesDictNew = GenModuleHeaderUserExt(DefineObj, ArchString) if DefinesDictNew: UserExtension = CommonObject.UserExtensionObject() UserExtension.SetDefinesDict(DefinesDictNew) UserExtension.SetIdentifier('DefineModifiers') UserExtension.SetUserID('EDK2') self.SetUserExtensionList(self.GetUserExtensionList() + [UserExtension]) # # Get all meta-file header information # the record is list of items formated: # [LineValue, Arch, StartLine, ID, Third] # InfHeaderObj = self.Parser.InfHeader # # Put header information into POM object # if self.UniFileClassObject: Lang = DT.TAB_LANGUAGE_EN_X else: Lang = DT.TAB_LANGUAGE_EN_US if InfHeaderObj.GetAbstract(): self.SetAbstract((Lang, InfHeaderObj.GetAbstract())) if InfHeaderObj.GetDescription(): self.SetDescription((Lang, InfHeaderObj.GetDescription())) if InfHeaderObj.GetCopyright(): self.SetCopyright(('', InfHeaderObj.GetCopyright())) if InfHeaderObj.GetLicense(): self.SetLicense(('', InfHeaderObj.GetLicense())) # # Put Binary header information into POM object # InfBinaryHeaderObj = self.Parser.InfBinaryHeader if InfBinaryHeaderObj.GetAbstract(): self.SetBinaryHeaderAbstract( (Lang, InfBinaryHeaderObj.GetAbstract())) if InfBinaryHeaderObj.GetDescription(): self.SetBinaryHeaderDescription( (Lang, InfBinaryHeaderObj.GetDescription())) if InfBinaryHeaderObj.GetCopyright(): self.SetBinaryHeaderCopyright( ('', InfBinaryHeaderObj.GetCopyright())) if InfBinaryHeaderObj.GetLicense(): self.SetBinaryHeaderLicense(('', InfBinaryHeaderObj.GetLicense()))
# # Make sure the Db will get closed correctly # try: ReturnCode = 0 CheckConflictOption(Opt) RunModule = None if Opt.PackFileToCreate: if Opt.PackageInformationDataFile: if not os.path.exists(Opt.PackageInformationDataFile): if not os.path.exists( os.path.join(WorkspaceDir, Opt.PackageInformationDataFile)): Logger.Error( "\nUPT", FILE_NOT_FOUND, ST.ERR_NO_TEMPLATE_FILE % Opt.PackageInformationDataFile) else: Opt.PackageInformationDataFile = os.path.join( WorkspaceDir, Opt.PackageInformationDataFile) else: Logger.Error("UPT", OPTION_MISSING, ExtraData=ST.ERR_REQUIRE_T_OPTION) if not Opt.PackFileToCreate.endswith('.dist'): Logger.Error("CreatePkg", FILE_TYPE_MISMATCH, ExtraData=ST.ERR_DIST_EXT_ERROR % Opt.PackFileToCreate) RunModule = MkPkg.Main
def _GenDepexes(self): Logger.Debug(2, "Generate %s ..." % DT.TAB_DEPEX) PEI_LIST = [DT.SUP_MODULE_PEIM] SMM_LIST = [DT.SUP_MODULE_DXE_SMM_DRIVER] DXE_LIST = [ DT.SUP_MODULE_DXE_DRIVER, DT.SUP_MODULE_DXE_SAL_DRIVER, DT.SUP_MODULE_DXE_RUNTIME_DRIVER ] IsLibraryClass = self.GetIsLibrary() # # Get all Depexes # DepexData = self.Parser.InfDepexSection.GetDepex() SmmDepexList = [] DxeDepexList = [] PeiDepexList = [] for Depex in DepexData: ModuleType = Depex.GetModuleType() ModuleTypeList = [] if IsLibraryClass: if self.GetModuleType() == 'BASE' and not ModuleType: Logger.Error( "\nMkPkg", PARSER_ERROR, ST. ERR_INF_PARSER_DEPEX_SECTION_INVALID_FOR_BASE_LIBRARY_CLASS, self.GetFullPath(), RaiseError=True) if self.GetModuleType( ) != 'BASE' and not self.GetIsLibraryModList(): Logger.Error( "\nMkPkg", PARSER_ERROR, ST. ERR_INF_PARSER_DEPEX_SECTION_INVALID_FOR_LIBRARY_CLASS, self.GetFullPath(), RaiseError=True) if self.GetModuleType( ) != 'BASE' and ModuleType and ModuleType not in self.GetIsLibraryModList( ): Logger.Error( "\nMkPkg", PARSER_ERROR, ST.ERR_INF_PARSER_DEPEX_SECTION_NOT_DETERMINED, self.GetFullPath(), RaiseError=True) if ModuleType: ModuleTypeList = [ModuleType] else: for ModuleTypeInList in self.GetIsLibraryModList(): if ModuleTypeInList in DT.VALID_DEPEX_MODULE_TYPE_LIST: ModuleTypeList.append(ModuleTypeInList) if not ModuleTypeList: Logger.Error( "\nMkPkg", PARSER_ERROR, ST.ERR_INF_PARSER_DEPEX_SECTION_NOT_DETERMINED, self.GetFullPath(), RaiseError=True) else: if not ModuleType: ModuleType = self.ModuleType if ModuleType not in DT.VALID_DEPEX_MODULE_TYPE_LIST: Logger.Error( "\nMkPkg", PARSER_ERROR, ST.ERR_INF_PARSER_DEPEX_SECTION_MODULE_TYPE_ERROR % (ModuleType), self.GetFullPath(), RaiseError=True) if ModuleType != self.ModuleType: Logger.Error( "\nMkPkg", PARSER_ERROR, ST.ERR_INF_PARSER_DEPEX_SECTION_NOT_DETERMINED, self.GetFullPath(), RaiseError=True) ModuleTypeList = [ModuleType] for ModuleType in ModuleTypeList: DepexIns = DepexObject() DepexIns.SetDepex(Depex.GetDepexContent()) if IsLibraryClass: DepexIns.SetModuleType(ModuleType) else: if Depex.GetModuleType(): DepexIns.SetModuleType(Depex.GetModuleType()) DepexIns.SetSupArchList(ConvertArchList([Depex.GetSupArch()])) DepexIns.SetFeatureFlag(Depex.GetFeatureFlagExp()) if Depex.HelpString: HelpIns = CommonObject.TextObject() if self.UniFileClassObject: HelpIns.SetLang(DT.TAB_LANGUAGE_EN_X) HelpIns.SetString( GetHelpStringByRemoveHashKey(Depex.HelpString)) DepexIns.SetHelpText(HelpIns) if ModuleType in SMM_LIST: SmmDepexList.append(DepexIns) if ModuleType in DXE_LIST: DxeDepexList.append(DepexIns) if ModuleType in PEI_LIST: PeiDepexList.append(DepexIns) if ModuleType == DT.SUP_MODULE_UEFI_DRIVER: if IsLibraryClass: DxeDepexList.append(DepexIns) else: Logger.Error( "\nMkPkg", PARSER_ERROR, ST.ERR_INF_PARSER_DEPEX_SECTION_INVALID_FOR_DRIVER, self.GetFullPath(), RaiseError=True) #End of for ModuleType in ModuleTypeList self._GenDepexesList(SmmDepexList, DxeDepexList, PeiDepexList)
def SetPpi(self, PpiList, Arch=None): __SupArchList = [] for ArchItem in Arch: # # Validate Arch # if (ArchItem == '' or ArchItem == None): ArchItem = 'COMMON' __SupArchList.append(ArchItem) for Item in PpiList: # # Get Comment content of this protocol # CommentsList = None if len(Item) == 3: CommentsList = Item[1] CurrentLineOfItem = Item[2] Item = Item[0] InfPpiItemObj = InfPpiItem() if len(Item) >= 1 and len(Item) <= 2: # # Only CName contained # if not IsValidCVariableName(Item[0]): Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_INVALID_CNAME % (Item[0]), File=CurrentLineOfItem[2], Line=CurrentLineOfItem[1], ExtraData=CurrentLineOfItem[0]) if (Item[0] != ''): InfPpiItemObj.SetName(Item[0]) else: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_CNAME_MISSING, File=CurrentLineOfItem[2], Line=CurrentLineOfItem[1], ExtraData=CurrentLineOfItem[0]) # # Have FeatureFlag information # if len(Item) == 2: # # Contained CName and Feature Flag Express # <statements> ::= <CName> ["|" <FeatureFlagExpress>] # Item[1] should not be empty # if Item[1].strip() == '': Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING, File=CurrentLineOfItem[2], Line=CurrentLineOfItem[1], ExtraData=CurrentLineOfItem[0]) # # Validate Feature Flag Express for PPI entry # Item[1] contain FFE information # FeatureFlagRtv = IsValidFeatureFlagExp(Item[1].strip()) if not FeatureFlagRtv[0]: Logger.Error( "InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID % (FeatureFlagRtv[1]), File=CurrentLineOfItem[2], Line=CurrentLineOfItem[1], ExtraData=CurrentLineOfItem[0]) InfPpiItemObj.SetFeatureFlagExp(Item[1]) if len(Item) != 1 and len(Item) != 2: # # Invalid format of Ppi statement # Logger.Error( "InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_GUID_PPI_PROTOCOL_SECTION_CONTENT_ERROR, File=CurrentLineOfItem[2], Line=CurrentLineOfItem[1], ExtraData=CurrentLineOfItem[0]) # # Get/Set Usage and HelpString for PPI entry # if CommentsList != None and len(CommentsList) != 0: InfPpiItemObj = ParsePpiComment(CommentsList, InfPpiItemObj) else: CommentItemIns = InfPpiItemCommentContent() CommentItemIns.SetUsage(DT.ITEM_UNDEFINED) CommentItemIns.SetNotify(DT.ITEM_UNDEFINED) InfPpiItemObj.SetCommentList([CommentItemIns]) InfPpiItemObj.SetSupArchList(__SupArchList) # # Determine PPI name duplicate. Follow below rule: # # A PPI must not be duplicated within a [Ppis] section. # A PPI may appear in multiple architectural [Ppis] # sections. A PPI listed in an architectural [Ppis] # section must not be listed in the common architectural # [Ppis] section. # # NOTE: This check will not report error now. # for Item in self.Ppis: if Item.GetName() == InfPpiItemObj.GetName(): ItemSupArchList = Item.GetSupArchList() for ItemArch in ItemSupArchList: for PpiItemObjArch in __SupArchList: if ItemArch == PpiItemObjArch: # # ST.ERR_INF_PARSER_ITEM_DUPLICATE # pass if ItemArch.upper( ) == 'COMMON' or PpiItemObjArch.upper( ) == 'COMMON': # # ST.ERR_INF_PARSER_ITEM_DUPLICATE_COMMON # pass if self.Ppis.has_key((InfPpiItemObj)): PpiList = self.Ppis[InfPpiItemObj] PpiList.append(InfPpiItemObj) self.Ppis[InfPpiItemObj] = PpiList else: PpiList = [] PpiList.append(InfPpiItemObj) self.Ppis[InfPpiItemObj] = PpiList return True
def _GenAsBuiltPcds(self, PcdList, AsBuildIns): AsBuildPatchPcdList = [] AsBuildPcdExList = [] # # Pcd AsBuild Info # for PcdItem in PcdList: if PcdItem[0].upper() == DT.TAB_INF_PATCH_PCD.upper(): PcdItemObj = PcdItem[1] Pcd = CommonObject.PcdObject() Pcd.SetCName(PcdItemObj.GetCName()) Pcd.SetTokenSpaceGuidCName(PcdItemObj.GetTokenSpaceGuidCName()) if PcdItemObj.GetTokenSpaceGuidValue( ) == '' and self.BinaryModule: Logger.Error("\nMkPkg", PARSER_ERROR, ST.ERR_ASBUILD_PCD_TOKENSPACE_GUID_VALUE_MISS % \ (PcdItemObj.GetTokenSpaceGuidCName()), self.GetFullPath(), RaiseError=True) else: Pcd.SetTokenSpaceGuidValue( PcdItemObj.GetTokenSpaceGuidValue()) if (PcdItemObj.GetToken() == '' or PcdItemObj.GetDatumType() == '') and self.BinaryModule: Logger.Error("\nMkPkg", PARSER_ERROR, ST.ERR_ASBUILD_PCD_DECLARITION_MISS % \ (PcdItemObj.GetTokenSpaceGuidCName() + '.' + PcdItemObj.GetCName()), self.GetFullPath(), RaiseError=True) Pcd.SetToken(PcdItemObj.GetToken()) Pcd.SetDatumType(PcdItemObj.GetDatumType()) Pcd.SetMaxDatumSize(PcdItemObj.GetMaxDatumSize()) Pcd.SetDefaultValue(PcdItemObj.GetDefaultValue()) Pcd.SetOffset(PcdItemObj.GetOffset()) Pcd.SetItemType(PcdItem[0]) Pcd.SetFeatureFlag(PcdItemObj.GetFeatureFlagExp()) Pcd.SetSupArchList( ConvertArchList(PcdItemObj.GetSupportArchList())) Pcd.SetValidUsage(PcdItemObj.GetValidUsage()) for CommentItem in PcdItemObj.GetHelpStringList(): HelpTextObj = CommonObject.TextObject() if self.UniFileClassObject: HelpTextObj.SetLang(DT.TAB_LANGUAGE_EN_X) HelpTextObj.SetString(CommentItem.GetHelpStringItem()) Pcd.SetHelpTextList(Pcd.GetHelpTextList() + [HelpTextObj]) AsBuildPatchPcdList.append(Pcd) else: PcdItemObj = PcdItem[1] Pcd = CommonObject.PcdObject() Pcd.SetTokenSpaceGuidValue(PcdItemObj.GetTokenSpaceGuidValue()) Pcd.SetToken(PcdItemObj.GetToken()) Pcd.SetDatumType(PcdItemObj.GetDatumType()) Pcd.SetMaxDatumSize(PcdItemObj.GetMaxDatumSize()) Pcd.SetDefaultValue(PcdItemObj.GetDefaultValue()) Pcd.SetItemType(PcdItem[0]) Pcd.SetFeatureFlag(PcdItemObj.GetFeatureFlagExp()) Pcd.SetSupArchList( ConvertArchList(PcdItemObj.GetSupportArchList())) Pcd.SetValidUsage(PcdItemObj.GetValidUsage()) for CommentItem in PcdItemObj.GetHelpStringList(): HelpTextObj = CommonObject.TextObject() if self.UniFileClassObject: HelpTextObj.SetLang(DT.TAB_LANGUAGE_EN_X) HelpTextObj.SetString(CommentItem.GetHelpStringItem()) Pcd.SetHelpTextList(Pcd.GetHelpTextList() + [HelpTextObj]) AsBuildPcdExList.append(Pcd) AsBuildIns.SetPatchPcdList(AsBuildPatchPcdList) AsBuildIns.SetPcdExList(AsBuildPcdExList) return AsBuildIns
def IniParseError(Error, File, Line): Logger.Error("UPT", UPT_INI_PARSE_ERROR, File=File, Line=Line, ExtraData=Error)
def ParseInfFile(self, Filename): Filename = NormPath(Filename) (Path, Name) = os.path.split(Filename) self.FullPath = Filename self.RelaPath = Path self.FileName = Name GlobalData.gINF_MODULE_DIR = Path GlobalData.gINF_MODULE_NAME = self.FullPath GlobalData.gIS_BINARY_INF = False # # Initialize common data # LineNo = 0 CurrentSection = DT.MODEL_UNKNOWN SectionLines = [] # # Flags # HeaderCommentStart = False HeaderCommentEnd = False HeaderStarLineNo = -1 BinaryHeaderCommentStart = False BinaryHeaderCommentEnd = False BinaryHeaderStarLineNo = -1 # # While Section ends. parse whole section contents. # NewSectionStartFlag = False FirstSectionStartFlag = False # # Parse file content # CommentBlock = [] # # Variables for Event/Hob/BootMode # self.EventList = [] self.HobList = [] self.BootModeList = [] SectionType = '' FileLinesList = OpenInfFile(Filename) # # One INF file can only has one [Defines] section. # DefineSectionParsedFlag = False # # Convert special characters in lines to space character. # FileLinesList = ConvertSpecialChar(FileLinesList) # # Process Line Extender # FileLinesList = ProcessLineExtender(FileLinesList) # # Process EdkI INF style comment if found # OrigLines = [Line for Line in FileLinesList] FileLinesList, EdkCommentStartPos = ProcessEdkComment(FileLinesList) # # Judge whether the INF file is Binary INF or not # if IsBinaryInf(FileLinesList): GlobalData.gIS_BINARY_INF = True InfSectionCommonDefObj = None for Line in FileLinesList: LineNo = LineNo + 1 Line = Line.strip() if (LineNo < len(FileLinesList) - 1): NextLine = FileLinesList[LineNo].strip() # # blank line # if (Line == '' or not Line) and LineNo == len(FileLinesList): LastSectionFalg = True # # check whether file header comment section started # if Line.startswith(DT.TAB_SPECIAL_COMMENT) and \ (Line.find(DT.TAB_HEADER_COMMENT) > -1) and \ not HeaderCommentStart and not HeaderCommentEnd: CurrentSection = DT.MODEL_META_DATA_FILE_HEADER # # Append the first line to section lines. # HeaderStarLineNo = LineNo SectionLines.append((Line, LineNo)) HeaderCommentStart = True continue # # Collect Header content. # if (Line.startswith(DT.TAB_COMMENT_SPLIT) and CurrentSection == DT.MODEL_META_DATA_FILE_HEADER) and\ HeaderCommentStart and not Line.startswith(DT.TAB_SPECIAL_COMMENT) and not\ HeaderCommentEnd and NextLine != '': SectionLines.append((Line, LineNo)) continue # # Header content end # if (Line.startswith(DT.TAB_SPECIAL_COMMENT) or not Line.strip().startswith("#")) and HeaderCommentStart \ and not HeaderCommentEnd: HeaderCommentEnd = True BinaryHeaderCommentStart = False BinaryHeaderCommentEnd = False HeaderCommentStart = False if Line.find(DT.TAB_BINARY_HEADER_COMMENT) > -1: self.InfHeaderParser(SectionLines, self.InfHeader, self.FileName) SectionLines = [] else: SectionLines.append((Line, LineNo)) # # Call Header comment parser. # self.InfHeaderParser(SectionLines, self.InfHeader, self.FileName) SectionLines = [] continue # # check whether binary header comment section started # if Line.startswith(DT.TAB_SPECIAL_COMMENT) and \ (Line.find(DT.TAB_BINARY_HEADER_COMMENT) > -1) and \ not BinaryHeaderCommentStart: SectionLines = [] CurrentSection = DT.MODEL_META_DATA_FILE_HEADER # # Append the first line to section lines. # BinaryHeaderStarLineNo = LineNo SectionLines.append((Line, LineNo)) BinaryHeaderCommentStart = True HeaderCommentEnd = True continue # # check whether there are more than one binary header exist # if Line.startswith(DT.TAB_SPECIAL_COMMENT) and BinaryHeaderCommentStart and \ not BinaryHeaderCommentEnd and (Line.find(DT.TAB_BINARY_HEADER_COMMENT) > -1): Logger.Error('Parser', FORMAT_INVALID, ST.ERR_MULTIPLE_BINARYHEADER_EXIST, File=Filename) # # Collect Binary Header content. # if (Line.startswith(DT.TAB_COMMENT_SPLIT) and CurrentSection == DT.MODEL_META_DATA_FILE_HEADER) and\ BinaryHeaderCommentStart and not Line.startswith(DT.TAB_SPECIAL_COMMENT) and not\ BinaryHeaderCommentEnd and NextLine != '': SectionLines.append((Line, LineNo)) continue # # Binary Header content end # if (Line.startswith(DT.TAB_SPECIAL_COMMENT) or not Line.strip().startswith(DT.TAB_COMMENT_SPLIT)) and \ BinaryHeaderCommentStart and not BinaryHeaderCommentEnd: SectionLines.append((Line, LineNo)) BinaryHeaderCommentStart = False # # Call Binary Header comment parser. # self.InfHeaderParser(SectionLines, self.InfBinaryHeader, self.FileName, True) SectionLines = [] BinaryHeaderCommentEnd = True continue # # Find a new section tab # Or at the last line of INF file, # need to process the last section. # LastSectionFalg = False if LineNo == len(FileLinesList): LastSectionFalg = True if Line.startswith(DT.TAB_COMMENT_SPLIT) and not Line.startswith( DT.TAB_SPECIAL_COMMENT): SectionLines.append((Line, LineNo)) if not LastSectionFalg: continue # # Encountered a section. start with '[' and end with ']' # if (Line.startswith(DT.TAB_SECTION_START) and \ Line.find(DT.TAB_SECTION_END) > -1) or LastSectionFalg: HeaderCommentEnd = True BinaryHeaderCommentEnd = True if not LastSectionFalg: # # check to prevent '#' inside section header # HeaderContent = Line[1:Line.find(DT.TAB_SECTION_END)] if HeaderContent.find(DT.TAB_COMMENT_SPLIT) != -1: Logger.Error( "InfParser", FORMAT_INVALID, ST.ERR_INF_PARSER_DEFINE_SECTION_HEADER_INVALID, File=self.FullPath, Line=LineNo, ExtraData=Line) # # Keep last time section header content for section parser # usage. # self.LastSectionHeaderContent = deepcopy( self.SectionHeaderContent) # # TailComments in section define. # TailComments = '' CommentIndex = Line.find(DT.TAB_COMMENT_SPLIT) if CommentIndex > -1: TailComments = Line[CommentIndex:] Line = Line[:CommentIndex] InfSectionCommonDefObj = InfSectionCommonDef() if TailComments != '': InfSectionCommonDefObj.SetTailComments(TailComments) if CommentBlock != '': InfSectionCommonDefObj.SetHeaderComments(CommentBlock) CommentBlock = [] # # Call section parser before section header parer to avoid encounter EDKI INF file # if CurrentSection == DT.MODEL_META_DATA_DEFINE: DefineSectionParsedFlag = self._CallSectionParsers( CurrentSection, DefineSectionParsedFlag, SectionLines, InfSectionCommonDefObj, LineNo) # # Compare the new section name with current # self.SectionHeaderParser(Line, self.FileName, LineNo) self._CheckSectionHeaders(Line, LineNo) SectionType = _ConvertSecNameToType( self.SectionHeaderContent[0][0]) if not FirstSectionStartFlag: CurrentSection = SectionType FirstSectionStartFlag = True else: NewSectionStartFlag = True else: SectionLines.append((Line, LineNo)) continue if LastSectionFalg: SectionLines, CurrentSection = self._ProcessLastSection( SectionLines, Line, LineNo, CurrentSection) # # End of section content collect. # Parser the section content collected previously. # if NewSectionStartFlag or LastSectionFalg: if CurrentSection != DT.MODEL_META_DATA_DEFINE or \ (LastSectionFalg and CurrentSection == DT.MODEL_META_DATA_DEFINE): DefineSectionParsedFlag = self._CallSectionParsers( CurrentSection, DefineSectionParsedFlag, SectionLines, InfSectionCommonDefObj, LineNo) CurrentSection = SectionType # # Clear section lines # SectionLines = [] if HeaderStarLineNo == -1: Logger.Error("InfParser", FORMAT_INVALID, ST.ERR_NO_SOURCE_HEADER, File=self.FullPath) if BinaryHeaderStarLineNo > -1 and HeaderStarLineNo > -1 and HeaderStarLineNo > BinaryHeaderStarLineNo: Logger.Error("InfParser", FORMAT_INVALID, ST.ERR_BINARY_HEADER_ORDER, File=self.FullPath) # # EDKII INF should not have EDKI style comment # if EdkCommentStartPos != -1: Logger.Error("InfParser", FORMAT_INVALID, ST.ERR_INF_PARSER_EDKI_COMMENT_IN_EDKII, File=self.FullPath, Line=EdkCommentStartPos + 1, ExtraData=OrigLines[EdkCommentStartPos]) # # extract [Event] [Hob] [BootMode] sections # self._ExtractEventHobBootMod(FileLinesList)
def InfUserExtensionParser(self, SectionString, InfSectionObject, FileName): UserExtensionContent = '' # # Parse section content # for Line in SectionString: LineContent = Line[0] # Comment the code to support user extension without any statement just the section header in [] # if LineContent.strip() == '': # continue UserExtensionContent += LineContent + DT.END_OF_LINE continue # # Current section UserId, IdString # IdContentList = [] LastItem = '' SectionLineNo = None for Item in self.LastSectionHeaderContent: UserId = Item[1] IdString = Item[2] Arch = Item[3] SectionLineNo = Item[4] if not IsValidArch(Arch): Logger.Error('InfParser', FORMAT_INVALID, ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID % (Arch), File=GlobalData.gINF_MODULE_NAME, Line=SectionLineNo, ExtraData=None) if (UserId, IdString, Arch) not in IdContentList: # # To check the UserId and IdString valid or not. # if not IsValidUserId(UserId): Logger.Error('InfParser', FORMAT_INVALID, ST.ERR_INF_PARSER_UE_SECTION_USER_ID_ERROR % (Item[1]), File=GlobalData.gINF_MODULE_NAME, Line=SectionLineNo, ExtraData=None) if not IsValidIdString(IdString): Logger.Error('InfParser', FORMAT_INVALID, ST.ERR_INF_PARSER_UE_SECTION_ID_STRING_ERROR % (IdString), File=GlobalData.gINF_MODULE_NAME, Line=SectionLineNo, ExtraData=None) IdContentList.append((UserId, IdString, Arch)) else: # # Each UserExtensions section header must have a unique set # of UserId, IdString and Arch values. # This means that the same UserId can be used in more than one # section header, provided the IdString or Arch values are # different. The same IdString values can be used in more than # one section header if the UserId or Arch values are # different. The same UserId and the same IdString can be used # in a section header if the Arch values are different in each # of the section headers. # Logger.Error('InfParser', FORMAT_INVALID, ST.ERR_INF_PARSER_UE_SECTION_DUPLICATE_ERROR % (IdString), File=GlobalData.gINF_MODULE_NAME, Line=SectionLineNo, ExtraData=None) LastItem = Item if not InfSectionObject.SetUserExtension(UserExtensionContent, IdContent=IdContentList, LineNo=SectionLineNo): Logger.Error\ ('InfParser', FORMAT_INVALID, \ ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % ("[UserExtension]"), \ File=FileName, Line=LastItem[4])
def Main(Options = None): try: DataBase = GlobalData.gDB if not Options.DistributionFile: Logger.Error("RmPkg", OPTION_MISSING, ExtraData=ST.ERR_SPECIFY_PACKAGE) CheckEnvVariable() WorkspaceDir = GlobalData.gWORKSPACE # # Prepare check dependency # Dep = DependencyRules(DataBase) if Options.DistributionFile: (Guid, Version, NewDpFileName) = \ DataBase.GetDpByName(os.path.split(Options.DistributionFile)[1]) if not Guid: Logger.Error("RmPkg", UNKNOWN_ERROR, ST.ERR_PACKAGE_NOT_INSTALLED % Options.DistributionFile) else: Guid = Options.PackageGuid Version = Options.PackageVersion # # Check Dp existing # if not Dep.CheckDpExists(Guid, Version): Logger.Error("RmPkg", UNKNOWN_ERROR, ST.ERR_DISTRIBUTION_NOT_INSTALLED) # # Check for Distribution files existence in /conf/upt, if not exist, # Warn user and go on. # StoredDistFile = os.path.normpath(os.path.join(WorkspaceDir, GlobalData.gUPT_DIR, NewDpFileName)) if not os.path.isfile(StoredDistFile): Logger.Warn("RmPkg", ST.WRN_DIST_NOT_FOUND%StoredDistFile) StoredDistFile = None # # Check Dp depex # CheckDpDepex(Dep, Guid, Version, WorkspaceDir) # # Get Current File List # NewFileList = GetCurrentFileList(DataBase, Guid, Version, WorkspaceDir) # # Remove all files # MissingFileList = [] for (Path, Md5Sum) in DataBase.GetDpFileList(Guid, Version): if os.path.isfile(Path): if Path in NewFileList: NewFileList.remove(Path) if not Options.Yes: # # check whether modified by users # Md5Sigature = md5.new(open(str(Path), 'rb').read()) if Md5Sum != Md5Sigature.hexdigest(): Logger.Info(ST.MSG_CONFIRM_REMOVE2 % Path) Input = stdin.readline() Input = Input.replace('\r', '').replace('\n', '') if Input.upper() != 'Y': continue RemovePath(Path) else: MissingFileList.append(Path) for Path in NewFileList: if os.path.isfile(Path): if (not Options.Yes) and (not os.path.split(Path)[1].startswith('.')): Logger.Info(ST.MSG_CONFIRM_REMOVE3 % Path) Input = stdin.readline() Input = Input.replace('\r', '').replace('\n', '') if Input.upper() != 'Y': continue RemovePath(Path) # # Remove distribution files in /Conf/.upt # if StoredDistFile is not None: os.remove(StoredDistFile) # # update database # Logger.Quiet(ST.MSG_UPDATE_PACKAGE_DATABASE) DataBase.RemoveDpObj(Guid, Version) Logger.Quiet(ST.MSG_FINISH) ReturnCode = 0 except FatalError, XExcept: ReturnCode = XExcept.args[0] if Logger.GetLevel() <= Logger.DEBUG_9: Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + \ format_exc())