From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (using TLSv1 with cipher CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id F1FD41A1E4F for ; Tue, 18 Oct 2016 18:32:45 -0700 (PDT) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP; 18 Oct 2016 18:32:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,364,1473145200"; d="scan'208";a="1072389970" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by fmsmga002.fm.intel.com with ESMTP; 18 Oct 2016 18:32:45 -0700 Received: from fmsmsx158.amr.corp.intel.com (10.18.116.75) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.248.2; Tue, 18 Oct 2016 18:32:44 -0700 Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by fmsmsx158.amr.corp.intel.com (10.18.116.75) with Microsoft SMTP Server (TLS) id 14.3.248.2; Tue, 18 Oct 2016 18:32:44 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.206]) by SHSMSX104.ccr.corp.intel.com ([169.254.5.209]) with mapi id 14.03.0248.002; Wed, 19 Oct 2016 09:32:42 +0800 From: "Gao, Liming" To: "Zhu, Yonghong" , "edk2-devel@lists.01.org" Thread-Topic: [Patch] BaseTools: support PCD value to use expression in the DEC file Thread-Index: AQHSJTRx1srWcHbRW0muehNbr+FaWaCvBusg Date: Wed, 19 Oct 2016 01:32:42 +0000 Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14B49625B@shsmsx102.ccr.corp.intel.com> References: <1476350987-11628-1-git-send-email-yonghong.zhu@intel.com> <1476350987-11628-2-git-send-email-yonghong.zhu@intel.com> In-Reply-To: <1476350987-11628-2-git-send-email-yonghong.zhu@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [Patch] BaseTools: support PCD value to use expression in the DEC file X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 19 Oct 2016 01:32:46 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Liming Gao > -----Original Message----- > From: Zhu, Yonghong > Sent: Thursday, October 13, 2016 5:30 PM > To: edk2-devel@lists.01.org > Cc: Gao, Liming > Subject: [Patch] BaseTools: support PCD value to use expression in the DE= C > file >=20 > This patch add the support for Pcd value to use expression in the DEC fil= e. >=20 > Cc: Liming Gao > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Yonghong Zhu > --- > BaseTools/Source/Python/Common/Misc.py | 57 ++++++++++++----= -- > ---- > .../Source/Python/Workspace/MetaFileParser.py | 21 ++++++-- > 2 files changed, 49 insertions(+), 29 deletions(-) >=20 > 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) >=20 > Opr.close() > Opw.close() >=20 > -## 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 val= ue > 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=3D''): > +def AnalyzePcdExpression(Setting): > Setting =3D Setting.strip() > # There might be escaped quote in a string: \", \\\" > Data =3D Setting.replace('\\\\', '//').replace('\\\"', '\\\'') > # There might be '|' in string and in ( ... | ... ), replace it with= '-' > NewStr =3D '' > @@ -1465,10 +1440,40 @@ def AnalyzeDscPcd(Setting, PcdType, > DataType=3D''): > FieldList.append(Setting[StartPos:].strip()) > break > FieldList.append(Setting[StartPos:Pos].strip()) > StartPos =3D Pos + 1 >=20 > + 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 val= ue > 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=3D''): > + FieldList =3D AnalyzePcdExpression(Setting) > + > IsValid =3D True > if PcdType in (MODEL_PCD_FIXED_AT_BUILD, > MODEL_PCD_PATCHABLE_IN_MODULE, MODEL_PCD_FEATURE_FLAG): > Value =3D FieldList[0] > Size =3D '' > 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 >=20 > 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 >=20 > from MetaFileTable import MetaFileStorage > @@ -1633,10 +1633,11 @@ class DecParser(MetaFileParser): > return > MetaFileParser.__init__(self, FilePath, FileType, Arch, Table, -= 1) > self._Comments =3D [] > self._Version =3D 0x00010005 # Only EDK2 dec file is supported > self._AllPCDs =3D [] # Only for check duplicate PCD > + self._AllPcdDict =3D {} >=20 > ## Parser starter > def Start(self): > Content =3D '' > try: > @@ -1846,14 +1847,14 @@ class DecParser(MetaFileParser): > PtrValue =3D ValueRe.findall(TokenList[1]) >=20 > # Has VOID* type string, may contain "|" character in the string= . > if len(PtrValue) !=3D 0: > ptrValueList =3D re.sub(ValueRe, '', TokenList[1]) > - ValueList =3D GetSplitValueList(ptrValueList) > + ValueList =3D AnalyzePcdExpression(ptrValueList) > ValueList[0] =3D PtrValue[0] > else: > - ValueList =3D GetSplitValueList(TokenList[1]) > + ValueList =3D AnalyzePcdExpression(TokenList[1]) >=20 >=20 > # check if there's enough datum information given > if len(ValueList) !=3D 3: > EdkLogger.error('Parser', FORMAT_INVALID, "Invalid PCD Datum > information given", > @@ -1876,10 +1877,23 @@ class DecParser(MetaFileParser): > if ValueList[2] =3D=3D '': > EdkLogger.error('Parser', FORMAT_INVALID, "Missing Token in = PCD > Datum information", > ExtraData=3Dself._CurrentLine + \ > " > (.|||< > Token>)", > File=3Dself.MetaFile, Line=3Dself._LineIndex= + 1) > + > + PcdValue =3D ValueList[0] > + if PcdValue: > + try: > + ValueList[0] =3D ValueExpression(PcdValue, self._AllPcdD= ict)(True) > + except WrnExpression, Value: > + ValueList[0] =3D Value.result > + > + if ValueList[0] =3D=3D 'True': > + ValueList[0] =3D '1' > + if ValueList[0] =3D=3D 'False': > + ValueList[0] =3D '0' > + > # check format of default value against the datum type > IsValid, Cause =3D CheckPcdDatum(ValueList[1], ValueList[0]) > if not IsValid: > EdkLogger.error('Parser', FORMAT_INVALID, Cause, > ExtraData=3Dself._CurrentLine, > File=3Dself.MetaFile, Line=3Dself._LineIndex= + 1) > @@ -1894,10 +1908,11 @@ class DecParser(MetaFileParser): > EdkLogger.error('Parser', FORMAT_INVALID, > "The same PCD name and GUID have been alread= y defined", > ExtraData=3Dself._CurrentLine, File=3Dself.M= etaFile, > Line=3Dself._LineIndex + 1) > else: > self._AllPCDs.append((self._Scope[0], self._ValueList[0], > self._ValueList[1])) > + self._AllPcdDict[TAB_SPLIT.join(self._ValueList[0:2])] =3D V= alueList[0] >=20 > self._ValueList[2] =3D ValueList[0].strip() + '|' + ValueList[1]= .strip() + '|' + > ValueList[2].strip() >=20 > _SectionParser =3D { > MODEL_META_DATA_HEADER : MetaFileParser._DefineParser= , > -- > 2.6.1.windows.1