3 # This file contained the logical of transfer package object to INF files.
5 # Copyright (c) 2011 - 2017, 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
44 from Library
.String
import GetUniFileName
47 ## Transfer Module Object to Inf files
49 # Transfer all contents of a standard Module Object to an Inf file
50 # @param ModuleObject: A Module Object
52 def ModuleToInf(ModuleObject
, PackageObject
=None, DistHeader
=None):
53 if not GlobalData
.gWSPKG_LIST
:
54 GlobalData
.gWSPKG_LIST
= GetWorkspacePackage()
56 # Init global information for the file
58 ContainerFile
= ModuleObject
.GetFullPath()
62 # Generate file header, If any Abstract, Description, Copyright or License XML elements are missing,
63 # should 1) use the Abstract, Description, Copyright or License from the PackageSurfaceArea.Header elements
64 # that the module belongs to, or 2) if this is a stand-alone module that is not included in a PackageSurfaceArea,
65 # use the abstract, description, copyright or license from the DistributionPackage.Header elements.
67 ModuleAbstract
= GetLocalValue(ModuleObject
.GetAbstract())
68 if not ModuleAbstract
and PackageObject
:
69 ModuleAbstract
= GetLocalValue(PackageObject
.GetAbstract())
70 if not ModuleAbstract
and DistHeader
:
71 ModuleAbstract
= GetLocalValue(DistHeader
.GetAbstract())
72 ModuleDescription
= GetLocalValue(ModuleObject
.GetDescription())
73 if not ModuleDescription
and PackageObject
:
74 ModuleDescription
= GetLocalValue(PackageObject
.GetDescription())
75 if not ModuleDescription
and DistHeader
:
76 ModuleDescription
= GetLocalValue(DistHeader
.GetDescription())
78 for (Lang
, Copyright
) in ModuleObject
.GetCopyright():
81 ModuleCopyright
= Copyright
82 if not ModuleCopyright
and PackageObject
:
83 for (Lang
, Copyright
) in PackageObject
.GetCopyright():
86 ModuleCopyright
= Copyright
87 if not ModuleCopyright
and DistHeader
:
88 for (Lang
, Copyright
) in DistHeader
.GetCopyright():
91 ModuleCopyright
= Copyright
93 for (Lang
, License
) in ModuleObject
.GetLicense():
96 ModuleLicense
= License
97 if not ModuleLicense
and PackageObject
:
98 for (Lang
, License
) in PackageObject
.GetLicense():
101 ModuleLicense
= License
102 if not ModuleLicense
and DistHeader
:
103 for (Lang
, License
) in DistHeader
.GetLicense():
106 ModuleLicense
= License
109 # Generate header comment section of INF file
111 Content
+= GenHeaderCommentSection(ModuleAbstract
,
114 ModuleLicense
).replace('\r\n', '\n')
117 # Generate Binary Header
119 for UserExtension
in ModuleObject
.GetUserExtensionList():
120 if UserExtension
.GetUserID() == DT
.TAB_BINARY_HEADER_USERID \
121 and UserExtension
.GetIdentifier() == DT
.TAB_BINARY_HEADER_IDENTIFIER
:
122 ModuleBinaryAbstract
= GetLocalValue(UserExtension
.GetBinaryAbstract())
123 ModuleBinaryDescription
= GetLocalValue(UserExtension
.GetBinaryDescription())
124 ModuleBinaryCopyright
= ''
125 ModuleBinaryLicense
= ''
126 for (Lang
, Copyright
) in UserExtension
.GetBinaryCopyright():
127 ModuleBinaryCopyright
= Copyright
128 for (Lang
, License
) in UserExtension
.GetBinaryLicense():
129 ModuleBinaryLicense
= License
130 if ModuleBinaryAbstract
and ModuleBinaryDescription
and \
131 ModuleBinaryCopyright
and ModuleBinaryLicense
:
132 Content
+= GenHeaderCommentSection(ModuleBinaryAbstract
,
133 ModuleBinaryDescription
,
134 ModuleBinaryCopyright
,
139 # Generate MODULE_UNI_FILE for module
141 FileHeader
= GenHeaderCommentSection(ModuleAbstract
, ModuleDescription
, ModuleCopyright
, ModuleLicense
, False, \
142 DT
.TAB_COMMENT_EDK1_SPLIT
)
143 GenModuleUNIEncodeFile(ModuleObject
, FileHeader
)
146 # Judge whether the INF file is an AsBuild INF.
148 if ModuleObject
.BinaryModule
:
149 GlobalData
.gIS_BINARY_INF
= True
151 GlobalData
.gIS_BINARY_INF
= False
153 # for each section, maintain a dict, sorted arch will be its key,
154 # statement list will be its data
155 # { 'Arch1 Arch2 Arch3': [statement1, statement2],
156 # 'Arch1' : [statement1, statement3]
159 # Gen section contents
161 Content
+= GenDefines(ModuleObject
)
162 Content
+= GenBuildOptions(ModuleObject
)
163 Content
+= GenLibraryClasses(ModuleObject
)
164 Content
+= GenPackages(ModuleObject
)
165 Content
+= GenPcdSections(ModuleObject
)
166 Content
+= GenSources(ModuleObject
)
167 Content
+= GenProtocolPPiSections(ModuleObject
.GetProtocolList(), True)
168 Content
+= GenProtocolPPiSections(ModuleObject
.GetPpiList(), False)
169 Content
+= GenGuidSections(ModuleObject
.GetGuidList())
170 Content
+= GenBinaries(ModuleObject
)
171 Content
+= GenDepex(ModuleObject
)
172 __UserExtensionsContent
= GenUserExtensions(ModuleObject
)
173 Content
+= __UserExtensionsContent
174 if ModuleObject
.GetEventList() or ModuleObject
.GetBootModeList() or ModuleObject
.GetHobList():
177 # generate [Event], [BootMode], [Hob] section
179 Content
+= GenSpecialSections(ModuleObject
.GetEventList(), 'Event', __UserExtensionsContent
)
180 Content
+= GenSpecialSections(ModuleObject
.GetBootModeList(), 'BootMode', __UserExtensionsContent
)
181 Content
+= GenSpecialSections(ModuleObject
.GetHobList(), 'Hob', __UserExtensionsContent
)
182 SaveFileOnChange(ContainerFile
, Content
, False)
183 if DistHeader
.ReadOnly
:
184 os
.chmod(ContainerFile
, stat
.S_IRUSR|stat
.S_IRGRP|stat
.S_IROTH
)
186 os
.chmod(ContainerFile
, stat
.S_IRUSR|stat
.S_IRGRP|stat
.S_IROTH|stat
.S_IWUSR|stat
.S_IWGRP|stat
.S_IWOTH
)
189 ## GenModuleUNIEncodeFile
190 # GenModuleUNIEncodeFile, default is a UCS-2LE encode file
192 def GenModuleUNIEncodeFile(ModuleObject
, UniFileHeader
='', Encoding
=DT
.TAB_ENCODING_UTF16LE
):
194 OnlyLANGUAGE_EN_X
= True
196 BinaryDescription
= []
198 # If more than one language code is used for any element that would be present in the MODULE_UNI_FILE,
199 # then the MODULE_UNI_FILE must be created.
201 for (Key
, Value
) in ModuleObject
.GetAbstract() + ModuleObject
.GetDescription():
202 if Key
== DT
.TAB_LANGUAGE_EN_X
:
205 OnlyLANGUAGE_EN_X
= False
207 for UserExtension
in ModuleObject
.GetUserExtensionList():
208 if UserExtension
.GetUserID() == DT
.TAB_BINARY_HEADER_USERID \
209 and UserExtension
.GetIdentifier() == DT
.TAB_BINARY_HEADER_IDENTIFIER
:
210 for (Key
, Value
) in UserExtension
.GetBinaryAbstract():
211 if Key
== DT
.TAB_LANGUAGE_EN_X
:
214 OnlyLANGUAGE_EN_X
= False
215 BinaryAbstract
.append((Key
, Value
))
216 for (Key
, Value
) in UserExtension
.GetBinaryDescription():
217 if Key
== DT
.TAB_LANGUAGE_EN_X
:
220 OnlyLANGUAGE_EN_X
= False
221 BinaryDescription
.append((Key
, Value
))
226 elif OnlyLANGUAGE_EN_X
:
229 ModuleObject
.UNIFlag
= True
230 ContainerFile
= GetUniFileName(os
.path
.dirname(ModuleObject
.GetFullPath()), ModuleObject
.GetBaseName())
232 if not os
.path
.exists(os
.path
.dirname(ModuleObject
.GetFullPath())):
233 os
.makedirs(os
.path
.dirname(ModuleObject
.GetFullPath()))
235 Content
= UniFileHeader
+ '\r\n'
238 Content
+= FormatUniEntry('#string ' + DT
.TAB_INF_ABSTRACT
, ModuleObject
.GetAbstract(), ContainerFile
) + '\r\n'
240 Content
+= FormatUniEntry('#string ' + DT
.TAB_INF_DESCRIPTION
, ModuleObject
.GetDescription(), ContainerFile
) \
243 BinaryAbstractString
= FormatUniEntry('#string ' + DT
.TAB_INF_BINARY_ABSTRACT
, BinaryAbstract
, ContainerFile
)
244 if BinaryAbstractString
:
245 Content
+= BinaryAbstractString
+ '\r\n'
247 BinaryDescriptionString
= FormatUniEntry('#string ' + DT
.TAB_INF_BINARY_DESCRIPTION
, BinaryDescription
, \
249 if BinaryDescriptionString
:
250 Content
+= BinaryDescriptionString
+ '\r\n'
252 if not os
.path
.exists(ContainerFile
):
253 File
= codecs
.open(ContainerFile
, 'wb', Encoding
)
254 File
.write(u
'\uFEFF' + Content
)
256 Md5Sigature
= md5
.new(__FileHookOpen__(str(ContainerFile
), 'rb').read())
257 Md5Sum
= Md5Sigature
.hexdigest()
258 if (ContainerFile
, Md5Sum
) not in ModuleObject
.FileList
:
259 ModuleObject
.FileList
.append((ContainerFile
, Md5Sum
))
262 def GenDefines(ModuleObject
):
264 # generate [Defines] section
270 for UserExtension
in ModuleObject
.GetUserExtensionList():
271 DefinesDict
= UserExtension
.GetDefinesDict()
274 for Statement
in DefinesDict
:
275 if Statement
.split(DT
.TAB_EQUAL_SPLIT
) > 1:
276 Statement
= (u
'%s ' % Statement
.split(DT
.TAB_EQUAL_SPLIT
, 1)[0]).ljust(LeftOffset
) \
277 + u
'= %s' % Statement
.split(DT
.TAB_EQUAL_SPLIT
, 1)[1].lstrip()
278 SortedArch
= DT
.TAB_ARCH_COMMON
279 if Statement
.strip().startswith(DT
.TAB_INF_DEFINES_CUSTOM_MAKEFILE
):
280 pos
= Statement
.find(DT
.TAB_VALUE_SPLIT
)
282 pos
= Statement
.find(DT
.TAB_EQUAL_SPLIT
)
283 Makefile
= ConvertPath(Statement
[pos
+ 1:].strip())
284 Statement
= Statement
[:pos
+ 1] + ' ' + Makefile
285 if SortedArch
in NewSectionDict
:
286 NewSectionDict
[SortedArch
] = NewSectionDict
[SortedArch
] + [Statement
]
288 NewSectionDict
[SortedArch
] = [Statement
]
289 SpecialStatementList
= []
291 # TAB_INF_DEFINES_INF_VERSION
292 Statement
= (u
'%s ' % DT
.TAB_INF_DEFINES_INF_VERSION
).ljust(LeftOffset
) + u
'= %s' % '0x00010017'
293 SpecialStatementList
.append(Statement
)
296 BaseName
= ModuleObject
.GetBaseName()
297 if BaseName
.startswith('.') or BaseName
.startswith('-'):
298 BaseName
= '_' + BaseName
299 Statement
= (u
'%s ' % DT
.TAB_INF_DEFINES_BASE_NAME
).ljust(LeftOffset
) + u
'= %s' % BaseName
300 SpecialStatementList
.append(Statement
)
302 # TAB_INF_DEFINES_FILE_GUID
303 Statement
= (u
'%s ' % DT
.TAB_INF_DEFINES_FILE_GUID
).ljust(LeftOffset
) + u
'= %s' % ModuleObject
.GetGuid()
304 SpecialStatementList
.append(Statement
)
306 # TAB_INF_DEFINES_VERSION_STRING
307 Statement
= (u
'%s ' % DT
.TAB_INF_DEFINES_VERSION_STRING
).ljust(LeftOffset
) + u
'= %s' % ModuleObject
.GetVersion()
308 SpecialStatementList
.append(Statement
)
310 # TAB_INF_DEFINES_VERSION_STRING
311 if ModuleObject
.UNIFlag
:
312 Statement
= (u
'%s ' % DT
.TAB_INF_DEFINES_MODULE_UNI_FILE
).ljust(LeftOffset
) + \
313 u
'= %s' % ModuleObject
.GetBaseName() + '.uni'
314 SpecialStatementList
.append(Statement
)
316 # TAB_INF_DEFINES_MODULE_TYPE
317 if ModuleObject
.GetModuleType():
318 Statement
= (u
'%s ' % DT
.TAB_INF_DEFINES_MODULE_TYPE
).ljust(LeftOffset
) + u
'= %s' % ModuleObject
.GetModuleType()
319 SpecialStatementList
.append(Statement
)
321 # TAB_INF_DEFINES_PCD_IS_DRIVER
322 if ModuleObject
.GetPcdIsDriver():
323 Statement
= (u
'%s ' % DT
.TAB_INF_DEFINES_PCD_IS_DRIVER
).ljust(LeftOffset
) + \
324 u
'= %s' % ModuleObject
.GetPcdIsDriver()
325 SpecialStatementList
.append(Statement
)
327 # TAB_INF_DEFINES_UEFI_SPECIFICATION_VERSION
328 if ModuleObject
.GetUefiSpecificationVersion():
329 Statement
= (u
'%s ' % DT
.TAB_INF_DEFINES_UEFI_SPECIFICATION_VERSION
).ljust(LeftOffset
) + \
330 u
'= %s' % ModuleObject
.GetUefiSpecificationVersion()
331 SpecialStatementList
.append(Statement
)
333 # TAB_INF_DEFINES_PI_SPECIFICATION_VERSION
334 if ModuleObject
.GetPiSpecificationVersion():
335 Statement
= (u
'%s ' % DT
.TAB_INF_DEFINES_PI_SPECIFICATION_VERSION
).ljust(LeftOffset
) + \
336 u
'= %s' % ModuleObject
.GetPiSpecificationVersion()
337 SpecialStatementList
.append(Statement
)
340 for LibraryClass
in ModuleObject
.GetLibraryClassList():
341 if LibraryClass
.GetUsage() == DT
.USAGE_ITEM_PRODUCES
or \
342 LibraryClass
.GetUsage() == DT
.USAGE_ITEM_SOMETIMES_PRODUCES
:
343 Statement
= (u
'%s ' % DT
.TAB_INF_DEFINES_LIBRARY_CLASS
).ljust(LeftOffset
) + \
344 u
'= %s' % LibraryClass
.GetLibraryClass()
345 if LibraryClass
.GetSupModuleList():
346 Statement
+= '|' + DT
.TAB_SPACE_SPLIT
.join(l
for l
in LibraryClass
.GetSupModuleList())
347 SpecialStatementList
.append(Statement
)
350 for SpecItem
in ModuleObject
.GetSpecList():
351 Spec
, Version
= SpecItem
352 Spec
= ConvertSpec(Spec
)
353 Statement
= '%s %s = %s' % (DT
.TAB_INF_DEFINES_SPEC
, Spec
, Version
)
354 SpecialStatementList
.append(Statement
)
358 for Extern
in ModuleObject
.GetExternList():
359 ArchList
= Extern
.GetSupArchList()
360 EntryPoint
= Extern
.GetEntryPoint()
361 UnloadImage
= Extern
.GetUnloadImage()
362 Constructor
= Extern
.GetConstructor()
363 Destructor
= Extern
.GetDestructor()
364 HelpStringList
= Extern
.GetHelpTextList()
365 FFE
= Extern
.GetFeatureFlag()
366 ExternList
.append([ArchList
, EntryPoint
, UnloadImage
, Constructor
, Destructor
, FFE
, HelpStringList
])
368 # Add VALID_ARCHITECTURES information
370 ValidArchStatement
= None
371 if ModuleObject
.SupArchList
:
372 ValidArchStatement
= '\n' + '# ' + '\n'
373 ValidArchStatement
+= '# The following information is for reference only and not required by the build tools.\n'
374 ValidArchStatement
+= '# ' + '\n'
375 ValidArchStatement
+= '# VALID_ARCHITECTURES = %s' % (' '.join(ModuleObject
.SupArchList
)) + '\n'
376 ValidArchStatement
+= '# '
377 if DT
.TAB_ARCH_COMMON
not in NewSectionDict
:
378 NewSectionDict
[DT
.TAB_ARCH_COMMON
] = []
379 NewSectionDict
[DT
.TAB_ARCH_COMMON
] = NewSectionDict
[DT
.TAB_ARCH_COMMON
] + SpecialStatementList
380 GenMetaFileMisc
.AddExternToDefineSec(NewSectionDict
, DT
.TAB_ARCH_COMMON
, ExternList
)
381 if ValidArchStatement
is not None:
382 NewSectionDict
[DT
.TAB_ARCH_COMMON
] = NewSectionDict
[DT
.TAB_ARCH_COMMON
] + [ValidArchStatement
]
383 Content
+= GenSection('Defines', NewSectionDict
)
386 def GenLibraryClasses(ModuleObject
):
388 # generate [LibraryClasses] section
392 if not GlobalData
.gIS_BINARY_INF
:
393 for LibraryClass
in ModuleObject
.GetLibraryClassList():
394 if LibraryClass
.GetUsage() == DT
.USAGE_ITEM_PRODUCES
:
397 # Generate generic comment
399 HelpTextList
= LibraryClass
.GetHelpTextList()
400 HelpStr
= _GetHelpStr(HelpTextList
)
401 CommentStr
= GenGenericCommentF(HelpStr
)
402 Statement
= CommentStr
403 Name
= LibraryClass
.GetLibraryClass()
404 FFE
= LibraryClass
.GetFeatureFlag()
407 Statement
+= '|' + FFE
408 ModuleList
= LibraryClass
.GetSupModuleList()
409 ArchList
= LibraryClass
.GetSupArchList()
410 for Index
in xrange(0, len(ArchList
)):
411 ArchList
[Index
] = ConvertArchForInstall(ArchList
[Index
])
413 SortedArch
= ' '.join(ArchList
)
415 if not ModuleList
or IsAllModuleList(ModuleList
):
416 KeyList
= [SortedArch
]
418 ModuleString
= DT
.TAB_VALUE_SPLIT
.join(l
for l
in ModuleList
)
420 SortedArch
= DT
.TAB_ARCH_COMMON
421 KeyList
= [SortedArch
+ '.' + ModuleString
]
423 KeyList
= [Arch
+ '.' + ModuleString
for Arch
in ArchList
]
425 if Key
in NewSectionDict
:
426 NewSectionDict
[Key
] = NewSectionDict
[Key
] + [Statement
]
428 NewSectionDict
[Key
] = [Statement
]
429 Content
+= GenSection('LibraryClasses', NewSectionDict
)
431 LibraryClassDict
= {}
432 for BinaryFile
in ModuleObject
.GetBinaryFileList():
433 if not BinaryFile
.AsBuiltList
:
435 for LibraryItem
in BinaryFile
.AsBuiltList
[0].LibraryInstancesList
:
436 Statement
= '# Guid: ' + LibraryItem
.Guid
+ ' Version: ' + LibraryItem
.Version
438 if len(BinaryFile
.SupArchList
) == 0:
439 if LibraryClassDict
.has_key('COMMON') and Statement
not in LibraryClassDict
['COMMON']:
440 LibraryClassDict
['COMMON'].append(Statement
)
442 LibraryClassDict
['COMMON'] = ['## @LIB_INSTANCES']
443 LibraryClassDict
['COMMON'].append(Statement
)
445 for Arch
in BinaryFile
.SupArchList
:
446 if LibraryClassDict
.has_key(Arch
):
447 if Statement
not in LibraryClassDict
[Arch
]:
448 LibraryClassDict
[Arch
].append(Statement
)
452 LibraryClassDict
[Arch
] = ['## @LIB_INSTANCES']
453 LibraryClassDict
[Arch
].append(Statement
)
454 Content
+= GenSection('LibraryClasses', LibraryClassDict
)
458 def GenPackages(ModuleObject
):
461 # generate [Packages] section
463 NewSectionDict
= Sdict()
464 WorkspaceDir
= GlobalData
.gWORKSPACE
465 for PackageDependency
in ModuleObject
.GetPackageDependencyList():
467 # Generate generic comment
470 HelpText
= PackageDependency
.GetHelpText()
472 HelpStr
= HelpText
.GetString()
473 CommentStr
= GenGenericCommentF(HelpStr
)
474 Statement
= CommentStr
475 Guid
= PackageDependency
.GetGuid()
476 Version
= PackageDependency
.GetVersion()
477 FFE
= PackageDependency
.GetFeatureFlag()
480 # find package path/name
482 for PkgInfo
in GlobalData
.gWSPKG_LIST
:
483 if Guid
== PkgInfo
[1]:
484 if (not Version
) or (Version
== PkgInfo
[2]):
490 RelaPath
= GetRelativePath(Path
, WorkspaceDir
)
491 Statement
+= RelaPath
.replace('\\', '/')
493 Statement
+= '|' + FFE
494 ArchList
= PackageDependency
.GetSupArchList()
496 SortedArch
= ' '.join(ArchList
)
497 if SortedArch
in NewSectionDict
:
498 NewSectionDict
[SortedArch
] = NewSectionDict
[SortedArch
] + [Statement
]
500 NewSectionDict
[SortedArch
] = [Statement
]
501 Content
+= GenSection('Packages', NewSectionDict
)
504 def GenSources(ModuleObject
):
506 # generate [Sources] section
510 for Source
in ModuleObject
.GetSourceFileList():
511 SourceFile
= Source
.GetSourceFile()
512 Family
= Source
.GetFamily()
513 FeatureFlag
= Source
.GetFeatureFlag()
514 SupArchList
= Source
.GetSupArchList()
516 SortedArch
= ' '.join(SupArchList
)
517 Statement
= GenSourceStatement(ConvertPath(SourceFile
), Family
, FeatureFlag
)
518 if SortedArch
in NewSectionDict
:
519 NewSectionDict
[SortedArch
] = NewSectionDict
[SortedArch
] + [Statement
]
521 NewSectionDict
[SortedArch
] = [Statement
]
522 Content
+= GenSection('Sources', NewSectionDict
)
526 def GenDepex(ModuleObject
):
528 # generate [Depex] section
530 NewSectionDict
= Sdict()
532 for Depex
in ModuleObject
.GetPeiDepex() + ModuleObject
.GetDxeDepex() + ModuleObject
.GetSmmDepex():
533 HelpTextList
= Depex
.GetHelpTextList()
534 HelpStr
= _GetHelpStr(HelpTextList
)
535 CommentStr
= GenGenericCommentF(HelpStr
)
536 SupArchList
= Depex
.GetSupArchList()
537 SupModList
= Depex
.GetModuleType()
538 Expression
= Depex
.GetDepex()
539 Statement
= CommentStr
+ Expression
543 SupArchList
.append(DT
.TAB_ARCH_COMMON
.lower())
545 KeyList
= SupArchList
547 for ModuleType
in SupModList
:
548 for Arch
in SupArchList
:
549 KeyList
.append(ConvertArchForInstall(Arch
) + '.' + ModuleType
)
551 if Key
in NewSectionDict
:
552 NewSectionDict
[Key
] = NewSectionDict
[Key
] + [Statement
]
554 NewSectionDict
[Key
] = [Statement
]
555 Content
+= GenSection('Depex', NewSectionDict
, False)
562 def GenUserExtensions(ModuleObject
):
564 for UserExtension
in ModuleObject
.GetUserExtensionList():
565 if UserExtension
.GetUserID() == DT
.TAB_BINARY_HEADER_USERID
and \
566 UserExtension
.GetIdentifier() == DT
.TAB_BINARY_HEADER_IDENTIFIER
:
568 if UserExtension
.GetIdentifier() == 'Depex':
570 Statement
= UserExtension
.GetStatement()
571 # Comment the code to support user extension without any statement just the section header in []
574 ArchList
= UserExtension
.GetSupArchList()
575 for Index
in xrange(0, len(ArchList
)):
576 ArchList
[Index
] = ConvertArchForInstall(ArchList
[Index
])
580 if UserExtension
.GetUserID():
581 CommonPreFix
= UserExtension
.GetUserID()
582 if CommonPreFix
.find('.') > -1:
583 CommonPreFix
= '"' + CommonPreFix
+ '"'
584 if UserExtension
.GetIdentifier():
585 CommonPreFix
+= '.' + '"' + UserExtension
.GetIdentifier() + '"'
587 KeyList
= [CommonPreFix
+ '.' + Arch
for Arch
in ArchList
]
589 KeyList
= [CommonPreFix
]
591 if Key
in NewSectionDict
:
592 NewSectionDict
[Key
] = NewSectionDict
[Key
] + [Statement
]
594 NewSectionDict
[Key
] = [Statement
]
595 Content
= GenSection('UserExtensions', NewSectionDict
, False)
601 # @param SourceFile: string of source file path/name
602 # @param Family: string of source file family field
603 # @param FeatureFlag: string of source file FeatureFlag field
604 # @param TagName: string of source file TagName field
605 # @param ToolCode: string of source file ToolCode field
606 # @param HelpStr: string of source file HelpStr field
608 # @retval Statement: The generated statement for source
610 def GenSourceStatement(SourceFile
, Family
, FeatureFlag
, TagName
=None,
611 ToolCode
=None, HelpStr
=None):
614 Statement
+= GenGenericCommentF(HelpStr
)
616 # format of SourceFile|Family|TagName|ToolCode|FeatureFlag
618 Statement
+= SourceFile
626 Statement
+= '|' + Family
+ '|' + TagName
+ '|' + ToolCode
+ '|' + FeatureFlag
628 Statement
+= '|' + Family
+ '|' + TagName
+ '|' + ToolCode
630 Statement
+= '|' + Family
+ '|' + TagName
632 Statement
+= '|' + Family
637 # @param Key: (FileName, FileType, FFE, SortedArch)
638 # @param Value: (Target, Family, TagName, Comment)
641 def GenBinaryStatement(Key
, Value
, SubTypeGuidValue
=None):
642 (FileName
, FileType
, FFE
, SortedArch
) = Key
646 (Target
, Family
, TagName
, Comment
) = Value
653 Statement
= GenGenericCommentF(Comment
)
656 if FileType
== 'SUBTYPE_GUID' and SubTypeGuidValue
:
657 Statement
+= FileType
+ '|' + SubTypeGuidValue
+ '|' + FileName
659 Statement
+= FileType
+ '|' + FileName
660 if FileType
in DT
.BINARY_FILE_TYPE_UI_LIST
+ DT
.BINARY_FILE_TYPE_VER_LIST
:
662 Statement
+= '|' + Target
+ '|' + FFE
664 Statement
+= '|' + Target
667 Statement
+= '|' + Target
+ '|' + Family
+ '|' + TagName
+ '|' + FFE
669 Statement
+= '|' + Target
+ '|' + Family
+ '|' + TagName
671 Statement
+= '|' + Target
+ '|' + Family
673 Statement
+= '|' + Target
677 # @param GuidObjList: List of GuidObject
678 # @retVal Content: The generated section contents
680 def GenGuidSections(GuidObjList
):
682 # generate [Guids] section
686 for Guid
in GuidObjList
:
687 HelpTextList
= Guid
.GetHelpTextList()
688 HelpStr
= _GetHelpStr(HelpTextList
)
689 CName
= Guid
.GetCName()
690 FFE
= Guid
.GetFeatureFlag()
693 Statement
+= '|' + FFE
694 Usage
= Guid
.GetUsage()
695 GuidType
= Guid
.GetGuidTypeList()[0]
696 VariableName
= Guid
.GetVariableName()
698 # Differentiate the generic comment and usage comment as multiple generic comment need to be put at first
700 if Usage
== DT
.ITEM_UNDEFINED
and GuidType
== DT
.ITEM_UNDEFINED
:
701 # generate list of generic comment
702 Comment
= GenGenericCommentF(HelpStr
)
704 # generate list of other comment
705 Comment
= HelpStr
.replace('\n', ' ')
706 Comment
= Comment
.strip()
708 Comment
= ' # ' + Comment
711 if Usage
!= DT
.ITEM_UNDEFINED
and GuidType
== DT
.ITEM_UNDEFINED
:
712 Comment
= '## ' + Usage
+ Comment
713 elif GuidType
== 'Variable':
714 Comment
= '## ' + Usage
+ ' ## ' + GuidType
+ ':' + VariableName
+ Comment
716 Comment
= '## ' + Usage
+ ' ## ' + GuidType
+ Comment
721 # merge duplicate items
723 ArchList
= Guid
.GetSupArchList()
725 SortedArch
= ' '.join(ArchList
)
726 if (Statement
, SortedArch
) in GuidDict
:
727 PreviousComment
= GuidDict
[Statement
, SortedArch
]
728 Comment
= PreviousComment
+ Comment
729 GuidDict
[Statement
, SortedArch
] = Comment
730 NewSectionDict
= GenMetaFileMisc
.TransferDict(GuidDict
, 'INF_GUID')
732 # generate the section contents
735 Content
= GenSection('Guids', NewSectionDict
)
739 ## GenProtocolPPiSections
741 # @param ObjList: List of ProtocolObject or Ppi Object
742 # @retVal Content: The generated section contents
744 def GenProtocolPPiSections(ObjList
, IsProtocol
):
747 for Object
in ObjList
:
748 HelpTextList
= Object
.GetHelpTextList()
749 HelpStr
= _GetHelpStr(HelpTextList
)
750 CName
= Object
.GetCName()
751 FFE
= Object
.GetFeatureFlag()
754 Statement
+= '|' + FFE
755 Usage
= Object
.GetUsage()
756 Notify
= Object
.GetNotify()
758 # Differentiate the generic comment and usage comment as consecutive generic comment need to be put together
760 if Usage
== DT
.ITEM_UNDEFINED
and Notify
== '':
761 # generate list of generic comment
762 Comment
= GenGenericCommentF(HelpStr
)
764 # generate list of other comment
765 Comment
= HelpStr
.replace('\n', ' ')
766 Comment
= Comment
.strip()
768 Comment
= ' # ' + Comment
771 if Usage
== DT
.ITEM_UNDEFINED
and not Comment
and Notify
== '':
775 Comment
= '## ' + Usage
+ ' ## ' + 'NOTIFY' + Comment
777 Comment
= '## ' + Usage
+ Comment
781 # merge duplicate items
783 ArchList
= Object
.GetSupArchList()
785 SortedArch
= ' '.join(ArchList
)
786 if (Statement
, SortedArch
) in Dict
:
787 PreviousComment
= Dict
[Statement
, SortedArch
]
788 Comment
= PreviousComment
+ Comment
789 Dict
[Statement
, SortedArch
] = Comment
790 NewSectionDict
= GenMetaFileMisc
.TransferDict(Dict
, 'INF_PPI_PROTOCOL')
792 # generate the section contents
796 Content
= GenSection('Protocols', NewSectionDict
)
798 Content
= GenSection('Ppis', NewSectionDict
)
805 def GenPcdSections(ModuleObject
):
807 if not GlobalData
.gIS_BINARY_INF
:
809 # for each Pcd Itemtype, maintain a dict so the same type will be grouped
813 for Pcd
in ModuleObject
.GetPcdList():
814 HelpTextList
= Pcd
.GetHelpTextList()
815 HelpStr
= _GetHelpStr(HelpTextList
)
817 CName
= Pcd
.GetCName()
818 TokenSpaceGuidCName
= Pcd
.GetTokenSpaceGuidCName()
819 DefaultValue
= Pcd
.GetDefaultValue()
820 ItemType
= Pcd
.GetItemType()
821 if ItemType
in ItemTypeDict
:
822 Dict
= ItemTypeDict
[ItemType
]
825 ItemTypeDict
[ItemType
] = Dict
826 FFE
= Pcd
.GetFeatureFlag()
827 Statement
+= TokenSpaceGuidCName
+ '.' + CName
829 Statement
+= '|' + DefaultValue
831 Statement
+= '|' + FFE
833 Statement
+= '||' + FFE
837 Usage
= Pcd
.GetValidUsage()
838 # if FeatureFlag Pcd, then assume all Usage is CONSUMES
839 if ItemType
== DT
.TAB_INF_FEATURE_PCD
:
840 Usage
= DT
.USAGE_ITEM_CONSUMES
841 if Usage
== DT
.ITEM_UNDEFINED
:
842 # generate list of generic comment
843 Comment
= GenGenericCommentF(HelpStr
)
845 # generate list of other comment
846 Comment
= HelpStr
.replace('\n', ' ')
847 Comment
= Comment
.strip()
849 Comment
= ' # ' + Comment
852 Comment
= '## ' + Usage
+ Comment
856 # Merge duplicate entries
858 ArchList
= Pcd
.GetSupArchList()
860 SortedArch
= ' '.join(ArchList
)
861 if (Statement
, SortedArch
) in Dict
:
862 PreviousComment
= Dict
[Statement
, SortedArch
]
863 Comment
= PreviousComment
+ Comment
864 Dict
[Statement
, SortedArch
] = Comment
865 for ItemType
in ItemTypeDict
:
866 # First we need to transfer the Dict to use SortedArch as key
867 Dict
= ItemTypeDict
[ItemType
]
868 NewSectionDict
= GenMetaFileMisc
.TransferDict(Dict
, 'INF_PCD')
870 Content
+= GenSection(ItemType
, NewSectionDict
)
872 # For AsBuild INF files
875 Content
+= GenAsBuiltPacthPcdSections(ModuleObject
)
876 Content
+= GenAsBuiltPcdExSections(ModuleObject
)
883 def GenAsBuiltPacthPcdSections(ModuleObject
):
885 for BinaryFile
in ModuleObject
.GetBinaryFileList():
886 if not BinaryFile
.AsBuiltList
:
888 for PatchPcd
in BinaryFile
.AsBuiltList
[0].PatchPcdList
:
890 PcdCName
= PatchPcd
.CName
891 PcdValue
= PatchPcd
.DefaultValue
892 PcdOffset
= PatchPcd
.Offset
893 TokenSpaceGuidValue
= PatchPcd
.TokenSpaceGuidValue
894 Token
= PatchPcd
.Token
895 HelpTextList
= PatchPcd
.HelpTextList
897 for HelpStringItem
in HelpTextList
:
898 for HelpLine
in GetSplitValueList(HelpStringItem
.String
, '\n'):
899 HelpString
+= '## ' + HelpLine
+ '\n'
900 TokenSpaceName
, PcdCName
= GenMetaFileMisc
.ObtainPcdName(ModuleObject
.PackageDependencyList
,
903 if TokenSpaceName
== '' or PcdCName
== '':
905 ToolError
.RESOURCE_NOT_AVAILABLE
,
906 ST
.ERR_INSTALL_FILE_DEC_FILE_ERROR
% (TokenSpaceGuidValue
, Token
),
907 File
=ModuleObject
.GetFullPath())
908 Statement
= HelpString
+ TokenSpaceName
+ '.' + PcdCName
+ ' | ' + PcdValue
+ ' | ' + \
909 PcdOffset
+ DT
.TAB_SPACE_SPLIT
911 # Use binary file's Arch to be Pcd's Arch
914 FileNameObjList
= BinaryFile
.GetFileNameList()
916 ArchList
= FileNameObjList
[0].GetSupArchList()
917 if len(ArchList
) == 0:
918 if PatchPcdDict
.has_key(DT
.TAB_ARCH_COMMON
):
919 if Statement
not in PatchPcdDict
[DT
.TAB_ARCH_COMMON
]:
920 PatchPcdDict
[DT
.TAB_ARCH_COMMON
].append(Statement
)
922 PatchPcdDict
[DT
.TAB_ARCH_COMMON
] = [Statement
]
924 for Arch
in ArchList
:
925 if PatchPcdDict
.has_key(Arch
):
926 if Statement
not in PatchPcdDict
[Arch
]:
927 PatchPcdDict
[Arch
].append(Statement
)
929 PatchPcdDict
[Arch
] = [Statement
]
930 return GenSection(DT
.TAB_INF_PATCH_PCD
, PatchPcdDict
)
934 def GenAsBuiltPcdExSections(ModuleObject
):
936 for BinaryFile
in ModuleObject
.GetBinaryFileList():
937 if not BinaryFile
.AsBuiltList
:
939 for PcdExItem
in BinaryFile
.AsBuiltList
[0].PcdExValueList
:
941 PcdCName
= PcdExItem
.CName
942 TokenSpaceGuidValue
= PcdExItem
.TokenSpaceGuidValue
943 Token
= PcdExItem
.Token
944 HelpTextList
= PcdExItem
.HelpTextList
946 for HelpStringItem
in HelpTextList
:
947 for HelpLine
in GetSplitValueList(HelpStringItem
.String
, '\n'):
948 HelpString
+= '## ' + HelpLine
+ '\n'
949 TokenSpaceName
, PcdCName
= GenMetaFileMisc
.ObtainPcdName(ModuleObject
.PackageDependencyList
,
950 TokenSpaceGuidValue
, Token
)
951 if TokenSpaceName
== '' or PcdCName
== '':
953 ToolError
.RESOURCE_NOT_AVAILABLE
,
954 ST
.ERR_INSTALL_FILE_DEC_FILE_ERROR
% (TokenSpaceGuidValue
, Token
),
955 File
=ModuleObject
.GetFullPath())
957 Statement
= HelpString
+ TokenSpaceName
+ DT
.TAB_SPLIT
+ PcdCName
+ DT
.TAB_SPACE_SPLIT
960 # Use binary file's Arch to be Pcd's Arch
963 FileNameObjList
= BinaryFile
.GetFileNameList()
965 ArchList
= FileNameObjList
[0].GetSupArchList()
967 if len(ArchList
) == 0:
968 if PcdExDict
.has_key('COMMON'):
969 PcdExDict
['COMMON'].append(Statement
)
971 PcdExDict
['COMMON'] = [Statement
]
973 for Arch
in ArchList
:
974 if PcdExDict
.has_key(Arch
):
975 if Statement
not in PcdExDict
[Arch
]:
976 PcdExDict
[Arch
].append(Statement
)
978 PcdExDict
[Arch
] = [Statement
]
979 return GenSection('PcdEx', PcdExDict
)
981 ## GenSpecialSections
982 # generate special sections for Event/BootMode/Hob
984 def GenSpecialSections(ObjectList
, SectionName
, UserExtensionsContent
=''):
990 for Obj
in ObjectList
:
995 HelpTextList
= Obj
.GetHelpTextList()
996 HelpStr
= _GetHelpStr(HelpTextList
)
997 CommentStr
= GenGenericCommentF(HelpStr
)
998 if SectionName
== 'Hob':
999 Type
= Obj
.GetHobType()
1000 elif SectionName
== 'Event':
1001 Type
= Obj
.GetEventType()
1002 elif SectionName
== 'BootMode':
1003 Type
= Obj
.GetSupportedBootModes()
1006 Usage
= Obj
.GetUsage()
1008 # If the content already in UserExtensionsContent then ignore
1009 if '[%s]' % SectionName
in UserExtensionsContent
and Type
in UserExtensionsContent
:
1012 Statement
= ' ' + Type
+ ' ## ' + Usage
1013 if CommentStr
in ['#\n', '#\n#\n']:
1014 CommentStr
= '#\n#\n#\n'
1016 # the first head comment line should start with '##\n', if it starts with '#\n', then add one '#'
1017 # else add '##\n' to meet the format defined in INF spec
1019 if CommentStr
.startswith('#\n'):
1020 CommentStr
= '#' + CommentStr
1022 CommentStr
= '##\n' + CommentStr
1023 if CommentStr
and not CommentStr
.endswith('\n#\n'):
1024 CommentStr
= CommentStr
+ '#\n'
1025 NewStateMent
= CommentStr
+ Statement
1026 SupArch
= Obj
.GetSupArchList()
1028 SortedArch
= ' '.join(SupArch
)
1029 if SortedArch
in NewSectionDict
:
1030 NewSectionDict
[SortedArch
] = NewSectionDict
[SortedArch
] + [NewStateMent
]
1032 NewSectionDict
[SortedArch
] = [NewStateMent
]
1033 SectionContent
= GenSection(SectionName
, NewSectionDict
)
1034 SectionContent
= SectionContent
.strip()
1036 Content
= '# ' + ('\n' + '# ').join(GetSplitValueList(SectionContent
, '\n'))
1037 Content
= Content
.lstrip()
1039 # add a return to differentiate it between other possible sections
1047 def GenBuildOptions(ModuleObject
):
1049 if not ModuleObject
.BinaryModule
:
1051 # generate [BuildOptions] section
1054 for UserExtension
in ModuleObject
.GetUserExtensionList():
1055 BuildOptionDict
= UserExtension
.GetBuildOptionDict()
1056 if not BuildOptionDict
:
1058 for Arch
in BuildOptionDict
:
1059 if Arch
in NewSectionDict
:
1060 NewSectionDict
[Arch
] = NewSectionDict
[Arch
] + [BuildOptionDict
[Arch
]]
1062 NewSectionDict
[Arch
] = [BuildOptionDict
[Arch
]]
1063 Content
= GenSection('BuildOptions', NewSectionDict
)
1065 BuildOptionDict
= {}
1066 for BinaryFile
in ModuleObject
.GetBinaryFileList():
1067 if not BinaryFile
.AsBuiltList
:
1069 for BuilOptionItem
in BinaryFile
.AsBuiltList
[0].BinaryBuildFlagList
:
1070 Statement
= '#' + BuilOptionItem
.AsBuiltOptionFlags
1071 if len(BinaryFile
.SupArchList
) == 0:
1072 if BuildOptionDict
.has_key('COMMON'):
1073 if Statement
not in BuildOptionDict
['COMMON']:
1074 BuildOptionDict
['COMMON'].append(Statement
)
1076 BuildOptionDict
['COMMON'] = ['## @AsBuilt']
1077 BuildOptionDict
['COMMON'].append(Statement
)
1079 for Arch
in BinaryFile
.SupArchList
:
1080 if BuildOptionDict
.has_key(Arch
):
1081 if Statement
not in BuildOptionDict
[Arch
]:
1082 BuildOptionDict
[Arch
].append(Statement
)
1084 BuildOptionDict
[Arch
] = ['## @AsBuilt']
1085 BuildOptionDict
[Arch
].append(Statement
)
1086 Content
= GenSection('BuildOptions', BuildOptionDict
)
1092 def GenBinaries(ModuleObject
):
1095 for UserExtension
in ModuleObject
.GetUserExtensionList():
1096 BinariesDict
= UserExtension
.GetBinariesDict()
1099 for BinaryFile
in ModuleObject
.GetBinaryFileList():
1100 FileNameObjList
= BinaryFile
.GetFileNameList()
1101 for FileNameObj
in FileNameObjList
:
1102 FileName
= ConvertPath(FileNameObj
.GetFilename())
1103 FileType
= FileNameObj
.GetFileType()
1104 FFE
= FileNameObj
.GetFeatureFlag()
1105 ArchList
= FileNameObj
.GetSupArchList()
1107 SortedArch
= ' '.join(ArchList
)
1108 Key
= (FileName
, FileType
, FFE
, SortedArch
)
1109 if Key
in BinariesDict
:
1110 ValueList
= BinariesDict
[Key
]
1111 for ValueItem
in ValueList
:
1112 Statement
= GenBinaryStatement(Key
, ValueItem
)
1113 if SortedArch
in NewSectionDict
:
1114 NewSectionDict
[SortedArch
] = NewSectionDict
[SortedArch
] + [Statement
]
1116 NewSectionDict
[SortedArch
] = [Statement
]
1118 # as we already generated statement for this DictKey here set the Valuelist to be empty
1119 # to avoid generate duplicate entries as the DictKey may have multiple entries
1121 BinariesDict
[Key
] = []
1123 if FileType
== 'SUBTYPE_GUID' and FileNameObj
.GetGuidValue():
1124 Statement
= GenBinaryStatement(Key
, None, FileNameObj
.GetGuidValue())
1126 Statement
= GenBinaryStatement(Key
, None)
1127 if SortedArch
in NewSectionDict
:
1128 NewSectionDict
[SortedArch
] = NewSectionDict
[SortedArch
] + [Statement
]
1130 NewSectionDict
[SortedArch
] = [Statement
]
1131 Content
= GenSection('Binaries', NewSectionDict
)