]>
Commit | Line | Data |
---|---|---|
1 | ## @file GenInfFile.py\r | |
2 | #\r | |
3 | # This file contained the logical of transfer package object to INF files.\r | |
4 | #\r | |
5 | # Copyright (c) 2011 - 2018, 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 | GenInf\r | |
17 | '''\r | |
18 | import os\r | |
19 | import stat\r | |
20 | import codecs\r | |
21 | import md5\r | |
22 | from Core.FileHook import __FileHookOpen__\r | |
23 | from Library.StringUtils import GetSplitValueList\r | |
24 | from Library.Parsing import GenSection\r | |
25 | from Library.Parsing import GetWorkspacePackage\r | |
26 | from Library.Parsing import ConvertArchForInstall\r | |
27 | from Library.Misc import SaveFileOnChange\r | |
28 | from Library.Misc import IsAllModuleList\r | |
29 | from Library.Misc import Sdict\r | |
30 | from Library.Misc import ConvertPath\r | |
31 | from Library.Misc import ConvertSpec\r | |
32 | from Library.Misc import GetRelativePath\r | |
33 | from Library.Misc import GetLocalValue\r | |
34 | from Library.CommentGenerating import GenHeaderCommentSection\r | |
35 | from Library.CommentGenerating import GenGenericCommentF\r | |
36 | from Library.CommentGenerating import _GetHelpStr\r | |
37 | from Library import GlobalData\r | |
38 | from Logger import StringTable as ST\r | |
39 | from Logger import ToolError\r | |
40 | import Logger.Log as Logger\r | |
41 | from Library import DataType as DT\r | |
42 | from GenMetaFile import GenMetaFileMisc\r | |
43 | from Library.UniClassObject import FormatUniEntry\r | |
44 | from Library.StringUtils import GetUniFileName\r | |
45 | \r | |
46 | \r | |
47 | ## Transfer Module Object to Inf files\r | |
48 | #\r | |
49 | # Transfer all contents of a standard Module Object to an Inf file\r | |
50 | # @param ModuleObject: A Module Object\r | |
51 | #\r | |
52 | def ModuleToInf(ModuleObject, PackageObject=None, DistHeader=None):\r | |
53 | if not GlobalData.gWSPKG_LIST:\r | |
54 | GlobalData.gWSPKG_LIST = GetWorkspacePackage()\r | |
55 | #\r | |
56 | # Init global information for the file\r | |
57 | #\r | |
58 | ContainerFile = ModuleObject.GetFullPath()\r | |
59 | \r | |
60 | Content = ''\r | |
61 | #\r | |
62 | # Generate file header, If any Abstract, Description, Copyright or License XML elements are missing,\r | |
63 | # should 1) use the Abstract, Description, Copyright or License from the PackageSurfaceArea.Header elements\r | |
64 | # that the module belongs to, or 2) if this is a stand-alone module that is not included in a PackageSurfaceArea,\r | |
65 | # use the abstract, description, copyright or license from the DistributionPackage.Header elements.\r | |
66 | #\r | |
67 | ModuleAbstract = GetLocalValue(ModuleObject.GetAbstract())\r | |
68 | if not ModuleAbstract and PackageObject:\r | |
69 | ModuleAbstract = GetLocalValue(PackageObject.GetAbstract())\r | |
70 | if not ModuleAbstract and DistHeader:\r | |
71 | ModuleAbstract = GetLocalValue(DistHeader.GetAbstract())\r | |
72 | ModuleDescription = GetLocalValue(ModuleObject.GetDescription())\r | |
73 | if not ModuleDescription and PackageObject:\r | |
74 | ModuleDescription = GetLocalValue(PackageObject.GetDescription())\r | |
75 | if not ModuleDescription and DistHeader:\r | |
76 | ModuleDescription = GetLocalValue(DistHeader.GetDescription())\r | |
77 | ModuleCopyright = ''\r | |
78 | for (Lang, Copyright) in ModuleObject.GetCopyright():\r | |
79 | if Lang:\r | |
80 | pass\r | |
81 | ModuleCopyright = Copyright\r | |
82 | if not ModuleCopyright and PackageObject:\r | |
83 | for (Lang, Copyright) in PackageObject.GetCopyright():\r | |
84 | if Lang:\r | |
85 | pass\r | |
86 | ModuleCopyright = Copyright\r | |
87 | if not ModuleCopyright and DistHeader:\r | |
88 | for (Lang, Copyright) in DistHeader.GetCopyright():\r | |
89 | if Lang:\r | |
90 | pass\r | |
91 | ModuleCopyright = Copyright\r | |
92 | ModuleLicense = ''\r | |
93 | for (Lang, License) in ModuleObject.GetLicense():\r | |
94 | if Lang:\r | |
95 | pass\r | |
96 | ModuleLicense = License\r | |
97 | if not ModuleLicense and PackageObject:\r | |
98 | for (Lang, License) in PackageObject.GetLicense():\r | |
99 | if Lang:\r | |
100 | pass\r | |
101 | ModuleLicense = License\r | |
102 | if not ModuleLicense and DistHeader:\r | |
103 | for (Lang, License) in DistHeader.GetLicense():\r | |
104 | if Lang:\r | |
105 | pass\r | |
106 | ModuleLicense = License\r | |
107 | \r | |
108 | #\r | |
109 | # Generate header comment section of INF file\r | |
110 | #\r | |
111 | Content += GenHeaderCommentSection(ModuleAbstract,\r | |
112 | ModuleDescription,\r | |
113 | ModuleCopyright,\r | |
114 | ModuleLicense).replace('\r\n', '\n')\r | |
115 | \r | |
116 | #\r | |
117 | # Generate Binary Header\r | |
118 | #\r | |
119 | for UserExtension in ModuleObject.GetUserExtensionList():\r | |
120 | if UserExtension.GetUserID() == DT.TAB_BINARY_HEADER_USERID \\r | |
121 | and UserExtension.GetIdentifier() == DT.TAB_BINARY_HEADER_IDENTIFIER:\r | |
122 | ModuleBinaryAbstract = GetLocalValue(UserExtension.GetBinaryAbstract())\r | |
123 | ModuleBinaryDescription = GetLocalValue(UserExtension.GetBinaryDescription())\r | |
124 | ModuleBinaryCopyright = ''\r | |
125 | ModuleBinaryLicense = ''\r | |
126 | for (Lang, Copyright) in UserExtension.GetBinaryCopyright():\r | |
127 | ModuleBinaryCopyright = Copyright\r | |
128 | for (Lang, License) in UserExtension.GetBinaryLicense():\r | |
129 | ModuleBinaryLicense = License\r | |
130 | if ModuleBinaryAbstract and ModuleBinaryDescription and \\r | |
131 | ModuleBinaryCopyright and ModuleBinaryLicense:\r | |
132 | Content += GenHeaderCommentSection(ModuleBinaryAbstract,\r | |
133 | ModuleBinaryDescription,\r | |
134 | ModuleBinaryCopyright,\r | |
135 | ModuleBinaryLicense,\r | |
136 | True)\r | |
137 | \r | |
138 | #\r | |
139 | # Generate MODULE_UNI_FILE for module\r | |
140 | #\r | |
141 | FileHeader = GenHeaderCommentSection(ModuleAbstract, ModuleDescription, ModuleCopyright, ModuleLicense, False, \\r | |
142 | DT.TAB_COMMENT_EDK1_SPLIT)\r | |
143 | ModuleUniFile = GenModuleUNIEncodeFile(ModuleObject, FileHeader)\r | |
144 | if ModuleUniFile:\r | |
145 | ModuleObject.SetModuleUniFile(os.path.basename(ModuleUniFile))\r | |
146 | \r | |
147 | #\r | |
148 | # Judge whether the INF file is an AsBuild INF.\r | |
149 | #\r | |
150 | if ModuleObject.BinaryModule:\r | |
151 | GlobalData.gIS_BINARY_INF = True\r | |
152 | else:\r | |
153 | GlobalData.gIS_BINARY_INF = False\r | |
154 | #\r | |
155 | # for each section, maintain a dict, sorted arch will be its key,\r | |
156 | # statement list will be its data\r | |
157 | # { 'Arch1 Arch2 Arch3': [statement1, statement2],\r | |
158 | # 'Arch1' : [statement1, statement3]\r | |
159 | # }\r | |
160 | #\r | |
161 | # Gen section contents\r | |
162 | #\r | |
163 | Content += GenDefines(ModuleObject)\r | |
164 | Content += GenBuildOptions(ModuleObject)\r | |
165 | Content += GenLibraryClasses(ModuleObject)\r | |
166 | Content += GenPackages(ModuleObject)\r | |
167 | Content += GenPcdSections(ModuleObject)\r | |
168 | Content += GenSources(ModuleObject)\r | |
169 | Content += GenProtocolPPiSections(ModuleObject.GetProtocolList(), True)\r | |
170 | Content += GenProtocolPPiSections(ModuleObject.GetPpiList(), False)\r | |
171 | Content += GenGuidSections(ModuleObject.GetGuidList())\r | |
172 | Content += GenBinaries(ModuleObject)\r | |
173 | Content += GenDepex(ModuleObject)\r | |
174 | __UserExtensionsContent = GenUserExtensions(ModuleObject)\r | |
175 | Content += __UserExtensionsContent\r | |
176 | if ModuleObject.GetEventList() or ModuleObject.GetBootModeList() or ModuleObject.GetHobList():\r | |
177 | Content += '\n'\r | |
178 | #\r | |
179 | # generate [Event], [BootMode], [Hob] section\r | |
180 | #\r | |
181 | Content += GenSpecialSections(ModuleObject.GetEventList(), 'Event', __UserExtensionsContent)\r | |
182 | Content += GenSpecialSections(ModuleObject.GetBootModeList(), 'BootMode', __UserExtensionsContent)\r | |
183 | Content += GenSpecialSections(ModuleObject.GetHobList(), 'Hob', __UserExtensionsContent)\r | |
184 | SaveFileOnChange(ContainerFile, Content, False)\r | |
185 | if DistHeader.ReadOnly:\r | |
186 | os.chmod(ContainerFile, stat.S_IRUSR|stat.S_IRGRP|stat.S_IROTH)\r | |
187 | else:\r | |
188 | os.chmod(ContainerFile, stat.S_IRUSR|stat.S_IRGRP|stat.S_IROTH|stat.S_IWUSR|stat.S_IWGRP|stat.S_IWOTH)\r | |
189 | return ContainerFile\r | |
190 | \r | |
191 | ## GenModuleUNIEncodeFile\r | |
192 | # GenModuleUNIEncodeFile, default is a UCS-2LE encode file\r | |
193 | #\r | |
194 | def GenModuleUNIEncodeFile(ModuleObject, UniFileHeader='', Encoding=DT.TAB_ENCODING_UTF16LE):\r | |
195 | GenUNIFlag = False\r | |
196 | OnlyLANGUAGE_EN_X = True\r | |
197 | BinaryAbstract = []\r | |
198 | BinaryDescription = []\r | |
199 | #\r | |
200 | # If more than one language code is used for any element that would be present in the MODULE_UNI_FILE,\r | |
201 | # then the MODULE_UNI_FILE must be created.\r | |
202 | #\r | |
203 | for (Key, Value) in ModuleObject.GetAbstract() + ModuleObject.GetDescription():\r | |
204 | if Key == DT.TAB_LANGUAGE_EN_X:\r | |
205 | GenUNIFlag = True\r | |
206 | else:\r | |
207 | OnlyLANGUAGE_EN_X = False\r | |
208 | \r | |
209 | for UserExtension in ModuleObject.GetUserExtensionList():\r | |
210 | if UserExtension.GetUserID() == DT.TAB_BINARY_HEADER_USERID \\r | |
211 | and UserExtension.GetIdentifier() == DT.TAB_BINARY_HEADER_IDENTIFIER:\r | |
212 | for (Key, Value) in UserExtension.GetBinaryAbstract():\r | |
213 | if Key == DT.TAB_LANGUAGE_EN_X:\r | |
214 | GenUNIFlag = True\r | |
215 | else:\r | |
216 | OnlyLANGUAGE_EN_X = False\r | |
217 | BinaryAbstract.append((Key, Value))\r | |
218 | for (Key, Value) in UserExtension.GetBinaryDescription():\r | |
219 | if Key == DT.TAB_LANGUAGE_EN_X:\r | |
220 | GenUNIFlag = True\r | |
221 | else:\r | |
222 | OnlyLANGUAGE_EN_X = False\r | |
223 | BinaryDescription.append((Key, Value))\r | |
224 | \r | |
225 | \r | |
226 | if not GenUNIFlag:\r | |
227 | return\r | |
228 | elif OnlyLANGUAGE_EN_X:\r | |
229 | return\r | |
230 | else:\r | |
231 | ModuleObject.UNIFlag = True\r | |
232 | ContainerFile = GetUniFileName(os.path.dirname(ModuleObject.GetFullPath()), ModuleObject.GetBaseName())\r | |
233 | \r | |
234 | if not os.path.exists(os.path.dirname(ModuleObject.GetFullPath())):\r | |
235 | os.makedirs(os.path.dirname(ModuleObject.GetFullPath()))\r | |
236 | \r | |
237 | Content = UniFileHeader + '\r\n'\r | |
238 | Content += '\r\n'\r | |
239 | \r | |
240 | Content += FormatUniEntry('#string ' + DT.TAB_INF_ABSTRACT, ModuleObject.GetAbstract(), ContainerFile) + '\r\n'\r | |
241 | \r | |
242 | Content += FormatUniEntry('#string ' + DT.TAB_INF_DESCRIPTION, ModuleObject.GetDescription(), ContainerFile) \\r | |
243 | + '\r\n'\r | |
244 | \r | |
245 | BinaryAbstractString = FormatUniEntry('#string ' + DT.TAB_INF_BINARY_ABSTRACT, BinaryAbstract, ContainerFile)\r | |
246 | if BinaryAbstractString:\r | |
247 | Content += BinaryAbstractString + '\r\n'\r | |
248 | \r | |
249 | BinaryDescriptionString = FormatUniEntry('#string ' + DT.TAB_INF_BINARY_DESCRIPTION, BinaryDescription, \\r | |
250 | ContainerFile)\r | |
251 | if BinaryDescriptionString:\r | |
252 | Content += BinaryDescriptionString + '\r\n'\r | |
253 | \r | |
254 | if not os.path.exists(ContainerFile):\r | |
255 | File = codecs.open(ContainerFile, 'wb', Encoding)\r | |
256 | File.write(u'\uFEFF' + Content)\r | |
257 | File.stream.close()\r | |
258 | Md5Sigature = md5.new(__FileHookOpen__(str(ContainerFile), 'rb').read())\r | |
259 | Md5Sum = Md5Sigature.hexdigest()\r | |
260 | if (ContainerFile, Md5Sum) not in ModuleObject.FileList:\r | |
261 | ModuleObject.FileList.append((ContainerFile, Md5Sum))\r | |
262 | \r | |
263 | return ContainerFile\r | |
264 | def GenDefines(ModuleObject):\r | |
265 | #\r | |
266 | # generate [Defines] section\r | |
267 | #\r | |
268 | LeftOffset = 31\r | |
269 | Content = ''\r | |
270 | NewSectionDict = {}\r | |
271 | \r | |
272 | for UserExtension in ModuleObject.GetUserExtensionList():\r | |
273 | DefinesDict = UserExtension.GetDefinesDict()\r | |
274 | if not DefinesDict:\r | |
275 | continue\r | |
276 | for Statement in DefinesDict:\r | |
277 | if Statement.split(DT.TAB_EQUAL_SPLIT) > 1:\r | |
278 | Statement = (u'%s ' % Statement.split(DT.TAB_EQUAL_SPLIT, 1)[0]).ljust(LeftOffset) \\r | |
279 | + u'= %s' % Statement.split(DT.TAB_EQUAL_SPLIT, 1)[1].lstrip()\r | |
280 | SortedArch = DT.TAB_ARCH_COMMON\r | |
281 | if Statement.strip().startswith(DT.TAB_INF_DEFINES_CUSTOM_MAKEFILE):\r | |
282 | pos = Statement.find(DT.TAB_VALUE_SPLIT)\r | |
283 | if pos == -1:\r | |
284 | pos = Statement.find(DT.TAB_EQUAL_SPLIT)\r | |
285 | Makefile = ConvertPath(Statement[pos + 1:].strip())\r | |
286 | Statement = Statement[:pos + 1] + ' ' + Makefile\r | |
287 | if SortedArch in NewSectionDict:\r | |
288 | NewSectionDict[SortedArch] = NewSectionDict[SortedArch] + [Statement]\r | |
289 | else:\r | |
290 | NewSectionDict[SortedArch] = [Statement]\r | |
291 | SpecialStatementList = []\r | |
292 | \r | |
293 | # TAB_INF_DEFINES_INF_VERSION\r | |
294 | Statement = (u'%s ' % DT.TAB_INF_DEFINES_INF_VERSION).ljust(LeftOffset) + u'= %s' % '0x00010017'\r | |
295 | SpecialStatementList.append(Statement)\r | |
296 | \r | |
297 | # BaseName\r | |
298 | BaseName = ModuleObject.GetBaseName()\r | |
299 | if BaseName.startswith('.') or BaseName.startswith('-'):\r | |
300 | BaseName = '_' + BaseName\r | |
301 | Statement = (u'%s ' % DT.TAB_INF_DEFINES_BASE_NAME).ljust(LeftOffset) + u'= %s' % BaseName\r | |
302 | SpecialStatementList.append(Statement)\r | |
303 | \r | |
304 | # TAB_INF_DEFINES_FILE_GUID\r | |
305 | Statement = (u'%s ' % DT.TAB_INF_DEFINES_FILE_GUID).ljust(LeftOffset) + u'= %s' % ModuleObject.GetGuid()\r | |
306 | SpecialStatementList.append(Statement)\r | |
307 | \r | |
308 | # TAB_INF_DEFINES_VERSION_STRING\r | |
309 | Statement = (u'%s ' % DT.TAB_INF_DEFINES_VERSION_STRING).ljust(LeftOffset) + u'= %s' % ModuleObject.GetVersion()\r | |
310 | SpecialStatementList.append(Statement)\r | |
311 | \r | |
312 | # TAB_INF_DEFINES_VERSION_STRING\r | |
313 | if ModuleObject.UNIFlag:\r | |
314 | Statement = (u'%s ' % DT.TAB_INF_DEFINES_MODULE_UNI_FILE).ljust(LeftOffset) + \\r | |
315 | u'= %s' % ModuleObject.GetModuleUniFile()\r | |
316 | SpecialStatementList.append(Statement)\r | |
317 | \r | |
318 | # TAB_INF_DEFINES_MODULE_TYPE\r | |
319 | if ModuleObject.GetModuleType():\r | |
320 | Statement = (u'%s ' % DT.TAB_INF_DEFINES_MODULE_TYPE).ljust(LeftOffset) + u'= %s' % ModuleObject.GetModuleType()\r | |
321 | SpecialStatementList.append(Statement)\r | |
322 | \r | |
323 | # TAB_INF_DEFINES_PCD_IS_DRIVER\r | |
324 | if ModuleObject.GetPcdIsDriver():\r | |
325 | Statement = (u'%s ' % DT.TAB_INF_DEFINES_PCD_IS_DRIVER).ljust(LeftOffset) + \\r | |
326 | u'= %s' % ModuleObject.GetPcdIsDriver()\r | |
327 | SpecialStatementList.append(Statement)\r | |
328 | \r | |
329 | # TAB_INF_DEFINES_UEFI_SPECIFICATION_VERSION\r | |
330 | if ModuleObject.GetUefiSpecificationVersion():\r | |
331 | Statement = (u'%s ' % DT.TAB_INF_DEFINES_UEFI_SPECIFICATION_VERSION).ljust(LeftOffset) + \\r | |
332 | u'= %s' % ModuleObject.GetUefiSpecificationVersion()\r | |
333 | SpecialStatementList.append(Statement)\r | |
334 | \r | |
335 | # TAB_INF_DEFINES_PI_SPECIFICATION_VERSION\r | |
336 | if ModuleObject.GetPiSpecificationVersion():\r | |
337 | Statement = (u'%s ' % DT.TAB_INF_DEFINES_PI_SPECIFICATION_VERSION).ljust(LeftOffset) + \\r | |
338 | u'= %s' % ModuleObject.GetPiSpecificationVersion()\r | |
339 | SpecialStatementList.append(Statement)\r | |
340 | \r | |
341 | # LibraryClass\r | |
342 | for LibraryClass in ModuleObject.GetLibraryClassList():\r | |
343 | if LibraryClass.GetUsage() == DT.USAGE_ITEM_PRODUCES or \\r | |
344 | LibraryClass.GetUsage() == DT.USAGE_ITEM_SOMETIMES_PRODUCES:\r | |
345 | Statement = (u'%s ' % DT.TAB_INF_DEFINES_LIBRARY_CLASS).ljust(LeftOffset) + \\r | |
346 | u'= %s' % LibraryClass.GetLibraryClass()\r | |
347 | if LibraryClass.GetSupModuleList():\r | |
348 | Statement += '|' + DT.TAB_SPACE_SPLIT.join(l for l in LibraryClass.GetSupModuleList())\r | |
349 | SpecialStatementList.append(Statement)\r | |
350 | \r | |
351 | # Spec Item\r | |
352 | for SpecItem in ModuleObject.GetSpecList():\r | |
353 | Spec, Version = SpecItem\r | |
354 | Spec = ConvertSpec(Spec)\r | |
355 | Statement = '%s %s = %s' % (DT.TAB_INF_DEFINES_SPEC, Spec, Version)\r | |
356 | SpecialStatementList.append(Statement)\r | |
357 | \r | |
358 | # Extern\r | |
359 | ExternList = []\r | |
360 | for Extern in ModuleObject.GetExternList():\r | |
361 | ArchList = Extern.GetSupArchList()\r | |
362 | EntryPoint = Extern.GetEntryPoint()\r | |
363 | UnloadImage = Extern.GetUnloadImage()\r | |
364 | Constructor = Extern.GetConstructor()\r | |
365 | Destructor = Extern.GetDestructor()\r | |
366 | HelpStringList = Extern.GetHelpTextList()\r | |
367 | FFE = Extern.GetFeatureFlag()\r | |
368 | ExternList.append([ArchList, EntryPoint, UnloadImage, Constructor, Destructor, FFE, HelpStringList])\r | |
369 | #\r | |
370 | # Add VALID_ARCHITECTURES information\r | |
371 | #\r | |
372 | ValidArchStatement = None\r | |
373 | if ModuleObject.SupArchList:\r | |
374 | ValidArchStatement = '\n' + '# ' + '\n'\r | |
375 | ValidArchStatement += '# The following information is for reference only and not required by the build tools.\n'\r | |
376 | ValidArchStatement += '# ' + '\n'\r | |
377 | ValidArchStatement += '# VALID_ARCHITECTURES = %s' % (' '.join(ModuleObject.SupArchList)) + '\n'\r | |
378 | ValidArchStatement += '# '\r | |
379 | if DT.TAB_ARCH_COMMON not in NewSectionDict:\r | |
380 | NewSectionDict[DT.TAB_ARCH_COMMON] = []\r | |
381 | NewSectionDict[DT.TAB_ARCH_COMMON] = NewSectionDict[DT.TAB_ARCH_COMMON] + SpecialStatementList\r | |
382 | GenMetaFileMisc.AddExternToDefineSec(NewSectionDict, DT.TAB_ARCH_COMMON, ExternList)\r | |
383 | if ValidArchStatement is not None:\r | |
384 | NewSectionDict[DT.TAB_ARCH_COMMON] = NewSectionDict[DT.TAB_ARCH_COMMON] + [ValidArchStatement]\r | |
385 | Content += GenSection('Defines', NewSectionDict)\r | |
386 | return Content\r | |
387 | \r | |
388 | def GenLibraryClasses(ModuleObject):\r | |
389 | #\r | |
390 | # generate [LibraryClasses] section\r | |
391 | #\r | |
392 | Content = ''\r | |
393 | NewSectionDict = {}\r | |
394 | if not GlobalData.gIS_BINARY_INF:\r | |
395 | for LibraryClass in ModuleObject.GetLibraryClassList():\r | |
396 | if LibraryClass.GetUsage() == DT.USAGE_ITEM_PRODUCES:\r | |
397 | continue\r | |
398 | #\r | |
399 | # Generate generic comment\r | |
400 | #\r | |
401 | HelpTextList = LibraryClass.GetHelpTextList()\r | |
402 | HelpStr = _GetHelpStr(HelpTextList)\r | |
403 | CommentStr = GenGenericCommentF(HelpStr)\r | |
404 | Statement = CommentStr\r | |
405 | Name = LibraryClass.GetLibraryClass()\r | |
406 | FFE = LibraryClass.GetFeatureFlag()\r | |
407 | Statement += Name\r | |
408 | if FFE:\r | |
409 | Statement += '|' + FFE\r | |
410 | ModuleList = LibraryClass.GetSupModuleList()\r | |
411 | ArchList = LibraryClass.GetSupArchList()\r | |
412 | for Index in xrange(0, len(ArchList)):\r | |
413 | ArchList[Index] = ConvertArchForInstall(ArchList[Index])\r | |
414 | ArchList.sort()\r | |
415 | SortedArch = ' '.join(ArchList)\r | |
416 | KeyList = []\r | |
417 | if not ModuleList or IsAllModuleList(ModuleList):\r | |
418 | KeyList = [SortedArch]\r | |
419 | else:\r | |
420 | ModuleString = DT.TAB_VALUE_SPLIT.join(l for l in ModuleList)\r | |
421 | if not ArchList:\r | |
422 | SortedArch = DT.TAB_ARCH_COMMON\r | |
423 | KeyList = [SortedArch + '.' + ModuleString]\r | |
424 | else:\r | |
425 | KeyList = [Arch + '.' + ModuleString for Arch in ArchList]\r | |
426 | for Key in KeyList:\r | |
427 | if Key in NewSectionDict:\r | |
428 | NewSectionDict[Key] = NewSectionDict[Key] + [Statement]\r | |
429 | else:\r | |
430 | NewSectionDict[Key] = [Statement]\r | |
431 | Content += GenSection('LibraryClasses', NewSectionDict)\r | |
432 | else:\r | |
433 | LibraryClassDict = {}\r | |
434 | for BinaryFile in ModuleObject.GetBinaryFileList():\r | |
435 | if not BinaryFile.AsBuiltList:\r | |
436 | continue\r | |
437 | for LibraryItem in BinaryFile.AsBuiltList[0].LibraryInstancesList:\r | |
438 | Statement = '# Guid: ' + LibraryItem.Guid + ' Version: ' + LibraryItem.Version\r | |
439 | \r | |
440 | if len(BinaryFile.SupArchList) == 0:\r | |
441 | if 'COMMON' in LibraryClassDict and Statement not in LibraryClassDict['COMMON']:\r | |
442 | LibraryClassDict['COMMON'].append(Statement)\r | |
443 | else:\r | |
444 | LibraryClassDict['COMMON'] = ['## @LIB_INSTANCES']\r | |
445 | LibraryClassDict['COMMON'].append(Statement)\r | |
446 | else:\r | |
447 | for Arch in BinaryFile.SupArchList:\r | |
448 | if Arch in LibraryClassDict:\r | |
449 | if Statement not in LibraryClassDict[Arch]:\r | |
450 | LibraryClassDict[Arch].append(Statement)\r | |
451 | else:\r | |
452 | continue\r | |
453 | else:\r | |
454 | LibraryClassDict[Arch] = ['## @LIB_INSTANCES']\r | |
455 | LibraryClassDict[Arch].append(Statement)\r | |
456 | Content += GenSection('LibraryClasses', LibraryClassDict)\r | |
457 | \r | |
458 | return Content\r | |
459 | \r | |
460 | def GenPackages(ModuleObject):\r | |
461 | Content = ''\r | |
462 | #\r | |
463 | # generate [Packages] section\r | |
464 | #\r | |
465 | NewSectionDict = Sdict()\r | |
466 | WorkspaceDir = GlobalData.gWORKSPACE\r | |
467 | for PackageDependency in ModuleObject.GetPackageDependencyList():\r | |
468 | #\r | |
469 | # Generate generic comment\r | |
470 | #\r | |
471 | CommentStr = ''\r | |
472 | HelpText = PackageDependency.GetHelpText()\r | |
473 | if HelpText:\r | |
474 | HelpStr = HelpText.GetString()\r | |
475 | CommentStr = GenGenericCommentF(HelpStr)\r | |
476 | Statement = CommentStr\r | |
477 | Guid = PackageDependency.GetGuid()\r | |
478 | Version = PackageDependency.GetVersion()\r | |
479 | FFE = PackageDependency.GetFeatureFlag()\r | |
480 | Path = ''\r | |
481 | #\r | |
482 | # find package path/name\r | |
483 | #\r | |
484 | for PkgInfo in GlobalData.gWSPKG_LIST:\r | |
485 | if Guid == PkgInfo[1]:\r | |
486 | if (not Version) or (Version == PkgInfo[2]):\r | |
487 | Path = PkgInfo[3]\r | |
488 | break\r | |
489 | #\r | |
490 | # get relative path\r | |
491 | #\r | |
492 | RelaPath = GetRelativePath(Path, WorkspaceDir)\r | |
493 | Statement += RelaPath.replace('\\', '/')\r | |
494 | if FFE:\r | |
495 | Statement += '|' + FFE\r | |
496 | ArchList = sorted(PackageDependency.GetSupArchList())\r | |
497 | SortedArch = ' '.join(ArchList)\r | |
498 | if SortedArch in NewSectionDict:\r | |
499 | NewSectionDict[SortedArch] = NewSectionDict[SortedArch] + [Statement]\r | |
500 | else:\r | |
501 | NewSectionDict[SortedArch] = [Statement]\r | |
502 | Content += GenSection('Packages', NewSectionDict)\r | |
503 | return Content\r | |
504 | \r | |
505 | def GenSources(ModuleObject):\r | |
506 | #\r | |
507 | # generate [Sources] section\r | |
508 | #\r | |
509 | Content = ''\r | |
510 | NewSectionDict = {}\r | |
511 | for Source in ModuleObject.GetSourceFileList():\r | |
512 | SourceFile = Source.GetSourceFile()\r | |
513 | Family = Source.GetFamily()\r | |
514 | FeatureFlag = Source.GetFeatureFlag()\r | |
515 | SupArchList = sorted(Source.GetSupArchList())\r | |
516 | SortedArch = ' '.join(SupArchList)\r | |
517 | Statement = GenSourceStatement(ConvertPath(SourceFile), Family, FeatureFlag)\r | |
518 | if SortedArch in NewSectionDict:\r | |
519 | NewSectionDict[SortedArch] = NewSectionDict[SortedArch] + [Statement]\r | |
520 | else:\r | |
521 | NewSectionDict[SortedArch] = [Statement]\r | |
522 | Content += GenSection('Sources', NewSectionDict)\r | |
523 | \r | |
524 | return Content\r | |
525 | \r | |
526 | def GenDepex(ModuleObject):\r | |
527 | #\r | |
528 | # generate [Depex] section\r | |
529 | #\r | |
530 | NewSectionDict = Sdict()\r | |
531 | Content = ''\r | |
532 | for Depex in ModuleObject.GetPeiDepex() + ModuleObject.GetDxeDepex() + ModuleObject.GetSmmDepex():\r | |
533 | HelpTextList = Depex.GetHelpTextList()\r | |
534 | HelpStr = _GetHelpStr(HelpTextList)\r | |
535 | CommentStr = GenGenericCommentF(HelpStr)\r | |
536 | SupArchList = Depex.GetSupArchList()\r | |
537 | SupModList = Depex.GetModuleType()\r | |
538 | Expression = Depex.GetDepex()\r | |
539 | Statement = CommentStr + Expression\r | |
540 | SupArchList.sort()\r | |
541 | KeyList = []\r | |
542 | if not SupArchList:\r | |
543 | SupArchList.append(DT.TAB_ARCH_COMMON.lower())\r | |
544 | if not SupModList:\r | |
545 | KeyList = SupArchList\r | |
546 | else:\r | |
547 | for ModuleType in SupModList:\r | |
548 | for Arch in SupArchList:\r | |
549 | KeyList.append(ConvertArchForInstall(Arch) + '.' + ModuleType)\r | |
550 | for Key in KeyList:\r | |
551 | if Key in NewSectionDict:\r | |
552 | NewSectionDict[Key] = NewSectionDict[Key] + [Statement]\r | |
553 | else:\r | |
554 | NewSectionDict[Key] = [Statement]\r | |
555 | Content += GenSection('Depex', NewSectionDict, False)\r | |
556 | \r | |
557 | return Content\r | |
558 | ## GenUserExtensions\r | |
559 | #\r | |
560 | # GenUserExtensions\r | |
561 | #\r | |
562 | def GenUserExtensions(ModuleObject):\r | |
563 | NewSectionDict = {}\r | |
564 | for UserExtension in ModuleObject.GetUserExtensionList():\r | |
565 | if UserExtension.GetUserID() == DT.TAB_BINARY_HEADER_USERID and \\r | |
566 | UserExtension.GetIdentifier() == DT.TAB_BINARY_HEADER_IDENTIFIER:\r | |
567 | continue\r | |
568 | if UserExtension.GetIdentifier() == 'Depex':\r | |
569 | continue\r | |
570 | Statement = UserExtension.GetStatement()\r | |
571 | # Comment the code to support user extension without any statement just the section header in []\r | |
572 | # if not Statement:\r | |
573 | # continue\r | |
574 | ArchList = UserExtension.GetSupArchList()\r | |
575 | for Index in xrange(0, len(ArchList)):\r | |
576 | ArchList[Index] = ConvertArchForInstall(ArchList[Index])\r | |
577 | ArchList.sort()\r | |
578 | KeyList = []\r | |
579 | CommonPreFix = ''\r | |
580 | if UserExtension.GetUserID():\r | |
581 | CommonPreFix = UserExtension.GetUserID()\r | |
582 | if CommonPreFix.find('.') > -1:\r | |
583 | CommonPreFix = '"' + CommonPreFix + '"'\r | |
584 | if UserExtension.GetIdentifier():\r | |
585 | CommonPreFix += '.' + '"' + UserExtension.GetIdentifier() + '"'\r | |
586 | if ArchList:\r | |
587 | KeyList = [CommonPreFix + '.' + Arch for Arch in ArchList]\r | |
588 | else:\r | |
589 | KeyList = [CommonPreFix]\r | |
590 | for Key in KeyList:\r | |
591 | if Key in NewSectionDict:\r | |
592 | NewSectionDict[Key] = NewSectionDict[Key] + [Statement]\r | |
593 | else:\r | |
594 | NewSectionDict[Key] = [Statement]\r | |
595 | Content = GenSection('UserExtensions', NewSectionDict, False)\r | |
596 | \r | |
597 | return Content\r | |
598 | \r | |
599 | # GenSourceStatement\r | |
600 | #\r | |
601 | # @param SourceFile: string of source file path/name\r | |
602 | # @param Family: string of source file family field\r | |
603 | # @param FeatureFlag: string of source file FeatureFlag field\r | |
604 | # @param TagName: string of source file TagName field\r | |
605 | # @param ToolCode: string of source file ToolCode field\r | |
606 | # @param HelpStr: string of source file HelpStr field\r | |
607 | #\r | |
608 | # @retval Statement: The generated statement for source\r | |
609 | #\r | |
610 | def GenSourceStatement(SourceFile, Family, FeatureFlag, TagName=None,\r | |
611 | ToolCode=None, HelpStr=None):\r | |
612 | Statement = ''\r | |
613 | if HelpStr:\r | |
614 | Statement += GenGenericCommentF(HelpStr)\r | |
615 | #\r | |
616 | # format of SourceFile|Family|TagName|ToolCode|FeatureFlag\r | |
617 | #\r | |
618 | Statement += SourceFile\r | |
619 | if TagName is None:\r | |
620 | TagName = ''\r | |
621 | if ToolCode is None:\r | |
622 | ToolCode = ''\r | |
623 | if HelpStr is None:\r | |
624 | HelpStr = ''\r | |
625 | if FeatureFlag:\r | |
626 | Statement += '|' + Family + '|' + TagName + '|' + ToolCode + '|' + FeatureFlag\r | |
627 | elif ToolCode:\r | |
628 | Statement += '|' + Family + '|' + TagName + '|' + ToolCode\r | |
629 | elif TagName:\r | |
630 | Statement += '|' + Family + '|' + TagName\r | |
631 | elif Family:\r | |
632 | Statement += '|' + Family\r | |
633 | return Statement\r | |
634 | \r | |
635 | # GenBinaryStatement\r | |
636 | #\r | |
637 | # @param Key: (FileName, FileType, FFE, SortedArch)\r | |
638 | # @param Value: (Target, Family, TagName, Comment)\r | |
639 | #\r | |
640 | #\r | |
641 | def GenBinaryStatement(Key, Value, SubTypeGuidValue=None):\r | |
642 | (FileName, FileType, FFE, SortedArch) = Key\r | |
643 | if SortedArch:\r | |
644 | pass\r | |
645 | if Value:\r | |
646 | (Target, Family, TagName, Comment) = Value\r | |
647 | else:\r | |
648 | Target = ''\r | |
649 | Family = ''\r | |
650 | TagName = ''\r | |
651 | Comment = ''\r | |
652 | if Comment:\r | |
653 | Statement = GenGenericCommentF(Comment)\r | |
654 | else:\r | |
655 | Statement = ''\r | |
656 | if FileType == 'SUBTYPE_GUID' and SubTypeGuidValue:\r | |
657 | Statement += FileType + '|' + SubTypeGuidValue + '|' + FileName\r | |
658 | else:\r | |
659 | Statement += FileType + '|' + FileName\r | |
660 | if FileType in DT.BINARY_FILE_TYPE_UI_LIST + DT.BINARY_FILE_TYPE_VER_LIST:\r | |
661 | if FFE:\r | |
662 | Statement += '|' + Target + '|' + FFE\r | |
663 | elif Target:\r | |
664 | Statement += '|' + Target\r | |
665 | else:\r | |
666 | if FFE:\r | |
667 | Statement += '|' + Target + '|' + Family + '|' + TagName + '|' + FFE\r | |
668 | elif TagName:\r | |
669 | Statement += '|' + Target + '|' + Family + '|' + TagName\r | |
670 | elif Family:\r | |
671 | Statement += '|' + Target + '|' + Family\r | |
672 | elif Target:\r | |
673 | Statement += '|' + Target\r | |
674 | return Statement\r | |
675 | ## GenGuidSections\r | |
676 | #\r | |
677 | # @param GuidObjList: List of GuidObject\r | |
678 | # @retVal Content: The generated section contents\r | |
679 | #\r | |
680 | def GenGuidSections(GuidObjList):\r | |
681 | #\r | |
682 | # generate [Guids] section\r | |
683 | #\r | |
684 | Content = ''\r | |
685 | GuidDict = Sdict()\r | |
686 | for Guid in GuidObjList:\r | |
687 | HelpTextList = Guid.GetHelpTextList()\r | |
688 | HelpStr = _GetHelpStr(HelpTextList)\r | |
689 | CName = Guid.GetCName()\r | |
690 | FFE = Guid.GetFeatureFlag()\r | |
691 | Statement = CName\r | |
692 | if FFE:\r | |
693 | Statement += '|' + FFE\r | |
694 | Usage = Guid.GetUsage()\r | |
695 | GuidType = Guid.GetGuidTypeList()[0]\r | |
696 | VariableName = Guid.GetVariableName()\r | |
697 | #\r | |
698 | # Differentiate the generic comment and usage comment as multiple generic comment need to be put at first\r | |
699 | #\r | |
700 | if Usage == DT.ITEM_UNDEFINED and GuidType == DT.ITEM_UNDEFINED:\r | |
701 | # generate list of generic comment\r | |
702 | Comment = GenGenericCommentF(HelpStr)\r | |
703 | else:\r | |
704 | # generate list of other comment\r | |
705 | Comment = HelpStr.replace('\n', ' ')\r | |
706 | Comment = Comment.strip()\r | |
707 | if Comment:\r | |
708 | Comment = ' # ' + Comment\r | |
709 | else:\r | |
710 | Comment = ''\r | |
711 | if Usage != DT.ITEM_UNDEFINED and GuidType == DT.ITEM_UNDEFINED:\r | |
712 | Comment = '## ' + Usage + Comment\r | |
713 | elif GuidType == 'Variable':\r | |
714 | Comment = '## ' + Usage + ' ## ' + GuidType + ':' + VariableName + Comment\r | |
715 | else:\r | |
716 | Comment = '## ' + Usage + ' ## ' + GuidType + Comment\r | |
717 | \r | |
718 | if Comment:\r | |
719 | Comment += '\n'\r | |
720 | #\r | |
721 | # merge duplicate items\r | |
722 | #\r | |
723 | ArchList = sorted(Guid.GetSupArchList())\r | |
724 | SortedArch = ' '.join(ArchList)\r | |
725 | if (Statement, SortedArch) in GuidDict:\r | |
726 | PreviousComment = GuidDict[Statement, SortedArch]\r | |
727 | Comment = PreviousComment + Comment\r | |
728 | GuidDict[Statement, SortedArch] = Comment\r | |
729 | NewSectionDict = GenMetaFileMisc.TransferDict(GuidDict, 'INF_GUID')\r | |
730 | #\r | |
731 | # generate the section contents\r | |
732 | #\r | |
733 | if NewSectionDict:\r | |
734 | Content = GenSection('Guids', NewSectionDict)\r | |
735 | \r | |
736 | return Content\r | |
737 | \r | |
738 | ## GenProtocolPPiSections\r | |
739 | #\r | |
740 | # @param ObjList: List of ProtocolObject or Ppi Object\r | |
741 | # @retVal Content: The generated section contents\r | |
742 | #\r | |
743 | def GenProtocolPPiSections(ObjList, IsProtocol):\r | |
744 | Content = ''\r | |
745 | Dict = Sdict()\r | |
746 | for Object in ObjList:\r | |
747 | HelpTextList = Object.GetHelpTextList()\r | |
748 | HelpStr = _GetHelpStr(HelpTextList)\r | |
749 | CName = Object.GetCName()\r | |
750 | FFE = Object.GetFeatureFlag()\r | |
751 | Statement = CName\r | |
752 | if FFE:\r | |
753 | Statement += '|' + FFE\r | |
754 | Usage = Object.GetUsage()\r | |
755 | Notify = Object.GetNotify()\r | |
756 | #\r | |
757 | # Differentiate the generic comment and usage comment as consecutive generic comment need to be put together\r | |
758 | #\r | |
759 | if Usage == DT.ITEM_UNDEFINED and Notify == '':\r | |
760 | # generate list of generic comment\r | |
761 | Comment = GenGenericCommentF(HelpStr)\r | |
762 | else:\r | |
763 | # generate list of other comment\r | |
764 | Comment = HelpStr.replace('\n', ' ')\r | |
765 | Comment = Comment.strip()\r | |
766 | if Comment:\r | |
767 | Comment = ' # ' + Comment\r | |
768 | else:\r | |
769 | Comment = ''\r | |
770 | if Usage == DT.ITEM_UNDEFINED and not Comment and Notify == '':\r | |
771 | Comment = ''\r | |
772 | else:\r | |
773 | if Notify:\r | |
774 | Comment = '## ' + Usage + ' ## ' + 'NOTIFY' + Comment\r | |
775 | else:\r | |
776 | Comment = '## ' + Usage + Comment\r | |
777 | if Comment:\r | |
778 | Comment += '\n'\r | |
779 | #\r | |
780 | # merge duplicate items\r | |
781 | #\r | |
782 | ArchList = sorted(Object.GetSupArchList())\r | |
783 | SortedArch = ' '.join(ArchList)\r | |
784 | if (Statement, SortedArch) in Dict:\r | |
785 | PreviousComment = Dict[Statement, SortedArch]\r | |
786 | Comment = PreviousComment + Comment\r | |
787 | Dict[Statement, SortedArch] = Comment\r | |
788 | NewSectionDict = GenMetaFileMisc.TransferDict(Dict, 'INF_PPI_PROTOCOL')\r | |
789 | #\r | |
790 | # generate the section contents\r | |
791 | #\r | |
792 | if NewSectionDict:\r | |
793 | if IsProtocol:\r | |
794 | Content = GenSection('Protocols', NewSectionDict)\r | |
795 | else:\r | |
796 | Content = GenSection('Ppis', NewSectionDict)\r | |
797 | \r | |
798 | return Content\r | |
799 | \r | |
800 | ## GenPcdSections\r | |
801 | #\r | |
802 | #\r | |
803 | def GenPcdSections(ModuleObject):\r | |
804 | Content = ''\r | |
805 | if not GlobalData.gIS_BINARY_INF:\r | |
806 | #\r | |
807 | # for each Pcd Itemtype, maintain a dict so the same type will be grouped\r | |
808 | # together\r | |
809 | #\r | |
810 | ItemTypeDict = {}\r | |
811 | for Pcd in ModuleObject.GetPcdList():\r | |
812 | HelpTextList = Pcd.GetHelpTextList()\r | |
813 | HelpStr = _GetHelpStr(HelpTextList)\r | |
814 | Statement = ''\r | |
815 | CName = Pcd.GetCName()\r | |
816 | TokenSpaceGuidCName = Pcd.GetTokenSpaceGuidCName()\r | |
817 | DefaultValue = Pcd.GetDefaultValue()\r | |
818 | ItemType = Pcd.GetItemType()\r | |
819 | if ItemType in ItemTypeDict:\r | |
820 | Dict = ItemTypeDict[ItemType]\r | |
821 | else:\r | |
822 | Dict = Sdict()\r | |
823 | ItemTypeDict[ItemType] = Dict\r | |
824 | FFE = Pcd.GetFeatureFlag()\r | |
825 | Statement += TokenSpaceGuidCName + '.' + CName\r | |
826 | if DefaultValue:\r | |
827 | Statement += '|' + DefaultValue\r | |
828 | if FFE:\r | |
829 | Statement += '|' + FFE\r | |
830 | elif FFE:\r | |
831 | Statement += '||' + FFE\r | |
832 | #\r | |
833 | # Generate comment\r | |
834 | #\r | |
835 | Usage = Pcd.GetValidUsage()\r | |
836 | # if FeatureFlag Pcd, then assume all Usage is CONSUMES\r | |
837 | if ItemType == DT.TAB_INF_FEATURE_PCD:\r | |
838 | Usage = DT.USAGE_ITEM_CONSUMES\r | |
839 | if Usage == DT.ITEM_UNDEFINED:\r | |
840 | # generate list of generic comment\r | |
841 | Comment = GenGenericCommentF(HelpStr)\r | |
842 | else:\r | |
843 | # generate list of other comment\r | |
844 | Comment = HelpStr.replace('\n', ' ')\r | |
845 | Comment = Comment.strip()\r | |
846 | if Comment:\r | |
847 | Comment = ' # ' + Comment\r | |
848 | else:\r | |
849 | Comment = ''\r | |
850 | Comment = '## ' + Usage + Comment\r | |
851 | if Comment:\r | |
852 | Comment += '\n'\r | |
853 | #\r | |
854 | # Merge duplicate entries\r | |
855 | #\r | |
856 | ArchList = sorted(Pcd.GetSupArchList())\r | |
857 | SortedArch = ' '.join(ArchList)\r | |
858 | if (Statement, SortedArch) in Dict:\r | |
859 | PreviousComment = Dict[Statement, SortedArch]\r | |
860 | Comment = PreviousComment + Comment\r | |
861 | Dict[Statement, SortedArch] = Comment\r | |
862 | for ItemType in ItemTypeDict:\r | |
863 | # First we need to transfer the Dict to use SortedArch as key\r | |
864 | Dict = ItemTypeDict[ItemType]\r | |
865 | NewSectionDict = GenMetaFileMisc.TransferDict(Dict, 'INF_PCD')\r | |
866 | if NewSectionDict:\r | |
867 | Content += GenSection(ItemType, NewSectionDict)\r | |
868 | #\r | |
869 | # For AsBuild INF files\r | |
870 | #\r | |
871 | else:\r | |
872 | Content += GenAsBuiltPacthPcdSections(ModuleObject)\r | |
873 | Content += GenAsBuiltPcdExSections(ModuleObject)\r | |
874 | \r | |
875 | return Content\r | |
876 | \r | |
877 | ## GenPcdSections\r | |
878 | #\r | |
879 | #\r | |
880 | def GenAsBuiltPacthPcdSections(ModuleObject):\r | |
881 | PatchPcdDict = {}\r | |
882 | for BinaryFile in ModuleObject.GetBinaryFileList():\r | |
883 | if not BinaryFile.AsBuiltList:\r | |
884 | continue\r | |
885 | for PatchPcd in BinaryFile.AsBuiltList[0].PatchPcdList:\r | |
886 | TokenSpaceName = ''\r | |
887 | PcdCName = PatchPcd.CName\r | |
888 | PcdValue = PatchPcd.DefaultValue\r | |
889 | PcdOffset = PatchPcd.Offset\r | |
890 | TokenSpaceGuidValue = PatchPcd.TokenSpaceGuidValue\r | |
891 | Token = PatchPcd.Token\r | |
892 | HelpTextList = PatchPcd.HelpTextList\r | |
893 | HelpString = ''\r | |
894 | for HelpStringItem in HelpTextList:\r | |
895 | for HelpLine in GetSplitValueList(HelpStringItem.String, '\n'):\r | |
896 | HelpString += '## ' + HelpLine + '\n'\r | |
897 | TokenSpaceName, PcdCName = GenMetaFileMisc.ObtainPcdName(ModuleObject.PackageDependencyList,\r | |
898 | TokenSpaceGuidValue,\r | |
899 | Token)\r | |
900 | if TokenSpaceName == '' or PcdCName == '':\r | |
901 | Logger.Error("Upt",\r | |
902 | ToolError.RESOURCE_NOT_AVAILABLE,\r | |
903 | ST.ERR_INSTALL_FILE_DEC_FILE_ERROR % (TokenSpaceGuidValue, Token),\r | |
904 | File=ModuleObject.GetFullPath())\r | |
905 | Statement = HelpString + TokenSpaceName + '.' + PcdCName + ' | ' + PcdValue + ' | ' + \\r | |
906 | PcdOffset + DT.TAB_SPACE_SPLIT\r | |
907 | #\r | |
908 | # Use binary file's Arch to be Pcd's Arch\r | |
909 | #\r | |
910 | ArchList = []\r | |
911 | FileNameObjList = BinaryFile.GetFileNameList()\r | |
912 | if FileNameObjList:\r | |
913 | ArchList = FileNameObjList[0].GetSupArchList()\r | |
914 | if len(ArchList) == 0:\r | |
915 | if DT.TAB_ARCH_COMMON in PatchPcdDict:\r | |
916 | if Statement not in PatchPcdDict[DT.TAB_ARCH_COMMON]:\r | |
917 | PatchPcdDict[DT.TAB_ARCH_COMMON].append(Statement)\r | |
918 | else:\r | |
919 | PatchPcdDict[DT.TAB_ARCH_COMMON] = [Statement]\r | |
920 | else:\r | |
921 | for Arch in ArchList:\r | |
922 | if Arch in PatchPcdDict:\r | |
923 | if Statement not in PatchPcdDict[Arch]:\r | |
924 | PatchPcdDict[Arch].append(Statement)\r | |
925 | else:\r | |
926 | PatchPcdDict[Arch] = [Statement]\r | |
927 | return GenSection(DT.TAB_INF_PATCH_PCD, PatchPcdDict)\r | |
928 | ## GenPcdSections\r | |
929 | #\r | |
930 | #\r | |
931 | def GenAsBuiltPcdExSections(ModuleObject):\r | |
932 | PcdExDict = {}\r | |
933 | for BinaryFile in ModuleObject.GetBinaryFileList():\r | |
934 | if not BinaryFile.AsBuiltList:\r | |
935 | continue\r | |
936 | for PcdExItem in BinaryFile.AsBuiltList[0].PcdExValueList:\r | |
937 | TokenSpaceName = ''\r | |
938 | PcdCName = PcdExItem.CName\r | |
939 | TokenSpaceGuidValue = PcdExItem.TokenSpaceGuidValue\r | |
940 | Token = PcdExItem.Token\r | |
941 | HelpTextList = PcdExItem.HelpTextList\r | |
942 | HelpString = ''\r | |
943 | for HelpStringItem in HelpTextList:\r | |
944 | for HelpLine in GetSplitValueList(HelpStringItem.String, '\n'):\r | |
945 | HelpString += '## ' + HelpLine + '\n'\r | |
946 | TokenSpaceName, PcdCName = GenMetaFileMisc.ObtainPcdName(ModuleObject.PackageDependencyList,\r | |
947 | TokenSpaceGuidValue, Token)\r | |
948 | if TokenSpaceName == '' or PcdCName == '':\r | |
949 | Logger.Error("Upt",\r | |
950 | ToolError.RESOURCE_NOT_AVAILABLE,\r | |
951 | ST.ERR_INSTALL_FILE_DEC_FILE_ERROR % (TokenSpaceGuidValue, Token),\r | |
952 | File=ModuleObject.GetFullPath())\r | |
953 | \r | |
954 | Statement = HelpString + TokenSpaceName + DT.TAB_SPLIT + PcdCName + DT.TAB_SPACE_SPLIT\r | |
955 | \r | |
956 | #\r | |
957 | # Use binary file's Arch to be Pcd's Arch\r | |
958 | #\r | |
959 | ArchList = []\r | |
960 | FileNameObjList = BinaryFile.GetFileNameList()\r | |
961 | if FileNameObjList:\r | |
962 | ArchList = FileNameObjList[0].GetSupArchList()\r | |
963 | \r | |
964 | if len(ArchList) == 0:\r | |
965 | if 'COMMON' in PcdExDict:\r | |
966 | PcdExDict['COMMON'].append(Statement)\r | |
967 | else:\r | |
968 | PcdExDict['COMMON'] = [Statement]\r | |
969 | else:\r | |
970 | for Arch in ArchList:\r | |
971 | if Arch in PcdExDict:\r | |
972 | if Statement not in PcdExDict[Arch]:\r | |
973 | PcdExDict[Arch].append(Statement)\r | |
974 | else:\r | |
975 | PcdExDict[Arch] = [Statement]\r | |
976 | return GenSection('PcdEx', PcdExDict)\r | |
977 | \r | |
978 | ## GenSpecialSections\r | |
979 | # generate special sections for Event/BootMode/Hob\r | |
980 | #\r | |
981 | def GenSpecialSections(ObjectList, SectionName, UserExtensionsContent=''):\r | |
982 | #\r | |
983 | # generate section\r | |
984 | #\r | |
985 | Content = ''\r | |
986 | NewSectionDict = {}\r | |
987 | for Obj in ObjectList:\r | |
988 | #\r | |
989 | # Generate comment\r | |
990 | #\r | |
991 | CommentStr = ''\r | |
992 | HelpTextList = Obj.GetHelpTextList()\r | |
993 | HelpStr = _GetHelpStr(HelpTextList)\r | |
994 | CommentStr = GenGenericCommentF(HelpStr)\r | |
995 | if SectionName == 'Hob':\r | |
996 | Type = Obj.GetHobType()\r | |
997 | elif SectionName == 'Event':\r | |
998 | Type = Obj.GetEventType()\r | |
999 | elif SectionName == 'BootMode':\r | |
1000 | Type = Obj.GetSupportedBootModes()\r | |
1001 | else:\r | |
1002 | assert(SectionName)\r | |
1003 | Usage = Obj.GetUsage()\r | |
1004 | \r | |
1005 | # If the content already in UserExtensionsContent then ignore\r | |
1006 | if '[%s]' % SectionName in UserExtensionsContent and Type in UserExtensionsContent:\r | |
1007 | return ''\r | |
1008 | \r | |
1009 | Statement = ' ' + Type + ' ## ' + Usage\r | |
1010 | if CommentStr in ['#\n', '#\n#\n']:\r | |
1011 | CommentStr = '#\n#\n#\n'\r | |
1012 | #\r | |
1013 | # the first head comment line should start with '##\n', if it starts with '#\n', then add one '#'\r | |
1014 | # else add '##\n' to meet the format defined in INF spec\r | |
1015 | #\r | |
1016 | if CommentStr.startswith('#\n'):\r | |
1017 | CommentStr = '#' + CommentStr\r | |
1018 | elif CommentStr:\r | |
1019 | CommentStr = '##\n' + CommentStr\r | |
1020 | if CommentStr and not CommentStr.endswith('\n#\n'):\r | |
1021 | CommentStr = CommentStr + '#\n'\r | |
1022 | NewStateMent = CommentStr + Statement\r | |
1023 | SupArch = sorted(Obj.GetSupArchList())\r | |
1024 | SortedArch = ' '.join(SupArch)\r | |
1025 | if SortedArch in NewSectionDict:\r | |
1026 | NewSectionDict[SortedArch] = NewSectionDict[SortedArch] + [NewStateMent]\r | |
1027 | else:\r | |
1028 | NewSectionDict[SortedArch] = [NewStateMent]\r | |
1029 | SectionContent = GenSection(SectionName, NewSectionDict)\r | |
1030 | SectionContent = SectionContent.strip()\r | |
1031 | if SectionContent:\r | |
1032 | Content = '# ' + ('\n' + '# ').join(GetSplitValueList(SectionContent, '\n'))\r | |
1033 | Content = Content.lstrip()\r | |
1034 | #\r | |
1035 | # add a return to differentiate it between other possible sections\r | |
1036 | #\r | |
1037 | if Content:\r | |
1038 | Content += '\n'\r | |
1039 | return Content\r | |
1040 | ## GenBuildOptions\r | |
1041 | #\r | |
1042 | #\r | |
1043 | def GenBuildOptions(ModuleObject):\r | |
1044 | Content = ''\r | |
1045 | if not ModuleObject.BinaryModule:\r | |
1046 | #\r | |
1047 | # generate [BuildOptions] section\r | |
1048 | #\r | |
1049 | NewSectionDict = {}\r | |
1050 | for UserExtension in ModuleObject.GetUserExtensionList():\r | |
1051 | BuildOptionDict = UserExtension.GetBuildOptionDict()\r | |
1052 | if not BuildOptionDict:\r | |
1053 | continue\r | |
1054 | for Arch in BuildOptionDict:\r | |
1055 | if Arch in NewSectionDict:\r | |
1056 | NewSectionDict[Arch] = NewSectionDict[Arch] + [BuildOptionDict[Arch]]\r | |
1057 | else:\r | |
1058 | NewSectionDict[Arch] = [BuildOptionDict[Arch]]\r | |
1059 | Content = GenSection('BuildOptions', NewSectionDict)\r | |
1060 | else:\r | |
1061 | BuildOptionDict = {}\r | |
1062 | for BinaryFile in ModuleObject.GetBinaryFileList():\r | |
1063 | if not BinaryFile.AsBuiltList:\r | |
1064 | continue\r | |
1065 | for BuilOptionItem in BinaryFile.AsBuiltList[0].BinaryBuildFlagList:\r | |
1066 | Statement = '#' + BuilOptionItem.AsBuiltOptionFlags\r | |
1067 | if len(BinaryFile.SupArchList) == 0:\r | |
1068 | if 'COMMON' in BuildOptionDict:\r | |
1069 | if Statement not in BuildOptionDict['COMMON']:\r | |
1070 | BuildOptionDict['COMMON'].append(Statement)\r | |
1071 | else:\r | |
1072 | BuildOptionDict['COMMON'] = ['## @AsBuilt']\r | |
1073 | BuildOptionDict['COMMON'].append(Statement)\r | |
1074 | else:\r | |
1075 | for Arch in BinaryFile.SupArchList:\r | |
1076 | if Arch in BuildOptionDict:\r | |
1077 | if Statement not in BuildOptionDict[Arch]:\r | |
1078 | BuildOptionDict[Arch].append(Statement)\r | |
1079 | else:\r | |
1080 | BuildOptionDict[Arch] = ['## @AsBuilt']\r | |
1081 | BuildOptionDict[Arch].append(Statement)\r | |
1082 | Content = GenSection('BuildOptions', BuildOptionDict)\r | |
1083 | \r | |
1084 | return Content\r | |
1085 | ## GenBinaries\r | |
1086 | #\r | |
1087 | #\r | |
1088 | def GenBinaries(ModuleObject):\r | |
1089 | NewSectionDict = {}\r | |
1090 | BinariesDict = []\r | |
1091 | for UserExtension in ModuleObject.GetUserExtensionList():\r | |
1092 | BinariesDict = UserExtension.GetBinariesDict()\r | |
1093 | if BinariesDict:\r | |
1094 | break\r | |
1095 | for BinaryFile in ModuleObject.GetBinaryFileList():\r | |
1096 | FileNameObjList = BinaryFile.GetFileNameList()\r | |
1097 | for FileNameObj in FileNameObjList:\r | |
1098 | FileName = ConvertPath(FileNameObj.GetFilename())\r | |
1099 | FileType = FileNameObj.GetFileType()\r | |
1100 | FFE = FileNameObj.GetFeatureFlag()\r | |
1101 | ArchList = sorted(FileNameObj.GetSupArchList())\r | |
1102 | SortedArch = ' '.join(ArchList)\r | |
1103 | Key = (FileName, FileType, FFE, SortedArch)\r | |
1104 | if Key in BinariesDict:\r | |
1105 | ValueList = BinariesDict[Key]\r | |
1106 | for ValueItem in ValueList:\r | |
1107 | Statement = GenBinaryStatement(Key, ValueItem)\r | |
1108 | if SortedArch in NewSectionDict:\r | |
1109 | NewSectionDict[SortedArch] = NewSectionDict[SortedArch] + [Statement]\r | |
1110 | else:\r | |
1111 | NewSectionDict[SortedArch] = [Statement]\r | |
1112 | #\r | |
1113 | # as we already generated statement for this DictKey here set the Valuelist to be empty\r | |
1114 | # to avoid generate duplicate entries as the DictKey may have multiple entries\r | |
1115 | #\r | |
1116 | BinariesDict[Key] = []\r | |
1117 | else:\r | |
1118 | if FileType == 'SUBTYPE_GUID' and FileNameObj.GetGuidValue():\r | |
1119 | Statement = GenBinaryStatement(Key, None, FileNameObj.GetGuidValue())\r | |
1120 | else:\r | |
1121 | Statement = GenBinaryStatement(Key, None)\r | |
1122 | if SortedArch in NewSectionDict:\r | |
1123 | NewSectionDict[SortedArch] = NewSectionDict[SortedArch] + [Statement]\r | |
1124 | else:\r | |
1125 | NewSectionDict[SortedArch] = [Statement]\r | |
1126 | Content = GenSection('Binaries', NewSectionDict)\r | |
1127 | \r | |
1128 | return Content\r |