public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Zhaozh1x <zhiqiangx.zhao@intel.com>
To: edk2-devel@lists.01.org
Cc: Zhaozh1x <zhiqiangx.zhao@intel.com>,
	Liming Gao <liming.gao@intel.com>,
	Yonghong Zhu <yonghong.zhu@intel.com>,
	Bob Feng <bob.c.feng@intel.com>
Subject: [PATCH] BaseTools: Unused StructurePcd value is not requried to be calculated.
Date: Mon, 17 Sep 2018 14:51:20 +0800	[thread overview]
Message-ID: <20180917065120.26036-1-zhiqiangx.zhao@intel.com> (raw)

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 <zhiqiangx.zhao@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Cc: Bob Feng <bob.c.feng@intel.com>
---
 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



                 reply	other threads:[~2018-09-17  6:51 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180917065120.26036-1-zhiqiangx.zhao@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox