]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/UPT/PomAdapter/InfPomAlignmentMisc.py
BaseTools: Fix old python2 idioms
[mirror_edk2.git] / BaseTools / Source / Python / UPT / PomAdapter / InfPomAlignmentMisc.py
1 ## @file InfPomAlignmentMisc.py
2 # This file contained the routines for InfPomAlignment
3 #
4 # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
5 #
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
10 #
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.
13 #
14
15 '''
16 InfPomAlignmentMisc
17 '''
18
19 ##
20 # Import modules
21 #
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
30
31
32 ## GenModuleHeaderUserExt
33 #
34 #
35 def GenModuleHeaderUserExt(DefineObj, ArchString):
36 DefinesDictNew = {}
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()
47
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(),
52 Name,
53 Value,
54 EdkReleaseVersion.Comments.GetTailComments())
55 DefinesDictNew[Statement] = ArchString
56
57 if Shadow is not None:
58 Name = DT.TAB_INF_DEFINES_SHADOW
59 Value = Shadow.GetValue()
60 Statement = _GenInfDefineStateMent(Shadow.Comments.GetHeaderComments(),
61 Name,
62 Value,
63 Shadow.Comments.GetTailComments())
64 DefinesDictNew[Statement] = ArchString
65
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(),
71 Name,
72 Value,
73 DpxSourceItem[1].GetTailComments())
74 DefinesDictNew[Statement] = ArchString
75
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(),
80 Name,
81 Value,
82 PciVendorId.Comments.GetTailComments())
83 DefinesDictNew[Statement] = ArchString
84
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(),
89 Name,
90 Value,
91 PciDeviceId.Comments.GetTailComments())
92 DefinesDictNew[Statement] = ArchString
93
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(),
98 Name,
99 Value,
100 PciClassCode.Comments.GetTailComments())
101 DefinesDictNew[Statement] = ArchString
102
103 if PciRevision is not None:
104 Name = DT.TAB_INF_DEFINES_PCI_REVISION
105 Value = PciRevision.GetValue()
106 Statement = _GenInfDefineStateMent(PciRevision.Comments.GetHeaderComments(),
107 Name,
108 Value,
109 PciRevision.Comments.GetTailComments())
110 DefinesDictNew[Statement] = ArchString
111
112 if PciCompress is not None:
113 Name = DT.TAB_INF_DEFINES_PCI_COMPRESS
114 Value = PciCompress.GetValue()
115 Statement = _GenInfDefineStateMent(PciCompress.Comments.GetHeaderComments(),
116 Name,
117 Value,
118 PciCompress.Comments.GetTailComments())
119 DefinesDictNew[Statement] = ArchString
120
121 if len(CustomMakefile) >= 1:
122 for CustomMakefileItem in CustomMakefile:
123 Name = DT.TAB_INF_DEFINES_CUSTOM_MAKEFILE
124 #
125 # Not with Feature Flag Expression
126 #
127 if len(CustomMakefileItem) == 3:
128 if CustomMakefileItem[0] != '':
129 Value = CustomMakefileItem[0] + ' | ' + CustomMakefileItem[1]
130 else:
131 Value = CustomMakefileItem[1]
132
133 Comments = CustomMakefileItem[2]
134 Statement = _GenInfDefineStateMent(Comments.GetHeaderComments(),
135 Name,
136 Value,
137 Comments.GetTailComments())
138
139 DefinesDictNew[Statement] = ArchString
140
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,
147 Name,
148 Value,
149 TailComment)
150 DefinesDictNew[Statement] = ""
151
152 return DefinesDictNew
153
154
155 ## Generate the define statement that will be put into userextension
156 # Not support comments.
157 #
158 # @param HeaderComment: the original header comment (# not remvoed)
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 remvoed)
162 #
163 # @return: the regenerated define statement
164 #
165 def _GenInfDefineStateMent(HeaderComment, Name, Value, TailComment):
166 Logger.Debug(5, HeaderComment + TailComment)
167 Statement = '%s = %s' % (Name, Value)
168
169 return Statement
170
171 ## GenBinaryData
172 #
173 #
174 def GenBinaryData(BinaryData, BinaryObj, BinariesDict, AsBuildIns, BinaryFileObjectList, \
175 SupArchList, BinaryModule, DecObjList=None):
176 if BinaryModule:
177 pass
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()
184 else:
185 TagName = ''
186 Family = ''
187
188 FFE = ItemObj.GetFeatureFlagExp()
189
190 #
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.
196 #
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
201 else:
202 SupArchList = ['COMMON']
203
204 FileNameObj = CommonObject.FileNameObject()
205 FileNameObj.SetFileType(ItemObj.GetType())
206 FileNameObj.SetFilename(ItemObj.GetFileName())
207 FileNameObj.SetFeatureFlag(FFE)
208 #
209 # Get GUID value of the GUID CName in the DEC file
210 #
211 if ItemObj.GetType() == DT.SUBTYPE_GUID_BINARY_FILE_TYPE:
212 if not CheckGuidRegFormat(ItemObj.GetGuidValue()):
213 if not DecObjList:
214 if DT.TAB_HORIZON_LINE_SPLIT in ItemObj.GetGuidValue() or \
215 DT.TAB_COMMA_SPLIT in ItemObj.GetGuidValue():
216 Logger.Error("\nMkPkg",
217 FORMAT_INVALID,
218 ST.ERR_DECPARSE_DEFINE_PKGGUID,
219 ExtraData=ItemObj.GetGuidValue(),
220 RaiseError=True)
221 else:
222 Logger.Error("\nMkPkg",
223 FORMAT_INVALID,
224 ST.ERR_UNI_SUBGUID_VALUE_DEFINE_DEC_NOT_FOUND % \
225 (ItemObj.GetGuidValue()),
226 RaiseError=True)
227 else:
228 for DecObj in DecObjList:
229 for GuidObj in DecObj.GetGuidList():
230 if GuidObj.GetCName() == ItemObj.GetGuidValue():
231 FileNameObj.SetGuidValue(GuidObj.GetGuid())
232 break
233
234 if not FileNameObj.GetGuidValue():
235 Logger.Error("\nMkPkg",
236 FORMAT_INVALID,
237 ST.ERR_DECPARSE_CGUID_NOT_FOUND % \
238 (ItemObj.GetGuidValue()),
239 RaiseError=True)
240 else:
241 FileNameObj.SetGuidValue(ItemObj.GetGuidValue().strip())
242
243 FileNameObj.SetSupArchList(SupArchList)
244 FileNameList = [FileNameObj]
245
246 BinaryFile = BinaryFileObject()
247 BinaryFile.SetFileNameList(FileNameList)
248 BinaryFile.SetAsBuiltList(AsBuildIns)
249 BinaryFileObjectList.append(BinaryFile)
250
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
258 else:
259 BinariesDict[Key] = [ValueItem]
260
261 return BinariesDict, AsBuildIns, BinaryFileObjectList