1 ## @file InfPomAlignmentMisc.py
2 # This file contained the routines for InfPomAlignment
4 # Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
6 # This program and the accompanying materials are licensed and made available
7 # under the terms and conditions of the BSD License which accompanies this
8 # distribution. The full text of the license may be found at
9 # http://opensource.org/licenses/bsd-license.php
11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
22 import Logger
.Log
as Logger
23 from Library
import DataType
as DT
24 from Library
.Misc
import ConvertArchList
25 from Object
.POM
.ModuleObject
import BinaryFileObject
26 from Object
.POM
import CommonObject
28 ## GenModuleHeaderUserExt
31 def GenModuleHeaderUserExt(DefineObj
, ArchString
):
33 EdkReleaseVersion
= DefineObj
.GetEdkReleaseVersion()
34 Shadow
= DefineObj
.GetShadow()
35 DpxSource
= DefineObj
.GetDpxSource()
36 PciVendorId
= DefineObj
.GetPciVendorId()
37 PciDeviceId
= DefineObj
.GetPciDeviceId()
38 PciClassCode
= DefineObj
.GetPciClassCode()
39 PciRevision
= DefineObj
.GetPciRevision()
40 PciCompress
= DefineObj
.GetPciCompress()
41 CustomMakefile
= DefineObj
.GetCustomMakefile()
42 UefiHiiResourceSection
= DefineObj
.GetUefiHiiResourceSection()
44 if EdkReleaseVersion
!= None:
45 Name
= DT
.TAB_INF_DEFINES_EDK_RELEASE_VERSION
46 Value
= EdkReleaseVersion
.GetValue()
47 Statement
= _GenInfDefineStateMent(EdkReleaseVersion
.Comments
.GetHeaderComments(),
50 EdkReleaseVersion
.Comments
.GetTailComments())
51 DefinesDictNew
[Statement
] = ArchString
54 Name
= DT
.TAB_INF_DEFINES_SHADOW
55 Value
= Shadow
.GetValue()
56 Statement
= _GenInfDefineStateMent(Shadow
.Comments
.GetHeaderComments(),
59 Shadow
.Comments
.GetTailComments())
60 DefinesDictNew
[Statement
] = ArchString
63 Name
= DT
.TAB_INF_DEFINES_DPX_SOURCE
64 for DpxSourceItem
in DpxSource
:
65 Value
= DpxSourceItem
[0]
66 Statement
= _GenInfDefineStateMent(DpxSourceItem
[1].GetHeaderComments(),
69 DpxSourceItem
[1].GetTailComments())
70 DefinesDictNew
[Statement
] = ArchString
72 if PciVendorId
!= None:
73 Name
= DT
.TAB_INF_DEFINES_PCI_VENDOR_ID
74 Value
= PciVendorId
.GetValue()
75 Statement
= _GenInfDefineStateMent(PciVendorId
.Comments
.GetHeaderComments(),
78 PciVendorId
.Comments
.GetTailComments())
79 DefinesDictNew
[Statement
] = ArchString
81 if PciDeviceId
!= None:
82 Name
= DT
.TAB_INF_DEFINES_PCI_DEVICE_ID
83 Value
= PciDeviceId
.GetValue()
84 Statement
= _GenInfDefineStateMent(PciDeviceId
.Comments
.GetHeaderComments(),
87 PciDeviceId
.Comments
.GetTailComments())
88 DefinesDictNew
[Statement
] = ArchString
90 if PciClassCode
!= None:
91 Name
= DT
.TAB_INF_DEFINES_PCI_CLASS_CODE
92 Value
= PciClassCode
.GetValue()
93 Statement
= _GenInfDefineStateMent(PciClassCode
.Comments
.GetHeaderComments(),
96 PciClassCode
.Comments
.GetTailComments())
97 DefinesDictNew
[Statement
] = ArchString
99 if PciRevision
!= None:
100 Name
= DT
.TAB_INF_DEFINES_PCI_REVISION
101 Value
= PciRevision
.GetValue()
102 Statement
= _GenInfDefineStateMent(PciRevision
.Comments
.GetHeaderComments(),
105 PciRevision
.Comments
.GetTailComments())
106 DefinesDictNew
[Statement
] = ArchString
108 if PciCompress
!= None:
109 Name
= DT
.TAB_INF_DEFINES_PCI_COMPRESS
110 Value
= PciCompress
.GetValue()
111 Statement
= _GenInfDefineStateMent(PciCompress
.Comments
.GetHeaderComments(),
114 PciCompress
.Comments
.GetTailComments())
115 DefinesDictNew
[Statement
] = ArchString
117 if len(CustomMakefile
) >= 1:
118 for CustomMakefileItem
in CustomMakefile
:
119 Name
= DT
.TAB_INF_DEFINES_CUSTOM_MAKEFILE
121 # Not with Feature Flag Expression
123 if len(CustomMakefileItem
) == 3:
124 if CustomMakefileItem
[0] != '':
125 Value
= CustomMakefileItem
[0] + ' | ' + CustomMakefileItem
[1]
127 Value
= CustomMakefileItem
[1]
129 Comments
= CustomMakefileItem
[2]
130 Statement
= _GenInfDefineStateMent(Comments
.GetHeaderComments(),
133 Comments
.GetTailComments())
135 DefinesDictNew
[Statement
] = ArchString
137 if UefiHiiResourceSection
!= None:
138 Name
= DT
.TAB_INF_DEFINES_UEFI_HII_RESOURCE_SECTION
139 Value
= UefiHiiResourceSection
.GetValue()
140 HeaderComment
= UefiHiiResourceSection
.Comments
.GetHeaderComments()
141 TailComment
= UefiHiiResourceSection
.Comments
.GetTailComments()
142 Statement
= _GenInfDefineStateMent(HeaderComment
,
146 DefinesDictNew
[Statement
] = ""
148 return DefinesDictNew
151 ## Generate the define statement that will be put into userextension
152 # Not support comments.
154 # @param HeaderComment: the original header comment (# not remvoed)
155 # @param Name: the definition keyword, should not be empty or none
156 # @param Value: the definition keyword value
157 # @param TailComment: the original Tail comment (# not remvoed)
159 # @return: the regenerated define statement
161 def _GenInfDefineStateMent(HeaderComment
, Name
, Value
, TailComment
):
162 Logger
.Debug(5, HeaderComment
+ TailComment
)
163 Statement
= '%s = %s' % (Name
, Value
)
170 def GenBinaryData(BinaryData
, BinaryObj
, BinariesDict
, AsBuildIns
, BinaryFileObjectList
, SupArchList
, BinaryModule
):
173 OriSupArchList
= SupArchList
174 for Item
in BinaryData
:
175 ItemObj
= BinaryObj
[Item
][0][0]
176 if ItemObj
.GetType() not in DT
.BINARY_FILE_TYPE_UI_LIST
+ DT
.BINARY_FILE_TYPE_VER_LIST
:
177 TagName
= ItemObj
.GetTagName()
178 Family
= ItemObj
.GetFamily()
182 FFE
= ItemObj
.GetFeatureFlagExp()
185 # If have architecturie specified, then use the specified architecturie;
186 # If the section tag does not have an architecture modifier or the modifier is "common" (case in-sensitive),
187 # and the VALID_ARCHITECTURES comment exists, the list from the VALID_ARCHITECTURES comment
188 # can be used for the attribute.
189 # If both not have VALID_ARCHITECTURE comment and no architecturie specified, then keep it empty.
191 SupArchList
= ConvertArchList(ItemObj
.GetSupArchList())
193 if len(SupArchList
) == 1 and SupArchList
[0] == 'COMMON':
194 if not (len(OriSupArchList
) == 1 or OriSupArchList
[0] == 'COMMON'):
195 SupArchList
= OriSupArchList
197 SupArchList
= ['COMMON']
199 FileNameObj
= CommonObject
.FileNameObject()
200 FileNameObj
.SetFileType(ItemObj
.GetType())
201 FileNameObj
.SetFilename(ItemObj
.GetFileName())
202 FileNameObj
.SetFeatureFlag(FFE
)
203 FileNameObj
.SetSupArchList(SupArchList
)
204 FileNameList
= [FileNameObj
]
206 BinaryFile
= BinaryFileObject()
207 BinaryFile
.SetFileNameList(FileNameList
)
208 BinaryFile
.SetAsBuiltList(AsBuildIns
)
209 BinaryFileObjectList
.append(BinaryFile
)
211 SupArchStr
= ' '.join(SupArchList
)
212 Key
= (ItemObj
.GetFileName(), ItemObj
.GetType(), FFE
, SupArchStr
)
213 ValueItem
= (ItemObj
.GetTarget(), Family
, TagName
, '')
214 if Key
in BinariesDict
:
215 ValueList
= BinariesDict
[Key
]
216 ValueList
.append(ValueItem
)
217 BinariesDict
[Key
] = ValueList
219 BinariesDict
[Key
] = [ValueItem
]
221 return BinariesDict
, AsBuildIns
, BinaryFileObjectList