diff options
Diffstat (limited to 'BaseTools/Source/Python/UPT/Parser')
9 files changed, 240 insertions, 188 deletions
diff --git a/BaseTools/Source/Python/UPT/Parser/DecParser.py b/BaseTools/Source/Python/UPT/Parser/DecParser.py index 060b9274f3..25407f9a2d 100644 --- a/BaseTools/Source/Python/UPT/Parser/DecParser.py +++ b/BaseTools/Source/Python/UPT/Parser/DecParser.py @@ -1,7 +1,7 @@ ## @file
# This file is used to parse DEC file. It will consumed by DecParser
#
-# Copyright (c) 2011 - 2013, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials are licensed and made available
# under the terms and conditions of the BSD License which accompanies this
@@ -60,6 +60,7 @@ from Library.String import ReplaceMacro from Library.String import GetSplitValueList
from Library.String import gMACRO_PATTERN
from Library.String import ConvertSpecialChar
+from Library.CommentParsing import ParsePcdErrorCode
##
# _DecBase class for parsing
@@ -77,6 +78,9 @@ class _DecBase: def GetDataObject(self):
return self.ItemObject
+ def GetLocalMacro(self):
+ return self._LocalMacro
+
## BlockStart
#
# Called if a new section starts
@@ -184,7 +188,7 @@ class _DecBase: self._LocalMacro[TokenList[0]] = ''
else:
self._LocalMacro[TokenList[0]] = self._ReplaceMacro(TokenList[1])
-
+
## _ParseItem
#
# Parse specified item, this function must be derived by subclass
@@ -395,6 +399,7 @@ class _DecDefine(_DecBase): DT.TAB_DEC_DEFINES_PACKAGE_NAME : self._SetPackageName,
DT.TAB_DEC_DEFINES_PACKAGE_GUID : self._SetPackageGuid,
DT.TAB_DEC_DEFINES_PACKAGE_VERSION : self._SetPackageVersion,
+ DT.TAB_DEC_DEFINES_PKG_UNI_FILE : self._SetPackageUni,
}
def BlockStart(self):
@@ -429,7 +434,7 @@ class _DecDefine(_DecBase): Line = self._RawData.CurrentLine
TokenList = GetSplitValueList(Line, DT.TAB_EQUAL_SPLIT, 1)
if TokenList[0] == DT.TAB_DEC_DEFINES_PKG_UNI_FILE:
- pass
+ self.DefineValidation[TokenList[0]](TokenList[1])
elif len(TokenList) < 2:
self._LoggerError(ST.ERR_DECPARSE_DEFINE_FORMAT)
elif TokenList[0] not in self.DefineValidation:
@@ -438,10 +443,9 @@ class _DecDefine(_DecBase): self.DefineValidation[TokenList[0]](TokenList[1])
DefineItem = DecDefineItemObject()
- if TokenList[0] != DT.TAB_DEC_DEFINES_PKG_UNI_FILE:
- DefineItem.Key = TokenList[0]
- DefineItem.Value = TokenList[1]
- self.ItemObject.AddItem(DefineItem, self._RawData.CurrentScope)
+ DefineItem.Key = TokenList[0]
+ DefineItem.Value = TokenList[1]
+ self.ItemObject.AddItem(DefineItem, self._RawData.CurrentScope)
return DefineItem
def _SetDecSpecification(self, Token):
@@ -473,7 +477,12 @@ class _DecDefine(_DecBase): else:
if not DT.TAB_SPLIT in Token:
Token = Token + '.0'
- self.ItemObject._PkgVersion = Token
+ self.ItemObject.SetPackageVersion(Token)
+
+ def _SetPackageUni(self, Token):
+ if self.ItemObject.GetPackageUniFile():
+ self._LoggerError(ST.ERR_DECPARSE_DEFINE_DEFINED % DT.TAB_DEC_DEFINES_PKG_UNI_FILE)
+ self.ItemObject.SetPackageUniFile(Token)
## _DecInclude
#
@@ -727,7 +736,7 @@ class _DecUserExtension(_DecBase): class Dec(_DecBase, _DecComments):
def __init__(self, DecFile, Parse = True):
try:
- Content = ConvertSpecialChar(open(DecFile, 'rb').readlines())
+ Content = ConvertSpecialChar(open(DecFile, 'rb').readlines())
except BaseException:
Logger.Error(TOOL_NAME, FILE_OPEN_FAILURE, File=DecFile,
ExtraData=ST.ERR_DECPARSE_FILEOPEN % DecFile)
@@ -736,7 +745,9 @@ class Dec(_DecBase, _DecComments): _DecComments.__init__(self)
_DecBase.__init__(self, RawData)
- self.BinaryHeadComment = []
+ self.BinaryHeadComment = []
+ self.PcdErrorCommentDict = {}
+
self._Define = _DecDefine(RawData)
self._Include = _DecInclude(RawData)
self._Guid = _DecGuid(RawData)
@@ -775,7 +786,7 @@ class Dec(_DecBase, _DecComments): if not SectionParser.CheckRequiredFields():
return False
return True
-
+
##
# Parse DEC file
#
@@ -784,9 +795,47 @@ class Dec(_DecBase, _DecComments): IsBinaryHeader = False
FileHeaderLineIndex = -1
BinaryHeaderLineIndex = -1
+ TokenSpaceGuidCName = ''
+
+ #
+ # Parse PCD error comment section
+ #
while not self._RawData.IsEndOfFile():
- Line, Comment = CleanString(self._RawData.GetNextLine())
+ self._RawData.CurrentLine = self._RawData.GetNextLine()
+ if self._RawData.CurrentLine.startswith(DT.TAB_COMMENT_SPLIT) and \
+ DT.TAB_SECTION_START in self._RawData.CurrentLine and \
+ DT.TAB_SECTION_END in self._RawData.CurrentLine:
+ self._RawData.CurrentLine = self._RawData.CurrentLine.replace(DT.TAB_COMMENT_SPLIT, '').strip()
+ if self._RawData.CurrentLine[0] == DT.TAB_SECTION_START and \
+ self._RawData.CurrentLine[-1] == DT.TAB_SECTION_END:
+ RawSection = self._RawData.CurrentLine[1:-1].strip()
+ if RawSection.upper().startswith(DT.TAB_PCD_ERROR.upper()+'.'):
+ TokenSpaceGuidCName = RawSection.split(DT.TAB_PCD_ERROR+'.')[1].strip()
+ continue
+
+ if TokenSpaceGuidCName and self._RawData.CurrentLine.startswith(DT.TAB_COMMENT_SPLIT):
+ self._RawData.CurrentLine = self._RawData.CurrentLine.replace(DT.TAB_COMMENT_SPLIT, '').strip()
+ if self._RawData.CurrentLine != '':
+ if DT.TAB_VALUE_SPLIT not in self._RawData.CurrentLine:
+ self._LoggerError(ST.ERR_DECPARSE_PCDERRORMSG_MISS_VALUE_SPLIT)
+
+ PcdErrorNumber, PcdErrorMsg = GetSplitValueList(self._RawData.CurrentLine, DT.TAB_VALUE_SPLIT, 1)
+ PcdErrorNumber = ParsePcdErrorCode(PcdErrorNumber, self._RawData.Filename, self._RawData.LineIndex)
+ if not PcdErrorMsg.strip():
+ self._LoggerError(ST.ERR_DECPARSE_PCD_MISS_ERRORMSG)
+
+ self.PcdErrorCommentDict[(TokenSpaceGuidCName, PcdErrorNumber)] = PcdErrorMsg.strip()
+ else:
+ TokenSpaceGuidCName = ''
+
+ self._RawData.LineIndex = 0
+ self._RawData.CurrentLine = ''
+ self._RawData.NextLine = ''
+
+ while not self._RawData.IsEndOfFile():
+ Line, Comment = CleanString(self._RawData.GetNextLine())
+
#
# Header must be pure comment
#
@@ -840,9 +889,10 @@ class Dec(_DecBase, _DecComments): self._LoggerError(ST.ERR_BINARY_HEADER_ORDER)
if FileHeaderLineIndex == -1:
+# self._LoggerError(ST.ERR_NO_SOURCE_HEADER)
Logger.Error(TOOL_NAME, FORMAT_INVALID,
ST.ERR_NO_SOURCE_HEADER,
- File=self._RawData.Filename)
+ File=self._RawData.Filename)
return
def _StopCurrentParsing(self, Line):
@@ -852,19 +902,15 @@ class Dec(_DecBase, _DecComments): self._SectionHeaderParser()
if len(self._RawData.CurrentScope) == 0:
self._LoggerError(ST.ERR_DECPARSE_SECTION_EMPTY)
-
SectionObj = self._SectionParser[self._RawData.CurrentScope[0][0]]
-
SectionObj.BlockStart()
SectionObj.Parse()
-
return SectionObj.GetDataObject()
def _UserExtentionSectionParser(self):
self._RawData.CurrentScope = []
ArchList = set()
Section = self._RawData.CurrentLine[1:-1]
-
Par = ParserHelper(Section, self._RawData.Filename)
while not Par.End():
#
@@ -874,8 +920,8 @@ class Dec(_DecBase, _DecComments): if Token.upper() != DT.TAB_USER_EXTENSIONS.upper():
self._LoggerError(ST.ERR_DECPARSE_SECTION_UE)
UserExtension = Token.upper()
-
- Par.AssertChar(DT.TAB_SPLIT, ST.ERR_DECPARSE_SECTION_UE, self._RawData.LineIndex)
+ Par.AssertChar(DT.TAB_SPLIT, ST.ERR_DECPARSE_SECTION_UE, self._RawData.LineIndex)
+
#
# UserID
#
@@ -883,7 +929,6 @@ class Dec(_DecBase, _DecComments): if not IsValidUserId(Token):
self._LoggerError(ST.ERR_DECPARSE_SECTION_UE_USERID)
UserId = Token
-
Par.AssertChar(DT.TAB_SPLIT, ST.ERR_DECPARSE_SECTION_UE, self._RawData.LineIndex)
#
# IdString
@@ -892,7 +937,6 @@ class Dec(_DecBase, _DecComments): if not IsValidIdString(Token):
self._LoggerError(ST.ERR_DECPARSE_SECTION_UE_IDSTRING)
IdString = Token
-
Arch = 'COMMON'
if Par.Expect(DT.TAB_SPLIT):
Token = Par.GetToken()
@@ -900,20 +944,16 @@ class Dec(_DecBase, _DecComments): if not IsValidArch(Arch):
self._LoggerError(ST.ERR_DECPARSE_ARCH)
ArchList.add(Arch)
-
if [UserExtension, UserId, IdString, Arch] not in \
self._RawData.CurrentScope:
self._RawData.CurrentScope.append(
[UserExtension, UserId, IdString, Arch]
)
-
if not Par.Expect(DT.TAB_COMMA_SPLIT):
break
elif Par.End():
self._LoggerError(ST.ERR_DECPARSE_SECTION_COMMA)
-
Par.AssertEnd(ST.ERR_DECPARSE_SECTION_UE, self._RawData.LineIndex)
-
if 'COMMON' in ArchList and len(ArchList) > 1:
self._LoggerError(ST.ERR_DECPARSE_SECTION_COMMON)
@@ -928,7 +968,6 @@ class Dec(_DecBase, _DecComments): self._LoggerError(ST.ERR_DECPARSE_SECTION_IDENTIFY)
RawSection = self._RawData.CurrentLine[1:-1].strip().upper()
-
#
# Check defines section which is only allowed to occur once and
# no arch can be followed
@@ -936,13 +975,11 @@ class Dec(_DecBase, _DecComments): if RawSection.startswith(DT.TAB_DEC_DEFINES.upper()):
if RawSection != DT.TAB_DEC_DEFINES.upper():
self._LoggerError(ST.ERR_DECPARSE_DEFINE_SECNAME)
-
#
# Check user extension section
#
if RawSection.startswith(DT.TAB_USER_EXTENSIONS.upper()):
return self._UserExtentionSectionParser()
-
self._RawData.CurrentScope = []
SectionNames = []
ArchList = set()
@@ -951,17 +988,14 @@ class Dec(_DecBase, _DecComments): self._LoggerError(ST.ERR_DECPARSE_SECTION_SUBEMPTY % self._RawData.CurrentLine)
ItemList = GetSplitValueList(Item, DT.TAB_SPLIT)
-
#
# different types of PCD are permissible in one section
#
SectionName = ItemList[0]
if SectionName not in self._SectionParser:
self._LoggerError(ST.ERR_DECPARSE_SECTION_UNKNOW % SectionName)
-
if SectionName not in SectionNames:
SectionNames.append(SectionName)
-
#
# In DEC specification, all section headers have at most two part:
# SectionName.Arch except UserExtention
@@ -989,7 +1023,6 @@ class Dec(_DecBase, _DecComments): #
if 'COMMON' in ArchList and len(ArchList) > 1:
self._LoggerError(ST.ERR_DECPARSE_SECTION_COMMON)
-
if len(SectionNames) == 0:
self._LoggerError(ST.ERR_DECPARSE_SECTION_SUBEMPTY % self._RawData.CurrentLine)
if len(SectionNames) != 1:
@@ -997,41 +1030,31 @@ class Dec(_DecBase, _DecComments): if not Sec.startswith(DT.TAB_PCDS.upper()):
self._LoggerError(ST.ERR_DECPARSE_SECTION_NAME % str(SectionNames))
+ def GetDefineSectionMacro(self):
+ return self._Define.GetLocalMacro()
def GetDefineSectionObject(self):
return self._Define.GetDataObject()
-
def GetIncludeSectionObject(self):
return self._Include.GetDataObject()
-
def GetGuidSectionObject(self):
return self._Guid.GetGuidObject()
-
def GetProtocolSectionObject(self):
return self._Guid.GetProtocolObject()
-
def GetPpiSectionObject(self):
return self._Guid.GetPpiObject()
-
def GetLibraryClassSectionObject(self):
return self._LibClass.GetDataObject()
-
def GetPcdSectionObject(self):
return self._Pcd.GetDataObject()
-
def GetUserExtensionSectionObject(self):
return self._UserEx.GetDataObject()
-
def GetPackageSpecification(self):
- return self._Define.GetDataObject().GetPackageSpecification()
-
+ return self._Define.GetDataObject().GetPackageSpecification()
def GetPackageName(self):
- return self._Define.GetDataObject().GetPackageName()
-
+ return self._Define.GetDataObject().GetPackageName()
def GetPackageGuid(self):
- return self._Define.GetDataObject().GetPackageGuid()
-
+ return self._Define.GetDataObject().GetPackageGuid()
def GetPackageVersion(self):
return self._Define.GetDataObject().GetPackageVersion()
-
def GetPackageUniFile(self):
return self._Define.GetDataObject().GetPackageUniFile()
diff --git a/BaseTools/Source/Python/UPT/Parser/DecParserMisc.py b/BaseTools/Source/Python/UPT/Parser/DecParserMisc.py index 8d28979393..22a50680fb 100644 --- a/BaseTools/Source/Python/UPT/Parser/DecParserMisc.py +++ b/BaseTools/Source/Python/UPT/Parser/DecParserMisc.py @@ -1,7 +1,7 @@ ## @file
# This file is used to define helper class and function for DEC parser
#
-# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials are licensed and made available
# under the terms and conditions of the BSD License which accompanies this
@@ -25,6 +25,7 @@ from Library.DataType import TAB_COMMENT_SPLIT from Library.DataType import TAB_COMMENT_EDK1_SPLIT
from Library.ExpressionValidate import IsValidBareCString
from Library.ParserValidate import IsValidCFormatGuid
+from Library.ExpressionValidate import IsValidFeatureFlagExp
from Library.ExpressionValidate import IsValidLogicalExpr
from Library.ExpressionValidate import IsValidStringTest
from Library.Misc import CheckGuidRegFormat
@@ -134,26 +135,38 @@ def CleanString(Line, CommentCharacter=TAB_COMMENT_SPLIT, \ return Line, Comment
-## IsValidHexByte
+## IsValidNumValUint8
#
-# Check if Token is HexByte: <HexByte> ::= 0x <HexDigit>{1,2}
+# Check if Token is NumValUint8: <NumValUint8> ::= {<ShortNum>} {<UINT8>} {<Expression>}
#
# @param Token: Token to be checked
#
-def IsValidHexByte(Token):
+def IsValidNumValUint8(Token):
+ Valid = True
+ Cause = ""
+ TokenValue = None
Token = Token.strip()
- if not Token.lower().startswith('0x') or not (len(Token) < 5 and len(Token) > 2):
- return False
+ if Token.lower().startswith('0x'):
+ Base = 16
+ else:
+ Base = 10
try:
- Token = long(Token, 0)
+ TokenValue = long(Token, Base)
except BaseException:
+ Valid, Cause = IsValidLogicalExpr(Token, True)
+ if Cause:
+ pass
+ if not Valid:
return False
- return True
+ if TokenValue and (TokenValue < 0 or TokenValue > 0xFF):
+ return False
+ else:
+ return True
## IsValidNList
#
-# Check if Value has the format of <HexByte> ["," <HexByte>]{0,}
-# <HexByte> ::= "0x" <HexDigit>{1,2}
+# Check if Value has the format of <NumValUint8> ["," <NumValUint8>]{0,}
+# <NumValUint8> ::= {<ShortNum>} {<UINT8>} {<Expression>}
#
# @param Value: Value to be checked
#
@@ -162,8 +175,8 @@ def IsValidNList(Value): if Par.End():
return False
while not Par.End():
- Token = Par.GetToken(',\t ')
- if not IsValidHexByte(Token):
+ Token = Par.GetToken(',')
+ if not IsValidNumValUint8(Token):
return False
if Par.Expect(','):
if Par.End():
@@ -186,11 +199,11 @@ def IsValidCArray(Array): if Par.End():
return False
while not Par.End():
- Token = Par.GetToken(',}\t ')
+ Token = Par.GetToken(',}')
#
- # 0xa, 0xaa
+ # ShortNum, UINT8, Expression
#
- if not IsValidHexByte(Token):
+ if not IsValidNumValUint8(Token):
return False
if Par.Expect(','):
if Par.End():
@@ -213,6 +226,10 @@ def IsValidCArray(Array): # @param Value: The pcd Value
#
def IsValidPcdDatum(Type, Value):
+ if not Value:
+ return False, ST.ERR_DECPARSE_PCD_VALUE_EMPTY
+ Valid = True
+ Cause = ""
if Type not in ["UINT8", "UINT16", "UINT32", "UINT64", "VOID*", "BOOLEAN"]:
return False, ST.ERR_DECPARSE_PCD_TYPE
if Type == "VOID*":
@@ -230,9 +247,9 @@ def IsValidPcdDatum(Type, Value): if Value in ['TRUE', 'FALSE', 'true', 'false', 'True', 'False',
'0x1', '0x01', '1', '0x0', '0x00', '0']:
return True, ""
- Valid, Cause = IsValidStringTest(Value)
+ Valid, Cause = IsValidStringTest(Value, True)
if not Valid:
- Valid, Cause = IsValidLogicalExpr(Value)
+ Valid, Cause = IsValidFeatureFlagExp(Value, True)
if not Valid:
return False, Cause
else:
@@ -271,8 +288,10 @@ def IsValidPcdDatum(Type, Value): if TypeLenMap[Type] < len(HexStr) - 3:
return False, ST.ERR_DECPARSE_PCD_INT_EXCEED % (StrVal, Type)
except BaseException:
- return False, ST.ERR_DECPARSE_PCD_INT % (Value, Type)
-
+ Valid, Cause = IsValidLogicalExpr(Value, True)
+ if not Valid:
+ return False, Cause
+
return True, ""
## ParserHelper
diff --git a/BaseTools/Source/Python/UPT/Parser/InfAsBuiltProcess.py b/BaseTools/Source/Python/UPT/Parser/InfAsBuiltProcess.py index 6bf070be41..498f2d7634 100644 --- a/BaseTools/Source/Python/UPT/Parser/InfAsBuiltProcess.py +++ b/BaseTools/Source/Python/UPT/Parser/InfAsBuiltProcess.py @@ -1,7 +1,7 @@ ## @file
# This file is used to provide method for process AsBuilt INF file. It will consumed by InfParser
#
-# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials are licensed and made available
# under the terms and conditions of the BSD License which accompanies this
@@ -19,7 +19,6 @@ InfAsBuiltProcess import os
import re
from Library import GlobalData
-
import Logger.Log as Logger
from Logger import StringTable as ST
from Logger import ToolError
@@ -74,7 +73,7 @@ def GetLibInstanceInfo(String, WorkSpace, LineNo, CurrentInfFileName): if VersionMatchedObj:
Guid = GuidMatchedObj.group().strip()
Version = VersionMatchedObj.group().strip()
- return GetGuidVerFormLibInstance(Guid, Version, WorkSpace, CurrentInfFileName)
+ return Guid, Version
#
# To deal with library instance specified by file name
@@ -106,47 +105,47 @@ def GetLibInstanceInfo(String, WorkSpace, LineNo, CurrentInfFileName): # @param WorkSpace. The WorkSpace directory used to combined with INF file path.
#
# @return GUID, Version
-def GetPackageListInfo(FileNameString, WorkSpace, LineNo):
+def GetPackageListInfo(FileNameString, WorkSpace, LineNo):
PackageInfoList = []
DefineSectionMacros = {}
PackageSectionMacros = {}
-
+
FileLinesList = GetFileLineContent(FileNameString, WorkSpace, LineNo, '')
-
+
RePackageHeader = re.compile('^\s*\[Packages.*\].*$')
ReDefineHeader = re.compile('^\s*\[Defines].*$')
-
+
PackageHederFlag = False
DefineHeaderFlag = False
LineNo = -1
for Line in FileLinesList:
LineNo += 1
Line = Line.strip()
-
+
if Line.startswith('['):
PackageHederFlag = False
- DefineHeaderFlag = False
-
+ DefineHeaderFlag = False
+
if Line.startswith("#"):
continue
-
+
if not Line:
- continue
-
+ continue
+
#
# Found [Packages] section
#
if RePackageHeader.match(Line):
PackageHederFlag = True
continue
-
+
#
# Found [Define] section
#
if ReDefineHeader.match(Line):
DefineHeaderFlag = True
continue
-
+
if DefineHeaderFlag:
#
# Find Macro
@@ -154,12 +153,12 @@ def GetPackageListInfo(FileNameString, WorkSpace, LineNo): Name, Value = MacroParser((Line, LineNo),
FileNameString,
DT.MODEL_META_DATA_HEADER,
- DefineSectionMacros)
-
+ DefineSectionMacros)
+
if Name != None:
- DefineSectionMacros[Name] = Value
+ DefineSectionMacros[Name] = Value
continue
-
+
if PackageHederFlag:
#
@@ -170,22 +169,22 @@ def GetPackageListInfo(FileNameString, WorkSpace, LineNo): DT.MODEL_META_DATA_PACKAGE,
DefineSectionMacros)
if Name != None:
- PackageSectionMacros[Name] = Value
+ PackageSectionMacros[Name] = Value
continue
-
+
#
# Replace with Local section Macro and [Defines] section Macro.
#
Line = InfExpandMacro(Line, (FileNameString, Line, LineNo), DefineSectionMacros, PackageSectionMacros, True)
-
+
Line = GetSplitValueList(Line, "#", 1)[0]
Line = GetSplitValueList(Line, "|", 1)[0]
PackageInfoList.append(Line)
-
- return PackageInfoList
-
+
+ return PackageInfoList
+
def GetFileLineContent(FileName, WorkSpace, LineNo, OriginalString):
-
+
if not LineNo:
LineNo = -1
@@ -194,26 +193,16 @@ def GetFileLineContent(FileName, WorkSpace, LineNo, OriginalString): #
FullFileName = os.path.normpath(os.path.realpath(os.path.join(WorkSpace, FileName)))
if not (ValidFile(FullFileName)):
- Logger.Error("InfParser",
- ToolError.FORMAT_INVALID,
- ST.ERR_FILELIST_EXIST%(FileName),
- File=GlobalData.gINF_MODULE_NAME,
- Line=LineNo,
- ExtraData=OriginalString)
-
+ return []
+
#
# Validate file exist/format.
#
if not IsValidPath(FileName, WorkSpace):
- Logger.Error("InfParser",
- ToolError.FORMAT_INVALID,
- ST.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID%(FileName),
- File=GlobalData.gINF_MODULE_NAME,
- Line=LineNo,
- ExtraData=OriginalString)
-
+ return []
+
FileLinesList = []
-
+
try:
FullFileName = FullFileName.replace('\\', '/')
Inputfile = open(FullFileName, "rb", 0)
@@ -228,9 +217,9 @@ def GetFileLineContent(FileName, WorkSpace, LineNo, OriginalString): ToolError.FILE_READ_FAILURE,
ST.ERR_FILE_OPEN_FAILURE,
File=FullFileName)
-
+
FileLinesList = ProcessLineExtender(FileLinesList)
-
+
return FileLinesList
##
diff --git a/BaseTools/Source/Python/UPT/Parser/InfBinarySectionParser.py b/BaseTools/Source/Python/UPT/Parser/InfBinarySectionParser.py index 36142cf84a..f1d6943cbf 100644 --- a/BaseTools/Source/Python/UPT/Parser/InfBinarySectionParser.py +++ b/BaseTools/Source/Python/UPT/Parser/InfBinarySectionParser.py @@ -1,7 +1,7 @@ ## @file
# This file contained the parser for [Binaries] sections in INF file
#
-# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials are licensed and made available
# under the terms and conditions of the BSD License which accompanies this
@@ -178,9 +178,15 @@ class InfBinarySectionParser(InfParserSectionRoot): CurrentLineObj))
else:
if len(ValueList) == 2:
- TokenList = GetSplitValueList(ValueList[1],
- DT.TAB_VALUE_SPLIT,
- 4)
+ 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:
@@ -188,6 +194,15 @@ class InfBinarySectionParser(InfParserSectionRoot): ComBinaryList.append((NewValueList,
LineComment,
CurrentLineObj))
+ elif len(ValueList) == 1:
+ NewValueList = []
+ NewValueList.append(ValueList[0])
+ ComBinaryList.append((NewValueList,
+ LineComment,
+ CurrentLineObj))
+
+
+
ValueList = []
LineComment = None
diff --git a/BaseTools/Source/Python/UPT/Parser/InfLibrarySectionParser.py b/BaseTools/Source/Python/UPT/Parser/InfLibrarySectionParser.py index 4540fe2754..210f973f1a 100644 --- a/BaseTools/Source/Python/UPT/Parser/InfLibrarySectionParser.py +++ b/BaseTools/Source/Python/UPT/Parser/InfLibrarySectionParser.py @@ -1,7 +1,7 @@ ## @file
# This file contained the parser for [Libraries] sections in INF file
#
-# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials are licensed and made available
# under the terms and conditions of the BSD License which accompanies this
@@ -44,21 +44,21 @@ class InfLibrarySectionParser(InfParserSectionRoot): # Macro defined in this section
#
SectionMacros = {}
- ValueList = []
- LibraryList = []
- LibStillCommentFalg = False
- LibHeaderComments = []
- LibLineComment = None
+ ValueList = []
+ LibraryList = []
+ LibStillCommentFalg = False
+ LibHeaderComments = []
+ LibLineComment = None
#
# Parse section content
#
for Line in SectionString:
LibLineContent = Line[0]
- LibLineNo = Line[1]
-
+ LibLineNo = Line[1]
+
if LibLineContent.strip() == '':
continue
-
+
#
# Found Header Comments
#
@@ -82,14 +82,14 @@ class InfLibrarySectionParser(InfParserSectionRoot): continue
else:
LibStillCommentFalg = False
-
+
if len(LibHeaderComments) >= 1:
LibLineComment = InfLineCommentObject()
LineCommentContent = ''
for Item in LibHeaderComments:
LineCommentContent += Item[0] + DT.END_OF_LINE
LibLineComment.SetHeaderComments(LineCommentContent)
-
+
#
# Find Tail comment.
#
@@ -98,8 +98,8 @@ class InfLibrarySectionParser(InfParserSectionRoot): LibLineContent = LibLineContent[:LibLineContent.find(DT.TAB_COMMENT_SPLIT)]
if LibLineComment == None:
LibLineComment = InfLineCommentObject()
- LibLineComment.SetTailComments(LibTailComments)
-
+ LibLineComment.SetTailComments(LibTailComments)
+
#
# Find Macro
#
@@ -110,28 +110,28 @@ class InfLibrarySectionParser(InfParserSectionRoot): if Name != None:
SectionMacros[Name] = Value
LibLineComment = None
- LibHeaderComments = []
+ LibHeaderComments = []
continue
-
+
TokenList = GetSplitValueList(LibLineContent, DT.TAB_VALUE_SPLIT, 1)
ValueList[0:len(TokenList)] = TokenList
-
+
#
# Replace with Local section Macro and [Defines] section Macro.
#
- ValueList = [InfExpandMacro(Value, (FileName, LibLineContent, LibLineNo),
+ ValueList = [InfExpandMacro(Value, (FileName, LibLineContent, LibLineNo),
self.FileLocalMacros, SectionMacros, True)
for Value in ValueList]
-
- LibraryList.append((ValueList, LibLineComment,
+
+ LibraryList.append((ValueList, LibLineComment,
(LibLineContent, LibLineNo, FileName)))
ValueList = []
LibLineComment = None
LibTailComments = ''
LibHeaderComments = []
-
+
continue
-
+
#
# Current section archs
#
@@ -139,36 +139,36 @@ class InfLibrarySectionParser(InfParserSectionRoot): for Item in self.LastSectionHeaderContent:
if (Item[1], Item[2]) not in KeyList:
KeyList.append((Item[1], Item[2]))
-
- if not InfSectionObject.SetLibraryClasses(LibraryList, KeyList = KeyList):
- Logger.Error('InfParser',
+
+ if not InfSectionObject.SetLibraryClasses(LibraryList, KeyList=KeyList):
+ Logger.Error('InfParser',
FORMAT_INVALID,
ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % ("[Library]"),
- File=FileName,
+ File=FileName,
Line=Item[3])
#
# For Binary INF
#
else:
self.InfAsBuiltLibraryParser(SectionString, InfSectionObject, FileName)
-
+
def InfAsBuiltLibraryParser(self, SectionString, InfSectionObject, FileName):
LibraryList = []
LibInsFlag = False
for Line in SectionString:
LineContent = Line[0]
- LineNo = Line[1]
-
+ LineNo = Line[1]
+
if LineContent.strip() == '':
LibInsFlag = False
continue
-
+
if not LineContent.strip().startswith("#"):
- Logger.Error('InfParser',
+ Logger.Error('InfParser',
FORMAT_INVALID,
- ST.ERR_LIB_CONTATIN_ASBUILD_AND_COMMON,
- File=FileName,
- Line=LineNo,
+ ST.ERR_LIB_CONTATIN_ASBUILD_AND_COMMON,
+ File=FileName,
+ Line=LineNo,
ExtraData=LineContent)
if IsLibInstanceInfo(LineContent):
@@ -185,13 +185,6 @@ class InfLibrarySectionParser(InfParserSectionRoot): if LibGuid != '':
if (LibGuid, LibVer) not in LibraryList:
LibraryList.append((LibGuid, LibVer))
- else:
- Logger.Error('InfParser',
- FORMAT_INVALID,
- ST.ERR_LIB_INSTANCE_MISS_GUID,
- File=FileName,
- Line=LineNo,
- ExtraData=LineContent)
#
# Current section archs
@@ -201,10 +194,10 @@ class InfLibrarySectionParser(InfParserSectionRoot): for Item in self.LastSectionHeaderContent:
if (Item[1], Item[2]) not in KeyList:
KeyList.append((Item[1], Item[2]))
-
- if not InfSectionObject.SetLibraryClasses(LibraryList, KeyList = KeyList):
- Logger.Error('InfParser',
+
+ if not InfSectionObject.SetLibraryClasses(LibraryList, KeyList=KeyList):
+ Logger.Error('InfParser',
FORMAT_INVALID,
ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % ("[Library]"),
- File=FileName,
- Line=Item[3])
\ No newline at end of file + File=FileName,
+ Line=Item[3])
diff --git a/BaseTools/Source/Python/UPT/Parser/InfParser.py b/BaseTools/Source/Python/UPT/Parser/InfParser.py index 8a41eca0a7..e7bef2e35e 100644 --- a/BaseTools/Source/Python/UPT/Parser/InfParser.py +++ b/BaseTools/Source/Python/UPT/Parser/InfParser.py @@ -1,7 +1,7 @@ ## @file
# This file contained the parser for INF file
#
-# Copyright (c) 2011 - 2013, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials are licensed and made available
# under the terms and conditions of the BSD License which accompanies this
@@ -210,7 +210,7 @@ class InfParser(InfSectionParser): SectionLines.append((Line, LineNo))
HeaderCommentStart = True
continue
-
+
#
# Collect Header content.
#
@@ -227,18 +227,18 @@ class InfParser(InfSectionParser): HeaderCommentEnd = True
BinaryHeaderCommentStart = False
BinaryHeaderCommentEnd = False
- HeaderCommentStart = 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
+ #
+ # Call Header comment parser.
+ #
+ self.InfHeaderParser(SectionLines, self.InfHeader, self.FileName)
+ SectionLines = []
+ continue
#
# check whether binary header comment section started
@@ -254,9 +254,9 @@ class InfParser(InfSectionParser): BinaryHeaderStarLineNo = LineNo
SectionLines.append((Line, LineNo))
BinaryHeaderCommentStart = True
- HeaderCommentEnd = True
- continue
-
+ HeaderCommentEnd = True
+ continue
+
#
# check whether there are more than one binary header exist
#
@@ -302,12 +302,12 @@ class InfParser(InfSectionParser): 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:
+ Line.find(DT.TAB_SECTION_END) > -1) or LastSectionFalg:
HeaderCommentEnd = True
BinaryHeaderCommentEnd = True
@@ -324,13 +324,13 @@ class InfParser(InfSectionParser): 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.
#
@@ -357,11 +357,11 @@ class InfParser(InfSectionParser): # 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
@@ -370,10 +370,10 @@ class InfParser(InfSectionParser): 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.
@@ -393,9 +393,9 @@ class InfParser(InfSectionParser): if HeaderStarLineNo == -1:
Logger.Error("InfParser",
- FORMAT_INVALID,
- ST.ERR_NO_SOURCE_HEADER,
- File=self.FullPath)
+ FORMAT_INVALID,
+ ST.ERR_NO_SOURCE_HEADER,
+ File=self.FullPath)
if BinaryHeaderStarLineNo > -1 and HeaderStarLineNo > -1 and HeaderStarLineNo > BinaryHeaderStarLineNo:
Logger.Error("InfParser",
FORMAT_INVALID,
diff --git a/BaseTools/Source/Python/UPT/Parser/InfParserMisc.py b/BaseTools/Source/Python/UPT/Parser/InfParserMisc.py index 7058e69da1..a416897d27 100644 --- a/BaseTools/Source/Python/UPT/Parser/InfParserMisc.py +++ b/BaseTools/Source/Python/UPT/Parser/InfParserMisc.py @@ -1,7 +1,7 @@ ## @file
# This file contained the miscellaneous functions for INF parser
#
-# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials are licensed and made available
# under the terms and conditions of the BSD License which accompanies this
@@ -82,6 +82,10 @@ def InfExpandMacro(Content, LineInfo, GlobalMacros=None, SectionMacros=None, Fla LineContent = LineInfo[1]
LineNo = LineInfo[2]
+ # Don't expand macros in comments
+ if LineContent.strip().startswith("#"):
+ return Content
+
NewLineInfo = (FileName, LineNo, LineContent)
#
diff --git a/BaseTools/Source/Python/UPT/Parser/InfPcdSectionParser.py b/BaseTools/Source/Python/UPT/Parser/InfPcdSectionParser.py index 1011559450..f4324cc2ff 100644 --- a/BaseTools/Source/Python/UPT/Parser/InfPcdSectionParser.py +++ b/BaseTools/Source/Python/UPT/Parser/InfPcdSectionParser.py @@ -1,7 +1,7 @@ ## @file
# This file contained the parser for [Pcds] sections in INF file
#
-# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials are licensed and made available
# under the terms and conditions of the BSD License which accompanies this
@@ -160,13 +160,13 @@ class InfPcdSectionParser(InfParserSectionRoot): ExtraData=LineContent)
#
elif KeysList[0][0].upper() == DT.TAB_INF_PCD_EX.upper():
- if len(TokenList) != 2:
+ if len(TokenList) != 1:
Logger.Error('InfParser',
FORMAT_INVALID,
ST.ERR_ASBUILD_PCDEX_FORMAT_INVALID,
File=FileName,
Line=LineNo,
- ExtraData=LineContent)
+ ExtraData=LineContent)
ValueList[0:len(TokenList)] = TokenList
if len(ValueList) >= 1:
PcdList.append((ValueList, CommentsList, (LineContent, LineNo, FileName)))
diff --git a/BaseTools/Source/Python/UPT/Parser/InfSectionParser.py b/BaseTools/Source/Python/UPT/Parser/InfSectionParser.py index 879f924c45..727164c2c2 100644 --- a/BaseTools/Source/Python/UPT/Parser/InfSectionParser.py +++ b/BaseTools/Source/Python/UPT/Parser/InfSectionParser.py @@ -1,7 +1,7 @@ ## @file
# This file contained the parser for sections in INF file
#
-# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials are licensed and made available
# under the terms and conditions of the BSD License which accompanies this
@@ -239,6 +239,7 @@ class InfSectionParser(InfDefinSectionParser, self.InfSmmDepexSection = InfDepexObject()
self.InfBinariesSection = InfBinariesObject()
self.InfHeader = InfHeaderObject()
+ self.InfBinaryHeader = InfHeaderObject()
self.InfSpecialCommentSection = InfSpecialCommentObject()
#
@@ -253,8 +254,16 @@ class InfSectionParser(InfDefinSectionParser, #
# File Header content parser
#
- def InfHeaderParser(self, Content, InfHeaderObject2, FileName):
- (Abstract, Description, Copyright, License) = ParseHeaderCommentSection(Content, FileName)
+ def InfHeaderParser(self, Content, InfHeaderObject2, FileName, IsBinaryHeader = False):
+ if IsBinaryHeader:
+ (Abstract, Description, Copyright, License) = ParseHeaderCommentSection(Content, FileName, True)
+ if not Abstract or not Description or not Copyright or not License:
+ Logger.Error('Parser',
+ FORMAT_INVALID,
+ ST.ERR_INVALID_BINARYHEADER_FORMAT,
+ File=FileName)
+ else:
+ (Abstract, Description, Copyright, License) = ParseHeaderCommentSection(Content, FileName)
#
# Not process file name now, for later usage.
#
|