def SetValueDatumTypeMaxSizeToken(PcdItem, CurrentLineOfPcdItem, PcdItemObj, Arch, PackageInfo=None): # # Package information not been generated currently, we need to parser INF file to get information. # if not PackageInfo: PackageInfo = [] InfFileName = CurrentLineOfPcdItem[2] PackageInfoList = GetPackageListInfo(InfFileName, GlobalData.gWORKSPACE, -1) for PackageInfoListItem in PackageInfoList: PackageInfoIns = InfPackageItem() PackageInfoIns.SetPackageName(PackageInfoListItem) PackageInfo.append(PackageInfoIns) PcdInfoInDecHasFound = False for PackageItem in PackageInfo: if PcdInfoInDecHasFound: break PackageName = PackageItem.PackageName # # Open DEC file to get information # FullFileName = os.path.normpath(os.path.realpath(os.path.join(GlobalData.gWORKSPACE, PackageName))) DecParser = None if FullFileName not in GlobalData.gPackageDict: DecParser = Dec(FullFileName) GlobalData.gPackageDict[FullFileName] = DecParser else: DecParser = GlobalData.gPackageDict[FullFileName] # # Find PCD information. # DecPcdsDict = DecParser.GetPcdSectionObject().ValueDict for Key in DecPcdsDict.keys(): if (Key[0] == 'PCDSDYNAMICEX' and PcdItemObj.GetItemType() == 'PcdEx') and \ (Key[1] == 'COMMON' or Key[1] == Arch): for PcdInDec in DecPcdsDict[Key]: if PcdInDec.TokenCName == PcdItemObj.CName and \ PcdInDec.TokenSpaceGuidCName == PcdItemObj.TokenSpaceGuidCName: PcdItemObj.SetToken(PcdInDec.TokenValue) PcdItemObj.SetDatumType(PcdInDec.DatumType) PcdItemObj.SetSupportArchList([Arch]) PcdItemObj.SetDefaultValue(PcdInDec.DefaultValue) if (Key[0] == 'PCDSPATCHABLEINMODULE' and PcdItemObj.GetItemType() == 'PatchPcd') and \ (Key[1] == 'COMMON' or Key[1] == Arch): for PcdInDec in DecPcdsDict[Key]: if PcdInDec.TokenCName == PcdItemObj.CName and \ PcdInDec.TokenSpaceGuidCName == PcdItemObj.TokenSpaceGuidCName: PcdItemObj.SetToken(PcdInDec.TokenValue) PcdItemObj.SetDatumType(PcdInDec.DatumType) PcdItemObj.SetSupportArchList([Arch]) if PcdItemObj.GetDatumType() == 'VOID*': if len(PcdItem) > 1: PcdItemObj.SetMaxDatumSize('%s' % (len(GetSplitValueList(PcdItem[1], DT.TAB_COMMA_SPLIT)))) DecGuidsDict = DecParser.GetGuidSectionObject().ValueDict for Key in DecGuidsDict.keys(): if Key == 'COMMON' or Key == Arch: for GuidInDec in DecGuidsDict[Key]: if GuidInDec.GuidCName == PcdItemObj.TokenSpaceGuidCName: PcdItemObj.SetTokenSpaceGuidValue(GuidInDec.GuidString) if PcdItemObj.GetItemType().upper() == DT.TAB_INF_PATCH_PCD.upper(): # # Validate Value. # # convert the value from a decimal 0 to a formatted hex value. if PcdItem[1] == "0": DatumType = PcdItemObj.GetDatumType() if DatumType == "UINT8": PcdItem[1] = "0x00" if DatumType == "UINT16": PcdItem[1] = "0x0000" if DatumType == "UINT32": PcdItem[1] = "0x00000000" if DatumType == "UINT64": PcdItem[1] = "0x0000000000000000" if ValidatePcdValueOnDatumType(PcdItem[1], PcdItemObj.GetDatumType()): PcdItemObj.SetDefaultValue(PcdItem[1]) else: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_ASBUILD_PCD_VALUE_INVALID % ("\"" + PcdItem[1] + "\"", "\"" + PcdItemObj.GetDatumType() + "\""), File=CurrentLineOfPcdItem[2], Line=CurrentLineOfPcdItem[1], ExtraData=CurrentLineOfPcdItem[0]) # # validate offset # if PcdItemObj.GetItemType().upper() == DT.TAB_INF_PATCH_PCD.upper(): if not IsHexDigitUINT32(PcdItem[2]): Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_ASBUILD_PCD_OFFSET_FORMAT_INVALID % ("\"" + PcdItem[2] + "\""), File=CurrentLineOfPcdItem[2], Line=CurrentLineOfPcdItem[1], ExtraData=CurrentLineOfPcdItem[0]) PcdItemObj.SetOffset(PcdItem[2]) if PcdItemObj.GetToken() == '' or PcdItemObj.GetDatumType() == '': Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_ASBUILD_PCD_DECLARITION_MISS % ("\"" + PcdItem[0] + "\""), File=CurrentLineOfPcdItem[2], Line=CurrentLineOfPcdItem[1], ExtraData=CurrentLineOfPcdItem[0]) return PcdItemObj
def GenPcds(self, ContainerFile): Logger.Debug(2, "Generate %s ..." % TAB_PCDS) PcdObj = self.DecParser.GetPcdSectionObject() # # Get all Pcds # PcdDeclarations = [] IterList = [(TAB_PCDS_FIXED_AT_BUILD_NULL, 'FixedPcd'), (TAB_PCDS_PATCHABLE_IN_MODULE_NULL, 'PatchPcd'), (TAB_PCDS_FEATURE_FLAG_NULL, 'FeaturePcd'), (TAB_PCDS_DYNAMIC_EX_NULL, 'PcdEx'), (TAB_PCDS_DYNAMIC_NULL, 'Pcd')] PromptStrList = [] HelpStrList = [] PcdErrStrList = [] # Initialize UniStrDict dictionary, top keys are language codes UniStrDict = {} StrList = [] Language = '' if self.UniFileClassObject: Language = TAB_LANGUAGE_EN_X else: Language = TAB_LANGUAGE_EN_US if self.UniFileClassObject: UniStrDict = self.UniFileClassObject.OrderedStringList for Lang in UniStrDict: for StringDefClassObject in UniStrDict[Lang]: StrList = StringDefClassObject.StringName.split('_') # StringName format is STR_<TOKENSPACECNAME>_<PCDCNAME>_PROMPT if len(StrList) == 4 and StrList[ 0] == TAB_STR_TOKENCNAME and StrList[ 3] == TAB_STR_TOKENPROMPT: PromptStrList.append((GetLanguageCode1766(Lang), StringDefClassObject.StringName, \ StringDefClassObject.StringValue)) # StringName format is STR_<TOKENSPACECNAME>_<PCDCNAME>_HELP if len(StrList) == 4 and StrList[ 0] == TAB_STR_TOKENCNAME and StrList[ 3] == TAB_STR_TOKENHELP: HelpStrList.append((GetLanguageCode1766(Lang), StringDefClassObject.StringName, \ StringDefClassObject.StringValue)) # StringName format is STR_<TOKENSPACECNAME>_ERR_## if len(StrList) == 4 and StrList[ 0] == TAB_STR_TOKENCNAME and StrList[ 2] == TAB_STR_TOKENERR: PcdErrStrList.append((GetLanguageCode1766(Lang), StringDefClassObject.StringName, \ StringDefClassObject.StringValue)) # # For each PCD type # for PcdType, Type in IterList: # # Go through all archs # # for Arch in self.SupArchList + [TAB_ARCH_COMMON]: # for Item in PcdObj.GetPcdsByType(PcdType.upper()): PcdDeclaration = GenPcdDeclaration( ContainerFile, (Item.TokenSpaceGuidCName, Item.TokenCName, Item.DefaultValue, Item.DatumType, Item.TokenValue, Type, Item.GetHeadComment(), Item.GetTailComment(), ''), Language, self.DecParser.GetDefineSectionMacro()) PcdDeclaration.SetSupArchList(Item.GetArchListOfType(PcdType)) # # Get PCD error message from PCD error comment section in DEC file # for PcdErr in PcdDeclaration.GetPcdErrorsList(): if (PcdDeclaration.GetTokenSpaceGuidCName(), PcdErr.GetErrorNumber()) \ in self.DecParser.PcdErrorCommentDict: Key = (PcdDeclaration.GetTokenSpaceGuidCName(), PcdErr.GetErrorNumber()) PcdErr.SetErrorMessageList(PcdErr.GetErrorMessageList() + \ [(Language, self.DecParser.PcdErrorCommentDict[Key])]) for Index in range(0, len(PromptStrList)): StrNameList = PromptStrList[Index][1].split('_') if StrNameList[1].lower() == Item.TokenSpaceGuidCName.lower() and \ StrNameList[2].lower() == Item.TokenCName.lower(): TxtObj = TextObject() TxtObj.SetLang(PromptStrList[Index][0]) TxtObj.SetString(PromptStrList[Index][2]) for Prompt in PcdDeclaration.GetPromptList(): if Prompt.GetLang() == TxtObj.GetLang() and \ Prompt.GetString() == TxtObj.GetString(): break else: PcdDeclaration.SetPromptList( PcdDeclaration.GetPromptList() + [TxtObj]) for Index in range(0, len(HelpStrList)): StrNameList = HelpStrList[Index][1].split('_') if StrNameList[1].lower() == Item.TokenSpaceGuidCName.lower() and \ StrNameList[2].lower() == Item.TokenCName.lower(): TxtObj = TextObject() TxtObj.SetLang(HelpStrList[Index][0]) TxtObj.SetString(HelpStrList[Index][2]) for HelpStrObj in PcdDeclaration.GetHelpTextList(): if HelpStrObj.GetLang() == TxtObj.GetLang() and \ HelpStrObj.GetString() == TxtObj.GetString(): break else: PcdDeclaration.SetHelpTextList( PcdDeclaration.GetHelpTextList() + [TxtObj]) # # Get PCD error message from UNI file # for Index in range(0, len(PcdErrStrList)): StrNameList = PcdErrStrList[Index][1].split('_') if StrNameList[1].lower() == Item.TokenSpaceGuidCName.lower() and \ StrNameList[2].lower() == TAB_STR_TOKENERR.lower(): for PcdErr in PcdDeclaration.GetPcdErrorsList(): if PcdErr.GetErrorNumber().lower() == (TAB_HEX_START + StrNameList[3]).lower() and \ (PcdErrStrList[Index][0], PcdErrStrList[Index][2]) not in PcdErr.GetErrorMessageList(): PcdErr.SetErrorMessageList(PcdErr.GetErrorMessageList() + \ [(PcdErrStrList[Index][0], PcdErrStrList[Index][2])]) # # Check to prevent missing error message if a Pcd has the error code. # for PcdErr in PcdDeclaration.GetPcdErrorsList(): if PcdErr.GetErrorNumber().strip(): if not PcdErr.GetErrorMessageList(): Logger.Error( 'UPT', FORMAT_INVALID, ST.ERR_DECPARSE_PCD_UNMATCHED_ERRORCODE % PcdErr.GetErrorNumber(), ContainerFile, PcdErr.GetLineNum(), PcdErr.GetFileLine()) PcdDeclarations.append(PcdDeclaration) self.SetPcdList(self.GetPcdList() + PcdDeclarations) self.CheckPcdValue()
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 is None: LineComment = InfLineCommentObject() LineComment.SetTailComments(TailComments) # # Find Macro # MacroDef = MacroParser((BinLineContent, BinLineNo), FileName, DT.MODEL_EFI_BINARY_FILE, self.FileLocalMacros) if MacroDef[0] is not 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 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 is None: LineComment = InfLineCommentObject() LineComment.SetTailComments(TailComments) # # Find Macro # Name, Value = MacroParser((PkgLineContent, PkgLineNo), FileName, DT.MODEL_META_DATA_PACKAGE, self.FileLocalMacros) if Name is not 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 GenIncludes(self, ContainerFile): if ContainerFile: pass Logger.Debug(2, "Generate %s ..." % TAB_INCLUDES) IncludesDict = Sdict() IncObj = self.DecParser.GetIncludeSectionObject() for Item in IncObj.GetAllIncludes(): IncludePath = os.path.normpath(Item.File) if platform.system() != 'Windows' and platform.system( ) != 'Microsoft': IncludePath = IncludePath.replace('\\', '/') if IncludePath in IncludesDict: if Item.GetArchList() == [ TAB_ARCH_COMMON ] or IncludesDict[IncludePath] == [TAB_ARCH_COMMON]: IncludesDict[IncludePath] = [TAB_ARCH_COMMON] else: IncludesDict[IncludePath] = IncludesDict[ IncludePath] + Item.GetArchList() else: IncludesDict[IncludePath] = Item.GetArchList() # # get the standardIncludeFileList(industry), packageIncludeFileList # (others) for PackageObject # PackagePath = os.path.split(self.GetFullPath())[0] IncludePathList = \ sorted([os.path.normpath(Path) + sep for Path in IncludesDict.keys()]) # # get a non-overlap set of include path, IncludePathList should be # sorted, and path should be end with path separator '\' # NonOverLapList = [] for Path1 in IncludePathList: for Path2 in NonOverLapList: if Path1.startswith(Path2): break else: NonOverLapList.append(Path1) # # revert the list so the longest path shown first in list, also need # to remove the extra path separator '\' # as this list is used to search the supported Arch info # for IndexN in range(0, len(IncludePathList)): IncludePathList[IndexN] = os.path.normpath(IncludePathList[IndexN]) IncludePathList.sort() IncludePathList.reverse() # # save the include path list for later usage # self.SetIncludePathList(IncludePathList) StandardIncludeFileList = [] PackageIncludeFileList = [] IncludeFileList = [] for Path in NonOverLapList: FileList = GetFiles(os.path.join(PackagePath, Path), ['CVS', '.svn'], False) IncludeFileList += [ os.path.normpath(os.path.join(Path, File)) for File in FileList ] for Includefile in IncludeFileList: ExtName = os.path.splitext(Includefile)[1] if ExtName.upper() == '.DEC' and self.CheckMulDec: Logger.Error( 'MkPkg', UPT_MUL_DEC_ERROR, ST.ERR_MUL_DEC_ERROR % (os.path.dirname(ContainerFile), os.path.basename(ContainerFile), Includefile)) FileCombinePath = os.path.dirname(Includefile) Include = IncludeObject() for Path in IncludePathList: if FileCombinePath.startswith(Path): SupArchList = IncludesDict[Path] break Include.SetFilePath(Includefile) Include.SetSupArchList(SupArchList) if Includefile.find('IndustryStandard') != -1: StandardIncludeFileList.append(Include) else: PackageIncludeFileList.append(Include) self.SetStandardIncludeFileList(StandardIncludeFileList) # # put include path into the PackageIncludeFileList # PackagePathList = [] IncObj = self.DecParser.GetIncludeSectionObject() for Item in IncObj.GetAllIncludes(): IncludePath = Item.File Include = IncludeObject() Include.SetFilePath(IncludePath) Include.SetSupArchList(Item.GetArchList()) PackagePathList.append(Include) self.SetPackageIncludeFileList(PackagePathList + PackageIncludeFileList)
def ParseHeaderCommentSection(CommentList, FileName=None, IsBinaryHeader=False): Abstract = '' Description = '' Copyright = '' License = '' EndOfLine = "\n" if IsBinaryHeader: STR_HEADER_COMMENT_START = "@BinaryHeader" else: STR_HEADER_COMMENT_START = "@file" HeaderCommentStage = HEADER_COMMENT_NOT_STARTED # # first find the last copyright line # Last = 0 for Index in range(len(CommentList) - 1, 0, -1): Line = CommentList[Index][0] if _IsCopyrightLine(Line): Last = Index break for Item in CommentList: Line = Item[0] LineNo = Item[1] if not Line.startswith(TAB_COMMENT_SPLIT) and Line: Logger.Error("\nUPT", FORMAT_INVALID, ST.ERR_INVALID_COMMENT_FORMAT, FileName, Item[1]) Comment = CleanString2(Line)[1] Comment = Comment.strip() # # if there are blank lines between License or Description, keep them as they would be # indication of different block; or in the position that Abstract should be, also keep it # as it indicates that no abstract # if not Comment and HeaderCommentStage not in [HEADER_COMMENT_LICENSE, \ HEADER_COMMENT_DESCRIPTION, HEADER_COMMENT_ABSTRACT]: continue if HeaderCommentStage == HEADER_COMMENT_NOT_STARTED: if Comment.startswith(STR_HEADER_COMMENT_START): HeaderCommentStage = HEADER_COMMENT_ABSTRACT else: License += Comment + EndOfLine else: if HeaderCommentStage == HEADER_COMMENT_ABSTRACT: # # in case there is no abstract and description # if not Comment: HeaderCommentStage = HEADER_COMMENT_DESCRIPTION elif _IsCopyrightLine(Comment): Result, ErrMsg = _ValidateCopyright(Comment) ValidateCopyright(Result, ST.WRN_INVALID_COPYRIGHT, FileName, LineNo, ErrMsg) Copyright += Comment + EndOfLine HeaderCommentStage = HEADER_COMMENT_COPYRIGHT else: Abstract += Comment + EndOfLine HeaderCommentStage = HEADER_COMMENT_DESCRIPTION elif HeaderCommentStage == HEADER_COMMENT_DESCRIPTION: # # in case there is no description # if _IsCopyrightLine(Comment): Result, ErrMsg = _ValidateCopyright(Comment) ValidateCopyright(Result, ST.WRN_INVALID_COPYRIGHT, FileName, LineNo, ErrMsg) Copyright += Comment + EndOfLine HeaderCommentStage = HEADER_COMMENT_COPYRIGHT else: Description += Comment + EndOfLine elif HeaderCommentStage == HEADER_COMMENT_COPYRIGHT: if _IsCopyrightLine(Comment): Result, ErrMsg = _ValidateCopyright(Comment) ValidateCopyright(Result, ST.WRN_INVALID_COPYRIGHT, FileName, LineNo, ErrMsg) Copyright += Comment + EndOfLine else: # # Contents after copyright line are license, those non-copyright lines in between # copyright line will be discarded # if LineNo > Last: if License: License += EndOfLine License += Comment + EndOfLine HeaderCommentStage = HEADER_COMMENT_LICENSE else: if not Comment and not License: continue License += Comment + EndOfLine return Abstract.strip(), Description.strip(), Copyright.strip( ), License.strip()
def SectionHeaderParser(self, SectionString, FileName, LineNo): _Scope = [] _SectionName = '' ArchList = set() _ValueList = [] _PcdNameList = [ DT.TAB_INF_FIXED_PCD.upper(), DT.TAB_INF_FEATURE_PCD.upper(), DT.TAB_INF_PATCH_PCD.upper(), DT.TAB_INF_PCD.upper(), DT.TAB_INF_PCD_EX.upper() ] SectionString = SectionString.strip() for Item in GetSplitValueList(SectionString[1:-1], DT.TAB_COMMA_SPLIT): if Item == '': Logger.Error('Parser', FORMAT_INVALID, ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % (""), File=FileName, Line=LineNo, ExtraData=SectionString) ItemList = GetSplitValueList(Item, DT.TAB_SPLIT) # # different section should not mix in one section # Allow different PCD type sections mixed together # if _SectionName.upper() not in _PcdNameList: if _SectionName != '' and _SectionName.upper( ) != ItemList[0].upper(): Logger.Error('Parser', FORMAT_INVALID, ST.ERR_INF_PARSER_SECTION_NAME_DUPLICATE, File=FileName, Line=LineNo, ExtraData=SectionString) elif _PcdNameList[1] in [_SectionName.upper(), ItemList[0].upper()] and \ (_SectionName.upper()!= ItemList[0].upper()): Logger.Error('Parser', FORMAT_INVALID, ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % (""), File=FileName, Line=LineNo, ExtraData=SectionString) _SectionName = ItemList[0] if _SectionName.upper() in gINF_SECTION_DEF: self._SectionType = gINF_SECTION_DEF[_SectionName.upper()] else: self._SectionType = DT.MODEL_UNKNOWN Logger.Error("Parser", FORMAT_INVALID, ST.ERR_INF_PARSER_UNKNOWN_SECTION, File=FileName, Line=LineNo, ExtraData=SectionString) # # Get Arch # Str1, ArchList = GetArch(ItemList, ArchList, FileName, LineNo, SectionString) # # For [Defines] section, do special check. # if ItemList[0].upper() == DT.TAB_COMMON_DEFINES.upper(): if len(ItemList) != 1: Logger.Error('Parser', FORMAT_INVALID, ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID % (SectionString), File=FileName, Line=LineNo, ExtraData=SectionString) # # For [UserExtension] section, do special check. # if ItemList[0].upper() == DT.TAB_USER_EXTENSIONS.upper(): RetValue = ProcessUseExtHeader(ItemList) if not RetValue[0]: Logger.Error('Parser', FORMAT_INVALID, ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID % (SectionString), File=FileName, Line=LineNo, ExtraData=SectionString) else: ItemList = RetValue[1] if len(ItemList) == 3: ItemList.append('COMMON') Str1 = ItemList[1] # # For Library classes, need to check module type. # if ItemList[0].upper() == DT.TAB_LIBRARY_CLASSES.upper() and len( ItemList) == 3: if ItemList[2] != '': ModuleTypeList = GetSplitValueList(ItemList[2], DT.TAB_VALUE_SPLIT) for Item in ModuleTypeList: if Item.strip() not in DT.MODULE_LIST: Logger.Error( 'Parser', FORMAT_INVALID, ST.ERR_INF_PARSER_DEFINE_MODULETYPE_INVALID % (Item), File=FileName, Line=LineNo, ExtraData=SectionString) # # GetSpecialStr2 # Str2 = GetSpecialStr2(ItemList, FileName, LineNo, SectionString) _Scope.append([Str1, Str2]) _NewValueList = [] _AppendFlag = True if _SectionName.upper() in _PcdNameList: for ValueItem in _ValueList: if _SectionName.upper() == ValueItem[0].upper( ) and Str1.upper() not in ValueItem[1].split(): ValueItem[1] = ValueItem[1] + " " + Str1 _AppendFlag = False elif _SectionName.upper() == ValueItem[0].upper( ) and Str1.upper() in ValueItem[1].split(): _AppendFlag = False _NewValueList.append(ValueItem) _ValueList = _NewValueList if _AppendFlag: if not ItemList[0].upper() == DT.TAB_USER_EXTENSIONS.upper(): _ValueList.append([_SectionName, Str1, Str2, LineNo]) else: if len(ItemList) == 4: _ValueList.append( [_SectionName, Str1, Str2, ItemList[3], LineNo]) self.SectionHeaderContent = deepcopy(_ValueList)
def Main(Options=None): if Options is 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 = mws.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 Md5Signature # DistPkg.Header.Signature = md5(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 as XExcept: 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 % ST.MSG_EDKII_MAIL_ADDR, 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 Main(Options=None): ContentZipFile, DistFile = None, None try: DataBase = GlobalData.gDB WorkspaceDir = GlobalData.gWORKSPACE Dep = DependencyRules(DataBase) DistPkg, ContentZipFile, DpPkgFileName, DistFile = UnZipDp( WorkspaceDir, Options.PackFileToReplace) StoredDistFile, OrigDpGuid, OrigDpVersion = GetInstalledDpInfo(Options.PackFileToBeReplaced, \ Dep, DataBase, WorkspaceDir) # # check dependency # CheckReplaceDpx(Dep, DistPkg, OrigDpGuid, OrigDpVersion) # # Remove the old distribution # RemoveDist(OrigDpGuid, OrigDpVersion, StoredDistFile, DataBase, WorkspaceDir, Options.Yes) # # Install the new distribution # InstallDp(DistPkg, DpPkgFileName, ContentZipFile, Options, Dep, WorkspaceDir, DataBase) ReturnCode = 0 except FatalError as XExcept: 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: ReturnCode = CODE_ERROR Logger.Error("\nReplacePkg", CODE_ERROR, ST.ERR_UNKNOWN_FATAL_REPLACE_ERR % (Options.PackFileToReplace, Options.PackFileToBeReplaced), ExtraData=ST.MSG_SEARCH_FOR_HELP % ST.MSG_EDKII_MAIL_ADDR, RaiseError=False) Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc()) finally: Logger.Quiet(ST.MSG_REMOVE_TEMP_FILE_STARTED) if DistFile: DistFile.Close() if ContentZipFile: ContentZipFile.Close() for TempDir in GlobalData.gUNPACK_DIR: rmtree(TempDir) GlobalData.gUNPACK_DIR = [] Logger.Quiet(ST.MSG_REMOVE_TEMP_FILE_DONE) if ReturnCode == 0: Logger.Quiet(ST.MSG_FINISH) return ReturnCode
def Unpack(self, ToDest): for FileN in self._ZipFile.namelist(): ToFile = os.path.normpath(os.path.join(ToDest, FileN)) Msg = "%s -> %s" % (FileN, ToFile) Logger.Info(Msg) self.Extract(FileN, ToFile)
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 _ExtractEventHobBootMod(self, FileLinesList): SpecialSectionStart = False CheckLocation = False GFindSpecialCommentRe = \ re.compile(r"""#(?:\s*)\[(.*?)\](?:.*)""", re.DOTALL) GFindNewSectionRe2 = \ re.compile(r"""#?(\s*)\[(.*?)\](.*)""", re.DOTALL) LineNum = 0 Element = [] for Line in FileLinesList: Line = Line.strip() LineNum += 1 MatchObject = GFindSpecialCommentRe.search(Line) if MatchObject: SpecialSectionStart = True Element = [] if MatchObject.group(1).upper().startswith("EVENT"): List = self.EventList elif MatchObject.group(1).upper().startswith("HOB"): List = self.HobList elif MatchObject.group(1).upper().startswith("BOOTMODE"): List = self.BootModeList else: SpecialSectionStart = False CheckLocation = False if SpecialSectionStart: Element.append([Line, LineNum]) List.append(Element) else: # # if currently in special section, try to detect end of current section # MatchObject = GFindNewSectionRe2.search(Line) if SpecialSectionStart: if MatchObject: SpecialSectionStart = False CheckLocation = False Element = [] elif not Line: SpecialSectionStart = False CheckLocation = True Element = [] else: if not Line.startswith(DT.TAB_COMMENT_SPLIT): Logger.Warn("Parser", ST.WARN_SPECIAL_SECTION_LOCATION_WRONG, File=self.FullPath, Line=LineNum) SpecialSectionStart = False CheckLocation = False Element = [] else: Element.append([Line, LineNum]) else: if CheckLocation: if MatchObject: CheckLocation = False elif Line: Logger.Warn("Parser", ST.WARN_SPECIAL_SECTION_LOCATION_WRONG, File=self.FullPath, Line=LineNum) CheckLocation = False if len(self.BootModeList) >= 1: self.InfSpecialCommentParser(self.BootModeList, self.InfSpecialCommentSection, self.FileName, DT.TYPE_BOOTMODE_SECTION) if len(self.EventList) >= 1: self.InfSpecialCommentParser(self.EventList, self.InfSpecialCommentSection, self.FileName, DT.TYPE_EVENT_SECTION) if len(self.HobList) >= 1: self.InfSpecialCommentParser(self.HobList, self.InfSpecialCommentSection, self.FileName, DT.TYPE_HOB_SECTION)
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 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 ParseDecPcdGenericComment(GenericComment, ContainerFile, TokenSpaceGuidCName, CName, MacroReplaceDict): HelpStr = '' PromptStr = '' PcdErr = None PcdErrList = [] ValidValueNum = 0 ValidRangeNum = 0 ExpressionNum = 0 for (CommentLine, LineNum) in GenericComment: Comment = CleanString2(CommentLine)[1] # # To replace Macro # MACRO_PATTERN = '[\t\s]*\$\([A-Z][_A-Z0-9]*\)' MatchedStrs = re.findall(MACRO_PATTERN, Comment) for MatchedStr in MatchedStrs: if MatchedStr: Macro = MatchedStr.strip().lstrip('$(').rstrip(')').strip() if Macro in MacroReplaceDict: Comment = Comment.replace(MatchedStr, MacroReplaceDict[Macro]) if Comment.startswith(TAB_PCD_VALIDRANGE): if ValidValueNum > 0 or ExpressionNum > 0: Logger.Error('Parser', FORMAT_NOT_SUPPORTED, ST.WRN_MULTI_PCD_RANGES, File=ContainerFile, Line=LineNum) else: PcdErr = PcdErrorObject() PcdErr.SetTokenSpaceGuidCName(TokenSpaceGuidCName) PcdErr.SetCName(CName) PcdErr.SetFileLine(Comment) PcdErr.SetLineNum(LineNum) ValidRangeNum += 1 ValidRange = Comment.replace(TAB_PCD_VALIDRANGE, "", 1).strip() Valid, Cause = _CheckRangeExpression(ValidRange) if Valid: ValueList = ValidRange.split(TAB_VALUE_SPLIT) if len(ValueList) > 1: PcdErr.SetValidValueRange( (TAB_VALUE_SPLIT.join(ValueList[1:])).strip()) PcdErr.SetErrorNumber( ParsePcdErrorCode(ValueList[0], ContainerFile, LineNum)) else: PcdErr.SetValidValueRange(ValidRange) PcdErrList.append(PcdErr) else: Logger.Error("Parser", FORMAT_NOT_SUPPORTED, Cause, ContainerFile, LineNum) elif Comment.startswith(TAB_PCD_VALIDLIST): if ValidRangeNum > 0 or ExpressionNum > 0: Logger.Error('Parser', FORMAT_NOT_SUPPORTED, ST.WRN_MULTI_PCD_RANGES, File=ContainerFile, Line=LineNum) elif ValidValueNum > 0: Logger.Error('Parser', FORMAT_NOT_SUPPORTED, ST.WRN_MULTI_PCD_VALIDVALUE, File=ContainerFile, Line=LineNum) else: PcdErr = PcdErrorObject() PcdErr.SetTokenSpaceGuidCName(TokenSpaceGuidCName) PcdErr.SetCName(CName) PcdErr.SetFileLine(Comment) PcdErr.SetLineNum(LineNum) ValidValueNum += 1 ValidValueExpr = Comment.replace(TAB_PCD_VALIDLIST, "", 1).strip() Valid, Cause = _CheckListExpression(ValidValueExpr) if Valid: ValidValue = Comment.replace(TAB_PCD_VALIDLIST, "", 1).replace( TAB_COMMA_SPLIT, TAB_SPACE_SPLIT) ValueList = ValidValue.split(TAB_VALUE_SPLIT) if len(ValueList) > 1: PcdErr.SetValidValue( (TAB_VALUE_SPLIT.join(ValueList[1:])).strip()) PcdErr.SetErrorNumber( ParsePcdErrorCode(ValueList[0], ContainerFile, LineNum)) else: PcdErr.SetValidValue(ValidValue) PcdErrList.append(PcdErr) else: Logger.Error("Parser", FORMAT_NOT_SUPPORTED, Cause, ContainerFile, LineNum) elif Comment.startswith(TAB_PCD_EXPRESSION): if ValidRangeNum > 0 or ValidValueNum > 0: Logger.Error('Parser', FORMAT_NOT_SUPPORTED, ST.WRN_MULTI_PCD_RANGES, File=ContainerFile, Line=LineNum) else: PcdErr = PcdErrorObject() PcdErr.SetTokenSpaceGuidCName(TokenSpaceGuidCName) PcdErr.SetCName(CName) PcdErr.SetFileLine(Comment) PcdErr.SetLineNum(LineNum) ExpressionNum += 1 Expression = Comment.replace(TAB_PCD_EXPRESSION, "", 1).strip() Valid, Cause = _CheckExpression(Expression) if Valid: ValueList = Expression.split(TAB_VALUE_SPLIT) if len(ValueList) > 1: PcdErr.SetExpression( (TAB_VALUE_SPLIT.join(ValueList[1:])).strip()) PcdErr.SetErrorNumber( ParsePcdErrorCode(ValueList[0], ContainerFile, LineNum)) else: PcdErr.SetExpression(Expression) PcdErrList.append(PcdErr) else: Logger.Error("Parser", FORMAT_NOT_SUPPORTED, Cause, ContainerFile, LineNum) elif Comment.startswith(TAB_PCD_PROMPT): if PromptStr: Logger.Error('Parser', FORMAT_NOT_SUPPORTED, ST.WRN_MULTI_PCD_PROMPT, File=ContainerFile, Line=LineNum) PromptStr = Comment.replace(TAB_PCD_PROMPT, "", 1).strip() else: if Comment: HelpStr += Comment + '\n' # # remove the last EOL if the comment is of format 'FOO\n' # if HelpStr.endswith('\n'): if HelpStr != '\n' and not HelpStr.endswith('\n\n'): HelpStr = HelpStr[:-1] return HelpStr, PcdErrList, PromptStr
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 ValidateCopyright(Result, ErrType, FileName, LineNo, ErrMsg): if not Result: Logger.Warn("\nUPT", ErrType, FileName, LineNo, ErrMsg)
def Main(Options=None): ContentZipFile, DistFile = None, None ReturnCode = 0 try: DataBase = GlobalData.gDB WorkspaceDir = GlobalData.gWORKSPACE if not Options.DistFiles: Logger.Error("TestInstallPkg", TE.OPTION_MISSING, ExtraData=ST.ERR_SPECIFY_PACKAGE) DistPkgList = [] for DistFile in Options.DistFiles: DistPkg, ContentZipFile, __, DistFile = UnZipDp( WorkspaceDir, DistFile) DistPkgList.append(DistPkg) # # check dependency # Dep = DependencyRules(DataBase) Result = True DpObj = None try: Result, DpObj = Dep.CheckTestInstallPdDepexSatisfied(DistPkgList) except: Result = False if Result: Logger.Quiet(ST.MSG_TEST_INSTALL_PASS) else: Logger.Quiet(ST.MSG_TEST_INSTALL_FAIL) except TE.FatalError as XExcept: ReturnCode = XExcept.args[0] if Logger.GetLevel() <= Logger.DEBUG_9: Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc()) except Exception as x: ReturnCode = TE.CODE_ERROR Logger.Error("\nTestInstallPkg", TE.CODE_ERROR, ST.ERR_UNKNOWN_FATAL_INSTALL_ERR % Options.DistFiles, ExtraData=ST.MSG_SEARCH_FOR_HELP % ST.MSG_EDKII_MAIL_ADDR, RaiseError=False) Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc()) finally: Logger.Quiet(ST.MSG_REMOVE_TEMP_FILE_STARTED) if DistFile: DistFile.Close() if ContentZipFile: ContentZipFile.Close() for TempDir in GlobalData.gUNPACK_DIR: shutil.rmtree(TempDir) GlobalData.gUNPACK_DIR = [] Logger.Quiet(ST.MSG_REMOVE_TEMP_FILE_DONE) if ReturnCode == 0: Logger.Quiet(ST.MSG_FINISH) return ReturnCode
def SetPpi(self, PpiList, Arch = None): __SupArchList = [] for ArchItem in Arch: # # Validate Arch # if (ArchItem == '' or ArchItem is 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 is not 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 (InfPpiItemObj) in self.Ppis: PpiList = self.Ppis[InfPpiItemObj] PpiList.append(InfPpiItemObj) self.Ppis[InfPpiItemObj] = PpiList else: PpiList = [] PpiList.append(InfPpiItemObj) self.Ppis[InfPpiItemObj] = PpiList return True
TempFile.close() except: print("File Create Error") CurrentLine = CurrentLine() CurrentLine.SetFileName("Test") CurrentLine.SetLineString(Item[0]) CurrentLine.SetLineNo(Item[1]) InfLineCommentObject = InfLineCommentObject() ItemList.append((ValueList, InfLineCommentObject, CurrentLine)) return ItemList if __name__ == '__main__': Logger.Initialize() InfBinariesInstance = InfBinariesObject() ArchList = ['COMMON'] Global.gINF_MODULE_DIR = os.getcwd() AllPassedFlag = True # # For All Ui test # UiStringList = [ SectionStringsUiItem1, SectionStringsUiItem2, SectionStringsUiItem3, SectionStringsUiItem4, SectionStringsUiItem5, SectionStringsUiItem6, SectionStringsUiItem7, SectionStringsUiItem8 ]
def InfSpecialCommentParser(self, SpecialSectionList, InfSectionObject, ContainerFile, SectionType): ReFindSpecialCommentRe = re.compile(r"""#(?:\s*)\[(.*?)\](?:.*)""", re.DOTALL) ReFindHobArchRe = re.compile(r"""[Hh][Oo][Bb]\.([^,]*)""", re.DOTALL) if self.FileName: pass SpecialObjectList = [] ArchList = [] if SectionType == DT.TYPE_EVENT_SECTION: TokenDict = DT.EVENT_TOKENS elif SectionType == DT.TYPE_HOB_SECTION: TokenDict = DT.HOB_TOKENS else: TokenDict = DT.BOOTMODE_TOKENS for List in SpecialSectionList: # # Hob has Arch attribute, need to be handled specially here # if SectionType == DT.TYPE_HOB_SECTION: MatchObject = ReFindSpecialCommentRe.search(List[0][0]) HobSectionStr = MatchObject.group(1) ArchList = [] for Match in ReFindHobArchRe.finditer(HobSectionStr): Arch = Match.groups(1)[0].upper() ArchList.append(Arch) CommentSoFar = '' for Index in range(1, len(List)): Result = ParseComment(List[Index], DT.ALL_USAGE_TOKENS, TokenDict, [], False) Usage = Result[0] Type = Result[1] HelpText = Result[3] if Usage == DT.ITEM_UNDEFINED and Type == DT.ITEM_UNDEFINED: if HelpText is None: HelpText = '' if not HelpText.endswith('\n'): HelpText += '\n' CommentSoFar += HelpText else: if HelpText: CommentSoFar += HelpText if SectionType == DT.TYPE_EVENT_SECTION: SpecialObject = InfEventObject() SpecialObject.SetEventType(Type) SpecialObject.SetUsage(Usage) SpecialObject.SetHelpString(CommentSoFar) elif SectionType == DT.TYPE_HOB_SECTION: SpecialObject = InfHobObject() SpecialObject.SetHobType(Type) SpecialObject.SetUsage(Usage) SpecialObject.SetHelpString(CommentSoFar) if len(ArchList) >= 1: SpecialObject.SetSupArchList(ArchList) else: SpecialObject = InfBootModeObject() SpecialObject.SetSupportedBootModes(Type) SpecialObject.SetUsage(Usage) SpecialObject.SetHelpString(CommentSoFar) SpecialObjectList.append(SpecialObject) CommentSoFar = '' if not InfSectionObject.SetSpecialComments(SpecialObjectList, SectionType): Logger.Error( 'InfParser', FORMAT_INVALID, ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % (SectionType), ContainerFile)
def InfDepexParser(self, SectionString, InfSectionObject, FileName): DepexContent = [] DepexComment = [] ValueList = [] # # Parse section content # for Line in SectionString: LineContent = Line[0] LineNo = Line[1] # # Found comment # if LineContent.strip().startswith(DT.TAB_COMMENT_SPLIT): DepexComment.append((LineContent, LineNo)) continue # # Replace with [Defines] section Macro # LineContent = InfExpandMacro(LineContent, (FileName, LineContent, Line[1]), self.FileLocalMacros, None, True) CommentCount = LineContent.find(DT.TAB_COMMENT_SPLIT) if CommentCount > -1: DepexComment.append((LineContent[CommentCount:], LineNo)) LineContent = LineContent[:CommentCount-1] CommentCount = -1 DepexContent.append((LineContent, LineNo)) TokenList = GetSplitValueList(LineContent, DT.TAB_COMMENT_SPLIT) ValueList[0:len(TokenList)] = TokenList # # Current section archs # KeyList = [] LastItem = '' for Item in self.LastSectionHeaderContent: LastItem = Item if (Item[1], Item[2], Item[3]) not in KeyList: KeyList.append((Item[1], Item[2], Item[3])) NewCommentList = [] FormatCommentLn = -1 ReFormatComment = re.compile(r"""#(?:\s*)\[(.*?)\](?:.*)""", re.DOTALL) for CommentItem in DepexComment: CommentContent = CommentItem[0] if ReFormatComment.match(CommentContent) is not None: FormatCommentLn = CommentItem[1] + 1 continue if CommentItem[1] != FormatCommentLn: NewCommentList.append(CommentContent) else: FormatCommentLn = CommentItem[1] + 1 if not InfSectionObject.SetDepex(DepexContent, KeyList = KeyList, CommentList = NewCommentList): Logger.Error('InfParser', FORMAT_INVALID, ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR%("[Depex]"), File=FileName, Line=LastItem[3])
def GenPackageHeader(self, ContainerFile): Logger.Debug(2, "Generate PackageHeader ...") DefinesDict = {} # # Update all defines item in database # DefObj = self.DecParser.GetDefineSectionObject() for Item in DefObj.GetDefines(): # # put items into Dict except for PackageName, Guid, Version, DEC_SPECIFICATION # SkipItemList = [TAB_DEC_DEFINES_PACKAGE_NAME, \ TAB_DEC_DEFINES_PACKAGE_GUID, TAB_DEC_DEFINES_PACKAGE_VERSION, \ TAB_DEC_DEFINES_DEC_SPECIFICATION, TAB_DEC_DEFINES_PKG_UNI_FILE] if Item.Key in SkipItemList: continue DefinesDict['%s = %s' % (Item.Key, Item.Value)] = TAB_ARCH_COMMON self.SetBaseName(DefObj.GetPackageName()) self.SetVersion(DefObj.GetPackageVersion()) # self.SetName(DefObj.GetPackageName() + ' Version ' + \ # DefObj.GetPackageVersion()) self.SetName(os.path.splitext(self.GetFileName())[0]) self.SetGuid(DefObj.GetPackageGuid()) if DefObj.GetPackageUniFile(): ValidateUNIFilePath(DefObj.GetPackageUniFile()) self.UniFileClassObject = \ UniFileClassObject([PathClass(os.path.join(DefObj.GetPackagePath(), DefObj.GetPackageUniFile()))]) else: self.UniFileClassObject = None if DefinesDict: UserExtension = UserExtensionObject() UserExtension.SetDefinesDict(DefinesDict) UserExtension.SetIdentifier('DefineModifiers') UserExtension.SetUserID('EDK2') self.SetUserExtensionList(self.GetUserExtensionList() + [UserExtension]) # # Get File header information # if self.UniFileClassObject: Lang = TAB_LANGUAGE_EN_X else: Lang = TAB_LANGUAGE_EN_US Abstract, Description, Copyright, License = \ ParseHeaderCommentSection(self.DecParser.GetHeadComment(), ContainerFile) if Abstract: self.SetAbstract((Lang, Abstract)) if Description: self.SetDescription((Lang, Description)) if Copyright: self.SetCopyright(('', Copyright)) if License: self.SetLicense(('', License)) # # Get Binary header information # if self.DecParser.BinaryHeadComment: Abstract, Description, Copyright, License = \ ParseHeaderCommentSection(self.DecParser.BinaryHeadComment, ContainerFile, True) if not Abstract or not Description or not Copyright or not License: Logger.Error('MkPkg', FORMAT_INVALID, ST.ERR_INVALID_BINARYHEADER_FORMAT, ContainerFile) else: self.SetBinaryHeaderAbstract((Lang, Abstract)) self.SetBinaryHeaderDescription((Lang, Description)) self.SetBinaryHeaderCopyright(('', Copyright)) self.SetBinaryHeaderLicense(('', License)) BinaryAbstractList = [] BinaryDescriptionList = [] #Get Binary header from UNI file # Initialize the UniStrDict dictionary, top keys are language codes UniStrDict = {} if self.UniFileClassObject: UniStrDict = self.UniFileClassObject.OrderedStringList for Lang in UniStrDict: for StringDefClassObject in UniStrDict[Lang]: Lang = GetLanguageCode1766(Lang) if StringDefClassObject.StringName == TAB_DEC_BINARY_ABSTRACT: if (Lang, ConvertSpecialUnicodes(StringDefClassObject.StringValue)) \ not in self.GetBinaryHeaderAbstract(): BinaryAbstractList.append( (Lang, ConvertSpecialUnicodes( StringDefClassObject.StringValue))) if StringDefClassObject.StringName == TAB_DEC_BINARY_DESCRIPTION: if (Lang, ConvertSpecialUnicodes(StringDefClassObject.StringValue)) \ not in self.GetBinaryHeaderDescription(): BinaryDescriptionList.append( (Lang, ConvertSpecialUnicodes( StringDefClassObject.StringValue))) #Combine Binary header from DEC file and UNI file BinaryAbstractList = self.GetBinaryHeaderAbstract( ) + BinaryAbstractList BinaryDescriptionList = self.GetBinaryHeaderDescription( ) + BinaryDescriptionList BinaryCopyrightList = self.GetBinaryHeaderCopyright() BinaryLicenseList = self.GetBinaryHeaderLicense() #Generate the UserExtensionObject for TianoCore."BinaryHeader" if BinaryAbstractList or BinaryDescriptionList or BinaryCopyrightList or BinaryLicenseList: BinaryUserExtension = UserExtensionObject() BinaryUserExtension.SetBinaryAbstract(BinaryAbstractList) BinaryUserExtension.SetBinaryDescription(BinaryDescriptionList) BinaryUserExtension.SetBinaryCopyright(BinaryCopyrightList) BinaryUserExtension.SetBinaryLicense(BinaryLicenseList) BinaryUserExtension.SetIdentifier(TAB_BINARY_HEADER_IDENTIFIER) BinaryUserExtension.SetUserID(TAB_BINARY_HEADER_USERID) self.SetUserExtensionList(self.GetUserExtensionList() + [BinaryUserExtension])
def _GenInfDefineStateMent(HeaderComment, Name, Value, TailComment): Logger.Debug(5, HeaderComment + TailComment) Statement = '%s = %s' % (Name, Value) return Statement
def GenGuidProtocolPpis(self, Type, ContainerFile): if ContainerFile: pass Logger.Debug(2, "Generate %s ..." % Type) Obj = None Factory = None if Type == TAB_GUIDS: Obj = self.DecParser.GetGuidSectionObject() def CreateGuidObject(): Object = GuidObject() Object.SetGuidTypeList([]) Object.SetUsage(None) Object.SetName(None) return Object Factory = CreateGuidObject elif Type == TAB_PROTOCOLS: Obj = self.DecParser.GetProtocolSectionObject() def CreateProtocolObject(): return ProtocolObject() Factory = CreateProtocolObject elif Type == TAB_PPIS: Obj = self.DecParser.GetPpiSectionObject() def CreatePpiObject(): return PpiObject() Factory = CreatePpiObject else: # # Should not be here # return DeclarationsList = [] # # Go through each arch # for Item in Obj.GetGuidStyleAllItems(): Name = Item.GuidCName Value = Item.GuidString HelpTxt = ParseGenericComment(Item.GetHeadComment() + \ Item.GetTailComment()) ListObject = Factory() ListObject.SetCName(Name) ListObject.SetGuid(Value) ListObject.SetSupArchList(Item.GetArchList()) if HelpTxt: if self.UniFileClassObject: HelpTxt.SetLang(TAB_LANGUAGE_EN_X) ListObject.SetHelpTextList([HelpTxt]) DeclarationsList.append(ListObject) # #GuidTypeList is abstracted from help # if Type == TAB_GUIDS: self.SetGuidList(self.GetGuidList() + DeclarationsList) elif Type == TAB_PROTOCOLS: self.SetProtocolList(self.GetProtocolList() + DeclarationsList) elif Type == TAB_PPIS: self.SetPpiList(self.GetPpiList() + DeclarationsList)
def GenBinaryData(BinaryData, BinaryObj, BinariesDict, AsBuildIns, BinaryFileObjectList, \ SupArchList, BinaryModule, DecObjList=None): if BinaryModule: pass OriSupArchList = SupArchList for Item in BinaryData: ItemObj = BinaryObj[Item][0][0] if ItemObj.GetType( ) not in DT.BINARY_FILE_TYPE_UI_LIST + DT.BINARY_FILE_TYPE_VER_LIST: TagName = ItemObj.GetTagName() Family = ItemObj.GetFamily() else: TagName = '' Family = '' FFE = ItemObj.GetFeatureFlagExp() # # If have architecturie specified, then use the specified architecturie; # If the section tag does not have an architecture modifier or the modifier is "common" (case in-sensitive), # and the VALID_ARCHITECTURES comment exists, the list from the VALID_ARCHITECTURES comment # can be used for the attribute. # If both not have VALID_ARCHITECTURE comment and no architecturie specified, then keep it empty. # SupArchList = sorted(ConvertArchList(ItemObj.GetSupArchList())) if len(SupArchList) == 1 and SupArchList[0] == 'COMMON': if not (len(OriSupArchList) == 1 or OriSupArchList[0] == 'COMMON'): SupArchList = OriSupArchList else: SupArchList = ['COMMON'] FileNameObj = CommonObject.FileNameObject() FileNameObj.SetFileType(ItemObj.GetType()) FileNameObj.SetFilename(ItemObj.GetFileName()) FileNameObj.SetFeatureFlag(FFE) # # Get GUID value of the GUID CName in the DEC file # if ItemObj.GetType() == DT.SUBTYPE_GUID_BINARY_FILE_TYPE: if not CheckGuidRegFormat(ItemObj.GetGuidValue()): if not DecObjList: if DT.TAB_HORIZON_LINE_SPLIT in ItemObj.GetGuidValue() or \ DT.TAB_COMMA_SPLIT in ItemObj.GetGuidValue(): Logger.Error("\nMkPkg", FORMAT_INVALID, ST.ERR_DECPARSE_DEFINE_PKGGUID, ExtraData=ItemObj.GetGuidValue(), RaiseError=True) else: Logger.Error("\nMkPkg", FORMAT_INVALID, ST.ERR_UNI_SUBGUID_VALUE_DEFINE_DEC_NOT_FOUND % \ (ItemObj.GetGuidValue()), RaiseError=True) else: for DecObj in DecObjList: for GuidObj in DecObj.GetGuidList(): if GuidObj.GetCName() == ItemObj.GetGuidValue(): FileNameObj.SetGuidValue(GuidObj.GetGuid()) break if not FileNameObj.GetGuidValue(): Logger.Error("\nMkPkg", FORMAT_INVALID, ST.ERR_DECPARSE_CGUID_NOT_FOUND % \ (ItemObj.GetGuidValue()), RaiseError=True) else: FileNameObj.SetGuidValue(ItemObj.GetGuidValue().strip()) FileNameObj.SetSupArchList(SupArchList) FileNameList = [FileNameObj] BinaryFile = BinaryFileObject() BinaryFile.SetFileNameList(FileNameList) BinaryFile.SetAsBuiltList(AsBuildIns) BinaryFileObjectList.append(BinaryFile) SupArchStr = ' '.join(SupArchList) Key = (ItemObj.GetFileName(), ItemObj.GetType(), FFE, SupArchStr) ValueItem = (ItemObj.GetTarget(), Family, TagName, '') if Key in BinariesDict: ValueList = BinariesDict[Key] ValueList.append(ValueItem) BinariesDict[Key] = ValueList else: BinariesDict[Key] = [ValueItem] return BinariesDict, AsBuildIns, BinaryFileObjectList
def CheckPcdValue(self): for Pcd in self.GetPcdList(): self.PcdDefaultValueDict[TAB_SPLIT.join((Pcd.GetTokenSpaceGuidCName(), Pcd.GetCName())).strip()] = \ Pcd.GetDefaultValue() for Pcd in self.GetPcdList(): ValidationExpressions = [] PcdGuidName = TAB_SPLIT.join( (Pcd.GetTokenSpaceGuidCName(), Pcd.GetCName())) Valids = Pcd.GetPcdErrorsList() for Valid in Valids: Expression = Valid.GetExpression() if Expression: # # Delete the 'L' prefix of a quoted string, this operation is for eval() # QUOTED_PATTERN = '[\t\s]*L?"[^"]*"' QuotedMatchedObj = re.search(QUOTED_PATTERN, Expression) if QuotedMatchedObj: MatchedStr = QuotedMatchedObj.group().strip() if MatchedStr.startswith('L'): Expression = Expression.replace( MatchedStr, MatchedStr[1:].strip()) Expression = self.ReplaceForEval(Expression, IsExpr=True) Expression = Expression.replace(PcdGuidName, 'x') Message = self.GetEnErrorMessage( Valid.GetErrorMessageList()) ValidationExpressions.append((Expression, Message)) ValidList = Valid.GetValidValue() if ValidList: ValidValue = 'x in %s' % [ eval(v) for v in ValidList.split(' ') if v ] Message = self.GetEnErrorMessage( Valid.GetErrorMessageList()) ValidationExpressions.append((ValidValue, Message)) ValidValueRange = Valid.GetValidValueRange() if ValidValueRange: ValidValueRange = self.ReplaceForEval(ValidValueRange, IsRange=True) if ValidValueRange.find('-') >= 0: ValidValueRange = ValidValueRange.replace( '-', '<= x <=') elif not ValidValueRange.startswith('x ') and not ValidValueRange.startswith('not ') \ and not ValidValueRange.startswith('not(') and not ValidValueRange.startswith('('): ValidValueRange = 'x %s' % ValidValueRange Message = self.GetEnErrorMessage( Valid.GetErrorMessageList()) ValidationExpressions.append((ValidValueRange, Message)) DefaultValue = self.PcdDefaultValueDict[PcdGuidName.strip()] # # Delete the 'L' prefix of a quoted string, this operation is for eval() # QUOTED_PATTERN = '[\t\s]*L?"[^"]*"' QuotedMatchedObj = re.search(QUOTED_PATTERN, DefaultValue) if QuotedMatchedObj: MatchedStr = QuotedMatchedObj.group().strip() if MatchedStr.startswith('L'): DefaultValue = DefaultValue.replace( MatchedStr, MatchedStr[1:].strip()) try: DefaultValue = eval( DefaultValue.replace('TRUE', 'True').replace( 'true', 'True').replace('FALSE', 'False').replace('false', 'False')) except BaseException: pass for (Expression, Msg) in ValidationExpressions: try: if not eval(Expression, {'x': DefaultValue}): Logger.Error("Dec File Parser", FORMAT_INVALID, ExtraData='%s, value = %s' %\ (PcdGuidName, DefaultValue), Message=Msg, File=self.FullPath) except TypeError: Logger.Error("Dec File Parser", FORMAT_INVALID, ExtraData=PcdGuidName, \ Message=Msg, File=self.FullPath)
def Main(): Logger.Initialize() Parser = OptionParser(version=(MSG_VERSION + ' Build ' + gBUILD_VERSION), description=MSG_DESCRIPTION, prog="UPT.exe", usage=MSG_USAGE) Parser.add_option("-d", "--debug", action="store", type="int", dest="debug_level", help=ST.HLP_PRINT_DEBUG_INFO) Parser.add_option("-v", "--verbose", action="store_true", dest="opt_verbose", help=ST.HLP_PRINT_INFORMATIONAL_STATEMENT) Parser.add_option("-s", "--silent", action="store_true", dest="opt_slient", help=ST.HLP_RETURN_NO_DISPLAY) Parser.add_option("-q", "--quiet", action="store_true", dest="opt_quiet", help=ST.HLP_RETURN_AND_DISPLAY) Parser.add_option("-i", "--install", action="append", type="string", dest="Install_Distribution_Package_File", help=ST.HLP_SPECIFY_PACKAGE_NAME_INSTALL) Parser.add_option("-c", "--create", action="store", type="string", dest="Create_Distribution_Package_File", help=ST.HLP_SPECIFY_PACKAGE_NAME_CREATE) Parser.add_option("-r", "--remove", action="store", type="string", dest="Remove_Distribution_Package_File", help=ST.HLP_SPECIFY_PACKAGE_NAME_REMOVE) Parser.add_option("-t", "--template", action="store", type="string", dest="Package_Information_Data_File", help=ST.HLP_SPECIFY_TEMPLATE_NAME_CREATE) Parser.add_option("-p", "--dec-filename", action="append", type="string", dest="EDK2_DEC_Filename", help=ST.HLP_SPECIFY_DEC_NAME_CREATE) Parser.add_option("-m", "--inf-filename", action="append", type="string", dest="EDK2_INF_Filename", help=ST.HLP_SPECIFY_INF_NAME_CREATE) Parser.add_option("-l", "--list", action="store_true", dest="List_Dist_Installed", help=ST.HLP_LIST_DIST_INSTALLED) Parser.add_option("-f", "--force", action="store_true", dest="Yes", help=ST.HLP_DISABLE_PROMPT) Parser.add_option("-n", "--custom-path", action="store_true", dest="CustomPath", help=ST.HLP_CUSTOM_PATH_PROMPT) Parser.add_option("-x", "--free-lock", action="store_true", dest="SkipLock", help=ST.HLP_SKIP_LOCK_CHECK) Parser.add_option("-u", "--replace", action="store", type="string", dest="Replace_Distribution_Package_File", help=ST.HLP_SPECIFY_PACKAGE_NAME_REPLACE) Parser.add_option("-o", "--original", action="store", type="string", dest="Original_Distribution_Package_File", help=ST.HLP_SPECIFY_PACKAGE_NAME_TO_BE_REPLACED) Parser.add_option("--use-guided-paths", action="store_true", dest="Use_Guided_Paths", help=ST.HLP_USE_GUIDED_PATHS) Parser.add_option("-j", "--test-install", action="append", type="string", dest="Test_Install_Distribution_Package_Files", help=ST.HLP_TEST_INSTALL) Opt = Parser.parse_args()[0] Var2Var = [ ("PackageInformationDataFile", Opt.Package_Information_Data_File), ("PackFileToInstall", Opt.Install_Distribution_Package_File), ("PackFileToCreate", Opt.Create_Distribution_Package_File), ("PackFileToRemove", Opt.Remove_Distribution_Package_File), ("PackageFileList", Opt.EDK2_DEC_Filename), ("ModuleFileList", Opt.EDK2_INF_Filename), ("InventoryWs", Opt.List_Dist_Installed), ("PackFileToReplace", Opt.Replace_Distribution_Package_File), ("PackFileToBeReplaced", Opt.Original_Distribution_Package_File), ("UseGuidedPkgPath", Opt.Use_Guided_Paths), ("TestDistFiles", Opt.Test_Install_Distribution_Package_Files) ] for Var in Var2Var: setattr(Opt, Var[0], Var[1]) try: GlobalData.gWORKSPACE, GlobalData.gPACKAGE_PATH = GetWorkspace() except FatalError as XExcept: if Logger.GetLevel() <= Logger.DEBUG_9: Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + format_exc()) return XExcept.args[0] # Support WORKSPACE is a long path # Only works for windows system if pf.system() == 'Windows': Vol = 'B:' for Index in range(90, 65, -1): Vol = chr(Index) + ':' if not os.path.isdir(Vol): os.system('subst %s "%s"' % (Vol, GlobalData.gWORKSPACE)) break GlobalData.gWORKSPACE = '%s\\' % Vol WorkspaceDir = GlobalData.gWORKSPACE SetLogLevel(Opt) Mgr = FileHook.RecoverMgr(WorkspaceDir) FileHook.SetRecoverMgr(Mgr) GlobalData.gDB = IpiDatabase(os.path.normpath(os.path.join(WorkspaceDir, \ "Conf/DistributionPackageDatabase.db")), WorkspaceDir) GlobalData.gDB.InitDatabase(Opt.SkipLock) # # 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 elif Opt.PackFileToInstall: AbsPath = [] for Item in Opt.PackFileToInstall: if not Item.endswith('.dist'): Logger.Error("InstallPkg", FILE_TYPE_MISMATCH, ExtraData=ST.ERR_DIST_EXT_ERROR % Item) AbsPath.append(GetFullPathDist(Item, WorkspaceDir)) if not AbsPath: Logger.Error("InstallPkg", FILE_NOT_FOUND, ST.ERR_INSTALL_DIST_NOT_FOUND % Item) Opt.PackFileToInstall = AbsPath setattr(Opt, 'PackageFile', Opt.PackFileToInstall) RunModule = InstallPkg.Main elif Opt.PackFileToRemove: if not Opt.PackFileToRemove.endswith('.dist'): Logger.Error("RemovePkg", FILE_TYPE_MISMATCH, ExtraData=ST.ERR_DIST_EXT_ERROR % Opt.PackFileToRemove) head, tail = os.path.split(Opt.PackFileToRemove) if head or not tail: Logger.Error("RemovePkg", FILE_TYPE_MISMATCH, ExtraData=ST.ERR_DIST_FILENAME_ONLY_FOR_REMOVE % Opt.PackFileToRemove) setattr(Opt, 'DistributionFile', Opt.PackFileToRemove) RunModule = RmPkg.Main elif Opt.InventoryWs: RunModule = InventoryWs.Main elif Opt.PackFileToBeReplaced and not Opt.PackFileToReplace: Logger.Error("ReplacePkg", OPTION_MISSING, ExtraData=ST.ERR_REQUIRE_U_OPTION) elif Opt.PackFileToReplace: if not Opt.PackFileToReplace.endswith('.dist'): Logger.Error("ReplacePkg", FILE_TYPE_MISMATCH, ExtraData=ST.ERR_DIST_EXT_ERROR % Opt.PackFileToReplace) if not Opt.PackFileToBeReplaced: Logger.Error("ReplacePkg", OPTION_MISSING, ExtraData=ST.ERR_REQUIRE_O_OPTION) if not Opt.PackFileToBeReplaced.endswith('.dist'): Logger.Error("ReplacePkg", FILE_TYPE_MISMATCH, ExtraData=ST.ERR_DIST_EXT_ERROR % Opt.PackFileToBeReplaced) head, tail = os.path.split(Opt.PackFileToBeReplaced) if head or not tail: Logger.Error( "ReplacePkg", FILE_TYPE_MISMATCH, ExtraData=ST.ERR_DIST_FILENAME_ONLY_FOR_REPLACE_ORIG % Opt.PackFileToBeReplaced) AbsPath = GetFullPathDist(Opt.PackFileToReplace, WorkspaceDir) if not AbsPath: Logger.Error( "ReplacePkg", FILE_NOT_FOUND, ST.ERR_REPLACE_DIST_NOT_FOUND % Opt.PackFileToReplace) Opt.PackFileToReplace = AbsPath RunModule = ReplacePkg.Main elif Opt.Test_Install_Distribution_Package_Files: for Dist in Opt.Test_Install_Distribution_Package_Files: if not Dist.endswith('.dist'): Logger.Error("TestInstall", FILE_TYPE_MISMATCH, ExtraData=ST.ERR_DIST_EXT_ERROR % Dist) setattr(Opt, 'DistFiles', Opt.Test_Install_Distribution_Package_Files) RunModule = TestInstall.Main else: Parser.print_usage() return OPTION_MISSING ReturnCode = RunModule(Opt) except FatalError as XExcept: ReturnCode = XExcept.args[0] if Logger.GetLevel() <= Logger.DEBUG_9: Logger.Quiet(ST.MSG_PYTHON_ON % (python_version(), platform) + \ format_exc()) finally: try: if ReturnCode != 0 and ReturnCode != UPT_ALREADY_INSTALLED_ERROR: Logger.Quiet(ST.MSG_RECOVER_START) GlobalData.gDB.RollBack() Mgr.rollback() Logger.Quiet(ST.MSG_RECOVER_DONE) else: GlobalData.gDB.Commit() Mgr.commit() except Exception: Logger.Quiet(ST.MSG_RECOVER_FAIL) GlobalData.gDB.CloseDb() if pf.system() == 'Windows': os.system('subst %s /D' % GlobalData.gWORKSPACE.replace('\\', '')) return ReturnCode
def InfPcdParser(self, SectionString, InfSectionObject, FileName): KeysList = [] PcdList = [] CommentsList = [] ValueList = [] # # Current section archs # LineIndex = -1 for Item in self.LastSectionHeaderContent: if (Item[0], Item[1], Item[3]) not in KeysList: KeysList.append((Item[0], Item[1], Item[3])) LineIndex = Item[3] if (Item[0].upper() == DT.TAB_INF_FIXED_PCD.upper() or \ Item[0].upper() == DT.TAB_INF_FEATURE_PCD.upper() or \ Item[0].upper() == DT.TAB_INF_PCD.upper()) and GlobalData.gIS_BINARY_INF: Logger.Error('InfParser', FORMAT_INVALID, ST.ERR_ASBUILD_PCD_SECTION_TYPE % ("\"" + Item[0] + "\""), File=FileName, Line=LineIndex) # # For Common INF file # if not GlobalData.gIS_BINARY_INF: # # Macro defined in this section # SectionMacros = {} for Line in SectionString: PcdLineContent = Line[0] PcdLineNo = Line[1] if PcdLineContent.strip() == '': CommentsList = [] continue if PcdLineContent.strip().startswith(DT.TAB_COMMENT_SPLIT): CommentsList.append(Line) continue else: # # Encounter a PCD entry # if PcdLineContent.find(DT.TAB_COMMENT_SPLIT) > -1: CommentsList.append( (PcdLineContent[PcdLineContent. find(DT.TAB_COMMENT_SPLIT):], PcdLineNo)) PcdLineContent = PcdLineContent[:PcdLineContent.find( DT.TAB_COMMENT_SPLIT)] if PcdLineContent != '': # # Find Macro # Name, Value = MacroParser((PcdLineContent, PcdLineNo), FileName, DT.MODEL_EFI_PCD, self.FileLocalMacros) if Name is not None: SectionMacros[Name] = Value ValueList = [] CommentsList = [] continue PcdEntryReturn = SplitPcdEntry(PcdLineContent) if not PcdEntryReturn[1]: TokenList = [''] else: TokenList = PcdEntryReturn[0] ValueList[0:len(TokenList)] = TokenList # # Replace with Local section Macro and [Defines] section Macro. # ValueList = [ InfExpandMacro(Value, (FileName, PcdLineContent, PcdLineNo), self.FileLocalMacros, SectionMacros, True) for Value in ValueList ] if len(ValueList) >= 1: PcdList.append((ValueList, CommentsList, (PcdLineContent, PcdLineNo, FileName))) ValueList = [] CommentsList = [] continue # # For Binary INF file # else: for Line in SectionString: LineContent = Line[0].strip() LineNo = Line[1] if LineContent == '': CommentsList = [] continue if LineContent.startswith(DT.TAB_COMMENT_SPLIT): CommentsList.append(LineContent) continue # # Have comments at tail. # CommentIndex = LineContent.find(DT.TAB_COMMENT_SPLIT) if CommentIndex > -1: CommentsList.append(LineContent[CommentIndex + 1:]) LineContent = LineContent[:CommentIndex] TokenList = GetSplitValueList(LineContent, DT.TAB_VALUE_SPLIT) # # PatchablePcd # TokenSpace.CName | Value | Offset # if KeysList[0][0].upper() == DT.TAB_INF_PATCH_PCD.upper(): if len(TokenList) != 3: Logger.Error('InfParser', FORMAT_INVALID, ST.ERR_ASBUILD_PATCHPCD_FORMAT_INVALID, File=FileName, Line=LineNo, ExtraData=LineContent) # elif KeysList[0][0].upper() == DT.TAB_INF_PCD_EX.upper(): if len(TokenList) != 1: Logger.Error('InfParser', FORMAT_INVALID, ST.ERR_ASBUILD_PCDEX_FORMAT_INVALID, File=FileName, Line=LineNo, ExtraData=LineContent) ValueList[0:len(TokenList)] = TokenList if len(ValueList) >= 1: PcdList.append((ValueList, CommentsList, (LineContent, LineNo, FileName))) ValueList = [] CommentsList = [] continue if not InfSectionObject.SetPcds( PcdList, KeysList=KeysList, PackageInfo=self.InfPackageSection.GetPackages()): Logger.Error('InfParser', FORMAT_INVALID, ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % ("[PCD]"), File=FileName, Line=LineIndex)
def SetPcds(self, PcdContent, KeysList=None, PackageInfo=None): if GlobalData.gIS_BINARY_INF: self.SetAsBuildPcds(PcdContent, KeysList, PackageInfo) return True # # Validate Arch # SupArchList = [] SupArchDict = {} PcdTypeItem = '' for (PcdTypeItem1, ArchItem, LineNo) in KeysList: SupArchList, SupArchDict = ValidateArch(ArchItem, PcdTypeItem1, LineNo, SupArchDict, SupArchList) # # Validate PcdType # if (PcdTypeItem1 == '' or PcdTypeItem1 is None): return False else: if not IsValidPcdType(PcdTypeItem1): Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_PCD_SECTION_TYPE_ERROR % (DT.PCD_USAGE_TYPE_LIST_OF_MODULE), File=GlobalData.gINF_MODULE_NAME, Line=LineNo, ExtraData=PcdTypeItem1) return False PcdTypeItem = PcdTypeItem1 for PcdItem in PcdContent: PcdItemObj = InfPcdItem() CommentList = PcdItem[1] CurrentLineOfPcdItem = PcdItem[2] PcdItem = PcdItem[0] if CommentList is not None and len(CommentList) != 0: PcdItemObj = ParsePcdComment(CommentList, PcdTypeItem, PcdItemObj) else: CommentItemIns = InfPcdItemCommentContent() CommentItemIns.SetUsageItem(DT.ITEM_UNDEFINED) PcdItemObj.SetHelpStringList([CommentItemIns]) if len(PcdItem) >= 1 and len(PcdItem) <= 3: PcdItemObj = SetPcdName(PcdItem, CurrentLineOfPcdItem, PcdItemObj) if len(PcdItem) >= 2 and len(PcdItem) <= 3: # # Contain PcdName and Value, validate value. # if IsValidPcdValue(PcdItem[1]) or PcdItem[1].strip() == "": PcdItemObj.SetDefaultValue(PcdItem[1]) else: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_PCD_VALUE_INVALID, File=CurrentLineOfPcdItem[2], Line=CurrentLineOfPcdItem[1], ExtraData=PcdItem[1]) if len(PcdItem) == 3: # # Contain PcdName, value, and FeatureFlag express # # # Validate Feature Flag Express # if PcdItem[2].strip() == '': Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING, File=CurrentLineOfPcdItem[2], Line=CurrentLineOfPcdItem[1], ExtraData=CurrentLineOfPcdItem[0]) # # Validate FFE # FeatureFlagRtv = IsValidFeatureFlagExp(PcdItem[2].strip()) if not FeatureFlagRtv[0]: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID % (FeatureFlagRtv[1]), File=CurrentLineOfPcdItem[2], Line=CurrentLineOfPcdItem[1], ExtraData=CurrentLineOfPcdItem[0]) PcdItemObj.SetFeatureFlagExp(PcdItem[2]) if len(PcdItem) < 1 or len(PcdItem) > 3: Logger.Error("InfParser", ToolError.FORMAT_INVALID, ST.ERR_INF_PARSER_PCD_SECTION_CONTENT_ERROR, File=CurrentLineOfPcdItem[2], Line=CurrentLineOfPcdItem[1], ExtraData=CurrentLineOfPcdItem[0]) return False if PcdTypeItem.upper != DT.TAB_INF_FEATURE_PCD.upper(): PcdItemObj.SetSupportArchList(SupArchDict[PcdTypeItem]) else: PcdItemObj.SetSupportArchList(SupArchList) if (PcdTypeItem, PcdItemObj) in self.Pcds: PcdsList = self.Pcds[PcdTypeItem, PcdItemObj] PcdsList.append(PcdItemObj) self.Pcds[PcdTypeItem, PcdItemObj] = PcdsList else: PcdsList = [] PcdsList.append(PcdItemObj) self.Pcds[PcdTypeItem, PcdItemObj] = PcdsList return True