2 # This file is used to parse meta files
4 # Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>
5 # (C) Copyright 2015-2018 Hewlett Packard Enterprise Development LP<BR>
6 # This program and the accompanying materials
7 # are licensed and made available under the terms and conditions of the BSD License
8 # which accompanies this distribution. The full text of the license may be found at
9 # http://opensource.org/licenses/bsd-license.php
11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 from __future__
import print_function
19 import Common
.LongFilePathOs
as os
25 import Common
.EdkLogger
as EdkLogger
26 import Common
.GlobalData
as GlobalData
28 from CommonDataClass
.DataClass
import *
29 from Common
.DataType
import *
30 from Common
.StringUtils
import *
31 from Common
.Misc
import GuidStructureStringToGuidString
, CheckPcdDatum
, PathClass
, AnalyzePcdData
, AnalyzeDscPcd
, AnalyzePcdExpression
, ParseFieldValue
32 from Common
.Expression
import *
33 from CommonDataClass
.Exceptions
import *
34 from Common
.LongFilePathSupport
import OpenLongFilePath
as open
35 from collections
import defaultdict
36 from MetaFileTable
import MetaFileStorage
37 from MetaFileCommentParser
import CheckInfComment
39 ## RegEx for finding file versions
40 hexVersionPattern
= re
.compile(r
'0[xX][\da-f-A-F]{5,8}')
41 decVersionPattern
= re
.compile(r
'\d+\.\d+')
43 ## A decorator used to parse macro definition
44 def ParseMacro(Parser
):
45 def MacroParser(self
):
46 Match
= gMacroDefPattern
.match(self
._CurrentLine
)
48 # Not 'DEFINE/EDK_GLOBAL' statement, call decorated method
52 TokenList
= GetSplitValueList(self
._CurrentLine
[Match
.end(1):], TAB_EQUAL_SPLIT
, 1)
55 EdkLogger
.error('Parser', FORMAT_INVALID
, "No macro name given",
56 ExtraData
=self
._CurrentLine
, File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
57 if len(TokenList
) < 2:
61 Name
, Value
= TokenList
62 # Global macros can be only defined via environment variable
63 if Name
in GlobalData
.gGlobalDefines
:
64 EdkLogger
.error('Parser', FORMAT_INVALID
, "%s can only be defined via environment variable" % Name
,
65 ExtraData
=self
._CurrentLine
, File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
66 # Only upper case letters, digit and '_' are allowed
67 if not gMacroNamePattern
.match(Name
):
68 EdkLogger
.error('Parser', FORMAT_INVALID
, "The macro name must be in the pattern [A-Z][A-Z0-9_]*",
69 ExtraData
=self
._CurrentLine
, File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
71 Value
= ReplaceMacro(Value
, self
._Macros
)
72 if Type
in self
.DataType
:
73 self
._ItemType
= self
.DataType
[Type
]
75 self
._ItemType
= MODEL_META_DATA_DEFINE
76 # DEFINE defined macros
77 if Type
== TAB_DSC_DEFINES_DEFINE
:
79 # First judge whether this DEFINE is in conditional directive statements or not.
81 if isinstance(self
, DscParser
) and self
._InDirective
> -1:
84 if isinstance(self
, DecParser
):
85 if MODEL_META_DATA_HEADER
in self
._SectionType
:
86 self
._FileLocalMacros
[Name
] = Value
88 self
._ConstructSectionMacroDict
(Name
, Value
)
89 elif self
._SectionType
== MODEL_META_DATA_HEADER
:
90 self
._FileLocalMacros
[Name
] = Value
92 self
._ConstructSectionMacroDict
(Name
, Value
)
94 # EDK_GLOBAL defined macros
95 elif not isinstance(self
, DscParser
):
96 EdkLogger
.error('Parser', FORMAT_INVALID
, "EDK_GLOBAL can only be used in .dsc file",
97 ExtraData
=self
._CurrentLine
, File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
98 elif self
._SectionType
!= MODEL_META_DATA_HEADER
:
99 EdkLogger
.error('Parser', FORMAT_INVALID
, "EDK_GLOBAL can only be used under [Defines] section",
100 ExtraData
=self
._CurrentLine
, File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
101 elif (Name
in self
._FileLocalMacros
) and (self
._FileLocalMacros
[Name
] != Value
):
102 EdkLogger
.error('Parser', FORMAT_INVALID
, "EDK_GLOBAL defined a macro with the same name and different value as one defined by 'DEFINE'",
103 ExtraData
=self
._CurrentLine
, File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
105 self
._ValueList
= [Type
, Name
, Value
]
109 ## Base class of parser
111 # This class is used for derivation purpose. The specific parser for one kind
112 # type file must derive this class and implement some public interfaces.
114 # @param FilePath The path of platform description file
115 # @param FileType The raw data of DSC file
116 # @param Table Database used to retrieve module/package information
117 # @param Macros Macros used for replacement in file
118 # @param Owner Owner ID (for sub-section parsing)
119 # @param From ID from which the data comes (for !INCLUDE directive)
121 class MetaFileParser(object):
122 # data type (file content) for specific file type
125 # Parser objects used to implement singleton
130 # One file, one parser object. This factory method makes sure that there's
131 # only one object constructed for one meta file.
133 # @param Class class object of real AutoGen class
134 # (InfParser, DecParser or DscParser)
135 # @param FilePath The path of meta file
136 # @param *args The specific class related parameters
137 # @param **kwargs The specific class related dict parameters
139 def __new__(Class
, FilePath
, *args
, **kwargs
):
140 if FilePath
in Class
.MetaFiles
:
141 return Class
.MetaFiles
[FilePath
]
143 ParserObject
= super(MetaFileParser
, Class
).__new
__(Class
)
144 Class
.MetaFiles
[FilePath
] = ParserObject
147 ## Constructor of MetaFileParser
149 # Initialize object of MetaFileParser
151 # @param FilePath The path of platform description file
152 # @param FileType The raw data of DSC file
153 # @param Arch Default Arch value for filtering sections
154 # @param Table Database used to retrieve module/package information
155 # @param Owner Owner ID (for sub-section parsing)
156 # @param From ID from which the data comes (for !INCLUDE directive)
158 def __init__(self
, FilePath
, FileType
, Arch
, Table
, Owner
= -1, From
= -1):
160 self
._RawTable
= Table
162 self
._FileType
= FileType
163 self
.MetaFile
= FilePath
164 self
._FileDir
= self
.MetaFile
.Dir
166 self
._FileLocalMacros
= {}
167 self
._SectionsMacroDict
= defaultdict(dict)
169 # for recursive parsing
170 self
._Owner
= [Owner
]
173 # parsr status for parsing
174 self
._ValueList
= ['', '', '', '', '']
177 self
._CurrentLine
= ''
178 self
._SectionType
= MODEL_UNKNOWN
179 self
._SectionName
= ''
180 self
._InSubsection
= False
181 self
._SubsectionType
= MODEL_UNKNOWN
182 self
._SubsectionName
= ''
183 self
._ItemType
= MODEL_UNKNOWN
186 self
._Finished
= False
187 self
._PostProcessed
= False
188 # Different version of meta-file has different way to parse.
190 self
._GuidDict
= {} # for Parser PCD value {GUID(gTokeSpaceGuidName)}
192 ## Store the parsed data in table
193 def _Store(self
, *Args
):
194 return self
._Table
.Insert(*Args
)
196 ## Virtual method for starting parse
198 raise NotImplementedError
200 ## Notify a post-process is needed
201 def DoPostProcess(self
):
202 self
._PostProcessed
= False
204 ## Set parsing complete flag in both class and table
206 self
._Finished
= True
207 ## Do not set end flag when processing included files
209 self
._Table
.SetEndFlag()
211 def _PostProcess(self
):
212 self
._PostProcessed
= True
214 ## Get the parse complete flag
215 def _GetFinished(self
):
216 return self
._Finished
218 ## Set the complete flag
219 def _SetFinished(self
, Value
):
220 self
._Finished
= Value
222 ## Remove records that do not match given Filter Arch
223 def _FilterRecordList(self
, RecordList
, FilterArch
):
225 for Record
in RecordList
:
227 if Arch
== TAB_ARCH_COMMON
or Arch
== FilterArch
:
228 NewRecordList
.append(Record
)
231 ## Use [] style to query data in table, just for readability
233 # DataInfo = [data_type, scope1(arch), scope2(platform/moduletype)]
235 def __getitem__(self
, DataInfo
):
236 if not isinstance(DataInfo
, type(())):
237 DataInfo
= (DataInfo
,)
239 # Parse the file first, if necessary
240 if not self
._Finished
:
241 if self
._RawTable
.IsIntegrity():
242 self
._Finished
= True
244 self
._Table
= self
._RawTable
245 self
._PostProcessed
= False
248 # No specific ARCH or Platform given, use raw data
249 if self
._RawTable
and (len(DataInfo
) == 1 or DataInfo
[1] is None):
250 return self
._FilterRecordList
(self
._RawTable
.Query(*DataInfo
), self
._Arch
)
252 # Do post-process if necessary
253 if not self
._PostProcessed
:
256 return self
._FilterRecordList
(self
._Table
.Query(*DataInfo
), DataInfo
[1])
258 ## Data parser for the common format in different type of file
260 # The common format in the meatfile is like
265 def _CommonParser(self
):
266 TokenList
= GetSplitValueList(self
._CurrentLine
, TAB_VALUE_SPLIT
)
267 self
._ValueList
[0:len(TokenList
)] = TokenList
269 ## Data parser for the format in which there's path
271 # Only path can have macro used. So we need to replace them before use.
274 def _PathParser(self
):
275 TokenList
= GetSplitValueList(self
._CurrentLine
, TAB_VALUE_SPLIT
)
276 self
._ValueList
[0:len(TokenList
)] = TokenList
277 # Don't do macro replacement for dsc file at this point
278 if not isinstance(self
, DscParser
):
279 Macros
= self
._Macros
280 self
._ValueList
= [ReplaceMacro(Value
, Macros
) for Value
in self
._ValueList
]
282 ## Skip unsupported data
284 EdkLogger
.warn("Parser", "Unrecognized content", File
=self
.MetaFile
,
285 Line
=self
._LineIndex
+ 1, ExtraData
=self
._CurrentLine
);
286 self
._ValueList
[0:1] = [self
._CurrentLine
]
288 ## Skip unsupported data for UserExtension Section
289 def _SkipUserExtension(self
):
290 self
._ValueList
[0:1] = [self
._CurrentLine
]
292 ## Section header parser
294 # The section header is always in following format:
296 # [section_name.arch<.platform|module_type>]
298 def _SectionHeaderParser(self
):
300 self
._SectionName
= ''
302 for Item
in GetSplitValueList(self
._CurrentLine
[1:-1], TAB_COMMA_SPLIT
):
305 ItemList
= GetSplitValueList(Item
, TAB_SPLIT
, 3)
306 # different section should not mix in one section
307 if self
._SectionName
!= '' and self
._SectionName
!= ItemList
[0].upper():
308 EdkLogger
.error('Parser', FORMAT_INVALID
, "Different section names in the same section",
309 File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1, ExtraData
=self
._CurrentLine
)
310 self
._SectionName
= ItemList
[0].upper()
311 if self
._SectionName
in self
.DataType
:
312 self
._SectionType
= self
.DataType
[self
._SectionName
]
313 # Check if the section name is valid
314 if self
._SectionName
not in SECTIONS_HAVE_ITEM_AFTER_ARCH_SET
and len(ItemList
) > 3:
315 EdkLogger
.error("Parser", FORMAT_UNKNOWN_ERROR
, "%s is not a valid section name" % Item
,
316 self
.MetaFile
, self
._LineIndex
+ 1, self
._CurrentLine
)
317 elif self
._Version
>= 0x00010005:
318 EdkLogger
.error("Parser", FORMAT_UNKNOWN_ERROR
, "%s is not a valid section name" % Item
,
319 self
.MetaFile
, self
._LineIndex
+ 1, self
._CurrentLine
)
321 self
._SectionType
= MODEL_UNKNOWN
324 if len(ItemList
) > 1:
325 S1
= ItemList
[1].upper()
330 # S2 may be Platform or ModuleType
331 if len(ItemList
) > 2:
332 if self
._SectionName
.upper() in SECTIONS_HAVE_ITEM_PCD_SET
:
335 S2
= ItemList
[2].upper()
338 if len(ItemList
) > 3:
342 self
._Scope
.append([S1
, S2
, S3
])
344 # 'COMMON' must not be used with specific ARCHs at the same section
345 if TAB_ARCH_COMMON
in ArchList
and len(ArchList
) > 1:
346 EdkLogger
.error('Parser', FORMAT_INVALID
, "'common' ARCH must not be used with specific ARCHs",
347 File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1, ExtraData
=self
._CurrentLine
)
348 # If the section information is needed later, it should be stored in database
349 self
._ValueList
[0] = self
._SectionName
351 ## [defines] section parser
353 def _DefineParser(self
):
354 TokenList
= GetSplitValueList(self
._CurrentLine
, TAB_EQUAL_SPLIT
, 1)
355 self
._ValueList
[1:len(TokenList
)] = TokenList
356 if not self
._ValueList
[1]:
357 EdkLogger
.error('Parser', FORMAT_INVALID
, "No name specified",
358 ExtraData
=self
._CurrentLine
, File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
359 if not self
._ValueList
[2]:
360 EdkLogger
.error('Parser', FORMAT_INVALID
, "No value specified",
361 ExtraData
=self
._CurrentLine
, File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
363 self
._ValueList
= [ReplaceMacro(Value
, self
._Macros
) for Value
in self
._ValueList
]
364 Name
, Value
= self
._ValueList
[1], self
._ValueList
[2]
365 MacroUsed
= GlobalData
.gMacroRefPattern
.findall(Value
)
366 if len(MacroUsed
) != 0:
367 for Macro
in MacroUsed
:
368 if Macro
in GlobalData
.gGlobalDefines
:
369 EdkLogger
.error("Parser", FORMAT_INVALID
, "Global macro %s is not permitted." % (Macro
), ExtraData
=self
._CurrentLine
, File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
371 EdkLogger
.error("Parser", FORMAT_INVALID
, "%s not defined" % (Macro
), ExtraData
=self
._CurrentLine
, File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
372 # Sometimes, we need to make differences between EDK and EDK2 modules
373 if Name
== 'INF_VERSION':
374 if hexVersionPattern
.match(Value
):
375 self
._Version
= int(Value
, 0)
376 elif decVersionPattern
.match(Value
):
377 ValueList
= Value
.split('.')
378 Major
= '%04o' % int(ValueList
[0], 0)
379 Minor
= '%04o' % int(ValueList
[1], 0)
380 self
._Version
= int('0x' + Major
+ Minor
, 0)
382 EdkLogger
.error('Parser', FORMAT_INVALID
, "Invalid version number",
383 ExtraData
=self
._CurrentLine
, File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
385 if isinstance(self
, InfParser
) and self
._Version
< 0x00010005:
386 # EDK module allows using defines as macros
387 self
._FileLocalMacros
[Name
] = Value
388 self
._Defines
[Name
] = Value
390 ## [BuildOptions] section parser
392 def _BuildOptionParser(self
):
393 self
._CurrentLine
= CleanString(self
._CurrentLine
, BuildOption
=True)
394 TokenList
= GetSplitValueList(self
._CurrentLine
, TAB_EQUAL_SPLIT
, 1)
395 TokenList2
= GetSplitValueList(TokenList
[0], ':', 1)
396 if len(TokenList2
) == 2:
397 self
._ValueList
[0] = TokenList2
[0] # toolchain family
398 self
._ValueList
[1] = TokenList2
[1] # keys
400 self
._ValueList
[1] = TokenList
[0]
401 if len(TokenList
) == 2 and not isinstance(self
, DscParser
): # value
402 self
._ValueList
[2] = ReplaceMacro(TokenList
[1], self
._Macros
)
404 if self
._ValueList
[1].count('_') != 4:
408 "'%s' must be in format of <TARGET>_<TOOLCHAIN>_<ARCH>_<TOOL>_FLAGS" % self
._ValueList
[1],
409 ExtraData
=self
._CurrentLine
,
411 Line
=self
._LineIndex
+ 1
413 def GetValidExpression(self
, TokenSpaceGuid
, PcdCName
):
414 return self
._Table
.GetValidExpression(TokenSpaceGuid
, PcdCName
)
415 def _GetMacros(self
):
417 Macros
.update(self
._FileLocalMacros
)
418 Macros
.update(self
._GetApplicableSectionMacro
())
421 ## Construct section Macro dict
422 def _ConstructSectionMacroDict(self
, Name
, Value
):
423 ScopeKey
= [(Scope
[0], Scope
[1], Scope
[2]) for Scope
in self
._Scope
]
424 ScopeKey
= tuple(ScopeKey
)
426 # DecParser SectionType is a list, will contain more than one item only in Pcd Section
427 # As Pcd section macro usage is not alllowed, so here it is safe
429 if isinstance(self
, DecParser
):
430 SectionDictKey
= self
._SectionType
[0], ScopeKey
432 SectionDictKey
= self
._SectionType
, ScopeKey
434 self
._SectionsMacroDict
[SectionDictKey
][Name
] = Value
436 ## Get section Macros that are applicable to current line, which may come from other sections
437 ## that share the same name while scope is wider
438 def _GetApplicableSectionMacro(self
):
445 ActiveSectionType
= self
._SectionType
446 if isinstance(self
, DecParser
):
447 ActiveSectionType
= self
._SectionType
[0]
449 for (SectionType
, Scope
) in self
._SectionsMacroDict
:
450 if SectionType
!= ActiveSectionType
:
453 for ActiveScope
in self
._Scope
:
454 Scope0
, Scope1
, Scope2
= ActiveScope
[0], ActiveScope
[1], ActiveScope
[2]
455 if(Scope0
, Scope1
, Scope2
) not in Scope
:
458 SpeSpeMacroDict
.update(self
._SectionsMacroDict
[(SectionType
, Scope
)])
460 for ActiveScope
in self
._Scope
:
461 Scope0
, Scope1
, Scope2
= ActiveScope
[0], ActiveScope
[1], ActiveScope
[2]
462 if(Scope0
, Scope1
, Scope2
) not in Scope
and (Scope0
, TAB_COMMON
, TAB_COMMON
) not in Scope
and (TAB_COMMON
, Scope1
, TAB_COMMON
) not in Scope
:
465 ComSpeMacroDict
.update(self
._SectionsMacroDict
[(SectionType
, Scope
)])
467 if (TAB_COMMON
, TAB_COMMON
, TAB_COMMON
) in Scope
:
468 ComComMacroDict
.update(self
._SectionsMacroDict
[(SectionType
, Scope
)])
470 Macros
.update(ComComMacroDict
)
471 Macros
.update(ComSpeMacroDict
)
472 Macros
.update(SpeSpeMacroDict
)
477 Finished
= property(_GetFinished
, _SetFinished
)
478 _Macros
= property(_GetMacros
)
481 ## INF file parser class
483 # @param FilePath The path of platform description file
484 # @param FileType The raw data of DSC file
485 # @param Table Database used to retrieve module/package information
486 # @param Macros Macros used for replacement in file
488 class InfParser(MetaFileParser
):
489 # INF file supported data types (one type per section)
491 TAB_UNKNOWN
.upper() : MODEL_UNKNOWN
,
492 TAB_INF_DEFINES
.upper() : MODEL_META_DATA_HEADER
,
493 TAB_DSC_DEFINES_DEFINE
: MODEL_META_DATA_DEFINE
,
494 TAB_BUILD_OPTIONS
.upper() : MODEL_META_DATA_BUILD_OPTION
,
495 TAB_INCLUDES
.upper() : MODEL_EFI_INCLUDE
,
496 TAB_LIBRARIES
.upper() : MODEL_EFI_LIBRARY_INSTANCE
,
497 TAB_LIBRARY_CLASSES
.upper() : MODEL_EFI_LIBRARY_CLASS
,
498 TAB_PACKAGES
.upper() : MODEL_META_DATA_PACKAGE
,
499 TAB_NMAKE
.upper() : MODEL_META_DATA_NMAKE
,
500 TAB_INF_FIXED_PCD
.upper() : MODEL_PCD_FIXED_AT_BUILD
,
501 TAB_INF_PATCH_PCD
.upper() : MODEL_PCD_PATCHABLE_IN_MODULE
,
502 TAB_INF_FEATURE_PCD
.upper() : MODEL_PCD_FEATURE_FLAG
,
503 TAB_INF_PCD_EX
.upper() : MODEL_PCD_DYNAMIC_EX
,
504 TAB_INF_PCD
.upper() : MODEL_PCD_DYNAMIC
,
505 TAB_SOURCES
.upper() : MODEL_EFI_SOURCE_FILE
,
506 TAB_GUIDS
.upper() : MODEL_EFI_GUID
,
507 TAB_PROTOCOLS
.upper() : MODEL_EFI_PROTOCOL
,
508 TAB_PPIS
.upper() : MODEL_EFI_PPI
,
509 TAB_DEPEX
.upper() : MODEL_EFI_DEPEX
,
510 TAB_BINARIES
.upper() : MODEL_EFI_BINARY_FILE
,
511 TAB_USER_EXTENSIONS
.upper() : MODEL_META_DATA_USER_EXTENSION
514 ## Constructor of InfParser
516 # Initialize object of InfParser
518 # @param FilePath The path of module description file
519 # @param FileType The raw data of DSC file
520 # @param Arch Default Arch value for filtering sections
521 # @param Table Database used to retrieve module/package information
523 def __init__(self
, FilePath
, FileType
, Arch
, Table
):
524 # prevent re-initialization
525 if hasattr(self
, "_Table"):
527 MetaFileParser
.__init
__(self
, FilePath
, FileType
, Arch
, Table
)
535 Content
= open(str(self
.MetaFile
), 'r').readlines()
537 EdkLogger
.error("Parser", FILE_READ_FAILURE
, ExtraData
=self
.MetaFile
)
539 # parse the file line by line
540 IsFindBlockComment
= False
541 GetHeaderComment
= False
546 for Index
in range(0, len(Content
)):
547 # skip empty, commented, block commented lines
548 Line
, Comment
= CleanString2(Content
[Index
], AllowCppStyleComment
=True)
550 if Index
+ 1 < len(Content
):
551 NextLine
, NextComment
= CleanString2(Content
[Index
+ 1])
554 Comments
.append((Comment
, Index
+ 1))
555 elif GetHeaderComment
:
556 SectionComments
.extend(Comments
)
559 if Line
.find(DataType
.TAB_COMMENT_EDK_START
) > -1:
560 IsFindBlockComment
= True
562 if Line
.find(DataType
.TAB_COMMENT_EDK_END
) > -1:
563 IsFindBlockComment
= False
565 if IsFindBlockComment
:
568 self
._LineIndex
= Index
569 self
._CurrentLine
= Line
572 if Line
[0] == TAB_SECTION_START
and Line
[-1] == TAB_SECTION_END
:
573 if not GetHeaderComment
:
574 for Cmt
, LNo
in Comments
:
575 self
._Store
(MODEL_META_DATA_HEADER_COMMENT
, Cmt
, '', '', TAB_COMMON
,
576 TAB_COMMON
, self
._Owner
[-1], LNo
, -1, LNo
, -1, 0)
577 GetHeaderComment
= True
579 TailComments
.extend(SectionComments
+ Comments
)
581 self
._SectionHeaderParser
()
582 # Check invalid sections
583 if self
._Version
< 0x00010005:
584 if self
._SectionType
in [MODEL_META_DATA_BUILD_OPTION
,
585 MODEL_EFI_LIBRARY_CLASS
,
586 MODEL_META_DATA_PACKAGE
,
587 MODEL_PCD_FIXED_AT_BUILD
,
588 MODEL_PCD_PATCHABLE_IN_MODULE
,
589 MODEL_PCD_FEATURE_FLAG
,
590 MODEL_PCD_DYNAMIC_EX
,
595 MODEL_META_DATA_USER_EXTENSION
]:
596 EdkLogger
.error('Parser', FORMAT_INVALID
,
597 "Section [%s] is not allowed in inf file without version" % (self
._SectionName
),
598 ExtraData
=self
._CurrentLine
, File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
599 elif self
._SectionType
in [MODEL_EFI_INCLUDE
,
600 MODEL_EFI_LIBRARY_INSTANCE
,
601 MODEL_META_DATA_NMAKE
]:
602 EdkLogger
.error('Parser', FORMAT_INVALID
,
603 "Section [%s] is not allowed in inf file with version 0x%08x" % (self
._SectionName
, self
._Version
),
604 ExtraData
=self
._CurrentLine
, File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
606 # merge two lines specified by '\' in section NMAKE
607 elif self
._SectionType
== MODEL_META_DATA_NMAKE
:
610 self
._CurrentLine
= NmakeLine
+ Line
[0:-1]
613 if NextLine
[0] == TAB_SECTION_START
and NextLine
[-1] == TAB_SECTION_END
:
614 self
._CurrentLine
= NmakeLine
+ Line
[0:-1]
617 NmakeLine
= NmakeLine
+ ' ' + Line
[0:-1]
620 self
._CurrentLine
= NmakeLine
+ Line
624 self
._ValueList
= ['', '', '']
625 # parse current line, result will be put in self._ValueList
626 self
._SectionParser
[self
._SectionType
](self
)
627 if self
._ValueList
is None or self
._ItemType
== MODEL_META_DATA_DEFINE
:
632 Comments
.append((Comment
, Index
+ 1))
633 if GlobalData
.gOptions
and GlobalData
.gOptions
.CheckUsage
:
634 CheckInfComment(self
._SectionType
, Comments
, str(self
.MetaFile
), Index
+ 1, self
._ValueList
)
636 # Model, Value1, Value2, Value3, Arch, Platform, BelongsToItem=-1,
637 # LineBegin=-1, ColumnBegin=-1, LineEnd=-1, ColumnEnd=-1, Enabled=-1
639 for Arch
, Platform
, _
in self
._Scope
:
640 LastItem
= self
._Store
(self
._SectionType
,
653 for Comment
, LineNo
in Comments
:
654 self
._Store
(MODEL_META_DATA_COMMENT
, Comment
, '', '', Arch
, Platform
,
655 LastItem
, LineNo
, -1, LineNo
, -1, 0)
658 TailComments
.extend(SectionComments
+ Comments
)
659 if IsFindBlockComment
:
660 EdkLogger
.error("Parser", FORMAT_INVALID
, "Open block comments (starting with /*) are expected to end with */",
663 # If there are tail comments in INF file, save to database whatever the comments are
664 for Comment
in TailComments
:
665 self
._Store
(MODEL_META_DATA_TAIL_COMMENT
, Comment
[0], '', '', TAB_COMMON
,
666 TAB_COMMON
, self
._Owner
[-1], -1, -1, -1, -1, 0)
669 ## Data parser for the format in which there's path
671 # Only path can have macro used. So we need to replace them before use.
673 def _IncludeParser(self
):
674 TokenList
= GetSplitValueList(self
._CurrentLine
, TAB_VALUE_SPLIT
)
675 self
._ValueList
[0:len(TokenList
)] = TokenList
676 Macros
= self
._Macros
678 for Index
in range(0, len(self
._ValueList
)):
679 Value
= self
._ValueList
[Index
]
683 if Value
.upper().find('$(EFI_SOURCE)\Edk'.upper()) > -1 or Value
.upper().find('$(EFI_SOURCE)/Edk'.upper()) > -1:
684 Value
= '$(EDK_SOURCE)' + Value
[17:]
685 if Value
.find('$(EFI_SOURCE)') > -1 or Value
.find('$(EDK_SOURCE)') > -1:
687 elif Value
.startswith('.'):
689 elif Value
.startswith('$('):
692 Value
= '$(EFI_SOURCE)/' + Value
694 self
._ValueList
[Index
] = ReplaceMacro(Value
, Macros
)
696 ## Parse [Sources] section
698 # Only path can have macro used. So we need to replace them before use.
701 def _SourceFileParser(self
):
702 TokenList
= GetSplitValueList(self
._CurrentLine
, TAB_VALUE_SPLIT
)
703 self
._ValueList
[0:len(TokenList
)] = TokenList
704 Macros
= self
._Macros
705 # For Acpi tables, remove macro like ' TABLE_NAME=Sata1'
706 if 'COMPONENT_TYPE' in Macros
:
707 if self
._Defines
['COMPONENT_TYPE'].upper() == 'ACPITABLE':
708 self
._ValueList
[0] = GetSplitValueList(self
._ValueList
[0], ' ', 1)[0]
709 if self
._Defines
['BASE_NAME'] == 'Microcode':
711 self
._ValueList
= [ReplaceMacro(Value
, Macros
) for Value
in self
._ValueList
]
713 ## Parse [Binaries] section
715 # Only path can have macro used. So we need to replace them before use.
718 def _BinaryFileParser(self
):
719 TokenList
= GetSplitValueList(self
._CurrentLine
, TAB_VALUE_SPLIT
, 2)
720 if len(TokenList
) < 2:
721 EdkLogger
.error('Parser', FORMAT_INVALID
, "No file type or path specified",
722 ExtraData
=self
._CurrentLine
+ " (<FileType> | <FilePath> [| <Target>])",
723 File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
725 EdkLogger
.error('Parser', FORMAT_INVALID
, "No file type specified",
726 ExtraData
=self
._CurrentLine
+ " (<FileType> | <FilePath> [| <Target>])",
727 File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
729 EdkLogger
.error('Parser', FORMAT_INVALID
, "No file path specified",
730 ExtraData
=self
._CurrentLine
+ " (<FileType> | <FilePath> [| <Target>])",
731 File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
732 self
._ValueList
[0:len(TokenList
)] = TokenList
733 self
._ValueList
[1] = ReplaceMacro(self
._ValueList
[1], self
._Macros
)
735 ## [nmake] section parser (Edk.x style only)
736 def _NmakeParser(self
):
737 TokenList
= GetSplitValueList(self
._CurrentLine
, TAB_EQUAL_SPLIT
, 1)
738 self
._ValueList
[0:len(TokenList
)] = TokenList
740 self
._ValueList
[1] = ReplaceMacro(self
._ValueList
[1], self
._Macros
)
741 # remove self-reference in macro setting
742 #self._ValueList[1] = ReplaceMacro(self._ValueList[1], {self._ValueList[0]:''})
744 ## [FixedPcd], [FeaturePcd], [PatchPcd], [Pcd] and [PcdEx] sections parser
746 def _PcdParser(self
):
747 TokenList
= GetSplitValueList(self
._CurrentLine
, TAB_VALUE_SPLIT
, 1)
748 ValueList
= GetSplitValueList(TokenList
[0], TAB_SPLIT
)
749 if len(ValueList
) != 2:
750 EdkLogger
.error('Parser', FORMAT_INVALID
, "Illegal token space GUID and PCD name format",
751 ExtraData
=self
._CurrentLine
+ " (<TokenSpaceGuidCName>.<PcdCName>)",
752 File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
753 self
._ValueList
[0:1] = ValueList
754 if len(TokenList
) > 1:
755 self
._ValueList
[2] = TokenList
[1]
756 if self
._ValueList
[0] == '' or self
._ValueList
[1] == '':
757 EdkLogger
.error('Parser', FORMAT_INVALID
, "No token space GUID or PCD name specified",
758 ExtraData
=self
._CurrentLine
+ " (<TokenSpaceGuidCName>.<PcdCName>)",
759 File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
761 # if value are 'True', 'true', 'TRUE' or 'False', 'false', 'FALSE', replace with integer 1 or 0.
762 if self
._ValueList
[2] != '':
763 InfPcdValueList
= GetSplitValueList(TokenList
[1], TAB_VALUE_SPLIT
, 1)
764 if InfPcdValueList
[0] in ['True', 'true', 'TRUE']:
765 self
._ValueList
[2] = TokenList
[1].replace(InfPcdValueList
[0], '1', 1);
766 elif InfPcdValueList
[0] in ['False', 'false', 'FALSE']:
767 self
._ValueList
[2] = TokenList
[1].replace(InfPcdValueList
[0], '0', 1);
768 if (self
._ValueList
[0], self
._ValueList
[1]) not in self
.PcdsDict
:
769 self
.PcdsDict
[self
._ValueList
[0], self
._ValueList
[1]] = self
._SectionType
770 elif self
.PcdsDict
[self
._ValueList
[0], self
._ValueList
[1]] != self
._SectionType
:
771 EdkLogger
.error('Parser', FORMAT_INVALID
, "It is not permissible to list a specified PCD in different PCD type sections.",
772 ExtraData
=self
._CurrentLine
+ " (<TokenSpaceGuidCName>.<PcdCName>)",
773 File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
775 ## [depex] section parser
777 def _DepexParser(self
):
778 self
._ValueList
[0:1] = [self
._CurrentLine
]
781 MODEL_UNKNOWN
: MetaFileParser
._Skip
,
782 MODEL_META_DATA_HEADER
: MetaFileParser
._DefineParser
,
783 MODEL_META_DATA_BUILD_OPTION
: MetaFileParser
._BuildOptionParser
,
784 MODEL_EFI_INCLUDE
: _IncludeParser
, # for Edk.x modules
785 MODEL_EFI_LIBRARY_INSTANCE
: MetaFileParser
._CommonParser
, # for Edk.x modules
786 MODEL_EFI_LIBRARY_CLASS
: MetaFileParser
._PathParser
,
787 MODEL_META_DATA_PACKAGE
: MetaFileParser
._PathParser
,
788 MODEL_META_DATA_NMAKE
: _NmakeParser
, # for Edk.x modules
789 MODEL_PCD_FIXED_AT_BUILD
: _PcdParser
,
790 MODEL_PCD_PATCHABLE_IN_MODULE
: _PcdParser
,
791 MODEL_PCD_FEATURE_FLAG
: _PcdParser
,
792 MODEL_PCD_DYNAMIC_EX
: _PcdParser
,
793 MODEL_PCD_DYNAMIC
: _PcdParser
,
794 MODEL_EFI_SOURCE_FILE
: _SourceFileParser
,
795 MODEL_EFI_GUID
: MetaFileParser
._CommonParser
,
796 MODEL_EFI_PROTOCOL
: MetaFileParser
._CommonParser
,
797 MODEL_EFI_PPI
: MetaFileParser
._CommonParser
,
798 MODEL_EFI_DEPEX
: _DepexParser
,
799 MODEL_EFI_BINARY_FILE
: _BinaryFileParser
,
800 MODEL_META_DATA_USER_EXTENSION
: MetaFileParser
._SkipUserExtension
,
803 ## DSC file parser class
805 # @param FilePath The path of platform description file
806 # @param FileType The raw data of DSC file
807 # @param Table Database used to retrieve module/package information
808 # @param Macros Macros used for replacement in file
809 # @param Owner Owner ID (for sub-section parsing)
810 # @param From ID from which the data comes (for !INCLUDE directive)
812 class DscParser(MetaFileParser
):
813 # DSC file supported data types (one type per section)
815 TAB_SKUIDS
.upper() : MODEL_EFI_SKU_ID
,
816 TAB_DEFAULT_STORES
.upper() : MODEL_EFI_DEFAULT_STORES
,
817 TAB_LIBRARIES
.upper() : MODEL_EFI_LIBRARY_INSTANCE
,
818 TAB_LIBRARY_CLASSES
.upper() : MODEL_EFI_LIBRARY_CLASS
,
819 TAB_BUILD_OPTIONS
.upper() : MODEL_META_DATA_BUILD_OPTION
,
820 TAB_PCDS_FIXED_AT_BUILD_NULL
.upper() : MODEL_PCD_FIXED_AT_BUILD
,
821 TAB_PCDS_PATCHABLE_IN_MODULE_NULL
.upper() : MODEL_PCD_PATCHABLE_IN_MODULE
,
822 TAB_PCDS_FEATURE_FLAG_NULL
.upper() : MODEL_PCD_FEATURE_FLAG
,
823 TAB_PCDS_DYNAMIC_DEFAULT_NULL
.upper() : MODEL_PCD_DYNAMIC_DEFAULT
,
824 TAB_PCDS_DYNAMIC_HII_NULL
.upper() : MODEL_PCD_DYNAMIC_HII
,
825 TAB_PCDS_DYNAMIC_VPD_NULL
.upper() : MODEL_PCD_DYNAMIC_VPD
,
826 TAB_PCDS_DYNAMIC_EX_DEFAULT_NULL
.upper() : MODEL_PCD_DYNAMIC_EX_DEFAULT
,
827 TAB_PCDS_DYNAMIC_EX_HII_NULL
.upper() : MODEL_PCD_DYNAMIC_EX_HII
,
828 TAB_PCDS_DYNAMIC_EX_VPD_NULL
.upper() : MODEL_PCD_DYNAMIC_EX_VPD
,
829 TAB_COMPONENTS
.upper() : MODEL_META_DATA_COMPONENT
,
830 TAB_COMPONENTS_SOURCE_OVERRIDE_PATH
.upper() : MODEL_META_DATA_COMPONENT_SOURCE_OVERRIDE_PATH
,
831 TAB_DSC_DEFINES
.upper() : MODEL_META_DATA_HEADER
,
832 TAB_DSC_DEFINES_DEFINE
: MODEL_META_DATA_DEFINE
,
833 TAB_DSC_DEFINES_EDKGLOBAL
: MODEL_META_DATA_GLOBAL_DEFINE
,
834 TAB_INCLUDE
.upper() : MODEL_META_DATA_INCLUDE
,
835 TAB_IF
.upper() : MODEL_META_DATA_CONDITIONAL_STATEMENT_IF
,
836 TAB_IF_DEF
.upper() : MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF
,
837 TAB_IF_N_DEF
.upper() : MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF
,
838 TAB_ELSE_IF
.upper() : MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSEIF
,
839 TAB_ELSE
.upper() : MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE
,
840 TAB_END_IF
.upper() : MODEL_META_DATA_CONDITIONAL_STATEMENT_ENDIF
,
841 TAB_USER_EXTENSIONS
.upper() : MODEL_META_DATA_USER_EXTENSION
,
842 TAB_ERROR
.upper() : MODEL_META_DATA_CONDITIONAL_STATEMENT_ERROR
,
845 # Valid names in define section
852 "PCD_INFO_GENERATION",
853 "PCD_VAR_CHECK_GENERATION",
854 "SUPPORTED_ARCHITECTURES",
863 "FIX_LOAD_TOP_MEMORY_ADDRESS",
868 SubSectionDefineKeywords
= [
872 SymbolPattern
= ValueExpression
.SymbolPattern
874 IncludedFiles
= set()
876 ## Constructor of DscParser
878 # Initialize object of DscParser
880 # @param FilePath The path of platform description file
881 # @param FileType The raw data of DSC file
882 # @param Arch Default Arch value for filtering sections
883 # @param Table Database used to retrieve module/package information
884 # @param Owner Owner ID (for sub-section parsing)
885 # @param From ID from which the data comes (for !INCLUDE directive)
887 def __init__(self
, FilePath
, FileType
, Arch
, Table
, Owner
= -1, From
= -1):
888 # prevent re-initialization
889 if hasattr(self
, "_Table"):
891 MetaFileParser
.__init
__(self
, FilePath
, FileType
, Arch
, Table
, Owner
, From
)
892 self
._Version
= 0x00010005 # Only EDK2 dsc file is supported
893 # to store conditional directive evaluation result
894 self
._DirectiveStack
= []
895 self
._DirectiveEvalStack
= []
899 # Specify whether current line is in uncertain condition
901 self
._InDirective
= -1
903 # Final valid replacable symbols
906 # Map the ID between the original table and new table to track
909 self
._IdMapping
= {-1:-1}
915 Content
= open(str(self
.MetaFile
), 'r').readlines()
917 EdkLogger
.error("Parser", FILE_READ_FAILURE
, ExtraData
=self
.MetaFile
)
920 for Index
in range(0, len(Content
)):
921 Line
= CleanString(Content
[Index
])
926 self
._CurrentLine
= Line
927 self
._LineIndex
= Index
928 if self
._InSubsection
and self
._Owner
[-1] == -1:
929 self
._Owner
.append(self
._LastItem
)
932 if Line
[0] == TAB_SECTION_START
and Line
[-1] == TAB_SECTION_END
:
933 self
._SectionType
= MODEL_META_DATA_SECTION_HEADER
935 elif Line
[0] == '}' and self
._InSubsection
:
936 self
._InSubsection
= False
937 self
._SubsectionType
= MODEL_UNKNOWN
938 self
._SubsectionName
= ''
943 elif Line
[0] == TAB_OPTION_START
and Line
[-1] == TAB_OPTION_END
:
944 self
._SubsectionType
= MODEL_META_DATA_SUBSECTION_HEADER
947 TokenList
= GetSplitValueList(Line
, ' ', 1)
948 if TokenList
[0] == TAB_INCLUDE
:
949 for Arch
, ModuleType
, DefaultStore
in self
._Scope
:
950 if self
._SubsectionType
!= MODEL_UNKNOWN
and Arch
in OwnerId
:
951 self
._Owner
[-1] = OwnerId
[Arch
]
952 self
._DirectiveParser
()
954 self
._DirectiveParser
()
956 if Line
[0] == TAB_OPTION_START
and not self
._InSubsection
:
957 EdkLogger
.error("Parser", FILE_READ_FAILURE
, "Missing the '{' before %s in Line %s" % (Line
, Index
+1), ExtraData
=self
.MetaFile
)
959 if self
._InSubsection
:
960 SectionType
= self
._SubsectionType
962 SectionType
= self
._SectionType
963 self
._ItemType
= SectionType
965 self
._ValueList
= ['', '', '']
966 self
._SectionParser
[SectionType
](self
)
967 if self
._ValueList
is None:
970 # Model, Value1, Value2, Value3, Arch, ModuleType, BelongsToItem=-1, BelongsToFile=-1,
971 # LineBegin=-1, ColumnBegin=-1, LineEnd=-1, ColumnEnd=-1, Enabled=-1
973 for Arch
, ModuleType
, DefaultStore
in self
._Scope
:
974 Owner
= self
._Owner
[-1]
975 if self
._SubsectionType
!= MODEL_UNKNOWN
and Arch
in OwnerId
:
976 Owner
= OwnerId
[Arch
]
977 self
._LastItem
= self
._Store
(
993 if self
._SubsectionType
== MODEL_UNKNOWN
and self
._InSubsection
:
994 OwnerId
[Arch
] = self
._LastItem
996 if self
._DirectiveStack
:
997 Type
, Line
, Text
= self
._DirectiveStack
[-1]
998 EdkLogger
.error('Parser', FORMAT_INVALID
, "No matching '!endif' found",
999 ExtraData
=Text
, File
=self
.MetaFile
, Line
=Line
)
1002 ## <subsection_header> parser
1003 def _SubsectionHeaderParser(self
):
1004 self
._SubsectionName
= self
._CurrentLine
[1:-1].upper()
1005 if self
._SubsectionName
in self
.DataType
:
1006 self
._SubsectionType
= self
.DataType
[self
._SubsectionName
]
1008 self
._SubsectionType
= MODEL_UNKNOWN
1009 EdkLogger
.warn("Parser", "Unrecognized sub-section", File
=self
.MetaFile
,
1010 Line
=self
._LineIndex
+ 1, ExtraData
=self
._CurrentLine
)
1011 self
._ValueList
[0] = self
._SubsectionName
1013 ## Directive statement parser
1014 def _DirectiveParser(self
):
1015 self
._ValueList
= ['', '', '']
1016 TokenList
= GetSplitValueList(self
._CurrentLine
, ' ', 1)
1017 self
._ValueList
[0:len(TokenList
)] = TokenList
1020 DirectiveName
= self
._ValueList
[0].upper()
1021 if DirectiveName
not in self
.DataType
:
1022 EdkLogger
.error("Parser", FORMAT_INVALID
, "Unknown directive [%s]" % DirectiveName
,
1023 File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
1025 if DirectiveName
in ['!IF', '!IFDEF', '!IFNDEF']:
1026 self
._InDirective
+= 1
1028 if DirectiveName
in ['!ENDIF']:
1029 self
._InDirective
-= 1
1031 if DirectiveName
in ['!IF', '!IFDEF', '!INCLUDE', '!IFNDEF', '!ELSEIF'] and self
._ValueList
[1] == '':
1032 EdkLogger
.error("Parser", FORMAT_INVALID
, "Missing expression",
1033 File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1,
1034 ExtraData
=self
._CurrentLine
)
1036 ItemType
= self
.DataType
[DirectiveName
]
1037 Scope
= [[TAB_COMMON
, TAB_COMMON
, TAB_COMMON
]]
1038 if ItemType
== MODEL_META_DATA_INCLUDE
:
1040 elif ItemType
== MODEL_META_DATA_CONDITIONAL_STATEMENT_ERROR
:
1042 if ItemType
== MODEL_META_DATA_CONDITIONAL_STATEMENT_ENDIF
:
1043 # Remove all directives between !if and !endif, including themselves
1044 while self
._DirectiveStack
:
1045 # Remove any !else or !elseif
1046 DirectiveInfo
= self
._DirectiveStack
.pop()
1047 if DirectiveInfo
[0] in [MODEL_META_DATA_CONDITIONAL_STATEMENT_IF
,
1048 MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF
,
1049 MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF
]:
1052 EdkLogger
.error("Parser", FORMAT_INVALID
, "Redundant '!endif'",
1053 File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1,
1054 ExtraData
=self
._CurrentLine
)
1055 elif ItemType
not in {MODEL_META_DATA_INCLUDE
, MODEL_META_DATA_CONDITIONAL_STATEMENT_ERROR
}:
1056 # Break if there's a !else is followed by a !elseif
1057 if ItemType
== MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSEIF
and \
1058 self
._DirectiveStack
and \
1059 self
._DirectiveStack
[-1][0] == MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE
:
1060 EdkLogger
.error("Parser", FORMAT_INVALID
, "'!elseif' after '!else'",
1061 File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1,
1062 ExtraData
=self
._CurrentLine
)
1063 self
._DirectiveStack
.append((ItemType
, self
._LineIndex
+ 1, self
._CurrentLine
))
1066 # Model, Value1, Value2, Value3, Arch, ModuleType, BelongsToItem=-1, BelongsToFile=-1,
1067 # LineBegin=-1, ColumnBegin=-1, LineEnd=-1, ColumnEnd=-1, Enabled=-1
1069 for Arch
, ModuleType
, DefaultStore
in Scope
:
1070 self
._LastItem
= self
._Store
(
1080 self
._LineIndex
+ 1,
1082 self
._LineIndex
+ 1,
1087 ## [defines] section parser
1089 def _DefineParser(self
):
1090 TokenList
= GetSplitValueList(self
._CurrentLine
, TAB_EQUAL_SPLIT
, 1)
1091 self
._ValueList
[1:len(TokenList
)] = TokenList
1094 if not self
._ValueList
[1]:
1095 EdkLogger
.error('Parser', FORMAT_INVALID
, "No name specified",
1096 ExtraData
=self
._CurrentLine
, File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
1097 if not self
._ValueList
[2]:
1098 EdkLogger
.error('Parser', FORMAT_INVALID
, "No value specified",
1099 ExtraData
=self
._CurrentLine
, File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
1100 if (not self
._ValueList
[1] in self
.DefineKeywords
and
1101 (self
._InSubsection
and self
._ValueList
[1] not in self
.SubSectionDefineKeywords
)):
1102 EdkLogger
.error('Parser', FORMAT_INVALID
,
1103 "Unknown keyword found: %s. "
1104 "If this is a macro you must "
1105 "add it as a DEFINE in the DSC" % self
._ValueList
[1],
1106 ExtraData
=self
._CurrentLine
, File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
1107 if not self
._InSubsection
:
1108 self
._Defines
[self
._ValueList
[1]] = self
._ValueList
[2]
1109 self
._ItemType
= self
.DataType
[TAB_DSC_DEFINES
.upper()]
1112 def _SkuIdParser(self
):
1113 TokenList
= GetSplitValueList(self
._CurrentLine
, TAB_VALUE_SPLIT
)
1114 if len(TokenList
) not in (2, 3):
1115 EdkLogger
.error('Parser', FORMAT_INVALID
, "Correct format is '<Number>|<UiName>[|<UiName>]'",
1116 ExtraData
=self
._CurrentLine
, File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
1117 self
._ValueList
[0:len(TokenList
)] = TokenList
1119 def _DefaultStoresParser(self
):
1120 TokenList
= GetSplitValueList(self
._CurrentLine
, TAB_VALUE_SPLIT
)
1121 if len(TokenList
) != 2:
1122 EdkLogger
.error('Parser', FORMAT_INVALID
, "Correct format is '<Number>|<UiName>'",
1123 ExtraData
=self
._CurrentLine
, File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
1124 self
._ValueList
[0:len(TokenList
)] = TokenList
1126 ## Parse Edk style of library modules
1128 def _LibraryInstanceParser(self
):
1129 self
._ValueList
[0] = self
._CurrentLine
1131 ## PCD sections parser
1133 # [PcdsFixedAtBuild]
1134 # [PcdsPatchableInModule]
1137 # [PcdsDynamicExDefault]
1138 # [PcdsDynamicExVpd]
1139 # [PcdsDynamicExHii]
1141 # [PcdsDynamicDefault]
1146 def _PcdParser(self
):
1147 TokenList
= GetSplitValueList(self
._CurrentLine
, TAB_VALUE_SPLIT
, 1)
1148 self
._ValueList
[0:1] = GetSplitValueList(TokenList
[0], TAB_SPLIT
)
1149 PcdNameTockens
= GetSplitValueList(TokenList
[0], TAB_SPLIT
)
1150 if len(PcdNameTockens
) == 2:
1151 self
._ValueList
[0], self
._ValueList
[1] = PcdNameTockens
[0], PcdNameTockens
[1]
1152 elif len(PcdNameTockens
) == 3:
1153 self
._ValueList
[0], self
._ValueList
[1] = ".".join((PcdNameTockens
[0], PcdNameTockens
[1])), PcdNameTockens
[2]
1154 elif len(PcdNameTockens
) > 3:
1155 self
._ValueList
[0], self
._ValueList
[1] = ".".join((PcdNameTockens
[0], PcdNameTockens
[1])), ".".join(PcdNameTockens
[2:])
1156 if len(TokenList
) == 2:
1157 self
._ValueList
[2] = TokenList
[1]
1158 if self
._ValueList
[0] == '' or self
._ValueList
[1] == '':
1159 EdkLogger
.error('Parser', FORMAT_INVALID
, "No token space GUID or PCD name specified",
1160 ExtraData
=self
._CurrentLine
+ " (<TokenSpaceGuidCName>.<TokenCName>|<PcdValue>)",
1161 File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
1162 if self
._ValueList
[2] == '':
1164 # The PCD values are optional for FIXEDATBUILD, PATCHABLEINMODULE, Dynamic/DynamicEx default
1166 if self
._SectionType
in (MODEL_PCD_FIXED_AT_BUILD
, MODEL_PCD_PATCHABLE_IN_MODULE
, MODEL_PCD_DYNAMIC_DEFAULT
, MODEL_PCD_DYNAMIC_EX_DEFAULT
):
1168 EdkLogger
.error('Parser', FORMAT_INVALID
, "No PCD value given",
1169 ExtraData
=self
._CurrentLine
+ " (<TokenSpaceGuidCName>.<TokenCName>|<PcdValue>)",
1170 File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
1172 # Validate the datum type of Dynamic Defaul PCD and DynamicEx Default PCD
1173 ValueList
= GetSplitValueList(self
._ValueList
[2])
1174 if len(ValueList
) > 1 and ValueList
[1] in [TAB_UINT8
, TAB_UINT16
, TAB_UINT32
, TAB_UINT64
] \
1175 and self
._ItemType
in [MODEL_PCD_DYNAMIC_DEFAULT
, MODEL_PCD_DYNAMIC_EX_DEFAULT
]:
1176 EdkLogger
.error('Parser', FORMAT_INVALID
, "The datum type '%s' of PCD is wrong" % ValueList
[1],
1177 ExtraData
=self
._CurrentLine
, File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
1179 # Validate the VariableName of DynamicHii and DynamicExHii for PCD Entry must not be an empty string
1180 if self
._ItemType
in [MODEL_PCD_DYNAMIC_HII
, MODEL_PCD_DYNAMIC_EX_HII
]:
1181 DscPcdValueList
= GetSplitValueList(TokenList
[1], TAB_VALUE_SPLIT
, 1)
1182 if len(DscPcdValueList
[0].replace('L', '').replace('"', '').strip()) == 0:
1183 EdkLogger
.error('Parser', FORMAT_INVALID
, "The VariableName field in the HII format PCD entry must not be an empty string",
1184 ExtraData
=self
._CurrentLine
, File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
1186 # if value are 'True', 'true', 'TRUE' or 'False', 'false', 'FALSE', replace with integer 1 or 0.
1187 DscPcdValueList
= GetSplitValueList(TokenList
[1], TAB_VALUE_SPLIT
, 1)
1188 if DscPcdValueList
[0] in ['True', 'true', 'TRUE']:
1189 self
._ValueList
[2] = TokenList
[1].replace(DscPcdValueList
[0], '1', 1);
1190 elif DscPcdValueList
[0] in ['False', 'false', 'FALSE']:
1191 self
._ValueList
[2] = TokenList
[1].replace(DscPcdValueList
[0], '0', 1);
1194 ## [components] section parser
1196 def _ComponentParser(self
):
1197 if self
._CurrentLine
[-1] == '{':
1198 self
._ValueList
[0] = self
._CurrentLine
[0:-1].strip()
1199 self
._InSubsection
= True
1200 self
._SubsectionType
= MODEL_UNKNOWN
1202 self
._ValueList
[0] = self
._CurrentLine
1204 ## [LibraryClasses] section
1206 def _LibraryClassParser(self
):
1207 TokenList
= GetSplitValueList(self
._CurrentLine
, TAB_VALUE_SPLIT
)
1208 if len(TokenList
) < 2:
1209 EdkLogger
.error('Parser', FORMAT_INVALID
, "No library class or instance specified",
1210 ExtraData
=self
._CurrentLine
+ " (<LibraryClassName>|<LibraryInstancePath>)",
1211 File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
1212 if TokenList
[0] == '':
1213 EdkLogger
.error('Parser', FORMAT_INVALID
, "No library class specified",
1214 ExtraData
=self
._CurrentLine
+ " (<LibraryClassName>|<LibraryInstancePath>)",
1215 File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
1216 if TokenList
[1] == '':
1217 EdkLogger
.error('Parser', FORMAT_INVALID
, "No library instance specified",
1218 ExtraData
=self
._CurrentLine
+ " (<LibraryClassName>|<LibraryInstancePath>)",
1219 File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
1221 self
._ValueList
[0:len(TokenList
)] = TokenList
1223 def _CompponentSourceOverridePathParser(self
):
1224 self
._ValueList
[0] = self
._CurrentLine
1226 ## [BuildOptions] section parser
1228 def _BuildOptionParser(self
):
1229 self
._CurrentLine
= CleanString(self
._CurrentLine
, BuildOption
=True)
1230 TokenList
= GetSplitValueList(self
._CurrentLine
, TAB_EQUAL_SPLIT
, 1)
1231 TokenList2
= GetSplitValueList(TokenList
[0], ':', 1)
1232 if len(TokenList2
) == 2:
1233 self
._ValueList
[0] = TokenList2
[0] # toolchain family
1234 self
._ValueList
[1] = TokenList2
[1] # keys
1236 self
._ValueList
[1] = TokenList
[0]
1237 if len(TokenList
) == 2: # value
1238 self
._ValueList
[2] = TokenList
[1]
1240 if self
._ValueList
[1].count('_') != 4:
1244 "'%s' must be in format of <TARGET>_<TOOLCHAIN>_<ARCH>_<TOOL>_FLAGS" % self
._ValueList
[1],
1245 ExtraData
=self
._CurrentLine
,
1247 Line
=self
._LineIndex
+ 1
1250 ## Override parent's method since we'll do all macro replacements in parser
1251 def _GetMacros(self
):
1253 Macros
.update(self
._FileLocalMacros
)
1254 Macros
.update(self
._GetApplicableSectionMacro
())
1255 Macros
.update(GlobalData
.gEdkGlobal
)
1256 Macros
.update(GlobalData
.gPlatformDefines
)
1257 Macros
.update(GlobalData
.gCommandLineDefines
)
1258 # PCD cannot be referenced in macro definition
1259 if self
._ItemType
not in [MODEL_META_DATA_DEFINE
, MODEL_META_DATA_GLOBAL_DEFINE
]:
1260 Macros
.update(self
._Symbols
)
1261 if GlobalData
.BuildOptionPcd
:
1262 for Item
in GlobalData
.BuildOptionPcd
:
1263 if isinstance(Item
, tuple):
1265 PcdName
, TmpValue
= Item
.split("=")
1266 TmpValue
= BuildOptionValue(TmpValue
, self
._GuidDict
)
1267 Macros
[PcdName
.strip()] = TmpValue
1270 def _PostProcess(self
):
1272 MODEL_META_DATA_SECTION_HEADER
: self
.__ProcessSectionHeader
,
1273 MODEL_META_DATA_SUBSECTION_HEADER
: self
.__ProcessSubsectionHeader
,
1274 MODEL_META_DATA_HEADER
: self
.__ProcessDefine
,
1275 MODEL_META_DATA_DEFINE
: self
.__ProcessDefine
,
1276 MODEL_META_DATA_GLOBAL_DEFINE
: self
.__ProcessDefine
,
1277 MODEL_META_DATA_INCLUDE
: self
.__ProcessDirective
,
1278 MODEL_META_DATA_CONDITIONAL_STATEMENT_IF
: self
.__ProcessDirective
,
1279 MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE
: self
.__ProcessDirective
,
1280 MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF
: self
.__ProcessDirective
,
1281 MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF
: self
.__ProcessDirective
,
1282 MODEL_META_DATA_CONDITIONAL_STATEMENT_ENDIF
: self
.__ProcessDirective
,
1283 MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSEIF
: self
.__ProcessDirective
,
1284 MODEL_EFI_SKU_ID
: self
.__ProcessSkuId
,
1285 MODEL_EFI_DEFAULT_STORES
: self
.__ProcessDefaultStores
,
1286 MODEL_EFI_LIBRARY_INSTANCE
: self
.__ProcessLibraryInstance
,
1287 MODEL_EFI_LIBRARY_CLASS
: self
.__ProcessLibraryClass
,
1288 MODEL_PCD_FIXED_AT_BUILD
: self
.__ProcessPcd
,
1289 MODEL_PCD_PATCHABLE_IN_MODULE
: self
.__ProcessPcd
,
1290 MODEL_PCD_FEATURE_FLAG
: self
.__ProcessPcd
,
1291 MODEL_PCD_DYNAMIC_DEFAULT
: self
.__ProcessPcd
,
1292 MODEL_PCD_DYNAMIC_HII
: self
.__ProcessPcd
,
1293 MODEL_PCD_DYNAMIC_VPD
: self
.__ProcessPcd
,
1294 MODEL_PCD_DYNAMIC_EX_DEFAULT
: self
.__ProcessPcd
,
1295 MODEL_PCD_DYNAMIC_EX_HII
: self
.__ProcessPcd
,
1296 MODEL_PCD_DYNAMIC_EX_VPD
: self
.__ProcessPcd
,
1297 MODEL_META_DATA_COMPONENT
: self
.__ProcessComponent
,
1298 MODEL_META_DATA_COMPONENT_SOURCE_OVERRIDE_PATH
: self
.__ProcessSourceOverridePath
,
1299 MODEL_META_DATA_BUILD_OPTION
: self
.__ProcessBuildOption
,
1300 MODEL_UNKNOWN
: self
._Skip
,
1301 MODEL_META_DATA_USER_EXTENSION
: self
._SkipUserExtension
,
1302 MODEL_META_DATA_CONDITIONAL_STATEMENT_ERROR
: self
._ProcessError
,
1305 self
._Table
= MetaFileStorage(self
._RawTable
.Cur
, self
.MetaFile
, MODEL_FILE_DSC
, True)
1306 self
._Table
.Create()
1307 self
._DirectiveStack
= []
1308 self
._DirectiveEvalStack
= []
1309 self
._FileWithError
= self
.MetaFile
1310 self
._FileLocalMacros
= {}
1311 self
._SectionsMacroDict
.clear()
1312 GlobalData
.gPlatformDefines
= {}
1314 # Get all macro and PCD which has straitforward value
1315 self
.__RetrievePcdValue
()
1316 self
._Content
= self
._RawTable
.GetAll()
1317 self
._ContentIndex
= 0
1318 self
._InSubsection
= False
1319 while self
._ContentIndex
< len(self
._Content
) :
1320 Id
, self
._ItemType
, V1
, V2
, V3
, S1
, S2
, S3
, Owner
, self
._From
, \
1321 LineStart
, ColStart
, LineEnd
, ColEnd
, Enabled
= self
._Content
[self
._ContentIndex
]
1324 self
._FileWithError
= self
.MetaFile
1326 self
._ContentIndex
+= 1
1328 self
._Scope
= [[S1
, S2
, S3
]]
1330 # For !include directive, handle it specially,
1331 # merge arch and module type in case of duplicate items
1333 while self
._ItemType
== MODEL_META_DATA_INCLUDE
:
1334 if self
._ContentIndex
>= len(self
._Content
):
1336 Record
= self
._Content
[self
._ContentIndex
]
1337 if LineStart
== Record
[10] and LineEnd
== Record
[12]:
1338 if [Record
[5], Record
[6], Record
[7]] not in self
._Scope
:
1339 self
._Scope
.append([Record
[5], Record
[6], Record
[7]])
1340 self
._ContentIndex
+= 1
1344 self
._LineIndex
= LineStart
- 1
1345 self
._ValueList
= [V1
, V2
, V3
]
1347 if Owner
> 0 and Owner
in self
._IdMapping
:
1348 self
._InSubsection
= True
1350 self
._InSubsection
= False
1352 Processer
[self
._ItemType
]()
1353 except EvaluationException
as Excpt
:
1355 # Only catch expression evaluation error here. We need to report
1356 # the precise number of line on which the error occurred
1358 if hasattr(Excpt
, 'Pcd'):
1359 if Excpt
.Pcd
in GlobalData
.gPlatformOtherPcds
:
1360 Info
= GlobalData
.gPlatformOtherPcds
[Excpt
.Pcd
]
1361 EdkLogger
.error('Parser', FORMAT_INVALID
, "Cannot use this PCD (%s) in an expression as"
1362 " it must be defined in a [PcdsFixedAtBuild] or [PcdsFeatureFlag] section"
1363 " of the DSC file, and it is currently defined in this section:"
1364 " %s, line #: %d." % (Excpt
.Pcd
, Info
[0], Info
[1]),
1365 File
=self
._FileWithError
, ExtraData
=' '.join(self
._ValueList
),
1366 Line
=self
._LineIndex
+ 1)
1368 EdkLogger
.error('Parser', FORMAT_INVALID
, "PCD (%s) is not defined in DSC file" % Excpt
.Pcd
,
1369 File
=self
._FileWithError
, ExtraData
=' '.join(self
._ValueList
),
1370 Line
=self
._LineIndex
+ 1)
1372 EdkLogger
.error('Parser', FORMAT_INVALID
, "Invalid expression: %s" % str(Excpt
),
1373 File
=self
._FileWithError
, ExtraData
=' '.join(self
._ValueList
),
1374 Line
=self
._LineIndex
+ 1)
1375 except MacroException
as Excpt
:
1376 EdkLogger
.error('Parser', FORMAT_INVALID
, str(Excpt
),
1377 File
=self
._FileWithError
, ExtraData
=' '.join(self
._ValueList
),
1378 Line
=self
._LineIndex
+ 1)
1380 if self
._ValueList
is None:
1383 NewOwner
= self
._IdMapping
.get(Owner
, -1)
1384 self
._Enabled
= int((not self
._DirectiveEvalStack
) or (False not in self
._DirectiveEvalStack
))
1385 self
._LastItem
= self
._Store
(
1395 self
._LineIndex
+ 1,
1397 self
._LineIndex
+ 1,
1401 self
._IdMapping
[Id
] = self
._LastItem
1403 GlobalData
.gPlatformDefines
.update(self
._FileLocalMacros
)
1404 self
._PostProcessed
= True
1405 self
._Content
= None
1406 def _ProcessError(self
):
1407 if not self
._Enabled
:
1409 EdkLogger
.error('Parser', ERROR_STATEMENT
, self
._ValueList
[1], File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
1411 def __ProcessSectionHeader(self
):
1412 self
._SectionName
= self
._ValueList
[0]
1413 if self
._SectionName
in self
.DataType
:
1414 self
._SectionType
= self
.DataType
[self
._SectionName
]
1416 self
._SectionType
= MODEL_UNKNOWN
1418 def __ProcessSubsectionHeader(self
):
1419 self
._SubsectionName
= self
._ValueList
[0]
1420 if self
._SubsectionName
in self
.DataType
:
1421 self
._SubsectionType
= self
.DataType
[self
._SubsectionName
]
1423 self
._SubsectionType
= MODEL_UNKNOWN
1425 def __RetrievePcdValue(self
):
1426 Content
= open(str(self
.MetaFile
), 'r').readlines()
1427 GlobalData
.gPlatformOtherPcds
['DSCFILE'] = str(self
.MetaFile
)
1428 for PcdType
in (MODEL_PCD_PATCHABLE_IN_MODULE
, MODEL_PCD_DYNAMIC_DEFAULT
, MODEL_PCD_DYNAMIC_HII
,
1429 MODEL_PCD_DYNAMIC_VPD
, MODEL_PCD_DYNAMIC_EX_DEFAULT
, MODEL_PCD_DYNAMIC_EX_HII
,
1430 MODEL_PCD_DYNAMIC_EX_VPD
):
1431 Records
= self
._RawTable
.Query(PcdType
, BelongsToItem
= -1.0)
1432 for TokenSpaceGuid
, PcdName
, Value
, Dummy2
, Dummy3
, Dummy4
, ID
, Line
in Records
:
1433 Name
= TokenSpaceGuid
+ '.' + PcdName
1434 if Name
not in GlobalData
.gPlatformOtherPcds
:
1436 while not Content
[Line
- 1].lstrip().startswith(TAB_SECTION_START
):
1438 GlobalData
.gPlatformOtherPcds
[Name
] = (CleanString(Content
[Line
- 1]), PcdLine
, PcdType
)
1440 def __ProcessDefine(self
):
1441 if not self
._Enabled
:
1444 Type
, Name
, Value
= self
._ValueList
1445 Value
= ReplaceMacro(Value
, self
._Macros
, False)
1447 # If it is <Defines>, return
1449 if self
._InSubsection
:
1450 self
._ValueList
= [Type
, Name
, Value
]
1453 if self
._ItemType
== MODEL_META_DATA_DEFINE
:
1454 if self
._SectionType
== MODEL_META_DATA_HEADER
:
1455 self
._FileLocalMacros
[Name
] = Value
1457 self
._ConstructSectionMacroDict
(Name
, Value
)
1458 elif self
._ItemType
== MODEL_META_DATA_GLOBAL_DEFINE
:
1459 GlobalData
.gEdkGlobal
[Name
] = Value
1462 # Keyword in [Defines] section can be used as Macros
1464 if (self
._ItemType
== MODEL_META_DATA_HEADER
) and (self
._SectionType
== MODEL_META_DATA_HEADER
):
1465 self
._FileLocalMacros
[Name
] = Value
1467 self
._ValueList
= [Type
, Name
, Value
]
1469 def __ProcessDirective(self
):
1471 if self
._ItemType
in [MODEL_META_DATA_CONDITIONAL_STATEMENT_IF
,
1472 MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSEIF
]:
1473 Macros
= self
._Macros
1474 Macros
.update(GlobalData
.gGlobalDefines
)
1476 Result
= ValueExpression(self
._ValueList
[1], Macros
)()
1477 except SymbolNotFound
as Exc
:
1478 EdkLogger
.debug(EdkLogger
.DEBUG_5
, str(Exc
), self
._ValueList
[1])
1480 except WrnExpression
as Excpt
:
1482 # Catch expression evaluation warning here. We need to report
1483 # the precise number of line and return the evaluation result
1485 EdkLogger
.warn('Parser', "Suspicious expression: %s" % str(Excpt
),
1486 File
=self
._FileWithError
, ExtraData
=' '.join(self
._ValueList
),
1487 Line
=self
._LineIndex
+ 1)
1488 Result
= Excpt
.result
1490 if self
._ItemType
in [MODEL_META_DATA_CONDITIONAL_STATEMENT_IF
,
1491 MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF
,
1492 MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF
]:
1493 self
._DirectiveStack
.append(self
._ItemType
)
1494 if self
._ItemType
== MODEL_META_DATA_CONDITIONAL_STATEMENT_IF
:
1495 Result
= bool(Result
)
1497 Macro
= self
._ValueList
[1]
1498 Macro
= Macro
[2:-1] if (Macro
.startswith("$(") and Macro
.endswith(")")) else Macro
1499 Result
= Macro
in self
._Macros
1500 if self
._ItemType
== MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF
:
1502 self
._DirectiveEvalStack
.append(Result
)
1503 elif self
._ItemType
== MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSEIF
:
1504 self
._DirectiveStack
.append(self
._ItemType
)
1505 self
._DirectiveEvalStack
[-1] = not self
._DirectiveEvalStack
[-1]
1506 self
._DirectiveEvalStack
.append(bool(Result
))
1507 elif self
._ItemType
== MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE
:
1508 self
._DirectiveStack
.append(self
._ItemType
)
1509 self
._DirectiveEvalStack
[-1] = not self
._DirectiveEvalStack
[-1]
1510 self
._DirectiveEvalStack
.append(True)
1511 elif self
._ItemType
== MODEL_META_DATA_CONDITIONAL_STATEMENT_ENDIF
:
1512 # Back to the nearest !if/!ifdef/!ifndef
1513 while self
._DirectiveStack
:
1514 self
._DirectiveEvalStack
.pop()
1515 Directive
= self
._DirectiveStack
.pop()
1516 if Directive
in [MODEL_META_DATA_CONDITIONAL_STATEMENT_IF
,
1517 MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF
,
1518 MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF
]:
1520 elif self
._ItemType
== MODEL_META_DATA_INCLUDE
:
1521 # The included file must be relative to workspace or same directory as DSC file
1522 __IncludeMacros
= {}
1524 # Allow using system environment variables in path after !include
1526 __IncludeMacros
['WORKSPACE'] = GlobalData
.gGlobalDefines
['WORKSPACE']
1527 if "ECP_SOURCE" in GlobalData
.gGlobalDefines
:
1528 __IncludeMacros
['ECP_SOURCE'] = GlobalData
.gGlobalDefines
['ECP_SOURCE']
1530 # During GenFds phase call DSC parser, will go into this branch.
1532 elif "ECP_SOURCE" in GlobalData
.gCommandLineDefines
:
1533 __IncludeMacros
['ECP_SOURCE'] = GlobalData
.gCommandLineDefines
['ECP_SOURCE']
1535 __IncludeMacros
['EFI_SOURCE'] = GlobalData
.gGlobalDefines
['EFI_SOURCE']
1536 __IncludeMacros
['EDK_SOURCE'] = GlobalData
.gGlobalDefines
['EDK_SOURCE']
1538 # Allow using MACROs comes from [Defines] section to keep compatible.
1540 __IncludeMacros
.update(self
._Macros
)
1542 IncludedFile
= NormPath(ReplaceMacro(self
._ValueList
[1], __IncludeMacros
, RaiseError
=True))
1544 # First search the include file under the same directory as DSC file
1546 IncludedFile1
= PathClass(IncludedFile
, self
.MetaFile
.Dir
)
1547 ErrorCode
, ErrorInfo1
= IncludedFile1
.Validate()
1550 # Also search file under the WORKSPACE directory
1552 IncludedFile1
= PathClass(IncludedFile
, GlobalData
.gWorkspace
)
1553 ErrorCode
, ErrorInfo2
= IncludedFile1
.Validate()
1555 EdkLogger
.error('parser', ErrorCode
, File
=self
._FileWithError
,
1556 Line
=self
._LineIndex
+ 1, ExtraData
=ErrorInfo1
+ "\n" + ErrorInfo2
)
1558 self
._FileWithError
= IncludedFile1
1560 IncludedFileTable
= MetaFileStorage(self
._Table
.Cur
, IncludedFile1
, MODEL_FILE_DSC
, False)
1561 FromItem
= self
._Content
[self
._ContentIndex
- 1][0]
1562 if self
._InSubsection
:
1563 Owner
= self
._Content
[self
._ContentIndex
- 1][8]
1565 Owner
= self
._Content
[self
._ContentIndex
- 1][0]
1566 Parser
= DscParser(IncludedFile1
, self
._FileType
, self
._Arch
, IncludedFileTable
,
1567 Owner
=Owner
, From
=FromItem
)
1569 self
.IncludedFiles
.add (IncludedFile1
)
1571 # set the parser status with current status
1572 Parser
._SectionName
= self
._SectionName
1573 Parser
._SubsectionType
= self
._SubsectionType
1574 Parser
._InSubsection
= self
._InSubsection
1575 Parser
._SectionType
= self
._SectionType
1576 Parser
._Scope
= self
._Scope
1577 Parser
._Enabled
= self
._Enabled
1578 # Parse the included file
1582 # Insert all records in the table for the included file into dsc file table
1583 Records
= IncludedFileTable
.GetAll()
1585 self
._Content
[self
._ContentIndex
:self
._ContentIndex
] = Records
1586 self
._Content
.pop(self
._ContentIndex
- 1)
1587 self
._ValueList
= None
1588 self
._ContentIndex
-= 1
1590 def __ProcessSkuId(self
):
1591 self
._ValueList
= [ReplaceMacro(Value
, self
._Macros
, RaiseError
=True)
1592 for Value
in self
._ValueList
]
1593 def __ProcessDefaultStores(self
):
1594 self
._ValueList
= [ReplaceMacro(Value
, self
._Macros
, RaiseError
=True)
1595 for Value
in self
._ValueList
]
1597 def __ProcessLibraryInstance(self
):
1598 self
._ValueList
= [ReplaceMacro(Value
, self
._Macros
) for Value
in self
._ValueList
]
1600 def __ProcessLibraryClass(self
):
1601 self
._ValueList
[1] = ReplaceMacro(self
._ValueList
[1], self
._Macros
, RaiseError
=True)
1603 def __ProcessPcd(self
):
1604 if self
._ItemType
not in [MODEL_PCD_FEATURE_FLAG
, MODEL_PCD_FIXED_AT_BUILD
]:
1605 self
._ValueList
[2] = ReplaceMacro(self
._ValueList
[2], self
._Macros
, RaiseError
=True)
1608 ValList
, Valid
, Index
= AnalyzeDscPcd(self
._ValueList
[2], self
._ItemType
)
1610 EdkLogger
.error('build', FORMAT_INVALID
, "Pcd format incorrect.", File
=self
._FileWithError
, Line
=self
._LineIndex
+ 1,
1611 ExtraData
="%s.%s|%s" % (self
._ValueList
[0], self
._ValueList
[1], self
._ValueList
[2]))
1612 PcdValue
= ValList
[Index
]
1613 if PcdValue
and "." not in self
._ValueList
[0]:
1615 ValList
[Index
] = ValueExpression(PcdValue
, self
._Macros
)(True)
1616 except WrnExpression
as Value
:
1617 ValList
[Index
] = Value
.result
1621 if ValList
[Index
] == 'True':
1622 ValList
[Index
] = '1'
1623 if ValList
[Index
] == 'False':
1624 ValList
[Index
] = '0'
1626 if (not self
._DirectiveEvalStack
) or (False not in self
._DirectiveEvalStack
):
1627 GlobalData
.gPlatformPcds
[TAB_SPLIT
.join(self
._ValueList
[0:2])] = PcdValue
1628 self
._Symbols
[TAB_SPLIT
.join(self
._ValueList
[0:2])] = PcdValue
1630 self
._ValueList
[2] = '|'.join(ValList
)
1634 def __ProcessComponent(self
):
1635 self
._ValueList
[0] = ReplaceMacro(self
._ValueList
[0], self
._Macros
)
1637 def __ProcessSourceOverridePath(self
):
1638 self
._ValueList
[0] = ReplaceMacro(self
._ValueList
[0], self
._Macros
)
1640 def __ProcessBuildOption(self
):
1641 self
._ValueList
= [ReplaceMacro(Value
, self
._Macros
, RaiseError
=False)
1642 for Value
in self
._ValueList
]
1645 MODEL_META_DATA_HEADER
: _DefineParser
,
1646 MODEL_EFI_SKU_ID
: _SkuIdParser
,
1647 MODEL_EFI_DEFAULT_STORES
: _DefaultStoresParser
,
1648 MODEL_EFI_LIBRARY_INSTANCE
: _LibraryInstanceParser
,
1649 MODEL_EFI_LIBRARY_CLASS
: _LibraryClassParser
,
1650 MODEL_PCD_FIXED_AT_BUILD
: _PcdParser
,
1651 MODEL_PCD_PATCHABLE_IN_MODULE
: _PcdParser
,
1652 MODEL_PCD_FEATURE_FLAG
: _PcdParser
,
1653 MODEL_PCD_DYNAMIC_DEFAULT
: _PcdParser
,
1654 MODEL_PCD_DYNAMIC_HII
: _PcdParser
,
1655 MODEL_PCD_DYNAMIC_VPD
: _PcdParser
,
1656 MODEL_PCD_DYNAMIC_EX_DEFAULT
: _PcdParser
,
1657 MODEL_PCD_DYNAMIC_EX_HII
: _PcdParser
,
1658 MODEL_PCD_DYNAMIC_EX_VPD
: _PcdParser
,
1659 MODEL_META_DATA_COMPONENT
: _ComponentParser
,
1660 MODEL_META_DATA_COMPONENT_SOURCE_OVERRIDE_PATH
: _CompponentSourceOverridePathParser
,
1661 MODEL_META_DATA_BUILD_OPTION
: _BuildOptionParser
,
1662 MODEL_UNKNOWN
: MetaFileParser
._Skip
,
1663 MODEL_META_DATA_USER_EXTENSION
: MetaFileParser
._SkipUserExtension
,
1664 MODEL_META_DATA_SECTION_HEADER
: MetaFileParser
._SectionHeaderParser
,
1665 MODEL_META_DATA_SUBSECTION_HEADER
: _SubsectionHeaderParser
,
1668 _Macros
= property(_GetMacros
)
1670 ## DEC file parser class
1672 # @param FilePath The path of platform description file
1673 # @param FileType The raw data of DSC file
1674 # @param Table Database used to retrieve module/package information
1675 # @param Macros Macros used for replacement in file
1677 class DecParser(MetaFileParser
):
1678 # DEC file supported data types (one type per section)
1680 TAB_DEC_DEFINES
.upper() : MODEL_META_DATA_HEADER
,
1681 TAB_DSC_DEFINES_DEFINE
: MODEL_META_DATA_DEFINE
,
1682 TAB_INCLUDES
.upper() : MODEL_EFI_INCLUDE
,
1683 TAB_LIBRARY_CLASSES
.upper() : MODEL_EFI_LIBRARY_CLASS
,
1684 TAB_GUIDS
.upper() : MODEL_EFI_GUID
,
1685 TAB_PPIS
.upper() : MODEL_EFI_PPI
,
1686 TAB_PROTOCOLS
.upper() : MODEL_EFI_PROTOCOL
,
1687 TAB_PCDS_FIXED_AT_BUILD_NULL
.upper() : MODEL_PCD_FIXED_AT_BUILD
,
1688 TAB_PCDS_PATCHABLE_IN_MODULE_NULL
.upper() : MODEL_PCD_PATCHABLE_IN_MODULE
,
1689 TAB_PCDS_FEATURE_FLAG_NULL
.upper() : MODEL_PCD_FEATURE_FLAG
,
1690 TAB_PCDS_DYNAMIC_NULL
.upper() : MODEL_PCD_DYNAMIC
,
1691 TAB_PCDS_DYNAMIC_EX_NULL
.upper() : MODEL_PCD_DYNAMIC_EX
,
1692 TAB_USER_EXTENSIONS
.upper() : MODEL_META_DATA_USER_EXTENSION
,
1695 ## Constructor of DecParser
1697 # Initialize object of DecParser
1699 # @param FilePath The path of platform description file
1700 # @param FileType The raw data of DSC file
1701 # @param Arch Default Arch value for filtering sections
1702 # @param Table Database used to retrieve module/package information
1704 def __init__(self
, FilePath
, FileType
, Arch
, Table
):
1705 # prevent re-initialization
1706 if hasattr(self
, "_Table"):
1708 MetaFileParser
.__init
__(self
, FilePath
, FileType
, Arch
, Table
, -1)
1710 self
._Version
= 0x00010005 # Only EDK2 dec file is supported
1711 self
._AllPCDs
= [] # Only for check duplicate PCD
1712 self
._AllPcdDict
= {}
1714 self
._CurrentStructurePcdName
= ""
1715 self
._include
_flag
= False
1716 self
._package
_flag
= False
1722 Content
= open(str(self
.MetaFile
), 'r').readlines()
1724 EdkLogger
.error("Parser", FILE_READ_FAILURE
, ExtraData
=self
.MetaFile
)
1726 self
._DefinesCount
= 0
1727 for Index
in range(0, len(Content
)):
1728 Line
, Comment
= CleanString2(Content
[Index
])
1729 self
._CurrentLine
= Line
1730 self
._LineIndex
= Index
1732 # save comment for later use
1734 self
._Comments
.append((Comment
, self
._LineIndex
+ 1))
1740 if Line
[0] == TAB_SECTION_START
and Line
[-1] == TAB_SECTION_END
:
1741 self
._SectionHeaderParser
()
1742 if self
._SectionName
== TAB_DEC_DEFINES
.upper():
1743 self
._DefinesCount
+= 1
1746 if self
._SectionType
== MODEL_UNKNOWN
:
1747 EdkLogger
.error("Parser", FORMAT_INVALID
,
1749 "Not able to determine \"%s\" in which section."%self
._CurrentLine
,
1750 self
.MetaFile
, self
._LineIndex
+ 1)
1751 elif len(self
._SectionType
) == 0:
1756 self
._ValueList
= ['', '', '']
1757 self
._SectionParser
[self
._SectionType
[0]](self
)
1758 if self
._ValueList
is None or self
._ItemType
== MODEL_META_DATA_DEFINE
:
1764 # Model, Value1, Value2, Value3, Arch, BelongsToItem=-1, LineBegin=-1,
1765 # ColumnBegin=-1, LineEnd=-1, ColumnEnd=-1, FeatureFlag='', Enabled=-1
1767 for Arch
, ModuleType
, Type
in self
._Scope
:
1768 self
._LastItem
= self
._Store
(
1776 self
._LineIndex
+ 1,
1778 self
._LineIndex
+ 1,
1782 for Comment
, LineNo
in self
._Comments
:
1784 MODEL_META_DATA_COMMENT
,
1798 if self
._DefinesCount
> 1:
1799 EdkLogger
.error('Parser', FORMAT_INVALID
, 'Multiple [Defines] section is exist.', self
.MetaFile
)
1800 if self
._DefinesCount
== 0:
1801 EdkLogger
.error('Parser', FORMAT_INVALID
, 'No [Defines] section exist.', self
.MetaFile
)
1805 ## Section header parser
1807 # The section header is always in following format:
1809 # [section_name.arch<.platform|module_type>]
1811 def _SectionHeaderParser(self
):
1813 self
._SectionName
= ''
1814 self
._SectionType
= []
1817 Line
= re
.sub(',[\s]*', TAB_COMMA_SPLIT
, self
._CurrentLine
)
1818 for Item
in Line
[1:-1].split(TAB_COMMA_SPLIT
):
1820 EdkLogger
.error("Parser", FORMAT_UNKNOWN_ERROR
,
1821 "section name can NOT be empty or incorrectly use separator comma",
1822 self
.MetaFile
, self
._LineIndex
+ 1, self
._CurrentLine
)
1823 ItemList
= Item
.split(TAB_SPLIT
)
1825 # different types of PCD are permissible in one section
1826 self
._SectionName
= ItemList
[0].upper()
1827 if self
._SectionName
== TAB_DEC_DEFINES
.upper() and (len(ItemList
) > 1 or len(Line
.split(TAB_COMMA_SPLIT
)) > 1):
1828 EdkLogger
.error("Parser", FORMAT_INVALID
, "Defines section format is invalid",
1829 self
.MetaFile
, self
._LineIndex
+ 1, self
._CurrentLine
)
1830 if self
._SectionName
in self
.DataType
:
1831 if self
.DataType
[self
._SectionName
] not in self
._SectionType
:
1832 self
._SectionType
.append(self
.DataType
[self
._SectionName
])
1834 EdkLogger
.error("Parser", FORMAT_UNKNOWN_ERROR
, "%s is not a valid section name" % Item
,
1835 self
.MetaFile
, self
._LineIndex
+ 1, self
._CurrentLine
)
1837 if MODEL_PCD_FEATURE_FLAG
in self
._SectionType
and len(self
._SectionType
) > 1:
1841 "%s must not be in the same section of other types of PCD" % TAB_PCDS_FEATURE_FLAG_NULL
,
1843 Line
=self
._LineIndex
+ 1,
1844 ExtraData
=self
._CurrentLine
1847 if len(ItemList
) > 1:
1848 S1
= ItemList
[1].upper()
1850 S1
= TAB_ARCH_COMMON
1852 # S2 may be Platform or ModuleType
1853 if len(ItemList
) > 2:
1854 S2
= ItemList
[2].upper()
1855 # only Includes, GUIDs, PPIs, Protocols section have Private tag
1856 if self
._SectionName
in [TAB_INCLUDES
.upper(), TAB_GUIDS
.upper(), TAB_PROTOCOLS
.upper(), TAB_PPIS
.upper()]:
1858 EdkLogger
.error("Parser", FORMAT_INVALID
, 'Please use keyword "Private" as section tag modifier.',
1859 File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1, ExtraData
=self
._CurrentLine
)
1863 if [S1
, S2
, self
.DataType
[self
._SectionName
]] not in self
._Scope
:
1864 self
._Scope
.append([S1
, S2
, self
.DataType
[self
._SectionName
]])
1866 # 'COMMON' must not be used with specific ARCHs at the same section
1867 if TAB_ARCH_COMMON
in ArchList
and len(ArchList
) > 1:
1868 EdkLogger
.error('Parser', FORMAT_INVALID
, "'common' ARCH must not be used with specific ARCHs",
1869 File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1, ExtraData
=self
._CurrentLine
)
1871 # It is not permissible to mix section tags without the Private attribute with section tags with the Private attribute
1872 if TAB_COMMON
in PrivateList
and len(PrivateList
) > 1:
1873 EdkLogger
.error('Parser', FORMAT_INVALID
, "Can't mix section tags without the Private attribute with section tags with the Private attribute",
1874 File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1, ExtraData
=self
._CurrentLine
)
1876 ## [guids], [ppis] and [protocols] section parser
1878 def _GuidParser(self
):
1879 TokenList
= GetSplitValueList(self
._CurrentLine
, TAB_EQUAL_SPLIT
, 1)
1880 if len(TokenList
) < 2:
1881 EdkLogger
.error('Parser', FORMAT_INVALID
, "No GUID name or value specified",
1882 ExtraData
=self
._CurrentLine
+ " (<CName> = <GuidValueInCFormat>)",
1883 File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
1884 if TokenList
[0] == '':
1885 EdkLogger
.error('Parser', FORMAT_INVALID
, "No GUID name specified",
1886 ExtraData
=self
._CurrentLine
+ " (<CName> = <GuidValueInCFormat>)",
1887 File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
1888 if TokenList
[1] == '':
1889 EdkLogger
.error('Parser', FORMAT_INVALID
, "No GUID value specified",
1890 ExtraData
=self
._CurrentLine
+ " (<CName> = <GuidValueInCFormat>)",
1891 File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
1892 if TokenList
[1][0] != '{' or TokenList
[1][-1] != '}' or GuidStructureStringToGuidString(TokenList
[1]) == '':
1893 EdkLogger
.error('Parser', FORMAT_INVALID
, "Invalid GUID value format",
1894 ExtraData
=self
._CurrentLine
+ \
1895 " (<CName> = <GuidValueInCFormat:{8,4,4,{2,2,2,2,2,2,2,2}}>)",
1896 File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
1897 self
._ValueList
[0] = TokenList
[0]
1898 self
._ValueList
[1] = TokenList
[1]
1899 if self
._ValueList
[0] not in self
._GuidDict
:
1900 self
._GuidDict
[self
._ValueList
[0]] = self
._ValueList
[1]
1902 ## PCD sections parser
1904 # [PcdsFixedAtBuild]
1905 # [PcdsPatchableInModule]
1911 def _PcdParser(self
):
1912 if self
._CurrentStructurePcdName
:
1913 self
._ValueList
[0] = self
._CurrentStructurePcdName
1915 if "|" not in self
._CurrentLine
:
1916 if "<HeaderFiles>" == self
._CurrentLine
:
1917 self
._include
_flag
= True
1918 self
._package
_flag
= False
1919 self
._ValueList
= None
1921 if "<Packages>" == self
._CurrentLine
:
1922 self
._package
_flag
= True
1923 self
._ValueList
= None
1924 self
._include
_flag
= False
1927 if self
._include
_flag
:
1928 self
._ValueList
[1] = "<HeaderFiles>_" + md5
.new(self
._CurrentLine
).hexdigest()
1929 self
._ValueList
[2] = self
._CurrentLine
1930 if self
._package
_flag
and "}" != self
._CurrentLine
:
1931 self
._ValueList
[1] = "<Packages>_" + md5
.new(self
._CurrentLine
).hexdigest()
1932 self
._ValueList
[2] = self
._CurrentLine
1933 if self
._CurrentLine
== "}":
1934 self
._package
_flag
= False
1935 self
._include
_flag
= False
1936 self
._ValueList
= None
1939 PcdTockens
= self
._CurrentLine
.split(TAB_VALUE_SPLIT
)
1940 PcdNames
= PcdTockens
[0].split(TAB_SPLIT
)
1941 if len(PcdNames
) == 2:
1942 self
._CurrentStructurePcdName
= ""
1944 if self
._CurrentStructurePcdName
!= TAB_SPLIT
.join(PcdNames
[:2]):
1945 EdkLogger
.error('Parser', FORMAT_INVALID
, "Pcd Name does not match: %s and %s " % (self
._CurrentStructurePcdName
, TAB_SPLIT
.join(PcdNames
[:2])),
1946 File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
1947 self
._ValueList
[1] = TAB_SPLIT
.join(PcdNames
[2:])
1948 self
._ValueList
[2] = PcdTockens
[1]
1949 if not self
._CurrentStructurePcdName
:
1950 TokenList
= GetSplitValueList(self
._CurrentLine
, TAB_VALUE_SPLIT
, 1)
1951 self
._ValueList
[0:1] = GetSplitValueList(TokenList
[0], TAB_SPLIT
)
1952 ValueRe
= re
.compile(r
'^[a-zA-Z_][a-zA-Z0-9_]*')
1953 # check PCD information
1954 if self
._ValueList
[0] == '' or self
._ValueList
[1] == '':
1955 EdkLogger
.error('Parser', FORMAT_INVALID
, "No token space GUID or PCD name specified",
1956 ExtraData
=self
._CurrentLine
+ \
1957 " (<TokenSpaceGuidCName>.<PcdCName>|<DefaultValue>|<DatumType>|<Token>)",
1958 File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
1959 # check format of token space GUID CName
1960 if not ValueRe
.match(self
._ValueList
[0]):
1961 EdkLogger
.error('Parser', FORMAT_INVALID
, "The format of the token space GUID CName is invalid. The correct format is '(a-zA-Z_)[a-zA-Z0-9_]*'",
1962 ExtraData
=self
._CurrentLine
+ \
1963 " (<TokenSpaceGuidCName>.<PcdCName>|<DefaultValue>|<DatumType>|<Token>)",
1964 File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
1965 # check format of PCD CName
1966 if not ValueRe
.match(self
._ValueList
[1]):
1967 EdkLogger
.error('Parser', FORMAT_INVALID
, "The format of the PCD CName is invalid. The correct format is '(a-zA-Z_)[a-zA-Z0-9_]*'",
1968 ExtraData
=self
._CurrentLine
+ \
1969 " (<TokenSpaceGuidCName>.<PcdCName>|<DefaultValue>|<DatumType>|<Token>)",
1970 File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
1971 # check PCD datum information
1972 if len(TokenList
) < 2 or TokenList
[1] == '':
1973 EdkLogger
.error('Parser', FORMAT_INVALID
, "No PCD Datum information given",
1974 ExtraData
=self
._CurrentLine
+ \
1975 " (<TokenSpaceGuidCName>.<PcdCName>|<DefaultValue>|<DatumType>|<Token>)",
1976 File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
1979 ValueRe
= re
.compile(r
'^\s*L?\".*\|.*\"')
1980 PtrValue
= ValueRe
.findall(TokenList
[1])
1982 # Has VOID* type string, may contain "|" character in the string.
1983 if len(PtrValue
) != 0:
1984 ptrValueList
= re
.sub(ValueRe
, '', TokenList
[1])
1985 ValueList
= AnalyzePcdExpression(ptrValueList
)
1986 ValueList
[0] = PtrValue
[0]
1988 ValueList
= AnalyzePcdExpression(TokenList
[1])
1991 # check if there's enough datum information given
1992 if len(ValueList
) != 3:
1993 EdkLogger
.error('Parser', FORMAT_INVALID
, "Invalid PCD Datum information given",
1994 ExtraData
=self
._CurrentLine
+ \
1995 " (<TokenSpaceGuidCName>.<PcdCName>|<DefaultValue>|<DatumType>|<Token>)",
1996 File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
1997 # check default value
1998 if ValueList
[0] == '':
1999 EdkLogger
.error('Parser', FORMAT_INVALID
, "Missing DefaultValue in PCD Datum information",
2000 ExtraData
=self
._CurrentLine
+ \
2001 " (<TokenSpaceGuidCName>.<PcdCName>|<DefaultValue>|<DatumType>|<Token>)",
2002 File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
2004 if ValueList
[1] == '':
2005 EdkLogger
.error('Parser', FORMAT_INVALID
, "Missing DatumType in PCD Datum information",
2006 ExtraData
=self
._CurrentLine
+ \
2007 " (<TokenSpaceGuidCName>.<PcdCName>|<DefaultValue>|<DatumType>|<Token>)",
2008 File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
2009 # check token of the PCD
2010 if ValueList
[2] == '':
2011 EdkLogger
.error('Parser', FORMAT_INVALID
, "Missing Token in PCD Datum information",
2012 ExtraData
=self
._CurrentLine
+ \
2013 " (<TokenSpaceGuidCName>.<PcdCName>|<DefaultValue>|<DatumType>|<Token>)",
2014 File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
2016 PcdValue
= ValueList
[0]
2019 self
._GuidDict
.update(self
._AllPcdDict
)
2020 ValueList
[0] = ValueExpressionEx(ValueList
[0], ValueList
[1], self
._GuidDict
)(True)
2021 except BadExpression
as Value
:
2022 EdkLogger
.error('Parser', FORMAT_INVALID
, Value
, ExtraData
=self
._CurrentLine
, File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
2023 # check format of default value against the datum type
2024 IsValid
, Cause
= CheckPcdDatum(ValueList
[1], ValueList
[0])
2026 EdkLogger
.error('Parser', FORMAT_INVALID
, Cause
, ExtraData
=self
._CurrentLine
,
2027 File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
2029 if Cause
== "StructurePcd":
2030 self
._CurrentStructurePcdName
= TAB_SPLIT
.join(self
._ValueList
[0:2])
2031 self
._ValueList
[0] = self
._CurrentStructurePcdName
2032 self
._ValueList
[1] = ValueList
[1].strip()
2034 if ValueList
[0] in ['True', 'true', 'TRUE']:
2036 elif ValueList
[0] in ['False', 'false', 'FALSE']:
2039 # check for duplicate PCD definition
2040 if (self
._Scope
[0], self
._ValueList
[0], self
._ValueList
[1]) in self
._AllPCDs
:
2041 EdkLogger
.error('Parser', FORMAT_INVALID
,
2042 "The same PCD name and GUID have been already defined",
2043 ExtraData
=self
._CurrentLine
, File
=self
.MetaFile
, Line
=self
._LineIndex
+ 1)
2045 self
._AllPCDs
.append((self
._Scope
[0], self
._ValueList
[0], self
._ValueList
[1]))
2046 self
._AllPcdDict
[TAB_SPLIT
.join(self
._ValueList
[0:2])] = ValueList
[0]
2048 self
._ValueList
[2] = ValueList
[0].strip() + '|' + ValueList
[1].strip() + '|' + ValueList
[2].strip()
2051 MODEL_META_DATA_HEADER
: MetaFileParser
._DefineParser
,
2052 MODEL_EFI_INCLUDE
: MetaFileParser
._PathParser
,
2053 MODEL_EFI_LIBRARY_CLASS
: MetaFileParser
._PathParser
,
2054 MODEL_EFI_GUID
: _GuidParser
,
2055 MODEL_EFI_PPI
: _GuidParser
,
2056 MODEL_EFI_PROTOCOL
: _GuidParser
,
2057 MODEL_PCD_FIXED_AT_BUILD
: _PcdParser
,
2058 MODEL_PCD_PATCHABLE_IN_MODULE
: _PcdParser
,
2059 MODEL_PCD_FEATURE_FLAG
: _PcdParser
,
2060 MODEL_PCD_DYNAMIC
: _PcdParser
,
2061 MODEL_PCD_DYNAMIC_EX
: _PcdParser
,
2062 MODEL_UNKNOWN
: MetaFileParser
._Skip
,
2063 MODEL_META_DATA_USER_EXTENSION
: MetaFileParser
._SkipUserExtension
,
2068 # This acts like the main() function for the script, unless it is 'import'ed into another
2071 if __name__
== '__main__':