From nobody Wed May 15 02:28:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+87652+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+87652+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1647497752024415.9531244916568; Wed, 16 Mar 2022 23:15:52 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id HAm9YY1788612xDi1wHVQSOv; Wed, 16 Mar 2022 23:15:53 -0700 X-Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web10.7035.1647497749805390624 for ; Wed, 16 Mar 2022 23:15:52 -0700 X-IronPort-AV: E=McAfee;i="6200,9189,10288"; a="256520671" X-IronPort-AV: E=Sophos;i="5.90,188,1643702400"; d="scan'208";a="256520671" X-Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Mar 2022 23:15:51 -0700 X-IronPort-AV: E=Sophos;i="5.90,188,1643702400"; d="scan'208";a="541242807" X-Received: from shwdejointd178.ccr.corp.intel.com ([10.239.153.103]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Mar 2022 23:15:50 -0700 From: "yi1 li" To: devel@edk2.groups.io Cc: yi1 li Subject: [edk2-devel] [PATCH 1/2] BaseTools: TEST ONLY1 FeatureFlagExpression Date: Thu, 17 Mar 2022 14:15:41 +0800 Message-Id: <7420ff3ad3ee0fad8c588d8031602a992a9d0d73.1646746333.git.yi1.li@intel.com> In-Reply-To: References: MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,yi1.li@intel.com X-Gm-Message-State: MJAmziIMksBWVjpG4nmlHkJox1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1647497753; bh=w9hg921kZjnyb3lr7iSB7yT0W85q9s/CvfHfhAV2rXA=; h=Cc:Date:From:Reply-To:Subject:To; b=D8xY157k2qbJm+E8YpcIwfJzMoRaANBToPvRe1k11CUzYIJpel6CqzEucF9JMZNkPRa FdyOem0K36CzApJGkY1Yur9dGhCMTXm0OaS543r2gD2RGT8HHU4gT69AroITF8Je57UPg PSmUjitoIo2oX0ez/c/YrB15ZglWH9oxo/w= X-ZohoMail-DKIM: fail (Signature date is -1 seconds in the future.) X-ZM-MESSAGEID: 1647497754662100006 Content-Type: text/plain; charset="utf-8" REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D1446 FeatureFlagExpression Support in LibraryClasses/Guids/Ppi/Protocols section of INF file. The Pcd value in the expression is from INF or DEC When a FeatureFlagExpression is present,if the expression evaluates to TRUE,then the entry is valid. If the expression evaluates to FALSE, then the EDK II build tools must ignore the entry. This patch is going to add this feature. Signed-off-by: yi1 li --- BaseTools/Source/Python/Common/Expression.py | 2 +- BaseTools/Source/Python/Common/GlobalData.py | 1 + .../Source/Python/Workspace/InfBuildData.py | 67 +++++++++++++++++-- .../Python/Workspace/WorkspaceCommon.py | 10 ++- 4 files changed, 72 insertions(+), 8 deletions(-) diff --git a/BaseTools/Source/Python/Common/Expression.py b/BaseTools/Sourc= e/Python/Common/Expression.py index 07ca039a9cf3..31bf0e4b6cf7 100644 --- a/BaseTools/Source/Python/Common/Expression.py +++ b/BaseTools/Source/Python/Common/Expression.py @@ -43,7 +43,7 @@ ERR_IN_OPERAND =3D 'Macro after IN operator can = only be: $(FAMILY), $(ARC __ValidString =3D re.compile(r'[_a-zA-Z][_0-9a-zA-Z]*$') _ReLabel =3D re.compile('LABEL\((\w+)\)') _ReOffset =3D re.compile('OFFSET_OF\((\w+)\)') -PcdPattern =3D re.compile(r'[_a-zA-Z][0-9A-Za-z_]*\.[_a-zA-Z][0-9A-Za-z_]*= $') +PcdPattern =3D re.compile(r'^[_a-zA-Z][0-9A-Za-z_]*\.[_a-zA-Z][0-9A-Za-z_]= *$') =20 ## SplitString # Split string to list according double quote diff --git a/BaseTools/Source/Python/Common/GlobalData.py b/BaseTools/Sourc= e/Python/Common/GlobalData.py index 61ab3f7e24cd..197bd8366682 100755 --- a/BaseTools/Source/Python/Common/GlobalData.py +++ b/BaseTools/Source/Python/Common/GlobalData.py @@ -18,6 +18,7 @@ gGlobalDefines =3D {} gPlatformDefines =3D {} # PCD name and value pair for fixed at build and feature flag gPlatformPcds =3D {} +gPlatformFinalPcds =3D {} # PCDs with type that are not fixed at build and feature flag gPlatformOtherPcds =3D {} gActivePlatform =3D None diff --git a/BaseTools/Source/Python/Workspace/InfBuildData.py b/BaseTools/= Source/Python/Workspace/InfBuildData.py index 45b8ef4716dd..91d986d8cb1b 100644 --- a/BaseTools/Source/Python/Workspace/InfBuildData.py +++ b/BaseTools/Source/Python/Workspace/InfBuildData.py @@ -14,6 +14,7 @@ from types import * from .MetaFileParser import * from collections import OrderedDict from Workspace.BuildClassObject import ModuleBuildClassObject, LibraryClas= sObject, PcdClassObject +from Common.Expression import ValueExpressionEx, PcdPattern =20 ## Get Protocol value from given packages # @@ -554,6 +555,9 @@ class InfBuildData(ModuleBuildClassObject): Instance =3D Record[1] if Instance: Instance =3D NormPath(Instance, self._Macros) + FeaturePcdExpression =3D self.CheckFeatureFlagPcd(Instance) + if not FeaturePcdExpression: + continue RetVal[Lib] =3D Instance else: RetVal[Lib] =3D None @@ -584,6 +588,10 @@ class InfBuildData(ModuleBuildClassObject): self._ProtocolComments =3D OrderedDict() RecordList =3D self._RawData[MODEL_EFI_PROTOCOL, self._Arch, self.= _Platform] for Record in RecordList: + if Record[1]: + FeaturePcdExpression =3D self.CheckFeatureFlagPcd(Record[1= ]) + if not FeaturePcdExpression: + continue CName =3D Record[0] Value =3D _ProtocolValue(CName, self.Packages, self.MetaFile.P= ath) if Value is None: @@ -608,6 +616,10 @@ class InfBuildData(ModuleBuildClassObject): self._PpiComments =3D OrderedDict() RecordList =3D self._RawData[MODEL_EFI_PPI, self._Arch, self._Plat= form] for Record in RecordList: + if Record[1]: + FeaturePcdExpression =3D self.CheckFeatureFlagPcd(Record[1= ]) + if not FeaturePcdExpression: + continue CName =3D Record[0] Value =3D _PpiValue(CName, self.Packages, self.MetaFile.Path) if Value is None: @@ -631,7 +643,12 @@ class InfBuildData(ModuleBuildClassObject): RetVal =3D OrderedDict() self._GuidComments =3D OrderedDict() RecordList =3D self._RawData[MODEL_EFI_GUID, self._Arch, self._Pla= tform] + RetVal.update(self.GetGuidsUsedByPcd()) for Record in RecordList: + if Record[1]: + FeaturePcdExpression =3D self.CheckFeatureFlagPcd(Record[1= ]) + if not FeaturePcdExpression: + continue CName =3D Record[0] Value =3D GuidValue(CName, self.Packages, self.MetaFile.Path) if Value is None: @@ -860,7 +877,12 @@ class InfBuildData(ModuleBuildClassObject): def GetGuidsUsedByPcd(self): self.Guid return self._GuidsUsedByPcd - + @cached_class_function + def GetGuidDict(self): + GuidDict =3D OrderedDict() + for Package in self.Packages: + GuidDict.update(Package.Guids) + return GuidDict ## Retrieve PCD for given type def _GetPcd(self, Type): Pcds =3D OrderedDict() @@ -877,7 +899,6 @@ class InfBuildData(ModuleBuildClassObject): self._PcdComments[TokenSpaceGuid, PcdCName] =3D Comments =20 # resolve PCD type, value, datum info, etc. by getting its definit= ion from package - _GuidDict =3D self.Guids.copy() for PcdCName, TokenSpaceGuid in PcdList: PcdRealName =3D PcdCName Setting, LineNo =3D PcdDict[self._Arch, self.Platform, PcdCNam= e, TokenSpaceGuid] @@ -895,7 +916,7 @@ class InfBuildData(ModuleBuildClassObject): '', {}, False, - self.Guids[TokenSpaceGuid] + self.GetGuidDict()[TokenSpaceGuid] ) if Type =3D=3D MODEL_PCD_PATCHABLE_IN_MODULE and ValueList[1]: # Patch PCD: TokenSpace.PcdCName|Value|Offset @@ -931,7 +952,6 @@ class InfBuildData(ModuleBuildClassObject): # # TAB_PCDS_FIXED_AT_BUILD, TAB_PCDS_PATCHABLE_IN_MODULE,= TAB_PCDS_FEATURE_FLAG, TAB_PCDS_DYNAMIC, TAB_PCDS_DYNAMIC_EX # - _GuidDict.update(Package.Guids) PcdType =3D self._PCD_TYPE_STRING_[Type] if Type =3D=3D MODEL_PCD_DYNAMIC: Pcd.Pending =3D True @@ -1023,7 +1043,7 @@ class InfBuildData(ModuleBuildClassObject): Pcd.DefaultValue =3D PcdInPackage.DefaultValue else: try: - Pcd.DefaultValue =3D ValueExpressionEx(Pcd.Def= aultValue, Pcd.DatumType, _GuidDict)(True) + Pcd.DefaultValue =3D ValueExpressionEx(Pcd.Def= aultValue, Pcd.DatumType, self.GetGuidDict())(True) except BadExpression as Value: EdkLogger.error('Parser', FORMAT_INVALID, 'PCD= [%s.%s] Value "%s", %s' %(TokenSpaceGuid, PcdRealName, Pcd.DefaultValue, V= alue), File=3Dself.MetaFile, Line=3DL= ineNo) @@ -1046,6 +1066,43 @@ class InfBuildData(ModuleBuildClassObject): if (self.Binaries and not self.Sources) or GlobalData.gIgnoreSourc= e: return True return False + def CheckFeatureFlagPcd(self,Instance): + Pcds =3D {} + if GlobalData.gPlatformFinalPcds.get(self.Arch): + Pcds =3D GlobalData.gPlatformFinalPcds[self.Arch].copy() + if PcdPattern.search(Instance): + PcdTuple =3D tuple(Instance.split('.')[::-1]) + if PcdTuple in self.Pcds: + if not (self.Pcds[PcdTuple].Type =3D=3D 'FeatureFlag' or s= elf.Pcds[PcdTuple].Type =3D=3D 'FixedAtBuild') and Instance not in Pcds: + EdkLogger.error('build', FORMAT_INVALID, + "\nit must be defined in a [PcdsFeatur= eFlag] or [PcdsFixedAtBuild] section of Dsc or Dec file or [FeaturePcd] or = [FixedPcd] of Inf file", + File=3Dstr(self), ExtraData=3DInstance) + Pcds[Instance] =3D self.Pcds[PcdTuple].DefaultValue + if Instance in Pcds: + if Pcds[Instance] =3D=3D '0': + return False + elif Pcds[Instance] =3D=3D '1': + return True + try: + Value =3D ValueExpression(Instance, Pcds)() + if Value =3D=3D True: + return True + return False + except: + EdkLogger.warn('build', FORMAT_INVALID,"The FeatureFlagExp= ression cannot be evaluated", File=3Dstr(self), ExtraData=3DInstance) + return False + else: + for Name, Guid in self.Pcds: + if self.Pcds[(Name, Guid)].Type =3D=3D 'FeatureFlag' or se= lf.Pcds[(Name, Guid)].Type =3D=3D 'FixedAtBuild': + Pcds['%s.%s' % (Guid, Name)] =3D self.Pcds[(Name, Guid= )].DefaultValue + try: + Value =3D ValueExpression(Instance, Pcds)() + if Value =3D=3D True: + return True + return False + except: + EdkLogger.warn('build', FORMAT_INVALID, "The FeatureFlagEx= pression cannot be evaluated", File=3Dstr(self), ExtraData=3DInstance) + return False def ExtendCopyDictionaryLists(CopyToDict, CopyFromDict): for Key in CopyFromDict: CopyToDict[Key].extend(CopyFromDict[Key]) diff --git a/BaseTools/Source/Python/Workspace/WorkspaceCommon.py b/BaseToo= ls/Source/Python/Workspace/WorkspaceCommon.py index 53027a0e30f5..03e31bacfb51 100644 --- a/BaseTools/Source/Python/Workspace/WorkspaceCommon.py +++ b/BaseTools/Source/Python/Workspace/WorkspaceCommon.py @@ -42,8 +42,9 @@ def GetPackageList(Platform, BuildDatabase, Arch, Target,= Toolchain): for ModuleFile in Platform.Modules: Data =3D BuildDatabase[ModuleFile, Arch, Target, Toolchain] PkgSet.update(Data.Packages) - for Lib in GetLiabraryInstances(Data, Platform, BuildDatabase, Arc= h, Target, Toolchain): - PkgSet.update(Lib.Packages) + for ModuleFile in Platform.LibraryInstances: + Data =3D BuildDatabase[ModuleFile, Arch, Target, Toolchain] + PkgSet.update(Data.Packages) return list(PkgSet) =20 ## Get all declared PCD from platform for specified arch, target and toolc= hain @@ -75,6 +76,11 @@ def GetDeclaredPcd(Platform, BuildDatabase, Arch, Target= , Toolchain, additionalP break if (PcdCName, PcdTokenName) not in DecPcds: DecPcds[PcdCName, PcdTokenName] =3D Pkg.Pcds[Pcd] + if not GlobalData.gPlatformFinalPcds.get(Arch): + GlobalData.gPlatformFinalPcds[Arch] =3D OrderedDict() + for Name,Guid in DecPcds: + if DecPcds[Name, Guid].Type =3D=3D 'FeatureFlag' or DecPcds[Name, = Guid].Type =3D=3D 'FixedAtBuild': + GlobalData.gPlatformFinalPcds[Arch]['%s.%s'%(Guid, Name)]=3DDe= cPcds[Name, Guid].DefaultValue return DecPcds, GuidDict =20 ## Get all dependent libraries for a module --=20 2.33.0.windows.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#87652): https://edk2.groups.io/g/devel/message/87652 Mute This Topic: https://groups.io/mt/89839903/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 15 02:28:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+87653+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+87653+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 164749775371765.44396315924075; Wed, 16 Mar 2022 23:15:53 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id BqhlYY1788612xcTRPjdw0bZ; Wed, 16 Mar 2022 23:15:54 -0700 X-Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web10.7035.1647497749805390624 for ; Wed, 16 Mar 2022 23:15:54 -0700 X-IronPort-AV: E=McAfee;i="6200,9189,10288"; a="256520690" X-IronPort-AV: E=Sophos;i="5.90,188,1643702400"; d="scan'208";a="256520690" X-Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Mar 2022 23:15:53 -0700 X-IronPort-AV: E=Sophos;i="5.90,188,1643702400"; d="scan'208";a="541242820" X-Received: from shwdejointd178.ccr.corp.intel.com ([10.239.153.103]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Mar 2022 23:15:52 -0700 From: "yi1 li" To: devel@edk2.groups.io Cc: yi1 li Subject: [edk2-devel] [PATCH 2/2] BaseTools: TEST ONLY2 FeatureFlagExpression Date: Thu, 17 Mar 2022 14:15:42 +0800 Message-Id: <964dee97e12793125d8c6cb486cf4d6498c05570.1646746333.git.yi1.li@intel.com> In-Reply-To: References: MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,yi1.li@intel.com X-Gm-Message-State: T7k64Slwm7ZbzRLUlyCi3quJx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1647497754; bh=CafmqbK31mEBuLrCuiAEh5diGdBcktTb3VEvZH6HX7U=; h=Cc:Date:From:Reply-To:Subject:To; b=OmCj3hKXZmyl2eYE+9KRnHht8vmLlWHHmL/A7Ilmb6v6kLoGUeS6/ZrvfW7JuPTLaOT sswCuorm6yeaXFznzhntMj/23sDsgg4ZMs0Ct6NM+bL99K0wMHeaLFjvyfYLSwmRiH9wr WEv8xDaVu6r6fJH8yR1ugH88BsVqnr22Iaw= X-ZohoMail-DKIM: fail (Signature date is -1 seconds in the future.) X-ZM-MESSAGEID: 1647497780736100002 Content-Type: text/plain; charset="utf-8" REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D1446 FeatureFlagExpression Support in Source section of INF file. The Pcd value in the expression is from INF or DEC. When a FeatureFlagExpression is present,if the expression evaluates to TRUE,then the entry is valid. If the expression evaluates to FALSE, then the EDK II build tools must ignore the entry. This patch is going to add this feature. Signed-off-by: yi1 li --- BaseTools/Source/Python/Workspace/InfBuildData.py | 14 ++++++++++---- .../Source/Python/Workspace/MetaFileParser.py | 4 ++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/BaseTools/Source/Python/Workspace/InfBuildData.py b/BaseTools/= Source/Python/Workspace/InfBuildData.py index 91d986d8cb1b..cb58e612cbd0 100644 --- a/BaseTools/Source/Python/Workspace/InfBuildData.py +++ b/BaseTools/Source/Python/Workspace/InfBuildData.py @@ -529,11 +529,17 @@ class InfBuildData(ModuleBuildClassObject): for Record in RecordList: LineNo =3D Record[-1] ToolChainFamily =3D Record[1] - TagName =3D Record[2] - ToolCode =3D Record[3] - + # OptionsList :=3D [TagName, ToolCode, FeatureFlag] + OptionsList =3D ['','',''] + TokenList =3D GetSplitValueList(Record[2], TAB_VALUE_SPLIT) + for Index in range(len(TokenList)): + OptionsList[Index] =3D TokenList[Index] + if OptionsList[2]: + FeaturePcdExpression =3D self.CheckFeatureFlagPcd(OptionsL= ist[2]) + if not FeaturePcdExpression: + continue File =3D PathClass(NormPath(Record[0], Macros), self._ModuleDi= r, '', - '', False, self._Arch, ToolChainFamily, '', T= agName, ToolCode) + '', False, self._Arch, ToolChainFamily, '', O= ptionsList[0], OptionsList[1]) # check the file validation ErrorCode, ErrorInfo =3D File.Validate() if ErrorCode !=3D 0: diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py b/BaseTool= s/Source/Python/Workspace/MetaFileParser.py index a3b6edbd15ee..3508591b281e 100644 --- a/BaseTools/Source/Python/Workspace/MetaFileParser.py +++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py @@ -736,6 +736,10 @@ class InfParser(MetaFileParser): @ParseMacro def _SourceFileParser(self): TokenList =3D GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT) + # Let TokenList[2] be TagName|ToolCode|FeatureFlag + if len(TokenList) > 3: + for extraToken in range(3, len(TokenList)): + TokenList[2] =3D TokenList[2] + '|' + TokenList[extraToken] self._ValueList[0:len(TokenList)] =3D TokenList Macros =3D self._Macros # For Acpi tables, remove macro like ' TABLE_NAME=3DSata1' --=20 2.33.0.windows.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#87653): https://edk2.groups.io/g/devel/message/87653 Mute This Topic: https://groups.io/mt/89839904/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-