]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/AutoGen/AutoGen.py
BaseTools: replace 'UINT8','UINT16','UINT32','UINT64','VOID*' with shared constants.
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / AutoGen.py
index 3384fdb70b7ef2b1f292db5992e88ab6ba4a35fc..56b5d399727e4f68af31d654c4115047286267c6 100644 (file)
@@ -45,10 +45,22 @@ import InfSectionParser
 import datetime\r
 import hashlib\r
 from GenVar import VariableMgr,var_info\r
+from collections import OrderedDict\r
+from collections import defaultdict\r
 \r
 ## Regular expression for splitting Dependency Expression string into tokens\r
 gDepexTokenPattern = re.compile("(\(|\)|\w+| \S+\.inf)")\r
 \r
+## Regular expression for match: PCD(xxxx.yyy)\r
+gPCDAsGuidPattern = re.compile(r"^PCD\(.+\..+\)$")\r
+\r
+#\r
+# Regular expression for finding Include Directories, the difference between MSFT and INTEL/GCC/RVCT\r
+# is the former use /I , the Latter used -I to specify include directories\r
+#\r
+gBuildOptIncludePatternMsft = re.compile(r"(?:.*?)/I[ \t]*([^ ]*)", re.MULTILINE | re.DOTALL)\r
+gBuildOptIncludePatternOther = re.compile(r"(?:.*?)-I[ \t]*([^ ]*)", re.MULTILINE | re.DOTALL)\r
+\r
 #\r
 # Match name = variable\r
 #\r
@@ -244,16 +256,10 @@ class WorkspaceAutoGen(AutoGen):
     def _InitWorker(self, WorkspaceDir, ActivePlatform, Target, Toolchain, ArchList, MetaFileDb,\r
               BuildConfig, ToolDefinition, FlashDefinitionFile='', Fds=None, Fvs=None, Caps=None, SkuId='', UniFlag=None,\r
               Progress=None, BuildModule=None):\r
-        if Fds is None:\r
-            Fds = []\r
-        if Fvs is None:\r
-            Fvs = []\r
-        if Caps is None:\r
-            Caps = []\r
         self.BuildDatabase  = MetaFileDb\r
         self.MetaFile       = ActivePlatform\r
         self.WorkspaceDir   = WorkspaceDir\r
-        self.Platform       = self.BuildDatabase[self.MetaFile, 'COMMON', Target, Toolchain]\r
+        self.Platform       = self.BuildDatabase[self.MetaFile, TAB_COMMON, Target, Toolchain]\r
         GlobalData.gActivePlatform = self.Platform\r
         self.BuildTarget    = Target\r
         self.ToolChain      = Toolchain\r
@@ -264,9 +270,9 @@ class WorkspaceAutoGen(AutoGen):
         self.TargetTxt      = BuildConfig\r
         self.ToolDef        = ToolDefinition\r
         self.FdfFile        = FlashDefinitionFile\r
-        self.FdTargetList   = Fds\r
-        self.FvTargetList   = Fvs\r
-        self.CapTargetList  = Caps\r
+        self.FdTargetList   = Fds if Fds else []\r
+        self.FvTargetList   = Fvs if Fvs else []\r
+        self.CapTargetList  = Caps if Caps else []\r
         self.AutoGenObjectList = []\r
         self._BuildDir      = None\r
         self._FvDir         = None\r
@@ -349,13 +355,12 @@ class WorkspaceAutoGen(AutoGen):
             # but the path (self.MetaFile.Path) is the real path\r
             for key in self.FdfProfile.InfDict:\r
                 if key == 'ArchTBD':\r
-                    Platform_cache = {}\r
                     MetaFile_cache = {}\r
                     for Arch in self.ArchList:\r
-                        Platform_cache[Arch] = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain]\r
-                        MetaFile_cache[Arch] = []\r
-                        for Pkey in Platform_cache[Arch].Modules.keys():\r
-                            MetaFile_cache[Arch].append(Platform_cache[Arch].Modules[Pkey].MetaFile)\r
+                        Current_Platform_cache = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain]\r
+                        MetaFile_cache[Arch] = set()\r
+                        for Pkey in Current_Platform_cache.Modules:\r
+                            MetaFile_cache[Arch].add(Current_Platform_cache.Modules[Pkey].MetaFile)\r
                     for Inf in self.FdfProfile.InfDict[key]:\r
                         ModuleFile = PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch)\r
                         for Arch in self.ArchList:\r
@@ -370,9 +375,9 @@ class WorkspaceAutoGen(AutoGen):
                     for Arch in self.ArchList:\r
                         if Arch == key:\r
                             Platform = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain]\r
-                            MetaFileList = []\r
-                            for Pkey in Platform.Modules.keys():\r
-                                MetaFileList.append(Platform.Modules[Pkey].MetaFile)\r
+                            MetaFileList = set()\r
+                            for Pkey in Platform.Modules:\r
+                                MetaFileList.add(Platform.Modules[Pkey].MetaFile)\r
                             for Inf in self.FdfProfile.InfDict[key]:\r
                                 ModuleFile = PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch)\r
                                 if ModuleFile in MetaFileList:\r
@@ -398,14 +403,10 @@ class WorkspaceAutoGen(AutoGen):
         # apply SKU and inject PCDs from Flash Definition file\r
         for Arch in self.ArchList:\r
             Platform = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain]\r
-\r
-\r
-\r
-\r
-\r
-\r
-            SourcePcdDict = {'DynamicEx':[], 'PatchableInModule':[],'Dynamic':[],'FixedAtBuild':[]}\r
-            BinaryPcdDict = {'DynamicEx':[], 'PatchableInModule':[]}\r
+            PlatformPcds = Platform.Pcds\r
+            self._GuidDict = Platform._GuidDict\r
+            SourcePcdDict = {'DynamicEx':set(), 'PatchableInModule':set(),'Dynamic':set(),'FixedAtBuild':set()}\r
+            BinaryPcdDict = {'DynamicEx':set(), 'PatchableInModule':set()}\r
             SourcePcdDict_Keys = SourcePcdDict.keys()\r
             BinaryPcdDict_Keys = BinaryPcdDict.keys()\r
 \r
@@ -431,27 +432,21 @@ class WorkspaceAutoGen(AutoGen):
 \r
                         if 'DynamicEx' in BuildData.Pcds[key].Type:\r
                             if BuildData.IsBinaryModule:\r
