]>
Commit | Line | Data |
---|---|---|
4234283c LG |
1 | ## @file\r |
2 | # This file contained the parser for INF file\r | |
3 | #\r | |
64285f15 | 4 | # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>\r |
4234283c | 5 | #\r |
2e351cbe | 6 | # SPDX-License-Identifier: BSD-2-Clause-Patent\r |
4234283c LG |
7 | #\r |
8 | \r | |
9 | '''\r | |
10 | InfParser\r | |
11 | '''\r | |
12 | \r | |
13 | ##\r | |
14 | # Import Modules\r | |
15 | #\r | |
16 | import re\r | |
17 | import os\r | |
18 | from copy import deepcopy\r | |
19 | \r | |
64285f15 YZ |
20 | from Library.StringUtils import GetSplitValueList\r |
21 | from Library.StringUtils import ConvertSpecialChar\r | |
4234283c | 22 | from Library.Misc import ProcessLineExtender\r |
2bcc713e | 23 | from Library.Misc import ProcessEdkComment\r |
4234283c LG |
24 | from Library.Parsing import NormPath\r |
25 | from Library.ParserValidate import IsValidInfMoudleTypeList\r | |
26 | from Library.ParserValidate import IsValidArch\r | |
27 | from Library import DataType as DT\r | |
28 | from Library import GlobalData\r | |
29 | \r | |
30 | import Logger.Log as Logger\r | |
31 | from Logger import StringTable as ST\r | |
32 | from Logger.ToolError import FORMAT_INVALID\r | |
33 | from Logger.ToolError import FILE_READ_FAILURE\r | |
34 | from Logger.ToolError import PARSER_ERROR\r | |
35 | \r | |
36 | from Object.Parser.InfCommonObject import InfSectionCommonDef\r | |
37 | from Parser.InfSectionParser import InfSectionParser\r | |
38 | from Parser.InfParserMisc import gINF_SECTION_DEF\r | |
39 | from Parser.InfParserMisc import IsBinaryInf\r | |
40 | \r | |
41 | ## OpenInfFile\r | |
42 | #\r | |
43 | #\r | |
44 | def OpenInfFile(Filename):\r | |
45 | FileLinesList = []\r | |
f7496d71 | 46 | \r |
4234283c | 47 | try:\r |
174a9d3c | 48 | FInputfile = open(Filename, "r")\r |
4234283c LG |
49 | try:\r |
50 | FileLinesList = FInputfile.readlines()\r | |
51 | except BaseException:\r | |
f7496d71 LG |
52 | Logger.Error("InfParser",\r |
53 | FILE_READ_FAILURE,\r | |
4234283c LG |
54 | ST.ERR_FILE_OPEN_FAILURE,\r |
55 | File=Filename)\r | |
56 | finally:\r | |
57 | FInputfile.close()\r | |
58 | except BaseException:\r | |
f7496d71 LG |
59 | Logger.Error("InfParser",\r |
60 | FILE_READ_FAILURE,\r | |
4234283c LG |
61 | ST.ERR_FILE_OPEN_FAILURE,\r |
62 | File=Filename)\r | |
f7496d71 | 63 | \r |
4234283c LG |
64 | return FileLinesList\r |
65 | \r | |
66 | ## InfParser\r | |
67 | #\r | |
68 | # This class defined the structure used in InfParser object\r | |
69 | #\r | |
70 | # @param InfObject: Inherited from InfSectionParser class\r | |
f7496d71 | 71 | # @param Filename: Input value for Filename of INF file, default is\r |
4234283c | 72 | # None\r |
f7496d71 | 73 | # @param WorkspaceDir: Input value for current workspace directory,\r |
4234283c LG |
74 | # default is None\r |
75 | #\r | |
76 | class InfParser(InfSectionParser):\r | |
77 | \r | |
78 | def __init__(self, Filename = None, WorkspaceDir = None):\r | |
f7496d71 | 79 | \r |
4234283c LG |
80 | #\r |
81 | # Call parent class construct function\r | |
82 | #\r | |
174a9d3c | 83 | InfSectionParser.__init__()\r |
f7496d71 | 84 | \r |
4234283c LG |
85 | self.WorkspaceDir = WorkspaceDir\r |
86 | self.SupArchList = DT.ARCH_LIST\r | |
87 | self.EventList = []\r | |
88 | self.HobList = []\r | |
89 | self.BootModeList = []\r | |
90 | \r | |
91 | #\r | |
92 | # Load Inf file if filename is not None\r | |
93 | #\r | |
4231a819 | 94 | if Filename is not None:\r |
4234283c LG |
95 | self.ParseInfFile(Filename)\r |
96 | \r | |
97 | ## Parse INF file\r | |
98 | #\r | |
99 | # Parse the file if it exists\r | |
100 | #\r | |
101 | # @param Filename: Input value for filename of INF file\r | |
102 | #\r | |
103 | def ParseInfFile(self, Filename):\r | |
f7496d71 | 104 | \r |
4234283c LG |
105 | Filename = NormPath(Filename)\r |
106 | (Path, Name) = os.path.split(Filename)\r | |
107 | self.FullPath = Filename\r | |
108 | self.RelaPath = Path\r | |
109 | self.FileName = Name\r | |
110 | GlobalData.gINF_MODULE_DIR = Path\r | |
111 | GlobalData.gINF_MODULE_NAME = self.FullPath\r | |
112 | GlobalData.gIS_BINARY_INF = False\r | |
113 | #\r | |
114 | # Initialize common data\r | |
115 | #\r | |
116 | LineNo = 0\r | |
f7496d71 | 117 | CurrentSection = DT.MODEL_UNKNOWN\r |
4234283c | 118 | SectionLines = []\r |
f7496d71 | 119 | \r |
4234283c LG |
120 | #\r |
121 | # Flags\r | |
122 | #\r | |
f7496d71 | 123 | HeaderCommentStart = False\r |
4234283c | 124 | HeaderCommentEnd = False\r |
2bc3256c | 125 | HeaderStarLineNo = -1\r |
f7496d71 | 126 | BinaryHeaderCommentStart = False\r |
2bc3256c LG |
127 | BinaryHeaderCommentEnd = False\r |
128 | BinaryHeaderStarLineNo = -1\r | |
f7496d71 | 129 | \r |
4234283c LG |
130 | #\r |
131 | # While Section ends. parse whole section contents.\r | |
132 | #\r | |
133 | NewSectionStartFlag = False\r | |
134 | FirstSectionStartFlag = False\r | |
f7496d71 | 135 | \r |
4234283c LG |
136 | #\r |
137 | # Parse file content\r | |
138 | #\r | |
139 | CommentBlock = []\r | |
f7496d71 | 140 | \r |
4234283c LG |
141 | #\r |
142 | # Variables for Event/Hob/BootMode\r | |
143 | #\r | |
144 | self.EventList = []\r | |
145 | self.HobList = []\r | |
146 | self.BootModeList = []\r | |
147 | SectionType = ''\r | |
f7496d71 | 148 | \r |
4234283c | 149 | FileLinesList = OpenInfFile (Filename)\r |
f7496d71 | 150 | \r |
4234283c LG |
151 | #\r |
152 | # One INF file can only has one [Defines] section.\r | |
153 | #\r | |
154 | DefineSectionParsedFlag = False\r | |
f7496d71 | 155 | \r |
4234283c LG |
156 | #\r |
157 | # Convert special characters in lines to space character.\r | |
158 | #\r | |
159 | FileLinesList = ConvertSpecialChar(FileLinesList)\r | |
f7496d71 | 160 | \r |
4234283c LG |
161 | #\r |
162 | # Process Line Extender\r | |
163 | #\r | |
164 | FileLinesList = ProcessLineExtender(FileLinesList)\r | |
f7496d71 | 165 | \r |
2bcc713e LG |
166 | #\r |
167 | # Process EdkI INF style comment if found\r | |
168 | #\r | |
169 | OrigLines = [Line for Line in FileLinesList]\r | |
170 | FileLinesList, EdkCommentStartPos = ProcessEdkComment(FileLinesList)\r | |
f7496d71 | 171 | \r |
4234283c LG |
172 | #\r |
173 | # Judge whether the INF file is Binary INF or not\r | |
174 | #\r | |
175 | if IsBinaryInf(FileLinesList):\r | |
176 | GlobalData.gIS_BINARY_INF = True\r | |
f7496d71 | 177 | \r |
4234283c | 178 | InfSectionCommonDefObj = None\r |
f7496d71 | 179 | \r |
4234283c LG |
180 | for Line in FileLinesList:\r |
181 | LineNo = LineNo + 1\r | |
182 | Line = Line.strip()\r | |
183 | if (LineNo < len(FileLinesList) - 1):\r | |
184 | NextLine = FileLinesList[LineNo].strip()\r | |
f7496d71 | 185 | \r |
4234283c LG |
186 | #\r |
187 | # blank line\r | |
188 | #\r | |
189 | if (Line == '' or not Line) and LineNo == len(FileLinesList):\r | |
190 | LastSectionFalg = True\r | |
191 | \r | |
192 | #\r | |
193 | # check whether file header comment section started\r | |
194 | #\r | |
195 | if Line.startswith(DT.TAB_SPECIAL_COMMENT) and \\r | |
196 | (Line.find(DT.TAB_HEADER_COMMENT) > -1) and \\r | |
2bc3256c LG |
197 | not HeaderCommentStart and not HeaderCommentEnd:\r |
198 | \r | |
199 | CurrentSection = DT.MODEL_META_DATA_FILE_HEADER\r | |
200 | #\r | |
201 | # Append the first line to section lines.\r | |
202 | #\r | |
203 | HeaderStarLineNo = LineNo\r | |
204 | SectionLines.append((Line, LineNo))\r | |
205 | HeaderCommentStart = True\r | |
f7496d71 | 206 | continue\r |
421ccda3 | 207 | \r |
4234283c LG |
208 | #\r |
209 | # Collect Header content.\r | |
210 | #\r | |
211 | if (Line.startswith(DT.TAB_COMMENT_SPLIT) and CurrentSection == DT.MODEL_META_DATA_FILE_HEADER) and\\r | |
212 | HeaderCommentStart and not Line.startswith(DT.TAB_SPECIAL_COMMENT) and not\\r | |
213 | HeaderCommentEnd and NextLine != '':\r | |
214 | SectionLines.append((Line, LineNo))\r | |
215 | continue\r | |
216 | #\r | |
217 | # Header content end\r | |
218 | #\r | |
219 | if (Line.startswith(DT.TAB_SPECIAL_COMMENT) or not Line.strip().startswith("#")) and HeaderCommentStart \\r | |
220 | and not HeaderCommentEnd:\r | |
2bc3256c | 221 | HeaderCommentEnd = True\r |
f7496d71 | 222 | BinaryHeaderCommentStart = False\r |
2bc3256c | 223 | BinaryHeaderCommentEnd = False\r |
f7496d71 | 224 | HeaderCommentStart = False\r |
2bc3256c | 225 | if Line.find(DT.TAB_BINARY_HEADER_COMMENT) > -1:\r |
f7496d71 | 226 | self.InfHeaderParser(SectionLines, self.InfHeader, self.FileName)\r |
2bc3256c LG |
227 | SectionLines = []\r |
228 | else:\r | |
229 | SectionLines.append((Line, LineNo))\r | |
421ccda3 HC |
230 | #\r |
231 | # Call Header comment parser.\r | |
232 | #\r | |
233 | self.InfHeaderParser(SectionLines, self.InfHeader, self.FileName)\r | |
234 | SectionLines = []\r | |
235 | continue\r | |
2bc3256c LG |
236 | \r |
237 | #\r | |
238 | # check whether binary header comment section started\r | |
239 | #\r | |
240 | if Line.startswith(DT.TAB_SPECIAL_COMMENT) and \\r | |
241 | (Line.find(DT.TAB_BINARY_HEADER_COMMENT) > -1) and \\r | |
242 | not BinaryHeaderCommentStart:\r | |
243 | SectionLines = []\r | |
244 | CurrentSection = DT.MODEL_META_DATA_FILE_HEADER\r | |
245 | #\r | |
246 | # Append the first line to section lines.\r | |
247 | #\r | |
248 | BinaryHeaderStarLineNo = LineNo\r | |
249 | SectionLines.append((Line, LineNo))\r | |
250 | BinaryHeaderCommentStart = True\r | |
421ccda3 | 251 | HeaderCommentEnd = True\r |
f7496d71 LG |
252 | continue\r |
253 | \r | |
4234283c | 254 | #\r |
2bc3256c LG |
255 | # check whether there are more than one binary header exist\r |
256 | #\r | |
257 | if Line.startswith(DT.TAB_SPECIAL_COMMENT) and BinaryHeaderCommentStart and \\r | |
258 | not BinaryHeaderCommentEnd and (Line.find(DT.TAB_BINARY_HEADER_COMMENT) > -1):\r | |
259 | Logger.Error('Parser',\r | |
260 | FORMAT_INVALID,\r | |
261 | ST.ERR_MULTIPLE_BINARYHEADER_EXIST,\r | |
262 | File=Filename)\r | |
f7496d71 | 263 | \r |
2bc3256c LG |
264 | #\r |
265 | # Collect Binary Header content.\r | |
266 | #\r | |
267 | if (Line.startswith(DT.TAB_COMMENT_SPLIT) and CurrentSection == DT.MODEL_META_DATA_FILE_HEADER) and\\r | |
268 | BinaryHeaderCommentStart and not Line.startswith(DT.TAB_SPECIAL_COMMENT) and not\\r | |
269 | BinaryHeaderCommentEnd and NextLine != '':\r | |
270 | SectionLines.append((Line, LineNo))\r | |
271 | continue\r | |
272 | #\r | |
273 | # Binary Header content end\r | |
274 | #\r | |
275 | if (Line.startswith(DT.TAB_SPECIAL_COMMENT) or not Line.strip().startswith(DT.TAB_COMMENT_SPLIT)) and \\r | |
276 | BinaryHeaderCommentStart and not BinaryHeaderCommentEnd:\r | |
277 | SectionLines.append((Line, LineNo))\r | |
278 | BinaryHeaderCommentStart = False\r | |
279 | #\r | |
280 | # Call Binary Header comment parser.\r | |
281 | #\r | |
282 | self.InfHeaderParser(SectionLines, self.InfBinaryHeader, self.FileName, True)\r | |
283 | SectionLines = []\r | |
f7496d71 LG |
284 | BinaryHeaderCommentEnd = True\r |
285 | continue\r | |
2bc3256c | 286 | #\r |
4234283c | 287 | # Find a new section tab\r |
f7496d71 | 288 | # Or at the last line of INF file,\r |
4234283c LG |
289 | # need to process the last section.\r |
290 | #\r | |
291 | LastSectionFalg = False\r | |
292 | if LineNo == len(FileLinesList):\r | |
293 | LastSectionFalg = True\r | |
f7496d71 | 294 | \r |
4234283c LG |
295 | if Line.startswith(DT.TAB_COMMENT_SPLIT) and not Line.startswith(DT.TAB_SPECIAL_COMMENT):\r |
296 | SectionLines.append((Line, LineNo))\r | |
297 | if not LastSectionFalg:\r | |
298 | continue\r | |
421ccda3 | 299 | \r |
4234283c LG |
300 | #\r |
301 | # Encountered a section. start with '[' and end with ']'\r | |
302 | #\r | |
303 | if (Line.startswith(DT.TAB_SECTION_START) and \\r | |
f7496d71 LG |
304 | Line.find(DT.TAB_SECTION_END) > -1) or LastSectionFalg:\r |
305 | \r | |
306 | HeaderCommentEnd = True\r | |
307 | BinaryHeaderCommentEnd = True\r | |
308 | \r | |
4234283c LG |
309 | if not LastSectionFalg:\r |
310 | #\r | |
311 | # check to prevent '#' inside section header\r | |
312 | #\r | |
313 | HeaderContent = Line[1:Line.find(DT.TAB_SECTION_END)]\r | |
314 | if HeaderContent.find(DT.TAB_COMMENT_SPLIT) != -1:\r | |
f7496d71 | 315 | Logger.Error("InfParser",\r |
4234283c LG |
316 | FORMAT_INVALID,\r |
317 | ST.ERR_INF_PARSER_DEFINE_SECTION_HEADER_INVALID,\r | |
318 | File=self.FullPath,\r | |
f7496d71 LG |
319 | Line=LineNo,\r |
320 | ExtraData=Line)\r | |
421ccda3 | 321 | \r |
4234283c LG |
322 | #\r |
323 | # Keep last time section header content for section parser\r | |
324 | # usage.\r | |
325 | #\r | |
326 | self.LastSectionHeaderContent = deepcopy(self.SectionHeaderContent)\r | |
421ccda3 | 327 | \r |
4234283c LG |
328 | #\r |
329 | # TailComments in section define.\r | |
330 | #\r | |
331 | TailComments = ''\r | |
332 | CommentIndex = Line.find(DT.TAB_COMMENT_SPLIT)\r | |
333 | if CommentIndex > -1:\r | |
334 | TailComments = Line[CommentIndex:]\r | |
335 | Line = Line[:CommentIndex]\r | |
f7496d71 | 336 | \r |
4234283c LG |
337 | InfSectionCommonDefObj = InfSectionCommonDef()\r |
338 | if TailComments != '':\r | |
339 | InfSectionCommonDefObj.SetTailComments(TailComments)\r | |
340 | if CommentBlock != '':\r | |
341 | InfSectionCommonDefObj.SetHeaderComments(CommentBlock)\r | |
342 | CommentBlock = []\r | |
343 | #\r | |
344 | # Call section parser before section header parer to avoid encounter EDKI INF file\r | |
345 | #\r | |
346 | if CurrentSection == DT.MODEL_META_DATA_DEFINE:\r | |
f7496d71 LG |
347 | DefineSectionParsedFlag = self._CallSectionParsers(CurrentSection,\r |
348 | DefineSectionParsedFlag, SectionLines,\r | |
4234283c LG |
349 | InfSectionCommonDefObj, LineNo)\r |
350 | #\r | |
351 | # Compare the new section name with current\r | |
352 | #\r | |
353 | self.SectionHeaderParser(Line, self.FileName, LineNo)\r | |
421ccda3 | 354 | \r |
4234283c LG |
355 | self._CheckSectionHeaders(Line, LineNo)\r |
356 | \r | |
357 | SectionType = _ConvertSecNameToType(self.SectionHeaderContent[0][0])\r | |
421ccda3 | 358 | \r |
4234283c LG |
359 | if not FirstSectionStartFlag:\r |
360 | CurrentSection = SectionType\r | |
361 | FirstSectionStartFlag = True\r | |
362 | else:\r | |
363 | NewSectionStartFlag = True\r | |
364 | else:\r | |
365 | SectionLines.append((Line, LineNo))\r | |
366 | continue\r | |
421ccda3 | 367 | \r |
4234283c LG |
368 | if LastSectionFalg:\r |
369 | SectionLines, CurrentSection = self._ProcessLastSection(SectionLines, Line, LineNo, CurrentSection)\r | |
421ccda3 | 370 | \r |
4234283c LG |
371 | #\r |
372 | # End of section content collect.\r | |
373 | # Parser the section content collected previously.\r | |
f7496d71 | 374 | #\r |
4234283c LG |
375 | if NewSectionStartFlag or LastSectionFalg:\r |
376 | if CurrentSection != DT.MODEL_META_DATA_DEFINE or \\r | |
f7496d71 LG |
377 | (LastSectionFalg and CurrentSection == DT.MODEL_META_DATA_DEFINE):\r |
378 | DefineSectionParsedFlag = self._CallSectionParsers(CurrentSection,\r | |
379 | DefineSectionParsedFlag, SectionLines,\r | |
4234283c | 380 | InfSectionCommonDefObj, LineNo)\r |
f7496d71 | 381 | \r |
4234283c LG |
382 | CurrentSection = SectionType\r |
383 | #\r | |
384 | # Clear section lines\r | |
385 | #\r | |
f7496d71 LG |
386 | SectionLines = []\r |
387 | \r | |
2bc3256c | 388 | if HeaderStarLineNo == -1:\r |
f7496d71 | 389 | Logger.Error("InfParser",\r |
421ccda3 HC |
390 | FORMAT_INVALID,\r |
391 | ST.ERR_NO_SOURCE_HEADER,\r | |
f7496d71 | 392 | File=self.FullPath)\r |
2bc3256c | 393 | if BinaryHeaderStarLineNo > -1 and HeaderStarLineNo > -1 and HeaderStarLineNo > BinaryHeaderStarLineNo:\r |
f7496d71 | 394 | Logger.Error("InfParser",\r |
2bc3256c LG |
395 | FORMAT_INVALID,\r |
396 | ST.ERR_BINARY_HEADER_ORDER,\r | |
f7496d71 | 397 | File=self.FullPath)\r |
2bcc713e LG |
398 | #\r |
399 | # EDKII INF should not have EDKI style comment\r | |
400 | #\r | |
401 | if EdkCommentStartPos != -1:\r | |
f7496d71 LG |
402 | Logger.Error("InfParser",\r |
403 | FORMAT_INVALID,\r | |
404 | ST.ERR_INF_PARSER_EDKI_COMMENT_IN_EDKII,\r | |
2bcc713e LG |
405 | File=self.FullPath,\r |
406 | Line=EdkCommentStartPos + 1,\r | |
407 | ExtraData=OrigLines[EdkCommentStartPos])\r | |
f7496d71 LG |
408 | \r |
409 | #\r | |
410 | # extract [Event] [Hob] [BootMode] sections\r | |
4234283c | 411 | #\r |
4234283c | 412 | self._ExtractEventHobBootMod(FileLinesList)\r |
f7496d71 | 413 | \r |
4234283c LG |
414 | ## _CheckSectionHeaders\r |
415 | #\r | |
416 | #\r | |
417 | def _CheckSectionHeaders(self, Line, LineNo):\r | |
418 | if len(self.SectionHeaderContent) == 0:\r | |
f7496d71 | 419 | Logger.Error("InfParser",\r |
4234283c LG |
420 | FORMAT_INVALID,\r |
421 | ST.ERR_INF_PARSER_DEFINE_SECTION_HEADER_INVALID,\r | |
422 | File=self.FullPath,\r | |
423 | Line=LineNo, ExtraData=Line)\r | |
424 | else:\r | |
425 | for SectionItem in self.SectionHeaderContent:\r | |
426 | ArchList = []\r | |
427 | #\r | |
f7496d71 | 428 | # Not cover Depex/UserExtension section header\r |
4234283c LG |
429 | # check.\r |
430 | #\r | |
431 | if SectionItem[0].strip().upper() == DT.TAB_INF_FIXED_PCD.upper() or \\r | |
432 | SectionItem[0].strip().upper() == DT.TAB_INF_PATCH_PCD.upper() or \\r | |
433 | SectionItem[0].strip().upper() == DT.TAB_INF_PCD_EX.upper() or \\r | |
434 | SectionItem[0].strip().upper() == DT.TAB_INF_PCD.upper() or \\r | |
435 | SectionItem[0].strip().upper() == DT.TAB_INF_FEATURE_PCD.upper():\r | |
436 | ArchList = GetSplitValueList(SectionItem[1].strip(), ' ')\r | |
437 | else:\r | |
438 | ArchList = [SectionItem[1].strip()]\r | |
f7496d71 | 439 | \r |
4234283c LG |
440 | for Arch in ArchList:\r |
441 | if (not IsValidArch(Arch)) and \\r | |
442 | (SectionItem[0].strip().upper() != DT.TAB_DEPEX.upper()) and \\r | |
443 | (SectionItem[0].strip().upper() != DT.TAB_USER_EXTENSIONS.upper()) and \\r | |
444 | (SectionItem[0].strip().upper() != DT.TAB_COMMON_DEFINES.upper()):\r | |
f7496d71 | 445 | Logger.Error("InfParser",\r |
4234283c | 446 | FORMAT_INVALID,\r |
f7496d71 | 447 | ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID%(SectionItem[1]),\r |
4234283c LG |
448 | File=self.FullPath,\r |
449 | Line=LineNo, ExtraData=Line)\r | |
450 | #\r | |
451 | # Check if the ModuleType is valid\r | |
452 | #\r | |
453 | ChkModSectionList = ['LIBRARYCLASSES']\r | |
454 | if (self.SectionHeaderContent[0][0].upper() in ChkModSectionList):\r | |
455 | if SectionItem[2].strip().upper():\r | |
456 | MoudleTypeList = GetSplitValueList(\r | |
457 | SectionItem[2].strip().upper())\r | |
458 | if (not IsValidInfMoudleTypeList(MoudleTypeList)):\r | |
459 | Logger.Error("InfParser",\r | |
460 | FORMAT_INVALID,\r | |
461 | ST.ERR_INF_PARSER_DEFINE_FROMAT_INVALID%(SectionItem[2]),\r | |
462 | File=self.FullPath, Line=LineNo,\r | |
463 | ExtraData=Line)\r | |
f7496d71 | 464 | \r |
4234283c LG |
465 | ## _CallSectionParsers\r |
466 | #\r | |
467 | #\r | |
f7496d71 | 468 | def _CallSectionParsers(self, CurrentSection, DefineSectionParsedFlag,\r |
4234283c LG |
469 | SectionLines, InfSectionCommonDefObj, LineNo):\r |
470 | if CurrentSection == DT.MODEL_META_DATA_DEFINE:\r | |
471 | if not DefineSectionParsedFlag:\r | |
472 | self.InfDefineParser(SectionLines,\r | |
473 | self.InfDefSection,\r | |
474 | self.FullPath,\r | |
475 | InfSectionCommonDefObj)\r | |
476 | DefineSectionParsedFlag = True\r | |
477 | else:\r | |
f7496d71 LG |
478 | Logger.Error("Parser",\r |
479 | PARSER_ERROR,\r | |
480 | ST.ERR_INF_PARSER_MULTI_DEFINE_SECTION,\r | |
481 | File=self.FullPath,\r | |
4234283c | 482 | RaiseError = Logger.IS_RAISE_ERROR)\r |
f7496d71 | 483 | \r |
4234283c LG |
484 | elif CurrentSection == DT.MODEL_META_DATA_BUILD_OPTION:\r |
485 | self.InfBuildOptionParser(SectionLines,\r | |
486 | self.InfBuildOptionSection,\r | |
487 | self.FullPath)\r | |
f7496d71 | 488 | \r |
4234283c LG |
489 | elif CurrentSection == DT.MODEL_EFI_LIBRARY_CLASS:\r |
490 | self.InfLibraryParser(SectionLines,\r | |
491 | self.InfLibraryClassSection,\r | |
492 | self.FullPath)\r | |
f7496d71 | 493 | \r |
4234283c LG |
494 | elif CurrentSection == DT.MODEL_META_DATA_PACKAGE:\r |
495 | self.InfPackageParser(SectionLines,\r | |
496 | self.InfPackageSection,\r | |
497 | self.FullPath)\r | |
498 | #\r | |
499 | # [Pcd] Sections, put it together\r | |
500 | #\r | |
501 | elif CurrentSection == DT.MODEL_PCD_FIXED_AT_BUILD or \\r | |
502 | CurrentSection == DT.MODEL_PCD_PATCHABLE_IN_MODULE or \\r | |
503 | CurrentSection == DT.MODEL_PCD_FEATURE_FLAG or \\r | |
504 | CurrentSection == DT.MODEL_PCD_DYNAMIC_EX or \\r | |
505 | CurrentSection == DT.MODEL_PCD_DYNAMIC:\r | |
506 | self.InfPcdParser(SectionLines,\r | |
507 | self.InfPcdSection,\r | |
508 | self.FullPath)\r | |
f7496d71 | 509 | \r |
4234283c LG |
510 | elif CurrentSection == DT.MODEL_EFI_SOURCE_FILE:\r |
511 | self.InfSourceParser(SectionLines,\r | |
512 | self.InfSourcesSection,\r | |
513 | self.FullPath)\r | |
f7496d71 | 514 | \r |
4234283c LG |
515 | elif CurrentSection == DT.MODEL_META_DATA_USER_EXTENSION:\r |
516 | self.InfUserExtensionParser(SectionLines,\r | |
517 | self.InfUserExtensionSection,\r | |
518 | self.FullPath)\r | |
f7496d71 | 519 | \r |
4234283c LG |
520 | elif CurrentSection == DT.MODEL_EFI_PROTOCOL:\r |
521 | self.InfProtocolParser(SectionLines,\r | |
522 | self.InfProtocolSection,\r | |
523 | self.FullPath)\r | |
f7496d71 | 524 | \r |
4234283c LG |
525 | elif CurrentSection == DT.MODEL_EFI_PPI:\r |
526 | self.InfPpiParser(SectionLines,\r | |
527 | self.InfPpiSection,\r | |
528 | self.FullPath)\r | |
f7496d71 | 529 | \r |
4234283c LG |
530 | elif CurrentSection == DT.MODEL_EFI_GUID:\r |
531 | self.InfGuidParser(SectionLines,\r | |
532 | self.InfGuidSection,\r | |
533 | self.FullPath)\r | |
f7496d71 | 534 | \r |
4234283c LG |
535 | elif CurrentSection == DT.MODEL_EFI_DEPEX:\r |
536 | self.InfDepexParser(SectionLines,\r | |
537 | self.InfDepexSection,\r | |
538 | self.FullPath)\r | |
f7496d71 | 539 | \r |
4234283c LG |
540 | elif CurrentSection == DT.MODEL_EFI_BINARY_FILE:\r |
541 | self.InfBinaryParser(SectionLines,\r | |
542 | self.InfBinariesSection,\r | |
543 | self.FullPath)\r | |
544 | #\r | |
545 | # Unknown section type found, raise error.\r | |
546 | #\r | |
547 | else:\r | |
548 | if len(self.SectionHeaderContent) >= 1:\r | |
f7496d71 LG |
549 | Logger.Error("Parser",\r |
550 | PARSER_ERROR,\r | |
551 | ST.ERR_INF_PARSER_UNKNOWN_SECTION,\r | |
552 | File=self.FullPath, Line=LineNo,\r | |
4234283c LG |
553 | RaiseError = Logger.IS_RAISE_ERROR)\r |
554 | else:\r | |
f7496d71 LG |
555 | Logger.Error("Parser",\r |
556 | PARSER_ERROR,\r | |
557 | ST.ERR_INF_PARSER_NO_SECTION_ERROR,\r | |
558 | File=self.FullPath, Line=LineNo,\r | |
4234283c | 559 | RaiseError = Logger.IS_RAISE_ERROR)\r |
f7496d71 LG |
560 | \r |
561 | return DefineSectionParsedFlag\r | |
562 | \r | |
4234283c LG |
563 | def _ExtractEventHobBootMod(self, FileLinesList):\r |
564 | SpecialSectionStart = False\r | |
565 | CheckLocation = False\r | |
566 | GFindSpecialCommentRe = \\r | |
567 | re.compile(r"""#(?:\s*)\[(.*?)\](?:.*)""", re.DOTALL)\r | |
568 | GFindNewSectionRe2 = \\r | |
569 | re.compile(r"""#?(\s*)\[(.*?)\](.*)""", re.DOTALL)\r | |
570 | LineNum = 0\r | |
571 | Element = []\r | |
572 | for Line in FileLinesList:\r | |
573 | Line = Line.strip()\r | |
574 | LineNum += 1\r | |
575 | MatchObject = GFindSpecialCommentRe.search(Line)\r | |
576 | if MatchObject:\r | |
577 | SpecialSectionStart = True\r | |
578 | Element = []\r | |
579 | if MatchObject.group(1).upper().startswith("EVENT"):\r | |
580 | List = self.EventList\r | |
581 | elif MatchObject.group(1).upper().startswith("HOB"):\r | |
582 | List = self.HobList\r | |
583 | elif MatchObject.group(1).upper().startswith("BOOTMODE"):\r | |
584 | List = self.BootModeList\r | |
585 | else:\r | |
586 | SpecialSectionStart = False\r | |
587 | CheckLocation = False\r | |
588 | if SpecialSectionStart:\r | |
589 | Element.append([Line, LineNum])\r | |
590 | List.append(Element)\r | |
591 | else:\r | |
592 | #\r | |
593 | # if currently in special section, try to detect end of current section\r | |
594 | #\r | |
595 | MatchObject = GFindNewSectionRe2.search(Line)\r | |
596 | if SpecialSectionStart:\r | |
597 | if MatchObject:\r | |
598 | SpecialSectionStart = False\r | |
599 | CheckLocation = False\r | |
600 | Element = []\r | |
601 | elif not Line:\r | |
602 | SpecialSectionStart = False\r | |
603 | CheckLocation = True\r | |
f7496d71 | 604 | Element = []\r |
4234283c LG |
605 | else:\r |
606 | if not Line.startswith(DT.TAB_COMMENT_SPLIT):\r | |
f7496d71 LG |
607 | Logger.Warn("Parser",\r |
608 | ST.WARN_SPECIAL_SECTION_LOCATION_WRONG,\r | |
4234283c LG |
609 | File=self.FullPath, Line=LineNum)\r |
610 | SpecialSectionStart = False\r | |
611 | CheckLocation = False\r | |
612 | Element = []\r | |
613 | else:\r | |
f7496d71 | 614 | Element.append([Line, LineNum])\r |
4234283c LG |
615 | else:\r |
616 | if CheckLocation:\r | |
617 | if MatchObject:\r | |
618 | CheckLocation = False\r | |
619 | elif Line:\r | |
f7496d71 LG |
620 | Logger.Warn("Parser",\r |
621 | ST.WARN_SPECIAL_SECTION_LOCATION_WRONG,\r | |
622 | File=self.FullPath, Line=LineNum)\r | |
4234283c | 623 | CheckLocation = False\r |
f7496d71 | 624 | \r |
4234283c | 625 | if len(self.BootModeList) >= 1:\r |
f7496d71 LG |
626 | self.InfSpecialCommentParser(self.BootModeList,\r |
627 | self.InfSpecialCommentSection,\r | |
628 | self.FileName,\r | |
4234283c | 629 | DT.TYPE_BOOTMODE_SECTION)\r |
f7496d71 | 630 | \r |
4234283c | 631 | if len(self.EventList) >= 1:\r |
f7496d71 | 632 | self.InfSpecialCommentParser(self.EventList,\r |
4234283c | 633 | self.InfSpecialCommentSection,\r |
f7496d71 | 634 | self.FileName,\r |
4234283c | 635 | DT.TYPE_EVENT_SECTION)\r |
f7496d71 | 636 | \r |
4234283c | 637 | if len(self.HobList) >= 1:\r |
f7496d71 LG |
638 | self.InfSpecialCommentParser(self.HobList,\r |
639 | self.InfSpecialCommentSection,\r | |
640 | self.FileName,\r | |
4234283c LG |
641 | DT.TYPE_HOB_SECTION)\r |
642 | ## _ProcessLastSection\r | |
643 | #\r | |
644 | #\r | |
645 | def _ProcessLastSection(self, SectionLines, Line, LineNo, CurrentSection):\r | |
646 | #\r | |
647 | # The last line is a section header. will discard it.\r | |
648 | #\r | |
f7496d71 | 649 | if not (Line.startswith(DT.TAB_SECTION_START) and Line.find(DT.TAB_SECTION_END) > -1):\r |
4234283c | 650 | SectionLines.append((Line, LineNo))\r |
f7496d71 | 651 | \r |
4234283c LG |
652 | if len(self.SectionHeaderContent) >= 1:\r |
653 | TemSectionName = self.SectionHeaderContent[0][0].upper()\r | |
654 | if TemSectionName.upper() not in gINF_SECTION_DEF.keys():\r | |
f7496d71 LG |
655 | Logger.Error("InfParser",\r |
656 | FORMAT_INVALID,\r | |
657 | ST.ERR_INF_PARSER_UNKNOWN_SECTION,\r | |
658 | File=self.FullPath,\r | |
659 | Line=LineNo,\r | |
4234283c LG |
660 | ExtraData=Line,\r |
661 | RaiseError = Logger.IS_RAISE_ERROR\r | |
f7496d71 | 662 | )\r |
4234283c LG |
663 | else:\r |
664 | CurrentSection = gINF_SECTION_DEF[TemSectionName]\r | |
665 | self.LastSectionHeaderContent = self.SectionHeaderContent\r | |
f7496d71 | 666 | \r |
4234283c LG |
667 | return SectionLines, CurrentSection\r |
668 | \r | |
669 | ## _ConvertSecNameToType\r | |
670 | #\r | |
671 | #\r | |
f7496d71 | 672 | def _ConvertSecNameToType(SectionName):\r |
4234283c LG |
673 | SectionType = ''\r |
674 | if SectionName.upper() not in gINF_SECTION_DEF.keys():\r | |
f7496d71 | 675 | SectionType = DT.MODEL_UNKNOWN\r |
4234283c | 676 | else:\r |
f7496d71 LG |
677 | SectionType = gINF_SECTION_DEF[SectionName.upper()]\r |
678 | \r | |
679 | return SectionType\r | |
680 | \r |