]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/UPT/PomAdapter/InfPomAlignmentMisc.py
BaseTools: Remove equality operator with None
[mirror_edk2.git] / BaseTools / Source / Python / UPT / PomAdapter / InfPomAlignmentMisc.py
CommitLineData
4234283c
LG
1## @file InfPomAlignmentMisc.py\r
2# This file contained the routines for InfPomAlignment\r
3#\r
421ccda3 4# Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>\r
4234283c
LG
5#\r
6# This program and the accompanying materials are licensed and made available \r
7# under the terms and conditions of the BSD License which accompanies this \r
8# distribution. The full text of the license may be found at \r
9# http://opensource.org/licenses/bsd-license.php\r
10#\r
11# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13#\r
14\r
15'''\r
16InfPomAlignmentMisc\r
17'''\r
18\r
19##\r
20# Import modules\r
21#\r
22import Logger.Log as Logger\r
23from Library import DataType as DT\r
24from Library.Misc import ConvertArchList\r
25from Object.POM.ModuleObject import BinaryFileObject\r
26from Object.POM import CommonObject\r
421ccda3
HC
27from Library.String import FORMAT_INVALID\r
28from Library.Misc import CheckGuidRegFormat\r
29from Logger import StringTable as ST\r
30\r
4234283c
LG
31\r
32## GenModuleHeaderUserExt\r
33#\r
34#\r
35def GenModuleHeaderUserExt(DefineObj, ArchString):\r
36 DefinesDictNew = {}\r
37 EdkReleaseVersion = DefineObj.GetEdkReleaseVersion()\r
38 Shadow = DefineObj.GetShadow()\r
39 DpxSource = DefineObj.GetDpxSource()\r
40 PciVendorId = DefineObj.GetPciVendorId()\r
41 PciDeviceId = DefineObj.GetPciDeviceId()\r
42 PciClassCode = DefineObj.GetPciClassCode()\r
43 PciRevision = DefineObj.GetPciRevision()\r
44 PciCompress = DefineObj.GetPciCompress()\r
45 CustomMakefile = DefineObj.GetCustomMakefile()\r
46 UefiHiiResourceSection = DefineObj.GetUefiHiiResourceSection()\r
47\r
4231a819 48 if EdkReleaseVersion is not None:\r
4234283c
LG
49 Name = DT.TAB_INF_DEFINES_EDK_RELEASE_VERSION\r
50 Value = EdkReleaseVersion.GetValue()\r
51 Statement = _GenInfDefineStateMent(EdkReleaseVersion.Comments.GetHeaderComments(),\r
52 Name,\r
53 Value,\r
54 EdkReleaseVersion.Comments.GetTailComments())\r
55 DefinesDictNew[Statement] = ArchString\r
56\r
4231a819 57 if Shadow is not None:\r
4234283c
LG
58 Name = DT.TAB_INF_DEFINES_SHADOW\r
59 Value = Shadow.GetValue()\r
60 Statement = _GenInfDefineStateMent(Shadow.Comments.GetHeaderComments(),\r
61 Name,\r
62 Value,\r
63 Shadow.Comments.GetTailComments())\r
64 DefinesDictNew[Statement] = ArchString\r
65\r
4231a819 66 if DpxSource is not None:\r
4234283c
LG
67 Name = DT.TAB_INF_DEFINES_DPX_SOURCE\r
68 for DpxSourceItem in DpxSource:\r
69 Value = DpxSourceItem[0]\r
70 Statement = _GenInfDefineStateMent(DpxSourceItem[1].GetHeaderComments(),\r
71 Name,\r
72 Value,\r
73 DpxSourceItem[1].GetTailComments())\r
74 DefinesDictNew[Statement] = ArchString\r
75\r
4231a819 76 if PciVendorId is not None:\r
4234283c
LG
77 Name = DT.TAB_INF_DEFINES_PCI_VENDOR_ID\r
78 Value = PciVendorId.GetValue()\r
79 Statement = _GenInfDefineStateMent(PciVendorId.Comments.GetHeaderComments(),\r
80 Name,\r
81 Value,\r
82 PciVendorId.Comments.GetTailComments())\r
83 DefinesDictNew[Statement] = ArchString\r
84\r
4231a819 85 if PciDeviceId is not None:\r
4234283c
LG
86 Name = DT.TAB_INF_DEFINES_PCI_DEVICE_ID\r
87 Value = PciDeviceId.GetValue()\r
88 Statement = _GenInfDefineStateMent(PciDeviceId.Comments.GetHeaderComments(),\r
89 Name,\r
90 Value,\r
91 PciDeviceId.Comments.GetTailComments())\r
92 DefinesDictNew[Statement] = ArchString\r
93\r
4231a819 94 if PciClassCode is not None:\r
4234283c
LG
95 Name = DT.TAB_INF_DEFINES_PCI_CLASS_CODE\r
96 Value = PciClassCode.GetValue()\r
97 Statement = _GenInfDefineStateMent(PciClassCode.Comments.GetHeaderComments(),\r
98 Name,\r
99 Value,\r
100 PciClassCode.Comments.GetTailComments())\r
101 DefinesDictNew[Statement] = ArchString\r
102\r
4231a819 103 if PciRevision is not None:\r
4234283c
LG
104 Name = DT.TAB_INF_DEFINES_PCI_REVISION\r
105 Value = PciRevision.GetValue()\r
106 Statement = _GenInfDefineStateMent(PciRevision.Comments.GetHeaderComments(),\r
107 Name,\r
108 Value,\r
109 PciRevision.Comments.GetTailComments())\r
110 DefinesDictNew[Statement] = ArchString\r
111\r
4231a819 112 if PciCompress is not None:\r
4234283c
LG
113 Name = DT.TAB_INF_DEFINES_PCI_COMPRESS\r
114 Value = PciCompress.GetValue()\r
115 Statement = _GenInfDefineStateMent(PciCompress.Comments.GetHeaderComments(),\r
116 Name,\r
117 Value,\r
118 PciCompress.Comments.GetTailComments())\r
119 DefinesDictNew[Statement] = ArchString\r
120\r
121 if len(CustomMakefile) >= 1:\r
122 for CustomMakefileItem in CustomMakefile:\r
123 Name = DT.TAB_INF_DEFINES_CUSTOM_MAKEFILE\r
124 #\r
125 # Not with Feature Flag Expression\r
126 #\r
127 if len(CustomMakefileItem) == 3:\r
128 if CustomMakefileItem[0] != '':\r
129 Value = CustomMakefileItem[0] + ' | ' + CustomMakefileItem[1]\r
130 else:\r
131 Value = CustomMakefileItem[1]\r
132\r
133 Comments = CustomMakefileItem[2]\r
134 Statement = _GenInfDefineStateMent(Comments.GetHeaderComments(),\r
135 Name,\r
136 Value,\r
137 Comments.GetTailComments())\r
138\r
139 DefinesDictNew[Statement] = ArchString\r
140\r
4231a819 141 if UefiHiiResourceSection is not None:\r
4234283c
LG
142 Name = DT.TAB_INF_DEFINES_UEFI_HII_RESOURCE_SECTION\r
143 Value = UefiHiiResourceSection.GetValue()\r
144 HeaderComment = UefiHiiResourceSection.Comments.GetHeaderComments()\r
145 TailComment = UefiHiiResourceSection.Comments.GetTailComments()\r
146 Statement = _GenInfDefineStateMent(HeaderComment,\r
147 Name,\r
148 Value,\r
149 TailComment)\r
150 DefinesDictNew[Statement] = ""\r
151\r
152 return DefinesDictNew\r
153\r
154\r
155## Generate the define statement that will be put into userextension\r
156# Not support comments.\r
157#\r
158# @param HeaderComment: the original header comment (# not remvoed)\r
159# @param Name: the definition keyword, should not be empty or none\r
160# @param Value: the definition keyword value\r
161# @param TailComment: the original Tail comment (# not remvoed)\r
162#\r
163# @return: the regenerated define statement\r
164#\r
165def _GenInfDefineStateMent(HeaderComment, Name, Value, TailComment):\r
166 Logger.Debug(5, HeaderComment + TailComment)\r
167 Statement = '%s = %s' % (Name, Value)\r
168\r
169 return Statement\r
170\r
171## GenBinaryData\r
172#\r
173#\r
421ccda3
HC
174def GenBinaryData(BinaryData, BinaryObj, BinariesDict, AsBuildIns, BinaryFileObjectList, \\r
175 SupArchList, BinaryModule, DecObjList=None):\r
4234283c
LG
176 if BinaryModule:\r
177 pass\r
178 OriSupArchList = SupArchList\r
179 for Item in BinaryData:\r
180 ItemObj = BinaryObj[Item][0][0]\r
181 if ItemObj.GetType() not in DT.BINARY_FILE_TYPE_UI_LIST + DT.BINARY_FILE_TYPE_VER_LIST:\r
182 TagName = ItemObj.GetTagName()\r
183 Family = ItemObj.GetFamily()\r
184 else:\r
185 TagName = ''\r
186 Family = ''\r
421ccda3 187 \r
4234283c
LG
188 FFE = ItemObj.GetFeatureFlagExp()\r
189\r
190 #\r
191 # If have architecturie specified, then use the specified architecturie;\r
192 # If the section tag does not have an architecture modifier or the modifier is "common" (case in-sensitive),\r
193 # and the VALID_ARCHITECTURES comment exists, the list from the VALID_ARCHITECTURES comment \r
194 # can be used for the attribute.\r
195 # If both not have VALID_ARCHITECTURE comment and no architecturie specified, then keep it empty.\r
196 # \r
197 SupArchList = ConvertArchList(ItemObj.GetSupArchList())\r
198 SupArchList.sort()\r
199 if len(SupArchList) == 1 and SupArchList[0] == 'COMMON':\r
200 if not (len(OriSupArchList) == 1 or OriSupArchList[0] == 'COMMON'):\r
201 SupArchList = OriSupArchList\r
202 else:\r
203 SupArchList = ['COMMON']\r
204\r
205 FileNameObj = CommonObject.FileNameObject()\r
206 FileNameObj.SetFileType(ItemObj.GetType())\r
207 FileNameObj.SetFilename(ItemObj.GetFileName())\r
208 FileNameObj.SetFeatureFlag(FFE)\r
421ccda3
HC
209 #\r
210 # Get GUID value of the GUID CName in the DEC file\r
211 #\r
212 if ItemObj.GetType() == DT.SUBTYPE_GUID_BINARY_FILE_TYPE: \r
213 if not CheckGuidRegFormat(ItemObj.GetGuidValue()):\r
214 if not DecObjList:\r
215 if DT.TAB_HORIZON_LINE_SPLIT in ItemObj.GetGuidValue() or \\r
216 DT.TAB_COMMA_SPLIT in ItemObj.GetGuidValue():\r
217 Logger.Error("\nMkPkg",\r
218 FORMAT_INVALID,\r
219 ST.ERR_DECPARSE_DEFINE_PKGGUID,\r
220 ExtraData=ItemObj.GetGuidValue(),\r
221 RaiseError=True)\r
222 else:\r
223 Logger.Error("\nMkPkg",\r
224 FORMAT_INVALID,\r
225 ST.ERR_UNI_SUBGUID_VALUE_DEFINE_DEC_NOT_FOUND % \\r
226 (ItemObj.GetGuidValue()),\r
227 RaiseError=True)\r
228 else:\r
229 for DecObj in DecObjList:\r
230 for GuidObj in DecObj.GetGuidList():\r
231 if GuidObj.GetCName() == ItemObj.GetGuidValue():\r
232 FileNameObj.SetGuidValue(GuidObj.GetGuid())\r
233 break\r
234\r
235 if not FileNameObj.GetGuidValue(): \r
236 Logger.Error("\nMkPkg",\r
237 FORMAT_INVALID,\r
238 ST.ERR_DECPARSE_CGUID_NOT_FOUND % \\r
239 (ItemObj.GetGuidValue()),\r
240 RaiseError=True) \r
241 else:\r
242 FileNameObj.SetGuidValue(ItemObj.GetGuidValue().strip())\r
243\r
4234283c
LG
244 FileNameObj.SetSupArchList(SupArchList)\r
245 FileNameList = [FileNameObj]\r
246\r
247 BinaryFile = BinaryFileObject()\r
248 BinaryFile.SetFileNameList(FileNameList)\r
249 BinaryFile.SetAsBuiltList(AsBuildIns)\r
250 BinaryFileObjectList.append(BinaryFile)\r
251\r
252 SupArchStr = ' '.join(SupArchList)\r
253 Key = (ItemObj.GetFileName(), ItemObj.GetType(), FFE, SupArchStr)\r
254 ValueItem = (ItemObj.GetTarget(), Family, TagName, '')\r
255 if Key in BinariesDict:\r
256 ValueList = BinariesDict[Key]\r
257 ValueList.append(ValueItem)\r
258 BinariesDict[Key] = ValueList\r
259 else:\r
260 BinariesDict[Key] = [ValueItem]\r
261\r
262 return BinariesDict, AsBuildIns, BinaryFileObjectList\r