-                                if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in BinaryPcdDict['DynamicEx']:\r
-                                    BinaryPcdDict['DynamicEx'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
+                                BinaryPcdDict['DynamicEx'].add((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
                             else:\r
-                                if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in SourcePcdDict['DynamicEx']:\r
-                                    SourcePcdDict['DynamicEx'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
+                                SourcePcdDict['DynamicEx'].add((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
 \r
                         elif 'PatchableInModule' in BuildData.Pcds[key].Type:\r
                             if BuildData.MetaFile.Ext == '.inf':\r
                                 if BuildData.IsBinaryModule:\r
-                                    if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in BinaryPcdDict['PatchableInModule']:\r
-                                        BinaryPcdDict['PatchableInModule'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
+                                    BinaryPcdDict['PatchableInModule'].add((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
                                 else:\r
-                                    if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in SourcePcdDict['PatchableInModule']:\r
-                                        SourcePcdDict['PatchableInModule'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
+                                    SourcePcdDict['PatchableInModule'].add((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
 \r
                         elif 'Dynamic' in BuildData.Pcds[key].Type:\r
-                            if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in SourcePcdDict['Dynamic']:\r
-                                SourcePcdDict['Dynamic'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
+                            SourcePcdDict['Dynamic'].add((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
                         elif 'FixedAtBuild' in BuildData.Pcds[key].Type:\r
-                            if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in SourcePcdDict['FixedAtBuild']:\r
-                                SourcePcdDict['FixedAtBuild'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
+                            SourcePcdDict['FixedAtBuild'].add((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
                 else:\r
                     pass\r
             #\r
@@ -460,16 +455,14 @@ class WorkspaceAutoGen(AutoGen):
             for i in SourcePcdDict_Keys:\r
                 for j in SourcePcdDict_Keys:\r
                     if i != j:\r
-                        IntersectionList = list(set(SourcePcdDict[i]).intersection(set(SourcePcdDict[j])))\r
-                        if len(IntersectionList) > 0:\r
+                        Intersections = SourcePcdDict[i].intersection(SourcePcdDict[j])\r
+                        if len(Intersections) > 0:\r
                             EdkLogger.error(\r
                             'build',\r
                             FORMAT_INVALID,\r
                             "Building modules from source INFs, following PCD use %s and %s access method. It must be corrected to use only one access method." % (i, j),\r
-                            ExtraData="%s" % '\n\t'.join([str(P[1]+'.'+P[0]) for P in IntersectionList])\r
+                            ExtraData="%s" % '\n\t'.join([str(P[1]+'.'+P[0]) for P in Intersections])\r
                             )\r
-                    else:\r
-                        pass\r
 \r
             #\r
             # intersection the BinaryPCD for Mixed PCD\r
@@ -477,8 +470,8 @@ class WorkspaceAutoGen(AutoGen):
             for i in BinaryPcdDict_Keys:\r
                 for j in BinaryPcdDict_Keys:\r
                     if i != j:\r
-                        IntersectionList = list(set(BinaryPcdDict[i]).intersection(set(BinaryPcdDict[j])))\r
-                        for item in IntersectionList:\r
+                        Intersections = BinaryPcdDict[i].intersection(BinaryPcdDict[j])\r
+                        for item in Intersections:\r
                             NewPcd1 = (item[0] + '_' + i, item[1])\r
                             NewPcd2 = (item[0] + '_' + j, item[1])\r
                             if item not in GlobalData.MixedPcd:\r
@@ -488,8 +481,6 @@ class WorkspaceAutoGen(AutoGen):
                                     GlobalData.MixedPcd[item].append(NewPcd1)\r
                                 if NewPcd2 not in GlobalData.MixedPcd[item]:\r
                                     GlobalData.MixedPcd[item].append(NewPcd2)\r
-                    else:\r
-                        pass\r
 \r
             #\r
             # intersection the SourcePCD and BinaryPCD for Mixed PCD\r
@@ -497,8 +488,8 @@ class WorkspaceAutoGen(AutoGen):
             for i in SourcePcdDict_Keys:\r
                 for j in BinaryPcdDict_Keys:\r
                     if i != j:\r
-                        IntersectionList = list(set(SourcePcdDict[i]).intersection(set(BinaryPcdDict[j])))\r
-                        for item in IntersectionList:\r
+                        Intersections = SourcePcdDict[i].intersection(BinaryPcdDict[j])\r
+                        for item in Intersections:\r
                             NewPcd1 = (item[0] + '_' + i, item[1])\r
                             NewPcd2 = (item[0] + '_' + j, item[1])\r
                             if item not in GlobalData.MixedPcd:\r
@@ -508,8 +499,6 @@ class WorkspaceAutoGen(AutoGen):
                                     GlobalData.MixedPcd[item].append(NewPcd1)\r
                                 if NewPcd2 not in GlobalData.MixedPcd[item]:\r
                                     GlobalData.MixedPcd[item].append(NewPcd2)\r
-                    else:\r
-                        pass\r
 \r
             for BuildData in PGen.BuildDatabase._CACHE_.values():\r
                 if BuildData.Arch != Arch:\r
@@ -530,11 +519,7 @@ class WorkspaceAutoGen(AutoGen):
                                     del BuildData.Pcds[key]\r
                                     BuildData.Pcds[newkey] = Value\r
                                     break\r
-                                else:\r
-                                    pass\r
                             break\r
-                        else:\r
-                            pass\r
 \r
             # handle the mixed pcd in FDF file\r
             for key in PcdSet:\r
@@ -553,11 +538,11 @@ class WorkspaceAutoGen(AutoGen):
                 ModuleData = self.BuildDatabase[ModuleFile, Arch, Target, Toolchain]\r
                 PkgSet.update(ModuleData.Packages)\r
             Pkgs = list(PkgSet) + list(PGen.PackageList)\r
-            DecPcds = {}\r
+            DecPcds = set()\r
             DecPcdsKey = set()\r
             for Pkg in Pkgs:\r
                 for Pcd in Pkg.Pcds:\r
-                    DecPcds[Pcd[0], Pcd[1]] = Pkg.Pcds[Pcd]\r
+                    DecPcds.add((Pcd[0], Pcd[1]))\r
                     DecPcdsKey.add((Pcd[0], Pcd[1], Pcd[2]))\r
 \r
             Platform.SkuName = self.SkuId\r
@@ -777,7 +762,7 @@ class WorkspaceAutoGen(AutoGen):
                         for Module in Pa.ModuleAutoGenList:\r
                             if path.normpath(Module.MetaFile.File) == path.normpath(FfsFile.InfFileName):\r
                                 InfFoundFlag = True\r
-                                if not Module.Guid.upper() in _GuidDict.keys():\r
+                                if Module.Guid.upper() not in _GuidDict:\r
                                     _GuidDict[Module.Guid.upper()] = FfsFile\r
                                     break\r
                                 else:\r
@@ -803,8 +788,8 @@ class WorkspaceAutoGen(AutoGen):
                             # 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, 'COMMON', self.BuildTarget, self.ToolChain]\r
-                            if not InfObj.Guid.upper() in _GuidDict.keys():\r
+                            InfObj = self.AutoGenObjectList[0].BuildDatabase.WorkspaceDb.BuildObject[PathClassObj, TAB_COMMON, self.BuildTarget, self.ToolChain]\r
+                            if InfObj.Guid.upper() not in _GuidDict:\r
                                 _GuidDict[InfObj.Guid.upper()] = FfsFile\r
                             else:\r
                                 EdkLogger.error("build",\r
@@ -818,13 +803,11 @@ class WorkspaceAutoGen(AutoGen):
                         InfFoundFlag = False\r
 \r
                 if FfsFile.NameGuid is not None:\r
-                    _CheckPCDAsGuidPattern = re.compile("^PCD\(.+\..+\)$")\r
-\r
                     #\r
                     # If the NameGuid reference a PCD name. \r
                     # The style must match: PCD(xxxx.yyy)\r
                     #\r
-                    if _CheckPCDAsGuidPattern.match(FfsFile.NameGuid):\r
+                    if gPCDAsGuidPattern.match(FfsFile.NameGuid):\r
                         #\r
                         # Replace the PCD value.\r
                         #\r
@@ -854,7 +837,7 @@ class WorkspaceAutoGen(AutoGen):
                                                             "The format of PCD value is incorrect. PCD: %s , Value: %s\n" % (_PcdName, PcdItem.DefaultValue),\r
                                                             ExtraData=self.FdfFile)\r
 \r
-                                        if not _PcdGuidString.upper() in _GuidDict.keys():\r
+                                        if _PcdGuidString.upper() not in _GuidDict:\r
                                             _GuidDict[_PcdGuidString.upper()] = FfsFile\r
                                             PcdFoundFlag = True\r
                                             break\r
@@ -868,7 +851,7 @@ class WorkspaceAutoGen(AutoGen):
                                                                                                                                            FfsFile.NameGuid.upper()),\r
                                                             ExtraData=self.FdfFile)\r
 \r
-                    if not FfsFile.NameGuid.upper() in _GuidDict.keys():\r
+                    if FfsFile.NameGuid.upper() not in _GuidDict:\r
                         _GuidDict[FfsFile.NameGuid.upper()] = FfsFile\r
                     else:\r
                         #\r
@@ -892,7 +875,7 @@ class WorkspaceAutoGen(AutoGen):
         ]\r
 \r
         # This dict store PCDs which are not used by any modules with specified arches\r
-        UnusedPcd = sdict()\r
+        UnusedPcd = OrderedDict()\r
         for Pa in self.AutoGenObjectList:\r
             # Key of DSC's Pcds dictionary is PcdCName, TokenSpaceGuid\r
             for Pcd in Pa.Platform.Pcds:\r
@@ -1306,7 +1289,7 @@ class PlatformAutoGen(AutoGen):
                     if DscPcd.Type != "FixedAtBuild":\r
                         continue\r
                 if key in ShareFixedAtBuildPcdsSameValue and ShareFixedAtBuildPcdsSameValue[key]:                    \r
-                    LibAuto.ConstPcd[key] = Pcd.DefaultValue\r
+                    LibAuto.ConstPcd[key] = FixedAtBuildPcds[key]\r
 \r
     def CollectVariables(self, DynamicPcdSet):\r
 \r
@@ -1355,7 +1338,7 @@ class PlatformAutoGen(AutoGen):
                     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
-                default_skuobj = PcdNvStoreDfBuffer[0].SkuInfoList.get("DEFAULT")\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
 \r
@@ -1363,7 +1346,7 @@ class PlatformAutoGen(AutoGen):
                     default_skuobj.DefaultValue = var_data\r
                     PcdNvStoreDfBuffer[0].DefaultValue = var_data\r
                     PcdNvStoreDfBuffer[0].SkuInfoList.clear()\r
-                    PcdNvStoreDfBuffer[0].SkuInfoList['DEFAULT'] = default_skuobj\r
+                    PcdNvStoreDfBuffer[0].SkuInfoList[TAB_DEFAULT] = default_skuobj\r
                     PcdNvStoreDfBuffer[0].MaxDatumSize = str(len(default_skuobj.DefaultValue.split(",")))\r
 \r
         return OrgVpdFile\r
@@ -1399,8 +1382,6 @@ class PlatformAutoGen(AutoGen):
 \r
         # for gathering error information\r
         NoDatumTypePcdList = set()\r
-        PcdNotInDb = []\r
-        self._GuidValue = {}\r
         FdfModuleList = []\r
         for InfName in self._AsBuildInfList:\r
             InfName = mws.join(self.WorkspaceDir, InfName)\r
@@ -1413,7 +1394,7 @@ class PlatformAutoGen(AutoGen):
 \r
             for PcdFromModule in M.ModulePcdList + M.LibraryPcdList:\r
                 # make sure that the "VOID*" kind of datum has MaxDatumSize set\r
-                if PcdFromModule.DatumType == "VOID*" and PcdFromModule.MaxDatumSize in [None, '']:\r
+                if PcdFromModule.DatumType == TAB_VOID and PcdFromModule.MaxDatumSize in [None, '']:\r
                     NoDatumTypePcdList.add("%s.%s [%s]" % (PcdFromModule.TokenSpaceGuidCName, PcdFromModule.TokenCName, F))\r
 \r
                 # Check the PCD from Binary INF or Source INF\r
@@ -1421,10 +1402,8 @@ class PlatformAutoGen(AutoGen):
                     PcdFromModule.IsFromBinaryInf = True\r
 \r
                 # Check the PCD from DSC or not \r
-                if (PcdFromModule.TokenCName, PcdFromModule.TokenSpaceGuidCName) in self.Platform.Pcds.keys():\r
-                    PcdFromModule.IsFromDsc = True\r
-                else:\r
-                    PcdFromModule.IsFromDsc = False\r
+                PcdFromModule.IsFromDsc = (PcdFromModule.TokenCName, PcdFromModule.TokenSpaceGuidCName) in self.Platform.Pcds\r
+\r
                 if PcdFromModule.Type in GenC.gDynamicPcd or PcdFromModule.Type in GenC.gDynamicExPcd:\r
                     if F.Path not in FdfModuleList:\r
                         # If one of the Source built modules listed in the DSC is not listed \r
@@ -1438,8 +1417,6 @@ class PlatformAutoGen(AutoGen):
                         if PcdFromModule.Type in GenC.gDynamicPcd and \\r
                             PcdFromModule.IsFromBinaryInf == False:\r
                             # Print warning message to let the developer make a determine.\r
-                            if PcdFromModule not in PcdNotInDb:\r
-                                PcdNotInDb.append(PcdFromModule)\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
@@ -1447,8 +1424,6 @@ class PlatformAutoGen(AutoGen):
                         # 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 GenC.gDynamicExPcd:\r
-                            if PcdFromModule not in PcdNotInDb:\r
-                                PcdNotInDb.append(PcdFromModule)\r
                             continue\r
                     #\r
                     # If a dynamic PCD used by a PEM module/PEI module & DXE module,\r
@@ -1473,13 +1448,10 @@ class PlatformAutoGen(AutoGen):
                         self._NonDynaPcdList_.remove (self._NonDynaPcdList_[Index])\r
                         PcdFromModule.Pending = False\r
                         self._NonDynaPcdList_.append (PcdFromModule)\r
-        # Parse the DynamicEx PCD from the AsBuild INF module list of FDF.\r
-        DscModuleList = []\r
-        for ModuleInf in self.Platform.Modules.keys():\r
-            DscModuleList.append (os.path.normpath(ModuleInf.Path))\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
         for InfName in FdfModuleList:\r
-            if InfName not in DscModuleList:\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
@@ -1499,7 +1471,7 @@ class PlatformAutoGen(AutoGen):
                                         ExtraData="\n\tExisted %s PCD %s in:\n\t\t%s\n"\r
                                         % (PcdFromModule.Type, PcdFromModule.TokenCName, InfName))\r
                     # make sure that the "VOID*" kind of datum has MaxDatumSize set\r
-                    if PcdFromModule.DatumType == "VOID*" and PcdFromModule.MaxDatumSize in [None, '']:\r
+                    if PcdFromModule.DatumType == TAB_VOID and PcdFromModule.MaxDatumSize in [None, '']:\r
                         NoDatumTypePcdList.add("%s.%s [%s]" % (PcdFromModule.TokenSpaceGuidCName, PcdFromModule.TokenCName, InfName))\r
                     if M.ModuleType in ["PEIM", "PEI_CORE"]:\r
                         PcdFromModule.Phase = "PEI"\r
@@ -1558,22 +1530,22 @@ class PlatformAutoGen(AutoGen):
         VpdFile               = VpdInfoFile.VpdInfoFile()\r
         NeedProcessVpdMapFile = False\r
 \r
-        for pcd in self.Platform.Pcds.keys():\r
-            if pcd not in self._PlatformPcds.keys():\r
+        for pcd in self.Platform.Pcds:\r
+            if pcd not in self._PlatformPcds:\r
                 self._PlatformPcds[pcd] = self.Platform.Pcds[pcd]\r
 \r
         for item in self._PlatformPcds:\r
             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 = "VOID*"\r
+                self._PlatformPcds[item].DatumType = TAB_VOID\r
 \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[Pcd.SkuInfoList.keys()[0]]\r
+                Sku = Pcd.SkuInfoList.values()[0]\r
                 Sku.VpdOffset = Sku.VpdOffset.strip()\r
 \r
                 if Pcd.DatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, TAB_VOID, "BOOLEAN"]:\r
-                    Pcd.DatumType = "VOID*"\r
+                    Pcd.DatumType = TAB_VOID\r
 \r
                     # if found PCD which datum value is unicode string the insert to left size of UnicodeIndex\r
                     # if found HII type PCD then insert to right of UnicodeIndex\r
@@ -1603,12 +1575,12 @@ class PlatformAutoGen(AutoGen):
                    PcdKey in VpdPcdDict:\r
                     Pcd = VpdPcdDict[PcdKey]\r
                     SkuValueMap = {}\r
-                    DefaultSku = Pcd.SkuInfoList.get('DEFAULT')\r
+                    DefaultSku = Pcd.SkuInfoList.get(TAB_DEFAULT)\r
                     if DefaultSku:\r
                         PcdValue = DefaultSku.DefaultValue\r
                         if PcdValue not in SkuValueMap:\r
                             SkuValueMap[PcdValue] = []\r
-                            VpdFile.Add(Pcd, '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
@@ -1656,7 +1628,7 @@ class PlatformAutoGen(AutoGen):
                 if DscPcdEntry.Type in [TAB_PCDS_DYNAMIC_VPD, TAB_PCDS_DYNAMIC_EX_VPD]:\r
                     if not (self.Platform.VpdToolGuid is None or self.Platform.VpdToolGuid == ''):\r
                         FoundFlag = False\r
-                        for VpdPcd in VpdFile._VpdArray.keys():\r
+                        for VpdPcd in VpdFile._VpdArray:\r
                             # This PCD has been referenced by module\r
                             if (VpdPcd.TokenSpaceGuidCName == DscPcdEntry.TokenSpaceGuidCName) and \\r
                                (VpdPcd.TokenCName == DscPcdEntry.TokenCName):\r
@@ -1667,9 +1639,9 @@ class PlatformAutoGen(AutoGen):
                             # just pick the a value to determine whether is unicode string type\r
                             SkuValueMap = {}\r
                             SkuObjList = DscPcdEntry.SkuInfoList.items()\r
-                            DefaultSku = DscPcdEntry.SkuInfoList.get('DEFAULT')\r
+                            DefaultSku = DscPcdEntry.SkuInfoList.get(TAB_DEFAULT)\r
                             if DefaultSku:\r
-                                defaultindex = SkuObjList.index(('DEFAULT',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
@@ -1691,7 +1663,7 @@ class PlatformAutoGen(AutoGen):
                                             DscPcdEntry.TokenValue = DecPcdEntry.TokenValue\r
                                             DscPcdEntry.TokenSpaceGuidValue = eachDec.Guids[DecPcdEntry.TokenSpaceGuidCName]\r
                                             # Only fix the value while no value provided in DSC file.\r
-                                            if (Sku.DefaultValue == "" or Sku.DefaultValue==None):\r
+                                            if not Sku.DefaultValue:\r
                                                 DscPcdEntry.SkuInfoList[DscPcdEntry.SkuInfoList.keys()[0]].DefaultValue = DecPcdEntry.DefaultValue\r
                                                                                                                     \r
                                 if DscPcdEntry not in self._DynamicPcdList:\r
@@ -1725,7 +1697,7 @@ class PlatformAutoGen(AutoGen):
                                 SkuValueMap[PcdValue].append(Sku)\r
                                 if not NeedProcessVpdMapFile and Sku.VpdOffset == "*":\r
                                     NeedProcessVpdMapFile = True \r
-                            if DscPcdEntry.DatumType == 'VOID*' and PcdValue.startswith("L"):\r
+                            if DscPcdEntry.DatumType == TAB_VOID and PcdValue.startswith("L"):\r
                                 UnicodePcdArray.add(DscPcdEntry)\r
                             elif len(Sku.VariableName) > 0:\r
                                 HiiPcdArray.add(DscPcdEntry)\r
@@ -1768,14 +1740,14 @@ class PlatformAutoGen(AutoGen):
             # Delete the DynamicPcdList At the last time enter into this function\r
             for Pcd in self._DynamicPcdList:\r
                 # just pick the a value to determine whether is unicode string type\r
-                Sku = Pcd.SkuInfoList[Pcd.SkuInfoList.keys()[0]]\r
+                Sku = Pcd.SkuInfoList.values()[0]\r
                 Sku.VpdOffset = Sku.VpdOffset.strip()\r
 \r
                 if Pcd.DatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, TAB_VOID, "BOOLEAN"]:\r
-                    Pcd.DatumType = "VOID*"\r
+                    Pcd.DatumType = TAB_VOID\r
 \r
                 PcdValue = Sku.DefaultValue\r
-                if Pcd.DatumType == 'VOID*' and PcdValue.startswith("L"):\r
+                if Pcd.DatumType == TAB_VOID and PcdValue.startswith("L"):\r
                     # if found PCD which datum value is unicode string the insert to left size of UnicodeIndex\r
                     UnicodePcdArray.add(Pcd)\r
                 elif len(Sku.VariableName) > 0:\r
@@ -1793,7 +1765,7 @@ class PlatformAutoGen(AutoGen):
                 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['DEFAULT'])\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
@@ -1929,7 +1901,6 @@ class PlatformAutoGen(AutoGen):
                 self._ToolDefinitions[Tool][Attr] = Value\r
 \r
             ToolsDef = ''\r
-            MakePath = ''\r
             if GlobalData.gOptions.SilentMode and "MAKE" in self._ToolDefinitions:\r
                 if "FLAGS" not in self._ToolDefinitions["MAKE"]:\r
                     self._ToolDefinitions["MAKE"]["FLAGS"] = ""\r
@@ -1950,9 +1921,7 @@ class PlatformAutoGen(AutoGen):
 \r
                     if Attr == "PATH":\r
                         # Don't put MAKE definition in the file\r
-                        if Tool == "MAKE":\r
-                            MakePath = Value\r
-                        else:\r
+                        if Tool != "MAKE":\r
                             ToolsDef += "%s = %s\n" % (Tool, Value)\r
                     elif Attr != "DLL":\r
                         # Don't put MAKE definition in the file\r
@@ -2084,7 +2053,7 @@ class PlatformAutoGen(AutoGen):
     ## Generate Token Number for all PCD\r
     def _GetPcdTokenNumbers(self):\r
         if self._PcdTokenNumber is None:\r
-            self._PcdTokenNumber = sdict()\r
+            self._PcdTokenNumber = OrderedDict()\r
             TokenNumber = 1\r
             #\r
             # Make the Dynamic and DynamicEx PCD use within different TokenNumber area. \r
@@ -2207,8 +2176,8 @@ class PlatformAutoGen(AutoGen):
         # EdkII module\r
         LibraryConsumerList = [Module]\r
         Constructor         = []\r
-        ConsumedByList      = sdict()\r
-        LibraryInstance     = sdict()\r
+        ConsumedByList      = OrderedDict()\r
+        LibraryInstance     = OrderedDict()\r
 \r
         EdkLogger.verbose("")\r
         EdkLogger.verbose("Library instances of module [%s] [%s]:" % (str(Module), self.Arch))\r
@@ -2372,17 +2341,16 @@ class PlatformAutoGen(AutoGen):
                                              ToPcd.Type, Module, FromPcd.Type),\r
                                           File=self.MetaFile)\r
 \r
-            if FromPcd.MaxDatumSize not in [None, '']:\r
+            if FromPcd.MaxDatumSize:\r
                 ToPcd.MaxDatumSize = FromPcd.MaxDatumSize\r
-            if FromPcd.DefaultValue not in [None, '']:\r
+                ToPcd.MaxSizeUserSet = FromPcd.MaxDatumSize\r
+            if FromPcd.DefaultValue:\r
                 ToPcd.DefaultValue = FromPcd.DefaultValue\r
-            if FromPcd.TokenValue not in [None, '']:\r
+            if FromPcd.TokenValue:\r
                 ToPcd.TokenValue = FromPcd.TokenValue\r
-            if FromPcd.MaxDatumSize not in [None, '']:\r
-                ToPcd.MaxDatumSize = FromPcd.MaxDatumSize\r
-            if FromPcd.DatumType not in [None, '']:\r
+            if FromPcd.DatumType:\r
                 ToPcd.DatumType = FromPcd.DatumType\r
-            if FromPcd.SkuInfoList not in [None, '', []]:\r
+            if FromPcd.SkuInfoList:\r
                 ToPcd.SkuInfoList = FromPcd.SkuInfoList\r
             # Add Flexible PCD format parse\r
             if ToPcd.DefaultValue:\r
@@ -2401,7 +2369,7 @@ class PlatformAutoGen(AutoGen):
             ToPcd.validlists = FromPcd.validlists\r
             ToPcd.expressions = FromPcd.expressions\r
 \r
-        if FromPcd is not None and ToPcd.DatumType == "VOID*" and ToPcd.MaxDatumSize in ['', None]:\r
+        if FromPcd is not None and ToPcd.DatumType == TAB_VOID and ToPcd.MaxDatumSize in ['', None]:\r
             EdkLogger.debug(EdkLogger.DEBUG_9, "No MaxDatumSize specified for PCD %s.%s" \\r
                             % (ToPcd.TokenSpaceGuidCName, TokenCName))\r
             Value = ToPcd.DefaultValue\r
@@ -2420,7 +2388,7 @@ class PlatformAutoGen(AutoGen):
             if self.Platform.SkuName in self.Platform.SkuIds:\r
                 SkuName = self.Platform.SkuName\r
             else:\r
-                SkuName = 'DEFAULT'\r
+                SkuName = TAB_DEFAULT\r
             ToPcd.SkuInfoList = {\r
                 SkuName : SkuInfoClass(SkuName, self.Platform.SkuIds[SkuName][0], '', '', '', '', '', ToPcd.DefaultValue)\r
             }\r
@@ -2477,7 +2445,8 @@ class PlatformAutoGen(AutoGen):
         # use PCD value to calculate the MaxDatumSize when it is not specified\r
         for Name, Guid in Pcds:\r
             Pcd = Pcds[Name, Guid]\r
-            if Pcd.DatumType == "VOID*" and Pcd.MaxDatumSize in ['', None]:\r
+            if Pcd.DatumType == TAB_VOID and Pcd.MaxDatumSize in ['', None]:\r
+                Pcd.MaxSizeUserSet = None\r
                 Value = Pcd.DefaultValue\r
                 if Value in [None, '']:\r
                     Pcd.MaxDatumSize = '1'\r
@@ -2511,7 +2480,7 @@ class PlatformAutoGen(AutoGen):
             for LibraryName in M.Libraries:\r
                 Library = self.Platform.LibraryClasses[LibraryName, ':dummy:']\r
                 if Library is None:\r
-                    for Key in self.Platform.LibraryClasses.data.keys():\r
+                    for Key in self.Platform.LibraryClasses.data:\r
                         if LibraryName.upper() == Key.upper():\r
                             Library = self.Platform.LibraryClasses[Key, ':dummy:']\r
                             break\r
@@ -2708,40 +2677,31 @@ class PlatformAutoGen(AutoGen):
         AllTools = set(ModuleOptions.keys() + PlatformOptions.keys() +\r
                        PlatformModuleOptions.keys() + ModuleTypeOptions.keys() +\r
                        self.ToolDefinition.keys())\r
-        BuildOptions = {}\r
+        BuildOptions = defaultdict(lambda: defaultdict(str))\r
         for Tool in AllTools:\r
-            if Tool not in BuildOptions:\r
-                BuildOptions[Tool] = {}\r
-\r
             for Options in [self.ToolDefinition, ModuleOptions, PlatformOptions, ModuleTypeOptions, PlatformModuleOptions]:\r
                 if Tool not in Options:\r
                     continue\r
                 for Attr in Options[Tool]:\r
-                    Value = Options[Tool][Attr]\r
                     #\r
                     # Do not generate it in Makefile\r
                     #\r
                     if Attr == TAB_TOD_DEFINES_BUILDRULEORDER:\r
                         continue\r
-                    if Attr not in BuildOptions[Tool]:\r
-                        BuildOptions[Tool][Attr] = ""\r
+                    Value = Options[Tool][Attr]\r
                     # check if override is indicated\r
                     if Value.startswith('='):\r
-                        ToolPath = Value[1:]\r
-                        ToolPath = mws.handleWsMacro(ToolPath)\r
-                        BuildOptions[Tool][Attr] = ToolPath\r
+                        BuildOptions[Tool][Attr] = mws.handleWsMacro(Value[1:])\r
                     else:\r
-                        Value = mws.handleWsMacro(Value)\r
                         if Attr != 'PATH':\r
-                            BuildOptions[Tool][Attr] += " " + Value\r
+                            BuildOptions[Tool][Attr] += " " + mws.handleWsMacro(Value)\r
                         else:\r
-                            BuildOptions[Tool][Attr] = Value\r
+                            BuildOptions[Tool][Attr] = mws.handleWsMacro(Value)\r
+\r
         if Module.AutoGenVersion < 0x00010005 and self.Workspace.UniFlag is not None:\r
             #\r
             # Override UNI flag only for EDK module.\r
             #\r
-            if 'BUILD' not in BuildOptions:\r
-                BuildOptions['BUILD'] = {}\r
             BuildOptions['BUILD']['FLAGS'] = self.Workspace.UniFlag\r
         return BuildOptions, BuildRuleOrder\r
 \r
@@ -2819,7 +2779,7 @@ class ModuleAutoGen(AutoGen):
 \r
         self.Workspace = Workspace\r
         self.WorkspaceDir = Workspace.WorkspaceDir\r
-\r
+        self._GuidDict = Workspace._GuidDict\r
         self.MetaFile = ModuleFile\r
         self.PlatformInfo = PlatformAutoGen(Workspace, PlatformFile, Target, Toolchain, Arch)\r
 \r
@@ -2880,14 +2840,14 @@ class ModuleAutoGen(AutoGen):
         self._DerivedPackageList      = None\r
         self._ModulePcdList           = None\r
         self._LibraryPcdList          = None\r
-        self._PcdComments = sdict()\r
+        self._PcdComments = OrderedDict()\r
         self._GuidList                = None\r
         self._GuidsUsedByPcd = None\r
-        self._GuidComments = sdict()\r
+        self._GuidComments = OrderedDict()\r
         self._ProtocolList            = None\r
-        self._ProtocolComments = sdict()\r
+        self._ProtocolComments = OrderedDict()\r
         self._PpiList                 = None\r
-        self._PpiComments = sdict()\r
+        self._PpiComments = OrderedDict()\r
         self._DepexList               = None\r
         self._DepexExpressionList     = None\r
         self._BuildOption             = None\r
@@ -2943,7 +2903,7 @@ class ModuleAutoGen(AutoGen):
     # Macros could be used in build_rule.txt (also Makefile)\r
     def _GetMacros(self):\r
         if self._Macro is None:\r
-            self._Macro = sdict()\r
+            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
@@ -3143,7 +3103,7 @@ class ModuleAutoGen(AutoGen):
             InfObj = InfSectionParser.InfSectionParser(Filename)\r
             DepexExpresionList = InfObj.GetDepexExpresionList()\r
             for DepexExpresion in DepexExpresionList:\r
-                for key in DepexExpresion.keys():\r
+                for key in DepexExpresion:\r
                     Arch, ModuleType = key\r
                     DepexExpr = [x for x in DepexExpresion[key] if not str(x).startswith('#')]\r
                     # the type of build module is USER_DEFINED.\r
@@ -3161,7 +3121,7 @@ class ModuleAutoGen(AutoGen):
         #the type of build module is USER_DEFINED.\r
         if self.ModuleType.upper() == SUP_MODULE_USER_DEFINED:\r
             for Depex in DepexList:\r
-                for key in Depex.keys():\r
+                for key in Depex:\r
                     DepexStr += '[Depex.%s.%s]\n' % key\r
                     DepexStr += '\n'.join(['# '+ val for val in Depex[key]])\r
                     DepexStr += '\n\n'\r
@@ -3271,7 +3231,7 @@ class ModuleAutoGen(AutoGen):
             InfObj = InfSectionParser.InfSectionParser(Filename)\r
             TianoCoreUserExtenList = InfObj.GetUserExtensionTianoCore()\r
             for TianoCoreUserExtent in TianoCoreUserExtenList:\r
-                for Section in TianoCoreUserExtent.keys():\r
+                for Section in TianoCoreUserExtent:\r
                     ItemList = Section.split(TAB_SPLIT)\r
                     Arch = self.Arch\r
                     if len(ItemList) == 4:\r
@@ -3315,9 +3275,9 @@ class ModuleAutoGen(AutoGen):
             # is the former use /I , the Latter used -I to specify include directories\r
             #\r
             if self.PlatformInfo.ToolChainFamily in ('MSFT'):\r
-                gBuildOptIncludePattern = re.compile(r"(?:.*?)/I[ \t]*([^ ]*)", re.MULTILINE | re.DOTALL)\r
+                BuildOptIncludeRegEx = gBuildOptIncludePatternMsft\r
             elif self.PlatformInfo.ToolChainFamily in ('INTEL', 'GCC', 'RVCT'):\r
-                gBuildOptIncludePattern = re.compile(r"(?:.*?)-I[ \t]*([^ ]*)", re.MULTILINE | re.DOTALL)\r
+                BuildOptIncludeRegEx = gBuildOptIncludePatternOther\r
             else:\r
                 #\r
                 # New ToolChainFamily, don't known whether there is option to specify include directories\r
@@ -3334,13 +3294,13 @@ class ModuleAutoGen(AutoGen):
                     FlagOption = ''\r
                 \r
                 if self.PlatformInfo.ToolChainFamily != 'RVCT':\r
-                    IncPathList = [NormPath(Path, self.Macros) for Path in gBuildOptIncludePattern.findall(FlagOption)]\r
+                    IncPathList = [NormPath(Path, self.Macros) for Path in BuildOptIncludeRegEx.findall(FlagOption)]\r
                 else:\r
                     #\r
                     # RVCT may specify a list of directory seperated by commas\r
                     #\r
                     IncPathList = []\r
-                    for Path in gBuildOptIncludePattern.findall(FlagOption):\r
+                    for Path in BuildOptIncludeRegEx.findall(FlagOption):\r
                         PathList = GetSplitList(Path, TAB_COMMA_SPLIT)\r
                         IncPathList += [NormPath(PathEntry, self.Macros) for PathEntry in PathList]\r
 \r
@@ -3458,7 +3418,7 @@ class ModuleAutoGen(AutoGen):
         if self._BinaryFileList is None:\r
             self._BinaryFileList = []\r
             for F in self.Module.Binaries:\r
-                if F.Target not in ['COMMON', '*'] and F.Target != self.BuildTarget:\r
+                if F.Target not in [TAB_COMMON, '*'] and F.Target != self.BuildTarget:\r
                     continue\r
                 self._BinaryFileList.append(F)\r
                 self._ApplyBuildRule(F, F.Type)\r
@@ -3495,8 +3455,8 @@ class ModuleAutoGen(AutoGen):
         if self._BuildTargets is None:\r
             self._IntroBuildTargetList = set()\r
             self._FinalBuildTargetList = set()\r
-            self._BuildTargets = {}\r
-            self._FileTypes = {}\r
+            self._BuildTargets = defaultdict(set)\r
+            self._FileTypes = defaultdict(set)\r
 \r
         SubDirectory = os.path.join(self.OutputDir, File.SubDir)\r
         if not os.path.exists(SubDirectory):\r
@@ -3533,8 +3493,6 @@ class ModuleAutoGen(AutoGen):
                 break\r
 \r
             FileType = RuleObject.SourceFileType\r
-            if FileType not in self._FileTypes:\r
-                self._FileTypes[FileType] = set()\r
             self._FileTypes[FileType].add(Source)\r
 \r
             # stop at STATIC_LIBRARY for library\r
@@ -3552,8 +3510,6 @@ class ModuleAutoGen(AutoGen):
                 # Only do build for target with outputs\r
                 self._FinalBuildTargetList.add(Target)\r
 \r
-            if FileType not in self._BuildTargets:\r
-                self._BuildTargets[FileType] = set()\r
             self._BuildTargets[FileType].add(Target)\r
 \r
             if not Source.IsBinary and Source == File:\r
@@ -3572,8 +3528,8 @@ class ModuleAutoGen(AutoGen):
         if self._BuildTargets is None:\r
             self._IntroBuildTargetList = set()\r
             self._FinalBuildTargetList = set()\r
-            self._BuildTargets = {}\r
-            self._FileTypes = {}\r
+            self._BuildTargets = defaultdict(set)\r
+            self._FileTypes = defaultdict(set)\r
 \r
         #TRICK: call _GetSourceFileList to apply build rule for source files\r
         if self.SourceFileList:\r
@@ -3695,7 +3651,7 @@ class ModuleAutoGen(AutoGen):
     #\r
     def _GetLibraryPcdList(self):\r
         if self._LibraryPcdList is None:\r
-            Pcds = sdict()\r
+            Pcds = OrderedDict()\r
             if not self.IsLibrary:\r
                 # get PCDs from dependent libraries\r
                 for Library in self.DependentLibraryList:\r
@@ -3717,7 +3673,7 @@ class ModuleAutoGen(AutoGen):
     #\r
     def _GetGuidList(self):\r
         if self._GuidList is None:\r
-            self._GuidList = sdict()\r
+            self._GuidList = OrderedDict()\r
             self._GuidList.update(self.Module.Guids)\r
             for Library in self.DependentLibraryList:\r
                 self._GuidList.update(Library.Guids)\r
@@ -3727,7 +3683,7 @@ class ModuleAutoGen(AutoGen):
 \r
     def GetGuidsUsedByPcd(self):\r
         if self._GuidsUsedByPcd is None:\r
-            self._GuidsUsedByPcd = sdict()\r
+            self._GuidsUsedByPcd = OrderedDict()\r
             self._GuidsUsedByPcd.update(self.Module.GetGuidsUsedByPcd())\r
             for Library in self.DependentLibraryList:\r
                 self._GuidsUsedByPcd.update(Library.GetGuidsUsedByPcd())\r
@@ -3738,7 +3694,7 @@ class ModuleAutoGen(AutoGen):
     #\r
     def _GetProtocolList(self):\r
         if self._ProtocolList is None:\r
-            self._ProtocolList = sdict()\r
+            self._ProtocolList = OrderedDict()\r
             self._ProtocolList.update(self.Module.Protocols)\r
             for Library in self.DependentLibraryList:\r
                 self._ProtocolList.update(Library.Protocols)\r
@@ -3752,7 +3708,7 @@ class ModuleAutoGen(AutoGen):
     #\r
     def _GetPpiList(self):\r
         if self._PpiList is None:\r
-            self._PpiList = sdict()\r
+            self._PpiList = OrderedDict()\r
             self._PpiList.update(self.Module.Ppis)\r
             for Library in self.DependentLibraryList:\r
                 self._PpiList.update(Library.Ppis)\r
@@ -3813,7 +3769,7 @@ class ModuleAutoGen(AutoGen):
         if not self.SourceFileList:\r
             return []\r
 \r
-        NameGuids = []\r
+        NameGuids = set()\r
         for SrcFile in self.SourceFileList:\r
             if SrcFile.Ext.lower() != '.vfr':\r
                 continue\r
@@ -3845,7 +3801,7 @@ class ModuleAutoGen(AutoGen):
                 if not Guid:\r
                     break\r
                 NameArray = ConvertStringToByteArray('L"' + Name.group(1) + '"')\r
-                NameGuids.append((NameArray, GuidStructureStringToGuidString(Guid.group(1))))\r
+                NameGuids.add((NameArray, GuidStructureStringToGuidString(Guid.group(1))))\r
                 Pos = Content.find('efivarstore', Name.end())\r
         if not NameGuids:\r
             return []\r
@@ -3920,7 +3876,6 @@ class ModuleAutoGen(AutoGen):
                 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
-                type (Item[1]) \r
                 VfrValue = pack ('Q', int (Item[1], 16))\r
                 fStringIO.write (VfrValue)\r
         #\r
@@ -3939,7 +3894,7 @@ class ModuleAutoGen(AutoGen):
     ## Create AsBuilt INF file the module\r
     #\r
     def CreateAsBuiltInf(self, IsOnlyCopy = False):\r
-        self.OutputFile = []\r
+        self.OutputFile = set()\r
         if IsOnlyCopy:\r
             if GlobalData.gBinCacheDest:\r
                 self.CopyModuleToCache()\r
@@ -3957,11 +3912,11 @@ class ModuleAutoGen(AutoGen):
             return\r
             \r
         # Skip the following code for modules with no source files\r
-        if self.SourceFileList is None or self.SourceFileList == []:\r
+        if not self.SourceFileList:\r
             return\r
 \r
         # Skip the following code for modules without any binary files\r
-        if self.BinaryFileList <> None and self.BinaryFileList <> []:\r
+        if not self.BinaryFileList:\r
             return\r
             \r
         ### TODO: How to handles mixed source and binary modules\r
@@ -3983,7 +3938,7 @@ class ModuleAutoGen(AutoGen):
                     PcdCheckList.append((Pcd.TokenCName, Pcd.TokenSpaceGuidCName, 'DynamicEx'))\r
                     PcdCheckList.append((Pcd.TokenCName, Pcd.TokenSpaceGuidCName, 'Dynamic'))\r
                     PcdTokenSpaceList.append(Pcd.TokenSpaceGuidCName)\r
-        GuidList = sdict()\r
+        GuidList = OrderedDict()\r
         GuidList.update(self.GuidList)\r
         for TokenSpace in self.GetGuidsUsedByPcd():\r
             # If token space is not referred by patch PCD or Ex PCD, remove the GUID from GUID list\r
@@ -4080,8 +4035,7 @@ class ModuleAutoGen(AutoGen):
         DebugDir = self.DebugDir.replace('\\', '/').strip('/')\r
         for Item in self.CodaTargetList:\r
             File = Item.Target.Path.replace('\\', '/').strip('/').replace(DebugDir, '').replace(OutputDir, '').strip('/')\r
-            if File not in self.OutputFile:\r
-                self.OutputFile.append(File)\r
+            self.OutputFile.add(File)\r
             if os.path.isabs(File):\r
                 File = File.replace('\\', '/').strip('/').replace(OutputDir, '').strip('/')\r
             if Item.Target.Ext.lower() == '.aml':\r
@@ -4093,8 +4047,7 @@ class ModuleAutoGen(AutoGen):
             else:\r
                 AsBuiltInfDict['binary_item'] += ['BIN|' + File]\r
         if self.DepexGenerated:\r
-            if self.Name + '.depex' not in self.OutputFile:\r
-                self.OutputFile.append(self.Name + '.depex')\r
+            self.OutputFile.add(self.Name + '.depex')\r
             if self.ModuleType in ['PEIM']:\r
                 AsBuiltInfDict['binary_item'] += ['PEI_DEPEX|' + self.Name + '.depex']\r
             if self.ModuleType in ['DXE_DRIVER', 'DXE_RUNTIME_DRIVER', 'DXE_SAL_DRIVER', 'UEFI_DRIVER']:\r
@@ -4105,15 +4058,13 @@ class ModuleAutoGen(AutoGen):
         Bin = self._GenOffsetBin()\r
         if Bin:\r
             AsBuiltInfDict['binary_item'] += ['BIN|%s' % Bin]\r
-            if Bin not in self.OutputFile:\r
-                self.OutputFile.append(Bin)\r
+            self.OutputFile.add(Bin)\r
 \r
         for Root, Dirs, Files in os.walk(OutputDir):\r
             for File in Files:\r
                 if File.lower().endswith('.pdb'):\r
                     AsBuiltInfDict['binary_item'] += ['DISPOSABLE|' + File]\r
-                    if File not in self.OutputFile:\r
-                        self.OutputFile.append(File)\r
+                    self.OutputFile.add(File)\r
         HeaderComments = self.Module.HeaderComments\r
         StartPos = 0\r
         for Index in range(len(HeaderComments)):\r
@@ -4162,13 +4113,13 @@ class ModuleAutoGen(AutoGen):
                     elif BoolValue == 'FALSE':\r
                         Pcd.DefaultValue = '0'\r
 \r
-                if Pcd.DatumType in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']:\r
+                if Pcd.DatumType in TAB_PCD_NUMERIC_TYPES:\r
                     HexFormat = '0x%02x'\r
-                    if Pcd.DatumType == 'UINT16':\r
+                    if Pcd.DatumType == TAB_UINT16:\r
                         HexFormat = '0x%04x'\r
-                    elif Pcd.DatumType == 'UINT32':\r
+                    elif Pcd.DatumType == TAB_UINT32:\r
                         HexFormat = '0x%08x'\r
-                    elif Pcd.DatumType == 'UINT64':\r
+                    elif Pcd.DatumType == TAB_UINT64:\r
                         HexFormat = '0x%016x'\r
                     PcdValue = HexFormat % int(Pcd.DefaultValue, 0)\r
                 else:\r
@@ -4197,9 +4148,12 @@ class ModuleAutoGen(AutoGen):
                             Padding = Padding * 2\r
                             ArraySize = ArraySize / 2\r
                         if ArraySize < (len(PcdValue) + 1):\r
-                            EdkLogger.error("build", AUTOGEN_ERROR,\r
+                            if Pcd.MaxSizeUserSet:\r
+                                EdkLogger.error("build", AUTOGEN_ERROR,\r
                                             "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, TokenCName)\r
                                             )\r
+                            else:\r
+                                ArraySize = len(PcdValue) + 1\r
                         if ArraySize > len(PcdValue) + 1:\r
                             NewValue = NewValue + Padding * (ArraySize - len(PcdValue) - 1)\r
                         PcdValue = NewValue + Padding.strip().rstrip(',') + '}'\r
@@ -4207,9 +4161,12 @@ class ModuleAutoGen(AutoGen):
                         PcdValue = PcdValue.rstrip('}') + ', 0x00' * (ArraySize - len(PcdValue.split(',')))\r
                         PcdValue += '}'\r
                     else:\r
-                        EdkLogger.error("build", AUTOGEN_ERROR,\r
+                        if Pcd.MaxSizeUserSet:\r
+                            EdkLogger.error("build", AUTOGEN_ERROR,\r
                                         "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, TokenCName)\r
                                         )\r
+                        else:\r
+                            ArraySize = len(PcdValue) + 1\r
                 PcdItem = '%s.%s|%s|0x%X' % \\r
                     (Pcd.TokenSpaceGuidCName, TokenCName, PcdValue, PatchPcd[1])\r
                 PcdComments = ''\r
@@ -4219,7 +4176,7 @@ class ModuleAutoGen(AutoGen):
                     PcdItem = PcdComments + '\n  ' + PcdItem\r
                 AsBuiltInfDict['patchablepcd_item'].append(PcdItem)\r
 \r
-        HiiPcds = []\r
+        HiiPcds = set()\r
         for Pcd in Pcds + VfrPcds:\r
             PcdComments = ''\r
             PcdCommentList = []\r
@@ -4242,8 +4199,7 @@ class ModuleAutoGen(AutoGen):
                 #\r
                 if (SkuId, Pcd.TokenSpaceGuidCName, Pcd.TokenCName) in HiiPcds:\r
                     continue\r
-                else:\r
-                    HiiPcds.append((SkuId, Pcd.TokenSpaceGuidCName, Pcd.TokenCName))\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