]>
Commit | Line | Data |
---|---|---|
4234283c | 1 | ## @file\r |
f7496d71 LG |
2 | # This file is used to define class objects of INF file [Binaries] section.\r |
3 | # It will consumed by InfParser.\r | |
4234283c | 4 | #\r |
f7496d71 | 5 | # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>\r |
4234283c | 6 | #\r |
2e351cbe | 7 | # SPDX-License-Identifier: BSD-2-Clause-Patent\r |
4234283c LG |
8 | \r |
9 | '''\r | |
10 | InfBinaryObject\r | |
11 | '''\r | |
12 | \r | |
13 | import os\r | |
14 | \r | |
15 | from copy import deepcopy\r | |
16 | from Library import DataType as DT\r | |
17 | from Library import GlobalData\r | |
18 | import Logger.Log as Logger\r | |
19 | from Logger import ToolError\r | |
20 | from Logger import StringTable as ST\r | |
21 | from Library.Misc import Sdict\r | |
22 | \r | |
23 | from Object.Parser.InfCommonObject import InfSectionCommonDef\r | |
24 | from Object.Parser.InfCommonObject import CurrentLine\r | |
25 | from Library.Misc import ConvPathFromAbsToRel\r | |
26 | from Library.ExpressionValidate import IsValidFeatureFlagExp\r | |
27 | from Library.Misc import ValidFile\r | |
28 | from Library.ParserValidate import IsValidPath\r | |
29 | \r | |
30 | \r | |
31 | class InfBianryItem():\r | |
32 | def __init__(self):\r | |
33 | self.FileName = ''\r | |
34 | self.Target = ''\r | |
35 | self.FeatureFlagExp = ''\r | |
36 | self.HelpString = ''\r | |
37 | self.Type = ''\r | |
38 | self.SupArchList = []\r | |
39 | \r | |
40 | def SetFileName(self, FileName):\r | |
41 | self.FileName = FileName\r | |
42 | def GetFileName(self):\r | |
43 | return self.FileName\r | |
44 | \r | |
45 | def SetTarget(self, Target):\r | |
46 | self.Target = Target\r | |
47 | def GetTarget(self):\r | |
48 | return self.Target\r | |
49 | \r | |
50 | def SetFeatureFlagExp(self, FeatureFlagExp):\r | |
51 | self.FeatureFlagExp = FeatureFlagExp\r | |
52 | def GetFeatureFlagExp(self):\r | |
53 | return self.FeatureFlagExp\r | |
54 | \r | |
55 | def SetHelpString(self, HelpString):\r | |
56 | self.HelpString = HelpString\r | |
57 | def GetHelpString(self):\r | |
58 | return self.HelpString\r | |
59 | \r | |
60 | def SetType(self, Type):\r | |
61 | self.Type = Type\r | |
62 | def GetType(self):\r | |
63 | return self.Type\r | |
64 | def SetSupArchList(self, SupArchList):\r | |
65 | self.SupArchList = SupArchList\r | |
66 | def GetSupArchList(self):\r | |
67 | return self.SupArchList\r | |
68 | \r | |
69 | class InfBianryVerItem(InfBianryItem, CurrentLine):\r | |
70 | def __init__(self):\r | |
71 | InfBianryItem.__init__(self)\r | |
72 | CurrentLine.__init__(self)\r | |
73 | self.VerTypeName = ''\r | |
74 | \r | |
75 | def SetVerTypeName(self, VerTypeName):\r | |
76 | self.VerTypeName = VerTypeName\r | |
77 | def GetVerTypeName(self):\r | |
78 | return self.VerTypeName\r | |
79 | \r | |
80 | class InfBianryUiItem(InfBianryItem, CurrentLine):\r | |
81 | def __init__(self):\r | |
82 | InfBianryItem.__init__(self)\r | |
83 | CurrentLine.__init__(self)\r | |
84 | self.UiTypeName = ''\r | |
85 | \r | |
86 | def SetUiTypeName(self, UiTypeName):\r | |
87 | self.UiTypeName = UiTypeName\r | |
88 | def GetVerTypeName(self):\r | |
89 | return self.UiTypeName\r | |
90 | \r | |
91 | class InfBianryCommonItem(InfBianryItem, CurrentLine):\r | |
92 | def __init__(self):\r | |
93 | self.CommonType = ''\r | |
94 | self.TagName = ''\r | |
95 | self.Family = ''\r | |
421ccda3 | 96 | self.GuidValue = ''\r |
4234283c LG |
97 | InfBianryItem.__init__(self)\r |
98 | CurrentLine.__init__(self)\r | |
99 | \r | |
100 | def SetCommonType(self, CommonType):\r | |
101 | self.CommonType = CommonType\r | |
102 | def GetCommonType(self):\r | |
103 | return self.CommonType\r | |
104 | \r | |
105 | def SetTagName(self, TagName):\r | |
106 | self.TagName = TagName\r | |
107 | def GetTagName(self):\r | |
108 | return self.TagName\r | |
109 | \r | |
110 | def SetFamily(self, Family):\r | |
111 | self.Family = Family\r | |
112 | def GetFamily(self):\r | |
113 | return self.Family\r | |
f7496d71 | 114 | \r |
421ccda3 HC |
115 | def SetGuidValue(self, GuidValue):\r |
116 | self.GuidValue = GuidValue\r | |
117 | def GetGuidValue(self):\r | |
118 | return self.GuidValue\r | |
4234283c LG |
119 | \r |
120 | ##\r | |
121 | #\r | |
122 | #\r | |
123 | #\r | |
124 | class InfBinariesObject(InfSectionCommonDef):\r | |
125 | def __init__(self):\r | |
126 | self.Binaries = Sdict()\r | |
127 | #\r | |
128 | # Macro defined in this section should be only used in this section.\r | |
129 | #\r | |
130 | self.Macros = {}\r | |
131 | InfSectionCommonDef.__init__(self)\r | |
132 | \r | |
133 | ## CheckVer\r | |
134 | #\r | |
135 | #\r | |
136 | def CheckVer(self, Ver, __SupArchList):\r | |
137 | #\r | |
138 | # Check Ver\r | |
139 | #\r | |
140 | for VerItem in Ver:\r | |
141 | IsValidFileFlag = False\r | |
142 | VerContent = VerItem[0]\r | |
143 | VerComment = VerItem[1]\r | |
144 | VerCurrentLine = VerItem[2]\r | |
145 | GlobalData.gINF_CURRENT_LINE = VerCurrentLine\r | |
146 | InfBianryVerItemObj = None\r | |
147 | #\r | |
148 | # Should not less than 2 elements\r | |
149 | #\r | |
150 | if len(VerContent) < 2:\r | |
151 | Logger.Error("InfParser",\r | |
152 | ToolError.FORMAT_INVALID,\r | |
421ccda3 | 153 | ST.ERR_INF_PARSER_BINARY_ITEM_FORMAT_INVALID % (VerContent[0], 2),\r |
4234283c LG |
154 | File=VerCurrentLine.GetFileName(),\r |
155 | Line=VerCurrentLine.GetLineNo(),\r | |
156 | ExtraData=VerCurrentLine.GetLineString())\r | |
157 | return False\r | |
158 | if len(VerContent) > 4:\r | |
159 | Logger.Error("InfParser",\r | |
160 | ToolError.FORMAT_INVALID,\r | |
161 | ST.ERR_INF_PARSER_BINARY_ITEM_FORMAT_INVALID_MAX % (VerContent[0], 4),\r | |
162 | File=VerCurrentLine.GetFileName(),\r | |
163 | Line=VerCurrentLine.GetLineNo(),\r | |
164 | ExtraData=VerCurrentLine.GetLineString())\r | |
165 | return False\r | |
166 | if len(VerContent) >= 2:\r | |
167 | #\r | |
168 | # Create a Ver Object.\r | |
169 | #\r | |
170 | InfBianryVerItemObj = InfBianryVerItem()\r | |
171 | \r | |
172 | if VerContent[0] != DT.BINARY_FILE_TYPE_VER:\r | |
173 | Logger.Error("InfParser",\r | |
174 | ToolError.FORMAT_INVALID,\r | |
175 | ST.ERR_INF_PARSER_BINARY_VER_TYPE % DT.BINARY_FILE_TYPE_VER,\r | |
176 | File=VerCurrentLine.GetFileName(),\r | |
177 | Line=VerCurrentLine.GetLineNo(),\r | |
178 | ExtraData=VerCurrentLine.GetLineString())\r | |
179 | \r | |
180 | InfBianryVerItemObj.SetVerTypeName(VerContent[0])\r | |
181 | InfBianryVerItemObj.SetType(VerContent[0])\r | |
182 | #\r | |
183 | # Verify File exist or not\r | |
184 | #\r | |
185 | FullFileName = os.path.normpath(os.path.realpath(os.path.join(GlobalData.gINF_MODULE_DIR,\r | |
186 | VerContent[1])))\r | |
187 | if not (ValidFile(FullFileName) or ValidFile(VerContent[1])):\r | |
188 | Logger.Error("InfParser",\r | |
189 | ToolError.FORMAT_INVALID,\r | |
190 | ST.ERR_INF_PARSER_BINARY_ITEM_FILE_NOT_EXIST % (VerContent[1]),\r | |
191 | File=VerCurrentLine.GetFileName(),\r | |
192 | Line=VerCurrentLine.GetLineNo(),\r | |
193 | ExtraData=VerCurrentLine.GetLineString())\r | |
194 | #\r | |
195 | # Validate file exist/format.\r | |
196 | #\r | |
197 | if IsValidPath(VerContent[1], GlobalData.gINF_MODULE_DIR):\r | |
198 | IsValidFileFlag = True\r | |
199 | else:\r | |
200 | Logger.Error("InfParser",\r | |
201 | ToolError.FORMAT_INVALID,\r | |
202 | ST.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID % (VerContent[1]),\r | |
203 | File=VerCurrentLine.GetFileName(),\r | |
204 | Line=VerCurrentLine.GetLineNo(),\r | |
205 | ExtraData=VerCurrentLine.GetLineString())\r | |
206 | return False\r | |
207 | if IsValidFileFlag:\r | |
208 | VerContent[0] = ConvPathFromAbsToRel(VerContent[0],\r | |
209 | GlobalData.gINF_MODULE_DIR)\r | |
210 | InfBianryVerItemObj.SetFileName(VerContent[1])\r | |
211 | if len(VerContent) >= 3:\r | |
212 | #\r | |
213 | # Add Target information\r | |
214 | #\r | |
215 | InfBianryVerItemObj.SetTarget(VerContent[2])\r | |
216 | if len(VerContent) == 4:\r | |
217 | if VerContent[3].strip() == '':\r | |
218 | Logger.Error("InfParser",\r | |
219 | ToolError.FORMAT_INVALID,\r | |
220 | ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING,\r | |
221 | File=VerCurrentLine.GetFileName(),\r | |
222 | Line=VerCurrentLine.GetLineNo(),\r | |
223 | ExtraData=VerCurrentLine.GetLineString())\r | |
224 | #\r | |
f7496d71 | 225 | # Validate Feature Flag Express\r |
4234283c LG |
226 | #\r |
227 | FeatureFlagRtv = IsValidFeatureFlagExp(VerContent[3].\\r | |
228 | strip())\r | |
229 | if not FeatureFlagRtv[0]:\r | |
230 | Logger.Error("InfParser",\r | |
231 | ToolError.FORMAT_INVALID,\r | |
232 | ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID % (FeatureFlagRtv[1]),\r | |
233 | File=VerCurrentLine.GetFileName(),\r | |
234 | Line=VerCurrentLine.GetLineNo(),\r | |
235 | ExtraData=VerCurrentLine.GetLineString())\r | |
236 | InfBianryVerItemObj.SetFeatureFlagExp(VerContent[3])\r | |
237 | \r | |
238 | InfBianryVerItemObj.SetSupArchList(__SupArchList)\r | |
239 | \r | |
240 | #\r | |
241 | # Determine binary file name duplicate. Follow below rule:\r | |
242 | #\r | |
f7496d71 LG |
243 | # A binary filename must not be duplicated within\r |
244 | # a [Binaries] section. A binary filename may appear in\r | |
245 | # multiple architectural [Binaries] sections. A binary\r | |
246 | # filename listed in an architectural [Binaries] section\r | |
247 | # must not be listed in the common architectural\r | |
4234283c | 248 | # [Binaries] section.\r |
f7496d71 | 249 | #\r |
4234283c | 250 | # NOTE: This check will not report error now.\r |
f7496d71 | 251 | #\r |
4234283c LG |
252 | for Item in self.Binaries:\r |
253 | if Item.GetFileName() == InfBianryVerItemObj.GetFileName():\r | |
254 | ItemSupArchList = Item.GetSupArchList()\r | |
255 | for ItemArch in ItemSupArchList:\r | |
256 | for VerItemObjArch in __SupArchList:\r | |
257 | if ItemArch == VerItemObjArch:\r | |
258 | #\r | |
259 | # ST.ERR_INF_PARSER_ITEM_DUPLICATE\r | |
260 | #\r | |
261 | pass\r | |
262 | if ItemArch.upper() == 'COMMON' or VerItemObjArch.upper() == 'COMMON':\r | |
263 | #\r | |
264 | # ERR_INF_PARSER_ITEM_DUPLICATE_COMMON\r | |
265 | #\r | |
266 | pass\r | |
267 | \r | |
4231a819 | 268 | if InfBianryVerItemObj is not None:\r |
27c4ceb4 | 269 | if (InfBianryVerItemObj) in self.Binaries:\r |
4234283c LG |
270 | BinariesList = self.Binaries[InfBianryVerItemObj]\r |
271 | BinariesList.append((InfBianryVerItemObj, VerComment))\r | |
272 | self.Binaries[InfBianryVerItemObj] = BinariesList\r | |
273 | else:\r | |
274 | BinariesList = []\r | |
275 | BinariesList.append((InfBianryVerItemObj, VerComment))\r | |
276 | self.Binaries[InfBianryVerItemObj] = BinariesList\r | |
277 | \r | |
278 | ## ParseCommonBinary\r | |
279 | #\r | |
280 | # ParseCommonBinary\r | |
281 | #\r | |
282 | def ParseCommonBinary(self, CommonBinary, __SupArchList):\r | |
283 | #\r | |
284 | # Check common binary definitions\r | |
285 | # Type | FileName | Target | Family | TagName | FeatureFlagExp\r | |
286 | #\r | |
287 | for Item in CommonBinary:\r | |
288 | IsValidFileFlag = False\r | |
289 | ItemContent = Item[0]\r | |
290 | ItemComment = Item[1]\r | |
291 | CurrentLineOfItem = Item[2]\r | |
292 | GlobalData.gINF_CURRENT_LINE = CurrentLineOfItem\r | |
293 | InfBianryCommonItemObj = None\r | |
421ccda3 HC |
294 | if ItemContent[0] == 'SUBTYPE_GUID':\r |
295 | if len(ItemContent) < 3:\r | |
296 | Logger.Error("InfParser",\r | |
297 | ToolError.FORMAT_INVALID,\r | |
298 | ST.ERR_INF_PARSER_BINARY_ITEM_FORMAT_INVALID % (ItemContent[0], 3),\r | |
299 | File=CurrentLineOfItem.GetFileName(),\r | |
300 | Line=CurrentLineOfItem.GetLineNo(),\r | |
301 | ExtraData=CurrentLineOfItem.GetLineString())\r | |
302 | return False\r | |
303 | else:\r | |
304 | if len(ItemContent) < 2:\r | |
305 | Logger.Error("InfParser",\r | |
306 | ToolError.FORMAT_INVALID,\r | |
307 | ST.ERR_INF_PARSER_BINARY_ITEM_FORMAT_INVALID % (ItemContent[0], 2),\r | |
308 | File=CurrentLineOfItem.GetFileName(),\r | |
309 | Line=CurrentLineOfItem.GetLineNo(),\r | |
310 | ExtraData=CurrentLineOfItem.GetLineString())\r | |
311 | return False\r | |
f7496d71 | 312 | \r |
421ccda3 | 313 | if len(ItemContent) > 7:\r |
4234283c LG |
314 | Logger.Error("InfParser",\r |
315 | ToolError.FORMAT_INVALID,\r | |
421ccda3 | 316 | ST.ERR_INF_PARSER_BINARY_ITEM_FORMAT_INVALID_MAX % (ItemContent[0], 7),\r |
4234283c LG |
317 | File=CurrentLineOfItem.GetFileName(),\r |
318 | Line=CurrentLineOfItem.GetLineNo(),\r | |
319 | ExtraData=CurrentLineOfItem.GetLineString())\r | |
320 | return False\r | |
321 | if len(ItemContent) >= 2:\r | |
322 | #\r | |
323 | # Create a Common Object.\r | |
324 | #\r | |
325 | InfBianryCommonItemObj = InfBianryCommonItem()\r | |
326 | #\r | |
327 | # Convert Binary type.\r | |
328 | #\r | |
329 | BinaryFileType = ItemContent[0].strip()\r | |
330 | if BinaryFileType == 'RAW' or BinaryFileType == 'ACPI' or BinaryFileType == 'ASL':\r | |
331 | BinaryFileType = 'BIN'\r | |
f7496d71 | 332 | \r |
4234283c LG |
333 | if BinaryFileType not in DT.BINARY_FILE_TYPE_LIST:\r |
334 | Logger.Error("InfParser",\r | |
335 | ToolError.FORMAT_INVALID,\r | |
336 | ST.ERR_INF_PARSER_BINARY_ITEM_INVALID_FILETYPE % \\r | |
337 | (DT.BINARY_FILE_TYPE_LIST.__str__()),\r | |
338 | File=CurrentLineOfItem.GetFileName(),\r | |
339 | Line=CurrentLineOfItem.GetLineNo(),\r | |
340 | ExtraData=CurrentLineOfItem.GetLineString())\r | |
f7496d71 | 341 | \r |
4234283c LG |
342 | if BinaryFileType == 'SUBTYPE_GUID':\r |
343 | BinaryFileType = 'FREEFORM'\r | |
f7496d71 | 344 | \r |
4234283c LG |
345 | if BinaryFileType == 'LIB' or BinaryFileType == 'UEFI_APP':\r |
346 | Logger.Error("InfParser",\r | |
347 | ToolError.FORMAT_INVALID,\r | |
348 | ST.ERR_INF_PARSER_BINARY_ITEM_INVALID_FILETYPE % \\r | |
349 | (DT.BINARY_FILE_TYPE_LIST.__str__()),\r | |
350 | File=CurrentLineOfItem.GetFileName(),\r | |
351 | Line=CurrentLineOfItem.GetLineNo(),\r | |
352 | ExtraData=CurrentLineOfItem.GetLineString())\r | |
353 | \r | |
354 | InfBianryCommonItemObj.SetType(BinaryFileType)\r | |
355 | InfBianryCommonItemObj.SetCommonType(ItemContent[0])\r | |
421ccda3 HC |
356 | FileName = ''\r |
357 | if BinaryFileType == 'FREEFORM':\r | |
358 | InfBianryCommonItemObj.SetGuidValue(ItemContent[1])\r | |
359 | if len(ItemContent) >= 3:\r | |
360 | FileName = ItemContent[2]\r | |
361 | else:\r | |
362 | Logger.Error("InfParser",\r | |
363 | ToolError.FORMAT_INVALID,\r | |
364 | ST.ERR_INF_PARSER_BINARY_ITEM_FILENAME_NOT_EXIST,\r | |
365 | File=CurrentLineOfItem.GetFileName(),\r | |
366 | Line=CurrentLineOfItem.GetLineNo(),\r | |
367 | ExtraData=CurrentLineOfItem.GetLineString())\r | |
368 | else:\r | |
369 | FileName = ItemContent[1]\r | |
4234283c LG |
370 | #\r |
371 | # Verify File exist or not\r | |
372 | #\r | |
373 | FullFileName = os.path.normpath(os.path.realpath(os.path.join(GlobalData.gINF_MODULE_DIR,\r | |
421ccda3 HC |
374 | FileName)))\r |
375 | if not (ValidFile(FullFileName) or ValidFile(FileName)):\r | |
4234283c LG |
376 | Logger.Error("InfParser",\r |
377 | ToolError.FORMAT_INVALID,\r | |
421ccda3 | 378 | ST.ERR_INF_PARSER_BINARY_ITEM_FILE_NOT_EXIST % (FileName),\r |
4234283c LG |
379 | File=CurrentLineOfItem.GetFileName(),\r |
380 | Line=CurrentLineOfItem.GetLineNo(),\r | |
381 | ExtraData=CurrentLineOfItem.GetLineString())\r | |
382 | #\r | |
383 | # Validate file exist/format.\r | |
384 | #\r | |
421ccda3 | 385 | if IsValidPath(FileName, GlobalData.gINF_MODULE_DIR):\r |
4234283c LG |
386 | IsValidFileFlag = True\r |
387 | else:\r | |
388 | Logger.Error("InfParser",\r | |
389 | ToolError.FORMAT_INVALID,\r | |
421ccda3 | 390 | ST.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID % (FileName),\r |
4234283c LG |
391 | File=CurrentLineOfItem.GetFileName(),\r |
392 | Line=CurrentLineOfItem.GetLineNo(),\r | |
393 | ExtraData=CurrentLineOfItem.GetLineString())\r | |
394 | return False\r | |
395 | if IsValidFileFlag:\r | |
396 | ItemContent[0] = ConvPathFromAbsToRel(ItemContent[0], GlobalData.gINF_MODULE_DIR)\r | |
421ccda3 | 397 | InfBianryCommonItemObj.SetFileName(FileName)\r |
4234283c LG |
398 | if len(ItemContent) >= 3:\r |
399 | #\r | |
400 | # Add Target information\r | |
401 | #\r | |
421ccda3 HC |
402 | if BinaryFileType != 'FREEFORM':\r |
403 | InfBianryCommonItemObj.SetTarget(ItemContent[2])\r | |
f7496d71 | 404 | \r |
4234283c LG |
405 | if len(ItemContent) >= 4:\r |
406 | #\r | |
407 | # Add Family information\r | |
408 | #\r | |
421ccda3 HC |
409 | if BinaryFileType != 'FREEFORM':\r |
410 | InfBianryCommonItemObj.SetFamily(ItemContent[3])\r | |
411 | else:\r | |
412 | InfBianryCommonItemObj.SetTarget(ItemContent[3])\r | |
f7496d71 | 413 | \r |
4234283c LG |
414 | if len(ItemContent) >= 5:\r |
415 | #\r | |
f7496d71 LG |
416 | # TagName entries are build system specific. If there\r |
417 | # is content in the entry, the tool must exit\r | |
4234283c | 418 | # gracefully with an error message that indicates build\r |
f7496d71 | 419 | # system specific content cannot be distributed using\r |
4234283c LG |
420 | # the UDP\r |
421 | #\r | |
421ccda3 HC |
422 | if BinaryFileType != 'FREEFORM':\r |
423 | if ItemContent[4].strip() != '':\r | |
424 | Logger.Error("InfParser",\r | |
425 | ToolError.FORMAT_INVALID,\r | |
426 | ST.ERR_INF_PARSER_TAGNAME_NOT_PERMITTED % (ItemContent[4]),\r | |
427 | File=CurrentLineOfItem.GetFileName(),\r | |
428 | Line=CurrentLineOfItem.GetLineNo(),\r | |
429 | ExtraData=CurrentLineOfItem.GetLineString())\r | |
430 | else:\r | |
431 | InfBianryCommonItemObj.SetFamily(ItemContent[4])\r | |
f7496d71 | 432 | \r |
421ccda3 | 433 | if len(ItemContent) >= 6:\r |
4234283c LG |
434 | #\r |
435 | # Add FeatureFlagExp\r | |
436 | #\r | |
421ccda3 HC |
437 | if BinaryFileType != 'FREEFORM':\r |
438 | if ItemContent[5].strip() == '':\r | |
439 | Logger.Error("InfParser",\r | |
440 | ToolError.FORMAT_INVALID,\r | |
441 | ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING,\r | |
442 | File=CurrentLineOfItem.GetFileName(),\r | |
443 | Line=CurrentLineOfItem.GetLineNo(),\r | |
444 | ExtraData=CurrentLineOfItem.GetLineString())\r | |
445 | #\r | |
f7496d71 | 446 | # Validate Feature Flag Express\r |
421ccda3 HC |
447 | #\r |
448 | FeatureFlagRtv = IsValidFeatureFlagExp(ItemContent[5].strip())\r | |
449 | if not FeatureFlagRtv[0]:\r | |
450 | Logger.Error("InfParser",\r | |
451 | ToolError.FORMAT_INVALID,\r | |
452 | ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID % (FeatureFlagRtv[1]),\r | |
453 | File=CurrentLineOfItem.GetFileName(),\r | |
454 | Line=CurrentLineOfItem.GetLineNo(),\r | |
455 | ExtraData=CurrentLineOfItem.GetLineString())\r | |
456 | InfBianryCommonItemObj.SetFeatureFlagExp(ItemContent[5])\r | |
457 | else:\r | |
458 | if ItemContent[5].strip() != '':\r | |
459 | Logger.Error("InfParser",\r | |
460 | ToolError.FORMAT_INVALID,\r | |
461 | ST.ERR_INF_PARSER_TAGNAME_NOT_PERMITTED % (ItemContent[5]),\r | |
462 | File=CurrentLineOfItem.GetFileName(),\r | |
463 | Line=CurrentLineOfItem.GetLineNo(),\r | |
464 | ExtraData=CurrentLineOfItem.GetLineString())\r | |
f7496d71 | 465 | \r |
421ccda3 HC |
466 | if len(ItemContent) == 7:\r |
467 | if ItemContent[6].strip() == '':\r | |
4234283c | 468 | Logger.Error("InfParser",\r |
421ccda3 HC |
469 | ToolError.FORMAT_INVALID,\r |
470 | ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING,\r | |
471 | File=CurrentLineOfItem.GetFileName(),\r | |
472 | Line=CurrentLineOfItem.GetLineNo(),\r | |
473 | ExtraData=CurrentLineOfItem.GetLineString())\r | |
4234283c | 474 | #\r |
f7496d71 | 475 | # Validate Feature Flag Express\r |
4234283c | 476 | #\r |
421ccda3 | 477 | FeatureFlagRtv = IsValidFeatureFlagExp(ItemContent[6].strip())\r |
4234283c LG |
478 | if not FeatureFlagRtv[0]:\r |
479 | Logger.Error("InfParser",\r | |
480 | ToolError.FORMAT_INVALID,\r | |
481 | ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID % (FeatureFlagRtv[1]),\r | |
482 | File=CurrentLineOfItem.GetFileName(),\r | |
483 | Line=CurrentLineOfItem.GetLineNo(),\r | |
484 | ExtraData=CurrentLineOfItem.GetLineString())\r | |
421ccda3 | 485 | InfBianryCommonItemObj.SetFeatureFlagExp(ItemContent[6])\r |
4234283c LG |
486 | \r |
487 | InfBianryCommonItemObj.SetSupArchList(__SupArchList)\r | |
488 | \r | |
489 | #\r | |
490 | # Determine binary file name duplicate. Follow below rule:\r | |
491 | #\r | |
f7496d71 LG |
492 | # A binary filename must not be duplicated within\r |
493 | # a [Binaries] section. A binary filename may appear in\r | |
494 | # multiple architectural [Binaries] sections. A binary\r | |
495 | # filename listed in an architectural [Binaries] section\r | |
496 | # must not be listed in the common architectural\r | |
4234283c | 497 | # [Binaries] section.\r |
f7496d71 | 498 | #\r |
4234283c | 499 | # NOTE: This check will not report error now.\r |
f7496d71 | 500 | #\r |
4234283c LG |
501 | # for Item in self.Binaries:\r |
502 | # if Item.GetFileName() == InfBianryCommonItemObj.GetFileName():\r | |
503 | # ItemSupArchList = Item.GetSupArchList()\r | |
504 | # for ItemArch in ItemSupArchList:\r | |
505 | # for ComItemObjArch in __SupArchList:\r | |
506 | # if ItemArch == ComItemObjArch:\r | |
507 | # #\r | |
508 | # # ST.ERR_INF_PARSER_ITEM_DUPLICATE\r | |
509 | # #\r | |
510 | # pass\r | |
511 | #\r | |
512 | # if ItemArch.upper() == 'COMMON' or ComItemObjArch.upper() == 'COMMON':\r | |
513 | # #\r | |
514 | # # ERR_INF_PARSER_ITEM_DUPLICATE_COMMON\r | |
515 | # #\r | |
516 | # pass\r | |
517 | \r | |
4231a819 | 518 | if InfBianryCommonItemObj is not None:\r |
27c4ceb4 | 519 | if (InfBianryCommonItemObj) in self.Binaries:\r |
4234283c LG |
520 | BinariesList = self.Binaries[InfBianryCommonItemObj]\r |
521 | BinariesList.append((InfBianryCommonItemObj, ItemComment))\r | |
522 | self.Binaries[InfBianryCommonItemObj] = BinariesList\r | |
523 | else:\r | |
524 | BinariesList = []\r | |
525 | BinariesList.append((InfBianryCommonItemObj, ItemComment))\r | |
526 | self.Binaries[InfBianryCommonItemObj] = BinariesList\r | |
527 | \r | |
528 | def SetBinary(self, UiInf=None, Ver=None, CommonBinary=None, ArchList=None):\r | |
529 | \r | |
530 | __SupArchList = []\r | |
531 | for ArchItem in ArchList:\r | |
532 | #\r | |
533 | # Validate Arch\r | |
f7496d71 | 534 | #\r |
4231a819 | 535 | if (ArchItem == '' or ArchItem is None):\r |
4234283c LG |
536 | ArchItem = 'COMMON'\r |
537 | __SupArchList.append(ArchItem)\r | |
538 | \r | |
4231a819 | 539 | if UiInf is not None:\r |
4234283c LG |
540 | if len(UiInf) > 0:\r |
541 | #\r | |
542 | # Check UI\r | |
f7496d71 | 543 | #\r |
4234283c LG |
544 | for UiItem in UiInf:\r |
545 | IsValidFileFlag = False\r | |
546 | InfBianryUiItemObj = None\r | |
547 | UiContent = UiItem[0]\r | |
548 | UiComment = UiItem[1]\r | |
549 | UiCurrentLine = UiItem[2]\r | |
550 | GlobalData.gINF_CURRENT_LINE = deepcopy(UiItem[2])\r | |
551 | #\r | |
552 | # Should not less than 2 elements\r | |
553 | #\r | |
554 | if len(UiContent) < 2:\r | |
555 | Logger.Error("InfParser",\r | |
556 | ToolError.FORMAT_INVALID,\r | |
421ccda3 | 557 | ST.ERR_INF_PARSER_BINARY_ITEM_FORMAT_INVALID % (UiContent[0], 2),\r |
4234283c LG |
558 | File=UiCurrentLine.GetFileName(),\r |
559 | Line=UiCurrentLine.GetLineNo(),\r | |
560 | ExtraData=UiCurrentLine.GetLineString())\r | |
561 | return False\r | |
562 | \r | |
563 | if len(UiContent) > 4:\r | |
564 | Logger.Error("InfParser",\r | |
565 | ToolError.FORMAT_INVALID,\r | |
566 | ST.ERR_INF_PARSER_BINARY_ITEM_FORMAT_INVALID_MAX % (UiContent[0], 4),\r | |
567 | File=UiCurrentLine.GetFileName(),\r | |
568 | Line=UiCurrentLine.GetLineNo(),\r | |
569 | ExtraData=UiCurrentLine.GetLineString())\r | |
570 | return False\r | |
571 | if len(UiContent) >= 2:\r | |
572 | #\r | |
573 | # Create an Ui Object.\r | |
574 | #\r | |
575 | InfBianryUiItemObj = InfBianryUiItem()\r | |
576 | if UiContent[0] != 'UI':\r | |
577 | Logger.Error("InfParser",\r | |
578 | ToolError.FORMAT_INVALID,\r | |
579 | ST.ERR_INF_PARSER_BINARY_VER_TYPE % ('UI'),\r | |
580 | File=UiCurrentLine.GetFileName(),\r | |
581 | Line=UiCurrentLine.GetLineNo(),\r | |
582 | ExtraData=UiCurrentLine.GetLineString())\r | |
583 | InfBianryUiItemObj.SetUiTypeName(UiContent[0])\r | |
584 | InfBianryUiItemObj.SetType(UiContent[0])\r | |
585 | #\r | |
586 | # Verify File exist or not\r | |
587 | #\r | |
588 | FullFileName = os.path.normpath(os.path.realpath(os.path.join(GlobalData.gINF_MODULE_DIR,\r | |
589 | UiContent[1])))\r | |
590 | if not (ValidFile(FullFileName) or ValidFile(UiContent[1])):\r | |
591 | Logger.Error("InfParser",\r | |
592 | ToolError.FORMAT_INVALID,\r | |
593 | ST.ERR_INF_PARSER_BINARY_ITEM_FILE_NOT_EXIST % (UiContent[1]),\r | |
594 | File=UiCurrentLine.GetFileName(),\r | |
595 | Line=UiCurrentLine.GetLineNo(),\r | |
596 | ExtraData=UiCurrentLine.GetLineString())\r | |
597 | #\r | |
598 | # Validate file exist/format.\r | |
599 | #\r | |
600 | if IsValidPath(UiContent[1], GlobalData.gINF_MODULE_DIR):\r | |
601 | IsValidFileFlag = True\r | |
602 | else:\r | |
603 | Logger.Error("InfParser",\r | |
604 | ToolError.FORMAT_INVALID,\r | |
605 | ST.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID % (UiContent[1]),\r | |
606 | File=UiCurrentLine.GetFileName(),\r | |
607 | Line=UiCurrentLine.GetLineNo(),\r | |
608 | ExtraData=UiCurrentLine.GetLineString())\r | |
609 | return False\r | |
610 | if IsValidFileFlag:\r | |
611 | UiContent[0] = ConvPathFromAbsToRel(UiContent[0], GlobalData.gINF_MODULE_DIR)\r | |
612 | InfBianryUiItemObj.SetFileName(UiContent[1])\r | |
613 | if len(UiContent) >= 3:\r | |
614 | #\r | |
615 | # Add Target information\r | |
616 | #\r | |
617 | InfBianryUiItemObj.SetTarget(UiContent[2])\r | |
618 | if len(UiContent) == 4:\r | |
619 | if UiContent[3].strip() == '':\r | |
620 | Logger.Error("InfParser",\r | |
621 | ToolError.FORMAT_INVALID,\r | |
622 | ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING,\r | |
623 | File=UiCurrentLine.GetFileName(),\r | |
624 | Line=UiCurrentLine.GetLineNo(),\r | |
625 | ExtraData=UiCurrentLine.GetLineString())\r | |
626 | #\r | |
f7496d71 | 627 | # Validate Feature Flag Express\r |
4234283c LG |
628 | #\r |
629 | FeatureFlagRtv = IsValidFeatureFlagExp(UiContent[3].strip())\r | |
630 | if not FeatureFlagRtv[0]:\r | |
631 | Logger.Error("InfParser",\r | |
632 | ToolError.FORMAT_INVALID,\r | |
633 | ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID % (FeatureFlagRtv[1]),\r | |
634 | File=UiCurrentLine.GetFileName(),\r | |
635 | Line=UiCurrentLine.GetLineNo(),\r | |
636 | ExtraData=UiCurrentLine.GetLineString())\r | |
637 | InfBianryUiItemObj.SetFeatureFlagExp(UiContent[3])\r | |
638 | \r | |
639 | InfBianryUiItemObj.SetSupArchList(__SupArchList)\r | |
640 | \r | |
641 | #\r | |
642 | # Determine binary file name duplicate. Follow below rule:\r | |
643 | #\r | |
f7496d71 LG |
644 | # A binary filename must not be duplicated within\r |
645 | # a [Binaries] section. A binary filename may appear in\r | |
646 | # multiple architectural [Binaries] sections. A binary\r | |
647 | # filename listed in an architectural [Binaries] section\r | |
648 | # must not be listed in the common architectural\r | |
4234283c | 649 | # [Binaries] section.\r |
f7496d71 | 650 | #\r |
4234283c | 651 | # NOTE: This check will not report error now.\r |
f7496d71 | 652 | #\r |
4234283c LG |
653 | # for Item in self.Binaries:\r |
654 | # if Item.GetFileName() == InfBianryUiItemObj.GetFileName():\r | |
655 | # ItemSupArchList = Item.GetSupArchList()\r | |
656 | # for ItemArch in ItemSupArchList:\r | |
657 | # for UiItemObjArch in __SupArchList:\r | |
658 | # if ItemArch == UiItemObjArch:\r | |
659 | # #\r | |
660 | # # ST.ERR_INF_PARSER_ITEM_DUPLICATE\r | |
661 | # #\r | |
662 | # pass\r | |
663 | # if ItemArch.upper() == 'COMMON' or UiItemObjArch.upper() == 'COMMON':\r | |
664 | # #\r | |
665 | # # ERR_INF_PARSER_ITEM_DUPLICATE_COMMON\r | |
666 | # #\r | |
667 | # pass\r | |
668 | \r | |
4231a819 | 669 | if InfBianryUiItemObj is not None:\r |
27c4ceb4 | 670 | if (InfBianryUiItemObj) in self.Binaries:\r |
4234283c LG |
671 | BinariesList = self.Binaries[InfBianryUiItemObj]\r |
672 | BinariesList.append((InfBianryUiItemObj, UiComment))\r | |
673 | self.Binaries[InfBianryUiItemObj] = BinariesList\r | |
674 | else:\r | |
675 | BinariesList = []\r | |
676 | BinariesList.append((InfBianryUiItemObj, UiComment))\r | |
677 | self.Binaries[InfBianryUiItemObj] = BinariesList\r | |
4231a819 | 678 | if Ver is not None and len(Ver) > 0:\r |
4234283c LG |
679 | self.CheckVer(Ver, __SupArchList)\r |
680 | if CommonBinary and len(CommonBinary) > 0:\r | |
681 | self.ParseCommonBinary(CommonBinary, __SupArchList)\r | |
682 | \r | |
683 | return True\r | |
684 | \r | |
685 | def GetBinary(self):\r | |
686 | return self.Binaries\r |