]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Scripts/PackageDocumentTools/plugins/EdkPlugins/edk2/model/dsc.py
a2d23a7732f4ef75c048482ce6ef1f90de559c0e
3 # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
5 # SPDX-License-Identifier: BSD-2-Clause-Patent
8 from plugins
.EdkPlugins
.basemodel
import ini
10 from plugins
.EdkPlugins
.basemodel
.message
import *
12 class DSCFile(ini
.BaseINIFile
):
13 def GetSectionInstance(self
, parent
, name
, isCombined
=False):
14 return DSCSection(parent
, name
, isCombined
)
16 def GetComponents(self
):
17 return self
.GetSectionObjectsByName('Components')
19 class DSCSection(ini
.BaseINISection
):
20 def GetSectionINIObject(self
, parent
):
23 if type.lower() == 'components':
24 return DSCComponentObject(self
)
25 if type.lower() == 'libraryclasses':
26 return DSCLibraryClassObject(self
)
27 if type.lower() == 'defines':
28 return ini
.BaseINISectionObject(self
)
29 if type.lower() == 'pcdsfeatureflag' or \
30 type.lower() == 'pcdsfixedatbuild' or \
31 type.lower() == 'pcdspatchableinmodule' or\
32 type.lower() == 'pcdsdynamicdefault' or \
33 type.lower() == 'pcdsdynamicex' or \
34 type.lower() == 'pcdsdynamichii' or \
35 type.lower() == 'pcdsdynamicvpd':
36 return DSCPcdObject(self
)
38 return DSCSectionObject(self
)
41 arr
= self
._name
.split('.')
45 arr
= self
._name
.split('.')
50 def GetModuleType(self
):
51 arr
= self
._name
.split('.')
56 class DSCSectionObject(ini
.BaseINISectionObject
):
58 return self
.GetParent().GetArch()
60 class DSCPcdObject(DSCSectionObject
):
62 def __init__(self
, parent
):
63 ini
.BaseINISectionObject
.__init
__(self
, parent
)
67 line
= self
.GetLineByOffset(self
._start
).strip().split('#')[0]
68 self
._name
= line
.split('|')[0]
69 self
._value
= line
.split('|')[1]
76 return self
.GetParent().GetType()
78 def GetPcdValue(self
):
81 class DSCLibraryClassObject(DSCSectionObject
):
82 def __init__(self
, parent
):
83 ini
.BaseINISectionObject
.__init
__(self
, parent
)
86 line
= self
.GetLineByOffset(self
._start
)
87 return line
.split('#')[0].split('|')[0].strip()
89 def GetInstance(self
):
90 line
= self
.GetLineByOffset(self
._start
)
91 return line
.split('#')[0].split('|')[1].strip()
94 return self
.GetParent().GetArch()
96 def GetModuleType(self
):
97 return self
.GetParent().GetModuleType()
99 class DSCComponentObject(DSCSectionObject
):
101 def __init__(self
, parent
):
102 ini
.BaseINISectionObject
.__init
__(self
, parent
)
103 self
._OveridePcds
= {}
104 self
._OverideLibraries
= {}
108 self
._OverideLibraries
.clear()
109 self
._OverideLibraries
.clear()
110 ini
.BaseINISectionObject
.__del
__(self
)
112 def AddOverideLib(self
, libclass
, libinstPath
):
113 if libclass
not in self
._OverideLibraries
.keys():
114 self
._OverideLibraries
[libclass
] = libinstPath
116 def AddOveridePcd(self
, name
, type, value
=None):
117 if type not in self
._OveridePcds
.keys():
118 self
._OveridePcds
[type] = []
119 self
._OveridePcds
[type].append((name
, value
))
121 def GetOverideLibs(self
):
122 return self
._OverideLibraries
125 return self
.GetParent().GetArch()
127 def GetOveridePcds(self
):
128 return self
._OveridePcds
130 def GetFilename(self
):
131 return self
.GetLineByOffset(self
._start
).split('#')[0].split('{')[0].strip()
133 def SetFilename(self
, fName
):
134 self
._Filename
= fName
137 if (self
._start
< self
._end
):
139 # The first line is inf path and could be ignored
140 # The end line is '}' and could be ignored
142 curr
= self
._start
+ 1
146 line
= self
.GetLineByOffset(curr
).strip()
147 if len(line
) > 0 and line
[0] != '#':
148 line
= line
.split('#')[0].strip()
150 OverideName
= line
[1:len(line
)-1]
151 elif OverideName
.lower() == 'libraryclasses':
152 arr
= line
.split('|')
153 self
._OverideLibraries
[arr
[0].strip()] = arr
[1].strip()
154 elif OverideName
.lower() == 'pcds':
155 ErrorMsg('EDES does not support PCD overide',
157 self
.GetParent().GetLinenumberByOffset(curr
))
161 def GenerateLines(self
):
165 if len(self
._OverideLibraries
) != 0:
167 if len(self
._OveridePcds
) != 0:
171 lines
.append((' %s {\n' % self
._Filename
))
173 lines
.append((' %s \n' % self
._Filename
))
177 lines
.append(' <LibraryClasses>\n')
178 for libKey
in self
._OverideLibraries
.keys():
179 lines
.append(' %s|%s\n' % (libKey
, self
._OverideLibraries
[libKey
]))
182 for key
in self
._OveridePcds
.keys():
183 lines
.append(' <%s>\n' % key
)
185 for name
, value
in self
._OveridePcds
[key
]:
186 if value
is not None:
187 lines
.append(' %s|%s\n' % (name
, value
))
189 lines
.append(' %s\n' % name
)