]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Scripts/PackageDocumentTools/plugins/EdkPlugins/edk2/model/dsc.py
BaseTools: Remove equality operator with None
[mirror_edk2.git] / BaseTools / Scripts / PackageDocumentTools / plugins / EdkPlugins / edk2 / model / dsc.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 DSCFile(ini.BaseINIFile):
19 def GetSectionInstance(self, parent, name, isCombined=False):
20 return DSCSection(parent, name, isCombined)
21
22 def GetComponents(self):
23 return self.GetSectionObjectsByName('Components')
24
25 class DSCSection(ini.BaseINISection):
26 def GetSectionINIObject(self, parent):
27 type = self.GetType()
28
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)
43
44 return DSCSectionObject(self)
45
46 def GetType(self):
47 arr = self._name.split('.')
48 return arr[0].strip()
49
50 def GetArch(self):
51 arr = self._name.split('.')
52 if len(arr) == 1:
53 return 'common'
54 return arr[1]
55
56 def GetModuleType(self):
57 arr = self._name.split('.')
58 if len(arr) < 3:
59 return 'common'
60 return arr[2]
61
62 class DSCSectionObject(ini.BaseINISectionObject):
63 def GetArch(self):
64 return self.GetParent().GetArch()
65
66 class DSCPcdObject(DSCSectionObject):
67
68 def __init__(self, parent):
69 ini.BaseINISectionObject.__init__(self, parent)
70 self._name = None
71
72 def Parse(self):
73 line = self.GetLineByOffset(self._start).strip().split('#')[0]
74 self._name = line.split('|')[0]
75 self._value = line.split('|')[1]
76 return True
77
78 def GetPcdName(self):
79 return self._name
80
81 def GetPcdType(self):
82 return self.GetParent().GetType()
83
84 def GetPcdValue(self):
85 return self._value
86
87 class DSCLibraryClassObject(DSCSectionObject):
88 def __init__(self, parent):
89 ini.BaseINISectionObject.__init__(self, parent)
90
91 def GetClass(self):
92 line = self.GetLineByOffset(self._start)
93 return line.split('#')[0].split('|')[0].strip()
94
95 def GetInstance(self):
96 line = self.GetLineByOffset(self._start)
97 return line.split('#')[0].split('|')[1].strip()
98
99 def GetArch(self):
100 return self.GetParent().GetArch()
101
102 def GetModuleType(self):
103 return self.GetParent().GetModuleType()
104
105 class DSCComponentObject(DSCSectionObject):
106
107 def __init__(self, parent):
108 ini.BaseINISectionObject.__init__(self, parent)
109 self._OveridePcds = {}
110 self._OverideLibraries = {}
111 self._Filename = ''
112
113 def __del__(self):
114 self._OverideLibraries.clear()
115 self._OverideLibraries.clear()
116 ini.BaseINISectionObject.__del__(self)
117
118 def AddOverideLib(self, libclass, libinstPath):
119 if libclass not in self._OverideLibraries.keys():
120 self._OverideLibraries[libclass] = libinstPath
121
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))
126
127 def GetOverideLibs(self):
128 return self._OverideLibraries
129
130 def GetArch(self):
131 return self.GetParent().GetArch()
132
133 def GetOveridePcds(self):
134 return self._OveridePcds
135
136 def GetFilename(self):
137 return self.GetLineByOffset(self._start).split('#')[0].split('{')[0].strip()
138
139 def SetFilename(self, fName):
140 self._Filename = fName
141
142 def Parse(self):
143 if (self._start < self._end):
144 #
145 # The first line is inf path and could be ignored
146 # The end line is '}' and could be ignored
147 #
148 curr = self._start + 1
149 end = self._end - 1
150 OverideName = ''
151 while (curr <= end):
152 line = self.GetLineByOffset(curr).strip()
153 if len(line) > 0 and line[0] != '#':
154 line = line.split('#')[0].strip()
155 if line[0] == '<':
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',
162 self.GetFileName(),
163 self.GetParent().GetLinenumberByOffset(curr))
164 curr = curr + 1
165 return True
166
167 def GenerateLines(self):
168 lines = []
169 hasLib = False
170 hasPcd = False
171 if len(self._OverideLibraries) != 0:
172 hasLib = True
173 if len(self._OveridePcds) != 0:
174 hasPcd = True
175
176 if hasLib or hasPcd:
177 lines.append((' %s {\n' % self._Filename))
178 else:
179 lines.append((' %s \n' % self._Filename))
180 return lines
181
182 if hasLib:
183 lines.append(' <LibraryClasses>\n')
184 for libKey in self._OverideLibraries.keys():
185 lines.append(' %s|%s\n' % (libKey, self._OverideLibraries[libKey]))
186
187 if hasPcd:
188 for key in self._OveridePcds.keys():
189 lines.append(' <%s>\n' % key)
190
191 for name, value in self._OveridePcds[key]:
192 if value is not None:
193 lines.append(' %s|%s\n' % (name, value))
194 else:
195 lines.append(' %s\n' % name)
196
197 if hasLib or hasPcd:
198 lines.append(' }\n')
199
200 return lines
201