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