]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Scripts/PackageDocumentTools/plugins/EdkPlugins/edk2/model/inf.py
9d70fbcf97dbfffab08f0c10921cf5fb3587cdc5
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 import plugins
.EdkPlugins
.basemodel
.ini
as ini
16 from plugins
.EdkPlugins
.basemodel
.message
import *
18 class INFFile(ini
.BaseINIFile
):
21 def GetSectionInstance(self
, parent
, name
, isCombined
=False):
22 return INFSection(parent
, name
, isCombined
)
24 def GetProduceLibraryClass(self
):
25 obj
= self
.GetDefine("LIBRARY_CLASS")
26 if obj
== None: return None
28 return obj
.split('|')[0].strip()
30 def GetSectionObjectsByName(self
, name
, arch
=None):
32 sects
= self
.GetSectionByName(name
)
34 # skip unmatched archtecture content
35 if not sect
.IsArchMatch(arch
):
38 for obj
in sect
.GetObjects():
43 def GetSourceObjects(self
, arch
=None, tool
=None):
45 sects
= self
.GetSectionByName('sources')
47 # skip unmatched archtecture content
48 if not sect
.IsArchMatch(arch
):
51 for obj
in sect
.GetObjects():
52 if not obj
.IsMatchFamily(tool
):
59 if not ini
.BaseINIFile
.Parse(self
):
61 classname
= self
.GetProduceLibraryClass()
63 libobjdict
= INFFile
._libobjs
64 if libobjdict
.has_key(classname
):
65 if self
not in libobjdict
[classname
]:
66 libobjdict
[classname
].append(self
)
68 libobjdict
[classname
] = [self
]
72 def GetBaseName(self
):
73 return self
.GetDefine("BASE_NAME").strip()
75 def GetModuleRootPath(self
):
76 return os
.path
.dirname(self
.GetFilename())
79 classname
= self
.GetProduceLibraryClass()
81 libobjdict
= INFFile
._libobjs
82 libobjdict
[classname
].remove(self
)
83 if len(libobjdict
[classname
]) == 0:
84 del libobjdict
[classname
]
85 ini
.BaseINIFile
.Clear(self
)
88 class INFSection(ini
.BaseINISection
):
89 def GetSectionINIObject(self
, parent
):
92 if type.lower() == 'libraryclasses':
93 return INFLibraryClassObject(self
)
94 if type.lower() == 'sources':
95 return INFSourceObject(self
)
96 if type.lower().find('pcd') != -1:
97 return INFPcdObject(self
)
98 if type.lower() == 'packages':
99 return INFDependentPackageObject(self
)
100 if type.lower() in ['guids', 'protocols', 'ppis']:
101 return INFGuidObject(self
)
102 if type.lower() == 'defines':
103 return INFDefineSectionObject(self
)
104 return INFSectionObject(self
)
107 arr
= self
._name
.split('.')
108 return arr
[0].strip()
111 arr
= self
._name
.split('.')
116 def IsArchMatch(self
, arch
):
117 if arch
== None or self
.GetArch() == 'common':
120 if self
.GetArch().lower() != arch
.lower():
125 class INFSectionObject(ini
.BaseINISectionObject
):
127 return self
.GetParent().GetArch()
129 class INFDefineSectionObject(INFSectionObject
):
130 def __init__(self
, parent
):
131 INFSectionObject
.__init
__(self
, parent
)
136 assert (self
._start
== self
._end
), 'The object in define section must be in single line'
138 line
= self
.GetLineByOffset(self
._start
).strip()
140 line
= line
.split('#')[0]
141 arr
= line
.split('=')
143 ErrorMsg('Invalid define section object',
149 self
._key
= arr
[0].strip()
150 self
._value
= arr
[1].strip()
160 class INFLibraryClassObject(INFSectionObject
):
162 def __init__(self
, parent
):
163 INFSectionObject
.__init
__(self
, parent
)
164 self
._classname
= None
167 return self
._classname
170 self
._classname
= self
.GetLineByOffset(self
._start
).split('#')[0].strip()
171 objdict
= INFLibraryClassObject
._objs
172 if objdict
.has_key(self
._classname
):
173 objdict
[self
._classname
].append(self
)
175 objdict
[self
._classname
] = [self
]
179 objdict
= INFLibraryClassObject
._objs
180 objdict
[self
._classname
].remove(self
)
181 if len(objdict
[self
._classname
]) == 0:
182 del objdict
[self
._classname
]
185 return self
._classname
189 return INFLibraryClassObject
._objs
191 class INFDependentPackageObject(INFSectionObject
):
193 return self
.GetLineByOffset(self
._start
).split('#')[0].strip()
195 class INFSourceObject(INFSectionObject
):
197 def __init__(self
, parent
):
198 INFSectionObject
.__init
__(self
, parent
)
200 self
.mSourcename
= None
201 self
.mToolCode
= None
204 self
.mFeaturePcd
= None
205 self
.mFilename
= None
207 def GetSourcePath(self
):
208 return self
.mSourcename
210 def GetSourceFullPath(self
):
211 path
= os
.path
.dirname(self
.GetFilename())
212 path
= os
.path
.join(path
, self
.GetSourcePath())
213 return os
.path
.normpath(path
)
215 def GetToolCode(self
):
216 return self
.mToolCode
221 def GetTagName(self
):
224 def GetFeaturePcd(self
):
225 return self
.mFeaturePcd
228 line
= self
.GetLineByOffset(self
._start
).strip().split('#')[0]
230 arr
= line
.split('|')
232 self
.mSourcename
= arr
[0].strip()
234 self
.mFamily
= arr
[1].strip()
236 self
.mTagName
= arr
[2].strip()
238 self
.mToolCode
= arr
[3].strip()
240 self
.mFeaturePcd
= arr
[4].strip()
242 self
.mFilename
= os
.path
.basename(self
.GetSourceFullPath())
243 objdict
= INFSourceObject
._objs
244 if not objdict
.has_key(self
.mFilename
):
245 objdict
[self
.mFilename
] = [self
]
247 objdict
[self
.mFilename
].append(self
)
252 return self
.mFilename
255 objdict
= INFSourceObject
._objs
256 objdict
[self
.mFilename
].remove(self
)
257 if len(objdict
[self
.mFilename
]) == 0:
258 del objdict
[self
.mFilename
]
260 def IsMatchFamily(self
, family
):
263 if self
.mFamily
!= None:
264 if family
.strip().lower() == self
.mFamily
.lower():
269 fname
= self
.GetSourcePath()
270 if fname
.endswith('.S') and family
.lower() != 'gcc':
272 if fname
.endswith('.s') and (self
.GetArch().lower() != 'ipf' and self
.GetArch().lower() != 'common'):
274 if fname
.lower().endswith('.asm') and (family
.lower() != 'msft' and family
.lower() != 'intel'):
280 return INFSourceObject
._objs
282 class INFPcdObject(INFSectionObject
):
285 def __init__(self
, parent
):
286 INFSectionObject
.__init
__(self
, parent
)
289 self
.mDefaultValue
= None
294 return INFPcdObject
._objs
297 line
= self
.GetLineByOffset(self
._start
).strip().split('#')[0]
299 arr
= line
.split('|')
300 self
.mPcdName
= arr
[0].strip()
303 self
.mDefaultValue
= arr
[1].strip()
305 objdict
= INFPcdObject
._objs
306 if objdict
.has_key(self
.GetName()):
307 if self
not in objdict
[self
.GetName()]:
308 objdict
[self
.GetName()].append(self
)
310 objdict
[self
.GetName()] = [self
]
313 def GetPcdName(self
):
316 def GetPcdType(self
):
317 return self
.GetParent().GetType()
320 return self
.mPcdName
.split('.')[1]
323 objdict
= INFPcdObject
._objs
324 objdict
[self
.GetName()].remove(self
)
325 if len(objdict
[self
.GetName()]) == 0:
326 del objdict
[self
.GetName()]
328 class INFGuidObject(INFSectionObject
):
329 def __init__(self
, parent
):
330 INFSectionObject
.__init
__(self
, parent
)
334 line
= self
.GetLineByOffset(self
._start
).strip().split('#')[0].split("|")[0]
335 self
._name
= line
.strip()