]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Scripts/PackageDocumentTools/plugins/EdkPlugins/edk2/model/dec.py
BaseTools: Remove equality operator with None
[mirror_edk2.git] / BaseTools / Scripts / PackageDocumentTools / plugins / EdkPlugins / edk2 / model / dec.py
1 ## @file
2 #
3 # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
4 #
5 # This program and the accompanying materials are licensed and made available
6 # under the terms and conditions of the BSD License which accompanies this
7 # distribution. The full text of the license may be found at
8 # http://opensource.org/licenses/bsd-license.php
9 #
10 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 #
13
14 import plugins.EdkPlugins.basemodel.ini as ini
15 import re, os
16 from plugins.EdkPlugins.basemodel.message import *
17
18 class DECFile(ini.BaseINIFile):
19
20 def GetSectionInstance(self, parent, name, isCombined=False):
21 return DECSection(parent, name, isCombined)
22
23 def GetComponents(self):
24 return self.GetSectionByName('Components')
25
26 def GetPackageRootPath(self):
27 return os.path.dirname(self.GetFilename()).strip()
28
29 def GetBaseName(self):
30 return self.GetDefine("PACKAGE_NAME").strip()
31
32 def GetVersion(self):
33 return self.GetDefine("PACKAGE_VERSION").strip()
34
35 def GetSectionObjectsByName(self, name, arch=None):
36 arr = []
37 sects = self.GetSectionByName(name)
38 for sect in sects:
39 # skip unmatched archtecture content
40 if not sect.IsArchMatch(arch):
41 continue
42
43 for obj in sect.GetObjects():
44 arr.append(obj)
45
46 return arr
47
48 class DECSection(ini.BaseINISection):
49 def GetSectionINIObject(self, parent):
50 type = self.GetType()
51
52 if type.lower().find('defines') != -1:
53 return DECDefineSectionObject(self)
54 if type.lower().find('includes') != -1:
55 return DECIncludeObject(self)
56 if type.lower().find('pcd') != -1:
57 return DECPcdObject(self)
58 if type.lower() == 'libraryclasses':
59 return DECLibraryClassObject(self)
60 if type.lower() == 'guids':
61 return DECGuidObject(self)
62 if type.lower() == 'ppis':
63 return DECPpiObject(self)
64 if type.lower() == 'protocols':
65 return DECProtocolObject(self)
66
67 return DECSectionObject(self)
68
69 def GetType(self):
70 arr = self._name.split('.')
71 return arr[0].strip()
72
73 def GetArch(self):
74 arr = self._name.split('.')
75 if len(arr) == 1:
76 return 'common'
77 return arr[1]
78
79 def IsArchMatch(self, arch):
80 if arch is None or self.GetArch() == 'common':
81 return True
82
83 if self.GetArch().lower() != arch.lower():
84 return False
85
86 return True
87
88 class DECSectionObject(ini.BaseINISectionObject):
89 def GetArch(self):
90 return self.GetParent().GetArch()
91
92 class DECDefineSectionObject(DECSectionObject):
93 def __init__(self, parent):
94 DECSectionObject.__init__(self, parent)
95 self._key = None
96 self._value = None
97
98 def Parse(self):
99 assert (self._start == self._end), 'The object in define section must be in single line'
100
101 line = self.GetLineByOffset(self._start).strip()
102
103 line = line.split('#')[0]
104 arr = line.split('=')
105 if len(arr) != 2:
106 ErrorMsg('Invalid define section object',
107 self.GetFilename(),
108 self.GetParent().GetName()
109 )
110 return False
111
112 self._key = arr[0].strip()
113 self._value = arr[1].strip()
114
115 return True
116
117 def GetKey(self):
118 return self._key
119
120 def GetValue(self):
121 return self._value
122
123 class DECGuidObject(DECSectionObject):
124 _objs = {}
125
126 def __init__(self, parent):
127 DECSectionObject.__init__(self, parent)
128 self._name = None
129
130 def Parse(self):
131 line = self.GetLineByOffset(self._start).strip().split('#')[0]
132 self._name = line.split('=')[0].strip()
133 self._guid = line.split('=')[1].strip()
134 objdict = DECGuidObject._objs
135 if self._name not in objdict.keys():
136 objdict[self._name] = [self]
137 else:
138 objdict[self._name].append(self)
139
140 return True
141
142 def GetName(self):
143 return self._name
144
145 def GetGuid(self):
146 return self._guid
147
148 def Destroy(self):
149 objdict = DECGuidObject._objs
150 objdict[self._name].remove(self)
151 if len(objdict[self._name]) == 0:
152 del objdict[self._name]
153
154 @staticmethod
155 def GetObjectDict():
156 return DECGuidObject._objs
157
158 class DECPpiObject(DECSectionObject):
159 _objs = {}
160 def __init__(self, parent):
161 DECSectionObject.__init__(self, parent)
162 self._name = None
163
164 def Parse(self):
165 line = self.GetLineByOffset(self._start).strip().split('#')[0]
166 self._name = line.split('=')[0].strip()
167 self._guid = line.split('=')[1].strip()
168 objdict = DECPpiObject._objs
169 if self._name not in objdict.keys():
170 objdict[self._name] = [self]
171 else:
172 objdict[self._name].append(self)
173
174 return True
175
176 def GetName(self):
177 return self._name
178
179 def GetGuid(self):
180 return self._guid
181
182 def Destroy(self):
183 objdict = DECPpiObject._objs
184 objdict[self._name].remove(self)
185 if len(objdict[self._name]) == 0:
186 del objdict[self._name]
187
188 @staticmethod
189 def GetObjectDict():
190 return DECPpiObject._objs
191
192 class DECProtocolObject(DECSectionObject):
193 _objs = {}
194
195 def __init__(self, parent):
196 DECSectionObject.__init__(self, parent)
197 self._name = None
198
199 def Parse(self):
200 line = self.GetLineByOffset(self._start).strip().split('#')[0]
201 self._name = line.split('=')[0].strip()
202 self._guid = line.split('=')[1].strip()
203 objdict = DECProtocolObject._objs
204 if self._name not in objdict.keys():
205 objdict[self._name] = [self]
206 else:
207 objdict[self._name].append(self)
208
209 return True
210
211 def GetName(self):
212 return self._name
213
214 def GetGuid(self):
215 return self._guid
216
217 def Destroy(self):
218 objdict = DECProtocolObject._objs
219 objdict[self._name].remove(self)
220 if len(objdict[self._name]) == 0:
221 del objdict[self._name]
222
223
224 @staticmethod
225 def GetObjectDict():
226 return DECProtocolObject._objs
227
228 class DECLibraryClassObject(DECSectionObject):
229 _objs = {}
230
231 def __init__(self, parent):
232 DECSectionObject.__init__(self, parent)
233 self.mClassName = None
234 self.mHeaderFile = None
235
236 def Parse(self):
237 line = self.GetLineByOffset(self._start).strip().split('#')[0]
238 self.mClassName, self.mHeaderFile = line.split('|')
239 objdict = DECLibraryClassObject._objs
240 if self.mClassName not in objdict.keys():
241 objdict[self.mClassName] = [self]
242 else:
243 objdict[self.mClassName].append(self)
244 return True
245
246 def GetClassName(self):
247 return self.mClassName
248
249 def GetName(self):
250 return self.mClassName
251
252 def GetHeaderFile(self):
253 return self.mHeaderFile
254
255 def Destroy(self):
256 objdict = DECLibraryClassObject._objs
257 objdict[self.mClassName].remove(self)
258 if len(objdict[self.mClassName]) == 0:
259 del objdict[self.mClassName]
260
261 @staticmethod
262 def GetObjectDict():
263 return DECLibraryClassObject._objs
264
265 class DECIncludeObject(DECSectionObject):
266 def __init__(self, parent):
267 DECSectionObject.__init__(self, parent)
268
269 def GetPath(self):
270 return self.GetLineByOffset(self._start).split('#')[0].strip()
271
272 class DECPcdObject(DECSectionObject):
273 _objs = {}
274
275 def __init__(self, parent):
276 DECSectionObject.__init__(self, parent)
277 self.mPcdName = None
278 self.mPcdDefaultValue = None
279 self.mPcdDataType = None
280 self.mPcdToken = None
281
282 def Parse(self):
283 line = self.GetLineByOffset(self._start).strip().split('#')[0]
284 (self.mPcdName, self.mPcdDefaultValue, self.mPcdDataType, self.mPcdToken) = line.split('|')
285 objdict = DECPcdObject._objs
286 if self.mPcdName not in objdict.keys():
287 objdict[self.mPcdName] = [self]
288 else:
289 objdict[self.mPcdName].append(self)
290
291 return True
292
293 def Destroy(self):
294 objdict = DECPcdObject._objs
295 objdict[self.mPcdName].remove(self)
296 if len(objdict[self.mPcdName]) == 0:
297 del objdict[self.mPcdName]
298
299 def GetPcdType(self):
300 return self.GetParent().GetType()
301
302 def GetPcdName(self):
303 return self.mPcdName
304
305 def GetPcdValue(self):
306 return self.mPcdDefaultValue
307
308 def GetPcdDataType(self):
309 return self.mPcdDataType
310
311 def GetPcdToken(self):
312 return self.mPcdToken
313
314 def GetName(self):
315 return self.GetPcdName().split('.')[1]
316
317 @staticmethod
318 def GetObjectDict():
319 return DECPcdObject._objs