]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/AutoGen/AutoGen.py
BaseTools: Remove the duplicate Pcd items
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / AutoGen.py
index dbcf662389e4f715fb1b4c9b7736a5a61d89c9bb..a7af33d520367110db63f82d73c7356fd221c3b7 100644 (file)
 ## Import Modules\r
 #\r
 from __future__ import print_function\r
+from __future__ import absolute_import\r
 import Common.LongFilePathOs as os\r
 import re\r
 import os.path as path\r
 import copy\r
 import uuid\r
 \r
-import GenC\r
-import GenMake\r
-import GenDepex\r
-from StringIO import StringIO\r
+from . import GenC\r
+from . import GenMake\r
+from . import GenDepex\r
+from io import BytesIO\r
 \r
-from StrGather import *\r
-from BuildEngine import BuildRule\r
+from .StrGather import *\r
+from .BuildEngine import BuildRule\r
 \r
 from Common.LongFilePathSupport import CopyLongFilePath\r
 from Common.BuildToolError import *\r
@@ -41,14 +42,14 @@ from CommonDataClass.CommonClass import SkuInfoClass
 from Workspace.BuildClassObject import *\r
 from GenPatchPcdTable.GenPatchPcdTable import parsePcdInfoFromMapFile\r
 import Common.VpdInfoFile as VpdInfoFile\r
-from GenPcdDb import CreatePcdDatabaseCode\r
+from .GenPcdDb import CreatePcdDatabaseCode\r
 from Workspace.MetaFileCommentParser import UsageList\r
 from Workspace.WorkspaceCommon import GetModuleLibInstances\r
 from Common.MultipleWorkspace import MultipleWorkspace as mws\r
-import InfSectionParser\r
+from . import InfSectionParser\r
 import datetime\r
 import hashlib\r
-from GenVar import VariableMgr,var_info\r
+from .GenVar import VariableMgr, var_info\r
 from collections import OrderedDict\r
 from collections import defaultdict\r
 from Workspace.WorkspaceCommon import OrderedListDict\r
@@ -241,7 +242,7 @@ class WorkspaceAutoGen(AutoGen):
             super(WorkspaceAutoGen, self).__init__(Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs)\r
             self._InitWorker(Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs)\r
             self._Init = True\r
-    \r
+\r
     ## Initialize WorkspaceAutoGen\r
     #\r
     #   @param  WorkspaceDir            Root directory of workspace\r
@@ -310,7 +311,7 @@ class WorkspaceAutoGen(AutoGen):
                             ExtraData="Build target [%s] is not supported by the platform. [Valid target: %s]"\r
                                       % (self.BuildTarget, " ".join(self.Platform.BuildTargets)))\r
 \r
-        \r
+\r
         # parse FDF file to get PCDs in it, if any\r
         if not self.FdfFile:\r
             self.FdfFile = self.Platform.FlashDefinition\r
@@ -568,7 +569,7 @@ class WorkspaceAutoGen(AutoGen):
                     DecPcdsKey.add((Pcd[0], Pcd[1], Pcd[2]))\r
 \r
             Platform.SkuName = self.SkuId\r
-            for Name, Guid in PcdSet:\r
+            for Name, Guid,Fileds in PcdSet:\r
                 if (Name, Guid) not in DecPcds:\r
                     EdkLogger.error(\r
                         'build',\r
@@ -582,7 +583,6 @@ class WorkspaceAutoGen(AutoGen):
                     if (Name, Guid, TAB_PCDS_FIXED_AT_BUILD) in DecPcdsKey \\r
                         or (Name, Guid, TAB_PCDS_PATCHABLE_IN_MODULE) in DecPcdsKey \\r
                         or (Name, Guid, TAB_PCDS_FEATURE_FLAG) in DecPcdsKey:\r
-                        Platform.AddPcd(Name, Guid, PcdSet[Name, Guid])\r
                         continue\r
                     elif (Name, Guid, TAB_PCDS_DYNAMIC) in DecPcdsKey or (Name, Guid, TAB_PCDS_DYNAMIC_EX) in DecPcdsKey:\r
                         EdkLogger.error(\r
@@ -763,7 +763,7 @@ class WorkspaceAutoGen(AutoGen):
 \r
     ## _CheckDuplicateInFV() method\r
     #\r
-    # Check whether there is duplicate modules/files exist in FV section. \r
+    # Check whether there is duplicate modules/files exist in FV section.\r
     # The check base on the file GUID;\r
     #\r
     def _CheckDuplicateInFV(self, Fdf):\r
@@ -794,7 +794,7 @@ class WorkspaceAutoGen(AutoGen):
                                                                                                                                    Module.Guid.upper()),\r
                                                     ExtraData=self.FdfFile)\r
                     #\r
-                    # Some INF files not have entity in DSC file. \r
+                    # Some INF files not have entity in DSC file.\r
                     #\r
                     if not InfFoundFlag:\r
                         if FfsFile.InfFileName.find('$') == -1:\r
@@ -804,7 +804,7 @@ class WorkspaceAutoGen(AutoGen):
 \r
                             PathClassObj = PathClass(FfsFile.InfFileName, self.WorkspaceDir)\r
                             #\r
-                            # Here we just need to get FILE_GUID from INF file, use 'COMMON' as ARCH attribute. and use \r
+                            # Here we just need to get FILE_GUID from INF file, use 'COMMON' as ARCH attribute. and use\r
                             # BuildObject from one of AutoGenObjectList is enough.\r
                             #\r
                             InfObj = self.AutoGenObjectList[0].BuildDatabase.WorkspaceDb.BuildObject[PathClassObj, TAB_ARCH_COMMON, self.BuildTarget, self.ToolChain]\r
@@ -823,7 +823,7 @@ class WorkspaceAutoGen(AutoGen):
 \r
                 if FfsFile.NameGuid is not None:\r
                     #\r
-                    # If the NameGuid reference a PCD name. \r
+                    # If the NameGuid reference a PCD name.\r
                     # The style must match: PCD(xxxx.yyy)\r
                     #\r
                     if gPCDAsGuidPattern.match(FfsFile.NameGuid):\r
@@ -900,7 +900,7 @@ class WorkspaceAutoGen(AutoGen):
             for Pcd in Pa.Platform.Pcds:\r
                 PcdType = Pa.Platform.Pcds[Pcd].Type\r
 \r
-                # If no PCD type, this PCD comes from FDF \r
+                # If no PCD type, this PCD comes from FDF\r
                 if not PcdType:\r
                     continue\r
 \r
@@ -992,14 +992,14 @@ class WorkspaceAutoGen(AutoGen):
     ## Check the PCDs token value conflict in each DEC file.\r
     #\r
     # Will cause build break and raise error message while two PCDs conflict.\r
-    # \r
+    #\r
     # @return  None\r
     #\r
     def _CheckAllPcdsTokenValueConflict(self):\r
         for Pa in self.AutoGenObjectList:\r
             for Package in Pa.PackageList:\r
                 PcdList = Package.Pcds.values()\r
-                PcdList.sort(lambda x, y: cmp(int(x.TokenValue, 0), int(y.TokenValue, 0))) \r
+                PcdList.sort(lambda x, y: cmp(int(x.TokenValue, 0), int(y.TokenValue, 0)))\r
                 Count = 0\r
                 while (Count < len(PcdList) - 1) :\r
                     Item = PcdList[Count]\r
@@ -1124,20 +1124,20 @@ class PlatformAutoGen(AutoGen):
             self._InitWorker(Workspace, MetaFile, Target, Toolchain, Arch)\r
             self._Init = True\r
     #\r
-    # Used to store all PCDs for both PEI and DXE phase, in order to generate \r
+    # Used to store all PCDs for both PEI and DXE phase, in order to generate\r
     # correct PCD database\r
-    # \r
+    #\r
     _DynaPcdList_ = []\r
     _NonDynaPcdList_ = []\r
     _PlatformPcds = {}\r
-    \r
+\r
     #\r
-    # The priority list while override build option \r
+    # The priority list while override build option\r
     #\r
     PrioList = {"0x11111"  : 16,     #  TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE (Highest)\r
                 "0x01111"  : 15,     #  ******_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE\r
                 "0x10111"  : 14,     #  TARGET_*********_ARCH_COMMANDTYPE_ATTRIBUTE\r
-                "0x00111"  : 13,     #  ******_*********_ARCH_COMMANDTYPE_ATTRIBUTE \r
+                "0x00111"  : 13,     #  ******_*********_ARCH_COMMANDTYPE_ATTRIBUTE\r
                 "0x11011"  : 12,     #  TARGET_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE\r
                 "0x01011"  : 11,     #  ******_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE\r
                 "0x10011"  : 10,     #  TARGET_*********_****_COMMANDTYPE_ATTRIBUTE\r
@@ -1289,26 +1289,31 @@ class PlatformAutoGen(AutoGen):
     #\r
     def CollectFixedAtBuildPcds(self):\r
         for LibAuto in self.LibraryAutoGenList:\r
-            FixedAtBuildPcds = {}  \r
-            ShareFixedAtBuildPcdsSameValue = {} \r
-            for Module in LibAuto._ReferenceModules:                \r
-                for Pcd in Module.FixedAtBuildPcds + LibAuto.FixedAtBuildPcds:\r
-                    key = ".".join((Pcd.TokenSpaceGuidCName,Pcd.TokenCName))  \r
+            FixedAtBuildPcds = {}\r
+            ShareFixedAtBuildPcdsSameValue = {}\r
+            for Module in LibAuto._ReferenceModules:\r
+                for Pcd in set(Module.FixedAtBuildPcds + LibAuto.FixedAtBuildPcds):\r
+                    DefaultValue = Pcd.DefaultValue\r
+                    # Cover the case: DSC component override the Pcd value and the Pcd only used in one Lib\r
+                    if Pcd in Module.LibraryPcdList:\r
+                        Index = Module.LibraryPcdList.index(Pcd)\r
+                        DefaultValue = Module.LibraryPcdList[Index].DefaultValue\r
+                    key = ".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName))\r
                     if key not in FixedAtBuildPcds:\r
                         ShareFixedAtBuildPcdsSameValue[key] = True\r
-                        FixedAtBuildPcds[key] = Pcd.DefaultValue\r
+                        FixedAtBuildPcds[key] = DefaultValue\r
                     else:\r
-                        if FixedAtBuildPcds[key] != Pcd.DefaultValue:\r
-                            ShareFixedAtBuildPcdsSameValue[key] = False      \r
+                        if FixedAtBuildPcds[key] != DefaultValue:\r
+                            ShareFixedAtBuildPcdsSameValue[key] = False\r
             for Pcd in LibAuto.FixedAtBuildPcds:\r
-                key = ".".join((Pcd.TokenSpaceGuidCName,Pcd.TokenCName))\r
-                if (Pcd.TokenCName,Pcd.TokenSpaceGuidCName) not in self.NonDynamicPcdDict:\r
+                key = ".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName))\r
+                if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) not in self.NonDynamicPcdDict:\r
                     continue\r
                 else:\r
-                    DscPcd = self.NonDynamicPcdDict[(Pcd.TokenCName,Pcd.TokenSpaceGuidCName)]\r
+                    DscPcd = self.NonDynamicPcdDict[(Pcd.TokenCName, Pcd.TokenSpaceGuidCName)]\r
                     if DscPcd.Type != TAB_PCDS_FIXED_AT_BUILD:\r
                         continue\r
-                if key in ShareFixedAtBuildPcdsSameValue and ShareFixedAtBuildPcdsSameValue[key]:                    \r
+                if key in ShareFixedAtBuildPcdsSameValue and ShareFixedAtBuildPcdsSameValue[key]:\r
                     LibAuto.ConstPcd[key] = FixedAtBuildPcds[key]\r
 \r
     def CollectVariables(self, DynamicPcdSet):\r
@@ -1325,12 +1330,12 @@ class PlatformAutoGen(AutoGen):
                         break\r
 \r
 \r
-        VariableInfo = VariableMgr(self.DscBuildDataObj._GetDefaultStores(),self.DscBuildDataObj._GetSkuIds())\r
+        VariableInfo = VariableMgr(self.DscBuildDataObj._GetDefaultStores(), self.DscBuildDataObj._GetSkuIds())\r
         VariableInfo.SetVpdRegionMaxSize(VpdRegionSize)\r
         VariableInfo.SetVpdRegionOffset(VpdRegionBase)\r
         Index = 0\r
         for Pcd in DynamicPcdSet:\r
-            pcdname = ".".join((Pcd.TokenSpaceGuidCName,Pcd.TokenCName))\r
+            pcdname = ".".join((Pcd.TokenSpaceGuidCName, Pcd.TokenCName))\r
             for SkuName in Pcd.SkuInfoList:\r
                 Sku = Pcd.SkuInfoList[SkuName]\r
                 SkuId = Sku.SkuId\r
@@ -1340,11 +1345,11 @@ class PlatformAutoGen(AutoGen):
                     VariableGuidStructure = Sku.VariableGuidValue\r
                     VariableGuid = GuidStructureStringToGuidString(VariableGuidStructure)\r
                     for StorageName in Sku.DefaultStoreDict:\r
-                        VariableInfo.append_variable(var_info(Index,pcdname,StorageName,SkuName, StringToArray(Sku.VariableName),VariableGuid, Sku.VariableOffset, Sku.VariableAttribute , Sku.HiiDefaultValue,Sku.DefaultStoreDict[StorageName],Pcd.DatumType))\r
+                        VariableInfo.append_variable(var_info(Index, pcdname, StorageName, SkuName, StringToArray(Sku.VariableName), VariableGuid, Sku.VariableOffset, Sku.VariableAttribute, Sku.HiiDefaultValue, Sku.DefaultStoreDict[StorageName], Pcd.DatumType))\r
             Index += 1\r
         return VariableInfo\r
 \r
-    def UpdateNVStoreMaxSize(self,OrgVpdFile):\r
+    def UpdateNVStoreMaxSize(self, OrgVpdFile):\r
         if self.VariableInfo:\r
             VpdMapFilePath = os.path.join(self.BuildDir, TAB_FV_DIRECTORY, "%s.map" % self.Platform.VpdToolGuid)\r
             PcdNvStoreDfBuffer = [item for item in self._DynamicPcdList if item.TokenCName == "PcdNvStoreDefaultValueBuffer" and item.TokenSpaceGuidCName == "gEfiMdeModulePkgTokenSpaceGuid"]\r
@@ -1357,7 +1362,7 @@ class PlatformAutoGen(AutoGen):
                 else:\r
                     EdkLogger.error("build", FILE_READ_FAILURE, "Can not find VPD map file %s to fix up VPD offset." % VpdMapFilePath)\r
 \r
-                NvStoreOffset = int(NvStoreOffset,16) if NvStoreOffset.upper().startswith("0X") else int(NvStoreOffset)\r
+                NvStoreOffset = int(NvStoreOffset, 16) if NvStoreOffset.upper().startswith("0X") else int(NvStoreOffset)\r
                 default_skuobj = PcdNvStoreDfBuffer[0].SkuInfoList.get(TAB_DEFAULT)\r
                 maxsize = self.VariableInfo.VpdRegionSize  - NvStoreOffset if self.VariableInfo.VpdRegionSize else len(default_skuobj.DefaultValue.split(","))\r
                 var_data = self.VariableInfo.PatchNVStoreDefaultMaxSize(maxsize)\r
@@ -1405,7 +1410,7 @@ class PlatformAutoGen(AutoGen):
         for F in self.Platform.Modules.keys():\r
             M = ModuleAutoGen(self.Workspace, F, self.BuildTarget, self.ToolChain, self.Arch, self.MetaFile)\r
             #GuidValue.update(M.Guids)\r
-            \r
+\r
             self.Platform.Modules[F].M = M\r
 \r
             for PcdFromModule in M.ModulePcdList + M.LibraryPcdList:\r
@@ -1417,27 +1422,27 @@ class PlatformAutoGen(AutoGen):
                 if M.IsBinaryModule == True:\r
                     PcdFromModule.IsFromBinaryInf = True\r
 \r
-                # Check the PCD from DSC or not \r
+                # Check the PCD from DSC or not\r
                 PcdFromModule.IsFromDsc = (PcdFromModule.TokenCName, PcdFromModule.TokenSpaceGuidCName) in self.Platform.Pcds\r
 \r
                 if PcdFromModule.Type in PCD_DYNAMIC_TYPE_SET or PcdFromModule.Type in PCD_DYNAMIC_EX_TYPE_SET:\r
                     if F.Path not in FdfModuleList:\r
-                        # If one of the Source built modules listed in the DSC is not listed \r
-                        # in FDF modules, and the INF lists a PCD can only use the PcdsDynamic \r
-                        # access method (it is only listed in the DEC file that declares the \r
+                        # If one of the Source built modules listed in the DSC is not listed\r
+                        # in FDF modules, and the INF lists a PCD can only use the PcdsDynamic\r
+                        # access method (it is only listed in the DEC file that declares the\r
                         # PCD as PcdsDynamic), then build tool will report warning message\r
-                        # notify the PI that they are attempting to build a module that must \r
-                        # be included in a flash image in order to be functional. These Dynamic \r
-                        # PCD will not be added into the Database unless it is used by other \r
+                        # notify the PI that they are attempting to build a module that must\r
+                        # be included in a flash image in order to be functional. These Dynamic\r
+                        # PCD will not be added into the Database unless it is used by other\r
                         # modules that are included in the FDF file.\r
                         if PcdFromModule.Type in PCD_DYNAMIC_TYPE_SET and \\r
                             PcdFromModule.IsFromBinaryInf == False:\r
                             # Print warning message to let the developer make a determine.\r
                             continue\r
-                        # If one of the Source built modules listed in the DSC is not listed in \r
-                        # FDF modules, and the INF lists a PCD can only use the PcdsDynamicEx \r
-                        # access method (it is only listed in the DEC file that declares the \r
-                        # PCD as PcdsDynamicEx), then DO NOT break the build; DO NOT add the \r
+                        # If one of the Source built modules listed in the DSC is not listed in\r
+                        # FDF modules, and the INF lists a PCD can only use the PcdsDynamicEx\r
+                        # access method (it is only listed in the DEC file that declares the\r
+                        # PCD as PcdsDynamicEx), then DO NOT break the build; DO NOT add the\r
                         # PCD to the Platform's PCD Database.\r
                         if PcdFromModule.Type in PCD_DYNAMIC_EX_TYPE_SET:\r
                             continue\r
@@ -1465,14 +1470,14 @@ class PlatformAutoGen(AutoGen):
                         PcdFromModule.Pending = False\r
                         self._NonDynaPcdList_.append (PcdFromModule)\r
         DscModuleSet = {os.path.normpath(ModuleInf.Path) for ModuleInf in self.Platform.Modules}\r
-        # add the PCD from modules that listed in FDF but not in DSC to Database \r
+        # add the PCD from modules that listed in FDF but not in DSC to Database\r
         for InfName in FdfModuleList:\r
             if InfName not in DscModuleSet:\r
                 InfClass = PathClass(InfName)\r
                 M = self.BuildDatabase[InfClass, self.Arch, self.BuildTarget, self.ToolChain]\r
-                # If a module INF in FDF but not in current arch's DSC module list, it must be module (either binary or source) \r
-                # for different Arch. PCDs in source module for different Arch is already added before, so skip the source module here. \r
-                # For binary module, if in current arch, we need to list the PCDs into database.   \r
+                # If a module INF in FDF but not in current arch's DSC module list, it must be module (either binary or source)\r
+                # for different Arch. PCDs in source module for different Arch is already added before, so skip the source module here.\r
+                # For binary module, if in current arch, we need to list the PCDs into database.\r
                 if not M.IsSupportedArch:\r
                     continue\r
                 # Override the module PCD setting by platform setting\r
@@ -1497,20 +1502,20 @@ class PlatformAutoGen(AutoGen):
                         self._NonDynaPcdList_.append(PcdFromModule)\r
                     if PcdFromModule in self._DynaPcdList_ and PcdFromModule.Phase == 'PEI' and PcdFromModule.Type in PCD_DYNAMIC_EX_TYPE_SET:\r
                         # Overwrite the phase of any the same PCD existing, if Phase is PEI.\r
-                        # It is to solve the case that a dynamic PCD used by a PEM module/PEI \r
+                        # It is to solve the case that a dynamic PCD used by a PEM module/PEI\r
                         # module & DXE module at a same time.\r
                         # Overwrite the type of the PCDs in source INF by the type of AsBuild\r
-                        # INF file as DynamicEx. \r
+                        # INF file as DynamicEx.\r
                         Index = self._DynaPcdList_.index(PcdFromModule)\r
                         self._DynaPcdList_[Index].Phase = PcdFromModule.Phase\r
                         self._DynaPcdList_[Index].Type = PcdFromModule.Type\r
         for PcdFromModule in self._NonDynaPcdList_:\r
-            # If a PCD is not listed in the DSC file, but binary INF files used by \r
-            # this platform all (that use this PCD) list the PCD in a [PatchPcds] \r
-            # section, AND all source INF files used by this platform the build \r
-            # that use the PCD list the PCD in either a [Pcds] or [PatchPcds] \r
+            # If a PCD is not listed in the DSC file, but binary INF files used by\r
+            # this platform all (that use this PCD) list the PCD in a [PatchPcds]\r
+            # section, AND all source INF files used by this platform the build\r
+            # that use the PCD list the PCD in either a [Pcds] or [PatchPcds]\r
             # section, then the tools must NOT add the PCD to the Platform's PCD\r
-            # Database; the build must assign the access method for this PCD as \r
+            # Database; the build must assign the access method for this PCD as\r
             # PcdsPatchableInModule.\r
             if PcdFromModule not in self._DynaPcdList_:\r
                 continue\r
@@ -1533,7 +1538,7 @@ class PlatformAutoGen(AutoGen):
         self._DynamicPcdList = self._DynaPcdList_\r
         #\r
         # Sort dynamic PCD list to:\r
-        # 1) If PCD's datum type is VOID* and value is unicode string which starts with L, the PCD item should \r
+        # 1) If PCD's datum type is VOID* and value is unicode string which starts with L, the PCD item should\r
         #    try to be put header of dynamicd List\r
         # 2) If PCD is HII type, the PCD item should be put after unicode type PCD\r
         #\r
@@ -1554,7 +1559,7 @@ class PlatformAutoGen(AutoGen):
             if self._PlatformPcds[item].DatumType and self._PlatformPcds[item].DatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, TAB_VOID, "BOOLEAN"]:\r
                 self._PlatformPcds[item].DatumType = TAB_VOID\r
 \r
-        if (self.Workspace.ArchList[-1] == self.Arch): \r
+        if (self.Workspace.ArchList[-1] == self.Arch):\r
             for Pcd in self._DynamicPcdList:\r
                 # just pick the a value to determine whether is unicode string type\r
                 Sku = Pcd.SkuInfoList.values()[0]\r
@@ -1569,7 +1574,7 @@ class PlatformAutoGen(AutoGen):
                     VpdPcdDict[(Pcd.TokenCName, Pcd.TokenSpaceGuidCName)] = Pcd\r
 \r
             #Collect DynamicHii PCD values and assign it to DynamicExVpd PCD gEfiMdeModulePkgTokenSpaceGuid.PcdNvStoreDefaultValueBuffer\r
-            PcdNvStoreDfBuffer = VpdPcdDict.get(("PcdNvStoreDefaultValueBuffer","gEfiMdeModulePkgTokenSpaceGuid"))\r
+            PcdNvStoreDfBuffer = VpdPcdDict.get(("PcdNvStoreDefaultValueBuffer", "gEfiMdeModulePkgTokenSpaceGuid"))\r
             if PcdNvStoreDfBuffer:\r
                 self.VariableInfo = self.CollectVariables(self._DynamicPcdList)\r
                 vardump = self.VariableInfo.dump()\r
@@ -1595,10 +1600,10 @@ class PlatformAutoGen(AutoGen):
                         PcdValue = DefaultSku.DefaultValue\r
                         if PcdValue not in SkuValueMap:\r
                             SkuValueMap[PcdValue] = []\r
-                            VpdFile.Add(Pcd, TAB_DEFAULT,DefaultSku.VpdOffset)\r
+                            VpdFile.Add(Pcd, TAB_DEFAULT, DefaultSku.VpdOffset)\r
                         SkuValueMap[PcdValue].append(DefaultSku)\r
 \r
-                    for (SkuName,Sku) in Pcd.SkuInfoList.items():\r
+                    for (SkuName, Sku) in Pcd.SkuInfoList.items():\r
                         Sku.VpdOffset = Sku.VpdOffset.strip()\r
                         PcdValue = Sku.DefaultValue\r
                         if PcdValue == "":\r
@@ -1624,7 +1629,7 @@ class PlatformAutoGen(AutoGen):
                                     EdkLogger.error("build", FORMAT_INVALID, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, Alignment))\r
                         if PcdValue not in SkuValueMap:\r
                             SkuValueMap[PcdValue] = []\r
-                            VpdFile.Add(Pcd, SkuName,Sku.VpdOffset)\r
+                            VpdFile.Add(Pcd, SkuName, Sku.VpdOffset)\r
                         SkuValueMap[PcdValue].append(Sku)\r
                         # if the offset of a VPD is *, then it need to be fixed up by third party tool.\r
                         if not NeedProcessVpdMapFile and Sku.VpdOffset == "*":\r
@@ -1637,7 +1642,7 @@ class PlatformAutoGen(AutoGen):
             #\r
             # Fix the PCDs define in VPD PCD section that never referenced by module.\r
             # An example is PCD for signature usage.\r
-            #            \r
+            #\r
             for DscPcd in PlatformPcds:\r
                 DscPcdEntry = self._PlatformPcds[DscPcd]\r
                 if DscPcdEntry.Type in [TAB_PCDS_DYNAMIC_VPD, TAB_PCDS_DYNAMIC_EX_VPD]:\r
@@ -1656,11 +1661,11 @@ class PlatformAutoGen(AutoGen):
                             SkuObjList = DscPcdEntry.SkuInfoList.items()\r
                             DefaultSku = DscPcdEntry.SkuInfoList.get(TAB_DEFAULT)\r
                             if DefaultSku:\r
