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