]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/Workspace/MetaFileParser.py
Sync EDKII BaseTools to BaseTools project r1937.
[mirror_edk2.git] / BaseTools / Source / Python / Workspace / MetaFileParser.py
1 ## @file
2 # This file is used to parse meta files
3 #
4 # Copyright (c) 2008 - 2010, Intel Corporation
5 # All rights reserved. This program and the accompanying materials
6 # are licensed and made available under the terms and conditions of the BSD License
7 # which accompanies this distribution. The full text of the license may be found at
8 # http://opensource.org/licenses/bsd-license.php
9 #
10 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 #
13
14 ##
15 # Import Modules
16 #
17 import os
18 import time
19 import copy
20
21 import Common.EdkLogger as EdkLogger
22 from CommonDataClass.DataClass import *
23 from Common.DataType import *
24 from Common.String import *
25 from Common.Misc import Blist, GuidStructureStringToGuidString, CheckPcdDatum
26
27 ## Base class of parser
28 #
29 # This class is used for derivation purpose. The specific parser for one kind
30 # type file must derive this class and implement some public interfaces.
31 #
32 # @param FilePath The path of platform description file
33 # @param FileType The raw data of DSC file
34 # @param Table Database used to retrieve module/package information
35 # @param Macros Macros used for replacement in file
36 # @param Owner Owner ID (for sub-section parsing)
37 # @param From ID from which the data comes (for !INCLUDE directive)
38 #
39 class MetaFileParser(object):
40 # data type (file content) for specific file type
41 DataType = {}
42
43 # Parser objects used to implement singleton
44 MetaFiles = {}
45
46 ## Factory method
47 #
48 # One file, one parser object. This factory method makes sure that there's
49 # only one object constructed for one meta file.
50 #
51 # @param Class class object of real AutoGen class
52 # (InfParser, DecParser or DscParser)
53 # @param FilePath The path of meta file
54 # @param *args The specific class related parameters
55 # @param **kwargs The specific class related dict parameters
56 #
57 def __new__(Class, FilePath, *args, **kwargs):
58 if FilePath in Class.MetaFiles:
59 return Class.MetaFiles[FilePath]
60 else:
61 ParserObject = super(MetaFileParser, Class).__new__(Class)
62 Class.MetaFiles[FilePath] = ParserObject
63 return ParserObject
64
65 ## Constructor of MetaFileParser
66 #
67 # Initialize object of MetaFileParser
68 #
69 # @param FilePath The path of platform description file
70 # @param FileType The raw data of DSC file
71 # @param Table Database used to retrieve module/package information
72 # @param Macros Macros used for replacement in file
73 # @param Owner Owner ID (for sub-section parsing)
74 # @param From ID from which the data comes (for !INCLUDE directive)
75 #
76 def __init__(self, FilePath, FileType, Table, Macros=None, Owner=-1, From=-1):
77 # prevent re-initialization
78 if hasattr(self, "_Table"):
79 return
80 self._Table = Table
81 self._FileType = FileType
82 self.MetaFile = FilePath
83 self._FileDir = os.path.dirname(self.MetaFile)
84 self._Macros = copy.copy(Macros)
85
86 # for recursive parsing
87 self._Owner = Owner
88 self._From = From
89
90 # parsr status for parsing
91 self._Content = None
92 self._ValueList = ['', '', '', '', '']
93 self._Scope = []
94 self._LineIndex = 0
95 self._CurrentLine = ''
96 self._SectionType = MODEL_UNKNOWN
97 self._SectionName = ''
98 self._InSubsection = False
99 self._SubsectionType = MODEL_UNKNOWN
100 self._SubsectionName = ''
101 self._LastItem = -1
102 self._Enabled = 0
103 self._Finished = False
104
105 ## Store the parsed data in table
106 def _Store(self, *Args):
107 return self._Table.Insert(*Args)
108
109 ## Virtual method for starting parse
110 def Start(self):
111 raise NotImplementedError
112
113 ## Set parsing complete flag in both class and table
114 def _Done(self):
115 self._Finished = True
116 ## Do not set end flag when processing included files
117 if self._From == -1:
118 self._Table.SetEndFlag()
119
120 ## Return the table containg parsed data
121 #
122 # If the parse complete flag is not set, this method will try to parse the
123 # file before return the table
124 #
125 def _GetTable(self):
126 if not self._Finished:
127 self.Start()
128 return self._Table
129
130 ## Get the parse complete flag
131 def _GetFinished(self):
132 return self._Finished
133
134 ## Set the complete flag
135 def _SetFinished(self, Value):
136 self._Finished = Value
137
138 ## Use [] style to query data in table, just for readability
139 #
140 # DataInfo = [data_type, scope1(arch), scope2(platform,moduletype)]
141 #
142 def __getitem__(self, DataInfo):
143 if type(DataInfo) != type(()):
144 DataInfo = (DataInfo,)
145 return self.Table.Query(*DataInfo)
146
147 ## Data parser for the common format in different type of file
148 #
149 # The common format in the meatfile is like
150 #
151 # xxx1 | xxx2 | xxx3
152 #
153 def _CommonParser(self):
154 TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT)
155 self._ValueList[0:len(TokenList)] = TokenList
156
157 ## Data parser for the format in which there's path
158 #
159 # Only path can have macro used. So we need to replace them before use.
160 #
161 def _PathParser(self):
162 TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT)
163 self._ValueList[0:len(TokenList)] = TokenList
164 if len(self._Macros) > 0:
165 for Index in range(0, len(self._ValueList)):
166 Value = self._ValueList[Index]
167 if Value == None or Value == '':
168 continue
169 self._ValueList[Index] = NormPath(Value, self._Macros)
170
171 ## Skip unsupported data
172 def _Skip(self):
173 EdkLogger.warn("Parser", "Unrecognized content", File=self.MetaFile,
174 Line=self._LineIndex+1, ExtraData=self._CurrentLine);
175 self._ValueList[0:1] = [self._CurrentLine]
176
177 ## Section header parser
178 #
179 # The section header is always in following format:
180 #
181 # [section_name.arch<.platform|module_type>]
182 #
183 def _SectionHeaderParser(self):
184 self._Scope = []
185 self._SectionName = ''
186 ArchList = set()
187 for Item in GetSplitValueList(self._CurrentLine[1:-1], TAB_COMMA_SPLIT):
188 if Item == '':
189 continue
190 ItemList = GetSplitValueList(Item, TAB_SPLIT)
191 # different section should not mix in one section
192 if self._SectionName != '' and self._SectionName != ItemList[0].upper():
193 EdkLogger.error('Parser', FORMAT_INVALID, "Different section names in the same section",
194 File=self.MetaFile, Line=self._LineIndex+1, ExtraData=self._CurrentLine)
195 self._SectionName = ItemList[0].upper()
196 if self._SectionName in self.DataType:
197 self._SectionType = self.DataType[self._SectionName]
198 else:
199 self._SectionType = MODEL_UNKNOWN
200 EdkLogger.warn("Parser", "Unrecognized section", File=self.MetaFile,
201 Line=self._LineIndex+1, ExtraData=self._CurrentLine)
202 # S1 is always Arch
203 if len(ItemList) > 1:
204 S1 = ItemList[1].upper()
205 else:
206 S1 = 'COMMON'
207 ArchList.add(S1)
208 # S2 may be Platform or ModuleType
209 if len(ItemList) > 2:
210 S2 = ItemList[2].upper()
211 else:
212 S2 = 'COMMON'
213 self._Scope.append([S1, S2])
214
215 # 'COMMON' must not be used with specific ARCHs at the same section
216 if 'COMMON' in ArchList and len(ArchList) > 1:
217 EdkLogger.error('Parser', FORMAT_INVALID, "'common' ARCH must not be used with specific ARCHs",
218 File=self.MetaFile, Line=self._LineIndex+1, ExtraData=self._CurrentLine)
219
220 ## [defines] section parser
221 def _DefineParser(self):
222 TokenList = GetSplitValueList(self._CurrentLine, TAB_EQUAL_SPLIT, 1)
223 self._ValueList[0:len(TokenList)] = TokenList
224 if self._ValueList[1] == '':
225 EdkLogger.error('Parser', FORMAT_INVALID, "No value specified",
226 ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1)
227
228 ## DEFINE name=value parser
229 def _MacroParser(self):
230 TokenList = GetSplitValueList(self._CurrentLine, ' ', 1)
231 MacroType = TokenList[0]
232 if len(TokenList) < 2 or TokenList[1] == '':
233 EdkLogger.error('Parser', FORMAT_INVALID, "No macro name/value given",
234 ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1)
235 TokenList = GetSplitValueList(TokenList[1], TAB_EQUAL_SPLIT, 1)
236 if TokenList[0] == '':
237 EdkLogger.error('Parser', FORMAT_INVALID, "No macro name given",
238 ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1)
239
240 # Macros defined in the command line override ones defined in the meta-data file
241 if not TokenList[0] in self._Macros:
242 if len(TokenList) == 1:
243 self._Macros[TokenList[0]] = ''
244 else:
245 # keep the macro definition for later use
246 self._Macros[TokenList[0]] = ReplaceMacro(TokenList[1], self._Macros, False)
247
248 return TokenList[0], self._Macros[TokenList[0]]
249
250 ## [BuildOptions] section parser
251 def _BuildOptionParser(self):
252 TokenList = GetSplitValueList(self._CurrentLine, TAB_EQUAL_SPLIT, 1)
253 TokenList2 = GetSplitValueList(TokenList[0], ':', 1)
254 if len(TokenList2) == 2:
255 self._ValueList[0] = TokenList2[0] # toolchain family
256 self._ValueList[1] = TokenList2[1] # keys
257 else:
258 self._ValueList[1] = TokenList[0]
259 if len(TokenList) == 2: # value
260 self._ValueList[2] = ReplaceMacro(TokenList[1], self._Macros)
261
262 if self._ValueList[1].count('_') != 4:
263 EdkLogger.error(
264 'Parser',
265 FORMAT_INVALID,
266 "'%s' must be in format of <TARGET>_<TOOLCHAIN>_<ARCH>_<TOOL>_FLAGS" % self._ValueList[1],
267 ExtraData=self._CurrentLine,
268 File=self.MetaFile,
269 Line=self._LineIndex+1
270 )
271
272 _SectionParser = {}
273 Table = property(_GetTable)
274 Finished = property(_GetFinished, _SetFinished)
275
276
277 ## INF file parser class
278 #
279 # @param FilePath The path of platform description file
280 # @param FileType The raw data of DSC file
281 # @param Table Database used to retrieve module/package information
282 # @param Macros Macros used for replacement in file
283 #
284 class InfParser(MetaFileParser):
285 # INF file supported data types (one type per section)
286 DataType = {
287 TAB_UNKNOWN.upper() : MODEL_UNKNOWN,
288 TAB_INF_DEFINES.upper() : MODEL_META_DATA_HEADER,
289 TAB_BUILD_OPTIONS.upper() : MODEL_META_DATA_BUILD_OPTION,
290 TAB_INCLUDES.upper() : MODEL_EFI_INCLUDE,
291 TAB_LIBRARIES.upper() : MODEL_EFI_LIBRARY_INSTANCE,
292 TAB_LIBRARY_CLASSES.upper() : MODEL_EFI_LIBRARY_CLASS,
293 TAB_PACKAGES.upper() : MODEL_META_DATA_PACKAGE,
294 TAB_NMAKE.upper() : MODEL_META_DATA_NMAKE,
295 TAB_INF_FIXED_PCD.upper() : MODEL_PCD_FIXED_AT_BUILD,
296 TAB_INF_PATCH_PCD.upper() : MODEL_PCD_PATCHABLE_IN_MODULE,
297 TAB_INF_FEATURE_PCD.upper() : MODEL_PCD_FEATURE_FLAG,
298 TAB_INF_PCD_EX.upper() : MODEL_PCD_DYNAMIC_EX,
299 TAB_INF_PCD.upper() : MODEL_PCD_DYNAMIC,
300 TAB_SOURCES.upper() : MODEL_EFI_SOURCE_FILE,
301 TAB_GUIDS.upper() : MODEL_EFI_GUID,
302 TAB_PROTOCOLS.upper() : MODEL_EFI_PROTOCOL,
303 TAB_PPIS.upper() : MODEL_EFI_PPI,
304 TAB_DEPEX.upper() : MODEL_EFI_DEPEX,
305 TAB_BINARIES.upper() : MODEL_EFI_BINARY_FILE,
306 TAB_USER_EXTENSIONS.upper() : MODEL_META_DATA_USER_EXTENSION
307 }
308
309 ## Constructor of InfParser
310 #
311 # Initialize object of InfParser
312 #
313 # @param FilePath The path of module description file
314 # @param FileType The raw data of DSC file
315 # @param Table Database used to retrieve module/package information
316 # @param Macros Macros used for replacement in file
317 #
318 def __init__(self, FilePath, FileType, Table, Macros=None):
319 MetaFileParser.__init__(self, FilePath, FileType, Table, Macros)
320
321 ## Parser starter
322 def Start(self):
323 NmakeLine = ''
324 try:
325 self._Content = open(self.MetaFile, 'r').readlines()
326 except:
327 EdkLogger.error("Parser", FILE_READ_FAILURE, ExtraData=self.MetaFile)
328
329 # parse the file line by line
330 IsFindBlockComment = False
331
332 for Index in range(0, len(self._Content)):
333 # skip empty, commented, block commented lines
334 Line = CleanString(self._Content[Index], AllowCppStyleComment=True)
335 NextLine = ''
336 if Index + 1 < len(self._Content):
337 NextLine = CleanString(self._Content[Index + 1])
338 if Line == '':
339 continue
340 if Line.find(DataType.TAB_COMMENT_R8_START) > -1:
341 IsFindBlockComment = True
342 continue
343 if Line.find(DataType.TAB_COMMENT_R8_END) > -1:
344 IsFindBlockComment = False
345 continue
346 if IsFindBlockComment:
347 continue
348
349 self._LineIndex = Index
350 self._CurrentLine = Line
351
352 # section header
353 if Line[0] == TAB_SECTION_START and Line[-1] == TAB_SECTION_END:
354 self._SectionHeaderParser()
355 continue
356 # merge two lines specified by '\' in section NMAKE
357 elif self._SectionType == MODEL_META_DATA_NMAKE:
358 if Line[-1] == '\\':
359 if NextLine == '':
360 self._CurrentLine = NmakeLine + Line[0:-1]
361 NmakeLine = ''
362 else:
363 if NextLine[0] == TAB_SECTION_START and NextLine[-1] == TAB_SECTION_END:
364 self._CurrentLine = NmakeLine + Line[0:-1]
365 NmakeLine = ''
366 else:
367 NmakeLine = NmakeLine + ' ' + Line[0:-1]
368 continue
369 else:
370 self._CurrentLine = NmakeLine + Line
371 NmakeLine = ''
372 elif Line.upper().startswith('DEFINE '):
373 # file private macros
374 self._MacroParser()
375 continue
376
377 # section content
378 self._ValueList = ['','','']
379 # parse current line, result will be put in self._ValueList
380 self._SectionParser[self._SectionType](self)
381 if self._ValueList == None:
382 continue
383 #
384 # Model, Value1, Value2, Value3, Arch, Platform, BelongsToItem=-1,
385 # LineBegin=-1, ColumnBegin=-1, LineEnd=-1, ColumnEnd=-1, Enabled=-1
386 #
387 for Arch, Platform in self._Scope:
388 self._Store(self._SectionType,
389 self._ValueList[0],
390 self._ValueList[1],
391 self._ValueList[2],
392 Arch,
393 Platform,
394 self._Owner,
395 self._LineIndex+1,
396 -1,
397 self._LineIndex+1,
398 -1,
399 0
400 )
401 if IsFindBlockComment:
402 EdkLogger.error("Parser", FORMAT_INVALID, "Open block comments (starting with /*) are expected to end with */",
403 File=self.MetaFile)
404 self._Done()
405
406 ## Data parser for the format in which there's path
407 #
408 # Only path can have macro used. So we need to replace them before use.
409 #
410 def _IncludeParser(self):
411 TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT)
412 self._ValueList[0:len(TokenList)] = TokenList
413 if len(self._Macros) > 0:
414 for Index in range(0, len(self._ValueList)):
415 Value = self._ValueList[Index]
416 if Value.upper().find('$(EFI_SOURCE)\Edk'.upper()) > -1 or Value.upper().find('$(EFI_SOURCE)/Edk'.upper()) > -1:
417 Value = '$(EDK_SOURCE)' + Value[17:]
418 if Value.find('$(EFI_SOURCE)') > -1 or Value.find('$(EDK_SOURCE)') > -1:
419 pass
420 elif Value.startswith('.'):
421 pass
422 elif Value.startswith('$('):
423 pass
424 else:
425 Value = '$(EFI_SOURCE)/' + Value
426
427 if Value == None or Value == '':
428 continue
429 self._ValueList[Index] = NormPath(Value, self._Macros)
430
431 ## Parse [Sources] section
432 #
433 # Only path can have macro used. So we need to replace them before use.
434 #
435 def _SourceFileParser(self):
436 TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT)
437 self._ValueList[0:len(TokenList)] = TokenList
438 # For Acpi tables, remove macro like ' TABLE_NAME=Sata1'
439 if 'COMPONENT_TYPE' in self._Macros:
440 if self._Macros['COMPONENT_TYPE'].upper() == 'ACPITABLE':
441 self._ValueList[0] = GetSplitValueList(self._ValueList[0], ' ', 1)[0]
442 if self._Macros['BASE_NAME'] == 'Microcode':
443 pass
444 if len(self._Macros) > 0:
445 for Index in range(0, len(self._ValueList)):
446 Value = self._ValueList[Index]
447 if Value == None or Value == '':
448 continue
449 self._ValueList[Index] = NormPath(Value, self._Macros)
450
451 ## Parse [Binaries] section
452 #
453 # Only path can have macro used. So we need to replace them before use.
454 #
455 def _BinaryFileParser(self):
456 TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT, 2)
457 if len(TokenList) < 2:
458 EdkLogger.error('Parser', FORMAT_INVALID, "No file type or path specified",
459 ExtraData=self._CurrentLine + " (<FileType> | <FilePath> [| <Target>])",
460 File=self.MetaFile, Line=self._LineIndex+1)
461 if not TokenList[0]:
462 EdkLogger.error('Parser', FORMAT_INVALID, "No file type specified",
463 ExtraData=self._CurrentLine + " (<FileType> | <FilePath> [| <Target>])",
464 File=self.MetaFile, Line=self._LineIndex+1)
465 if not TokenList[1]:
466 EdkLogger.error('Parser', FORMAT_INVALID, "No file path specified",
467 ExtraData=self._CurrentLine + " (<FileType> | <FilePath> [| <Target>])",
468 File=self.MetaFile, Line=self._LineIndex+1)
469 self._ValueList[0:len(TokenList)] = TokenList
470 self._ValueList[1] = NormPath(self._ValueList[1], self._Macros)
471
472 ## [defines] section parser
473 def _DefineParser(self):
474 TokenList = GetSplitValueList(self._CurrentLine, TAB_EQUAL_SPLIT, 1)
475 self._ValueList[0:len(TokenList)] = TokenList
476 self._Macros[TokenList[0]] = ReplaceMacro(TokenList[1], self._Macros, False)
477 if self._ValueList[1] == '':
478 EdkLogger.error('Parser', FORMAT_INVALID, "No value specified",
479 ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1)
480
481 ## [nmake] section parser (R8.x style only)
482 def _NmakeParser(self):
483 TokenList = GetSplitValueList(self._CurrentLine, TAB_EQUAL_SPLIT, 1)
484 self._ValueList[0:len(TokenList)] = TokenList
485 # remove macros
486 self._ValueList[1] = ReplaceMacro(self._ValueList[1], self._Macros, False)
487 # remove self-reference in macro setting
488 #self._ValueList[1] = ReplaceMacro(self._ValueList[1], {self._ValueList[0]:''})
489
490 ## [FixedPcd], [FeaturePcd], [PatchPcd], [Pcd] and [PcdEx] sections parser
491 def _PcdParser(self):
492 TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT, 1)
493 self._ValueList[0:1] = GetSplitValueList(TokenList[0], TAB_SPLIT)
494 if len(TokenList) > 1:
495 self._ValueList[2] = TokenList[1]
496 if self._ValueList[0] == '' or self._ValueList[1] == '':
497 EdkLogger.error('Parser', FORMAT_INVALID, "No token space GUID or PCD name specified",
498 ExtraData=self._CurrentLine + " (<TokenSpaceGuidCName>.<PcdCName>)",
499 File=self.MetaFile, Line=self._LineIndex+1)
500
501 ## [depex] section parser
502 def _DepexParser(self):
503 self._ValueList[0:1] = [self._CurrentLine]
504
505 _SectionParser = {
506 MODEL_UNKNOWN : MetaFileParser._Skip,
507 MODEL_META_DATA_HEADER : _DefineParser,
508 MODEL_META_DATA_BUILD_OPTION : MetaFileParser._BuildOptionParser,
509 MODEL_EFI_INCLUDE : _IncludeParser, # for R8.x modules
510 MODEL_EFI_LIBRARY_INSTANCE : MetaFileParser._CommonParser, # for R8.x modules
511 MODEL_EFI_LIBRARY_CLASS : MetaFileParser._PathParser,
512 MODEL_META_DATA_PACKAGE : MetaFileParser._PathParser,
513 MODEL_META_DATA_NMAKE : _NmakeParser, # for R8.x modules
514 MODEL_PCD_FIXED_AT_BUILD : _PcdParser,
515 MODEL_PCD_PATCHABLE_IN_MODULE : _PcdParser,
516 MODEL_PCD_FEATURE_FLAG : _PcdParser,
517 MODEL_PCD_DYNAMIC_EX : _PcdParser,
518 MODEL_PCD_DYNAMIC : _PcdParser,
519 MODEL_EFI_SOURCE_FILE : _SourceFileParser,
520 MODEL_EFI_GUID : MetaFileParser._CommonParser,
521 MODEL_EFI_PROTOCOL : MetaFileParser._CommonParser,
522 MODEL_EFI_PPI : MetaFileParser._CommonParser,
523 MODEL_EFI_DEPEX : _DepexParser,
524 MODEL_EFI_BINARY_FILE : _BinaryFileParser,
525 MODEL_META_DATA_USER_EXTENSION : MetaFileParser._Skip,
526 }
527
528 ## DSC file parser class
529 #
530 # @param FilePath The path of platform description file
531 # @param FileType The raw data of DSC file
532 # @param Table Database used to retrieve module/package information
533 # @param Macros Macros used for replacement in file
534 # @param Owner Owner ID (for sub-section parsing)
535 # @param From ID from which the data comes (for !INCLUDE directive)
536 #
537 class DscParser(MetaFileParser):
538 # DSC file supported data types (one type per section)
539 DataType = {
540 TAB_SKUIDS.upper() : MODEL_EFI_SKU_ID,
541 TAB_LIBRARIES.upper() : MODEL_EFI_LIBRARY_INSTANCE,
542 TAB_LIBRARY_CLASSES.upper() : MODEL_EFI_LIBRARY_CLASS,
543 TAB_BUILD_OPTIONS.upper() : MODEL_META_DATA_BUILD_OPTION,
544 TAB_PCDS_FIXED_AT_BUILD_NULL.upper() : MODEL_PCD_FIXED_AT_BUILD,
545 TAB_PCDS_PATCHABLE_IN_MODULE_NULL.upper() : MODEL_PCD_PATCHABLE_IN_MODULE,
546 TAB_PCDS_FEATURE_FLAG_NULL.upper() : MODEL_PCD_FEATURE_FLAG,
547 TAB_PCDS_DYNAMIC_DEFAULT_NULL.upper() : MODEL_PCD_DYNAMIC_DEFAULT,
548 TAB_PCDS_DYNAMIC_HII_NULL.upper() : MODEL_PCD_DYNAMIC_HII,
549 TAB_PCDS_DYNAMIC_VPD_NULL.upper() : MODEL_PCD_DYNAMIC_VPD,
550 TAB_PCDS_DYNAMIC_EX_DEFAULT_NULL.upper() : MODEL_PCD_DYNAMIC_EX_DEFAULT,
551 TAB_PCDS_DYNAMIC_EX_HII_NULL.upper() : MODEL_PCD_DYNAMIC_EX_HII,
552 TAB_PCDS_DYNAMIC_EX_VPD_NULL.upper() : MODEL_PCD_DYNAMIC_EX_VPD,
553 TAB_COMPONENTS.upper() : MODEL_META_DATA_COMPONENT,
554 TAB_COMPONENTS_SOURCE_OVERRIDE_PATH.upper() : MODEL_META_DATA_COMPONENT_SOURCE_OVERRIDE_PATH,
555 TAB_DSC_DEFINES.upper() : MODEL_META_DATA_HEADER,
556 TAB_INCLUDE.upper() : MODEL_META_DATA_INCLUDE,
557 TAB_IF.upper() : MODEL_META_DATA_CONDITIONAL_STATEMENT_IF,
558 TAB_IF_DEF.upper() : MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF,
559 TAB_IF_N_DEF.upper() : MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF,
560 TAB_ELSE_IF.upper() : MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSEIF,
561 TAB_ELSE.upper() : MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE,
562 TAB_END_IF.upper() : MODEL_META_DATA_CONDITIONAL_STATEMENT_ENDIF,
563 }
564
565 # sections which allow "!include" directive
566 _IncludeAllowedSection = [
567 TAB_LIBRARIES.upper(),
568 TAB_LIBRARY_CLASSES.upper(),
569 TAB_SKUIDS.upper(),
570 TAB_COMPONENTS.upper(),
571 TAB_BUILD_OPTIONS.upper(),
572 TAB_PCDS_FIXED_AT_BUILD_NULL.upper(),
573 TAB_PCDS_PATCHABLE_IN_MODULE_NULL.upper(),
574 TAB_PCDS_FEATURE_FLAG_NULL.upper(),
575 TAB_PCDS_DYNAMIC_DEFAULT_NULL.upper(),
576 TAB_PCDS_DYNAMIC_HII_NULL.upper(),
577 TAB_PCDS_DYNAMIC_VPD_NULL.upper(),
578 TAB_PCDS_DYNAMIC_EX_DEFAULT_NULL.upper(),
579 TAB_PCDS_DYNAMIC_EX_HII_NULL.upper(),
580 TAB_PCDS_DYNAMIC_EX_VPD_NULL.upper(),
581 ]
582
583 # operators which can be used in "!if/!ifdef/!ifndef" directives
584 _OP_ = {
585 "!" : lambda a: not a,
586 "!=" : lambda a,b: a!=b,
587 "==" : lambda a,b: a==b,
588 ">" : lambda a,b: a>b,
589 "<" : lambda a,b: a<b,
590 "=>" : lambda a,b: a>=b,
591 ">=" : lambda a,b: a>=b,
592 "<=" : lambda a,b: a<=b,
593 "=<" : lambda a,b: a<=b,
594 }
595
596 ## Constructor of DscParser
597 #
598 # Initialize object of DscParser
599 #
600 # @param FilePath The path of platform description file
601 # @param FileType The raw data of DSC file
602 # @param Table Database used to retrieve module/package information
603 # @param Macros Macros used for replacement in file
604 # @param Owner Owner ID (for sub-section parsing)
605 # @param From ID from which the data comes (for !INCLUDE directive)
606 #
607 def __init__(self, FilePath, FileType, Table, Macros=None, Owner=-1, From=-1):
608 MetaFileParser.__init__(self, FilePath, FileType, Table, Macros, Owner, From)
609 # to store conditional directive evaluation result
610 self._Eval = Blist()
611
612 ## Parser starter
613 def Start(self):
614 try:
615 if self._Content == None:
616 self._Content = open(self.MetaFile, 'r').readlines()
617 except:
618 EdkLogger.error("Parser", FILE_READ_FAILURE, ExtraData=self.MetaFile)
619
620 for Index in range(0, len(self._Content)):
621 Line = CleanString(self._Content[Index])
622 # skip empty line
623 if Line == '':
624 continue
625 self._CurrentLine = Line
626 self._LineIndex = Index
627 if self._InSubsection and self._Owner == -1:
628 self._Owner = self._LastItem
629
630 # section header
631 if Line[0] == TAB_SECTION_START and Line[-1] == TAB_SECTION_END:
632 self._SectionHeaderParser()
633 continue
634 # subsection ending
635 elif Line[0] == '}':
636 self._InSubsection = False
637 self._SubsectionType = MODEL_UNKNOWN
638 self._SubsectionName = ''
639 self._Owner = -1
640 continue
641 # subsection header
642 elif Line[0] == TAB_OPTION_START and Line[-1] == TAB_OPTION_END:
643 self._SubsectionHeaderParser()
644 continue
645 # directive line
646 elif Line[0] == '!':
647 self._DirectiveParser()
648 continue
649 # file private macros
650 elif Line.upper().startswith('DEFINE '):
651 self._MacroParser()
652 continue
653 elif Line.upper().startswith('EDK_GLOBAL '):
654 (Name, Value) = self._MacroParser()
655 for Arch, ModuleType in self._Scope:
656 self._LastItem = self._Store(
657 MODEL_META_DATA_DEFINE,
658 Name,
659 Value,
660 '',
661 Arch,
662 'COMMON',
663 self._Owner,
664 self._From,
665 self._LineIndex+1,
666 -1,
667 self._LineIndex+1,
668 -1,
669 self._Enabled
670 )
671 continue
672
673 # section content
674 if self._InSubsection:
675 SectionType = self._SubsectionType
676 SectionName = self._SubsectionName
677 else:
678 SectionType = self._SectionType
679 SectionName = self._SectionName
680
681 self._ValueList = ['', '', '']
682 self._SectionParser[SectionType](self)
683 if self._ValueList == None:
684 continue
685
686 #
687 # Model, Value1, Value2, Value3, Arch, ModuleType, BelongsToItem=-1, BelongsToFile=-1,
688 # LineBegin=-1, ColumnBegin=-1, LineEnd=-1, ColumnEnd=-1, Enabled=-1
689 #
690 for Arch, ModuleType in self._Scope:
691 self._LastItem = self._Store(
692 SectionType,
693 self._ValueList[0],
694 self._ValueList[1],
695 self._ValueList[2],
696 Arch,
697 ModuleType,
698 self._Owner,
699 self._From,
700 self._LineIndex+1,
701 -1,
702 self._LineIndex+1,
703 -1,
704 self._Enabled
705 )
706 self._Done()
707
708 ## [defines] section parser
709 def _DefineParser(self):
710 TokenList = GetSplitValueList(self._CurrentLine, TAB_EQUAL_SPLIT, 1)
711 if len(TokenList) < 2:
712 EdkLogger.error('Parser', FORMAT_INVALID, "No value specified",
713 ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1)
714 # 'FLASH_DEFINITION', 'OUTPUT_DIRECTORY' need special processing
715 if TokenList[0] in ['FLASH_DEFINITION', 'OUTPUT_DIRECTORY']:
716 TokenList[1] = NormPath(TokenList[1], self._Macros)
717 self._ValueList[0:len(TokenList)] = TokenList
718
719 ## <subsection_header> parser
720 def _SubsectionHeaderParser(self):
721 self._SubsectionName = self._CurrentLine[1:-1].upper()
722 if self._SubsectionName in self.DataType:
723 self._SubsectionType = self.DataType[self._SubsectionName]
724 else:
725 self._SubsectionType = MODEL_UNKNOWN
726 EdkLogger.warn("Parser", "Unrecognized sub-section", File=self.MetaFile,
727 Line=self._LineIndex+1, ExtraData=self._CurrentLine)
728
729 ## Directive statement parser
730 def _DirectiveParser(self):
731 self._ValueList = ['','','']
732 TokenList = GetSplitValueList(self._CurrentLine, ' ', 1)
733 self._ValueList[0:len(TokenList)] = TokenList
734 DirectiveName = self._ValueList[0].upper()
735 if DirectiveName not in self.DataType:
736 EdkLogger.error("Parser", FORMAT_INVALID, "Unknown directive [%s]" % DirectiveName,
737 File=self.MetaFile, Line=self._LineIndex+1)
738 if DirectiveName in ['!IF', '!IFDEF', '!INCLUDE', '!IFNDEF', '!ELSEIF'] and self._ValueList[1] == '':
739 EdkLogger.error("Parser", FORMAT_INVALID, "Missing expression",
740 File=self.MetaFile, Line=self._LineIndex+1,
741 ExtraData=self._CurrentLine)
742 # keep the directive in database first
743 self._LastItem = self._Store(
744 self.DataType[DirectiveName],
745 self._ValueList[0],
746 self._ValueList[1],
747 self._ValueList[2],
748 'COMMON',
749 'COMMON',
750 self._Owner,
751 self._From,
752 self._LineIndex + 1,
753 -1,
754 self._LineIndex + 1,
755 -1,
756 0
757 )
758
759 # process the directive
760 if DirectiveName == "!INCLUDE":
761 if not self._SectionName in self._IncludeAllowedSection:
762 EdkLogger.error("Parser", FORMAT_INVALID, File=self.MetaFile, Line=self._LineIndex+1,
763 ExtraData="'!include' is not allowed under section [%s]" % self._SectionName)
764 # the included file must be relative to the parsing file
765 IncludedFile = os.path.join(self._FileDir, self._ValueList[1])
766 Parser = DscParser(IncludedFile, self._FileType, self._Table, self._Macros, From=self._LastItem)
767 # set the parser status with current status
768 Parser._SectionName = self._SectionName
769 Parser._SectionType = self._SectionType
770 Parser._Scope = self._Scope
771 Parser._Enabled = self._Enabled
772 try:
773 Parser.Start()
774 except:
775 EdkLogger.error("Parser", PARSER_ERROR, File=self.MetaFile, Line=self._LineIndex+1,
776 ExtraData="Failed to parse content in file %s" % IncludedFile)
777 # update current status with sub-parser's status
778 self._SectionName = Parser._SectionName
779 self._SectionType = Parser._SectionType
780 self._Scope = Parser._Scope
781 self._Enabled = Parser._Enabled
782 else:
783 if DirectiveName in ["!IF", "!IFDEF", "!IFNDEF"]:
784 # evaluate the expression
785 Result = self._Evaluate(self._ValueList[1])
786 if DirectiveName == "!IFNDEF":
787 Result = not Result
788 self._Eval.append(Result)
789 elif DirectiveName in ["!ELSEIF"]:
790 # evaluate the expression
791 self._Eval[-1] = (not self._Eval[-1]) & self._Evaluate(self._ValueList[1])
792 elif DirectiveName in ["!ELSE"]:
793 self._Eval[-1] = not self._Eval[-1]
794 elif DirectiveName in ["!ENDIF"]:
795 if len(self._Eval) > 0:
796 self._Eval.pop()
797 else:
798 EdkLogger.error("Parser", FORMAT_INVALID, "!IF..[!ELSE]..!ENDIF doesn't match",
799 File=self.MetaFile, Line=self._LineIndex+1)
800 if self._Eval.Result == False:
801 self._Enabled = 0 - len(self._Eval)
802 else:
803 self._Enabled = len(self._Eval)
804
805 ## Evaluate the Token for its value; for now only macros are supported.
806 def _EvaluateToken(self, TokenName, Expression):
807 if TokenName.startswith("$(") and TokenName.endswith(")"):
808 Name = TokenName[2:-1]
809 return self._Macros.get(Name)
810 else:
811 EdkLogger.error('Parser', FORMAT_INVALID, "Unknown operand '%(Token)s', "
812 "please use '$(%(Token)s)' if '%(Token)s' is a macro" % {"Token" : TokenName},
813 File=self.MetaFile, Line=self._LineIndex+1, ExtraData=Expression)
814
815 ## Evaluate the value of expression in "if/ifdef/ifndef" directives
816 def _Evaluate(self, Expression):
817 TokenList = Expression.split()
818 TokenNumber = len(TokenList)
819 # one operand, guess it's just a macro name
820 if TokenNumber == 1:
821 TokenValue = self._EvaluateToken(TokenList[0], Expression)
822 return TokenValue != None
823 # two operands, suppose it's "!xxx" format
824 elif TokenNumber == 2:
825 Op = TokenList[0]
826 if Op not in self._OP_:
827 EdkLogger.error('Parser', FORMAT_INVALID, "Unsupported operator [%s]" % Op, File=self.MetaFile,
828 Line=self._LineIndex+1, ExtraData=Expression)
829 if TokenList[1].upper() == 'TRUE':
830 Value = True
831 else:
832 Value = False
833 return self._OP_[Op](Value)
834 # three operands
835 elif TokenNumber == 3:
836 TokenValue = self._EvaluateToken(TokenList[0], Expression)
837 if TokenValue == None:
838 return False
839 Value = TokenList[2]
840 if Value[0] in ["'", '"'] and Value[-1] in ["'", '"']:
841 Value = Value[1:-1]
842 Op = TokenList[1]
843 if Op not in self._OP_:
844 EdkLogger.error('Parser', FORMAT_INVALID, "Unsupported operator [%s]" % Op, File=self.MetaFile,
845 Line=self._LineIndex+1, ExtraData=Expression)
846 return self._OP_[Op](TokenValue, Value)
847 else:
848 EdkLogger.error('Parser', FORMAT_INVALID, File=self.MetaFile, Line=self._LineIndex+1,
849 ExtraData=Expression)
850
851 ## PCD sections parser
852 #
853 # [PcdsFixedAtBuild]
854 # [PcdsPatchableInModule]
855 # [PcdsFeatureFlag]
856 # [PcdsDynamicEx
857 # [PcdsDynamicExDefault]
858 # [PcdsDynamicExVpd]
859 # [PcdsDynamicExHii]
860 # [PcdsDynamic]
861 # [PcdsDynamicDefault]
862 # [PcdsDynamicVpd]
863 # [PcdsDynamicHii]
864 #
865 def _PcdParser(self):
866 TokenList = GetSplitValueList(ReplaceMacro(self._CurrentLine, self._Macros), TAB_VALUE_SPLIT, 1)
867 self._ValueList[0:1] = GetSplitValueList(TokenList[0], TAB_SPLIT)
868 if len(TokenList) == 2:
869 self._ValueList[2] = TokenList[1]
870 if self._ValueList[0] == '' or self._ValueList[1] == '':
871 EdkLogger.error('Parser', FORMAT_INVALID, "No token space GUID or PCD name specified",
872 ExtraData=self._CurrentLine + " (<TokenSpaceGuidCName>.<TokenCName>|<PcdValue>)",
873 File=self.MetaFile, Line=self._LineIndex+1)
874 if self._ValueList[2] == '':
875 EdkLogger.error('Parser', FORMAT_INVALID, "No PCD value given",
876 ExtraData=self._CurrentLine + " (<TokenSpaceGuidCName>.<TokenCName>|<PcdValue>)",
877 File=self.MetaFile, Line=self._LineIndex+1)
878
879 ## [components] section parser
880 def _ComponentParser(self):
881 if self._CurrentLine[-1] == '{':
882 self._ValueList[0] = self._CurrentLine[0:-1].strip()
883 self._InSubsection = True
884 else:
885 self._ValueList[0] = self._CurrentLine
886 if len(self._Macros) > 0:
887 self._ValueList[0] = NormPath(self._ValueList[0], self._Macros)
888
889 def _LibraryClassParser(self):
890 TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT)
891 if len(TokenList) < 2:
892 EdkLogger.error('Parser', FORMAT_INVALID, "No library class or instance specified",
893 ExtraData=self._CurrentLine + " (<LibraryClassName>|<LibraryInstancePath>)",
894 File=self.MetaFile, Line=self._LineIndex+1)
895 if TokenList[0] == '':
896 EdkLogger.error('Parser', FORMAT_INVALID, "No library class specified",
897 ExtraData=self._CurrentLine + " (<LibraryClassName>|<LibraryInstancePath>)",
898 File=self.MetaFile, Line=self._LineIndex+1)
899 if TokenList[1] == '':
900 EdkLogger.error('Parser', FORMAT_INVALID, "No library instance specified",
901 ExtraData=self._CurrentLine + " (<LibraryClassName>|<LibraryInstancePath>)",
902 File=self.MetaFile, Line=self._LineIndex+1)
903 self._ValueList[0:len(TokenList)] = TokenList
904 if len(self._Macros) > 0:
905 self._ValueList[1] = NormPath(self._ValueList[1], self._Macros)
906
907 def _CompponentSourceOverridePathParser(self):
908 if len(self._Macros) > 0:
909 self._ValueList[0] = NormPath(self._CurrentLine, self._Macros)
910
911 _SectionParser = {
912 MODEL_META_DATA_HEADER : _DefineParser,
913 MODEL_EFI_SKU_ID : MetaFileParser._CommonParser,
914 MODEL_EFI_LIBRARY_INSTANCE : MetaFileParser._PathParser,
915 MODEL_EFI_LIBRARY_CLASS : _LibraryClassParser,
916 MODEL_PCD_FIXED_AT_BUILD : _PcdParser,
917 MODEL_PCD_PATCHABLE_IN_MODULE : _PcdParser,
918 MODEL_PCD_FEATURE_FLAG : _PcdParser,
919 MODEL_PCD_DYNAMIC_DEFAULT : _PcdParser,
920 MODEL_PCD_DYNAMIC_HII : _PcdParser,
921 MODEL_PCD_DYNAMIC_VPD : _PcdParser,
922 MODEL_PCD_DYNAMIC_EX_DEFAULT : _PcdParser,
923 MODEL_PCD_DYNAMIC_EX_HII : _PcdParser,
924 MODEL_PCD_DYNAMIC_EX_VPD : _PcdParser,
925 MODEL_META_DATA_COMPONENT : _ComponentParser,
926 MODEL_META_DATA_COMPONENT_SOURCE_OVERRIDE_PATH : _CompponentSourceOverridePathParser,
927 MODEL_META_DATA_BUILD_OPTION : MetaFileParser._BuildOptionParser,
928 MODEL_UNKNOWN : MetaFileParser._Skip,
929 MODEL_META_DATA_USER_EXTENSION : MetaFileParser._Skip,
930 }
931
932 ## DEC file parser class
933 #
934 # @param FilePath The path of platform description file
935 # @param FileType The raw data of DSC file
936 # @param Table Database used to retrieve module/package information
937 # @param Macros Macros used for replacement in file
938 #
939 class DecParser(MetaFileParser):
940 # DEC file supported data types (one type per section)
941 DataType = {
942 TAB_DEC_DEFINES.upper() : MODEL_META_DATA_HEADER,
943 TAB_INCLUDES.upper() : MODEL_EFI_INCLUDE,
944 TAB_LIBRARY_CLASSES.upper() : MODEL_EFI_LIBRARY_CLASS,
945 TAB_GUIDS.upper() : MODEL_EFI_GUID,
946 TAB_PPIS.upper() : MODEL_EFI_PPI,
947 TAB_PROTOCOLS.upper() : MODEL_EFI_PROTOCOL,
948 TAB_PCDS_FIXED_AT_BUILD_NULL.upper() : MODEL_PCD_FIXED_AT_BUILD,
949 TAB_PCDS_PATCHABLE_IN_MODULE_NULL.upper() : MODEL_PCD_PATCHABLE_IN_MODULE,
950 TAB_PCDS_FEATURE_FLAG_NULL.upper() : MODEL_PCD_FEATURE_FLAG,
951 TAB_PCDS_DYNAMIC_NULL.upper() : MODEL_PCD_DYNAMIC,
952 TAB_PCDS_DYNAMIC_EX_NULL.upper() : MODEL_PCD_DYNAMIC_EX,
953 }
954
955 ## Constructor of DecParser
956 #
957 # Initialize object of DecParser
958 #
959 # @param FilePath The path of platform description file
960 # @param FileType The raw data of DSC file
961 # @param Table Database used to retrieve module/package information
962 # @param Macros Macros used for replacement in file
963 #
964 def __init__(self, FilePath, FileType, Table, Macro=None):
965 MetaFileParser.__init__(self, FilePath, FileType, Table, Macro, -1)
966
967 ## Parser starter
968 def Start(self):
969 try:
970 if self._Content == None:
971 self._Content = open(self.MetaFile, 'r').readlines()
972 except:
973 EdkLogger.error("Parser", FILE_READ_FAILURE, ExtraData=self.MetaFile)
974
975 for Index in range(0, len(self._Content)):
976 Line = CleanString(self._Content[Index])
977 # skip empty line
978 if Line == '':
979 continue
980 self._CurrentLine = Line
981 self._LineIndex = Index
982
983 # section header
984 if Line[0] == TAB_SECTION_START and Line[-1] == TAB_SECTION_END:
985 self._SectionHeaderParser()
986 continue
987 elif Line.startswith('DEFINE '):
988 self._MacroParser()
989 continue
990 elif len(self._SectionType) == 0:
991 continue
992
993 # section content
994 self._ValueList = ['','','']
995 self._SectionParser[self._SectionType[0]](self)
996 if self._ValueList == None:
997 continue
998
999 #
1000 # Model, Value1, Value2, Value3, Arch, BelongsToItem=-1, LineBegin=-1,
1001 # ColumnBegin=-1, LineEnd=-1, ColumnEnd=-1, FeatureFlag='', Enabled=-1
1002 #
1003 for Arch, ModuleType, Type in self._Scope:
1004 self._LastItem = self._Store(
1005 Type,
1006 self._ValueList[0],
1007 self._ValueList[1],
1008 self._ValueList[2],
1009 Arch,
1010 ModuleType,
1011 self._Owner,
1012 self._LineIndex+1,
1013 -1,
1014 self._LineIndex+1,
1015 -1,
1016 0
1017 )
1018 self._Done()
1019
1020 ## Section header parser
1021 #
1022 # The section header is always in following format:
1023 #
1024 # [section_name.arch<.platform|module_type>]
1025 #
1026 def _SectionHeaderParser(self):
1027 self._Scope = []
1028 self._SectionName = ''
1029 self._SectionType = []
1030 ArchList = set()
1031 for Item in GetSplitValueList(self._CurrentLine[1:-1], TAB_COMMA_SPLIT):
1032 if Item == '':
1033 continue
1034 ItemList = GetSplitValueList(Item, TAB_SPLIT)
1035
1036 # different types of PCD are permissible in one section
1037 self._SectionName = ItemList[0].upper()
1038 if self._SectionName in self.DataType:
1039 if self.DataType[self._SectionName] not in self._SectionType:
1040 self._SectionType.append(self.DataType[self._SectionName])
1041 else:
1042 EdkLogger.warn("Parser", "Unrecognized section", File=self.MetaFile,
1043 Line=self._LineIndex+1, ExtraData=self._CurrentLine)
1044 continue
1045
1046 if MODEL_PCD_FEATURE_FLAG in self._SectionType and len(self._SectionType) > 1:
1047 EdkLogger.error(
1048 'Parser',
1049 FORMAT_INVALID,
1050 "%s must not be in the same section of other types of PCD" % TAB_PCDS_FEATURE_FLAG_NULL,
1051 File=self.MetaFile,
1052 Line=self._LineIndex+1,
1053 ExtraData=self._CurrentLine
1054 )
1055 # S1 is always Arch
1056 if len(ItemList) > 1:
1057 S1 = ItemList[1].upper()
1058 else:
1059 S1 = 'COMMON'
1060 ArchList.add(S1)
1061 # S2 may be Platform or ModuleType
1062 if len(ItemList) > 2:
1063 S2 = ItemList[2].upper()
1064 else:
1065 S2 = 'COMMON'
1066 if [S1, S2, self.DataType[self._SectionName]] not in self._Scope:
1067 self._Scope.append([S1, S2, self.DataType[self._SectionName]])
1068
1069 # 'COMMON' must not be used with specific ARCHs at the same section
1070 if 'COMMON' in ArchList and len(ArchList) > 1:
1071 EdkLogger.error('Parser', FORMAT_INVALID, "'common' ARCH must not be used with specific ARCHs",
1072 File=self.MetaFile, Line=self._LineIndex+1, ExtraData=self._CurrentLine)
1073
1074 ## [guids], [ppis] and [protocols] section parser
1075 def _GuidParser(self):
1076 TokenList = GetSplitValueList(self._CurrentLine, TAB_EQUAL_SPLIT, 1)
1077 if len(TokenList) < 2:
1078 EdkLogger.error('Parser', FORMAT_INVALID, "No GUID name or value specified",
1079 ExtraData=self._CurrentLine + " (<CName> = <GuidValueInCFormat>)",
1080 File=self.MetaFile, Line=self._LineIndex+1)
1081 if TokenList[0] == '':
1082 EdkLogger.error('Parser', FORMAT_INVALID, "No GUID name specified",
1083 ExtraData=self._CurrentLine + " (<CName> = <GuidValueInCFormat>)",
1084 File=self.MetaFile, Line=self._LineIndex+1)
1085 if TokenList[1] == '':
1086 EdkLogger.error('Parser', FORMAT_INVALID, "No GUID value specified",
1087 ExtraData=self._CurrentLine + " (<CName> = <GuidValueInCFormat>)",
1088 File=self.MetaFile, Line=self._LineIndex+1)
1089 if TokenList[1][0] != '{' or TokenList[1][-1] != '}' or GuidStructureStringToGuidString(TokenList[1]) == '':
1090 EdkLogger.error('Parser', FORMAT_INVALID, "Invalid GUID value format",
1091 ExtraData=self._CurrentLine + \
1092 " (<CName> = <GuidValueInCFormat:{8,4,4,{2,2,2,2,2,2,2,2}}>)",
1093 File=self.MetaFile, Line=self._LineIndex+1)
1094 self._ValueList[0] = TokenList[0]
1095 self._ValueList[1] = TokenList[1]
1096
1097 ## PCD sections parser
1098 #
1099 # [PcdsFixedAtBuild]
1100 # [PcdsPatchableInModule]
1101 # [PcdsFeatureFlag]
1102 # [PcdsDynamicEx
1103 # [PcdsDynamic]
1104 #
1105 def _PcdParser(self):
1106 TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT, 1)
1107 self._ValueList[0:1] = GetSplitValueList(TokenList[0], TAB_SPLIT)
1108 # check PCD information
1109 if self._ValueList[0] == '' or self._ValueList[1] == '':
1110 EdkLogger.error('Parser', FORMAT_INVALID, "No token space GUID or PCD name specified",
1111 ExtraData=self._CurrentLine + \
1112 " (<TokenSpaceGuidCName>.<PcdCName>|<DefaultValue>|<DatumType>|<Token>)",
1113 File=self.MetaFile, Line=self._LineIndex+1)
1114 # check PCD datum information
1115 if len(TokenList) < 2 or TokenList[1] == '':
1116 EdkLogger.error('Parser', FORMAT_INVALID, "No PCD Datum information given",
1117 ExtraData=self._CurrentLine + \
1118 " (<TokenSpaceGuidCName>.<PcdCName>|<DefaultValue>|<DatumType>|<Token>)",
1119 File=self.MetaFile, Line=self._LineIndex+1)
1120
1121 ValueList = GetSplitValueList(TokenList[1])
1122 # check if there's enough datum information given
1123 if len(ValueList) != 3:
1124 EdkLogger.error('Parser', FORMAT_INVALID, "Invalid PCD Datum information given",
1125 ExtraData=self._CurrentLine + \
1126 " (<TokenSpaceGuidCName>.<PcdCName>|<DefaultValue>|<DatumType>|<Token>)",
1127 File=self.MetaFile, Line=self._LineIndex+1)
1128 # check default value
1129 if ValueList[0] == '':
1130 EdkLogger.error('Parser', FORMAT_INVALID, "Missing DefaultValue in PCD Datum information",
1131 ExtraData=self._CurrentLine + \
1132 " (<TokenSpaceGuidCName>.<PcdCName>|<DefaultValue>|<DatumType>|<Token>)",
1133 File=self.MetaFile, Line=self._LineIndex+1)
1134 # check datum type
1135 if ValueList[1] == '':
1136 EdkLogger.error('Parser', FORMAT_INVALID, "Missing DatumType in PCD Datum information",
1137 ExtraData=self._CurrentLine + \
1138 " (<TokenSpaceGuidCName>.<PcdCName>|<DefaultValue>|<DatumType>|<Token>)",
1139 File=self.MetaFile, Line=self._LineIndex+1)
1140 # check token of the PCD
1141 if ValueList[2] == '':
1142 EdkLogger.error('Parser', FORMAT_INVALID, "Missing Token in PCD Datum information",
1143 ExtraData=self._CurrentLine + \
1144 " (<TokenSpaceGuidCName>.<PcdCName>|<DefaultValue>|<DatumType>|<Token>)",
1145 File=self.MetaFile, Line=self._LineIndex+1)
1146 # check format of default value against the datum type
1147 IsValid, Cause = CheckPcdDatum(ValueList[1], ValueList[0])
1148 if not IsValid:
1149 EdkLogger.error('Parser', FORMAT_INVALID, Cause, ExtraData=self._CurrentLine,
1150 File=self.MetaFile, Line=self._LineIndex+1)
1151
1152 self._ValueList[2] = ValueList[0].strip() + '|' + ValueList[1].strip() + '|' + ValueList[2].strip()
1153
1154 _SectionParser = {
1155 MODEL_META_DATA_HEADER : MetaFileParser._DefineParser,
1156 MODEL_EFI_INCLUDE : MetaFileParser._PathParser,
1157 MODEL_EFI_LIBRARY_CLASS : MetaFileParser._PathParser,
1158 MODEL_EFI_GUID : _GuidParser,
1159 MODEL_EFI_PPI : _GuidParser,
1160 MODEL_EFI_PROTOCOL : _GuidParser,
1161 MODEL_PCD_FIXED_AT_BUILD : _PcdParser,
1162 MODEL_PCD_PATCHABLE_IN_MODULE : _PcdParser,
1163 MODEL_PCD_FEATURE_FLAG : _PcdParser,
1164 MODEL_PCD_DYNAMIC : _PcdParser,
1165 MODEL_PCD_DYNAMIC_EX : _PcdParser,
1166 MODEL_UNKNOWN : MetaFileParser._Skip,
1167 MODEL_META_DATA_USER_EXTENSION : MetaFileParser._Skip,
1168 }
1169
1170 ##
1171 #
1172 # This acts like the main() function for the script, unless it is 'import'ed into another
1173 # script.
1174 #
1175 if __name__ == '__main__':
1176 pass
1177