-                                defaultindex = SkuObjList.index((TAB_DEFAULT,DefaultSku))\r
-                                SkuObjList[0],SkuObjList[defaultindex] = SkuObjList[defaultindex],SkuObjList[0]\r
-                            for (SkuName,Sku) in SkuObjList:\r
-                                Sku.VpdOffset = Sku.VpdOffset.strip() \r
-                                \r
+                                defaultindex = SkuObjList.index((TAB_DEFAULT, DefaultSku))\r
+                                SkuObjList[0], SkuObjList[defaultindex] = SkuObjList[defaultindex], SkuObjList[0]\r
+                            for (SkuName, Sku) in SkuObjList:\r
+                                Sku.VpdOffset = Sku.VpdOffset.strip()\r
+\r
                                 # Need to iterate DEC pcd information to get the value & datumtype\r
                                 for eachDec in self.PackageList:\r
                                     for DecPcd in eachDec.Pcds:\r
@@ -1671,8 +1676,8 @@ class PlatformAutoGen(AutoGen):
                                             EdkLogger.warn("build", "Unreferenced vpd pcd used!",\r
                                                             File=self.MetaFile, \\r
                                                             ExtraData = "PCD: %s.%s used in the DSC file %s is unreferenced." \\r
-                                                            %(DscPcdEntry.TokenSpaceGuidCName, DscPcdEntry.TokenCName, self.Platform.MetaFile.Path))  \r
-                                                                                  \r
+                                                            %(DscPcdEntry.TokenSpaceGuidCName, DscPcdEntry.TokenCName, self.Platform.MetaFile.Path))\r
+\r
                                             DscPcdEntry.DatumType    = DecPcdEntry.DatumType\r
                                             DscPcdEntry.DefaultValue = DecPcdEntry.DefaultValue\r
                                             DscPcdEntry.TokenValue = DecPcdEntry.TokenValue\r
@@ -1680,7 +1685,7 @@ class PlatformAutoGen(AutoGen):
                                             # Only fix the value while no value provided in DSC file.\r
                                             if not Sku.DefaultValue:\r
                                                 DscPcdEntry.SkuInfoList[DscPcdEntry.SkuInfoList.keys()[0]].DefaultValue = DecPcdEntry.DefaultValue\r
-                                                                                                                    \r
+\r
                                 if DscPcdEntry not in self._DynamicPcdList:\r
                                     self._DynamicPcdList.append(DscPcdEntry)\r
                                 Sku.VpdOffset = Sku.VpdOffset.strip()\r
@@ -1708,10 +1713,10 @@ class PlatformAutoGen(AutoGen):
                                             EdkLogger.error("build", FORMAT_INVALID, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (DscPcdEntry.TokenSpaceGuidCName, DscPcdEntry.TokenCName, Alignment))\r
                                 if PcdValue not in SkuValueMap:\r
                                     SkuValueMap[PcdValue] = []\r
-                                    VpdFile.Add(DscPcdEntry, SkuName,Sku.VpdOffset)\r
+                                    VpdFile.Add(DscPcdEntry, SkuName, Sku.VpdOffset)\r
                                 SkuValueMap[PcdValue].append(Sku)\r
                                 if not NeedProcessVpdMapFile and Sku.VpdOffset == "*":\r
-                                    NeedProcessVpdMapFile = True \r
+                                    NeedProcessVpdMapFile = True\r
                             if DscPcdEntry.DatumType == TAB_VOID and PcdValue.startswith("L"):\r
                                 UnicodePcdArray.add(DscPcdEntry)\r
                             elif len(Sku.VariableName) > 0:\r
@@ -1723,7 +1728,7 @@ class PlatformAutoGen(AutoGen):
                             VpdSkuMap[DscPcd] = SkuValueMap\r
             if (self.Platform.FlashDefinition is None or self.Platform.FlashDefinition == '') and \\r
                VpdFile.GetCount() != 0:\r
-                EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, \r
+                EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE,\r
                                 "Fail to get FLASH_DEFINITION definition in DSC file %s which is required when DSC contains VPD PCD." % str(self.Platform.MetaFile))\r
 \r
             if VpdFile.GetCount() != 0:\r
@@ -1774,17 +1779,17 @@ class PlatformAutoGen(AutoGen):
         self._DynamicPcdList.extend(list(UnicodePcdArray))\r
         self._DynamicPcdList.extend(list(HiiPcdArray))\r
         self._DynamicPcdList.extend(list(OtherPcdArray))\r
-        allskuset = [(SkuName,Sku.SkuId) for pcd in self._DynamicPcdList for (SkuName,Sku) in pcd.SkuInfoList.items()]\r
+        allskuset = [(SkuName, Sku.SkuId) for pcd in self._DynamicPcdList for (SkuName, Sku) in pcd.SkuInfoList.items()]\r
         for pcd in self._DynamicPcdList:\r
             if len(pcd.SkuInfoList) == 1:\r
-                for (SkuName,SkuId) in allskuset:\r
-                    if type(SkuId) in (str,unicode) and eval(SkuId) == 0 or SkuId == 0:\r
+                for (SkuName, SkuId) in allskuset:\r
+                    if type(SkuId) in (str, unicode) and eval(SkuId) == 0 or SkuId == 0:\r
                         continue\r
                     pcd.SkuInfoList[SkuName] = copy.deepcopy(pcd.SkuInfoList[TAB_DEFAULT])\r
                     pcd.SkuInfoList[SkuName].SkuId = SkuId\r
         self.AllPcdList = self._NonDynamicPcdList + self._DynamicPcdList\r
 \r
-    def FixVpdOffset(self,VpdFile ):\r
+    def FixVpdOffset(self, VpdFile ):\r
         FvPath = os.path.join(self.BuildDir, TAB_FV_DIRECTORY)\r
         if not os.path.exists(FvPath):\r
             try:\r
@@ -2050,7 +2055,7 @@ class PlatformAutoGen(AutoGen):
         if self._NonDynamicPcdDict:\r
             return self._NonDynamicPcdDict\r
         for Pcd in self.NonDynamicPcdList:\r
-            self._NonDynamicPcdDict[(Pcd.TokenCName,Pcd.TokenSpaceGuidCName)] = Pcd\r
+            self._NonDynamicPcdDict[(Pcd.TokenCName, Pcd.TokenSpaceGuidCName)] = Pcd\r
         return self._NonDynamicPcdDict\r
 \r
     ## Get list of non-dynamic PCDs\r
@@ -2071,9 +2076,9 @@ class PlatformAutoGen(AutoGen):
             self._PcdTokenNumber = OrderedDict()\r
             TokenNumber = 1\r
             #\r
-            # Make the Dynamic and DynamicEx PCD use within different TokenNumber area. \r
+            # Make the Dynamic and DynamicEx PCD use within different TokenNumber area.\r
             # Such as:\r
-            # \r
+            #\r
             # Dynamic PCD:\r
             # TokenNumber 0 ~ 10\r
             # DynamicEx PCD:\r
@@ -2388,7 +2393,7 @@ class PlatformAutoGen(AutoGen):
     #   @param  Options     Options to be expanded\r
     #\r
     #   @retval options     Options expanded\r
-    #      \r
+    #\r
     def _ExpandBuildOption(self, Options, ModuleStyle=None):\r
         BuildOptions = {}\r
         FamilyMatch  = False\r
@@ -2414,9 +2419,9 @@ class PlatformAutoGen(AutoGen):
                     if OverrideList.get(Key[1]) is not None:\r
                         OverrideList.pop(Key[1])\r
                     OverrideList[Key[1]] = Options[Key]\r
-        \r
+\r
         #\r
-        # Use the highest priority value. \r
+        # Use the highest priority value.\r
         #\r
         if (len(OverrideList) >= 2):\r
             KeyList = OverrideList.keys()\r
@@ -2427,7 +2432,7 @@ class PlatformAutoGen(AutoGen):
                     NextKey = KeyList[Index1 + Index + 1]\r
                     #\r
                     # Compare two Key, if one is included by another, choose the higher priority one\r
-                    #                    \r
+                    #\r
                     Target2, ToolChain2, Arch2, CommandType2, Attr2 = NextKey.split("_")\r
                     if (Target1 == Target2 or Target1 == "*" or Target2 == "*") and\\r
                         (ToolChain1 == ToolChain2 or ToolChain1 == "*" or ToolChain2 == "*") and\\r
@@ -2441,7 +2446,7 @@ class PlatformAutoGen(AutoGen):
                         else:\r
                             if Options.get((self.BuildRuleFamily, NowKey)) is not None:\r
                                 Options.pop((self.BuildRuleFamily, NowKey))\r
-                                                           \r
+\r
         for Key in Options:\r
             if ModuleStyle is not None and len (Key) > 2:\r
                 # Check Module style is EDK or EDKII.\r
@@ -2639,7 +2644,7 @@ class ModuleAutoGen(AutoGen):
                               % (MetaFile, Arch))\r
             return None\r
         return obj\r
-            \r
+\r
     ## Initialize ModuleAutoGen\r
     #\r
     #   @param      Workspace           EdkIIWorkspaceBuild object\r
@@ -2737,13 +2742,13 @@ class ModuleAutoGen(AutoGen):
 \r
         self.AutoGenDepSet = set()\r
 \r
-        \r
+\r
         ## The Modules referenced to this Library\r
         #  Only Library has this attribute\r
-        self._ReferenceModules        = []        \r
-        \r
+        self._ReferenceModules        = []\r
+\r
         ## Store the FixedAtBuild Pcds\r
-        #  \r
+        #\r
         self._FixedAtBuildPcds         = []\r
         self.ConstPcd                  = {}\r
 \r
@@ -2759,8 +2764,8 @@ class ModuleAutoGen(AutoGen):
                 continue\r
             if Pcd not in self._FixedAtBuildPcds:\r
                 self._FixedAtBuildPcds.append(Pcd)\r
-                \r
-        return self._FixedAtBuildPcds        \r
+\r
+        return self._FixedAtBuildPcds\r
 \r
     def _GetUniqueBaseName(self):\r
         BaseName = self.Name\r
@@ -2780,7 +2785,7 @@ class ModuleAutoGen(AutoGen):
             self._Macro = OrderedDict()\r
             self._Macro["WORKSPACE"             ] = self.WorkspaceDir\r
             self._Macro["MODULE_NAME"           ] = self.Name\r
-            self._Macro["MODULE_NAME_GUID"      ] = self._GetUniqueBaseName()\r
+            self._Macro["MODULE_NAME_GUID"      ] = self.UniqueBaseName\r
             self._Macro["MODULE_GUID"           ] = self.Guid\r
             self._Macro["MODULE_VERSION"        ] = self.Version\r
             self._Macro["MODULE_TYPE"           ] = self.ModuleType\r
@@ -2959,7 +2964,7 @@ class ModuleAutoGen(AutoGen):
                     continue\r
                 PackageList.append(Package)\r
         return PackageList\r
-    \r
+\r
     ## Get the depex string\r
     #\r
     # @return : a string contain all depex expresion.\r
@@ -2988,7 +2993,7 @@ class ModuleAutoGen(AutoGen):
                           (Arch.upper() == self.Arch.upper() and \\r
                           ModuleType.upper() in [TAB_ARCH_COMMON, self.ModuleType.upper()]):\r
                             DepexList.append({(Arch, ModuleType): DepexExpr})\r
-        \r
+\r
         #the type of build module is USER_DEFINED.\r
         if self.ModuleType.upper() == SUP_MODULE_USER_DEFINED:\r
             for Depex in DepexList:\r
@@ -2999,7 +3004,7 @@ class ModuleAutoGen(AutoGen):
             if not DepexStr:\r
                 return '[Depex.%s]\n' % self.Arch\r
             return DepexStr\r
-        \r
+\r
         #the type of build module not is USER_DEFINED.\r
         Count = 0\r
         for Depex in DepexList:\r
@@ -3019,7 +3024,7 @@ class ModuleAutoGen(AutoGen):
         if not DepexStr:\r
             return '[Depex.%s]\n' % self.Arch\r
         return '[Depex.%s]\n#  ' % self.Arch + DepexStr\r
-    \r
+\r
     ## Merge dependency expression\r
     #\r
     #   @retval     list    The token list of the dependency expression after parsed\r
@@ -3155,14 +3160,14 @@ class ModuleAutoGen(AutoGen):
                 #\r
                 self._BuildOptionIncPathList = []\r
                 return self._BuildOptionIncPathList\r
-            \r
+\r
             BuildOptionIncPathList = []\r
             for Tool in ('CC', 'PP', 'VFRPP', 'ASLPP', 'ASLCC', 'APP', 'ASM'):\r
                 try:\r
                     FlagOption = self.BuildOption[Tool]['FLAGS']\r
                 except KeyError:\r
                     FlagOption = ''\r
-                \r
+\r
                 if self.PlatformInfo.ToolChainFamily != 'RVCT':\r
                     IncPathList = [NormPath(Path, self.Macros) for Path in BuildOptIncludeRegEx.findall(FlagOption)]\r
                 else:\r
@@ -3175,7 +3180,7 @@ class ModuleAutoGen(AutoGen):
                         IncPathList.extend(NormPath(PathEntry, self.Macros) for PathEntry in PathList)\r
 \r
                 #\r
