X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FCommon%2FFdfParserLite.py;h=806fdd8aa5bb487cdbb23da1ffc5ecea51927e44;hp=031dc15bc7665b8cab3de77b574a999202ffb098;hb=4d603daa3a2276d98ac6749d1db8e327ff7c1f5f;hpb=4afd3d042215afe68d00b9ab8c32f063a3a1c03f diff --git a/BaseTools/Source/Python/Common/FdfParserLite.py b/BaseTools/Source/Python/Common/FdfParserLite.py index 031dc15bc7..806fdd8aa5 100644 --- a/BaseTools/Source/Python/Common/FdfParserLite.py +++ b/BaseTools/Source/Python/Common/FdfParserLite.py @@ -1,7 +1,7 @@ ## @file # parse FDF file # -# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.
+# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
# # This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License @@ -16,9 +16,12 @@ # Import Modules # import re -import os +import Common.LongFilePathOs as os import CommonDataClass.FdfClass +from Common.LongFilePathSupport import OpenLongFilePath as open +from Common.MultipleWorkspace import MultipleWorkspace as mws +from Common.RangeExpression import RangeExpression ##define T_CHAR_SPACE ' ' ##define T_CHAR_NULL '\0' @@ -44,6 +47,8 @@ InputMacroDict = {} # All Macro values when parsing file, not replace existing Macro AllMacroList = [] +FileExtensionPattern = re.compile(r'([a-zA-Z][a-zA-Z0-9]*)') + def GetRealFileLine (File, Line): InsertedLines = 0 @@ -67,8 +72,8 @@ class Warning (Exception): # @param File The FDF name # @param Line The Line number that error occurs # - def __init__(self, Str, File = None, Line = None): - + def __init__(self, Str, File=None, Line=None): + FileLineTuple = GetRealFileLine(File, Line) self.FileName = FileLineTuple[0] self.LineNumber = FileLineTuple[1] @@ -357,8 +362,8 @@ class FdfParser(object): else: raise Warning("Macro not complete At Line ", self.FileName, self.CurrentLineNumber) return Str - - def __ReplaceFragment(self, StartPos, EndPos, Value = ' '): + + def __ReplaceFragment(self, StartPos, EndPos, Value=' '): if StartPos[0] == EndPos[0]: Offset = StartPos[1] while Offset <= EndPos[1]: @@ -484,7 +489,8 @@ class FdfParser(object): IncFileName = self.__Token if not os.path.isabs(IncFileName): if IncFileName.startswith('$(WORKSPACE)'): - Str = IncFileName.replace('$(WORKSPACE)', os.environ.get('WORKSPACE')) + Str = mws.handleWsMacro(IncFileName) + Str = Str.replace('$(WORKSPACE)', os.environ.get('WORKSPACE')) if os.path.exists(Str): if not os.path.isabs(Str): Str = os.path.abspath(Str) @@ -493,7 +499,7 @@ class FdfParser(object): # file is in the same dir with FDF file FullFdf = self.FileName if not os.path.isabs(self.FileName): - FullFdf = os.path.join(os.environ.get('WORKSPACE'), self.FileName) + FullFdf = mws.join(os.environ.get('WORKSPACE'), self.FileName) IncFileName = os.path.join(os.path.dirname(FullFdf), IncFileName) @@ -928,8 +934,7 @@ class FdfParser(object): if not self.__GetNextToken(): return False - p = re.compile('[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}') - if p.match(self.__Token) != None: + if RangeExpression.RegGuidPattern.match(self.__Token) != None: return True else: self.__UndoToken() @@ -2337,7 +2342,8 @@ class FdfParser(object): AlignValue = None if self.__GetAlignment(): - if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K"): + if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K", "128K", + "256K", "512K", "1M", "2M", "4M", "8M", "16M"): raise Warning("Incorrect alignment '%s'" % self.__Token, self.FileName, self.CurrentLineNumber) AlignValue = self.__Token @@ -2605,7 +2611,8 @@ class FdfParser(object): AlignValue = None if self.__GetAlignment(): - if self.__Token not in ("8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K"): + if self.__Token not in ("8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K", "128K", + "256K", "512K", "1M", "2M", "4M", "8M", "16M"): raise Warning("Incorrect alignment '%s'" % self.__Token, self.FileName, self.CurrentLineNumber) AlignValue = self.__Token @@ -2820,7 +2827,7 @@ class FdfParser(object): "DXE_SMM_DRIVER", "DXE_RUNTIME_DRIVER", \ "UEFI_DRIVER", "UEFI_APPLICATION", "USER_DEFINED", "DEFAULT", "BASE", \ "SECURITY_CORE", "COMBINED_PEIM_DRIVER", "PIC_PEIM", "RELOCATABLE_PEIM", \ - "PE32_PEIM", "BS_DRIVER", "RT_DRIVER", "SAL_RT_DRIVER", "APPLICATION", "ACPITABLE", "SMM_CORE"): + "PE32_PEIM", "BS_DRIVER", "RT_DRIVER", "SAL_RT_DRIVER", "APPLICATION", "ACPITABLE", "SMM_CORE", "MM_STANDALONE", "MM_CORE_STANDALONE"): raise Warning("Unknown Module type At line ", self.FileName, self.CurrentLineNumber) return self.__Token @@ -2837,8 +2844,7 @@ class FdfParser(object): Ext = "" if self.__GetNextToken(): - Pattern = re.compile(r'([a-zA-Z][a-zA-Z0-9]*)') - if Pattern.match(self.__Token): + if FileExtensionPattern.match(self.__Token): Ext = self.__Token return '.' + Ext else: @@ -2864,7 +2870,7 @@ class FdfParser(object): Type = self.__Token.strip().upper() if Type not in ("RAW", "FREEFORM", "SEC", "PEI_CORE", "PEIM",\ - "PEI_DXE_COMBO", "DRIVER", "DXE_CORE", "APPLICATION", "FV_IMAGE", "SMM", "SMM_CORE"): + "PEI_DXE_COMBO", "DRIVER", "DXE_CORE", "APPLICATION", "FV_IMAGE", "SMM", "SMM_CORE", "MM_STANDALONE"): raise Warning("Unknown FV type At line ", self.FileName, self.CurrentLineNumber) if not self.__IsToken("="): @@ -2921,7 +2927,8 @@ class FdfParser(object): AlignValue = "" if self.__GetAlignment(): - if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K"): + if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K", "128K", + "256K", "512K", "1M", "2M", "4M", "8M", "16M"): raise Warning("Incorrect alignment At Line ", self.FileName, self.CurrentLineNumber) AlignValue = self.__Token @@ -2985,7 +2992,8 @@ class FdfParser(object): CheckSum = True if self.__GetAlignment(): - if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K"): + if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K", "128K", + "256K", "512K", "1M", "2M", "4M", "8M", "16M"): raise Warning("Incorrect alignment At Line ", self.FileName, self.CurrentLineNumber) if self.__Token == 'Auto' and (not SectionName == 'PE32') and (not SectionName == 'TE'): raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber) @@ -3059,7 +3067,8 @@ class FdfParser(object): FvImageSectionObj.FvFileType = self.__Token if self.__GetAlignment(): - if self.__Token not in ("8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K"): + if self.__Token not in ("8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K", "128K", + "256K", "512K", "1M", "2M", "4M", "8M", "16M"): raise Warning("Incorrect alignment At Line ", self.FileName, self.CurrentLineNumber) FvImageSectionObj.Alignment = self.__Token @@ -3126,7 +3135,8 @@ class FdfParser(object): EfiSectionObj.BuildNum = self.__Token if self.__GetAlignment(): - if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K"): + if self.__Token not in ("Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K" ,"64K", "128K", + "256K", "512K", "1M", "2M", "4M", "8M", "16M"): raise Warning("Incorrect alignment '%s'" % self.__Token, self.FileName, self.CurrentLineNumber) if self.__Token == 'Auto' and (not SectionName == 'PE32') and (not SectionName == 'TE'): raise Warning("Auto alignment can only be used in PE32 or TE section ", self.FileName, self.CurrentLineNumber)