]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Scripts/PackageDocumentTools/plugins/EdkPlugins/edk2/model/dec.py
3 # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
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
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.
14 from plugins
.EdkPlugins
.basemodel
import ini
16 from plugins
.EdkPlugins
.basemodel
.message
import *
18 class DECFile(ini
.BaseINIFile
):
20 def GetSectionInstance(self
, parent
, name
, isCombined
=False):
21 return DECSection(parent
, name
, isCombined
)
23 def GetComponents(self
):
24 return self
.GetSectionByName('Components')
26 def GetPackageRootPath(self
):
27 return os
.path
.dirname(self
.GetFilename()).strip()
29 def GetBaseName(self
):
30 return self
.GetDefine("PACKAGE_NAME").strip()
33 return self
.GetDefine("PACKAGE_VERSION").strip()
35 def GetSectionObjectsByName(self
, name
, arch
=None):
37 sects
= self
.GetSectionByName(name
)
39 # skip unmatched archtecture content
40 if not sect
.IsArchMatch(arch
):
43 for obj
in sect
.GetObjects():
48 class DECSection(ini
.BaseINISection
):
49 def GetSectionINIObject(self
, parent
):
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
)
67 return DECSectionObject(self
)
70 arr
= self
._name
.split('.')
74 arr
= self
._name
.split('.')
79 def IsArchMatch(self
, arch
):
80 if arch
is None or self
.GetArch() == 'common':
83 if self
.GetArch().lower() != arch
.lower():
88 class DECSectionObject(ini
.BaseINISectionObject
):
90 return self
.GetParent().GetArch()
92 class DECDefineSectionObject(DECSectionObject
):
93 def __init__(self
, parent
):
94 DECSectionObject
.__init
__(self
, parent
)
99 assert (self
._start
== self
._end
), 'The object in define section must be in single line'
101 line
= self
.GetLineByOffset(self
._start
).strip()
103 line
= line
.split('#')[0]
104 arr
= line
.split('=')
106 ErrorMsg('Invalid define section object',
108 self
.GetParent().GetName()
112 self
._key
= arr
[0].strip()
113 self
._value
= arr
[1].strip()
123 class DECGuidObject(DECSectionObject
):
126 def __init__(self
, parent
):
127 DECSectionObject
.__init
__(self
, parent
)
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
]
138 objdict
[self
._name
].append(self
)
149 objdict
= DECGuidObject
._objs
150 objdict
[self
._name
].remove(self
)
151 if len(objdict
[self
._name
]) == 0:
152 del objdict
[self
._name
]
156 return DECGuidObject
._objs
158 class DECPpiObject(DECSectionObject
):
160 def __init__(self
, parent
):
161 DECSectionObject
.__init
__(self
, parent
)
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
]
172 objdict
[self
._name
].append(self
)
183 objdict
= DECPpiObject
._objs
184 objdict
[self
._name
].remove(self
)
185 if len(objdict
[self
._name
]) == 0:
186 del objdict
[self
._name
]
190 return DECPpiObject
._objs
192 class DECProtocolObject(DECSectionObject
):
195 def __init__(self
, parent
):
196 DECSectionObject
.__init
__(self
, parent
)
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
]
207 objdict
[self
._name
].append(self
)
218 objdict
= DECProtocolObject
._objs
219 objdict
[self
._name
].remove(self
)
220 if len(objdict
[self
._name
]) == 0:
221 del objdict
[self
._name
]
226 return DECProtocolObject
._objs
228 class DECLibraryClassObject(DECSectionObject
):
231 def __init__(self
, parent
):
232 DECSectionObject
.__init
__(self
, parent
)
233 self
.mClassName
= None
234 self
.mHeaderFile
= None
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
]
243 objdict
[self
.mClassName
].append(self
)
246 def GetClassName(self
):
247 return self
.mClassName
250 return self
.mClassName
252 def GetHeaderFile(self
):
253 return self
.mHeaderFile
256 objdict
= DECLibraryClassObject
._objs
257 objdict
[self
.mClassName
].remove(self
)
258 if len(objdict
[self
.mClassName
]) == 0:
259 del objdict
[self
.mClassName
]
263 return DECLibraryClassObject
._objs
265 class DECIncludeObject(DECSectionObject
):
266 def __init__(self
, parent
):
267 DECSectionObject
.__init
__(self
, parent
)
270 return self
.GetLineByOffset(self
._start
).split('#')[0].strip()
272 class DECPcdObject(DECSectionObject
):
275 def __init__(self
, parent
):
276 DECSectionObject
.__init
__(self
, parent
)
278 self
.mPcdDefaultValue
= None
279 self
.mPcdDataType
= None
280 self
.mPcdToken
= None
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
]
289 objdict
[self
.mPcdName
].append(self
)
294 objdict
= DECPcdObject
._objs
295 objdict
[self
.mPcdName
].remove(self
)
296 if len(objdict
[self
.mPcdName
]) == 0:
297 del objdict
[self
.mPcdName
]
299 def GetPcdType(self
):
300 return self
.GetParent().GetType()
302 def GetPcdName(self
):
305 def GetPcdValue(self
):
306 return self
.mPcdDefaultValue
308 def GetPcdDataType(self
):
309 return self
.mPcdDataType
311 def GetPcdToken(self
):
312 return self
.mPcdToken
315 return self
.GetPcdName().split('.')[1]
319 return DECPcdObject
._objs