]>
Commit | Line | Data |
---|---|---|
4234283c | 1 | ## @file\r |
f7496d71 | 2 | # This file contained the parser for [Libraries] sections in INF file\r |
4234283c | 3 | #\r |
f7496d71 | 4 | # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>\r |
4234283c | 5 | #\r |
f7496d71 LG |
6 | # This program and the accompanying materials are licensed and made available\r |
7 | # under the terms and conditions of the BSD License which accompanies this\r | |
8 | # distribution. The full text of the license may be found at\r | |
4234283c LG |
9 | # http://opensource.org/licenses/bsd-license.php\r |
10 | #\r | |
11 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | #\r | |
14 | '''\r | |
15 | InfLibrarySectionParser\r | |
16 | '''\r | |
17 | ##\r | |
18 | # Import Modules\r | |
19 | #\r | |
20 | \r | |
21 | import Logger.Log as Logger\r | |
22 | from Logger import StringTable as ST\r | |
23 | from Logger.ToolError import FORMAT_INVALID\r | |
24 | from Parser.InfParserMisc import InfExpandMacro\r | |
25 | from Library import DataType as DT\r | |
26 | from Library.Parsing import MacroParser\r | |
27 | from Library.Misc import GetSplitValueList\r | |
28 | from Object.Parser.InfCommonObject import InfLineCommentObject\r | |
29 | from Library import GlobalData\r | |
30 | from Parser.InfParserMisc import IsLibInstanceInfo\r | |
31 | from Parser.InfAsBuiltProcess import GetLibInstanceInfo\r | |
32 | from Parser.InfParserMisc import InfParserSectionRoot\r | |
33 | \r | |
34 | class InfLibrarySectionParser(InfParserSectionRoot):\r | |
35 | ## InfLibraryParser\r | |
36 | #\r | |
f7496d71 | 37 | #\r |
4234283c LG |
38 | def InfLibraryParser(self, SectionString, InfSectionObject, FileName):\r |
39 | #\r | |
40 | # For Common INF file\r | |
41 | #\r | |
42 | if not GlobalData.gIS_BINARY_INF:\r | |
43 | #\r | |
f7496d71 | 44 | # Macro defined in this section\r |
4234283c LG |
45 | #\r |
46 | SectionMacros = {}\r | |
421ccda3 HC |
47 | ValueList = []\r |
48 | LibraryList = []\r | |
49 | LibStillCommentFalg = False\r | |
50 | LibHeaderComments = []\r | |
51 | LibLineComment = None\r | |
4234283c LG |
52 | #\r |
53 | # Parse section content\r | |
54 | #\r | |
55 | for Line in SectionString:\r | |
56 | LibLineContent = Line[0]\r | |
421ccda3 HC |
57 | LibLineNo = Line[1]\r |
58 | \r | |
4234283c LG |
59 | if LibLineContent.strip() == '':\r |
60 | continue\r | |
421ccda3 | 61 | \r |
4234283c | 62 | #\r |
f7496d71 | 63 | # Found Header Comments\r |
4234283c LG |
64 | #\r |
65 | if LibLineContent.strip().startswith(DT.TAB_COMMENT_SPLIT):\r | |
66 | #\r | |
67 | # Last line is comments, and this line go on.\r | |
68 | #\r | |
69 | if LibStillCommentFalg:\r | |
70 | LibHeaderComments.append(Line)\r | |
71 | continue\r | |
72 | #\r | |
f7496d71 | 73 | # First time encounter comment\r |
4234283c LG |
74 | #\r |
75 | else:\r | |
76 | #\r | |
77 | # Clear original data\r | |
78 | #\r | |
79 | LibHeaderComments = []\r | |
80 | LibHeaderComments.append(Line)\r | |
81 | LibStillCommentFalg = True\r | |
82 | continue\r | |
83 | else:\r | |
84 | LibStillCommentFalg = False\r | |
421ccda3 | 85 | \r |
4234283c LG |
86 | if len(LibHeaderComments) >= 1:\r |
87 | LibLineComment = InfLineCommentObject()\r | |
88 | LineCommentContent = ''\r | |
89 | for Item in LibHeaderComments:\r | |
90 | LineCommentContent += Item[0] + DT.END_OF_LINE\r | |
91 | LibLineComment.SetHeaderComments(LineCommentContent)\r | |
421ccda3 | 92 | \r |
4234283c LG |
93 | #\r |
94 | # Find Tail comment.\r | |
95 | #\r | |
96 | if LibLineContent.find(DT.TAB_COMMENT_SPLIT) > -1:\r | |
97 | LibTailComments = LibLineContent[LibLineContent.find(DT.TAB_COMMENT_SPLIT):]\r | |
98 | LibLineContent = LibLineContent[:LibLineContent.find(DT.TAB_COMMENT_SPLIT)]\r | |
4231a819 | 99 | if LibLineComment is None:\r |
4234283c | 100 | LibLineComment = InfLineCommentObject()\r |
421ccda3 HC |
101 | LibLineComment.SetTailComments(LibTailComments)\r |
102 | \r | |
4234283c LG |
103 | #\r |
104 | # Find Macro\r | |
105 | #\r | |
106 | Name, Value = MacroParser((LibLineContent, LibLineNo),\r | |
107 | FileName,\r | |
108 | DT.MODEL_EFI_LIBRARY_CLASS,\r | |
109 | self.FileLocalMacros)\r | |
4231a819 | 110 | if Name is not None:\r |
4234283c LG |
111 | SectionMacros[Name] = Value\r |
112 | LibLineComment = None\r | |
421ccda3 | 113 | LibHeaderComments = []\r |
4234283c | 114 | continue\r |
421ccda3 | 115 | \r |
4234283c LG |
116 | TokenList = GetSplitValueList(LibLineContent, DT.TAB_VALUE_SPLIT, 1)\r |
117 | ValueList[0:len(TokenList)] = TokenList\r | |
421ccda3 | 118 | \r |
4234283c LG |
119 | #\r |
120 | # Replace with Local section Macro and [Defines] section Macro.\r | |
f7496d71 | 121 | #\r |
421ccda3 | 122 | ValueList = [InfExpandMacro(Value, (FileName, LibLineContent, LibLineNo),\r |
4234283c LG |
123 | self.FileLocalMacros, SectionMacros, True)\r |
124 | for Value in ValueList]\r | |
421ccda3 HC |
125 | \r |
126 | LibraryList.append((ValueList, LibLineComment,\r | |
4234283c LG |
127 | (LibLineContent, LibLineNo, FileName)))\r |
128 | ValueList = []\r | |
129 | LibLineComment = None\r | |
130 | LibTailComments = ''\r | |
131 | LibHeaderComments = []\r | |
421ccda3 | 132 | \r |
4234283c | 133 | continue\r |
421ccda3 | 134 | \r |
4234283c LG |
135 | #\r |
136 | # Current section archs\r | |
f7496d71 | 137 | #\r |
4234283c LG |
138 | KeyList = []\r |
139 | for Item in self.LastSectionHeaderContent:\r | |
140 | if (Item[1], Item[2]) not in KeyList:\r | |
141 | KeyList.append((Item[1], Item[2]))\r | |
421ccda3 HC |
142 | \r |
143 | if not InfSectionObject.SetLibraryClasses(LibraryList, KeyList=KeyList):\r | |
144 | Logger.Error('InfParser',\r | |
4234283c LG |
145 | FORMAT_INVALID,\r |
146 | ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % ("[Library]"),\r | |
421ccda3 | 147 | File=FileName,\r |
4234283c LG |
148 | Line=Item[3])\r |
149 | #\r | |
150 | # For Binary INF\r | |
151 | #\r | |
152 | else:\r | |
153 | self.InfAsBuiltLibraryParser(SectionString, InfSectionObject, FileName)\r | |
421ccda3 | 154 | \r |
4234283c LG |
155 | def InfAsBuiltLibraryParser(self, SectionString, InfSectionObject, FileName):\r |
156 | LibraryList = []\r | |
157 | LibInsFlag = False\r | |
158 | for Line in SectionString:\r | |
159 | LineContent = Line[0]\r | |
421ccda3 HC |
160 | LineNo = Line[1]\r |
161 | \r | |
4234283c LG |
162 | if LineContent.strip() == '':\r |
163 | LibInsFlag = False\r | |
164 | continue\r | |
421ccda3 | 165 | \r |
4234283c | 166 | if not LineContent.strip().startswith("#"):\r |
421ccda3 | 167 | Logger.Error('InfParser',\r |
4234283c | 168 | FORMAT_INVALID,\r |
421ccda3 HC |
169 | ST.ERR_LIB_CONTATIN_ASBUILD_AND_COMMON,\r |
170 | File=FileName,\r | |
171 | Line=LineNo,\r | |
4234283c | 172 | ExtraData=LineContent)\r |
4afd3d04 | 173 | \r |
4234283c LG |
174 | if IsLibInstanceInfo(LineContent):\r |
175 | LibInsFlag = True\r | |
176 | continue\r | |
4afd3d04 | 177 | \r |
4234283c | 178 | if LibInsFlag:\r |
4afd3d04 | 179 | LibGuid, LibVer = GetLibInstanceInfo(LineContent, GlobalData.gWORKSPACE, LineNo, FileName)\r |
4234283c LG |
180 | #\r |
181 | # If the VERSION_STRING is missing from the INF file, tool should default to "0".\r | |
182 | #\r | |
183 | if LibVer == '':\r | |
184 | LibVer = '0'\r | |
185 | if LibGuid != '':\r | |
4afd3d04 LG |
186 | if (LibGuid, LibVer) not in LibraryList:\r |
187 | LibraryList.append((LibGuid, LibVer))\r | |
4afd3d04 | 188 | \r |
4234283c LG |
189 | #\r |
190 | # Current section archs\r | |
f7496d71 | 191 | #\r |
4234283c LG |
192 | KeyList = []\r |
193 | Item = ['', '', '']\r | |
194 | for Item in self.LastSectionHeaderContent:\r | |
195 | if (Item[1], Item[2]) not in KeyList:\r | |
196 | KeyList.append((Item[1], Item[2]))\r | |
421ccda3 HC |
197 | \r |
198 | if not InfSectionObject.SetLibraryClasses(LibraryList, KeyList=KeyList):\r | |
199 | Logger.Error('InfParser',\r | |
4234283c LG |
200 | FORMAT_INVALID,\r |
201 | ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % ("[Library]"),\r | |
421ccda3 HC |
202 | File=FileName,\r |
203 | Line=Item[3])\r |