From: "Gao, Liming" <liming.gao@intel.com>
To: "Zhu, Yonghong" <yonghong.zhu@intel.com>,
"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Subject: Re: [Patch] BaseTools: support PCD value to use expression in the DEC file
Date: Wed, 19 Oct 2016 01:32:42 +0000 [thread overview]
Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14B49625B@shsmsx102.ccr.corp.intel.com> (raw)
In-Reply-To: <1476350987-11628-2-git-send-email-yonghong.zhu@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
> -----Original Message-----
> From: Zhu, Yonghong
> Sent: Thursday, October 13, 2016 5:30 PM
> To: edk2-devel@lists.01.org
> Cc: Gao, Liming <liming.gao@intel.com>
> Subject: [Patch] BaseTools: support PCD value to use expression in the DEC
> file
>
> This patch add the support for Pcd value to use expression in the DEC file.
>
> Cc: Liming Gao <liming.gao@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Yonghong Zhu <yonghong.zhu@intel.com>
> ---
> BaseTools/Source/Python/Common/Misc.py | 57 ++++++++++++------
> ----
> .../Source/Python/Workspace/MetaFileParser.py | 21 ++++++--
> 2 files changed, 49 insertions(+), 29 deletions(-)
>
> diff --git a/BaseTools/Source/Python/Common/Misc.py
> b/BaseTools/Source/Python/Common/Misc.py
> index c99716d..3be1f0f 100644
> --- a/BaseTools/Source/Python/Common/Misc.py
> +++ b/BaseTools/Source/Python/Common/Misc.py
> @@ -1410,36 +1410,11 @@ def ParseConsoleLog(Filename):
> Opw.write('%s\n' % Line)
>
> Opr.close()
> Opw.close()
>
> -## AnalyzeDscPcd
> -#
> -# Analyze DSC PCD value, since there is no data type info in DSC
> -# This fuction is used to match functions (AnalyzePcdData,
> AnalyzeHiiPcdData, AnalyzeVpdPcdData) used for retrieving PCD value from
> database
> -# 1. Feature flag: TokenSpace.PcdCName|PcdValue
> -# 2. Fix and Patch:TokenSpace.PcdCName|PcdValue[|MaxSize]
> -# 3. Dynamic default:
> -# TokenSpace.PcdCName|PcdValue[|VOID*[|MaxSize]]
> -# TokenSpace.PcdCName|PcdValue
> -# 4. Dynamic VPD:
> -# TokenSpace.PcdCName|VpdOffset[|VpdValue]
> -# TokenSpace.PcdCName|VpdOffset[|MaxSize[|VpdValue]]
> -# 5. Dynamic HII:
> -# TokenSpace.PcdCName|HiiString|VaiableGuid|VariableOffset[|HiiValue]
> -# PCD value needs to be located in such kind of string, and the PCD value
> might be an expression in which
> -# there might have "|" operator, also in string value.
> -#
> -# @param Setting: String contain information described above with
> "TokenSpace.PcdCName|" stripped
> -# @param PcdType: PCD type: feature, fixed, dynamic default VPD HII
> -# @param DataType: The datum type of PCD: VOID*, UNIT, BOOL
> -# @retval:
> -# ValueList: A List contain fields described above
> -# IsValid: True if conforming EBNF, otherwise False
> -# Index: The index where PcdValue is in ValueList
> -#
> -def AnalyzeDscPcd(Setting, PcdType, DataType=''):
> +def AnalyzePcdExpression(Setting):
> Setting = Setting.strip()
> # There might be escaped quote in a string: \", \\\"
> Data = Setting.replace('\\\\', '//').replace('\\\"', '\\\'')
> # There might be '|' in string and in ( ... | ... ), replace it with '-'
> NewStr = ''
> @@ -1465,10 +1440,40 @@ def AnalyzeDscPcd(Setting, PcdType,
> DataType=''):
> FieldList.append(Setting[StartPos:].strip())
> break
> FieldList.append(Setting[StartPos:Pos].strip())
> StartPos = Pos + 1
>
> + return FieldList
> +
> +## AnalyzeDscPcd
> +#
> +# Analyze DSC PCD value, since there is no data type info in DSC
> +# This fuction is used to match functions (AnalyzePcdData,
> AnalyzeHiiPcdData, AnalyzeVpdPcdData) used for retrieving PCD value from
> database
> +# 1. Feature flag: TokenSpace.PcdCName|PcdValue
> +# 2. Fix and Patch:TokenSpace.PcdCName|PcdValue[|MaxSize]
> +# 3. Dynamic default:
> +# TokenSpace.PcdCName|PcdValue[|VOID*[|MaxSize]]
> +# TokenSpace.PcdCName|PcdValue
> +# 4. Dynamic VPD:
> +# TokenSpace.PcdCName|VpdOffset[|VpdValue]
> +# TokenSpace.PcdCName|VpdOffset[|MaxSize[|VpdValue]]
> +# 5. Dynamic HII:
> +#
> TokenSpace.PcdCName|HiiString|VaiableGuid|VariableOffset[|HiiValue]
> +# PCD value needs to be located in such kind of string, and the PCD value
> might be an expression in which
> +# there might have "|" operator, also in string value.
> +#
> +# @param Setting: String contain information described above with
> "TokenSpace.PcdCName|" stripped
> +# @param PcdType: PCD type: feature, fixed, dynamic default VPD HII
> +# @param DataType: The datum type of PCD: VOID*, UNIT, BOOL
> +# @retval:
> +# ValueList: A List contain fields described above
> +# IsValid: True if conforming EBNF, otherwise False
> +# Index: The index where PcdValue is in ValueList
> +#
> +def AnalyzeDscPcd(Setting, PcdType, DataType=''):
> + FieldList = AnalyzePcdExpression(Setting)
> +
> IsValid = True
> if PcdType in (MODEL_PCD_FIXED_AT_BUILD,
> MODEL_PCD_PATCHABLE_IN_MODULE, MODEL_PCD_FEATURE_FLAG):
> Value = FieldList[0]
> Size = ''
> if len(FieldList) > 1:
> diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py
> b/BaseTools/Source/Python/Workspace/MetaFileParser.py
> index 82d874f..1a5fdf5 100644
> --- a/BaseTools/Source/Python/Workspace/MetaFileParser.py
> +++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py
> @@ -24,11 +24,11 @@ import Common.EdkLogger as EdkLogger
> 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
> +from Common.Misc import GuidStructureStringToGuidString,
> CheckPcdDatum, PathClass, AnalyzePcdData, AnalyzeDscPcd,
> AnalyzePcdExpression
> from Common.Expression import *
> from CommonDataClass.Exceptions import *
> from Common.LongFilePathSupport import OpenLongFilePath as open
>
> from MetaFileTable import MetaFileStorage
> @@ -1633,10 +1633,11 @@ class DecParser(MetaFileParser):
> return
> MetaFileParser.__init__(self, FilePath, FileType, Arch, Table, -1)
> self._Comments = []
> self._Version = 0x00010005 # Only EDK2 dec file is supported
> self._AllPCDs = [] # Only for check duplicate PCD
> + self._AllPcdDict = {}
>
> ## Parser starter
> def Start(self):
> Content = ''
> try:
> @@ -1846,14 +1847,14 @@ class DecParser(MetaFileParser):
> 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 = AnalyzePcdExpression(ptrValueList)
> ValueList[0] = PtrValue[0]
> else:
> - ValueList = GetSplitValueList(TokenList[1])
> + ValueList = AnalyzePcdExpression(TokenList[1])
>
>
> # check if there's enough datum information given
> if len(ValueList) != 3:
> EdkLogger.error('Parser', FORMAT_INVALID, "Invalid PCD Datum
> information given",
> @@ -1876,10 +1877,23 @@ class DecParser(MetaFileParser):
> 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)
> +
> + 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'
> +
> # 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)
> @@ -1894,10 +1908,11 @@ class DecParser(MetaFileParser):
> 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._AllPcdDict[TAB_SPLIT.join(self._ValueList[0:2])] = ValueList[0]
>
> self._ValueList[2] = ValueList[0].strip() + '|' + ValueList[1].strip() + '|' +
> ValueList[2].strip()
>
> _SectionParser = {
> MODEL_META_DATA_HEADER : MetaFileParser._DefineParser,
> --
> 2.6.1.windows.1
next prev parent reply other threads:[~2016-10-19 1:32 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-13 9:29 [Patch] BaseTools: PatchCheck to align with wiki and report error for EFI_D_* Yonghong Zhu
2016-10-13 9:29 ` [Patch] BaseTools: support PCD value to use expression in the DEC file Yonghong Zhu
2016-10-19 1:32 ` Gao, Liming [this message]
2016-10-15 20:13 ` [Patch] BaseTools: PatchCheck to align with wiki and report error for EFI_D_* Jordan Justen
2016-10-16 13:32 ` Zhu, Yonghong
2016-10-17 5:49 ` Jordan Justen
2016-10-17 6:53 ` Zhu, Yonghong
2016-10-17 5:56 ` Jordan Justen
2016-10-17 6:43 ` Zhu, Yonghong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4A89E2EF3DFEDB4C8BFDE51014F606A14B49625B@shsmsx102.ccr.corp.intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox