2 # This file is used to define class objects of [Defines] section for INF file.
3 # It will consumed by InfParser
5 # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
7 # SPDX-License-Identifier: BSD-2-Clause-Patent
16 from Logger
import StringTable
as ST
17 from Logger
import ToolError
18 from Library
import GlobalData
19 from Library
import DataType
as DT
20 from Library
.StringUtils
import GetSplitValueList
21 from Library
.Misc
import CheckGuidRegFormat
22 from Library
.Misc
import Sdict
23 from Library
.Misc
import ConvPathFromAbsToRel
24 from Library
.Misc
import ValidateUNIFilePath
25 from Library
.ExpressionValidate
import IsValidFeatureFlagExp
26 from Library
.ParserValidate
import IsValidWord
27 from Library
.ParserValidate
import IsValidInfMoudleType
28 from Library
.ParserValidate
import IsValidHex
29 from Library
.ParserValidate
import IsValidHexVersion
30 from Library
.ParserValidate
import IsValidDecVersion
31 from Library
.ParserValidate
import IsValidCVariableName
32 from Library
.ParserValidate
import IsValidBoolType
33 from Library
.ParserValidate
import IsValidPath
34 from Library
.ParserValidate
import IsValidFamily
35 from Library
.ParserValidate
import IsValidIdentifier
36 from Library
.ParserValidate
import IsValidDecVersionVal
37 from Object
.Parser
.InfCommonObject
import InfLineCommentObject
38 from Object
.Parser
.InfCommonObject
import CurrentLine
39 from Object
.Parser
.InfCommonObject
import InfSectionCommonDef
40 from Object
.Parser
.InfMisc
import ErrorInInf
41 from Object
.Parser
.InfDefineCommonObject
import InfDefineLibraryItem
42 from Object
.Parser
.InfDefineCommonObject
import InfDefineEntryPointItem
43 from Object
.Parser
.InfDefineCommonObject
import InfDefineUnloadImageItem
44 from Object
.Parser
.InfDefineCommonObject
import InfDefineConstructorItem
45 from Object
.Parser
.InfDefineCommonObject
import InfDefineDestructorItem
47 class InfDefSectionOptionRomInfo():
49 self
.PciVendorId
= None
50 self
.PciDeviceId
= None
51 self
.PciClassCode
= None
52 self
.PciRevision
= None
53 self
.PciCompress
= None
54 self
.CurrentLine
= ['', -1, '']
55 def SetPciVendorId(self
, PciVendorId
, Comments
):
57 # Value has been set before.
59 if self
.PciVendorId
is not None:
60 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND
%(DT
.TAB_INF_DEFINES_PCI_VENDOR_ID
),
61 LineInfo
=self
.CurrentLine
)
64 # The PciVendorId should be hex string.
66 if (IsValidHex(PciVendorId
)):
67 self
.PciVendorId
= InfDefMember()
68 self
.PciVendorId
.SetValue(PciVendorId
)
69 self
.PciVendorId
.Comments
= Comments
72 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(PciVendorId),
73 LineInfo
=self
.CurrentLine
)
76 def GetPciVendorId(self
):
77 return self
.PciVendorId
79 def SetPciDeviceId(self
, PciDeviceId
, Comments
):
81 # Value has been set before.
83 if self
.PciDeviceId
is not None:
84 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND
%(DT
.TAB_INF_DEFINES_PCI_DEVICE_ID
),
85 LineInfo
=self
.CurrentLine
)
88 # The PciDeviceId should be hex string.
90 if (IsValidHex(PciDeviceId
)):
91 self
.PciDeviceId
= InfDefMember()
92 self
.PciDeviceId
.SetValue(PciDeviceId
)
93 self
.PciDeviceId
.Comments
= Comments
96 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(PciDeviceId),
97 LineInfo
=self
.CurrentLine
)
100 def GetPciDeviceId(self
):
101 return self
.PciDeviceId
103 def SetPciClassCode(self
, PciClassCode
, Comments
):
105 # Value has been set before.
107 if self
.PciClassCode
is not None:
108 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND
%(DT
.TAB_INF_DEFINES_PCI_CLASS_CODE
),
109 LineInfo
=self
.CurrentLine
)
112 # The PciClassCode should be 4 bytes hex string.
114 if (IsValidHex(PciClassCode
)):
115 self
.PciClassCode
= InfDefMember()
116 self
.PciClassCode
.SetValue(PciClassCode
)
117 self
.PciClassCode
.Comments
= Comments
120 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%\
122 LineInfo
=self
.CurrentLine
)
125 def GetPciClassCode(self
):
126 return self
.PciClassCode
128 def SetPciRevision(self
, PciRevision
, Comments
):
130 # Value has been set before.
132 if self
.PciRevision
is not None:
133 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND
%(DT
.TAB_INF_DEFINES_PCI_REVISION
),
134 LineInfo
=self
.CurrentLine
)
137 # The PciRevision should be 4 bytes hex string.
139 if (IsValidHex(PciRevision
)):
140 self
.PciRevision
= InfDefMember()
141 self
.PciRevision
.SetValue(PciRevision
)
142 self
.PciRevision
.Comments
= Comments
145 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(PciRevision),
146 LineInfo
=self
.CurrentLine
)
149 def GetPciRevision(self
):
150 return self
.PciRevision
152 def SetPciCompress(self
, PciCompress
, Comments
):
154 # Value has been set before.
156 if self
.PciCompress
is not None:
157 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND
%(DT
.TAB_INF_DEFINES_PCI_COMPRESS
),
158 LineInfo
=self
.CurrentLine
)
162 # The PciCompress should be 'TRUE' or 'FALSE'.
164 if (PciCompress
== 'TRUE' or PciCompress
== 'FALSE'):
165 self
.PciCompress
= InfDefMember()
166 self
.PciCompress
.SetValue(PciCompress
)
167 self
.PciCompress
.Comments
= Comments
170 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(PciCompress),
171 LineInfo
=self
.CurrentLine
)
173 def GetPciCompress(self
):
174 return self
.PciCompress
176 # INF [Define] section Object
178 class InfDefSection(InfDefSectionOptionRomInfo
):
182 self
.ModuleType
= None
183 self
.ModuleUniFileName
= None
184 self
.InfVersion
= None
185 self
.EdkReleaseVersion
= None
186 self
.UefiSpecificationVersion
= None
187 self
.PiSpecificationVersion
= None
188 self
.LibraryClass
= []
190 self
.VersionString
= None
191 self
.PcdIsDriver
= None
193 self
.UnloadImages
= []
194 self
.Constructor
= []
197 self
.CustomMakefile
= []
198 self
.Specification
= []
199 self
.UefiHiiResourceSection
= None
201 self
.CurrentLine
= ['', -1, '']
202 InfDefSectionOptionRomInfo
.__init
__(self
)
206 # @param BaseName: BaseName
208 def SetBaseName(self
, BaseName
, Comments
):
210 # Value has been set before.
212 if self
.BaseName
is not None:
213 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND
%(DT
.TAB_INF_DEFINES_BASE_NAME
),
214 LineInfo
=self
.CurrentLine
)
216 if not (BaseName
== '' or BaseName
is None):
217 if IsValidWord(BaseName
) and not BaseName
.startswith("_"):
218 self
.BaseName
= InfDefMember()
219 self
.BaseName
.SetValue(BaseName
)
220 self
.BaseName
.Comments
= Comments
223 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_NAME_INVALID
%(BaseName),
224 LineInfo
=self
.CurrentLine
)
229 def GetBaseName(self
):
234 # @param FileGuid: FileGuid
236 def SetFileGuid(self
, FileGuid
, Comments
):
238 # Value has been set before.
240 if self
.FileGuid
is not None:
241 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND\
242 %(DT
.TAB_INF_DEFINES_FILE_GUID
),
243 LineInfo
=self
.CurrentLine
)
246 # Do verification of GUID content/format
248 if (CheckGuidRegFormat(FileGuid
)):
249 self
.FileGuid
= InfDefMember()
250 self
.FileGuid
.SetValue(FileGuid
)
251 self
.FileGuid
.Comments
= Comments
254 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_GUID_INVALID
%(FileGuid),
255 LineInfo
=self
.CurrentLine
)
260 def GetFileGuid(self
):
265 # @param ModuleType: ModuleType
267 def SetModuleType(self
, ModuleType
, Comments
):
269 # Value has been set before.
271 if self
.ModuleType
is not None:
272 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND\
273 %(DT
.TAB_INF_DEFINES_MODULE_TYPE
),
274 LineInfo
=self
.CurrentLine
)
277 # Valid Module Type or not
279 if (IsValidInfMoudleType(ModuleType
)):
280 self
.ModuleType
= InfDefMember()
281 self
.ModuleType
.SetValue(ModuleType
)
282 self
.ModuleType
.CurrentLine
= CurrentLine()
283 self
.ModuleType
.CurrentLine
.SetLineNo(self
.CurrentLine
[1])
284 self
.ModuleType
.CurrentLine
.SetLineString(self
.CurrentLine
[2])
285 self
.ModuleType
.CurrentLine
.SetFileName(self
.CurrentLine
[0])
286 self
.ModuleType
.Comments
= Comments
289 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_MODULETYPE_INVALID
%\
291 LineInfo
=self
.CurrentLine
)
296 def GetModuleType(self
):
297 return self
.ModuleType
299 ## SetModuleUniFileName
301 # @param ModuleUniFileName: ModuleUniFileName
303 def SetModuleUniFileName(self
, ModuleUniFileName
, Comments
):
306 if self
.ModuleUniFileName
is not None:
307 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND
%(DT
.TAB_INF_DEFINES_MODULE_UNI_FILE
),
308 LineInfo
=self
.CurrentLine
)
309 self
.ModuleUniFileName
= ModuleUniFileName
313 def GetModuleUniFileName(self
):
314 return self
.ModuleUniFileName
318 # @param InfVersion: InfVersion
320 def SetInfVersion(self
, InfVersion
, Comments
):
322 # Value has been set before.
324 if self
.InfVersion
is not None:
325 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND\
326 %(DT
.TAB_INF_DEFINES_INF_VERSION
),
327 LineInfo
=self
.CurrentLine
)
330 # The InfVersion should be 4 bytes hex string.
332 if (IsValidHex(InfVersion
)):
333 if (InfVersion
< '0x00010005'):
334 ErrorInInf(ST
.ERR_INF_PARSER_NOT_SUPPORT_EDKI_INF
,
335 ErrorCode
=ToolError
.EDK1_INF_ERROR
,
336 LineInfo
=self
.CurrentLine
)
337 elif IsValidDecVersionVal(InfVersion
):
338 if (InfVersion
< 65541):
339 ErrorInInf(ST
.ERR_INF_PARSER_NOT_SUPPORT_EDKI_INF
,
340 ErrorCode
=ToolError
.EDK1_INF_ERROR
,
341 LineInfo
=self
.CurrentLine
)
343 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(InfVersion),
344 LineInfo
=self
.CurrentLine
)
347 self
.InfVersion
= InfDefMember()
348 self
.InfVersion
.SetValue(InfVersion
)
349 self
.InfVersion
.Comments
= Comments
354 def GetInfVersion(self
):
355 return self
.InfVersion
357 ## SetEdkReleaseVersion
359 # @param EdkReleaseVersion: EdkReleaseVersion
361 def SetEdkReleaseVersion(self
, EdkReleaseVersion
, Comments
):
363 # Value has been set before.
365 if self
.EdkReleaseVersion
is not None:
366 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND\
367 %(DT
.TAB_INF_DEFINES_EDK_RELEASE_VERSION
),
368 LineInfo
=self
.CurrentLine
)
371 # The EdkReleaseVersion should be 4 bytes hex string.
373 if IsValidHexVersion(EdkReleaseVersion
) or \
374 IsValidDecVersionVal(EdkReleaseVersion
):
375 self
.EdkReleaseVersion
= InfDefMember()
376 self
.EdkReleaseVersion
.SetValue(EdkReleaseVersion
)
377 self
.EdkReleaseVersion
.Comments
= Comments
380 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID\
381 %(EdkReleaseVersion),
382 LineInfo
=self
.CurrentLine
)
385 ## GetEdkReleaseVersion
387 def GetEdkReleaseVersion(self
):
388 return self
.EdkReleaseVersion
390 ## SetUefiSpecificationVersion
392 # @param UefiSpecificationVersion: UefiSpecificationVersion
394 def SetUefiSpecificationVersion(self
, UefiSpecificationVersion
, Comments
):
396 # Value has been set before.
398 if self
.UefiSpecificationVersion
is not None:
399 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND\
400 %(DT
.TAB_INF_DEFINES_UEFI_SPECIFICATION_VERSION
),
401 LineInfo
=self
.CurrentLine
)
404 # The EdkReleaseVersion should be 4 bytes hex string.
406 if IsValidHexVersion(UefiSpecificationVersion
) or \
407 IsValidDecVersionVal(UefiSpecificationVersion
):
408 self
.UefiSpecificationVersion
= InfDefMember()
409 self
.UefiSpecificationVersion
.SetValue(UefiSpecificationVersion
)
410 self
.UefiSpecificationVersion
.Comments
= Comments
413 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID\
414 %(UefiSpecificationVersion),
415 LineInfo
=self
.CurrentLine
)
418 ## GetUefiSpecificationVersion
420 def GetUefiSpecificationVersion(self
):
421 return self
.UefiSpecificationVersion
423 ## SetPiSpecificationVersion
425 # @param PiSpecificationVersion: PiSpecificationVersion
427 def SetPiSpecificationVersion(self
, PiSpecificationVersion
, Comments
):
429 # Value has been set before.
431 if self
.PiSpecificationVersion
is not None:
432 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND\
433 %(DT
.TAB_INF_DEFINES_PI_SPECIFICATION_VERSION
),
434 LineInfo
=self
.CurrentLine
)
437 # The EdkReleaseVersion should be 4 bytes hex string.
439 if IsValidHexVersion(PiSpecificationVersion
) or \
440 IsValidDecVersionVal(PiSpecificationVersion
):
441 self
.PiSpecificationVersion
= InfDefMember()
442 self
.PiSpecificationVersion
.SetValue(PiSpecificationVersion
)
443 self
.PiSpecificationVersion
.Comments
= Comments
446 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID\
447 %(PiSpecificationVersion),
448 LineInfo
=self
.CurrentLine
)
451 ## GetPiSpecificationVersion
453 def GetPiSpecificationVersion(self
):
454 return self
.PiSpecificationVersion
458 # @param LibraryClass: LibraryClass
460 def SetLibraryClass(self
, LibraryClass
, Comments
):
461 ValueList
= GetSplitValueList(LibraryClass
)
463 if IsValidWord(Name
):
464 InfDefineLibraryItemObj
= InfDefineLibraryItem()
465 InfDefineLibraryItemObj
.SetLibraryName(Name
)
466 InfDefineLibraryItemObj
.Comments
= Comments
467 if len(ValueList
) == 2:
469 TypeList
= GetSplitValueList(Type
, ' ')
470 TypeList
= [Type
for Type
in TypeList
if Type
!= '']
471 for Item
in TypeList
:
472 if Item
not in DT
.MODULE_LIST
:
473 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(Item),
474 LineInfo
=self
.CurrentLine
)
476 InfDefineLibraryItemObj
.SetTypes(TypeList
)
477 self
.LibraryClass
.append(InfDefineLibraryItemObj
)
479 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(Name),
480 LineInfo
=self
.CurrentLine
)
485 def GetLibraryClass(self
):
486 return self
.LibraryClass
488 def SetVersionString(self
, VersionString
, Comments
):
490 # Value has been set before.
492 if self
.VersionString
is not None:
493 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND\
494 %(DT
.TAB_INF_DEFINES_VERSION_STRING
),
495 LineInfo
=self
.CurrentLine
)
497 if not IsValidDecVersion(VersionString
):
498 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID\
500 LineInfo
=self
.CurrentLine
)
501 self
.VersionString
= InfDefMember()
502 self
.VersionString
.SetValue(VersionString
)
503 self
.VersionString
.Comments
= Comments
507 def GetVersionString(self
):
508 return self
.VersionString
510 def SetPcdIsDriver(self
, PcdIsDriver
, Comments
):
512 # Value has been set before.
514 if self
.PcdIsDriver
is not None:
515 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND\
516 %(DT
.TAB_INF_DEFINES_PCD_IS_DRIVER
),
517 LineInfo
=self
.CurrentLine
)
519 if PcdIsDriver
== 'PEI_PCD_DRIVER' or PcdIsDriver
== 'DXE_PCD_DRIVER':
520 self
.PcdIsDriver
= InfDefMember()
521 self
.PcdIsDriver
.SetValue(PcdIsDriver
)
522 self
.PcdIsDriver
.Comments
= Comments
525 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(PcdIsDriver),
526 LineInfo
=self
.CurrentLine
)
529 def GetPcdIsDriver(self
):
530 return self
.PcdIsDriver
535 def SetEntryPoint(self
, EntryPoint
, Comments
):
540 TokenList
= GetSplitValueList(EntryPoint
, DT
.TAB_VALUE_SPLIT
)
541 ValueList
[0:len(TokenList
)] = TokenList
542 InfDefineEntryPointItemObj
= InfDefineEntryPointItem()
543 if not IsValidCVariableName(ValueList
[0]):
544 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%\
546 LineInfo
=self
.CurrentLine
)
547 InfDefineEntryPointItemObj
.SetCName(ValueList
[0])
548 if len(ValueList
) == 2:
549 if ValueList
[1].strip() == '':
550 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%\
552 LineInfo
=self
.CurrentLine
)
556 FeatureFlagRtv
= IsValidFeatureFlagExp(ValueList
[1].strip())
557 if not FeatureFlagRtv
[0]:
558 ErrorInInf(ST
.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID
%\
560 LineInfo
=self
.CurrentLine
)
561 InfDefineEntryPointItemObj
.SetFeatureFlagExp(ValueList
[1])
562 if len(ValueList
) > 2:
563 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(EntryPoint),
564 LineInfo
=self
.CurrentLine
)
565 InfDefineEntryPointItemObj
.Comments
= Comments
566 self
.EntryPoint
.append(InfDefineEntryPointItemObj
)
568 def GetEntryPoint(self
):
569 return self
.EntryPoint
574 def SetUnloadImages(self
, UnloadImages
, Comments
):
579 TokenList
= GetSplitValueList(UnloadImages
, DT
.TAB_VALUE_SPLIT
)
580 ValueList
[0:len(TokenList
)] = TokenList
581 InfDefineUnloadImageItemObj
= InfDefineUnloadImageItem()
582 if not IsValidCVariableName(ValueList
[0]):
583 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(ValueList
[0]),
584 LineInfo
=self
.CurrentLine
)
585 InfDefineUnloadImageItemObj
.SetCName(ValueList
[0])
586 if len(ValueList
) == 2:
587 if ValueList
[1].strip() == '':
588 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(ValueList
[1]),
589 LineInfo
=self
.CurrentLine
)
593 FeatureFlagRtv
= IsValidFeatureFlagExp(ValueList
[1].strip())
594 if not FeatureFlagRtv
[0]:
595 ErrorInInf(ST
.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID
%(FeatureFlagRtv
[1]),
596 LineInfo
=self
.CurrentLine
)
597 InfDefineUnloadImageItemObj
.SetFeatureFlagExp(ValueList
[1])
599 if len(ValueList
) > 2:
600 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(UnloadImages),
601 LineInfo
=self
.CurrentLine
)
602 InfDefineUnloadImageItemObj
.Comments
= Comments
603 self
.UnloadImages
.append(InfDefineUnloadImageItemObj
)
605 def GetUnloadImages(self
):
606 return self
.UnloadImages
611 def SetConstructor(self
, Constructor
, Comments
):
616 TokenList
= GetSplitValueList(Constructor
, DT
.TAB_VALUE_SPLIT
)
617 ValueList
[0:len(TokenList
)] = TokenList
618 InfDefineConstructorItemObj
= InfDefineConstructorItem()
619 if not IsValidCVariableName(ValueList
[0]):
620 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(ValueList
[0]),
621 LineInfo
=self
.CurrentLine
)
622 InfDefineConstructorItemObj
.SetCName(ValueList
[0])
623 if len(ValueList
) >= 2:
624 ModList
= GetSplitValueList(ValueList
[1], ' ')
625 if ValueList
[1].strip() == '':
626 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(ValueList
[1]),
627 LineInfo
=self
.CurrentLine
)
628 for ModItem
in ModList
:
629 if ModItem
not in DT
.MODULE_LIST
:
630 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_MODULETYPE_INVALID
%(ModItem),
631 LineInfo
=self
.CurrentLine
)
632 InfDefineConstructorItemObj
.SetSupModList(ModList
)
633 if len(ValueList
) == 3:
634 if ValueList
[2].strip() == '':
635 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(ValueList
[2]),
636 LineInfo
=self
.CurrentLine
)
640 FeatureFlagRtv
= IsValidFeatureFlagExp(ValueList
[2].strip())
641 if not FeatureFlagRtv
[0]:
642 ErrorInInf(ST
.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID
%(FeatureFlagRtv
[2]),
643 LineInfo
=self
.CurrentLine
)
644 InfDefineConstructorItemObj
.SetFeatureFlagExp(ValueList
[2])
646 if len(ValueList
) > 3:
647 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(Constructor),
648 LineInfo
=self
.CurrentLine
)
649 InfDefineConstructorItemObj
.Comments
= Comments
650 self
.Constructor
.append(InfDefineConstructorItemObj
)
652 def GetConstructor(self
):
653 return self
.Constructor
658 def SetDestructor(self
, Destructor
, Comments
):
660 # It can be a list and only 1 set to TRUE
663 TokenList
= GetSplitValueList(Destructor
, DT
.TAB_VALUE_SPLIT
)
664 ValueList
[0:len(TokenList
)] = TokenList
665 InfDefineDestructorItemObj
= InfDefineDestructorItem()
666 if not IsValidCVariableName(ValueList
[0]):
667 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(ValueList
[0]),
668 LineInfo
=self
.CurrentLine
)
669 InfDefineDestructorItemObj
.SetCName(ValueList
[0])
670 if len(ValueList
) >= 2:
671 ModList
= GetSplitValueList(ValueList
[1].strip(), ' ')
672 if ValueList
[1].strip() == '':
673 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(ValueList
[1]),
674 LineInfo
=self
.CurrentLine
)
675 for ModItem
in ModList
:
676 if ModItem
not in DT
.MODULE_LIST
:
677 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_MODULETYPE_INVALID
%(ModItem),
678 LineInfo
=self
.CurrentLine
)
679 InfDefineDestructorItemObj
.SetSupModList(ModList
)
680 if len(ValueList
) == 3:
681 if ValueList
[2].strip() == '':
682 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(ValueList
[2]),
683 LineInfo
=self
.CurrentLine
)
687 FeatureFlagRtv
= IsValidFeatureFlagExp(ValueList
[2].strip())
688 if not FeatureFlagRtv
[0]:
689 ErrorInInf(ST
.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID
%(FeatureFlagRtv
[1]),
690 LineInfo
=self
.CurrentLine
)
691 InfDefineDestructorItemObj
.SetFeatureFlagExp(ValueList
[2])
693 if len(ValueList
) > 3:
694 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(Destructor),
695 LineInfo
=self
.CurrentLine
)
697 InfDefineDestructorItemObj
.Comments
= Comments
698 self
.Destructor
.append(InfDefineDestructorItemObj
)
700 def GetDestructor(self
):
701 return self
.Destructor
703 def SetShadow(self
, Shadow
, Comments
):
705 # Value has been set before.
707 if self
.Shadow
is not None:
708 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND
%(DT
.TAB_INF_DEFINES_SHADOW
),
709 LineInfo
=self
.CurrentLine
)
711 if (IsValidBoolType(Shadow
)):
712 self
.Shadow
= InfDefMember()
713 self
.Shadow
.SetValue(Shadow
)
714 self
.Shadow
.Comments
= Comments
717 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(Shadow),
718 LineInfo
=self
.CurrentLine
)
724 # <Family> ::= {"MSFT"} {"GCC"}
725 # <CustomMake> ::= [<Family> "|"] <Filename>
727 def SetCustomMakefile(self
, CustomMakefile
, Comments
):
728 if not (CustomMakefile
== '' or CustomMakefile
is None):
729 ValueList
= GetSplitValueList(CustomMakefile
)
730 if len(ValueList
) == 1:
731 FileName
= ValueList
[0]
734 Family
= ValueList
[0]
735 FileName
= ValueList
[1]
736 Family
= Family
.strip()
738 if not IsValidFamily(Family
):
739 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(Family),
740 LineInfo
=self
.CurrentLine
)
743 # The MakefileName specified file should exist
745 IsValidFileFlag
= False
746 ModulePath
= os
.path
.split(self
.CurrentLine
[0])[0]
747 if IsValidPath(FileName
, ModulePath
):
748 IsValidFileFlag
= True
750 ErrorInInf(ST
.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID
%(FileName),
751 LineInfo
=self
.CurrentLine
)
754 FileName
= ConvPathFromAbsToRel(FileName
, GlobalData
.gINF_MODULE_DIR
)
755 self
.CustomMakefile
.append((Family
, FileName
, Comments
))
756 IsValidFileFlag
= False
761 def GetCustomMakefile(self
):
762 return self
.CustomMakefile
765 # ["SPEC" <Spec> <EOL>]*{0,}
766 # <Spec> ::= <Word> "=" <VersionVal>
767 # <VersionVal> ::= {<HexVersion>] {<DecVersion>}
768 # <HexNumber> ::= "0x" [<HexDigit>]{1,}
769 # <DecVersion> ::= (0-9){1,} ["." (0-9){1,2}]
771 def SetSpecification(self
, Specification
, Comments
):
773 # Valid the value of Specification
776 TokenList
= GetSplitValueList(Specification
, DT
.TAB_EQUAL_SPLIT
, 1)
777 __ValueList
[0:len(TokenList
)] = TokenList
778 if len(__ValueList
) != 2:
779 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_NO_NAME
+ ' Or ' + ST
.ERR_INF_PARSER_DEFINE_ITEM_NO_VALUE
,
780 LineInfo
=self
.CurrentLine
)
781 Name
= __ValueList
[0].strip()
782 Version
= __ValueList
[1].strip()
783 if IsValidIdentifier(Name
):
784 if IsValidDecVersion(Version
):
785 self
.Specification
.append((Name
, Version
, Comments
))
788 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(Version),
789 LineInfo
=self
.CurrentLine
)
792 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(Name),
793 LineInfo
=self
.CurrentLine
)
797 def GetSpecification(self
):
798 return self
.Specification
801 # [<UefiHiiResource> <EOL>]{0,1}
802 # <UefiHiiResource> ::= "UEFI_HII_RESOURCE_SECTION" "=" <BoolType>
804 def SetUefiHiiResourceSection(self
, UefiHiiResourceSection
, Comments
):
806 # Value has been set before.
808 if self
.UefiHiiResourceSection
is not None:
809 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND
810 %(DT
.TAB_INF_DEFINES_UEFI_HII_RESOURCE_SECTION
),
811 LineInfo
=self
.CurrentLine
)
813 if not (UefiHiiResourceSection
== '' or UefiHiiResourceSection
is None):
814 if (IsValidBoolType(UefiHiiResourceSection
)):
815 self
.UefiHiiResourceSection
= InfDefMember()
816 self
.UefiHiiResourceSection
.SetValue(UefiHiiResourceSection
)
817 self
.UefiHiiResourceSection
.Comments
= Comments
820 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(UefiHiiResourceSection),
821 LineInfo
=self
.CurrentLine
)
826 def GetUefiHiiResourceSection(self
):
827 return self
.UefiHiiResourceSection
829 def SetDpxSource(self
, DpxSource
, Comments
):
831 # The MakefileName specified file should exist
833 IsValidFileFlag
= False
834 ModulePath
= os
.path
.split(self
.CurrentLine
[0])[0]
835 if IsValidPath(DpxSource
, ModulePath
):
836 IsValidFileFlag
= True
838 ErrorInInf(ST
.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID
%(DpxSource),
839 LineInfo
=self
.CurrentLine
)
842 DpxSource
= ConvPathFromAbsToRel(DpxSource
,
843 GlobalData
.gINF_MODULE_DIR
)
844 self
.DpxSource
.append((DpxSource
, Comments
))
845 IsValidFileFlag
= False
848 def GetDpxSource(self
):
849 return self
.DpxSource
851 gFUNCTION_MAPPING_FOR_DEFINE_SECTION
= {
855 DT
.TAB_INF_DEFINES_BASE_NAME
: InfDefSection
.SetBaseName
,
856 DT
.TAB_INF_DEFINES_FILE_GUID
: InfDefSection
.SetFileGuid
,
857 DT
.TAB_INF_DEFINES_MODULE_TYPE
: InfDefSection
.SetModuleType
,
859 # Required by EDKII style INF file
861 DT
.TAB_INF_DEFINES_INF_VERSION
: InfDefSection
.SetInfVersion
,
865 DT
.TAB_INF_DEFINES_MODULE_UNI_FILE
: InfDefSection
.SetModuleUniFileName
,
866 DT
.TAB_INF_DEFINES_EDK_RELEASE_VERSION
: InfDefSection
.SetEdkReleaseVersion
,
867 DT
.TAB_INF_DEFINES_UEFI_SPECIFICATION_VERSION
: InfDefSection
.SetUefiSpecificationVersion
,
868 DT
.TAB_INF_DEFINES_PI_SPECIFICATION_VERSION
: InfDefSection
.SetPiSpecificationVersion
,
869 DT
.TAB_INF_DEFINES_LIBRARY_CLASS
: InfDefSection
.SetLibraryClass
,
870 DT
.TAB_INF_DEFINES_VERSION_STRING
: InfDefSection
.SetVersionString
,
871 DT
.TAB_INF_DEFINES_PCD_IS_DRIVER
: InfDefSection
.SetPcdIsDriver
,
872 DT
.TAB_INF_DEFINES_ENTRY_POINT
: InfDefSection
.SetEntryPoint
,
873 DT
.TAB_INF_DEFINES_UNLOAD_IMAGE
: InfDefSection
.SetUnloadImages
,
874 DT
.TAB_INF_DEFINES_CONSTRUCTOR
: InfDefSection
.SetConstructor
,
875 DT
.TAB_INF_DEFINES_DESTRUCTOR
: InfDefSection
.SetDestructor
,
876 DT
.TAB_INF_DEFINES_SHADOW
: InfDefSection
.SetShadow
,
877 DT
.TAB_INF_DEFINES_PCI_VENDOR_ID
: InfDefSection
.SetPciVendorId
,
878 DT
.TAB_INF_DEFINES_PCI_DEVICE_ID
: InfDefSection
.SetPciDeviceId
,
879 DT
.TAB_INF_DEFINES_PCI_CLASS_CODE
: InfDefSection
.SetPciClassCode
,
880 DT
.TAB_INF_DEFINES_PCI_REVISION
: InfDefSection
.SetPciRevision
,
881 DT
.TAB_INF_DEFINES_PCI_COMPRESS
: InfDefSection
.SetPciCompress
,
882 DT
.TAB_INF_DEFINES_CUSTOM_MAKEFILE
: InfDefSection
.SetCustomMakefile
,
883 DT
.TAB_INF_DEFINES_SPEC
: InfDefSection
.SetSpecification
,
884 DT
.TAB_INF_DEFINES_UEFI_HII_RESOURCE_SECTION
: InfDefSection
.SetUefiHiiResourceSection
,
885 DT
.TAB_INF_DEFINES_DPX_SOURCE
: InfDefSection
.SetDpxSource
891 class InfDefMember():
892 def __init__(self
, Name
='', Value
=''):
893 self
.Comments
= InfLineCommentObject()
896 self
.CurrentLine
= CurrentLine()
899 def SetName(self
, Name
):
903 def SetValue(self
, Value
):
909 class InfDefObject(InfSectionCommonDef
):
911 self
.Defines
= Sdict()
912 InfSectionCommonDef
.__init
__(self
)
913 def SetDefines(self
, DefineContent
, Arch
= None):
917 HasFoundInfVersionFalg
= False
918 LineInfo
= ['', -1, '']
919 ArchListString
= ' '.join(Arch
)
921 # Parse Define items.
923 for InfDefMemberObj
in DefineContent
:
925 Name
= InfDefMemberObj
.GetName()
926 Value
= InfDefMemberObj
.GetValue()
927 if Name
== DT
.TAB_INF_DEFINES_MODULE_UNI_FILE
:
928 ValidateUNIFilePath(Value
)
929 Value
= os
.path
.join(os
.path
.dirname(InfDefMemberObj
.CurrentLine
.FileName
), Value
)
930 if not os
.path
.isfile(Value
) or not os
.path
.exists(Value
):
931 LineInfo
[0] = InfDefMemberObj
.CurrentLine
.GetFileName()
932 LineInfo
[1] = InfDefMemberObj
.CurrentLine
.GetLineNo()
933 LineInfo
[2] = InfDefMemberObj
.CurrentLine
.GetLineString()
934 ErrorInInf(ST
.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID
%(Name),
936 InfLineCommentObj
= InfLineCommentObject()
937 InfLineCommentObj
.SetHeaderComments(InfDefMemberObj
.Comments
.GetHeaderComments())
938 InfLineCommentObj
.SetTailComments(InfDefMemberObj
.Comments
.GetTailComments())
939 if Name
== 'COMPONENT_TYPE':
940 ErrorInInf(ST
.ERR_INF_PARSER_NOT_SUPPORT_EDKI_INF
,
941 ErrorCode
=ToolError
.EDK1_INF_ERROR
,
943 if Name
== DT
.TAB_INF_DEFINES_INF_VERSION
:
944 HasFoundInfVersionFalg
= True
945 if not (Name
== '' or Name
is None):
947 # Process "SPEC" Keyword definition.
949 ReName
= re
.compile(r
"SPEC ", re
.DOTALL
)
950 if ReName
.match(Name
):
951 SpecValue
= Name
[Name
.find("SPEC") + len("SPEC"):].strip()
953 Value
= SpecValue
+ " = " + Value
954 if ArchListString
in self
.Defines
:
955 DefineList
= self
.Defines
[ArchListString
]
956 LineInfo
[0] = InfDefMemberObj
.CurrentLine
.GetFileName()
957 LineInfo
[1] = InfDefMemberObj
.CurrentLine
.GetLineNo()
958 LineInfo
[2] = InfDefMemberObj
.CurrentLine
.GetLineString()
959 DefineList
.CurrentLine
= LineInfo
961 # Found the process function from mapping table.
963 if Name
not in gFUNCTION_MAPPING_FOR_DEFINE_SECTION
.keys():
964 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_SECTION_KEYWORD_INVALID
%(Name),
967 ProcessFunc
= gFUNCTION_MAPPING_FOR_DEFINE_SECTION
[Name
]
968 if (ProcessFunc
is not None):
969 ProcessFunc(DefineList
, Value
, InfLineCommentObj
)
970 self
.Defines
[ArchListString
] = DefineList
972 DefineList
= InfDefSection()
973 LineInfo
[0] = InfDefMemberObj
.CurrentLine
.GetFileName()
974 LineInfo
[1] = InfDefMemberObj
.CurrentLine
.GetLineNo()
975 LineInfo
[2] = InfDefMemberObj
.CurrentLine
.GetLineString()
976 DefineList
.CurrentLine
= LineInfo
978 # Found the process function from mapping table.
980 if Name
not in gFUNCTION_MAPPING_FOR_DEFINE_SECTION
.keys():
981 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_SECTION_KEYWORD_INVALID
%(Name),
984 # Found the process function from mapping table.
987 ProcessFunc
= gFUNCTION_MAPPING_FOR_DEFINE_SECTION
[Name
]
988 if (ProcessFunc
is not None):
989 ProcessFunc(DefineList
, Value
, InfLineCommentObj
)
990 self
.Defines
[ArchListString
] = DefineList
992 # After set, check whether INF_VERSION defined.
994 if not HasFoundInfVersionFalg
:
995 ErrorInInf(ST
.ERR_INF_PARSER_NOT_SUPPORT_EDKI_INF
,
996 ErrorCode
=ToolError
.EDK1_INF_ERROR
,
1000 def GetDefines(self
):