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