]>
Commit | Line | Data |
---|---|---|
4234283c | 1 | ## @file\r |
f7496d71 | 2 | # This file contained the parser for BuildOption 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 | '''\r | |
10 | InfBuildOptionSectionParser\r | |
11 | '''\r | |
12 | ##\r | |
13 | # Import Modules\r | |
14 | #\r | |
15 | from Library import DataType as DT\r | |
16 | from Library import GlobalData\r | |
17 | import Logger.Log as Logger\r | |
18 | from Logger import StringTable as ST\r | |
19 | from Logger.ToolError import FORMAT_INVALID\r | |
20 | from Parser.InfParserMisc import InfExpandMacro\r | |
21 | from Library.Misc import GetSplitValueList\r | |
22 | from Parser.InfParserMisc import IsAsBuildOptionInfo\r | |
23 | from Library.Misc import GetHelpStringByRemoveHashKey\r | |
24 | from Library.ParserValidate import IsValidFamily\r | |
25 | from Library.ParserValidate import IsValidBuildOptionName\r | |
26 | from Parser.InfParserMisc import InfParserSectionRoot\r | |
27 | \r | |
28 | class InfBuildOptionSectionParser(InfParserSectionRoot):\r | |
29 | ## InfBuildOptionParser\r | |
30 | #\r | |
31 | #\r | |
32 | def InfBuildOptionParser(self, SectionString, InfSectionObject, FileName):\r | |
f7496d71 | 33 | \r |
4234283c LG |
34 | BuildOptionList = []\r |
35 | SectionContent = ''\r | |
f7496d71 | 36 | \r |
4234283c LG |
37 | if not GlobalData.gIS_BINARY_INF:\r |
38 | ValueList = []\r | |
39 | LineNo = 0\r | |
40 | \r | |
41 | for Line in SectionString:\r | |
42 | LineContent = Line[0]\r | |
43 | LineNo = Line[1]\r | |
44 | TailComments = ''\r | |
45 | ReplaceFlag = False\r | |
f7496d71 | 46 | \r |
4234283c | 47 | if LineContent.strip() == '':\r |
f7496d71 LG |
48 | SectionContent += LineContent + DT.END_OF_LINE\r |
49 | continue\r | |
4234283c LG |
50 | #\r |
51 | # Found Comment\r | |
52 | #\r | |
53 | if LineContent.strip().startswith(DT.TAB_COMMENT_SPLIT):\r | |
f7496d71 | 54 | SectionContent += LineContent + DT.END_OF_LINE\r |
4234283c | 55 | continue\r |
f7496d71 | 56 | \r |
4234283c LG |
57 | #\r |
58 | # Find Tail comment.\r | |
59 | #\r | |
60 | if LineContent.find(DT.TAB_COMMENT_SPLIT) > -1:\r | |
61 | TailComments = LineContent[LineContent.find(DT.TAB_COMMENT_SPLIT):]\r | |
f7496d71 LG |
62 | LineContent = LineContent[:LineContent.find(DT.TAB_COMMENT_SPLIT)]\r |
63 | \r | |
4234283c LG |
64 | TokenList = GetSplitValueList(LineContent, DT.TAB_DEQUAL_SPLIT, 1)\r |
65 | if len(TokenList) == 2:\r | |
66 | #\r | |
67 | # "Replace" type build option\r | |
68 | #\r | |
69 | TokenList.append('True')\r | |
70 | ReplaceFlag = True\r | |
71 | else:\r | |
72 | TokenList = GetSplitValueList(LineContent, DT.TAB_EQUAL_SPLIT, 1)\r | |
73 | #\r | |
74 | # "Append" type build option\r | |
75 | #\r | |
76 | if len(TokenList) == 2:\r | |
77 | TokenList.append('False')\r | |
78 | else:\r | |
f7496d71 | 79 | Logger.Error('InfParser',\r |
4234283c LG |
80 | FORMAT_INVALID,\r |
81 | ST.ERR_INF_PARSER_BUILD_OPTION_FORMAT_INVALID,\r | |
f7496d71 | 82 | ExtraData=LineContent,\r |
4234283c | 83 | File=FileName,\r |
f7496d71 LG |
84 | Line=LineNo)\r |
85 | \r | |
4234283c | 86 | ValueList[0:len(TokenList)] = TokenList\r |
f7496d71 | 87 | \r |
4234283c LG |
88 | #\r |
89 | # Replace with [Defines] section Macro\r | |
90 | #\r | |
f7496d71 | 91 | ValueList[0] = InfExpandMacro(ValueList[0], (FileName, LineContent, LineNo),\r |
4234283c | 92 | self.FileLocalMacros, None)\r |
f7496d71 | 93 | ValueList[1] = InfExpandMacro(ValueList[1], (FileName, LineContent, LineNo),\r |
4234283c LG |
94 | self.FileLocalMacros, None, True)\r |
95 | EqualString = ''\r | |
96 | if not ReplaceFlag:\r | |
97 | EqualString = ' = '\r | |
98 | else:\r | |
99 | EqualString = ' == '\r | |
100 | \r | |
101 | SectionContent += ValueList[0] + EqualString + ValueList[1] + TailComments + DT.END_OF_LINE\r | |
102 | \r | |
103 | Family = GetSplitValueList(ValueList[0], DT.TAB_COLON_SPLIT, 1)\r | |
104 | if len(Family) == 2:\r | |
f7496d71 LG |
105 | if not IsValidFamily(Family[0]):\r |
106 | Logger.Error('InfParser',\r | |
4234283c LG |
107 | FORMAT_INVALID,\r |
108 | ST.ERR_INF_PARSER_BUILD_OPTION_FORMAT_INVALID,\r | |
f7496d71 | 109 | ExtraData=LineContent,\r |
4234283c LG |
110 | File=FileName,\r |
111 | Line=LineNo)\r | |
112 | if not IsValidBuildOptionName(Family[1]):\r | |
f7496d71 | 113 | Logger.Error('InfParser',\r |
4234283c LG |
114 | FORMAT_INVALID,\r |
115 | ST.ERR_INF_PARSER_BUILD_OPTION_FORMAT_INVALID,\r | |
f7496d71 | 116 | ExtraData=LineContent,\r |
4234283c LG |
117 | File=FileName,\r |
118 | Line=LineNo)\r | |
119 | if len(Family) == 1:\r | |
120 | if not IsValidBuildOptionName(Family[0]):\r | |
f7496d71 | 121 | Logger.Error('InfParser',\r |
4234283c LG |
122 | FORMAT_INVALID,\r |
123 | ST.ERR_INF_PARSER_BUILD_OPTION_FORMAT_INVALID,\r | |
f7496d71 | 124 | ExtraData=LineContent,\r |
4234283c LG |
125 | File=FileName,\r |
126 | Line=LineNo)\r | |
f7496d71 LG |
127 | \r |
128 | BuildOptionList.append(ValueList)\r | |
4234283c LG |
129 | ValueList = []\r |
130 | continue\r | |
131 | else:\r | |
132 | BuildOptionList = InfAsBuiltBuildOptionParser(SectionString, FileName)\r | |
133 | \r | |
134 | #\r | |
135 | # Current section archs\r | |
136 | #\r | |
137 | ArchList = []\r | |
138 | LastItem = ''\r | |
139 | for Item in self.LastSectionHeaderContent:\r | |
140 | LastItem = Item\r | |
141 | if not (Item[1] == '' or Item[1] == '') and Item[1] not in ArchList:\r | |
142 | ArchList.append(Item[1])\r | |
143 | InfSectionObject.SetSupArchList(Item[1])\r | |
f7496d71 | 144 | \r |
4234283c LG |
145 | InfSectionObject.SetAllContent(SectionContent)\r |
146 | if not InfSectionObject.SetBuildOptions(BuildOptionList, ArchList, SectionContent):\r | |
f7496d71 | 147 | Logger.Error('InfParser',\r |
4234283c LG |
148 | FORMAT_INVALID,\r |
149 | ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR%("[BuilOptions]"),\r | |
150 | File=FileName,\r | |
f7496d71 | 151 | Line=LastItem[3])\r |
4234283c LG |
152 | \r |
153 | ## InfBuildOptionParser\r | |
154 | #\r | |
155 | #\r | |
156 | def InfAsBuiltBuildOptionParser(SectionString, FileName):\r | |
f7496d71 | 157 | BuildOptionList = []\r |
4234283c LG |
158 | #\r |
159 | # AsBuild Binary INF file.\r | |
160 | #\r | |
161 | AsBuildOptionFlag = False\r | |
162 | BuildOptionItem = []\r | |
163 | Count = 0\r | |
164 | for Line in SectionString:\r | |
165 | Count += 1\r | |
166 | LineContent = Line[0]\r | |
167 | LineNo = Line[1]\r | |
f7496d71 | 168 | \r |
4234283c LG |
169 | #\r |
170 | # The last line\r | |
171 | #\r | |
172 | if len(SectionString) == Count:\r | |
173 | if LineContent.strip().startswith("##") and AsBuildOptionFlag:\r | |
174 | BuildOptionList.append(BuildOptionItem)\r | |
175 | BuildOptionList.append([GetHelpStringByRemoveHashKey(LineContent)])\r | |
176 | elif LineContent.strip().startswith("#") and AsBuildOptionFlag:\r | |
177 | BuildOptionInfo = GetHelpStringByRemoveHashKey(LineContent)\r | |
178 | BuildOptionItem.append(BuildOptionInfo)\r | |
179 | BuildOptionList.append(BuildOptionItem)\r | |
180 | else:\r | |
181 | if len(BuildOptionItem) > 0:\r | |
182 | BuildOptionList.append(BuildOptionItem)\r | |
f7496d71 LG |
183 | \r |
184 | break\r | |
185 | \r | |
4234283c LG |
186 | if LineContent.strip() == '':\r |
187 | AsBuildOptionFlag = False\r | |
188 | continue\r | |
f7496d71 | 189 | \r |
4234283c LG |
190 | if LineContent.strip().startswith("##") and AsBuildOptionFlag:\r |
191 | if len(BuildOptionItem) > 0:\r | |
f7496d71 LG |
192 | BuildOptionList.append(BuildOptionItem)\r |
193 | \r | |
4234283c | 194 | BuildOptionItem = []\r |
f7496d71 | 195 | \r |
4234283c | 196 | if not LineContent.strip().startswith("#"):\r |
f7496d71 | 197 | Logger.Error('InfParser',\r |
4234283c | 198 | FORMAT_INVALID,\r |
f7496d71 LG |
199 | ST.ERR_BO_CONTATIN_ASBUILD_AND_COMMON,\r |
200 | File=FileName,\r | |
201 | Line=LineNo,\r | |
4234283c | 202 | ExtraData=LineContent)\r |
f7496d71 | 203 | \r |
4234283c LG |
204 | if IsAsBuildOptionInfo(LineContent):\r |
205 | AsBuildOptionFlag = True\r | |
206 | continue\r | |
f7496d71 | 207 | \r |
4234283c LG |
208 | if AsBuildOptionFlag:\r |
209 | BuildOptionInfo = GetHelpStringByRemoveHashKey(LineContent)\r | |
210 | BuildOptionItem.append(BuildOptionInfo)\r | |
f7496d71 LG |
211 | \r |
212 | return BuildOptionList\r |