--- /dev/null
+## @file\r
+# This file contained the parser for [Libraries] sections in INF file \r
+#\r
+# Copyright (c) 2011, 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
+#\r
+'''\r
+InfLibrarySectionParser\r
+'''\r
+##\r
+# Import Modules\r
+#\r
+\r
+import Logger.Log as Logger\r
+from Logger import StringTable as ST\r
+from Logger.ToolError import FORMAT_INVALID\r
+from Parser.InfParserMisc import InfExpandMacro\r
+from Library import DataType as DT\r
+from Library.Parsing import MacroParser\r
+from Library.Misc import GetSplitValueList\r
+from Object.Parser.InfCommonObject import InfLineCommentObject\r
+from Library import GlobalData\r
+from Parser.InfParserMisc import IsLibInstanceInfo\r
+from Parser.InfAsBuiltProcess import GetLibInstanceInfo\r
+from Parser.InfParserMisc import InfParserSectionRoot\r
+\r
+class InfLibrarySectionParser(InfParserSectionRoot):\r
+ ## InfLibraryParser\r
+ #\r
+ # \r
+ def InfLibraryParser(self, SectionString, InfSectionObject, FileName):\r
+ #\r
+ # For Common INF file\r
+ #\r
+ if not GlobalData.gIS_BINARY_INF:\r
+ #\r
+ # Macro defined in this section \r
+ #\r
+ SectionMacros = {}\r
+ ValueList = []\r
+ LibraryList = []\r
+ LibStillCommentFalg = False\r
+ LibHeaderComments = []\r
+ LibLineComment = None \r
+ #\r
+ # Parse section content\r
+ #\r
+ for Line in SectionString:\r
+ LibLineContent = Line[0]\r
+ LibLineNo = Line[1]\r
+ \r
+ if LibLineContent.strip() == '':\r
+ continue\r
+ \r
+ #\r
+ # Found Header Comments \r
+ #\r
+ if LibLineContent.strip().startswith(DT.TAB_COMMENT_SPLIT):\r
+ #\r
+ # Last line is comments, and this line go on.\r
+ #\r
+ if LibStillCommentFalg:\r
+ LibHeaderComments.append(Line)\r
+ continue\r
+ #\r
+ # First time encounter comment \r
+ #\r
+ else:\r
+ #\r
+ # Clear original data\r
+ #\r
+ LibHeaderComments = []\r
+ LibHeaderComments.append(Line)\r
+ LibStillCommentFalg = True\r
+ continue\r
+ else:\r
+ LibStillCommentFalg = False\r
+ \r
+ if len(LibHeaderComments) >= 1:\r
+ LibLineComment = InfLineCommentObject()\r
+ LineCommentContent = ''\r
+ for Item in LibHeaderComments:\r
+ LineCommentContent += Item[0] + DT.END_OF_LINE\r
+ LibLineComment.SetHeaderComments(LineCommentContent)\r
+ \r
+ #\r
+ # Find Tail comment.\r
+ #\r
+ if LibLineContent.find(DT.TAB_COMMENT_SPLIT) > -1:\r
+ LibTailComments = LibLineContent[LibLineContent.find(DT.TAB_COMMENT_SPLIT):]\r
+ LibLineContent = LibLineContent[:LibLineContent.find(DT.TAB_COMMENT_SPLIT)]\r
+ if LibLineComment == None:\r
+ LibLineComment = InfLineCommentObject()\r
+ LibLineComment.SetTailComments(LibTailComments) \r
+ \r
+ #\r
+ # Find Macro\r
+ #\r
+ Name, Value = MacroParser((LibLineContent, LibLineNo),\r
+ FileName,\r
+ DT.MODEL_EFI_LIBRARY_CLASS,\r
+ self.FileLocalMacros)\r
+ if Name != None:\r
+ SectionMacros[Name] = Value\r
+ LibLineComment = None\r
+ LibHeaderComments = [] \r
+ continue\r
+ \r
+ TokenList = GetSplitValueList(LibLineContent, DT.TAB_VALUE_SPLIT, 1)\r
+ ValueList[0:len(TokenList)] = TokenList\r
+ \r
+ #\r
+ # Replace with Local section Macro and [Defines] section Macro.\r
+ # \r
+ ValueList = [InfExpandMacro(Value, (FileName, LibLineContent, LibLineNo), \r
+ self.FileLocalMacros, SectionMacros, True)\r
+ for Value in ValueList]\r
+ \r
+ LibraryList.append((ValueList, LibLineComment, \r
+ (LibLineContent, LibLineNo, FileName)))\r
+ ValueList = []\r
+ LibLineComment = None\r
+ LibTailComments = ''\r
+ LibHeaderComments = []\r
+ \r
+ continue\r
+ \r
+ #\r
+ # Current section archs\r
+ # \r
+ KeyList = []\r
+ for Item in self.LastSectionHeaderContent:\r
+ if (Item[1], Item[2]) not in KeyList:\r
+ KeyList.append((Item[1], Item[2]))\r
+ \r
+ if not InfSectionObject.SetLibraryClasses(LibraryList, KeyList = KeyList):\r
+ Logger.Error('InfParser', \r
+ FORMAT_INVALID,\r
+ ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % ("[Library]"),\r
+ File=FileName, \r
+ Line=Item[3])\r
+ #\r
+ # For Binary INF\r
+ #\r
+ else:\r
+ self.InfAsBuiltLibraryParser(SectionString, InfSectionObject, FileName)\r
+ \r
+ def InfAsBuiltLibraryParser(self, SectionString, InfSectionObject, FileName):\r
+ LibraryList = []\r
+ LibInsFlag = False\r
+ for Line in SectionString:\r
+ LineContent = Line[0]\r
+ LineNo = Line[1]\r
+ \r
+ if LineContent.strip() == '':\r
+ LibInsFlag = False\r
+ continue\r
+ \r
+ if not LineContent.strip().startswith("#"):\r
+ Logger.Error('InfParser', \r
+ FORMAT_INVALID,\r
+ ST.ERR_LIB_CONTATIN_ASBUILD_AND_COMMON, \r
+ File=FileName, \r
+ Line=LineNo, \r
+ ExtraData=LineContent)\r
+ \r
+ if IsLibInstanceInfo(LineContent):\r
+ LibInsFlag = True\r
+ continue\r
+ \r
+ if LibInsFlag:\r
+ LibGuid, LibVer = GetLibInstanceInfo(LineContent, GlobalData.gWORKSPACE, LineNo)\r
+ #\r
+ # If the VERSION_STRING is missing from the INF file, tool should default to "0".\r
+ #\r
+ if LibVer == '':\r
+ LibVer = '0'\r
+ if LibGuid != '':\r
+ LibraryList.append((LibGuid, LibVer))\r
+ else:\r
+ Logger.Error('InfParser', \r
+ FORMAT_INVALID,\r
+ ST.ERR_LIB_INSTANCE_MISS_GUID, \r
+ File=FileName, \r
+ Line=LineNo, \r
+ ExtraData=LineContent) \r
+ \r
+ #\r
+ # Current section archs\r
+ # \r
+ KeyList = []\r
+ Item = ['', '', '']\r
+ for Item in self.LastSectionHeaderContent:\r
+ if (Item[1], Item[2]) not in KeyList:\r
+ KeyList.append((Item[1], Item[2]))\r
+ \r
+ if not InfSectionObject.SetLibraryClasses(LibraryList, KeyList = KeyList):\r
+ Logger.Error('InfParser', \r
+ FORMAT_INVALID,\r
+ ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % ("[Library]"),\r
+ File=FileName, \r
+ Line=Item[3])
\ No newline at end of file