-                # EDK II modules must not reference header files outside of the packages they depend on or \r
+                # EDK II modules must not reference header files outside of the packages they depend on or\r
                 # within the module's directory tree. Report error if violation.\r
                 #\r
                 if self.AutoGenVersion >= 0x00010005:\r
@@ -3187,13 +3192,13 @@ class ModuleAutoGen(AutoGen):
                                             ExtraData=ErrMsg,\r
                                             File=str(self.MetaFile))\r
 \r
-                \r
+\r
                 BuildOptionIncPathList += IncPathList\r
-            \r
+\r
             self._BuildOptionIncPathList = BuildOptionIncPathList\r
-        \r
+\r
         return self._BuildOptionIncPathList\r
-        \r
+\r
     ## Return a list of files which can be built from source\r
     #\r
     #  What kind of files can be built is determined by build rules in\r
@@ -3202,14 +3207,16 @@ class ModuleAutoGen(AutoGen):
     def _GetSourceFileList(self):\r
         if self._SourceFileList is None:\r
             self._SourceFileList = []\r
+            ToolChainTagSet = {"", "*", self.ToolChain}\r
+            ToolChainFamilySet = {"", "*", self.ToolChainFamily, self.BuildRuleFamily}\r
             for F in self.Module.Sources:\r
                 # match tool chain\r
-                if F.TagName not in ("", "*", self.ToolChain):\r
+                if F.TagName not in ToolChainTagSet:\r
                     EdkLogger.debug(EdkLogger.DEBUG_9, "The toolchain [%s] for processing file [%s] is found, "\r
                                     "but [%s] is needed" % (F.TagName, str(F), self.ToolChain))\r
                     continue\r
                 # match tool chain family or build rule family\r
-                if F.ToolChainFamily not in ("", "*", self.ToolChainFamily, self.BuildRuleFamily):\r
+                if F.ToolChainFamily not in ToolChainFamilySet:\r
                     EdkLogger.debug(\r
                                 EdkLogger.DEBUG_0,\r
                                 "The file [%s] must be built by tools of [%s], " \\r
@@ -3245,7 +3252,7 @@ class ModuleAutoGen(AutoGen):
                 Order_Dict[F].sort(key=lambda i: self.BuildRuleOrder.index(i))\r
                 for Ext in Order_Dict[F][1:]:\r
                     RemoveList.append(F + Ext)\r
-                   \r
+\r
         for item in RemoveList:\r
             FileList.remove(item)\r
 \r
@@ -3437,8 +3444,8 @@ class ModuleAutoGen(AutoGen):
     def _GetAutoGenFileList(self):\r
         UniStringAutoGenC = True\r
         IdfStringAutoGenC = True\r
-        UniStringBinBuffer = StringIO()\r
-        IdfGenBinBuffer = StringIO()\r
+        UniStringBinBuffer = BytesIO()\r
+        IdfGenBinBuffer = BytesIO()\r
         if self.BuildType == 'UEFI_HII':\r
             UniStringAutoGenC = False\r
             IdfStringAutoGenC = False\r
@@ -3688,12 +3695,12 @@ class ModuleAutoGen(AutoGen):
         for SourceFile in self.Module.Sources:\r
             if SourceFile.Type.upper() == ".VFR" :\r
                 #\r
-                # search the .map file to find the offset of vfr binary in the PE32+/TE file. \r
+                # search the .map file to find the offset of vfr binary in the PE32+/TE file.\r
                 #\r
                 VfrUniBaseName[SourceFile.BaseName] = (SourceFile.BaseName + "Bin")\r
             elif SourceFile.Type.upper() == ".UNI" :\r
                 #\r
-                # search the .map file to find the offset of Uni strings binary in the PE32+/TE file. \r
+                # search the .map file to find the offset of Uni strings binary in the PE32+/TE file.\r
                 #\r
                 VfrUniBaseName["UniOffsetName"] = (self.Name + "Strings")\r
 \r
@@ -3711,10 +3718,10 @@ class ModuleAutoGen(AutoGen):
         try:\r
             fInputfile = open(UniVfrOffsetFileName, "wb+", 0)\r
         except:\r
-            EdkLogger.error("build", FILE_OPEN_FAILURE, "File open failed for %s" % UniVfrOffsetFileName,None)\r
+            EdkLogger.error("build", FILE_OPEN_FAILURE, "File open failed for %s" % UniVfrOffsetFileName, None)\r
 \r
-        # Use a instance of StringIO to cache data\r
-        fStringIO = StringIO('')  \r
+        # Use a instance of BytesIO to cache data\r
+        fStringIO = BytesIO('')\r
 \r
         for Item in VfrUniOffsetList:\r
             if (Item[0].find("Strings") != -1):\r
@@ -3725,7 +3732,7 @@ class ModuleAutoGen(AutoGen):
                 #\r
                 UniGuid = [0xe0, 0xc5, 0x13, 0x89, 0xf6, 0x33, 0x86, 0x4d, 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66]\r
                 UniGuid = [chr(ItemGuid) for ItemGuid in UniGuid]\r
-                fStringIO.write(''.join(UniGuid))            \r
+                fStringIO.write(''.join(UniGuid))\r
                 UniValue = pack ('Q', int (Item[1], 16))\r
                 fStringIO.write (UniValue)\r
             else:\r
@@ -3736,17 +3743,17 @@ class ModuleAutoGen(AutoGen):
                 #\r
                 VfrGuid = [0xb4, 0x7c, 0xbc, 0xd0, 0x47, 0x6a, 0x5f, 0x49, 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2]\r
                 VfrGuid = [chr(ItemGuid) for ItemGuid in VfrGuid]\r
-                fStringIO.write(''.join(VfrGuid))                   \r
+                fStringIO.write(''.join(VfrGuid))\r
                 VfrValue = pack ('Q', int (Item[1], 16))\r
                 fStringIO.write (VfrValue)\r
         #\r
         # write data into file.\r
         #\r
-        try :  \r
+        try :\r
             fInputfile.write (fStringIO.getvalue())\r
         except:\r
             EdkLogger.error("build", FILE_WRITE_FAILURE, "Write data to file %s failed, please check whether the "\r
-                            "file been locked or using by other applications." %UniVfrOffsetFileName,None)\r
+                            "file been locked or using by other applications." %UniVfrOffsetFileName, None)\r
 \r
         fStringIO.close ()\r
         fInputfile.close ()\r
@@ -3762,15 +3769,15 @@ class ModuleAutoGen(AutoGen):
 \r
         if self.IsAsBuiltInfCreated:\r
             return\r
-            \r
+\r
         # Skip the following code for EDK I inf\r
         if self.AutoGenVersion < 0x00010005:\r
             return\r
-            \r
+\r
         # Skip the following code for libraries\r
         if self.IsLibrary:\r
             return\r
