X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FWorkspace%2FMetaFileParser.py;h=322ed384496658635e8b87c1de4e75d6d564713c;hp=6fa008ef65529de52b14de795699b62fd7743322;hb=3378782691af1158560579444a23bdd2f0a7d154;hpb=e651d06c5ed167e706e2dbe122ec0953a54033f3
diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py b/BaseTools/Source/Python/Workspace/MetaFileParser.py
index 6fa008ef65..322ed38449 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 - 2017, Intel Corporation. All rights reserved.
+# Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.
# (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
@@ -27,7 +27,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, AnalyzeDscPcd, AnalyzePcdExpression
+from Common.Misc import GuidStructureStringToGuidString, CheckPcdDatum, PathClass, AnalyzePcdData, AnalyzeDscPcd, AnalyzePcdExpression, ParseFieldValue
from Common.Expression import *
from CommonDataClass.Exceptions import *
from Common.LongFilePathSupport import OpenLongFilePath as open
@@ -182,6 +182,7 @@ class MetaFileParser(object):
self._PostProcessed = False
# Different version of meta-file has different way to parse.
self._Version = 0
+ self._GuidDict = {} # for Parser PCD value {GUID(gTokeSpaceGuidName)}
## Store the parsed data in table
def _Store(self, *Args):
@@ -218,7 +219,7 @@ class MetaFileParser(object):
NewRecordList = []
for Record in RecordList:
Arch = Record[3]
- if Arch == 'COMMON' or Arch == FilterArch:
+ if Arch == TAB_ARCH_COMMON or Arch == FilterArch:
NewRecordList.append(Record)
return NewRecordList
@@ -240,7 +241,7 @@ class MetaFileParser(object):
self.Start()
# No specific ARCH or Platform given, use raw data
- if self._RawTable and (len(DataInfo) == 1 or DataInfo[1] == None):
+ if self._RawTable and (len(DataInfo) == 1 or DataInfo[1] is None):
return self._FilterRecordList(self._RawTable.Query(*DataInfo), self._Arch)
# Do post-process if necessary
@@ -318,7 +319,7 @@ class MetaFileParser(object):
if len(ItemList) > 1:
S1 = ItemList[1].upper()
else:
- S1 = 'COMMON'
+ S1 = TAB_ARCH_COMMON
ArchList.add(S1)
# S2 may be Platform or ModuleType
@@ -328,15 +329,15 @@ class MetaFileParser(object):
else:
S2 = ItemList[2].upper()
else:
- S2 = 'COMMON'
+ S2 = TAB_COMMON
if len(ItemList) > 3:
S3 = ItemList[3]
else:
- S3 = "COMMON"
+ S3 = TAB_COMMON
self._Scope.append([S1, S2, S3])
# 'COMMON' must not be used with specific ARCHs at the same section
- if 'COMMON' in ArchList and len(ArchList) > 1:
+ if TAB_ARCH_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)
# If the section information is needed later, it should be stored in database
@@ -454,12 +455,12 @@ class MetaFileParser(object):
for ActiveScope in self._Scope:
Scope0, Scope1,Scope2 = ActiveScope[0], ActiveScope[1],ActiveScope[2]
- if(Scope0, Scope1,Scope2) not in Scope and (Scope0, "COMMON","COMMON") not in Scope and ("COMMON", Scope1,"COMMON") not in Scope:
+ 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:
break
else:
ComSpeMacroDict.update(self._SectionsMacroDict[(SectionType, Scope)])
- if ("COMMON", "COMMON","COMMON") in Scope:
+ if (TAB_COMMON, TAB_COMMON, TAB_COMMON) in Scope:
ComComMacroDict.update(self._SectionsMacroDict[(SectionType, Scope)])
Macros.update(ComComMacroDict)
@@ -567,8 +568,8 @@ class InfParser(MetaFileParser):
if Line[0] == TAB_SECTION_START and Line[-1] == TAB_SECTION_END:
if not GetHeaderComment:
for Cmt, LNo in Comments:
- self._Store(MODEL_META_DATA_HEADER_COMMENT, Cmt, '', '', 'COMMON',
- 'COMMON', self._Owner[-1], LNo, -1, LNo, -1, 0)
+ self._Store(MODEL_META_DATA_HEADER_COMMENT, Cmt, '', '', TAB_COMMON,
+ TAB_COMMON, self._Owner[-1], LNo, -1, LNo, -1, 0)
GetHeaderComment = True
else:
TailComments.extend(SectionComments + Comments)
@@ -619,7 +620,7 @@ class InfParser(MetaFileParser):
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:
+ if self._ValueList is None or self._ItemType == MODEL_META_DATA_DEFINE:
self._ItemType = -1
Comments = []
continue
@@ -657,8 +658,8 @@ class InfParser(MetaFileParser):
# If there are tail comments in INF file, save to database whatever the comments are
for Comment in TailComments:
- self._Store(MODEL_META_DATA_TAIL_COMMENT, Comment[0], '', '', 'COMMON',
- 'COMMON', self._Owner[-1], -1, -1, -1, -1, 0)
+ self._Store(MODEL_META_DATA_TAIL_COMMENT, Comment[0], '', '', TAB_COMMON,
+ TAB_COMMON, self._Owner[-1], -1, -1, -1, -1, 0)
self._Done()
## Data parser for the format in which there's path
@@ -951,7 +952,7 @@ class DscParser(MetaFileParser):
self._ValueList = ['', '', '']
self._SectionParser[SectionType](self)
- if self._ValueList == None:
+ if self._ValueList is None:
continue
#
# Model, Value1, Value2, Value3, Arch, ModuleType, BelongsToItem=-1, BelongsToFile=-1,
@@ -1021,7 +1022,7 @@ class DscParser(MetaFileParser):
ExtraData=self._CurrentLine)
ItemType = self.DataType[DirectiveName]
- Scope = [['COMMON', 'COMMON','COMMON']]
+ Scope = [[TAB_COMMON, TAB_COMMON, TAB_COMMON]]
if ItemType == MODEL_META_DATA_INCLUDE:
Scope = self._Scope
if ItemType == MODEL_META_DATA_CONDITIONAL_STATEMENT_ENDIF:
@@ -1097,14 +1098,14 @@ class DscParser(MetaFileParser):
def _SkuIdParser(self):
TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT)
if len(TokenList) not in (2,3):
- EdkLogger.error('Parser', FORMAT_INVALID, "Correct format is '|[|]'",
+ EdkLogger.error('Parser', FORMAT_INVALID, "Correct format is '|[|]'",
ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)
self._ValueList[0:len(TokenList)] = TokenList
@ParseMacro
def _DefaultStoresParser(self):
TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT)
if len(TokenList) != 2:
- EdkLogger.error('Parser', FORMAT_INVALID, "Correct format is '|'",
+ EdkLogger.error('Parser', FORMAT_INVALID, "Correct format is '|'",
ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)
self._ValueList[0:len(TokenList)] = TokenList
@@ -1136,6 +1137,8 @@ class DscParser(MetaFileParser):
self._ValueList[0], self._ValueList[1] = PcdNameTockens[0], PcdNameTockens[1]
elif len(PcdNameTockens) == 3:
self._ValueList[0], self._ValueList[1] = ".".join((PcdNameTockens[0], PcdNameTockens[1])), PcdNameTockens[2]
+ elif len(PcdNameTockens) > 3:
+ self._ValueList[0], self._ValueList[1] = ".".join((PcdNameTockens[0], PcdNameTockens[1])), ".".join(PcdNameTockens[2:])
if len(TokenList) == 2:
self._ValueList[2] = TokenList[1]
if self._ValueList[0] == '' or self._ValueList[1] == '':
@@ -1240,6 +1243,13 @@ class DscParser(MetaFileParser):
# PCD cannot be referenced in macro definition
if self._ItemType not in [MODEL_META_DATA_DEFINE, MODEL_META_DATA_GLOBAL_DEFINE]:
Macros.update(self._Symbols)
+ if GlobalData.BuildOptionPcd:
+ for Item in GlobalData.BuildOptionPcd:
+ if type(Item) is tuple:
+ continue
+ PcdName, TmpValue = Item.split("=")
+ TmpValue = BuildOptionValue(TmpValue, self._GuidDict)
+ Macros[PcdName.strip()] = TmpValue
return Macros
def _PostProcess(self):
@@ -1351,7 +1361,7 @@ class DscParser(MetaFileParser):
File=self._FileWithError, ExtraData=' '.join(self._ValueList),
Line=self._LineIndex + 1)
- if self._ValueList == None:
+ if self._ValueList is None:
continue
NewOwner = self._IdMapping.get(Owner, -1)
@@ -1494,12 +1504,12 @@ class DscParser(MetaFileParser):
# Allow using system environment variables in path after !include
#
__IncludeMacros['WORKSPACE'] = GlobalData.gGlobalDefines['WORKSPACE']
- if "ECP_SOURCE" in GlobalData.gGlobalDefines.keys():
+ if "ECP_SOURCE" in GlobalData.gGlobalDefines:
__IncludeMacros['ECP_SOURCE'] = GlobalData.gGlobalDefines['ECP_SOURCE']
#
# During GenFds phase call DSC parser, will go into this branch.
#
- elif "ECP_SOURCE" in GlobalData.gCommandLineDefines.keys():
+ elif "ECP_SOURCE" in GlobalData.gCommandLineDefines:
__IncludeMacros['ECP_SOURCE'] = GlobalData.gCommandLineDefines['ECP_SOURCE']
__IncludeMacros['EFI_SOURCE'] = GlobalData.gGlobalDefines['EFI_SOURCE']
@@ -1528,9 +1538,13 @@ class DscParser(MetaFileParser):
self._FileWithError = IncludedFile1
IncludedFileTable = MetaFileStorage(self._Table.Cur, IncludedFile1, MODEL_FILE_DSC, False)
- Owner = self._Content[self._ContentIndex - 1][0]
+ FromItem = self._Content[self._ContentIndex - 1][0]
+ if self._Content[self._ContentIndex - 1][8] != -1.0:
+ Owner = self._Content[self._ContentIndex - 1][8]
+ else:
+ Owner = self._Content[self._ContentIndex - 1][0]
Parser = DscParser(IncludedFile1, self._FileType, self._Arch, IncludedFileTable,
- Owner=Owner, From=Owner)
+ Owner=Owner, From=FromItem)
self.IncludedFiles.add (IncludedFile1)
@@ -1542,7 +1556,10 @@ class DscParser(MetaFileParser):
# set the parser status with current status
Parser._SectionName = self._SectionName
- Parser._SectionType = self._SectionType
+ if self._InSubsection:
+ Parser._SectionType = self._SubsectionType
+ else:
+ Parser._SectionType = self._SectionType
Parser._Scope = self._Scope
Parser._Enabled = self._Enabled
# Parse the included file
@@ -1590,6 +1607,8 @@ class DscParser(MetaFileParser):
ValList[Index] = ValueExpression(PcdValue, self._Macros)(True)
except WrnExpression, Value:
ValList[Index] = Value.result
+ except:
+ pass
if ValList[Index] == 'True':
ValList[Index] = '1'
@@ -1728,7 +1747,7 @@ class DecParser(MetaFileParser):
# section content
self._ValueList = ['', '', '']
self._SectionParser[self._SectionType[0]](self)
- if self._ValueList == None or self._ItemType == MODEL_META_DATA_DEFINE:
+ if self._ValueList is None or self._ItemType == MODEL_META_DATA_DEFINE:
self._ItemType = -1
self._Comments = []
continue
@@ -1820,7 +1839,7 @@ class DecParser(MetaFileParser):
if len(ItemList) > 1:
S1 = ItemList[1].upper()
else:
- S1 = 'COMMON'
+ S1 = TAB_ARCH_COMMON
ArchList.add(S1)
# S2 may be Platform or ModuleType
if len(ItemList) > 2:
@@ -1831,18 +1850,18 @@ class DecParser(MetaFileParser):
EdkLogger.error("Parser", FORMAT_INVALID, 'Please use keyword "Private" as section tag modifier.',
File=self.MetaFile, Line=self._LineIndex + 1, ExtraData=self._CurrentLine)
else:
- S2 = 'COMMON'
+ S2 = TAB_COMMON
PrivateList.add(S2)
if [S1, S2, self.DataType[self._SectionName]] not in self._Scope:
self._Scope.append([S1, S2, self.DataType[self._SectionName]])
# 'COMMON' must not be used with specific ARCHs at the same section
- if 'COMMON' in ArchList and len(ArchList) > 1:
+ if TAB_ARCH_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)
# It is not permissible to mix section tags without the Private attribute with section tags with the Private attribute
- if 'COMMON' in PrivateList and len(PrivateList) > 1:
+ if TAB_COMMON in PrivateList and len(PrivateList) > 1:
EdkLogger.error('Parser', FORMAT_INVALID, "Can't mix section tags without the Private attribute with section tags with the Private attribute",
File=self.MetaFile, Line=self._LineIndex + 1, ExtraData=self._CurrentLine)
@@ -1869,6 +1888,8 @@ class DecParser(MetaFileParser):
File=self.MetaFile, Line=self._LineIndex + 1)
self._ValueList[0] = TokenList[0]
self._ValueList[1] = TokenList[1]
+ if self._ValueList[0] not in self._GuidDict:
+ self._GuidDict[self._ValueList[0]] = self._ValueList[1]
## PCD sections parser
#
@@ -1886,22 +1907,24 @@ class DecParser(MetaFileParser):
if "|" not in self._CurrentLine:
if "" == self._CurrentLine:
self._include_flag = True
+ self._package_flag = False
self._ValueList = None
return
if "" == self._CurrentLine:
self._package_flag = True
self._ValueList = None
+ self._include_flag = False
return
if self._include_flag:
self._ValueList[1] = "_" + md5.new(self._CurrentLine).hexdigest()
self._ValueList[2] = self._CurrentLine
- self._include_flag = False
if self._package_flag and "}" != self._CurrentLine:
self._ValueList[1] = "_" + md5.new(self._CurrentLine).hexdigest()
self._ValueList[2] = self._CurrentLine
if self._CurrentLine == "}":
self._package_flag = False
+ self._include_flag = False
self._ValueList = None
return
else:
@@ -1910,7 +1933,10 @@ class DecParser(MetaFileParser):
if len(PcdNames) == 2:
self._CurrentStructurePcdName = ""
else:
- self._ValueList[1] = PcdNames[2]
+ if self._CurrentStructurePcdName != TAB_SPLIT.join(PcdNames[:2]):
+ EdkLogger.error('Parser', FORMAT_INVALID, "Pcd Name does not match: %s and %s " % (self._CurrentStructurePcdName , TAB_SPLIT.join(PcdNames[:2])),
+ File=self.MetaFile, Line=self._LineIndex + 1)
+ self._ValueList[1] = TAB_SPLIT.join(PcdNames[2:])
self._ValueList[2] = PcdTockens[1]
if not self._CurrentStructurePcdName:
TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT, 1)
@@ -1982,15 +2008,10 @@ class DecParser(MetaFileParser):
PcdValue = ValueList[0]
if PcdValue:
try:
- ValueList[0] = ValueExpression(PcdValue, self._AllPcdDict)(True)
- except WrnExpression, Value:
- ValueList[0] = Value.result
-
- if ValueList[0] == 'True':
- ValueList[0] = '1'
- if ValueList[0] == 'False':
- ValueList[0] = '0'
-
+ self._GuidDict.update(self._AllPcdDict)
+ ValueList[0] = ValueExpressionEx(ValueList[0], ValueList[1], self._GuidDict)(True)
+ except BadExpression, Value:
+ EdkLogger.error('Parser', FORMAT_INVALID, Value, ExtraData=self._CurrentLine, 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: