]>
Commit | Line | Data |
---|---|---|
4234283c | 1 | ## @file\r |
f7496d71 | 2 | # This file contained the parser for [Packages] sections in INF file\r |
4234283c | 3 | #\r |
f7496d71 | 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 | InfPackageSectionParser\r | |
10 | '''\r | |
11 | ##\r | |
12 | # Import Modules\r | |
13 | #\r | |
14 | \r | |
15 | import Logger.Log as Logger\r | |
16 | from Logger import StringTable as ST\r | |
17 | from Logger.ToolError import FORMAT_INVALID\r | |
18 | from Parser.InfParserMisc import InfExpandMacro\r | |
19 | from Library import DataType as DT\r | |
20 | from Library.Parsing import MacroParser\r | |
21 | from Library.Misc import GetSplitValueList\r | |
22 | from Object.Parser.InfCommonObject import InfLineCommentObject\r | |
23 | from Parser.InfParserMisc import InfParserSectionRoot\r | |
24 | \r | |
25 | class InfPackageSectionParser(InfParserSectionRoot):\r | |
26 | ## InfPackageParser\r | |
27 | #\r | |
f7496d71 | 28 | #\r |
4234283c LG |
29 | def InfPackageParser(self, SectionString, InfSectionObject, FileName):\r |
30 | #\r | |
f7496d71 | 31 | # Macro defined in this section\r |
4234283c LG |
32 | #\r |
33 | SectionMacros = {}\r | |
34 | ValueList = []\r | |
35 | PackageList = []\r | |
36 | StillCommentFalg = False\r | |
37 | HeaderComments = []\r | |
f7496d71 | 38 | LineComment = None\r |
4234283c LG |
39 | #\r |
40 | # Parse section content\r | |
41 | #\r | |
42 | for Line in SectionString:\r | |
43 | PkgLineContent = Line[0]\r | |
f7496d71 LG |
44 | PkgLineNo = Line[1]\r |
45 | \r | |
4234283c LG |
46 | if PkgLineContent.strip() == '':\r |
47 | continue\r | |
f7496d71 | 48 | \r |
4234283c | 49 | #\r |
f7496d71 | 50 | # Find Header Comments\r |
4234283c LG |
51 | #\r |
52 | if PkgLineContent.strip().startswith(DT.TAB_COMMENT_SPLIT):\r | |
53 | #\r | |
54 | # Last line is comments, and this line go on.\r | |
55 | #\r | |
56 | if StillCommentFalg:\r | |
57 | HeaderComments.append(Line)\r | |
58 | continue\r | |
59 | #\r | |
f7496d71 | 60 | # First time encounter comment\r |
4234283c LG |
61 | #\r |
62 | else:\r | |
63 | #\r | |
64 | # Clear original data\r | |
65 | #\r | |
66 | HeaderComments = []\r | |
67 | HeaderComments.append(Line)\r | |
68 | StillCommentFalg = True\r | |
69 | continue\r | |
70 | else:\r | |
71 | StillCommentFalg = False\r | |
f7496d71 | 72 | \r |
4234283c LG |
73 | if len(HeaderComments) >= 1:\r |
74 | LineComment = InfLineCommentObject()\r | |
75 | LineCommentContent = ''\r | |
76 | for Item in HeaderComments:\r | |
77 | LineCommentContent += Item[0] + DT.END_OF_LINE\r | |
78 | LineComment.SetHeaderComments(LineCommentContent)\r | |
f7496d71 | 79 | \r |
4234283c LG |
80 | #\r |
81 | # Find Tail comment.\r | |
82 | #\r | |
83 | if PkgLineContent.find(DT.TAB_COMMENT_SPLIT) > -1:\r | |
84 | TailComments = PkgLineContent[PkgLineContent.find(DT.TAB_COMMENT_SPLIT):]\r | |
85 | PkgLineContent = PkgLineContent[:PkgLineContent.find(DT.TAB_COMMENT_SPLIT)]\r | |
4231a819 | 86 | if LineComment is None:\r |
4234283c | 87 | LineComment = InfLineCommentObject()\r |
f7496d71 | 88 | LineComment.SetTailComments(TailComments)\r |
4234283c LG |
89 | #\r |
90 | # Find Macro\r | |
91 | #\r | |
92 | Name, Value = MacroParser((PkgLineContent, PkgLineNo),\r | |
93 | FileName,\r | |
94 | DT.MODEL_META_DATA_PACKAGE,\r | |
95 | self.FileLocalMacros)\r | |
4231a819 | 96 | if Name is not None:\r |
4234283c LG |
97 | SectionMacros[Name] = Value\r |
98 | LineComment = None\r | |
f7496d71 | 99 | HeaderComments = []\r |
4234283c LG |
100 | continue\r |
101 | \r | |
102 | TokenList = GetSplitValueList(PkgLineContent, DT.TAB_VALUE_SPLIT, 1)\r | |
103 | ValueList[0:len(TokenList)] = TokenList\r | |
f7496d71 | 104 | \r |
4234283c LG |
105 | #\r |
106 | # Replace with Local section Macro and [Defines] section Macro.\r | |
f7496d71 LG |
107 | #\r |
108 | ValueList = [InfExpandMacro(Value, (FileName, PkgLineContent, PkgLineNo),\r | |
4234283c LG |
109 | self.FileLocalMacros, SectionMacros, True)\r |
110 | for Value in ValueList]\r | |
f7496d71 LG |
111 | \r |
112 | PackageList.append((ValueList, LineComment,\r | |
4234283c LG |
113 | (PkgLineContent, PkgLineNo, FileName)))\r |
114 | ValueList = []\r | |
115 | LineComment = None\r | |
116 | TailComments = ''\r | |
f7496d71 | 117 | HeaderComments = []\r |
4234283c LG |
118 | continue\r |
119 | \r | |
120 | #\r | |
121 | # Current section archs\r | |
f7496d71 | 122 | #\r |
4234283c LG |
123 | ArchList = []\r |
124 | for Item in self.LastSectionHeaderContent:\r | |
125 | if Item[1] not in ArchList:\r | |
f7496d71 LG |
126 | ArchList.append(Item[1])\r |
127 | \r | |
4234283c | 128 | if not InfSectionObject.SetPackages(PackageList, Arch = ArchList):\r |
f7496d71 LG |
129 | Logger.Error('InfParser',\r |
130 | FORMAT_INVALID,\r | |
4234283c LG |
131 | ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR\\r |
132 | %("[Packages]"),\r | |
133 | File=FileName,\r | |
f7496d71 | 134 | Line=Item[3])\r |