]>
Commit | Line | Data |
---|---|---|
f51461c8 LG |
1 | ## @file\r |
2 | # This file is used to parse meta files\r | |
3 | #\r | |
22a99b87 | 4 | # Copyright (c) 2008 - 2015, Intel Corporation. All rights reserved.<BR>\r |
118bf096 | 5 | # Copyright (c) 2015, Hewlett Packard Enterprise Development, L.P.<BR>\r |
f51461c8 LG |
6 | # This program and the accompanying materials\r |
7 | # are licensed and made available under the terms and conditions of the BSD License\r | |
8 | # which accompanies this distribution. The full text of the license may be found at\r | |
9 | # http://opensource.org/licenses/bsd-license.php\r | |
10 | #\r | |
11 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | #\r | |
14 | \r | |
15 | ##\r | |
16 | # Import Modules\r | |
17 | #\r | |
1be2ed90 | 18 | import Common.LongFilePathOs as os\r |
f51461c8 LG |
19 | import re\r |
20 | import time\r | |
21 | import copy\r | |
22 | \r | |
23 | import Common.EdkLogger as EdkLogger\r | |
24 | import Common.GlobalData as GlobalData\r | |
25 | \r | |
26 | from CommonDataClass.DataClass import *\r | |
27 | from Common.DataType import *\r | |
28 | from Common.String import *\r | |
29 | from Common.Misc import GuidStructureStringToGuidString, CheckPcdDatum, PathClass, AnalyzePcdData, AnalyzeDscPcd\r | |
30 | from Common.Expression import *\r | |
31 | from CommonDataClass.Exceptions import *\r | |
1be2ed90 | 32 | from Common.LongFilePathSupport import OpenLongFilePath as open\r |
f51461c8 LG |
33 | \r |
34 | from MetaFileTable import MetaFileStorage\r | |
97fa0ee9 | 35 | from MetaFileCommentParser import CheckInfComment\r |
f51461c8 LG |
36 | \r |
37 | ## A decorator used to parse macro definition\r | |
38 | def ParseMacro(Parser):\r | |
39 | def MacroParser(self):\r | |
40 | Match = gMacroDefPattern.match(self._CurrentLine)\r | |
41 | if not Match:\r | |
42 | # Not 'DEFINE/EDK_GLOBAL' statement, call decorated method\r | |
43 | Parser(self)\r | |
44 | return\r | |
45 | \r | |
46 | TokenList = GetSplitValueList(self._CurrentLine[Match.end(1):], TAB_EQUAL_SPLIT, 1)\r | |
47 | # Syntax check\r | |
48 | if not TokenList[0]:\r | |
49 | EdkLogger.error('Parser', FORMAT_INVALID, "No macro name given",\r | |
50 | ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)\r | |
51 | if len(TokenList) < 2:\r | |
52 | TokenList.append('')\r | |
53 | \r | |
54 | Type = Match.group(1)\r | |
55 | Name, Value = TokenList\r | |
56 | # Global macros can be only defined via environment variable\r | |
57 | if Name in GlobalData.gGlobalDefines:\r | |
58 | EdkLogger.error('Parser', FORMAT_INVALID, "%s can only be defined via environment variable" % Name,\r | |
59 | ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)\r | |
60 | # Only upper case letters, digit and '_' are allowed\r | |
61 | if not gMacroNamePattern.match(Name):\r | |
62 | EdkLogger.error('Parser', FORMAT_INVALID, "The macro name must be in the pattern [A-Z][A-Z0-9_]*",\r | |
63 | ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)\r | |
64 | \r | |
65 | Value = ReplaceMacro(Value, self._Macros)\r | |
66 | if Type in self.DataType:\r | |
67 | self._ItemType = self.DataType[Type]\r | |
68 | else:\r | |
69 | self._ItemType = MODEL_META_DATA_DEFINE\r | |
70 | # DEFINE defined macros\r | |
71 | if Type == TAB_DSC_DEFINES_DEFINE:\r | |
72 | #\r | |
73 | # First judge whether this DEFINE is in conditional directive statements or not.\r | |
74 | #\r | |
75 | if type(self) == DscParser and self._InDirective > -1:\r | |
76 | pass\r | |
77 | else:\r | |
78 | if type(self) == DecParser:\r | |
79 | if MODEL_META_DATA_HEADER in self._SectionType:\r | |
80 | self._FileLocalMacros[Name] = Value\r | |
81 | else:\r | |
82 | self._ConstructSectionMacroDict(Name, Value)\r | |
83 | elif self._SectionType == MODEL_META_DATA_HEADER:\r | |
84 | self._FileLocalMacros[Name] = Value\r | |
85 | else:\r | |
86 | self._ConstructSectionMacroDict(Name, Value)\r | |
87 | \r | |
88 | # EDK_GLOBAL defined macros\r | |
89 | elif type(self) != DscParser:\r | |
90 | EdkLogger.error('Parser', FORMAT_INVALID, "EDK_GLOBAL can only be used in .dsc file",\r | |
91 | ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)\r | |
92 | elif self._SectionType != MODEL_META_DATA_HEADER:\r | |
93 | EdkLogger.error('Parser', FORMAT_INVALID, "EDK_GLOBAL can only be used under [Defines] section",\r | |
94 | ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)\r | |
95 | elif (Name in self._FileLocalMacros) and (self._FileLocalMacros[Name] != Value):\r | |
96 | EdkLogger.error('Parser', FORMAT_INVALID, "EDK_GLOBAL defined a macro with the same name and different value as one defined by 'DEFINE'",\r | |
97 | ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)\r | |
98 | \r | |
99 | self._ValueList = [Type, Name, Value]\r | |
100 | \r | |
101 | return MacroParser\r | |
102 | \r | |
103 | ## Base class of parser\r | |
104 | #\r | |
105 | # This class is used for derivation purpose. The specific parser for one kind\r | |
106 | # type file must derive this class and implement some public interfaces.\r | |
107 | #\r | |
108 | # @param FilePath The path of platform description file\r | |
109 | # @param FileType The raw data of DSC file\r | |
110 | # @param Table Database used to retrieve module/package information\r | |
111 | # @param Macros Macros used for replacement in file\r | |
112 | # @param Owner Owner ID (for sub-section parsing)\r | |
113 | # @param From ID from which the data comes (for !INCLUDE directive)\r | |
114 | #\r | |
115 | class MetaFileParser(object):\r | |
116 | # data type (file content) for specific file type\r | |
117 | DataType = {}\r | |
118 | \r | |
119 | # Parser objects used to implement singleton\r | |
120 | MetaFiles = {}\r | |
121 | \r | |
122 | ## Factory method\r | |
123 | #\r | |
124 | # One file, one parser object. This factory method makes sure that there's\r | |
125 | # only one object constructed for one meta file.\r | |
126 | #\r | |
127 | # @param Class class object of real AutoGen class\r | |
128 | # (InfParser, DecParser or DscParser)\r | |
129 | # @param FilePath The path of meta file\r | |
130 | # @param *args The specific class related parameters\r | |
131 | # @param **kwargs The specific class related dict parameters\r | |
132 | #\r | |
133 | def __new__(Class, FilePath, *args, **kwargs):\r | |
134 | if FilePath in Class.MetaFiles:\r | |
135 | return Class.MetaFiles[FilePath]\r | |
136 | else:\r | |
137 | ParserObject = super(MetaFileParser, Class).__new__(Class)\r | |
138 | Class.MetaFiles[FilePath] = ParserObject\r | |
139 | return ParserObject\r | |
140 | \r | |
141 | ## Constructor of MetaFileParser\r | |
142 | #\r | |
143 | # Initialize object of MetaFileParser\r | |
144 | #\r | |
145 | # @param FilePath The path of platform description file\r | |
146 | # @param FileType The raw data of DSC file\r | |
147 | # @param Table Database used to retrieve module/package information\r | |
148 | # @param Macros Macros used for replacement in file\r | |
149 | # @param Owner Owner ID (for sub-section parsing)\r | |
150 | # @param From ID from which the data comes (for !INCLUDE directive)\r | |
151 | #\r | |
152 | def __init__(self, FilePath, FileType, Table, Owner= -1, From= -1):\r | |
153 | self._Table = Table\r | |
154 | self._RawTable = Table\r | |
155 | self._FileType = FileType\r | |
156 | self.MetaFile = FilePath\r | |
157 | self._FileDir = self.MetaFile.Dir\r | |
158 | self._Defines = {}\r | |
159 | self._FileLocalMacros = {}\r | |
160 | self._SectionsMacroDict = {}\r | |
161 | \r | |
162 | # for recursive parsing\r | |
163 | self._Owner = [Owner]\r | |
164 | self._From = From\r | |
165 | \r | |
166 | # parsr status for parsing\r | |
167 | self._ValueList = ['', '', '', '', '']\r | |
168 | self._Scope = []\r | |
169 | self._LineIndex = 0\r | |
170 | self._CurrentLine = ''\r | |
171 | self._SectionType = MODEL_UNKNOWN\r | |
172 | self._SectionName = ''\r | |
173 | self._InSubsection = False\r | |
174 | self._SubsectionType = MODEL_UNKNOWN\r | |
175 | self._SubsectionName = ''\r | |
176 | self._ItemType = MODEL_UNKNOWN\r | |
177 | self._LastItem = -1\r | |
178 | self._Enabled = 0\r | |
179 | self._Finished = False\r | |
180 | self._PostProcessed = False\r | |
181 | # Different version of meta-file has different way to parse.\r | |
182 | self._Version = 0\r | |
183 | \r | |
184 | ## Store the parsed data in table\r | |
185 | def _Store(self, *Args):\r | |
186 | return self._Table.Insert(*Args)\r | |
187 | \r | |
188 | ## Virtual method for starting parse\r | |
189 | def Start(self):\r | |
190 | raise NotImplementedError\r | |
191 | \r | |
192 | ## Notify a post-process is needed\r | |
193 | def DoPostProcess(self):\r | |
194 | self._PostProcessed = False\r | |
195 | \r | |
196 | ## Set parsing complete flag in both class and table\r | |
197 | def _Done(self):\r | |
198 | self._Finished = True\r | |
199 | ## Do not set end flag when processing included files\r | |
200 | if self._From == -1:\r | |
201 | self._Table.SetEndFlag()\r | |
202 | \r | |
203 | def _PostProcess(self):\r | |
204 | self._PostProcessed = True\r | |
205 | \r | |
206 | ## Get the parse complete flag\r | |
207 | def _GetFinished(self):\r | |
208 | return self._Finished\r | |
209 | \r | |
210 | ## Set the complete flag\r | |
211 | def _SetFinished(self, Value):\r | |
212 | self._Finished = Value\r | |
213 | \r | |
214 | ## Use [] style to query data in table, just for readability\r | |
215 | #\r | |
216 | # DataInfo = [data_type, scope1(arch), scope2(platform/moduletype)]\r | |
217 | #\r | |
218 | def __getitem__(self, DataInfo):\r | |
219 | if type(DataInfo) != type(()):\r | |
220 | DataInfo = (DataInfo,)\r | |
221 | \r | |
222 | # Parse the file first, if necessary\r | |
223 | if not self._Finished:\r | |
224 | if self._RawTable.IsIntegrity():\r | |
225 | self._Finished = True\r | |
226 | else:\r | |
227 | self._Table = self._RawTable\r | |
228 | self._PostProcessed = False\r | |
229 | self.Start()\r | |
230 | \r | |
231 | # No specific ARCH or Platform given, use raw data\r | |
232 | if self._RawTable and (len(DataInfo) == 1 or DataInfo[1] == None):\r | |
233 | return self._RawTable.Query(*DataInfo)\r | |
234 | \r | |
235 | # Do post-process if necessary\r | |
236 | if not self._PostProcessed:\r | |
237 | self._PostProcess()\r | |
238 | \r | |
239 | return self._Table.Query(*DataInfo)\r | |
240 | \r | |
241 | ## Data parser for the common format in different type of file\r | |
242 | #\r | |
243 | # The common format in the meatfile is like\r | |
244 | #\r | |
245 | # xxx1 | xxx2 | xxx3\r | |
246 | #\r | |
247 | @ParseMacro\r | |
248 | def _CommonParser(self):\r | |
249 | TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT)\r | |
250 | self._ValueList[0:len(TokenList)] = TokenList\r | |
251 | \r | |
252 | ## Data parser for the format in which there's path\r | |
253 | #\r | |
254 | # Only path can have macro used. So we need to replace them before use.\r | |
255 | #\r | |
256 | @ParseMacro\r | |
257 | def _PathParser(self):\r | |
258 | TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT)\r | |
259 | self._ValueList[0:len(TokenList)] = TokenList\r | |
260 | # Don't do macro replacement for dsc file at this point\r | |
261 | if type(self) != DscParser:\r | |
262 | Macros = self._Macros\r | |
263 | self._ValueList = [ReplaceMacro(Value, Macros) for Value in self._ValueList]\r | |
264 | \r | |
265 | ## Skip unsupported data\r | |
266 | def _Skip(self):\r | |
267 | EdkLogger.warn("Parser", "Unrecognized content", File=self.MetaFile,\r | |
268 | Line=self._LineIndex + 1, ExtraData=self._CurrentLine);\r | |
269 | self._ValueList[0:1] = [self._CurrentLine]\r | |
270 | \r | |
0923aa1c HC |
271 | ## Skip unsupported data for UserExtension Section\r |
272 | def _SkipUserExtension(self):\r | |
273 | self._ValueList[0:1] = [self._CurrentLine]\r | |
274 | \r | |
f51461c8 LG |
275 | ## Section header parser\r |
276 | #\r | |
277 | # The section header is always in following format:\r | |
278 | #\r | |
279 | # [section_name.arch<.platform|module_type>]\r | |
280 | #\r | |
281 | def _SectionHeaderParser(self):\r | |
282 | self._Scope = []\r | |
283 | self._SectionName = ''\r | |
284 | ArchList = set()\r | |
285 | for Item in GetSplitValueList(self._CurrentLine[1:-1], TAB_COMMA_SPLIT):\r | |
286 | if Item == '':\r | |
287 | continue\r | |
288 | ItemList = GetSplitValueList(Item, TAB_SPLIT,2)\r | |
289 | # different section should not mix in one section\r | |
290 | if self._SectionName != '' and self._SectionName != ItemList[0].upper():\r | |
291 | EdkLogger.error('Parser', FORMAT_INVALID, "Different section names in the same section",\r | |
292 | File=self.MetaFile, Line=self._LineIndex + 1, ExtraData=self._CurrentLine)\r | |
293 | self._SectionName = ItemList[0].upper()\r | |
294 | if self._SectionName in self.DataType:\r | |
295 | self._SectionType = self.DataType[self._SectionName]\r | |
296 | # Check if the section name is valid\r | |
297 | if self._SectionName not in SECTIONS_HAVE_ITEM_AFTER_ARCH and len(ItemList) > 3:\r | |
298 | EdkLogger.error("Parser", FORMAT_UNKNOWN_ERROR, "%s is not a valid section name" % Item,\r | |
299 | self.MetaFile, self._LineIndex + 1, self._CurrentLine)\r | |
300 | elif self._Version >= 0x00010005:\r | |
301 | EdkLogger.error("Parser", FORMAT_UNKNOWN_ERROR, "%s is not a valid section name" % Item,\r | |
302 | self.MetaFile, self._LineIndex + 1, self._CurrentLine)\r | |
303 | else:\r | |
304 | self._SectionType = MODEL_UNKNOWN\r | |
305 | \r | |
306 | # S1 is always Arch\r | |
307 | if len(ItemList) > 1:\r | |
308 | S1 = ItemList[1].upper()\r | |
309 | else:\r | |
310 | S1 = 'COMMON'\r | |
311 | ArchList.add(S1)\r | |
312 | \r | |
313 | # S2 may be Platform or ModuleType\r | |
314 | if len(ItemList) > 2:\r | |
315 | if self._SectionName.upper() in SECTIONS_HAVE_ITEM_PCD:\r | |
316 | S2 = ItemList[2]\r | |
317 | else:\r | |
318 | S2 = ItemList[2].upper()\r | |
319 | else:\r | |
320 | S2 = 'COMMON'\r | |
321 | self._Scope.append([S1, S2])\r | |
322 | \r | |
323 | # 'COMMON' must not be used with specific ARCHs at the same section\r | |
324 | if 'COMMON' in ArchList and len(ArchList) > 1:\r | |
325 | EdkLogger.error('Parser', FORMAT_INVALID, "'common' ARCH must not be used with specific ARCHs",\r | |
326 | File=self.MetaFile, Line=self._LineIndex + 1, ExtraData=self._CurrentLine)\r | |
327 | # If the section information is needed later, it should be stored in database\r | |
328 | self._ValueList[0] = self._SectionName\r | |
329 | \r | |
330 | ## [defines] section parser\r | |
331 | @ParseMacro\r | |
332 | def _DefineParser(self):\r | |
333 | TokenList = GetSplitValueList(self._CurrentLine, TAB_EQUAL_SPLIT, 1)\r | |
334 | self._ValueList[1:len(TokenList)] = TokenList\r | |
335 | if not self._ValueList[1]:\r | |
336 | EdkLogger.error('Parser', FORMAT_INVALID, "No name specified",\r | |
337 | ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)\r | |
338 | if not self._ValueList[2]:\r | |
339 | EdkLogger.error('Parser', FORMAT_INVALID, "No value specified",\r | |
340 | ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)\r | |
341 | \r | |
342 | self._ValueList = [ReplaceMacro(Value, self._Macros) for Value in self._ValueList]\r | |
343 | Name, Value = self._ValueList[1], self._ValueList[2]\r | |
344 | # Sometimes, we need to make differences between EDK and EDK2 modules \r | |
345 | if Name == 'INF_VERSION':\r | |
3ab1434a YZ |
346 | if re.match(r'0[xX][\da-f-A-F]{5,8}', Value):\r |
347 | self._Version = int(Value, 0) \r | |
348 | elif re.match(r'\d+\.\d+', Value):\r | |
349 | ValueList = Value.split('.')\r | |
350 | Major = '%04o' % int(ValueList[0], 0)\r | |
351 | Minor = '%04o' % int(ValueList[1], 0)\r | |
352 | self._Version = int('0x' + Major + Minor, 0)\r | |
353 | else:\r | |
f51461c8 LG |
354 | EdkLogger.error('Parser', FORMAT_INVALID, "Invalid version number",\r |
355 | ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)\r | |
356 | \r | |
357 | if type(self) == InfParser and self._Version < 0x00010005:\r | |
358 | # EDK module allows using defines as macros\r | |
359 | self._FileLocalMacros[Name] = Value\r | |
360 | self._Defines[Name] = Value\r | |
361 | \r | |
362 | ## [BuildOptions] section parser\r | |
363 | @ParseMacro\r | |
364 | def _BuildOptionParser(self):\r | |
365 | self._CurrentLine = CleanString(self._CurrentLine, BuildOption=True)\r | |
366 | TokenList = GetSplitValueList(self._CurrentLine, TAB_EQUAL_SPLIT, 1)\r | |
367 | TokenList2 = GetSplitValueList(TokenList[0], ':', 1)\r | |
368 | if len(TokenList2) == 2:\r | |
369 | self._ValueList[0] = TokenList2[0] # toolchain family\r | |
370 | self._ValueList[1] = TokenList2[1] # keys\r | |
371 | else:\r | |
372 | self._ValueList[1] = TokenList[0]\r | |
373 | if len(TokenList) == 2 and type(self) != DscParser: # value\r | |
374 | self._ValueList[2] = ReplaceMacro(TokenList[1], self._Macros)\r | |
375 | \r | |
376 | if self._ValueList[1].count('_') != 4:\r | |
377 | EdkLogger.error(\r | |
378 | 'Parser',\r | |
379 | FORMAT_INVALID,\r | |
380 | "'%s' must be in format of <TARGET>_<TOOLCHAIN>_<ARCH>_<TOOL>_FLAGS" % self._ValueList[1],\r | |
381 | ExtraData=self._CurrentLine,\r | |
382 | File=self.MetaFile,\r | |
383 | Line=self._LineIndex + 1\r | |
384 | )\r | |
82a6a960 BF |
385 | def GetValidExpression(self, TokenSpaceGuid, PcdCName):\r |
386 | return self._Table.GetValidExpression(TokenSpaceGuid, PcdCName)\r | |
f51461c8 LG |
387 | def _GetMacros(self):\r |
388 | Macros = {}\r | |
389 | Macros.update(self._FileLocalMacros)\r | |
390 | Macros.update(self._GetApplicableSectionMacro())\r | |
391 | return Macros\r | |
392 | \r | |
393 | ## Construct section Macro dict \r | |
394 | def _ConstructSectionMacroDict(self, Name, Value):\r | |
395 | ScopeKey = [(Scope[0], Scope[1]) for Scope in self._Scope]\r | |
396 | ScopeKey = tuple(ScopeKey)\r | |
397 | SectionDictKey = self._SectionType, ScopeKey\r | |
398 | #\r | |
399 | # DecParser SectionType is a list, will contain more than one item only in Pcd Section\r | |
400 | # As Pcd section macro usage is not alllowed, so here it is safe\r | |
401 | #\r | |
402 | if type(self) == DecParser:\r | |
403 | SectionDictKey = self._SectionType[0], ScopeKey\r | |
404 | if SectionDictKey not in self._SectionsMacroDict:\r | |
405 | self._SectionsMacroDict[SectionDictKey] = {}\r | |
406 | SectionLocalMacros = self._SectionsMacroDict[SectionDictKey]\r | |
407 | SectionLocalMacros[Name] = Value\r | |
408 | \r | |
409 | ## Get section Macros that are applicable to current line, which may come from other sections \r | |
410 | ## that share the same name while scope is wider\r | |
411 | def _GetApplicableSectionMacro(self):\r | |
412 | Macros = {}\r | |
413 | \r | |
414 | ComComMacroDict = {}\r | |
415 | ComSpeMacroDict = {}\r | |
416 | SpeSpeMacroDict = {}\r | |
417 | \r | |
418 | ActiveSectionType = self._SectionType\r | |
419 | if type(self) == DecParser:\r | |
420 | ActiveSectionType = self._SectionType[0]\r | |
421 | \r | |
422 | for (SectionType, Scope) in self._SectionsMacroDict:\r | |
423 | if SectionType != ActiveSectionType:\r | |
424 | continue\r | |
425 | \r | |
426 | for ActiveScope in self._Scope:\r | |
427 | Scope0, Scope1 = ActiveScope[0], ActiveScope[1]\r | |
428 | if(Scope0, Scope1) not in Scope:\r | |
429 | break\r | |
430 | else:\r | |
431 | SpeSpeMacroDict.update(self._SectionsMacroDict[(SectionType, Scope)])\r | |
432 | \r | |
433 | for ActiveScope in self._Scope:\r | |
434 | Scope0, Scope1 = ActiveScope[0], ActiveScope[1]\r | |
435 | if(Scope0, Scope1) not in Scope and (Scope0, "COMMON") not in Scope and ("COMMON", Scope1) not in Scope:\r | |
436 | break\r | |
437 | else:\r | |
438 | ComSpeMacroDict.update(self._SectionsMacroDict[(SectionType, Scope)])\r | |
439 | \r | |
440 | if ("COMMON", "COMMON") in Scope:\r | |
441 | ComComMacroDict.update(self._SectionsMacroDict[(SectionType, Scope)])\r | |
442 | \r | |
443 | Macros.update(ComComMacroDict)\r | |
444 | Macros.update(ComSpeMacroDict)\r | |
445 | Macros.update(SpeSpeMacroDict)\r | |
446 | \r | |
447 | return Macros\r | |
448 | \r | |
449 | _SectionParser = {}\r | |
450 | Finished = property(_GetFinished, _SetFinished)\r | |
451 | _Macros = property(_GetMacros)\r | |
452 | \r | |
453 | \r | |
454 | ## INF file parser class\r | |
455 | #\r | |
456 | # @param FilePath The path of platform description file\r | |
457 | # @param FileType The raw data of DSC file\r | |
458 | # @param Table Database used to retrieve module/package information\r | |
459 | # @param Macros Macros used for replacement in file\r | |
460 | #\r | |
461 | class InfParser(MetaFileParser):\r | |
462 | # INF file supported data types (one type per section)\r | |
463 | DataType = {\r | |
464 | TAB_UNKNOWN.upper() : MODEL_UNKNOWN,\r | |
465 | TAB_INF_DEFINES.upper() : MODEL_META_DATA_HEADER,\r | |
466 | TAB_DSC_DEFINES_DEFINE : MODEL_META_DATA_DEFINE,\r | |
467 | TAB_BUILD_OPTIONS.upper() : MODEL_META_DATA_BUILD_OPTION,\r | |
468 | TAB_INCLUDES.upper() : MODEL_EFI_INCLUDE,\r | |
469 | TAB_LIBRARIES.upper() : MODEL_EFI_LIBRARY_INSTANCE,\r | |
470 | TAB_LIBRARY_CLASSES.upper() : MODEL_EFI_LIBRARY_CLASS,\r | |
471 | TAB_PACKAGES.upper() : MODEL_META_DATA_PACKAGE,\r | |
472 | TAB_NMAKE.upper() : MODEL_META_DATA_NMAKE,\r | |
473 | TAB_INF_FIXED_PCD.upper() : MODEL_PCD_FIXED_AT_BUILD,\r | |
474 | TAB_INF_PATCH_PCD.upper() : MODEL_PCD_PATCHABLE_IN_MODULE,\r | |
475 | TAB_INF_FEATURE_PCD.upper() : MODEL_PCD_FEATURE_FLAG,\r | |
476 | TAB_INF_PCD_EX.upper() : MODEL_PCD_DYNAMIC_EX,\r | |
477 | TAB_INF_PCD.upper() : MODEL_PCD_DYNAMIC,\r | |
478 | TAB_SOURCES.upper() : MODEL_EFI_SOURCE_FILE,\r | |
479 | TAB_GUIDS.upper() : MODEL_EFI_GUID,\r | |
480 | TAB_PROTOCOLS.upper() : MODEL_EFI_PROTOCOL,\r | |
481 | TAB_PPIS.upper() : MODEL_EFI_PPI,\r | |
482 | TAB_DEPEX.upper() : MODEL_EFI_DEPEX,\r | |
483 | TAB_BINARIES.upper() : MODEL_EFI_BINARY_FILE,\r | |
484 | TAB_USER_EXTENSIONS.upper() : MODEL_META_DATA_USER_EXTENSION\r | |
485 | }\r | |
486 | \r | |
487 | ## Constructor of InfParser\r | |
488 | #\r | |
489 | # Initialize object of InfParser\r | |
490 | #\r | |
491 | # @param FilePath The path of module description file\r | |
492 | # @param FileType The raw data of DSC file\r | |
493 | # @param Table Database used to retrieve module/package information\r | |
494 | # @param Macros Macros used for replacement in file\r | |
495 | #\r | |
496 | def __init__(self, FilePath, FileType, Table):\r | |
497 | # prevent re-initialization\r | |
498 | if hasattr(self, "_Table"):\r | |
499 | return\r | |
500 | MetaFileParser.__init__(self, FilePath, FileType, Table)\r | |
501 | self.PcdsDict = {}\r | |
502 | \r | |
503 | ## Parser starter\r | |
504 | def Start(self):\r | |
505 | NmakeLine = ''\r | |
506 | Content = ''\r | |
507 | try:\r | |
508 | Content = open(str(self.MetaFile), 'r').readlines()\r | |
509 | except:\r | |
510 | EdkLogger.error("Parser", FILE_READ_FAILURE, ExtraData=self.MetaFile)\r | |
511 | \r | |
512 | # parse the file line by line\r | |
513 | IsFindBlockComment = False\r | |
514 | GetHeaderComment = False\r | |
515 | TailComments = []\r | |
516 | SectionComments = []\r | |
517 | Comments = []\r | |
518 | \r | |
519 | for Index in range(0, len(Content)):\r | |
520 | # skip empty, commented, block commented lines\r | |
521 | Line, Comment = CleanString2(Content[Index], AllowCppStyleComment=True)\r | |
522 | NextLine = ''\r | |
523 | if Index + 1 < len(Content):\r | |
524 | NextLine, NextComment = CleanString2(Content[Index + 1])\r | |
525 | if Line == '':\r | |
526 | if Comment:\r | |
527 | Comments.append((Comment, Index + 1))\r | |
528 | elif GetHeaderComment:\r | |
529 | SectionComments.extend(Comments)\r | |
530 | Comments = []\r | |
531 | continue\r | |
532 | if Line.find(DataType.TAB_COMMENT_EDK_START) > -1:\r | |
533 | IsFindBlockComment = True\r | |
534 | continue\r | |
535 | if Line.find(DataType.TAB_COMMENT_EDK_END) > -1:\r | |
536 | IsFindBlockComment = False\r | |
537 | continue\r | |
538 | if IsFindBlockComment:\r | |
539 | continue\r | |
540 | \r | |
541 | self._LineIndex = Index\r | |
542 | self._CurrentLine = Line\r | |
543 | \r | |
544 | # section header\r | |
545 | if Line[0] == TAB_SECTION_START and Line[-1] == TAB_SECTION_END:\r | |
546 | if not GetHeaderComment:\r | |
547 | for Cmt, LNo in Comments:\r | |
548 | self._Store(MODEL_META_DATA_HEADER_COMMENT, Cmt, '', '', 'COMMON',\r | |
549 | 'COMMON', self._Owner[-1], LNo, -1, LNo, -1, 0)\r | |
550 | GetHeaderComment = True\r | |
551 | else:\r | |
552 | TailComments.extend(SectionComments + Comments)\r | |
553 | Comments = []\r | |
554 | self._SectionHeaderParser()\r | |
555 | # Check invalid sections\r | |
556 | if self._Version < 0x00010005:\r | |
557 | if self._SectionType in [MODEL_META_DATA_BUILD_OPTION,\r | |
558 | MODEL_EFI_LIBRARY_CLASS,\r | |
559 | MODEL_META_DATA_PACKAGE,\r | |
560 | MODEL_PCD_FIXED_AT_BUILD,\r | |
561 | MODEL_PCD_PATCHABLE_IN_MODULE,\r | |
562 | MODEL_PCD_FEATURE_FLAG,\r | |
563 | MODEL_PCD_DYNAMIC_EX,\r | |
564 | MODEL_PCD_DYNAMIC,\r | |
565 | MODEL_EFI_GUID,\r | |
566 | MODEL_EFI_PROTOCOL,\r | |
567 | MODEL_EFI_PPI,\r | |
568 | MODEL_META_DATA_USER_EXTENSION]:\r | |
569 | EdkLogger.error('Parser', FORMAT_INVALID,\r | |
570 | "Section [%s] is not allowed in inf file without version" % (self._SectionName),\r | |
571 | ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)\r | |
572 | elif self._SectionType in [MODEL_EFI_INCLUDE,\r | |
573 | MODEL_EFI_LIBRARY_INSTANCE,\r | |
574 | MODEL_META_DATA_NMAKE]:\r | |
575 | EdkLogger.error('Parser', FORMAT_INVALID,\r | |
576 | "Section [%s] is not allowed in inf file with version 0x%08x" % (self._SectionName, self._Version),\r | |
577 | ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)\r | |
578 | continue\r | |
579 | # merge two lines specified by '\' in section NMAKE\r | |
580 | elif self._SectionType == MODEL_META_DATA_NMAKE:\r | |
581 | if Line[-1] == '\\':\r | |
582 | if NextLine == '':\r | |
583 | self._CurrentLine = NmakeLine + Line[0:-1]\r | |
584 | NmakeLine = ''\r | |
585 | else:\r | |
586 | if NextLine[0] == TAB_SECTION_START and NextLine[-1] == TAB_SECTION_END:\r | |
587 | self._CurrentLine = NmakeLine + Line[0:-1]\r | |
588 | NmakeLine = ''\r | |
589 | else:\r | |
590 | NmakeLine = NmakeLine + ' ' + Line[0:-1]\r | |
591 | continue\r | |
592 | else:\r | |
593 | self._CurrentLine = NmakeLine + Line\r | |
594 | NmakeLine = ''\r | |
595 | \r | |
596 | # section content\r | |
597 | self._ValueList = ['', '', '']\r | |
598 | # parse current line, result will be put in self._ValueList\r | |
599 | self._SectionParser[self._SectionType](self)\r | |
600 | if self._ValueList == None or self._ItemType == MODEL_META_DATA_DEFINE:\r | |
601 | self._ItemType = -1\r | |
602 | Comments = []\r | |
603 | continue\r | |
604 | if Comment:\r | |
605 | Comments.append((Comment, Index + 1))\r | |
97fa0ee9 YL |
606 | if GlobalData.gOptions and GlobalData.gOptions.CheckUsage:\r |
607 | CheckInfComment(self._SectionType, Comments, str(self.MetaFile), Index + 1, self._ValueList)\r | |
f51461c8 LG |
608 | #\r |
609 | # Model, Value1, Value2, Value3, Arch, Platform, BelongsToItem=-1,\r | |
610 | # LineBegin=-1, ColumnBegin=-1, LineEnd=-1, ColumnEnd=-1, Enabled=-1\r | |
611 | #\r | |
612 | for Arch, Platform in self._Scope:\r | |
613 | LastItem = self._Store(self._SectionType,\r | |
614 | self._ValueList[0],\r | |
615 | self._ValueList[1],\r | |
616 | self._ValueList[2],\r | |
617 | Arch,\r | |
618 | Platform,\r | |
619 | self._Owner[-1],\r | |
620 | self._LineIndex + 1,\r | |
621 | - 1,\r | |
622 | self._LineIndex + 1,\r | |
623 | - 1,\r | |
624 | 0\r | |
625 | )\r | |
626 | for Comment, LineNo in Comments:\r | |
627 | self._Store(MODEL_META_DATA_COMMENT, Comment, '', '', Arch, Platform,\r | |
628 | LastItem, LineNo, -1, LineNo, -1, 0)\r | |
629 | Comments = []\r | |
630 | SectionComments = []\r | |
631 | TailComments.extend(SectionComments + Comments)\r | |
632 | if IsFindBlockComment:\r | |
633 | EdkLogger.error("Parser", FORMAT_INVALID, "Open block comments (starting with /*) are expected to end with */",\r | |
634 | File=self.MetaFile)\r | |
635 | \r | |
636 | # If there are tail comments in INF file, save to database whatever the comments are\r | |
637 | for Comment in TailComments:\r | |
638 | self._Store(MODEL_META_DATA_TAIL_COMMENT, Comment[0], '', '', 'COMMON',\r | |
639 | 'COMMON', self._Owner[-1], -1, -1, -1, -1, 0)\r | |
640 | self._Done()\r | |
641 | \r | |
642 | ## Data parser for the format in which there's path\r | |
643 | #\r | |
644 | # Only path can have macro used. So we need to replace them before use.\r | |
645 | #\r | |
646 | def _IncludeParser(self):\r | |
647 | TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT)\r | |
648 | self._ValueList[0:len(TokenList)] = TokenList\r | |
649 | Macros = self._Macros\r | |
650 | if Macros:\r | |
651 | for Index in range(0, len(self._ValueList)):\r | |
652 | Value = self._ValueList[Index]\r | |
653 | if not Value:\r | |
654 | continue\r | |
655 | \r | |
656 | if Value.upper().find('$(EFI_SOURCE)\Edk'.upper()) > -1 or Value.upper().find('$(EFI_SOURCE)/Edk'.upper()) > -1:\r | |
657 | Value = '$(EDK_SOURCE)' + Value[17:]\r | |
658 | if Value.find('$(EFI_SOURCE)') > -1 or Value.find('$(EDK_SOURCE)') > -1:\r | |
659 | pass\r | |
660 | elif Value.startswith('.'):\r | |
661 | pass\r | |
662 | elif Value.startswith('$('):\r | |
663 | pass\r | |
664 | else:\r | |
665 | Value = '$(EFI_SOURCE)/' + Value\r | |
666 | \r | |
667 | self._ValueList[Index] = ReplaceMacro(Value, Macros)\r | |
668 | \r | |
669 | ## Parse [Sources] section\r | |
670 | #\r | |
671 | # Only path can have macro used. So we need to replace them before use.\r | |
672 | #\r | |
673 | @ParseMacro\r | |
674 | def _SourceFileParser(self):\r | |
675 | TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT)\r | |
676 | self._ValueList[0:len(TokenList)] = TokenList\r | |
677 | Macros = self._Macros\r | |
678 | # For Acpi tables, remove macro like ' TABLE_NAME=Sata1'\r | |
679 | if 'COMPONENT_TYPE' in Macros:\r | |
680 | if self._Defines['COMPONENT_TYPE'].upper() == 'ACPITABLE':\r | |
681 | self._ValueList[0] = GetSplitValueList(self._ValueList[0], ' ', 1)[0]\r | |
682 | if self._Defines['BASE_NAME'] == 'Microcode':\r | |
683 | pass\r | |
684 | self._ValueList = [ReplaceMacro(Value, Macros) for Value in self._ValueList]\r | |
685 | \r | |
686 | ## Parse [Binaries] section\r | |
687 | #\r | |
688 | # Only path can have macro used. So we need to replace them before use.\r | |
689 | #\r | |
690 | @ParseMacro\r | |
691 | def _BinaryFileParser(self):\r | |
692 | TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT, 2)\r | |
693 | if len(TokenList) < 2:\r | |
694 | EdkLogger.error('Parser', FORMAT_INVALID, "No file type or path specified",\r | |
695 | ExtraData=self._CurrentLine + " (<FileType> | <FilePath> [| <Target>])",\r | |
696 | File=self.MetaFile, Line=self._LineIndex + 1)\r | |
697 | if not TokenList[0]:\r | |
698 | EdkLogger.error('Parser', FORMAT_INVALID, "No file type specified",\r | |
699 | ExtraData=self._CurrentLine + " (<FileType> | <FilePath> [| <Target>])",\r | |
700 | File=self.MetaFile, Line=self._LineIndex + 1)\r | |
701 | if not TokenList[1]:\r | |
702 | EdkLogger.error('Parser', FORMAT_INVALID, "No file path specified",\r | |
703 | ExtraData=self._CurrentLine + " (<FileType> | <FilePath> [| <Target>])",\r | |
704 | File=self.MetaFile, Line=self._LineIndex + 1)\r | |
705 | self._ValueList[0:len(TokenList)] = TokenList\r | |
706 | self._ValueList[1] = ReplaceMacro(self._ValueList[1], self._Macros)\r | |
707 | \r | |
708 | ## [nmake] section parser (Edk.x style only)\r | |
709 | def _NmakeParser(self):\r | |
710 | TokenList = GetSplitValueList(self._CurrentLine, TAB_EQUAL_SPLIT, 1)\r | |
711 | self._ValueList[0:len(TokenList)] = TokenList\r | |
712 | # remove macros\r | |
713 | self._ValueList[1] = ReplaceMacro(self._ValueList[1], self._Macros)\r | |
714 | # remove self-reference in macro setting\r | |
715 | #self._ValueList[1] = ReplaceMacro(self._ValueList[1], {self._ValueList[0]:''})\r | |
716 | \r | |
717 | ## [FixedPcd], [FeaturePcd], [PatchPcd], [Pcd] and [PcdEx] sections parser\r | |
718 | @ParseMacro\r | |
719 | def _PcdParser(self):\r | |
720 | TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT, 1)\r | |
721 | ValueList = GetSplitValueList(TokenList[0], TAB_SPLIT)\r | |
722 | if len(ValueList) != 2:\r | |
723 | EdkLogger.error('Parser', FORMAT_INVALID, "Illegal token space GUID and PCD name format",\r | |
724 | ExtraData=self._CurrentLine + " (<TokenSpaceGuidCName>.<PcdCName>)",\r | |
725 | File=self.MetaFile, Line=self._LineIndex + 1)\r | |
726 | self._ValueList[0:1] = ValueList\r | |
727 | if len(TokenList) > 1:\r | |
728 | self._ValueList[2] = TokenList[1]\r | |
729 | if self._ValueList[0] == '' or self._ValueList[1] == '':\r | |
730 | EdkLogger.error('Parser', FORMAT_INVALID, "No token space GUID or PCD name specified",\r | |
731 | ExtraData=self._CurrentLine + " (<TokenSpaceGuidCName>.<PcdCName>)",\r | |
732 | File=self.MetaFile, Line=self._LineIndex + 1)\r | |
733 | \r | |
734 | # if value are 'True', 'true', 'TRUE' or 'False', 'false', 'FALSE', replace with integer 1 or 0.\r | |
735 | if self._ValueList[2] != '':\r | |
736 | InfPcdValueList = GetSplitValueList(TokenList[1], TAB_VALUE_SPLIT, 1)\r | |
737 | if InfPcdValueList[0] in ['True', 'true', 'TRUE']:\r | |
738 | self._ValueList[2] = TokenList[1].replace(InfPcdValueList[0], '1', 1);\r | |
739 | elif InfPcdValueList[0] in ['False', 'false', 'FALSE']:\r | |
740 | self._ValueList[2] = TokenList[1].replace(InfPcdValueList[0], '0', 1);\r | |
741 | if (self._ValueList[0], self._ValueList[1]) not in self.PcdsDict:\r | |
742 | self.PcdsDict[self._ValueList[0], self._ValueList[1]] = self._SectionType\r | |
743 | elif self.PcdsDict[self._ValueList[0], self._ValueList[1]] != self._SectionType:\r | |
744 | EdkLogger.error('Parser', FORMAT_INVALID, "It is not permissible to list a specified PCD in different PCD type sections.",\r | |
745 | ExtraData=self._CurrentLine + " (<TokenSpaceGuidCName>.<PcdCName>)",\r | |
746 | File=self.MetaFile, Line=self._LineIndex + 1)\r | |
747 | \r | |
748 | ## [depex] section parser\r | |
749 | @ParseMacro\r | |
750 | def _DepexParser(self):\r | |
751 | self._ValueList[0:1] = [self._CurrentLine]\r | |
752 | \r | |
753 | _SectionParser = {\r | |
754 | MODEL_UNKNOWN : MetaFileParser._Skip,\r | |
755 | MODEL_META_DATA_HEADER : MetaFileParser._DefineParser,\r | |
756 | MODEL_META_DATA_BUILD_OPTION : MetaFileParser._BuildOptionParser,\r | |
757 | MODEL_EFI_INCLUDE : _IncludeParser, # for Edk.x modules\r | |
758 | MODEL_EFI_LIBRARY_INSTANCE : MetaFileParser._CommonParser, # for Edk.x modules\r | |
759 | MODEL_EFI_LIBRARY_CLASS : MetaFileParser._PathParser,\r | |
760 | MODEL_META_DATA_PACKAGE : MetaFileParser._PathParser,\r | |
761 | MODEL_META_DATA_NMAKE : _NmakeParser, # for Edk.x modules\r | |
762 | MODEL_PCD_FIXED_AT_BUILD : _PcdParser,\r | |
763 | MODEL_PCD_PATCHABLE_IN_MODULE : _PcdParser,\r | |
764 | MODEL_PCD_FEATURE_FLAG : _PcdParser,\r | |
765 | MODEL_PCD_DYNAMIC_EX : _PcdParser,\r | |
766 | MODEL_PCD_DYNAMIC : _PcdParser,\r | |
767 | MODEL_EFI_SOURCE_FILE : _SourceFileParser,\r | |
768 | MODEL_EFI_GUID : MetaFileParser._CommonParser,\r | |
769 | MODEL_EFI_PROTOCOL : MetaFileParser._CommonParser,\r | |
770 | MODEL_EFI_PPI : MetaFileParser._CommonParser,\r | |
771 | MODEL_EFI_DEPEX : _DepexParser,\r | |
772 | MODEL_EFI_BINARY_FILE : _BinaryFileParser,\r | |
0923aa1c | 773 | MODEL_META_DATA_USER_EXTENSION : MetaFileParser._SkipUserExtension,\r |
f51461c8 LG |
774 | }\r |
775 | \r | |
776 | ## DSC file parser class\r | |
777 | #\r | |
778 | # @param FilePath The path of platform description file\r | |
779 | # @param FileType The raw data of DSC file\r | |
780 | # @param Table Database used to retrieve module/package information\r | |
781 | # @param Macros Macros used for replacement in file\r | |
782 | # @param Owner Owner ID (for sub-section parsing)\r | |
783 | # @param From ID from which the data comes (for !INCLUDE directive)\r | |
784 | #\r | |
785 | class DscParser(MetaFileParser):\r | |
786 | # DSC file supported data types (one type per section)\r | |
787 | DataType = {\r | |
788 | TAB_SKUIDS.upper() : MODEL_EFI_SKU_ID,\r | |
789 | TAB_LIBRARIES.upper() : MODEL_EFI_LIBRARY_INSTANCE,\r | |
790 | TAB_LIBRARY_CLASSES.upper() : MODEL_EFI_LIBRARY_CLASS,\r | |
791 | TAB_BUILD_OPTIONS.upper() : MODEL_META_DATA_BUILD_OPTION,\r | |
792 | TAB_PCDS_FIXED_AT_BUILD_NULL.upper() : MODEL_PCD_FIXED_AT_BUILD,\r | |
793 | TAB_PCDS_PATCHABLE_IN_MODULE_NULL.upper() : MODEL_PCD_PATCHABLE_IN_MODULE,\r | |
794 | TAB_PCDS_FEATURE_FLAG_NULL.upper() : MODEL_PCD_FEATURE_FLAG,\r | |
795 | TAB_PCDS_DYNAMIC_DEFAULT_NULL.upper() : MODEL_PCD_DYNAMIC_DEFAULT,\r | |
796 | TAB_PCDS_DYNAMIC_HII_NULL.upper() : MODEL_PCD_DYNAMIC_HII,\r | |
797 | TAB_PCDS_DYNAMIC_VPD_NULL.upper() : MODEL_PCD_DYNAMIC_VPD,\r | |
798 | TAB_PCDS_DYNAMIC_EX_DEFAULT_NULL.upper() : MODEL_PCD_DYNAMIC_EX_DEFAULT,\r | |
799 | TAB_PCDS_DYNAMIC_EX_HII_NULL.upper() : MODEL_PCD_DYNAMIC_EX_HII,\r | |
800 | TAB_PCDS_DYNAMIC_EX_VPD_NULL.upper() : MODEL_PCD_DYNAMIC_EX_VPD,\r | |
801 | TAB_COMPONENTS.upper() : MODEL_META_DATA_COMPONENT,\r | |
802 | TAB_COMPONENTS_SOURCE_OVERRIDE_PATH.upper() : MODEL_META_DATA_COMPONENT_SOURCE_OVERRIDE_PATH,\r | |
803 | TAB_DSC_DEFINES.upper() : MODEL_META_DATA_HEADER,\r | |
804 | TAB_DSC_DEFINES_DEFINE : MODEL_META_DATA_DEFINE,\r | |
805 | TAB_DSC_DEFINES_EDKGLOBAL : MODEL_META_DATA_GLOBAL_DEFINE,\r | |
806 | TAB_INCLUDE.upper() : MODEL_META_DATA_INCLUDE,\r | |
807 | TAB_IF.upper() : MODEL_META_DATA_CONDITIONAL_STATEMENT_IF,\r | |
808 | TAB_IF_DEF.upper() : MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF,\r | |
809 | TAB_IF_N_DEF.upper() : MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF,\r | |
810 | TAB_ELSE_IF.upper() : MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSEIF,\r | |
811 | TAB_ELSE.upper() : MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE,\r | |
812 | TAB_END_IF.upper() : MODEL_META_DATA_CONDITIONAL_STATEMENT_ENDIF,\r | |
0923aa1c | 813 | TAB_USER_EXTENSIONS.upper() : MODEL_META_DATA_USER_EXTENSION,\r |
f51461c8 LG |
814 | }\r |
815 | \r | |
816 | # Valid names in define section\r | |
817 | DefineKeywords = [\r | |
818 | "DSC_SPECIFICATION",\r | |
819 | "PLATFORM_NAME",\r | |
820 | "PLATFORM_GUID",\r | |
821 | "PLATFORM_VERSION",\r | |
822 | "SKUID_IDENTIFIER",\r | |
823 | "PCD_INFO_GENERATION",\r | |
82a6a960 | 824 | "PCD_VAR_CHECK_GENERATION",\r |
f51461c8 LG |
825 | "SUPPORTED_ARCHITECTURES",\r |
826 | "BUILD_TARGETS",\r | |
827 | "OUTPUT_DIRECTORY",\r | |
828 | "FLASH_DEFINITION",\r | |
829 | "BUILD_NUMBER",\r | |
830 | "RFC_LANGUAGES",\r | |
831 | "ISO_LANGUAGES",\r | |
832 | "TIME_STAMP_FILE",\r | |
833 | "VPD_TOOL_GUID",\r | |
834 | "FIX_LOAD_TOP_MEMORY_ADDRESS"\r | |
835 | ]\r | |
836 | \r | |
97fa0ee9 YL |
837 | SubSectionDefineKeywords = [\r |
838 | "FILE_GUID"\r | |
839 | ]\r | |
840 | \r | |
f51461c8 LG |
841 | SymbolPattern = ValueExpression.SymbolPattern\r |
842 | \r | |
843 | ## Constructor of DscParser\r | |
844 | #\r | |
845 | # Initialize object of DscParser\r | |
846 | #\r | |
847 | # @param FilePath The path of platform description file\r | |
848 | # @param FileType The raw data of DSC file\r | |
849 | # @param Table Database used to retrieve module/package information\r | |
850 | # @param Macros Macros used for replacement in file\r | |
851 | # @param Owner Owner ID (for sub-section parsing)\r | |
852 | # @param From ID from which the data comes (for !INCLUDE directive)\r | |
853 | #\r | |
854 | def __init__(self, FilePath, FileType, Table, Owner= -1, From= -1):\r | |
855 | # prevent re-initialization\r | |
856 | if hasattr(self, "_Table"):\r | |
857 | return\r | |
858 | MetaFileParser.__init__(self, FilePath, FileType, Table, Owner, From)\r | |
859 | self._Version = 0x00010005 # Only EDK2 dsc file is supported\r | |
860 | # to store conditional directive evaluation result\r | |
861 | self._DirectiveStack = []\r | |
862 | self._DirectiveEvalStack = []\r | |
863 | self._Enabled = 1\r | |
864 | \r | |
865 | #\r | |
866 | # Specify whether current line is in uncertain condition\r | |
867 | #\r | |
868 | self._InDirective = -1\r | |
869 | \r | |
870 | # Final valid replacable symbols\r | |
871 | self._Symbols = {}\r | |
872 | #\r | |
873 | # Map the ID between the original table and new table to track\r | |
874 | # the owner item\r | |
875 | #\r | |
876 | self._IdMapping = {-1:-1}\r | |
877 | \r | |
878 | ## Parser starter\r | |
879 | def Start(self):\r | |
880 | Content = ''\r | |
881 | try:\r | |
882 | Content = open(str(self.MetaFile), 'r').readlines()\r | |
883 | except:\r | |
884 | EdkLogger.error("Parser", FILE_READ_FAILURE, ExtraData=self.MetaFile)\r | |
885 | \r | |
886 | OwnerId = {}\r | |
887 | for Index in range(0, len(Content)):\r | |
888 | Line = CleanString(Content[Index])\r | |
889 | # skip empty line\r | |
890 | if Line == '':\r | |
891 | continue\r | |
892 | \r | |
893 | self._CurrentLine = Line\r | |
894 | self._LineIndex = Index\r | |
895 | if self._InSubsection and self._Owner[-1] == -1:\r | |
896 | self._Owner.append(self._LastItem)\r | |
897 | \r | |
898 | # section header\r | |
899 | if Line[0] == TAB_SECTION_START and Line[-1] == TAB_SECTION_END:\r | |
900 | self._SectionType = MODEL_META_DATA_SECTION_HEADER\r | |
901 | # subsection ending\r | |
902 | elif Line[0] == '}' and self._InSubsection:\r | |
903 | self._InSubsection = False\r | |
904 | self._SubsectionType = MODEL_UNKNOWN\r | |
905 | self._SubsectionName = ''\r | |
906 | self._Owner[-1] = -1\r | |
907 | OwnerId = {}\r | |
908 | continue\r | |
909 | # subsection header\r | |
910 | elif Line[0] == TAB_OPTION_START and Line[-1] == TAB_OPTION_END:\r | |
911 | self._SubsectionType = MODEL_META_DATA_SUBSECTION_HEADER\r | |
912 | # directive line\r | |
913 | elif Line[0] == '!':\r | |
914 | self._DirectiveParser()\r | |
915 | continue\r | |
916 | \r | |
917 | if self._InSubsection:\r | |
918 | SectionType = self._SubsectionType\r | |
919 | else:\r | |
920 | SectionType = self._SectionType\r | |
921 | self._ItemType = SectionType\r | |
922 | \r | |
923 | self._ValueList = ['', '', '']\r | |
924 | self._SectionParser[SectionType](self)\r | |
925 | if self._ValueList == None:\r | |
926 | continue\r | |
927 | #\r | |
928 | # Model, Value1, Value2, Value3, Arch, ModuleType, BelongsToItem=-1, BelongsToFile=-1,\r | |
929 | # LineBegin=-1, ColumnBegin=-1, LineEnd=-1, ColumnEnd=-1, Enabled=-1\r | |
930 | #\r | |
931 | for Arch, ModuleType in self._Scope:\r | |
932 | Owner = self._Owner[-1]\r | |
933 | if self._SubsectionType != MODEL_UNKNOWN:\r | |
934 | Owner = OwnerId[Arch]\r | |
935 | self._LastItem = self._Store(\r | |
936 | self._ItemType,\r | |
937 | self._ValueList[0],\r | |
938 | self._ValueList[1],\r | |
939 | self._ValueList[2],\r | |
940 | Arch,\r | |
941 | ModuleType,\r | |
942 | Owner,\r | |
943 | self._From,\r | |
944 | self._LineIndex + 1,\r | |
945 | - 1,\r | |
946 | self._LineIndex + 1,\r | |
947 | - 1,\r | |
948 | self._Enabled\r | |
949 | )\r | |
950 | if self._SubsectionType == MODEL_UNKNOWN and self._InSubsection:\r | |
951 | OwnerId[Arch] = self._LastItem\r | |
952 | \r | |
953 | if self._DirectiveStack:\r | |
954 | Type, Line, Text = self._DirectiveStack[-1]\r | |
955 | EdkLogger.error('Parser', FORMAT_INVALID, "No matching '!endif' found",\r | |
956 | ExtraData=Text, File=self.MetaFile, Line=Line)\r | |
957 | self._Done()\r | |
958 | \r | |
959 | ## <subsection_header> parser\r | |
960 | def _SubsectionHeaderParser(self):\r | |
961 | self._SubsectionName = self._CurrentLine[1:-1].upper()\r | |
962 | if self._SubsectionName in self.DataType:\r | |
963 | self._SubsectionType = self.DataType[self._SubsectionName]\r | |
964 | else:\r | |
965 | self._SubsectionType = MODEL_UNKNOWN\r | |
966 | EdkLogger.warn("Parser", "Unrecognized sub-section", File=self.MetaFile,\r | |
967 | Line=self._LineIndex + 1, ExtraData=self._CurrentLine)\r | |
968 | self._ValueList[0] = self._SubsectionName\r | |
969 | \r | |
970 | ## Directive statement parser\r | |
971 | def _DirectiveParser(self):\r | |
972 | self._ValueList = ['', '', '']\r | |
973 | TokenList = GetSplitValueList(self._CurrentLine, ' ', 1)\r | |
974 | self._ValueList[0:len(TokenList)] = TokenList\r | |
975 | \r | |
976 | # Syntax check\r | |
977 | DirectiveName = self._ValueList[0].upper()\r | |
978 | if DirectiveName not in self.DataType:\r | |
979 | EdkLogger.error("Parser", FORMAT_INVALID, "Unknown directive [%s]" % DirectiveName,\r | |
980 | File=self.MetaFile, Line=self._LineIndex + 1)\r | |
981 | \r | |
982 | if DirectiveName in ['!IF', '!IFDEF', '!IFNDEF']:\r | |
983 | self._InDirective += 1\r | |
984 | \r | |
985 | if DirectiveName in ['!ENDIF']:\r | |
986 | self._InDirective -= 1\r | |
987 | \r | |
988 | if DirectiveName in ['!IF', '!IFDEF', '!INCLUDE', '!IFNDEF', '!ELSEIF'] and self._ValueList[1] == '':\r | |
989 | EdkLogger.error("Parser", FORMAT_INVALID, "Missing expression",\r | |
990 | File=self.MetaFile, Line=self._LineIndex + 1,\r | |
991 | ExtraData=self._CurrentLine)\r | |
992 | \r | |
993 | ItemType = self.DataType[DirectiveName]\r | |
994 | Scope = [['COMMON', 'COMMON']]\r | |
995 | if ItemType == MODEL_META_DATA_INCLUDE:\r | |
996 | Scope = self._Scope\r | |
997 | if ItemType == MODEL_META_DATA_CONDITIONAL_STATEMENT_ENDIF:\r | |
998 | # Remove all directives between !if and !endif, including themselves\r | |
999 | while self._DirectiveStack:\r | |
1000 | # Remove any !else or !elseif\r | |
1001 | DirectiveInfo = self._DirectiveStack.pop()\r | |
1002 | if DirectiveInfo[0] in [MODEL_META_DATA_CONDITIONAL_STATEMENT_IF,\r | |
1003 | MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF,\r | |
1004 | MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF]:\r | |
1005 | break\r | |
1006 | else:\r | |
1007 | EdkLogger.error("Parser", FORMAT_INVALID, "Redundant '!endif'",\r | |
1008 | File=self.MetaFile, Line=self._LineIndex + 1,\r | |
1009 | ExtraData=self._CurrentLine)\r | |
1010 | elif ItemType != MODEL_META_DATA_INCLUDE:\r | |
1011 | # Break if there's a !else is followed by a !elseif\r | |
1012 | if ItemType == MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSEIF and \\r | |
1013 | self._DirectiveStack and \\r | |
1014 | self._DirectiveStack[-1][0] == MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE:\r | |
1015 | EdkLogger.error("Parser", FORMAT_INVALID, "'!elseif' after '!else'",\r | |
1016 | File=self.MetaFile, Line=self._LineIndex + 1,\r | |
1017 | ExtraData=self._CurrentLine)\r | |
1018 | self._DirectiveStack.append((ItemType, self._LineIndex + 1, self._CurrentLine))\r | |
f51461c8 LG |
1019 | \r |
1020 | #\r | |
1021 | # Model, Value1, Value2, Value3, Arch, ModuleType, BelongsToItem=-1, BelongsToFile=-1,\r | |
1022 | # LineBegin=-1, ColumnBegin=-1, LineEnd=-1, ColumnEnd=-1, Enabled=-1\r | |
1023 | #\r | |
1024 | for Arch, ModuleType in Scope:\r | |
1025 | self._LastItem = self._Store(\r | |
1026 | ItemType,\r | |
1027 | self._ValueList[0],\r | |
1028 | self._ValueList[1],\r | |
1029 | self._ValueList[2],\r | |
1030 | Arch,\r | |
1031 | ModuleType,\r | |
1032 | self._Owner[-1],\r | |
1033 | self._From,\r | |
1034 | self._LineIndex + 1,\r | |
1035 | - 1,\r | |
1036 | self._LineIndex + 1,\r | |
1037 | - 1,\r | |
1038 | 0\r | |
1039 | )\r | |
1040 | \r | |
1041 | ## [defines] section parser\r | |
1042 | @ParseMacro\r | |
1043 | def _DefineParser(self):\r | |
1044 | TokenList = GetSplitValueList(self._CurrentLine, TAB_EQUAL_SPLIT, 1)\r | |
1045 | self._ValueList[1:len(TokenList)] = TokenList\r | |
1046 | \r | |
1047 | # Syntax check\r | |
1048 | if not self._ValueList[1]:\r | |
1049 | EdkLogger.error('Parser', FORMAT_INVALID, "No name specified",\r | |
1050 | ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)\r | |
1051 | if not self._ValueList[2]:\r | |
1052 | EdkLogger.error('Parser', FORMAT_INVALID, "No value specified",\r | |
1053 | ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)\r | |
97fa0ee9 YL |
1054 | if (not self._ValueList[1] in self.DefineKeywords and\r |
1055 | (self._InSubsection and self._ValueList[1] not in self.SubSectionDefineKeywords)):\r | |
f51461c8 LG |
1056 | EdkLogger.error('Parser', FORMAT_INVALID,\r |
1057 | "Unknown keyword found: %s. "\r | |
1058 | "If this is a macro you must "\r | |
1059 | "add it as a DEFINE in the DSC" % self._ValueList[1],\r | |
1060 | ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)\r | |
97fa0ee9 YL |
1061 | if not self._InSubsection:\r |
1062 | self._Defines[self._ValueList[1]] = self._ValueList[2]\r | |
f51461c8 LG |
1063 | self._ItemType = self.DataType[TAB_DSC_DEFINES.upper()]\r |
1064 | \r | |
1065 | @ParseMacro\r | |
1066 | def _SkuIdParser(self):\r | |
1067 | TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT)\r | |
1068 | if len(TokenList) != 2:\r | |
1069 | EdkLogger.error('Parser', FORMAT_INVALID, "Correct format is '<Integer>|<UiName>'",\r | |
1070 | ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)\r | |
1071 | self._ValueList[0:len(TokenList)] = TokenList\r | |
1072 | \r | |
1073 | ## Parse Edk style of library modules\r | |
1074 | @ParseMacro\r | |
1075 | def _LibraryInstanceParser(self):\r | |
1076 | self._ValueList[0] = self._CurrentLine\r | |
1077 | \r | |
1078 | ## PCD sections parser\r | |
1079 | #\r | |
1080 | # [PcdsFixedAtBuild]\r | |
1081 | # [PcdsPatchableInModule]\r | |
1082 | # [PcdsFeatureFlag]\r | |
1083 | # [PcdsDynamicEx\r | |
1084 | # [PcdsDynamicExDefault]\r | |
1085 | # [PcdsDynamicExVpd]\r | |
1086 | # [PcdsDynamicExHii]\r | |
1087 | # [PcdsDynamic]\r | |
1088 | # [PcdsDynamicDefault]\r | |
1089 | # [PcdsDynamicVpd]\r | |
1090 | # [PcdsDynamicHii]\r | |
1091 | #\r | |
1092 | @ParseMacro\r | |
1093 | def _PcdParser(self):\r | |
1094 | TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT, 1)\r | |
1095 | self._ValueList[0:1] = GetSplitValueList(TokenList[0], TAB_SPLIT)\r | |
1096 | if len(TokenList) == 2:\r | |
1097 | self._ValueList[2] = TokenList[1]\r | |
1098 | if self._ValueList[0] == '' or self._ValueList[1] == '':\r | |
1099 | EdkLogger.error('Parser', FORMAT_INVALID, "No token space GUID or PCD name specified",\r | |
1100 | ExtraData=self._CurrentLine + " (<TokenSpaceGuidCName>.<TokenCName>|<PcdValue>)",\r | |
1101 | File=self.MetaFile, Line=self._LineIndex + 1)\r | |
1102 | if self._ValueList[2] == '':\r | |
1103 | #\r | |
1104 | # The PCD values are optional for FIXEDATBUILD and PATCHABLEINMODULE\r | |
1105 | #\r | |
1106 | if self._SectionType in (MODEL_PCD_FIXED_AT_BUILD, MODEL_PCD_PATCHABLE_IN_MODULE):\r | |
1107 | return\r | |
1108 | EdkLogger.error('Parser', FORMAT_INVALID, "No PCD value given",\r | |
1109 | ExtraData=self._CurrentLine + " (<TokenSpaceGuidCName>.<TokenCName>|<PcdValue>)",\r | |
1110 | File=self.MetaFile, Line=self._LineIndex + 1)\r | |
1111 | \r | |
1112 | # Validate the datum type of Dynamic Defaul PCD and DynamicEx Default PCD\r | |
1113 | ValueList = GetSplitValueList(self._ValueList[2])\r | |
1114 | if len(ValueList) > 1 and ValueList[1] != TAB_VOID \\r | |
1115 | and self._ItemType in [MODEL_PCD_DYNAMIC_DEFAULT, MODEL_PCD_DYNAMIC_EX_DEFAULT]:\r | |
1116 | EdkLogger.error('Parser', FORMAT_INVALID, "The datum type '%s' of PCD is wrong" % ValueList[1],\r | |
1117 | ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)\r | |
1118 | \r | |
1119 | # if value are 'True', 'true', 'TRUE' or 'False', 'false', 'FALSE', replace with integer 1 or 0.\r | |
1120 | DscPcdValueList = GetSplitValueList(TokenList[1], TAB_VALUE_SPLIT, 1)\r | |
1121 | if DscPcdValueList[0] in ['True', 'true', 'TRUE']:\r | |
1122 | self._ValueList[2] = TokenList[1].replace(DscPcdValueList[0], '1', 1);\r | |
1123 | elif DscPcdValueList[0] in ['False', 'false', 'FALSE']:\r | |
1124 | self._ValueList[2] = TokenList[1].replace(DscPcdValueList[0], '0', 1);\r | |
1125 | \r | |
1126 | \r | |
1127 | ## [components] section parser\r | |
1128 | @ParseMacro\r | |
1129 | def _ComponentParser(self):\r | |
1130 | if self._CurrentLine[-1] == '{':\r | |
1131 | self._ValueList[0] = self._CurrentLine[0:-1].strip()\r | |
1132 | self._InSubsection = True\r | |
1133 | else:\r | |
1134 | self._ValueList[0] = self._CurrentLine\r | |
1135 | \r | |
1136 | ## [LibraryClasses] section\r | |
1137 | @ParseMacro\r | |
1138 | def _LibraryClassParser(self):\r | |
1139 | TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT)\r | |
1140 | if len(TokenList) < 2:\r | |
1141 | EdkLogger.error('Parser', FORMAT_INVALID, "No library class or instance specified",\r | |
1142 | ExtraData=self._CurrentLine + " (<LibraryClassName>|<LibraryInstancePath>)",\r | |
1143 | File=self.MetaFile, Line=self._LineIndex + 1)\r | |
1144 | if TokenList[0] == '':\r | |
1145 | EdkLogger.error('Parser', FORMAT_INVALID, "No library class specified",\r | |
1146 | ExtraData=self._CurrentLine + " (<LibraryClassName>|<LibraryInstancePath>)",\r | |
1147 | File=self.MetaFile, Line=self._LineIndex + 1)\r | |
1148 | if TokenList[1] == '':\r | |
1149 | EdkLogger.error('Parser', FORMAT_INVALID, "No library instance specified",\r | |
1150 | ExtraData=self._CurrentLine + " (<LibraryClassName>|<LibraryInstancePath>)",\r | |
1151 | File=self.MetaFile, Line=self._LineIndex + 1)\r | |
1152 | \r | |
1153 | self._ValueList[0:len(TokenList)] = TokenList\r | |
1154 | \r | |
1155 | def _CompponentSourceOverridePathParser(self):\r | |
1156 | self._ValueList[0] = self._CurrentLine\r | |
1157 | \r | |
1158 | ## [BuildOptions] section parser\r | |
1159 | @ParseMacro\r | |
1160 | def _BuildOptionParser(self):\r | |
1161 | self._CurrentLine = CleanString(self._CurrentLine, BuildOption=True)\r | |
1162 | TokenList = GetSplitValueList(self._CurrentLine, TAB_EQUAL_SPLIT, 1)\r | |
1163 | TokenList2 = GetSplitValueList(TokenList[0], ':', 1)\r | |
1164 | if len(TokenList2) == 2:\r | |
1165 | self._ValueList[0] = TokenList2[0] # toolchain family\r | |
1166 | self._ValueList[1] = TokenList2[1] # keys\r | |
1167 | else:\r | |
1168 | self._ValueList[1] = TokenList[0]\r | |
1169 | if len(TokenList) == 2: # value\r | |
1170 | self._ValueList[2] = TokenList[1]\r | |
1171 | \r | |
1172 | if self._ValueList[1].count('_') != 4:\r | |
1173 | EdkLogger.error(\r | |
1174 | 'Parser',\r | |
1175 | FORMAT_INVALID,\r | |
1176 | "'%s' must be in format of <TARGET>_<TOOLCHAIN>_<ARCH>_<TOOL>_FLAGS" % self._ValueList[1],\r | |
1177 | ExtraData=self._CurrentLine,\r | |
1178 | File=self.MetaFile,\r | |
1179 | Line=self._LineIndex + 1\r | |
1180 | )\r | |
1181 | \r | |
1182 | ## Override parent's method since we'll do all macro replacements in parser\r | |
1183 | def _GetMacros(self):\r | |
1184 | Macros = {}\r | |
1185 | Macros.update(self._FileLocalMacros)\r | |
1186 | Macros.update(self._GetApplicableSectionMacro())\r | |
1187 | Macros.update(GlobalData.gEdkGlobal)\r | |
1188 | Macros.update(GlobalData.gPlatformDefines)\r | |
1189 | Macros.update(GlobalData.gCommandLineDefines)\r | |
1190 | # PCD cannot be referenced in macro definition\r | |
1191 | if self._ItemType not in [MODEL_META_DATA_DEFINE, MODEL_META_DATA_GLOBAL_DEFINE]:\r | |
1192 | Macros.update(self._Symbols)\r | |
1193 | return Macros\r | |
1194 | \r | |
1195 | def _PostProcess(self):\r | |
1196 | Processer = {\r | |
1197 | MODEL_META_DATA_SECTION_HEADER : self.__ProcessSectionHeader,\r | |
1198 | MODEL_META_DATA_SUBSECTION_HEADER : self.__ProcessSubsectionHeader,\r | |
1199 | MODEL_META_DATA_HEADER : self.__ProcessDefine,\r | |
1200 | MODEL_META_DATA_DEFINE : self.__ProcessDefine,\r | |
1201 | MODEL_META_DATA_GLOBAL_DEFINE : self.__ProcessDefine,\r | |
1202 | MODEL_META_DATA_INCLUDE : self.__ProcessDirective,\r | |
1203 | MODEL_META_DATA_CONDITIONAL_STATEMENT_IF : self.__ProcessDirective,\r | |
1204 | MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE : self.__ProcessDirective,\r | |
1205 | MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF : self.__ProcessDirective,\r | |
1206 | MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF : self.__ProcessDirective,\r | |
1207 | MODEL_META_DATA_CONDITIONAL_STATEMENT_ENDIF : self.__ProcessDirective,\r | |
1208 | MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSEIF : self.__ProcessDirective,\r | |
1209 | MODEL_EFI_SKU_ID : self.__ProcessSkuId,\r | |
1210 | MODEL_EFI_LIBRARY_INSTANCE : self.__ProcessLibraryInstance,\r | |
1211 | MODEL_EFI_LIBRARY_CLASS : self.__ProcessLibraryClass,\r | |
1212 | MODEL_PCD_FIXED_AT_BUILD : self.__ProcessPcd,\r | |
1213 | MODEL_PCD_PATCHABLE_IN_MODULE : self.__ProcessPcd,\r | |
1214 | MODEL_PCD_FEATURE_FLAG : self.__ProcessPcd,\r | |
1215 | MODEL_PCD_DYNAMIC_DEFAULT : self.__ProcessPcd,\r | |
1216 | MODEL_PCD_DYNAMIC_HII : self.__ProcessPcd,\r | |
1217 | MODEL_PCD_DYNAMIC_VPD : self.__ProcessPcd,\r | |
1218 | MODEL_PCD_DYNAMIC_EX_DEFAULT : self.__ProcessPcd,\r | |
1219 | MODEL_PCD_DYNAMIC_EX_HII : self.__ProcessPcd,\r | |
1220 | MODEL_PCD_DYNAMIC_EX_VPD : self.__ProcessPcd,\r | |
1221 | MODEL_META_DATA_COMPONENT : self.__ProcessComponent,\r | |
1222 | MODEL_META_DATA_COMPONENT_SOURCE_OVERRIDE_PATH : self.__ProcessSourceOverridePath,\r | |
1223 | MODEL_META_DATA_BUILD_OPTION : self.__ProcessBuildOption,\r | |
1224 | MODEL_UNKNOWN : self._Skip,\r | |
0923aa1c | 1225 | MODEL_META_DATA_USER_EXTENSION : self._SkipUserExtension,\r |
f51461c8 LG |
1226 | }\r |
1227 | \r | |
1228 | self._Table = MetaFileStorage(self._RawTable.Cur, self.MetaFile, MODEL_FILE_DSC, True)\r | |
1229 | self._Table.Create()\r | |
1230 | self._DirectiveStack = []\r | |
1231 | self._DirectiveEvalStack = []\r | |
1232 | self._FileWithError = self.MetaFile\r | |
1233 | self._FileLocalMacros = {}\r | |
1234 | self._SectionsMacroDict = {}\r | |
1235 | GlobalData.gPlatformDefines = {}\r | |
1236 | \r | |
1237 | # Get all macro and PCD which has straitforward value\r | |
1238 | self.__RetrievePcdValue()\r | |
1239 | self._Content = self._RawTable.GetAll()\r | |
1240 | self._ContentIndex = 0\r | |
97fa0ee9 | 1241 | self._InSubsection = False\r |
f51461c8 LG |
1242 | while self._ContentIndex < len(self._Content) :\r |
1243 | Id, self._ItemType, V1, V2, V3, S1, S2, Owner, self._From, \\r | |
1244 | LineStart, ColStart, LineEnd, ColEnd, Enabled = self._Content[self._ContentIndex]\r | |
1245 | \r | |
1246 | if self._From < 0:\r | |
1247 | self._FileWithError = self.MetaFile\r | |
1248 | \r | |
1249 | self._ContentIndex += 1\r | |
1250 | \r | |
1251 | self._Scope = [[S1, S2]]\r | |
1252 | #\r | |
1253 | # For !include directive, handle it specially,\r | |
1254 | # merge arch and module type in case of duplicate items\r | |
1255 | #\r | |
1256 | while self._ItemType == MODEL_META_DATA_INCLUDE:\r | |
1257 | if self._ContentIndex >= len(self._Content):\r | |
1258 | break\r | |
1259 | Record = self._Content[self._ContentIndex]\r | |
1260 | if LineStart == Record[9] and LineEnd == Record[11]:\r | |
1261 | if [Record[5], Record[6]] not in self._Scope:\r | |
1262 | self._Scope.append([Record[5], Record[6]])\r | |
1263 | self._ContentIndex += 1\r | |
1264 | else:\r | |
1265 | break\r | |
1266 | \r | |
1267 | self._LineIndex = LineStart - 1\r | |
1268 | self._ValueList = [V1, V2, V3]\r | |
1269 | \r | |
97fa0ee9 YL |
1270 | if Owner > 0 and Owner in self._IdMapping:\r |
1271 | self._InSubsection = True\r | |
1272 | else:\r | |
1273 | self._InSubsection = False\r | |
f51461c8 LG |
1274 | try:\r |
1275 | Processer[self._ItemType]()\r | |
1276 | except EvaluationException, Excpt:\r | |
1277 | # \r | |
1278 | # Only catch expression evaluation error here. We need to report\r | |
1279 | # the precise number of line on which the error occurred\r | |
1280 | #\r | |
1281 | if hasattr(Excpt, 'Pcd'):\r | |
1282 | if Excpt.Pcd in GlobalData.gPlatformOtherPcds:\r | |
1283 | Info = GlobalData.gPlatformOtherPcds[Excpt.Pcd]\r | |
1284 | EdkLogger.error('Parser', FORMAT_INVALID, "Cannot use this PCD (%s) in an expression as"\r | |
1285 | " it must be defined in a [PcdsFixedAtBuild] or [PcdsFeatureFlag] section"\r | |
1286 | " of the DSC file, and it is currently defined in this section:"\r | |
1287 | " %s, line #: %d." % (Excpt.Pcd, Info[0], Info[1]),\r | |
1288 | File=self._FileWithError, ExtraData=' '.join(self._ValueList),\r | |
1289 | Line=self._LineIndex + 1)\r | |
1290 | else:\r | |
1291 | EdkLogger.error('Parser', FORMAT_INVALID, "PCD (%s) is not defined in DSC file" % Excpt.Pcd,\r | |
1292 | File=self._FileWithError, ExtraData=' '.join(self._ValueList),\r | |
1293 | Line=self._LineIndex + 1)\r | |
1294 | else:\r | |
1295 | EdkLogger.error('Parser', FORMAT_INVALID, "Invalid expression: %s" % str(Excpt),\r | |
1296 | File=self._FileWithError, ExtraData=' '.join(self._ValueList),\r | |
1297 | Line=self._LineIndex + 1)\r | |
1298 | except MacroException, Excpt:\r | |
1299 | EdkLogger.error('Parser', FORMAT_INVALID, str(Excpt),\r | |
1300 | File=self._FileWithError, ExtraData=' '.join(self._ValueList),\r | |
1301 | Line=self._LineIndex + 1)\r | |
1302 | \r | |
1303 | if self._ValueList == None:\r | |
1304 | continue\r | |
1305 | \r | |
1306 | NewOwner = self._IdMapping.get(Owner, -1)\r | |
1307 | self._Enabled = int((not self._DirectiveEvalStack) or (False not in self._DirectiveEvalStack))\r | |
1308 | self._LastItem = self._Store(\r | |
1309 | self._ItemType,\r | |
1310 | self._ValueList[0],\r | |
1311 | self._ValueList[1],\r | |
1312 | self._ValueList[2],\r | |
1313 | S1,\r | |
1314 | S2,\r | |
1315 | NewOwner,\r | |
1316 | self._From,\r | |
1317 | self._LineIndex + 1,\r | |
1318 | - 1,\r | |
1319 | self._LineIndex + 1,\r | |
1320 | - 1,\r | |
1321 | self._Enabled\r | |
1322 | )\r | |
1323 | self._IdMapping[Id] = self._LastItem\r | |
1324 | \r | |
1325 | GlobalData.gPlatformDefines.update(self._FileLocalMacros)\r | |
1326 | self._PostProcessed = True\r | |
1327 | self._Content = None\r | |
1328 | \r | |
1329 | def __ProcessSectionHeader(self):\r | |
1330 | self._SectionName = self._ValueList[0]\r | |
1331 | if self._SectionName in self.DataType:\r | |
1332 | self._SectionType = self.DataType[self._SectionName]\r | |
1333 | else:\r | |
1334 | self._SectionType = MODEL_UNKNOWN\r | |
1335 | \r | |
1336 | def __ProcessSubsectionHeader(self):\r | |
1337 | self._SubsectionName = self._ValueList[0]\r | |
1338 | if self._SubsectionName in self.DataType:\r | |
1339 | self._SubsectionType = self.DataType[self._SubsectionName]\r | |
1340 | else:\r | |
1341 | self._SubsectionType = MODEL_UNKNOWN\r | |
1342 | \r | |
1343 | def __RetrievePcdValue(self):\r | |
f51461c8 LG |
1344 | Content = open(str(self.MetaFile), 'r').readlines()\r |
1345 | GlobalData.gPlatformOtherPcds['DSCFILE'] = str(self.MetaFile)\r | |
1346 | for PcdType in (MODEL_PCD_PATCHABLE_IN_MODULE, MODEL_PCD_DYNAMIC_DEFAULT, MODEL_PCD_DYNAMIC_HII,\r | |
1347 | MODEL_PCD_DYNAMIC_VPD, MODEL_PCD_DYNAMIC_EX_DEFAULT, MODEL_PCD_DYNAMIC_EX_HII,\r | |
1348 | MODEL_PCD_DYNAMIC_EX_VPD):\r | |
1349 | Records = self._RawTable.Query(PcdType, BelongsToItem= -1.0)\r | |
1350 | for TokenSpaceGuid, PcdName, Value, Dummy2, Dummy3, ID, Line in Records:\r | |
1351 | Name = TokenSpaceGuid + '.' + PcdName\r | |
1352 | if Name not in GlobalData.gPlatformOtherPcds:\r | |
1353 | PcdLine = Line\r | |
1354 | while not Content[Line - 1].lstrip().startswith(TAB_SECTION_START):\r | |
1355 | Line -= 1\r | |
1356 | GlobalData.gPlatformOtherPcds[Name] = (CleanString(Content[Line - 1]), PcdLine, PcdType)\r | |
1357 | \r | |
1358 | def __ProcessDefine(self):\r | |
1359 | if not self._Enabled:\r | |
1360 | return\r | |
1361 | \r | |
1362 | Type, Name, Value = self._ValueList\r | |
1363 | Value = ReplaceMacro(Value, self._Macros, False)\r | |
97fa0ee9 YL |
1364 | #\r |
1365 | # If it is <Defines>, return\r | |
1366 | #\r | |
1367 | if self._InSubsection:\r | |
1368 | self._ValueList = [Type, Name, Value]\r | |
1369 | return\r | |
1370 | \r | |
f51461c8 LG |
1371 | if self._ItemType == MODEL_META_DATA_DEFINE:\r |
1372 | if self._SectionType == MODEL_META_DATA_HEADER:\r | |
1373 | self._FileLocalMacros[Name] = Value\r | |
1374 | else:\r | |
1375 | self._ConstructSectionMacroDict(Name, Value)\r | |
1376 | elif self._ItemType == MODEL_META_DATA_GLOBAL_DEFINE:\r | |
1377 | GlobalData.gEdkGlobal[Name] = Value\r | |
1378 | \r | |
1379 | #\r | |
1380 | # Keyword in [Defines] section can be used as Macros\r | |
1381 | #\r | |
1382 | if (self._ItemType == MODEL_META_DATA_HEADER) and (self._SectionType == MODEL_META_DATA_HEADER):\r | |
1383 | self._FileLocalMacros[Name] = Value\r | |
1384 | \r | |
1385 | self._ValueList = [Type, Name, Value]\r | |
1386 | \r | |
1387 | def __ProcessDirective(self):\r | |
1388 | Result = None\r | |
1389 | if self._ItemType in [MODEL_META_DATA_CONDITIONAL_STATEMENT_IF,\r | |
1390 | MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSEIF]:\r | |
1391 | Macros = self._Macros\r | |
1392 | Macros.update(GlobalData.gGlobalDefines)\r | |
1393 | try:\r | |
1394 | Result = ValueExpression(self._ValueList[1], Macros)()\r | |
1395 | except SymbolNotFound, Exc:\r | |
1396 | EdkLogger.debug(EdkLogger.DEBUG_5, str(Exc), self._ValueList[1])\r | |
1397 | Result = False\r | |
1398 | except WrnExpression, Excpt:\r | |
1399 | # \r | |
1400 | # Catch expression evaluation warning here. We need to report\r | |
1401 | # the precise number of line and return the evaluation result\r | |
1402 | #\r | |
1403 | EdkLogger.warn('Parser', "Suspicious expression: %s" % str(Excpt),\r | |
1404 | File=self._FileWithError, ExtraData=' '.join(self._ValueList),\r | |
1405 | Line=self._LineIndex + 1)\r | |
1406 | Result = Excpt.result\r | |
1407 | \r | |
1408 | if self._ItemType in [MODEL_META_DATA_CONDITIONAL_STATEMENT_IF,\r | |
1409 | MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF,\r | |
1410 | MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF]:\r | |
1411 | self._DirectiveStack.append(self._ItemType)\r | |
1412 | if self._ItemType == MODEL_META_DATA_CONDITIONAL_STATEMENT_IF:\r | |
1413 | Result = bool(Result)\r | |
1414 | else:\r | |
1415 | Macro = self._ValueList[1]\r | |
1416 | Macro = Macro[2:-1] if (Macro.startswith("$(") and Macro.endswith(")")) else Macro\r | |
1417 | Result = Macro in self._Macros\r | |
1418 | if self._ItemType == MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF:\r | |
1419 | Result = not Result\r | |
1420 | self._DirectiveEvalStack.append(Result)\r | |
1421 | elif self._ItemType == MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSEIF:\r | |
1422 | self._DirectiveStack.append(self._ItemType)\r | |
1423 | self._DirectiveEvalStack[-1] = not self._DirectiveEvalStack[-1]\r | |
1424 | self._DirectiveEvalStack.append(bool(Result))\r | |
1425 | elif self._ItemType == MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE:\r | |
1426 | self._DirectiveStack.append(self._ItemType)\r | |
1427 | self._DirectiveEvalStack[-1] = not self._DirectiveEvalStack[-1]\r | |
1428 | self._DirectiveEvalStack.append(True)\r | |
1429 | elif self._ItemType == MODEL_META_DATA_CONDITIONAL_STATEMENT_ENDIF:\r | |
1430 | # Back to the nearest !if/!ifdef/!ifndef\r | |
1431 | while self._DirectiveStack:\r | |
1432 | self._DirectiveEvalStack.pop()\r | |
1433 | Directive = self._DirectiveStack.pop()\r | |
1434 | if Directive in [MODEL_META_DATA_CONDITIONAL_STATEMENT_IF,\r | |
1435 | MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF,\r | |
1436 | MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF]:\r | |
1437 | break\r | |
1438 | elif self._ItemType == MODEL_META_DATA_INCLUDE:\r | |
1439 | # The included file must be relative to workspace or same directory as DSC file\r | |
1440 | __IncludeMacros = {}\r | |
1441 | #\r | |
1442 | # Allow using system environment variables in path after !include\r | |
1443 | #\r | |
1444 | __IncludeMacros['WORKSPACE'] = GlobalData.gGlobalDefines['WORKSPACE']\r | |
1445 | if "ECP_SOURCE" in GlobalData.gGlobalDefines.keys():\r | |
1446 | __IncludeMacros['ECP_SOURCE'] = GlobalData.gGlobalDefines['ECP_SOURCE']\r | |
1447 | #\r | |
1448 | # During GenFds phase call DSC parser, will go into this branch.\r | |
1449 | #\r | |
1450 | elif "ECP_SOURCE" in GlobalData.gCommandLineDefines.keys():\r | |
1451 | __IncludeMacros['ECP_SOURCE'] = GlobalData.gCommandLineDefines['ECP_SOURCE']\r | |
1452 | \r | |
1453 | __IncludeMacros['EFI_SOURCE'] = GlobalData.gGlobalDefines['EFI_SOURCE']\r | |
1454 | __IncludeMacros['EDK_SOURCE'] = GlobalData.gGlobalDefines['EDK_SOURCE']\r | |
1455 | #\r | |
1456 | # Allow using MACROs comes from [Defines] section to keep compatible. \r | |
1457 | #\r | |
1458 | __IncludeMacros.update(self._Macros)\r | |
1459 | \r | |
1460 | IncludedFile = NormPath(ReplaceMacro(self._ValueList[1], __IncludeMacros, RaiseError=True))\r | |
1461 | #\r | |
1462 | # First search the include file under the same directory as DSC file\r | |
1463 | #\r | |
1464 | IncludedFile1 = PathClass(IncludedFile, self.MetaFile.Dir)\r | |
1465 | ErrorCode, ErrorInfo1 = IncludedFile1.Validate()\r | |
1466 | if ErrorCode != 0:\r | |
1467 | #\r | |
1468 | # Also search file under the WORKSPACE directory\r | |
1469 | #\r | |
1470 | IncludedFile1 = PathClass(IncludedFile, GlobalData.gWorkspace)\r | |
1471 | ErrorCode, ErrorInfo2 = IncludedFile1.Validate()\r | |
1472 | if ErrorCode != 0:\r | |
1473 | EdkLogger.error('parser', ErrorCode, File=self._FileWithError,\r | |
1474 | Line=self._LineIndex + 1, ExtraData=ErrorInfo1 + "\n" + ErrorInfo2)\r | |
1475 | \r | |
1476 | self._FileWithError = IncludedFile1\r | |
1477 | \r | |
1478 | IncludedFileTable = MetaFileStorage(self._Table.Cur, IncludedFile1, MODEL_FILE_DSC, False)\r | |
1479 | Owner = self._Content[self._ContentIndex - 1][0]\r | |
1480 | Parser = DscParser(IncludedFile1, self._FileType, IncludedFileTable,\r | |
1481 | Owner=Owner, From=Owner)\r | |
1482 | \r | |
118bf096 CS |
1483 | # Does not allow lower level included file to include upper level included file\r |
1484 | if Parser._From != Owner and int(Owner) > int (Parser._From):\r | |
1485 | EdkLogger.error('parser', FILE_ALREADY_EXIST, File=self._FileWithError,\r | |
1486 | Line=self._LineIndex + 1, ExtraData="{0} is already included at a higher level.".format(IncludedFile1))\r | |
1487 | \r | |
1488 | \r | |
f51461c8 LG |
1489 | # set the parser status with current status\r |
1490 | Parser._SectionName = self._SectionName\r | |
1491 | Parser._SectionType = self._SectionType\r | |
1492 | Parser._Scope = self._Scope\r | |
1493 | Parser._Enabled = self._Enabled\r | |
1494 | # Parse the included file\r | |
1495 | Parser.Start()\r | |
1496 | \r | |
1497 | # update current status with sub-parser's status\r | |
1498 | self._SectionName = Parser._SectionName\r | |
1499 | self._SectionType = Parser._SectionType\r | |
1500 | self._Scope = Parser._Scope\r | |
1501 | self._Enabled = Parser._Enabled\r | |
1502 | \r | |
1503 | # Insert all records in the table for the included file into dsc file table\r | |
1504 | Records = IncludedFileTable.GetAll()\r | |
1505 | if Records:\r | |
1506 | self._Content[self._ContentIndex:self._ContentIndex] = Records\r | |
1507 | self._Content.pop(self._ContentIndex - 1)\r | |
1508 | self._ValueList = None\r | |
1509 | self._ContentIndex -= 1\r | |
1510 | \r | |
1511 | def __ProcessSkuId(self):\r | |
1512 | self._ValueList = [ReplaceMacro(Value, self._Macros, RaiseError=True)\r | |
1513 | for Value in self._ValueList]\r | |
1514 | \r | |
1515 | def __ProcessLibraryInstance(self):\r | |
1516 | self._ValueList = [ReplaceMacro(Value, self._Macros) for Value in self._ValueList]\r | |
1517 | \r | |
1518 | def __ProcessLibraryClass(self):\r | |
1519 | self._ValueList[1] = ReplaceMacro(self._ValueList[1], self._Macros, RaiseError=True)\r | |
1520 | \r | |
1521 | def __ProcessPcd(self):\r | |
1522 | if self._ItemType not in [MODEL_PCD_FEATURE_FLAG, MODEL_PCD_FIXED_AT_BUILD]:\r | |
1523 | self._ValueList[2] = ReplaceMacro(self._ValueList[2], self._Macros, RaiseError=True)\r | |
1524 | return\r | |
1525 | \r | |
1526 | ValList, Valid, Index = AnalyzeDscPcd(self._ValueList[2], self._ItemType)\r | |
1527 | if not Valid:\r | |
1528 | EdkLogger.error('build', FORMAT_INVALID, "Pcd format incorrect.", File=self._FileWithError, Line=self._LineIndex+1,\r | |
1529 | ExtraData="%s.%s|%s" % (self._ValueList[0], self._ValueList[1], self._ValueList[2]))\r | |
1530 | PcdValue = ValList[Index]\r | |
1531 | if PcdValue:\r | |
1532 | try:\r | |
1533 | ValList[Index] = ValueExpression(PcdValue, self._Macros)(True)\r | |
1534 | except WrnExpression, Value:\r | |
1535 | ValList[Index] = Value.result\r | |
1536 | \r | |
1537 | if ValList[Index] == 'True':\r | |
1538 | ValList[Index] = '1'\r | |
1539 | if ValList[Index] == 'False':\r | |
1540 | ValList[Index] = '0'\r | |
1541 | \r | |
22a99b87 YL |
1542 | if (not self._DirectiveEvalStack) or (False not in self._DirectiveEvalStack):\r |
1543 | GlobalData.gPlatformPcds[TAB_SPLIT.join(self._ValueList[0:2])] = PcdValue\r | |
1544 | self._Symbols[TAB_SPLIT.join(self._ValueList[0:2])] = PcdValue\r | |
f51461c8 LG |
1545 | self._ValueList[2] = '|'.join(ValList)\r |
1546 | \r | |
1547 | def __ProcessComponent(self):\r | |
1548 | self._ValueList[0] = ReplaceMacro(self._ValueList[0], self._Macros)\r | |
1549 | \r | |
1550 | def __ProcessSourceOverridePath(self):\r | |
1551 | self._ValueList[0] = ReplaceMacro(self._ValueList[0], self._Macros)\r | |
1552 | \r | |
1553 | def __ProcessBuildOption(self):\r | |
1554 | self._ValueList = [ReplaceMacro(Value, self._Macros, RaiseError=False)\r | |
1555 | for Value in self._ValueList]\r | |
1556 | \r | |
1557 | _SectionParser = {\r | |
1558 | MODEL_META_DATA_HEADER : _DefineParser,\r | |
1559 | MODEL_EFI_SKU_ID : _SkuIdParser,\r | |
1560 | MODEL_EFI_LIBRARY_INSTANCE : _LibraryInstanceParser,\r | |
1561 | MODEL_EFI_LIBRARY_CLASS : _LibraryClassParser,\r | |
1562 | MODEL_PCD_FIXED_AT_BUILD : _PcdParser,\r | |
1563 | MODEL_PCD_PATCHABLE_IN_MODULE : _PcdParser,\r | |
1564 | MODEL_PCD_FEATURE_FLAG : _PcdParser,\r | |
1565 | MODEL_PCD_DYNAMIC_DEFAULT : _PcdParser,\r | |
1566 | MODEL_PCD_DYNAMIC_HII : _PcdParser,\r | |
1567 | MODEL_PCD_DYNAMIC_VPD : _PcdParser,\r | |
1568 | MODEL_PCD_DYNAMIC_EX_DEFAULT : _PcdParser,\r | |
1569 | MODEL_PCD_DYNAMIC_EX_HII : _PcdParser,\r | |
1570 | MODEL_PCD_DYNAMIC_EX_VPD : _PcdParser,\r | |
1571 | MODEL_META_DATA_COMPONENT : _ComponentParser,\r | |
1572 | MODEL_META_DATA_COMPONENT_SOURCE_OVERRIDE_PATH : _CompponentSourceOverridePathParser,\r | |
1573 | MODEL_META_DATA_BUILD_OPTION : _BuildOptionParser,\r | |
1574 | MODEL_UNKNOWN : MetaFileParser._Skip,\r | |
0923aa1c | 1575 | MODEL_META_DATA_USER_EXTENSION : MetaFileParser._SkipUserExtension,\r |
f51461c8 LG |
1576 | MODEL_META_DATA_SECTION_HEADER : MetaFileParser._SectionHeaderParser,\r |
1577 | MODEL_META_DATA_SUBSECTION_HEADER : _SubsectionHeaderParser,\r | |
1578 | }\r | |
1579 | \r | |
1580 | _Macros = property(_GetMacros)\r | |
1581 | \r | |
1582 | ## DEC file parser class\r | |
1583 | #\r | |
1584 | # @param FilePath The path of platform description file\r | |
1585 | # @param FileType The raw data of DSC file\r | |
1586 | # @param Table Database used to retrieve module/package information\r | |
1587 | # @param Macros Macros used for replacement in file\r | |
1588 | #\r | |
1589 | class DecParser(MetaFileParser):\r | |
1590 | # DEC file supported data types (one type per section)\r | |
1591 | DataType = {\r | |
1592 | TAB_DEC_DEFINES.upper() : MODEL_META_DATA_HEADER,\r | |
1593 | TAB_DSC_DEFINES_DEFINE : MODEL_META_DATA_DEFINE,\r | |
1594 | TAB_INCLUDES.upper() : MODEL_EFI_INCLUDE,\r | |
1595 | TAB_LIBRARY_CLASSES.upper() : MODEL_EFI_LIBRARY_CLASS,\r | |
1596 | TAB_GUIDS.upper() : MODEL_EFI_GUID,\r | |
1597 | TAB_PPIS.upper() : MODEL_EFI_PPI,\r | |
1598 | TAB_PROTOCOLS.upper() : MODEL_EFI_PROTOCOL,\r | |
1599 | TAB_PCDS_FIXED_AT_BUILD_NULL.upper() : MODEL_PCD_FIXED_AT_BUILD,\r | |
1600 | TAB_PCDS_PATCHABLE_IN_MODULE_NULL.upper() : MODEL_PCD_PATCHABLE_IN_MODULE,\r | |
1601 | TAB_PCDS_FEATURE_FLAG_NULL.upper() : MODEL_PCD_FEATURE_FLAG,\r | |
1602 | TAB_PCDS_DYNAMIC_NULL.upper() : MODEL_PCD_DYNAMIC,\r | |
1603 | TAB_PCDS_DYNAMIC_EX_NULL.upper() : MODEL_PCD_DYNAMIC_EX,\r | |
0923aa1c | 1604 | TAB_USER_EXTENSIONS.upper() : MODEL_META_DATA_USER_EXTENSION,\r |
f51461c8 LG |
1605 | }\r |
1606 | \r | |
1607 | ## Constructor of DecParser\r | |
1608 | #\r | |
1609 | # Initialize object of DecParser\r | |
1610 | #\r | |
1611 | # @param FilePath The path of platform description file\r | |
1612 | # @param FileType The raw data of DSC file\r | |
1613 | # @param Table Database used to retrieve module/package information\r | |
1614 | # @param Macros Macros used for replacement in file\r | |
1615 | #\r | |
1616 | def __init__(self, FilePath, FileType, Table):\r | |
1617 | # prevent re-initialization\r | |
1618 | if hasattr(self, "_Table"):\r | |
1619 | return\r | |
1620 | MetaFileParser.__init__(self, FilePath, FileType, Table, -1)\r | |
1621 | self._Comments = []\r | |
1622 | self._Version = 0x00010005 # Only EDK2 dec file is supported\r | |
1623 | self._AllPCDs = [] # Only for check duplicate PCD\r | |
1624 | \r | |
1625 | ## Parser starter\r | |
1626 | def Start(self):\r | |
1627 | Content = ''\r | |
1628 | try:\r | |
1629 | Content = open(str(self.MetaFile), 'r').readlines()\r | |
1630 | except:\r | |
1631 | EdkLogger.error("Parser", FILE_READ_FAILURE, ExtraData=self.MetaFile)\r | |
1632 | \r | |
1633 | for Index in range(0, len(Content)):\r | |
1634 | Line, Comment = CleanString2(Content[Index])\r | |
1635 | self._CurrentLine = Line\r | |
1636 | self._LineIndex = Index\r | |
1637 | \r | |
1638 | # save comment for later use\r | |
1639 | if Comment:\r | |
1640 | self._Comments.append((Comment, self._LineIndex + 1))\r | |
1641 | # skip empty line\r | |
1642 | if Line == '':\r | |
1643 | continue\r | |
1644 | \r | |
1645 | # section header\r | |
1646 | if Line[0] == TAB_SECTION_START and Line[-1] == TAB_SECTION_END:\r | |
1647 | self._SectionHeaderParser()\r | |
1648 | self._Comments = []\r | |
1649 | continue\r | |
1650 | elif len(self._SectionType) == 0:\r | |
1651 | self._Comments = []\r | |
1652 | continue\r | |
1653 | \r | |
1654 | # section content\r | |
1655 | self._ValueList = ['', '', '']\r | |
1656 | self._SectionParser[self._SectionType[0]](self)\r | |
1657 | if self._ValueList == None or self._ItemType == MODEL_META_DATA_DEFINE:\r | |
1658 | self._ItemType = -1\r | |
1659 | self._Comments = []\r | |
1660 | continue\r | |
1661 | \r | |
1662 | #\r | |
1663 | # Model, Value1, Value2, Value3, Arch, BelongsToItem=-1, LineBegin=-1,\r | |
1664 | # ColumnBegin=-1, LineEnd=-1, ColumnEnd=-1, FeatureFlag='', Enabled=-1\r | |
1665 | #\r | |
1666 | for Arch, ModuleType, Type in self._Scope:\r | |
1667 | self._LastItem = self._Store(\r | |
1668 | Type,\r | |
1669 | self._ValueList[0],\r | |
1670 | self._ValueList[1],\r | |
1671 | self._ValueList[2],\r | |
1672 | Arch,\r | |
1673 | ModuleType,\r | |
1674 | self._Owner[-1],\r | |
1675 | self._LineIndex + 1,\r | |
1676 | - 1,\r | |
1677 | self._LineIndex + 1,\r | |
1678 | - 1,\r | |
1679 | 0\r | |
1680 | )\r | |
1681 | for Comment, LineNo in self._Comments:\r | |
1682 | self._Store(\r | |
1683 | MODEL_META_DATA_COMMENT,\r | |
1684 | Comment,\r | |
1685 | self._ValueList[0],\r | |
1686 | self._ValueList[1],\r | |
1687 | Arch,\r | |
1688 | ModuleType,\r | |
1689 | self._LastItem,\r | |
1690 | LineNo,\r | |
1691 | - 1,\r | |
1692 | LineNo,\r | |
1693 | - 1,\r | |
1694 | 0\r | |
1695 | )\r | |
1696 | self._Comments = []\r | |
1697 | self._Done()\r | |
1698 | \r | |
1699 | \r | |
1700 | ## Section header parser\r | |
1701 | #\r | |
1702 | # The section header is always in following format:\r | |
1703 | #\r | |
1704 | # [section_name.arch<.platform|module_type>]\r | |
1705 | #\r | |
1706 | def _SectionHeaderParser(self):\r | |
1707 | self._Scope = []\r | |
1708 | self._SectionName = ''\r | |
1709 | self._SectionType = []\r | |
1710 | ArchList = set()\r | |
1711 | Line = self._CurrentLine.replace("%s%s" % (TAB_COMMA_SPLIT, TAB_SPACE_SPLIT), TAB_COMMA_SPLIT)\r | |
1712 | for Item in Line[1:-1].split(TAB_COMMA_SPLIT):\r | |
1713 | if Item == '':\r | |
1714 | EdkLogger.error("Parser", FORMAT_UNKNOWN_ERROR,\r | |
1715 | "section name can NOT be empty or incorrectly use separator comma",\r | |
1716 | self.MetaFile, self._LineIndex + 1, self._CurrentLine)\r | |
1717 | ItemList = Item.split(TAB_SPLIT)\r | |
1718 | \r | |
1719 | # different types of PCD are permissible in one section\r | |
1720 | self._SectionName = ItemList[0].upper()\r | |
1721 | if self._SectionName in self.DataType:\r | |
1722 | if self.DataType[self._SectionName] not in self._SectionType:\r | |
1723 | self._SectionType.append(self.DataType[self._SectionName])\r | |
1724 | else:\r | |
1725 | EdkLogger.error("Parser", FORMAT_UNKNOWN_ERROR, "%s is not a valid section name" % Item,\r | |
1726 | self.MetaFile, self._LineIndex + 1, self._CurrentLine)\r | |
1727 | \r | |
1728 | if MODEL_PCD_FEATURE_FLAG in self._SectionType and len(self._SectionType) > 1:\r | |
1729 | EdkLogger.error(\r | |
1730 | 'Parser',\r | |
1731 | FORMAT_INVALID,\r | |
1732 | "%s must not be in the same section of other types of PCD" % TAB_PCDS_FEATURE_FLAG_NULL,\r | |
1733 | File=self.MetaFile,\r | |
1734 | Line=self._LineIndex + 1,\r | |
1735 | ExtraData=self._CurrentLine\r | |
1736 | )\r | |
1737 | # S1 is always Arch\r | |
1738 | if len(ItemList) > 1:\r | |
1739 | S1 = ItemList[1].upper()\r | |
1740 | else:\r | |
1741 | S1 = 'COMMON'\r | |
1742 | ArchList.add(S1)\r | |
1743 | # S2 may be Platform or ModuleType\r | |
1744 | if len(ItemList) > 2:\r | |
1745 | S2 = ItemList[2].upper()\r | |
1746 | else:\r | |
1747 | S2 = 'COMMON'\r | |
1748 | if [S1, S2, self.DataType[self._SectionName]] not in self._Scope:\r | |
1749 | self._Scope.append([S1, S2, self.DataType[self._SectionName]])\r | |
1750 | \r | |
1751 | # 'COMMON' must not be used with specific ARCHs at the same section\r | |
1752 | if 'COMMON' in ArchList and len(ArchList) > 1:\r | |
1753 | EdkLogger.error('Parser', FORMAT_INVALID, "'common' ARCH must not be used with specific ARCHs",\r | |
1754 | File=self.MetaFile, Line=self._LineIndex + 1, ExtraData=self._CurrentLine)\r | |
1755 | \r | |
1756 | ## [guids], [ppis] and [protocols] section parser\r | |
1757 | @ParseMacro\r | |
1758 | def _GuidParser(self):\r | |
1759 | TokenList = GetSplitValueList(self._CurrentLine, TAB_EQUAL_SPLIT, 1)\r | |
1760 | if len(TokenList) < 2:\r | |
1761 | EdkLogger.error('Parser', FORMAT_INVALID, "No GUID name or value specified",\r | |
1762 | ExtraData=self._CurrentLine + " (<CName> = <GuidValueInCFormat>)",\r | |
1763 | File=self.MetaFile, Line=self._LineIndex + 1)\r | |
1764 | if TokenList[0] == '':\r | |
1765 | EdkLogger.error('Parser', FORMAT_INVALID, "No GUID name specified",\r | |
1766 | ExtraData=self._CurrentLine + " (<CName> = <GuidValueInCFormat>)",\r | |
1767 | File=self.MetaFile, Line=self._LineIndex + 1)\r | |
1768 | if TokenList[1] == '':\r | |
1769 | EdkLogger.error('Parser', FORMAT_INVALID, "No GUID value specified",\r | |
1770 | ExtraData=self._CurrentLine + " (<CName> = <GuidValueInCFormat>)",\r | |
1771 | File=self.MetaFile, Line=self._LineIndex + 1)\r | |
1772 | if TokenList[1][0] != '{' or TokenList[1][-1] != '}' or GuidStructureStringToGuidString(TokenList[1]) == '':\r | |
1773 | EdkLogger.error('Parser', FORMAT_INVALID, "Invalid GUID value format",\r | |
1774 | ExtraData=self._CurrentLine + \\r | |
1775 | " (<CName> = <GuidValueInCFormat:{8,4,4,{2,2,2,2,2,2,2,2}}>)",\r | |
1776 | File=self.MetaFile, Line=self._LineIndex + 1)\r | |
1777 | self._ValueList[0] = TokenList[0]\r | |
1778 | self._ValueList[1] = TokenList[1]\r | |
1779 | \r | |
1780 | ## PCD sections parser\r | |
1781 | #\r | |
1782 | # [PcdsFixedAtBuild]\r | |
1783 | # [PcdsPatchableInModule]\r | |
1784 | # [PcdsFeatureFlag]\r | |
1785 | # [PcdsDynamicEx\r | |
1786 | # [PcdsDynamic]\r | |
1787 | #\r | |
1788 | @ParseMacro\r | |
1789 | def _PcdParser(self):\r | |
1790 | TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT, 1)\r | |
1791 | self._ValueList[0:1] = GetSplitValueList(TokenList[0], TAB_SPLIT)\r | |
1792 | ValueRe = re.compile(r'^[a-zA-Z_][a-zA-Z0-9_]*')\r | |
1793 | # check PCD information\r | |
1794 | if self._ValueList[0] == '' or self._ValueList[1] == '':\r | |
1795 | EdkLogger.error('Parser', FORMAT_INVALID, "No token space GUID or PCD name specified",\r | |
1796 | ExtraData=self._CurrentLine + \\r | |
1797 | " (<TokenSpaceGuidCName>.<PcdCName>|<DefaultValue>|<DatumType>|<Token>)",\r | |
1798 | File=self.MetaFile, Line=self._LineIndex + 1)\r | |
1799 | # check format of token space GUID CName\r | |
1800 | if not ValueRe.match(self._ValueList[0]):\r | |
1801 | EdkLogger.error('Parser', FORMAT_INVALID, "The format of the token space GUID CName is invalid. The correct format is '(a-zA-Z_)[a-zA-Z0-9_]*'",\r | |
1802 | ExtraData=self._CurrentLine + \\r | |
1803 | " (<TokenSpaceGuidCName>.<PcdCName>|<DefaultValue>|<DatumType>|<Token>)",\r | |
1804 | File=self.MetaFile, Line=self._LineIndex + 1)\r | |
1805 | # check format of PCD CName\r | |
1806 | if not ValueRe.match(self._ValueList[1]):\r | |
1807 | EdkLogger.error('Parser', FORMAT_INVALID, "The format of the PCD CName is invalid. The correct format is '(a-zA-Z_)[a-zA-Z0-9_]*'",\r | |
1808 | ExtraData=self._CurrentLine + \\r | |
1809 | " (<TokenSpaceGuidCName>.<PcdCName>|<DefaultValue>|<DatumType>|<Token>)",\r | |
1810 | File=self.MetaFile, Line=self._LineIndex + 1)\r | |
1811 | # check PCD datum information\r | |
1812 | if len(TokenList) < 2 or TokenList[1] == '':\r | |
1813 | EdkLogger.error('Parser', FORMAT_INVALID, "No PCD Datum information given",\r | |
1814 | ExtraData=self._CurrentLine + \\r | |
1815 | " (<TokenSpaceGuidCName>.<PcdCName>|<DefaultValue>|<DatumType>|<Token>)",\r | |
1816 | File=self.MetaFile, Line=self._LineIndex + 1)\r | |
1817 | \r | |
1818 | \r | |
1819 | ValueRe = re.compile(r'^\s*L?\".*\|.*\"')\r | |
1820 | PtrValue = ValueRe.findall(TokenList[1])\r | |
1821 | \r | |
1822 | # Has VOID* type string, may contain "|" character in the string. \r | |
1823 | if len(PtrValue) != 0:\r | |
1824 | ptrValueList = re.sub(ValueRe, '', TokenList[1])\r | |
1825 | ValueList = GetSplitValueList(ptrValueList)\r | |
1826 | ValueList[0] = PtrValue[0]\r | |
1827 | else:\r | |
1828 | ValueList = GetSplitValueList(TokenList[1])\r | |
1829 | \r | |
1830 | \r | |
1831 | # check if there's enough datum information given\r | |
1832 | if len(ValueList) != 3:\r | |
1833 | EdkLogger.error('Parser', FORMAT_INVALID, "Invalid PCD Datum information given",\r | |
1834 | ExtraData=self._CurrentLine + \\r | |
1835 | " (<TokenSpaceGuidCName>.<PcdCName>|<DefaultValue>|<DatumType>|<Token>)",\r | |
1836 | File=self.MetaFile, Line=self._LineIndex + 1)\r | |
1837 | # check default value\r | |
1838 | if ValueList[0] == '':\r | |
1839 | EdkLogger.error('Parser', FORMAT_INVALID, "Missing DefaultValue in PCD Datum information",\r | |
1840 | ExtraData=self._CurrentLine + \\r | |
1841 | " (<TokenSpaceGuidCName>.<PcdCName>|<DefaultValue>|<DatumType>|<Token>)",\r | |
1842 | File=self.MetaFile, Line=self._LineIndex + 1)\r | |
1843 | # check datum type\r | |
1844 | if ValueList[1] == '':\r | |
1845 | EdkLogger.error('Parser', FORMAT_INVALID, "Missing DatumType in PCD Datum information",\r | |
1846 | ExtraData=self._CurrentLine + \\r | |
1847 | " (<TokenSpaceGuidCName>.<PcdCName>|<DefaultValue>|<DatumType>|<Token>)",\r | |
1848 | File=self.MetaFile, Line=self._LineIndex + 1)\r | |
1849 | # check token of the PCD\r | |
1850 | if ValueList[2] == '':\r | |
1851 | EdkLogger.error('Parser', FORMAT_INVALID, "Missing Token in PCD Datum information",\r | |
1852 | ExtraData=self._CurrentLine + \\r | |
1853 | " (<TokenSpaceGuidCName>.<PcdCName>|<DefaultValue>|<DatumType>|<Token>)",\r | |
1854 | File=self.MetaFile, Line=self._LineIndex + 1)\r | |
1855 | # check format of default value against the datum type\r | |
1856 | IsValid, Cause = CheckPcdDatum(ValueList[1], ValueList[0])\r | |
1857 | if not IsValid:\r | |
1858 | EdkLogger.error('Parser', FORMAT_INVALID, Cause, ExtraData=self._CurrentLine,\r | |
1859 | File=self.MetaFile, Line=self._LineIndex + 1)\r | |
1860 | \r | |
1861 | if ValueList[0] in ['True', 'true', 'TRUE']:\r | |
1862 | ValueList[0] = '1'\r | |
1863 | elif ValueList[0] in ['False', 'false', 'FALSE']:\r | |
1864 | ValueList[0] = '0'\r | |
1865 | \r | |
1866 | # check for duplicate PCD definition\r | |
1867 | if (self._Scope[0], self._ValueList[0], self._ValueList[1]) in self._AllPCDs:\r | |
1868 | EdkLogger.error('Parser', FORMAT_INVALID,\r | |
1869 | "The same PCD name and GUID have been already defined",\r | |
1870 | ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)\r | |
1871 | else:\r | |
1872 | self._AllPCDs.append((self._Scope[0], self._ValueList[0], self._ValueList[1]))\r | |
1873 | \r | |
1874 | self._ValueList[2] = ValueList[0].strip() + '|' + ValueList[1].strip() + '|' + ValueList[2].strip()\r | |
1875 | \r | |
1876 | _SectionParser = {\r | |
1877 | MODEL_META_DATA_HEADER : MetaFileParser._DefineParser,\r | |
1878 | MODEL_EFI_INCLUDE : MetaFileParser._PathParser,\r | |
1879 | MODEL_EFI_LIBRARY_CLASS : MetaFileParser._PathParser,\r | |
1880 | MODEL_EFI_GUID : _GuidParser,\r | |
1881 | MODEL_EFI_PPI : _GuidParser,\r | |
1882 | MODEL_EFI_PROTOCOL : _GuidParser,\r | |
1883 | MODEL_PCD_FIXED_AT_BUILD : _PcdParser,\r | |
1884 | MODEL_PCD_PATCHABLE_IN_MODULE : _PcdParser,\r | |
1885 | MODEL_PCD_FEATURE_FLAG : _PcdParser,\r | |
1886 | MODEL_PCD_DYNAMIC : _PcdParser,\r | |
1887 | MODEL_PCD_DYNAMIC_EX : _PcdParser,\r | |
1888 | MODEL_UNKNOWN : MetaFileParser._Skip,\r | |
0923aa1c | 1889 | MODEL_META_DATA_USER_EXTENSION : MetaFileParser._SkipUserExtension,\r |
f51461c8 LG |
1890 | }\r |
1891 | \r | |
1892 | ##\r | |
1893 | #\r | |
1894 | # This acts like the main() function for the script, unless it is 'import'ed into another\r | |
1895 | # script.\r | |
1896 | #\r | |
1897 | if __name__ == '__main__':\r | |
1898 | pass\r | |
1899 | \r |