summaryrefslogtreecommitdiff
path: root/BaseTools/Source/Python/Workspace
diff options
context:
space:
mode:
authorLiming Gao <liming.gao@intel.com>2013-08-23 02:18:16 +0000
committerlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>2013-08-23 02:18:16 +0000
commit4afd3d042215afe68d00b9ab8c32f063a3a1c03f (patch)
treeb5190bd11547ac22fe35eeceee85ef42bfe6eea5 /BaseTools/Source/Python/Workspace
parenta365eed476687881ce0ed49af7d483fd3cb0c491 (diff)
downloadedk2-platforms-4afd3d042215afe68d00b9ab8c32f063a3a1c03f.tar.xz
Sync BaseTool trunk (version r2599) into EDKII BaseTools.
Signed-off-by: Liming Gao <liming.gao@intel.com> Reviewed-by: Heshen Chen <chen.heshen@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14591 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'BaseTools/Source/Python/Workspace')
-rw-r--r--BaseTools/Source/Python/Workspace/MetaFileParser.py391
-rw-r--r--BaseTools/Source/Python/Workspace/WorkspaceCommon.py237
-rw-r--r--BaseTools/Source/Python/Workspace/WorkspaceDatabase.py93
3 files changed, 501 insertions, 220 deletions
diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py b/BaseTools/Source/Python/Workspace/MetaFileParser.py
index a6668774b5..b2e98633af 100644
--- a/BaseTools/Source/Python/Workspace/MetaFileParser.py
+++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py
@@ -1,7 +1,7 @@
## @file
# This file is used to parse meta files
#
-# Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.<BR>
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
@@ -25,7 +25,7 @@ import Common.GlobalData as GlobalData
from CommonDataClass.DataClass import *
from Common.DataType import *
from Common.String import *
-from Common.Misc import GuidStructureStringToGuidString, CheckPcdDatum, PathClass, AnalyzePcdData
+from Common.Misc import GuidStructureStringToGuidString, CheckPcdDatum, PathClass, AnalyzePcdData, AnalyzeDscPcd
from Common.Expression import *
from CommonDataClass.Exceptions import *
@@ -44,7 +44,7 @@ def ParseMacro(Parser):
# Syntax check
if not TokenList[0]:
EdkLogger.error('Parser', FORMAT_INVALID, "No macro name given",
- ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1)
+ ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)
if len(TokenList) < 2:
TokenList.append('')
@@ -53,11 +53,11 @@ def ParseMacro(Parser):
# Global macros can be only defined via environment variable
if Name in GlobalData.gGlobalDefines:
EdkLogger.error('Parser', FORMAT_INVALID, "%s can only be defined via environment variable" % Name,
- ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1)
+ ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)
# Only upper case letters, digit and '_' are allowed
if not gMacroNamePattern.match(Name):
EdkLogger.error('Parser', FORMAT_INVALID, "The macro name must be in the pattern [A-Z][A-Z0-9_]*",
- ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1)
+ ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)
Value = ReplaceMacro(Value, self._Macros)
if Type in self.DataType:
@@ -85,14 +85,14 @@ def ParseMacro(Parser):
# EDK_GLOBAL defined macros
elif type(self) != DscParser:
EdkLogger.error('Parser', FORMAT_INVALID, "EDK_GLOBAL can only be used in .dsc file",
- ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1)
+ ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)
elif self._SectionType != MODEL_META_DATA_HEADER:
EdkLogger.error('Parser', FORMAT_INVALID, "EDK_GLOBAL can only be used under [Defines] section",
- ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1)
+ ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)
elif (Name in self._FileLocalMacros) and (self._FileLocalMacros[Name] != Value):
EdkLogger.error('Parser', FORMAT_INVALID, "EDK_GLOBAL defined a macro with the same name and different value as one defined by 'DEFINE'",
- ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1)
-
+ ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)
+
self._ValueList = [Type, Name, Value]
return MacroParser
@@ -146,7 +146,7 @@ class MetaFileParser(object):
# @param Owner Owner ID (for sub-section parsing)
# @param From ID from which the data comes (for !INCLUDE directive)
#
- def __init__(self, FilePath, FileType, Table, Owner=-1, From=-1):
+ def __init__(self, FilePath, FileType, Table, Owner= -1, From= -1):
self._Table = Table
self._RawTable = Table
self._FileType = FileType
@@ -262,7 +262,7 @@ class MetaFileParser(object):
## Skip unsupported data
def _Skip(self):
EdkLogger.warn("Parser", "Unrecognized content", File=self.MetaFile,
- Line=self._LineIndex+1, ExtraData=self._CurrentLine);
+ Line=self._LineIndex + 1, ExtraData=self._CurrentLine);
self._ValueList[0:1] = [self._CurrentLine]
## Section header parser
@@ -282,20 +282,27 @@ class MetaFileParser(object):
# different section should not mix in one section
if self._SectionName != '' and self._SectionName != ItemList[0].upper():
EdkLogger.error('Parser', FORMAT_INVALID, "Different section names in the same section",
- File=self.MetaFile, Line=self._LineIndex+1, ExtraData=self._CurrentLine)
+ File=self.MetaFile, Line=self._LineIndex + 1, ExtraData=self._CurrentLine)
self._SectionName = ItemList[0].upper()
if self._SectionName in self.DataType:
self._SectionType = self.DataType[self._SectionName]
+ # Check if the section name is valid
+ if self._SectionName not in SECTIONS_HAVE_ITEM_AFTER_ARCH and len(ItemList) > 2:
+ EdkLogger.error("Parser", FORMAT_UNKNOWN_ERROR, "%s is not a valid section name" % Item,
+ self.MetaFile, self._LineIndex + 1, self._CurrentLine)
+ elif self._Version >= 0x00010005:
+ EdkLogger.error("Parser", FORMAT_UNKNOWN_ERROR, "%s is not a valid section name" % Item,
+ self.MetaFile, self._LineIndex + 1, self._CurrentLine)
else:
self._SectionType = MODEL_UNKNOWN
- EdkLogger.warn("Parser", "Unrecognized section", File=self.MetaFile,
- Line=self._LineIndex+1, ExtraData=self._CurrentLine)
+
# S1 is always Arch
if len(ItemList) > 1:
S1 = ItemList[1].upper()
else:
S1 = 'COMMON'
ArchList.add(S1)
+
# S2 may be Platform or ModuleType
if len(ItemList) > 2:
S2 = ItemList[2].upper()
@@ -306,7 +313,7 @@ class MetaFileParser(object):
# 'COMMON' must not be used with specific ARCHs at the same section
if 'COMMON' in ArchList and len(ArchList) > 1:
EdkLogger.error('Parser', FORMAT_INVALID, "'common' ARCH must not be used with specific ARCHs",
- File=self.MetaFile, Line=self._LineIndex+1, ExtraData=self._CurrentLine)
+ File=self.MetaFile, Line=self._LineIndex + 1, ExtraData=self._CurrentLine)
# If the section information is needed later, it should be stored in database
self._ValueList[0] = self._SectionName
@@ -317,10 +324,10 @@ class MetaFileParser(object):
self._ValueList[1:len(TokenList)] = TokenList
if not self._ValueList[1]:
EdkLogger.error('Parser', FORMAT_INVALID, "No name specified",
- ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1)
+ ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)
if not self._ValueList[2]:
EdkLogger.error('Parser', FORMAT_INVALID, "No value specified",
- ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1)
+ ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)
self._ValueList = [ReplaceMacro(Value, self._Macros) for Value in self._ValueList]
Name, Value = self._ValueList[1], self._ValueList[2]
@@ -330,7 +337,7 @@ class MetaFileParser(object):
self._Version = int(Value, 0)
except:
EdkLogger.error('Parser', FORMAT_INVALID, "Invalid version number",
- ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1)
+ ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)
if type(self) == InfParser and self._Version < 0x00010005:
# EDK module allows using defines as macros
@@ -358,7 +365,7 @@ class MetaFileParser(object):
"'%s' must be in format of <TARGET>_<TOOLCHAIN>_<ARCH>_<TOOL>_FLAGS" % self._ValueList[1],
ExtraData=self._CurrentLine,
File=self.MetaFile,
- Line=self._LineIndex+1
+ Line=self._LineIndex + 1
)
def _GetMacros(self):
@@ -391,11 +398,11 @@ class MetaFileParser(object):
ComComMacroDict = {}
ComSpeMacroDict = {}
SpeSpeMacroDict = {}
-
+
ActiveSectionType = self._SectionType
if type(self) == DecParser:
ActiveSectionType = self._SectionType[0]
-
+
for (SectionType, Scope) in self._SectionsMacroDict:
if SectionType != ActiveSectionType:
continue
@@ -406,7 +413,7 @@ class MetaFileParser(object):
break
else:
SpeSpeMacroDict.update(self._SectionsMacroDict[(SectionType, Scope)])
-
+
for ActiveScope in self._Scope:
Scope0, Scope1 = ActiveScope[0], ActiveScope[1]
if(Scope0, Scope1) not in Scope and (Scope0, "COMMON") not in Scope and ("COMMON", Scope1) not in Scope:
@@ -423,9 +430,9 @@ class MetaFileParser(object):
return Macros
- _SectionParser = {}
- Finished = property(_GetFinished, _SetFinished)
- _Macros = property(_GetMacros)
+ _SectionParser = {}
+ Finished = property(_GetFinished, _SetFinished)
+ _Macros = property(_GetMacros)
## INF file parser class
@@ -475,6 +482,7 @@ class InfParser(MetaFileParser):
if hasattr(self, "_Table"):
return
MetaFileParser.__init__(self, FilePath, FileType, Table)
+ self.PcdsDict = {}
## Parser starter
def Start(self):
@@ -527,13 +535,13 @@ class InfParser(MetaFileParser):
MODEL_META_DATA_USER_EXTENSION]:
EdkLogger.error('Parser', FORMAT_INVALID,
"Section [%s] is not allowed in inf file without version" % (self._SectionName),
- ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1)
+ ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)
elif self._SectionType in [MODEL_EFI_INCLUDE,
MODEL_EFI_LIBRARY_INSTANCE,
MODEL_META_DATA_NMAKE]:
EdkLogger.error('Parser', FORMAT_INVALID,
"Section [%s] is not allowed in inf file with version 0x%08x" % (self._SectionName, self._Version),
- ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1)
+ ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)
continue
# merge two lines specified by '\' in section NMAKE
elif self._SectionType == MODEL_META_DATA_NMAKE:
@@ -553,7 +561,7 @@ class InfParser(MetaFileParser):
NmakeLine = ''
# section content
- self._ValueList = ['','','']
+ self._ValueList = ['', '', '']
# parse current line, result will be put in self._ValueList
self._SectionParser[self._SectionType](self)
if self._ValueList == None or self._ItemType == MODEL_META_DATA_DEFINE:
@@ -571,14 +579,14 @@ class InfParser(MetaFileParser):
Arch,
Platform,
self._Owner[-1],
- self._LineIndex+1,
- -1,
- self._LineIndex+1,
- -1,
+ self._LineIndex + 1,
+ - 1,
+ self._LineIndex + 1,
+ - 1,
0
)
if IsFindBlockComment:
- EdkLogger.error("Parser", FORMAT_INVALID, "Open block comments (starting with /*) are expected to end with */",
+ EdkLogger.error("Parser", FORMAT_INVALID, "Open block comments (starting with /*) are expected to end with */",
File=self.MetaFile)
self._Done()
@@ -636,15 +644,15 @@ class InfParser(MetaFileParser):
if len(TokenList) < 2:
EdkLogger.error('Parser', FORMAT_INVALID, "No file type or path specified",
ExtraData=self._CurrentLine + " (<FileType> | <FilePath> [| <Target>])",
- File=self.MetaFile, Line=self._LineIndex+1)
+ File=self.MetaFile, Line=self._LineIndex + 1)
if not TokenList[0]:
EdkLogger.error('Parser', FORMAT_INVALID, "No file type specified",
ExtraData=self._CurrentLine + " (<FileType> | <FilePath> [| <Target>])",
- File=self.MetaFile, Line=self._LineIndex+1)
+ File=self.MetaFile, Line=self._LineIndex + 1)
if not TokenList[1]:
EdkLogger.error('Parser', FORMAT_INVALID, "No file path specified",
ExtraData=self._CurrentLine + " (<FileType> | <FilePath> [| <Target>])",
- File=self.MetaFile, Line=self._LineIndex+1)
+ File=self.MetaFile, Line=self._LineIndex + 1)
self._ValueList[0:len(TokenList)] = TokenList
self._ValueList[1] = ReplaceMacro(self._ValueList[1], self._Macros)
@@ -665,14 +673,14 @@ class InfParser(MetaFileParser):
if len(ValueList) != 2:
EdkLogger.error('Parser', FORMAT_INVALID, "Illegal token space GUID and PCD name format",
ExtraData=self._CurrentLine + " (<TokenSpaceGuidCName>.<PcdCName>)",
- File=self.MetaFile, Line=self._LineIndex+1)
+ File=self.MetaFile, Line=self._LineIndex + 1)
self._ValueList[0:1] = ValueList
if len(TokenList) > 1:
self._ValueList[2] = TokenList[1]
if self._ValueList[0] == '' or self._ValueList[1] == '':
EdkLogger.error('Parser', FORMAT_INVALID, "No token space GUID or PCD name specified",
ExtraData=self._CurrentLine + " (<TokenSpaceGuidCName>.<PcdCName>)",
- File=self.MetaFile, Line=self._LineIndex+1)
+ File=self.MetaFile, Line=self._LineIndex + 1)
# if value are 'True', 'true', 'TRUE' or 'False', 'false', 'FALSE', replace with integer 1 or 0.
if self._ValueList[2] != '':
@@ -681,6 +689,12 @@ class InfParser(MetaFileParser):
self._ValueList[2] = TokenList[1].replace(InfPcdValueList[0], '1', 1);
elif InfPcdValueList[0] in ['False', 'false', 'FALSE']:
self._ValueList[2] = TokenList[1].replace(InfPcdValueList[0], '0', 1);
+ if (self._ValueList[0], self._ValueList[1]) not in self.PcdsDict:
+ self.PcdsDict[self._ValueList[0], self._ValueList[1]] = self._SectionType
+ elif self.PcdsDict[self._ValueList[0], self._ValueList[1]] != self._SectionType:
+ EdkLogger.error('Parser', FORMAT_INVALID, "It is not permissible to list a specified PCD in different PCD type sections.",
+ ExtraData=self._CurrentLine + " (<TokenSpaceGuidCName>.<PcdCName>)",
+ File=self.MetaFile, Line=self._LineIndex + 1)
## [depex] section parser
@ParseMacro
@@ -691,11 +705,11 @@ class InfParser(MetaFileParser):
MODEL_UNKNOWN : MetaFileParser._Skip,
MODEL_META_DATA_HEADER : MetaFileParser._DefineParser,
MODEL_META_DATA_BUILD_OPTION : MetaFileParser._BuildOptionParser,
- MODEL_EFI_INCLUDE : _IncludeParser, # for Edk.x modules
- MODEL_EFI_LIBRARY_INSTANCE : MetaFileParser._CommonParser, # for Edk.x modules
+ MODEL_EFI_INCLUDE : _IncludeParser, # for Edk.x modules
+ MODEL_EFI_LIBRARY_INSTANCE : MetaFileParser._CommonParser, # for Edk.x modules
MODEL_EFI_LIBRARY_CLASS : MetaFileParser._PathParser,
MODEL_META_DATA_PACKAGE : MetaFileParser._PathParser,
- MODEL_META_DATA_NMAKE : _NmakeParser, # for Edk.x modules
+ MODEL_META_DATA_NMAKE : _NmakeParser, # for Edk.x modules
MODEL_PCD_FIXED_AT_BUILD : _PcdParser,
MODEL_PCD_PATCHABLE_IN_MODULE : _PcdParser,
MODEL_PCD_FEATURE_FLAG : _PcdParser,
@@ -781,7 +795,7 @@ class DscParser(MetaFileParser):
# @param Owner Owner ID (for sub-section parsing)
# @param From ID from which the data comes (for !INCLUDE directive)
#
- def __init__(self, FilePath, FileType, Table, Owner=-1, From=-1):
+ def __init__(self, FilePath, FileType, Table, Owner= -1, From= -1):
# prevent re-initialization
if hasattr(self, "_Table"):
return
@@ -791,12 +805,12 @@ class DscParser(MetaFileParser):
self._DirectiveStack = []
self._DirectiveEvalStack = []
self._Enabled = 1
-
+
#
# Specify whether current line is in uncertain condition
#
self._InDirective = -1
-
+
# Final valid replacable symbols
self._Symbols = {}
#
@@ -823,7 +837,7 @@ class DscParser(MetaFileParser):
self._LineIndex = Index
if self._InSubsection and self._Owner[-1] == -1:
self._Owner.append(self._LastItem)
-
+
# section header
if Line[0] == TAB_SECTION_START and Line[-1] == TAB_SECTION_END:
self._SectionType = MODEL_META_DATA_SECTION_HEADER
@@ -866,10 +880,10 @@ class DscParser(MetaFileParser):
ModuleType,
self._Owner[-1],
self._From,
- self._LineIndex+1,
- -1,
- self._LineIndex+1,
- -1,
+ self._LineIndex + 1,
+ - 1,
+ self._LineIndex + 1,
+ - 1,
self._Enabled
)
@@ -887,12 +901,12 @@ class DscParser(MetaFileParser):
else:
self._SubsectionType = MODEL_UNKNOWN
EdkLogger.warn("Parser", "Unrecognized sub-section", File=self.MetaFile,
- Line=self._LineIndex+1, ExtraData=self._CurrentLine)
+ Line=self._LineIndex + 1, ExtraData=self._CurrentLine)
self._ValueList[0] = self._SubsectionName
## Directive statement parser
def _DirectiveParser(self):
- self._ValueList = ['','','']
+ self._ValueList = ['', '', '']
TokenList = GetSplitValueList(self._CurrentLine, ' ', 1)
self._ValueList[0:len(TokenList)] = TokenList
@@ -900,7 +914,7 @@ class DscParser(MetaFileParser):
DirectiveName = self._ValueList[0].upper()
if DirectiveName not in self.DataType:
EdkLogger.error("Parser", FORMAT_INVALID, "Unknown directive [%s]" % DirectiveName,
- File=self.MetaFile, Line=self._LineIndex+1)
+ File=self.MetaFile, Line=self._LineIndex + 1)
if DirectiveName in ['!IF', '!IFDEF', '!IFNDEF']:
self._InDirective += 1
@@ -910,7 +924,7 @@ class DscParser(MetaFileParser):
if DirectiveName in ['!IF', '!IFDEF', '!INCLUDE', '!IFNDEF', '!ELSEIF'] and self._ValueList[1] == '':
EdkLogger.error("Parser", FORMAT_INVALID, "Missing expression",
- File=self.MetaFile, Line=self._LineIndex+1,
+ File=self.MetaFile, Line=self._LineIndex + 1,
ExtraData=self._CurrentLine)
ItemType = self.DataType[DirectiveName]
@@ -928,7 +942,7 @@ class DscParser(MetaFileParser):
break
else:
EdkLogger.error("Parser", FORMAT_INVALID, "Redundant '!endif'",
- File=self.MetaFile, Line=self._LineIndex+1,
+ File=self.MetaFile, Line=self._LineIndex + 1,
ExtraData=self._CurrentLine)
elif ItemType != MODEL_META_DATA_INCLUDE:
# Break if there's a !else is followed by a !elseif
@@ -936,14 +950,14 @@ class DscParser(MetaFileParser):
self._DirectiveStack and \
self._DirectiveStack[-1][0] == MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE:
EdkLogger.error("Parser", FORMAT_INVALID, "'!elseif' after '!else'",
- File=self.MetaFile, Line=self._LineIndex+1,
+ File=self.MetaFile, Line=self._LineIndex + 1,
ExtraData=self._CurrentLine)
- self._DirectiveStack.append((ItemType, self._LineIndex+1, self._CurrentLine))
+ self._DirectiveStack.append((ItemType, self._LineIndex + 1, self._CurrentLine))
elif self._From > 0:
EdkLogger.error('Parser', FORMAT_INVALID,
"No '!include' allowed in included file",
- ExtraData=self._CurrentLine, File=self.MetaFile,
- Line=self._LineIndex+1)
+ ExtraData=self._CurrentLine, File=self.MetaFile,
+ Line=self._LineIndex + 1)
#
# Model, Value1, Value2, Value3, Arch, ModuleType, BelongsToItem=-1, BelongsToFile=-1,
@@ -959,10 +973,10 @@ class DscParser(MetaFileParser):
ModuleType,
self._Owner[-1],
self._From,
- self._LineIndex+1,
- -1,
- self._LineIndex+1,
- -1,
+ self._LineIndex + 1,
+ - 1,
+ self._LineIndex + 1,
+ - 1,
0
)
@@ -975,16 +989,16 @@ class DscParser(MetaFileParser):
# Syntax check
if not self._ValueList[1]:
EdkLogger.error('Parser', FORMAT_INVALID, "No name specified",
- ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1)
+ ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)
if not self._ValueList[2]:
EdkLogger.error('Parser', FORMAT_INVALID, "No value specified",
- ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1)
+ ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)
if not self._ValueList[1] in self.DefineKeywords:
EdkLogger.error('Parser', FORMAT_INVALID,
"Unknown keyword found: %s. "
"If this is a macro you must "
"add it as a DEFINE in the DSC" % self._ValueList[1],
- ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1)
+ ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)
self._Defines[self._ValueList[1]] = self._ValueList[2]
self._ItemType = self.DataType[TAB_DSC_DEFINES.upper()]
@@ -993,7 +1007,7 @@ class DscParser(MetaFileParser):
TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT)
if len(TokenList) != 2:
EdkLogger.error('Parser', FORMAT_INVALID, "Correct format is '<Integer>|<UiName>'",
- ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1)
+ ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)
self._ValueList[0:len(TokenList)] = TokenList
## Parse Edk style of library modules
@@ -1024,11 +1038,19 @@ class DscParser(MetaFileParser):
if self._ValueList[0] == '' or self._ValueList[1] == '':
EdkLogger.error('Parser', FORMAT_INVALID, "No token space GUID or PCD name specified",
ExtraData=self._CurrentLine + " (<TokenSpaceGuidCName>.<TokenCName>|<PcdValue>)",
- File=self.MetaFile, Line=self._LineIndex+1)
+ File=self.MetaFile, Line=self._LineIndex + 1)
if self._ValueList[2] == '':
EdkLogger.error('Parser', FORMAT_INVALID, "No PCD value given",
ExtraData=self._CurrentLine + " (<TokenSpaceGuidCName>.<TokenCName>|<PcdValue>)",
- File=self.MetaFile, Line=self._LineIndex+1)
+ File=self.MetaFile, Line=self._LineIndex + 1)
+
+ # Validate the datum type of Dynamic Defaul PCD and DynamicEx Default PCD
+ ValueList = GetSplitValueList(self._ValueList[2])
+ if len(ValueList) > 1 and ValueList[1] != TAB_VOID \
+ and self._ItemType in [MODEL_PCD_DYNAMIC_DEFAULT, MODEL_PCD_DYNAMIC_EX_DEFAULT]:
+ EdkLogger.error('Parser', FORMAT_INVALID, "The datum type '%s' of PCD is wrong" % ValueList[1],
+ ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)
+
# if value are 'True', 'true', 'TRUE' or 'False', 'false', 'FALSE', replace with integer 1 or 0.
DscPcdValueList = GetSplitValueList(TokenList[1], TAB_VALUE_SPLIT, 1)
if DscPcdValueList[0] in ['True', 'true', 'TRUE']:
@@ -1036,6 +1058,7 @@ class DscParser(MetaFileParser):
elif DscPcdValueList[0] in ['False', 'false', 'FALSE']:
self._ValueList[2] = TokenList[1].replace(DscPcdValueList[0], '0', 1);
+
## [components] section parser
@ParseMacro
def _ComponentParser(self):
@@ -1052,15 +1075,15 @@ class DscParser(MetaFileParser):
if len(TokenList) < 2:
EdkLogger.error('Parser', FORMAT_INVALID, "No library class or instance specified",
ExtraData=self._CurrentLine + " (<LibraryClassName>|<LibraryInstancePath>)",
- File=self.MetaFile, Line=self._LineIndex+1)
+ File=self.MetaFile, Line=self._LineIndex + 1)
if TokenList[0] == '':
EdkLogger.error('Parser', FORMAT_INVALID, "No library class specified",
ExtraData=self._CurrentLine + " (<LibraryClassName>|<LibraryInstancePath>)",
- File=self.MetaFile, Line=self._LineIndex+1)
+ File=self.MetaFile, Line=self._LineIndex + 1)
if TokenList[1] == '':
EdkLogger.error('Parser', FORMAT_INVALID, "No library instance specified",
ExtraData=self._CurrentLine + " (<LibraryClassName>|<LibraryInstancePath>)",
- File=self.MetaFile, Line=self._LineIndex+1)
+ File=self.MetaFile, Line=self._LineIndex + 1)
self._ValueList[0:len(TokenList)] = TokenList
@@ -1088,7 +1111,7 @@ class DscParser(MetaFileParser):
"'%s' must be in format of <TARGET>_<TOOLCHAIN>_<ARCH>_<TOOL>_FLAGS" % self._ValueList[1],
ExtraData=self._CurrentLine,
File=self.MetaFile,
- Line=self._LineIndex+1
+ Line=self._LineIndex + 1
)
## Override parent's method since we'll do all macro replacements in parser
@@ -1192,23 +1215,23 @@ class DscParser(MetaFileParser):
" it must be defined in a [PcdsFixedAtBuild] or [PcdsFeatureFlag] section"
" of the DSC file, and it is currently defined in this section:"
" %s, line #: %d." % (Excpt.Pcd, Info[0], Info[1]),
- File=self._FileWithError, ExtraData=' '.join(self._ValueList),
- Line=self._LineIndex+1)
+ File=self._FileWithError, ExtraData=' '.join(self._ValueList),
+ Line=self._LineIndex + 1)
else:
EdkLogger.error('Parser', FORMAT_INVALID, "PCD (%s) is not defined in DSC file" % Excpt.Pcd,
- File=self._FileWithError, ExtraData=' '.join(self._ValueList),
- Line=self._LineIndex+1)
+ File=self._FileWithError, ExtraData=' '.join(self._ValueList),
+ Line=self._LineIndex + 1)
else:
EdkLogger.error('Parser', FORMAT_INVALID, "Invalid expression: %s" % str(Excpt),
- File=self._FileWithError, ExtraData=' '.join(self._ValueList),
- Line=self._LineIndex+1)
+ File=self._FileWithError, ExtraData=' '.join(self._ValueList),
+ Line=self._LineIndex + 1)
except MacroException, Excpt:
EdkLogger.error('Parser', FORMAT_INVALID, str(Excpt),
- File=self._FileWithError, ExtraData=' '.join(self._ValueList),
- Line=self._LineIndex+1)
+ File=self._FileWithError, ExtraData=' '.join(self._ValueList),
+ Line=self._LineIndex + 1)
if self._ValueList == None:
- continue
+ continue
NewOwner = self._IdMapping.get(Owner, -1)
self._Enabled = int((not self._DirectiveEvalStack) or (False not in self._DirectiveEvalStack))
@@ -1221,10 +1244,10 @@ class DscParser(MetaFileParser):
S2,
NewOwner,
self._From,
- self._LineIndex+1,
- -1,
- self._LineIndex+1,
- -1,
+ self._LineIndex + 1,
+ - 1,
+ self._LineIndex + 1,
+ - 1,
self._Enabled
)
self._IdMapping[Id] = self._LastItem
@@ -1248,25 +1271,25 @@ class DscParser(MetaFileParser):
self._SubsectionType = MODEL_UNKNOWN
def __RetrievePcdValue(self):
- Records = self._RawTable.Query(MODEL_PCD_FEATURE_FLAG, BelongsToItem=-1.0)
- for TokenSpaceGuid,PcdName,Value,Dummy2,Dummy3,ID,Line in Records:
- Value, DatumType, MaxDatumSize = AnalyzePcdData(Value)
+ Records = self._RawTable.Query(MODEL_PCD_FEATURE_FLAG, BelongsToItem= -1.0)
+ for TokenSpaceGuid, PcdName, Value, Dummy2, Dummy3, ID, Line in Records:
Name = TokenSpaceGuid + '.' + PcdName
- self._Symbols[Name] = Value
+ ValList, Valid, Index = AnalyzeDscPcd(Value, MODEL_PCD_FEATURE_FLAG)
+ self._Symbols[Name] = ValList[Index]
- Records = self._RawTable.Query(MODEL_PCD_FIXED_AT_BUILD, BelongsToItem=-1.0)
- for TokenSpaceGuid,PcdName,Value,Dummy2,Dummy3,ID,Line in Records:
- Value, DatumType, MaxDatumSize = AnalyzePcdData(Value)
+ Records = self._RawTable.Query(MODEL_PCD_FIXED_AT_BUILD, BelongsToItem= -1.0)
+ for TokenSpaceGuid, PcdName, Value, Dummy2, Dummy3, ID, Line in Records:
Name = TokenSpaceGuid + '.' + PcdName
- self._Symbols[Name] = Value
+ ValList, Valid, Index = AnalyzeDscPcd(Value, MODEL_PCD_FIXED_AT_BUILD)
+ self._Symbols[Name] = ValList[Index]
Content = open(str(self.MetaFile), 'r').readlines()
GlobalData.gPlatformOtherPcds['DSCFILE'] = str(self.MetaFile)
for PcdType in (MODEL_PCD_PATCHABLE_IN_MODULE, MODEL_PCD_DYNAMIC_DEFAULT, MODEL_PCD_DYNAMIC_HII,
MODEL_PCD_DYNAMIC_VPD, MODEL_PCD_DYNAMIC_EX_DEFAULT, MODEL_PCD_DYNAMIC_EX_HII,
MODEL_PCD_DYNAMIC_EX_VPD):
- Records = self._RawTable.Query(PcdType, BelongsToItem=-1.0)
- for TokenSpaceGuid,PcdName,Value,Dummy2,Dummy3,ID,Line in Records:
+ Records = self._RawTable.Query(PcdType, BelongsToItem= -1.0)
+ for TokenSpaceGuid, PcdName, Value, Dummy2, Dummy3, ID, Line in Records:
Name = TokenSpaceGuid + '.' + PcdName
if Name not in GlobalData.gPlatformOtherPcds:
PcdLine = Line
@@ -1287,13 +1310,13 @@ class DscParser(MetaFileParser):
self._ConstructSectionMacroDict(Name, Value)
elif self._ItemType == MODEL_META_DATA_GLOBAL_DEFINE:
GlobalData.gEdkGlobal[Name] = Value
-
+
#
# Keyword in [Defines] section can be used as Macros
#
if (self._ItemType == MODEL_META_DATA_HEADER) and (self._SectionType == MODEL_META_DATA_HEADER):
self._FileLocalMacros[Name] = Value
-
+
self._ValueList = [Type, Name, Value]
def __ProcessDirective(self):
@@ -1313,8 +1336,8 @@ class DscParser(MetaFileParser):
# the precise number of line and return the evaluation result
#
EdkLogger.warn('Parser', "Suspicious expression: %s" % str(Excpt),
- File=self._FileWithError, ExtraData=' '.join(self._ValueList),
- Line=self._LineIndex+1)
+ File=self._FileWithError, ExtraData=' '.join(self._ValueList),
+ Line=self._LineIndex + 1)
Result = Excpt.result
if self._ItemType in [MODEL_META_DATA_CONDITIONAL_STATEMENT_IF,
@@ -1368,7 +1391,7 @@ class DscParser(MetaFileParser):
# Allow using MACROs comes from [Defines] section to keep compatible.
#
__IncludeMacros.update(self._Macros)
-
+
IncludedFile = NormPath(ReplaceMacro(self._ValueList[1], __IncludeMacros, RaiseError=True))
#
# First search the include file under the same directory as DSC file
@@ -1382,14 +1405,14 @@ class DscParser(MetaFileParser):
IncludedFile1 = PathClass(IncludedFile, GlobalData.gWorkspace)
ErrorCode, ErrorInfo2 = IncludedFile1.Validate()
if ErrorCode != 0:
- EdkLogger.error('parser', ErrorCode, File=self._FileWithError,
- Line=self._LineIndex+1, ExtraData=ErrorInfo1 + "\n"+ ErrorInfo2)
+ EdkLogger.error('parser', ErrorCode, File=self._FileWithError,
+ Line=self._LineIndex + 1, ExtraData=ErrorInfo1 + "\n" + ErrorInfo2)
self._FileWithError = IncludedFile1
IncludedFileTable = MetaFileStorage(self._Table.Cur, IncludedFile1, MODEL_FILE_DSC, False)
- Owner = self._Content[self._ContentIndex-1][0]
- Parser = DscParser(IncludedFile1, self._FileType, IncludedFileTable,
+ Owner = self._Content[self._ContentIndex - 1][0]
+ Parser = DscParser(IncludedFile1, self._FileType, IncludedFileTable,
Owner=Owner, From=Owner)
# set the parser status with current status
@@ -1403,17 +1426,17 @@ class DscParser(MetaFileParser):
# update current status with sub-parser's status
self._SectionName = Parser._SectionName
self._SectionType = Parser._SectionType
- self._Scope = Parser._Scope
- self._Enabled = Parser._Enabled
+ self._Scope = Parser._Scope
+ self._Enabled = Parser._Enabled
# Insert all records in the table for the included file into dsc file table
Records = IncludedFileTable.GetAll()
if Records:
self._Content[self._ContentIndex:self._ContentIndex] = Records
- self._Content.pop(self._ContentIndex-1)
+ self._Content.pop(self._ContentIndex - 1)
self._ValueList = None
self._ContentIndex -= 1
-
+
def __ProcessSkuId(self):
self._ValueList = [ReplaceMacro(Value, self._Macros, RaiseError=True)
for Value in self._ValueList]
@@ -1425,48 +1448,28 @@ class DscParser(MetaFileParser):
self._ValueList[1] = ReplaceMacro(self._ValueList[1], self._Macros, RaiseError=True)
def __ProcessPcd(self):
- PcdValue = None
- ValueList = GetSplitValueList(self._ValueList[2])
- #
- # PCD value can be an expression
- #
- if len(ValueList) > 1 and ValueList[1] == 'VOID*':
- PcdValue = ValueList[0]
+ if self._ItemType not in [MODEL_PCD_FEATURE_FLAG, MODEL_PCD_FIXED_AT_BUILD]:
+ self._ValueList[2] = ReplaceMacro(self._ValueList[2], self._Macros, RaiseError=True)
+ return
+
+ ValList, Valid, Index = AnalyzeDscPcd(self._ValueList[2], self._ItemType)
+ if not Valid:
+ EdkLogger.error('build', FORMAT_INVALID, "Pcd format incorrect.", File=self._FileWithError, Line=self._LineIndex+1,
+ ExtraData="%s.%s|%s" % (self._ValueList[0], self._ValueList[1], self._ValueList[2]))
+ PcdValue = ValList[Index]
+ if PcdValue:
try:
- ValueList[0] = ValueExpression(PcdValue, self._Macros)(True)
+ ValList[Index] = ValueExpression(PcdValue, self._Macros)(True)
except WrnExpression, Value:
- ValueList[0] = Value.result
- PcdValue = ValueList[0]
- else:
- #
- # Int*/Boolean VPD PCD
- # TokenSpace | PcdCName | Offset | [Value]
- #
- # VOID* VPD PCD
- # TokenSpace | PcdCName | Offset | [Size] | [Value]
- #
- if self._ItemType == MODEL_PCD_DYNAMIC_VPD:
- if len(ValueList) >= 4:
- PcdValue = ValueList[-1]
- else:
- PcdValue = ValueList[-1]
- #
- # For the VPD PCD, there may not have PcdValue data in DSC file
- #
- if PcdValue:
- try:
- ValueList[-1] = ValueExpression(PcdValue, self._Macros)(True)
- except WrnExpression, Value:
- ValueList[-1] = Value.result
-
- if ValueList[-1] == 'True':
- ValueList[-1] = '1'
- if ValueList[-1] == 'False':
- ValueList[-1] = '0'
- PcdValue = ValueList[-1]
- if PcdValue and self._ItemType in [MODEL_PCD_FEATURE_FLAG, MODEL_PCD_FIXED_AT_BUILD]:
- GlobalData.gPlatformPcds[TAB_SPLIT.join(self._ValueList[0:2])] = PcdValue
- self._ValueList[2] = '|'.join(ValueList)
+ ValList[Index] = Value.result
+
+ if ValList[Index] == 'True':
+ ValList[Index] = '1'
+ if ValList[Index] == 'False':
+ ValList[Index] = '0'
+
+ GlobalData.gPlatformPcds[TAB_SPLIT.join(self._ValueList[0:2])] = PcdValue
+ self._ValueList[2] = '|'.join(ValList)
def __ProcessComponent(self):
self._ValueList[0] = ReplaceMacro(self._ValueList[0], self._Macros)
@@ -1501,7 +1504,7 @@ class DscParser(MetaFileParser):
MODEL_META_DATA_SUBSECTION_HEADER : _SubsectionHeaderParser,
}
- _Macros = property(_GetMacros)
+ _Macros = property(_GetMacros)
## DEC file parser class
#
@@ -1543,6 +1546,7 @@ class DecParser(MetaFileParser):
MetaFileParser.__init__(self, FilePath, FileType, Table, -1)
self._Comments = []
self._Version = 0x00010005 # Only EDK2 dec file is supported
+ self._AllPCDs = [] # Only for check duplicate PCD
## Parser starter
def Start(self):
@@ -1559,7 +1563,7 @@ class DecParser(MetaFileParser):
# save comment for later use
if Comment:
- self._Comments.append((Comment, self._LineIndex+1))
+ self._Comments.append((Comment, self._LineIndex + 1))
# skip empty line
if Line == '':
continue
@@ -1574,7 +1578,7 @@ class DecParser(MetaFileParser):
continue
# section content
- self._ValueList = ['','','']
+ self._ValueList = ['', '', '']
self._SectionParser[self._SectionType[0]](self)
if self._ValueList == None or self._ItemType == MODEL_META_DATA_DEFINE:
self._ItemType = -1
@@ -1594,10 +1598,10 @@ class DecParser(MetaFileParser):
Arch,
ModuleType,
self._Owner[-1],
- self._LineIndex+1,
- -1,
- self._LineIndex+1,
- -1,
+ self._LineIndex + 1,
+ - 1,
+ self._LineIndex + 1,
+ - 1,
0
)
for Comment, LineNo in self._Comments:
@@ -1610,9 +1614,9 @@ class DecParser(MetaFileParser):
ModuleType,
self._LastItem,
LineNo,
- -1,
+ - 1,
LineNo,
- -1,
+ - 1,
0
)
self._Comments = []
@@ -1630,10 +1634,13 @@ class DecParser(MetaFileParser):
self._SectionName = ''
self._SectionType = []
ArchList = set()
- for Item in GetSplitValueList(self._CurrentLine[1:-1], TAB_COMMA_SPLIT):
+ Line = self._CurrentLine.replace("%s%s" % (TAB_COMMA_SPLIT, TAB_SPACE_SPLIT), TAB_COMMA_SPLIT)
+ for Item in Line[1:-1].split(TAB_COMMA_SPLIT):
if Item == '':
- continue
- ItemList = GetSplitValueList(Item, TAB_SPLIT)
+ EdkLogger.error("Parser", FORMAT_UNKNOWN_ERROR,
+ "section name can NOT be empty or incorrectly use separator comma",
+ self.MetaFile, self._LineIndex + 1, self._CurrentLine)
+ ItemList = Item.split(TAB_SPLIT)
# different types of PCD are permissible in one section
self._SectionName = ItemList[0].upper()
@@ -1641,9 +1648,8 @@ class DecParser(MetaFileParser):
if self.DataType[self._SectionName] not in self._SectionType:
self._SectionType.append(self.DataType[self._SectionName])
else:
- EdkLogger.warn("Parser", "Unrecognized section", File=self.MetaFile,
- Line=self._LineIndex+1, ExtraData=self._CurrentLine)
- continue
+ EdkLogger.error("Parser", FORMAT_UNKNOWN_ERROR, "%s is not a valid section name" % Item,
+ self.MetaFile, self._LineIndex + 1, self._CurrentLine)
if MODEL_PCD_FEATURE_FLAG in self._SectionType and len(self._SectionType) > 1:
EdkLogger.error(
@@ -1651,7 +1657,7 @@ class DecParser(MetaFileParser):
FORMAT_INVALID,
"%s must not be in the same section of other types of PCD" % TAB_PCDS_FEATURE_FLAG_NULL,
File=self.MetaFile,
- Line=self._LineIndex+1,
+ Line=self._LineIndex + 1,
ExtraData=self._CurrentLine
)
# S1 is always Arch
@@ -1671,7 +1677,7 @@ class DecParser(MetaFileParser):
# 'COMMON' must not be used with specific ARCHs at the same section
if 'COMMON' in ArchList and len(ArchList) > 1:
EdkLogger.error('Parser', FORMAT_INVALID, "'common' ARCH must not be used with specific ARCHs",
- File=self.MetaFile, Line=self._LineIndex+1, ExtraData=self._CurrentLine)
+ File=self.MetaFile, Line=self._LineIndex + 1, ExtraData=self._CurrentLine)
## [guids], [ppis] and [protocols] section parser
@ParseMacro
@@ -1680,20 +1686,20 @@ class DecParser(MetaFileParser):
if len(TokenList) < 2:
EdkLogger.error('Parser', FORMAT_INVALID, "No GUID name or value specified",
ExtraData=self._CurrentLine + " (<CName> = <GuidValueInCFormat>)",
- File=self.MetaFile, Line=self._LineIndex+1)
+ File=self.MetaFile, Line=self._LineIndex + 1)
if TokenList[0] == '':
EdkLogger.error('Parser', FORMAT_INVALID, "No GUID name specified",
ExtraData=self._CurrentLine + " (<CName> = <GuidValueInCFormat>)",
- File=self.MetaFile, Line=self._LineIndex+1)
+ File=self.MetaFile, Line=self._LineIndex + 1)
if TokenList[1] == '':
EdkLogger.error('Parser', FORMAT_INVALID, "No GUID value specified",
ExtraData=self._CurrentLine + " (<CName> = <GuidValueInCFormat>)",
- File=self.MetaFile, Line=self._LineIndex+1)
+ File=self.MetaFile, Line=self._LineIndex + 1)
if TokenList[1][0] != '{' or TokenList[1][-1] != '}' or GuidStructureStringToGuidString(TokenList[1]) == '':
EdkLogger.error('Parser', FORMAT_INVALID, "Invalid GUID value format",
ExtraData=self._CurrentLine + \
" (<CName> = <GuidValueInCFormat:{8,4,4,{2,2,2,2,2,2,2,2}}>)",
- File=self.MetaFile, Line=self._LineIndex+1)
+ File=self.MetaFile, Line=self._LineIndex + 1)
self._ValueList[0] = TokenList[0]
self._ValueList[1] = TokenList[1]
@@ -1709,67 +1715,88 @@ class DecParser(MetaFileParser):
def _PcdParser(self):
TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT, 1)
self._ValueList[0:1] = GetSplitValueList(TokenList[0], TAB_SPLIT)
+ ValueRe = re.compile(r'^[a-zA-Z_][a-zA-Z0-9_]*')
# check PCD information
if self._ValueList[0] == '' or self._ValueList[1] == '':
EdkLogger.error('Parser', FORMAT_INVALID, "No token space GUID or PCD name specified",
ExtraData=self._CurrentLine + \
" (<TokenSpaceGuidCName>.<PcdCName>|<DefaultValue>|<DatumType>|<Token>)",
- File=self.MetaFile, Line=self._LineIndex+1)
+ File=self.MetaFile, Line=self._LineIndex + 1)
+ # check format of token space GUID CName
+ if not ValueRe.match(self._ValueList[0]):
+ 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_]*'",
+ ExtraData=self._CurrentLine + \
+ " (<TokenSpaceGuidCName>.<PcdCName>|<DefaultValue>|<DatumType>|<Token>)",
+ File=self.MetaFile, Line=self._LineIndex + 1)
+ # check format of PCD CName
+ if not ValueRe.match(self._ValueList[1]):
+ EdkLogger.error('Parser', FORMAT_INVALID, "The format of the PCD CName is invalid. The correct format is '(a-zA-Z_)[a-zA-Z0-9_]*'",
+ ExtraData=self._CurrentLine + \
+ " (<TokenSpaceGuidCName>.<PcdCName>|<DefaultValue>|<DatumType>|<Token>)",
+ File=self.MetaFile, Line=self._LineIndex + 1)
# check PCD datum information
if len(TokenList) < 2 or TokenList[1] == '':
EdkLogger.error('Parser', FORMAT_INVALID, "No PCD Datum information given",
ExtraData=self._CurrentLine + \
" (<TokenSpaceGuidCName>.<PcdCName>|<DefaultValue>|<DatumType>|<Token>)",
- File=self.MetaFile, Line=self._LineIndex+1)
+ File=self.MetaFile, Line=self._LineIndex + 1)
+
-
- ValueRe = re.compile(r'^\s*L?\".*\|.*\"')
+ ValueRe = re.compile(r'^\s*L?\".*\|.*\"')
PtrValue = ValueRe.findall(TokenList[1])
-
+
# Has VOID* type string, may contain "|" character in the string.
if len(PtrValue) != 0:
ptrValueList = re.sub(ValueRe, '', TokenList[1])
- ValueList = GetSplitValueList(ptrValueList)
+ ValueList = GetSplitValueList(ptrValueList)
ValueList[0] = PtrValue[0]
else:
ValueList = GetSplitValueList(TokenList[1])
-
-
+
+
# check if there's enough datum information given
if len(ValueList) != 3:
EdkLogger.error('Parser', FORMAT_INVALID, "Invalid PCD Datum information given",
ExtraData=self._CurrentLine + \
" (<TokenSpaceGuidCName>.<PcdCName>|<DefaultValue>|<DatumType>|<Token>)",
- File=self.MetaFile, Line=self._LineIndex+1)
+ File=self.MetaFile, Line=self._LineIndex + 1)
# check default value
if ValueList[0] == '':
EdkLogger.error('Parser', FORMAT_INVALID, "Missing DefaultValue in PCD Datum information",
ExtraData=self._CurrentLine + \
" (<TokenSpaceGuidCName>.<PcdCName>|<DefaultValue>|<DatumType>|<Token>)",
- File=self.MetaFile, Line=self._LineIndex+1)
+ File=self.MetaFile, Line=self._LineIndex + 1)
# check datum type
if ValueList[1] == '':
EdkLogger.error('Parser', FORMAT_INVALID, "Missing DatumType in PCD Datum information",
ExtraData=self._CurrentLine + \
" (<TokenSpaceGuidCName>.<PcdCName>|<DefaultValue>|<DatumType>|<Token>)",
- File=self.MetaFile, Line=self._LineIndex+1)
+ File=self.MetaFile, Line=self._LineIndex + 1)
# check token of the PCD
if ValueList[2] == '':
EdkLogger.error('Parser', FORMAT_INVALID, "Missing Token in PCD Datum information",
ExtraData=self._CurrentLine + \
" (<TokenSpaceGuidCName>.<PcdCName>|<DefaultValue>|<DatumType>|<Token>)",
- File=self.MetaFile, Line=self._LineIndex+1)
+ File=self.MetaFile, Line=self._LineIndex + 1)
# check format of default value against the datum type
IsValid, Cause = CheckPcdDatum(ValueList[1], ValueList[0])
if not IsValid:
EdkLogger.error('Parser', FORMAT_INVALID, Cause, ExtraData=self._CurrentLine,
- File=self.MetaFile, Line=self._LineIndex+1)
+ File=self.MetaFile, Line=self._LineIndex + 1)
if ValueList[0] in ['True', 'true', 'TRUE']:
ValueList[0] = '1'
elif ValueList[0] in ['False', 'false', 'FALSE']:
ValueList[0] = '0'
+ # check for duplicate PCD definition
+ if (self._Scope[0], self._ValueList[0], self._ValueList[1]) in self._AllPCDs:
+ EdkLogger.error('Parser', FORMAT_INVALID,
+ "The same PCD name and GUID have been already defined",
+ ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)
+ else:
+ self._AllPCDs.append((self._Scope[0], self._ValueList[0], self._ValueList[1]))
+
self._ValueList[2] = ValueList[0].strip() + '|' + ValueList[1].strip() + '|' + ValueList[2].strip()
_SectionParser = {
diff --git a/BaseTools/Source/Python/Workspace/WorkspaceCommon.py b/BaseTools/Source/Python/Workspace/WorkspaceCommon.py
new file mode 100644
index 0000000000..60acc914e9
--- /dev/null
+++ b/BaseTools/Source/Python/Workspace/WorkspaceCommon.py
@@ -0,0 +1,237 @@
+## @file
+# Common routines used by workspace
+#
+# Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+
+from Common.Misc import sdict
+from Common.DataType import SUP_MODULE_USER_DEFINED
+from BuildClassObject import LibraryClassObject
+
+## Get all packages from platform for specified arch, target and toolchain
+#
+# @param Platform: DscBuildData instance
+# @param BuildDatabase: The database saves all data for all metafiles
+# @param Arch: Current arch
+# @param Target: Current target
+# @param Toolchain: Current toolchain
+# @retval: List of packages which are DecBuildData instances
+#
+def GetPackageList(Platform, BuildDatabase, Arch, Target, Toolchain):
+ PkgSet = set()
+ for ModuleFile in Platform.Modules:
+ Data = BuildDatabase[ModuleFile, Arch, Target, Toolchain]
+ PkgSet.update(Data.Packages)
+ for Lib in GetLiabraryInstances(Data, Platform, BuildDatabase, Arch, Target, Toolchain):
+ PkgSet.update(Lib.Packages)
+ return list(PkgSet)
+
+## Get all declared PCD from platform for specified arch, target and toolchain
+#
+# @param Platform: DscBuildData instance
+# @param BuildDatabase: The database saves all data for all metafiles
+# @param Arch: Current arch
+# @param Target: Current target
+# @param Toolchain: Current toolchain
+# @retval: A dictionary contains instances of PcdClassObject with key (PcdCName, TokenSpaceGuid)
+#
+def GetDeclaredPcd(Platform, BuildDatabase, Arch, Target, Toolchain):
+ PkgList = GetPackageList(Platform, BuildDatabase, Arch, Target, Toolchain)
+ DecPcds = {}
+ for Pkg in PkgList:
+ for Pcd in Pkg.Pcds:
+ DecPcds[Pcd[0], Pcd[1]] = Pkg.Pcds[Pcd]
+ return DecPcds
+
+## Get all dependent libraries for a module
+#
+# @param Module: InfBuildData instance
+# @param Platform: DscBuildData instance
+# @param BuildDatabase: The database saves all data for all metafiles
+# @param Arch: Current arch
+# @param Target: Current target
+# @param Toolchain: Current toolchain
+# @retval: List of dependent libraries which are InfBuildData instances
+#
+def GetLiabraryInstances(Module, Platform, BuildDatabase, Arch, Target, Toolchain):
+ if Module.AutoGenVersion >= 0x00010005:
+ return _GetModuleLibraryInstances(Module, Platform, BuildDatabase, Arch, Target, Toolchain)
+ else:
+ return _ResolveLibraryReference(Module, Platform)
+
+def _GetModuleLibraryInstances(Module, Platform, BuildDatabase, Arch, Target, Toolchain):
+ ModuleType = Module.ModuleType
+
+ # for overriding library instances with module specific setting
+ PlatformModule = Platform.Modules[str(Module)]
+
+ # add forced library instances (specified under LibraryClasses sections)
+ #
+ # If a module has a MODULE_TYPE of USER_DEFINED,
+ # do not link in NULL library class instances from the global [LibraryClasses.*] sections.
+ #
+ if Module.ModuleType != SUP_MODULE_USER_DEFINED:
+ for LibraryClass in Platform.LibraryClasses.GetKeys():
+ if LibraryClass.startswith("NULL") and Platform.LibraryClasses[LibraryClass, Module.ModuleType]:
+ Module.LibraryClasses[LibraryClass] = Platform.LibraryClasses[LibraryClass, Module.ModuleType]
+
+ # add forced library instances (specified in module overrides)
+ for LibraryClass in PlatformModule.LibraryClasses:
+ if LibraryClass.startswith("NULL"):
+ Module.LibraryClasses[LibraryClass] = PlatformModule.LibraryClasses[LibraryClass]
+
+ # EdkII module
+ LibraryConsumerList = [Module]
+ Constructor = []
+ ConsumedByList = sdict()
+ LibraryInstance = sdict()
+
+ while len(LibraryConsumerList) > 0:
+ M = LibraryConsumerList.pop()
+ for LibraryClassName in M.LibraryClasses:
+ if LibraryClassName not in LibraryInstance:
+ # override library instance for this module
+ if LibraryClassName in PlatformModule.LibraryClasses:
+ LibraryPath = PlatformModule.LibraryClasses[LibraryClassName]
+ else:
+ LibraryPath = Platform.LibraryClasses[LibraryClassName, ModuleType]
+ if LibraryPath == None or LibraryPath == "":
+ LibraryPath = M.LibraryClasses[LibraryClassName]
+ if LibraryPath == None or LibraryPath == "":
+ return []
+
+ LibraryModule = BuildDatabase[LibraryPath, Arch, Target, Toolchain]
+ # for those forced library instance (NULL library), add a fake library class
+ if LibraryClassName.startswith("NULL"):
+ LibraryModule.LibraryClass.append(LibraryClassObject(LibraryClassName, [ModuleType]))
+ elif LibraryModule.LibraryClass == None \
+ or len(LibraryModule.LibraryClass) == 0 \
+ or (ModuleType != 'USER_DEFINED'
+ and ModuleType not in LibraryModule.LibraryClass[0].SupModList):
+ # only USER_DEFINED can link against any library instance despite of its SupModList
+ return []
+
+ LibraryInstance[LibraryClassName] = LibraryModule
+ LibraryConsumerList.append(LibraryModule)
+ else:
+ LibraryModule = LibraryInstance[LibraryClassName]
+
+ if LibraryModule == None:
+ continue
+
+ if LibraryModule.ConstructorList != [] and LibraryModule not in Constructor:
+ Constructor.append(LibraryModule)
+
+ if LibraryModule not in ConsumedByList:
+ ConsumedByList[LibraryModule] = []
+ # don't add current module itself to consumer list
+ if M != Module:
+ if M in ConsumedByList[LibraryModule]:
+ continue
+ ConsumedByList[LibraryModule].append(M)
+ #
+ # Initialize the sorted output list to the empty set
+ #
+ SortedLibraryList = []
+ #
+ # Q <- Set of all nodes with no incoming edges
+ #
+ LibraryList = [] #LibraryInstance.values()
+ Q = []
+ for LibraryClassName in LibraryInstance:
+ M = LibraryInstance[LibraryClassName]
+ LibraryList.append(M)
+ if ConsumedByList[M] == []:
+ Q.append(M)
+
+ #
+ # start the DAG algorithm
+ #
+ while True:
+ EdgeRemoved = True
+ while Q == [] and EdgeRemoved:
+ EdgeRemoved = False
+ # for each node Item with a Constructor
+ for Item in LibraryList:
+ if Item not in Constructor:
+ continue
+ # for each Node without a constructor with an edge e from Item to Node
+ for Node in ConsumedByList[Item]:
+ if Node in Constructor:
+ continue
+ # remove edge e from the graph if Node has no constructor
+ ConsumedByList[Item].remove(Node)
+ EdgeRemoved = True
+ if ConsumedByList[Item] == []:
+ # insert Item into Q
+ Q.insert(0, Item)
+ break
+ if Q != []:
+ break
+ # DAG is done if there's no more incoming edge for all nodes
+ if Q == []:
+ break
+
+ # remove node from Q
+ Node = Q.pop()
+ # output Node
+ SortedLibraryList.append(Node)
+
+ # for each node Item with an edge e from Node to Item do
+ for Item in LibraryList:
+ if Node not in ConsumedByList[Item]:
+ continue
+ # remove edge e from the graph
+ ConsumedByList[Item].remove(Node)
+
+ if ConsumedByList[Item] != []:
+ continue
+ # insert Item into Q, if Item has no other incoming edges
+ Q.insert(0, Item)
+
+ #
+ # if any remaining node Item in the graph has a constructor and an incoming edge, then the graph has a cycle
+ #
+ for Item in LibraryList:
+ if ConsumedByList[Item] != [] and Item in Constructor and len(Constructor) > 1:
+ return []
+ if Item not in SortedLibraryList:
+ SortedLibraryList.append(Item)
+
+ #
+ # Build the list of constructor and destructir names
+ # The DAG Topo sort produces the destructor order, so the list of constructors must generated in the reverse order
+ #
+ SortedLibraryList.reverse()
+ return SortedLibraryList
+
+def _ResolveLibraryReference(Module, Platform):
+ LibraryConsumerList = [Module]
+
+ # "CompilerStub" is a must for Edk modules
+ if Module.Libraries:
+ Module.Libraries.append("CompilerStub")
+ LibraryList = []
+ while len(LibraryConsumerList) > 0:
+ M = LibraryConsumerList.pop()
+ for LibraryName in M.Libraries:
+ Library = Platform.LibraryClasses[LibraryName, ':dummy:']
+ if Library == None:
+ for Key in Platform.LibraryClasses.data.keys():
+ if LibraryName.upper() == Key.upper():
+ Library = Platform.LibraryClasses[Key, ':dummy:']
+ break
+ if Library == None:
+ continue
+
+ if Library not in LibraryList:
+ LibraryList.append(Library)
+ LibraryConsumerList.append(Library)
+ return LibraryList
diff --git a/BaseTools/Source/Python/Workspace/WorkspaceDatabase.py b/BaseTools/Source/Python/Workspace/WorkspaceDatabase.py
index e5fb41a8e0..19c00ca78d 100644
--- a/BaseTools/Source/Python/Workspace/WorkspaceDatabase.py
+++ b/BaseTools/Source/Python/Workspace/WorkspaceDatabase.py
@@ -34,6 +34,8 @@ from MetaDataTable import *
from MetaFileTable import *
from MetaFileParser import *
from BuildClassObject import *
+from WorkspaceCommon import GetDeclaredPcd
+from Common.Misc import AnalyzeDscPcd
## Platform build information from DSC file
#
@@ -134,6 +136,7 @@ class DscBuildData(PlatformBuildClassObject):
self._LibraryInstances = None
self._LibraryClasses = None
self._Pcds = None
+ self._DecPcds = None
self._BuildOptions = None
self._LoadFixAddress = None
self._RFCLanguages = None
@@ -613,6 +616,46 @@ class DscBuildData(PlatformBuildClassObject):
self._LibraryClasses[Library.BaseName, ':dummy:'] = Library
return self._LibraryClasses
+ def _ValidatePcd(self, PcdCName, TokenSpaceGuid, Setting, PcdType, LineNo):
+ if self._DecPcds == None:
+ self._DecPcds = GetDeclaredPcd(self, self._Bdb, self._Arch, self._Target, self._Toolchain)
+ if (PcdCName, TokenSpaceGuid) not in self._DecPcds:
+ EdkLogger.error('build', PARSER_ERROR,
+ "Pcd (%s.%s) defined in DSC is not declared in DEC files." % (TokenSpaceGuid, PcdCName),
+ File=self.MetaFile, Line=LineNo)
+ ValueList, IsValid, Index = AnalyzeDscPcd(Setting, PcdType, self._DecPcds[PcdCName, TokenSpaceGuid].DatumType)
+ if not IsValid and PcdType not in [MODEL_PCD_FEATURE_FLAG, MODEL_PCD_FIXED_AT_BUILD]:
+ EdkLogger.error('build', FORMAT_INVALID, "Pcd format incorrect.", File=self.MetaFile, Line=LineNo,
+ ExtraData="%s.%s|%s" % (TokenSpaceGuid, PcdCName, Setting))
+ if ValueList[Index] and PcdType not in [MODEL_PCD_FEATURE_FLAG, MODEL_PCD_FIXED_AT_BUILD]:
+ try:
+ ValueList[Index] = ValueExpression(ValueList[Index], GlobalData.gPlatformPcds)(True)
+ except WrnExpression, Value:
+ ValueList[Index] = Value.result
+ except EvaluationException, Excpt:
+ if hasattr(Excpt, 'Pcd'):
+ if Excpt.Pcd in GlobalData.gPlatformOtherPcds:
+ EdkLogger.error('Parser', FORMAT_INVALID, "Cannot use this PCD (%s) in an expression as"
+ " it must be defined in a [PcdsFixedAtBuild] or [PcdsFeatureFlag] section"
+ " of the DSC file" % Excpt.Pcd,
+ File=self.MetaFile, Line=LineNo)
+ else:
+ EdkLogger.error('Parser', FORMAT_INVALID, "PCD (%s) is not defined in DSC file" % Excpt.Pcd,
+ File=self.MetaFile, Line=LineNo)
+ else:
+ EdkLogger.error('Parser', FORMAT_INVALID, "Invalid expression: %s" % str(Excpt),
+ File=self.MetaFile, Line=LineNo)
+ if ValueList[Index] == 'True':
+ ValueList[Index] = '1'
+ elif ValueList[Index] == 'False':
+ ValueList[Index] = '0'
+ if ValueList[Index]:
+ Valid, ErrStr = CheckPcdDatum(self._DecPcds[PcdCName, TokenSpaceGuid].DatumType, ValueList[Index])
+ if not Valid:
+ EdkLogger.error('build', FORMAT_INVALID, ErrStr, File=self.MetaFile, Line=LineNo,
+ ExtraData="%s.%s" % (TokenSpaceGuid, PcdCName))
+ return ValueList
+
## Retrieve all PCD settings in platform
def _GetPcds(self):
if self._Pcds == None:
@@ -663,14 +706,14 @@ class DscBuildData(PlatformBuildClassObject):
# Find out all possible PCD candidates for self._Arch
RecordList = self._RawData[Type, self._Arch]
for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, Dummy3, Dummy4 in RecordList:
- PcdSet.add((PcdCName, TokenSpaceGuid))
+ PcdSet.add((PcdCName, TokenSpaceGuid, Dummy4))
PcdDict[Arch, PcdCName, TokenSpaceGuid] = Setting
# Remove redundant PCD candidates
- for PcdCName, TokenSpaceGuid in PcdSet:
+ for PcdCName, TokenSpaceGuid, Dummy4 in PcdSet:
Setting = PcdDict[self._Arch, PcdCName, TokenSpaceGuid]
if Setting == None:
continue
- PcdValue, DatumType, MaxDatumSize = AnalyzePcdData(Setting)
+ PcdValue, DatumType, MaxDatumSize = self._ValidatePcd(PcdCName, TokenSpaceGuid, Setting, Type, Dummy4)
Pcds[PcdCName, TokenSpaceGuid] = PcdClassObject(
PcdCName,
TokenSpaceGuid,
@@ -702,15 +745,15 @@ class DscBuildData(PlatformBuildClassObject):
# Find out all possible PCD candidates for self._Arch
RecordList = self._RawData[Type, self._Arch]
for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, Dummy3, Dummy4 in RecordList:
- PcdList.append((PcdCName, TokenSpaceGuid))
+ PcdList.append((PcdCName, TokenSpaceGuid, Dummy4))
PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid] = Setting
# Remove redundant PCD candidates, per the ARCH and SKU
- for PcdCName, TokenSpaceGuid in PcdList:
+ for PcdCName, TokenSpaceGuid, Dummy4 in PcdList:
Setting = PcdDict[self._Arch, self.SkuName, PcdCName, TokenSpaceGuid]
if Setting == None:
continue
- PcdValue, DatumType, MaxDatumSize = AnalyzePcdData(Setting)
+ PcdValue, DatumType, MaxDatumSize = self._ValidatePcd(PcdCName, TokenSpaceGuid, Setting, Type, Dummy4)
SkuInfo = SkuInfoClass(self.SkuName, self.SkuIds[self.SkuName], '', '', '', '', '', PcdValue)
Pcds[PcdCName, TokenSpaceGuid] = PcdClassObject(
@@ -744,14 +787,14 @@ class DscBuildData(PlatformBuildClassObject):
RecordList = self._RawData[Type, self._Arch]
# Find out all possible PCD candidates for self._Arch
for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, Dummy3, Dummy4 in RecordList:
- PcdSet.add((PcdCName, TokenSpaceGuid))
+ PcdSet.add((PcdCName, TokenSpaceGuid, Dummy4))
PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid] = Setting
# Remove redundant PCD candidates, per the ARCH and SKU
- for PcdCName, TokenSpaceGuid in PcdSet:
+ for PcdCName, TokenSpaceGuid, Dummy4 in PcdSet:
Setting = PcdDict[self._Arch, self.SkuName, PcdCName, TokenSpaceGuid]
if Setting == None:
continue
- VariableName, VariableGuid, VariableOffset, DefaultValue = AnalyzeHiiPcdData(Setting)
+ VariableName, VariableGuid, VariableOffset, DefaultValue = self._ValidatePcd(PcdCName, TokenSpaceGuid, Setting, Type, Dummy4)
SkuInfo = SkuInfoClass(self.SkuName, self.SkuIds[self.SkuName], VariableName, VariableGuid, VariableOffset, DefaultValue)
Pcds[PcdCName, TokenSpaceGuid] = PcdClassObject(
PcdCName,
@@ -784,10 +827,10 @@ class DscBuildData(PlatformBuildClassObject):
# Find out all possible PCD candidates for self._Arch
RecordList = self._RawData[Type, self._Arch]
for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, Dummy3, Dummy4 in RecordList:
- PcdList.append((PcdCName, TokenSpaceGuid))
+ PcdList.append((PcdCName, TokenSpaceGuid, Dummy4))
PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid] = Setting
# Remove redundant PCD candidates, per the ARCH and SKU
- for PcdCName, TokenSpaceGuid in PcdList:
+ for PcdCName, TokenSpaceGuid, Dummy4 in PcdList:
Setting = PcdDict[self._Arch, self.SkuName, PcdCName, TokenSpaceGuid]
if Setting == None:
continue
@@ -797,7 +840,7 @@ class DscBuildData(PlatformBuildClassObject):
# At this point, we put all the data into the PcdClssObject for we don't know the PCD's datumtype
# until the DEC parser has been called.
#
- VpdOffset, MaxDatumSize, InitialValue = AnalyzeVpdPcdData(Setting)
+ VpdOffset, MaxDatumSize, InitialValue = self._ValidatePcd(PcdCName, TokenSpaceGuid, Setting, Type, Dummy4)
SkuInfo = SkuInfoClass(self.SkuName, self.SkuIds[self.SkuName], '', '', '', '', VpdOffset, InitialValue)
Pcds[PcdCName, TokenSpaceGuid] = PcdClassObject(
@@ -842,32 +885,6 @@ class DscBuildData(PlatformBuildClassObject):
self.Pcds[Name, Guid] = PcdClassObject(Name, Guid, '', '', '', '', '', {}, False, None)
self.Pcds[Name, Guid].DefaultValue = Value
- def IsPlatformPcdDeclared(self, DecPcds):
- for PcdType in (MODEL_PCD_FIXED_AT_BUILD, MODEL_PCD_PATCHABLE_IN_MODULE, MODEL_PCD_FEATURE_FLAG,
- MODEL_PCD_DYNAMIC_DEFAULT, MODEL_PCD_DYNAMIC_HII, MODEL_PCD_DYNAMIC_VPD,
- MODEL_PCD_DYNAMIC_EX_DEFAULT, MODEL_PCD_DYNAMIC_EX_HII, MODEL_PCD_DYNAMIC_EX_VPD):
- RecordList = self._RawData[PcdType, self._Arch]
- for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, Dummy3, Dummy4 in RecordList:
- if (PcdCName, TokenSpaceGuid) not in DecPcds:
- EdkLogger.error('build', PARSER_ERROR,
- "Pcd (%s.%s) defined in DSC is not declared in DEC files." % (TokenSpaceGuid, PcdCName),
- File=self.MetaFile, Line=Dummy4)
- PcdValue = ''
- if PcdType in (MODEL_PCD_DYNAMIC_VPD, MODEL_PCD_DYNAMIC_EX_VPD):
- if DecPcds[PcdCName, TokenSpaceGuid].DatumType == "VOID*":
- PcdValue = AnalyzeVpdPcdData(Setting)[2]
- else:
- PcdValue = AnalyzeVpdPcdData(Setting)[1]
- elif PcdType in (MODEL_PCD_DYNAMIC_HII, MODEL_PCD_DYNAMIC_EX_HII):
- PcdValue = AnalyzeHiiPcdData(Setting)[3]
- else:
- PcdValue = AnalyzePcdData(Setting)[0]
- if PcdValue:
- Valid, ErrStr = CheckPcdDatum(DecPcds[PcdCName, TokenSpaceGuid].DatumType, PcdValue)
- if not Valid:
- EdkLogger.error('build', FORMAT_INVALID, ErrStr, File=self.MetaFile, Line=Dummy4,
- ExtraData="%s.%s" % (TokenSpaceGuid, PcdCName))
-
_Macros = property(_GetMacros)
Arch = property(_GetArch, _SetArch)
Platform = property(_GetPlatformName)