From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.120; helo=mga04.intel.com; envelope-from=yonghong.zhu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 9FAF9222DE14D for ; Thu, 8 Feb 2018 15:52:03 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Feb 2018 15:57:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,480,1511856000"; d="scan'208";a="29335436" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by fmsmga001.fm.intel.com with ESMTP; 08 Feb 2018 15:57:48 -0800 Received: from shsmsx101.ccr.corp.intel.com (10.239.4.153) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 8 Feb 2018 15:57:48 -0800 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.116]) by SHSMSX101.ccr.corp.intel.com ([169.254.1.253]) with mapi id 14.03.0319.002; Fri, 9 Feb 2018 07:57:46 +0800 From: "Zhu, Yonghong" To: "Zhu, Yonghong" , "edk2-devel@lists.01.org" CC: "Feng, YunhuaX" , "Gao, Liming" , "Zhu, Yonghong" Thread-Topic: [edk2] [PATCH] BaseTools: Update Expression.py for string comparison and MACRO replace issue Thread-Index: AQHToOuNHxVZS/5mM0C7su4nEryQvKObLz6w Date: Thu, 8 Feb 2018 23:57:46 +0000 Message-ID: References: <1518101138-10064-1-git-send-email-yonghong.zhu@intel.com> In-Reply-To: <1518101138-10064-1-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: Update Expression.py for string comparison and MACRO replace issue X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 Feb 2018 23:52:04 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Yonghong Zhu =20 Best Regards, Zhu Yonghong -----Original Message----- From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Yong= hong Zhu Sent: Thursday, February 08, 2018 10:46 PM To: edk2-devel@lists.01.org Cc: Feng, YunhuaX ; Gao, Liming Subject: [edk2] [PATCH] BaseTools: Update Expression.py for string comparis= on and MACRO replace issue From: Yunhua Feng 1. Fix string comparison incorrect issue, we expected "ABC" is greater than= "AAD" since the second char 'B' is greater than 'A'. 2. fix MACRO not replace issue. Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Yunhua Feng --- BaseTools/Source/Python/Common/Expression.py | 41 ++++++------------= ---- BaseTools/Source/Python/Workspace/DscBuildData.py | 2 +- .../Source/Python/Workspace/MetaFileParser.py | 1 + 3 files changed, 13 insertions(+), 31 deletions(-) diff --git a/BaseTools/Source/Python/Common/Expression.py b/BaseTools/Sourc= e/Python/Common/Expression.py index 6a1103df2c..a19f35d991 100644 --- a/BaseTools/Source/Python/Common/Expression.py +++ b/BaseTools/Source/Python/Common/Expression.py @@ -155,23 +155,13 @@ class ValueExpression(object): =20 @staticmethod def Eval(Operator, Oprand1, Oprand2 =3D None): WrnExp =3D None =20 - if Operator not in ["in", "not in"] and (type(Oprand1) =3D=3D type= ('') or type(Oprand2) =3D=3D type('')): - if type(Oprand1) =3D=3D type(''): - if Oprand1[0] in ['"', "'"] or Oprand1.startswith('L"') or= Oprand1.startswith("L'")or Oprand1.startswith('UINT'): - Oprand1, Size =3D ParseFieldValue(Oprand1) - else: - Oprand1,Size =3D ParseFieldValue('"' + Oprand1 + '"') - if type(Oprand2) =3D=3D type(''): - if Oprand2[0] in ['"', "'"] or Oprand2.startswith('L"') or= Oprand2.startswith("L'") or Oprand2.startswith('UINT'): - Oprand2, Size =3D ParseFieldValue(Oprand2) - else: - Oprand2, Size =3D ParseFieldValue('"' + Oprand2 + '"') - if type(Oprand1) =3D=3D type('') or type(Oprand2) =3D=3D type(= ''): - raise BadExpression(ERR_STRING_EXPR % Operator) + if Operator not in ["=3D=3D", "!=3D", ">=3D", "<=3D", ">", "<", "i= n", "not in"] and \ + (type(Oprand1) =3D=3D type('') or type(Oprand2) =3D=3D type(''= )): + raise BadExpression(ERR_STRING_EXPR % Operator) if Operator in ['in', 'not in']: if type(Oprand1) !=3D type(''): Oprand1 =3D IntToStr(Oprand1) if type(Oprand2) !=3D type(''): Oprand2 =3D IntToStr(Oprand2) @@ -294,12 +284,10 @@ class = ValueExpression(object): try: Token =3D self._GetToken() except BadExpression: pass if type(Token) =3D=3D type('') and Token.startswith('{') and T= oken.endswith('}') and self._Idx >=3D self._Len: - if len(Token) !=3D len(self._Expr.replace(' ', '')): - raise BadExpression return self._Expr =20 self._Idx =3D 0 self._Token =3D '' =20 @@ -457,19 +445,17 @@ class ValueExpression(object): Flag =3D 0 for Index in range(len(self._Token)): if self._Token[Index] in ['"']: Flag +=3D 1 if Flag =3D=3D 2 and self._Token.endswith('"'): - self._Token =3D ParseFieldValue(self._Token)[0] return True if self._Token.startswith("'") or self._Token.startswith("L'"): Flag =3D 0 for Index in range(len(self._Token)): if self._Token[Index] in ["'"]: Flag +=3D 1 if Flag =3D=3D 2 and self._Token.endswith("'"): - self._Token =3D ParseFieldValue(self._Token)[0] return True try: self._Token =3D int(self._Token, Radix) return True except ValueError: @@ -620,28 +606,20 @@ class ValueExpression(object): if Expr.startswith('L"'): # Skip L self._Idx +=3D 1 UStr =3D self.__GetString() self._Token =3D 'L"' + UStr + '"' - self._Token, Size =3D ParseFieldValue(self._Token) return self._Token elif Expr.startswith("L'"): # Skip L self._Idx +=3D 1 UStr =3D self.__GetString() self._Token =3D "L'" + UStr + "'" - self._Token, Size =3D ParseFieldValue(self._Token) - return self._Token - elif Expr.startswith('"'): - UStr =3D self.__GetString() - self._Token =3D '"' + UStr + '"' - self._Token, Size =3D ParseFieldValue(self._Token) return self._Token elif Expr.startswith("'"): UStr =3D self.__GetString() self._Token =3D "'" + UStr + "'" - self._Token, Size =3D ParseFieldValue(self._Token) return self._Token elif Expr.startswith('UINT'): Re =3D re.compile('(?:UINT8|UINT16|UINT32|UINT64)\((.+)\)') try: RetValue =3D Re.search(Expr).group(1) @@ -749,11 +727,11 @= @ class ValueExpressionEx(ValueExpression): elif self.PcdType in ['UINT8', 'UINT16', 'UINT32', 'UINT64', '= BOOLEAN'] and (PcdValue.startswith("'") or \ PcdValue.startswith('"') or PcdValue.startswith("L'"= ) or PcdValue.startswith('L"') or PcdValue.startswith('{')): raise BadExpression except WrnExpression, Value: PcdValue =3D Value.result - except BadExpression: + except BadExpression, Value: if self.PcdType in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BO= OLEAN']: PcdValue =3D PcdValue.strip() if type(PcdValue) =3D=3D type('') and PcdValue.startswith(= '{') and PcdValue.endswith('}'): PcdValue =3D PcdValue[1:-1].split(',') if type(PcdValue) =3D=3D type([]): @@ -783,14 +761,17 @@ class ValueExpressionEx(ValueExpression): TmpValue =3D (ItemValue << (Size * 8)) | TmpValue Size =3D Size + ItemSize else: try: TmpValue, Size =3D ParseFieldValue(PcdValue) - except BadExpression: - raise BadExpression("Type: %s, Value: %s, format o= r value error" % (self.PcdType, PcdValue)) + except BadExpression, Value: + raise BadExpression("Type: %s, Value: %s, %s" %=20 + (self.PcdType, PcdValue, Value)) if type(TmpValue) =3D=3D type(''): - TmpValue =3D int(TmpValue) + try: + TmpValue =3D int(TmpValue) + except: + raise BadExpression(Value) else: PcdValue =3D '0x%0{}X'.format(Size) % (TmpValue) if TmpValue < 0: raise BadExpression('Type %s PCD Value is negative' %= self.PcdType) if self.PcdType =3D=3D 'UINT8' and Size > 1: @@ -896,11 +877,11 @@ class ValueExpressionEx(ValueExpression): Size +=3D ItemSize =20 if Size > 0: PcdValue =3D '{' + ValueStr[:-2] + '}' else: - raise BadExpression("Type: %s, Value: %s, format = or value error"%(self.PcdType, PcdValue)) + raise BadExpression("Type: %s, Value: %s,=20 + %s"%(self.PcdType, PcdValue, Value)) =20 if PcdValue =3D=3D 'True': PcdValue =3D '1' if PcdValue =3D=3D 'False': PcdValue =3D '0' diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/= Source/Python/Workspace/DscBuildData.py index d9165f2ac7..8eef252e30 100644 --- a/BaseTools/Source/Python/Workspace/DscBuildData.py +++ b/BaseTools/Source/Python/Workspace/DscBuildData.py @@ -806,11 +806,11 @@ class DscBuildData(PlatformBuildClassObject): continue ModuleData =3D self._Bdb[ModuleFile, self._Arch, self._Tar= get, self._Toolchain] PkgSet.update(ModuleData.Packages) =20 self._DecPcds, self._GuidDict =3D GetDeclaredPcd(self, self._B= db, self._Arch, self._Target, self._Toolchain,PkgSet) - + self._GuidDict.update(GlobalData.gPlatformPcds) =20 if (PcdCName, TokenSpaceGuid) not in self._DecPcds: EdkLogger.error('build', PARSER_ERROR, "Pcd (%s.%s) defined in DSC is not declared in= DEC files. Arch: ['%s']" % (TokenSpaceGuid, PcdCName, self._Arch), File=3Dself.MetaFile, Line=3DLineNo) diff --gi= t a/BaseTools/Source/Python/Workspace/MetaFileParser.py b/BaseTools/Source/= Python/Workspace/MetaFileParser.py index 57642de4ee..95ea6fb45a 100644 --- a/BaseTools/Source/Python/Workspace/MetaFileParser.py +++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py @@ -1992,10 +1992,11 @@ class DecParser(MetaFileParser): File=3Dself.MetaFile, Line=3Dself._LineInd= ex + 1) =20 PcdValue =3D ValueList[0] if PcdValue: try: + self._GuidDict.update(self._AllPcdDict) ValueList[0] =3D ValueExpressionEx(ValueList[0], Value= List[1], self._GuidDict)(True) except BadExpression, Value: EdkLogger.error('Parser', FORMAT_INVALID, Value, Extra= Data=3Dself._CurrentLine, File=3Dself.MetaFile, Line=3Dself._LineIndex + 1) # check format of default value against the datum type IsValid, Cause =3D CheckPcdDatum(ValueList[1], ValueList[0]) -- 2.12.2.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel