3 # This file contained the logical of transfer package object to DEC files.
5 # Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
7 # This program and the accompanying materials are licensed and made available
8 # under the terms and conditions of the BSD License which accompanies this
9 # distribution. The full text of the license may be found at
10 # http://opensource.org/licenses/bsd-license.php
12 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 from Library
.Parsing
import GenSection
21 from Library
.CommentGenerating
import GenHeaderCommentSection
22 from Library
.CommentGenerating
import GenGenericCommentF
23 from Library
.CommentGenerating
import GenDecTailComment
24 from Library
.CommentGenerating
import _GetHelpStr
25 from Library
.Misc
import GuidStringToGuidStructureString
26 from Library
.Misc
import SaveFileOnChange
27 from Library
.Misc
import ConvertPath
28 from Library
.DataType
import TAB_SPACE_SPLIT
29 from Library
.DataType
import TAB_COMMA_SPLIT
30 from Library
.DataType
import TAB_ARCH_COMMON
31 from Library
.DataType
import TAB_DEC_DEFINES_DEC_SPECIFICATION
32 from Library
.DataType
import TAB_DEC_DEFINES_PACKAGE_NAME
33 from Library
.DataType
import TAB_DEC_DEFINES_PACKAGE_GUID
34 from Library
.DataType
import TAB_DEC_DEFINES_PACKAGE_VERSION
37 def GenPcd(Package
, Content
):
39 # generate [Pcd] section
40 # <TokenSpcCName>.<TokenCName>|<Value>|<DatumType>|<Token>
43 for Pcd
in Package
.GetPcdList():
45 # Generate generic comment
47 HelpTextList
= Pcd
.GetHelpTextList()
48 HelpStr
= _GetHelpStr(HelpTextList
)
49 CommentStr
= GenGenericCommentF(HelpStr
, 2)
51 PcdErrList
= Pcd
.GetPcdErrorsList()
53 CommentStr
+= GenPcdErrComment(PcdErrList
[0])
54 Statement
= CommentStr
56 CName
= Pcd
.GetCName()
57 TokenSpaceGuidCName
= Pcd
.GetTokenSpaceGuidCName()
58 DefaultValue
= Pcd
.GetDefaultValue()
59 DatumType
= Pcd
.GetDatumType()
60 Token
= Pcd
.GetToken()
61 ValidUsage
= Pcd
.GetValidUsage()
63 if ValidUsage
== 'FeaturePcd':
64 ValidUsage
= 'PcdsFeatureFlag'
65 elif ValidUsage
== 'PatchPcd':
66 ValidUsage
= 'PcdsPatchableInModule'
67 elif ValidUsage
== 'FixedPcd':
68 ValidUsage
= 'PcdsFixedAtBuild'
69 elif ValidUsage
== 'Pcd':
70 ValidUsage
= 'PcdsDynamic'
71 elif ValidUsage
== 'PcdEx':
72 ValidUsage
= 'PcdsDynamicEx'
74 if ValidUsage
in ValidUsageDict
:
75 NewSectionDict
= ValidUsageDict
[ValidUsage
]
78 ValidUsageDict
[ValidUsage
] = NewSectionDict
79 Statement
+= TokenSpaceGuidCName
+ '.' + CName
80 Statement
+= '|' + DefaultValue
81 Statement
+= '|' + DatumType
82 Statement
+= '|' + Token
84 # generate tail comment
86 if Pcd
.GetSupModuleList():
87 Statement
+= GenDecTailComment(Pcd
.GetSupModuleList())
89 ArchList
= Pcd
.GetSupArchList()
91 SortedArch
= ' '.join(ArchList
)
92 if SortedArch
in NewSectionDict
:
93 NewSectionDict
[SortedArch
] = \
94 NewSectionDict
[SortedArch
] + [Statement
]
96 NewSectionDict
[SortedArch
] = [Statement
]
98 for ValidUsage
in ValidUsageDict
:
99 Content
+= GenSection(ValidUsage
, ValidUsageDict
[ValidUsage
])
103 def GenGuidProtocolPpi(Package
, Content
):
105 # generate [Guids] section
108 for Guid
in Package
.GetGuidList():
110 # Generate generic comment
112 HelpTextList
= Guid
.GetHelpTextList()
113 HelpStr
= _GetHelpStr(HelpTextList
)
114 CommentStr
= GenGenericCommentF(HelpStr
, 2)
116 Statement
= CommentStr
117 CName
= Guid
.GetCName()
118 Value
= GuidStringToGuidStructureString(Guid
.GetGuid())
119 Statement
+= CName
+ ' = ' + Value
121 # generate tail comment
123 if Guid
.GetSupModuleList():
124 Statement
+= GenDecTailComment(Guid
.GetSupModuleList())
125 ArchList
= Guid
.GetSupArchList()
127 SortedArch
= ' '.join(ArchList
)
128 if SortedArch
in NewSectionDict
:
129 NewSectionDict
[SortedArch
] = \
130 NewSectionDict
[SortedArch
] + [Statement
]
132 NewSectionDict
[SortedArch
] = [Statement
]
134 Content
+= GenSection('Guids', NewSectionDict
)
137 # generate [Protocols] section
140 for Protocol
in Package
.GetProtocolList():
142 # Generate generic comment
144 HelpTextList
= Protocol
.GetHelpTextList()
145 HelpStr
= _GetHelpStr(HelpTextList
)
146 CommentStr
= GenGenericCommentF(HelpStr
, 2)
148 Statement
= CommentStr
149 CName
= Protocol
.GetCName()
150 Value
= GuidStringToGuidStructureString(Protocol
.GetGuid())
151 Statement
+= CName
+ ' = ' + Value
154 # generate tail comment
156 if Protocol
.GetSupModuleList():
157 Statement
+= GenDecTailComment(Protocol
.GetSupModuleList())
158 ArchList
= Protocol
.GetSupArchList()
160 SortedArch
= ' '.join(ArchList
)
161 if SortedArch
in NewSectionDict
:
162 NewSectionDict
[SortedArch
] = \
163 NewSectionDict
[SortedArch
] + [Statement
]
165 NewSectionDict
[SortedArch
] = [Statement
]
167 Content
+= GenSection('Protocols', NewSectionDict
)
170 # generate [Ppis] section
173 for Ppi
in Package
.GetPpiList():
175 # Generate generic comment
177 HelpTextList
= Ppi
.GetHelpTextList()
178 HelpStr
= _GetHelpStr(HelpTextList
)
179 CommentStr
= GenGenericCommentF(HelpStr
, 2)
181 Statement
= CommentStr
182 CName
= Ppi
.GetCName()
183 Value
= GuidStringToGuidStructureString(Ppi
.GetGuid())
184 Statement
+= CName
+ ' = ' + Value
187 # generate tail comment
189 if Ppi
.GetSupModuleList():
190 Statement
+= GenDecTailComment(Ppi
.GetSupModuleList())
191 ArchList
= Ppi
.GetSupArchList()
193 SortedArch
= ' '.join(ArchList
)
194 if SortedArch
in NewSectionDict
:
195 NewSectionDict
[SortedArch
] = \
196 NewSectionDict
[SortedArch
] + [Statement
]
198 NewSectionDict
[SortedArch
] = [Statement
]
200 Content
+= GenSection('Ppis', NewSectionDict
)
204 ## Transfer Package Object to Dec files
206 # Transfer all contents of a standard Package Object to a Dec file
208 # @param Package: A Package
210 def PackageToDec(Package
):
212 # Init global information for the file
214 ContainerFile
= Package
.GetFullPath()
218 # generate header comment section
220 Content
+= GenHeaderCommentSection(Package
.GetAbstract(), \
221 Package
.GetDescription(), \
222 Package
.GetCopyright(), \
223 Package
.GetLicense())
226 # for each section, maintain a dict, sorted arch will be its key,
227 #statement list will be its data
228 # { 'Arch1 Arch2 Arch3': [statement1, statement2],
229 # 'Arch1' : [statement1, statement3]
234 # generate [Defines] section
236 NewSectionDict
= {TAB_ARCH_COMMON
: []}
239 Statement
= '%s = %s' % (TAB_DEC_DEFINES_DEC_SPECIFICATION
, '0x00010017')
240 SpecialItemList
.append(Statement
)
242 BaseName
= Package
.GetBaseName()
243 if BaseName
.startswith('.') or BaseName
.startswith('-'):
244 BaseName
= '_' + BaseName
245 Statement
= '%s = %s' % (TAB_DEC_DEFINES_PACKAGE_NAME
, BaseName
)
246 SpecialItemList
.append(Statement
)
247 Statement
= '%s = %s' % (TAB_DEC_DEFINES_PACKAGE_VERSION
, Package
.GetVersion())
248 SpecialItemList
.append(Statement
)
249 Statement
= '%s = %s' % (TAB_DEC_DEFINES_PACKAGE_GUID
, Package
.GetGuid())
250 SpecialItemList
.append(Statement
)
251 for SortedArch
in NewSectionDict
:
252 NewSectionDict
[SortedArch
] = \
253 NewSectionDict
[SortedArch
] + SpecialItemList
254 Content
+= GenSection('Defines', NewSectionDict
)
257 # generate [Includes] section
260 IncludeArchList
= Package
.GetIncludeArchList()
262 for Path
, ArchList
in IncludeArchList
:
265 SortedArch
= ' '.join(ArchList
)
266 if SortedArch
in NewSectionDict
:
267 NewSectionDict
[SortedArch
] = \
268 NewSectionDict
[SortedArch
] + [ConvertPath(Statement
)]
270 NewSectionDict
[SortedArch
] = [ConvertPath(Statement
)]
272 Content
+= GenSection('Includes', NewSectionDict
)
274 Content
= GenGuidProtocolPpi(Package
, Content
)
277 # generate [LibraryClasses] section
280 for LibraryClass
in Package
.GetLibraryClassList():
282 # Generate generic comment
284 HelpTextList
= LibraryClass
.GetHelpTextList()
285 HelpStr
= _GetHelpStr(HelpTextList
)
287 HelpStr
= '@libraryclass ' + HelpStr
288 CommentStr
= GenGenericCommentF(HelpStr
, 2)
290 Statement
= CommentStr
291 Name
= LibraryClass
.GetLibraryClass()
292 IncludeHeader
= LibraryClass
.GetIncludeHeader()
293 Statement
+= Name
+ '|' + ConvertPath(IncludeHeader
)
295 # generate tail comment
297 if LibraryClass
.GetSupModuleList():
299 GenDecTailComment(LibraryClass
.GetSupModuleList())
300 ArchList
= LibraryClass
.GetSupArchList()
302 SortedArch
= ' '.join(ArchList
)
303 if SortedArch
in NewSectionDict
:
304 NewSectionDict
[SortedArch
] = \
305 NewSectionDict
[SortedArch
] + [Statement
]
307 NewSectionDict
[SortedArch
] = [Statement
]
309 Content
+= GenSection('LibraryClasses', NewSectionDict
)
311 Content
= GenPcd(Package
, Content
)
314 # generate [UserExtensions] section
317 for UserExtension
in Package
.GetUserExtensionList():
318 Statement
= UserExtension
.GetStatement()
323 SectionName
= 'UserExtensions'
324 UserId
= UserExtension
.GetUserID()
327 UserId
= '"' + UserId
+ '"'
328 SectionName
+= '.' + UserId
329 if UserExtension
.GetIdentifier():
330 SectionName
+= '.' + '"' + UserExtension
.GetIdentifier() + '"'
331 if not UserExtension
.GetSupArchList():
332 SectionList
.append(SectionName
)
334 for Arch
in UserExtension
.GetSupArchList():
335 SectionList
.append(SectionName
+ '.' + Arch
)
336 SectionName
= ', '.join(SectionList
)
337 SectionName
= ''.join(['[', SectionName
, ']\n'])
338 Content
+= '\n\n' + SectionName
+ Statement
340 SaveFileOnChange(ContainerFile
, Content
, False)
345 # @param PcdErrObject: PcdErrorObject
347 # @retval CommentStr: Generated comment lines, with prefix "#"
349 def GenPcdErrComment (PcdErrObject
):
351 ValidValueRange
= PcdErrObject
.GetValidValueRange()
353 CommentStr
= "# @ValidRange " + ValidValueRange
+ EndOfLine
355 ValidValue
= PcdErrObject
.GetValidValue()
358 [Value
for Value
in ValidValue
.split(TAB_SPACE_SPLIT
) if Value
]
360 "# @ValidList " + TAB_COMMA_SPLIT
.join(ValidValueList
) + EndOfLine
362 Expression
= PcdErrObject
.GetExpression()
364 CommentStr
= "# @Expression " + Expression
+ EndOfLine