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 # 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.
22 from Logger
import StringTable
as ST
23 from Logger
import ToolError
24 from Library
import GlobalData
25 from Library
import DataType
as DT
26 from Library
.StringUtils
import GetSplitValueList
27 from Library
.Misc
import CheckGuidRegFormat
28 from Library
.Misc
import Sdict
29 from Library
.Misc
import ConvPathFromAbsToRel
30 from Library
.Misc
import ValidateUNIFilePath
31 from Library
.ExpressionValidate
import IsValidFeatureFlagExp
32 from Library
.ParserValidate
import IsValidWord
33 from Library
.ParserValidate
import IsValidInfMoudleType
34 from Library
.ParserValidate
import IsValidHex
35 from Library
.ParserValidate
import IsValidHexVersion
36 from Library
.ParserValidate
import IsValidDecVersion
37 from Library
.ParserValidate
import IsValidCVariableName
38 from Library
.ParserValidate
import IsValidBoolType
39 from Library
.ParserValidate
import IsValidPath
40 from Library
.ParserValidate
import IsValidFamily
41 from Library
.ParserValidate
import IsValidIdentifier
42 from Library
.ParserValidate
import IsValidDecVersionVal
43 from Object
.Parser
.InfCommonObject
import InfLineCommentObject
44 from Object
.Parser
.InfCommonObject
import CurrentLine
45 from Object
.Parser
.InfCommonObject
import InfSectionCommonDef
46 from Object
.Parser
.InfMisc
import ErrorInInf
47 from Object
.Parser
.InfDefineCommonObject
import InfDefineLibraryItem
48 from Object
.Parser
.InfDefineCommonObject
import InfDefineEntryPointItem
49 from Object
.Parser
.InfDefineCommonObject
import InfDefineUnloadImageItem
50 from Object
.Parser
.InfDefineCommonObject
import InfDefineConstructorItem
51 from Object
.Parser
.InfDefineCommonObject
import InfDefineDestructorItem
53 class InfDefSectionOptionRomInfo():
55 self
.PciVendorId
= None
56 self
.PciDeviceId
= None
57 self
.PciClassCode
= None
58 self
.PciRevision
= None
59 self
.PciCompress
= None
60 self
.CurrentLine
= ['', -1, '']
61 def SetPciVendorId(self
, PciVendorId
, Comments
):
63 # Value has been set before.
65 if self
.PciVendorId
is not None:
66 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND
%(DT
.TAB_INF_DEFINES_PCI_VENDOR_ID
),
67 LineInfo
=self
.CurrentLine
)
70 # The PciVendorId should be hex string.
72 if (IsValidHex(PciVendorId
)):
73 self
.PciVendorId
= InfDefMember()
74 self
.PciVendorId
.SetValue(PciVendorId
)
75 self
.PciVendorId
.Comments
= Comments
78 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(PciVendorId),
79 LineInfo
=self
.CurrentLine
)
82 def GetPciVendorId(self
):
83 return self
.PciVendorId
85 def SetPciDeviceId(self
, PciDeviceId
, Comments
):
87 # Value has been set before.
89 if self
.PciDeviceId
is not None:
90 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND
%(DT
.TAB_INF_DEFINES_PCI_DEVICE_ID
),
91 LineInfo
=self
.CurrentLine
)
94 # The PciDeviceId should be hex string.
96 if (IsValidHex(PciDeviceId
)):
97 self
.PciDeviceId
= InfDefMember()
98 self
.PciDeviceId
.SetValue(PciDeviceId
)
99 self
.PciDeviceId
.Comments
= Comments
102 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(PciDeviceId),
103 LineInfo
=self
.CurrentLine
)
106 def GetPciDeviceId(self
):
107 return self
.PciDeviceId
109 def SetPciClassCode(self
, PciClassCode
, Comments
):
111 # Value has been set before.
113 if self
.PciClassCode
is not None:
114 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND
%(DT
.TAB_INF_DEFINES_PCI_CLASS_CODE
),
115 LineInfo
=self
.CurrentLine
)
118 # The PciClassCode should be 4 bytes hex string.
120 if (IsValidHex(PciClassCode
)):
121 self
.PciClassCode
= InfDefMember()
122 self
.PciClassCode
.SetValue(PciClassCode
)
123 self
.PciClassCode
.Comments
= Comments
126 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%\
128 LineInfo
=self
.CurrentLine
)
131 def GetPciClassCode(self
):
132 return self
.PciClassCode
134 def SetPciRevision(self
, PciRevision
, Comments
):
136 # Value has been set before.
138 if self
.PciRevision
is not None:
139 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND
%(DT
.TAB_INF_DEFINES_PCI_REVISION
),
140 LineInfo
=self
.CurrentLine
)
143 # The PciRevision should be 4 bytes hex string.
145 if (IsValidHex(PciRevision
)):
146 self
.PciRevision
= InfDefMember()
147 self
.PciRevision
.SetValue(PciRevision
)
148 self
.PciRevision
.Comments
= Comments
151 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(PciRevision),
152 LineInfo
=self
.CurrentLine
)
155 def GetPciRevision(self
):
156 return self
.PciRevision
158 def SetPciCompress(self
, PciCompress
, Comments
):
160 # Value has been set before.
162 if self
.PciCompress
is not None:
163 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND
%(DT
.TAB_INF_DEFINES_PCI_COMPRESS
),
164 LineInfo
=self
.CurrentLine
)
168 # The PciCompress should be 'TRUE' or 'FALSE'.
170 if (PciCompress
== 'TRUE' or PciCompress
== 'FALSE'):
171 self
.PciCompress
= InfDefMember()
172 self
.PciCompress
.SetValue(PciCompress
)
173 self
.PciCompress
.Comments
= Comments
176 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(PciCompress),
177 LineInfo
=self
.CurrentLine
)
179 def GetPciCompress(self
):
180 return self
.PciCompress
182 # INF [Define] section Object
184 class InfDefSection(InfDefSectionOptionRomInfo
):
188 self
.ModuleType
= None
189 self
.ModuleUniFileName
= None
190 self
.InfVersion
= None
191 self
.EdkReleaseVersion
= None
192 self
.UefiSpecificationVersion
= None
193 self
.PiSpecificationVersion
= None
194 self
.LibraryClass
= []
196 self
.VersionString
= None
197 self
.PcdIsDriver
= None
199 self
.UnloadImages
= []
200 self
.Constructor
= []
203 self
.CustomMakefile
= []
204 self
.Specification
= []
205 self
.UefiHiiResourceSection
= None
207 self
.CurrentLine
= ['', -1, '']
208 InfDefSectionOptionRomInfo
.__init
__(self
)
212 # @param BaseName: BaseName
214 def SetBaseName(self
, BaseName
, Comments
):
216 # Value has been set before.
218 if self
.BaseName
is not None:
219 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND
%(DT
.TAB_INF_DEFINES_BASE_NAME
),
220 LineInfo
=self
.CurrentLine
)
222 if not (BaseName
== '' or BaseName
is None):
223 if IsValidWord(BaseName
) and not BaseName
.startswith("_"):
224 self
.BaseName
= InfDefMember()
225 self
.BaseName
.SetValue(BaseName
)
226 self
.BaseName
.Comments
= Comments
229 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_NAME_INVALID
%(BaseName),
230 LineInfo
=self
.CurrentLine
)
235 def GetBaseName(self
):
240 # @param FileGuid: FileGuid
242 def SetFileGuid(self
, FileGuid
, Comments
):
244 # Value has been set before.
246 if self
.FileGuid
is not None:
247 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND\
248 %(DT
.TAB_INF_DEFINES_FILE_GUID
),
249 LineInfo
=self
.CurrentLine
)
252 # Do verification of GUID content/format
254 if (CheckGuidRegFormat(FileGuid
)):
255 self
.FileGuid
= InfDefMember()
256 self
.FileGuid
.SetValue(FileGuid
)
257 self
.FileGuid
.Comments
= Comments
260 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_GUID_INVALID
%(FileGuid),
261 LineInfo
=self
.CurrentLine
)
266 def GetFileGuid(self
):
271 # @param ModuleType: ModuleType
273 def SetModuleType(self
, ModuleType
, Comments
):
275 # Value has been set before.
277 if self
.ModuleType
is not None:
278 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND\
279 %(DT
.TAB_INF_DEFINES_MODULE_TYPE
),
280 LineInfo
=self
.CurrentLine
)
283 # Valid Module Type or not
285 if (IsValidInfMoudleType(ModuleType
)):
286 self
.ModuleType
= InfDefMember()
287 self
.ModuleType
.SetValue(ModuleType
)
288 self
.ModuleType
.CurrentLine
= CurrentLine()
289 self
.ModuleType
.CurrentLine
.SetLineNo(self
.CurrentLine
[1])
290 self
.ModuleType
.CurrentLine
.SetLineString(self
.CurrentLine
[2])
291 self
.ModuleType
.CurrentLine
.SetFileName(self
.CurrentLine
[0])
292 self
.ModuleType
.Comments
= Comments
295 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_MODULETYPE_INVALID
%\
297 LineInfo
=self
.CurrentLine
)
302 def GetModuleType(self
):
303 return self
.ModuleType
305 ## SetModuleUniFileName
307 # @param ModuleUniFileName: ModuleUniFileName
309 def SetModuleUniFileName(self
, ModuleUniFileName
, Comments
):
312 if self
.ModuleUniFileName
is not None:
313 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND
%(DT
.TAB_INF_DEFINES_MODULE_UNI_FILE
),
314 LineInfo
=self
.CurrentLine
)
315 self
.ModuleUniFileName
= ModuleUniFileName
319 def GetModuleUniFileName(self
):
320 return self
.ModuleUniFileName
324 # @param InfVersion: InfVersion
326 def SetInfVersion(self
, InfVersion
, Comments
):
328 # Value has been set before.
330 if self
.InfVersion
is not None:
331 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND\
332 %(DT
.TAB_INF_DEFINES_INF_VERSION
),
333 LineInfo
=self
.CurrentLine
)
336 # The InfVersion should be 4 bytes hex string.
338 if (IsValidHex(InfVersion
)):
339 if (InfVersion
< '0x00010005'):
340 ErrorInInf(ST
.ERR_INF_PARSER_NOT_SUPPORT_EDKI_INF
,
341 ErrorCode
=ToolError
.EDK1_INF_ERROR
,
342 LineInfo
=self
.CurrentLine
)
343 elif IsValidDecVersionVal(InfVersion
):
344 if (InfVersion
< 65541):
345 ErrorInInf(ST
.ERR_INF_PARSER_NOT_SUPPORT_EDKI_INF
,
346 ErrorCode
=ToolError
.EDK1_INF_ERROR
,
347 LineInfo
=self
.CurrentLine
)
349 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(InfVersion),
350 LineInfo
=self
.CurrentLine
)
353 self
.InfVersion
= InfDefMember()
354 self
.InfVersion
.SetValue(InfVersion
)
355 self
.InfVersion
.Comments
= Comments
360 def GetInfVersion(self
):
361 return self
.InfVersion
363 ## SetEdkReleaseVersion
365 # @param EdkReleaseVersion: EdkReleaseVersion
367 def SetEdkReleaseVersion(self
, EdkReleaseVersion
, Comments
):
369 # Value has been set before.
371 if self
.EdkReleaseVersion
is not None:
372 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND\
373 %(DT
.TAB_INF_DEFINES_EDK_RELEASE_VERSION
),
374 LineInfo
=self
.CurrentLine
)
377 # The EdkReleaseVersion should be 4 bytes hex string.
379 if IsValidHexVersion(EdkReleaseVersion
) or \
380 IsValidDecVersionVal(EdkReleaseVersion
):
381 self
.EdkReleaseVersion
= InfDefMember()
382 self
.EdkReleaseVersion
.SetValue(EdkReleaseVersion
)
383 self
.EdkReleaseVersion
.Comments
= Comments
386 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID\
387 %(EdkReleaseVersion),
388 LineInfo
=self
.CurrentLine
)
391 ## GetEdkReleaseVersion
393 def GetEdkReleaseVersion(self
):
394 return self
.EdkReleaseVersion
396 ## SetUefiSpecificationVersion
398 # @param UefiSpecificationVersion: UefiSpecificationVersion
400 def SetUefiSpecificationVersion(self
, UefiSpecificationVersion
, Comments
):
402 # Value has been set before.
404 if self
.UefiSpecificationVersion
is not None:
405 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND\
406 %(DT
.TAB_INF_DEFINES_UEFI_SPECIFICATION_VERSION
),
407 LineInfo
=self
.CurrentLine
)
410 # The EdkReleaseVersion should be 4 bytes hex string.
412 if IsValidHexVersion(UefiSpecificationVersion
) or \
413 IsValidDecVersionVal(UefiSpecificationVersion
):
414 self
.UefiSpecificationVersion
= InfDefMember()
415 self
.UefiSpecificationVersion
.SetValue(UefiSpecificationVersion
)
416 self
.UefiSpecificationVersion
.Comments
= Comments
419 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID\
420 %(UefiSpecificationVersion),
421 LineInfo
=self
.CurrentLine
)
424 ## GetUefiSpecificationVersion
426 def GetUefiSpecificationVersion(self
):
427 return self
.UefiSpecificationVersion
429 ## SetPiSpecificationVersion
431 # @param PiSpecificationVersion: PiSpecificationVersion
433 def SetPiSpecificationVersion(self
, PiSpecificationVersion
, Comments
):
435 # Value has been set before.
437 if self
.PiSpecificationVersion
is not None:
438 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND\
439 %(DT
.TAB_INF_DEFINES_PI_SPECIFICATION_VERSION
),
440 LineInfo
=self
.CurrentLine
)
443 # The EdkReleaseVersion should be 4 bytes hex string.
445 if IsValidHexVersion(PiSpecificationVersion
) or \
446 IsValidDecVersionVal(PiSpecificationVersion
):
447 self
.PiSpecificationVersion
= InfDefMember()
448 self
.PiSpecificationVersion
.SetValue(PiSpecificationVersion
)
449 self
.PiSpecificationVersion
.Comments
= Comments
452 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID\
453 %(PiSpecificationVersion),
454 LineInfo
=self
.CurrentLine
)
457 ## GetPiSpecificationVersion
459 def GetPiSpecificationVersion(self
):
460 return self
.PiSpecificationVersion
464 # @param LibraryClass: LibraryClass
466 def SetLibraryClass(self
, LibraryClass
, Comments
):
467 ValueList
= GetSplitValueList(LibraryClass
)
469 if IsValidWord(Name
):
470 InfDefineLibraryItemObj
= InfDefineLibraryItem()
471 InfDefineLibraryItemObj
.SetLibraryName(Name
)
472 InfDefineLibraryItemObj
.Comments
= Comments
473 if len(ValueList
) == 2:
475 TypeList
= GetSplitValueList(Type
, ' ')
476 TypeList
= [Type
for Type
in TypeList
if Type
!= '']
477 for Item
in TypeList
:
478 if Item
not in DT
.MODULE_LIST
:
479 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(Item),
480 LineInfo
=self
.CurrentLine
)
482 InfDefineLibraryItemObj
.SetTypes(TypeList
)
483 self
.LibraryClass
.append(InfDefineLibraryItemObj
)
485 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(Name),
486 LineInfo
=self
.CurrentLine
)
491 def GetLibraryClass(self
):
492 return self
.LibraryClass
494 def SetVersionString(self
, VersionString
, Comments
):
496 # Value has been set before.
498 if self
.VersionString
is not None:
499 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND\
500 %(DT
.TAB_INF_DEFINES_VERSION_STRING
),
501 LineInfo
=self
.CurrentLine
)
503 if not IsValidDecVersion(VersionString
):
504 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID\
506 LineInfo
=self
.CurrentLine
)
507 self
.VersionString
= InfDefMember()
508 self
.VersionString
.SetValue(VersionString
)
509 self
.VersionString
.Comments
= Comments
513 def GetVersionString(self
):
514 return self
.VersionString
516 def SetPcdIsDriver(self
, PcdIsDriver
, Comments
):
518 # Value has been set before.
520 if self
.PcdIsDriver
is not None:
521 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND\
522 %(DT
.TAB_INF_DEFINES_PCD_IS_DRIVER
),
523 LineInfo
=self
.CurrentLine
)
525 if PcdIsDriver
== 'PEI_PCD_DRIVER' or PcdIsDriver
== 'DXE_PCD_DRIVER':
526 self
.PcdIsDriver
= InfDefMember()
527 self
.PcdIsDriver
.SetValue(PcdIsDriver
)
528 self
.PcdIsDriver
.Comments
= Comments
531 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(PcdIsDriver),
532 LineInfo
=self
.CurrentLine
)
535 def GetPcdIsDriver(self
):
536 return self
.PcdIsDriver
541 def SetEntryPoint(self
, EntryPoint
, Comments
):
546 TokenList
= GetSplitValueList(EntryPoint
, DT
.TAB_VALUE_SPLIT
)
547 ValueList
[0:len(TokenList
)] = TokenList
548 InfDefineEntryPointItemObj
= InfDefineEntryPointItem()
549 if not IsValidCVariableName(ValueList
[0]):
550 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%\
552 LineInfo
=self
.CurrentLine
)
553 InfDefineEntryPointItemObj
.SetCName(ValueList
[0])
554 if len(ValueList
) == 2:
555 if ValueList
[1].strip() == '':
556 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%\
558 LineInfo
=self
.CurrentLine
)
562 FeatureFlagRtv
= IsValidFeatureFlagExp(ValueList
[1].strip())
563 if not FeatureFlagRtv
[0]:
564 ErrorInInf(ST
.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID
%\
566 LineInfo
=self
.CurrentLine
)
567 InfDefineEntryPointItemObj
.SetFeatureFlagExp(ValueList
[1])
568 if len(ValueList
) > 2:
569 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(EntryPoint),
570 LineInfo
=self
.CurrentLine
)
571 InfDefineEntryPointItemObj
.Comments
= Comments
572 self
.EntryPoint
.append(InfDefineEntryPointItemObj
)
574 def GetEntryPoint(self
):
575 return self
.EntryPoint
580 def SetUnloadImages(self
, UnloadImages
, Comments
):
585 TokenList
= GetSplitValueList(UnloadImages
, DT
.TAB_VALUE_SPLIT
)
586 ValueList
[0:len(TokenList
)] = TokenList
587 InfDefineUnloadImageItemObj
= InfDefineUnloadImageItem()
588 if not IsValidCVariableName(ValueList
[0]):
589 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(ValueList
[0]),
590 LineInfo
=self
.CurrentLine
)
591 InfDefineUnloadImageItemObj
.SetCName(ValueList
[0])
592 if len(ValueList
) == 2:
593 if ValueList
[1].strip() == '':
594 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(ValueList
[1]),
595 LineInfo
=self
.CurrentLine
)
599 FeatureFlagRtv
= IsValidFeatureFlagExp(ValueList
[1].strip())
600 if not FeatureFlagRtv
[0]:
601 ErrorInInf(ST
.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID
%(FeatureFlagRtv
[1]),
602 LineInfo
=self
.CurrentLine
)
603 InfDefineUnloadImageItemObj
.SetFeatureFlagExp(ValueList
[1])
605 if len(ValueList
) > 2:
606 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(UnloadImages),
607 LineInfo
=self
.CurrentLine
)
608 InfDefineUnloadImageItemObj
.Comments
= Comments
609 self
.UnloadImages
.append(InfDefineUnloadImageItemObj
)
611 def GetUnloadImages(self
):
612 return self
.UnloadImages
617 def SetConstructor(self
, Constructor
, Comments
):
622 TokenList
= GetSplitValueList(Constructor
, DT
.TAB_VALUE_SPLIT
)
623 ValueList
[0:len(TokenList
)] = TokenList
624 InfDefineConstructorItemObj
= InfDefineConstructorItem()
625 if not IsValidCVariableName(ValueList
[0]):
626 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(ValueList
[0]),
627 LineInfo
=self
.CurrentLine
)
628 InfDefineConstructorItemObj
.SetCName(ValueList
[0])
629 if len(ValueList
) >= 2:
630 ModList
= GetSplitValueList(ValueList
[1], ' ')
631 if ValueList
[1].strip() == '':
632 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(ValueList
[1]),
633 LineInfo
=self
.CurrentLine
)
634 for ModItem
in ModList
:
635 if ModItem
not in DT
.MODULE_LIST
:
636 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_MODULETYPE_INVALID
%(ModItem),
637 LineInfo
=self
.CurrentLine
)
638 InfDefineConstructorItemObj
.SetSupModList(ModList
)
639 if len(ValueList
) == 3:
640 if ValueList
[2].strip() == '':
641 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(ValueList
[2]),
642 LineInfo
=self
.CurrentLine
)
646 FeatureFlagRtv
= IsValidFeatureFlagExp(ValueList
[2].strip())
647 if not FeatureFlagRtv
[0]:
648 ErrorInInf(ST
.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID
%(FeatureFlagRtv
[2]),
649 LineInfo
=self
.CurrentLine
)
650 InfDefineConstructorItemObj
.SetFeatureFlagExp(ValueList
[2])
652 if len(ValueList
) > 3:
653 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(Constructor),
654 LineInfo
=self
.CurrentLine
)
655 InfDefineConstructorItemObj
.Comments
= Comments
656 self
.Constructor
.append(InfDefineConstructorItemObj
)
658 def GetConstructor(self
):
659 return self
.Constructor
664 def SetDestructor(self
, Destructor
, Comments
):
666 # It can be a list and only 1 set to TRUE
669 TokenList
= GetSplitValueList(Destructor
, DT
.TAB_VALUE_SPLIT
)
670 ValueList
[0:len(TokenList
)] = TokenList
671 InfDefineDestructorItemObj
= InfDefineDestructorItem()
672 if not IsValidCVariableName(ValueList
[0]):
673 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(ValueList
[0]),
674 LineInfo
=self
.CurrentLine
)
675 InfDefineDestructorItemObj
.SetCName(ValueList
[0])
676 if len(ValueList
) >= 2:
677 ModList
= GetSplitValueList(ValueList
[1].strip(), ' ')
678 if ValueList
[1].strip() == '':
679 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(ValueList
[1]),
680 LineInfo
=self
.CurrentLine
)
681 for ModItem
in ModList
:
682 if ModItem
not in DT
.MODULE_LIST
:
683 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_MODULETYPE_INVALID
%(ModItem),
684 LineInfo
=self
.CurrentLine
)
685 InfDefineDestructorItemObj
.SetSupModList(ModList
)
686 if len(ValueList
) == 3:
687 if ValueList
[2].strip() == '':
688 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(ValueList
[2]),
689 LineInfo
=self
.CurrentLine
)
693 FeatureFlagRtv
= IsValidFeatureFlagExp(ValueList
[2].strip())
694 if not FeatureFlagRtv
[0]:
695 ErrorInInf(ST
.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID
%(FeatureFlagRtv
[1]),
696 LineInfo
=self
.CurrentLine
)
697 InfDefineDestructorItemObj
.SetFeatureFlagExp(ValueList
[2])
699 if len(ValueList
) > 3:
700 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(Destructor),
701 LineInfo
=self
.CurrentLine
)
703 InfDefineDestructorItemObj
.Comments
= Comments
704 self
.Destructor
.append(InfDefineDestructorItemObj
)
706 def GetDestructor(self
):
707 return self
.Destructor
709 def SetShadow(self
, Shadow
, Comments
):
711 # Value has been set before.
713 if self
.Shadow
is not None:
714 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND
%(DT
.TAB_INF_DEFINES_SHADOW
),
715 LineInfo
=self
.CurrentLine
)
717 if (IsValidBoolType(Shadow
)):
718 self
.Shadow
= InfDefMember()
719 self
.Shadow
.SetValue(Shadow
)
720 self
.Shadow
.Comments
= Comments
723 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(Shadow),
724 LineInfo
=self
.CurrentLine
)
730 # <Family> ::= {"MSFT"} {"GCC"}
731 # <CustomMake> ::= [<Family> "|"] <Filename>
733 def SetCustomMakefile(self
, CustomMakefile
, Comments
):
734 if not (CustomMakefile
== '' or CustomMakefile
is None):
735 ValueList
= GetSplitValueList(CustomMakefile
)
736 if len(ValueList
) == 1:
737 FileName
= ValueList
[0]
740 Family
= ValueList
[0]
741 FileName
= ValueList
[1]
742 Family
= Family
.strip()
744 if not IsValidFamily(Family
):
745 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(Family),
746 LineInfo
=self
.CurrentLine
)
749 # The MakefileName specified file should exist
751 IsValidFileFlag
= False
752 ModulePath
= os
.path
.split(self
.CurrentLine
[0])[0]
753 if IsValidPath(FileName
, ModulePath
):
754 IsValidFileFlag
= True
756 ErrorInInf(ST
.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID
%(FileName),
757 LineInfo
=self
.CurrentLine
)
760 FileName
= ConvPathFromAbsToRel(FileName
, GlobalData
.gINF_MODULE_DIR
)
761 self
.CustomMakefile
.append((Family
, FileName
, Comments
))
762 IsValidFileFlag
= False
767 def GetCustomMakefile(self
):
768 return self
.CustomMakefile
771 # ["SPEC" <Spec> <EOL>]*{0,}
772 # <Spec> ::= <Word> "=" <VersionVal>
773 # <VersionVal> ::= {<HexVersion>] {<DecVersion>}
774 # <HexNumber> ::= "0x" [<HexDigit>]{1,}
775 # <DecVersion> ::= (0-9){1,} ["." (0-9){1,2}]
777 def SetSpecification(self
, Specification
, Comments
):
779 # Valid the value of Specification
782 TokenList
= GetSplitValueList(Specification
, DT
.TAB_EQUAL_SPLIT
, 1)
783 __ValueList
[0:len(TokenList
)] = TokenList
784 if len(__ValueList
) != 2:
785 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_NO_NAME
+ ' Or ' + ST
.ERR_INF_PARSER_DEFINE_ITEM_NO_VALUE
,
786 LineInfo
=self
.CurrentLine
)
787 Name
= __ValueList
[0].strip()
788 Version
= __ValueList
[1].strip()
789 if IsValidIdentifier(Name
):
790 if IsValidDecVersion(Version
):
791 self
.Specification
.append((Name
, Version
, Comments
))
794 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(Version),
795 LineInfo
=self
.CurrentLine
)
798 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(Name),
799 LineInfo
=self
.CurrentLine
)
803 def GetSpecification(self
):
804 return self
.Specification
807 # [<UefiHiiResource> <EOL>]{0,1}
808 # <UefiHiiResource> ::= "UEFI_HII_RESOURCE_SECTION" "=" <BoolType>
810 def SetUefiHiiResourceSection(self
, UefiHiiResourceSection
, Comments
):
812 # Value has been set before.
814 if self
.UefiHiiResourceSection
is not None:
815 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_ITEM_MORE_THAN_ONE_FOUND
816 %(DT
.TAB_INF_DEFINES_UEFI_HII_RESOURCE_SECTION
),
817 LineInfo
=self
.CurrentLine
)
819 if not (UefiHiiResourceSection
== '' or UefiHiiResourceSection
is None):
820 if (IsValidBoolType(UefiHiiResourceSection
)):
821 self
.UefiHiiResourceSection
= InfDefMember()
822 self
.UefiHiiResourceSection
.SetValue(UefiHiiResourceSection
)
823 self
.UefiHiiResourceSection
.Comments
= Comments
826 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_FROMAT_INVALID
%(UefiHiiResourceSection),
827 LineInfo
=self
.CurrentLine
)
832 def GetUefiHiiResourceSection(self
):
833 return self
.UefiHiiResourceSection
835 def SetDpxSource(self
, DpxSource
, Comments
):
837 # The MakefileName specified file should exist
839 IsValidFileFlag
= False
840 ModulePath
= os
.path
.split(self
.CurrentLine
[0])[0]
841 if IsValidPath(DpxSource
, ModulePath
):
842 IsValidFileFlag
= True
844 ErrorInInf(ST
.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID
%(DpxSource),
845 LineInfo
=self
.CurrentLine
)
848 DpxSource
= ConvPathFromAbsToRel(DpxSource
,
849 GlobalData
.gINF_MODULE_DIR
)
850 self
.DpxSource
.append((DpxSource
, Comments
))
851 IsValidFileFlag
= False
854 def GetDpxSource(self
):
855 return self
.DpxSource
857 gFUNCTION_MAPPING_FOR_DEFINE_SECTION
= {
861 DT
.TAB_INF_DEFINES_BASE_NAME
: InfDefSection
.SetBaseName
,
862 DT
.TAB_INF_DEFINES_FILE_GUID
: InfDefSection
.SetFileGuid
,
863 DT
.TAB_INF_DEFINES_MODULE_TYPE
: InfDefSection
.SetModuleType
,
865 # Required by EDKII style INF file
867 DT
.TAB_INF_DEFINES_INF_VERSION
: InfDefSection
.SetInfVersion
,
871 DT
.TAB_INF_DEFINES_MODULE_UNI_FILE
: InfDefSection
.SetModuleUniFileName
,
872 DT
.TAB_INF_DEFINES_EDK_RELEASE_VERSION
: InfDefSection
.SetEdkReleaseVersion
,
873 DT
.TAB_INF_DEFINES_UEFI_SPECIFICATION_VERSION
: InfDefSection
.SetUefiSpecificationVersion
,
874 DT
.TAB_INF_DEFINES_PI_SPECIFICATION_VERSION
: InfDefSection
.SetPiSpecificationVersion
,
875 DT
.TAB_INF_DEFINES_LIBRARY_CLASS
: InfDefSection
.SetLibraryClass
,
876 DT
.TAB_INF_DEFINES_VERSION_STRING
: InfDefSection
.SetVersionString
,
877 DT
.TAB_INF_DEFINES_PCD_IS_DRIVER
: InfDefSection
.SetPcdIsDriver
,
878 DT
.TAB_INF_DEFINES_ENTRY_POINT
: InfDefSection
.SetEntryPoint
,
879 DT
.TAB_INF_DEFINES_UNLOAD_IMAGE
: InfDefSection
.SetUnloadImages
,
880 DT
.TAB_INF_DEFINES_CONSTRUCTOR
: InfDefSection
.SetConstructor
,
881 DT
.TAB_INF_DEFINES_DESTRUCTOR
: InfDefSection
.SetDestructor
,
882 DT
.TAB_INF_DEFINES_SHADOW
: InfDefSection
.SetShadow
,
883 DT
.TAB_INF_DEFINES_PCI_VENDOR_ID
: InfDefSection
.SetPciVendorId
,
884 DT
.TAB_INF_DEFINES_PCI_DEVICE_ID
: InfDefSection
.SetPciDeviceId
,
885 DT
.TAB_INF_DEFINES_PCI_CLASS_CODE
: InfDefSection
.SetPciClassCode
,
886 DT
.TAB_INF_DEFINES_PCI_REVISION
: InfDefSection
.SetPciRevision
,
887 DT
.TAB_INF_DEFINES_PCI_COMPRESS
: InfDefSection
.SetPciCompress
,
888 DT
.TAB_INF_DEFINES_CUSTOM_MAKEFILE
: InfDefSection
.SetCustomMakefile
,
889 DT
.TAB_INF_DEFINES_SPEC
: InfDefSection
.SetSpecification
,
890 DT
.TAB_INF_DEFINES_UEFI_HII_RESOURCE_SECTION
: InfDefSection
.SetUefiHiiResourceSection
,
891 DT
.TAB_INF_DEFINES_DPX_SOURCE
: InfDefSection
.SetDpxSource
897 class InfDefMember():
898 def __init__(self
, Name
='', Value
=''):
899 self
.Comments
= InfLineCommentObject()
902 self
.CurrentLine
= CurrentLine()
905 def SetName(self
, Name
):
909 def SetValue(self
, Value
):
915 class InfDefObject(InfSectionCommonDef
):
917 self
.Defines
= Sdict()
918 InfSectionCommonDef
.__init
__(self
)
919 def SetDefines(self
, DefineContent
, Arch
= None):
923 HasFoundInfVersionFalg
= False
924 LineInfo
= ['', -1, '']
925 ArchListString
= ' '.join(Arch
)
927 # Parse Define items.
929 for InfDefMemberObj
in DefineContent
:
931 Name
= InfDefMemberObj
.GetName()
932 Value
= InfDefMemberObj
.GetValue()
933 if Name
== DT
.TAB_INF_DEFINES_MODULE_UNI_FILE
:
934 ValidateUNIFilePath(Value
)
935 Value
= os
.path
.join(os
.path
.dirname(InfDefMemberObj
.CurrentLine
.FileName
), Value
)
936 if not os
.path
.isfile(Value
) or not os
.path
.exists(Value
):
937 LineInfo
[0] = InfDefMemberObj
.CurrentLine
.GetFileName()
938 LineInfo
[1] = InfDefMemberObj
.CurrentLine
.GetLineNo()
939 LineInfo
[2] = InfDefMemberObj
.CurrentLine
.GetLineString()
940 ErrorInInf(ST
.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID
%(Name),
942 InfLineCommentObj
= InfLineCommentObject()
943 InfLineCommentObj
.SetHeaderComments(InfDefMemberObj
.Comments
.GetHeaderComments())
944 InfLineCommentObj
.SetTailComments(InfDefMemberObj
.Comments
.GetTailComments())
945 if Name
== 'COMPONENT_TYPE':
946 ErrorInInf(ST
.ERR_INF_PARSER_NOT_SUPPORT_EDKI_INF
,
947 ErrorCode
=ToolError
.EDK1_INF_ERROR
,
949 if Name
== DT
.TAB_INF_DEFINES_INF_VERSION
:
950 HasFoundInfVersionFalg
= True
951 if not (Name
== '' or Name
is None):
953 # Process "SPEC" Keyword definition.
955 ReName
= re
.compile(r
"SPEC ", re
.DOTALL
)
956 if ReName
.match(Name
):
957 SpecValue
= Name
[Name
.find("SPEC") + len("SPEC"):].strip()
959 Value
= SpecValue
+ " = " + Value
960 if ArchListString
in self
.Defines
:
961 DefineList
= self
.Defines
[ArchListString
]
962 LineInfo
[0] = InfDefMemberObj
.CurrentLine
.GetFileName()
963 LineInfo
[1] = InfDefMemberObj
.CurrentLine
.GetLineNo()
964 LineInfo
[2] = InfDefMemberObj
.CurrentLine
.GetLineString()
965 DefineList
.CurrentLine
= LineInfo
967 # Found the process function from mapping table.
969 if Name
not in gFUNCTION_MAPPING_FOR_DEFINE_SECTION
.keys():
970 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_SECTION_KEYWORD_INVALID
%(Name),
973 ProcessFunc
= gFUNCTION_MAPPING_FOR_DEFINE_SECTION
[Name
]
974 if (ProcessFunc
is not None):
975 ProcessFunc(DefineList
, Value
, InfLineCommentObj
)
976 self
.Defines
[ArchListString
] = DefineList
978 DefineList
= InfDefSection()
979 LineInfo
[0] = InfDefMemberObj
.CurrentLine
.GetFileName()
980 LineInfo
[1] = InfDefMemberObj
.CurrentLine
.GetLineNo()
981 LineInfo
[2] = InfDefMemberObj
.CurrentLine
.GetLineString()
982 DefineList
.CurrentLine
= LineInfo
984 # Found the process function from mapping table.
986 if Name
not in gFUNCTION_MAPPING_FOR_DEFINE_SECTION
.keys():
987 ErrorInInf(ST
.ERR_INF_PARSER_DEFINE_SECTION_KEYWORD_INVALID
%(Name),
990 # Found the process function from mapping table.
993 ProcessFunc
= gFUNCTION_MAPPING_FOR_DEFINE_SECTION
[Name
]
994 if (ProcessFunc
is not None):
995 ProcessFunc(DefineList
, Value
, InfLineCommentObj
)
996 self
.Defines
[ArchListString
] = DefineList
998 # After set, check whether INF_VERSION defined.
1000 if not HasFoundInfVersionFalg
:
1001 ErrorInInf(ST
.ERR_INF_PARSER_NOT_SUPPORT_EDKI_INF
,
1002 ErrorCode
=ToolError
.EDK1_INF_ERROR
,
1006 def GetDefines(self
):