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