From nobody Mon Apr 29 09:12:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1518101151470900.861359980554; Thu, 8 Feb 2018 06:45:51 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 0DD2B21F0DA60; Thu, 8 Feb 2018 06:40:02 -0800 (PST) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (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 C378722361E43 for ; Thu, 8 Feb 2018 06:40:00 -0800 (PST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Feb 2018 06:45:44 -0800 Received: from shwdeopenpsi168.ccr.corp.intel.com ([10.239.158.129]) by fmsmga001.fm.intel.com with ESMTP; 08 Feb 2018 06:45:41 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.31; helo=mga06.intel.com; envelope-from=yonghong.zhu@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,479,1511856000"; d="scan'208";a="29193145" From: Yonghong Zhu To: edk2-devel@lists.01.org Date: Thu, 8 Feb 2018 22:45:38 +0800 Message-Id: <1518101138-10064-1-git-send-email-yonghong.zhu@intel.com> X-Mailer: git-send-email 2.6.1.windows.1 Subject: [edk2] [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: , Cc: Yunhua Feng , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Yonghong Zhu =20 --- 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" % (s= elf.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, %s"%(se= lf.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 --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py b/BaseTool= s/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]) --=20 2.12.2.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel