3 # This file contained the logical of transfer package object to INF files.
5 # Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
7 # This program and the accompanying materials are licensed and made available
8 # under the terms and conditions of the BSD License which accompanies this
9 # distribution. The full text of the license may be found at
10 # http://opensource.org/licenses/bsd-license.php
12 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
22 from Core
.FileHook
import __FileHookOpen__
23 from Library
.String
import GetSplitValueList
24 from Library
.Parsing
import GenSection
25 from Library
.Parsing
import GetWorkspacePackage
26 from Library
.Parsing
import ConvertArchForInstall
27 from Library
.Misc
import SaveFileOnChange
28 from Library
.Misc
import IsAllModuleList
29 from Library
.Misc
import Sdict
30 from Library
.Misc
import ConvertPath
31 from Library
.Misc
import ConvertSpec
32 from Library
.Misc
import GetRelativePath
33 from Library
.Misc
import GetLocalValue
34 from Library
.CommentGenerating
import GenHeaderCommentSection
35 from Library
.CommentGenerating
import GenGenericCommentF
36 from Library
.CommentGenerating
import _GetHelpStr
37 from Library
import GlobalData
38 from Logger
import StringTable
as ST
39 from Logger
import ToolError
40 import Logger
.Log
as Logger
41 from Library
import DataType
as DT
42 from GenMetaFile
import GenMetaFileMisc
43 from Library
.UniClassObject
import FormatUniEntry
46 ## Transfer Module Object to Inf files
48 # Transfer all contents of a standard Module Object to an Inf file
49 # @param ModuleObject: A Module Object
51 def ModuleToInf(ModuleObject
, PackageObject
=None, DistHeader
=None):
52 if not GlobalData
.gWSPKG_LIST
:
53 GlobalData
.gWSPKG_LIST
= GetWorkspacePackage()
55 # Init global information for the file
57 ContainerFile
= ModuleObject
.GetFullPath()
61 # Generate file header, If any Abstract, Description, Copyright or License XML elements are missing,
62 # should 1) use the Abstract, Description, Copyright or License from the PackageSurfaceArea.Header elements
63 # that the module belongs to, or 2) if this is a stand-alone module that is not included in a PackageSurfaceArea,
64 # use the abstract, description, copyright or license from the DistributionPackage.Header elements.
66 ModuleAbstract
= GetLocalValue(ModuleObject
.GetAbstract())
67 if not ModuleAbstract
and PackageObject
:
68 ModuleAbstract
= GetLocalValue(PackageObject
.GetAbstract())
69 if not ModuleAbstract
and DistHeader
:
70 ModuleAbstract
= GetLocalValue(DistHeader
.GetAbstract())
71 ModuleDescription
= GetLocalValue(ModuleObject
.GetDescription())
72 if not ModuleDescription
and PackageObject
:
73 ModuleDescription
= GetLocalValue(PackageObject
.GetDescription())
74 if not ModuleDescription
and DistHeader
:
75 ModuleDescription
= GetLocalValue(DistHeader
.GetDescription())
77 for (Lang
, Copyright
) in ModuleObject
.GetCopyright():
80 ModuleCopyright
= Copyright
81 if not ModuleCopyright
and PackageObject
:
82 for (Lang
, Copyright
) in PackageObject
.GetCopyright():
85 ModuleCopyright
= Copyright
86 if not ModuleCopyright
and DistHeader
:
87 for (Lang
, Copyright
) in DistHeader
.GetCopyright():
90 ModuleCopyright
= Copyright
92 for (Lang
, License
) in ModuleObject
.GetLicense():
95 ModuleLicense
= License
96 if not ModuleLicense
and PackageObject
:
97 for (Lang
, License
) in PackageObject
.GetLicense():
100 ModuleLicense
= License
101 if not ModuleLicense
and DistHeader
:
102 for (Lang
, License
) in DistHeader
.GetLicense():
105 ModuleLicense
= License
108 # Generate header comment section of INF file
110 Content
+= GenHeaderCommentSection(ModuleAbstract
,
116 # Generate Binary Header
118 for UserExtension
in ModuleObject
.GetUserExtensionList():
119 if UserExtension
.GetUserID() == DT
.TAB_BINARY_HEADER_USERID \
120 and UserExtension
.GetIdentifier() == DT
.TAB_BINARY_HEADER_IDENTIFIER
:
121 ModuleBinaryAbstract
= GetLocalValue(UserExtension
.GetBinaryAbstract())
122 ModuleBinaryDescription
= GetLocalValue(UserExtension
.GetBinaryDescription())
123 ModuleBinaryCopyright
= ''
124 ModuleBinaryLicense
= ''
125 for (Lang
, Copyright
) in UserExtension
.GetBinaryCopyright():
126 ModuleBinaryCopyright
= Copyright
127 for (Lang
, License
) in UserExtension
.GetBinaryLicense():
128 ModuleBinaryLicense
= License
129 if ModuleBinaryAbstract
and ModuleBinaryDescription
and \
130 ModuleBinaryCopyright
and ModuleBinaryLicense
:
131 Content
+= GenHeaderCommentSection(ModuleBinaryAbstract
,
132 ModuleBinaryDescription
,
133 ModuleBinaryCopyright
,
138 # Generate MODULE_UNI_FILE for module
140 FileHeader
= GenHeaderCommentSection(ModuleAbstract
, ModuleDescription
, ModuleCopyright
, ModuleLicense
, False, \
141 DT
.TAB_COMMENT_EDK1_SPLIT
)
142 GenModuleUNIEncodeFile(ModuleObject
, FileHeader
)
145 # Judge whether the INF file is an AsBuild INF.
147 if ModuleObject
.BinaryModule
:
148 GlobalData
.gIS_BINARY_INF
= True
150 GlobalData
.gIS_BINARY_INF
= False
152 # for each section, maintain a dict, sorted arch will be its key,
153 # statement list will be its data
154 # { 'Arch1 Arch2 Arch3': [statement1, statement2],
155 # 'Arch1' : [statement1, statement3]
158 # Gen section contents
160 Content
+= GenDefines(ModuleObject
)
161 Content
+= GenBuildOptions(ModuleObject
)
162 Content
+= GenLibraryClasses(ModuleObject
)
163 Content
+= GenPackages(ModuleObject
)
164 Content
+= GenPcdSections(ModuleObject
)
165 Content
+= GenSources(ModuleObject
)
166 Content
+= GenProtocolPPiSections(ModuleObject
.GetProtocolList(), True)
167 Content
+= GenProtocolPPiSections(ModuleObject
.GetPpiList(), False)
168 Content
+= GenGuidSections(ModuleObject
.GetGuidList())
169 Content
+= GenBinaries(ModuleObject
)
170 Content
+= GenDepex(ModuleObject
)
171 Content
+= GenUserExtensions(ModuleObject
)
172 if ModuleObject
.GetEventList() or ModuleObject
.GetBootModeList() or ModuleObject
.GetHobList():
175 # generate [Event], [BootMode], [Hob] section
177 Content
+= GenSpecialSections(ModuleObject
.GetEventList(), 'Event')
178 Content
+= GenSpecialSections(ModuleObject
.GetBootModeList(), 'BootMode')
179 Content
+= GenSpecialSections(ModuleObject
.GetHobList(), 'Hob')
180 SaveFileOnChange(ContainerFile
, Content
, False)
181 if DistHeader
.ReadOnly
:
182 os
.chmod(ContainerFile
, stat
.S_IRUSR|stat
.S_IRGRP|stat
.S_IROTH
)
184 os
.chmod(ContainerFile
, stat
.S_IRUSR|stat
.S_IRGRP|stat
.S_IROTH|stat
.S_IWUSR|stat
.S_IWGRP|stat
.S_IWOTH
)
187 ## GenModuleUNIEncodeFile
188 # GenModuleUNIEncodeFile, default is a UCS-2LE encode file
190 def GenModuleUNIEncodeFile(ModuleObject
, UniFileHeader
='', Encoding
=DT
.TAB_ENCODING_UTF16LE
):
192 OnlyLANGUAGE_EN_X
= True
194 BinaryDescription
= []
196 # If more than one language code is used for any element that would be present in the MODULE_UNI_FILE,
197 # then the MODULE_UNI_FILE must be created.
199 for (Key
, Value
) in ModuleObject
.GetAbstract() + ModuleObject
.GetDescription():
200 if Key
== DT
.TAB_LANGUAGE_EN_X
:
203 OnlyLANGUAGE_EN_X
= False
205 for UserExtension
in ModuleObject
.GetUserExtensionList():
206 if UserExtension
.GetUserID() == DT
.TAB_BINARY_HEADER_USERID \
207 and UserExtension
.GetIdentifier() == DT
.TAB_BINARY_HEADER_IDENTIFIER
:
208 for (Key
, Value
) in UserExtension
.GetBinaryAbstract():
209 if Key
== DT
.TAB_LANGUAGE_EN_X
:
212 OnlyLANGUAGE_EN_X
= False
213 BinaryAbstract
.append((Key
, Value
))
214 for (Key
, Value
) in UserExtension
.GetBinaryDescription():
215 if Key
== DT
.TAB_LANGUAGE_EN_X
:
218 OnlyLANGUAGE_EN_X
= False
219 BinaryDescription
.append((Key
, Value
))
224 elif OnlyLANGUAGE_EN_X
:
227 ModuleObject
.UNIFlag
= True
228 ContainerFile
= os
.path
.normpath(os
.path
.join(os
.path
.dirname(ModuleObject
.GetFullPath()),
229 (ModuleObject
.GetBaseName() + '.uni')))
230 if not os
.path
.exists(os
.path
.dirname(ModuleObject
.GetFullPath())):
231 os
.makedirs(os
.path
.dirname(ModuleObject
.GetFullPath()))
233 Content
= UniFileHeader
+ '\r\n'
236 Content
+= FormatUniEntry('#string ' + DT
.TAB_INF_ABSTRACT
, ModuleObject
.GetAbstract(), ContainerFile
) + '\r\n'
238 Content
+= FormatUniEntry('#string ' + DT
.TAB_INF_DESCRIPTION
, ModuleObject
.GetDescription(), ContainerFile
) \
241 BinaryAbstractString
= FormatUniEntry('#string ' + DT
.TAB_INF_BINARY_ABSTRACT
, BinaryAbstract
, ContainerFile
)
242 if BinaryAbstractString
:
243 Content
+= BinaryAbstractString
+ '\r\n'
245 BinaryDescriptionString
= FormatUniEntry('#string ' + DT
.TAB_INF_BINARY_DESCRIPTION
, BinaryDescription
, \
247 if BinaryDescriptionString
:
248 Content
+= BinaryDescriptionString
+ '\r\n'
250 if not os
.path
.exists(ContainerFile
):
251 File
= codecs
.open(ContainerFile
, 'wb', Encoding
)
252 File
.write(u
'\uFEFF' + Content
)
254 Md5Sigature
= md5
.new(__FileHookOpen__(str(ContainerFile
), 'rb').read())
255 Md5Sum
= Md5Sigature
.hexdigest()
256 if (ContainerFile
, Md5Sum
) not in ModuleObject
.FileList
:
257 ModuleObject
.FileList
.append((ContainerFile
, Md5Sum
))
260 def GenDefines(ModuleObject
):
262 # generate [Defines] section
266 for UserExtension
in ModuleObject
.GetUserExtensionList():
267 DefinesDict
= UserExtension
.GetDefinesDict()
270 for Statement
in DefinesDict
:
271 SortedArch
= DT
.TAB_ARCH_COMMON
272 if Statement
.strip().startswith(DT
.TAB_INF_DEFINES_CUSTOM_MAKEFILE
):
273 pos
= Statement
.find(DT
.TAB_VALUE_SPLIT
)
275 pos
= Statement
.find(DT
.TAB_EQUAL_SPLIT
)
276 Makefile
= ConvertPath(Statement
[pos
+ 1:].strip())
277 Statement
= Statement
[:pos
+ 1] + ' ' + Makefile
278 if SortedArch
in NewSectionDict
:
279 NewSectionDict
[SortedArch
] = NewSectionDict
[SortedArch
] + [Statement
]
281 NewSectionDict
[SortedArch
] = [Statement
]
282 SpecialStatementList
= []
284 # Add INF_VERSION statement firstly
288 # TAB_INF_DEFINES_INF_VERSION
289 Statement
= (u
'%s ' % DT
.TAB_INF_DEFINES_INF_VERSION
).ljust(LeftOffset
) + u
'= %s' % '0x00010017'
290 SpecialStatementList
.append(Statement
)
293 BaseName
= ModuleObject
.GetBaseName()
294 if BaseName
.startswith('.') or BaseName
.startswith('-'):
295 BaseName
= '_' + BaseName
296 Statement
= (u
'%s ' % DT
.TAB_INF_DEFINES_BASE_NAME
).ljust(LeftOffset
) + u
'= %s' % BaseName
297 SpecialStatementList
.append(Statement
)
299 # TAB_INF_DEFINES_FILE_GUID
300 Statement
= (u
'%s ' % DT
.TAB_INF_DEFINES_FILE_GUID
).ljust(LeftOffset
) + u
'= %s' % ModuleObject
.GetGuid()
301 SpecialStatementList
.append(Statement
)
303 # TAB_INF_DEFINES_VERSION_STRING
304 Statement
= (u
'%s ' % DT
.TAB_INF_DEFINES_VERSION_STRING
).ljust(LeftOffset
) + u
'= %s' % ModuleObject
.GetVersion()
305 SpecialStatementList
.append(Statement
)
307 # TAB_INF_DEFINES_VERSION_STRING
308 if ModuleObject
.UNIFlag
:
309 Statement
= (u
'%s ' % DT
.TAB_INF_DEFINES_MODULE_UNI_FILE
).ljust(LeftOffset
) + \
310 u
'= %s' % ModuleObject
.GetBaseName() + '.uni'
311 SpecialStatementList
.append(Statement
)
313 # TAB_INF_DEFINES_MODULE_TYPE
314 if ModuleObject
.GetModuleType():
315 Statement
= (u
'%s ' % DT
.TAB_INF_DEFINES_MODULE_TYPE
).ljust(LeftOffset
) + u
'= %s' % ModuleObject
.GetModuleType()
316 SpecialStatementList
.append(Statement
)
318 # TAB_INF_DEFINES_PCD_IS_DRIVER
319 if ModuleObject
.GetPcdIsDriver():
320 Statement
= (u
'%s ' % DT
.TAB_INF_DEFINES_PCD_IS_DRIVER
).ljust(LeftOffset
) + \
321 u
'= %s' % ModuleObject
.GetPcdIsDriver()
322 SpecialStatementList
.append(Statement
)
324 # TAB_INF_DEFINES_UEFI_SPECIFICATION_VERSION
325 if ModuleObject
.GetUefiSpecificationVersion():
326 Statement
= (u
'%s ' % DT
.TAB_INF_DEFINES_UEFI_SPECIFICATION_VERSION
).ljust(LeftOffset
) + \
327 u
'= %s' % ModuleObject
.GetUefiSpecificationVersion()
328 SpecialStatementList
.append(Statement
)
330 # TAB_INF_DEFINES_PI_SPECIFICATION_VERSION
331 if ModuleObject
.GetPiSpecificationVersion():
332 Statement
= (u
'%s ' % DT
.TAB_INF_DEFINES_PI_SPECIFICATION_VERSION
).ljust(LeftOffset
) + \
333 u
'= %s' % ModuleObject
.GetPiSpecificationVersion()
334 SpecialStatementList
.append(Statement
)
337 for LibraryClass
in ModuleObject
.GetLibraryClassList():
338 if LibraryClass
.GetUsage() == DT
.USAGE_ITEM_PRODUCES
or \
339 LibraryClass
.GetUsage() == DT
.USAGE_ITEM_SOMETIMES_PRODUCES
:
340 Statement
= (u
'%s ' % DT
.TAB_INF_DEFINES_LIBRARY_CLASS
).ljust(LeftOffset
) + \
341 u
'= %s' % LibraryClass
.GetLibraryClass()
342 if LibraryClass
.GetSupModuleList():
343 Statement
+= '|' + DT
.TAB_SPACE_SPLIT
.join(l
for l
in LibraryClass
.GetSupModuleList())
344 SpecialStatementList
.append(Statement
)
347 for SpecItem
in ModuleObject
.GetSpecList():
348 Spec
, Version
= SpecItem
349 Spec
= ConvertSpec(Spec
)
350 Statement
= '%s %s = %s' % (DT
.TAB_INF_DEFINES_SPEC
, Spec
, Version
)
351 SpecialStatementList
.append(Statement
)
355 for Extern
in ModuleObject
.GetExternList():
356 ArchList
= Extern
.GetSupArchList()
357 EntryPoint
= Extern
.GetEntryPoint()
358 UnloadImage
= Extern
.GetUnloadImage()
359 Constructor
= Extern
.GetConstructor()
360 Destructor
= Extern
.GetDestructor()
361 HelpStringList
= Extern
.GetHelpTextList()
362 FFE
= Extern
.GetFeatureFlag()
363 ExternList
.append([ArchList
, EntryPoint
, UnloadImage
, Constructor
, Destructor
, FFE
, HelpStringList
])
365 # Add VALID_ARCHITECTURES information
367 ValidArchStatement
= None
368 if ModuleObject
.SupArchList
:
369 ValidArchStatement
= '\n' + '# ' + '\n'
370 ValidArchStatement
+= '# The following information is for reference only and not required by the build tools.\n'
371 ValidArchStatement
+= '# ' + '\n'
372 ValidArchStatement
+= '# VALID_ARCHITECTURES = %s' % (' '.join(ModuleObject
.SupArchList
)) + '\n'
373 ValidArchStatement
+= '# '
374 if DT
.TAB_ARCH_COMMON
not in NewSectionDict
:
375 NewSectionDict
[DT
.TAB_ARCH_COMMON
] = []
376 NewSectionDict
[DT
.TAB_ARCH_COMMON
] = NewSectionDict
[DT
.TAB_ARCH_COMMON
] + SpecialStatementList
377 GenMetaFileMisc
.AddExternToDefineSec(NewSectionDict
, DT
.TAB_ARCH_COMMON
, ExternList
)
378 if ValidArchStatement
is not None:
379 NewSectionDict
[DT
.TAB_ARCH_COMMON
] = NewSectionDict
[DT
.TAB_ARCH_COMMON
] + [ValidArchStatement
]
380 Content
+= GenSection('Defines', NewSectionDict
)
383 def GenLibraryClasses(ModuleObject
):
385 # generate [LibraryClasses] section
389 if not GlobalData
.gIS_BINARY_INF
:
390 for LibraryClass
in ModuleObject
.GetLibraryClassList():
391 if LibraryClass
.GetUsage() == DT
.USAGE_ITEM_PRODUCES
:
394 # Generate generic comment
396 HelpTextList
= LibraryClass
.GetHelpTextList()
397 HelpStr
= _GetHelpStr(HelpTextList
)
398 CommentStr
= GenGenericCommentF(HelpStr
)
399 Statement
= CommentStr
400 Name
= LibraryClass
.GetLibraryClass()
401 FFE
= LibraryClass
.GetFeatureFlag()
404 Statement
+= '|' + FFE
405 ModuleList
= LibraryClass
.GetSupModuleList()
406 ArchList
= LibraryClass
.GetSupArchList()
407 for Index
in xrange(0, len(ArchList
)):
408 ArchList
[Index
] = ConvertArchForInstall(ArchList
[Index
])
410 SortedArch
= ' '.join(ArchList
)
412 if not ModuleList
or IsAllModuleList(ModuleList
):
413 KeyList
= [SortedArch
]
415 ModuleString
= DT
.TAB_VALUE_SPLIT
.join(l
for l
in ModuleList
)
417 SortedArch
= DT
.TAB_ARCH_COMMON
418 KeyList
= [SortedArch
+ '.' + ModuleString
]
420 KeyList
= [Arch
+ '.' + ModuleString
for Arch
in ArchList
]
422 if Key
in NewSectionDict
:
423 NewSectionDict
[Key
] = NewSectionDict
[Key
] + [Statement
]
425 NewSectionDict
[Key
] = [Statement
]
426 Content
+= GenSection('LibraryClasses', NewSectionDict
)
428 LibraryClassDict
= {}
429 for BinaryFile
in ModuleObject
.GetBinaryFileList():
430 if not BinaryFile
.AsBuiltList
:
432 for LibraryItem
in BinaryFile
.AsBuiltList
[0].LibraryInstancesList
:
433 Statement
= '# Guid: ' + LibraryItem
.Guid
+ ' Version: ' + LibraryItem
.Version
435 if len(BinaryFile
.SupArchList
) == 0:
436 if LibraryClassDict
.has_key('COMMON') and Statement
not in LibraryClassDict
['COMMON']:
437 LibraryClassDict
['COMMON'].append(Statement
)
439 LibraryClassDict
['COMMON'] = ['## @LIB_INSTANCES']
440 LibraryClassDict
['COMMON'].append(Statement
)
442 for Arch
in BinaryFile
.SupArchList
:
443 if LibraryClassDict
.has_key(Arch
):
444 if Statement
not in LibraryClassDict
[Arch
]:
445 LibraryClassDict
[Arch
].append(Statement
)
449 LibraryClassDict
[Arch
] = ['## @LIB_INSTANCES']
450 LibraryClassDict
[Arch
].append(Statement
)
451 Content
+= GenSection('LibraryClasses', LibraryClassDict
)
455 def GenPackages(ModuleObject
):
458 # generate [Packages] section
460 NewSectionDict
= Sdict()
461 WorkspaceDir
= GlobalData
.gWORKSPACE
462 for PackageDependency
in ModuleObject
.GetPackageDependencyList():
464 # Generate generic comment
467 HelpText
= PackageDependency
.GetHelpText()
469 HelpStr
= HelpText
.GetString()
470 CommentStr
= GenGenericCommentF(HelpStr
)
471 Statement
= CommentStr
472 Guid
= PackageDependency
.GetGuid()
473 Version
= PackageDependency
.GetVersion()
474 FFE
= PackageDependency
.GetFeatureFlag()
477 # find package path/name
479 for PkgInfo
in GlobalData
.gWSPKG_LIST
:
480 if Guid
== PkgInfo
[1]:
481 if (not Version
) or (Version
== PkgInfo
[2]):
487 RelaPath
= GetRelativePath(Path
, WorkspaceDir
)
488 Statement
+= RelaPath
.replace('\\', '/')
490 Statement
+= '|' + FFE
491 ArchList
= PackageDependency
.GetSupArchList()
493 SortedArch
= ' '.join(ArchList
)
494 if SortedArch
in NewSectionDict
:
495 NewSectionDict
[SortedArch
] = NewSectionDict
[SortedArch
] + [Statement
]
497 NewSectionDict
[SortedArch
] = [Statement
]
498 Content
+= GenSection('Packages', NewSectionDict
)
501 def GenSources(ModuleObject
):
503 # generate [Sources] section
507 for Source
in ModuleObject
.GetSourceFileList():
508 SourceFile
= Source
.GetSourceFile()
509 Family
= Source
.GetFamily()
510 FeatureFlag
= Source
.GetFeatureFlag()
511 SupArchList
= Source
.GetSupArchList()
513 SortedArch
= ' '.join(SupArchList
)
514 Statement
= GenSourceStatement(ConvertPath(SourceFile
), Family
, FeatureFlag
)
515 if SortedArch
in NewSectionDict
:
516 NewSectionDict
[SortedArch
] = NewSectionDict
[SortedArch
] + [Statement
]
518 NewSectionDict
[SortedArch
] = [Statement
]
519 Content
+= GenSection('Sources', NewSectionDict
)
523 def GenDepex(ModuleObject
):
525 # generate [Depex] section
527 NewSectionDict
= Sdict()
529 for Depex
in ModuleObject
.GetPeiDepex() + ModuleObject
.GetDxeDepex() + ModuleObject
.GetSmmDepex():
530 HelpTextList
= Depex
.GetHelpTextList()
531 HelpStr
= _GetHelpStr(HelpTextList
)
532 CommentStr
= GenGenericCommentF(HelpStr
)
533 SupArchList
= Depex
.GetSupArchList()
534 SupModList
= Depex
.GetModuleType()
535 Expression
= Depex
.GetDepex()
536 Statement
= CommentStr
+ Expression
540 SupArchList
.append(DT
.TAB_ARCH_COMMON
.lower())
542 KeyList
= SupArchList
544 for ModuleType
in SupModList
:
545 for Arch
in SupArchList
:
546 KeyList
.append(ConvertArchForInstall(Arch
) + '.' + ModuleType
)
548 if Key
in NewSectionDict
:
549 NewSectionDict
[Key
] = NewSectionDict
[Key
] + [Statement
]
551 NewSectionDict
[Key
] = [Statement
]
552 Content
+= GenSection('Depex', NewSectionDict
, False)
559 def GenUserExtensions(ModuleObject
):
561 for UserExtension
in ModuleObject
.GetUserExtensionList():
562 if UserExtension
.GetUserID() == DT
.TAB_BINARY_HEADER_USERID
and \
563 UserExtension
.GetIdentifier() == DT
.TAB_BINARY_HEADER_IDENTIFIER
:
565 if UserExtension
.GetIdentifier() == 'Depex':
567 Statement
= UserExtension
.GetStatement()
570 ArchList
= UserExtension
.GetSupArchList()
571 for Index
in xrange(0, len(ArchList
)):
572 ArchList
[Index
] = ConvertArchForInstall(ArchList
[Index
])
576 if UserExtension
.GetUserID():
577 CommonPreFix
= UserExtension
.GetUserID()
578 if CommonPreFix
.find('.') > -1:
579 CommonPreFix
= '"' + CommonPreFix
+ '"'
580 if UserExtension
.GetIdentifier():
581 CommonPreFix
+= '.' + '"' + UserExtension
.GetIdentifier() + '"'
583 KeyList
= [CommonPreFix
+ '.' + Arch
for Arch
in ArchList
]
585 KeyList
= [CommonPreFix
]
587 if Key
in NewSectionDict
:
588 NewSectionDict
[Key
] = NewSectionDict
[Key
] + [Statement
]
590 NewSectionDict
[Key
] = [Statement
]
591 Content
= GenSection('UserExtensions', NewSectionDict
, False)
597 # @param SourceFile: string of source file path/name
598 # @param Family: string of source file family field
599 # @param FeatureFlag: string of source file FeatureFlag field
600 # @param TagName: string of source file TagName field
601 # @param ToolCode: string of source file ToolCode field
602 # @param HelpStr: string of source file HelpStr field
604 # @retval Statement: The generated statement for source
606 def GenSourceStatement(SourceFile
, Family
, FeatureFlag
, TagName
=None,
607 ToolCode
=None, HelpStr
=None):
610 Statement
+= GenGenericCommentF(HelpStr
)
612 # format of SourceFile|Family|TagName|ToolCode|FeatureFlag
614 Statement
+= SourceFile
622 Statement
+= '|' + Family
+ '|' + TagName
+ '|' + ToolCode
+ '|' + FeatureFlag
624 Statement
+= '|' + Family
+ '|' + TagName
+ '|' + ToolCode
626 Statement
+= '|' + Family
+ '|' + TagName
628 Statement
+= '|' + Family
633 # @param Key: (FileName, FileType, FFE, SortedArch)
634 # @param Value: (Target, Family, TagName, Comment)
637 def GenBinaryStatement(Key
, Value
, SubTypeGuidValue
=None):
638 (FileName
, FileType
, FFE
, SortedArch
) = Key
642 (Target
, Family
, TagName
, Comment
) = Value
649 Statement
= GenGenericCommentF(Comment
)
652 if FileType
== 'SUBTYPE_GUID' and SubTypeGuidValue
:
653 Statement
+= FileType
+ '|' + SubTypeGuidValue
+ '|' + FileName
655 Statement
+= FileType
+ '|' + FileName
656 if FileType
in DT
.BINARY_FILE_TYPE_UI_LIST
+ DT
.BINARY_FILE_TYPE_VER_LIST
:
658 Statement
+= '|' + Target
+ '|' + FFE
660 Statement
+= '|' + Target
663 Statement
+= '|' + Target
+ '|' + Family
+ '|' + TagName
+ '|' + FFE
665 Statement
+= '|' + Target
+ '|' + Family
+ '|' + TagName
667 Statement
+= '|' + Target
+ '|' + Family
669 Statement
+= '|' + Target
673 # @param GuidObjList: List of GuidObject
674 # @retVal Content: The generated section contents
676 def GenGuidSections(GuidObjList
):
678 # generate [Guids] section
682 for Guid
in GuidObjList
:
683 HelpTextList
= Guid
.GetHelpTextList()
684 HelpStr
= _GetHelpStr(HelpTextList
)
685 CName
= Guid
.GetCName()
686 FFE
= Guid
.GetFeatureFlag()
689 Statement
+= '|' + FFE
690 Usage
= Guid
.GetUsage()
691 GuidType
= Guid
.GetGuidTypeList()[0]
692 VariableName
= Guid
.GetVariableName()
694 # Differentiate the generic comment and usage comment as multiple generic comment need to be put at first
696 if Usage
== DT
.ITEM_UNDEFINED
and GuidType
== DT
.ITEM_UNDEFINED
:
697 # generate list of generic comment
698 Comment
= GenGenericCommentF(HelpStr
)
700 # generate list of other comment
701 Comment
= HelpStr
.replace('\n', ' ')
702 Comment
= Comment
.strip()
704 Comment
= ' # ' + Comment
707 if Usage
!= DT
.ITEM_UNDEFINED
and GuidType
== DT
.ITEM_UNDEFINED
:
708 Comment
= '## ' + Usage
+ ' ## GUID ' + Comment
709 elif GuidType
== 'Variable':
710 Comment
= '## ' + Usage
+ ' ## ' + GuidType
+ ':' + VariableName
+ Comment
712 Comment
= '## ' + Usage
+ ' ## ' + GuidType
+ Comment
717 # merge duplicate items
719 ArchList
= Guid
.GetSupArchList()
721 SortedArch
= ' '.join(ArchList
)
722 if (Statement
, SortedArch
) in GuidDict
:
723 PreviousComment
= GuidDict
[Statement
, SortedArch
]
724 Comment
= PreviousComment
+ Comment
725 GuidDict
[Statement
, SortedArch
] = Comment
726 NewSectionDict
= GenMetaFileMisc
.TransferDict(GuidDict
, 'INF_GUID')
728 # generate the section contents
731 Content
= GenSection('Guids', NewSectionDict
)
735 ## GenProtocolPPiSections
737 # @param ObjList: List of ProtocolObject or Ppi Object
738 # @retVal Content: The generated section contents
740 def GenProtocolPPiSections(ObjList
, IsProtocol
):
743 for Object
in ObjList
:
744 HelpTextList
= Object
.GetHelpTextList()
745 HelpStr
= _GetHelpStr(HelpTextList
)
746 CName
= Object
.GetCName()
747 FFE
= Object
.GetFeatureFlag()
750 Statement
+= '|' + FFE
751 Usage
= Object
.GetUsage()
752 Notify
= Object
.GetNotify()
754 # Differentiate the generic comment and usage comment as consecutive generic comment need to be put together
756 if Usage
== DT
.ITEM_UNDEFINED
and Notify
== '':
757 # generate list of generic comment
758 Comment
= GenGenericCommentF(HelpStr
)
760 # generate list of other comment
761 Comment
= HelpStr
.replace('\n', ' ')
762 Comment
= Comment
.strip()
764 Comment
= ' # ' + Comment
767 if Usage
== DT
.ITEM_UNDEFINED
and not Comment
and Notify
== '':
771 Comment
= '## ' + Usage
+ ' ## ' + 'NOTIFY' + Comment
773 Comment
= '## ' + Usage
+ Comment
777 # merge duplicate items
779 ArchList
= Object
.GetSupArchList()
781 SortedArch
= ' '.join(ArchList
)
782 if (Statement
, SortedArch
) in Dict
:
783 PreviousComment
= Dict
[Statement
, SortedArch
]
784 Comment
= PreviousComment
+ Comment
785 Dict
[Statement
, SortedArch
] = Comment
786 NewSectionDict
= GenMetaFileMisc
.TransferDict(Dict
, 'INF_PPI_PROTOCOL')
788 # generate the section contents
792 Content
= GenSection('Protocols', NewSectionDict
)
794 Content
= GenSection('Ppis', NewSectionDict
)
801 def GenPcdSections(ModuleObject
):
803 if not GlobalData
.gIS_BINARY_INF
:
805 # for each Pcd Itemtype, maintain a dict so the same type will be grouped
809 for Pcd
in ModuleObject
.GetPcdList():
810 HelpTextList
= Pcd
.GetHelpTextList()
811 HelpStr
= _GetHelpStr(HelpTextList
)
813 CName
= Pcd
.GetCName()
814 TokenSpaceGuidCName
= Pcd
.GetTokenSpaceGuidCName()
815 DefaultValue
= Pcd
.GetDefaultValue()
816 ItemType
= Pcd
.GetItemType()
817 if ItemType
in ItemTypeDict
:
818 Dict
= ItemTypeDict
[ItemType
]
821 ItemTypeDict
[ItemType
] = Dict
822 FFE
= Pcd
.GetFeatureFlag()
823 Statement
+= TokenSpaceGuidCName
+ '.' + CName
825 Statement
+= '|' + DefaultValue
827 Statement
+= '|' + FFE
829 Statement
+= '||' + FFE
833 Usage
= Pcd
.GetValidUsage()
834 # if FeatureFlag Pcd, then assume all Usage is CONSUMES
835 if ItemType
== DT
.TAB_INF_FEATURE_PCD
:
836 Usage
= DT
.USAGE_ITEM_CONSUMES
837 if Usage
== DT
.ITEM_UNDEFINED
:
838 # generate list of generic comment
839 Comment
= GenGenericCommentF(HelpStr
)
841 # generate list of other comment
842 Comment
= HelpStr
.replace('\n', ' ')
843 Comment
= Comment
.strip()
845 Comment
= ' # ' + Comment
848 Comment
= '## ' + Usage
+ Comment
852 # Merge duplicate entries
854 ArchList
= Pcd
.GetSupArchList()
856 SortedArch
= ' '.join(ArchList
)
857 if (Statement
, SortedArch
) in Dict
:
858 PreviousComment
= Dict
[Statement
, SortedArch
]
859 Comment
= PreviousComment
+ Comment
860 Dict
[Statement
, SortedArch
] = Comment
861 for ItemType
in ItemTypeDict
:
862 # First we need to transfer the Dict to use SortedArch as key
863 Dict
= ItemTypeDict
[ItemType
]
864 NewSectionDict
= GenMetaFileMisc
.TransferDict(Dict
, 'INF_PCD')
866 Content
+= GenSection(ItemType
, NewSectionDict
)
868 # For AsBuild INF files
871 Content
+= GenAsBuiltPacthPcdSections(ModuleObject
)
872 Content
+= GenAsBuiltPcdExSections(ModuleObject
)
879 def GenAsBuiltPacthPcdSections(ModuleObject
):
881 for BinaryFile
in ModuleObject
.GetBinaryFileList():
882 if not BinaryFile
.AsBuiltList
:
884 for PatchPcd
in BinaryFile
.AsBuiltList
[0].PatchPcdList
:
886 PcdCName
= PatchPcd
.CName
887 PcdValue
= PatchPcd
.DefaultValue
888 PcdOffset
= PatchPcd
.Offset
889 TokenSpaceGuidValue
= PatchPcd
.TokenSpaceGuidValue
890 Token
= PatchPcd
.Token
891 HelpTextList
= PatchPcd
.HelpTextList
893 for HelpStringItem
in HelpTextList
:
894 for HelpLine
in GetSplitValueList(HelpStringItem
.String
, '\n'):
895 HelpString
+= '## ' + HelpLine
+ '\n'
896 TokenSpaceName
, PcdCName
= GenMetaFileMisc
.ObtainPcdName(ModuleObject
.PackageDependencyList
,
899 if TokenSpaceName
== '' or PcdCName
== '':
901 ToolError
.RESOURCE_NOT_AVAILABLE
,
902 ST
.ERR_INSTALL_FILE_DEC_FILE_ERROR
% (TokenSpaceGuidValue
, Token
),
903 File
=ModuleObject
.GetFullPath())
904 Statement
= HelpString
+ TokenSpaceName
+ '.' + PcdCName
+ ' | ' + PcdValue
+ ' | ' + \
905 PcdOffset
+ DT
.TAB_SPACE_SPLIT
907 # Use binary file's Arch to be Pcd's Arch
910 FileNameObjList
= BinaryFile
.GetFileNameList()
912 ArchList
= FileNameObjList
[0].GetSupArchList()
913 if len(ArchList
) == 0:
914 if PatchPcdDict
.has_key(DT
.TAB_ARCH_COMMON
):
915 if Statement
not in PatchPcdDict
[DT
.TAB_ARCH_COMMON
]:
916 PatchPcdDict
[DT
.TAB_ARCH_COMMON
].append(Statement
)
918 PatchPcdDict
[DT
.TAB_ARCH_COMMON
] = [Statement
]
920 for Arch
in ArchList
:
921 if PatchPcdDict
.has_key(Arch
):
922 if Statement
not in PatchPcdDict
[Arch
]:
923 PatchPcdDict
[Arch
].append(Statement
)
925 PatchPcdDict
[Arch
] = [Statement
]
926 return GenSection(DT
.TAB_INF_PATCH_PCD
, PatchPcdDict
)
930 def GenAsBuiltPcdExSections(ModuleObject
):
932 for BinaryFile
in ModuleObject
.GetBinaryFileList():
933 if not BinaryFile
.AsBuiltList
:
935 for PcdExItem
in BinaryFile
.AsBuiltList
[0].PcdExValueList
:
937 PcdCName
= PcdExItem
.CName
938 TokenSpaceGuidValue
= PcdExItem
.TokenSpaceGuidValue
939 Token
= PcdExItem
.Token
940 HelpTextList
= PcdExItem
.HelpTextList
942 for HelpStringItem
in HelpTextList
:
943 for HelpLine
in GetSplitValueList(HelpStringItem
.String
, '\n'):
944 HelpString
+= '## ' + HelpLine
+ '\n'
945 TokenSpaceName
, PcdCName
= GenMetaFileMisc
.ObtainPcdName(ModuleObject
.PackageDependencyList
,
946 TokenSpaceGuidValue
, Token
)
947 if TokenSpaceName
== '' or PcdCName
== '':
949 ToolError
.RESOURCE_NOT_AVAILABLE
,
950 ST
.ERR_INSTALL_FILE_DEC_FILE_ERROR
% (TokenSpaceGuidValue
, Token
),
951 File
=ModuleObject
.GetFullPath())
953 Statement
= HelpString
+ TokenSpaceName
+ DT
.TAB_SPLIT
+ PcdCName
+ DT
.TAB_SPACE_SPLIT
956 # Use binary file's Arch to be Pcd's Arch
959 FileNameObjList
= BinaryFile
.GetFileNameList()
961 ArchList
= FileNameObjList
[0].GetSupArchList()
963 if len(ArchList
) == 0:
964 if PcdExDict
.has_key('COMMON'):
965 PcdExDict
['COMMON'].append(Statement
)
967 PcdExDict
['COMMON'] = [Statement
]
969 for Arch
in ArchList
:
970 if PcdExDict
.has_key(Arch
):
971 if Statement
not in PcdExDict
[Arch
]:
972 PcdExDict
[Arch
].append(Statement
)
974 PcdExDict
[Arch
] = [Statement
]
975 return GenSection('PcdEx', PcdExDict
)
977 ## GenSpecialSections
978 # generate special sections for Event/BootMode/Hob
980 def GenSpecialSections(ObjectList
, SectionName
):
986 for Obj
in ObjectList
:
991 HelpTextList
= Obj
.GetHelpTextList()
992 HelpStr
= _GetHelpStr(HelpTextList
)
993 CommentStr
= GenGenericCommentF(HelpStr
)
994 if SectionName
== 'Hob':
995 Type
= Obj
.GetHobType()
996 elif SectionName
== 'Event':
997 Type
= Obj
.GetEventType()
998 elif SectionName
== 'BootMode':
999 Type
= Obj
.GetSupportedBootModes()
1002 Usage
= Obj
.GetUsage()
1003 Statement
= ' ' + Type
+ ' ## ' + Usage
1004 if CommentStr
in ['#\n', '#\n#\n']:
1005 CommentStr
= '#\n#\n#\n'
1007 # the first head comment line should start with '##\n', if it starts with '#\n', then add one '#'
1008 # else add '##\n' to meet the format defined in INF spec
1010 if CommentStr
.startswith('#\n'):
1011 CommentStr
= '#' + CommentStr
1013 CommentStr
= '##\n' + CommentStr
1014 if CommentStr
and not CommentStr
.endswith('\n#\n'):
1015 CommentStr
= CommentStr
+ '#\n'
1016 NewStateMent
= CommentStr
+ Statement
1017 SupArch
= Obj
.GetSupArchList()
1019 SortedArch
= ' '.join(SupArch
)
1020 if SortedArch
in NewSectionDict
:
1021 NewSectionDict
[SortedArch
] = NewSectionDict
[SortedArch
] + [NewStateMent
]
1023 NewSectionDict
[SortedArch
] = [NewStateMent
]
1024 SectionContent
= GenSection(SectionName
, NewSectionDict
)
1025 SectionContent
= SectionContent
.strip()
1027 Content
= '# ' + ('\n' + '# ').join(GetSplitValueList(SectionContent
, '\n'))
1028 Content
= Content
.lstrip()
1030 # add two empty line after the generated section content to differentiate it between other possible sections
1033 Content
+= '\n#\n#\n'
1038 def GenBuildOptions(ModuleObject
):
1040 if not ModuleObject
.BinaryModule
:
1042 # generate [BuildOptions] section
1045 for UserExtension
in ModuleObject
.GetUserExtensionList():
1046 BuildOptionDict
= UserExtension
.GetBuildOptionDict()
1047 if not BuildOptionDict
:
1049 for Arch
in BuildOptionDict
:
1050 if Arch
in NewSectionDict
:
1051 NewSectionDict
[Arch
] = NewSectionDict
[Arch
] + [BuildOptionDict
[Arch
]]
1053 NewSectionDict
[Arch
] = [BuildOptionDict
[Arch
]]
1054 Content
= GenSection('BuildOptions', NewSectionDict
)
1056 BuildOptionDict
= {}
1057 for BinaryFile
in ModuleObject
.GetBinaryFileList():
1058 if not BinaryFile
.AsBuiltList
:
1060 for BuilOptionItem
in BinaryFile
.AsBuiltList
[0].BinaryBuildFlagList
:
1061 Statement
= '#' + BuilOptionItem
.AsBuiltOptionFlags
1062 if len(BinaryFile
.SupArchList
) == 0:
1063 if BuildOptionDict
.has_key('COMMON'):
1064 if Statement
not in BuildOptionDict
['COMMON']:
1065 BuildOptionDict
['COMMON'].append(Statement
)
1067 BuildOptionDict
['COMMON'] = ['## @AsBuilt']
1068 BuildOptionDict
['COMMON'].append(Statement
)
1070 for Arch
in BinaryFile
.SupArchList
:
1071 if BuildOptionDict
.has_key(Arch
):
1072 if Statement
not in BuildOptionDict
[Arch
]:
1073 BuildOptionDict
[Arch
].append(Statement
)
1075 BuildOptionDict
[Arch
] = ['## @AsBuilt']
1076 BuildOptionDict
[Arch
].append(Statement
)
1077 Content
= GenSection('BuildOptions', BuildOptionDict
)
1083 def GenBinaries(ModuleObject
):
1086 for UserExtension
in ModuleObject
.GetUserExtensionList():
1087 BinariesDict
= UserExtension
.GetBinariesDict()
1090 for BinaryFile
in ModuleObject
.GetBinaryFileList():
1091 FileNameObjList
= BinaryFile
.GetFileNameList()
1092 for FileNameObj
in FileNameObjList
:
1093 FileName
= ConvertPath(FileNameObj
.GetFilename())
1094 FileType
= FileNameObj
.GetFileType()
1095 FFE
= FileNameObj
.GetFeatureFlag()
1096 ArchList
= FileNameObj
.GetSupArchList()
1098 SortedArch
= ' '.join(ArchList
)
1099 Key
= (FileName
, FileType
, FFE
, SortedArch
)
1100 if Key
in BinariesDict
:
1101 ValueList
= BinariesDict
[Key
]
1102 for ValueItem
in ValueList
:
1103 Statement
= GenBinaryStatement(Key
, ValueItem
)
1104 if SortedArch
in NewSectionDict
:
1105 NewSectionDict
[SortedArch
] = NewSectionDict
[SortedArch
] + [Statement
]
1107 NewSectionDict
[SortedArch
] = [Statement
]
1109 # as we already generated statement for this DictKey here set the Valuelist to be empty
1110 # to avoid generate duplicate entries as the DictKey may have multiple entries
1112 BinariesDict
[Key
] = []
1114 if FileType
== 'SUBTYPE_GUID' and FileNameObj
.GetGuidValue():
1115 Statement
= GenBinaryStatement(Key
, None, FileNameObj
.GetGuidValue())
1117 Statement
= GenBinaryStatement(Key
, None)
1118 if SortedArch
in NewSectionDict
:
1119 NewSectionDict
[SortedArch
] = NewSectionDict
[SortedArch
] + [Statement
]
1121 NewSectionDict
[SortedArch
] = [Statement
]
1122 Content
= GenSection('Binaries', NewSectionDict
)