2 # This file is used to parse meta files
4 # Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.<BR>
5 # 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
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.
22 import Common
.EdkLogger
as EdkLogger
23 import Common
.GlobalData
as GlobalData
26 from CommonDataClass
.DataClass
import *
27 from Common
.DataType
import *
28 from Common
.String
import *
29 from Common
.Misc
import GuidStructureStringToGuidString
, CheckPcdDatum
, PathClass
, AnalyzePcdData
30 from Common
.Expression
import *
31 from CommonDataClass
.Exceptions
import *
33 from MetaFileTable
import MetaFileStorage
34 from GenFds
.FdfParser
import FdfParser
36 ## A decorator used to parse macro definition
37 def ParseMacro(Parser
):
38 def MacroParser(self
):
39 Match
= gMacroDefPattern
.match(self
._CurrentLine
)
41 # Not 'DEFINE/EDK_GLOBAL' statement, call decorated method
45 TokenList
= GetSplitValueList(self
._CurrentLine
[Match
.end(1):], TAB_EQUAL_SPLIT
, 1)
48 EdkLogger
.error('Parser', FORMAT_INVALID
, "No macro name given",
49 ExtraData
=self
._CurrentLine
, File
=self
.MetaFile
, Line
=self
._LineIndex
+1)
50 if len(TokenList
) < 2:
54 Name
, Value
= TokenList
55 # Global macros can be only defined via environment variable
56 if Name
in GlobalData
.gGlobalDefines
:
57 EdkLogger
.error('Parser', FORMAT_INVALID
, "%s can only be defined via environment variable" % Name
,
58 ExtraData
=self
._CurrentLine
, File
=self
.MetaFile
, Line
=self
._LineIndex
+1)
59 # Only upper case letters, digit and '_' are allowed
60 if not gMacroNamePattern
.match(Name
):
61 EdkLogger
.error('Parser', FORMAT_INVALID
, "The macro name must be in the pattern [A-Z][A-Z0-9_]*",
62 ExtraData
=self
._CurrentLine
, File
=self
.MetaFile
, Line
=self
._LineIndex
+1)
64 Value
= ReplaceMacro(Value
, self
._Macros
)
65 self
._ItemType
= MODEL_META_DATA_DEFINE
66 # DEFINE defined macros
67 if Type
== TAB_DSC_DEFINES_DEFINE
:
68 if type(self
) == DecParser
:
69 if MODEL_META_DATA_HEADER
in self
._SectionType
:
70 self
._FileLocalMacros
[Name
] = Value
72 for Scope
in self
._Scope
:
73 self
._SectionsMacroDict
.setdefault((Scope
[2], Scope
[0], Scope
[1]), {})[Name
] = Value
74 elif self
._SectionType
== MODEL_META_DATA_HEADER
:
75 self
._FileLocalMacros
[Name
] = Value
77 SectionDictKey
= self
._SectionType
, self
._Scope
[0][0], self
._Scope
[0][1]
78 if SectionDictKey
not in self
._SectionsMacroDict
:
79 self
._SectionsMacroDict
[SectionDictKey
] = {}
80 SectionLocalMacros
= self
._SectionsMacroDict
[SectionDictKey
]
81 SectionLocalMacros
[Name
] = Value
82 # EDK_GLOBAL defined macros
83 elif type(self
) != DscParser
:
84 EdkLogger
.error('Parser', FORMAT_INVALID
, "EDK_GLOBAL can only be used in .dsc file",
85 ExtraData
=self
._CurrentLine
, File
=self
.MetaFile
, Line
=self
._LineIndex
+1)
86 elif self
._SectionType
!= MODEL_META_DATA_HEADER
:
87 EdkLogger
.error('Parser', FORMAT_INVALID
, "EDK_GLOBAL can only be used under [Defines] section",
88 ExtraData
=self
._CurrentLine
, File
=self
.MetaFile
, Line
=self
._LineIndex
+1)
89 elif (Name
in self
._FileLocalMacros
) and (self
._FileLocalMacros
[Name
] != Value
):
90 EdkLogger
.error('Parser', FORMAT_INVALID
, "EDK_GLOBAL defined a macro with the same name and different value as one defined by 'DEFINE'",
91 ExtraData
=self
._CurrentLine
, File
=self
.MetaFile
, Line
=self
._LineIndex
+1)
93 self
._ValueList
= [Type
, Name
, Value
]
97 ## Base class of parser
99 # This class is used for derivation purpose. The specific parser for one kind
100 # type file must derive this class and implement some public interfaces.
102 # @param FilePath The path of platform description file
103 # @param FileType The raw data of DSC file
104 # @param Table Database used to retrieve module/package information
105 # @param Macros Macros used for replacement in file
106 # @param Owner Owner ID (for sub-section parsing)
107 # @param From ID from which the data comes (for !INCLUDE directive)
109 class MetaFileParser(object):
110 # data type (file content) for specific file type
113 # Parser objects used to implement singleton
118 # One file, one parser object. This factory method makes sure that there's
119 # only one object constructed for one meta file.
121 # @param Class class object of real AutoGen class
122 # (InfParser, DecParser or DscParser)
123 # @param FilePath The path of meta file
124 # @param *args The specific class related parameters
125 # @param **kwargs The specific class related dict parameters
127 def __new__(Class
, FilePath
, *args
, **kwargs
):
128 if FilePath
in Class
.MetaFiles
:
129 return Class
.MetaFiles
[FilePath
]
131 ParserObject
= super(MetaFileParser
, Class
).__new
__(Class
)
132 Class
.MetaFiles
[FilePath
] = ParserObject
135 ## Constructor of MetaFileParser
137 # Initialize object of MetaFileParser
139 # @param FilePath The path of platform description file
140 # @param FileType The raw data of DSC file
141 # @param Table Database used to retrieve module/package information
142 # @param Macros Macros used for replacement in file
143 # @param Owner Owner ID (for sub-section parsing)
144 # @param From ID from which the data comes (for !INCLUDE directive)
146 def __init__(self
, FilePath
, FileType
, Table
, Owner
=-1, From
=-1):
148 self
._RawTable
= Table
149 self
._FileType
= FileType
150 self
.MetaFile
= FilePath
152 self
._FileLocalMacros
= {}
153 self
._SectionsMacroDict
= {}
155 # for recursive parsing
156 self
._Owner
= [Owner
]
159 # parsr status for parsing
160 self
._ValueList
= ['', '', '', '', '']
163 self
._CurrentLine
= ''
164 self
._SectionType
= MODEL_UNKNOWN
165 self
._SectionName
= ''
166 self
._InSubsection
= False
167 self
._SubsectionType
= MODEL_UNKNOWN
168 self
._SubsectionName
= ''
169 self
._ItemType
= MODEL_UNKNOWN
172 self
._Finished
= False
173 self
._PostProcessed
= False
174 # Different version of meta-file has different way to parse.
177 ## Store the parsed data in table
178 def _Store(self
, *Args
):
179 return self
._Table
.Insert(*Args
)
181 ## Virtual method for starting parse
183 raise NotImplementedError
185 ## Notify a post-process is needed
186 def DoPostProcess(self
):
187 self
._PostProcessed
= False
189 ## Set parsing complete flag in both class and table
191 self
._Finished
= True
192 ## Do not set end flag when processing included files
194 self
._Table
.SetEndFlag()
196 def _PostProcess(self
):
197 self
._PostProcessed
= True
199 ## Get the parse complete flag
200 def _GetFinished(self
):
201 return self
._Finished
203 ## Set the complete flag
204 def _SetFinished(self
, Value
):
205 self
._Finished
= Value
207 ## Use [] style to query data in table, just for readability
209 # DataInfo = [data_type, scope1(arch), scope2(platform/moduletype)]
211 def __getitem__(self
, DataInfo
):
212 if type(DataInfo
) != type(()):
213 DataInfo
= (DataInfo
,)
215 # Parse the file first, if necessary
216 if not self
._Finished
:
217 if self
._RawTable
.IsIntegrity():
218 self
._Finished
= True
220 self
._Table
= self
._RawTable
221 self
._PostProcessed
= False
224 # No specific ARCH or Platform given, use raw data
225 if self
._RawTable
and (len(DataInfo
) == 1 or DataInfo
[1] == None):
226 return self
._RawTable
.Query(*DataInfo
)
228 # Do post-process if necessary
229 if not self
._PostProcessed
:
232 return self
._Table
.Query(*DataInfo
)
234 ## Data parser for the common format in different type of file
236 # The common format in the meatfile is like
241 def _CommonParser(self
):
242 TokenList
= GetSplitValueList(self
._CurrentLine
, TAB_VALUE_SPLIT
)
243 self
._ValueList
[0:len(TokenList
)] = TokenList
245 ## Data parser for the format in which there's path
247 # Only path can have macro used. So we need to replace them before use.
250 def _PathParser(self
):
251 TokenList
= GetSplitValueList(self
._CurrentLine
, TAB_VALUE_SPLIT
)
252 self
._ValueList
[0:len(TokenList
)] = TokenList
253 # Don't do macro replacement for dsc file at this point
254 if type(self
) != DscParser
:
255 Macros
= self
._Macros
256 self
._ValueList
= [ReplaceMacro(Value
, Macros
) for Value
in self
._ValueList
]
258 ## Skip unsupported data
260 EdkLogger
.warn("Parser", "Unrecognized content", File
=self
.MetaFile
,
261 Line
=self
._LineIndex
+1, ExtraData
=self
._CurrentLine
);
262 self
._ValueList
[0:1] = [self
._CurrentLine
]
264 ## Section header parser
266 # The section header is always in following format:
268 # [section_name.arch<.platform|module_type>]
270 def _SectionHeaderParser(self
):
272 self
._SectionName
= ''
274 for Item
in GetSplitValueList(self
._CurrentLine
[1:-1], TAB_COMMA_SPLIT
):
277 ItemList
= GetSplitValueList(Item
, TAB_SPLIT
)
278 # different section should not mix in one section
279 if self
._SectionName
!= '' and self
._SectionName
!= ItemList
[0].upper():
280 EdkLogger
.error('Parser', FORMAT_INVALID
, "Different section names in the same section",
281 File
=self
.MetaFile
, Line
=self
._LineIndex
+1, ExtraData
=self
._CurrentLine
)
282 self
._SectionName
= ItemList
[0].upper()
283 if self
._SectionName
in self
.DataType
:
284 self
._SectionType
= self
.DataType
[self
._SectionName
]
286 self
._SectionType
= MODEL_UNKNOWN
287 EdkLogger
.warn("Parser", "Unrecognized section", File
=self
.MetaFile
,
288 Line
=self
._LineIndex
+1, ExtraData
=self
._CurrentLine
)
290 if len(ItemList
) > 1:
291 S1
= ItemList
[1].upper()
295 # S2 may be Platform or ModuleType
296 if len(ItemList
) > 2:
297 S2
= ItemList
[2].upper()
300 self
._Scope
.append([S1
, S2
])
302 # 'COMMON' must not be used with specific ARCHs at the same section
303 if 'COMMON' in ArchList
and len(ArchList
) > 1:
304 EdkLogger
.error('Parser', FORMAT_INVALID
, "'common' ARCH must not be used with specific ARCHs",
305 File
=self
.MetaFile
, Line
=self
._LineIndex
+1, ExtraData
=self
._CurrentLine
)
306 # If the section information is needed later, it should be stored in database
307 self
._ValueList
[0] = self
._SectionName
309 ## [defines] section parser
311 def _DefineParser(self
):
312 TokenList
= GetSplitValueList(self
._CurrentLine
, TAB_EQUAL_SPLIT
, 1)
313 self
._ValueList
[1:len(TokenList
)] = TokenList
314 if not self
._ValueList
[1]:
315 EdkLogger
.error('Parser', FORMAT_INVALID
, "No name specified",
316 ExtraData
=self
._CurrentLine
, File
=self
.MetaFile
, Line
=self
._LineIndex
+1)
317 if not self
._ValueList
[2]:
318 EdkLogger
.error('Parser', FORMAT_INVALID
, "No value specified",
319 ExtraData
=self
._CurrentLine
, File
=self
.MetaFile
, Line
=self
._LineIndex
+1)
321 self
._ValueList
= [ReplaceMacro(Value
, self
._Macros
) for Value
in self
._ValueList
]
322 Name
, Value
= self
._ValueList
[1], self
._ValueList
[2]
323 # Sometimes, we need to make differences between EDK and EDK2 modules
324 if Name
== 'INF_VERSION':
326 self
._Version
= int(Value
, 0)
328 EdkLogger
.error('Parser', FORMAT_INVALID
, "Invalid version number",
329 ExtraData
=self
._CurrentLine
, File
=self
.MetaFile
, Line
=self
._LineIndex
+1)
331 if type(self
) == InfParser
and self
._Version
< 0x00010005:
332 # EDK module allows using defines as macros
333 self
._FileLocalMacros
[Name
] = Value
334 self
._Defines
[Name
] = Value
336 ## [BuildOptions] section parser
338 def _BuildOptionParser(self
):
339 TokenList
= GetSplitValueList(self
._CurrentLine
, TAB_EQUAL_SPLIT
, 1)
340 TokenList2
= GetSplitValueList(TokenList
[0], ':', 1)
341 if len(TokenList2
) == 2:
342 self
._ValueList
[0] = TokenList2
[0] # toolchain family
343 self
._ValueList
[1] = TokenList2
[1] # keys
345 self
._ValueList
[1] = TokenList
[0]
346 if len(TokenList
) == 2 and type(self
) != DscParser
: # value
347 self
._ValueList
[2] = ReplaceMacro(TokenList
[1], self
._Macros
)
349 if self
._ValueList
[1].count('_') != 4:
353 "'%s' must be in format of <TARGET>_<TOOLCHAIN>_<ARCH>_<TOOL>_FLAGS" % self
._ValueList
[1],
354 ExtraData
=self
._CurrentLine
,
356 Line
=self
._LineIndex
+1
359 def _GetMacros(self
):
361 Macros
.update(self
._FileLocalMacros
)
362 Macros
.update(self
._GetApplicableSectionMacro
())
366 ## Get section Macros that are applicable to current line, which may come from other sections
367 ## that share the same name while scope is wider
368 def _GetApplicableSectionMacro(self
):
370 for Scope1
, Scope2
in [("COMMON", "COMMON"), ("COMMON", self
._Scope
[0][1]),
371 (self
._Scope
[0][0], "COMMON"), (self
._Scope
[0][0], self
._Scope
[0][1])]:
372 if (self
._SectionType
, Scope1
, Scope2
) in self
._SectionsMacroDict
:
373 Macros
.update(self
._SectionsMacroDict
[(self
._SectionType
, Scope1
, Scope2
)])
377 Finished
= property(_GetFinished
, _SetFinished
)
378 _Macros
= property(_GetMacros
)
381 ## INF file parser class
383 # @param FilePath The path of platform description file
384 # @param FileType The raw data of DSC file
385 # @param Table Database used to retrieve module/package information
386 # @param Macros Macros used for replacement in file
388 class InfParser(MetaFileParser
):
389 # INF file supported data types (one type per section)
391 TAB_UNKNOWN
.upper() : MODEL_UNKNOWN
,
392 TAB_INF_DEFINES
.upper() : MODEL_META_DATA_HEADER
,
393 TAB_DSC_DEFINES_DEFINE
: MODEL_META_DATA_DEFINE
,
394 TAB_BUILD_OPTIONS
.upper() : MODEL_META_DATA_BUILD_OPTION
,
395 TAB_INCLUDES
.upper() : MODEL_EFI_INCLUDE
,
396 TAB_LIBRARIES
.upper() : MODEL_EFI_LIBRARY_INSTANCE
,
397 TAB_LIBRARY_CLASSES
.upper() : MODEL_EFI_LIBRARY_CLASS
,
398 TAB_PACKAGES
.upper() : MODEL_META_DATA_PACKAGE
,
399 TAB_NMAKE
.upper() : MODEL_META_DATA_NMAKE
,
400 TAB_INF_FIXED_PCD
.upper() : MODEL_PCD_FIXED_AT_BUILD
,
401 TAB_INF_PATCH_PCD
.upper() : MODEL_PCD_PATCHABLE_IN_MODULE
,
402 TAB_INF_FEATURE_PCD
.upper() : MODEL_PCD_FEATURE_FLAG
,
403 TAB_INF_PCD_EX
.upper() : MODEL_PCD_DYNAMIC_EX
,
404 TAB_INF_PCD
.upper() : MODEL_PCD_DYNAMIC
,
405 TAB_SOURCES
.upper() : MODEL_EFI_SOURCE_FILE
,
406 TAB_GUIDS
.upper() : MODEL_EFI_GUID
,
407 TAB_PROTOCOLS
.upper() : MODEL_EFI_PROTOCOL
,
408 TAB_PPIS
.upper() : MODEL_EFI_PPI
,
409 TAB_DEPEX
.upper() : MODEL_EFI_DEPEX
,
410 TAB_BINARIES
.upper() : MODEL_EFI_BINARY_FILE
,
411 TAB_USER_EXTENSIONS
.upper() : MODEL_META_DATA_USER_EXTENSION
414 ## Constructor of InfParser
416 # Initialize object of InfParser
418 # @param FilePath The path of module description file
419 # @param FileType The raw data of DSC file
420 # @param Table Database used to retrieve module/package information
421 # @param Macros Macros used for replacement in file
423 def __init__(self
, FilePath
, FileType
, Table
):
424 # prevent re-initialization
425 if hasattr(self
, "_Table"):
427 MetaFileParser
.__init
__(self
, FilePath
, FileType
, Table
)
428 self
.TblFile
= EccGlobalData
.gDb
.TblFile
436 Content
= open(str(self
.MetaFile
), 'r').readlines()
438 EdkLogger
.error("Parser", FILE_READ_FAILURE
, ExtraData
=self
.MetaFile
)
440 # Insert a record for file
442 Filename
= NormPath(self
.MetaFile
)
443 FileID
= self
.TblFile
.GetFileId(Filename
)
447 self
.FileID
= self
.TblFile
.InsertFile(Filename
, MODEL_FILE_INF
)
449 # parse the file line by line
450 IsFindBlockComment
= False
452 for Index
in range(0, len(Content
)):
453 # skip empty, commented, block commented lines
454 Line
= CleanString(Content
[Index
], AllowCppStyleComment
=True)
456 if Index
+ 1 < len(Content
):
457 NextLine
= CleanString(Content
[Index
+ 1])
460 if Line
.find(DataType
.TAB_COMMENT_EDK_START
) > -1:
461 IsFindBlockComment
= True
463 if Line
.find(DataType
.TAB_COMMENT_EDK_END
) > -1:
464 IsFindBlockComment
= False
466 if IsFindBlockComment
:
469 self
._LineIndex
= Index
470 self
._CurrentLine
= Line
473 if Line
[0] == TAB_SECTION_START
and Line
[-1] == TAB_SECTION_END
:
474 self
._SectionHeaderParser
()
475 # Check invalid sections
476 if self
._Version
< 0x00010005:
477 if self
._SectionType
in [MODEL_META_DATA_BUILD_OPTION
,
478 MODEL_EFI_LIBRARY_CLASS
,
479 MODEL_META_DATA_PACKAGE
,
480 MODEL_PCD_FIXED_AT_BUILD
,
481 MODEL_PCD_PATCHABLE_IN_MODULE
,
482 MODEL_PCD_FEATURE_FLAG
,
483 MODEL_PCD_DYNAMIC_EX
,
488 MODEL_META_DATA_USER_EXTENSION
]:
489 EdkLogger
.error('Parser', FORMAT_INVALID
,
490 "Section [%s] is not allowed in inf file without version" % (self
._SectionName
),
491 ExtraData
=self
._CurrentLine
, File
=self
.MetaFile
, Line
=self
._LineIndex
+1)
492 elif self
._SectionType
in [MODEL_EFI_INCLUDE
,
493 MODEL_EFI_LIBRARY_INSTANCE
,
494 MODEL_META_DATA_NMAKE
]:
495 EdkLogger
.error('Parser', FORMAT_INVALID
,
496 "Section [%s] is not allowed in inf file with version 0x%08x" % (self
._SectionName
, self
._Version
),
497 ExtraData
=self
._CurrentLine
, File
=self
.MetaFile
, Line
=self
._LineIndex
+1)
499 # merge two lines specified by '\' in section NMAKE
500 elif self
._SectionType
== MODEL_META_DATA_NMAKE
:
503 self
._CurrentLine
= NmakeLine
+ Line
[0:-1]
506 if NextLine
[0] == TAB_SECTION_START
and NextLine
[-1] == TAB_SECTION_END
:
507 self
._CurrentLine
= NmakeLine
+ Line
[0:-1]
510 NmakeLine
= NmakeLine
+ ' ' + Line
[0:-1]
513 self
._CurrentLine
= NmakeLine
+ Line
517 self
._ValueList
= ['','','']
518 # parse current line, result will be put in self._ValueList
519 self
._SectionParser
[self
._SectionType
](self
)
520 if self
._ValueList
== None or self
._ItemType
== MODEL_META_DATA_DEFINE
:
524 # Model, Value1, Value2, Value3, Arch, Platform, BelongsToItem=-1,
525 # LineBegin=-1, ColumnBegin=-1, LineEnd=-1, ColumnEnd=-1, Enabled=-1
527 self
._ValueList
[0] = self
._ValueList
[0].replace('/', '\\')
528 for Arch
, Platform
in self
._Scope
:
529 self
._Store
(self
._SectionType
,
543 if IsFindBlockComment
:
544 EdkLogger
.error("Parser", FORMAT_INVALID
, "Open block comments (starting with /*) are expected to end with */",
548 ## Data parser for the format in which there's path
550 # Only path can have macro used. So we need to replace them before use.
552 def _IncludeParser(self
):
553 TokenList
= GetSplitValueList(self
._CurrentLine
, TAB_VALUE_SPLIT
)
554 self
._ValueList
[0:len(TokenList
)] = TokenList
555 Macros
= self
._Macros
557 for Index
in range(0, len(self
._ValueList
)):
558 Value
= self
._ValueList
[Index
]
562 if Value
.upper().find('$(EFI_SOURCE)\Edk'.upper()) > -1 or Value
.upper().find('$(EFI_SOURCE)/Edk'.upper()) > -1:
563 Value
= '$(EDK_SOURCE)' + Value
[17:]
564 if Value
.find('$(EFI_SOURCE)') > -1 or Value
.find('$(EDK_SOURCE)') > -1:
566 elif Value
.startswith('.'):
568 elif Value
.startswith('$('):
571 Value
= '$(EFI_SOURCE)/' + Value
573 self
._ValueList
[Index
] = ReplaceMacro(Value
, Macros
)
575 ## Parse [Sources] section
577 # Only path can have macro used. So we need to replace them before use.
580 def _SourceFileParser(self
):
581 TokenList
= GetSplitValueList(self
._CurrentLine
, TAB_VALUE_SPLIT
)
582 self
._ValueList
[0:len(TokenList
)] = TokenList
583 Macros
= self
._Macros
584 # For Acpi tables, remove macro like ' TABLE_NAME=Sata1'
585 if 'COMPONENT_TYPE' in Macros
:
586 if self
._Defines
['COMPONENT_TYPE'].upper() == 'ACPITABLE':
587 self
._ValueList
[0] = GetSplitValueList(self
._ValueList
[0], ' ', 1)[0]
588 if self
._Defines
['BASE_NAME'] == 'Microcode':
590 self
._ValueList
= [ReplaceMacro(Value
, Macros
) for Value
in self
._ValueList
]
592 ## Parse [Binaries] section
594 # Only path can have macro used. So we need to replace them before use.
597 def _BinaryFileParser(self
):
598 TokenList
= GetSplitValueList(self
._CurrentLine
, TAB_VALUE_SPLIT
, 2)
599 if len(TokenList
) < 2:
600 EdkLogger
.error('Parser', FORMAT_INVALID
, "No file type or path specified",
601 ExtraData
=self
._CurrentLine
+ " (<FileType> | <FilePath> [| <Target>])",
602 File
=self
.MetaFile
, Line
=self
._LineIndex
+1)
604 EdkLogger
.error('Parser', FORMAT_INVALID
, "No file type specified",
605 ExtraData
=self
._CurrentLine
+ " (<FileType> | <FilePath> [| <Target>])",
606 File
=self
.MetaFile
, Line
=self
._LineIndex
+1)
608 EdkLogger
.error('Parser', FORMAT_INVALID
, "No file path specified",
609 ExtraData
=self
._CurrentLine
+ " (<FileType> | <FilePath> [| <Target>])",
610 File
=self
.MetaFile
, Line
=self
._LineIndex
+1)
611 self
._ValueList
[0:len(TokenList
)] = TokenList
612 self
._ValueList
[1] = ReplaceMacro(self
._ValueList
[1], self
._Macros
)
614 ## [nmake] section parser (Edk.x style only)
615 def _NmakeParser(self
):
616 TokenList
= GetSplitValueList(self
._CurrentLine
, TAB_EQUAL_SPLIT
, 1)
617 self
._ValueList
[0:len(TokenList
)] = TokenList
619 self
._ValueList
[1] = ReplaceMacro(self
._ValueList
[1], self
._Macros
)
620 # remove self-reference in macro setting
621 #self._ValueList[1] = ReplaceMacro(self._ValueList[1], {self._ValueList[0]:''})
623 ## [FixedPcd], [FeaturePcd], [PatchPcd], [Pcd] and [PcdEx] sections parser
625 def _PcdParser(self
):
626 TokenList
= GetSplitValueList(self
._CurrentLine
, TAB_VALUE_SPLIT
, 1)
627 ValueList
= GetSplitValueList(TokenList
[0], TAB_SPLIT
)
628 if len(ValueList
) != 2:
629 EdkLogger
.error('Parser', FORMAT_INVALID
, "Illegal token space GUID and PCD name format",
630 ExtraData
=self
._CurrentLine
+ " (<TokenSpaceGuidCName>.<PcdCName>)",
631 File
=self
.MetaFile
, Line
=self
._LineIndex
+1)
632 self
._ValueList
[0:1] = ValueList
633 if len(TokenList
) > 1:
634 self
._ValueList
[2] = TokenList
[1]
635 if self
._ValueList
[0] == '' or self
._ValueList
[1] == '':
636 EdkLogger
.error('Parser', FORMAT_INVALID
, "No token space GUID or PCD name specified",
637 ExtraData
=self
._CurrentLine
+ " (<TokenSpaceGuidCName>.<PcdCName>)",
638 File
=self
.MetaFile
, Line
=self
._LineIndex
+1)
640 # if value are 'True', 'true', 'TRUE' or 'False', 'false', 'FALSE', replace with integer 1 or 0.
641 if self
._ValueList
[2] != '':
642 InfPcdValueList
= GetSplitValueList(TokenList
[1], TAB_VALUE_SPLIT
, 1)
643 if InfPcdValueList
[0] in ['True', 'true', 'TRUE']:
644 self
._ValueList
[2] = TokenList
[1].replace(InfPcdValueList
[0], '1', 1);
645 elif InfPcdValueList
[0] in ['False', 'false', 'FALSE']:
646 self
._ValueList
[2] = TokenList
[1].replace(InfPcdValueList
[0], '0', 1);
648 ## [depex] section parser
650 def _DepexParser(self
):
651 self
._ValueList
[0:1] = [self
._CurrentLine
]
654 MODEL_UNKNOWN
: MetaFileParser
._Skip
,
655 MODEL_META_DATA_HEADER
: MetaFileParser
._DefineParser
,
656 MODEL_META_DATA_BUILD_OPTION
: MetaFileParser
._BuildOptionParser
,
657 MODEL_EFI_INCLUDE
: _IncludeParser
, # for Edk.x modules
658 MODEL_EFI_LIBRARY_INSTANCE
: MetaFileParser
._CommonParser
, # for Edk.x modules
659 MODEL_EFI_LIBRARY_CLASS
: MetaFileParser
._PathParser
,
660 MODEL_META_DATA_PACKAGE
: MetaFileParser
._PathParser
,
661 MODEL_META_DATA_NMAKE
: _NmakeParser
, # for Edk.x modules
662 MODEL_PCD_FIXED_AT_BUILD
: _PcdParser
,
663 MODEL_PCD_PATCHABLE_IN_MODULE
: _PcdParser
,
664 MODEL_PCD_FEATURE_FLAG
: _PcdParser
,
665 MODEL_PCD_DYNAMIC_EX
: _PcdParser
,
666 MODEL_PCD_DYNAMIC
: _PcdParser
,
667 MODEL_EFI_SOURCE_FILE
: _SourceFileParser
,
668 MODEL_EFI_GUID
: MetaFileParser
._CommonParser
,
669 MODEL_EFI_PROTOCOL
: MetaFileParser
._CommonParser
,
670 MODEL_EFI_PPI
: MetaFileParser
._CommonParser
,
671 MODEL_EFI_DEPEX
: _DepexParser
,
672 MODEL_EFI_BINARY_FILE
: _BinaryFileParser
,
673 MODEL_META_DATA_USER_EXTENSION
: MetaFileParser
._Skip
,
676 ## DSC file parser class
678 # @param FilePath The path of platform description file
679 # @param FileType The raw data of DSC file
680 # @param Table Database used to retrieve module/package information
681 # @param Macros Macros used for replacement in file
682 # @param Owner Owner ID (for sub-section parsing)
683 # @param From ID from which the data comes (for !INCLUDE directive)
685 class DscParser(MetaFileParser
):
686 # DSC file supported data types (one type per section)
688 TAB_SKUIDS
.upper() : MODEL_EFI_SKU_ID
,
689 TAB_LIBRARIES
.upper() : MODEL_EFI_LIBRARY_INSTANCE
,
690 TAB_LIBRARY_CLASSES
.upper() : MODEL_EFI_LIBRARY_CLASS
,
691 TAB_BUILD_OPTIONS
.upper() : MODEL_META_DATA_BUILD_OPTION
,
692 TAB_PCDS_FIXED_AT_BUILD_NULL
.upper() : MODEL_PCD_FIXED_AT_BUILD
,
693 TAB_PCDS_PATCHABLE_IN_MODULE_NULL
.upper() : MODEL_PCD_PATCHABLE_IN_MODULE
,
694 TAB_PCDS_FEATURE_FLAG_NULL
.upper() : MODEL_PCD_FEATURE_FLAG
,
695 TAB_PCDS_DYNAMIC_DEFAULT_NULL
.upper() : MODEL_PCD_DYNAMIC_DEFAULT
,
696 TAB_PCDS_DYNAMIC_HII_NULL
.upper() : MODEL_PCD_DYNAMIC_HII
,
697 TAB_PCDS_DYNAMIC_VPD_NULL
.upper() : MODEL_PCD_DYNAMIC_VPD
,
698 TAB_PCDS_DYNAMIC_EX_DEFAULT_NULL
.upper() : MODEL_PCD_DYNAMIC_EX_DEFAULT
,
699 TAB_PCDS_DYNAMIC_EX_HII_NULL
.upper() : MODEL_PCD_DYNAMIC_EX_HII
,
700 TAB_PCDS_DYNAMIC_EX_VPD_NULL
.upper() : MODEL_PCD_DYNAMIC_EX_VPD
,
701 TAB_COMPONENTS
.upper() : MODEL_META_DATA_COMPONENT
,
702 TAB_COMPONENTS_SOURCE_OVERRIDE_PATH
.upper() : MODEL_META_DATA_COMPONENT_SOURCE_OVERRIDE_PATH
,
703 TAB_DSC_DEFINES
.upper() : MODEL_META_DATA_HEADER
,
704 TAB_DSC_DEFINES_DEFINE
: MODEL_META_DATA_DEFINE
,
705 TAB_DSC_DEFINES_EDKGLOBAL
: MODEL_META_DATA_GLOBAL_DEFINE
,
706 TAB_INCLUDE
.upper() : MODEL_META_DATA_INCLUDE
,
707 TAB_IF
.upper() : MODEL_META_DATA_CONDITIONAL_STATEMENT_IF
,
708 TAB_IF_DEF
.upper() : MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF
,
709 TAB_IF_N_DEF
.upper() : MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF
,
710 TAB_ELSE_IF
.upper() : MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSEIF
,
711 TAB_ELSE
.upper() : MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE
,
712 TAB_END_IF
.upper() : MODEL_META_DATA_CONDITIONAL_STATEMENT_ENDIF
,
715 # Valid names in define section
722 "SUPPORTED_ARCHITECTURES",
731 "FIX_LOAD_TOP_MEMORY_ADDRESS"
734 SymbolPattern
= ValueExpression
.SymbolPattern
736 ## Constructor of DscParser
738 # Initialize object of DscParser
740 # @param FilePath The path of platform description file
741 # @param FileType The raw data of DSC file
742 # @param Table Database used to retrieve module/package information
743 # @param Macros Macros used for replacement in file
744 # @param Owner Owner ID (for sub-section parsing)
745 # @param From ID from which the data comes (for !INCLUDE directive)
747 def __init__(self
, FilePath
, FileType
, Table
, Owner
=-1, From
=-1):
748 # prevent re-initialization
749 if hasattr(self
, "_Table"):
751 MetaFileParser
.__init
__(self
, FilePath
, FileType
, Table
, Owner
, From
)
752 self
._Version
= 0x00010005 # Only EDK2 dsc file is supported
753 # to store conditional directive evaluation result
754 self
._DirectiveStack
= []
755 self
._DirectiveEvalStack
= []
758 # Final valid replacable symbols
761 # Map the ID between the original table and new table to track
764 self
._IdMapping
= {-1:-1}
766 self
.TblFile
= EccGlobalData
.gDb
.TblFile
773 Content
= open(str(self
.MetaFile
), 'r').readlines()
775 EdkLogger
.error("Parser", FILE_READ_FAILURE
, ExtraData
=self
.MetaFile
)
777 # Insert a record for file
779 Filename
= NormPath(self
.MetaFile
)
780 FileID
= self
.TblFile
.GetFileId(Filename
)
784 self
.FileID
= self
.TblFile
.InsertFile(Filename
, MODEL_FILE_DSC
)
787 for Index
in range(0, len(Content
)):
788 Line
= CleanString(Content
[Index
])
793 self
._CurrentLine
= Line
794 self
._LineIndex
= Index
795 if self
._InSubsection
and self
._Owner
[-1] == -1:
796 self
._Owner
.append(self
._LastItem
)
799 if Line
[0] == TAB_SECTION_START
and Line
[-1] == TAB_SECTION_END
:
800 self
._SectionType
= MODEL_META_DATA_SECTION_HEADER
802 elif Line
[0] == '}' and self
._InSubsection
:
803 self
._InSubsection
= False
804 self
._SubsectionType
= MODEL_UNKNOWN
805 self
._SubsectionName
= ''
809 elif Line
[0] == TAB_OPTION_START
and Line
[-1] == TAB_OPTION_END
:
810 self
._SubsectionType
= MODEL_META_DATA_SUBSECTION_HEADER
813 self
._DirectiveParser
()
816 if self
._InSubsection
:
817 SectionType
= self
._SubsectionType
819 SectionType
= self
._SectionType
820 self
._ItemType
= SectionType
822 self
._ValueList
= ['', '', '']
823 self
._SectionParser
[SectionType
](self
)
824 if self
._ValueList
== None:
827 # Model, Value1, Value2, Value3, Arch, ModuleType, BelongsToItem=-1, BelongsToFile=-1,
828 # LineBegin=-1, ColumnBegin=-1, LineEnd=-1, ColumnEnd=-1, Enabled=-1
830 for Arch
, ModuleType
in self
._Scope
:
831 self
._LastItem
= self
._Store
(
848 if self
._DirectiveStack
:
849 Type
, Line
, Text
= self
._DirectiveStack
[-1]
850 EdkLogger
.error('Parser', FORMAT_INVALID
, "No matching '!endif' found",
851 ExtraData
=Text
, File
=self
.MetaFile
, Line
=Line
)
854 ## <subsection_header> parser
855 def _SubsectionHeaderParser(self
):
856 self
._SubsectionName
= self
._CurrentLine
[1:-1].upper()
857 if self
._SubsectionName
in self
.DataType
:
858 self
._SubsectionType
= self
.DataType
[self
._SubsectionName
]
860 self
._SubsectionType
= MODEL_UNKNOWN
861 EdkLogger
.warn("Parser", "Unrecognized sub-section", File
=self
.MetaFile
,
862 Line
=self
._LineIndex
+1, ExtraData
=self
._CurrentLine
)
863 self
._ValueList
[0] = self
._SubsectionName
865 ## Directive statement parser
866 def _DirectiveParser(self
):
867 self
._ValueList
= ['','','']
868 TokenList
= GetSplitValueList(self
._CurrentLine
, ' ', 1)
869 self
._ValueList
[0:len(TokenList
)] = TokenList
872 DirectiveName
= self
._ValueList
[0].upper()
873 if DirectiveName
not in self
.DataType
:
874 EdkLogger
.error("Parser", FORMAT_INVALID
, "Unknown directive [%s]" % DirectiveName
,
875 File
=self
.MetaFile
, Line
=self
._LineIndex
+1)
876 if DirectiveName
in ['!IF', '!IFDEF', '!INCLUDE', '!IFNDEF', '!ELSEIF'] and self
._ValueList
[1] == '':
877 EdkLogger
.error("Parser", FORMAT_INVALID
, "Missing expression",
878 File
=self
.MetaFile
, Line
=self
._LineIndex
+1,
879 ExtraData
=self
._CurrentLine
)
881 ItemType
= self
.DataType
[DirectiveName
]
882 if ItemType
== MODEL_META_DATA_CONDITIONAL_STATEMENT_ENDIF
:
883 # Remove all directives between !if and !endif, including themselves
884 while self
._DirectiveStack
:
885 # Remove any !else or !elseif
886 DirectiveInfo
= self
._DirectiveStack
.pop()
887 if DirectiveInfo
[0] in [MODEL_META_DATA_CONDITIONAL_STATEMENT_IF
,
888 MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF
,
889 MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF
]:
892 EdkLogger
.error("Parser", FORMAT_INVALID
, "Redundant '!endif'",
893 File
=self
.MetaFile
, Line
=self
._LineIndex
+1,
894 ExtraData
=self
._CurrentLine
)
895 elif ItemType
!= MODEL_META_DATA_INCLUDE
:
896 # Break if there's a !else is followed by a !elseif
897 if ItemType
== MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSEIF
and \
898 self
._DirectiveStack
and \
899 self
._DirectiveStack
[-1][0] == MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE
:
900 EdkLogger
.error("Parser", FORMAT_INVALID
, "'!elseif' after '!else'",
901 File
=self
.MetaFile
, Line
=self
._LineIndex
+1,
902 ExtraData
=self
._CurrentLine
)
903 self
._DirectiveStack
.append((ItemType
, self
._LineIndex
+1, self
._CurrentLine
))
905 EdkLogger
.error('Parser', FORMAT_INVALID
,
906 "No '!include' allowed in included file",
907 ExtraData
=self
._CurrentLine
, File
=self
.MetaFile
,
908 Line
=self
._LineIndex
+1)
911 # Model, Value1, Value2, Value3, Arch, ModuleType, BelongsToItem=-1, BelongsToFile=-1,
912 # LineBegin=-1, ColumnBegin=-1, LineEnd=-1, ColumnEnd=-1, Enabled=-1
914 self
._LastItem
= self
._Store
(
931 ## [defines] section parser
933 def _DefineParser(self
):
934 TokenList
= GetSplitValueList(self
._CurrentLine
, TAB_EQUAL_SPLIT
, 1)
935 self
._ValueList
[1:len(TokenList
)] = TokenList
938 if not self
._ValueList
[1]:
939 EdkLogger
.error('Parser', FORMAT_INVALID
, "No name specified",
940 ExtraData
=self
._CurrentLine
, File
=self
.MetaFile
, Line
=self
._LineIndex
+1)
941 if not self
._ValueList
[2]:
942 EdkLogger
.error('Parser', FORMAT_INVALID
, "No value specified",
943 ExtraData
=self
._CurrentLine
, File
=self
.MetaFile
, Line
=self
._LineIndex
+1)
944 if not self
._ValueList
[1] in self
.DefineKeywords
:
945 EdkLogger
.error('Parser', FORMAT_INVALID
,
946 "Unknown keyword found: %s. "
947 "If this is a macro you must "
948 "add it as a DEFINE in the DSC" % self
._ValueList
[1],
949 ExtraData
=self
._CurrentLine
, File
=self
.MetaFile
, Line
=self
._LineIndex
+1)
950 self
._Defines
[self
._ValueList
[1]] = self
._ValueList
[2]
951 self
._ItemType
= self
.DataType
[TAB_DSC_DEFINES
.upper()]
954 def _SkuIdParser(self
):
955 TokenList
= GetSplitValueList(self
._CurrentLine
, TAB_VALUE_SPLIT
)
956 if len(TokenList
) != 2:
957 EdkLogger
.error('Parser', FORMAT_INVALID
, "Correct format is '<Integer>|<UiName>'",
958 ExtraData
=self
._CurrentLine
, File
=self
.MetaFile
, Line
=self
._LineIndex
+1)
959 self
._ValueList
[0:len(TokenList
)] = TokenList
961 ## Parse Edk style of library modules
962 def _LibraryInstanceParser(self
):
963 self
._ValueList
[0] = self
._CurrentLine
965 ## PCD sections parser
968 # [PcdsPatchableInModule]
971 # [PcdsDynamicExDefault]
975 # [PcdsDynamicDefault]
980 def _PcdParser(self
):
981 TokenList
= GetSplitValueList(self
._CurrentLine
, TAB_VALUE_SPLIT
, 1)
982 self
._ValueList
[0:1] = GetSplitValueList(TokenList
[0], TAB_SPLIT
)
983 if len(TokenList
) == 2:
984 self
._ValueList
[2] = TokenList
[1]
985 if self
._ValueList
[0] == '' or self
._ValueList
[1] == '':
986 EdkLogger
.error('Parser', FORMAT_INVALID
, "No token space GUID or PCD name specified",
987 ExtraData
=self
._CurrentLine
+ " (<TokenSpaceGuidCName>.<TokenCName>|<PcdValue>)",
988 File
=self
.MetaFile
, Line
=self
._LineIndex
+1)
989 if self
._ValueList
[2] == '':
990 EdkLogger
.error('Parser', FORMAT_INVALID
, "No PCD value given",
991 ExtraData
=self
._CurrentLine
+ " (<TokenSpaceGuidCName>.<TokenCName>|<PcdValue>)",
992 File
=self
.MetaFile
, Line
=self
._LineIndex
+1)
993 # if value are 'True', 'true', 'TRUE' or 'False', 'false', 'FALSE', replace with integer 1 or 0.
994 DscPcdValueList
= GetSplitValueList(TokenList
[1], TAB_VALUE_SPLIT
, 1)
995 if DscPcdValueList
[0] in ['True', 'true', 'TRUE']:
996 self
._ValueList
[2] = TokenList
[1].replace(DscPcdValueList
[0], '1', 1);
997 elif DscPcdValueList
[0] in ['False', 'false', 'FALSE']:
998 self
._ValueList
[2] = TokenList
[1].replace(DscPcdValueList
[0], '0', 1);
1000 ## [components] section parser
1002 def _ComponentParser(self
):
1003 if self
._CurrentLine
[-1] == '{':
1004 self
._ValueList
[0] = self
._CurrentLine
[0:-1].strip()
1005 self
._InSubsection
= True
1007 self
._ValueList
[0] = self
._CurrentLine
1009 ## [LibraryClasses] section
1011 def _LibraryClassParser(self
):
1012 TokenList
= GetSplitValueList(self
._CurrentLine
, TAB_VALUE_SPLIT
)
1013 if len(TokenList
) < 2:
1014 EdkLogger
.error('Parser', FORMAT_INVALID
, "No library class or instance specified",
1015 ExtraData
=self
._CurrentLine
+ " (<LibraryClassName>|<LibraryInstancePath>)",
1016 File
=self
.MetaFile
, Line
=self
._LineIndex
+1)
1017 if TokenList
[0] == '':
1018 EdkLogger
.error('Parser', FORMAT_INVALID
, "No library class specified",
1019 ExtraData
=self
._CurrentLine
+ " (<LibraryClassName>|<LibraryInstancePath>)",
1020 File
=self
.MetaFile
, Line
=self
._LineIndex
+1)
1021 if TokenList
[1] == '':
1022 EdkLogger
.error('Parser', FORMAT_INVALID
, "No library instance specified",
1023 ExtraData
=self
._CurrentLine
+ " (<LibraryClassName>|<LibraryInstancePath>)",
1024 File
=self
.MetaFile
, Line
=self
._LineIndex
+1)
1026 self
._ValueList
[0:len(TokenList
)] = TokenList
1028 def _CompponentSourceOverridePathParser(self
):
1029 self
._ValueList
[0] = self
._CurrentLine
1031 ## [BuildOptions] section parser
1033 def _BuildOptionParser(self
):
1034 TokenList
= GetSplitValueList(self
._CurrentLine
, TAB_EQUAL_SPLIT
, 1)
1035 TokenList2
= GetSplitValueList(TokenList
[0], ':', 1)
1036 if len(TokenList2
) == 2:
1037 self
._ValueList
[0] = TokenList2
[0] # toolchain family
1038 self
._ValueList
[1] = TokenList2
[1] # keys
1040 self
._ValueList
[1] = TokenList
[0]
1041 if len(TokenList
) == 2: # value
1042 self
._ValueList
[2] = TokenList
[1]
1044 if self
._ValueList
[1].count('_') != 4:
1048 "'%s' must be in format of <TARGET>_<TOOLCHAIN>_<ARCH>_<TOOL>_FLAGS" % self
._ValueList
[1],
1049 ExtraData
=self
._CurrentLine
,
1051 Line
=self
._LineIndex
+1
1054 ## Override parent's method since we'll do all macro replacements in parser
1055 def _GetMacros(self
):
1057 Macros
.update(self
._FileLocalMacros
)
1058 Macros
.update(self
._GetApplicableSectionMacro
())
1059 Macros
.update(GlobalData
.gEdkGlobal
)
1060 Macros
.update(GlobalData
.gPlatformDefines
)
1061 Macros
.update(GlobalData
.gCommandLineDefines
)
1062 # PCD cannot be referenced in macro definition
1063 if self
._ItemType
not in [MODEL_META_DATA_DEFINE
, MODEL_META_DATA_GLOBAL_DEFINE
]:
1064 Macros
.update(self
._Symbols
)
1067 def _PostProcess(self
):
1069 MODEL_META_DATA_SECTION_HEADER
: self
.__ProcessSectionHeader
,
1070 MODEL_META_DATA_SUBSECTION_HEADER
: self
.__ProcessSubsectionHeader
,
1071 MODEL_META_DATA_HEADER
: self
.__ProcessDefine
,
1072 MODEL_META_DATA_DEFINE
: self
.__ProcessDefine
,
1073 MODEL_META_DATA_GLOBAL_DEFINE
: self
.__ProcessDefine
,
1074 MODEL_META_DATA_INCLUDE
: self
.__ProcessDirective
,
1075 MODEL_META_DATA_CONDITIONAL_STATEMENT_IF
: self
.__ProcessDirective
,
1076 MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE
: self
.__ProcessDirective
,
1077 MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF
: self
.__ProcessDirective
,
1078 MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF
: self
.__ProcessDirective
,
1079 MODEL_META_DATA_CONDITIONAL_STATEMENT_ENDIF
: self
.__ProcessDirective
,
1080 MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSEIF
: self
.__ProcessDirective
,
1081 MODEL_EFI_SKU_ID
: self
.__ProcessSkuId
,
1082 MODEL_EFI_LIBRARY_INSTANCE
: self
.__ProcessLibraryInstance
,
1083 MODEL_EFI_LIBRARY_CLASS
: self
.__ProcessLibraryClass
,
1084 MODEL_PCD_FIXED_AT_BUILD
: self
.__ProcessPcd
,
1085 MODEL_PCD_PATCHABLE_IN_MODULE
: self
.__ProcessPcd
,
1086 MODEL_PCD_FEATURE_FLAG
: self
.__ProcessPcd
,
1087 MODEL_PCD_DYNAMIC_DEFAULT
: self
.__ProcessPcd
,
1088 MODEL_PCD_DYNAMIC_HII
: self
.__ProcessPcd
,
1089 MODEL_PCD_DYNAMIC_VPD
: self
.__ProcessPcd
,
1090 MODEL_PCD_DYNAMIC_EX_DEFAULT
: self
.__ProcessPcd
,
1091 MODEL_PCD_DYNAMIC_EX_HII
: self
.__ProcessPcd
,
1092 MODEL_PCD_DYNAMIC_EX_VPD
: self
.__ProcessPcd
,
1093 MODEL_META_DATA_COMPONENT
: self
.__ProcessComponent
,
1094 MODEL_META_DATA_COMPONENT_SOURCE_OVERRIDE_PATH
: self
.__ProcessSourceOverridePath
,
1095 MODEL_META_DATA_BUILD_OPTION
: self
.__ProcessBuildOption
,
1096 MODEL_UNKNOWN
: self
._Skip
,
1097 MODEL_META_DATA_USER_EXTENSION
: self
._Skip
,
1100 self
._RawTable
= self
._Table
1101 self
._Table
= MetaFileStorage(self
._RawTable
.Cur
, self
.MetaFile
, MODEL_FILE_DSC
, True)
1102 self
._DirectiveStack
= []
1103 self
._DirectiveEvalStack
= []
1104 self
._FileWithError
= self
.MetaFile
1105 self
._FileLocalMacros
= {}
1106 self
._SectionsMacroDict
= {}
1107 GlobalData
.gPlatformDefines
= {}
1109 # Get all macro and PCD which has straitforward value
1110 self
.__RetrievePcdValue
()
1111 self
._Content
= self
._RawTable
.GetAll()
1112 self
._ContentIndex
= 0
1113 while self
._ContentIndex
< len(self
._Content
) :
1114 Id
, self
._ItemType
, V1
, V2
, V3
, S1
, S2
, Owner
, BelongsToFile
, self
._From
, \
1115 LineStart
, ColStart
, LineEnd
, ColEnd
, Enabled
= self
._Content
[self
._ContentIndex
]
1118 self
._FileWithError
= self
.MetaFile
1120 self
._ContentIndex
+= 1
1122 self
._Scope
= [[S1
, S2
]]
1123 self
._LineIndex
= LineStart
- 1
1124 self
._ValueList
= [V1
, V2
, V3
]
1127 Processer
[self
._ItemType
]()
1128 except EvaluationException
, Excpt
:
1130 # Only catch expression evaluation error here. We need to report
1131 # the precise number of line on which the error occurred
1133 EdkLogger
.error('Parser', FORMAT_INVALID
, "Invalid expression: %s" % str(Excpt
),
1134 File
=self
._FileWithError
, ExtraData
=' '.join(self
._ValueList
),
1135 Line
=self
._LineIndex
+1)
1136 except MacroException
, Excpt
:
1137 EdkLogger
.error('Parser', FORMAT_INVALID
, str(Excpt
),
1138 File
=self
._FileWithError
, ExtraData
=' '.join(self
._ValueList
),
1139 Line
=self
._LineIndex
+1)
1141 if self
._ValueList
== None:
1144 NewOwner
= self
._IdMapping
.get(Owner
, -1)
1145 self
._Enabled
= int((not self
._DirectiveEvalStack
) or (False not in self
._DirectiveEvalStack
))
1146 self
._LastItem
= self
._Store
(
1162 self
._IdMapping
[Id
] = self
._LastItem
1164 RecordList
= self
._Table
.GetAll()
1165 for Record
in RecordList
:
1166 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])
1167 GlobalData
.gPlatformDefines
.update(self
._FileLocalMacros
)
1168 self
._PostProcessed
= True
1169 self
._Content
= None
1171 def __ProcessSectionHeader(self
):
1172 self
._SectionName
= self
._ValueList
[0]
1173 if self
._SectionName
in self
.DataType
:
1174 self
._SectionType
= self
.DataType
[self
._SectionName
]
1176 self
._SectionType
= MODEL_UNKNOWN
1178 def __ProcessSubsectionHeader(self
):
1179 self
._SubsectionName
= self
._ValueList
[0]
1180 if self
._SubsectionName
in self
.DataType
:
1181 self
._SubsectionType
= self
.DataType
[self
._SubsectionName
]
1183 self
._SubsectionType
= MODEL_UNKNOWN
1185 def __RetrievePcdValue(self
):
1186 Records
= self
._RawTable
.Query(MODEL_PCD_FEATURE_FLAG
, BelongsToItem
=-1.0)
1187 for TokenSpaceGuid
,PcdName
,Value
,Dummy2
,Dummy3
,ID
,Line
in Records
:
1188 Value
, DatumType
, MaxDatumSize
= AnalyzePcdData(Value
)
1189 # Only use PCD whose value is straitforward (no macro and PCD)
1190 if self
.SymbolPattern
.findall(Value
):
1192 Name
= TokenSpaceGuid
+ '.' + PcdName
1193 # Don't use PCD with different values.
1194 if Name
in self
._Symbols
and self
._Symbols
[Name
] != Value
:
1195 self
._Symbols
.pop(Name
)
1197 self
._Symbols
[Name
] = Value
1199 Records
= self
._RawTable
.Query(MODEL_PCD_FIXED_AT_BUILD
, BelongsToItem
=-1.0)
1200 for TokenSpaceGuid
,PcdName
,Value
,Dummy2
,Dummy3
,ID
,Line
in Records
:
1201 Value
, DatumType
, MaxDatumSize
= AnalyzePcdData(Value
)
1202 # Only use PCD whose value is straitforward (no macro and PCD)
1203 if self
.SymbolPattern
.findall(Value
):
1205 Name
= TokenSpaceGuid
+'.'+PcdName
1206 # Don't use PCD with different values.
1207 if Name
in self
._Symbols
and self
._Symbols
[Name
] != Value
:
1208 self
._Symbols
.pop(Name
)
1210 self
._Symbols
[Name
] = Value
1212 def __ProcessDefine(self
):
1213 if not self
._Enabled
:
1216 Type
, Name
, Value
= self
._ValueList
1217 Value
= ReplaceMacro(Value
, self
._Macros
, False)
1218 if self
._ItemType
== MODEL_META_DATA_DEFINE
:
1219 if self
._SectionType
== MODEL_META_DATA_HEADER
:
1220 self
._FileLocalMacros
[Name
] = Value
1222 SectionDictKey
= self
._SectionType
, self
._Scope
[0][0], self
._Scope
[0][1]
1223 if SectionDictKey
not in self
._SectionsMacroDict
:
1224 self
._SectionsMacroDict
[SectionDictKey
] = {}
1225 SectionLocalMacros
= self
._SectionsMacroDict
[SectionDictKey
]
1226 SectionLocalMacros
[Name
] = Value
1227 elif self
._ItemType
== MODEL_META_DATA_GLOBAL_DEFINE
:
1228 GlobalData
.gEdkGlobal
[Name
] = Value
1231 # Keyword in [Defines] section can be used as Macros
1233 if (self
._ItemType
== MODEL_META_DATA_HEADER
) and (self
._SectionType
== MODEL_META_DATA_HEADER
):
1234 self
._FileLocalMacros
[Name
] = Value
1236 self
._ValueList
= [Type
, Name
, Value
]
1238 def __ProcessDirective(self
):
1240 if self
._ItemType
in [MODEL_META_DATA_CONDITIONAL_STATEMENT_IF
,
1241 MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSEIF
]:
1242 Macros
= self
._Macros
1243 Macros
.update(GlobalData
.gGlobalDefines
)
1245 Result
= ValueExpression(self
._ValueList
[1], Macros
)()
1246 except SymbolNotFound
, Exc
:
1247 EdkLogger
.debug(EdkLogger
.DEBUG_5
, str(Exc
), self
._ValueList
[1])
1249 except WrnExpression
, Excpt
:
1251 # Catch expression evaluation warning here. We need to report
1252 # the precise number of line and return the evaluation result
1254 EdkLogger
.warn('Parser', "Suspicious expression: %s" % str(Excpt
),
1255 File
=self
._FileWithError
, ExtraData
=' '.join(self
._ValueList
),
1256 Line
=self
._LineIndex
+1)
1257 Result
= Excpt
.result
1259 if self
._ItemType
in [MODEL_META_DATA_CONDITIONAL_STATEMENT_IF
,
1260 MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF
,
1261 MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF
]:
1262 self
._DirectiveStack
.append(self
._ItemType
)
1263 if self
._ItemType
== MODEL_META_DATA_CONDITIONAL_STATEMENT_IF
:
1264 Result
= bool(Result
)
1266 Macro
= self
._ValueList
[1]
1267 Macro
= Macro
[2:-1] if (Macro
.startswith("$(") and Macro
.endswith(")")) else Macro
1268 Result
= Macro
in self
._Macros
1269 if self
._ItemType
== MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF
:
1271 self
._DirectiveEvalStack
.append(Result
)
1272 elif self
._ItemType
== MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSEIF
:
1273 self
._DirectiveStack
.append(self
._ItemType
)
1274 self
._DirectiveEvalStack
[-1] = not self
._DirectiveEvalStack
[-1]
1275 self
._DirectiveEvalStack
.append(bool(Result
))
1276 elif self
._ItemType
== MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE
:
1277 self
._DirectiveStack
[-1] = self
._ItemType
1278 self
._DirectiveEvalStack
[-1] = not self
._DirectiveEvalStack
[-1]
1279 elif self
._ItemType
== MODEL_META_DATA_CONDITIONAL_STATEMENT_ENDIF
:
1280 # Back to the nearest !if/!ifdef/!ifndef
1281 while self
._DirectiveStack
:
1282 self
._DirectiveEvalStack
.pop()
1283 Directive
= self
._DirectiveStack
.pop()
1284 if Directive
in [MODEL_META_DATA_CONDITIONAL_STATEMENT_IF
,
1285 MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF
,
1286 MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE
,
1287 MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF
]:
1289 elif self
._ItemType
== MODEL_META_DATA_INCLUDE
:
1290 # The included file must be relative to workspace or same directory as DSC file
1291 __IncludeMacros
= {}
1293 # Allow using system environment variables in path after !include
1295 __IncludeMacros
['WORKSPACE'] = GlobalData
.gGlobalDefines
['WORKSPACE']
1296 if "ECP_SOURCE" in GlobalData
.gGlobalDefines
.keys():
1297 __IncludeMacros
['ECP_SOURCE'] = GlobalData
.gGlobalDefines
['ECP_SOURCE']
1299 # During GenFds phase call DSC parser, will go into this branch.
1301 elif "ECP_SOURCE" in GlobalData
.gCommandLineDefines
.keys():
1302 __IncludeMacros
['ECP_SOURCE'] = GlobalData
.gCommandLineDefines
['ECP_SOURCE']
1304 __IncludeMacros
['EFI_SOURCE'] = GlobalData
.gGlobalDefines
['EFI_SOURCE']
1305 __IncludeMacros
['EDK_SOURCE'] = GlobalData
.gGlobalDefines
['EDK_SOURCE']
1307 # Allow using MACROs comes from [Defines] section to keep compatible.
1309 __IncludeMacros
.update(self
._Macros
)
1311 IncludedFile
= NormPath(ReplaceMacro(self
._ValueList
[1], __IncludeMacros
, RaiseError
=True))
1313 # First search the include file under the same directory as DSC file
1315 IncludedFile1
= PathClass(IncludedFile
, self
.MetaFile
.Dir
)
1316 ErrorCode
, ErrorInfo1
= IncludedFile1
.Validate()
1319 # Also search file under the WORKSPACE directory
1321 IncludedFile1
= PathClass(IncludedFile
, GlobalData
.gWorkspace
)
1322 ErrorCode
, ErrorInfo2
= IncludedFile1
.Validate()
1324 EdkLogger
.error('parser', ErrorCode
, File
=self
._FileWithError
,
1325 Line
=self
._LineIndex
+1, ExtraData
=ErrorInfo1
+ "\n"+ ErrorInfo2
)
1327 self
._FileWithError
= IncludedFile1
1329 IncludedFileTable
= MetaFileStorage(self
._Table
.Cur
, IncludedFile1
, MODEL_FILE_DSC
, True)
1330 Owner
= self
._Content
[self
._ContentIndex
-1][0]
1331 Parser
= DscParser(IncludedFile1
, self
._FileType
, IncludedFileTable
,
1332 Owner
=Owner
, From
=Owner
)
1334 # set the parser status with current status
1335 Parser
._SectionName
= self
._SectionName
1336 Parser
._SectionType
= self
._SectionType
1337 Parser
._Scope
= self
._Scope
1338 Parser
._Enabled
= self
._Enabled
1339 # Parse the included file
1342 # update current status with sub-parser's status
1343 self
._SectionName
= Parser
._SectionName
1344 self
._SectionType
= Parser
._SectionType
1345 self
._Scope
= Parser
._Scope
1346 self
._Enabled
= Parser
._Enabled
1348 # Insert all records in the table for the included file into dsc file table
1349 Records
= IncludedFileTable
.GetAll()
1351 self
._Content
[self
._ContentIndex
:self
._ContentIndex
] = Records
1352 self
._Content
.pop(self
._ContentIndex
-1)
1353 self
._ValueList
= None
1354 self
._ContentIndex
-= 1
1356 def __ProcessSkuId(self
):
1357 self
._ValueList
= [ReplaceMacro(Value
, self
._Macros
, RaiseError
=True)
1358 for Value
in self
._ValueList
]
1360 def __ProcessLibraryInstance(self
):
1361 self
._ValueList
= [ReplaceMacro(Value
, self
._Macros
) for Value
in self
._ValueList
]
1363 def __ProcessLibraryClass(self
):
1364 self
._ValueList
[1] = ReplaceMacro(self
._ValueList
[1], self
._Macros
, RaiseError
=True)
1366 def __ProcessPcd(self
):
1367 ValueList
= GetSplitValueList(self
._ValueList
[2])
1369 # PCD value can be an expression
1371 if len(ValueList
) > 1 and ValueList
[1] == 'VOID*':
1372 PcdValue
= ValueList
[0]
1374 ValueList
[0] = ValueExpression(PcdValue
, self
._Macros
)(True)
1375 except WrnExpression
, Value
:
1376 ValueList
[0] = Value
.result
1378 PcdValue
= ValueList
[-1]
1380 ValueList
[-1] = ValueExpression(PcdValue
, self
._Macros
)(True)
1381 except WrnExpression
, Value
:
1382 ValueList
[-1] = Value
.result
1384 if ValueList
[-1] == 'True':
1386 if ValueList
[-1] == 'False':
1389 self
._ValueList
[2] = '|'.join(ValueList
)
1391 def __ProcessComponent(self
):
1392 self
._ValueList
[0] = ReplaceMacro(self
._ValueList
[0], self
._Macros
)
1394 def __ProcessSourceOverridePath(self
):
1395 self
._ValueList
[0] = ReplaceMacro(self
._ValueList
[0], self
._Macros
)
1397 def __ProcessBuildOption(self
):
1398 self
._ValueList
= [ReplaceMacro(Value
, self
._Macros
, RaiseError
=False)
1399 for Value
in self
._ValueList
]
1402 MODEL_META_DATA_HEADER
: _DefineParser
,
1403 MODEL_EFI_SKU_ID
: _SkuIdParser
,
1404 MODEL_EFI_LIBRARY_INSTANCE
: _LibraryInstanceParser
,
1405 MODEL_EFI_LIBRARY_CLASS
: _LibraryClassParser
,
1406 MODEL_PCD_FIXED_AT_BUILD
: _PcdParser
,
1407 MODEL_PCD_PATCHABLE_IN_MODULE
: _PcdParser
,
1408 MODEL_PCD_FEATURE_FLAG
: _PcdParser
,
1409 MODEL_PCD_DYNAMIC_DEFAULT
: _PcdParser
,
1410 MODEL_PCD_DYNAMIC_HII
: _PcdParser
,
1411 MODEL_PCD_DYNAMIC_VPD
: _PcdParser
,
1412 MODEL_PCD_DYNAMIC_EX_DEFAULT
: _PcdParser
,
1413 MODEL_PCD_DYNAMIC_EX_HII
: _PcdParser
,
1414 MODEL_PCD_DYNAMIC_EX_VPD
: _PcdParser
,
1415 MODEL_META_DATA_COMPONENT
: _ComponentParser
,
1416 MODEL_META_DATA_COMPONENT_SOURCE_OVERRIDE_PATH
: _CompponentSourceOverridePathParser
,
1417 MODEL_META_DATA_BUILD_OPTION
: _BuildOptionParser
,
1418 MODEL_UNKNOWN
: MetaFileParser
._Skip
,
1419 MODEL_META_DATA_USER_EXTENSION
: MetaFileParser
._Skip
,
1420 MODEL_META_DATA_SECTION_HEADER
: MetaFileParser
._SectionHeaderParser
,
1421 MODEL_META_DATA_SUBSECTION_HEADER
: _SubsectionHeaderParser
,
1424 _Macros
= property(_GetMacros
)
1426 ## DEC file parser class
1428 # @param FilePath The path of platform description file
1429 # @param FileType The raw data of DSC file
1430 # @param Table Database used to retrieve module/package information
1431 # @param Macros Macros used for replacement in file
1433 class DecParser(MetaFileParser
):
1434 # DEC file supported data types (one type per section)
1436 TAB_DEC_DEFINES
.upper() : MODEL_META_DATA_HEADER
,
1437 TAB_DSC_DEFINES_DEFINE
: MODEL_META_DATA_DEFINE
,
1438 TAB_INCLUDES
.upper() : MODEL_EFI_INCLUDE
,
1439 TAB_LIBRARY_CLASSES
.upper() : MODEL_EFI_LIBRARY_CLASS
,
1440 TAB_GUIDS
.upper() : MODEL_EFI_GUID
,
1441 TAB_PPIS
.upper() : MODEL_EFI_PPI
,
1442 TAB_PROTOCOLS
.upper() : MODEL_EFI_PROTOCOL
,
1443 TAB_PCDS_FIXED_AT_BUILD_NULL
.upper() : MODEL_PCD_FIXED_AT_BUILD
,
1444 TAB_PCDS_PATCHABLE_IN_MODULE_NULL
.upper() : MODEL_PCD_PATCHABLE_IN_MODULE
,
1445 TAB_PCDS_FEATURE_FLAG_NULL
.upper() : MODEL_PCD_FEATURE_FLAG
,
1446 TAB_PCDS_DYNAMIC_NULL
.upper() : MODEL_PCD_DYNAMIC
,
1447 TAB_PCDS_DYNAMIC_EX_NULL
.upper() : MODEL_PCD_DYNAMIC_EX
,
1450 ## Constructor of DecParser
1452 # Initialize object of DecParser
1454 # @param FilePath The path of platform description file
1455 # @param FileType The raw data of DSC file
1456 # @param Table Database used to retrieve module/package information
1457 # @param Macros Macros used for replacement in file
1459 def __init__(self
, FilePath
, FileType
, Table
):
1460 # prevent re-initialization
1461 if hasattr(self
, "_Table"):
1463 MetaFileParser
.__init
__(self
, FilePath
, FileType
, Table
)
1465 self
._Version
= 0x00010005 # Only EDK2 dec file is supported
1466 self
.TblFile
= EccGlobalData
.gDb
.TblFile
1473 Content
= open(str(self
.MetaFile
), 'r').readlines()
1475 EdkLogger
.error("Parser", FILE_READ_FAILURE
, ExtraData
=self
.MetaFile
)
1478 # Insert a record for file
1480 Filename
= NormPath(self
.MetaFile
)
1481 FileID
= self
.TblFile
.GetFileId(Filename
)
1483 self
.FileID
= FileID
1485 self
.FileID
= self
.TblFile
.InsertFile(Filename
, MODEL_FILE_DEC
)
1487 for Index
in range(0, len(Content
)):
1488 Line
, Comment
= CleanString2(Content
[Index
])
1489 self
._CurrentLine
= Line
1490 self
._LineIndex
= Index
1492 # save comment for later use
1494 self
._Comments
.append((Comment
, self
._LineIndex
+1))
1500 if Line
[0] == TAB_SECTION_START
and Line
[-1] == TAB_SECTION_END
:
1501 self
._SectionHeaderParser
()
1504 elif len(self
._SectionType
) == 0:
1509 self
._ValueList
= ['','','']
1510 self
._SectionParser
[self
._SectionType
[0]](self
)
1511 if self
._ValueList
== None or self
._ItemType
== MODEL_META_DATA_DEFINE
:
1517 # Model, Value1, Value2, Value3, Arch, BelongsToItem=-1, LineBegin=-1,
1518 # ColumnBegin=-1, LineEnd=-1, ColumnEnd=-1, FeatureFlag='', Enabled=-1
1520 for Arch
, ModuleType
, Type
in self
._Scope
:
1521 self
._LastItem
= self
._Store
(
1536 for Comment
, LineNo
in self
._Comments
:
1538 MODEL_META_DATA_COMMENT
,
1555 def _GetApplicableSectionMacro(self
):
1557 for S1
, S2
, SectionType
in self
._Scope
:
1558 for Scope1
, Scope2
in [("COMMON", "COMMON"), ("COMMON", S2
), (S1
, "COMMON"), (S1
, S2
)]:
1559 if (SectionType
, Scope1
, Scope2
) in self
._SectionsMacroDict
:
1560 Macros
.update(self
._SectionsMacroDict
[(SectionType
, Scope1
, Scope2
)])
1563 ## Section header parser
1565 # The section header is always in following format:
1567 # [section_name.arch<.platform|module_type>]
1569 def _SectionHeaderParser(self
):
1571 self
._SectionName
= ''
1572 self
._SectionType
= []
1574 for Item
in GetSplitValueList(self
._CurrentLine
[1:-1], TAB_COMMA_SPLIT
):
1577 ItemList
= GetSplitValueList(Item
, TAB_SPLIT
)
1579 # different types of PCD are permissible in one section
1580 self
._SectionName
= ItemList
[0].upper()
1581 if self
._SectionName
in self
.DataType
:
1582 if self
.DataType
[self
._SectionName
] not in self
._SectionType
:
1583 self
._SectionType
.append(self
.DataType
[self
._SectionName
])
1585 EdkLogger
.warn("Parser", "Unrecognized section", File
=self
.MetaFile
,
1586 Line
=self
._LineIndex
+1, ExtraData
=self
._CurrentLine
)
1589 if MODEL_PCD_FEATURE_FLAG
in self
._SectionType
and len(self
._SectionType
) > 1:
1593 "%s must not be in the same section of other types of PCD" % TAB_PCDS_FEATURE_FLAG_NULL
,
1595 Line
=self
._LineIndex
+1,
1596 ExtraData
=self
._CurrentLine
1599 if len(ItemList
) > 1:
1600 S1
= ItemList
[1].upper()
1604 # S2 may be Platform or ModuleType
1605 if len(ItemList
) > 2:
1606 S2
= ItemList
[2].upper()
1609 if [S1
, S2
, self
.DataType
[self
._SectionName
]] not in self
._Scope
:
1610 self
._Scope
.append([S1
, S2
, self
.DataType
[self
._SectionName
]])
1612 # 'COMMON' must not be used with specific ARCHs at the same section
1613 if 'COMMON' in ArchList
and len(ArchList
) > 1:
1614 EdkLogger
.error('Parser', FORMAT_INVALID
, "'common' ARCH must not be used with specific ARCHs",
1615 File
=self
.MetaFile
, Line
=self
._LineIndex
+1, ExtraData
=self
._CurrentLine
)
1617 ## [guids], [ppis] and [protocols] section parser
1619 def _GuidParser(self
):
1620 TokenList
= GetSplitValueList(self
._CurrentLine
, TAB_EQUAL_SPLIT
, 1)
1621 if len(TokenList
) < 2:
1622 EdkLogger
.error('Parser', FORMAT_INVALID
, "No GUID name or value specified",
1623 ExtraData
=self
._CurrentLine
+ " (<CName> = <GuidValueInCFormat>)",
1624 File
=self
.MetaFile
, Line
=self
._LineIndex
+1)
1625 if TokenList
[0] == '':
1626 EdkLogger
.error('Parser', FORMAT_INVALID
, "No GUID name specified",
1627 ExtraData
=self
._CurrentLine
+ " (<CName> = <GuidValueInCFormat>)",
1628 File
=self
.MetaFile
, Line
=self
._LineIndex
+1)
1629 if TokenList
[1] == '':
1630 EdkLogger
.error('Parser', FORMAT_INVALID
, "No GUID value specified",
1631 ExtraData
=self
._CurrentLine
+ " (<CName> = <GuidValueInCFormat>)",
1632 File
=self
.MetaFile
, Line
=self
._LineIndex
+1)
1633 if TokenList
[1][0] != '{' or TokenList
[1][-1] != '}' or GuidStructureStringToGuidString(TokenList
[1]) == '':
1634 EdkLogger
.error('Parser', FORMAT_INVALID
, "Invalid GUID value format",
1635 ExtraData
=self
._CurrentLine
+ \
1636 " (<CName> = <GuidValueInCFormat:{8,4,4,{2,2,2,2,2,2,2,2}}>)",
1637 File
=self
.MetaFile
, Line
=self
._LineIndex
+1)
1638 self
._ValueList
[0] = TokenList
[0]
1639 #Parse the Guid value format
1640 GuidValueList
= TokenList
[1].strip(' {}').split(',')
1643 if len(GuidValueList
) == 11:
1644 for GuidValue
in GuidValueList
:
1645 GuidValue
= GuidValue
.strip()
1646 if GuidValue
.startswith('0x') or GuidValue
.startswith('0X'):
1647 HexList
.append('0x' + str(GuidValue
[2:]))
1651 if GuidValue
.startswith('{'):
1652 HexList
.append('0x' + str(GuidValue
[3:]))
1654 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])
1656 EdkLogger
.error('Parser', FORMAT_INVALID
, "Invalid GUID value format",
1657 ExtraData
=self
._CurrentLine
+ \
1658 " (<CName> = <GuidValueInCFormat:{8,4,4,{2,2,2,2,2,2,2,2}}>)",
1659 File
=self
.MetaFile
, Line
=self
._LineIndex
+1)
1660 self
._ValueList
[0] = ''
1662 ## PCD sections parser
1664 # [PcdsFixedAtBuild]
1665 # [PcdsPatchableInModule]
1671 def _PcdParser(self
):
1672 TokenList
= GetSplitValueList(self
._CurrentLine
, TAB_VALUE_SPLIT
, 1)
1673 self
._ValueList
[0:1] = GetSplitValueList(TokenList
[0], TAB_SPLIT
)
1674 # check PCD information
1675 if self
._ValueList
[0] == '' or self
._ValueList
[1] == '':
1676 EdkLogger
.error('Parser', FORMAT_INVALID
, "No token space GUID or PCD name specified",
1677 ExtraData
=self
._CurrentLine
+ \
1678 " (<TokenSpaceGuidCName>.<PcdCName>|<DefaultValue>|<DatumType>|<Token>)",
1679 File
=self
.MetaFile
, Line
=self
._LineIndex
+1)
1680 # check PCD datum information
1681 if len(TokenList
) < 2 or TokenList
[1] == '':
1682 EdkLogger
.error('Parser', FORMAT_INVALID
, "No PCD Datum information given",
1683 ExtraData
=self
._CurrentLine
+ \
1684 " (<TokenSpaceGuidCName>.<PcdCName>|<DefaultValue>|<DatumType>|<Token>)",
1685 File
=self
.MetaFile
, Line
=self
._LineIndex
+1)
1688 ValueRe
= re
.compile(r
'^\s*L?\".*\|.*\"')
1689 PtrValue
= ValueRe
.findall(TokenList
[1])
1691 # Has VOID* type string, may contain "|" character in the string.
1692 if len(PtrValue
) != 0:
1693 ptrValueList
= re
.sub(ValueRe
, '', TokenList
[1])
1694 ValueList
= GetSplitValueList(ptrValueList
)
1695 ValueList
[0] = PtrValue
[0]
1697 ValueList
= GetSplitValueList(TokenList
[1])
1700 # check if there's enough datum information given
1701 if len(ValueList
) != 3:
1702 EdkLogger
.error('Parser', FORMAT_INVALID
, "Invalid PCD Datum information given",
1703 ExtraData
=self
._CurrentLine
+ \
1704 " (<TokenSpaceGuidCName>.<PcdCName>|<DefaultValue>|<DatumType>|<Token>)",
1705 File
=self
.MetaFile
, Line
=self
._LineIndex
+1)
1706 # check default value
1707 if ValueList
[0] == '':
1708 EdkLogger
.error('Parser', FORMAT_INVALID
, "Missing DefaultValue in PCD Datum information",
1709 ExtraData
=self
._CurrentLine
+ \
1710 " (<TokenSpaceGuidCName>.<PcdCName>|<DefaultValue>|<DatumType>|<Token>)",
1711 File
=self
.MetaFile
, Line
=self
._LineIndex
+1)
1713 if ValueList
[1] == '':
1714 EdkLogger
.error('Parser', FORMAT_INVALID
, "Missing DatumType in PCD Datum information",
1715 ExtraData
=self
._CurrentLine
+ \
1716 " (<TokenSpaceGuidCName>.<PcdCName>|<DefaultValue>|<DatumType>|<Token>)",
1717 File
=self
.MetaFile
, Line
=self
._LineIndex
+1)
1718 # check token of the PCD
1719 if ValueList
[2] == '':
1720 EdkLogger
.error('Parser', FORMAT_INVALID
, "Missing Token in PCD Datum information",
1721 ExtraData
=self
._CurrentLine
+ \
1722 " (<TokenSpaceGuidCName>.<PcdCName>|<DefaultValue>|<DatumType>|<Token>)",
1723 File
=self
.MetaFile
, Line
=self
._LineIndex
+1)
1724 # check format of default value against the datum type
1725 IsValid
, Cause
= CheckPcdDatum(ValueList
[1], ValueList
[0])
1727 EdkLogger
.error('Parser', FORMAT_INVALID
, Cause
, ExtraData
=self
._CurrentLine
,
1728 File
=self
.MetaFile
, Line
=self
._LineIndex
+1)
1730 if ValueList
[0] in ['True', 'true', 'TRUE']:
1732 elif ValueList
[0] in ['False', 'false', 'FALSE']:
1735 self
._ValueList
[2] = ValueList
[0].strip() + '|' + ValueList
[1].strip() + '|' + ValueList
[2].strip()
1738 MODEL_META_DATA_HEADER
: MetaFileParser
._DefineParser
,
1739 MODEL_EFI_INCLUDE
: MetaFileParser
._PathParser
,
1740 MODEL_EFI_LIBRARY_CLASS
: MetaFileParser
._PathParser
,
1741 MODEL_EFI_GUID
: _GuidParser
,
1742 MODEL_EFI_PPI
: _GuidParser
,
1743 MODEL_EFI_PROTOCOL
: _GuidParser
,
1744 MODEL_PCD_FIXED_AT_BUILD
: _PcdParser
,
1745 MODEL_PCD_PATCHABLE_IN_MODULE
: _PcdParser
,
1746 MODEL_PCD_FEATURE_FLAG
: _PcdParser
,
1747 MODEL_PCD_DYNAMIC
: _PcdParser
,
1748 MODEL_PCD_DYNAMIC_EX
: _PcdParser
,
1749 MODEL_UNKNOWN
: MetaFileParser
._Skip
,
1750 MODEL_META_DATA_USER_EXTENSION
: MetaFileParser
._Skip
,
1756 # This class defined basic Fdf object which is used by inheriting
1758 # @param object: Inherited from object class
1760 class FdfObject(object):
1766 # This class defined the structure used in Fdf object
1768 # @param FdfObject: Inherited from FdfObject class
1769 # @param Filename: Input value for Ffilename of Fdf file, default is None
1770 # @param WorkspaceDir: Input value for current workspace directory, default is None
1772 class Fdf(FdfObject
):
1773 def __init__(self
, Filename
= None, IsToDatabase
= False, WorkspaceDir
= None, Database
= None):
1774 self
.WorkspaceDir
= WorkspaceDir
1775 self
.IsToDatabase
= IsToDatabase
1777 self
.Cur
= Database
.Cur
1778 self
.TblFile
= Database
.TblFile
1779 self
.TblFdf
= Database
.TblFdf
1784 # Load Fdf file if filename is not None
1786 if Filename
!= None:
1787 self
.LoadFdfFile(Filename
)
1790 # Insert a FDF file record into database
1792 def InsertFile(self
, Filename
):
1794 Filename
= NormPath(Filename
)
1795 if Filename
not in self
.FileList
:
1796 FileID
= self
.TblFile
.InsertFile(Filename
, MODEL_FILE_FDF
)
1797 self
.FileList
[Filename
] = FileID
1799 return self
.FileList
[Filename
]
1804 # Load the file if it exists
1806 # @param Filename: Input value for filename of Fdf file
1808 def LoadFdfFile(self
, Filename
):
1813 Filename
= NormPath(Filename
)
1814 Fdf
= FdfParser(Filename
)
1818 # Insert inf file and pcd information
1820 if self
.IsToDatabase
:
1821 (Model
, Value1
, Value2
, Value3
, Scope1
, Scope2
, BelongsToItem
, BelongsToFile
, StartLine
, StartColumn
, EndLine
, EndColumn
, Enabled
) = \
1822 (0, '', '', '', 'COMMON', 'COMMON', -1, -1, -1, -1, -1, -1, 0)
1823 for Index
in range(0, len(Fdf
.Profile
.PcdDict
)):
1825 for Key
in Fdf
.Profile
.PcdDict
.keys():
1829 FileName
= Fdf
.Profile
.PcdFileLineDict
[Key
][0]
1830 StartLine
= Fdf
.Profile
.PcdFileLineDict
[Key
][1]
1831 BelongsToFile
= self
.InsertFile(FileName
)
1832 self
.TblFdf
.Insert(Model
, Value1
, Value2
, Value3
, Scope1
, Scope2
, BelongsToItem
, BelongsToFile
, StartLine
, StartColumn
, EndLine
, EndColumn
, Enabled
)
1833 for Index
in range(0, len(Fdf
.Profile
.InfList
)):
1834 Model
= MODEL_META_DATA_COMPONENT
1835 Value1
= Fdf
.Profile
.InfList
[Index
]
1837 FileName
= Fdf
.Profile
.InfFileLineList
[Index
][0]
1838 StartLine
= Fdf
.Profile
.InfFileLineList
[Index
][1]
1839 BelongsToFile
= self
.InsertFile(FileName
)
1840 self
.TblFdf
.Insert(Model
, Value1
, Value2
, Value3
, Scope1
, Scope2
, BelongsToItem
, BelongsToFile
, StartLine
, StartColumn
, EndLine
, EndColumn
, Enabled
)
1844 # This acts like the main() function for the script, unless it is 'import'ed into another
1847 if __name__
== '__main__':