1 ## @file InfPomAlignmentMisc.py
2 # This file contained the routines for InfPomAlignment
4 # Copyright (c) 2011 - 2018, 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
27 from Library
.StringUtils
import FORMAT_INVALID
28 from Library
.Misc
import CheckGuidRegFormat
29 from Logger
import StringTable
as ST
32 ## GenModuleHeaderUserExt
35 def GenModuleHeaderUserExt(DefineObj
, ArchString
):
37 EdkReleaseVersion
= DefineObj
.GetEdkReleaseVersion()
38 Shadow
= DefineObj
.GetShadow()
39 DpxSource
= DefineObj
.GetDpxSource()
40 PciVendorId
= DefineObj
.GetPciVendorId()
41 PciDeviceId
= DefineObj
.GetPciDeviceId()
42 PciClassCode
= DefineObj
.GetPciClassCode()
43 PciRevision
= DefineObj
.GetPciRevision()
44 PciCompress
= DefineObj
.GetPciCompress()
45 CustomMakefile
= DefineObj
.GetCustomMakefile()
46 UefiHiiResourceSection
= DefineObj
.GetUefiHiiResourceSection()
48 if EdkReleaseVersion
is not None:
49 Name
= DT
.TAB_INF_DEFINES_EDK_RELEASE_VERSION
50 Value
= EdkReleaseVersion
.GetValue()
51 Statement
= _GenInfDefineStateMent(EdkReleaseVersion
.Comments
.GetHeaderComments(),
54 EdkReleaseVersion
.Comments
.GetTailComments())
55 DefinesDictNew
[Statement
] = ArchString
57 if Shadow
is not None:
58 Name
= DT
.TAB_INF_DEFINES_SHADOW
59 Value
= Shadow
.GetValue()
60 Statement
= _GenInfDefineStateMent(Shadow
.Comments
.GetHeaderComments(),
63 Shadow
.Comments
.GetTailComments())
64 DefinesDictNew
[Statement
] = ArchString
66 if DpxSource
is not None:
67 Name
= DT
.TAB_INF_DEFINES_DPX_SOURCE
68 for DpxSourceItem
in DpxSource
:
69 Value
= DpxSourceItem
[0]
70 Statement
= _GenInfDefineStateMent(DpxSourceItem
[1].GetHeaderComments(),
73 DpxSourceItem
[1].GetTailComments())
74 DefinesDictNew
[Statement
] = ArchString
76 if PciVendorId
is not None:
77 Name
= DT
.TAB_INF_DEFINES_PCI_VENDOR_ID
78 Value
= PciVendorId
.GetValue()
79 Statement
= _GenInfDefineStateMent(PciVendorId
.Comments
.GetHeaderComments(),
82 PciVendorId
.Comments
.GetTailComments())
83 DefinesDictNew
[Statement
] = ArchString
85 if PciDeviceId
is not None:
86 Name
= DT
.TAB_INF_DEFINES_PCI_DEVICE_ID
87 Value
= PciDeviceId
.GetValue()
88 Statement
= _GenInfDefineStateMent(PciDeviceId
.Comments
.GetHeaderComments(),
91 PciDeviceId
.Comments
.GetTailComments())
92 DefinesDictNew
[Statement
] = ArchString
94 if PciClassCode
is not None:
95 Name
= DT
.TAB_INF_DEFINES_PCI_CLASS_CODE
96 Value
= PciClassCode
.GetValue()
97 Statement
= _GenInfDefineStateMent(PciClassCode
.Comments
.GetHeaderComments(),
100 PciClassCode
.Comments
.GetTailComments())
101 DefinesDictNew
[Statement
] = ArchString
103 if PciRevision
is not None:
104 Name
= DT
.TAB_INF_DEFINES_PCI_REVISION
105 Value
= PciRevision
.GetValue()
106 Statement
= _GenInfDefineStateMent(PciRevision
.Comments
.GetHeaderComments(),
109 PciRevision
.Comments
.GetTailComments())
110 DefinesDictNew
[Statement
] = ArchString
112 if PciCompress
is not None:
113 Name
= DT
.TAB_INF_DEFINES_PCI_COMPRESS
114 Value
= PciCompress
.GetValue()
115 Statement
= _GenInfDefineStateMent(PciCompress
.Comments
.GetHeaderComments(),
118 PciCompress
.Comments
.GetTailComments())
119 DefinesDictNew
[Statement
] = ArchString
121 if len(CustomMakefile
) >= 1:
122 for CustomMakefileItem
in CustomMakefile
:
123 Name
= DT
.TAB_INF_DEFINES_CUSTOM_MAKEFILE
125 # Not with Feature Flag Expression
127 if len(CustomMakefileItem
) == 3:
128 if CustomMakefileItem
[0] != '':
129 Value
= CustomMakefileItem
[0] + ' | ' + CustomMakefileItem
[1]
131 Value
= CustomMakefileItem
[1]
133 Comments
= CustomMakefileItem
[2]
134 Statement
= _GenInfDefineStateMent(Comments
.GetHeaderComments(),
137 Comments
.GetTailComments())
139 DefinesDictNew
[Statement
] = ArchString
141 if UefiHiiResourceSection
is not None:
142 Name
= DT
.TAB_INF_DEFINES_UEFI_HII_RESOURCE_SECTION
143 Value
= UefiHiiResourceSection
.GetValue()
144 HeaderComment
= UefiHiiResourceSection
.Comments
.GetHeaderComments()
145 TailComment
= UefiHiiResourceSection
.Comments
.GetTailComments()
146 Statement
= _GenInfDefineStateMent(HeaderComment
,
150 DefinesDictNew
[Statement
] = ""
152 return DefinesDictNew
155 ## Generate the define statement that will be put into userextension
156 # Not support comments.
158 # @param HeaderComment: the original header comment (# not removed)
159 # @param Name: the definition keyword, should not be empty or none
160 # @param Value: the definition keyword value
161 # @param TailComment: the original Tail comment (# not removed)
163 # @return: the regenerated define statement
165 def _GenInfDefineStateMent(HeaderComment
, Name
, Value
, TailComment
):
166 Logger
.Debug(5, HeaderComment
+ TailComment
)
167 Statement
= '%s = %s' % (Name
, Value
)
174 def GenBinaryData(BinaryData
, BinaryObj
, BinariesDict
, AsBuildIns
, BinaryFileObjectList
, \
175 SupArchList
, BinaryModule
, DecObjList
=None):
178 OriSupArchList
= SupArchList
179 for Item
in BinaryData
:
180 ItemObj
= BinaryObj
[Item
][0][0]
181 if ItemObj
.GetType() not in DT
.BINARY_FILE_TYPE_UI_LIST
+ DT
.BINARY_FILE_TYPE_VER_LIST
:
182 TagName
= ItemObj
.GetTagName()
183 Family
= ItemObj
.GetFamily()
188 FFE
= ItemObj
.GetFeatureFlagExp()
191 # If have architecturie specified, then use the specified architecturie;
192 # If the section tag does not have an architecture modifier or the modifier is "common" (case in-sensitive),
193 # and the VALID_ARCHITECTURES comment exists, the list from the VALID_ARCHITECTURES comment
194 # can be used for the attribute.
195 # If both not have VALID_ARCHITECTURE comment and no architecturie specified, then keep it empty.
197 SupArchList
= sorted(ConvertArchList(ItemObj
.GetSupArchList()))
198 if len(SupArchList
) == 1 and SupArchList
[0] == 'COMMON':
199 if not (len(OriSupArchList
) == 1 or OriSupArchList
[0] == 'COMMON'):
200 SupArchList
= OriSupArchList
202 SupArchList
= ['COMMON']
204 FileNameObj
= CommonObject
.FileNameObject()
205 FileNameObj
.SetFileType(ItemObj
.GetType())
206 FileNameObj
.SetFilename(ItemObj
.GetFileName())
207 FileNameObj
.SetFeatureFlag(FFE
)
209 # Get GUID value of the GUID CName in the DEC file
211 if ItemObj
.GetType() == DT
.SUBTYPE_GUID_BINARY_FILE_TYPE
:
212 if not CheckGuidRegFormat(ItemObj
.GetGuidValue()):
214 if DT
.TAB_HORIZON_LINE_SPLIT
in ItemObj
.GetGuidValue() or \
215 DT
.TAB_COMMA_SPLIT
in ItemObj
.GetGuidValue():
216 Logger
.Error("\nMkPkg",
218 ST
.ERR_DECPARSE_DEFINE_PKGGUID
,
219 ExtraData
=ItemObj
.GetGuidValue(),
222 Logger
.Error("\nMkPkg",
224 ST
.ERR_UNI_SUBGUID_VALUE_DEFINE_DEC_NOT_FOUND
% \
225 (ItemObj
.GetGuidValue()),
228 for DecObj
in DecObjList
:
229 for GuidObj
in DecObj
.GetGuidList():
230 if GuidObj
.GetCName() == ItemObj
.GetGuidValue():
231 FileNameObj
.SetGuidValue(GuidObj
.GetGuid())
234 if not FileNameObj
.GetGuidValue():
235 Logger
.Error("\nMkPkg",
237 ST
.ERR_DECPARSE_CGUID_NOT_FOUND
% \
238 (ItemObj
.GetGuidValue()),
241 FileNameObj
.SetGuidValue(ItemObj
.GetGuidValue().strip())
243 FileNameObj
.SetSupArchList(SupArchList
)
244 FileNameList
= [FileNameObj
]
246 BinaryFile
= BinaryFileObject()
247 BinaryFile
.SetFileNameList(FileNameList
)
248 BinaryFile
.SetAsBuiltList(AsBuildIns
)
249 BinaryFileObjectList
.append(BinaryFile
)
251 SupArchStr
= ' '.join(SupArchList
)
252 Key
= (ItemObj
.GetFileName(), ItemObj
.GetType(), FFE
, SupArchStr
)
253 ValueItem
= (ItemObj
.GetTarget(), Family
, TagName
, '')
254 if Key
in BinariesDict
:
255 ValueList
= BinariesDict
[Key
]
256 ValueList
.append(ValueItem
)
257 BinariesDict
[Key
] = ValueList
259 BinariesDict
[Key
] = [ValueItem
]
261 return BinariesDict
, AsBuildIns
, BinaryFileObjectList