1 ## @file DecPomAlignment.py
2 # This file contained the adapter for convert INF parser object to POM Object
4 # Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
6 # This program and the accompanying materials are licensed and made available
7 # under the terms and conditions of the BSD License which accompanies this
8 # distribution. The full text of the license may be found at
9 # http://opensource.org/licenses/bsd-license.php
11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
27 import Logger
.Log
as Logger
28 from Logger
import StringTable
as ST
29 from Logger
.ToolError
import UPT_MUL_DEC_ERROR
30 from Logger
.ToolError
import FORMAT_INVALID
32 from Library
.Parsing
import NormPath
33 from Library
.DataType
import ARCH_LIST
34 from Library
.DataType
import TAB_GUIDS
35 from Library
.DataType
import TAB_PROTOCOLS
36 from Library
.DataType
import TAB_PPIS
37 from Library
.DataType
import TAB_DEC_DEFINES_PACKAGE_NAME
38 from Library
.DataType
import TAB_DEC_DEFINES_PACKAGE_GUID
39 from Library
.DataType
import TAB_DEC_DEFINES_PACKAGE_VERSION
40 from Library
.DataType
import TAB_DEC_DEFINES_DEC_SPECIFICATION
41 from Library
.DataType
import TAB_DEC_DEFINES_PKG_UNI_FILE
42 from Library
.DataType
import TAB_ARCH_COMMON
43 from Library
.DataType
import TAB_INCLUDES
44 from Library
.DataType
import TAB_LIBRARY_CLASSES
45 from Library
.DataType
import TAB_PCDS
46 from Library
.DataType
import TAB_PCDS_FIXED_AT_BUILD_NULL
47 from Library
.DataType
import TAB_PCDS_PATCHABLE_IN_MODULE_NULL
48 from Library
.DataType
import TAB_PCDS_FEATURE_FLAG_NULL
49 from Library
.DataType
import TAB_PCDS_DYNAMIC_EX_NULL
50 from Library
.DataType
import TAB_PCDS_DYNAMIC_NULL
51 from Library
.DataType
import TAB_PTR_TYPE_PCD
52 from Library
.DataType
import ITEM_UNDEFINED
53 from Library
.DataType
import TAB_DEC_BINARY_ABSTRACT
54 from Library
.DataType
import TAB_DEC_BINARY_DESCRIPTION
55 from Library
.DataType
import TAB_LANGUAGE_EN_US
56 from Library
.DataType
import TAB_BINARY_HEADER_IDENTIFIER
57 from Library
.DataType
import TAB_BINARY_HEADER_USERID
58 from Library
.DataType
import TAB_LANGUAGE_EN_X
59 from Library
.DataType
import TAB_LANGUAGE_EN
60 from Library
.DataType
import TAB_STR_TOKENCNAME
61 from Library
.DataType
import TAB_STR_TOKENPROMPT
62 from Library
.DataType
import TAB_STR_TOKENHELP
63 from Library
.DataType
import TAB_STR_TOKENERR
64 from Library
.DataType
import TAB_HEX_START
65 from Library
.DataType
import TAB_SPLIT
66 from Library
.CommentParsing
import ParseHeaderCommentSection
67 from Library
.CommentParsing
import ParseGenericComment
68 from Library
.CommentParsing
import ParseDecPcdGenericComment
69 from Library
.CommentParsing
import ParseDecPcdTailComment
70 from Library
.Misc
import GetFiles
71 from Library
.Misc
import Sdict
72 from Library
.Misc
import GetRelativePath
73 from Library
.Misc
import PathClass
74 from Library
.Misc
import ValidateUNIFilePath
75 from Library
.UniClassObject
import UniFileClassObject
76 from Library
.UniClassObject
import ConvertSpecialUnicodes
77 from Library
.UniClassObject
import GetLanguageCode1766
78 from Library
.ParserValidate
import IsValidPath
79 from Parser
.DecParser
import Dec
80 from Object
.POM
.PackageObject
import PackageObject
81 from Object
.POM
.CommonObject
import UserExtensionObject
82 from Object
.POM
.CommonObject
import IncludeObject
83 from Object
.POM
.CommonObject
import GuidObject
84 from Object
.POM
.CommonObject
import ProtocolObject
85 from Object
.POM
.CommonObject
import PpiObject
86 from Object
.POM
.CommonObject
import LibraryClassObject
87 from Object
.POM
.CommonObject
import PcdObject
88 from Object
.POM
.CommonObject
import TextObject
89 from Object
.POM
.CommonObject
import MiscFileObject
90 from Object
.POM
.CommonObject
import FileObject
95 # Inherited from PackageObject
97 class DecPomAlignment(PackageObject
):
98 def __init__(self
, Filename
, WorkspaceDir
= None, CheckMulDec
= False):
99 PackageObject
.__init
__(self
)
100 self
.UserExtensions
= ''
101 self
.WorkspaceDir
= WorkspaceDir
102 self
.SupArchList
= ARCH_LIST
103 self
.CheckMulDec
= CheckMulDec
104 self
.DecParser
= None
105 self
.UniFileClassObject
= None
106 self
.PcdDefaultValueDict
= {}
111 self
.LoadDecFile(Filename
)
114 # Transfer to Package Object if IsToPackage is True
120 # Load the file if it exists
122 # @param Filename: Input value for filename of Dec file
124 def LoadDecFile(self
, Filename
):
126 # Insert a record for file
128 Filename
= NormPath(Filename
)
129 (Path
, Name
) = os
.path
.split(Filename
)
130 self
.SetFullPath(Filename
)
131 self
.SetRelaPath(Path
)
132 self
.SetFileName(Name
)
133 self
.SetPackagePath(GetRelativePath(Path
, self
.WorkspaceDir
))
134 self
.SetCombinePath(GetRelativePath(Filename
, self
.WorkspaceDir
))
136 self
.DecParser
= Dec(Filename
)
138 ## Transfer to Package Object
140 # Transfer all contents of a Dec file to a standard Package Object
142 def DecToPackage(self
):
144 # Init global information for the file
146 ContainerFile
= self
.GetFullPath()
149 # Generate Package Header
151 self
.GenPackageHeader(ContainerFile
)
156 self
.GenIncludes(ContainerFile
)
161 self
.GenGuidProtocolPpis(TAB_GUIDS
, ContainerFile
)
166 self
.GenGuidProtocolPpis(TAB_PROTOCOLS
, ContainerFile
)
171 self
.GenGuidProtocolPpis(TAB_PPIS
, ContainerFile
)
174 # Generate LibraryClasses
176 self
.GenLibraryClasses(ContainerFile
)
181 self
.GenPcds(ContainerFile
)
184 # Generate Module File list, will be used later on to generate
187 self
.GenModuleFileList(ContainerFile
)
190 # Generate user extensions
192 self
.GenUserExtensions()
194 ## Generate user extension
197 def GenUserExtensions(self
):
198 UEObj
= self
.DecParser
.GetUserExtensionSectionObject()
199 UEList
= UEObj
.GetAllUserExtensions()
201 if not Item
.UserString
:
203 UserExtension
= UserExtensionObject()
205 if UserId
.startswith('"') and UserId
.endswith('"'):
206 UserId
= UserId
[1:-1]
207 UserExtension
.SetUserID(UserId
)
208 Identifier
= Item
.IdString
209 if Identifier
.startswith('"') and Identifier
.endswith('"'):
210 Identifier
= Identifier
[1:-1]
212 # Generate miscellaneous files of DEC file
214 if UserId
== 'TianoCore' and Identifier
== 'ExtraFiles':
215 self
.GenMiscFiles(Item
.UserString
)
216 UserExtension
.SetIdentifier(Identifier
)
217 UserExtension
.SetStatement(Item
.UserString
)
218 UserExtension
.SetSupArchList(
219 Item
.ArchAndModuleType
221 self
.SetUserExtensionList(
222 self
.GetUserExtensionList() + [UserExtension
]
225 ## Generate miscellaneous files on DEC file
228 def GenMiscFiles(self
, Content
):
229 MiscFileObj
= MiscFileObject()
230 for Line
in Content
.splitlines():
233 FileName
= Line
[:Line
.find('#')]
237 if IsValidPath(FileName
, self
.GetRelaPath()):
238 FileObj
= FileObject()
239 FileObj
.SetURI(FileName
)
240 MiscFileObj
.SetFileList(MiscFileObj
.GetFileList()+[FileObj
])
242 Logger
.Error("InfParser",
244 ST
.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID
%(Line),
245 File
=self
.GetFileName(),
247 self
.SetMiscFileList(self
.GetMiscFileList()+[MiscFileObj
])
249 ## Generate Package Header
251 # Gen Package Header of Dec as <Key> = <Value>
253 # @param ContainerFile: The Dec file full path
255 def GenPackageHeader(self
, ContainerFile
):
256 Logger
.Debug(2, "Generate PackageHeader ...")
260 # Update all defines item in database
262 DefObj
= self
.DecParser
.GetDefineSectionObject()
263 for Item
in DefObj
.GetDefines():
265 # put items into Dict except for PackageName, Guid, Version, DEC_SPECIFICATION
267 SkipItemList
= [TAB_DEC_DEFINES_PACKAGE_NAME
, \
268 TAB_DEC_DEFINES_PACKAGE_GUID
, TAB_DEC_DEFINES_PACKAGE_VERSION
, \
269 TAB_DEC_DEFINES_DEC_SPECIFICATION
, TAB_DEC_DEFINES_PKG_UNI_FILE
]
270 if Item
.Key
in SkipItemList
:
272 DefinesDict
['%s = %s' % (Item
.Key
, Item
.Value
)] = TAB_ARCH_COMMON
274 self
.SetBaseName(DefObj
.GetPackageName())
275 self
.SetVersion(DefObj
.GetPackageVersion())
276 # self.SetName(DefObj.GetPackageName() + ' Version ' + \
277 # DefObj.GetPackageVersion())
278 self
.SetName(os
.path
.splitext(self
.GetFileName())[0])
279 self
.SetGuid(DefObj
.GetPackageGuid())
280 if DefObj
.GetPackageUniFile():
281 ValidateUNIFilePath(DefObj
.GetPackageUniFile())
282 self
.UniFileClassObject
= \
283 UniFileClassObject([PathClass(os
.path
.join(DefObj
.GetPackagePath(), DefObj
.GetPackageUniFile()))])
285 self
.UniFileClassObject
= None
288 UserExtension
= UserExtensionObject()
289 UserExtension
.SetDefinesDict(DefinesDict
)
290 UserExtension
.SetIdentifier('DefineModifiers')
291 UserExtension
.SetUserID('EDK2')
292 self
.SetUserExtensionList(
293 self
.GetUserExtensionList() + [UserExtension
]
297 # Get File header information
299 if self
.UniFileClassObject
:
300 Lang
= TAB_LANGUAGE_EN_X
302 Lang
= TAB_LANGUAGE_EN_US
303 Abstract
, Description
, Copyright
, License
= \
304 ParseHeaderCommentSection(self
.DecParser
.GetHeadComment(),
307 self
.SetAbstract((Lang
, Abstract
))
309 self
.SetDescription((Lang
, Description
))
311 self
.SetCopyright(('', Copyright
))
313 self
.SetLicense(('', License
))
316 # Get Binary header information
318 if self
.DecParser
.BinaryHeadComment
:
319 Abstract
, Description
, Copyright
, License
= \
320 ParseHeaderCommentSection(self
.DecParser
.BinaryHeadComment
,
323 if not Abstract
or not Description
or not Copyright
or not License
:
324 Logger
.Error('MkPkg',
326 ST
.ERR_INVALID_BINARYHEADER_FORMAT
,
329 self
.SetBinaryHeaderAbstract((Lang
, Abstract
))
330 self
.SetBinaryHeaderDescription((Lang
, Description
))
331 self
.SetBinaryHeaderCopyright(('', Copyright
))
332 self
.SetBinaryHeaderLicense(('', License
))
334 BinaryAbstractList
= []
335 BinaryDescriptionList
= []
337 #Get Binary header from UNI file
338 # Initialize the UniStrDict dictionary, top keys are language codes
340 if self
.UniFileClassObject
:
341 UniStrDict
= self
.UniFileClassObject
.OrderedStringList
342 for Lang
in UniStrDict
:
343 for StringDefClassObject
in UniStrDict
[Lang
]:
344 Lang
= GetLanguageCode1766(Lang
)
345 if StringDefClassObject
.StringName
== TAB_DEC_BINARY_ABSTRACT
:
346 if (Lang
, ConvertSpecialUnicodes(StringDefClassObject
.StringValue
)) \
347 not in self
.GetBinaryHeaderAbstract():
348 BinaryAbstractList
.append((Lang
, ConvertSpecialUnicodes(StringDefClassObject
.StringValue
)))
349 if StringDefClassObject
.StringName
== TAB_DEC_BINARY_DESCRIPTION
:
350 if (Lang
, ConvertSpecialUnicodes(StringDefClassObject
.StringValue
)) \
351 not in self
.GetBinaryHeaderDescription():
352 BinaryDescriptionList
.append((Lang
,
353 ConvertSpecialUnicodes(StringDefClassObject
.StringValue
)))
354 #Combine Binary header from DEC file and UNI file
355 BinaryAbstractList
= self
.GetBinaryHeaderAbstract() + BinaryAbstractList
356 BinaryDescriptionList
= self
.GetBinaryHeaderDescription() + BinaryDescriptionList
357 BinaryCopyrightList
= self
.GetBinaryHeaderCopyright()
358 BinaryLicenseList
= self
.GetBinaryHeaderLicense()
359 #Generate the UserExtensionObject for TianoCore."BinaryHeader"
360 if BinaryAbstractList
or BinaryDescriptionList
or BinaryCopyrightList
or BinaryLicenseList
:
361 BinaryUserExtension
= UserExtensionObject()
362 BinaryUserExtension
.SetBinaryAbstract(BinaryAbstractList
)
363 BinaryUserExtension
.SetBinaryDescription(BinaryDescriptionList
)
364 BinaryUserExtension
.SetBinaryCopyright(BinaryCopyrightList
)
365 BinaryUserExtension
.SetBinaryLicense(BinaryLicenseList
)
366 BinaryUserExtension
.SetIdentifier(TAB_BINARY_HEADER_IDENTIFIER
)
367 BinaryUserExtension
.SetUserID(TAB_BINARY_HEADER_USERID
)
368 self
.SetUserExtensionList(self
.GetUserExtensionList() + [BinaryUserExtension
])
373 # Gen Includes of Dec
375 # @param ContainerFile: The Dec file full path
377 def GenIncludes(self
, ContainerFile
):
380 Logger
.Debug(2, "Generate %s ..." % TAB_INCLUDES
)
381 IncludesDict
= Sdict()
383 IncObj
= self
.DecParser
.GetIncludeSectionObject()
384 for Item
in IncObj
.GetAllIncludes():
385 IncludePath
= os
.path
.normpath(Item
.File
)
386 if platform
.system() != 'Windows' and platform
.system() != 'Microsoft':
387 IncludePath
= IncludePath
.replace('\\', '/')
388 if IncludePath
in IncludesDict
:
389 if Item
.GetArchList() == [TAB_ARCH_COMMON
] or IncludesDict
[IncludePath
] == [TAB_ARCH_COMMON
]:
390 IncludesDict
[IncludePath
] = [TAB_ARCH_COMMON
]
392 IncludesDict
[IncludePath
] = IncludesDict
[IncludePath
] + Item
.GetArchList()
394 IncludesDict
[IncludePath
] = Item
.GetArchList()
397 # get the standardIncludeFileList(industry), packageIncludeFileList
398 # (others) for PackageObject
400 PackagePath
= os
.path
.split(self
.GetFullPath())[0]
402 [os
.path
.normpath(Path
) + sep
for Path
in IncludesDict
.keys()]
403 IncludePathList
.sort()
406 # get a non-overlap set of include path, IncludePathList should be
407 # sorted, and path should be end with path seperator '\'
410 for Path1
in IncludePathList
:
411 for Path2
in NonOverLapList
:
412 if Path1
.startswith(Path2
):
415 NonOverLapList
.append(Path1
)
417 # revert the list so the longest path shown first in list, also need
418 # to remove the extra path seperator '\'
419 # as this list is used to search the supported Arch info
421 for IndexN
in range (0, len(IncludePathList
)):
422 IncludePathList
[IndexN
] = os
.path
.normpath(IncludePathList
[IndexN
])
423 IncludePathList
.sort()
424 IncludePathList
.reverse()
426 # save the include path list for later usage
428 self
.SetIncludePathList(IncludePathList
)
429 StandardIncludeFileList
= []
430 PackageIncludeFileList
= []
433 for Path
in NonOverLapList
:
434 FileList
= GetFiles(os
.path
.join(PackagePath
, Path
), ['CVS', '.svn'], False)
435 IncludeFileList
+= [os
.path
.normpath(os
.path
.join(Path
, File
)) for File
in FileList
]
436 for Includefile
in IncludeFileList
:
437 ExtName
= os
.path
.splitext(Includefile
)[1]
438 if ExtName
.upper() == '.DEC' and self
.CheckMulDec
:
439 Logger
.Error('MkPkg',
441 ST
.ERR_MUL_DEC_ERROR
%(os
.path
.dirname(ContainerFile
),
442 os
.path
.basename(ContainerFile
),
445 FileCombinePath
= os
.path
.dirname(Includefile
)
446 Include
= IncludeObject()
447 for Path
in IncludePathList
:
448 if FileCombinePath
.startswith(Path
):
449 SupArchList
= IncludesDict
[Path
]
451 Include
.SetFilePath(Includefile
)
452 Include
.SetSupArchList(SupArchList
)
453 if Includefile
.find('IndustryStandard') != -1:
454 StandardIncludeFileList
.append(Include
)
456 PackageIncludeFileList
.append(Include
)
458 self
.SetStandardIncludeFileList(StandardIncludeFileList
)
461 # put include path into the PackageIncludeFileList
464 IncObj
= self
.DecParser
.GetIncludeSectionObject()
465 for Item
in IncObj
.GetAllIncludes():
466 IncludePath
= Item
.File
467 Include
= IncludeObject()
468 Include
.SetFilePath(IncludePath
)
469 Include
.SetSupArchList(Item
.GetArchList())
470 PackagePathList
.append(Include
)
471 self
.SetPackageIncludeFileList(PackagePathList
+ PackageIncludeFileList
)
476 # <CName>=<GuidValue>
478 # @param ContainerFile: The Dec file full path
480 def GenGuidProtocolPpis(self
, Type
, ContainerFile
):
483 Logger
.Debug(2, "Generate %s ..." % Type
)
487 if Type
== TAB_GUIDS
:
488 Obj
= self
.DecParser
.GetGuidSectionObject()
489 def CreateGuidObject():
490 Object
= GuidObject()
491 Object
.SetGuidTypeList([])
492 Object
.SetUsage(None)
495 Factory
= CreateGuidObject
496 elif Type
== TAB_PROTOCOLS
:
497 Obj
= self
.DecParser
.GetProtocolSectionObject()
499 def CreateProtocolObject():
500 return ProtocolObject()
501 Factory
= CreateProtocolObject
502 elif Type
== TAB_PPIS
:
503 Obj
= self
.DecParser
.GetPpiSectionObject()
505 def CreatePpiObject():
507 Factory
= CreatePpiObject
514 DeclarationsList
= []
517 # Go through each arch
519 for Item
in Obj
.GetGuidStyleAllItems():
520 Name
= Item
.GuidCName
521 Value
= Item
.GuidString
522 HelpTxt
= ParseGenericComment(Item
.GetHeadComment() + \
523 Item
.GetTailComment())
525 ListObject
= Factory()
526 ListObject
.SetCName(Name
)
527 ListObject
.SetGuid(Value
)
528 ListObject
.SetSupArchList(Item
.GetArchList())
530 if self
.UniFileClassObject
:
531 HelpTxt
.SetLang(TAB_LANGUAGE_EN_X
)
532 ListObject
.SetHelpTextList([HelpTxt
])
534 DeclarationsList
.append(ListObject
)
537 #GuidTypeList is abstracted from help
539 if Type
== TAB_GUIDS
:
540 self
.SetGuidList(self
.GetGuidList() + DeclarationsList
)
541 elif Type
== TAB_PROTOCOLS
:
542 self
.SetProtocolList(self
.GetProtocolList() + DeclarationsList
)
543 elif Type
== TAB_PPIS
:
544 self
.SetPpiList(self
.GetPpiList() + DeclarationsList
)
548 # Gen LibraryClasses of Dec
549 # <CName>=<GuidValue>
551 # @param ContainerFile: The Dec file full path
553 def GenLibraryClasses(self
, ContainerFile
):
556 Logger
.Debug(2, "Generate %s ..." % TAB_LIBRARY_CLASSES
)
557 LibraryClassDeclarations
= []
559 LibObj
= self
.DecParser
.GetLibraryClassSectionObject()
560 for Item
in LibObj
.GetAllLibraryclasses():
561 LibraryClass
= LibraryClassObject()
562 LibraryClass
.SetLibraryClass(Item
.Libraryclass
)
563 LibraryClass
.SetSupArchList(Item
.GetArchList())
564 LibraryClass
.SetIncludeHeader(Item
.File
)
565 HelpTxt
= ParseGenericComment(Item
.GetHeadComment() + \
566 Item
.GetTailComment(), None, '@libraryclass')
568 if self
.UniFileClassObject
:
569 HelpTxt
.SetLang(TAB_LANGUAGE_EN_X
)
570 LibraryClass
.SetHelpTextList([HelpTxt
])
571 LibraryClassDeclarations
.append(LibraryClass
)
573 self
.SetLibraryClassList(self
.GetLibraryClassList() + \
574 LibraryClassDeclarations
)
579 # <TokenSpcCName>.<TokenCName>|<Value>|<DatumType>|<Token>
581 # @param ContainerFile: The Dec file full path
583 def GenPcds(self
, ContainerFile
):
584 Logger
.Debug(2, "Generate %s ..." % TAB_PCDS
)
585 PcdObj
= self
.DecParser
.GetPcdSectionObject()
591 (TAB_PCDS_FIXED_AT_BUILD_NULL
, 'FixedPcd'),
592 (TAB_PCDS_PATCHABLE_IN_MODULE_NULL
, 'PatchPcd'),
593 (TAB_PCDS_FEATURE_FLAG_NULL
, 'FeaturePcd'),
594 (TAB_PCDS_DYNAMIC_EX_NULL
, 'PcdEx'),
595 (TAB_PCDS_DYNAMIC_NULL
, 'Pcd')]
600 # Initialize UniStrDict dictionary, top keys are language codes
605 if self
.UniFileClassObject
:
606 Language
= TAB_LANGUAGE_EN_X
608 Language
= TAB_LANGUAGE_EN_US
610 if self
.UniFileClassObject
:
611 UniStrDict
= self
.UniFileClassObject
.OrderedStringList
612 for Lang
in UniStrDict
:
613 for StringDefClassObject
in UniStrDict
[Lang
]:
614 StrList
= StringDefClassObject
.StringName
.split('_')
615 # StringName format is STR_<TOKENSPACECNAME>_<PCDCNAME>_PROMPT
616 if len(StrList
) == 4 and StrList
[0] == TAB_STR_TOKENCNAME
and StrList
[3] == TAB_STR_TOKENPROMPT
:
617 PromptStrList
.append((GetLanguageCode1766(Lang
), StringDefClassObject
.StringName
, \
618 StringDefClassObject
.StringValue
))
619 # StringName format is STR_<TOKENSPACECNAME>_<PCDCNAME>_HELP
620 if len(StrList
) == 4 and StrList
[0] == TAB_STR_TOKENCNAME
and StrList
[3] == TAB_STR_TOKENHELP
:
621 HelpStrList
.append((GetLanguageCode1766(Lang
), StringDefClassObject
.StringName
, \
622 StringDefClassObject
.StringValue
))
623 # StringName format is STR_<TOKENSPACECNAME>_ERR_##
624 if len(StrList
) == 4 and StrList
[0] == TAB_STR_TOKENCNAME
and StrList
[2] == TAB_STR_TOKENERR
:
625 PcdErrStrList
.append((GetLanguageCode1766(Lang
), StringDefClassObject
.StringName
, \
626 StringDefClassObject
.StringValue
))
630 for PcdType
, Type
in IterList
:
632 # Go through all archs
634 # for Arch in self.SupArchList + [TAB_ARCH_COMMON]:
636 for Item
in PcdObj
.GetPcdsByType(PcdType
.upper()):
637 PcdDeclaration
= GenPcdDeclaration(
639 (Item
.TokenSpaceGuidCName
, Item
.TokenCName
,
640 Item
.DefaultValue
, Item
.DatumType
, Item
.TokenValue
,
641 Type
, Item
.GetHeadComment(), Item
.GetTailComment(),''),
643 self
.DecParser
.GetDefineSectionMacro()
645 PcdDeclaration
.SetSupArchList(Item
.GetArchListOfType(PcdType
))
648 # Get PCD error message from PCD error comment section in DEC file
650 for PcdErr
in PcdDeclaration
.GetPcdErrorsList():
651 if (PcdDeclaration
.GetTokenSpaceGuidCName(), PcdErr
.GetErrorNumber()) \
652 in self
.DecParser
.PcdErrorCommentDict
:
653 Key
= (PcdDeclaration
.GetTokenSpaceGuidCName(), PcdErr
.GetErrorNumber())
654 PcdErr
.SetErrorMessageList(PcdErr
.GetErrorMessageList() + \
655 [(Language
, self
.DecParser
.PcdErrorCommentDict
[Key
])])
657 for Index
in range(0, len(PromptStrList
)):
658 StrNameList
= PromptStrList
[Index
][1].split('_')
659 if StrNameList
[1].lower() == Item
.TokenSpaceGuidCName
.lower() and \
660 StrNameList
[2].lower() == Item
.TokenCName
.lower():
661 TxtObj
= TextObject()
662 TxtObj
.SetLang(PromptStrList
[Index
][0])
663 TxtObj
.SetString(PromptStrList
[Index
][2])
664 for Prompt
in PcdDeclaration
.GetPromptList():
665 if Prompt
.GetLang() == TxtObj
.GetLang() and \
666 Prompt
.GetString() == TxtObj
.GetString():
669 PcdDeclaration
.SetPromptList(PcdDeclaration
.GetPromptList() + [TxtObj
])
671 for Index
in range(0, len(HelpStrList
)):
672 StrNameList
= HelpStrList
[Index
][1].split('_')
673 if StrNameList
[1].lower() == Item
.TokenSpaceGuidCName
.lower() and \
674 StrNameList
[2].lower() == Item
.TokenCName
.lower():
675 TxtObj
= TextObject()
676 TxtObj
.SetLang(HelpStrList
[Index
][0])
677 TxtObj
.SetString(HelpStrList
[Index
][2])
678 for HelpStrObj
in PcdDeclaration
.GetHelpTextList():
679 if HelpStrObj
.GetLang() == TxtObj
.GetLang() and \
680 HelpStrObj
.GetString() == TxtObj
.GetString():
683 PcdDeclaration
.SetHelpTextList(PcdDeclaration
.GetHelpTextList() + [TxtObj
])
686 # Get PCD error message from UNI file
688 for Index
in range(0, len(PcdErrStrList
)):
689 StrNameList
= PcdErrStrList
[Index
][1].split('_')
690 if StrNameList
[1].lower() == Item
.TokenSpaceGuidCName
.lower() and \
691 StrNameList
[2].lower() == TAB_STR_TOKENERR
.lower():
692 for PcdErr
in PcdDeclaration
.GetPcdErrorsList():
693 if PcdErr
.GetErrorNumber().lower() == (TAB_HEX_START
+ StrNameList
[3]).lower() and \
694 (PcdErrStrList
[Index
][0], PcdErrStrList
[Index
][2]) not in PcdErr
.GetErrorMessageList():
695 PcdErr
.SetErrorMessageList(PcdErr
.GetErrorMessageList() + \
696 [(PcdErrStrList
[Index
][0], PcdErrStrList
[Index
][2])])
699 # Check to prevent missing error message if a Pcd has the error code.
701 for PcdErr
in PcdDeclaration
.GetPcdErrorsList():
702 if PcdErr
.GetErrorNumber().strip():
703 if not PcdErr
.GetErrorMessageList():
706 ST
.ERR_DECPARSE_PCD_UNMATCHED_ERRORCODE
% PcdErr
.GetErrorNumber(),
709 PcdErr
.GetFileLine())
711 PcdDeclarations
.append(PcdDeclaration
)
712 self
.SetPcdList(self
.GetPcdList() + PcdDeclarations
)
716 # Get error message via language
717 # @param ErrorMessageList: Error message tuple list the language and its message
718 # @param Lang: the language of setting
719 # @return: the error message described in the related UNI file
720 def GetEnErrorMessage(self
, ErrorMessageList
):
723 Lang
= TAB_LANGUAGE_EN_US
724 for (Language
, Message
) in ErrorMessageList
:
727 for (Language
, Message
) in ErrorMessageList
:
728 if Language
.find(TAB_LANGUAGE_EN
) >= 0:
732 return ErrorMessageList
[0][1]
738 # Replace the strings for Python eval function.
739 # @param ReplaceValue: The string that needs to be replaced.
740 # @return: The string was replaced, then eval function is always making out it.
741 def ReplaceForEval(self
, ReplaceValue
, IsRange
=False, IsExpr
=False):
745 # deal with "NOT EQ", "NOT LT", "NOT GT", "NOT LE", "NOT GE", "NOT NOT"
747 NOTNOT_Pattern
= '[\t\s]*NOT[\t\s]+NOT[\t\s]*'
748 NOTGE_Pattern
= '[\t\s]*NOT[\t\s]+GE[\t\s]*'
749 NOTLE_Pattern
= '[\t\s]*NOT[\t\s]+LE[\t\s]*'
750 NOTGT_Pattern
= '[\t\s]*NOT[\t\s]+GT[\t\s]*'
751 NOTLT_Pattern
= '[\t\s]*NOT[\t\s]+LT[\t\s]*'
752 NOTEQ_Pattern
= '[\t\s]*NOT[\t\s]+EQ[\t\s]*'
753 ReplaceValue
= re
.compile(NOTNOT_Pattern
).sub('', ReplaceValue
)
754 ReplaceValue
= re
.compile(NOTLT_Pattern
).sub('x >= ', ReplaceValue
)
755 ReplaceValue
= re
.compile(NOTGT_Pattern
).sub('x <= ', ReplaceValue
)
756 ReplaceValue
= re
.compile(NOTLE_Pattern
).sub('x > ', ReplaceValue
)
757 ReplaceValue
= re
.compile(NOTGE_Pattern
).sub('x < ', ReplaceValue
)
758 ReplaceValue
= re
.compile(NOTEQ_Pattern
).sub('x != ', ReplaceValue
)
761 ReplaceValue
= ReplaceValue
.replace('EQ', 'x ==')
762 ReplaceValue
= ReplaceValue
.replace('LT', 'x <')
763 ReplaceValue
= ReplaceValue
.replace('LE', 'x <=')
764 ReplaceValue
= ReplaceValue
.replace('GT', 'x >')
765 ReplaceValue
= ReplaceValue
.replace('GE', 'x >=')
766 ReplaceValue
= ReplaceValue
.replace('XOR', 'x ^')
768 ReplaceValue
= ReplaceValue
.replace('EQ', '==')
769 ReplaceValue
= ReplaceValue
.replace('NE', '!=')
770 ReplaceValue
= ReplaceValue
.replace('LT', '<')
771 ReplaceValue
= ReplaceValue
.replace('LE', '<=')
772 ReplaceValue
= ReplaceValue
.replace('GT', '>')
773 ReplaceValue
= ReplaceValue
.replace('GE', '>=')
774 ReplaceValue
= ReplaceValue
.replace('XOR', '^')
776 ReplaceValue
= ReplaceValue
.replace('AND', 'and')
777 ReplaceValue
= ReplaceValue
.replace('&&', ' and ')
778 ReplaceValue
= ReplaceValue
.replace('xor', '^')
779 ReplaceValue
= ReplaceValue
.replace('OR', 'or')
780 ReplaceValue
= ReplaceValue
.replace('||', ' or ')
781 ReplaceValue
= ReplaceValue
.replace('NOT', 'not')
782 if ReplaceValue
.find('!') >= 0 and ReplaceValue
[ReplaceValue
.index('!') + 1] != '=':
783 ReplaceValue
= ReplaceValue
.replace('!', ' not ')
784 if '.' in ReplaceValue
:
785 Pattern
= '[a-zA-Z0-9]{1,}\.[a-zA-Z0-9]{1,}'
786 MatchedList
= re
.findall(Pattern
, ReplaceValue
)
787 for MatchedItem
in MatchedList
:
788 if MatchedItem
not in self
.PcdDefaultValueDict
:
789 Logger
.Error("Dec File Parser", FORMAT_INVALID
, Message
=ST
.ERR_DECPARSE_PCD_NODEFINED
% MatchedItem
,
792 ReplaceValue
= ReplaceValue
.replace(MatchedItem
, self
.PcdDefaultValueDict
[MatchedItem
])
797 # Check pcd's default value according to the pcd's description
799 def CheckPcdValue(self
):
800 for Pcd
in self
.GetPcdList():
801 self
.PcdDefaultValueDict
[TAB_SPLIT
.join((Pcd
.GetTokenSpaceGuidCName(), Pcd
.GetCName())).strip()] = \
802 Pcd
.GetDefaultValue()
804 for Pcd
in self
.GetPcdList():
805 ValidationExpressions
= []
806 PcdGuidName
= TAB_SPLIT
.join((Pcd
.GetTokenSpaceGuidCName(), Pcd
.GetCName()))
807 Valids
= Pcd
.GetPcdErrorsList()
809 Expression
= Valid
.GetExpression()
812 # Delete the 'L' prefix of a quoted string, this operation is for eval()
814 QUOTED_PATTERN
= '[\t\s]*L?"[^"]*"'
815 QuotedMatchedObj
= re
.search(QUOTED_PATTERN
, Expression
)
817 MatchedStr
= QuotedMatchedObj
.group().strip()
818 if MatchedStr
.startswith('L'):
819 Expression
= Expression
.replace(MatchedStr
, MatchedStr
[1:].strip())
821 Expression
= self
.ReplaceForEval(Expression
, IsExpr
=True)
822 Expression
= Expression
.replace(PcdGuidName
, 'x')
823 Message
= self
.GetEnErrorMessage(Valid
.GetErrorMessageList())
824 ValidationExpressions
.append((Expression
, Message
))
826 ValidList
= Valid
.GetValidValue()
828 ValidValue
= 'x in %s' % [eval(v
) for v
in ValidList
.split(' ') if v
]
829 Message
= self
.GetEnErrorMessage(Valid
.GetErrorMessageList())
830 ValidationExpressions
.append((ValidValue
, Message
))
832 ValidValueRange
= Valid
.GetValidValueRange()
834 ValidValueRange
= self
.ReplaceForEval(ValidValueRange
, IsRange
=True)
835 if ValidValueRange
.find('-') >= 0:
836 ValidValueRange
= ValidValueRange
.replace('-', '<= x <=')
837 elif not ValidValueRange
.startswith('x ') and not ValidValueRange
.startswith('not ') \
838 and not ValidValueRange
.startswith('not(') and not ValidValueRange
.startswith('('):
839 ValidValueRange
= 'x %s' % ValidValueRange
840 Message
= self
.GetEnErrorMessage(Valid
.GetErrorMessageList())
841 ValidationExpressions
.append((ValidValueRange
, Message
))
843 DefaultValue
= self
.PcdDefaultValueDict
[PcdGuidName
.strip()]
845 # Delete the 'L' prefix of a quoted string, this operation is for eval()
847 QUOTED_PATTERN
= '[\t\s]*L?"[^"]*"'
848 QuotedMatchedObj
= re
.search(QUOTED_PATTERN
, DefaultValue
)
850 MatchedStr
= QuotedMatchedObj
.group().strip()
851 if MatchedStr
.startswith('L'):
852 DefaultValue
= DefaultValue
.replace(MatchedStr
, MatchedStr
[1:].strip())
855 DefaultValue
= eval(DefaultValue
.replace('TRUE', 'True').replace('true', 'True')
856 .replace('FALSE', 'False').replace('false', 'False'))
857 except BaseException
:
860 for (Expression
, Msg
) in ValidationExpressions
:
862 if not eval(Expression
, {'x':DefaultValue
}):
863 Logger
.Error("Dec File Parser", FORMAT_INVALID
, ExtraData
='%s, value = %s' %\
864 (PcdGuidName
, DefaultValue
), Message
=Msg
, File
=self
.FullPath
)
866 Logger
.Error("Dec File Parser", FORMAT_INVALID
, ExtraData
=PcdGuidName
, \
867 Message
=Msg
, File
=self
.FullPath
)
871 def GenModuleFileList(self
, ContainerFile
):
873 ContainerFileName
= os
.path
.basename(ContainerFile
)
874 ContainerFilePath
= os
.path
.dirname(ContainerFile
)
875 for Item
in GetFiles(ContainerFilePath
,
876 ['CVS', '.svn'] + self
.GetIncludePathList(), False):
877 ExtName
= os
.path
.splitext(Item
)[1]
878 if ExtName
.lower() == '.inf':
879 ModuleFileList
.append(Item
)
880 elif ExtName
.upper() == '.DEC' and self
.CheckMulDec
:
881 if Item
== ContainerFileName
:
883 Logger
.Error('MkPkg',
885 ST
.ERR_MUL_DEC_ERROR
%(ContainerFilePath
,
889 self
.SetModuleFileList(ModuleFileList
)
891 ## Show detailed information of Package
893 # Print all members and their values of Package class
895 def ShowPackage(self
):
896 print '\nName =', self
.GetName()
897 print '\nBaseName =', self
.GetBaseName()
898 print '\nVersion =', self
.GetVersion()
899 print '\nGuid =', self
.GetGuid()
901 print '\nStandardIncludes = %d ' \
902 % len(self
.GetStandardIncludeFileList()),
903 for Item
in self
.GetStandardIncludeFileList():
904 print Item
.GetFilePath(), ' ', Item
.GetSupArchList()
905 print '\nPackageIncludes = %d \n' \
906 % len(self
.GetPackageIncludeFileList()),
907 for Item
in self
.GetPackageIncludeFileList():
908 print Item
.GetFilePath(), ' ', Item
.GetSupArchList()
910 print '\nGuids =', self
.GetGuidList()
911 for Item
in self
.GetGuidList():
912 print Item
.GetCName(), Item
.GetGuid(), Item
.GetSupArchList()
913 print '\nProtocols =', self
.GetProtocolList()
914 for Item
in self
.GetProtocolList():
915 print Item
.GetCName(), Item
.GetGuid(), Item
.GetSupArchList()
916 print '\nPpis =', self
.GetPpiList()
917 for Item
in self
.GetPpiList():
918 print Item
.GetCName(), Item
.GetGuid(), Item
.GetSupArchList()
919 print '\nLibraryClasses =', self
.GetLibraryClassList()
920 for Item
in self
.GetLibraryClassList():
921 print Item
.GetLibraryClass(), Item
.GetRecommendedInstance(), \
922 Item
.GetSupArchList()
923 print '\nPcds =', self
.GetPcdList()
924 for Item
in self
.GetPcdList():
925 print 'CName=', Item
.GetCName(), 'TokenSpaceGuidCName=', \
926 Item
.GetTokenSpaceGuidCName(), \
927 'DefaultValue=', Item
.GetDefaultValue(), \
928 'ValidUsage=', Item
.GetValidUsage(), \
929 'SupArchList', Item
.GetSupArchList(), \
930 'Token=', Item
.GetToken(), 'DatumType=', Item
.GetDatumType()
932 for Item
in self
.GetMiscFileList():
934 for FileObjectItem
in Item
.GetFileList():
935 print FileObjectItem
.GetURI()
936 print '****************\n'
940 # @param ContainerFile: File name of the DEC file
941 # @param PcdInfo: Pcd information, of format (TokenGuidCName,
942 # TokenName, Value, DatumType, Token, Type,
943 # GenericComment, TailComment, Arch)
944 # @param Language: The language of HelpText, Prompt
946 def GenPcdDeclaration(ContainerFile
, PcdInfo
, Language
, MacroReplaceDict
):
950 TokenGuidCName
, TokenName
, Value
, DatumType
, Token
, Type
, \
951 GenericComment
, TailComment
, Arch
= PcdInfo
953 Pcd
.SetCName(TokenName
)
955 Pcd
.SetTokenSpaceGuidCName(TokenGuidCName
)
956 Pcd
.SetDatumType(DatumType
)
957 Pcd
.SetDefaultValue(Value
)
958 Pcd
.SetValidUsage(Type
)
960 # MaxDatumSize is required field for 'VOID*' PCD
962 if DatumType
== TAB_PTR_TYPE_PCD
:
963 Pcd
.SetMaxDatumSize(ITEM_UNDEFINED
)
966 Pcd
.SetSupArchList(SupArchList
)
969 HelpStr
, PcdErrList
, PromptStr
= ParseDecPcdGenericComment(GenericComment
,
975 Pcd
.SetPcdErrorsList(PcdErrList
)
978 SupModuleList
, TailHelpStr
= ParseDecPcdTailComment(TailComment
,
981 Pcd
.SetSupModuleList(SupModuleList
)
983 if HelpStr
and (not HelpStr
.endswith('\n')) and TailHelpStr
:
985 HelpStr
+= TailHelpStr
987 HelpTxtObj
= TextObject()
988 HelpTxtObj
.SetLang(Language
)
989 HelpTxtObj
.SetString(HelpStr
)
990 Pcd
.SetHelpTextList([HelpTxtObj
])
992 TxtObj
= TextObject()
993 TxtObj
.SetLang(Language
)
994 TxtObj
.SetString(PromptStr
)
995 Pcd
.SetPromptList([TxtObj
])