public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [Patch] BaseTool: Filter out unused structure pcds
@ 2018-10-19 12:00 BobCF
  2018-10-19 14:34 ` Carsey, Jaben
  2018-10-24 14:34 ` Gao, Liming
  0 siblings, 2 replies; 5+ messages in thread
From: BobCF @ 2018-10-19 12:00 UTC (permalink / raw)
  To: edk2-devel; +Cc: Bob Feng, Liming Gao

The current code handle all the structure pcds
even if there is no module or library use them.
This patch is going to filter out the unused structure pcds.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
---
 .../Source/Python/Workspace/DscBuildData.py   | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py
index e481ea4f64..31bce16d15 100644
--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
@@ -274,10 +274,11 @@ class DscBuildData(PlatformBuildClassObject):
         self._RFCLanguages      = None
         self._ISOLanguages      = None
         self._VpdToolGuid       = None
         self._MacroDict         = None
         self.DefaultStores      = None
+        self.UsedStructurePcd   = None
 
     ## handle Override Path of Module
     def _HandleOverridePath(self):
         RecordList = self._RawData[MODEL_META_DATA_COMPONENT, self._Arch]
         for Record in RecordList:
@@ -1476,10 +1477,11 @@ class DscBuildData(PlatformBuildClassObject):
                         if str_pcd_obj.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:
                             str_pcd_obj_str.DefaultFromDSC = {skuname:{defaultstore: str_pcd_obj.SkuInfoList[skuname].DefaultStoreDict.get(defaultstore, str_pcd_obj.SkuInfoList[skuname].HiiDefaultValue) for defaultstore in DefaultStores} for skuname in str_pcd_obj.SkuInfoList}
                         else:
                             str_pcd_obj_str.DefaultFromDSC = {skuname:{defaultstore: str_pcd_obj.SkuInfoList[skuname].DefaultStoreDict.get(defaultstore, str_pcd_obj.SkuInfoList[skuname].DefaultValue) for defaultstore in DefaultStores} for skuname in str_pcd_obj.SkuInfoList}
                     S_pcd_set[Pcd] = str_pcd_obj_str
+        self.FilterStrcturePcd(S_pcd_set)
         if S_pcd_set:
             GlobalData.gStructurePcd[self.Arch] = S_pcd_set
         for stru_pcd in S_pcd_set.values():
             for skuid in SkuIds:
                 if skuid in stru_pcd.SkuOverrideValues:
@@ -1571,10 +1573,27 @@ class DscBuildData(PlatformBuildClassObject):
                 elif TAB_DEFAULT in pcd.SkuInfoList and TAB_COMMON in pcd.SkuInfoList:
                     del pcd.SkuInfoList[TAB_COMMON]
 
         map(self.FilterSkuSettings, [Pcds[pcdkey] for pcdkey in Pcds if Pcds[pcdkey].Type in DynamicPcdType])
         return Pcds
+    #Filter the StrucutrePcd that is not used by any module in dsc file and fdf file.
+    def FilterStrcturePcd(self, S_pcd_set):
+        if not self.UsedStructurePcd:
+            FdfInfList = []
+            if GlobalData.gFdfParser:
+                FdfInfList = GlobalData.gFdfParser.Profile.InfList
+            FdfModuleList = [PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch=self._Arch) for Inf in FdfInfList]
+            AllModulePcds = set()
+            ModuleSet = set(self._Modules.keys() + self.LibraryInstances + FdfModuleList)
+            for ModuleFile in ModuleSet:
+                ModuleData = self._Bdb[ModuleFile, self._Arch, self._Target, self._Toolchain]
+                AllModulePcds = AllModulePcds | set(ModuleData.Pcds.keys())
+
+            self.UsedStructurePcd = AllModulePcds
+        UnusedStruPcds = set(S_pcd_set.keys()) - self.UsedStructurePcd
+        for (Token, TokenSpaceGuid) in UnusedStruPcds:
+            del S_pcd_set[(Token, TokenSpaceGuid)]
 
     ## Retrieve non-dynamic PCD settings
     #
     #   @param  Type    PCD type
     #
-- 
2.18.0.windows.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Patch] BaseTool: Filter out unused structure pcds
  2018-10-19 12:00 [Patch] BaseTool: Filter out unused structure pcds BobCF
@ 2018-10-19 14:34 ` Carsey, Jaben
  2018-10-24 14:34 ` Gao, Liming
  1 sibling, 0 replies; 5+ messages in thread
From: Carsey, Jaben @ 2018-10-19 14:34 UTC (permalink / raw)
  To: Feng, Bob C, edk2-devel@lists.01.org; +Cc: Gao, Liming

Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>

> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
> BobCF
> Sent: Friday, October 19, 2018 5:00 AM
> To: edk2-devel@lists.01.org
> Cc: Gao, Liming <liming.gao@intel.com>
> Subject: [edk2] [Patch] BaseTool: Filter out unused structure pcds
> 
> The current code handle all the structure pcds
> even if there is no module or library use them.
> This patch is going to filter out the unused structure pcds.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Bob Feng <bob.c.feng@intel.com>
> Cc: Liming Gao <liming.gao@intel.com>
> ---
>  .../Source/Python/Workspace/DscBuildData.py   | 19
> +++++++++++++++++++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py
> b/BaseTools/Source/Python/Workspace/DscBuildData.py
> index e481ea4f64..31bce16d15 100644
> --- a/BaseTools/Source/Python/Workspace/DscBuildData.py
> +++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
> @@ -274,10 +274,11 @@ class DscBuildData(PlatformBuildClassObject):
>          self._RFCLanguages      = None
>          self._ISOLanguages      = None
>          self._VpdToolGuid       = None
>          self._MacroDict         = None
>          self.DefaultStores      = None
> +        self.UsedStructurePcd   = None
> 
>      ## handle Override Path of Module
>      def _HandleOverridePath(self):
>          RecordList = self._RawData[MODEL_META_DATA_COMPONENT,
> self._Arch]
>          for Record in RecordList:
> @@ -1476,10 +1477,11 @@ class DscBuildData(PlatformBuildClassObject):
>                          if str_pcd_obj.Type in
> [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII],
> self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:
>                              str_pcd_obj_str.DefaultFromDSC = {skuname:{defaultstore:
> str_pcd_obj.SkuInfoList[skuname].DefaultStoreDict.get(defaultstore,
> str_pcd_obj.SkuInfoList[skuname].HiiDefaultValue) for defaultstore in
> DefaultStores} for skuname in str_pcd_obj.SkuInfoList}
>                          else:
>                              str_pcd_obj_str.DefaultFromDSC = {skuname:{defaultstore:
> str_pcd_obj.SkuInfoList[skuname].DefaultStoreDict.get(defaultstore,
> str_pcd_obj.SkuInfoList[skuname].DefaultValue) for defaultstore in
> DefaultStores} for skuname in str_pcd_obj.SkuInfoList}
>                      S_pcd_set[Pcd] = str_pcd_obj_str
> +        self.FilterStrcturePcd(S_pcd_set)
>          if S_pcd_set:
>              GlobalData.gStructurePcd[self.Arch] = S_pcd_set
>          for stru_pcd in S_pcd_set.values():
>              for skuid in SkuIds:
>                  if skuid in stru_pcd.SkuOverrideValues:
> @@ -1571,10 +1573,27 @@ class DscBuildData(PlatformBuildClassObject):
>                  elif TAB_DEFAULT in pcd.SkuInfoList and TAB_COMMON in
> pcd.SkuInfoList:
>                      del pcd.SkuInfoList[TAB_COMMON]
> 
>          map(self.FilterSkuSettings, [Pcds[pcdkey] for pcdkey in Pcds if
> Pcds[pcdkey].Type in DynamicPcdType])
>          return Pcds
> +    #Filter the StrucutrePcd that is not used by any module in dsc file and fdf
> file.
> +    def FilterStrcturePcd(self, S_pcd_set):
> +        if not self.UsedStructurePcd:
> +            FdfInfList = []
> +            if GlobalData.gFdfParser:
> +                FdfInfList = GlobalData.gFdfParser.Profile.InfList
> +            FdfModuleList = [PathClass(NormPath(Inf), GlobalData.gWorkspace,
> Arch=self._Arch) for Inf in FdfInfList]
> +            AllModulePcds = set()
> +            ModuleSet = set(self._Modules.keys() + self.LibraryInstances +
> FdfModuleList)
> +            for ModuleFile in ModuleSet:
> +                ModuleData = self._Bdb[ModuleFile, self._Arch, self._Target,
> self._Toolchain]
> +                AllModulePcds = AllModulePcds | set(ModuleData.Pcds.keys())
> +
> +            self.UsedStructurePcd = AllModulePcds
> +        UnusedStruPcds = set(S_pcd_set.keys()) - self.UsedStructurePcd
> +        for (Token, TokenSpaceGuid) in UnusedStruPcds:
> +            del S_pcd_set[(Token, TokenSpaceGuid)]
> 
>      ## Retrieve non-dynamic PCD settings
>      #
>      #   @param  Type    PCD type
>      #
> --
> 2.18.0.windows.1
> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch] BaseTool: Filter out unused structure pcds
  2018-10-19 12:00 [Patch] BaseTool: Filter out unused structure pcds BobCF
  2018-10-19 14:34 ` Carsey, Jaben
@ 2018-10-24 14:34 ` Gao, Liming
  1 sibling, 0 replies; 5+ messages in thread
From: Gao, Liming @ 2018-10-24 14:34 UTC (permalink / raw)
  To: Feng, Bob C, edk2-devel@lists.01.org

Reviewed-by: Liming Gao <liming.gao@intel.com>

> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of BobCF
> Sent: Friday, October 19, 2018 8:00 PM
> To: edk2-devel@lists.01.org
> Cc: Gao, Liming <liming.gao@intel.com>
> Subject: [edk2] [Patch] BaseTool: Filter out unused structure pcds
> 
> The current code handle all the structure pcds
> even if there is no module or library use them.
> This patch is going to filter out the unused structure pcds.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Bob Feng <bob.c.feng@intel.com>
> Cc: Liming Gao <liming.gao@intel.com>
> ---
>  .../Source/Python/Workspace/DscBuildData.py   | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py
> index e481ea4f64..31bce16d15 100644
> --- a/BaseTools/Source/Python/Workspace/DscBuildData.py
> +++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
> @@ -274,10 +274,11 @@ class DscBuildData(PlatformBuildClassObject):
>          self._RFCLanguages      = None
>          self._ISOLanguages      = None
>          self._VpdToolGuid       = None
>          self._MacroDict         = None
>          self.DefaultStores      = None
> +        self.UsedStructurePcd   = None
> 
>      ## handle Override Path of Module
>      def _HandleOverridePath(self):
>          RecordList = self._RawData[MODEL_META_DATA_COMPONENT, self._Arch]
>          for Record in RecordList:
> @@ -1476,10 +1477,11 @@ class DscBuildData(PlatformBuildClassObject):
>                          if str_pcd_obj.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII],
> self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:
>                              str_pcd_obj_str.DefaultFromDSC = {skuname:{defaultstore:
> str_pcd_obj.SkuInfoList[skuname].DefaultStoreDict.get(defaultstore, str_pcd_obj.SkuInfoList[skuname].HiiDefaultValue) for defaultstore
> in DefaultStores} for skuname in str_pcd_obj.SkuInfoList}
>                          else:
>                              str_pcd_obj_str.DefaultFromDSC = {skuname:{defaultstore:
> str_pcd_obj.SkuInfoList[skuname].DefaultStoreDict.get(defaultstore, str_pcd_obj.SkuInfoList[skuname].DefaultValue) for defaultstore in
> DefaultStores} for skuname in str_pcd_obj.SkuInfoList}
>                      S_pcd_set[Pcd] = str_pcd_obj_str
> +        self.FilterStrcturePcd(S_pcd_set)
>          if S_pcd_set:
>              GlobalData.gStructurePcd[self.Arch] = S_pcd_set
>          for stru_pcd in S_pcd_set.values():
>              for skuid in SkuIds:
>                  if skuid in stru_pcd.SkuOverrideValues:
> @@ -1571,10 +1573,27 @@ class DscBuildData(PlatformBuildClassObject):
>                  elif TAB_DEFAULT in pcd.SkuInfoList and TAB_COMMON in pcd.SkuInfoList:
>                      del pcd.SkuInfoList[TAB_COMMON]
> 
>          map(self.FilterSkuSettings, [Pcds[pcdkey] for pcdkey in Pcds if Pcds[pcdkey].Type in DynamicPcdType])
>          return Pcds
> +    #Filter the StrucutrePcd that is not used by any module in dsc file and fdf file.
> +    def FilterStrcturePcd(self, S_pcd_set):
> +        if not self.UsedStructurePcd:
> +            FdfInfList = []
> +            if GlobalData.gFdfParser:
> +                FdfInfList = GlobalData.gFdfParser.Profile.InfList
> +            FdfModuleList = [PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch=self._Arch) for Inf in FdfInfList]
> +            AllModulePcds = set()
> +            ModuleSet = set(self._Modules.keys() + self.LibraryInstances + FdfModuleList)
> +            for ModuleFile in ModuleSet:
> +                ModuleData = self._Bdb[ModuleFile, self._Arch, self._Target, self._Toolchain]
> +                AllModulePcds = AllModulePcds | set(ModuleData.Pcds.keys())
> +
> +            self.UsedStructurePcd = AllModulePcds
> +        UnusedStruPcds = set(S_pcd_set.keys()) - self.UsedStructurePcd
> +        for (Token, TokenSpaceGuid) in UnusedStruPcds:
> +            del S_pcd_set[(Token, TokenSpaceGuid)]
> 
>      ## Retrieve non-dynamic PCD settings
>      #
>      #   @param  Type    PCD type
>      #
> --
> 2.18.0.windows.1
> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Patch] BaseTool: Filter out unused structure pcds
@ 2018-11-01 14:57 BobCF
  2018-11-29  0:20 ` Gao, Liming
  0 siblings, 1 reply; 5+ messages in thread
From: BobCF @ 2018-11-01 14:57 UTC (permalink / raw)
  To: edk2-devel; +Cc: Bob Feng, Liming Gao

V2:
Fixed the issue that V1 adds new check
to the Pcds in the platform unused library INF files.
It breaks the existing platform.

V1:
The current code handle all the structure pcds
even if there is no module or library use them.
This patch is going to filter out the unused structure pcds.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
---
 .../Source/Python/Workspace/DscBuildData.py   | 22 +++++++++++++++++++
 .../Source/Python/Workspace/InfBuildData.py   |  9 ++++++++
 .../Python/Workspace/WorkspaceDatabase.py     |  5 ++++-
 3 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py
index 6d596b2b54..5d25d20639 100644
--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
@@ -1467,10 +1467,11 @@ class DscBuildData(PlatformBuildClassObject):
                         if str_pcd_obj.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:
                             str_pcd_obj_str.DefaultFromDSC = {skuname:{defaultstore: str_pcd_obj.SkuInfoList[skuname].DefaultStoreDict.get(defaultstore, str_pcd_obj.SkuInfoList[skuname].HiiDefaultValue) for defaultstore in DefaultStores} for skuname in str_pcd_obj.SkuInfoList}
                         else:
                             str_pcd_obj_str.DefaultFromDSC = {skuname:{defaultstore: str_pcd_obj.SkuInfoList[skuname].DefaultStoreDict.get(defaultstore, str_pcd_obj.SkuInfoList[skuname].DefaultValue) for defaultstore in DefaultStores} for skuname in str_pcd_obj.SkuInfoList}
                     S_pcd_set[Pcd] = str_pcd_obj_str
+        self.FilterStrcturePcd(S_pcd_set)
         if S_pcd_set:
             GlobalData.gStructurePcd[self.Arch] = S_pcd_set
         for stru_pcd in S_pcd_set.values():
             for skuid in SkuIds:
                 if skuid in stru_pcd.SkuOverrideValues:
@@ -1562,10 +1563,31 @@ class DscBuildData(PlatformBuildClassObject):
                 elif TAB_DEFAULT in pcd.SkuInfoList and TAB_COMMON in pcd.SkuInfoList:
                     del pcd.SkuInfoList[TAB_COMMON]
 
         map(self.FilterSkuSettings, [Pcds[pcdkey] for pcdkey in Pcds if Pcds[pcdkey].Type in DynamicPcdType])
         return Pcds
+    @cached_property
+    def PlatformUsedPcds(self):
+        FdfInfList = []
+        if GlobalData.gFdfParser:
+            FdfInfList = GlobalData.gFdfParser.Profile.InfList
+        FdfModuleList = [PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch=self._Arch) for Inf in FdfInfList]
+        AllModulePcds = set()
+        ModuleSet = set(self._Modules.keys() + FdfModuleList)
+        for ModuleFile in ModuleSet:
+            ModuleData = self._Bdb[ModuleFile, self._Arch, self._Target, self._Toolchain]
+            AllModulePcds = AllModulePcds | ModuleData.PcdsName
+        for ModuleFile in self.LibraryInstances:
+            ModuleData = self._Bdb.CreateBuildObject(ModuleFile, self._Arch, self._Target, self._Toolchain)
+            AllModulePcds = AllModulePcds | ModuleData.PcdsName
+        return AllModulePcds
+
+    #Filter the StrucutrePcd that is not used by any module in dsc file and fdf file.
+    def FilterStrcturePcd(self, S_pcd_set):
+        UnusedStruPcds = set(S_pcd_set.keys()) - self.PlatformUsedPcds
+        for (Token, TokenSpaceGuid) in UnusedStruPcds:
+            del S_pcd_set[(Token, TokenSpaceGuid)]
 
     ## Retrieve non-dynamic PCD settings
     #
     #   @param  Type    PCD type
     #
diff --git a/BaseTools/Source/Python/Workspace/InfBuildData.py b/BaseTools/Source/Python/Workspace/InfBuildData.py
index d615cccdf7..99bbecfd1f 100644
--- a/BaseTools/Source/Python/Workspace/InfBuildData.py
+++ b/BaseTools/Source/Python/Workspace/InfBuildData.py
@@ -792,10 +792,19 @@ class InfBuildData(ModuleBuildClassObject):
         RetVal.update(self._GetPcd(MODEL_PCD_FEATURE_FLAG))
         RetVal.update(self._GetPcd(MODEL_PCD_DYNAMIC))
         RetVal.update(self._GetPcd(MODEL_PCD_DYNAMIC_EX))
         return RetVal
 
+    @cached_property
+    def PcdsName(self):
+        PcdsName = set()
+        for Type in (MODEL_PCD_FIXED_AT_BUILD,MODEL_PCD_PATCHABLE_IN_MODULE,MODEL_PCD_FEATURE_FLAG,MODEL_PCD_DYNAMIC,MODEL_PCD_DYNAMIC_EX):
+            RecordList = self._RawData[Type, self._Arch, self._Platform]
+            for TokenSpaceGuid, PcdCName, _, _, _, _, _ in RecordList:
+                PcdsName.add((PcdCName, TokenSpaceGuid))
+        return PcdsName
+
     ## Retrieve build options specific to this module
     @cached_property
     def BuildOptions(self):
         if self._BuildOptions is None:
             self._BuildOptions = OrderedDict()
diff --git a/BaseTools/Source/Python/Workspace/WorkspaceDatabase.py b/BaseTools/Source/Python/Workspace/WorkspaceDatabase.py
index 3bb287b8b2..c41922f6f9 100644
--- a/BaseTools/Source/Python/Workspace/WorkspaceDatabase.py
+++ b/BaseTools/Source/Python/Workspace/WorkspaceDatabase.py
@@ -104,10 +104,14 @@ class WorkspaceDatabase(object):
             Key = (FilePath, Arch, Target, Toolchain)
             if Key in self._CACHE_:
                 return self._CACHE_[Key]
 
             # check file type
+            BuildObject = self.CreateBuildObject(FilePath, Arch, Target, Toolchain)
+            self._CACHE_[Key] = BuildObject
+            return BuildObject
+        def CreateBuildObject(self,FilePath, Arch, Target, Toolchain):
             Ext = FilePath.Type
             if Ext not in self._FILE_TYPE_:
                 return None
             FileType = self._FILE_TYPE_[Ext]
             if FileType not in self._GENERATOR_:
@@ -129,11 +133,10 @@ class WorkspaceDatabase(object):
                                     self,
                                     Arch,
                                     Target,
                                     Toolchain
                                     )
-            self._CACHE_[Key] = BuildObject
             return BuildObject
 
     # placeholder for file format conversion
     class TransformObjectFactory:
         def __init__(self, WorkspaceDb):
-- 
2.18.0.windows.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Patch] BaseTool: Filter out unused structure pcds
  2018-11-01 14:57 BobCF
@ 2018-11-29  0:20 ` Gao, Liming
  0 siblings, 0 replies; 5+ messages in thread
From: Gao, Liming @ 2018-11-29  0:20 UTC (permalink / raw)
  To: Feng, Bob C, edk2-devel@lists.01.org

Reviewed-by: Liming Gao <liming.gao@intel.com>

>-----Original Message-----
>From: Feng, Bob C
>Sent: Thursday, November 01, 2018 10:57 PM
>To: edk2-devel@lists.01.org
>Cc: Feng, Bob C <bob.c.feng@intel.com>; Gao, Liming <liming.gao@intel.com>
>Subject: [Patch] BaseTool: Filter out unused structure pcds
>
>V2:
>Fixed the issue that V1 adds new check
>to the Pcds in the platform unused library INF files.
>It breaks the existing platform.
>
>V1:
>The current code handle all the structure pcds
>even if there is no module or library use them.
>This patch is going to filter out the unused structure pcds.
>
>Contributed-under: TianoCore Contribution Agreement 1.1
>Signed-off-by: Bob Feng <bob.c.feng@intel.com>
>Cc: Liming Gao <liming.gao@intel.com>
>---
> .../Source/Python/Workspace/DscBuildData.py   | 22
>+++++++++++++++++++
> .../Source/Python/Workspace/InfBuildData.py   |  9 ++++++++
> .../Python/Workspace/WorkspaceDatabase.py     |  5 ++++-
> 3 files changed, 35 insertions(+), 1 deletion(-)
>
>diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py
>b/BaseTools/Source/Python/Workspace/DscBuildData.py
>index 6d596b2b54..5d25d20639 100644
>--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
>+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
>@@ -1467,10 +1467,11 @@ class DscBuildData(PlatformBuildClassObject):
>                         if str_pcd_obj.Type in
>[self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII],
>self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:
>                             str_pcd_obj_str.DefaultFromDSC = {skuname:{defaultstore:
>str_pcd_obj.SkuInfoList[skuname].DefaultStoreDict.get(defaultstore,
>str_pcd_obj.SkuInfoList[skuname].HiiDefaultValue) for defaultstore in
>DefaultStores} for skuname in str_pcd_obj.SkuInfoList}
>                         else:
>                             str_pcd_obj_str.DefaultFromDSC = {skuname:{defaultstore:
>str_pcd_obj.SkuInfoList[skuname].DefaultStoreDict.get(defaultstore,
>str_pcd_obj.SkuInfoList[skuname].DefaultValue) for defaultstore in
>DefaultStores} for skuname in str_pcd_obj.SkuInfoList}
>                     S_pcd_set[Pcd] = str_pcd_obj_str
>+        self.FilterStrcturePcd(S_pcd_set)
>         if S_pcd_set:
>             GlobalData.gStructurePcd[self.Arch] = S_pcd_set
>         for stru_pcd in S_pcd_set.values():
>             for skuid in SkuIds:
>                 if skuid in stru_pcd.SkuOverrideValues:
>@@ -1562,10 +1563,31 @@ class DscBuildData(PlatformBuildClassObject):
>                 elif TAB_DEFAULT in pcd.SkuInfoList and TAB_COMMON in
>pcd.SkuInfoList:
>                     del pcd.SkuInfoList[TAB_COMMON]
>
>         map(self.FilterSkuSettings, [Pcds[pcdkey] for pcdkey in Pcds if
>Pcds[pcdkey].Type in DynamicPcdType])
>         return Pcds
>+    @cached_property
>+    def PlatformUsedPcds(self):
>+        FdfInfList = []
>+        if GlobalData.gFdfParser:
>+            FdfInfList = GlobalData.gFdfParser.Profile.InfList
>+        FdfModuleList = [PathClass(NormPath(Inf), GlobalData.gWorkspace,
>Arch=self._Arch) for Inf in FdfInfList]
>+        AllModulePcds = set()
>+        ModuleSet = set(self._Modules.keys() + FdfModuleList)
>+        for ModuleFile in ModuleSet:
>+            ModuleData = self._Bdb[ModuleFile, self._Arch, self._Target,
>self._Toolchain]
>+            AllModulePcds = AllModulePcds | ModuleData.PcdsName
>+        for ModuleFile in self.LibraryInstances:
>+            ModuleData = self._Bdb.CreateBuildObject(ModuleFile, self._Arch,
>self._Target, self._Toolchain)
>+            AllModulePcds = AllModulePcds | ModuleData.PcdsName
>+        return AllModulePcds
>+
>+    #Filter the StrucutrePcd that is not used by any module in dsc file and fdf
>file.
>+    def FilterStrcturePcd(self, S_pcd_set):
>+        UnusedStruPcds = set(S_pcd_set.keys()) - self.PlatformUsedPcds
>+        for (Token, TokenSpaceGuid) in UnusedStruPcds:
>+            del S_pcd_set[(Token, TokenSpaceGuid)]
>
>     ## Retrieve non-dynamic PCD settings
>     #
>     #   @param  Type    PCD type
>     #
>diff --git a/BaseTools/Source/Python/Workspace/InfBuildData.py
>b/BaseTools/Source/Python/Workspace/InfBuildData.py
>index d615cccdf7..99bbecfd1f 100644
>--- a/BaseTools/Source/Python/Workspace/InfBuildData.py
>+++ b/BaseTools/Source/Python/Workspace/InfBuildData.py
>@@ -792,10 +792,19 @@ class InfBuildData(ModuleBuildClassObject):
>         RetVal.update(self._GetPcd(MODEL_PCD_FEATURE_FLAG))
>         RetVal.update(self._GetPcd(MODEL_PCD_DYNAMIC))
>         RetVal.update(self._GetPcd(MODEL_PCD_DYNAMIC_EX))
>         return RetVal
>
>+    @cached_property
>+    def PcdsName(self):
>+        PcdsName = set()
>+        for Type in
>(MODEL_PCD_FIXED_AT_BUILD,MODEL_PCD_PATCHABLE_IN_MODULE,MO
>DEL_PCD_FEATURE_FLAG,MODEL_PCD_DYNAMIC,MODEL_PCD_DYNAMIC_E
>X):
>+            RecordList = self._RawData[Type, self._Arch, self._Platform]
>+            for TokenSpaceGuid, PcdCName, _, _, _, _, _ in RecordList:
>+                PcdsName.add((PcdCName, TokenSpaceGuid))
>+        return PcdsName
>+
>     ## Retrieve build options specific to this module
>     @cached_property
>     def BuildOptions(self):
>         if self._BuildOptions is None:
>             self._BuildOptions = OrderedDict()
>diff --git a/BaseTools/Source/Python/Workspace/WorkspaceDatabase.py
>b/BaseTools/Source/Python/Workspace/WorkspaceDatabase.py
>index 3bb287b8b2..c41922f6f9 100644
>--- a/BaseTools/Source/Python/Workspace/WorkspaceDatabase.py
>+++ b/BaseTools/Source/Python/Workspace/WorkspaceDatabase.py
>@@ -104,10 +104,14 @@ class WorkspaceDatabase(object):
>             Key = (FilePath, Arch, Target, Toolchain)
>             if Key in self._CACHE_:
>                 return self._CACHE_[Key]
>
>             # check file type
>+            BuildObject = self.CreateBuildObject(FilePath, Arch, Target, Toolchain)
>+            self._CACHE_[Key] = BuildObject
>+            return BuildObject
>+        def CreateBuildObject(self,FilePath, Arch, Target, Toolchain):
>             Ext = FilePath.Type
>             if Ext not in self._FILE_TYPE_:
>                 return None
>             FileType = self._FILE_TYPE_[Ext]
>             if FileType not in self._GENERATOR_:
>@@ -129,11 +133,10 @@ class WorkspaceDatabase(object):
>                                     self,
>                                     Arch,
>                                     Target,
>                                     Toolchain
>                                     )
>-            self._CACHE_[Key] = BuildObject
>             return BuildObject
>
>     # placeholder for file format conversion
>     class TransformObjectFactory:
>         def __init__(self, WorkspaceDb):
>--
>2.18.0.windows.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-11-29  0:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-10-19 12:00 [Patch] BaseTool: Filter out unused structure pcds BobCF
2018-10-19 14:34 ` Carsey, Jaben
2018-10-24 14:34 ` Gao, Liming
  -- strict thread matches above, loose matches on Subject: below --
2018-11-01 14:57 BobCF
2018-11-29  0:20 ` Gao, Liming

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox