Now, BaseTools always calculates StructurePcd value only if it
is declared in DEC file. In fact, it only needs to calculate
StructurePcd value only when this PCD is used by any module.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: ZhiqiangX Zhao <[email protected]>
Cc: Liming Gao <[email protected]>
Cc: Yonghong Zhu <[email protected]>
Cc: Bob Feng <[email protected]>
---
 BaseTools/Source/Python/Workspace/DscBuildData.py | 44 +++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py 
b/BaseTools/Source/Python/Workspace/DscBuildData.py
index 88ba415c5a..a0322b9a26 100644
--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
@@ -222,6 +222,7 @@ class DscBuildData(PlatformBuildClassObject):
         self.WorkspaceDir = os.getenv("WORKSPACE") if os.getenv("WORKSPACE") 
else ""
         self.DefaultStores = None
         self.SkuIdMgr = SkuClass(self.SkuName, self.SkuIds)
+        self.UsedStructurePcd   = None
     @property
     def OutputPath(self):
         if os.getenv("WORKSPACE"):
@@ -275,6 +276,7 @@ class DscBuildData(PlatformBuildClassObject):
         self._VpdToolGuid       = None
         self.__Macros           = None
         self.DefaultStores      = None
+        self.UsedStructurePcd   = None
 
 
     ## handle Override Path of Module
@@ -1357,6 +1359,7 @@ class DscBuildData(PlatformBuildClassObject):
         # handle pcd value override
         StrPcdSet = DscBuildData.GetStructurePcdInfo(S_PcdSet)
         S_pcd_set = OrderedDict()
+        DscPcd = []
         for str_pcd in StrPcdSet:
             str_pcd_obj = Pcds.get((str_pcd[1], str_pcd[0]), None)
             str_pcd_dec = self._DecPcds.get((str_pcd[1], str_pcd[0]), None)
@@ -1377,6 +1380,7 @@ class DscBuildData(PlatformBuildClassObject):
                     if str_pcd_data[3] in SkuIds:
                         str_pcd_obj_str.AddOverrideValue(str_pcd_data[2], 
str(str_pcd_data[6]), TAB_DEFAULT if str_pcd_data[3] == TAB_COMMON else 
str_pcd_data[3], TAB_DEFAULT_STORES_DEFAULT if str_pcd_data[4] == TAB_COMMON 
else str_pcd_data[4], self.MetaFile.File if self.WorkspaceDir not in 
self.MetaFile.File else self.MetaFile.File[len(self.WorkspaceDir) if 
self.WorkspaceDir.endswith(os.path.sep) else len(self.WorkspaceDir)+1:], 
LineNo=str_pcd_data[5])
                 S_pcd_set[str_pcd[1], str_pcd[0]] = str_pcd_obj_str
+                DscPcd.append((str_pcd[1], str_pcd[0]))
             else:
                 EdkLogger.error('build', PARSER_ERROR,
                             "Pcd (%s.%s) defined in DSC is not declared in DEC 
files. Arch: ['%s']" % (str_pcd[0], str_pcd[1], self._Arch),
@@ -1395,6 +1399,8 @@ class DscBuildData(PlatformBuildClassObject):
                         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
+        #Filter the StrucutrePcd that is not used by any module in dsc file 
and fdf file.
+        self.FilterStrcturePcd(DscPcd, S_pcd_set)
         if S_pcd_set:
             GlobalData.gStructurePcd[self.Arch] = S_pcd_set
         for stru_pcd in S_pcd_set.values():
@@ -1490,6 +1496,44 @@ class DscBuildData(PlatformBuildClassObject):
         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, DscPcd, S_pcd_set):
+        if not self.UsedStructurePcd:
+            DscModulePcd = []
+            for ModuleFile in self._Modules:
+                ModuleData = self._Bdb[ModuleFile, self._Arch, self._Target, 
self._Toolchain]
+                for key in ModuleData.Pcds.keys():
+                    if isinstance(self._DecPcds.get(key, None), StructurePcd):
+                        DscModulePcd.append(key)
+            FdfPcd = []
+            FdfModulePcd = []
+            FdfInfList = []
+            if GlobalData.gFdfParser:
+                FdfInfList = GlobalData.gFdfParser.Profile.InfList
+                fdfpcd = GlobalData.gFdfParser.Profile.PcdDict
+                fdfpcdlocation = GlobalData.gFdfParser.Profile.PcdLocalDict
+                for Name, Guid, Field in fdfpcd.keys() + fdfpcdlocation.keys():
+                    if isinstance(self._DecPcds.get((Name, Guid), None), 
StructurePcd):
+                        FdfPcd.append((Name, Guid))
+            for Inf in FdfInfList:
+                ModuleFile = PathClass(NormPath(Inf), GlobalData.gWorkspace, 
Arch=self._Arch)
+                if ModuleFile in self._Modules:
+                    continue
+                ModuleData = self._Bdb[ModuleFile, self._Arch, self._Target, 
self._Toolchain]
+                for key in ModuleData.Pcds.keys():
+                    if isinstance(self._DecPcds.get(key, None), StructurePcd):
+                        FdfModulePcd.append(key)
+            CommandPcd = []
+            if GlobalData.BuildOptionPcd:
+                for pcdTuple in GlobalData.BuildOptionPcd:
+                    TokenSpaceGuid, Token, Field = pcdTuple[0], pcdTuple[1], 
pcdTuple[2]
+                    if isinstance(self._DecPcds.get((Token, TokenSpaceGuid), 
None), StructurePcd):
+                        CommandPcd.append((Token, TokenSpaceGuid))
+            self.UsedStructurePcd = set(DscPcd + DscModulePcd + FdfPcd + 
FdfModulePcd + CommandPcd)
+        for (Token, TokenSpaceGuid) in S_pcd_set:
+            if (Token, TokenSpaceGuid) not in self.UsedStructurePcd:
+                del S_pcd_set[(Token, TokenSpaceGuid)]
+
     ## Retrieve non-dynamic PCD settings
     #
     #   @param  Type    PCD type
-- 
2.14.1.windows.1

_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to