]>
Commit | Line | Data |
---|---|---|
7ccc9c95 YZ |
1 | ## @file\r |
2 | #\r | |
3 | # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>\r | |
4 | #\r | |
2e351cbe | 5 | # SPDX-License-Identifier: BSD-2-Clause-Patent\r |
7ccc9c95 YZ |
6 | #\r |
7 | \r | |
9ab4ec51 | 8 | from plugins.EdkPlugins.basemodel import ini\r |
7ccc9c95 | 9 | import re, os\r |
9ab4ec51 | 10 | from plugins.EdkPlugins.basemodel.message import *\r |
7ccc9c95 YZ |
11 | \r |
12 | class DSCFile(ini.BaseINIFile):\r | |
13 | def GetSectionInstance(self, parent, name, isCombined=False):\r | |
14 | return DSCSection(parent, name, isCombined)\r | |
15 | \r | |
16 | def GetComponents(self):\r | |
17 | return self.GetSectionObjectsByName('Components')\r | |
18 | \r | |
19 | class DSCSection(ini.BaseINISection):\r | |
20 | def GetSectionINIObject(self, parent):\r | |
21 | type = self.GetType()\r | |
22 | \r | |
23 | if type.lower() == 'components':\r | |
24 | return DSCComponentObject(self)\r | |
25 | if type.lower() == 'libraryclasses':\r | |
26 | return DSCLibraryClassObject(self)\r | |
27 | if type.lower() == 'defines':\r | |
28 | return ini.BaseINISectionObject(self)\r | |
29 | if type.lower() == 'pcdsfeatureflag' or \\r | |
30 | type.lower() == 'pcdsfixedatbuild' or \\r | |
31 | type.lower() == 'pcdspatchableinmodule' or\\r | |
32 | type.lower() == 'pcdsdynamicdefault' or \\r | |
33 | type.lower() == 'pcdsdynamicex' or \\r | |
34 | type.lower() == 'pcdsdynamichii' or \\r | |
35 | type.lower() == 'pcdsdynamicvpd':\r | |
36 | return DSCPcdObject(self)\r | |
37 | \r | |
38 | return DSCSectionObject(self)\r | |
39 | \r | |
40 | def GetType(self):\r | |
41 | arr = self._name.split('.')\r | |
42 | return arr[0].strip()\r | |
43 | \r | |
44 | def GetArch(self):\r | |
45 | arr = self._name.split('.')\r | |
46 | if len(arr) == 1:\r | |
47 | return 'common'\r | |
48 | return arr[1]\r | |
49 | \r | |
50 | def GetModuleType(self):\r | |
51 | arr = self._name.split('.')\r | |
52 | if len(arr) < 3:\r | |
53 | return 'common'\r | |
54 | return arr[2]\r | |
55 | \r | |
56 | class DSCSectionObject(ini.BaseINISectionObject):\r | |
57 | def GetArch(self):\r | |
58 | return self.GetParent().GetArch()\r | |
59 | \r | |
60 | class DSCPcdObject(DSCSectionObject):\r | |
61 | \r | |
62 | def __init__(self, parent):\r | |
63 | ini.BaseINISectionObject.__init__(self, parent)\r | |
64 | self._name = None\r | |
65 | \r | |
66 | def Parse(self):\r | |
67 | line = self.GetLineByOffset(self._start).strip().split('#')[0]\r | |
68 | self._name = line.split('|')[0]\r | |
69 | self._value = line.split('|')[1]\r | |
70 | return True\r | |
71 | \r | |
72 | def GetPcdName(self):\r | |
73 | return self._name\r | |
74 | \r | |
75 | def GetPcdType(self):\r | |
76 | return self.GetParent().GetType()\r | |
77 | \r | |
78 | def GetPcdValue(self):\r | |
79 | return self._value\r | |
80 | \r | |
81 | class DSCLibraryClassObject(DSCSectionObject):\r | |
82 | def __init__(self, parent):\r | |
83 | ini.BaseINISectionObject.__init__(self, parent)\r | |
84 | \r | |
85 | def GetClass(self):\r | |
86 | line = self.GetLineByOffset(self._start)\r | |
87 | return line.split('#')[0].split('|')[0].strip()\r | |
88 | \r | |
89 | def GetInstance(self):\r | |
90 | line = self.GetLineByOffset(self._start)\r | |
91 | return line.split('#')[0].split('|')[1].strip()\r | |
92 | \r | |
93 | def GetArch(self):\r | |
94 | return self.GetParent().GetArch()\r | |
95 | \r | |
96 | def GetModuleType(self):\r | |
97 | return self.GetParent().GetModuleType()\r | |
98 | \r | |
99 | class DSCComponentObject(DSCSectionObject):\r | |
100 | \r | |
101 | def __init__(self, parent):\r | |
102 | ini.BaseINISectionObject.__init__(self, parent)\r | |
103 | self._OveridePcds = {}\r | |
104 | self._OverideLibraries = {}\r | |
105 | self._Filename = ''\r | |
106 | \r | |
107 | def __del__(self):\r | |
108 | self._OverideLibraries.clear()\r | |
109 | self._OverideLibraries.clear()\r | |
110 | ini.BaseINISectionObject.__del__(self)\r | |
111 | \r | |
112 | def AddOverideLib(self, libclass, libinstPath):\r | |
113 | if libclass not in self._OverideLibraries.keys():\r | |
114 | self._OverideLibraries[libclass] = libinstPath\r | |
115 | \r | |
116 | def AddOveridePcd(self, name, type, value=None):\r | |
117 | if type not in self._OveridePcds.keys():\r | |
118 | self._OveridePcds[type] = []\r | |
119 | self._OveridePcds[type].append((name, value))\r | |
120 | \r | |
121 | def GetOverideLibs(self):\r | |
122 | return self._OverideLibraries\r | |
123 | \r | |
124 | def GetArch(self):\r | |
125 | return self.GetParent().GetArch()\r | |
126 | \r | |
127 | def GetOveridePcds(self):\r | |
128 | return self._OveridePcds\r | |
129 | \r | |
130 | def GetFilename(self):\r | |
131 | return self.GetLineByOffset(self._start).split('#')[0].split('{')[0].strip()\r | |
132 | \r | |
133 | def SetFilename(self, fName):\r | |
134 | self._Filename = fName\r | |
135 | \r | |
136 | def Parse(self):\r | |
137 | if (self._start < self._end):\r | |
138 | #\r | |
139 | # The first line is inf path and could be ignored\r | |
140 | # The end line is '}' and could be ignored\r | |
141 | #\r | |
142 | curr = self._start + 1\r | |
143 | end = self._end - 1\r | |
144 | OverideName = ''\r | |
145 | while (curr <= end):\r | |
146 | line = self.GetLineByOffset(curr).strip()\r | |
147 | if len(line) > 0 and line[0] != '#':\r | |
148 | line = line.split('#')[0].strip()\r | |
149 | if line[0] == '<':\r | |
150 | OverideName = line[1:len(line)-1]\r | |
151 | elif OverideName.lower() == 'libraryclasses':\r | |
152 | arr = line.split('|')\r | |
153 | self._OverideLibraries[arr[0].strip()] = arr[1].strip()\r | |
154 | elif OverideName.lower() == 'pcds':\r | |
155 | ErrorMsg('EDES does not support PCD overide',\r | |
156 | self.GetFileName(),\r | |
157 | self.GetParent().GetLinenumberByOffset(curr))\r | |
158 | curr = curr + 1\r | |
159 | return True\r | |
160 | \r | |
161 | def GenerateLines(self):\r | |
162 | lines = []\r | |
163 | hasLib = False\r | |
164 | hasPcd = False\r | |
165 | if len(self._OverideLibraries) != 0:\r | |
166 | hasLib = True\r | |
167 | if len(self._OveridePcds) != 0:\r | |
168 | hasPcd = True\r | |
169 | \r | |
170 | if hasLib or hasPcd:\r | |
171 | lines.append((' %s {\n' % self._Filename))\r | |
172 | else:\r | |
173 | lines.append((' %s \n' % self._Filename))\r | |
174 | return lines\r | |
175 | \r | |
176 | if hasLib:\r | |
177 | lines.append(' <LibraryClasses>\n')\r | |
178 | for libKey in self._OverideLibraries.keys():\r | |
179 | lines.append(' %s|%s\n' % (libKey, self._OverideLibraries[libKey]))\r | |
180 | \r | |
181 | if hasPcd:\r | |
182 | for key in self._OveridePcds.keys():\r | |
183 | lines.append(' <%s>\n' % key)\r | |
184 | \r | |
185 | for name, value in self._OveridePcds[key]:\r | |
4231a819 | 186 | if value is not None:\r |
7ccc9c95 YZ |
187 | lines.append(' %s|%s\n' % (name, value))\r |
188 | else:\r | |
189 | lines.append(' %s\n' % name)\r | |
190 | \r | |
191 | if hasLib or hasPcd:\r | |
192 | lines.append(' }\n')\r | |
193 | \r | |
194 | return lines\r | |
195 | \r |