3 # This file contained the logical of transfer package object to DEC files.
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.
23 from Core
.FileHook
import __FileHookOpen__
24 from Library
.Parsing
import GenSection
25 from Library
.CommentGenerating
import GenHeaderCommentSection
26 from Library
.CommentGenerating
import GenGenericCommentF
27 from Library
.CommentGenerating
import GenDecTailComment
28 from Library
.CommentGenerating
import _GetHelpStr
29 from Library
.Misc
import GuidStringToGuidStructureString
30 from Library
.Misc
import SaveFileOnChange
31 from Library
.Misc
import ConvertPath
32 from Library
.Misc
import GetLocalValue
33 from Library
.DataType
import TAB_SPACE_SPLIT
34 from Library
.DataType
import TAB_COMMA_SPLIT
35 from Library
.DataType
import END_OF_LINE
36 from Library
.DataType
import TAB_ARCH_COMMON
37 from Library
.DataType
import TAB_VALUE_SPLIT
38 from Library
.DataType
import TAB_COMMENT_SPLIT
39 from Library
.DataType
import TAB_PCD_VALIDRANGE
40 from Library
.DataType
import TAB_PCD_VALIDLIST
41 from Library
.DataType
import TAB_PCD_EXPRESSION
42 from Library
.DataType
import TAB_DEC_DEFINES_DEC_SPECIFICATION
43 from Library
.DataType
import TAB_DEC_DEFINES_PACKAGE_NAME
44 from Library
.DataType
import TAB_DEC_DEFINES_PACKAGE_GUID
45 from Library
.DataType
import TAB_DEC_DEFINES_PACKAGE_VERSION
46 from Library
.DataType
import TAB_DEC_DEFINES_PKG_UNI_FILE
47 from Library
.DataType
import TAB_DEC_PACKAGE_ABSTRACT
48 from Library
.DataType
import TAB_DEC_PACKAGE_DESCRIPTION
49 from Library
.DataType
import TAB_DEC_BINARY_ABSTRACT
50 from Library
.DataType
import TAB_DEC_BINARY_DESCRIPTION
51 from Library
.DataType
import TAB_LANGUAGE_EN_X
52 from Library
.DataType
import TAB_BINARY_HEADER_USERID
53 from Library
.DataType
import TAB_BINARY_HEADER_IDENTIFIER
54 from Library
.DataType
import TAB_COMMENT_EDK1_SPLIT
55 from Library
.DataType
import TAB_ENCODING_UTF16LE
56 from Library
.DataType
import TAB_CAPHEX_START
57 from Library
.DataType
import TAB_HEX_START
58 from Library
.DataType
import TAB_UNDERLINE_SPLIT
59 from Library
.DataType
import TAB_STR_TOKENERR
60 from Library
.DataType
import TAB_STR_TOKENCNAME
61 from Library
.DataType
import TAB_PCD_ERROR_SECTION_COMMENT
62 from Library
.DataType
import TAB_PCD_ERROR
63 from Library
.DataType
import TAB_SECTION_START
64 from Library
.DataType
import TAB_SECTION_END
65 from Library
.DataType
import TAB_SPLIT
66 import Library
.DataType
as DT
67 from Library
.UniClassObject
import FormatUniEntry
68 from Library
.StringUtils
import GetUniFileName
70 def GenPcd(Package
, Content
):
72 # generate [Pcd] section
73 # <TokenSpcCName>.<TokenCName>|<Value>|<DatumType>|<Token>
76 for Pcd
in Package
.GetPcdList():
78 # Generate generic comment
80 HelpTextList
= Pcd
.GetHelpTextList()
81 HelpStr
= _GetHelpStr(HelpTextList
)
82 CommentStr
= GenGenericCommentF(HelpStr
, 2)
84 PromptList
= Pcd
.GetPromptList()
85 PromptStr
= _GetHelpStr(PromptList
)
86 CommentStr
+= GenGenericCommentF(PromptStr
.strip(), 1, True)
88 PcdErrList
= Pcd
.GetPcdErrorsList()
89 for PcdErr
in PcdErrList
:
90 CommentStr
+= GenPcdErrComment(PcdErr
)
91 Statement
= CommentStr
93 CName
= Pcd
.GetCName()
94 TokenSpaceGuidCName
= Pcd
.GetTokenSpaceGuidCName()
95 DefaultValue
= Pcd
.GetDefaultValue()
96 DatumType
= Pcd
.GetDatumType()
97 Token
= Pcd
.GetToken()
98 ValidUsage
= Pcd
.GetValidUsage()
100 if ValidUsage
== 'FeaturePcd':
101 ValidUsage
= 'PcdsFeatureFlag'
102 elif ValidUsage
== 'PatchPcd':
103 ValidUsage
= 'PcdsPatchableInModule'
104 elif ValidUsage
== 'FixedPcd':
105 ValidUsage
= 'PcdsFixedAtBuild'
106 elif ValidUsage
== 'Pcd':
107 ValidUsage
= 'PcdsDynamic'
108 elif ValidUsage
== 'PcdEx':
109 ValidUsage
= 'PcdsDynamicEx'
111 if ValidUsage
in ValidUsageDict
:
112 NewSectionDict
= ValidUsageDict
[ValidUsage
]
115 ValidUsageDict
[ValidUsage
] = NewSectionDict
116 Statement
+= TokenSpaceGuidCName
+ '.' + CName
117 Statement
+= '|' + DefaultValue
118 Statement
+= '|' + DatumType
119 Statement
+= '|' + Token
121 # generate tail comment
123 if Pcd
.GetSupModuleList():
124 Statement
+= GenDecTailComment(Pcd
.GetSupModuleList())
126 ArchList
= Pcd
.GetSupArchList()
128 SortedArch
= ' '.join(ArchList
)
129 if SortedArch
in NewSectionDict
:
130 NewSectionDict
[SortedArch
] = \
131 NewSectionDict
[SortedArch
] + [Statement
]
133 NewSectionDict
[SortedArch
] = [Statement
]
135 for ValidUsage
in ValidUsageDict
:
136 Content
+= GenSection(ValidUsage
, ValidUsageDict
[ValidUsage
], True, True)
140 def GenPcdErrorMsgSection(Package
, Content
):
141 if not Package
.PcdErrorCommentDict
:
145 # Generate '# [Error.<TokenSpcCName>]' section
147 Content
+= END_OF_LINE
+ END_OF_LINE
148 SectionComment
= TAB_COMMENT_SPLIT
+ END_OF_LINE
149 SectionComment
+= TAB_COMMENT_SPLIT
+ TAB_SPACE_SPLIT
+ TAB_PCD_ERROR_SECTION_COMMENT
+ END_OF_LINE
150 SectionComment
+= TAB_COMMENT_SPLIT
+ END_OF_LINE
151 TokenSpcCNameList
= []
154 # Get TokenSpcCName list in PcdErrorCommentDict in Package object
156 for (TokenSpcCName
, ErrorNumber
) in Package
.PcdErrorCommentDict
:
157 if TokenSpcCName
not in TokenSpcCNameList
:
158 TokenSpcCNameList
.append(TokenSpcCName
)
160 for TokenSpcCNameItem
in TokenSpcCNameList
:
161 SectionName
= TAB_COMMENT_SPLIT
+ TAB_SPACE_SPLIT
+ TAB_SECTION_START
+ TAB_PCD_ERROR
+ \
162 TAB_SPLIT
+ TokenSpcCNameItem
+ TAB_SECTION_END
+ END_OF_LINE
163 Content
+= SectionComment
164 Content
+= SectionName
165 for (TokenSpcCName
, ErrorNumber
) in Package
.PcdErrorCommentDict
:
166 if TokenSpcCNameItem
== TokenSpcCName
:
167 PcdErrorMsg
= GetLocalValue(Package
.PcdErrorCommentDict
[(TokenSpcCName
, ErrorNumber
)])
168 SectionItem
= TAB_COMMENT_SPLIT
+ TAB_SPACE_SPLIT
+ TAB_SPACE_SPLIT
+ \
169 ErrorNumber
+ TAB_SPACE_SPLIT
+ TAB_VALUE_SPLIT
+ TAB_SPACE_SPLIT
+ \
170 PcdErrorMsg
+ END_OF_LINE
171 Content
+= SectionItem
173 Content
+= TAB_COMMENT_SPLIT
176 def GenGuidProtocolPpi(Package
, Content
):
178 # generate [Guids] section
183 # Get the line offset need
184 # If the real one < the min one, use the min one
185 # else use the real one
186 for Guid
in Package
.GetGuidList():
187 if len(Guid
.GetCName()) > LeftOffset
:
188 LeftOffset
= len(Guid
.GetCName())
191 for Guid
in Package
.GetGuidList():
193 # Generate generic comment
195 HelpTextList
= Guid
.GetHelpTextList()
196 HelpStr
= _GetHelpStr(HelpTextList
)
197 CommentStr
= GenGenericCommentF(HelpStr
, 2)
199 Statement
= CommentStr
200 CName
= Guid
.GetCName()
201 Value
= GuidStringToGuidStructureString(Guid
.GetGuid())
202 Statement
+= CName
.ljust(LeftOffset
) + ' = ' + Value
204 # generate tail comment
206 if Guid
.GetSupModuleList():
207 Statement
+= GenDecTailComment(Guid
.GetSupModuleList())
208 ArchList
= Guid
.GetSupArchList()
210 SortedArch
= ' '.join(ArchList
)
211 if SortedArch
in NewSectionDict
:
212 NewSectionDict
[SortedArch
] = \
213 NewSectionDict
[SortedArch
] + [Statement
]
215 NewSectionDict
[SortedArch
] = [Statement
]
217 Content
+= GenSection('Guids', NewSectionDict
, True, True)
220 # generate [Protocols] section
224 # Get the line offset need
225 # If the real one < the min one, use the min one
226 # else use the real one
227 for Protocol
in Package
.GetProtocolList():
228 if len(Protocol
.GetCName()) > LeftOffset
:
229 LeftOffset
= len(Protocol
.GetCName())
231 for Protocol
in Package
.GetProtocolList():
233 # Generate generic comment
235 HelpTextList
= Protocol
.GetHelpTextList()
236 HelpStr
= _GetHelpStr(HelpTextList
)
237 CommentStr
= GenGenericCommentF(HelpStr
, 2)
239 Statement
= CommentStr
240 CName
= Protocol
.GetCName()
241 Value
= GuidStringToGuidStructureString(Protocol
.GetGuid())
242 Statement
+= CName
.ljust(LeftOffset
) + ' = ' + Value
245 # generate tail comment
247 if Protocol
.GetSupModuleList():
248 Statement
+= GenDecTailComment(Protocol
.GetSupModuleList())
249 ArchList
= Protocol
.GetSupArchList()
251 SortedArch
= ' '.join(ArchList
)
252 if SortedArch
in NewSectionDict
:
253 NewSectionDict
[SortedArch
] = \
254 NewSectionDict
[SortedArch
] + [Statement
]
256 NewSectionDict
[SortedArch
] = [Statement
]
258 Content
+= GenSection('Protocols', NewSectionDict
, True, True)
261 # generate [Ppis] section
265 # Get the line offset need
266 # If the real one < the min one, use the min one
267 # else use the real one
268 for Ppi
in Package
.GetPpiList():
269 if len(Ppi
.GetCName()) > LeftOffset
:
270 LeftOffset
= len(Ppi
.GetCName())
272 for Ppi
in Package
.GetPpiList():
274 # Generate generic comment
276 HelpTextList
= Ppi
.GetHelpTextList()
277 HelpStr
= _GetHelpStr(HelpTextList
)
278 CommentStr
= GenGenericCommentF(HelpStr
, 2)
280 Statement
= CommentStr
281 CName
= Ppi
.GetCName()
282 Value
= GuidStringToGuidStructureString(Ppi
.GetGuid())
283 Statement
+= CName
.ljust(LeftOffset
) + ' = ' + Value
286 # generate tail comment
288 if Ppi
.GetSupModuleList():
289 Statement
+= GenDecTailComment(Ppi
.GetSupModuleList())
290 ArchList
= Ppi
.GetSupArchList()
292 SortedArch
= ' '.join(ArchList
)
293 if SortedArch
in NewSectionDict
:
294 NewSectionDict
[SortedArch
] = \
295 NewSectionDict
[SortedArch
] + [Statement
]
297 NewSectionDict
[SortedArch
] = [Statement
]
299 Content
+= GenSection('Ppis', NewSectionDict
, True, True)
303 ## Transfer Package Object to Dec files
305 # Transfer all contents of a standard Package Object to a Dec file
307 # @param Package: A Package
309 def PackageToDec(Package
, DistHeader
= None):
311 # Init global information for the file
313 ContainerFile
= Package
.GetFullPath()
318 # Generate file header
320 PackageAbstract
= GetLocalValue(Package
.GetAbstract())
321 PackageDescription
= GetLocalValue(Package
.GetDescription())
322 PackageCopyright
= ''
324 for (Lang
, Copyright
) in Package
.GetCopyright():
327 PackageCopyright
= Copyright
328 for (Lang
, License
) in Package
.GetLicense():
331 PackageLicense
= License
332 if not PackageAbstract
and DistHeader
:
333 PackageAbstract
= GetLocalValue(DistHeader
.GetAbstract())
334 if not PackageDescription
and DistHeader
:
335 PackageDescription
= GetLocalValue(DistHeader
.GetDescription())
336 if not PackageCopyright
and DistHeader
:
337 for (Lang
, Copyright
) in DistHeader
.GetCopyright():
338 PackageCopyright
= Copyright
339 if not PackageLicense
and DistHeader
:
340 for (Lang
, License
) in DistHeader
.GetLicense():
341 PackageLicense
= License
344 # Generate header comment section of DEC file
346 Content
+= GenHeaderCommentSection(PackageAbstract
, \
347 PackageDescription
, \
349 PackageLicense
).replace('\r\n', '\n')
352 # Generate Binary header
354 for UserExtension
in Package
.GetUserExtensionList():
355 if UserExtension
.GetUserID() == TAB_BINARY_HEADER_USERID \
356 and UserExtension
.GetIdentifier() == TAB_BINARY_HEADER_IDENTIFIER
:
357 PackageBinaryAbstract
= GetLocalValue(UserExtension
.GetBinaryAbstract())
358 PackageBinaryDescription
= GetLocalValue(UserExtension
.GetBinaryDescription())
359 PackageBinaryCopyright
= ''
360 PackageBinaryLicense
= ''
361 for (Lang
, Copyright
) in UserExtension
.GetBinaryCopyright():
362 PackageBinaryCopyright
= Copyright
363 for (Lang
, License
) in UserExtension
.GetBinaryLicense():
364 PackageBinaryLicense
= License
365 if PackageBinaryAbstract
and PackageBinaryDescription
and \
366 PackageBinaryCopyright
and PackageBinaryLicense
:
367 Content
+= GenHeaderCommentSection(PackageBinaryAbstract
,
368 PackageBinaryDescription
,
369 PackageBinaryCopyright
,
370 PackageBinaryLicense
,
374 # Generate PACKAGE_UNI_FILE for the Package
376 FileHeader
= GenHeaderCommentSection(PackageAbstract
, PackageDescription
, PackageCopyright
, PackageLicense
, False, \
377 TAB_COMMENT_EDK1_SPLIT
)
378 GenPackageUNIEncodeFile(Package
, FileHeader
)
381 # for each section, maintain a dict, sorted arch will be its key,
382 #statement list will be its data
383 # { 'Arch1 Arch2 Arch3': [statement1, statement2],
384 # 'Arch1' : [statement1, statement3]
389 # generate [Defines] section
392 NewSectionDict
= {TAB_ARCH_COMMON
: []}
395 Statement
= (u
'%s ' % TAB_DEC_DEFINES_DEC_SPECIFICATION
).ljust(LeftOffset
) + u
'= %s' % '0x00010017'
396 SpecialItemList
.append(Statement
)
398 BaseName
= Package
.GetBaseName()
399 if BaseName
.startswith('.') or BaseName
.startswith('-'):
400 BaseName
= '_' + BaseName
401 Statement
= (u
'%s ' % TAB_DEC_DEFINES_PACKAGE_NAME
).ljust(LeftOffset
) + u
'= %s' % BaseName
402 SpecialItemList
.append(Statement
)
404 Statement
= (u
'%s ' % TAB_DEC_DEFINES_PACKAGE_VERSION
).ljust(LeftOffset
) + u
'= %s' % Package
.GetVersion()
405 SpecialItemList
.append(Statement
)
407 Statement
= (u
'%s ' % TAB_DEC_DEFINES_PACKAGE_GUID
).ljust(LeftOffset
) + u
'= %s' % Package
.GetGuid()
408 SpecialItemList
.append(Statement
)
411 Statement
= (u
'%s ' % TAB_DEC_DEFINES_PKG_UNI_FILE
).ljust(LeftOffset
) + u
'= %s' % Package
.GetBaseName() + '.uni'
412 SpecialItemList
.append(Statement
)
414 for SortedArch
in NewSectionDict
:
415 NewSectionDict
[SortedArch
] = \
416 NewSectionDict
[SortedArch
] + SpecialItemList
417 Content
+= GenSection('Defines', NewSectionDict
)
420 # generate [Includes] section
423 IncludeArchList
= Package
.GetIncludeArchList()
425 for Path
, ArchList
in IncludeArchList
:
428 SortedArch
= ' '.join(ArchList
)
429 if SortedArch
in NewSectionDict
:
430 NewSectionDict
[SortedArch
] = \
431 NewSectionDict
[SortedArch
] + [ConvertPath(Statement
)]
433 NewSectionDict
[SortedArch
] = [ConvertPath(Statement
)]
435 Content
+= GenSection('Includes', NewSectionDict
)
438 # generate [guids][protocols][ppis] sections
440 Content
= GenGuidProtocolPpi(Package
, Content
)
443 # generate [LibraryClasses] section
446 for LibraryClass
in Package
.GetLibraryClassList():
448 # Generate generic comment
450 HelpTextList
= LibraryClass
.GetHelpTextList()
451 HelpStr
= _GetHelpStr(HelpTextList
)
453 HelpStr
= '@libraryclass' + HelpStr
454 CommentStr
= GenGenericCommentF(HelpStr
, 2, False, True)
456 Statement
= CommentStr
457 Name
= LibraryClass
.GetLibraryClass()
458 IncludeHeader
= LibraryClass
.GetIncludeHeader()
459 Statement
+= Name
+ '|' + ConvertPath(IncludeHeader
)
461 # generate tail comment
463 if LibraryClass
.GetSupModuleList():
465 GenDecTailComment(LibraryClass
.GetSupModuleList())
466 ArchList
= LibraryClass
.GetSupArchList()
468 SortedArch
= ' '.join(ArchList
)
469 if SortedArch
in NewSectionDict
:
470 NewSectionDict
[SortedArch
] = \
471 NewSectionDict
[SortedArch
] + [Statement
]
473 NewSectionDict
[SortedArch
] = [Statement
]
475 Content
+= GenSection('LibraryClasses', NewSectionDict
, True, True)
478 # Generate '# [Error.<TokenSpcCName>]' section
480 Content
= GenPcdErrorMsgSection(Package
, Content
)
482 Content
= GenPcd(Package
, Content
)
485 # generate [UserExtensions] section
488 for UserExtension
in Package
.GetUserExtensionList():
489 if UserExtension
.GetUserID() == TAB_BINARY_HEADER_USERID
and \
490 UserExtension
.GetIdentifier() == TAB_BINARY_HEADER_IDENTIFIER
:
493 # Generate Private Section first
494 if UserExtension
.GetUserID() == DT
.TAB_INTEL
and UserExtension
.GetIdentifier() == DT
.TAB_PRIVATE
:
495 Content
+= '\n' + UserExtension
.GetStatement()
498 Statement
= UserExtension
.GetStatement()
502 LineList
= Statement
.split('\n')
504 for Line
in LineList
:
505 NewStatement
+= " %s\n" % Line
508 SectionName
= 'UserExtensions'
509 UserId
= UserExtension
.GetUserID()
512 UserId
= '"' + UserId
+ '"'
513 SectionName
+= '.' + UserId
514 if UserExtension
.GetIdentifier():
515 SectionName
+= '.' + '"' + UserExtension
.GetIdentifier() + '"'
516 if not UserExtension
.GetSupArchList():
517 SectionList
.append(SectionName
)
519 for Arch
in UserExtension
.GetSupArchList():
520 SectionList
.append(SectionName
+ '.' + Arch
)
521 SectionName
= ', '.join(SectionList
)
522 SectionName
= ''.join(['[', SectionName
, ']\n'])
523 Content
+= '\n' + SectionName
+ NewStatement
525 SaveFileOnChange(ContainerFile
, Content
, False)
526 if DistHeader
.ReadOnly
:
527 os
.chmod(ContainerFile
, stat
.S_IRUSR|stat
.S_IRGRP|stat
.S_IROTH
)
529 os
.chmod(ContainerFile
, stat
.S_IRUSR|stat
.S_IRGRP|stat
.S_IROTH|stat
.S_IWUSR|stat
.S_IWGRP|stat
.S_IWOTH
)
532 ## GenPackageUNIEncodeFile
533 # GenPackageUNIEncodeFile, default is a UCS-2LE encode file
535 def GenPackageUNIEncodeFile(PackageObject
, UniFileHeader
= '', Encoding
=TAB_ENCODING_UTF16LE
):
537 OnlyLANGUAGE_EN_X
= True
539 BinaryDescription
= []
541 # If more than one language code is used for any element that would be present in the PACKAGE_UNI_FILE,
542 # then the PACKAGE_UNI_FILE must be created.
544 for (Key
, Value
) in PackageObject
.GetAbstract() + PackageObject
.GetDescription():
545 if Key
== TAB_LANGUAGE_EN_X
:
548 OnlyLANGUAGE_EN_X
= False
550 for UserExtension
in PackageObject
.GetUserExtensionList():
551 if UserExtension
.GetUserID() == TAB_BINARY_HEADER_USERID \
552 and UserExtension
.GetIdentifier() == TAB_BINARY_HEADER_IDENTIFIER
:
553 for (Key
, Value
) in UserExtension
.GetBinaryAbstract():
554 if Key
== TAB_LANGUAGE_EN_X
:
557 OnlyLANGUAGE_EN_X
= False
558 BinaryAbstract
.append((Key
, Value
))
560 for (Key
, Value
) in UserExtension
.GetBinaryDescription():
561 if Key
== TAB_LANGUAGE_EN_X
:
564 OnlyLANGUAGE_EN_X
= False
565 BinaryDescription
.append((Key
, Value
))
567 for Pcd
in PackageObject
.GetPcdList():
568 for TxtObj
in Pcd
.GetPromptList() + Pcd
.GetHelpTextList():
569 if TxtObj
.GetLang() == TAB_LANGUAGE_EN_X
:
572 OnlyLANGUAGE_EN_X
= False
574 for PcdError
in Pcd
.GetPcdErrorsList():
575 if PcdError
.GetErrorNumber().startswith('0x') or PcdError
.GetErrorNumber().startswith('0X'):
576 for (Key
, Value
) in PcdError
.GetErrorMessageList():
577 if Key
== TAB_LANGUAGE_EN_X
:
580 OnlyLANGUAGE_EN_X
= False
583 elif OnlyLANGUAGE_EN_X
:
586 PackageObject
.UNIFlag
= True
588 if not os
.path
.exists(os
.path
.dirname(PackageObject
.GetFullPath())):
589 os
.makedirs(os
.path
.dirname(PackageObject
.GetFullPath()))
591 ContainerFile
= GetUniFileName(os
.path
.dirname(PackageObject
.GetFullPath()), PackageObject
.GetBaseName())
593 Content
= UniFileHeader
+ '\r\n'
596 Content
+= FormatUniEntry('#string ' + TAB_DEC_PACKAGE_ABSTRACT
, PackageObject
.GetAbstract(), ContainerFile
) + '\r\n'
598 Content
+= FormatUniEntry('#string ' + TAB_DEC_PACKAGE_DESCRIPTION
, PackageObject
.GetDescription(), ContainerFile
) \
601 Content
+= FormatUniEntry('#string ' + TAB_DEC_BINARY_ABSTRACT
, BinaryAbstract
, ContainerFile
) + '\r\n'
603 Content
+= FormatUniEntry('#string ' + TAB_DEC_BINARY_DESCRIPTION
, BinaryDescription
, ContainerFile
) + '\r\n'
607 for Pcd
in PackageObject
.GetPcdList():
608 # Generate Prompt for each Pcd
609 PcdPromptStrName
= '#string ' + 'STR_' + Pcd
.GetTokenSpaceGuidCName() + '_' + Pcd
.GetCName() + '_PROMPT '
611 for TxtObj
in Pcd
.GetPromptList():
612 Lang
= TxtObj
.GetLang()
613 PromptStr
= TxtObj
.GetString()
615 # Avoid generating the same PROMPT entry more than one time.
617 if (PcdPromptStrName
, Lang
) not in PromptGenList
:
618 TokenValueList
.append((Lang
, PromptStr
))
619 PromptGenList
.append((PcdPromptStrName
, Lang
))
620 PromptString
= FormatUniEntry(PcdPromptStrName
, TokenValueList
, ContainerFile
) + '\r\n'
621 if PromptString
not in Content
:
622 Content
+= PromptString
624 # Generate Help String for each Pcd
625 PcdHelpStrName
= '#string ' + 'STR_' + Pcd
.GetTokenSpaceGuidCName() + '_' + Pcd
.GetCName() + '_HELP '
627 for TxtObj
in Pcd
.GetHelpTextList():
628 Lang
= TxtObj
.GetLang()
629 HelpStr
= TxtObj
.GetString()
631 # Avoid generating the same HELP entry more than one time.
633 if (PcdHelpStrName
, Lang
) not in HelpTextGenList
:
634 TokenValueList
.append((Lang
, HelpStr
))
635 HelpTextGenList
.append((PcdHelpStrName
, Lang
))
636 HelpTextString
= FormatUniEntry(PcdHelpStrName
, TokenValueList
, ContainerFile
) + '\r\n'
637 if HelpTextString
not in Content
:
638 Content
+= HelpTextString
640 # Generate PcdError for each Pcd if ErrorNo exist.
641 for PcdError
in Pcd
.GetPcdErrorsList():
642 ErrorNo
= PcdError
.GetErrorNumber()
643 if ErrorNo
.startswith(TAB_HEX_START
) or ErrorNo
.startswith(TAB_CAPHEX_START
):
644 PcdErrStrName
= '#string ' + TAB_STR_TOKENCNAME
+ TAB_UNDERLINE_SPLIT
+ Pcd
.GetTokenSpaceGuidCName() \
645 + TAB_UNDERLINE_SPLIT
+ TAB_STR_TOKENERR \
646 + TAB_UNDERLINE_SPLIT
+ ErrorNo
[2:]
647 PcdErrString
= FormatUniEntry(PcdErrStrName
, PcdError
.GetErrorMessageList(), ContainerFile
) + '\r\n'
648 if PcdErrString
not in Content
:
649 Content
+= PcdErrString
651 File
= codecs
.open(ContainerFile
, 'w', Encoding
)
652 File
.write(u
'\uFEFF' + Content
)
654 Md5Sigature
= md5
.new(__FileHookOpen__(str(ContainerFile
), 'rb').read())
655 Md5Sum
= Md5Sigature
.hexdigest()
656 if (ContainerFile
, Md5Sum
) not in PackageObject
.FileList
:
657 PackageObject
.FileList
.append((ContainerFile
, Md5Sum
))
663 # @param PcdErrObject: PcdErrorObject
665 # @retval CommentStr: Generated comment lines, with prefix "#"
667 def GenPcdErrComment (PcdErrObject
):
669 ErrorCode
= PcdErrObject
.GetErrorNumber()
670 ValidValueRange
= PcdErrObject
.GetValidValueRange()
672 CommentStr
= TAB_COMMENT_SPLIT
+ TAB_SPACE_SPLIT
+ TAB_PCD_VALIDRANGE
+ TAB_SPACE_SPLIT
674 CommentStr
+= ErrorCode
+ TAB_SPACE_SPLIT
+ TAB_VALUE_SPLIT
+ TAB_SPACE_SPLIT
675 CommentStr
+= ValidValueRange
+ END_OF_LINE
677 ValidValue
= PcdErrObject
.GetValidValue()
680 [Value
for Value
in ValidValue
.split(TAB_SPACE_SPLIT
) if Value
]
681 CommentStr
= TAB_COMMENT_SPLIT
+ TAB_SPACE_SPLIT
+ TAB_PCD_VALIDLIST
+ TAB_SPACE_SPLIT
683 CommentStr
+= ErrorCode
+ TAB_SPACE_SPLIT
+ TAB_VALUE_SPLIT
+ TAB_SPACE_SPLIT
684 CommentStr
+= TAB_COMMA_SPLIT
.join(ValidValueList
) + END_OF_LINE
686 Expression
= PcdErrObject
.GetExpression()
688 CommentStr
= TAB_COMMENT_SPLIT
+ TAB_SPACE_SPLIT
+ TAB_PCD_EXPRESSION
+ TAB_SPACE_SPLIT
690 CommentStr
+= ErrorCode
+ TAB_SPACE_SPLIT
+ TAB_VALUE_SPLIT
+ TAB_SPACE_SPLIT
691 CommentStr
+= Expression
+ END_OF_LINE