]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/UPT/PomAdapter/InfPomAlignmentMisc.py
Sync BaseTools Branch (version r2271) to EDKII main trunk.
[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, 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
28 ## GenModuleHeaderUserExt
29 #
30 #
31 def GenModuleHeaderUserExt(DefineObj, ArchString):
32 DefinesDictNew = {}
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()
43
44 if EdkReleaseVersion != None:
45 Name = DT.TAB_INF_DEFINES_EDK_RELEASE_VERSION
46 Value = EdkReleaseVersion.GetValue()
47 Statement = _GenInfDefineStateMent(EdkReleaseVersion.Comments.GetHeaderComments(),
48 Name,
49 Value,
50 EdkReleaseVersion.Comments.GetTailComments())
51 DefinesDictNew[Statement] = ArchString
52
53 if Shadow != None:
54 Name = DT.TAB_INF_DEFINES_SHADOW
55 Value = Shadow.GetValue()
56 Statement = _GenInfDefineStateMent(Shadow.Comments.GetHeaderComments(),
57 Name,
58 Value,
59 Shadow.Comments.GetTailComments())
60 DefinesDictNew[Statement] = ArchString
61
62 if DpxSource != None:
63 Name = DT.TAB_INF_DEFINES_DPX_SOURCE
64 for DpxSourceItem in DpxSource:
65 Value = DpxSourceItem[0]
66 Statement = _GenInfDefineStateMent(DpxSourceItem[1].GetHeaderComments(),
67 Name,
68 Value,
69 DpxSourceItem[1].GetTailComments())
70 DefinesDictNew[Statement] = ArchString
71
72 if PciVendorId != None:
73 Name = DT.TAB_INF_DEFINES_PCI_VENDOR_ID
74 Value = PciVendorId.GetValue()
75 Statement = _GenInfDefineStateMent(PciVendorId.Comments.GetHeaderComments(),
76 Name,
77 Value,
78 PciVendorId.Comments.GetTailComments())
79 DefinesDictNew[Statement] = ArchString
80
81 if PciDeviceId != None:
82 Name = DT.TAB_INF_DEFINES_PCI_DEVICE_ID
83 Value = PciDeviceId.GetValue()
84 Statement = _GenInfDefineStateMent(PciDeviceId.Comments.GetHeaderComments(),
85 Name,
86 Value,
87 PciDeviceId.Comments.GetTailComments())
88 DefinesDictNew[Statement] = ArchString
89
90 if PciClassCode != None:
91 Name = DT.TAB_INF_DEFINES_PCI_CLASS_CODE
92 Value = PciClassCode.GetValue()
93 Statement = _GenInfDefineStateMent(PciClassCode.Comments.GetHeaderComments(),
94 Name,
95 Value,
96 PciClassCode.Comments.GetTailComments())
97 DefinesDictNew[Statement] = ArchString
98
99 if PciRevision != None:
100 Name = DT.TAB_INF_DEFINES_PCI_REVISION
101 Value = PciRevision.GetValue()
102 Statement = _GenInfDefineStateMent(PciRevision.Comments.GetHeaderComments(),
103 Name,
104 Value,
105 PciRevision.Comments.GetTailComments())
106 DefinesDictNew[Statement] = ArchString
107
108 if PciCompress != None:
109 Name = DT.TAB_INF_DEFINES_PCI_COMPRESS
110 Value = PciCompress.GetValue()
111 Statement = _GenInfDefineStateMent(PciCompress.Comments.GetHeaderComments(),
112 Name,
113 Value,
114 PciCompress.Comments.GetTailComments())
115 DefinesDictNew[Statement] = ArchString
116
117 if len(CustomMakefile) >= 1:
118 for CustomMakefileItem in CustomMakefile:
119 Name = DT.TAB_INF_DEFINES_CUSTOM_MAKEFILE
120 #
121 # Not with Feature Flag Expression
122 #
123 if len(CustomMakefileItem) == 3:
124 if CustomMakefileItem[0] != '':
125 Value = CustomMakefileItem[0] + ' | ' + CustomMakefileItem[1]
126 else:
127 Value = CustomMakefileItem[1]
128
129 Comments = CustomMakefileItem[2]
130 Statement = _GenInfDefineStateMent(Comments.GetHeaderComments(),
131 Name,
132 Value,
133 Comments.GetTailComments())
134
135 DefinesDictNew[Statement] = ArchString
136
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,
143 Name,
144 Value,
145 TailComment)
146 DefinesDictNew[Statement] = ""
147
148 return DefinesDictNew
149
150
151 ## Generate the define statement that will be put into userextension
152 # Not support comments.
153 #
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)
158 #
159 # @return: the regenerated define statement
160 #
161 def _GenInfDefineStateMent(HeaderComment, Name, Value, TailComment):
162 Logger.Debug(5, HeaderComment + TailComment)
163 Statement = '%s = %s' % (Name, Value)
164
165 return Statement
166
167 ## GenBinaryData
168 #
169 #
170 def GenBinaryData(BinaryData, BinaryObj, BinariesDict, AsBuildIns, BinaryFileObjectList, SupArchList, BinaryModule):
171 if BinaryModule:
172 pass
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()
179 else:
180 TagName = ''
181 Family = ''
182 FFE = ItemObj.GetFeatureFlagExp()
183
184 #
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.
190 #
191 SupArchList = ConvertArchList(ItemObj.GetSupArchList())
192 SupArchList.sort()
193 if len(SupArchList) == 1 and SupArchList[0] == 'COMMON':
194 if not (len(OriSupArchList) == 1 or OriSupArchList[0] == 'COMMON'):
195 SupArchList = OriSupArchList
196 else:
197 SupArchList = ['COMMON']
198
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]
205
206 BinaryFile = BinaryFileObject()
207 BinaryFile.SetFileNameList(FileNameList)
208 BinaryFile.SetAsBuiltList(AsBuildIns)
209 BinaryFileObjectList.append(BinaryFile)
210
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
218 else:
219 BinariesDict[Key] = [ValueItem]
220
221 return BinariesDict, AsBuildIns, BinaryFileObjectList