-            \r
+\r
         # Skip the following code for modules with no source files\r
         if not self.SourceFileList:\r
             return\r
@@ -3778,7 +3785,7 @@ class ModuleAutoGen(AutoGen):
         # Skip the following code for modules without any binary files\r
         if self.BinaryFileList:\r
             return\r
-            \r
+\r
         ### TODO: How to handles mixed source and binary modules\r
 \r
         # Find all DynamicEx and PatchableInModule PCDs used by this module and dependent libraries\r
@@ -4027,11 +4034,9 @@ class ModuleAutoGen(AutoGen):
                     PcdItem = PcdComments + '\n  ' + PcdItem\r
                 AsBuiltInfDict['patchablepcd_item'].append(PcdItem)\r
 \r
-        HiiPcds = set()\r
         for Pcd in Pcds + VfrPcds:\r
             PcdCommentList = []\r
             HiiInfo = ''\r
-            SkuId = ''\r
             TokenCName = Pcd.TokenCName\r
             for PcdItem in GlobalData.MixedPcd:\r
                 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
@@ -4040,16 +4045,8 @@ class ModuleAutoGen(AutoGen):
             if Pcd.Type == TAB_PCDS_DYNAMIC_EX_HII:\r
                 for SkuName in Pcd.SkuInfoList:\r
                     SkuInfo = Pcd.SkuInfoList[SkuName]\r
-                    SkuId = SkuInfo.SkuId\r
                     HiiInfo = '## %s|%s|%s' % (SkuInfo.VariableName, SkuInfo.VariableGuid, SkuInfo.VariableOffset)\r
                     break\r
-            if SkuId:\r
-                #\r
-                # Don't generate duplicated HII PCD\r
-                #\r
-                if (SkuId, Pcd.TokenSpaceGuidCName, Pcd.TokenCName) in HiiPcds:\r
-                    continue\r
-                HiiPcds.add((SkuId, Pcd.TokenSpaceGuidCName, Pcd.TokenCName))\r
             if (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) in self._PcdComments:\r
                 PcdCommentList = self._PcdComments[Pcd.TokenSpaceGuidCName, Pcd.TokenCName][:]\r
             if HiiInfo:\r
@@ -4062,7 +4059,7 @@ class ModuleAutoGen(AutoGen):
                             UsageIndex = Index\r
                             break\r
                 if UsageIndex != -1:\r
-                    PcdCommentList[UsageIndex] = '## %s %s %s' % (UsageStr, HiiInfo, PcdCommentList[UsageIndex].replace(UsageStr, '')) \r
+                    PcdCommentList[UsageIndex] = '## %s %s %s' % (UsageStr, HiiInfo, PcdCommentList[UsageIndex].replace(UsageStr, ''))\r
                 else:\r
                     PcdCommentList.append('## UNDEFINED ' + HiiInfo)\r
             PcdComments = '\n  '.join(PcdCommentList)\r
@@ -4077,7 +4074,7 @@ class ModuleAutoGen(AutoGen):
         # Generated LibraryClasses section in comments.\r
         for Library in self.LibraryAutoGenList:\r
             AsBuiltInfDict['libraryclasses_item'].append(Library.MetaFile.File.replace('\\', '/'))\r
-        \r
+\r
         # Generated UserExtensions TianoCore section.\r
         # All tianocore user extensions are copied.\r
         UserExtStr = ''\r
@@ -4091,12 +4088,12 @@ class ModuleAutoGen(AutoGen):
         # Generated depex expression section in comments.\r
         DepexExpresion = self._GetDepexExpresionString()\r
         AsBuiltInfDict['depexsection_item'] = DepexExpresion if DepexExpresion else ''\r
-        \r
+\r
         AsBuiltInf = TemplateString()\r
         AsBuiltInf.Append(gAsBuiltInfHeaderString.Replace(AsBuiltInfDict))\r
-        \r
+\r
         SaveFileOnChange(os.path.join(self.OutputDir, self.Name + '.inf'), str(AsBuiltInf), False)\r
-        \r
+\r
         self.IsAsBuiltInfCreated = True\r
         if GlobalData.gBinCacheDest:\r
             self.CopyModuleToCache()\r
@@ -4181,7 +4178,7 @@ class ModuleAutoGen(AutoGen):
     def CopyBinaryFiles(self):\r
         for File in self.Module.Binaries:\r
             SrcPath = File.Path\r
-            DstPath = os.path.join(self.OutputDir , os.path.basename(SrcPath))\r
+            DstPath = os.path.join(self.OutputDir, os.path.basename(SrcPath))\r
             CopyLongFilePath(SrcPath, DstPath)\r
     ## Create autogen code for the module and its dependent libraries\r
     #\r
@@ -4317,11 +4314,14 @@ class ModuleAutoGen(AutoGen):
     def CanSkipbyHash(self):\r
         if GlobalData.gUseHashCache:\r
             return not self.GenModuleHash()\r
+        return False\r
 \r
     ## Decide whether we can skip the ModuleAutoGen process\r
     #  If any source file is newer than the module than we cannot skip\r
     #\r
     def CanSkip(self):\r
+        if self.MakeFileDir in GlobalData.gSikpAutoGenCache:\r
+            return True\r
         if not os.path.exists(self.GetTimeStampPath()):\r
             return False\r
         #last creation time of the module\r
@@ -4331,7 +4331,7 @@ class ModuleAutoGen(AutoGen):
         if SrcTimeStamp > DstTimeStamp:\r
             return False\r
 \r
-        with open(self.GetTimeStampPath(),'r') as f:\r
+        with open(self.GetTimeStampPath(), 'r') as f:\r
             for source in f:\r
                 source = source.rstrip('\n')\r
                 if not os.path.exists(source):\r
@@ -4340,6 +4340,7 @@ class ModuleAutoGen(AutoGen):
                     ModuleAutoGen.TimeDict[source] = os.stat(source)[8]\r
                 if ModuleAutoGen.TimeDict[source] > DstTimeStamp:\r
                     return False\r
+        GlobalData.gSikpAutoGenCache.add(self.MakeFileDir)\r
         return True\r
 \r
     def GetTimeStampPath(self):\r
@@ -4416,8 +4417,9 @@ class ModuleAutoGen(AutoGen):
     BuildOption             = property(_GetModuleBuildOption)\r
     BuildOptionIncPathList  = property(_GetBuildOptionIncPathList)\r
     BuildCommand            = property(_GetBuildCommand)\r
-    \r
+\r
     FixedAtBuildPcds         = property(_GetFixedAtBuildPcds)\r
+    UniqueBaseName          = property(_GetUniqueBaseName)\r
 \r
 # This acts like the main() function for the script, unless it is 'import'ed into another script.\r
 if __name__ == '__main__':\r