]>
Commit | Line | Data |
---|---|---|
1 | ## @file GenDecFile.py\r | |
2 | #\r | |
3 | # This file contained the logical of transfer package object to DEC files.\r | |
4 | #\r | |
5 | # Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r | |
6 | #\r | |
7 | # This program and the accompanying materials are licensed and made available \r | |
8 | # under the terms and conditions of the BSD License which accompanies this \r | |
9 | # distribution. The full text of the license may be found at \r | |
10 | # http://opensource.org/licenses/bsd-license.php\r | |
11 | #\r | |
12 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
13 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
14 | #\r | |
15 | \r | |
16 | '''\r | |
17 | GenDEC\r | |
18 | '''\r | |
19 | \r | |
20 | from Library.Parsing import GenSection\r | |
21 | from Library.CommentGenerating import GenHeaderCommentSection\r | |
22 | from Library.CommentGenerating import GenGenericCommentF\r | |
23 | from Library.CommentGenerating import GenDecTailComment\r | |
24 | from Library.CommentGenerating import _GetHelpStr\r | |
25 | from Library.Misc import GuidStringToGuidStructureString\r | |
26 | from Library.Misc import SaveFileOnChange\r | |
27 | from Library.Misc import ConvertPath\r | |
28 | from Library.DataType import TAB_SPACE_SPLIT\r | |
29 | from Library.DataType import TAB_COMMA_SPLIT\r | |
30 | from Library.DataType import TAB_ARCH_COMMON\r | |
31 | from Library.DataType import TAB_DEC_DEFINES_DEC_SPECIFICATION\r | |
32 | from Library.DataType import TAB_DEC_DEFINES_PACKAGE_NAME\r | |
33 | from Library.DataType import TAB_DEC_DEFINES_PACKAGE_GUID\r | |
34 | from Library.DataType import TAB_DEC_DEFINES_PACKAGE_VERSION\r | |
35 | \r | |
36 | \r | |
37 | def GenPcd(Package, Content):\r | |
38 | #\r | |
39 | # generate [Pcd] section\r | |
40 | # <TokenSpcCName>.<TokenCName>|<Value>|<DatumType>|<Token> \r | |
41 | #\r | |
42 | ValidUsageDict = {}\r | |
43 | for Pcd in Package.GetPcdList():\r | |
44 | #\r | |
45 | # Generate generic comment\r | |
46 | #\r | |
47 | HelpTextList = Pcd.GetHelpTextList()\r | |
48 | HelpStr = _GetHelpStr(HelpTextList)\r | |
49 | CommentStr = GenGenericCommentF(HelpStr, 2)\r | |
50 | \r | |
51 | PcdErrList = Pcd.GetPcdErrorsList()\r | |
52 | if PcdErrList:\r | |
53 | CommentStr += GenPcdErrComment(PcdErrList[0])\r | |
54 | Statement = CommentStr\r | |
55 | \r | |
56 | CName = Pcd.GetCName()\r | |
57 | TokenSpaceGuidCName = Pcd.GetTokenSpaceGuidCName()\r | |
58 | DefaultValue = Pcd.GetDefaultValue()\r | |
59 | DatumType = Pcd.GetDatumType()\r | |
60 | Token = Pcd.GetToken()\r | |
61 | ValidUsage = Pcd.GetValidUsage()\r | |
62 | \r | |
63 | if ValidUsage == 'FeaturePcd':\r | |
64 | ValidUsage = 'PcdsFeatureFlag'\r | |
65 | elif ValidUsage == 'PatchPcd':\r | |
66 | ValidUsage = 'PcdsPatchableInModule'\r | |
67 | elif ValidUsage == 'FixedPcd':\r | |
68 | ValidUsage = 'PcdsFixedAtBuild'\r | |
69 | elif ValidUsage == 'Pcd':\r | |
70 | ValidUsage = 'PcdsDynamic'\r | |
71 | elif ValidUsage == 'PcdEx':\r | |
72 | ValidUsage = 'PcdsDynamicEx'\r | |
73 | \r | |
74 | if ValidUsage in ValidUsageDict:\r | |
75 | NewSectionDict = ValidUsageDict[ValidUsage]\r | |
76 | else:\r | |
77 | NewSectionDict = {}\r | |
78 | ValidUsageDict[ValidUsage] = NewSectionDict\r | |
79 | Statement += TokenSpaceGuidCName + '.' + CName\r | |
80 | Statement += '|' + DefaultValue\r | |
81 | Statement += '|' + DatumType\r | |
82 | Statement += '|' + Token\r | |
83 | #\r | |
84 | # generate tail comment\r | |
85 | #\r | |
86 | if Pcd.GetSupModuleList():\r | |
87 | Statement += GenDecTailComment(Pcd.GetSupModuleList())\r | |
88 | \r | |
89 | ArchList = Pcd.GetSupArchList()\r | |
90 | ArchList.sort()\r | |
91 | SortedArch = ' '.join(ArchList)\r | |
92 | if SortedArch in NewSectionDict:\r | |
93 | NewSectionDict[SortedArch] = \\r | |
94 | NewSectionDict[SortedArch] + [Statement]\r | |
95 | else:\r | |
96 | NewSectionDict[SortedArch] = [Statement] \r | |
97 | \r | |
98 | for ValidUsage in ValidUsageDict:\r | |
99 | Content += GenSection(ValidUsage, ValidUsageDict[ValidUsage])\r | |
100 | \r | |
101 | return Content\r | |
102 | \r | |
103 | def GenGuidProtocolPpi(Package, Content):\r | |
104 | #\r | |
105 | # generate [Guids] section\r | |
106 | #\r | |
107 | NewSectionDict = {}\r | |
108 | for Guid in Package.GetGuidList():\r | |
109 | #\r | |
110 | # Generate generic comment\r | |
111 | #\r | |
112 | HelpTextList = Guid.GetHelpTextList()\r | |
113 | HelpStr = _GetHelpStr(HelpTextList)\r | |
114 | CommentStr = GenGenericCommentF(HelpStr, 2)\r | |
115 | \r | |
116 | Statement = CommentStr\r | |
117 | CName = Guid.GetCName()\r | |
118 | Value = GuidStringToGuidStructureString(Guid.GetGuid())\r | |
119 | Statement += CName + ' = ' + Value\r | |
120 | #\r | |
121 | # generate tail comment\r | |
122 | #\r | |
123 | if Guid.GetSupModuleList():\r | |
124 | Statement += GenDecTailComment(Guid.GetSupModuleList()) \r | |
125 | ArchList = Guid.GetSupArchList()\r | |
126 | ArchList.sort()\r | |
127 | SortedArch = ' '.join(ArchList)\r | |
128 | if SortedArch in NewSectionDict:\r | |
129 | NewSectionDict[SortedArch] = \\r | |
130 | NewSectionDict[SortedArch] + [Statement]\r | |
131 | else:\r | |
132 | NewSectionDict[SortedArch] = [Statement] \r | |
133 | \r | |
134 | Content += GenSection('Guids', NewSectionDict) \r | |
135 | \r | |
136 | #\r | |
137 | # generate [Protocols] section\r | |
138 | #\r | |
139 | NewSectionDict = {}\r | |
140 | for Protocol in Package.GetProtocolList():\r | |
141 | #\r | |
142 | # Generate generic comment\r | |
143 | #\r | |
144 | HelpTextList = Protocol.GetHelpTextList()\r | |
145 | HelpStr = _GetHelpStr(HelpTextList)\r | |
146 | CommentStr = GenGenericCommentF(HelpStr, 2) \r | |
147 | \r | |
148 | Statement = CommentStr \r | |
149 | CName = Protocol.GetCName()\r | |
150 | Value = GuidStringToGuidStructureString(Protocol.GetGuid())\r | |
151 | Statement += CName + ' = ' + Value\r | |
152 | \r | |
153 | #\r | |
154 | # generate tail comment\r | |
155 | #\r | |
156 | if Protocol.GetSupModuleList():\r | |
157 | Statement += GenDecTailComment(Protocol.GetSupModuleList())\r | |
158 | ArchList = Protocol.GetSupArchList()\r | |
159 | ArchList.sort()\r | |
160 | SortedArch = ' '.join(ArchList)\r | |
161 | if SortedArch in NewSectionDict:\r | |
162 | NewSectionDict[SortedArch] = \\r | |
163 | NewSectionDict[SortedArch] + [Statement]\r | |
164 | else:\r | |
165 | NewSectionDict[SortedArch] = [Statement] \r | |
166 | \r | |
167 | Content += GenSection('Protocols', NewSectionDict) \r | |
168 | \r | |
169 | #\r | |
170 | # generate [Ppis] section\r | |
171 | #\r | |
172 | NewSectionDict = {}\r | |
173 | for Ppi in Package.GetPpiList():\r | |
174 | #\r | |
175 | # Generate generic comment\r | |
176 | #\r | |
177 | HelpTextList = Ppi.GetHelpTextList()\r | |
178 | HelpStr = _GetHelpStr(HelpTextList)\r | |
179 | CommentStr = GenGenericCommentF(HelpStr, 2)\r | |
180 | \r | |
181 | Statement = CommentStr\r | |
182 | CName = Ppi.GetCName()\r | |
183 | Value = GuidStringToGuidStructureString(Ppi.GetGuid())\r | |
184 | Statement += CName + ' = ' + Value\r | |
185 | \r | |
186 | #\r | |
187 | # generate tail comment\r | |
188 | #\r | |
189 | if Ppi.GetSupModuleList():\r | |
190 | Statement += GenDecTailComment(Ppi.GetSupModuleList())\r | |
191 | ArchList = Ppi.GetSupArchList()\r | |
192 | ArchList.sort()\r | |
193 | SortedArch = ' '.join(ArchList)\r | |
194 | if SortedArch in NewSectionDict:\r | |
195 | NewSectionDict[SortedArch] = \\r | |
196 | NewSectionDict[SortedArch] + [Statement]\r | |
197 | else:\r | |
198 | NewSectionDict[SortedArch] = [Statement] \r | |
199 | \r | |
200 | Content += GenSection('Ppis', NewSectionDict)\r | |
201 | \r | |
202 | return Content\r | |
203 | \r | |
204 | ## Transfer Package Object to Dec files\r | |
205 | #\r | |
206 | # Transfer all contents of a standard Package Object to a Dec file \r | |
207 | #\r | |
208 | # @param Package: A Package \r | |
209 | #\r | |
210 | def PackageToDec(Package):\r | |
211 | #\r | |
212 | # Init global information for the file\r | |
213 | #\r | |
214 | ContainerFile = Package.GetFullPath()\r | |
215 | \r | |
216 | Content = ''\r | |
217 | #\r | |
218 | # generate header comment section\r | |
219 | #\r | |
220 | Content += GenHeaderCommentSection(Package.GetAbstract(), \\r | |
221 | Package.GetDescription(), \\r | |
222 | Package.GetCopyright(), \\r | |
223 | Package.GetLicense())\r | |
224 | \r | |
225 | #\r | |
226 | # for each section, maintain a dict, sorted arch will be its key, \r | |
227 | #statement list will be its data\r | |
228 | # { 'Arch1 Arch2 Arch3': [statement1, statement2],\r | |
229 | # 'Arch1' : [statement1, statement3] \r | |
230 | # }\r | |
231 | #\r | |
232 | \r | |
233 | #\r | |
234 | # generate [Defines] section \r | |
235 | #\r | |
236 | NewSectionDict = {TAB_ARCH_COMMON : []}\r | |
237 | SpecialItemList = []\r | |
238 | \r | |
239 | Statement = '%s = %s' % (TAB_DEC_DEFINES_DEC_SPECIFICATION, '0x00010017')\r | |
240 | SpecialItemList.append(Statement)\r | |
241 | \r | |
242 | BaseName = Package.GetBaseName()\r | |
243 | if BaseName.startswith('.') or BaseName.startswith('-'):\r | |
244 | BaseName = '_' + BaseName\r | |
245 | Statement = '%s = %s' % (TAB_DEC_DEFINES_PACKAGE_NAME, BaseName)\r | |
246 | SpecialItemList.append(Statement)\r | |
247 | Statement = '%s = %s' % (TAB_DEC_DEFINES_PACKAGE_VERSION, Package.GetVersion())\r | |
248 | SpecialItemList.append(Statement)\r | |
249 | Statement = '%s = %s' % (TAB_DEC_DEFINES_PACKAGE_GUID, Package.GetGuid())\r | |
250 | SpecialItemList.append(Statement) \r | |
251 | for SortedArch in NewSectionDict:\r | |
252 | NewSectionDict[SortedArch] = \\r | |
253 | NewSectionDict[SortedArch] + SpecialItemList\r | |
254 | Content += GenSection('Defines', NewSectionDict)\r | |
255 | \r | |
256 | #\r | |
257 | # generate [Includes] section\r | |
258 | #\r | |
259 | NewSectionDict = {}\r | |
260 | IncludeArchList = Package.GetIncludeArchList()\r | |
261 | if IncludeArchList: \r | |
262 | for Path, ArchList in IncludeArchList:\r | |
263 | Statement = Path\r | |
264 | ArchList.sort()\r | |
265 | SortedArch = ' '.join(ArchList)\r | |
266 | if SortedArch in NewSectionDict:\r | |
267 | NewSectionDict[SortedArch] = \\r | |
268 | NewSectionDict[SortedArch] + [ConvertPath(Statement)]\r | |
269 | else:\r | |
270 | NewSectionDict[SortedArch] = [ConvertPath(Statement)]\r | |
271 | \r | |
272 | Content += GenSection('Includes', NewSectionDict) \r | |
273 | \r | |
274 | Content = GenGuidProtocolPpi(Package, Content)\r | |
275 | \r | |
276 | #\r | |
277 | # generate [LibraryClasses] section\r | |
278 | #\r | |
279 | NewSectionDict = {}\r | |
280 | for LibraryClass in Package.GetLibraryClassList():\r | |
281 | #\r | |
282 | # Generate generic comment\r | |
283 | #\r | |
284 | HelpTextList = LibraryClass.GetHelpTextList()\r | |
285 | HelpStr = _GetHelpStr(HelpTextList)\r | |
286 | if HelpStr:\r | |
287 | HelpStr = '@libraryclass ' + HelpStr\r | |
288 | CommentStr = GenGenericCommentF(HelpStr, 2)\r | |
289 | \r | |
290 | Statement = CommentStr\r | |
291 | Name = LibraryClass.GetLibraryClass()\r | |
292 | IncludeHeader = LibraryClass.GetIncludeHeader()\r | |
293 | Statement += Name + '|' + ConvertPath(IncludeHeader)\r | |
294 | #\r | |
295 | # generate tail comment\r | |
296 | #\r | |
297 | if LibraryClass.GetSupModuleList():\r | |
298 | Statement += \\r | |
299 | GenDecTailComment(LibraryClass.GetSupModuleList())\r | |
300 | ArchList = LibraryClass.GetSupArchList()\r | |
301 | ArchList.sort()\r | |
302 | SortedArch = ' '.join(ArchList)\r | |
303 | if SortedArch in NewSectionDict:\r | |
304 | NewSectionDict[SortedArch] = \\r | |
305 | NewSectionDict[SortedArch] + [Statement]\r | |
306 | else:\r | |
307 | NewSectionDict[SortedArch] = [Statement] \r | |
308 | \r | |
309 | Content += GenSection('LibraryClasses', NewSectionDict)\r | |
310 | \r | |
311 | Content = GenPcd(Package, Content)\r | |
312 | \r | |
313 | #\r | |
314 | # generate [UserExtensions] section\r | |
315 | #\r | |
316 | NewSectionDict = {}\r | |
317 | for UserExtension in Package.GetUserExtensionList():\r | |
318 | Statement = UserExtension.GetStatement()\r | |
319 | if not Statement:\r | |
320 | continue\r | |
321 | \r | |
322 | SectionList = []\r | |
323 | SectionName = 'UserExtensions'\r | |
324 | UserId = UserExtension.GetUserID()\r | |
325 | if UserId:\r | |
326 | if '.' in UserId:\r | |
327 | UserId = '"' + UserId + '"'\r | |
328 | SectionName += '.' + UserId\r | |
329 | if UserExtension.GetIdentifier():\r | |
330 | SectionName += '.' + '"' + UserExtension.GetIdentifier() + '"'\r | |
331 | if not UserExtension.GetSupArchList():\r | |
332 | SectionList.append(SectionName)\r | |
333 | else:\r | |
334 | for Arch in UserExtension.GetSupArchList():\r | |
335 | SectionList.append(SectionName + '.' + Arch)\r | |
336 | SectionName = ', '.join(SectionList)\r | |
337 | SectionName = ''.join(['[', SectionName, ']\n'])\r | |
338 | Content += '\n\n' + SectionName + Statement\r | |
339 | \r | |
340 | SaveFileOnChange(ContainerFile, Content, False)\r | |
341 | return ContainerFile\r | |
342 | \r | |
343 | ## GenPcdErrComment\r | |
344 | #\r | |
345 | # @param PcdErrObject: PcdErrorObject\r | |
346 | # \r | |
347 | # @retval CommentStr: Generated comment lines, with prefix "#"\r | |
348 | # \r | |
349 | def GenPcdErrComment (PcdErrObject):\r | |
350 | EndOfLine = "\n" \r | |
351 | ValidValueRange = PcdErrObject.GetValidValueRange()\r | |
352 | if ValidValueRange:\r | |
353 | CommentStr = "# @ValidRange " + ValidValueRange + EndOfLine\r | |
354 | \r | |
355 | ValidValue = PcdErrObject.GetValidValue()\r | |
356 | if ValidValue:\r | |
357 | ValidValueList = \\r | |
358 | [Value for Value in ValidValue.split(TAB_SPACE_SPLIT) if Value]\r | |
359 | CommentStr = \\r | |
360 | "# @ValidList " + TAB_COMMA_SPLIT.join(ValidValueList) + EndOfLine\r | |
361 | \r | |
362 | Expression = PcdErrObject.GetExpression()\r | |
363 | if Expression:\r | |
364 | CommentStr = "# @Expression " + Expression + EndOfLine\r | |
365 | \r | |
366 | return CommentStr\r | |
367 | \r |