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()
573 ArchList
= UserExtension
.GetSupArchList()
574 for Index
in xrange(0, len(ArchList
)):
575 ArchList
[Index
] = ConvertArchForInstall(ArchList
[Index
])
579 if UserExtension
.GetUserID():
580 CommonPreFix
= UserExtension
.GetUserID()
581 if CommonPreFix
.find('.') > -1:
582 CommonPreFix
= '"' + CommonPreFix
+ '"'
583 if UserExtension
.GetIdentifier():
584 CommonPreFix
+= '.' + '"' + UserExtension
.GetIdentifier() + '"'
586 KeyList
= [CommonPreFix
+ '.' + Arch
for Arch
in ArchList
]
588 KeyList
= [CommonPreFix
]
590 if Key
in NewSectionDict
:
591 NewSectionDict
[Key
] = NewSectionDict
[Key
] + [Statement
]
593 NewSectionDict
[Key
] = [Statement
]
594 Content
= GenSection('UserExtensions', NewSectionDict
, False)
600 # @param SourceFile: string of source file path/name
601 # @param Family: string of source file family field
602 # @param FeatureFlag: string of source file FeatureFlag field
603 # @param TagName: string of source file TagName field
604 # @param ToolCode: string of source file ToolCode field
605 # @param HelpStr: string of source file HelpStr field
607 # @retval Statement: The generated statement for source
609 def GenSourceStatement(SourceFile
, Family
, FeatureFlag
, TagName
=None,
610 ToolCode
=None, HelpStr
=None):
613 Statement
+= GenGenericCommentF(HelpStr
)
615 # format of SourceFile|Family|TagName|ToolCode|FeatureFlag
617 Statement
+= SourceFile
625 Statement
+= '|' + Family
+ '|' + TagName
+ '|' + ToolCode
+ '|' + FeatureFlag
627 Statement
+= '|' + Family
+ '|' + TagName
+ '|' + ToolCode
629 Statement
+= '|' + Family
+ '|' + TagName
631 Statement
+= '|' + Family
636 # @param Key: (FileName, FileType, FFE, SortedArch)
637 # @param Value: (Target, Family, TagName, Comment)
640 def GenBinaryStatement(Key
, Value
, SubTypeGuidValue
=None):
641 (FileName
, FileType
, FFE
, SortedArch
) = Key
645 (Target
, Family
, TagName
, Comment
) = Value
652 Statement
= GenGenericCommentF(Comment
)
655 if FileType
== 'SUBTYPE_GUID' and SubTypeGuidValue
:
656 Statement
+= FileType
+ '|' + SubTypeGuidValue
+ '|' + FileName
658 Statement
+= FileType
+ '|' + FileName
659 if FileType
in DT
.BINARY_FILE_TYPE_UI_LIST
+ DT
.BINARY_FILE_TYPE_VER_LIST
:
661 Statement
+= '|' + Target
+ '|' + FFE
663 Statement
+= '|' + Target
666 Statement
+= '|' + Target
+ '|' + Family
+ '|' + TagName
+ '|' + FFE
668 Statement
+= '|' + Target
+ '|' + Family
+ '|' + TagName
670 Statement
+= '|' + Target
+ '|' + Family
672 Statement
+= '|' + Target
676 # @param GuidObjList: List of GuidObject
677 # @retVal Content: The generated section contents
679 def GenGuidSections(GuidObjList
):
681 # generate [Guids] section
685 for Guid
in GuidObjList
:
686 HelpTextList
= Guid
.GetHelpTextList()
687 HelpStr
= _GetHelpStr(HelpTextList
)
688 CName
= Guid
.GetCName()
689 FFE
= Guid
.GetFeatureFlag()
692 Statement
+= '|' + FFE
693 Usage
= Guid
.GetUsage()
694 GuidType
= Guid
.GetGuidTypeList()[0]
695 VariableName
= Guid
.GetVariableName()
697 # Differentiate the generic comment and usage comment as multiple generic comment need to be put at first
699 if Usage
== DT
.ITEM_UNDEFINED
and GuidType
== DT
.ITEM_UNDEFINED
:
700 # generate list of generic comment
701 Comment
= GenGenericCommentF(HelpStr
)
703 # generate list of other comment
704 Comment
= HelpStr
.replace('\n', ' ')
705 Comment
= Comment
.strip()
707 Comment
= ' # ' + Comment
710 if Usage
!= DT
.ITEM_UNDEFINED
and GuidType
== DT
.ITEM_UNDEFINED
:
711 Comment
= '## ' + Usage
+ Comment
712 elif GuidType
== 'Variable':
713 Comment
= '## ' + Usage
+ ' ## ' + GuidType
+ ':' + VariableName
+ Comment
715 Comment
= '## ' + Usage
+ ' ## ' + GuidType
+ Comment
720 # merge duplicate items
722 ArchList
= Guid
.GetSupArchList()
724 SortedArch
= ' '.join(ArchList
)
725 if (Statement
, SortedArch
) in GuidDict
:
726 PreviousComment
= GuidDict
[Statement
, SortedArch
]
727 Comment
= PreviousComment
+ Comment
728 GuidDict
[Statement
, SortedArch
] = Comment
729 NewSectionDict
= GenMetaFileMisc
.TransferDict(GuidDict
, 'INF_GUID')
731 # generate the section contents
734 Content
= GenSection('Guids', NewSectionDict
)
738 ## GenProtocolPPiSections
740 # @param ObjList: List of ProtocolObject or Ppi Object
741 # @retVal Content: The generated section contents
743 def GenProtocolPPiSections(ObjList
, IsProtocol
):
746 for Object
in ObjList
:
747 HelpTextList
= Object
.GetHelpTextList()
748 HelpStr
= _GetHelpStr(HelpTextList
)
749 CName
= Object
.GetCName()
750 FFE
= Object
.GetFeatureFlag()
753 Statement
+= '|' + FFE
754 Usage
= Object
.GetUsage()
755 Notify
= Object
.GetNotify()
757 # Differentiate the generic comment and usage comment as consecutive generic comment need to be put together
759 if Usage
== DT
.ITEM_UNDEFINED
and Notify
== '':
760 # generate list of generic comment
761 Comment
= GenGenericCommentF(HelpStr
)
763 # generate list of other comment
764 Comment
= HelpStr
.replace('\n', ' ')
765 Comment
= Comment
.strip()
767 Comment
= ' # ' + Comment
770 if Usage
== DT
.ITEM_UNDEFINED
and not Comment
and Notify
== '':
774 Comment
= '## ' + Usage
+ ' ## ' + 'NOTIFY' + Comment
776 Comment
= '## ' + Usage
+ Comment
780 # merge duplicate items
782 ArchList
= Object
.GetSupArchList()
784 SortedArch
= ' '.join(ArchList
)
785 if (Statement
, SortedArch
) in Dict
:
786 PreviousComment
= Dict
[Statement
, SortedArch
]
787 Comment
= PreviousComment
+ Comment
788 Dict
[Statement
, SortedArch
] = Comment
789 NewSectionDict
= GenMetaFileMisc
.TransferDict(Dict
, 'INF_PPI_PROTOCOL')
791 # generate the section contents
795 Content
= GenSection('Protocols', NewSectionDict
)
797 Content
= GenSection('Ppis', NewSectionDict
)
804 def GenPcdSections(ModuleObject
):
806 if not GlobalData
.gIS_BINARY_INF
:
808 # for each Pcd Itemtype, maintain a dict so the same type will be grouped
812 for Pcd
in ModuleObject
.GetPcdList():
813 HelpTextList
= Pcd
.GetHelpTextList()
814 HelpStr
= _GetHelpStr(HelpTextList
)
816 CName
= Pcd
.GetCName()
817 TokenSpaceGuidCName
= Pcd
.GetTokenSpaceGuidCName()
818 DefaultValue
= Pcd
.GetDefaultValue()
819 ItemType
= Pcd
.GetItemType()
820 if ItemType
in ItemTypeDict
:
821 Dict
= ItemTypeDict
[ItemType
]
824 ItemTypeDict
[ItemType
] = Dict
825 FFE
= Pcd
.GetFeatureFlag()
826 Statement
+= TokenSpaceGuidCName
+ '.' + CName
828 Statement
+= '|' + DefaultValue
830 Statement
+= '|' + FFE
832 Statement
+= '||' + FFE
836 Usage
= Pcd
.GetValidUsage()
837 # if FeatureFlag Pcd, then assume all Usage is CONSUMES
838 if ItemType
== DT
.TAB_INF_FEATURE_PCD
:
839 Usage
= DT
.USAGE_ITEM_CONSUMES
840 if Usage
== DT
.ITEM_UNDEFINED
:
841 # generate list of generic comment
842 Comment
= GenGenericCommentF(HelpStr
)
844 # generate list of other comment
845 Comment
= HelpStr
.replace('\n', ' ')
846 Comment
= Comment
.strip()
848 Comment
= ' # ' + Comment
851 Comment
= '## ' + Usage
+ Comment
855 # Merge duplicate entries
857 ArchList
= Pcd
.GetSupArchList()
859 SortedArch
= ' '.join(ArchList
)
860 if (Statement
, SortedArch
) in Dict
:
861 PreviousComment
= Dict
[Statement
, SortedArch
]
862 Comment
= PreviousComment
+ Comment
863 Dict
[Statement
, SortedArch
] = Comment
864 for ItemType
in ItemTypeDict
:
865 # First we need to transfer the Dict to use SortedArch as key
866 Dict
= ItemTypeDict
[ItemType
]
867 NewSectionDict
= GenMetaFileMisc
.TransferDict(Dict
, 'INF_PCD')
869 Content
+= GenSection(ItemType
, NewSectionDict
)
871 # For AsBuild INF files
874 Content
+= GenAsBuiltPacthPcdSections(ModuleObject
)
875 Content
+= GenAsBuiltPcdExSections(ModuleObject
)
882 def GenAsBuiltPacthPcdSections(ModuleObject
):
884 for BinaryFile
in ModuleObject
.GetBinaryFileList():
885 if not BinaryFile
.AsBuiltList
:
887 for PatchPcd
in BinaryFile
.AsBuiltList
[0].PatchPcdList
:
889 PcdCName
= PatchPcd
.CName
890 PcdValue
= PatchPcd
.DefaultValue
891 PcdOffset
= PatchPcd
.Offset
892 TokenSpaceGuidValue
= PatchPcd
.TokenSpaceGuidValue
893 Token
= PatchPcd
.Token
894 HelpTextList
= PatchPcd
.HelpTextList
896 for HelpStringItem
in HelpTextList
:
897 for HelpLine
in GetSplitValueList(HelpStringItem
.String
, '\n'):
898 HelpString
+= '## ' + HelpLine
+ '\n'
899 TokenSpaceName
, PcdCName
= GenMetaFileMisc
.ObtainPcdName(ModuleObject
.PackageDependencyList
,
902 if TokenSpaceName
== '' or PcdCName
== '':
904 ToolError
.RESOURCE_NOT_AVAILABLE
,
905 ST
.ERR_INSTALL_FILE_DEC_FILE_ERROR
% (TokenSpaceGuidValue
, Token
),
906 File
=ModuleObject
.GetFullPath())
907 Statement
= HelpString
+ TokenSpaceName
+ '.' + PcdCName
+ ' | ' + PcdValue
+ ' | ' + \
908 PcdOffset
+ DT
.TAB_SPACE_SPLIT
910 # Use binary file's Arch to be Pcd's Arch
913 FileNameObjList
= BinaryFile
.GetFileNameList()
915 ArchList
= FileNameObjList
[0].GetSupArchList()
916 if len(ArchList
) == 0:
917 if PatchPcdDict
.has_key(DT
.TAB_ARCH_COMMON
):
918 if Statement
not in PatchPcdDict
[DT
.TAB_ARCH_COMMON
]:
919 PatchPcdDict
[DT
.TAB_ARCH_COMMON
].append(Statement
)
921 PatchPcdDict
[DT
.TAB_ARCH_COMMON
] = [Statement
]
923 for Arch
in ArchList
:
924 if PatchPcdDict
.has_key(Arch
):
925 if Statement
not in PatchPcdDict
[Arch
]:
926 PatchPcdDict
[Arch
].append(Statement
)
928 PatchPcdDict
[Arch
] = [Statement
]
929 return GenSection(DT
.TAB_INF_PATCH_PCD
, PatchPcdDict
)
933 def GenAsBuiltPcdExSections(ModuleObject
):
935 for BinaryFile
in ModuleObject
.GetBinaryFileList():
936 if not BinaryFile
.AsBuiltList
:
938 for PcdExItem
in BinaryFile
.AsBuiltList
[0].PcdExValueList
:
940 PcdCName
= PcdExItem
.CName
941 TokenSpaceGuidValue
= PcdExItem
.TokenSpaceGuidValue
942 Token
= PcdExItem
.Token
943 HelpTextList
= PcdExItem
.HelpTextList
945 for HelpStringItem
in HelpTextList
:
946 for HelpLine
in GetSplitValueList(HelpStringItem
.String
, '\n'):
947 HelpString
+= '## ' + HelpLine
+ '\n'
948 TokenSpaceName
, PcdCName
= GenMetaFileMisc
.ObtainPcdName(ModuleObject
.PackageDependencyList
,
949 TokenSpaceGuidValue
, Token
)
950 if TokenSpaceName
== '' or PcdCName
== '':
952 ToolError
.RESOURCE_NOT_AVAILABLE
,
953 ST
.ERR_INSTALL_FILE_DEC_FILE_ERROR
% (TokenSpaceGuidValue
, Token
),
954 File
=ModuleObject
.GetFullPath())
956 Statement
= HelpString
+ TokenSpaceName
+ DT
.TAB_SPLIT
+ PcdCName
+ DT
.TAB_SPACE_SPLIT
959 # Use binary file's Arch to be Pcd's Arch
962 FileNameObjList
= BinaryFile
.GetFileNameList()
964 ArchList
= FileNameObjList
[0].GetSupArchList()
966 if len(ArchList
) == 0:
967 if PcdExDict
.has_key('COMMON'):
968 PcdExDict
['COMMON'].append(Statement
)
970 PcdExDict
['COMMON'] = [Statement
]
972 for Arch
in ArchList
:
973 if PcdExDict
.has_key(Arch
):
974 if Statement
not in PcdExDict
[Arch
]:
975 PcdExDict
[Arch
].append(Statement
)
977 PcdExDict
[Arch
] = [Statement
]
978 return GenSection('PcdEx', PcdExDict
)
980 ## GenSpecialSections
981 # generate special sections for Event/BootMode/Hob
983 def GenSpecialSections(ObjectList
, SectionName
, UserExtensionsContent
=''):
989 for Obj
in ObjectList
:
994 HelpTextList
= Obj
.GetHelpTextList()
995 HelpStr
= _GetHelpStr(HelpTextList
)
996 CommentStr
= GenGenericCommentF(HelpStr
)
997 if SectionName
== 'Hob':
998 Type
= Obj
.GetHobType()
999 elif SectionName
== 'Event':
1000 Type
= Obj
.GetEventType()
1001 elif SectionName
== 'BootMode':
1002 Type
= Obj
.GetSupportedBootModes()
1005 Usage
= Obj
.GetUsage()
1007 # If the content already in UserExtensionsContent then ignore
1008 if '[%s]' % SectionName
in UserExtensionsContent
and Type
in UserExtensionsContent
:
1011 Statement
= ' ' + Type
+ ' ## ' + Usage
1012 if CommentStr
in ['#\n', '#\n#\n']:
1013 CommentStr
= '#\n#\n#\n'
1015 # the first head comment line should start with '##\n', if it starts with '#\n', then add one '#'
1016 # else add '##\n' to meet the format defined in INF spec
1018 if CommentStr
.startswith('#\n'):
1019 CommentStr
= '#' + CommentStr
1021 CommentStr
= '##\n' + CommentStr
1022 if CommentStr
and not CommentStr
.endswith('\n#\n'):
1023 CommentStr
= CommentStr
+ '#\n'
1024 NewStateMent
= CommentStr
+ Statement
1025 SupArch
= Obj
.GetSupArchList()
1027 SortedArch
= ' '.join(SupArch
)
1028 if SortedArch
in NewSectionDict
:
1029 NewSectionDict
[SortedArch
] = NewSectionDict
[SortedArch
] + [NewStateMent
]
1031 NewSectionDict
[SortedArch
] = [NewStateMent
]
1032 SectionContent
= GenSection(SectionName
, NewSectionDict
)
1033 SectionContent
= SectionContent
.strip()
1035 Content
= '# ' + ('\n' + '# ').join(GetSplitValueList(SectionContent
, '\n'))
1036 Content
= Content
.lstrip()
1038 # add a return to differentiate it between other possible sections
1046 def GenBuildOptions(ModuleObject
):
1048 if not ModuleObject
.BinaryModule
:
1050 # generate [BuildOptions] section
1053 for UserExtension
in ModuleObject
.GetUserExtensionList():
1054 BuildOptionDict
= UserExtension
.GetBuildOptionDict()
1055 if not BuildOptionDict
:
1057 for Arch
in BuildOptionDict
:
1058 if Arch
in NewSectionDict
:
1059 NewSectionDict
[Arch
] = NewSectionDict
[Arch
] + [BuildOptionDict
[Arch
]]
1061 NewSectionDict
[Arch
] = [BuildOptionDict
[Arch
]]
1062 Content
= GenSection('BuildOptions', NewSectionDict
)
1064 BuildOptionDict
= {}
1065 for BinaryFile
in ModuleObject
.GetBinaryFileList():
1066 if not BinaryFile
.AsBuiltList
:
1068 for BuilOptionItem
in BinaryFile
.AsBuiltList
[0].BinaryBuildFlagList
:
1069 Statement
= '#' + BuilOptionItem
.AsBuiltOptionFlags
1070 if len(BinaryFile
.SupArchList
) == 0:
1071 if BuildOptionDict
.has_key('COMMON'):
1072 if Statement
not in BuildOptionDict
['COMMON']:
1073 BuildOptionDict
['COMMON'].append(Statement
)
1075 BuildOptionDict
['COMMON'] = ['## @AsBuilt']
1076 BuildOptionDict
['COMMON'].append(Statement
)
1078 for Arch
in BinaryFile
.SupArchList
:
1079 if BuildOptionDict
.has_key(Arch
):
1080 if Statement
not in BuildOptionDict
[Arch
]:
1081 BuildOptionDict
[Arch
].append(Statement
)
1083 BuildOptionDict
[Arch
] = ['## @AsBuilt']
1084 BuildOptionDict
[Arch
].append(Statement
)
1085 Content
= GenSection('BuildOptions', BuildOptionDict
)
1091 def GenBinaries(ModuleObject
):
1094 for UserExtension
in ModuleObject
.GetUserExtensionList():
1095 BinariesDict
= UserExtension
.GetBinariesDict()
1098 for BinaryFile
in ModuleObject
.GetBinaryFileList():
1099 FileNameObjList
= BinaryFile
.GetFileNameList()
1100 for FileNameObj
in FileNameObjList
:
1101 FileName
= ConvertPath(FileNameObj
.GetFilename())
1102 FileType
= FileNameObj
.GetFileType()
1103 FFE
= FileNameObj
.GetFeatureFlag()
1104 ArchList
= FileNameObj
.GetSupArchList()
1106 SortedArch
= ' '.join(ArchList
)
1107 Key
= (FileName
, FileType
, FFE
, SortedArch
)
1108 if Key
in BinariesDict
:
1109 ValueList
= BinariesDict
[Key
]
1110 for ValueItem
in ValueList
:
1111 Statement
= GenBinaryStatement(Key
, ValueItem
)
1112 if SortedArch
in NewSectionDict
:
1113 NewSectionDict
[SortedArch
] = NewSectionDict
[SortedArch
] + [Statement
]
1115 NewSectionDict
[SortedArch
] = [Statement
]
1117 # as we already generated statement for this DictKey here set the Valuelist to be empty
1118 # to avoid generate duplicate entries as the DictKey may have multiple entries
1120 BinariesDict
[Key
] = []
1122 if FileType
== 'SUBTYPE_GUID' and FileNameObj
.GetGuidValue():
1123 Statement
= GenBinaryStatement(Key
, None, FileNameObj
.GetGuidValue())
1125 Statement
= GenBinaryStatement(Key
, None)
1126 if SortedArch
in NewSectionDict
:
1127 NewSectionDict
[SortedArch
] = NewSectionDict
[SortedArch
] + [Statement
]
1129 NewSectionDict
[SortedArch
] = [Statement
]
1130 Content
= GenSection('Binaries', NewSectionDict
)