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