2 # This file is used to define class objects of INF file [Binaries] section.
3 # It will consumed by InfParser.
5 # Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
7 # This program and the accompanying materials are licensed and made available
8 # under the terms and conditions of the BSD License which accompanies this
9 # distribution. The full text of the license may be found at
10 # http://opensource.org/licenses/bsd-license.php
12 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 from copy
import deepcopy
22 from Library
import DataType
as DT
23 from Library
import GlobalData
24 import Logger
.Log
as Logger
25 from Logger
import ToolError
26 from Logger
import StringTable
as ST
27 from Library
.Misc
import Sdict
29 from Object
.Parser
.InfCommonObject
import InfSectionCommonDef
30 from Object
.Parser
.InfCommonObject
import CurrentLine
31 from Library
.Misc
import ConvPathFromAbsToRel
32 from Library
.ExpressionValidate
import IsValidFeatureFlagExp
33 from Library
.Misc
import ValidFile
34 from Library
.ParserValidate
import IsValidPath
37 class InfBianryItem():
41 self
.FeatureFlagExp
= ''
46 def SetFileName(self
, FileName
):
47 self
.FileName
= FileName
48 def GetFileName(self
):
51 def SetTarget(self
, Target
):
56 def SetFeatureFlagExp(self
, FeatureFlagExp
):
57 self
.FeatureFlagExp
= FeatureFlagExp
58 def GetFeatureFlagExp(self
):
59 return self
.FeatureFlagExp
61 def SetHelpString(self
, HelpString
):
62 self
.HelpString
= HelpString
63 def GetHelpString(self
):
64 return self
.HelpString
66 def SetType(self
, Type
):
70 def SetSupArchList(self
, SupArchList
):
71 self
.SupArchList
= SupArchList
72 def GetSupArchList(self
):
73 return self
.SupArchList
75 class InfBianryVerItem(InfBianryItem
, CurrentLine
):
77 InfBianryItem
.__init
__(self
)
78 CurrentLine
.__init
__(self
)
81 def SetVerTypeName(self
, VerTypeName
):
82 self
.VerTypeName
= VerTypeName
83 def GetVerTypeName(self
):
84 return self
.VerTypeName
86 class InfBianryUiItem(InfBianryItem
, CurrentLine
):
88 InfBianryItem
.__init
__(self
)
89 CurrentLine
.__init
__(self
)
92 def SetUiTypeName(self
, UiTypeName
):
93 self
.UiTypeName
= UiTypeName
94 def GetVerTypeName(self
):
95 return self
.UiTypeName
97 class InfBianryCommonItem(InfBianryItem
, CurrentLine
):
102 InfBianryItem
.__init
__(self
)
103 CurrentLine
.__init
__(self
)
105 def SetCommonType(self
, CommonType
):
106 self
.CommonType
= CommonType
107 def GetCommonType(self
):
108 return self
.CommonType
110 def SetTagName(self
, TagName
):
111 self
.TagName
= TagName
112 def GetTagName(self
):
115 def SetFamily(self
, Family
):
124 class InfBinariesObject(InfSectionCommonDef
):
126 self
.Binaries
= Sdict()
128 # Macro defined in this section should be only used in this section.
131 InfSectionCommonDef
.__init
__(self
)
136 def CheckVer(self
, Ver
, __SupArchList
):
141 IsValidFileFlag
= False
142 VerContent
= VerItem
[0]
143 VerComment
= VerItem
[1]
144 VerCurrentLine
= VerItem
[2]
145 GlobalData
.gINF_CURRENT_LINE
= VerCurrentLine
146 InfBianryVerItemObj
= None
148 # Should not less than 2 elements
150 if len(VerContent
) < 2:
151 Logger
.Error("InfParser",
152 ToolError
.FORMAT_INVALID
,
153 ST
.ERR_INF_PARSER_BINARY_ITEM_FORMAT_INVALID
% (VerContent
[0]),
154 File
=VerCurrentLine
.GetFileName(),
155 Line
=VerCurrentLine
.GetLineNo(),
156 ExtraData
=VerCurrentLine
.GetLineString())
158 if len(VerContent
) > 4:
159 Logger
.Error("InfParser",
160 ToolError
.FORMAT_INVALID
,
161 ST
.ERR_INF_PARSER_BINARY_ITEM_FORMAT_INVALID_MAX
% (VerContent
[0], 4),
162 File
=VerCurrentLine
.GetFileName(),
163 Line
=VerCurrentLine
.GetLineNo(),
164 ExtraData
=VerCurrentLine
.GetLineString())
166 if len(VerContent
) >= 2:
168 # Create a Ver Object.
170 InfBianryVerItemObj
= InfBianryVerItem()
172 if VerContent
[0] != DT
.BINARY_FILE_TYPE_VER
:
173 Logger
.Error("InfParser",
174 ToolError
.FORMAT_INVALID
,
175 ST
.ERR_INF_PARSER_BINARY_VER_TYPE
% DT
.BINARY_FILE_TYPE_VER
,
176 File
=VerCurrentLine
.GetFileName(),
177 Line
=VerCurrentLine
.GetLineNo(),
178 ExtraData
=VerCurrentLine
.GetLineString())
180 InfBianryVerItemObj
.SetVerTypeName(VerContent
[0])
181 InfBianryVerItemObj
.SetType(VerContent
[0])
183 # Verify File exist or not
185 FullFileName
= os
.path
.normpath(os
.path
.realpath(os
.path
.join(GlobalData
.gINF_MODULE_DIR
,
187 if not (ValidFile(FullFileName
) or ValidFile(VerContent
[1])):
188 Logger
.Error("InfParser",
189 ToolError
.FORMAT_INVALID
,
190 ST
.ERR_INF_PARSER_BINARY_ITEM_FILE_NOT_EXIST
% (VerContent
[1]),
191 File
=VerCurrentLine
.GetFileName(),
192 Line
=VerCurrentLine
.GetLineNo(),
193 ExtraData
=VerCurrentLine
.GetLineString())
195 # Validate file exist/format.
197 if IsValidPath(VerContent
[1], GlobalData
.gINF_MODULE_DIR
):
198 IsValidFileFlag
= True
200 Logger
.Error("InfParser",
201 ToolError
.FORMAT_INVALID
,
202 ST
.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID
% (VerContent
[1]),
203 File
=VerCurrentLine
.GetFileName(),
204 Line
=VerCurrentLine
.GetLineNo(),
205 ExtraData
=VerCurrentLine
.GetLineString())
208 VerContent
[0] = ConvPathFromAbsToRel(VerContent
[0],
209 GlobalData
.gINF_MODULE_DIR
)
210 InfBianryVerItemObj
.SetFileName(VerContent
[1])
211 if len(VerContent
) >= 3:
213 # Add Target information
215 InfBianryVerItemObj
.SetTarget(VerContent
[2])
216 if len(VerContent
) == 4:
217 if VerContent
[3].strip() == '':
218 Logger
.Error("InfParser",
219 ToolError
.FORMAT_INVALID
,
220 ST
.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING
,
221 File
=VerCurrentLine
.GetFileName(),
222 Line
=VerCurrentLine
.GetLineNo(),
223 ExtraData
=VerCurrentLine
.GetLineString())
225 # Validate Feature Flag Express
227 FeatureFlagRtv
= IsValidFeatureFlagExp(VerContent
[3].\
229 if not FeatureFlagRtv
[0]:
230 Logger
.Error("InfParser",
231 ToolError
.FORMAT_INVALID
,
232 ST
.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID
% (FeatureFlagRtv
[1]),
233 File
=VerCurrentLine
.GetFileName(),
234 Line
=VerCurrentLine
.GetLineNo(),
235 ExtraData
=VerCurrentLine
.GetLineString())
236 InfBianryVerItemObj
.SetFeatureFlagExp(VerContent
[3])
238 InfBianryVerItemObj
.SetSupArchList(__SupArchList
)
241 # Determine binary file name duplicate. Follow below rule:
243 # A binary filename must not be duplicated within
244 # a [Binaries] section. A binary filename may appear in
245 # multiple architectural [Binaries] sections. A binary
246 # filename listed in an architectural [Binaries] section
247 # must not be listed in the common architectural
248 # [Binaries] section.
250 # NOTE: This check will not report error now.
252 for Item
in self
.Binaries
:
253 if Item
.GetFileName() == InfBianryVerItemObj
.GetFileName():
254 ItemSupArchList
= Item
.GetSupArchList()
255 for ItemArch
in ItemSupArchList
:
256 for VerItemObjArch
in __SupArchList
:
257 if ItemArch
== VerItemObjArch
:
259 # ST.ERR_INF_PARSER_ITEM_DUPLICATE
262 if ItemArch
.upper() == 'COMMON' or VerItemObjArch
.upper() == 'COMMON':
264 # ERR_INF_PARSER_ITEM_DUPLICATE_COMMON
268 if InfBianryVerItemObj
!= None:
269 if self
.Binaries
.has_key((InfBianryVerItemObj
)):
270 BinariesList
= self
.Binaries
[InfBianryVerItemObj
]
271 BinariesList
.append((InfBianryVerItemObj
, VerComment
))
272 self
.Binaries
[InfBianryVerItemObj
] = BinariesList
275 BinariesList
.append((InfBianryVerItemObj
, VerComment
))
276 self
.Binaries
[InfBianryVerItemObj
] = BinariesList
282 def ParseCommonBinary(self
, CommonBinary
, __SupArchList
):
284 # Check common binary definitions
285 # Type | FileName | Target | Family | TagName | FeatureFlagExp
287 for Item
in CommonBinary
:
288 IsValidFileFlag
= False
289 ItemContent
= Item
[0]
290 ItemComment
= Item
[1]
291 CurrentLineOfItem
= Item
[2]
292 GlobalData
.gINF_CURRENT_LINE
= CurrentLineOfItem
293 InfBianryCommonItemObj
= None
294 if len(ItemContent
) < 2:
295 Logger
.Error("InfParser",
296 ToolError
.FORMAT_INVALID
,
297 ST
.ERR_INF_PARSER_BINARY_ITEM_FORMAT_INVALID
% (ItemContent
[0]),
298 File
=CurrentLineOfItem
.GetFileName(),
299 Line
=CurrentLineOfItem
.GetLineNo(),
300 ExtraData
=CurrentLineOfItem
.GetLineString())
302 if len(ItemContent
) > 6:
303 Logger
.Error("InfParser",
304 ToolError
.FORMAT_INVALID
,
305 ST
.ERR_INF_PARSER_BINARY_ITEM_FORMAT_INVALID_MAX
% (ItemContent
[0], 6),
306 File
=CurrentLineOfItem
.GetFileName(),
307 Line
=CurrentLineOfItem
.GetLineNo(),
308 ExtraData
=CurrentLineOfItem
.GetLineString())
310 if len(ItemContent
) >= 2:
312 # Create a Common Object.
314 InfBianryCommonItemObj
= InfBianryCommonItem()
316 # Convert Binary type.
318 BinaryFileType
= ItemContent
[0].strip()
319 if BinaryFileType
== 'RAW' or BinaryFileType
== 'ACPI' or BinaryFileType
== 'ASL':
320 BinaryFileType
= 'BIN'
322 if BinaryFileType
not in DT
.BINARY_FILE_TYPE_LIST
:
323 Logger
.Error("InfParser",
324 ToolError
.FORMAT_INVALID
,
325 ST
.ERR_INF_PARSER_BINARY_ITEM_INVALID_FILETYPE
% \
326 (DT
.BINARY_FILE_TYPE_LIST
.__str
__()),
327 File
=CurrentLineOfItem
.GetFileName(),
328 Line
=CurrentLineOfItem
.GetLineNo(),
329 ExtraData
=CurrentLineOfItem
.GetLineString())
331 if BinaryFileType
== 'SUBTYPE_GUID':
332 BinaryFileType
= 'FREEFORM'
334 if BinaryFileType
== 'LIB' or BinaryFileType
== 'UEFI_APP':
335 Logger
.Error("InfParser",
336 ToolError
.FORMAT_INVALID
,
337 ST
.ERR_INF_PARSER_BINARY_ITEM_INVALID_FILETYPE
% \
338 (DT
.BINARY_FILE_TYPE_LIST
.__str
__()),
339 File
=CurrentLineOfItem
.GetFileName(),
340 Line
=CurrentLineOfItem
.GetLineNo(),
341 ExtraData
=CurrentLineOfItem
.GetLineString())
343 InfBianryCommonItemObj
.SetType(BinaryFileType
)
344 InfBianryCommonItemObj
.SetCommonType(ItemContent
[0])
346 # Verify File exist or not
348 FullFileName
= os
.path
.normpath(os
.path
.realpath(os
.path
.join(GlobalData
.gINF_MODULE_DIR
,
350 if not (ValidFile(FullFileName
) or ValidFile(ItemContent
[1])):
351 Logger
.Error("InfParser",
352 ToolError
.FORMAT_INVALID
,
353 ST
.ERR_INF_PARSER_BINARY_ITEM_FILE_NOT_EXIST
% (ItemContent
[1]),
354 File
=CurrentLineOfItem
.GetFileName(),
355 Line
=CurrentLineOfItem
.GetLineNo(),
356 ExtraData
=CurrentLineOfItem
.GetLineString())
358 # Validate file exist/format.
360 if IsValidPath(ItemContent
[1], GlobalData
.gINF_MODULE_DIR
):
361 IsValidFileFlag
= True
363 Logger
.Error("InfParser",
364 ToolError
.FORMAT_INVALID
,
365 ST
.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID
% (ItemContent
[1]),
366 File
=CurrentLineOfItem
.GetFileName(),
367 Line
=CurrentLineOfItem
.GetLineNo(),
368 ExtraData
=CurrentLineOfItem
.GetLineString())
371 ItemContent
[0] = ConvPathFromAbsToRel(ItemContent
[0], GlobalData
.gINF_MODULE_DIR
)
372 InfBianryCommonItemObj
.SetFileName(ItemContent
[1])
373 if len(ItemContent
) >= 3:
375 # Add Target information
377 InfBianryCommonItemObj
.SetTarget(ItemContent
[2])
378 if len(ItemContent
) >= 4:
380 # Add Family information
382 InfBianryCommonItemObj
.SetFamily(ItemContent
[3])
383 if len(ItemContent
) >= 5:
385 # TagName entries are build system specific. If there
386 # is content in the entry, the tool must exit
387 # gracefully with an error message that indicates build
388 # system specific content cannot be distributed using
391 if ItemContent
[4].strip() != '':
392 Logger
.Error("InfParser",
393 ToolError
.FORMAT_INVALID
,
394 ST
.ERR_INF_PARSER_TAGNAME_NOT_PERMITTED
% (ItemContent
[4]),
395 File
=CurrentLineOfItem
.GetFileName(),
396 Line
=CurrentLineOfItem
.GetLineNo(),
397 ExtraData
=CurrentLineOfItem
.GetLineString())
398 if len(ItemContent
) == 6:
402 if ItemContent
[5].strip() == '':
403 Logger
.Error("InfParser",
404 ToolError
.FORMAT_INVALID
,
405 ST
.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING
,
406 File
=CurrentLineOfItem
.GetFileName(),
407 Line
=CurrentLineOfItem
.GetLineNo(),
408 ExtraData
=CurrentLineOfItem
.GetLineString())
410 # Validate Feature Flag Express
412 FeatureFlagRtv
= IsValidFeatureFlagExp(ItemContent
[5].strip())
413 if not FeatureFlagRtv
[0]:
414 Logger
.Error("InfParser",
415 ToolError
.FORMAT_INVALID
,
416 ST
.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID
% (FeatureFlagRtv
[1]),
417 File
=CurrentLineOfItem
.GetFileName(),
418 Line
=CurrentLineOfItem
.GetLineNo(),
419 ExtraData
=CurrentLineOfItem
.GetLineString())
420 InfBianryCommonItemObj
.SetFeatureFlagExp(ItemContent
[5])
422 InfBianryCommonItemObj
.SetSupArchList(__SupArchList
)
425 # Determine binary file name duplicate. Follow below rule:
427 # A binary filename must not be duplicated within
428 # a [Binaries] section. A binary filename may appear in
429 # multiple architectural [Binaries] sections. A binary
430 # filename listed in an architectural [Binaries] section
431 # must not be listed in the common architectural
432 # [Binaries] section.
434 # NOTE: This check will not report error now.
436 # for Item in self.Binaries:
437 # if Item.GetFileName() == InfBianryCommonItemObj.GetFileName():
438 # ItemSupArchList = Item.GetSupArchList()
439 # for ItemArch in ItemSupArchList:
440 # for ComItemObjArch in __SupArchList:
441 # if ItemArch == ComItemObjArch:
443 # # ST.ERR_INF_PARSER_ITEM_DUPLICATE
447 # if ItemArch.upper() == 'COMMON' or ComItemObjArch.upper() == 'COMMON':
449 # # ERR_INF_PARSER_ITEM_DUPLICATE_COMMON
453 if InfBianryCommonItemObj
!= None:
454 if self
.Binaries
.has_key((InfBianryCommonItemObj
)):
455 BinariesList
= self
.Binaries
[InfBianryCommonItemObj
]
456 BinariesList
.append((InfBianryCommonItemObj
, ItemComment
))
457 self
.Binaries
[InfBianryCommonItemObj
] = BinariesList
460 BinariesList
.append((InfBianryCommonItemObj
, ItemComment
))
461 self
.Binaries
[InfBianryCommonItemObj
] = BinariesList
463 def SetBinary(self
, UiInf
=None, Ver
=None, CommonBinary
=None, ArchList
=None):
466 for ArchItem
in ArchList
:
470 if (ArchItem
== '' or ArchItem
== None):
472 __SupArchList
.append(ArchItem
)
480 IsValidFileFlag
= False
481 InfBianryUiItemObj
= None
482 UiContent
= UiItem
[0]
483 UiComment
= UiItem
[1]
484 UiCurrentLine
= UiItem
[2]
485 GlobalData
.gINF_CURRENT_LINE
= deepcopy(UiItem
[2])
487 # Should not less than 2 elements
489 if len(UiContent
) < 2:
490 Logger
.Error("InfParser",
491 ToolError
.FORMAT_INVALID
,
492 ST
.ERR_INF_PARSER_BINARY_ITEM_FORMAT_INVALID
% (UiContent
[0]),
493 File
=UiCurrentLine
.GetFileName(),
494 Line
=UiCurrentLine
.GetLineNo(),
495 ExtraData
=UiCurrentLine
.GetLineString())
498 if len(UiContent
) > 4:
499 Logger
.Error("InfParser",
500 ToolError
.FORMAT_INVALID
,
501 ST
.ERR_INF_PARSER_BINARY_ITEM_FORMAT_INVALID_MAX
% (UiContent
[0], 4),
502 File
=UiCurrentLine
.GetFileName(),
503 Line
=UiCurrentLine
.GetLineNo(),
504 ExtraData
=UiCurrentLine
.GetLineString())
506 if len(UiContent
) >= 2:
508 # Create an Ui Object.
510 InfBianryUiItemObj
= InfBianryUiItem()
511 if UiContent
[0] != 'UI':
512 Logger
.Error("InfParser",
513 ToolError
.FORMAT_INVALID
,
514 ST
.ERR_INF_PARSER_BINARY_VER_TYPE
% ('UI'),
515 File
=UiCurrentLine
.GetFileName(),
516 Line
=UiCurrentLine
.GetLineNo(),
517 ExtraData
=UiCurrentLine
.GetLineString())
518 InfBianryUiItemObj
.SetUiTypeName(UiContent
[0])
519 InfBianryUiItemObj
.SetType(UiContent
[0])
521 # Verify File exist or not
523 FullFileName
= os
.path
.normpath(os
.path
.realpath(os
.path
.join(GlobalData
.gINF_MODULE_DIR
,
525 if not (ValidFile(FullFileName
) or ValidFile(UiContent
[1])):
526 Logger
.Error("InfParser",
527 ToolError
.FORMAT_INVALID
,
528 ST
.ERR_INF_PARSER_BINARY_ITEM_FILE_NOT_EXIST
% (UiContent
[1]),
529 File
=UiCurrentLine
.GetFileName(),
530 Line
=UiCurrentLine
.GetLineNo(),
531 ExtraData
=UiCurrentLine
.GetLineString())
533 # Validate file exist/format.
535 if IsValidPath(UiContent
[1], GlobalData
.gINF_MODULE_DIR
):
536 IsValidFileFlag
= True
538 Logger
.Error("InfParser",
539 ToolError
.FORMAT_INVALID
,
540 ST
.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID
% (UiContent
[1]),
541 File
=UiCurrentLine
.GetFileName(),
542 Line
=UiCurrentLine
.GetLineNo(),
543 ExtraData
=UiCurrentLine
.GetLineString())
546 UiContent
[0] = ConvPathFromAbsToRel(UiContent
[0], GlobalData
.gINF_MODULE_DIR
)
547 InfBianryUiItemObj
.SetFileName(UiContent
[1])
548 if len(UiContent
) >= 3:
550 # Add Target information
552 InfBianryUiItemObj
.SetTarget(UiContent
[2])
553 if len(UiContent
) == 4:
554 if UiContent
[3].strip() == '':
555 Logger
.Error("InfParser",
556 ToolError
.FORMAT_INVALID
,
557 ST
.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING
,
558 File
=UiCurrentLine
.GetFileName(),
559 Line
=UiCurrentLine
.GetLineNo(),
560 ExtraData
=UiCurrentLine
.GetLineString())
562 # Validate Feature Flag Express
564 FeatureFlagRtv
= IsValidFeatureFlagExp(UiContent
[3].strip())
565 if not FeatureFlagRtv
[0]:
566 Logger
.Error("InfParser",
567 ToolError
.FORMAT_INVALID
,
568 ST
.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID
% (FeatureFlagRtv
[1]),
569 File
=UiCurrentLine
.GetFileName(),
570 Line
=UiCurrentLine
.GetLineNo(),
571 ExtraData
=UiCurrentLine
.GetLineString())
572 InfBianryUiItemObj
.SetFeatureFlagExp(UiContent
[3])
574 InfBianryUiItemObj
.SetSupArchList(__SupArchList
)
577 # Determine binary file name duplicate. Follow below rule:
579 # A binary filename must not be duplicated within
580 # a [Binaries] section. A binary filename may appear in
581 # multiple architectural [Binaries] sections. A binary
582 # filename listed in an architectural [Binaries] section
583 # must not be listed in the common architectural
584 # [Binaries] section.
586 # NOTE: This check will not report error now.
588 # for Item in self.Binaries:
589 # if Item.GetFileName() == InfBianryUiItemObj.GetFileName():
590 # ItemSupArchList = Item.GetSupArchList()
591 # for ItemArch in ItemSupArchList:
592 # for UiItemObjArch in __SupArchList:
593 # if ItemArch == UiItemObjArch:
595 # # ST.ERR_INF_PARSER_ITEM_DUPLICATE
598 # if ItemArch.upper() == 'COMMON' or UiItemObjArch.upper() == 'COMMON':
600 # # ERR_INF_PARSER_ITEM_DUPLICATE_COMMON
604 if InfBianryUiItemObj
!= None:
605 if self
.Binaries
.has_key((InfBianryUiItemObj
)):
606 BinariesList
= self
.Binaries
[InfBianryUiItemObj
]
607 BinariesList
.append((InfBianryUiItemObj
, UiComment
))
608 self
.Binaries
[InfBianryUiItemObj
] = BinariesList
611 BinariesList
.append((InfBianryUiItemObj
, UiComment
))
612 self
.Binaries
[InfBianryUiItemObj
] = BinariesList
613 if Ver
!= None and len(Ver
) > 0:
614 self
.CheckVer(Ver
, __SupArchList
)
615 if CommonBinary
and len(CommonBinary
) > 0:
616 self
.ParseCommonBinary(CommonBinary
, __SupArchList
)