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