If a -D flag is passed into build that selects different lines in
[PcdsDynamicExVpd], then build does not see any changes to the timestamp
of the DSC file and the VPD tool is not used to regenerate the VPD
region based in the statements that are active. so we changed the detect
condition and use SaveFileOnChange function to generate VPD.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Yonghong Zhu <yonghong....@intel.com>
---
 BaseTools/Source/Python/AutoGen/AutoGen.py    |  7 +----
 BaseTools/Source/Python/Common/VpdInfoFile.py | 42 ++++++++++-----------------
 2 files changed, 16 insertions(+), 33 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py 
b/BaseTools/Source/Python/AutoGen/AutoGen.py
index dfb5b72..d9d7271 100644
--- a/BaseTools/Source/Python/AutoGen/AutoGen.py
+++ b/BaseTools/Source/Python/AutoGen/AutoGen.py
@@ -1240,25 +1240,20 @@ class PlatformAutoGen(AutoGen):
                VpdFile.GetCount() != 0:
                 EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, 
                                 "Fail to get FLASH_DEFINITION definition in 
DSC file %s which is required when DSC contains VPD PCD." % 
str(self.Platform.MetaFile))
 
             if VpdFile.GetCount() != 0:
-                DscTimeStamp = self.Platform.MetaFile.TimeStamp
                 FvPath = os.path.join(self.BuildDir, "FV")
                 if not os.path.exists(FvPath):
                     try:
                         os.makedirs(FvPath)
                     except:
                         EdkLogger.error("build", FILE_WRITE_FAILURE, "Fail to 
create FV folder under %s" % self.BuildDir)
 
-
                 VpdFilePath = os.path.join(FvPath, "%s.txt" % 
self.Platform.VpdToolGuid)
 
-
-                if not os.path.exists(VpdFilePath) or 
os.path.getmtime(VpdFilePath) < DscTimeStamp:
-                    VpdFile.Write(VpdFilePath)
-
+                if VpdFile.Write(VpdFilePath):
                     # retrieve BPDG tool's path from tool_def.txt according to 
VPD_TOOL_GUID defined in DSC file.
                     BPDGToolName = None
                     for ToolDef in self.ToolDefinition.values():
                         if ToolDef.has_key("GUID") and ToolDef["GUID"] == 
self.Platform.VpdToolGuid:
                             if not ToolDef.has_key("PATH"):
diff --git a/BaseTools/Source/Python/Common/VpdInfoFile.py 
b/BaseTools/Source/Python/Common/VpdInfoFile.py
index 1a68e9b..e303b4c 100644
--- a/BaseTools/Source/Python/Common/VpdInfoFile.py
+++ b/BaseTools/Source/Python/Common/VpdInfoFile.py
@@ -19,10 +19,11 @@ import Common.LongFilePathOs as os
 import re
 import Common.EdkLogger as EdkLogger
 import Common.BuildToolError as BuildToolError
 import subprocess
 from Common.LongFilePathSupport import OpenLongFilePath as open
+from Common.Misc import SaveFileOnChange
 
 FILE_COMMENT_TEMPLATE = \
 """
 ## @file
 #
@@ -122,38 +123,25 @@ class VpdInfoFile:
     #  @param FilePath        The given file path which would hold VPD 
information
     def Write(self, FilePath):
         if not (FilePath != None or len(FilePath) != 0):
             EdkLogger.error("VpdInfoFile", BuildToolError.PARAMETER_INVALID,  
                             "Invalid parameter FilePath: %s." % FilePath)      
  
-        try:
-            fd = open(FilePath, "w")
-        except:
-            EdkLogger.error("VpdInfoFile", 
-                            BuildToolError.FILE_OPEN_FAILURE, 
-                            "Fail to open file %s for written." % FilePath)
-        
-        try:
-            # write file header
-            fd.write(FILE_COMMENT_TEMPLATE)
 
-            # write each of PCD in VPD type
-            Pcds = self._VpdArray.keys()
-            Pcds.sort()
-            for Pcd in Pcds:
-                i = 0
-                for Offset in self._VpdArray[Pcd]:
-                    PcdValue = 
str(Pcd.SkuInfoList[Pcd.SkuInfoList.keys()[i]].DefaultValue).strip()
-                    if PcdValue == "" :
-                        PcdValue  = Pcd.DefaultValue
-                        
-                    fd.write("%s.%s|%s|%s|%s|%s  \n" % 
(Pcd.TokenSpaceGuidCName, Pcd.TokenCName, 
str(Pcd.SkuInfoList.keys()[i]),str(Offset).strip(), 
str(Pcd.MaxDatumSize).strip(),PcdValue))
-                    i += 1
-        except:
-            EdkLogger.error("VpdInfoFile",
-                            BuildToolError.FILE_WRITE_FAILURE,
-                            "Fail to write file %s" % FilePath) 
-        fd.close()
+        Content = FILE_COMMENT_TEMPLATE
+        Pcds = self._VpdArray.keys()
+        Pcds.sort()
+        for Pcd in Pcds:
+            i = 0
+            for Offset in self._VpdArray[Pcd]:
+                PcdValue = 
str(Pcd.SkuInfoList[Pcd.SkuInfoList.keys()[i]].DefaultValue).strip()
+                if PcdValue == "" :
+                    PcdValue  = Pcd.DefaultValue
+
+                Content += "%s.%s|%s|%s|%s|%s  \n" % (Pcd.TokenSpaceGuidCName, 
Pcd.TokenCName, str(Pcd.SkuInfoList.keys()[i]),str(Offset).strip(), 
str(Pcd.MaxDatumSize).strip(),PcdValue)
+                i += 1
+
+        return SaveFileOnChange(FilePath, Content, False)
 
     ## Read an existing VPD PCD info file.
     #
     #  This routine will read VPD PCD information from existing file and 
construct
     #  internal PcdClassObject array.
-- 
2.6.1.windows.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to