#\r
# Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>\r
#\r
-# This program and the accompanying materials are licensed and made available \r
-# under the terms and conditions of the BSD License which accompanies this \r
-# distribution. The full text of the license may be found at \r
-# http://opensource.org/licenses/bsd-license.php\r
-#\r
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
#\r
\r
'''\r
#\r
def OpenInfFile(Filename):\r
FileLinesList = []\r
- \r
+\r
try:\r
- FInputfile = open(Filename, "rb", 0)\r
+ FInputfile = open(Filename, "r")\r
try:\r
FileLinesList = FInputfile.readlines()\r
except BaseException:\r
- Logger.Error("InfParser", \r
- FILE_READ_FAILURE, \r
+ Logger.Error("InfParser",\r
+ FILE_READ_FAILURE,\r
ST.ERR_FILE_OPEN_FAILURE,\r
File=Filename)\r
finally:\r
FInputfile.close()\r
except BaseException:\r
- Logger.Error("InfParser", \r
- FILE_READ_FAILURE, \r
+ Logger.Error("InfParser",\r
+ FILE_READ_FAILURE,\r
ST.ERR_FILE_OPEN_FAILURE,\r
File=Filename)\r
- \r
+\r
return FileLinesList\r
\r
## InfParser\r
# This class defined the structure used in InfParser object\r
#\r
# @param InfObject: Inherited from InfSectionParser class\r
-# @param Filename: Input value for Filename of INF file, default is \r
+# @param Filename: Input value for Filename of INF file, default is\r
# None\r
-# @param WorkspaceDir: Input value for current workspace directory, \r
+# @param WorkspaceDir: Input value for current workspace directory,\r
# default is None\r
#\r
class InfParser(InfSectionParser):\r
\r
def __init__(self, Filename = None, WorkspaceDir = None):\r
- \r
+\r
#\r
# Call parent class construct function\r
#\r
- super(InfParser, self).__init__()\r
- \r
+ InfSectionParser.__init__()\r
+\r
self.WorkspaceDir = WorkspaceDir\r
self.SupArchList = DT.ARCH_LIST\r
self.EventList = []\r
# @param Filename: Input value for filename of INF file\r
#\r
def ParseInfFile(self, Filename):\r
- \r
+\r
Filename = NormPath(Filename)\r
(Path, Name) = os.path.split(Filename)\r
self.FullPath = Filename\r
# Initialize common data\r
#\r
LineNo = 0\r
- CurrentSection = DT.MODEL_UNKNOWN \r
+ CurrentSection = DT.MODEL_UNKNOWN\r
SectionLines = []\r
- \r
+\r
#\r
# Flags\r
#\r
- HeaderCommentStart = False \r
+ HeaderCommentStart = False\r
HeaderCommentEnd = False\r
HeaderStarLineNo = -1\r
- BinaryHeaderCommentStart = False \r
+ BinaryHeaderCommentStart = False\r
BinaryHeaderCommentEnd = False\r
BinaryHeaderStarLineNo = -1\r
- \r
+\r
#\r
# While Section ends. parse whole section contents.\r
#\r
NewSectionStartFlag = False\r
FirstSectionStartFlag = False\r
- \r
+\r
#\r
# Parse file content\r
#\r
CommentBlock = []\r
- \r
+\r
#\r
# Variables for Event/Hob/BootMode\r
#\r
self.HobList = []\r
self.BootModeList = []\r
SectionType = ''\r
- \r
+\r
FileLinesList = OpenInfFile (Filename)\r
- \r
+\r
#\r
# One INF file can only has one [Defines] section.\r
#\r
DefineSectionParsedFlag = False\r
- \r
+\r
#\r
# Convert special characters in lines to space character.\r
#\r
FileLinesList = ConvertSpecialChar(FileLinesList)\r
- \r
+\r
#\r
# Process Line Extender\r
#\r
FileLinesList = ProcessLineExtender(FileLinesList)\r
- \r
+\r
#\r
# Process EdkI INF style comment if found\r
#\r
OrigLines = [Line for Line in FileLinesList]\r
FileLinesList, EdkCommentStartPos = ProcessEdkComment(FileLinesList)\r
- \r
+\r
#\r
# Judge whether the INF file is Binary INF or not\r
#\r
if IsBinaryInf(FileLinesList):\r
GlobalData.gIS_BINARY_INF = True\r
- \r
+\r
InfSectionCommonDefObj = None\r
- \r
+\r
for Line in FileLinesList:\r
LineNo = LineNo + 1\r
Line = Line.strip()\r
if (LineNo < len(FileLinesList) - 1):\r
NextLine = FileLinesList[LineNo].strip()\r
- \r
+\r
#\r
# blank line\r
#\r
HeaderStarLineNo = LineNo\r
SectionLines.append((Line, LineNo))\r
HeaderCommentStart = True\r
- continue \r
+ continue\r
\r
#\r
# Collect Header content.\r
if (Line.startswith(DT.TAB_SPECIAL_COMMENT) or not Line.strip().startswith("#")) and HeaderCommentStart \\r
and not HeaderCommentEnd:\r
HeaderCommentEnd = True\r
- BinaryHeaderCommentStart = False \r
+ BinaryHeaderCommentStart = False\r
BinaryHeaderCommentEnd = False\r
- HeaderCommentStart = False \r
+ HeaderCommentStart = False\r
if Line.find(DT.TAB_BINARY_HEADER_COMMENT) > -1:\r
- self.InfHeaderParser(SectionLines, self.InfHeader, self.FileName) \r
+ self.InfHeaderParser(SectionLines, self.InfHeader, self.FileName)\r
SectionLines = []\r
else:\r
SectionLines.append((Line, LineNo))\r
SectionLines.append((Line, LineNo))\r
BinaryHeaderCommentStart = True\r
HeaderCommentEnd = True\r
- continue \r
- \r
+ continue\r
+\r
#\r
# check whether there are more than one binary header exist\r
#\r
FORMAT_INVALID,\r
ST.ERR_MULTIPLE_BINARYHEADER_EXIST,\r
File=Filename)\r
- \r
+\r
#\r
# Collect Binary Header content.\r
#\r
#\r
self.InfHeaderParser(SectionLines, self.InfBinaryHeader, self.FileName, True)\r
SectionLines = []\r
- BinaryHeaderCommentEnd = True \r
- continue \r
+ BinaryHeaderCommentEnd = True\r
+ continue\r
#\r
# Find a new section tab\r
- # Or at the last line of INF file, \r
+ # Or at the last line of INF file,\r
# need to process the last section.\r
#\r
LastSectionFalg = False\r
if LineNo == len(FileLinesList):\r
LastSectionFalg = True\r
- \r
+\r
if Line.startswith(DT.TAB_COMMENT_SPLIT) and not Line.startswith(DT.TAB_SPECIAL_COMMENT):\r
SectionLines.append((Line, LineNo))\r
if not LastSectionFalg:\r
# Encountered a section. start with '[' and end with ']'\r
#\r
if (Line.startswith(DT.TAB_SECTION_START) and \\r
- Line.find(DT.TAB_SECTION_END) > -1) or LastSectionFalg: \r
- \r
- HeaderCommentEnd = True \r
- BinaryHeaderCommentEnd = True \r
- \r
+ Line.find(DT.TAB_SECTION_END) > -1) or LastSectionFalg:\r
+\r
+ HeaderCommentEnd = True\r
+ BinaryHeaderCommentEnd = True\r
+\r
if not LastSectionFalg:\r
#\r
# check to prevent '#' inside section header\r
#\r
HeaderContent = Line[1:Line.find(DT.TAB_SECTION_END)]\r
if HeaderContent.find(DT.TAB_COMMENT_SPLIT) != -1:\r
- Logger.Error("InfParser", \r
+ Logger.Error("InfParser",\r
FORMAT_INVALID,\r
ST.ERR_INF_PARSER_DEFINE_SECTION_HEADER_INVALID,\r
File=self.FullPath,\r
- Line=LineNo, \r
- ExtraData=Line) \r
+ Line=LineNo,\r
+ ExtraData=Line)\r
\r
#\r
# Keep last time section header content for section parser\r
if CommentIndex > -1:\r
TailComments = Line[CommentIndex:]\r
Line = Line[:CommentIndex]\r
- \r
+\r
InfSectionCommonDefObj = InfSectionCommonDef()\r
if TailComments != '':\r
InfSectionCommonDefObj.SetTailComments(TailComments)\r
# Call section parser before section header parer to avoid encounter EDKI INF file\r
#\r
if CurrentSection == DT.MODEL_META_DATA_DEFINE:\r
- DefineSectionParsedFlag = self._CallSectionParsers(CurrentSection, \r
- DefineSectionParsedFlag, SectionLines, \r
+ DefineSectionParsedFlag = self._CallSectionParsers(CurrentSection,\r
+ DefineSectionParsedFlag, SectionLines,\r
InfSectionCommonDefObj, LineNo)\r
#\r
# Compare the new section name with current\r
#\r
# End of section content collect.\r
# Parser the section content collected previously.\r
- # \r
+ #\r
if NewSectionStartFlag or LastSectionFalg:\r
if CurrentSection != DT.MODEL_META_DATA_DEFINE or \\r
- (LastSectionFalg and CurrentSection == DT.MODEL_META_DATA_DEFINE): \r
- DefineSectionParsedFlag = self._CallSectionParsers(CurrentSection, \r
- DefineSectionParsedFlag, SectionLines, \r
+ (LastSectionFalg and CurrentSection == DT.MODEL_META_DATA_DEFINE):\r
+ DefineSectionParsedFlag = self._CallSectionParsers(CurrentSection,\r
+ DefineSectionParsedFlag, SectionLines,\r
InfSectionCommonDefObj, LineNo)\r
- \r
+\r
CurrentSection = SectionType\r
#\r
# Clear section lines\r
#\r
- SectionLines = [] \r
- \r
+ SectionLines = []\r
+\r
if HeaderStarLineNo == -1:\r
- Logger.Error("InfParser", \r
+ Logger.Error("InfParser",\r
FORMAT_INVALID,\r
ST.ERR_NO_SOURCE_HEADER,\r
- File=self.FullPath) \r
+ File=self.FullPath)\r
if BinaryHeaderStarLineNo > -1 and HeaderStarLineNo > -1 and HeaderStarLineNo > BinaryHeaderStarLineNo:\r
- Logger.Error("InfParser", \r
+ Logger.Error("InfParser",\r
FORMAT_INVALID,\r
ST.ERR_BINARY_HEADER_ORDER,\r
- File=self.FullPath) \r
+ File=self.FullPath)\r
#\r
# EDKII INF should not have EDKI style comment\r
#\r
if EdkCommentStartPos != -1:\r
- Logger.Error("InfParser", \r
- FORMAT_INVALID, \r
- ST.ERR_INF_PARSER_EDKI_COMMENT_IN_EDKII, \r
+ Logger.Error("InfParser",\r
+ FORMAT_INVALID,\r
+ ST.ERR_INF_PARSER_EDKI_COMMENT_IN_EDKII,\r
File=self.FullPath,\r
Line=EdkCommentStartPos + 1,\r
ExtraData=OrigLines[EdkCommentStartPos])\r
- \r
+\r
+ #\r
+ # extract [Event] [Hob] [BootMode] sections\r
#\r
- # extract [Event] [Hob] [BootMode] sections \r
- # \r
self._ExtractEventHobBootMod(FileLinesList)\r
- \r
+\r
## _CheckSectionHeaders\r
#\r
#\r
def _CheckSectionHeaders(self, Line, LineNo):\r
if len(self.SectionHeaderContent) == 0:\r
- Logger.Error("InfParser", \r
+ Logger.Error("InfParser",\r
FORMAT_INVALID,\r
ST.ERR_INF_PARSER_DEFINE_SECTION_HEADER_INVALID,\r
File=self.FullPath,\r
for SectionItem in self.SectionHeaderContent:\r
ArchList = []\r
#\r
- # Not cover Depex/UserExtension section header \r
+ # Not cover Depex/UserExtension section header\r
# check.\r
#\r
if SectionItem[0].strip().upper() == DT.TAB_INF_FIXED_PCD.upper() or \\r
ArchList = GetSplitValueList(SectionItem[1].strip(), ' ')\r
else:\r
ArchList = [SectionItem[1].strip()]\r
- \r
+\r
for Arch in ArchList:\r
if (not IsValidArch(Arch)) and \\r
(SectionItem[0].strip().upper() != DT.TAB_DEPEX.upper()) and \\r
(SectionItem[0].strip().upper() != DT.TAB_USER_EXTENSIONS.upper()) and \\r
(SectionItem[0].strip().upper() != DT.TAB_COMMON_DEFINES.upper()):\r
- Logger.Error("InfParser", \r
+ Logger.Error("InfParser",\r
FORMAT_INVALID,\r
- ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID%(SectionItem[1]), \r
+ ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID%(SectionItem[1]),\r
File=self.FullPath,\r
Line=LineNo, ExtraData=Line)\r
#\r
ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID%(SectionItem[2]),\r
File=self.FullPath, Line=LineNo,\r
ExtraData=Line)\r
- \r
+\r
## _CallSectionParsers\r
#\r
#\r
- def _CallSectionParsers(self, CurrentSection, DefineSectionParsedFlag, \r
+ def _CallSectionParsers(self, CurrentSection, DefineSectionParsedFlag,\r
SectionLines, InfSectionCommonDefObj, LineNo):\r
if CurrentSection == DT.MODEL_META_DATA_DEFINE:\r
if not DefineSectionParsedFlag:\r
InfSectionCommonDefObj)\r
DefineSectionParsedFlag = True\r
else:\r
- Logger.Error("Parser", \r
- PARSER_ERROR, \r
- ST.ERR_INF_PARSER_MULTI_DEFINE_SECTION, \r
- File=self.FullPath, \r
+ Logger.Error("Parser",\r
+ PARSER_ERROR,\r
+ ST.ERR_INF_PARSER_MULTI_DEFINE_SECTION,\r
+ File=self.FullPath,\r
RaiseError = Logger.IS_RAISE_ERROR)\r
- \r
+\r
elif CurrentSection == DT.MODEL_META_DATA_BUILD_OPTION:\r
self.InfBuildOptionParser(SectionLines,\r
self.InfBuildOptionSection,\r
self.FullPath)\r
- \r
+\r
elif CurrentSection == DT.MODEL_EFI_LIBRARY_CLASS:\r
self.InfLibraryParser(SectionLines,\r
self.InfLibraryClassSection,\r
self.FullPath)\r
- \r
+\r
elif CurrentSection == DT.MODEL_META_DATA_PACKAGE:\r
self.InfPackageParser(SectionLines,\r
self.InfPackageSection,\r
self.InfPcdParser(SectionLines,\r
self.InfPcdSection,\r
self.FullPath)\r
- \r
+\r
elif CurrentSection == DT.MODEL_EFI_SOURCE_FILE:\r
self.InfSourceParser(SectionLines,\r
self.InfSourcesSection,\r
self.FullPath)\r
- \r
+\r
elif CurrentSection == DT.MODEL_META_DATA_USER_EXTENSION:\r
self.InfUserExtensionParser(SectionLines,\r
self.InfUserExtensionSection,\r
self.FullPath)\r
- \r
+\r
elif CurrentSection == DT.MODEL_EFI_PROTOCOL:\r
self.InfProtocolParser(SectionLines,\r
self.InfProtocolSection,\r
self.FullPath)\r
- \r
+\r
elif CurrentSection == DT.MODEL_EFI_PPI:\r
self.InfPpiParser(SectionLines,\r
self.InfPpiSection,\r
self.FullPath)\r
- \r
+\r
elif CurrentSection == DT.MODEL_EFI_GUID:\r
self.InfGuidParser(SectionLines,\r
self.InfGuidSection,\r
self.FullPath)\r
- \r
+\r
elif CurrentSection == DT.MODEL_EFI_DEPEX:\r
self.InfDepexParser(SectionLines,\r
self.InfDepexSection,\r
self.FullPath)\r
- \r
+\r
elif CurrentSection == DT.MODEL_EFI_BINARY_FILE:\r
self.InfBinaryParser(SectionLines,\r
self.InfBinariesSection,\r
#\r
else:\r
if len(self.SectionHeaderContent) >= 1:\r
- Logger.Error("Parser", \r
- PARSER_ERROR, \r
- ST.ERR_INF_PARSER_UNKNOWN_SECTION, \r
- File=self.FullPath, Line=LineNo, \r
+ Logger.Error("Parser",\r
+ PARSER_ERROR,\r
+ ST.ERR_INF_PARSER_UNKNOWN_SECTION,\r
+ File=self.FullPath, Line=LineNo,\r
RaiseError = Logger.IS_RAISE_ERROR)\r
else:\r
- Logger.Error("Parser", \r
- PARSER_ERROR, \r
- ST.ERR_INF_PARSER_NO_SECTION_ERROR, \r
- File=self.FullPath, Line=LineNo, \r
+ Logger.Error("Parser",\r
+ PARSER_ERROR,\r
+ ST.ERR_INF_PARSER_NO_SECTION_ERROR,\r
+ File=self.FullPath, Line=LineNo,\r
RaiseError = Logger.IS_RAISE_ERROR)\r
- \r
- return DefineSectionParsedFlag \r
- \r
+\r
+ return DefineSectionParsedFlag\r
+\r
def _ExtractEventHobBootMod(self, FileLinesList):\r
SpecialSectionStart = False\r
CheckLocation = False\r
elif not Line:\r
SpecialSectionStart = False\r
CheckLocation = True\r
- Element = [] \r
+ Element = []\r
else:\r
if not Line.startswith(DT.TAB_COMMENT_SPLIT):\r
- Logger.Warn("Parser", \r
- ST.WARN_SPECIAL_SECTION_LOCATION_WRONG, \r
+ Logger.Warn("Parser",\r
+ ST.WARN_SPECIAL_SECTION_LOCATION_WRONG,\r
File=self.FullPath, Line=LineNum)\r
SpecialSectionStart = False\r
CheckLocation = False\r
Element = []\r
else:\r
- Element.append([Line, LineNum]) \r
+ Element.append([Line, LineNum])\r
else:\r
if CheckLocation:\r
if MatchObject:\r
CheckLocation = False\r
elif Line:\r
- Logger.Warn("Parser", \r
- ST.WARN_SPECIAL_SECTION_LOCATION_WRONG, \r
- File=self.FullPath, Line=LineNum) \r
+ Logger.Warn("Parser",\r
+ ST.WARN_SPECIAL_SECTION_LOCATION_WRONG,\r
+ File=self.FullPath, Line=LineNum)\r
CheckLocation = False\r
- \r
+\r
if len(self.BootModeList) >= 1:\r
- self.InfSpecialCommentParser(self.BootModeList, \r
- self.InfSpecialCommentSection, \r
- self.FileName, \r
+ self.InfSpecialCommentParser(self.BootModeList,\r
+ self.InfSpecialCommentSection,\r
+ self.FileName,\r
DT.TYPE_BOOTMODE_SECTION)\r
- \r
+\r
if len(self.EventList) >= 1:\r
- self.InfSpecialCommentParser(self.EventList, \r
+ self.InfSpecialCommentParser(self.EventList,\r
self.InfSpecialCommentSection,\r
- self.FileName, \r
+ self.FileName,\r
DT.TYPE_EVENT_SECTION)\r
- \r
+\r
if len(self.HobList) >= 1:\r
- self.InfSpecialCommentParser(self.HobList, \r
- self.InfSpecialCommentSection, \r
- self.FileName, \r
+ self.InfSpecialCommentParser(self.HobList,\r
+ self.InfSpecialCommentSection,\r
+ self.FileName,\r
DT.TYPE_HOB_SECTION)\r
## _ProcessLastSection\r
#\r
#\r
# The last line is a section header. will discard it.\r
#\r
- if not (Line.startswith(DT.TAB_SECTION_START) and Line.find(DT.TAB_SECTION_END) > -1): \r
+ if not (Line.startswith(DT.TAB_SECTION_START) and Line.find(DT.TAB_SECTION_END) > -1):\r
SectionLines.append((Line, LineNo))\r
- \r
+\r
if len(self.SectionHeaderContent) >= 1:\r
TemSectionName = self.SectionHeaderContent[0][0].upper()\r
if TemSectionName.upper() not in gINF_SECTION_DEF.keys():\r
- Logger.Error("InfParser", \r
- FORMAT_INVALID, \r
- ST.ERR_INF_PARSER_UNKNOWN_SECTION, \r
- File=self.FullPath, \r
- Line=LineNo, \r
+ Logger.Error("InfParser",\r
+ FORMAT_INVALID,\r
+ ST.ERR_INF_PARSER_UNKNOWN_SECTION,\r
+ File=self.FullPath,\r
+ Line=LineNo,\r
ExtraData=Line,\r
RaiseError = Logger.IS_RAISE_ERROR\r
- ) \r
+ )\r
else:\r
CurrentSection = gINF_SECTION_DEF[TemSectionName]\r
self.LastSectionHeaderContent = self.SectionHeaderContent\r
- \r
+\r
return SectionLines, CurrentSection\r
\r
## _ConvertSecNameToType\r
#\r
#\r
-def _ConvertSecNameToType(SectionName): \r
+def _ConvertSecNameToType(SectionName):\r
SectionType = ''\r
if SectionName.upper() not in gINF_SECTION_DEF.keys():\r
- SectionType = DT.MODEL_UNKNOWN \r
+ SectionType = DT.MODEL_UNKNOWN\r
else:\r
- SectionType = gINF_SECTION_DEF[SectionName.upper()] \r
- \r
- return SectionType \r
- \r
+ SectionType = gINF_SECTION_DEF[SectionName.upper()]\r
+\r
+ return SectionType\r
+\r