From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (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 3799782215 for ; Tue, 21 Feb 2017 02:03:10 -0800 (PST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Feb 2017 02:03:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,189,1484035200"; d="scan'208";a="826718666" Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by FMSMGA003.fm.intel.com with ESMTP; 21 Feb 2017 02:03:09 -0800 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.248.2; Tue, 21 Feb 2017 02:03:09 -0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.88]) by SHSMSX103.ccr.corp.intel.com ([10.239.4.69]) with mapi id 14.03.0248.002; Tue, 21 Feb 2017 18:03:07 +0800 From: "Gao, Liming" To: "Zhu, Yonghong" , "edk2-devel@lists.01.org" Thread-Topic: [Patch] BaseTools: add error check for Macro usage in the INF file Thread-Index: AQHSi+BtosM0nHLjZ0+tobSkW2PI+KFzO6Cg Date: Tue, 21 Feb 2017 10:03:06 +0000 Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14D6E175C@shsmsx102.ccr.corp.intel.com> References: <1487639901-43004-1-git-send-email-yonghong.zhu@intel.com> In-Reply-To: <1487639901-43004-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: add error check for Macro usage in the INF 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: Tue, 21 Feb 2017 10:03:10 -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=20 Sent: Tuesday, February 21, 2017 9:18 AM To: edk2-devel@lists.01.org Cc: Gao, Liming Subject: [Patch] BaseTools: add error check for Macro usage in the INF file Use of MACRO statements in the EDK II INF files is limited to local usage only; global or external macros are not permitted. This patch add the check for not defined macros. Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Yonghong Zhu --- BaseTools/Source/Python/Workspace/MetaFileParser.py | 9 ++++++++- BaseTools/Source/Python/Workspace/WorkspaceDatabase.py | 4 +++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py b/BaseTool= s/Source/Python/Workspace/MetaFileParser.py index 1a5fdf5..37a7f5d 100644 --- a/BaseTools/Source/Python/Workspace/MetaFileParser.py +++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py @@ -1,9 +1,9 @@ ## @file # This file is used to parse meta files # -# Copyright (c) 2008 - 2016, Intel Corporation. All rights reserved.
+# Copyright (c) 2008 - 2017, 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 BS= D License # which accompanies this distribution. The full text of the license may b= e found at # http://opensource.org/licenses/bsd-license.php @@ -349,10 +349,17 @@ class MetaFileParser(object): EdkLogger.error('Parser', FORMAT_INVALID, "No value specified"= , ExtraData=3Dself._CurrentLine, File=3Dself.Met= aFile, Line=3Dself._LineIndex + 1) =20 self._ValueList =3D [ReplaceMacro(Value, self._Macros) for Value i= n self._ValueList] Name, Value =3D self._ValueList[1], self._ValueList[2] + MacroUsed =3D GlobalData.gMacroRefPattern.findall(Value) + if len(MacroUsed) !=3D 0: + for Macro in MacroUsed: + if Macro in GlobalData.gGlobalDefines: + EdkLogger.error("Parser", FORMAT_INVALID, "Global macr= o %s is not permitted." % (Macro), ExtraData=3Dself._CurrentLine, File=3Dse= lf.MetaFile, Line=3Dself._LineIndex + 1) + else: + EdkLogger.error("Parser", FORMAT_INVALID, "%s not defined"= % (Macro), ExtraData=3Dself._CurrentLine, File=3Dself.MetaFile, Line=3Dsel= f._LineIndex + 1) # Sometimes, we need to make differences between EDK and EDK2 modu= les=20 if Name =3D=3D 'INF_VERSION': if re.match(r'0[xX][\da-f-A-F]{5,8}', Value): self._Version =3D int(Value, 0) =20 elif re.match(r'\d+\.\d+', Value): diff --git a/BaseTools/Source/Python/Workspace/WorkspaceDatabase.py b/BaseT= ools/Source/Python/Workspace/WorkspaceDatabase.py index e7bc87d..0686721 100644 --- a/BaseTools/Source/Python/Workspace/WorkspaceDatabase.py +++ b/BaseTools/Source/Python/Workspace/WorkspaceDatabase.py @@ -1,9 +1,9 @@ ## @file # This file is used to create a database used by build tool # -# Copyright (c) 2008 - 2016, Intel Corporation. All rights reserved.
+# Copyright (c) 2008 - 2017, Intel Corporation. All rights reserved.
# (C) Copyright 2016 Hewlett Packard Enterprise Development LP
# This program and the accompanying materials # are licensed and made available under the terms and conditions of the BS= D License # which accompanies this distribution. The full text of the license may b= e found at # http://opensource.org/licenses/bsd-license.php @@ -1828,10 +1828,12 @@ class InfBuildData(ModuleBuildClassObject): self.__Macros =3D {} # EDK_GLOBAL defined macros can be applied to EDK module if self.AutoGenVersion < 0x00010005: self.__Macros.update(GlobalData.gEdkGlobal) self.__Macros.update(GlobalData.gGlobalDefines) + else: + self.__Macros.update(self.Defines) return self.__Macros =20 ## Get architecture def _GetArch(self): return self._Arch --=20 2.6.1.windows.1