]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Scripts/PackageDocumentTools/plugins/EdkPlugins/edk2/model/dsc.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 import plugins
.EdkPlugins
.basemodel
.ini
as ini
16 from plugins
.EdkPlugins
.basemodel
.message
import *
18 class DSCFile(ini
.BaseINIFile
):
19 def GetSectionInstance(self
, parent
, name
, isCombined
=False):
20 return DSCSection(parent
, name
, isCombined
)
22 def GetComponents(self
):
23 return self
.GetSectionObjectsByName('Components')
25 class DSCSection(ini
.BaseINISection
):
26 def GetSectionINIObject(self
, parent
):
29 if type.lower() == 'components':
30 return DSCComponentObject(self
)
31 if type.lower() == 'libraryclasses':
32 return DSCLibraryClassObject(self
)
33 if type.lower() == 'defines':
34 return ini
.BaseINISectionObject(self
)
35 if type.lower() == 'pcdsfeatureflag' or \
36 type.lower() == 'pcdsfixedatbuild' or \
37 type.lower() == 'pcdspatchableinmodule' or\
38 type.lower() == 'pcdsdynamicdefault' or \
39 type.lower() == 'pcdsdynamicex' or \
40 type.lower() == 'pcdsdynamichii' or \
41 type.lower() == 'pcdsdynamicvpd':
42 return DSCPcdObject(self
)
44 return DSCSectionObject(self
)
47 arr
= self
._name
.split('.')
51 arr
= self
._name
.split('.')
56 def GetModuleType(self
):
57 arr
= self
._name
.split('.')
62 class DSCSectionObject(ini
.BaseINISectionObject
):
64 return self
.GetParent().GetArch()
66 class DSCPcdObject(DSCSectionObject
):
68 def __init__(self
, parent
):
69 ini
.BaseINISectionObject
.__init
__(self
, parent
)
73 line
= self
.GetLineByOffset(self
._start
).strip().split('#')[0]
74 self
._name
= line
.split('|')[0]
75 self
._value
= line
.split('|')[1]
82 return self
.GetParent().GetType()
84 def GetPcdValue(self
):
87 class DSCLibraryClassObject(DSCSectionObject
):
88 def __init__(self
, parent
):
89 ini
.BaseINISectionObject
.__init
__(self
, parent
)
92 line
= self
.GetLineByOffset(self
._start
)
93 return line
.split('#')[0].split('|')[0].strip()
95 def GetInstance(self
):
96 line
= self
.GetLineByOffset(self
._start
)
97 return line
.split('#')[0].split('|')[1].strip()
100 return self
.GetParent().GetArch()
102 def GetModuleType(self
):
103 return self
.GetParent().GetModuleType()
105 class DSCComponentObject(DSCSectionObject
):
107 def __init__(self
, parent
):
108 ini
.BaseINISectionObject
.__init
__(self
, parent
)
109 self
._OveridePcds
= {}
110 self
._OverideLibraries
= {}
114 self
._OverideLibraries
.clear()
115 self
._OverideLibraries
.clear()
116 ini
.BaseINISectionObject
.__del
__(self
)
118 def AddOverideLib(self
, libclass
, libinstPath
):
119 if libclass
not in self
._OverideLibraries
.keys():
120 self
._OverideLibraries
[libclass
] = libinstPath
122 def AddOveridePcd(self
, name
, type, value
=None):
123 if type not in self
._OveridePcds
.keys():
124 self
._OveridePcds
[type] = []
125 self
._OveridePcds
[type].append((name
, value
))
127 def GetOverideLibs(self
):
128 return self
._OverideLibraries
131 return self
.GetParent().GetArch()
133 def GetOveridePcds(self
):
134 return self
._OveridePcds
136 def GetFilename(self
):
137 return self
.GetLineByOffset(self
._start
).split('#')[0].split('{')[0].strip()
139 def SetFilename(self
, fName
):
140 self
._Filename
= fName
143 if (self
._start
< self
._end
):
145 # The first line is inf path and could be ignored
146 # The end line is '}' and could be ignored
148 curr
= self
._start
+ 1
152 line
= self
.GetLineByOffset(curr
).strip()
153 if len(line
) > 0 and line
[0] != '#':
154 line
= line
.split('#')[0].strip()
156 OverideName
= line
[1:len(line
)-1]
157 elif OverideName
.lower() == 'libraryclasses':
158 arr
= line
.split('|')
159 self
._OverideLibraries
[arr
[0].strip()] = arr
[1].strip()
160 elif OverideName
.lower() == 'pcds':
161 ErrorMsg('EDES does not support PCD overide',
163 self
.GetParent().GetLinenumberByOffset(curr
))
167 def GenerateLines(self
):
171 if len(self
._OverideLibraries
) != 0:
173 if len(self
._OveridePcds
) != 0:
177 lines
.append((' %s {\n' % self
._Filename
))
179 lines
.append((' %s \n' % self
._Filename
))
183 lines
.append(' <LibraryClasses>\n')
184 for libKey
in self
._OverideLibraries
.keys():
185 lines
.append(' %s|%s\n' % (libKey
, self
._OverideLibraries
[libKey
]))
188 for key
in self
._OveridePcds
.keys():
189 lines
.append(' <%s>\n' % key
)
191 for name
, value
in self
._OveridePcds
[key
]:
192 if value
is not None:
193 lines
.append(' %s|%s\n' % (name
, value
))
195 lines
.append(' %s\n' % name
)