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