From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (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 CA94781EDF for ; Sun, 22 Jan 2017 18:29:18 -0800 (PST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga105.fm.intel.com with ESMTP; 22 Jan 2017 18:29:18 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,272,1477983600"; d="scan'208";a="1086078783" Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by orsmga001.jf.intel.com with ESMTP; 22 Jan 2017 18:29:18 -0800 Received: from fmsmsx158.amr.corp.intel.com (10.18.116.75) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.248.2; Sun, 22 Jan 2017 18:29:18 -0800 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by fmsmsx158.amr.corp.intel.com (10.18.116.75) with Microsoft SMTP Server (TLS) id 14.3.248.2; Sun, 22 Jan 2017 18:29:17 -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; Mon, 23 Jan 2017 10:29:15 +0800 From: "Gao, Liming" To: "Zhu, Yonghong" , "edk2-devel@lists.01.org" Thread-Topic: [Patch] BaseTools: Extend the Macro used in the FDF !include statement Thread-Index: AQHSdF+TTiysQqPTvUCjQz37TkAGF6FFWChw Date: Mon, 23 Jan 2017 02:29:14 +0000 Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14D6D28CD@shsmsx102.ccr.corp.intel.com> References: <1485055691-106076-1-git-send-email-yonghong.zhu@intel.com> In-Reply-To: <1485055691-106076-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: Extend the Macro used in the FDF !include statement 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: Mon, 23 Jan 2017 02:29:19 -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: Sunday, January 22, 2017 11:28 AM >To: edk2-devel@lists.01.org >Cc: Gao, Liming >Subject: [Patch] BaseTools: Extend the Macro used in the FDF !include >statement > >Current it only support the system environment variables in the !include >statement, $(WORKSPACE), $(PACKAGES_PATH), $(EFI_SOURCE), >$(EDK_SOURCE), >$(ECP_SOURCE), this patch extend the usage to support the Global macros >and the macro which defined before the statement. > >Cc: Liming Gao >Contributed-under: TianoCore Contribution Agreement 1.0 >Signed-off-by: Yonghong Zhu >--- > BaseTools/Source/Python/GenFds/FdfParser.py | 41 >+++++++++++++++++++++-------- > 1 file changed, 30 insertions(+), 11 deletions(-) > >diff --git a/BaseTools/Source/Python/GenFds/FdfParser.py >b/BaseTools/Source/Python/GenFds/FdfParser.py >index e1295f2..27688e2 100644 >--- a/BaseTools/Source/Python/GenFds/FdfParser.py >+++ b/BaseTools/Source/Python/GenFds/FdfParser.py >@@ -618,31 +618,50 @@ class FdfParser: > # @param self The object pointer > # > def PreprocessIncludeFile(self): > # nested include support > Processed =3D False >+ MacroDict =3D {} > while self.__GetNextToken(): > >- if self.__Token =3D=3D '!include': >+ if self.__Token =3D=3D 'DEFINE': >+ if not self.__GetNextToken(): >+ raise Warning("expected Macro name", self.FileName, >self.CurrentLineNumber) >+ Macro =3D self.__Token >+ if not self.__IsToken( "=3D"): >+ raise Warning("expected '=3D'", self.FileName, >self.CurrentLineNumber) >+ Value =3D self.__GetExpression() >+ MacroDict[Macro] =3D Value >+ >+ elif self.__Token =3D=3D '!include': > Processed =3D True > IncludeLine =3D self.CurrentLineNumber > IncludeOffset =3D self.CurrentOffsetWithinLine - len('!in= clude') > if not self.__GetNextToken(): > raise Warning("expected include file name", self.File= Name, >self.CurrentLineNumber) > IncFileName =3D self.__Token >- __IncludeMacros =3D {} >- for Macro in ['WORKSPACE', 'ECP_SOURCE', 'EFI_SOURCE', >'EDK_SOURCE']: >+ PreIndex =3D 0 >+ StartPos =3D IncFileName.find('$(', PreIndex) >+ EndPos =3D IncFileName.find(')', StartPos+2) >+ while StartPos !=3D -1 and EndPos !=3D -1: >+ Macro =3D IncFileName[StartPos+2 : EndPos] > MacroVal =3D self.__GetMacroValue(Macro) >- if MacroVal: >- __IncludeMacros[Macro] =3D MacroVal >+ if not MacroVal: >+ if Macro in MacroDict: >+ MacroVal =3D MacroDict[Macro] >+ if MacroVal !=3D None: >+ IncFileName =3D IncFileName.replace('$(' + Macro = + ')', MacroVal, 1) >+ if MacroVal.find('$(') !=3D -1: >+ PreIndex =3D StartPos >+ else: >+ PreIndex =3D StartPos + len(MacroVal) >+ else: >+ raise Warning("The Macro %s is not defined" %Macr= o, >self.FileName, self.CurrentLineNumber) >+ StartPos =3D IncFileName.find('$(', PreIndex) >+ EndPos =3D IncFileName.find(')', StartPos+2) > >- try: >- IncludedFile =3D NormPath(ReplaceMacro(IncFileName, >__IncludeMacros, RaiseError=3DTrue)) >- except: >- raise Warning("only these system environment variable= s are >permitted to start the path of the included file: " >- "$(WORKSPACE), $(ECP_SOURCE), $(EFI_SOU= RCE), >$(EDK_SOURCE)", >- self.FileName, self.CurrentLineNumber) >+ IncludedFile =3D NormPath(IncFileName) > # > # First search the include file under the same directory = as FDF file > # > IncludedFile1 =3D PathClass(IncludedFile, >os.path.dirname(self.FileName)) > ErrorCode =3D IncludedFile1.Validate()[0] >-- >2.6.1.windows.1