]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/AutoGen/AutoGen.py
BaseTools: Optimize VPD PCD value for the different SKUs
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / AutoGen.py
index 86f33fbd86237656b155883611a819f3e4b417d1..63cda5a8ac106c6efae79ae8b9af924c55a64af2 100644 (file)
-## @file
-# Generate AutoGen.h, AutoGen.c and *.depex files
-#
-# Copyright (c) 2007, Intel Corporation
-# All rights reserved. This program and the accompanying materials
-# are licensed and made available under the terms and conditions of the BSD License
-# which accompanies this distribution.  The full text of the license may be found at
-# http://opensource.org/licenses/bsd-license.php
-#
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-#
-
-## Import Modules
-#
-import os
-import re
-import os.path as path
-import copy
-
-import GenC
-import GenMake
-import GenDepex
-
-from StrGather import *
-from BuildEngine import BuildRule
-
-from Common.BuildToolError import *
-from Common.DataType import *
-from Common.Misc import *
-from Common.String import *
-import Common.GlobalData as GlobalData
-from GenFds.FdfParser import *
-from CommonDataClass.CommonClass import SkuInfoClass
-from Workspace.BuildClassObject import *
-
-## Regular expression for splitting Dependency Expression stirng into tokens
-gDepexTokenPattern = re.compile("(\(|\)|\w+| \S+\.inf)")
-
-## Mapping Makefile type
-gMakeTypeMap = {"MSFT":"nmake", "GCC":"gmake"}
-
-
-## Build rule configuration file
-gBuildRuleFile = 'Conf/build_rule.txt'
-
-## default file name for AutoGen
-gAutoGenCodeFileName = "AutoGen.c"
-gAutoGenHeaderFileName = "AutoGen.h"
-gAutoGenStringFileName = "%(module_name)sStrDefs.h"
-gAutoGenDepexFileName = "%(module_name)s.depex"
-gAutoGenSmmDepexFileName = "%(module_name)s.smm"
-
-## Base class for AutoGen
-#
-#   This class just implements the cache mechanism of AutoGen objects.
-#
-class AutoGen(object):
-    # database to maintain the objects of xxxAutoGen
-    _CACHE_ = {}    # (BuildTarget, ToolChain) : {ARCH : {platform file: AutoGen object}}}
-
-    ## Factory method
-    #
-    #   @param  Class           class object of real AutoGen class
-    #                           (WorkspaceAutoGen, ModuleAutoGen or PlatformAutoGen)
-    #   @param  Workspace       Workspace directory or WorkspaceAutoGen object
-    #   @param  MetaFile        The path of meta file
-    #   @param  Target          Build target
-    #   @param  Toolchain       Tool chain name
-    #   @param  Arch            Target arch
-    #   @param  *args           The specific class related parameters
-    #   @param  **kwargs        The specific class related dict parameters
-    #
-    def __new__(Class, Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs):
-        # check if the object has been created
-        Key = (Target, Toolchain)
-        if Key not in Class._CACHE_ or Arch not in Class._CACHE_[Key] \
-           or MetaFile not in Class._CACHE_[Key][Arch]:
-            AutoGenObject = super(AutoGen, Class).__new__(Class)
-            # call real constructor
-            if not AutoGenObject._Init(Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs):
-                return None
-            if Key not in Class._CACHE_:
-                Class._CACHE_[Key] = {}
-            if Arch not in Class._CACHE_[Key]:
-                Class._CACHE_[Key][Arch] = {}
-            Class._CACHE_[Key][Arch][MetaFile] = AutoGenObject
-        else:
-            AutoGenObject = Class._CACHE_[Key][Arch][MetaFile]
-
-        return AutoGenObject
-
-    ## hash() operator
-    #
-    #  The file path of platform file will be used to represent hash value of this object
-    #
-    #   @retval int     Hash value of the file path of platform file
-    #
-    def __hash__(self):
-        return hash(self.MetaFile)
-
-    ## str() operator
-    #
-    #  The file path of platform file will be used to represent this object
-    #
-    #   @retval string  String of platform file path
-    #
-    def __str__(self):
-        return str(self.MetaFile)
-
-    ## "==" operator
-    def __eq__(self, Other):
-        return Other and self.MetaFile == Other
-
-## Workspace AutoGen class
-#
-#   This class is used mainly to control the whole platform build for different
-# architecture. This class will generate top level makefile.
-#
-class WorkspaceAutoGen(AutoGen):
-    ## Real constructor of WorkspaceAutoGen
-    #
-    # This method behaves the same as __init__ except that it needs explict invoke
-    # (in super class's __new__ method)
-    #
-    #   @param  WorkspaceDir            Root directory of workspace
-    #   @param  ActivePlatform          Meta-file of active platform
-    #   @param  Target                  Build target
-    #   @param  Toolchain               Tool chain name
-    #   @param  ArchList                List of architecture of current build
-    #   @param  MetaFileDb              Database containing meta-files
-    #   @param  BuildConfig             Configuration of build
-    #   @param  ToolDefinition          Tool chain definitions
-    #   @param  FlashDefinitionFile     File of flash definition
-    #   @param  Fds                     FD list to be generated
-    #   @param  Fvs                     FV list to be generated
-    #   @param  SkuId                   SKU id from command line
-    #
-    def _Init(self, WorkspaceDir, ActivePlatform, Target, Toolchain, ArchList, MetaFileDb,
-              BuildConfig, ToolDefinition, FlashDefinitionFile='', Fds=[], Fvs=[], SkuId=''):
-        self.MetaFile       = ActivePlatform.MetaFile
-        self.WorkspaceDir   = WorkspaceDir
-        self.Platform       = ActivePlatform
-        self.BuildTarget    = Target
-        self.ToolChain      = Toolchain
-        self.ArchList       = ArchList
-        self.SkuId          = SkuId
-
-        self.BuildDatabase  = MetaFileDb
-        self.TargetTxt      = BuildConfig
-        self.ToolDef        = ToolDefinition
-        self.FdfFile        = FlashDefinitionFile
-        self.FdTargetList   = Fds
-        self.FvTargetList   = Fvs
-        self.AutoGenObjectList = []
-
-        # there's many relative directory operations, so ...
-        os.chdir(self.WorkspaceDir)
-
-        # parse FDF file to get PCDs in it, if any
-        if self.FdfFile != None and self.FdfFile != '':
-            Fdf = FdfParser(self.FdfFile.Path)
-            Fdf.ParseFile()
-            PcdSet = Fdf.Profile.PcdDict
-            ModuleList = Fdf.Profile.InfList
-        else:
-            PcdSet = {}
-            ModuleList = []
-
-        # apply SKU and inject PCDs from Flash Definition file
-        for Arch in self.ArchList:
-            Platform = self.BuildDatabase[self.MetaFile, Arch]
-            Platform.SkuName = self.SkuId
-            for Name, Guid in PcdSet:
-                Platform.AddPcd(Name, Guid, PcdSet[Name, Guid])
-
-            Pa = PlatformAutoGen(self, self.MetaFile, Target, Toolchain, Arch)
-            #
-            # Explicitly collect platform's dynamic PCDs
-            #
-            Pa.CollectPlatformDynamicPcds()
-            self.AutoGenObjectList.append(Pa)
-
-        self._BuildDir = None
-        self._FvDir = None
-        self._MakeFileDir = None
-        self._BuildCommand = None
-
-        return True
-
-    def __repr__(self):
-        return "%s [%s]" % (self.MetaFile, ", ".join(self.ArchList))
-
-    ## Return the directory to store FV files
-    def _GetFvDir(self):
-        if self._FvDir == None:
-            self._FvDir = path.join(self.BuildDir, 'FV')
-        return self._FvDir
-
-    ## Return the directory to store all intermediate and final files built
-    def _GetBuildDir(self):
-        return self.AutoGenObjectList[0].BuildDir
-
-    ## Return the build output directory platform specifies
-    def _GetOutputDir(self):
-        return self.Platform.OutputDirectory
-
-    ## Return platform name
-    def _GetName(self):
-        return self.Platform.PlatformName
-
-    ## Return meta-file GUID
-    def _GetGuid(self):
-        return self.Platform.Guid
-
-    ## Return platform version
-    def _GetVersion(self):
-        return self.Platform.Version
-
-    ## Return paths of tools
-    def _GetToolDefinition(self):
-        return self.AutoGenObjectList[0].ToolDefinition
-
-    ## Return directory of platform makefile
-    #
-    #   @retval     string  Makefile directory
-    #
-    def _GetMakeFileDir(self):
-        if self._MakeFileDir == None:
-            self._MakeFileDir = self.BuildDir
-        return self._MakeFileDir
-
-    ## Return build command string
-    #
-    #   @retval     string  Build command string
-    #
-    def _GetBuildCommand(self):
-        if self._BuildCommand == None:
-            # BuildCommand should be all the same. So just get one from platform AutoGen
-            self._BuildCommand = self.AutoGenObjectList[0].BuildCommand
-        return self._BuildCommand
-
-    ## Create makefile for the platform and mdoules in it
-    #
-    #   @param      CreateDepsMakeFile      Flag indicating if the makefile for
-    #                                       modules will be created as well
-    #
-    def CreateMakeFile(self, CreateDepsMakeFile=False):
-        # create makefile for platform
-        Makefile = GenMake.TopLevelMakefile(self)
-        if Makefile.Generate():
-            EdkLogger.debug(EdkLogger.DEBUG_9, "Generated makefile for platform [%s] %s\n" %
-                            (self.MetaFile, self.ArchList))
-        else:
-            EdkLogger.debug(EdkLogger.DEBUG_9, "Skipped the generation of makefile for platform [%s] %s\n" %
-                            (self.MetaFile, self.ArchList))
-
-        if CreateDepsMakeFile:
-            for Pa in self.AutoGenObjectList:
-                Pa.CreateMakeFile(CreateDepsMakeFile)
-
-    ## Create autogen code for platform and modules
-    #
-    #  Since there's no autogen code for platform, this method will do nothing
-    #  if CreateModuleCodeFile is set to False.
-    #
-    #   @param      CreateDepsCodeFile      Flag indicating if creating module's
-    #                                       autogen code file or not
-    #
-    def CreateCodeFile(self, CreateDepsCodeFile=False):
-        if not CreateDepsCodeFile:
-            return
-        for Pa in self.AutoGenObjectList:
-            Pa.CreateCodeFile(CreateDepsCodeFile)
-
-    Name                = property(_GetName)
-    Guid                = property(_GetGuid)
-    Version             = property(_GetVersion)
-    OutputDir           = property(_GetOutputDir)
-
-    ToolDefinition      = property(_GetToolDefinition)       # toolcode : tool path
-
-    BuildDir            = property(_GetBuildDir)
-    FvDir               = property(_GetFvDir)
-    MakeFileDir         = property(_GetMakeFileDir)
-    BuildCommand        = property(_GetBuildCommand)
-
-## AutoGen class for platform
-#
-#  PlatformAutoGen class will process the original information in platform
-#  file in order to generate makefile for platform.
-#
-class PlatformAutoGen(AutoGen):
-    #
-    # Used to store all PCDs for both PEI and DXE phase, in order to generate 
-    # correct PCD database
-    # 
-    _DynaPcdList_ = []
-    _NonDynaPcdList_ = []
-
-    ## The real constructor of PlatformAutoGen
-    #
-    #  This method is not supposed to be called by users of PlatformAutoGen. It's
-    #  only used by factory method __new__() to do real initialization work for an
-    #  object of PlatformAutoGen
-    #
-    #   @param      Workspace       WorkspaceAutoGen object
-    #   @param      PlatformFile    Platform file (DSC file)
-    #   @param      Target          Build target (DEBUG, RELEASE)
-    #   @param      Toolchain       Name of tool chain
-    #   @param      Arch            arch of the platform supports
-    #
-    def _Init(self, Workspace, PlatformFile, Target, Toolchain, Arch):
-        EdkLogger.debug(EdkLogger.DEBUG_9, "AutoGen platform [%s] [%s]" % (PlatformFile, Arch))
-        GlobalData.gProcessingFile = "%s [%s, %s, %s]" % (PlatformFile, Arch, Toolchain, Target)
-
-        self.MetaFile = PlatformFile
-        self.Workspace = Workspace
-        self.WorkspaceDir = Workspace.WorkspaceDir
-        self.ToolChain = Toolchain
-        self.BuildTarget = Target
-        self.Arch = Arch
-        self.SourceDir = PlatformFile.SubDir
-        self.SourceOverrideDir = None
-        self.FdTargetList = self.Workspace.FdTargetList
-        self.FvTargetList = self.Workspace.FvTargetList
-
-        # flag indicating if the makefile/C-code file has been created or not
-        self.IsMakeFileCreated  = False
-        self.IsCodeFileCreated  = False
-
-        self._Platform   = None
-        self._Name       = None
-        self._Guid       = None
-        self._Version    = None
-
-        self._BuildRule = None
-        self._SourceDir = None
-        self._BuildDir = None
-        self._OutputDir = None
-        self._FvDir = None
-        self._MakeFileDir = None
-        self._FdfFile = None
-
-        self._PcdTokenNumber = None    # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber
-        self._DynamicPcdList = None    # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
-        self._NonDynamicPcdList = None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
-
-        self._ToolDefinitions = None
-        self._ToolDefFile = None          # toolcode : tool path
-        self._ToolChainFamily = None
-        self._BuildRuleFamily = None
-        self._BuildOption = None          # toolcode : option
-        self._PackageList = None
-        self._ModuleAutoGenList  = None
-        self._LibraryAutoGenList = None
-        self._BuildCommand = None
-
-        # get the original module/package/platform objects
-        self.BuildDatabase = Workspace.BuildDatabase
-        return True
-
-    def __repr__(self):
-        return "%s [%s]" % (self.MetaFile, self.Arch)
-
-    ## Create autogen code for platform and modules
-    #
-    #  Since there's no autogen code for platform, this method will do nothing
-    #  if CreateModuleCodeFile is set to False.
-    #
-    #   @param      CreateModuleCodeFile    Flag indicating if creating module's
-    #                                       autogen code file or not
-    #
-    def CreateCodeFile(self, CreateModuleCodeFile=False):
-        # only module has code to be greated, so do nothing if CreateModuleCodeFile is False
-        if self.IsCodeFileCreated or not CreateModuleCodeFile:
-            return
-
-        for Ma in self.ModuleAutoGenList:
-            Ma.CreateCodeFile(True)
-
-        # don't do this twice
-        self.IsCodeFileCreated = True
-
-    ## Create makefile for the platform and mdoules in it
-    #
-    #   @param      CreateModuleMakeFile    Flag indicating if the makefile for
-    #                                       modules will be created as well
-    #
-    def CreateMakeFile(self, CreateModuleMakeFile=False):
-        if CreateModuleMakeFile:
-            for ModuleFile in self.Platform.Modules:
-                Ma = ModuleAutoGen(self.Workspace, ModuleFile, self.BuildTarget,
-                                   self.ToolChain, self.Arch, self.MetaFile)
-                Ma.CreateMakeFile(True)
-
-        # no need to create makefile for the platform more than once
-        if self.IsMakeFileCreated:
-            return
-
-        # create makefile for platform
-        Makefile = GenMake.PlatformMakefile(self)
-        if Makefile.Generate():
-            EdkLogger.debug(EdkLogger.DEBUG_9, "Generated makefile for platform [%s] [%s]\n" %
-                            (self.MetaFile, self.Arch))
-        else:
-            EdkLogger.debug(EdkLogger.DEBUG_9, "Skipped the generation of makefile for platform [%s] [%s]\n" %
-                            (self.MetaFile, self.Arch))
-        self.IsMakeFileCreated = True
-
-    ## Collect dynamic PCDs
-    #
-    #  Gather dynamic PCDs list from each module and their settings from platform
-    #  This interface should be invoked explicitly when platform action is created.
-    #
-    def CollectPlatformDynamicPcds(self):
-        # for gathering error information
-        NoDatumTypePcdList = set()
-
-        self._GuidValue = {}
-        for F in self.Platform.Modules.keys():
-            M = ModuleAutoGen(self.Workspace, F, self.BuildTarget, self.ToolChain, self.Arch, self.MetaFile)
-            #GuidValue.update(M.Guids)
-            for PcdFromModule in M.ModulePcdList+M.LibraryPcdList:
-                # make sure that the "VOID*" kind of datum has MaxDatumSize set
-                if PcdFromModule.DatumType == "VOID*" and PcdFromModule.MaxDatumSize == None:
-                    NoDatumTypePcdList.add("%s.%s [%s]" % (PcdFromModule.TokenSpaceGuidCName, PcdFromModule.TokenCName, F))
-
-                if PcdFromModule.Type in GenC.gDynamicPcd or PcdFromModule.Type in GenC.gDynamicExPcd:
-                    #
-                    # If a dynamic PCD used by a PEM module/PEI module & DXE module,
-                    # it should be stored in Pcd PEI database, If a dynamic only
-                    # used by DXE module, it should be stored in DXE PCD database.
-                    # The default Phase is DXE
-                    #
-                    if M.ModuleType in ["PEIM", "PEI_CORE"]:
-                        PcdFromModule.Phase = "PEI"
-                    if PcdFromModule not in self._DynaPcdList_:
-                        self._DynaPcdList_.append(PcdFromModule)
-                    elif PcdFromModule.Phase == 'PEI':
-                        # overwrite any the same PCD existing, if Phase is PEI
-                        Index = self._DynaPcdList_.index(PcdFromModule)
-                        self._DynaPcdList_[Index] = PcdFromModule
-                elif PcdFromModule not in self._NonDynaPcdList_:
-                    self._NonDynaPcdList_.append(PcdFromModule)
-
-        # print out error information and break the build, if error found
-        if len(NoDatumTypePcdList) > 0:
-            NoDatumTypePcdListString = "\n\t\t".join(NoDatumTypePcdList)
-            EdkLogger.error("build", AUTOGEN_ERROR, "PCD setting error",
-                            File=self.MetaFile,
-                            ExtraData="\n\tPCD(s) without MaxDatumSize:\n\t\t%s\n"
-                                      % NoDatumTypePcdListString)
-        self._NonDynamicPcdList = self._NonDynaPcdList_
-        self._DynamicPcdList = self._DynaPcdList_
-        
-        #
-        # Sort dynamic PCD list to:
-        # 1) If PCD's datum type is VOID* and value is unicode string which starts with L, the PCD item should 
-        #    try to be put header of dynamicd List
-        # 2) If PCD is HII type, the PCD item should be put after unicode type PCD
-        #
-        # The reason of sorting is make sure the unicode string is in double-byte alignment in string table.
-        #
-        UnicodePcdArray = []
-        HiiPcdArray     = []
-        OtherPcdArray   = []
-        for Pcd in self._DynamicPcdList:
-            # just pick the a value to determine whether is unicode string type
-            Sku      = Pcd.SkuInfoList[Pcd.SkuInfoList.keys()[0]]
-            PcdValue = Sku.DefaultValue
-            if Pcd.DatumType == 'VOID*' and PcdValue.startswith("L"):
-                # if found PCD which datum value is unicode string the insert to left size of UnicodeIndex
-                UnicodePcdArray.append(Pcd)
-            elif len(Sku.VariableName) > 0:
-                # if found HII type PCD then insert to right of UnicodeIndex
-                HiiPcdArray.append(Pcd)
-            else:
-                OtherPcdArray.append(Pcd)
-        del self._DynamicPcdList[:]
-        self._DynamicPcdList.extend(UnicodePcdArray)
-        self._DynamicPcdList.extend(HiiPcdArray)
-        self._DynamicPcdList.extend(OtherPcdArray)
-            
-        
-    ## Return the platform build data object
-    def _GetPlatform(self):
-        if self._Platform == None:
-            self._Platform = self.BuildDatabase[self.MetaFile, self.Arch]
-        return self._Platform
-
-    ## Return platform name
-    def _GetName(self):
-        return self.Platform.PlatformName
-
-    ## Return the meta file GUID
-    def _GetGuid(self):
-        return self.Platform.Guid
-
-    ## Return the platform version
-    def _GetVersion(self):
-        return self.Platform.Version
-
-    ## Return the FDF file name
-    def _GetFdfFile(self):
-        if self._FdfFile == None:
-            if self.Workspace.FdfFile != "":
-                self._FdfFile= path.join(self.WorkspaceDir, self.Workspace.FdfFile)
-            else:
-                self._FdfFile = ''
-        return self._FdfFile
-
-    ## Return the build output directory platform specifies
-    def _GetOutputDir(self):
-        return self.Platform.OutputDirectory
-
-    ## Return the directory to store all intermediate and final files built
-    def _GetBuildDir(self):
-        if self._BuildDir == None:
-            if os.path.isabs(self.OutputDir):
-                self._BuildDir = path.join(
-                                            path.abspath(self.OutputDir),
-                                            self.BuildTarget + "_" + self.ToolChain,
-                                            )
-            else:
-                self._BuildDir = path.join(
-                                            self.WorkspaceDir,
-                                            self.OutputDir,
-                                            self.BuildTarget + "_" + self.ToolChain,
-                                            )
-        return self._BuildDir
-
-    ## Return directory of platform makefile
-    #
-    #   @retval     string  Makefile directory
-    #
-    def _GetMakeFileDir(self):
-        if self._MakeFileDir == None:
-            self._MakeFileDir = path.join(self.BuildDir, self.Arch)
-        return self._MakeFileDir
-
-    ## Return build command string
-    #
-    #   @retval     string  Build command string
-    #
-    def _GetBuildCommand(self):
-        if self._BuildCommand == None:
-            self._BuildCommand = []
-            if "MAKE" in self.ToolDefinition and "PATH" in self.ToolDefinition["MAKE"]:
-                self._BuildCommand += SplitOption(self.ToolDefinition["MAKE"]["PATH"])
-                if "FLAGS" in self.ToolDefinition["MAKE"]:
-                    NewOption = self.ToolDefinition["MAKE"]["FLAGS"].strip()
-                    if NewOption != '':
-                      self._BuildCommand += SplitOption(NewOption)
-        return self._BuildCommand
-
-    ## Get tool chain definition
-    #
-    #  Get each tool defition for given tool chain from tools_def.txt and platform
-    #
-    def _GetToolDefinition(self):
-        if self._ToolDefinitions == None:
-            ToolDefinition = self.Workspace.ToolDef.ToolsDefTxtDictionary
-            if TAB_TOD_DEFINES_COMMAND_TYPE not in self.Workspace.ToolDef.ToolsDefTxtDatabase:
-                EdkLogger.error('build', RESOURCE_NOT_AVAILABLE, "No tools found in configuration",
-                                ExtraData="[%s]" % self.MetaFile)
-            self._ToolDefinitions = {}
-            DllPathList = set()
-            for Def in ToolDefinition:
-                Target, Tag, Arch, Tool, Attr = Def.split("_")
-                if Target != self.BuildTarget or Tag != self.ToolChain or Arch != self.Arch:
-                    continue
-
-                Value = ToolDefinition[Def]
-                # don't record the DLL
-                if Attr == "DLL":
-                    DllPathList.add(Value)
-                    continue
-
-                if Tool not in self._ToolDefinitions:
-                    self._ToolDefinitions[Tool] = {}
-                self._ToolDefinitions[Tool][Attr] = Value
-
-            ToolsDef = ''
-            MakePath = ''
-            if GlobalData.gOptions.SilentMode and "MAKE" in self._ToolDefinitions:
-                if "FLAGS" not in self._ToolDefinitions["MAKE"]:
-                    self._ToolDefinitions["MAKE"]["FLAGS"] = ""
-                self._ToolDefinitions["MAKE"]["FLAGS"] += " -s"
-            MakeFlags = ''
-            for Tool in self._ToolDefinitions:
-                for Attr in self._ToolDefinitions[Tool]:
-                    Value = self._ToolDefinitions[Tool][Attr]
-                    if Tool in self.BuildOption and Attr in self.BuildOption[Tool]:
-                        # check if override is indicated
-                        if self.BuildOption[Tool][Attr].startswith('='):
-                            Value = self.BuildOption[Tool][Attr][1:]
-                        else:
-                            Value += " " + self.BuildOption[Tool][Attr]
-
-                    if Attr == "PATH":
-                        # Don't put MAKE definition in the file
-                        if Tool == "MAKE":
-                            MakePath = Value
-                        else:
-                            ToolsDef += "%s = %s\n" % (Tool, Value)
-                    elif Attr != "DLL":
-                        # Don't put MAKE definition in the file
-                        if Tool == "MAKE":
-                            if Attr == "FLAGS":
-                                MakeFlags = Value
-                        else:
-                            ToolsDef += "%s_%s = %s\n" % (Tool, Attr, Value)
-                ToolsDef += "\n"
-
-            SaveFileOnChange(self.ToolDefinitionFile, ToolsDef)
-            for DllPath in DllPathList:
-                os.environ["PATH"] = DllPath + os.pathsep + os.environ["PATH"]
-            os.environ["MAKE_FLAGS"] = MakeFlags
-
-        return self._ToolDefinitions
-
-    ## Return the paths of tools
-    def _GetToolDefFile(self):
-        if self._ToolDefFile == None:
-            self._ToolDefFile = os.path.join(self.MakeFileDir, "TOOLS_DEF." + self.Arch)
-        return self._ToolDefFile
-
-    ## Retrieve the toolchain family of given toolchain tag. Default to 'MSFT'.
-    def _GetToolChainFamily(self):
-        if self._ToolChainFamily == None:
-            ToolDefinition = self.Workspace.ToolDef.ToolsDefTxtDatabase
-            if TAB_TOD_DEFINES_FAMILY not in ToolDefinition \
-               or self.ToolChain not in ToolDefinition[TAB_TOD_DEFINES_FAMILY] \
-               or not ToolDefinition[TAB_TOD_DEFINES_FAMILY][self.ToolChain]:
-                EdkLogger.verbose("No tool chain family found in configuration for %s. Default to MSFT." \
-                                   % self.ToolChain)
-                self._ToolChainFamily = "MSFT"
-            else:
-                self._ToolChainFamily = ToolDefinition[TAB_TOD_DEFINES_FAMILY][self.ToolChain]
-        return self._ToolChainFamily
-
-    def _GetBuildRuleFamily(self):
-        if self._BuildRuleFamily == None:
-            ToolDefinition = self.Workspace.ToolDef.ToolsDefTxtDatabase
-            if TAB_TOD_DEFINES_BUILDRULEFAMILY not in ToolDefinition \
-               or self.ToolChain not in ToolDefinition[TAB_TOD_DEFINES_BUILDRULEFAMILY] \
-               or not ToolDefinition[TAB_TOD_DEFINES_BUILDRULEFAMILY][self.ToolChain]:
-                EdkLogger.verbose("No tool chain family found in configuration for %s. Default to MSFT." \
-                                   % self.ToolChain)
-                self._BuildRuleFamily = "MSFT"
-            else:
-                self._BuildRuleFamily = ToolDefinition[TAB_TOD_DEFINES_BUILDRULEFAMILY][self.ToolChain]
-        return self._BuildRuleFamily
-
-    ## Return the build options specific to this platform
-    def _GetBuildOptions(self):
-        if self._BuildOption == None:
-            self._BuildOption = self._ExpandBuildOption(self.Platform.BuildOptions)
-        return self._BuildOption
-
-    ## Parse build_rule.txt in $(WORKSPACE)/Conf/build_rule.txt
-    #
-    #   @retval     BuildRule object
-    #
-    def _GetBuildRule(self):
-        if self._BuildRule == None:
-            BuildRuleFile = None
-            if TAB_TAT_DEFINES_BUILD_RULE_CONF in self.Workspace.TargetTxt.TargetTxtDictionary:
-                BuildRuleFile = self.Workspace.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_BUILD_RULE_CONF]
-            if BuildRuleFile in [None, '']:
-                BuildRuleFile = gBuildRuleFile
-            self._BuildRule = BuildRule(BuildRuleFile)
-        return self._BuildRule
-
-    ## Summarize the packages used by modules in this platform
-    def _GetPackageList(self):
-        if self._PackageList == None:
-            self._PackageList = set()
-            for La in self.LibraryAutoGenList:
-                self._PackageList.update(La.DependentPackageList)
-            for Ma in self.ModuleAutoGenList:
-                self._PackageList.update(Ma.DependentPackageList)
-            self._PackageList = list(self._PackageList)
-        return self._PackageList
-
-    ## Get list of non-dynamic PCDs
-    def _GetNonDynamicPcdList(self):
-        return self._NonDynamicPcdList
-
-    ## Get list of dynamic PCDs
-    def _GetDynamicPcdList(self):
-        return self._DynamicPcdList
-
-    ## Generate Token Number for all PCD
-    def _GetPcdTokenNumbers(self):
-        if self._PcdTokenNumber == None:
-            self._PcdTokenNumber = sdict()
-            TokenNumber = 1
-            for Pcd in self.DynamicPcdList:
-                if Pcd.Phase == "PEI":
-                    EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))
-                    self._PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber
-                    TokenNumber += 1
-
-            for Pcd in self.DynamicPcdList:
-                if Pcd.Phase == "DXE":
-                    EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))
-                    self._PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber
-                    TokenNumber += 1
-
-            for Pcd in self.NonDynamicPcdList:
-                self._PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber
-                TokenNumber += 1
-        return self._PcdTokenNumber
-
-    ## Summarize ModuleAutoGen objects of all modules/libraries to be built for this platform
-    def _GetAutoGenObjectList(self):
-        self._ModuleAutoGenList = []
-        self._LibraryAutoGenList = []
-        for ModuleFile in self.Platform.Modules:
-            Ma = ModuleAutoGen(
-                    self.Workspace,
-                    ModuleFile,
-                    self.BuildTarget,
-                    self.ToolChain,
-                    self.Arch,
-                    self.MetaFile
-                    )
-            if Ma not in self._ModuleAutoGenList:
-                self._ModuleAutoGenList.append(Ma)
-            for La in Ma.LibraryAutoGenList:
-                if La not in self._LibraryAutoGenList:
-                    self._LibraryAutoGenList.append(La)
-
-    ## Summarize ModuleAutoGen objects of all modules to be built for this platform
-    def _GetModuleAutoGenList(self):
-        if self._ModuleAutoGenList == None:
-            self._GetAutoGenObjectList()
-        return self._ModuleAutoGenList
-
-    ## Summarize ModuleAutoGen objects of all libraries to be built for this platform
-    def _GetLibraryAutoGenList(self):
-        if self._LibraryAutoGenList == None:
-            self._GetAutoGenObjectList()
-        return self._LibraryAutoGenList
-
-    ## Test if a module is supported by the platform
-    #
-    #  An error will be raised directly if the module or its arch is not supported
-    #  by the platform or current configuration
-    #
-    def ValidModule(self, Module):
-        return Module in self.Platform.Modules or Module in self.Platform.LibraryInstances
-
-    ## Resolve the library classes in a module to library instances
-    #
-    # This method will not only resolve library classes but also sort the library
-    # instances according to the dependency-ship.
-    #
-    #   @param  Module      The module from which the library classes will be resolved
-    #
-    #   @retval library_list    List of library instances sorted
-    #
-    def ApplyLibraryInstance(self, Module):
-        ModuleType = Module.ModuleType
-
-        # for overridding library instances with module specific setting
-        PlatformModule = self.Platform.Modules[str(Module)]
-
-        # add forced library instance
-        for LibraryClass in PlatformModule.LibraryClasses:
-            if LibraryClass.startswith("NULL"):
-                Module.LibraryClasses[LibraryClass] = PlatformModule.LibraryClasses[LibraryClass]
-
-        # R9 module
-        LibraryConsumerList = [Module]
-        Constructor         = []
-        ConsumedByList      = sdict()
-        LibraryInstance     = sdict()
-
-        EdkLogger.verbose("")
-        EdkLogger.verbose("Library instances of module [%s] [%s]:" % (str(Module), self.Arch))
-        while len(LibraryConsumerList) > 0:
-            M = LibraryConsumerList.pop()
-            for LibraryClassName in M.LibraryClasses:
-                if LibraryClassName not in LibraryInstance:
-                    # override library instance for this module
-                    if LibraryClassName in PlatformModule.LibraryClasses:
-                        LibraryPath = PlatformModule.LibraryClasses[LibraryClassName]
-                    else:
-                        LibraryPath = self.Platform.LibraryClasses[LibraryClassName, ModuleType]
-                    if LibraryPath == None or LibraryPath == "":
-                        LibraryPath = M.LibraryClasses[LibraryClassName]
-                        if LibraryPath == None or LibraryPath == "":
-                            EdkLogger.error("build", RESOURCE_NOT_AVAILABLE,
-                                            "Instance of library class [%s] is not found" % LibraryClassName,
-                                            File=self.MetaFile,
-                                            ExtraData="in [%s] [%s]\n\tconsumed by module [%s]" % (str(M), self.Arch, str(Module)))
-
-                    LibraryModule = self.BuildDatabase[LibraryPath, self.Arch]
-                    # for those forced library instance (NULL library), add a fake library class
-                    if LibraryClassName.startswith("NULL"):
-                        LibraryModule.LibraryClass.append(LibraryClassObject(LibraryClassName, [ModuleType]))
-                    elif LibraryModule.LibraryClass == None \
-                         or len(LibraryModule.LibraryClass) == 0 \
-                         or (ModuleType != 'USER_DEFINED'
-                             and ModuleType not in LibraryModule.LibraryClass[0].SupModList):
-                        # only USER_DEFINED can link against any library instance despite of its SupModList
-                        EdkLogger.error("build", OPTION_MISSING,
-                                        "Module type [%s] is not supported by library instance [%s]" \
-                                        % (ModuleType, LibraryPath), File=self.MetaFile,
-                                        ExtraData="consumed by [%s]" % str(Module))
-
-                    LibraryInstance[LibraryClassName] = LibraryModule
-                    LibraryConsumerList.append(LibraryModule)
-                    EdkLogger.verbose("\t" + str(LibraryClassName) + " : " + str(LibraryModule))
-                else:
-                    LibraryModule = LibraryInstance[LibraryClassName]
-
-                if LibraryModule == None:
-                    continue
-
-                if LibraryModule.ConstructorList != [] and LibraryModule not in Constructor:
-                    Constructor.append(LibraryModule)
-
-                if LibraryModule not in ConsumedByList:
-                    ConsumedByList[LibraryModule] = []
-                # don't add current module itself to consumer list
-                if M != Module:
-                    if M in ConsumedByList[LibraryModule]:
-                        continue
-                    ConsumedByList[LibraryModule].append(M)
-        #
-        # Initialize the sorted output list to the empty set
-        #
-        SortedLibraryList = []
-        #
-        # Q <- Set of all nodes with no incoming edges
-        #
-        LibraryList = [] #LibraryInstance.values()
-        Q = []
-        for LibraryClassName in LibraryInstance:
-            M = LibraryInstance[LibraryClassName]
-            LibraryList.append(M)
-            if ConsumedByList[M] == []:
-                Q.insert(0, M)
-
-        #
-        # start the  DAG algorithm
-        #
-        while True:
-            EdgeRemoved = True
-            while Q == [] and EdgeRemoved:
-                EdgeRemoved = False
-                # for each node Item with a Constructor
-                for Item in LibraryList:
-                    if Item not in Constructor:
-                        continue
-                    # for each Node without a constructor with an edge e from Item to Node
-                    for Node in ConsumedByList[Item]:
-                        if Node in Constructor:
-                            continue
-                        # remove edge e from the graph if Node has no constructor
-                        ConsumedByList[Item].remove(Node)
-                        EdgeRemoved = True
-                        if ConsumedByList[Item] == []:
-                            # insert Item into Q
-                            Q.insert(0, Item)
-                            break
-                    if Q != []:
-                        break
-            # DAG is done if there's no more incoming edge for all nodes
-            if Q == []:
-                break
-
-            # remove node from Q
-            Node = Q.pop()
-            # output Node
-            SortedLibraryList.append(Node)
-
-            # for each node Item with an edge e from Node to Item do
-            for Item in LibraryList:
-                if Node not in ConsumedByList[Item]:
-                    continue
-                # remove edge e from the graph
-                ConsumedByList[Item].remove(Node)
-
-                if ConsumedByList[Item] != []:
-                    continue
-                # insert Item into Q, if Item has no other incoming edges
-                Q.insert(0, Item)
-
-        #
-        # if any remaining node Item in the graph has a constructor and an incoming edge, then the graph has a cycle
-        #
-        for Item in LibraryList:
-            if ConsumedByList[Item] != [] and Item in Constructor and len(Constructor) > 1:
-                ErrorMessage = "\tconsumed by " + "\n\tconsumed by ".join([str(L) for L in ConsumedByList[Item]])
-                EdkLogger.error("build", BUILD_ERROR, 'Library [%s] with constructors has a cycle' % str(Item),
-                                ExtraData=ErrorMessage, File=self.MetaFile)
-            if Item not in SortedLibraryList:
-                SortedLibraryList.append(Item)
-
-        #
-        # Build the list of constructor and destructir names
-        # The DAG Topo sort produces the destructor order, so the list of constructors must generated in the reverse order
-        #
-        SortedLibraryList.reverse()
-        return SortedLibraryList
-
-
-    ## Override PCD setting (type, value, ...)
-    #
-    #   @param  ToPcd       The PCD to be overrided
-    #   @param  FromPcd     The PCD overrideing from
-    #
-    def _OverridePcd(self, ToPcd, FromPcd, Module=""):
-        #
-        # in case there's PCDs coming from FDF file, which have no type given.
-        # at this point, ToPcd.Type has the type found from dependent
-        # package
-        #
-        if FromPcd != None:
-            if ToPcd.Pending and FromPcd.Type not in [None, '']:
-                ToPcd.Type = FromPcd.Type
-            elif ToPcd.Type not in [None, ''] and FromPcd.Type not in [None, ''] \
-                and ToPcd.Type != FromPcd.Type:
-                EdkLogger.error("build", OPTION_CONFLICT, "Mismatched PCD type",
-                                ExtraData="%s.%s is defined as [%s] in module %s, but as [%s] in platform."\
-                                          % (ToPcd.TokenSpaceGuidCName, ToPcd.TokenCName,
-                                             ToPcd.Type, Module, FromPcd.Type),
-                                          File=self.MetaFile)
-
-            if FromPcd.MaxDatumSize not in [None, '']:
-                ToPcd.MaxDatumSize = FromPcd.MaxDatumSize
-            if FromPcd.DefaultValue not in [None, '']:
-                ToPcd.DefaultValue = FromPcd.DefaultValue
-            if FromPcd.TokenValue not in [None, '']:
-                ToPcd.TokenValue = FromPcd.TokenValue
-            if FromPcd.MaxDatumSize not in [None, '']:
-                ToPcd.MaxDatumSize = FromPcd.MaxDatumSize
-            if FromPcd.DatumType not in [None, '']:
-                ToPcd.DatumType = FromPcd.DatumType
-            if FromPcd.SkuInfoList not in [None, '', []]:
-                ToPcd.SkuInfoList = FromPcd.SkuInfoList
-
-            # check the validation of datum
-            IsValid, Cause = CheckPcdDatum(ToPcd.DatumType, ToPcd.DefaultValue)
-            if not IsValid:
-                EdkLogger.error('build', FORMAT_INVALID, Cause, File=self.MetaFile,
-                                ExtraData="%s.%s" % (ToPcd.TokenSpaceGuidCName, ToPcd.TokenCName))
-
-        if ToPcd.DatumType == "VOID*" and ToPcd.MaxDatumSize in ['', None]:
-            EdkLogger.debug(EdkLogger.DEBUG_9, "No MaxDatumSize specified for PCD %s.%s" \
-                            % (ToPcd.TokenSpaceGuidCName, ToPcd.TokenCName))
-            Value = ToPcd.DefaultValue
-            if Value in [None, '']:
-                ToPcd.MaxDatumSize = 1
-            elif Value[0] == 'L':
-                ToPcd.MaxDatumSize = str(len(Value) * 2)
-            elif Value[0] == '{':
-                ToPcd.MaxDatumSize = str(len(Value.split(',')))
-            else:
-                ToPcd.MaxDatumSize = str(len(Value))
-
-        # apply default SKU for dynamic PCDS if specified one is not available
-        if (ToPcd.Type in PCD_DYNAMIC_TYPE_LIST or ToPcd.Type in PCD_DYNAMIC_EX_TYPE_LIST) \
-            and ToPcd.SkuInfoList in [None, {}, '']:
-            if self.Platform.SkuName in self.Platform.SkuIds:
-                SkuName = self.Platform.SkuName
-            else:
-                SkuName = 'DEFAULT'
-            ToPcd.SkuInfoList = {
-                SkuName : SkuInfoClass(SkuName, self.Platform.SkuIds[SkuName], '', '', '', '', '', ToPcd.DefaultValue)
-            }
-
-    ## Apply PCD setting defined platform to a module
-    #
-    #   @param  Module  The module from which the PCD setting will be overrided
-    #
-    #   @retval PCD_list    The list PCDs with settings from platform
-    #
-    def ApplyPcdSetting(self, Module, Pcds):
-        # for each PCD in module
-        for Name,Guid in Pcds:
-            PcdInModule = Pcds[Name,Guid]
-            # find out the PCD setting in platform
-            if (Name,Guid) in self.Platform.Pcds:
-                PcdInPlatform = self.Platform.Pcds[Name,Guid]
-            else:
-                PcdInPlatform = None
-            # then override the settings if any
-            self._OverridePcd(PcdInModule, PcdInPlatform, Module)
-            # resolve the VariableGuid value
-            for SkuId in PcdInModule.SkuInfoList:
-                Sku = PcdInModule.SkuInfoList[SkuId]
-                if Sku.VariableGuid == '': continue
-                Sku.VariableGuidValue = GuidValue(Sku.VariableGuid, self.PackageList)
-                if Sku.VariableGuidValue == None:
-                    PackageList = "\n\t".join([str(P) for P in self.PackageList])
-                    EdkLogger.error(
-                                'build',
-                                RESOURCE_NOT_AVAILABLE,
-                                "Value of GUID [%s] is not found in" % Sku.VariableGuid,
-                                ExtraData=PackageList + "\n\t(used with %s.%s from module %s)" \
-                                                        % (Guid, Name, str(Module)),
-                                File=self.MetaFile
-                                )
-
-        # override PCD settings with module specific setting
-        if Module in self.Platform.Modules:
-            PlatformModule = self.Platform.Modules[str(Module)]
-            for Key  in PlatformModule.Pcds:
-                if Key in Pcds:
-                    self._OverridePcd(Pcds[Key], PlatformModule.Pcds[Key], Module)
-        return Pcds.values()
-
-    ## Resolve library names to library modules
-    #
-    # (for R8.x modules)
-    #
-    #   @param  Module  The module from which the library names will be resolved
-    #
-    #   @retval library_list    The list of library modules
-    #
-    def ResolveLibraryReference(self, Module):
-        EdkLogger.verbose("")
-        EdkLogger.verbose("Library instances of module [%s] [%s]:" % (str(Module), self.Arch))
-        LibraryConsumerList = [Module]
-
-        # "CompilerStub" is a must for R8 modules
-        if Module.Libraries:
-            Module.Libraries.append("CompilerStub")
-        LibraryList = []
-        while len(LibraryConsumerList) > 0:
-            M = LibraryConsumerList.pop()
-            for LibraryName in M.Libraries:
-                Library = self.Platform.LibraryClasses[LibraryName, ':dummy:']
-                if Library == None:
-                    for Key in self.Platform.LibraryClasses.data.keys():
-                        if LibraryName.upper() == Key.upper():
-                            Library = self.Platform.LibraryClasses[Key, ':dummy:']
-                            break
-                    if Library == None:
-                        EdkLogger.warn("build", "Library [%s] is not found" % LibraryName, File=str(M),
-                            ExtraData="\t%s [%s]" % (str(Module), self.Arch))
-                        continue
-
-                if Library not in LibraryList:
-                    LibraryList.append(Library)
-                    LibraryConsumerList.append(Library)
-                    EdkLogger.verbose("\t" + LibraryName + " : " + str(Library) + ' ' + str(type(Library)))
-        return LibraryList
-
-    ## Expand * in build option key
-    #
-    #   @param  Options     Options to be expanded
-    #
-    #   @retval options     Options expanded
-    #
-    def _ExpandBuildOption(self, Options):
-        BuildOptions = {}
-        for Key in Options:
-            Family = Key[0]
-            Target, Tag, Arch, Tool, Attr = Key[1].split("_")
-            # if tool chain family doesn't match, skip it
-            if Family and Tool in self.ToolDefinition and Family != self.ToolDefinition[Tool]["FAMILY"]:
-                continue
-            # expand any wildcard
-            if Target == "*" or Target == self.BuildTarget:
-                if Tag == "*" or Tag == self.ToolChain:
-                    if Arch == "*" or Arch == self.Arch:
-                        if Tool not in BuildOptions:
-                            BuildOptions[Tool] = {}
-                        if Attr != "FLAGS" or Attr not in BuildOptions[Tool]:
-                            BuildOptions[Tool][Attr] = Options[Key]
-                        else:
-                            # append options for the same tool
-                            BuildOptions[Tool][Attr] += " " + Options[Key]
-        return BuildOptions
-
-    ## Append build options in platform to a module
-    #
-    #   @param  Module  The module to which the build options will be appened
-    #
-    #   @retval options     The options appended with build options in platform
-    #
-    def ApplyBuildOption(self, Module):
-        PlatformOptions = self.BuildOption
-        ModuleOptions = self._ExpandBuildOption(Module.BuildOptions)
-        if Module in self.Platform.Modules:
-            PlatformModule = self.Platform.Modules[str(Module)]
-            PlatformModuleOptions = self._ExpandBuildOption(PlatformModule.BuildOptions)
-        else:
-            PlatformModuleOptions = {}
-
-        AllTools = set(ModuleOptions.keys() + PlatformOptions.keys() + PlatformModuleOptions.keys() + self.ToolDefinition.keys())
-        BuildOptions = {}
-        for Tool in AllTools:
-            if Tool not in BuildOptions:
-                BuildOptions[Tool] = {}
-
-            for Options in [self.ToolDefinition, ModuleOptions, PlatformOptions, PlatformModuleOptions]:
-                if Tool not in Options:
-                    continue
-                for Attr in Options[Tool]:
-                    Value = Options[Tool][Attr]
-                    if Attr not in BuildOptions[Tool]:
-                        BuildOptions[Tool][Attr] = ""
-                    # check if override is indicated
-                    if Value.startswith('='):
-                        BuildOptions[Tool][Attr] = Value[1:]
-                    else:
-                        BuildOptions[Tool][Attr] += " " + Value
-        return BuildOptions
-
-    Platform            = property(_GetPlatform)
-    Name                = property(_GetName)
-    Guid                = property(_GetGuid)
-    Version             = property(_GetVersion)
-
-    OutputDir           = property(_GetOutputDir)
-    BuildDir            = property(_GetBuildDir)
-    MakeFileDir         = property(_GetMakeFileDir)
-    FdfFile             = property(_GetFdfFile)
-
-    PcdTokenNumber      = property(_GetPcdTokenNumbers)    # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber
-    DynamicPcdList      = property(_GetDynamicPcdList)    # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
-    NonDynamicPcdList   = property(_GetNonDynamicPcdList)    # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
-    PackageList         = property(_GetPackageList)
-
-    ToolDefinition      = property(_GetToolDefinition)    # toolcode : tool path
-    ToolDefinitionFile  = property(_GetToolDefFile)    # toolcode : lib path
-    ToolChainFamily     = property(_GetToolChainFamily)
-    BuildRuleFamily     = property(_GetBuildRuleFamily)
-    BuildOption         = property(_GetBuildOptions)    # toolcode : option
-
-    BuildCommand        = property(_GetBuildCommand)
-    BuildRule           = property(_GetBuildRule)
-    ModuleAutoGenList   = property(_GetModuleAutoGenList)
-    LibraryAutoGenList  = property(_GetLibraryAutoGenList)
-
-## ModuleAutoGen class
-#
-# This class encapsules the AutoGen behaviors for the build tools. In addition to
-# the generation of AutoGen.h and AutoGen.c, it will generate *.depex file according
-# to the [depex] section in module's inf file.
-#
-class ModuleAutoGen(AutoGen):
-    ## The real constructor of ModuleAutoGen
-    #
-    #  This method is not supposed to be called by users of ModuleAutoGen. It's
-    #  only used by factory method __new__() to do real initialization work for an
-    #  object of ModuleAutoGen
-    #
-    #   @param      Workspace           EdkIIWorkspaceBuild object
-    #   @param      ModuleFile          The path of module file
-    #   @param      Target              Build target (DEBUG, RELEASE)
-    #   @param      Toolchain           Name of tool chain
-    #   @param      Arch                The arch the module supports
-    #   @param      PlatformFile        Platform meta-file
-    #
-    def _Init(self, Workspace, ModuleFile, Target, Toolchain, Arch, PlatformFile):
-        EdkLogger.debug(EdkLogger.DEBUG_9, "AutoGen module [%s] [%s]" % (ModuleFile, Arch))
-        GlobalData.gProcessingFile = "%s [%s, %s, %s]" % (ModuleFile, Arch, Toolchain, Target)
-
-        self.Workspace = Workspace
-        self.WorkspaceDir = Workspace.WorkspaceDir
-
-        self.MetaFile = ModuleFile
-        self.PlatformInfo = PlatformAutoGen(Workspace, PlatformFile, Target, Toolchain, Arch)
-        # check if this module is employed by active platform
-        if not self.PlatformInfo.ValidModule(self.MetaFile):
-            EdkLogger.verbose("Module [%s] for [%s] is not employed by active platform\n" \
-                              % (self.MetaFile, Arch))
-            return False
-
-        self.SourceDir = self.MetaFile.SubDir
-        self.SourceOverrideDir = None
-        # use overrided path defined in DSC file
-        if self.MetaFile.Key in GlobalData.gOverrideDir:
-            self.SourceOverrideDir = GlobalData.gOverrideDir[self.MetaFile.Key]
-
-        self.ToolChain = Toolchain
-        self.BuildTarget = Target
-        self.Arch = Arch
-        self.ToolChainFamily = self.PlatformInfo.ToolChainFamily
-        self.BuildRuleFamily = self.PlatformInfo.BuildRuleFamily
-
-        self.IsMakeFileCreated = False
-        self.IsCodeFileCreated = False
-
-        self.BuildDatabase = self.Workspace.BuildDatabase
-
-        self._Module          = None
-        self._Name            = None
-        self._Guid            = None
-        self._Version         = None
-        self._ModuleType      = None
-        self._ComponentType   = None
-        self._PcdIsDriver     = None
-        self._AutoGenVersion  = None
-        self._LibraryFlag     = None
-        self._CustomMakefile  = None
-        self._Macro           = None
-
-        self._BuildDir        = None
-        self._OutputDir       = None
-        self._DebugDir        = None
-        self._MakeFileDir     = None
-
-        self._IncludePathList = None
-        self._AutoGenFileList = None
-        self._UnicodeFileList = None
-        self._SourceFileList  = None
-        self._ObjectFileList  = None
-        self._BinaryFileList  = None
-
-        self._DependentPackageList    = None
-        self._DependentLibraryList    = None
-        self._LibraryAutoGenList      = None
-        self._DerivedPackageList      = None
-        self._ModulePcdList           = None
-        self._LibraryPcdList          = None
-        self._GuidList                = None
-        self._ProtocolList            = None
-        self._PpiList                 = None
-        self._DepexList               = None
-        self._BuildOption             = None
-        self._BuildTargets            = None
-        self._IntroBuildTargetList    = None
-        self._FinalBuildTargetList    = None
-        self._FileTypes               = None
-        self._BuildRules              = None
-
-        return True
-
-    def __repr__(self):
-        return "%s [%s]" % (self.MetaFile, self.Arch)
-
-    # Macros could be used in build_rule.txt (also Makefile)
-    def _GetMacros(self):
-        if self._Macro == None:
-            self._Macro = sdict()
-            self._Macro["WORKSPACE"             ] = self.WorkspaceDir
-            self._Macro["MODULE_NAME"           ] = self.Name
-            self._Macro["MODULE_GUID"           ] = self.Guid
-            self._Macro["MODULE_VERSION"        ] = self.Version
-            self._Macro["MODULE_TYPE"           ] = self.ModuleType
-            self._Macro["MODULE_FILE"           ] = str(self.MetaFile)
-            self._Macro["MODULE_FILE_BASE_NAME" ] = self.MetaFile.BaseName
-            self._Macro["MODULE_RELATIVE_DIR"   ] = self.SourceDir
-            self._Macro["MODULE_DIR"            ] = self.SourceDir
-
-            self._Macro["BASE_NAME"             ] = self.Name
-
-            self._Macro["ARCH"                  ] = self.Arch
-            self._Macro["TOOLCHAIN"             ] = self.ToolChain
-            self._Macro["TOOLCHAIN_TAG"         ] = self.ToolChain
-            self._Macro["TARGET"                ] = self.BuildTarget
-
-            self._Macro["BUILD_DIR"             ] = self.PlatformInfo.BuildDir
-            self._Macro["BIN_DIR"               ] = os.path.join(self.PlatformInfo.BuildDir, self.Arch)
-            self._Macro["LIB_DIR"               ] = os.path.join(self.PlatformInfo.BuildDir, self.Arch)
-            self._Macro["MODULE_BUILD_DIR"      ] = self.BuildDir
-            self._Macro["OUTPUT_DIR"            ] = self.OutputDir
-            self._Macro["DEBUG_DIR"             ] = self.DebugDir
-        return self._Macro
-
-    ## Return the module build data object
-    def _GetModule(self):
-        if self._Module == None:
-            self._Module = self.Workspace.BuildDatabase[self.MetaFile, self.Arch]
-        return self._Module
-
-    ## Return the module name
-    def _GetBaseName(self):
-        return self.Module.BaseName
-
-    ## Return the module SourceOverridePath
-    def _GetSourceOverridePath(self):
-        return self.Module.SourceOverridePath
-
-    ## Return the module meta-file GUID
-    def _GetGuid(self):
-        return self.Module.Guid
-
-    ## Return the module version
-    def _GetVersion(self):
-        return self.Module.Version
-
-    ## Return the module type
-    def _GetModuleType(self):
-        return self.Module.ModuleType
-
-    ## Return the component type (for R8.x style of module)
-    def _GetComponentType(self):
-        return self.Module.ComponentType
-
-    ## Return the build type
-    def _GetBuildType(self):
-        return self.Module.BuildType
-
-    ## Return the PCD_IS_DRIVER setting
-    def _GetPcdIsDriver(self):
-        return self.Module.PcdIsDriver
-
-    ## Return the autogen version, i.e. module meta-file version
-    def _GetAutoGenVersion(self):
-        return self.Module.AutoGenVersion
-
-    ## Check if the module is library or not
-    def _IsLibrary(self):
-        if self._LibraryFlag == None:
-            if self.Module.LibraryClass != None and self.Module.LibraryClass != []:
-                self._LibraryFlag = True
-            else:
-                self._LibraryFlag = False
-        return self._LibraryFlag
-
-    ## Return the directory to store intermediate files of the module
-    def _GetBuildDir(self):
-        if self._BuildDir == None:
-            self._BuildDir = path.join(
-                                    self.PlatformInfo.BuildDir,
-                                    self.Arch,
-                                    self.SourceDir,
-                                    self.MetaFile.BaseName
-                                    )
-            CreateDirectory(self._BuildDir)
-        return self._BuildDir
-
-    ## Return the directory to store the intermediate object files of the mdoule
-    def _GetOutputDir(self):
-        if self._OutputDir == None:
-            self._OutputDir = path.join(self.BuildDir, "OUTPUT")
-            CreateDirectory(self._OutputDir)
-        return self._OutputDir
-
-    ## Return the directory to store auto-gened source files of the mdoule
-    def _GetDebugDir(self):
-        if self._DebugDir == None:
-            self._DebugDir = path.join(self.BuildDir, "DEBUG")
-            CreateDirectory(self._DebugDir)
-        return self._DebugDir
-
-    ## Return the path of custom file
-    def _GetCustomMakefile(self):
-        if self._CustomMakefile == None:
-            self._CustomMakefile = {}
-            for Type in self.Module.CustomMakefile:
-                if Type in gMakeTypeMap:
-                    MakeType = gMakeTypeMap[Type]
-                else:
-                    MakeType = 'nmake'
-                if self.SourceOverrideDir != None:
-                    File = os.path.join(self.SourceOverrideDir, self.Module.CustomMakefile[Type])
-                    if not os.path.exists(File):
-                        File = os.path.join(self.SourceDir, self.Module.CustomMakefile[Type])
-                else:
-                    File = os.path.join(self.SourceDir, self.Module.CustomMakefile[Type])
-                self._CustomMakefile[MakeType] = File
-        return self._CustomMakefile
-
-    ## Return the directory of the makefile
-    #
-    #   @retval     string  The directory string of module's makefile
-    #
-    def _GetMakeFileDir(self):
-        return self.BuildDir
-
-    ## Return build command string
-    #
-    #   @retval     string  Build command string
-    #
-    def _GetBuildCommand(self):
-        return self.PlatformInfo.BuildCommand
-
-    ## Get object list of all packages the module and its dependent libraries belong to
-    #
-    #   @retval     list    The list of package object
-    #
-    def _GetDerivedPackageList(self):
-        PackageList = []
-        for M in [self.Module] + self.DependentLibraryList:
-            for Package in M.Packages:
-                if Package in PackageList:
-                    continue
-                PackageList.append(Package)
-        return PackageList
-
-    ## Merge dependency expression
-    #
-    #   @retval     list    The token list of the dependency expression after parsed
-    #
-    def _GetDepexTokenList(self):
-        if self._DepexList == None:
-            self._DepexList = {}
-            if self.IsLibrary or TAB_DEPENDENCY_EXPRESSION_FILE in self.FileTypes:
-                return self._DepexList
-
-            if self.ModuleType == "DXE_SMM_DRIVER":
-                self._DepexList["DXE_DRIVER"] = []
-                self._DepexList["SMM_DRIVER"] = []
-            else:
-                self._DepexList[self.ModuleType] = []
-
-            for ModuleType in self._DepexList:
-                DepexList = self._DepexList[ModuleType]
-                #
-                # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion
-                #
-                for M in [self.Module] + self.DependentLibraryList:
-                    Inherited = False
-                    for D in M.Depex[self.Arch, ModuleType]:
-                        if DepexList != []:
-                            DepexList.append('AND')
-                        DepexList.append('(')
-                        DepexList.extend(D)
-                        if DepexList[-1] == 'END':  # no need of a END at this time
-                            DepexList.pop()
-                        DepexList.append(')')
-                        Inherited = True
-                    if Inherited:
-                        EdkLogger.verbose("DEPEX[%s] (+%s) = %s" % (self.Name, M.BaseName, DepexList))
-                    if 'BEFORE' in DepexList or 'AFTER' in DepexList:
-                        break
-                if len(DepexList) > 0:
-                    EdkLogger.verbose('')
-        return self._DepexList
-
-    ## Return the list of specification version required for the module
-    #
-    #   @retval     list    The list of specification defined in module file
-    #
-    def _GetSpecification(self):
-        return self.Module.Specification
-
-    ## Tool option for the module build
-    #
-    #   @param      PlatformInfo    The object of PlatformBuildInfo
-    #   @retval     dict            The dict containing valid options
-    #
-    def _GetModuleBuildOption(self):
-        if self._BuildOption == None:
-            self._BuildOption = self.PlatformInfo.ApplyBuildOption(self.Module)
-        return self._BuildOption
-
-    ## Return a list of files which can be built from source
-    #
-    #  What kind of files can be built is determined by build rules in
-    #  $(WORKSPACE)/Conf/build_rule.txt and toolchain family.
-    #
-    def _GetSourceFileList(self):
-        if self._SourceFileList == None:
-            self._SourceFileList = []
-            for F in self.Module.Sources:
-                # match tool chain
-                if F.TagName != "" and F.TagName != self.ToolChain:
-                    EdkLogger.debug(EdkLogger.DEBUG_9, "The toolchain [%s] for processing file [%s] is found, "
-                                    "but [%s] is needed" % (F.TagName, str(F), self.ToolChain))
-                    continue
-                # match tool chain family
-                if F.ToolChainFamily != "" and F.ToolChainFamily != self.ToolChainFamily:
-                    EdkLogger.debug(
-                                EdkLogger.DEBUG_0,
-                                "The file [%s] must be built by tools of [%s], " \
-                                "but current toolchain family is [%s]" \
-                                    % (str(F), F.ToolChainFamily, self.ToolChainFamily))
-                    continue
-
-                # add the file path into search path list for file including
-                if F.Dir not in self.IncludePathList and self.AutoGenVersion >= 0x00010005:
-                    self.IncludePathList.insert(0, F.Dir)
-                self._SourceFileList.append(F)
-                self._ApplyBuildRule(F, TAB_UNKNOWN_FILE)
-        return self._SourceFileList
-
-    ## Return the list of unicode files
-    def _GetUnicodeFileList(self):
-        if self._UnicodeFileList == None:
-            if TAB_UNICODE_FILE in self.FileTypes:
-                self._UnicodeFileList = self.FileTypes[TAB_UNICODE_FILE]
-            else:
-                self._UnicodeFileList = []
-        return self._UnicodeFileList
-
-    ## Return a list of files which can be built from binary
-    #
-    #  "Build" binary files are just to copy them to build directory.
-    #
-    #   @retval     list            The list of files which can be built later
-    #
-    def _GetBinaryFiles(self):
-        if self._BinaryFileList == None:
-            self._BinaryFileList = []
-            for F in self.Module.Binaries:
-                if F.Target not in ['COMMON', '*'] and F.Target != self.BuildTarget:
-                    continue
-                self._BinaryFileList.append(F)
-                self._ApplyBuildRule(F, F.Type)
-        return self._BinaryFileList
-
-    def _GetBuildRules(self):
-        if self._BuildRules == None:
-            BuildRules = {}
-            BuildRuleDatabase = self.PlatformInfo.BuildRule
-            for Type in BuildRuleDatabase.FileTypeList:
-                #first try getting build rule by BuildRuleFamily
-                RuleObject = BuildRuleDatabase[Type, self.BuildType, self.Arch, self.BuildRuleFamily]
-                if not RuleObject:
-                    # build type is always module type, but ...
-                    if self.ModuleType != self.BuildType:
-                        RuleObject = BuildRuleDatabase[Type, self.ModuleType, self.Arch, self.BuildRuleFamily]
-                #second try getting build rule by ToolChainFamily
-                if not RuleObject:
-                    RuleObject = BuildRuleDatabase[Type, self.BuildType, self.Arch, self.ToolChainFamily]
-                    if not RuleObject:
-                        # build type is always module type, but ...
-                        if self.ModuleType != self.BuildType:
-                            RuleObject = BuildRuleDatabase[Type, self.ModuleType, self.Arch, self.ToolChainFamily]
-                if not RuleObject:
-                    continue
-                RuleObject = RuleObject.Instantiate(self.Macros)
-                BuildRules[Type] = RuleObject
-                for Ext in RuleObject.SourceFileExtList:
-                    BuildRules[Ext] = RuleObject
-            self._BuildRules = BuildRules
-        return self._BuildRules
-
-    def _ApplyBuildRule(self, File, FileType):
-        if self._BuildTargets == None:
-            self._IntroBuildTargetList = set()
-            self._FinalBuildTargetList = set()
-            self._BuildTargets = {}
-            self._FileTypes = {}
-
-        LastTarget = None
-        RuleChain = []
-        SourceList = [File]
-        Index = 0
-        while Index < len(SourceList):
-            Source = SourceList[Index]
-            Index = Index + 1
-
-            if Source != File:
-                CreateDirectory(Source.Dir)
-
-            if FileType in self.BuildRules:
-                RuleObject = self.BuildRules[FileType]
-            elif Source.Ext in self.BuildRules:
-                RuleObject = self.BuildRules[Source.Ext]
-            elif File.IsBinary and File == Source:
-                RuleObject = self.BuildRules[TAB_DEFAULT_BINARY_FILE]
-            else:
-                # stop at no more rules
-                if LastTarget:
-                    self._FinalBuildTargetList.add(LastTarget)
-                break
-
-            FileType = RuleObject.SourceFileType
-            if FileType not in self._FileTypes:
-                self._FileTypes[FileType] = set()
-            self._FileTypes[FileType].add(Source)
-
-            # stop at STATIC_LIBRARY for library
-            if self.IsLibrary and FileType == TAB_STATIC_LIBRARY:
-                self._FinalBuildTargetList.add(LastTarget)
-                break
-
-            Target = RuleObject.Apply(Source)
-            if not Target:
-                if LastTarget:
-                    self._FinalBuildTargetList.add(LastTarget)
-                break
-            elif not Target.Outputs:
-                # Only do build for target with outputs
-                self._FinalBuildTargetList.add(Target)
-
-            if FileType not in self._BuildTargets:
-                self._BuildTargets[FileType] = set()
-            self._BuildTargets[FileType].add(Target)
-
-            if not Source.IsBinary and Source == File:
-                self._IntroBuildTargetList.add(Target)
-
-            # to avoid cyclic rule
-            if FileType in RuleChain:
-                break
-
-            RuleChain.append(FileType)
-            SourceList.extend(Target.Outputs)
-            LastTarget = Target
-            FileType = TAB_UNKNOWN_FILE
-
-    def _GetTargets(self):
-        if self._BuildTargets == None:
-            self._IntroBuildTargetList = set()
-            self._FinalBuildTargetList = set()
-            self._BuildTargets = {}
-            self._FileTypes = {}
-
-        #TRICK: call _GetSourceFileList to apply build rule for binary files
-        if self.SourceFileList:
-            pass
-
-        #TRICK: call _GetBinaryFileList to apply build rule for binary files
-        if self.BinaryFileList:
-            pass
-
-        return self._BuildTargets
-
-    def _GetIntroTargetList(self):
-        self._GetTargets()
-        return self._IntroBuildTargetList
-
-    def _GetFinalTargetList(self):
-        self._GetTargets()
-        return self._FinalBuildTargetList
-
-    def _GetFileTypes(self):
-        self._GetTargets()
-        return self._FileTypes
-
-    ## Get the list of package object the module depends on
-    #
-    #   @retval     list    The package object list
-    #
-    def _GetDependentPackageList(self):
-        return self.Module.Packages
-
-    ## Return the list of auto-generated code file
-    #
-    #   @retval     list        The list of auto-generated file
-    #
-    def _GetAutoGenFileList(self):
-        if self._AutoGenFileList == None:
-            self._AutoGenFileList = {}
-            AutoGenC = TemplateString()
-            AutoGenH = TemplateString()
-            StringH = TemplateString()
-            GenC.CreateCode(self, AutoGenC, AutoGenH, StringH)
-            if str(AutoGenC) != "" and TAB_C_CODE_FILE in self.FileTypes:
-                AutoFile = PathClass(gAutoGenCodeFileName, self.DebugDir)
-                self._AutoGenFileList[AutoFile] = str(AutoGenC)
-                self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)
-            if str(AutoGenH) != "":
-                AutoFile = PathClass(gAutoGenHeaderFileName, self.DebugDir)
-                self._AutoGenFileList[AutoFile] = str(AutoGenH)
-                self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)
-            if str(StringH) != "":
-                AutoFile = PathClass(gAutoGenStringFileName % {"module_name":self.Name}, self.DebugDir)
-                self._AutoGenFileList[AutoFile] = str(StringH)
-                self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)
-        return self._AutoGenFileList
-
-    ## Return the list of library modules explicitly or implicityly used by this module
-    def _GetLibraryList(self):
-        if self._DependentLibraryList == None:
-            # only merge library classes and PCD for non-library module
-            if self.IsLibrary:
-                self._DependentLibraryList = []
-            else:
-                if self.AutoGenVersion < 0x00010005:
-                    self._DependentLibraryList = self.PlatformInfo.ResolveLibraryReference(self.Module)
-                else:
-                    self._DependentLibraryList = self.PlatformInfo.ApplyLibraryInstance(self.Module)
-        return self._DependentLibraryList
-
-    ## Get the list of PCDs from current module
-    #
-    #   @retval     list                    The list of PCD
-    #
-    def _GetModulePcdList(self):
-        if self._ModulePcdList == None:
-            # apply PCD settings from platform
-            self._ModulePcdList = self.PlatformInfo.ApplyPcdSetting(self.Module, self.Module.Pcds)
-        return self._ModulePcdList
-
-    ## Get the list of PCDs from dependent libraries
-    #
-    #   @retval     list                    The list of PCD
-    #
-    def _GetLibraryPcdList(self):
-        if self._LibraryPcdList == None:
-            Pcds = {}
-            if not self.IsLibrary:
-                # get PCDs from dependent libraries
-                for Library in self.DependentLibraryList:
-                    for Key in Library.Pcds:
-                        # skip duplicated PCDs
-                        if Key in self.Module.Pcds or Key in Pcds:
-                            continue
-                        Pcds[Key] = copy.copy(Library.Pcds[Key])
-                # apply PCD settings from platform
-                self._LibraryPcdList = self.PlatformInfo.ApplyPcdSetting(self.Module, Pcds)
-            else:
-                self._LibraryPcdList = []
-        return self._LibraryPcdList
-
-    ## Get the GUID value mapping
-    #
-    #   @retval     dict    The mapping between GUID cname and its value
-    #
-    def _GetGuidList(self):
-        if self._GuidList == None:
-            self._GuidList = self.Module.Guids
-            for Library in self.DependentLibraryList:
-                self._GuidList.update(Library.Guids)
-        return self._GuidList
-
-    ## Get the protocol value mapping
-    #
-    #   @retval     dict    The mapping between protocol cname and its value
-    #
-    def _GetProtocolList(self):
-        if self._ProtocolList == None:
-            self._ProtocolList = self.Module.Protocols
-            for Library in self.DependentLibraryList:
-                self._ProtocolList.update(Library.Protocols)
-        return self._ProtocolList
-
-    ## Get the PPI value mapping
-    #
-    #   @retval     dict    The mapping between PPI cname and its value
-    #
-    def _GetPpiList(self):
-        if self._PpiList == None:
-            self._PpiList = self.Module.Ppis
-            for Library in self.DependentLibraryList:
-                self._PpiList.update(Library.Ppis)
-        return self._PpiList
-
-    ## Get the list of include search path
-    #
-    #   @retval     list                    The list path
-    #
-    def _GetIncludePathList(self):
-        if self._IncludePathList == None:
-            self._IncludePathList = []
-            if self.AutoGenVersion < 0x00010005:
-                for Inc in self.Module.Includes:
-                    if Inc not in self._IncludePathList:
-                        self._IncludePathList.append(Inc)
-                    # for r8 modules
-                    Inc = path.join(Inc, self.Arch.capitalize())
-                    if os.path.exists(Inc) and Inc not in self._IncludePathList:
-                        self._IncludePathList.append(Inc)
-                # r8 module needs to put DEBUG_DIR at the end of search path and not to use SOURCE_DIR all the time
-                self._IncludePathList.append(self.DebugDir)
-            else:
-                self._IncludePathList.append(self.MetaFile.Dir)
-                self._IncludePathList.append(self.DebugDir)
-
-            for Package in self.Module.Packages:
-                PackageDir = path.join(self.WorkspaceDir, Package.MetaFile.Dir)
-                if PackageDir not in self._IncludePathList:
-                    self._IncludePathList.append(PackageDir)
-                for Inc in Package.Includes:
-                    if Inc not in self._IncludePathList:
-                        self._IncludePathList.append(str(Inc))
-        return self._IncludePathList
-
-    ## Create makefile for the module and its dependent libraries
-    #
-    #   @param      CreateLibraryMakeFile   Flag indicating if or not the makefiles of
-    #                                       dependent libraries will be created
-    #
-    def CreateMakeFile(self, CreateLibraryMakeFile=True):
-        if self.IsMakeFileCreated:
-            return
-
-        if not self.IsLibrary and CreateLibraryMakeFile:
-            for LibraryAutoGen in self.LibraryAutoGenList:
-                LibraryAutoGen.CreateMakeFile()
-
-        if len(self.CustomMakefile) == 0:
-            Makefile = GenMake.ModuleMakefile(self)
-        else:
-            Makefile = GenMake.CustomMakefile(self)
-        if Makefile.Generate():
-            EdkLogger.debug(EdkLogger.DEBUG_9, "Generated makefile for module %s [%s]" %
-                            (self.Name, self.Arch))
-        else:
-            EdkLogger.debug(EdkLogger.DEBUG_9, "Skipped the generation of makefile for module %s [%s]" %
-                            (self.Name, self.Arch))
-
-        self.IsMakeFileCreated = True
-
-    ## Create autogen code for the module and its dependent libraries
-    #
-    #   @param      CreateLibraryCodeFile   Flag indicating if or not the code of
-    #                                       dependent libraries will be created
-    #
-    def CreateCodeFile(self, CreateLibraryCodeFile=True):
-        if self.IsCodeFileCreated:
-            return
-
-        if not self.IsLibrary and CreateLibraryCodeFile:
-            for LibraryAutoGen in self.LibraryAutoGenList:
-                LibraryAutoGen.CreateCodeFile()
-
-        AutoGenList = []
-        IgoredAutoGenList = []
-
-        for File in self.AutoGenFileList:
-            if GenC.Generate(File.Path, self.AutoGenFileList[File]):
-                #Ignore R8 AutoGen.c
-                if self.AutoGenVersion < 0x00010005 and File.Name == 'AutoGen.c':
-                        continue
-
-                AutoGenList.append(str(File))
-            else:
-                IgoredAutoGenList.append(str(File))
-
-        for ModuleType in self.DepexList:
-            if len(self.DepexList[ModuleType]) == 0:
-                continue
-            Dpx = GenDepex.DependencyExpression(self.DepexList[ModuleType], ModuleType, True)
-            if ModuleType == 'SMM_DRIVER':
-                DpxFile = gAutoGenSmmDepexFileName % {"module_name" : self.Name}
-            else:
-                DpxFile = gAutoGenDepexFileName % {"module_name" : self.Name}
-
-            if Dpx.Generate(path.join(self.OutputDir, DpxFile)):
-                AutoGenList.append(str(DpxFile))
-            else:
-                IgoredAutoGenList.append(str(DpxFile))
-
-        if IgoredAutoGenList == []:
-            EdkLogger.debug(EdkLogger.DEBUG_9, "Generated [%s] files for module %s [%s]" %
-                            (" ".join(AutoGenList), self.Name, self.Arch))
-        elif AutoGenList == []:
-            EdkLogger.debug(EdkLogger.DEBUG_9, "Skipped the generation of [%s] files for module %s [%s]" %
-                            (" ".join(IgoredAutoGenList), self.Name, self.Arch))
-        else:
-            EdkLogger.debug(EdkLogger.DEBUG_9, "Generated [%s] (skipped %s) files for module %s [%s]" %
-                            (" ".join(AutoGenList), " ".join(IgoredAutoGenList), self.Name, self.Arch))
-
-        self.IsCodeFileCreated = True
-        return AutoGenList
-
-    ## Summarize the ModuleAutoGen objects of all libraries used by this module
-    def _GetLibraryAutoGenList(self):
-        if self._LibraryAutoGenList == None:
-            self._LibraryAutoGenList = []
-            for Library in self.DependentLibraryList:
-                La = ModuleAutoGen(
-                        self.Workspace,
-                        Library.MetaFile,
-                        self.BuildTarget,
-                        self.ToolChain,
-                        self.Arch,
-                        self.PlatformInfo.MetaFile
-                        )
-                if La not in self._LibraryAutoGenList:
-                    self._LibraryAutoGenList.append(La)
-                    for Lib in La.CodaTargetList:
-                        self._ApplyBuildRule(Lib.Target, TAB_UNKNOWN_FILE)
-        return self._LibraryAutoGenList
-
-    ## Return build command string
-    #
-    #   @retval     string  Build command string
-    #
-    def _GetBuildCommand(self):
-        return self.PlatformInfo.BuildCommand
-
-
-    Module          = property(_GetModule)
-    Name            = property(_GetBaseName)
-    Guid            = property(_GetGuid)
-    Version         = property(_GetVersion)
-    ModuleType      = property(_GetModuleType)
-    ComponentType   = property(_GetComponentType)
-    BuildType       = property(_GetBuildType)
-    PcdIsDriver     = property(_GetPcdIsDriver)
-    AutoGenVersion  = property(_GetAutoGenVersion)
-    Macros          = property(_GetMacros)
-    Specification   = property(_GetSpecification)
-
-    IsLibrary       = property(_IsLibrary)
-
-    BuildDir        = property(_GetBuildDir)
-    OutputDir       = property(_GetOutputDir)
-    DebugDir        = property(_GetDebugDir)
-    MakeFileDir     = property(_GetMakeFileDir)
-    CustomMakefile  = property(_GetCustomMakefile)
-
-    IncludePathList = property(_GetIncludePathList)
-    AutoGenFileList = property(_GetAutoGenFileList)
-    UnicodeFileList = property(_GetUnicodeFileList)
-    SourceFileList  = property(_GetSourceFileList)
-    BinaryFileList  = property(_GetBinaryFiles) # FileType : [File List]
-    Targets         = property(_GetTargets)
-    IntroTargetList = property(_GetIntroTargetList)
-    CodaTargetList  = property(_GetFinalTargetList)
-    FileTypes       = property(_GetFileTypes)
-    BuildRules      = property(_GetBuildRules)
-
-    DependentPackageList    = property(_GetDependentPackageList)
-    DependentLibraryList    = property(_GetLibraryList)
-    LibraryAutoGenList      = property(_GetLibraryAutoGenList)
-    DerivedPackageList      = property(_GetDerivedPackageList)
-
-    ModulePcdList           = property(_GetModulePcdList)
-    LibraryPcdList          = property(_GetLibraryPcdList)
-    GuidList                = property(_GetGuidList)
-    ProtocolList            = property(_GetProtocolList)
-    PpiList                 = property(_GetPpiList)
-    DepexList               = property(_GetDepexTokenList)
-    BuildOption             = property(_GetModuleBuildOption)
-    BuildCommand            = property(_GetBuildCommand)
-
-# This acts like the main() function for the script, unless it is 'import'ed into another script.
-if __name__ == '__main__':
-    pass
-
+## @file\r
+# Generate AutoGen.h, AutoGen.c and *.depex files\r
+#\r
+# Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+\r
+## Import Modules\r
+#\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
+\r
+from StrGather import *\r
+from BuildEngine import BuildRule\r
+\r
+from Common.LongFilePathSupport import CopyLongFilePath\r
+from Common.BuildToolError import *\r
+from Common.DataType import *\r
+from Common.Misc import *\r
+from Common.String import *\r
+import Common.GlobalData as GlobalData\r
+from GenFds.FdfParser import *\r
+from CommonDataClass.CommonClass import SkuInfoClass\r
+from Workspace.BuildClassObject import *\r
+from GenPatchPcdTable.GenPatchPcdTable import parsePcdInfoFromMapFile\r
+import Common.VpdInfoFile as VpdInfoFile\r
+from GenPcdDb import CreatePcdDatabaseCode\r
+from Workspace.MetaFileCommentParser import UsageList\r
+from Common.MultipleWorkspace import MultipleWorkspace as mws\r
+import InfSectionParser\r
+import datetime\r
+import hashlib\r
+from GenVar import VariableMgr,var_info\r
+\r
+## Regular expression for splitting Dependency Expression string into tokens\r
+gDepexTokenPattern = re.compile("(\(|\)|\w+| \S+\.inf)")\r
+\r
+#\r
+# Match name = variable\r
+#\r
+gEfiVarStoreNamePattern = re.compile("\s*name\s*=\s*(\w+)")\r
+#\r
+# The format of guid in efivarstore statement likes following and must be correct:\r
+# guid = {0xA04A27f4, 0xDF00, 0x4D42, {0xB5, 0x52, 0x39, 0x51, 0x13, 0x02, 0x11, 0x3D}}\r
+#\r
+gEfiVarStoreGuidPattern = re.compile("\s*guid\s*=\s*({.*?{.*?}\s*})")\r
+\r
+## Mapping Makefile type\r
+gMakeTypeMap = {"MSFT":"nmake", "GCC":"gmake"}\r
+\r
+\r
+## Build rule configuration file\r
+gDefaultBuildRuleFile = 'build_rule.txt'\r
+\r
+## Tools definition configuration file\r
+gDefaultToolsDefFile = 'tools_def.txt'\r
+\r
+## Build rule default version\r
+AutoGenReqBuildRuleVerNum = "0.1"\r
+\r
+## default file name for AutoGen\r
+gAutoGenCodeFileName = "AutoGen.c"\r
+gAutoGenHeaderFileName = "AutoGen.h"\r
+gAutoGenStringFileName = "%(module_name)sStrDefs.h"\r
+gAutoGenStringFormFileName = "%(module_name)sStrDefs.hpk"\r
+gAutoGenDepexFileName = "%(module_name)s.depex"\r
+gAutoGenImageDefFileName = "%(module_name)sImgDefs.h"\r
+gAutoGenIdfFileName = "%(module_name)sIdf.hpk"\r
+gInfSpecVersion = "0x00010017"\r
+\r
+#\r
+# Template string to generic AsBuilt INF\r
+#\r
+gAsBuiltInfHeaderString = TemplateString("""${header_comments}\r
+\r
+# DO NOT EDIT\r
+# FILE auto-generated\r
+\r
+[Defines]\r
+  INF_VERSION                = ${module_inf_version}\r
+  BASE_NAME                  = ${module_name}\r
+  FILE_GUID                  = ${module_guid}\r
+  MODULE_TYPE                = ${module_module_type}${BEGIN}\r
+  VERSION_STRING             = ${module_version_string}${END}${BEGIN}\r
+  PCD_IS_DRIVER              = ${pcd_is_driver_string}${END}${BEGIN}\r
+  UEFI_SPECIFICATION_VERSION = ${module_uefi_specification_version}${END}${BEGIN}\r
+  PI_SPECIFICATION_VERSION   = ${module_pi_specification_version}${END}${BEGIN}\r
+  ENTRY_POINT                = ${module_entry_point}${END}${BEGIN}\r
+  UNLOAD_IMAGE               = ${module_unload_image}${END}${BEGIN}\r
+  CONSTRUCTOR                = ${module_constructor}${END}${BEGIN}\r
+  DESTRUCTOR                 = ${module_destructor}${END}${BEGIN}\r
+  SHADOW                     = ${module_shadow}${END}${BEGIN}\r
+  PCI_VENDOR_ID              = ${module_pci_vendor_id}${END}${BEGIN}\r
+  PCI_DEVICE_ID              = ${module_pci_device_id}${END}${BEGIN}\r
+  PCI_CLASS_CODE             = ${module_pci_class_code}${END}${BEGIN}\r
+  PCI_REVISION               = ${module_pci_revision}${END}${BEGIN}\r
+  BUILD_NUMBER               = ${module_build_number}${END}${BEGIN}\r
+  SPEC                       = ${module_spec}${END}${BEGIN}\r
+  UEFI_HII_RESOURCE_SECTION  = ${module_uefi_hii_resource_section}${END}${BEGIN}\r
+  MODULE_UNI_FILE            = ${module_uni_file}${END}\r
+\r
+[Packages.${module_arch}]${BEGIN}\r
+  ${package_item}${END}\r
+\r
+[Binaries.${module_arch}]${BEGIN}\r
+  ${binary_item}${END}\r
+\r
+[PatchPcd.${module_arch}]${BEGIN}\r
+  ${patchablepcd_item}\r
+${END}\r
+\r
+[Protocols.${module_arch}]${BEGIN}\r
+  ${protocol_item}\r
+${END}\r
+\r
+[Ppis.${module_arch}]${BEGIN}\r
+  ${ppi_item}\r
+${END}\r
+\r
+[Guids.${module_arch}]${BEGIN}\r
+  ${guid_item}\r
+${END}\r
+\r
+[PcdEx.${module_arch}]${BEGIN}\r
+  ${pcd_item}\r
+${END}\r
+\r
+[LibraryClasses.${module_arch}]\r
+## @LIB_INSTANCES${BEGIN}\r
+#  ${libraryclasses_item}${END}\r
+\r
+${depexsection_item}\r
+\r
+${userextension_tianocore_item}\r
+\r
+${tail_comments}\r
+\r
+[BuildOptions.${module_arch}]\r
+## @AsBuilt${BEGIN}\r
+##   ${flags_item}${END}\r
+""")\r
+\r
+## Base class for AutoGen\r
+#\r
+#   This class just implements the cache mechanism of AutoGen objects.\r
+#\r
+class AutoGen(object):\r
+    # database to maintain the objects of xxxAutoGen\r
+    _CACHE_ = {}    # (BuildTarget, ToolChain) : {ARCH : {platform file: AutoGen object}}}\r
+\r
+    ## Factory method\r
+    #\r
+    #   @param  Class           class object of real AutoGen class\r
+    #                           (WorkspaceAutoGen, ModuleAutoGen or PlatformAutoGen)\r
+    #   @param  Workspace       Workspace directory or WorkspaceAutoGen object\r
+    #   @param  MetaFile        The path of meta file\r
+    #   @param  Target          Build target\r
+    #   @param  Toolchain       Tool chain name\r
+    #   @param  Arch            Target arch\r
+    #   @param  *args           The specific class related parameters\r
+    #   @param  **kwargs        The specific class related dict parameters\r
+    #\r
+    def __new__(Class, Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs):\r
+        # check if the object has been created\r
+        Key = (Target, Toolchain)\r
+        if Key not in Class._CACHE_ or Arch not in Class._CACHE_[Key] \\r
+           or MetaFile not in Class._CACHE_[Key][Arch]:\r
+            AutoGenObject = super(AutoGen, Class).__new__(Class)\r
+            # call real constructor\r
+            if not AutoGenObject._Init(Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs):\r
+                return None\r
+            if Key not in Class._CACHE_:\r
+                Class._CACHE_[Key] = {}\r
+            if Arch not in Class._CACHE_[Key]:\r
+                Class._CACHE_[Key][Arch] = {}\r
+            Class._CACHE_[Key][Arch][MetaFile] = AutoGenObject\r
+        else:\r
+            AutoGenObject = Class._CACHE_[Key][Arch][MetaFile]\r
+\r
+        return AutoGenObject\r
+\r
+    ## hash() operator\r
+    #\r
+    #  The file path of platform file will be used to represent hash value of this object\r
+    #\r
+    #   @retval int     Hash value of the file path of platform file\r
+    #\r
+    def __hash__(self):\r
+        return hash(self.MetaFile)\r
+\r
+    ## str() operator\r
+    #\r
+    #  The file path of platform file will be used to represent this object\r
+    #\r
+    #   @retval string  String of platform file path\r
+    #\r
+    def __str__(self):\r
+        return str(self.MetaFile)\r
+\r
+    ## "==" operator\r
+    def __eq__(self, Other):\r
+        return Other and self.MetaFile == Other\r
+\r
+## Workspace AutoGen class\r
+#\r
+#   This class is used mainly to control the whole platform build for different\r
+# architecture. This class will generate top level makefile.\r
+#\r
+class WorkspaceAutoGen(AutoGen):\r
+    ## Real constructor of WorkspaceAutoGen\r
+    #\r
+    # This method behaves the same as __init__ except that it needs explicit invoke\r
+    # (in super class's __new__ method)\r
+    #\r
+    #   @param  WorkspaceDir            Root directory of workspace\r
+    #   @param  ActivePlatform          Meta-file of active platform\r
+    #   @param  Target                  Build target\r
+    #   @param  Toolchain               Tool chain name\r
+    #   @param  ArchList                List of architecture of current build\r
+    #   @param  MetaFileDb              Database containing meta-files\r
+    #   @param  BuildConfig             Configuration of build\r
+    #   @param  ToolDefinition          Tool chain definitions\r
+    #   @param  FlashDefinitionFile     File of flash definition\r
+    #   @param  Fds                     FD list to be generated\r
+    #   @param  Fvs                     FV list to be generated\r
+    #   @param  Caps                    Capsule list to be generated\r
+    #   @param  SkuId                   SKU id from command line\r
+    #\r
+    def _Init(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
+        GlobalData.gActivePlatform = self.Platform\r
+        self.BuildTarget    = Target\r
+        self.ToolChain      = Toolchain\r
+        self.ArchList       = ArchList\r
+        self.SkuId          = SkuId\r
+        self.UniFlag        = UniFlag\r
+\r
+        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.AutoGenObjectList = []\r
+        self._BuildDir      = None\r
+        self._FvDir         = None\r
+        self._MakeFileDir   = None\r
+        self._BuildCommand  = None\r
+\r
+        # there's many relative directory operations, so ...\r
+        os.chdir(self.WorkspaceDir)\r
+\r
+        #\r
+        # Merge Arch\r
+        #\r
+        if not self.ArchList:\r
+            ArchList = set(self.Platform.SupArchList)\r
+        else:\r
+            ArchList = set(self.ArchList) & set(self.Platform.SupArchList)\r
+        if not ArchList:\r
+            EdkLogger.error("build", PARAMETER_INVALID,\r
+                            ExtraData = "Invalid ARCH specified. [Valid ARCH: %s]" % (" ".join(self.Platform.SupArchList)))\r
+        elif self.ArchList and len(ArchList) != len(self.ArchList):\r
+            SkippedArchList = set(self.ArchList).symmetric_difference(set(self.Platform.SupArchList))\r
+            EdkLogger.verbose("\nArch [%s] is ignored because the platform supports [%s] only!"\r
+                              % (" ".join(SkippedArchList), " ".join(self.Platform.SupArchList)))\r
+        self.ArchList = tuple(ArchList)\r
+\r
+        # Validate build target\r
+        if self.BuildTarget not in self.Platform.BuildTargets:\r
+            EdkLogger.error("build", PARAMETER_INVALID,\r
+                            ExtraData="Build target [%s] is not supported by the platform. [Valid target: %s]"\r
+                                      % (self.BuildTarget, " ".join(self.Platform.BuildTargets)))\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
+\r
+        EdkLogger.info("")\r
+        if self.ArchList:\r
+            EdkLogger.info('%-16s = %s' % ("Architecture(s)", ' '.join(self.ArchList)))\r
+        EdkLogger.info('%-16s = %s' % ("Build target", self.BuildTarget))\r
+        EdkLogger.info('%-16s = %s' % ("Toolchain", self.ToolChain))\r
+\r
+        EdkLogger.info('\n%-24s = %s' % ("Active Platform", self.Platform))\r
+        if BuildModule:\r
+            EdkLogger.info('%-24s = %s' % ("Active Module", BuildModule))\r
+\r
+        if self.FdfFile:\r
+            EdkLogger.info('%-24s = %s' % ("Flash Image Definition", self.FdfFile))\r
+\r
+        EdkLogger.verbose("\nFLASH_DEFINITION = %s" % self.FdfFile)\r
+\r
+#         if Progress:\r
+#             Progress.Start("\nProcessing meta-data")\r
+\r
+        if self.FdfFile:\r
+            #\r
+            # Mark now build in AutoGen Phase\r
+            #\r
+            GlobalData.gAutoGenPhase = True\r
+            Fdf = FdfParser(self.FdfFile.Path)\r
+            Fdf.ParseFile()\r
+            GlobalData.gFdfParser = Fdf\r
+            GlobalData.gAutoGenPhase = False\r
+            PcdSet = Fdf.Profile.PcdDict\r
+            if Fdf.CurrentFdName and Fdf.CurrentFdName in Fdf.Profile.FdDict:\r
+                FdDict = Fdf.Profile.FdDict[Fdf.CurrentFdName]\r
+                for FdRegion in FdDict.RegionList:\r
+                    if str(FdRegion.RegionType) is 'FILE' and self.Platform.VpdToolGuid in str(FdRegion.RegionDataList):\r
+                        if int(FdRegion.Offset) % 8 != 0:\r
+                            EdkLogger.error("build", FORMAT_INVALID, 'The VPD Base Address %s must be 8-byte aligned.' % (FdRegion.Offset))\r
+            ModuleList = Fdf.Profile.InfList\r
+            self.FdfProfile = Fdf.Profile\r
+            for fvname in self.FvTargetList:\r
+                if fvname.upper() not in self.FdfProfile.FvDict:\r
+                    EdkLogger.error("build", OPTION_VALUE_INVALID,\r
+                                    "No such an FV in FDF file: %s" % fvname)\r
+\r
+            # In DSC file may use FILE_GUID to override the module, then in the Platform.Modules use FILE_GUIDmodule.inf as key,\r
+            # 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
+                    for Inf in self.FdfProfile.InfDict[key]:\r
+                        ModuleFile = PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch)\r
+                        for Arch in self.ArchList:\r
+                            if ModuleFile in MetaFile_cache[Arch]:\r
+                                break\r
+                        else:\r
+                            ModuleData = self.BuildDatabase[ModuleFile, Arch, Target, Toolchain]\r
+                            if not ModuleData.IsBinaryModule:\r
+                                EdkLogger.error('build', PARSER_ERROR, "Module %s NOT found in DSC file; Is it really a binary module?" % ModuleFile)\r
+\r
+                else:\r
+                    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
+                            for Inf in self.FdfProfile.InfDict[key]:\r
+                                ModuleFile = PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch)\r
+                                if ModuleFile in MetaFileList:\r
+                                    continue\r
+                                ModuleData = self.BuildDatabase[ModuleFile, Arch, Target, Toolchain]\r
+                                if not ModuleData.IsBinaryModule:\r
+                                    EdkLogger.error('build', PARSER_ERROR, "Module %s NOT found in DSC file; Is it really a binary module?" % ModuleFile)\r
+\r
+        else:\r
+            PcdSet = {}\r
+            ModuleList = []\r
+            self.FdfProfile = None\r
+            if self.FdTargetList:\r
+                EdkLogger.info("No flash definition file found. FD [%s] will be ignored." % " ".join(self.FdTargetList))\r
+                self.FdTargetList = []\r
+            if self.FvTargetList:\r
+                EdkLogger.info("No flash definition file found. FV [%s] will be ignored." % " ".join(self.FvTargetList))\r
+                self.FvTargetList = []\r
+            if self.CapTargetList:\r
+                EdkLogger.info("No flash definition file found. Capsule [%s] will be ignored." % " ".join(self.CapTargetList))\r
+                self.CapTargetList = []\r
+\r
+        # 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
+            DecPcds = {}\r
+            DecPcdsKey = set()\r
+            PGen = PlatformAutoGen(self, self.MetaFile, Target, Toolchain, Arch)\r
+            if GlobalData.BuildOptionPcd:\r
+                for i, pcd in enumerate(GlobalData.BuildOptionPcd):\r
+                    if type(pcd) is tuple:\r
+                        continue\r
+                    (pcdname, pcdvalue) = pcd.split('=')\r
+                    if not pcdvalue:\r
+                        EdkLogger.error('build', AUTOGEN_ERROR, "No Value specified for the PCD %s." % (pcdname))\r
+                    if '.' in pcdname:\r
+                        (TokenSpaceGuidCName, TokenCName) = pcdname.split('.')\r
+                        HasTokenSpace = True\r
+                    else:\r
+                        TokenCName = pcdname\r
+                        TokenSpaceGuidCName = ''\r
+                        HasTokenSpace = False\r
+                    TokenSpaceGuidCNameList = []\r
+                    FoundFlag = False\r
+                    PcdDatumType = ''\r
+                    NewValue = ''\r
+                    for package in PGen.PackageList:\r
+                        for key in package.Pcds:\r
+                            PcdItem = package.Pcds[key]\r
+                            if HasTokenSpace:\r
+                                if (PcdItem.TokenCName, PcdItem.TokenSpaceGuidCName) == (TokenCName, TokenSpaceGuidCName):\r
+                                    PcdDatumType = PcdItem.DatumType\r
+                                    NewValue = BuildOptionPcdValueFormat(TokenSpaceGuidCName, TokenCName, PcdDatumType, pcdvalue)\r
+                                    FoundFlag = True\r
+                            else:\r
+                                if PcdItem.TokenCName == TokenCName:\r
+                                    if not PcdItem.TokenSpaceGuidCName in TokenSpaceGuidCNameList:\r
+                                        if len (TokenSpaceGuidCNameList) < 1:\r
+                                            TokenSpaceGuidCNameList.append(PcdItem.TokenSpaceGuidCName)\r
+                                            PcdDatumType = PcdItem.DatumType\r
+                                            TokenSpaceGuidCName = PcdItem.TokenSpaceGuidCName\r
+                                            NewValue = BuildOptionPcdValueFormat(TokenSpaceGuidCName, TokenCName, PcdDatumType, pcdvalue)\r
+                                            FoundFlag = True\r
+                                        else:\r
+                                            EdkLogger.error(\r
+                                                    'build',\r
+                                                     AUTOGEN_ERROR,\r
+                                                    "The Pcd %s is found under multiple different TokenSpaceGuid: %s and %s." % (TokenCName, PcdItem.TokenSpaceGuidCName, TokenSpaceGuidCNameList[0])\r
+                                                    )\r
+\r
+                    GlobalData.BuildOptionPcd[i] = (TokenSpaceGuidCName, TokenCName, NewValue)\r
+\r
+                    if not FoundFlag:\r
+                        if HasTokenSpace:\r
+                            EdkLogger.error('build', AUTOGEN_ERROR, "The Pcd %s.%s is not found in the DEC file." % (TokenSpaceGuidCName, TokenCName))\r
+                        else:\r
+                            EdkLogger.error('build', AUTOGEN_ERROR, "The Pcd %s is not found in the DEC file." % (TokenCName))\r
+\r
+                    for BuildData in PGen.BuildDatabase._CACHE_.values():\r
+                        if BuildData.Arch != Arch:\r
+                            continue\r
+                        if BuildData.MetaFile.Ext == '.dec':\r
+                            continue\r
+                        for key in BuildData.Pcds:\r
+                            PcdItem = BuildData.Pcds[key]\r
+                            if (TokenSpaceGuidCName, TokenCName) == (PcdItem.TokenSpaceGuidCName, PcdItem.TokenCName):\r
+                                PcdItem.DefaultValue = NewValue\r
+\r
+                    if (TokenCName, TokenSpaceGuidCName) in PcdSet:\r
+                        PcdSet[(TokenCName, TokenSpaceGuidCName)] = NewValue\r
+\r
+            SourcePcdDict = {'DynamicEx':[], 'PatchableInModule':[],'Dynamic':[],'FixedAtBuild':[]}\r
+            BinaryPcdDict = {'DynamicEx':[], 'PatchableInModule':[]}\r
+            SourcePcdDict_Keys = SourcePcdDict.keys()\r
+            BinaryPcdDict_Keys = BinaryPcdDict.keys()\r
+\r
+            # generate the SourcePcdDict and BinaryPcdDict\r
+            for BuildData in PGen.BuildDatabase._CACHE_.values():\r
+                if BuildData.Arch != Arch:\r
+                    continue\r
+                if BuildData.MetaFile.Ext == '.inf':\r
+                    for key in BuildData.Pcds:\r
+                        if BuildData.Pcds[key].Pending:\r
+                            if key in Platform.Pcds:\r
+                                PcdInPlatform = Platform.Pcds[key]\r
+                                if PcdInPlatform.Type not in [None, '']:\r
+                                    BuildData.Pcds[key].Type = PcdInPlatform.Type\r
+\r
+                            if BuildData.MetaFile in Platform.Modules:\r
+                                PlatformModule = Platform.Modules[str(BuildData.MetaFile)]\r
+                                if key in PlatformModule.Pcds:\r
+                                    PcdInPlatform = PlatformModule.Pcds[key]\r
+                                    if PcdInPlatform.Type not in [None, '']:\r
+                                        BuildData.Pcds[key].Type = PcdInPlatform.Type\r
+\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
+                            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
+\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
+                                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
+\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
+                        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
+                else:\r
+                    pass\r
+            #\r
+            # A PCD can only use one type for all source modules\r
+            #\r
+            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
+                            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
+                            )\r
+                    else:\r
+                        pass\r
+\r
+            #\r
+            # intersection the BinaryPCD for Mixed PCD\r
+            #\r
+            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
+                            NewPcd1 = (item[0] + '_' + i, item[1])\r
+                            NewPcd2 = (item[0] + '_' + j, item[1])\r
+                            if item not in GlobalData.MixedPcd:\r
+                                GlobalData.MixedPcd[item] = [NewPcd1, NewPcd2]\r
+                            else:\r
+                                if NewPcd1 not in GlobalData.MixedPcd[item]:\r
+                                    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
+            #\r
+            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
+                            NewPcd1 = (item[0] + '_' + i, item[1])\r
+                            NewPcd2 = (item[0] + '_' + j, item[1])\r
+                            if item not in GlobalData.MixedPcd:\r
+                                GlobalData.MixedPcd[item] = [NewPcd1, NewPcd2]\r
+                            else:\r
+                                if NewPcd1 not in GlobalData.MixedPcd[item]:\r
+                                    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
+                    continue\r
+                for key in BuildData.Pcds:\r
+                    for SinglePcd in GlobalData.MixedPcd:\r
+                        if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) == SinglePcd:\r
+                            for item in GlobalData.MixedPcd[SinglePcd]:\r
+                                Pcd_Type = item[0].split('_')[-1]\r
+                                if (Pcd_Type == BuildData.Pcds[key].Type) or (Pcd_Type == TAB_PCDS_DYNAMIC_EX and BuildData.Pcds[key].Type in GenC.gDynamicExPcd) or \\r
+                                   (Pcd_Type == TAB_PCDS_DYNAMIC and BuildData.Pcds[key].Type in GenC.gDynamicPcd):\r
+                                    Value = BuildData.Pcds[key]\r
+                                    Value.TokenCName = BuildData.Pcds[key].TokenCName + '_' + Pcd_Type\r
+                                    if len(key) == 2:\r
+                                        newkey = (Value.TokenCName, key[1])\r
+                                    elif len(key) == 3:\r
+                                        newkey = (Value.TokenCName, key[1], key[2])\r
+                                    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
+                if key in GlobalData.MixedPcd:\r
+                    Value = PcdSet[key]\r
+                    del PcdSet[key]\r
+                    for item in GlobalData.MixedPcd[key]:\r
+                        PcdSet[item] = Value\r
+\r
+            #Collect package set information from INF of FDF\r
+            PkgSet = set()\r
+            for Inf in ModuleList:\r
+                ModuleFile = PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch)\r
+                if ModuleFile in Platform.Modules:\r
+                    continue\r
+                ModuleData = self.BuildDatabase[ModuleFile, Arch, Target, Toolchain]\r
+                PkgSet.update(ModuleData.Packages)\r
+            Pkgs = list(PkgSet) + list(PGen.PackageList)\r
+            for Pkg in Pkgs:\r
+                for Pcd in Pkg.Pcds:\r
+                    DecPcds[Pcd[0], Pcd[1]] = Pkg.Pcds[Pcd]\r
+                    DecPcdsKey.add((Pcd[0], Pcd[1], Pcd[2]))\r
+\r
+            Platform.SkuName = self.SkuId\r
+            for Name, Guid in PcdSet:\r
+                if (Name, Guid) not in DecPcds:\r
+                    EdkLogger.error(\r
+                        'build',\r
+                        PARSER_ERROR,\r
+                        "PCD (%s.%s) used in FDF is not declared in DEC files." % (Guid, Name),\r
+                        File = self.FdfProfile.PcdFileLineDict[Name, Guid][0],\r
+                        Line = self.FdfProfile.PcdFileLineDict[Name, Guid][1]\r
+                    )\r
+                else:\r
+                    # Check whether Dynamic or DynamicEx PCD used in FDF file. If used, build break and give a error message.\r
+                    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
+                                'build',\r
+                                PARSER_ERROR,\r
+                                "Using Dynamic or DynamicEx type of PCD [%s.%s] in FDF file is not allowed." % (Guid, Name),\r
+                                File = self.FdfProfile.PcdFileLineDict[Name, Guid][0],\r
+                                Line = self.FdfProfile.PcdFileLineDict[Name, Guid][1]\r
+                        )\r
+\r
+            Pa = PlatformAutoGen(self, self.MetaFile, Target, Toolchain, Arch)\r
+            #\r
+            # Explicitly collect platform's dynamic PCDs\r
+            #\r
+            Pa.CollectPlatformDynamicPcds()\r
+            Pa.CollectFixedAtBuildPcds()\r
+            self.AutoGenObjectList.append(Pa)\r
+\r
+            #\r
+            # Generate Package level hash value\r
+            #\r
+            GlobalData.gPackageHash[Arch] = {}\r
+            if GlobalData.gUseHashCache:\r
+                for Pkg in Pkgs:\r
+                    self._GenPkgLevelHash(Pkg)\r
+\r
+        #\r
+        # Check PCDs token value conflict in each DEC file.\r
+        #\r
+        self._CheckAllPcdsTokenValueConflict()\r
+\r
+        #\r
+        # Check PCD type and definition between DSC and DEC\r
+        #\r
+        self._CheckPcdDefineAndType()\r
+\r
+#         if self.FdfFile:\r
+#             self._CheckDuplicateInFV(Fdf)\r
+\r
+        #\r
+        # Create BuildOptions Macro & PCD metafile, also add the Active Platform and FDF file.\r
+        #\r
+        content = 'gCommandLineDefines: '\r
+        content += str(GlobalData.gCommandLineDefines)\r
+        content += os.linesep\r
+        content += 'BuildOptionPcd: '\r
+        content += str(GlobalData.BuildOptionPcd)\r
+        content += os.linesep\r
+        content += 'Active Platform: '\r
+        content += str(self.Platform)\r
+        content += os.linesep\r
+        if self.FdfFile:\r
+            content += 'Flash Image Definition: '\r
+            content += str(self.FdfFile)\r
+            content += os.linesep\r
+        SaveFileOnChange(os.path.join(self.BuildDir, 'BuildOptions'), content, False)\r
+\r
+        #\r
+        # Create PcdToken Number file for Dynamic/DynamicEx Pcd.\r
+        #\r
+        PcdTokenNumber = 'PcdTokenNumber: '\r
+        if Pa.PcdTokenNumber:\r
+            if Pa.DynamicPcdList:\r
+                for Pcd in Pa.DynamicPcdList:\r
+                    PcdTokenNumber += os.linesep\r
+                    PcdTokenNumber += str((Pcd.TokenCName, Pcd.TokenSpaceGuidCName))\r
+                    PcdTokenNumber += ' : '\r
+                    PcdTokenNumber += str(Pa.PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName])\r
+        SaveFileOnChange(os.path.join(self.BuildDir, 'PcdTokenNumber'), PcdTokenNumber, False)\r
+\r
+        #\r
+        # Get set of workspace metafiles\r
+        #\r
+        AllWorkSpaceMetaFiles = self._GetMetaFiles(Target, Toolchain, Arch)\r
+\r
+        #\r
+        # Retrieve latest modified time of all metafiles\r
+        #\r
+        SrcTimeStamp = 0\r
+        for f in AllWorkSpaceMetaFiles:\r
+            if os.stat(f)[8] > SrcTimeStamp:\r
+                SrcTimeStamp = os.stat(f)[8]\r
+        self._SrcTimeStamp = SrcTimeStamp\r
+\r
+        if GlobalData.gUseHashCache:\r
+            m = hashlib.md5()\r
+            for files in AllWorkSpaceMetaFiles:\r
+                if files.endswith('.dec'):\r
+                    continue\r
+                f = open(files, 'r')\r
+                Content = f.read()\r
+                f.close()\r
+                m.update(Content)\r
+            SaveFileOnChange(os.path.join(self.BuildDir, 'AutoGen.hash'), m.hexdigest(), True)\r
+            GlobalData.gPlatformHash = m.hexdigest()\r
+\r
+        #\r
+        # Write metafile list to build directory\r
+        #\r
+        AutoGenFilePath = os.path.join(self.BuildDir, 'AutoGen')\r
+        if os.path.exists (AutoGenFilePath):\r
+            os.remove(AutoGenFilePath)\r
+        if not os.path.exists(self.BuildDir):\r
+            os.makedirs(self.BuildDir)\r
+        with open(os.path.join(self.BuildDir, 'AutoGen'), 'w+') as file:\r
+            for f in AllWorkSpaceMetaFiles:\r
+                print >> file, f\r
+        return True\r
+\r
+    def _GenPkgLevelHash(self, Pkg):\r
+        PkgDir = os.path.join(self.BuildDir, Pkg.Arch, Pkg.PackageName)\r
+        CreateDirectory(PkgDir)\r
+        HashFile = os.path.join(PkgDir, Pkg.PackageName + '.hash')\r
+        m = hashlib.md5()\r
+        # Get .dec file's hash value\r
+        f = open(Pkg.MetaFile.Path, 'r')\r
+        Content = f.read()\r
+        f.close()\r
+        m.update(Content)\r
+        # Get include files hash value\r
+        if Pkg.Includes:\r
+            for inc in Pkg.Includes:\r
+                for Root, Dirs, Files in os.walk(str(inc)):\r
+                    for File in Files:\r
+                        File_Path = os.path.join(Root, File)\r
+                        f = open(File_Path, 'r')\r
+                        Content = f.read()\r
+                        f.close()\r
+                        m.update(Content)\r
+        SaveFileOnChange(HashFile, m.hexdigest(), True)\r
+        if Pkg.PackageName not in GlobalData.gPackageHash[Pkg.Arch]:\r
+            GlobalData.gPackageHash[Pkg.Arch][Pkg.PackageName] = m.hexdigest()\r
+\r
+    def _GetMetaFiles(self, Target, Toolchain, Arch):\r
+        AllWorkSpaceMetaFiles = set()\r
+        #\r
+        # add fdf\r
+        #\r
+        if self.FdfFile:\r
+            AllWorkSpaceMetaFiles.add (self.FdfFile.Path)\r
+            if self.FdfFile:\r
+                FdfFiles = GlobalData.gFdfParser.GetAllIncludedFile()\r
+                for f in FdfFiles:\r
+                    AllWorkSpaceMetaFiles.add (f.FileName)\r
+        #\r
+        # add dsc\r
+        #\r
+        AllWorkSpaceMetaFiles.add(self.MetaFile.Path)\r
+\r
+        #\r
+        # add build_rule.txt & tools_def.txt\r
+        #\r
+        AllWorkSpaceMetaFiles.add(os.path.join(GlobalData.gConfDirectory, gDefaultBuildRuleFile))\r
+        AllWorkSpaceMetaFiles.add(os.path.join(GlobalData.gConfDirectory, gDefaultToolsDefFile))\r
+\r
+        # add BuildOption metafile\r
+        #\r
+        AllWorkSpaceMetaFiles.add(os.path.join(self.BuildDir, 'BuildOptions'))\r
+\r
+        # add PcdToken Number file for Dynamic/DynamicEx Pcd\r
+        #\r
+        AllWorkSpaceMetaFiles.add(os.path.join(self.BuildDir, 'PcdTokenNumber'))\r
+\r
+        for Arch in self.ArchList:\r
+            Platform = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain]\r
+            PGen = PlatformAutoGen(self, self.MetaFile, Target, Toolchain, Arch)\r
+\r
+            #\r
+            # add dec\r
+            #\r
+            for Package in PGen.PackageList:\r
+                AllWorkSpaceMetaFiles.add(Package.MetaFile.Path)\r
+\r
+            #\r
+            # add included dsc\r
+            #\r
+            for filePath in Platform._RawData.IncludedFiles:\r
+                AllWorkSpaceMetaFiles.add(filePath.Path)\r
+\r
+        return AllWorkSpaceMetaFiles\r
+\r
+    ## _CheckDuplicateInFV() method\r
+    #\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
+        for Fv in Fdf.Profile.FvDict:\r
+            _GuidDict = {}\r
+            for FfsFile in Fdf.Profile.FvDict[Fv].FfsList:\r
+                if FfsFile.InfFileName and FfsFile.NameGuid == None:\r
+                    #\r
+                    # Get INF file GUID\r
+                    #\r
+                    InfFoundFlag = False\r
+                    for Pa in self.AutoGenObjectList:\r
+                        if InfFoundFlag:\r
+                            break\r
+                        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
+                                    _GuidDict[Module.Guid.upper()] = FfsFile\r
+                                    break\r
+                                else:\r
+                                    EdkLogger.error("build",\r
+                                                    FORMAT_INVALID,\r
+                                                    "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile.CurrentLineNum,\r
+                                                                                                                                   FfsFile.CurrentLineContent,\r
+                                                                                                                                   _GuidDict[Module.Guid.upper()].CurrentLineNum,\r
+                                                                                                                                   _GuidDict[Module.Guid.upper()].CurrentLineContent,\r
+                                                                                                                                   Module.Guid.upper()),\r
+                                                    ExtraData=self.FdfFile)\r
+                    #\r
+                    # Some INF files not have entity in DSC file. \r
+                    #\r
+                    if not InfFoundFlag:\r
+                        if FfsFile.InfFileName.find('$') == -1:\r
+                            InfPath = NormPath(FfsFile.InfFileName)\r
+                            if not os.path.exists(InfPath):\r
+                                EdkLogger.error('build', GENFDS_ERROR, "Non-existant Module %s !" % (FfsFile.InfFileName))\r
+\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
+                            # 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
+                                _GuidDict[InfObj.Guid.upper()] = FfsFile\r
+                            else:\r
+                                EdkLogger.error("build",\r
+                                                FORMAT_INVALID,\r
+                                                "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile.CurrentLineNum,\r
+                                                                                                                               FfsFile.CurrentLineContent,\r
+                                                                                                                               _GuidDict[InfObj.Guid.upper()].CurrentLineNum,\r
+                                                                                                                               _GuidDict[InfObj.Guid.upper()].CurrentLineContent,\r
+                                                                                                                               InfObj.Guid.upper()),\r
+                                                ExtraData=self.FdfFile)\r
+                        InfFoundFlag = False\r
+\r
+                if FfsFile.NameGuid != 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
+                        #\r
+                        # Replace the PCD value.\r
+                        #\r
+                        _PcdName = FfsFile.NameGuid.lstrip("PCD(").rstrip(")")\r
+                        PcdFoundFlag = False\r
+                        for Pa in self.AutoGenObjectList:\r
+                            if not PcdFoundFlag:\r
+                                for PcdItem in Pa.AllPcdList:\r
+                                    if (PcdItem.TokenSpaceGuidCName + "." + PcdItem.TokenCName) == _PcdName:\r
+                                        #\r
+                                        # First convert from CFormatGuid to GUID string\r
+                                        #\r
+                                        _PcdGuidString = GuidStructureStringToGuidString(PcdItem.DefaultValue)\r
+\r
+                                        if not _PcdGuidString:\r
+                                            #\r
+                                            # Then try Byte array.\r
+                                            #\r
+                                            _PcdGuidString = GuidStructureByteArrayToGuidString(PcdItem.DefaultValue)\r
+\r
+                                        if not _PcdGuidString:\r
+                                            #\r
+                                            # Not Byte array or CFormat GUID, raise error.\r
+                                            #\r
+                                            EdkLogger.error("build",\r
+                                                            FORMAT_INVALID,\r
+                                                            "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
+                                            _GuidDict[_PcdGuidString.upper()] = FfsFile\r
+                                            PcdFoundFlag = True\r
+                                            break\r
+                                        else:\r
+                                            EdkLogger.error("build",\r
+                                                            FORMAT_INVALID,\r
+                                                            "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile.CurrentLineNum,\r
+                                                                                                                                           FfsFile.CurrentLineContent,\r
+                                                                                                                                           _GuidDict[_PcdGuidString.upper()].CurrentLineNum,\r
+                                                                                                                                           _GuidDict[_PcdGuidString.upper()].CurrentLineContent,\r
+                                                                                                                                           FfsFile.NameGuid.upper()),\r
+                                                            ExtraData=self.FdfFile)\r
+\r
+                    if not FfsFile.NameGuid.upper() in _GuidDict.keys():\r
+                        _GuidDict[FfsFile.NameGuid.upper()] = FfsFile\r
+                    else:\r
+                        #\r
+                        # Two raw file GUID conflict.\r
+                        #\r
+                        EdkLogger.error("build",\r
+                                        FORMAT_INVALID,\r
+                                        "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile.CurrentLineNum,\r
+                                                                                                                       FfsFile.CurrentLineContent,\r
+                                                                                                                       _GuidDict[FfsFile.NameGuid.upper()].CurrentLineNum,\r
+                                                                                                                       _GuidDict[FfsFile.NameGuid.upper()].CurrentLineContent,\r
+                                                                                                                       FfsFile.NameGuid.upper()),\r
+                                        ExtraData=self.FdfFile)\r
+\r
+\r
+    def _CheckPcdDefineAndType(self):\r
+        PcdTypeList = [\r
+            "FixedAtBuild", "PatchableInModule", "FeatureFlag",\r
+            "Dynamic", #"DynamicHii", "DynamicVpd",\r
+            "DynamicEx", # "DynamicExHii", "DynamicExVpd"\r
+        ]\r
+\r
+        # This dict store PCDs which are not used by any modules with specified arches\r
+        UnusedPcd = sdict()\r
+        for Pa in self.AutoGenObjectList:\r
+            # Key of DSC's Pcds dictionary is PcdCName, TokenSpaceGuid\r
+            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 not PcdType:\r
+                    continue\r
+\r
+                # Try to remove Hii and Vpd suffix\r
+                if PcdType.startswith("DynamicEx"):\r
+                    PcdType = "DynamicEx"\r
+                elif PcdType.startswith("Dynamic"):\r
+                    PcdType = "Dynamic"\r
+\r
+                for Package in Pa.PackageList:\r
+                    # Key of DEC's Pcds dictionary is PcdCName, TokenSpaceGuid, PcdType\r
+                    if (Pcd[0], Pcd[1], PcdType) in Package.Pcds:\r
+                        break\r
+                    for Type in PcdTypeList:\r
+                        if (Pcd[0], Pcd[1], Type) in Package.Pcds:\r
+                            EdkLogger.error(\r
+                                'build',\r
+                                FORMAT_INVALID,\r
+                                "Type [%s] of PCD [%s.%s] in DSC file doesn't match the type [%s] defined in DEC file." \\r
+                                % (Pa.Platform.Pcds[Pcd].Type, Pcd[1], Pcd[0], Type),\r
+                                ExtraData=None\r
+                            )\r
+                            return\r
+                else:\r
+                    UnusedPcd.setdefault(Pcd, []).append(Pa.Arch)\r
+\r
+        for Pcd in UnusedPcd:\r
+            EdkLogger.warn(\r
+                'build',\r
+                "The PCD was not specified by any INF module in the platform for the given architecture.\n"\r
+                "\tPCD: [%s.%s]\n\tPlatform: [%s]\n\tArch: %s"\r
+                % (Pcd[1], Pcd[0], os.path.basename(str(self.MetaFile)), str(UnusedPcd[Pcd])),\r
+                ExtraData=None\r
+            )\r
+\r
+    def __repr__(self):\r
+        return "%s [%s]" % (self.MetaFile, ", ".join(self.ArchList))\r
+\r
+    ## Return the directory to store FV files\r
+    def _GetFvDir(self):\r
+        if self._FvDir == None:\r
+            self._FvDir = path.join(self.BuildDir, 'FV')\r
+        return self._FvDir\r
+\r
+    ## Return the directory to store all intermediate and final files built\r
+    def _GetBuildDir(self):\r
+        if self._BuildDir == None:\r
+            return self.AutoGenObjectList[0].BuildDir\r
+\r
+    ## Return the build output directory platform specifies\r
+    def _GetOutputDir(self):\r
+        return self.Platform.OutputDirectory\r
+\r
+    ## Return platform name\r
+    def _GetName(self):\r
+        return self.Platform.PlatformName\r
+\r
+    ## Return meta-file GUID\r
+    def _GetGuid(self):\r
+        return self.Platform.Guid\r
+\r
+    ## Return platform version\r
+    def _GetVersion(self):\r
+        return self.Platform.Version\r
+\r
+    ## Return paths of tools\r
+    def _GetToolDefinition(self):\r
+        return self.AutoGenObjectList[0].ToolDefinition\r
+\r
+    ## Return directory of platform makefile\r
+    #\r
+    #   @retval     string  Makefile directory\r
+    #\r
+    def _GetMakeFileDir(self):\r
+        if self._MakeFileDir == None:\r
+            self._MakeFileDir = self.BuildDir\r
+        return self._MakeFileDir\r
+\r
+    ## Return build command string\r
+    #\r
+    #   @retval     string  Build command string\r
+    #\r
+    def _GetBuildCommand(self):\r
+        if self._BuildCommand == None:\r
+            # BuildCommand should be all the same. So just get one from platform AutoGen\r
+            self._BuildCommand = self.AutoGenObjectList[0].BuildCommand\r
+        return self._BuildCommand\r
+\r
+    ## 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
+    # @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
+                Count = 0\r
+                while (Count < len(PcdList) - 1) :\r
+                    Item = PcdList[Count]\r
+                    ItemNext = PcdList[Count + 1]\r
+                    #\r
+                    # Make sure in the same token space the TokenValue should be unique\r
+                    #\r
+                    if (int(Item.TokenValue, 0) == int(ItemNext.TokenValue, 0)):\r
+                        SameTokenValuePcdList = []\r
+                        SameTokenValuePcdList.append(Item)\r
+                        SameTokenValuePcdList.append(ItemNext)\r
+                        RemainPcdListLength = len(PcdList) - Count - 2\r
+                        for ValueSameCount in range(RemainPcdListLength):\r
+                            if int(PcdList[len(PcdList) - RemainPcdListLength + ValueSameCount].TokenValue, 0) == int(Item.TokenValue, 0):\r
+                                SameTokenValuePcdList.append(PcdList[len(PcdList) - RemainPcdListLength + ValueSameCount])\r
+                            else:\r
+                                break;\r
+                        #\r
+                        # Sort same token value PCD list with TokenGuid and TokenCName\r
+                        #\r
+                        SameTokenValuePcdList.sort(lambda x, y: cmp("%s.%s" % (x.TokenSpaceGuidCName, x.TokenCName), "%s.%s" % (y.TokenSpaceGuidCName, y.TokenCName)))\r
+                        SameTokenValuePcdListCount = 0\r
+                        while (SameTokenValuePcdListCount < len(SameTokenValuePcdList) - 1):\r
+                            Flag = False\r
+                            TemListItem = SameTokenValuePcdList[SameTokenValuePcdListCount]\r
+                            TemListItemNext = SameTokenValuePcdList[SameTokenValuePcdListCount + 1]\r
+\r
+                            if (TemListItem.TokenSpaceGuidCName == TemListItemNext.TokenSpaceGuidCName) and (TemListItem.TokenCName != TemListItemNext.TokenCName):\r
+                                for PcdItem in GlobalData.MixedPcd:\r
+                                    if (TemListItem.TokenCName, TemListItem.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem] or \\r
+                                        (TemListItemNext.TokenCName, TemListItemNext.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
+                                        Flag = True\r
+                                if not Flag:\r
+                                    EdkLogger.error(\r
+                                                'build',\r
+                                                FORMAT_INVALID,\r
+                                                "The TokenValue [%s] of PCD [%s.%s] is conflict with: [%s.%s] in %s"\\r
+                                                % (TemListItem.TokenValue, TemListItem.TokenSpaceGuidCName, TemListItem.TokenCName, TemListItemNext.TokenSpaceGuidCName, TemListItemNext.TokenCName, Package),\r
+                                                ExtraData=None\r
+                                                )\r
+                            SameTokenValuePcdListCount += 1\r
+                        Count += SameTokenValuePcdListCount\r
+                    Count += 1\r
+\r
+                PcdList = Package.Pcds.values()\r
+                PcdList.sort(lambda x, y: cmp("%s.%s" % (x.TokenSpaceGuidCName, x.TokenCName), "%s.%s" % (y.TokenSpaceGuidCName, y.TokenCName)))\r
+                Count = 0\r
+                while (Count < len(PcdList) - 1) :\r
+                    Item = PcdList[Count]\r
+                    ItemNext = PcdList[Count + 1]\r
+                    #\r
+                    # Check PCDs with same TokenSpaceGuidCName.TokenCName have same token value as well.\r
+                    #\r
+                    if (Item.TokenSpaceGuidCName == ItemNext.TokenSpaceGuidCName) and (Item.TokenCName == ItemNext.TokenCName) and (int(Item.TokenValue, 0) != int(ItemNext.TokenValue, 0)):\r
+                        EdkLogger.error(\r
+                                    'build',\r
+                                    FORMAT_INVALID,\r
+                                    "The TokenValue [%s] of PCD [%s.%s] in %s defined in two places should be same as well."\\r
+                                    % (Item.TokenValue, Item.TokenSpaceGuidCName, Item.TokenCName, Package),\r
+                                    ExtraData=None\r
+                                    )\r
+                    Count += 1\r
+    ## Generate fds command\r
+    def _GenFdsCommand(self):\r
+        return (GenMake.TopLevelMakefile(self)._TEMPLATE_.Replace(GenMake.TopLevelMakefile(self)._TemplateDict)).strip()\r
+\r
+    ## Create makefile for the platform and modules in it\r
+    #\r
+    #   @param      CreateDepsMakeFile      Flag indicating if the makefile for\r
+    #                                       modules will be created as well\r
+    #\r
+    def CreateMakeFile(self, CreateDepsMakeFile=False):\r
+        if CreateDepsMakeFile:\r
+            for Pa in self.AutoGenObjectList:\r
+                Pa.CreateMakeFile(CreateDepsMakeFile)\r
+\r
+    ## Create autogen code for platform and modules\r
+    #\r
+    #  Since there's no autogen code for platform, this method will do nothing\r
+    #  if CreateModuleCodeFile is set to False.\r
+    #\r
+    #   @param      CreateDepsCodeFile      Flag indicating if creating module's\r
+    #                                       autogen code file or not\r
+    #\r
+    def CreateCodeFile(self, CreateDepsCodeFile=False):\r
+        if not CreateDepsCodeFile:\r
+            return\r
+        for Pa in self.AutoGenObjectList:\r
+            Pa.CreateCodeFile(CreateDepsCodeFile)\r
+\r
+    ## Create AsBuilt INF file the platform\r
+    #\r
+    def CreateAsBuiltInf(self):\r
+        return\r
+\r
+    Name                = property(_GetName)\r
+    Guid                = property(_GetGuid)\r
+    Version             = property(_GetVersion)\r
+    OutputDir           = property(_GetOutputDir)\r
+\r
+    ToolDefinition      = property(_GetToolDefinition)       # toolcode : tool path\r
+\r
+    BuildDir            = property(_GetBuildDir)\r
+    FvDir               = property(_GetFvDir)\r
+    MakeFileDir         = property(_GetMakeFileDir)\r
+    BuildCommand        = property(_GetBuildCommand)\r
+    GenFdsCommand       = property(_GenFdsCommand)\r
+\r
+## AutoGen class for platform\r
+#\r
+#  PlatformAutoGen class will process the original information in platform\r
+#  file in order to generate makefile for platform.\r
+#\r
+class PlatformAutoGen(AutoGen):\r
+    #\r
+    # Used to store all PCDs for both PEI and DXE phase, in order to generate \r
+    # correct PCD database\r
+    # \r
+    _DynaPcdList_ = []\r
+    _NonDynaPcdList_ = []\r
+    _PlatformPcds = {}\r
+    \r
+    #\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
+                "0x11011"  : 12,     #  TARGET_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE\r
+                "0x01011"  : 11,     #  ******_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE\r
+                "0x10011"  : 10,     #  TARGET_*********_****_COMMANDTYPE_ATTRIBUTE\r
+                "0x00011"  : 9,      #  ******_*********_****_COMMANDTYPE_ATTRIBUTE\r
+                "0x11101"  : 8,      #  TARGET_TOOLCHAIN_ARCH_***********_ATTRIBUTE\r
+                "0x01101"  : 7,      #  ******_TOOLCHAIN_ARCH_***********_ATTRIBUTE\r
+                "0x10101"  : 6,      #  TARGET_*********_ARCH_***********_ATTRIBUTE\r
+                "0x00101"  : 5,      #  ******_*********_ARCH_***********_ATTRIBUTE\r
+                "0x11001"  : 4,      #  TARGET_TOOLCHAIN_****_***********_ATTRIBUTE\r
+                "0x01001"  : 3,      #  ******_TOOLCHAIN_****_***********_ATTRIBUTE\r
+                "0x10001"  : 2,      #  TARGET_*********_****_***********_ATTRIBUTE\r
+                "0x00001"  : 1}      #  ******_*********_****_***********_ATTRIBUTE (Lowest)\r
+\r
+    ## The real constructor of PlatformAutoGen\r
+    #\r
+    #  This method is not supposed to be called by users of PlatformAutoGen. It's\r
+    #  only used by factory method __new__() to do real initialization work for an\r
+    #  object of PlatformAutoGen\r
+    #\r
+    #   @param      Workspace       WorkspaceAutoGen object\r
+    #   @param      PlatformFile    Platform file (DSC file)\r
+    #   @param      Target          Build target (DEBUG, RELEASE)\r
+    #   @param      Toolchain       Name of tool chain\r
+    #   @param      Arch            arch of the platform supports\r
+    #\r
+    def _Init(self, Workspace, PlatformFile, Target, Toolchain, Arch):\r
+        EdkLogger.debug(EdkLogger.DEBUG_9, "AutoGen platform [%s] [%s]" % (PlatformFile, Arch))\r
+        GlobalData.gProcessingFile = "%s [%s, %s, %s]" % (PlatformFile, Arch, Toolchain, Target)\r
+\r
+        self.MetaFile = PlatformFile\r
+        self.Workspace = Workspace\r
+        self.WorkspaceDir = Workspace.WorkspaceDir\r
+        self.ToolChain = Toolchain\r
+        self.BuildTarget = Target\r
+        self.Arch = Arch\r
+        self.SourceDir = PlatformFile.SubDir\r
+        self.SourceOverrideDir = None\r
+        self.FdTargetList = self.Workspace.FdTargetList\r
+        self.FvTargetList = self.Workspace.FvTargetList\r
+        self.AllPcdList = []\r
+        # get the original module/package/platform objects\r
+        self.BuildDatabase = Workspace.BuildDatabase\r
+        self.DscBuildDataObj = Workspace.Platform\r
+\r
+        # flag indicating if the makefile/C-code file has been created or not\r
+        self.IsMakeFileCreated  = False\r
+        self.IsCodeFileCreated  = False\r
+\r
+        self._Platform   = None\r
+        self._Name       = None\r
+        self._Guid       = None\r
+        self._Version    = None\r
+\r
+        self._BuildRule = None\r
+        self._SourceDir = None\r
+        self._BuildDir = None\r
+        self._OutputDir = None\r
+        self._FvDir = None\r
+        self._MakeFileDir = None\r
+        self._FdfFile = None\r
+\r
+        self._PcdTokenNumber = None    # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber\r
+        self._DynamicPcdList = None    # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]\r
+        self._NonDynamicPcdList = None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]\r
+        self._NonDynamicPcdDict = {}\r
+\r
+        self._ToolDefinitions = None\r
+        self._ToolDefFile = None          # toolcode : tool path\r
+        self._ToolChainFamily = None\r
+        self._BuildRuleFamily = None\r
+        self._BuildOption = None          # toolcode : option\r
+        self._EdkBuildOption = None       # edktoolcode : option\r
+        self._EdkIIBuildOption = None     # edkiitoolcode : option\r
+        self._PackageList = None\r
+        self._ModuleAutoGenList  = None\r
+        self._LibraryAutoGenList = None\r
+        self._BuildCommand = None\r
+        self._AsBuildInfList = []\r
+        self._AsBuildModuleList = []\r
+\r
+        self.VariableInfo = None\r
+\r
+        if GlobalData.gFdfParser != None:\r
+            self._AsBuildInfList = GlobalData.gFdfParser.Profile.InfList\r
+            for Inf in self._AsBuildInfList:\r
+                InfClass = PathClass(NormPath(Inf), GlobalData.gWorkspace, self.Arch)\r
+                M = self.BuildDatabase[InfClass, self.Arch, self.BuildTarget, self.ToolChain]\r
+                if not M.IsSupportedArch:\r
+                    continue\r
+                self._AsBuildModuleList.append(InfClass)\r
+        # get library/modules for build\r
+        self.LibraryBuildDirectoryList = []\r
+        self.ModuleBuildDirectoryList = []\r
+\r
+        return True\r
+\r
+    def __repr__(self):\r
+        return "%s [%s]" % (self.MetaFile, self.Arch)\r
+\r
+    ## Create autogen code for platform and modules\r
+    #\r
+    #  Since there's no autogen code for platform, this method will do nothing\r
+    #  if CreateModuleCodeFile is set to False.\r
+    #\r
+    #   @param      CreateModuleCodeFile    Flag indicating if creating module's\r
+    #                                       autogen code file or not\r
+    #\r
+    def CreateCodeFile(self, CreateModuleCodeFile=False):\r
+        # only module has code to be greated, so do nothing if CreateModuleCodeFile is False\r
+        if self.IsCodeFileCreated or not CreateModuleCodeFile:\r
+            return\r
+\r
+        for Ma in self.ModuleAutoGenList:\r
+            Ma.CreateCodeFile(True)\r
+\r
+        # don't do this twice\r
+        self.IsCodeFileCreated = True\r
+\r
+    ## Generate Fds Command\r
+    def _GenFdsCommand(self):\r
+        return self.Workspace.GenFdsCommand\r
+\r
+    ## Create makefile for the platform and mdoules in it\r
+    #\r
+    #   @param      CreateModuleMakeFile    Flag indicating if the makefile for\r
+    #                                       modules will be created as well\r
+    #\r
+    def CreateMakeFile(self, CreateModuleMakeFile=False, FfsCommand = {}):\r
+        if CreateModuleMakeFile:\r
+            for ModuleFile in self.Platform.Modules:\r
+                Ma = ModuleAutoGen(self.Workspace, ModuleFile, self.BuildTarget,\r
+                                   self.ToolChain, self.Arch, self.MetaFile)\r
+                if (ModuleFile.File, self.Arch) in FfsCommand:\r
+                    Ma.CreateMakeFile(True, FfsCommand[ModuleFile.File, self.Arch])\r
+                else:\r
+                    Ma.CreateMakeFile(True)\r
+                #Ma.CreateAsBuiltInf()\r
+\r
+        # no need to create makefile for the platform more than once\r
+        if self.IsMakeFileCreated:\r
+            return\r
+\r
+        # create library/module build dirs for platform\r
+        Makefile = GenMake.PlatformMakefile(self)\r
+        self.LibraryBuildDirectoryList = Makefile.GetLibraryBuildDirectoryList()\r
+        self.ModuleBuildDirectoryList = Makefile.GetModuleBuildDirectoryList()\r
+\r
+        self.IsMakeFileCreated = True\r
+\r
+    ## Deal with Shared FixedAtBuild Pcds\r
+    #\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
+                    if key not in FixedAtBuildPcds:\r
+                        ShareFixedAtBuildPcdsSameValue[key] = True\r
+                        FixedAtBuildPcds[key] = Pcd.DefaultValue\r
+                    else:\r
+                        if FixedAtBuildPcds[key] != Pcd.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
+                    continue\r
+                else:\r
+                    DscPcd = self.NonDynamicPcdDict[(Pcd.TokenCName,Pcd.TokenSpaceGuidCName)]\r
+                    if DscPcd.Type != "FixedAtBuild":\r
+                        continue\r
+                if key in ShareFixedAtBuildPcdsSameValue and ShareFixedAtBuildPcdsSameValue[key]:                    \r
+                    LibAuto.ConstPcd[key] = Pcd.DefaultValue\r
+\r
+    def CollectVariables(self, DynamicPcdSet):\r
+\r
+        VpdRegionSize = 0\r
+        VpdRegionBase = 0\r
+        if self.Workspace.FdfFile:\r
+            FdDict = self.Workspace.FdfProfile.FdDict[GlobalData.gFdfParser.CurrentFdName]\r
+            for FdRegion in FdDict.RegionList:\r
+                for item in FdRegion.RegionDataList:\r
+                    if self.Platform.VpdToolGuid.strip() and self.Platform.VpdToolGuid in item:\r
+                        VpdRegionSize = FdRegion.Size\r
+                        VpdRegionBase = FdRegion.Offset\r
+                        break\r
+\r
+\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
+            for SkuName in Pcd.SkuInfoList:\r
+                Sku = Pcd.SkuInfoList[SkuName]\r
+                SkuId = Sku.SkuId\r
+                if SkuId == None or SkuId == '':\r
+                    continue\r
+                if len(Sku.VariableName) > 0:\r
+                    VariableGuidStructure = Sku.VariableGuidValue\r
+                    VariableGuid = GuidStructureStringToGuidString(VariableGuidStructure)\r
+                    if Pcd.Phase == "DXE":\r
+                        for StorageName in Sku.DefaultStoreDict:\r
+                            VariableInfo.append_variable(var_info(Index,pcdname,StorageName,SkuName, StringToArray(Sku.VariableName),VariableGuid, Sku.VariableAttribute , Sku.HiiDefaultValue,Sku.DefaultStoreDict[StorageName],Pcd.DatumType))\r
+            Index += 1\r
+        return VariableInfo\r
+\r
+    def UpdateNVStoreMaxSize(self,OrgVpdFile):\r
+        VpdMapFilePath = os.path.join(self.BuildDir, "FV", "%s.map" % self.Platform.VpdToolGuid)\r
+#         VpdFile = VpdInfoFile.VpdInfoFile()\r
+        PcdNvStoreDfBuffer = [item for item in self._DynamicPcdList if item.TokenCName == "PcdNvStoreDefaultValueBuffer" and item.TokenSpaceGuidCName == "gEfiMdeModulePkgTokenSpaceGuid"]\r
+\r
+        if PcdNvStoreDfBuffer:\r
+            if os.path.exists(VpdMapFilePath):\r
+                OrgVpdFile.Read(VpdMapFilePath)\r
+                PcdItems = OrgVpdFile.GetOffset(PcdNvStoreDfBuffer[0])\r
+                NvStoreOffset = PcdItems[0].strip() if PcdItems else 0\r
+            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
+            maxsize = self.VariableInfo.VpdRegionSize  - NvStoreOffset\r
+            var_data = self.VariableInfo.PatchNVStoreDefaultMaxSize(maxsize)\r
+            default_skuobj = PcdNvStoreDfBuffer[0].SkuInfoList.get("DEFAULT")\r
+\r
+            if var_data and default_skuobj:\r
+                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].MaxDatumSize = str(len(default_skuobj.DefaultValue.split(",")))\r
+\r
+        return OrgVpdFile\r
+\r
+    ## Collect dynamic PCDs\r
+    #\r
+    #  Gather dynamic PCDs list from each module and their settings from platform\r
+    #  This interface should be invoked explicitly when platform action is created.\r
+    #\r
+    def CollectPlatformDynamicPcds(self):\r
+        # Override the platform Pcd's value by build option\r
+        if GlobalData.BuildOptionPcd:\r
+            for key in self.Platform.Pcds:\r
+                PlatformPcd = self.Platform.Pcds[key]\r
+                for PcdItem in GlobalData.BuildOptionPcd:\r
+                    if (PlatformPcd.TokenSpaceGuidCName, PlatformPcd.TokenCName) == (PcdItem[0], PcdItem[1]):\r
+                        PlatformPcd.DefaultValue = PcdItem[2]\r
+                        if PlatformPcd.SkuInfoList:\r
+                            Sku = PlatformPcd.SkuInfoList[PlatformPcd.SkuInfoList.keys()[0]]\r
+                            Sku.DefaultValue = PcdItem[2]\r
+                        break\r
+\r
+        for key in self.Platform.Pcds:\r
+            for SinglePcd in GlobalData.MixedPcd:\r
+                if (self.Platform.Pcds[key].TokenCName, self.Platform.Pcds[key].TokenSpaceGuidCName) == SinglePcd:\r
+                    for item in GlobalData.MixedPcd[SinglePcd]:\r
+                        Pcd_Type = item[0].split('_')[-1]\r
+                        if (Pcd_Type == self.Platform.Pcds[key].Type) or (Pcd_Type == TAB_PCDS_DYNAMIC_EX and self.Platform.Pcds[key].Type in GenC.gDynamicExPcd) or \\r
+                           (Pcd_Type == TAB_PCDS_DYNAMIC and self.Platform.Pcds[key].Type in GenC.gDynamicPcd):\r
+                            Value = self.Platform.Pcds[key]\r
+                            Value.TokenCName = self.Platform.Pcds[key].TokenCName + '_' + Pcd_Type\r
+                            if len(key) == 2:\r
+                                newkey = (Value.TokenCName, key[1])\r
+                            elif len(key) == 3:\r
+                                newkey = (Value.TokenCName, key[1], key[2])\r
+                            del self.Platform.Pcds[key]\r
+                            self.Platform.Pcds[newkey] = Value\r
+                            break\r
+                        else:\r
+                            pass\r
+                    break\r
+                else:\r
+                    pass\r
+\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
+            FdfModuleList.append(os.path.normpath(InfName))\r
+        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
+            self.Platform.Modules[F].M = M\r
+\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
+                    NoDatumTypePcdList.add("%s.%s [%s]" % (PcdFromModule.TokenSpaceGuidCName, PcdFromModule.TokenCName, F))\r
+\r
+                # Check the PCD from Binary INF or Source INF\r
+                if M.IsBinaryModule == True:\r
+                    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
+                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
+                        # 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
+                        # modules that are included in the FDF file.\r
+                        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
+                        # 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 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
+                    # it should be stored in Pcd PEI database, If a dynamic only\r
+                    # used by DXE module, it should be stored in DXE PCD database.\r
+                    # The default Phase is DXE\r
+                    #\r
+                    if M.ModuleType in ["PEIM", "PEI_CORE"]:\r
+                        PcdFromModule.Phase = "PEI"\r
+                    if PcdFromModule not in self._DynaPcdList_:\r
+                        self._DynaPcdList_.append(PcdFromModule)\r
+                    elif PcdFromModule.Phase == 'PEI':\r
+                        # overwrite any the same PCD existing, if Phase is PEI\r
+                        Index = self._DynaPcdList_.index(PcdFromModule)\r
+                        self._DynaPcdList_[Index] = PcdFromModule\r
+                elif PcdFromModule not in self._NonDynaPcdList_:\r
+                    self._NonDynaPcdList_.append(PcdFromModule)\r
+                elif PcdFromModule in self._NonDynaPcdList_ and PcdFromModule.IsFromBinaryInf == True:\r
+                    Index = self._NonDynaPcdList_.index(PcdFromModule)\r
+                    if self._NonDynaPcdList_[Index].IsFromBinaryInf == False:\r
+                        #The PCD from Binary INF will override the same one from source INF\r
+                        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
+        # 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
+                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 not M.IsSupportedArch:\r
+                    continue\r
+                # Override the module PCD setting by platform setting\r
+                ModulePcdList = self.ApplyPcdSetting(M, M.Pcds)\r
+                for PcdFromModule in ModulePcdList:\r
+                    PcdFromModule.IsFromBinaryInf = True\r
+                    PcdFromModule.IsFromDsc = False\r
+                    # Only allow the DynamicEx and Patchable PCD in AsBuild INF\r
+                    if PcdFromModule.Type not in GenC.gDynamicExPcd and PcdFromModule.Type not in TAB_PCDS_PATCHABLE_IN_MODULE:\r
+                        EdkLogger.error("build", AUTOGEN_ERROR, "PCD setting error",\r
+                                        File=self.MetaFile,\r
+                                        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
+                        NoDatumTypePcdList.add("%s.%s [%s]" % (PcdFromModule.TokenSpaceGuidCName, PcdFromModule.TokenCName, InfName))\r
+                    if M.ModuleType in ["PEIM", "PEI_CORE"]:\r
+                        PcdFromModule.Phase = "PEI"\r
+                    if PcdFromModule not in self._DynaPcdList_ and PcdFromModule.Type in GenC.gDynamicExPcd:\r
+                        self._DynaPcdList_.append(PcdFromModule)\r
+                    elif PcdFromModule not in self._NonDynaPcdList_ and PcdFromModule.Type in TAB_PCDS_PATCHABLE_IN_MODULE:\r
+                        self._NonDynaPcdList_.append(PcdFromModule)\r
+                    if PcdFromModule in self._DynaPcdList_ and PcdFromModule.Phase == 'PEI' and PcdFromModule.Type in GenC.gDynamicExPcd:\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
+                        # 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
+                        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
+            # 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
+            # PcdsPatchableInModule.\r
+            if PcdFromModule not in self._DynaPcdList_:\r
+                continue\r
+            Index = self._DynaPcdList_.index(PcdFromModule)\r
+            if PcdFromModule.IsFromDsc == False and \\r
+                PcdFromModule.Type in TAB_PCDS_PATCHABLE_IN_MODULE and \\r
+                PcdFromModule.IsFromBinaryInf == True and \\r
+                self._DynaPcdList_[Index].IsFromBinaryInf == False:\r
+                Index = self._DynaPcdList_.index(PcdFromModule)\r
+                self._DynaPcdList_.remove (self._DynaPcdList_[Index])\r
+\r
+        # print out error information and break the build, if error found\r
+        if len(NoDatumTypePcdList) > 0:\r
+            NoDatumTypePcdListString = "\n\t\t".join(NoDatumTypePcdList)\r
+            EdkLogger.error("build", AUTOGEN_ERROR, "PCD setting error",\r
+                            File=self.MetaFile,\r
+                            ExtraData="\n\tPCD(s) without MaxDatumSize:\n\t\t%s\n"\r
+                                      % NoDatumTypePcdListString)\r
+        self._NonDynamicPcdList = self._NonDynaPcdList_\r
+        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
+        #    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
+        # The reason of sorting is make sure the unicode string is in double-byte alignment in string table.\r
+        #\r
+        UnicodePcdArray = []\r
+        HiiPcdArray     = []\r
+        OtherPcdArray   = []\r
+        VpdPcdDict      = {}\r
+        VpdFile               = VpdInfoFile.VpdInfoFile()\r
+        NeedProcessVpdMapFile = False\r
+\r
+        for pcd in self.Platform.Pcds.keys():\r
+            if pcd not in self._PlatformPcds.keys():\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
+\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.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
+\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
+                if Pcd.Type in [TAB_PCDS_DYNAMIC_VPD, TAB_PCDS_DYNAMIC_EX_VPD]:\r
+                    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
+            if PcdNvStoreDfBuffer:\r
+                self.VariableInfo = self.CollectVariables(self._DynamicPcdList)\r
+                vardump = self.VariableInfo.dump()\r
+                if vardump:\r
+                    PcdNvStoreDfBuffer.DefaultValue = vardump\r
+                    for skuname in PcdNvStoreDfBuffer.SkuInfoList:\r
+                        PcdNvStoreDfBuffer.SkuInfoList[skuname].DefaultValue = vardump\r
+                        PcdNvStoreDfBuffer.MaxDatumSize = str(len(vardump.split(",")))\r
+\r
+            PlatformPcds = self._PlatformPcds.keys()\r
+            PlatformPcds.sort()\r
+            #\r
+            # Add VPD type PCD into VpdFile and determine whether the VPD PCD need to be fixed up.\r
+            #\r
+            VpdSkuMap = {}\r
+            for PcdKey in PlatformPcds:\r
+                Pcd = self._PlatformPcds[PcdKey]\r
+                if Pcd.Type in [TAB_PCDS_DYNAMIC_VPD, TAB_PCDS_DYNAMIC_EX_VPD] and \\r
+                   PcdKey in VpdPcdDict:\r
+                    Pcd = VpdPcdDict[PcdKey]\r
+                    SkuValueMap = {}\r
+                    for (SkuName,Sku) in Pcd.SkuInfoList.items():\r
+                        Sku.VpdOffset = Sku.VpdOffset.strip()\r
+                        PcdValue = Sku.DefaultValue\r
+                        if PcdValue == "":\r
+                            PcdValue  = Pcd.DefaultValue\r
+                        if Sku.VpdOffset != '*':\r
+                            if PcdValue.startswith("{"):\r
+                                Alignment = 8\r
+                            elif PcdValue.startswith("L"):\r
+                                Alignment = 2\r
+                            else:\r
+                                Alignment = 1\r
+                            try:\r
+                                VpdOffset = int(Sku.VpdOffset)\r
+                            except:\r
+                                try:\r
+                                    VpdOffset = int(Sku.VpdOffset, 16)\r
+                                except:\r
+                                    EdkLogger.error("build", FORMAT_INVALID, "Invalid offset value %s for PCD %s.%s." % (Sku.VpdOffset, Pcd.TokenSpaceGuidCName, Pcd.TokenCName))\r
+                            if VpdOffset % Alignment != 0:\r
+                                if PcdValue.startswith("{"):\r
+                                    EdkLogger.warn("build", "The offset value of PCD %s.%s is not 8-byte aligned!" %(Pcd.TokenSpaceGuidCName, Pcd.TokenCName), File=self.MetaFile)\r
+                                else:\r
+                                    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, 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
+                            NeedProcessVpdMapFile = True\r
+                            if self.Platform.VpdToolGuid == None or self.Platform.VpdToolGuid == '':\r
+                                EdkLogger.error("Build", FILE_NOT_FOUND, \\r
+                                                "Fail to find third-party BPDG tool to process VPD PCDs. BPDG Guid tool need to be defined in tools_def.txt and VPD_TOOL_GUID need to be provided in DSC file.")\r
+\r
+                    VpdSkuMap[PcdKey] = SkuValueMap\r
+            #\r
+            # Fix the PCDs define in VPD PCD section that never referenced by module.\r
+            # An example is PCD for signature usage.\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
+                    if not (self.Platform.VpdToolGuid == None or self.Platform.VpdToolGuid == ''):\r
+                        FoundFlag = False\r
+                        for VpdPcd in VpdFile._VpdArray.keys():\r
+                            # This PCD has been referenced by module\r
+                            if (VpdPcd.TokenSpaceGuidCName == DscPcdEntry.TokenSpaceGuidCName) and \\r
+                               (VpdPcd.TokenCName == DscPcdEntry.TokenCName):\r
+                                    FoundFlag = True\r
+\r
+                        # Not found, it should be signature\r
+                        if not FoundFlag :\r
+                            # just pick the a value to determine whether is unicode string type\r
+                            SkuValueMap = {}\r
+                            for (SkuName,Sku) in DscPcdEntry.SkuInfoList.items():\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
+                                        DecPcdEntry = eachDec.Pcds[DecPcd]\r
+                                        if (DecPcdEntry.TokenSpaceGuidCName == DscPcdEntry.TokenSpaceGuidCName) and \\r
+                                           (DecPcdEntry.TokenCName == DscPcdEntry.TokenCName):\r
+                                            # Print warning message to let the developer make a determine.\r
+                                            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.DatumType    = DecPcdEntry.DatumType\r
+                                            DscPcdEntry.DefaultValue = DecPcdEntry.DefaultValue\r
+                                            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
+                                                DscPcdEntry.SkuInfoList[DscPcdEntry.SkuInfoList.keys()[0]].DefaultValue = DecPcdEntry.DefaultValue\r
+                                                                                                                    \r
+                                if DscPcdEntry not in self._DynamicPcdList:\r
+                                    self._DynamicPcdList.append(DscPcdEntry)\r
+                                Sku.VpdOffset = Sku.VpdOffset.strip()\r
+                                PcdValue = Sku.DefaultValue\r
+                                if PcdValue == "":\r
+                                    PcdValue  = DscPcdEntry.DefaultValue\r
+                                if Sku.VpdOffset != '*':\r
+                                    if PcdValue.startswith("{"):\r
+                                        Alignment = 8\r
+                                    elif PcdValue.startswith("L"):\r
+                                        Alignment = 2\r
+                                    else:\r
+                                        Alignment = 1\r
+                                    try:\r
+                                        VpdOffset = int(Sku.VpdOffset)\r
+                                    except:\r
+                                        try:\r
+                                            VpdOffset = int(Sku.VpdOffset, 16)\r
+                                        except:\r
+                                            EdkLogger.error("build", FORMAT_INVALID, "Invalid offset value %s for PCD %s.%s." % (Sku.VpdOffset, DscPcdEntry.TokenSpaceGuidCName, DscPcdEntry.TokenCName))\r
+                                    if VpdOffset % Alignment != 0:\r
+                                        if PcdValue.startswith("{"):\r
+                                            EdkLogger.warn("build", "The offset value of PCD %s.%s is not 8-byte aligned!" %(DscPcdEntry.TokenSpaceGuidCName, DscPcdEntry.TokenCName), File=self.MetaFile)\r
+                                        else:\r
+                                            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, Sku.VpdOffset)\r
+                                SkuValueMap[PcdValue].append(Sku)\r
+                                if not NeedProcessVpdMapFile and Sku.VpdOffset == "*":\r
+                                    NeedProcessVpdMapFile = True \r
+                            if DscPcdEntry.DatumType == 'VOID*' and PcdValue.startswith("L"):\r
+                                UnicodePcdArray.append(DscPcdEntry)\r
+                            elif len(Sku.VariableName) > 0:\r
+                                HiiPcdArray.append(DscPcdEntry)\r
+                            else:\r
+                                OtherPcdArray.append(DscPcdEntry)\r
+                                \r
+                                # if the offset of a VPD is *, then it need to be fixed up by third party tool.\r
+                            VpdSkuMap[DscPcd] = SkuValueMap\r
+            if (self.Platform.FlashDefinition == None or self.Platform.FlashDefinition == '') and \\r
+               VpdFile.GetCount() != 0:\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
+\r
+                self.FixVpdOffset(VpdFile)\r
+\r
+                self.FixVpdOffset(self.UpdateNVStoreMaxSize(VpdFile))\r
+\r
+                # Process VPD map file generated by third party BPDG tool\r
+                if NeedProcessVpdMapFile:\r
+                    VpdMapFilePath = os.path.join(self.BuildDir, "FV", "%s.map" % self.Platform.VpdToolGuid)\r
+                    if os.path.exists(VpdMapFilePath):\r
+                        VpdFile.Read(VpdMapFilePath)\r
+\r
+                        # Fixup "*" offset\r
+                        for pcd in VpdSkuMap:\r
+                            vpdinfo = VpdFile.GetVpdInfo(pcd)\r
+                            if vpdinfo is None:\r
+                            # just pick the a value to determine whether is unicode string type\r
+                                continue\r
+                            for pcdvalue in VpdSkuMap[pcd]:\r
+                                for sku in VpdSkuMap[pcd][pcdvalue]:\r
+                                    for item in vpdinfo:\r
+                                        if item[2] == pcdvalue:\r
+                                            sku.VpdOffset = item[1]\r
+                    else:\r
+                        EdkLogger.error("build", FILE_READ_FAILURE, "Can not find VPD map file %s to fix up VPD offset." % VpdMapFilePath)\r
+\r
+            # 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.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
+\r
+                PcdValue = Sku.DefaultValue\r
+                if Pcd.DatumType == 'VOID*' and PcdValue.startswith("L"):\r
+                    # if found PCD which datum value is unicode string the insert to left size of UnicodeIndex\r
+                    UnicodePcdArray.append(Pcd)\r
+                elif len(Sku.VariableName) > 0:\r
+                    # if found HII type PCD then insert to right of UnicodeIndex\r
+                    HiiPcdArray.append(Pcd)\r
+                else:\r
+                    OtherPcdArray.append(Pcd)\r
+            del self._DynamicPcdList[:]\r
+        self._DynamicPcdList.extend(UnicodePcdArray)\r
+        self._DynamicPcdList.extend(HiiPcdArray)\r
+        self._DynamicPcdList.extend(OtherPcdArray)\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
+                        continue\r
+                    pcd.SkuInfoList[SkuName] = pcd.SkuInfoList['DEFAULT']\r
+        self.AllPcdList = self._NonDynamicPcdList + self._DynamicPcdList\r
+\r
+    def FixVpdOffset(self,VpdFile ):\r
+        FvPath = os.path.join(self.BuildDir, "FV")\r
+        if not os.path.exists(FvPath):\r
+            try:\r
+                os.makedirs(FvPath)\r
+            except:\r
+                EdkLogger.error("build", FILE_WRITE_FAILURE, "Fail to create FV folder under %s" % self.BuildDir)\r
+\r
+        VpdFilePath = os.path.join(FvPath, "%s.txt" % self.Platform.VpdToolGuid)\r
+\r
+        if VpdFile.Write(VpdFilePath):\r
+            # retrieve BPDG tool's path from tool_def.txt according to VPD_TOOL_GUID defined in DSC file.\r
+            BPDGToolName = None\r
+            for ToolDef in self.ToolDefinition.values():\r
+                if ToolDef.has_key("GUID") and ToolDef["GUID"] == self.Platform.VpdToolGuid:\r
+                    if not ToolDef.has_key("PATH"):\r
+                        EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, "PATH attribute was not provided for BPDG guid tool %s in tools_def.txt" % self.Platform.VpdToolGuid)\r
+                    BPDGToolName = ToolDef["PATH"]\r
+                    break\r
+            # Call third party GUID BPDG tool.\r
+            if BPDGToolName != None:\r
+                VpdInfoFile.CallExtenalBPDGTool(BPDGToolName, VpdFilePath)\r
+            else:\r
+                EdkLogger.error("Build", FILE_NOT_FOUND, "Fail to find third-party BPDG tool to process VPD PCDs. BPDG Guid tool need to be defined in tools_def.txt and VPD_TOOL_GUID need to be provided in DSC file.")\r
+\r
+    ## Return the platform build data object\r
+    def _GetPlatform(self):\r
+        if self._Platform == None:\r
+            self._Platform = self.BuildDatabase[self.MetaFile, self.Arch, self.BuildTarget, self.ToolChain]\r
+        return self._Platform\r
+\r
+    ## Return platform name\r
+    def _GetName(self):\r
+        return self.Platform.PlatformName\r
+\r
+    ## Return the meta file GUID\r
+    def _GetGuid(self):\r
+        return self.Platform.Guid\r
+\r
+    ## Return the platform version\r
+    def _GetVersion(self):\r
+        return self.Platform.Version\r
+\r
+    ## Return the FDF file name\r
+    def _GetFdfFile(self):\r
+        if self._FdfFile == None:\r
+            if self.Workspace.FdfFile != "":\r
+                self._FdfFile= mws.join(self.WorkspaceDir, self.Workspace.FdfFile)\r
+            else:\r
+                self._FdfFile = ''\r
+        return self._FdfFile\r
+\r
+    ## Return the build output directory platform specifies\r
+    def _GetOutputDir(self):\r
+        return self.Platform.OutputDirectory\r
+\r
+    ## Return the directory to store all intermediate and final files built\r
+    def _GetBuildDir(self):\r
+        if self._BuildDir == None:\r
+            if os.path.isabs(self.OutputDir):\r
+                self._BuildDir = path.join(\r
+                                            path.abspath(self.OutputDir),\r
+                                            self.BuildTarget + "_" + self.ToolChain,\r
+                                            )\r
+            else:\r
+                self._BuildDir = path.join(\r
+                                            self.WorkspaceDir,\r
+                                            self.OutputDir,\r
+                                            self.BuildTarget + "_" + self.ToolChain,\r
+                                            )\r
+            GlobalData.gBuildDirectory = self._BuildDir\r
+        return self._BuildDir\r
+\r
+    ## Return directory of platform makefile\r
+    #\r
+    #   @retval     string  Makefile directory\r
+    #\r
+    def _GetMakeFileDir(self):\r
+        if self._MakeFileDir == None:\r
+            self._MakeFileDir = path.join(self.BuildDir, self.Arch)\r
+        return self._MakeFileDir\r
+\r
+    ## Return build command string\r
+    #\r
+    #   @retval     string  Build command string\r
+    #\r
+    def _GetBuildCommand(self):\r
+        if self._BuildCommand == None:\r
+            self._BuildCommand = []\r
+            if "MAKE" in self.ToolDefinition and "PATH" in self.ToolDefinition["MAKE"]:\r
+                self._BuildCommand += SplitOption(self.ToolDefinition["MAKE"]["PATH"])\r
+                if "FLAGS" in self.ToolDefinition["MAKE"]:\r
+                    NewOption = self.ToolDefinition["MAKE"]["FLAGS"].strip()\r
+                    if NewOption != '':\r
+                        self._BuildCommand += SplitOption(NewOption)\r
+        return self._BuildCommand\r
+\r
+    ## Get tool chain definition\r
+    #\r
+    #  Get each tool defition for given tool chain from tools_def.txt and platform\r
+    #\r
+    def _GetToolDefinition(self):\r
+        if self._ToolDefinitions == None:\r
+            ToolDefinition = self.Workspace.ToolDef.ToolsDefTxtDictionary\r
+            if TAB_TOD_DEFINES_COMMAND_TYPE not in self.Workspace.ToolDef.ToolsDefTxtDatabase:\r
+                EdkLogger.error('build', RESOURCE_NOT_AVAILABLE, "No tools found in configuration",\r
+                                ExtraData="[%s]" % self.MetaFile)\r
+            self._ToolDefinitions = {}\r
+            DllPathList = set()\r
+            for Def in ToolDefinition:\r
+                Target, Tag, Arch, Tool, Attr = Def.split("_")\r
+                if Target != self.BuildTarget or Tag != self.ToolChain or Arch != self.Arch:\r
+                    continue\r
+\r
+                Value = ToolDefinition[Def]\r
+                # don't record the DLL\r
+                if Attr == "DLL":\r
+                    DllPathList.add(Value)\r
+                    continue\r
+\r
+                if Tool not in self._ToolDefinitions:\r
+                    self._ToolDefinitions[Tool] = {}\r
+                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
+                self._ToolDefinitions["MAKE"]["FLAGS"] += " -s"\r
+            MakeFlags = ''\r
+            for Tool in self._ToolDefinitions:\r
+                for Attr in self._ToolDefinitions[Tool]:\r
+                    Value = self._ToolDefinitions[Tool][Attr]\r
+                    if Tool in self.BuildOption and Attr in self.BuildOption[Tool]:\r
+                        # check if override is indicated\r
+                        if self.BuildOption[Tool][Attr].startswith('='):\r
+                            Value = self.BuildOption[Tool][Attr][1:]\r
+                        else:\r
+                            if Attr != 'PATH':\r
+                                Value += " " + self.BuildOption[Tool][Attr]\r
+                            else:\r
+                                Value = self.BuildOption[Tool][Attr]\r
+\r
+                    if Attr == "PATH":\r
+                        # Don't put MAKE definition in the file\r
+                        if Tool == "MAKE":\r
+                            MakePath = Value\r
+                        else:\r
+                            ToolsDef += "%s = %s\n" % (Tool, Value)\r
+                    elif Attr != "DLL":\r
+                        # Don't put MAKE definition in the file\r
+                        if Tool == "MAKE":\r
+                            if Attr == "FLAGS":\r
+                                MakeFlags = Value\r
+                        else:\r
+                            ToolsDef += "%s_%s = %s\n" % (Tool, Attr, Value)\r
+                ToolsDef += "\n"\r
+\r
+            SaveFileOnChange(self.ToolDefinitionFile, ToolsDef)\r
+            for DllPath in DllPathList:\r
+                os.environ["PATH"] = DllPath + os.pathsep + os.environ["PATH"]\r
+            os.environ["MAKE_FLAGS"] = MakeFlags\r
+\r
+        return self._ToolDefinitions\r
+\r
+    ## Return the paths of tools\r
+    def _GetToolDefFile(self):\r
+        if self._ToolDefFile == None:\r
+            self._ToolDefFile = os.path.join(self.MakeFileDir, "TOOLS_DEF." + self.Arch)\r
+        return self._ToolDefFile\r
+\r
+    ## Retrieve the toolchain family of given toolchain tag. Default to 'MSFT'.\r
+    def _GetToolChainFamily(self):\r
+        if self._ToolChainFamily == None:\r
+            ToolDefinition = self.Workspace.ToolDef.ToolsDefTxtDatabase\r
+            if TAB_TOD_DEFINES_FAMILY not in ToolDefinition \\r
+               or self.ToolChain not in ToolDefinition[TAB_TOD_DEFINES_FAMILY] \\r
+               or not ToolDefinition[TAB_TOD_DEFINES_FAMILY][self.ToolChain]:\r
+                EdkLogger.verbose("No tool chain family found in configuration for %s. Default to MSFT." \\r
+                                   % self.ToolChain)\r
+                self._ToolChainFamily = "MSFT"\r
+            else:\r
+                self._ToolChainFamily = ToolDefinition[TAB_TOD_DEFINES_FAMILY][self.ToolChain]\r
+        return self._ToolChainFamily\r
+\r
+    def _GetBuildRuleFamily(self):\r
+        if self._BuildRuleFamily == None:\r
+            ToolDefinition = self.Workspace.ToolDef.ToolsDefTxtDatabase\r
+            if TAB_TOD_DEFINES_BUILDRULEFAMILY not in ToolDefinition \\r
+               or self.ToolChain not in ToolDefinition[TAB_TOD_DEFINES_BUILDRULEFAMILY] \\r
+               or not ToolDefinition[TAB_TOD_DEFINES_BUILDRULEFAMILY][self.ToolChain]:\r
+                EdkLogger.verbose("No tool chain family found in configuration for %s. Default to MSFT." \\r
+                                   % self.ToolChain)\r
+                self._BuildRuleFamily = "MSFT"\r
+            else:\r
+                self._BuildRuleFamily = ToolDefinition[TAB_TOD_DEFINES_BUILDRULEFAMILY][self.ToolChain]\r
+        return self._BuildRuleFamily\r
+\r
+    ## Return the build options specific for all modules in this platform\r
+    def _GetBuildOptions(self):\r
+        if self._BuildOption == None:\r
+            self._BuildOption = self._ExpandBuildOption(self.Platform.BuildOptions)\r
+        return self._BuildOption\r
+\r
+    ## Return the build options specific for EDK modules in this platform\r
+    def _GetEdkBuildOptions(self):\r
+        if self._EdkBuildOption == None:\r
+            self._EdkBuildOption = self._ExpandBuildOption(self.Platform.BuildOptions, EDK_NAME)\r
+        return self._EdkBuildOption\r
+\r
+    ## Return the build options specific for EDKII modules in this platform\r
+    def _GetEdkIIBuildOptions(self):\r
+        if self._EdkIIBuildOption == None:\r
+            self._EdkIIBuildOption = self._ExpandBuildOption(self.Platform.BuildOptions, EDKII_NAME)\r
+        return self._EdkIIBuildOption\r
+\r
+    ## Parse build_rule.txt in Conf Directory.\r
+    #\r
+    #   @retval     BuildRule object\r
+    #\r
+    def _GetBuildRule(self):\r
+        if self._BuildRule == None:\r
+            BuildRuleFile = None\r
+            if TAB_TAT_DEFINES_BUILD_RULE_CONF in self.Workspace.TargetTxt.TargetTxtDictionary:\r
+                BuildRuleFile = self.Workspace.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_BUILD_RULE_CONF]\r
+            if BuildRuleFile in [None, '']:\r
+                BuildRuleFile = gDefaultBuildRuleFile\r
+            self._BuildRule = BuildRule(BuildRuleFile)\r
+            if self._BuildRule._FileVersion == "":\r
+                self._BuildRule._FileVersion = AutoGenReqBuildRuleVerNum\r
+            else:\r
+                if self._BuildRule._FileVersion < AutoGenReqBuildRuleVerNum :\r
+                    # If Build Rule's version is less than the version number required by the tools, halting the build.\r
+                    EdkLogger.error("build", AUTOGEN_ERROR,\r
+                                    ExtraData="The version number [%s] of build_rule.txt is less than the version number required by the AutoGen.(the minimum required version number is [%s])"\\r
+                                     % (self._BuildRule._FileVersion, AutoGenReqBuildRuleVerNum))\r
+\r
+        return self._BuildRule\r
+\r
+    ## Summarize the packages used by modules in this platform\r
+    def _GetPackageList(self):\r
+        if self._PackageList == None:\r
+            self._PackageList = set()\r
+            for La in self.LibraryAutoGenList:\r
+                self._PackageList.update(La.DependentPackageList)\r
+            for Ma in self.ModuleAutoGenList:\r
+                self._PackageList.update(Ma.DependentPackageList)\r
+            #Collect package set information from INF of FDF\r
+            PkgSet = set()\r
+            for ModuleFile in self._AsBuildModuleList:\r
+                if ModuleFile in self.Platform.Modules:\r
+                    continue\r
+                ModuleData = self.BuildDatabase[ModuleFile, self.Arch, self.BuildTarget, self.ToolChain]\r
+                PkgSet.update(ModuleData.Packages)\r
+            self._PackageList = list(self._PackageList) + list (PkgSet)\r
+        return self._PackageList\r
+\r
+    def _GetNonDynamicPcdDict(self):\r
+        if self._NonDynamicPcdDict:\r
+            return self._NonDynamicPcdDict\r
+        for Pcd in self.NonDynamicPcdList:\r
+            self._NonDynamicPcdDict[(Pcd.TokenCName,Pcd.TokenSpaceGuidCName)] = Pcd\r
+        return self._NonDynamicPcdDict\r
+\r
+    ## Get list of non-dynamic PCDs\r
+    def _GetNonDynamicPcdList(self):\r
+        if self._NonDynamicPcdList == None:\r
+            self.CollectPlatformDynamicPcds()\r
+        return self._NonDynamicPcdList\r
+\r
+    ## Get list of dynamic PCDs\r
+    def _GetDynamicPcdList(self):\r
+        if self._DynamicPcdList == None:\r
+            self.CollectPlatformDynamicPcds()\r
+        return self._DynamicPcdList\r
+\r
+    ## Generate Token Number for all PCD\r
+    def _GetPcdTokenNumbers(self):\r
+        if self._PcdTokenNumber == None:\r
+            self._PcdTokenNumber = sdict()\r
+            TokenNumber = 1\r
+            #\r
+            # Make the Dynamic and DynamicEx PCD use within different TokenNumber area. \r
+            # Such as:\r
+            # \r
+            # Dynamic PCD:\r
+            # TokenNumber 0 ~ 10\r
+            # DynamicEx PCD:\r
+            # TokeNumber 11 ~ 20\r
+            #\r
+            for Pcd in self.DynamicPcdList:\r
+                if Pcd.Phase == "PEI":\r
+                    if Pcd.Type in ["Dynamic", "DynamicDefault", "DynamicVpd", "DynamicHii"]:\r
+                        EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))\r
+                        self._PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber\r
+                        TokenNumber += 1\r
+\r
+            for Pcd in self.DynamicPcdList:\r
+                if Pcd.Phase == "PEI":\r
+                    if Pcd.Type in ["DynamicEx", "DynamicExDefault", "DynamicExVpd", "DynamicExHii"]:\r
+                        EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))\r
+                        self._PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber\r
+                        TokenNumber += 1\r
+\r
+            for Pcd in self.DynamicPcdList:\r
+                if Pcd.Phase == "DXE":\r
+                    if Pcd.Type in ["Dynamic", "DynamicDefault", "DynamicVpd", "DynamicHii"]:\r
+                        EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))\r
+                        self._PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber\r
+                        TokenNumber += 1\r
+\r
+            for Pcd in self.DynamicPcdList:\r
+                if Pcd.Phase == "DXE":\r
+                    if Pcd.Type in ["DynamicEx", "DynamicExDefault", "DynamicExVpd", "DynamicExHii"]:\r
+                        EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))\r
+                        self._PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber\r
+                        TokenNumber += 1\r
+\r
+            for Pcd in self.NonDynamicPcdList:\r
+                self._PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber\r
+                TokenNumber += 1\r
+        return self._PcdTokenNumber\r
+\r
+    ## Summarize ModuleAutoGen objects of all modules/libraries to be built for this platform\r
+    def _GetAutoGenObjectList(self):\r
+        self._ModuleAutoGenList = []\r
+        self._LibraryAutoGenList = []\r
+        for ModuleFile in self.Platform.Modules:\r
+            Ma = ModuleAutoGen(\r
+                    self.Workspace,\r
+                    ModuleFile,\r
+                    self.BuildTarget,\r
+                    self.ToolChain,\r
+                    self.Arch,\r
+                    self.MetaFile\r
+                    )\r
+            if Ma not in self._ModuleAutoGenList:\r
+                self._ModuleAutoGenList.append(Ma)\r
+            for La in Ma.LibraryAutoGenList:\r
+                if La not in self._LibraryAutoGenList:\r
+                    self._LibraryAutoGenList.append(La)\r
+                if Ma not in La._ReferenceModules:\r
+                    La._ReferenceModules.append(Ma)\r
+\r
+    ## Summarize ModuleAutoGen objects of all modules to be built for this platform\r
+    def _GetModuleAutoGenList(self):\r
+        if self._ModuleAutoGenList == None:\r
+            self._GetAutoGenObjectList()\r
+        return self._ModuleAutoGenList\r
+\r
+    ## Summarize ModuleAutoGen objects of all libraries to be built for this platform\r
+    def _GetLibraryAutoGenList(self):\r
+        if self._LibraryAutoGenList == None:\r
+            self._GetAutoGenObjectList()\r
+        return self._LibraryAutoGenList\r
+\r
+    ## Test if a module is supported by the platform\r
+    #\r
+    #  An error will be raised directly if the module or its arch is not supported\r
+    #  by the platform or current configuration\r
+    #\r
+    def ValidModule(self, Module):\r
+        return Module in self.Platform.Modules or Module in self.Platform.LibraryInstances \\r
+            or Module in self._AsBuildModuleList\r
+\r
+    ## Resolve the library classes in a module to library instances\r
+    #\r
+    # This method will not only resolve library classes but also sort the library\r
+    # instances according to the dependency-ship.\r
+    #\r
+    #   @param  Module      The module from which the library classes will be resolved\r
+    #\r
+    #   @retval library_list    List of library instances sorted\r
+    #\r
+    def ApplyLibraryInstance(self, Module):\r
+        # Cover the case that the binary INF file is list in the FDF file but not DSC file, return empty list directly\r
+        if str(Module) not in self.Platform.Modules:\r
+            return []\r
+\r
+        ModuleType = Module.ModuleType\r
+\r
+        # for overridding library instances with module specific setting\r
+        PlatformModule = self.Platform.Modules[str(Module)]\r
+\r
+        # add forced library instances (specified under LibraryClasses sections)\r
+        #\r
+        # If a module has a MODULE_TYPE of USER_DEFINED,\r
+        # do not link in NULL library class instances from the global [LibraryClasses.*] sections.\r
+        #\r
+        if Module.ModuleType != SUP_MODULE_USER_DEFINED:\r
+            for LibraryClass in self.Platform.LibraryClasses.GetKeys():\r
+                if LibraryClass.startswith("NULL") and self.Platform.LibraryClasses[LibraryClass, Module.ModuleType]:\r
+                    Module.LibraryClasses[LibraryClass] = self.Platform.LibraryClasses[LibraryClass, Module.ModuleType]\r
+\r
+        # add forced library instances (specified in module overrides)\r
+        for LibraryClass in PlatformModule.LibraryClasses:\r
+            if LibraryClass.startswith("NULL"):\r
+                Module.LibraryClasses[LibraryClass] = PlatformModule.LibraryClasses[LibraryClass]\r
+\r
+        # EdkII module\r
+        LibraryConsumerList = [Module]\r
+        Constructor         = []\r
+        ConsumedByList      = sdict()\r
+        LibraryInstance     = sdict()\r
+\r
+        EdkLogger.verbose("")\r
+        EdkLogger.verbose("Library instances of module [%s] [%s]:" % (str(Module), self.Arch))\r
+        while len(LibraryConsumerList) > 0:\r
+            M = LibraryConsumerList.pop()\r
+            for LibraryClassName in M.LibraryClasses:\r
+                if LibraryClassName not in LibraryInstance:\r
+                    # override library instance for this module\r
+                    if LibraryClassName in PlatformModule.LibraryClasses:\r
+                        LibraryPath = PlatformModule.LibraryClasses[LibraryClassName]\r
+                    else:\r
+                        LibraryPath = self.Platform.LibraryClasses[LibraryClassName, ModuleType]\r
+                    if LibraryPath == None or LibraryPath == "":\r
+                        LibraryPath = M.LibraryClasses[LibraryClassName]\r
+                        if LibraryPath == None or LibraryPath == "":\r
+                            EdkLogger.error("build", RESOURCE_NOT_AVAILABLE,\r
+                                            "Instance of library class [%s] is not found" % LibraryClassName,\r
+                                            File=self.MetaFile,\r
+                                            ExtraData="in [%s] [%s]\n\tconsumed by module [%s]" % (str(M), self.Arch, str(Module)))\r
+\r
+                    LibraryModule = self.BuildDatabase[LibraryPath, self.Arch, self.BuildTarget, self.ToolChain]\r
+                    # for those forced library instance (NULL library), add a fake library class\r
+                    if LibraryClassName.startswith("NULL"):\r
+                        LibraryModule.LibraryClass.append(LibraryClassObject(LibraryClassName, [ModuleType]))\r
+                    elif LibraryModule.LibraryClass == None \\r
+                         or len(LibraryModule.LibraryClass) == 0 \\r
+                         or (ModuleType != 'USER_DEFINED'\r
+                             and ModuleType not in LibraryModule.LibraryClass[0].SupModList):\r
+                        # only USER_DEFINED can link against any library instance despite of its SupModList\r
+                        EdkLogger.error("build", OPTION_MISSING,\r
+                                        "Module type [%s] is not supported by library instance [%s]" \\r
+                                        % (ModuleType, LibraryPath), File=self.MetaFile,\r
+                                        ExtraData="consumed by [%s]" % str(Module))\r
+\r
+                    LibraryInstance[LibraryClassName] = LibraryModule\r
+                    LibraryConsumerList.append(LibraryModule)\r
+                    EdkLogger.verbose("\t" + str(LibraryClassName) + " : " + str(LibraryModule))\r
+                else:\r
+                    LibraryModule = LibraryInstance[LibraryClassName]\r
+\r
+                if LibraryModule == None:\r
+                    continue\r
+\r
+                if LibraryModule.ConstructorList != [] and LibraryModule not in Constructor:\r
+                    Constructor.append(LibraryModule)\r
+\r
+                if LibraryModule not in ConsumedByList:\r
+                    ConsumedByList[LibraryModule] = []\r
+                # don't add current module itself to consumer list\r
+                if M != Module:\r
+                    if M in ConsumedByList[LibraryModule]:\r
+                        continue\r
+                    ConsumedByList[LibraryModule].append(M)\r
+        #\r
+        # Initialize the sorted output list to the empty set\r
+        #\r
+        SortedLibraryList = []\r
+        #\r
+        # Q <- Set of all nodes with no incoming edges\r
+        #\r
+        LibraryList = [] #LibraryInstance.values()\r
+        Q = []\r
+        for LibraryClassName in LibraryInstance:\r
+            M = LibraryInstance[LibraryClassName]\r
+            LibraryList.append(M)\r
+            if ConsumedByList[M] == []:\r
+                Q.append(M)\r
+\r
+        #\r
+        # start the  DAG algorithm\r
+        #\r
+        while True:\r
+            EdgeRemoved = True\r
+            while Q == [] and EdgeRemoved:\r
+                EdgeRemoved = False\r
+                # for each node Item with a Constructor\r
+                for Item in LibraryList:\r
+                    if Item not in Constructor:\r
+                        continue\r
+                    # for each Node without a constructor with an edge e from Item to Node\r
+                    for Node in ConsumedByList[Item]:\r
+                        if Node in Constructor:\r
+                            continue\r
+                        # remove edge e from the graph if Node has no constructor\r
+                        ConsumedByList[Item].remove(Node)\r
+                        EdgeRemoved = True\r
+                        if ConsumedByList[Item] == []:\r
+                            # insert Item into Q\r
+                            Q.insert(0, Item)\r
+                            break\r
+                    if Q != []:\r
+                        break\r
+            # DAG is done if there's no more incoming edge for all nodes\r
+            if Q == []:\r
+                break\r
+\r
+            # remove node from Q\r
+            Node = Q.pop()\r
+            # output Node\r
+            SortedLibraryList.append(Node)\r
+\r
+            # for each node Item with an edge e from Node to Item do\r
+            for Item in LibraryList:\r
+                if Node not in ConsumedByList[Item]:\r
+                    continue\r
+                # remove edge e from the graph\r
+                ConsumedByList[Item].remove(Node)\r
+\r
+                if ConsumedByList[Item] != []:\r
+                    continue\r
+                # insert Item into Q, if Item has no other incoming edges\r
+                Q.insert(0, Item)\r
+\r
+        #\r
+        # if any remaining node Item in the graph has a constructor and an incoming edge, then the graph has a cycle\r
+        #\r
+        for Item in LibraryList:\r
+            if ConsumedByList[Item] != [] and Item in Constructor and len(Constructor) > 1:\r
+                ErrorMessage = "\tconsumed by " + "\n\tconsumed by ".join([str(L) for L in ConsumedByList[Item]])\r
+                EdkLogger.error("build", BUILD_ERROR, 'Library [%s] with constructors has a cycle' % str(Item),\r
+                                ExtraData=ErrorMessage, File=self.MetaFile)\r
+            if Item not in SortedLibraryList:\r
+                SortedLibraryList.append(Item)\r
+\r
+        #\r
+        # Build the list of constructor and destructir names\r
+        # The DAG Topo sort produces the destructor order, so the list of constructors must generated in the reverse order\r
+        #\r
+        SortedLibraryList.reverse()\r
+        return SortedLibraryList\r
+\r
+\r
+    ## Override PCD setting (type, value, ...)\r
+    #\r
+    #   @param  ToPcd       The PCD to be overrided\r
+    #   @param  FromPcd     The PCD overrideing from\r
+    #\r
+    def _OverridePcd(self, ToPcd, FromPcd, Module=""):\r
+        #\r
+        # in case there's PCDs coming from FDF file, which have no type given.\r
+        # at this point, ToPcd.Type has the type found from dependent\r
+        # package\r
+        #\r
+        TokenCName = ToPcd.TokenCName\r
+        for PcdItem in GlobalData.MixedPcd:\r
+            if (ToPcd.TokenCName, ToPcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
+                TokenCName = PcdItem[0]\r
+                break\r
+        if FromPcd != None:\r
+            if GlobalData.BuildOptionPcd:\r
+                for pcd in GlobalData.BuildOptionPcd:\r
+                    if (FromPcd.TokenSpaceGuidCName, FromPcd.TokenCName) == (pcd[0], pcd[1]):\r
+                        FromPcd.DefaultValue = pcd[2]\r
+                        break\r
+            if ToPcd.Pending and FromPcd.Type not in [None, '']:\r
+                ToPcd.Type = FromPcd.Type\r
+            elif (ToPcd.Type not in [None, '']) and (FromPcd.Type not in [None, ''])\\r
+                and (ToPcd.Type != FromPcd.Type) and (ToPcd.Type in FromPcd.Type):\r
+                if ToPcd.Type.strip() == "DynamicEx":\r
+                    ToPcd.Type = FromPcd.Type\r
+            elif ToPcd.Type not in [None, ''] and FromPcd.Type not in [None, ''] \\r
+                and ToPcd.Type != FromPcd.Type:\r
+                EdkLogger.error("build", OPTION_CONFLICT, "Mismatched PCD type",\r
+                                ExtraData="%s.%s is defined as [%s] in module %s, but as [%s] in platform."\\r
+                                          % (ToPcd.TokenSpaceGuidCName, TokenCName,\r
+                                             ToPcd.Type, Module, FromPcd.Type),\r
+                                          File=self.MetaFile)\r
+\r
+            if FromPcd.MaxDatumSize not in [None, '']:\r
+                ToPcd.MaxDatumSize = FromPcd.MaxDatumSize\r
+            if FromPcd.DefaultValue not in [None, '']:\r
+                ToPcd.DefaultValue = FromPcd.DefaultValue\r
+            if FromPcd.TokenValue not in [None, '']:\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
+                ToPcd.DatumType = FromPcd.DatumType\r
+            if FromPcd.SkuInfoList not in [None, '', []]:\r
+                ToPcd.SkuInfoList = FromPcd.SkuInfoList\r
+\r
+            # check the validation of datum\r
+            IsValid, Cause = CheckPcdDatum(ToPcd.DatumType, ToPcd.DefaultValue)\r
+            if not IsValid:\r
+                EdkLogger.error('build', FORMAT_INVALID, Cause, File=self.MetaFile,\r
+                                ExtraData="%s.%s" % (ToPcd.TokenSpaceGuidCName, TokenCName))\r
+            ToPcd.validateranges = FromPcd.validateranges\r
+            ToPcd.validlists = FromPcd.validlists\r
+            ToPcd.expressions = FromPcd.expressions\r
+\r
+        if ToPcd.DatumType == "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
+            if Value in [None, '']:\r
+                ToPcd.MaxDatumSize = '1'\r
+            elif Value[0] == 'L':\r
+                ToPcd.MaxDatumSize = str((len(Value) - 2) * 2)\r
+            elif Value[0] == '{':\r
+                ToPcd.MaxDatumSize = str(len(Value.split(',')))\r
+            else:\r
+                ToPcd.MaxDatumSize = str(len(Value) - 1)\r
+\r
+        # apply default SKU for dynamic PCDS if specified one is not available\r
+        if (ToPcd.Type in PCD_DYNAMIC_TYPE_LIST or ToPcd.Type in PCD_DYNAMIC_EX_TYPE_LIST) \\r
+            and ToPcd.SkuInfoList in [None, {}, '']:\r
+            if self.Platform.SkuName in self.Platform.SkuIds:\r
+                SkuName = self.Platform.SkuName\r
+            else:\r
+                SkuName = 'DEFAULT'\r
+            ToPcd.SkuInfoList = {\r
+                SkuName : SkuInfoClass(SkuName, self.Platform.SkuIds[SkuName][0], '', '', '', '', '', ToPcd.DefaultValue)\r
+            }\r
+\r
+    ## Apply PCD setting defined platform to a module\r
+    #\r
+    #   @param  Module  The module from which the PCD setting will be overrided\r
+    #\r
+    #   @retval PCD_list    The list PCDs with settings from platform\r
+    #\r
+    def ApplyPcdSetting(self, Module, Pcds):\r
+        # for each PCD in module\r
+        for Name, Guid in Pcds:\r
+            PcdInModule = Pcds[Name, Guid]\r
+            # find out the PCD setting in platform\r
+            if (Name, Guid) in self.Platform.Pcds:\r
+                PcdInPlatform = self.Platform.Pcds[Name, Guid]\r
+            else:\r
+                PcdInPlatform = None\r
+            # then override the settings if any\r
+            self._OverridePcd(PcdInModule, PcdInPlatform, Module)\r
+            # resolve the VariableGuid value\r
+            for SkuId in PcdInModule.SkuInfoList:\r
+                Sku = PcdInModule.SkuInfoList[SkuId]\r
+                if Sku.VariableGuid == '': continue\r
+                Sku.VariableGuidValue = GuidValue(Sku.VariableGuid, self.PackageList, self.MetaFile.Path)\r
+                if Sku.VariableGuidValue == None:\r
+                    PackageList = "\n\t".join([str(P) for P in self.PackageList])\r
+                    EdkLogger.error(\r
+                                'build',\r
+                                RESOURCE_NOT_AVAILABLE,\r
+                                "Value of GUID [%s] is not found in" % Sku.VariableGuid,\r
+                                ExtraData=PackageList + "\n\t(used with %s.%s from module %s)" \\r
+                                                        % (Guid, Name, str(Module)),\r
+                                File=self.MetaFile\r
+                                )\r
+\r
+        # override PCD settings with module specific setting\r
+        if Module in self.Platform.Modules:\r
+            PlatformModule = self.Platform.Modules[str(Module)]\r
+            for Key  in PlatformModule.Pcds:\r
+                Flag = False\r
+                if Key in Pcds:\r
+                    ToPcd = Pcds[Key]\r
+                    Flag = True\r
+                elif Key in GlobalData.MixedPcd:\r
+                    for PcdItem in GlobalData.MixedPcd[Key]:\r
+                        if PcdItem in Pcds:\r
+                            ToPcd = Pcds[PcdItem]\r
+                            Flag = True\r
+                            break\r
+                if Flag:\r
+                    self._OverridePcd(ToPcd, PlatformModule.Pcds[Key], Module)\r
+        return Pcds.values()\r
+\r
+    ## Resolve library names to library modules\r
+    #\r
+    # (for Edk.x modules)\r
+    #\r
+    #   @param  Module  The module from which the library names will be resolved\r
+    #\r
+    #   @retval library_list    The list of library modules\r
+    #\r
+    def ResolveLibraryReference(self, Module):\r
+        EdkLogger.verbose("")\r
+        EdkLogger.verbose("Library instances of module [%s] [%s]:" % (str(Module), self.Arch))\r
+        LibraryConsumerList = [Module]\r
+\r
+        # "CompilerStub" is a must for Edk modules\r
+        if Module.Libraries:\r
+            Module.Libraries.append("CompilerStub")\r
+        LibraryList = []\r
+        while len(LibraryConsumerList) > 0:\r
+            M = LibraryConsumerList.pop()\r
+            for LibraryName in M.Libraries:\r
+                Library = self.Platform.LibraryClasses[LibraryName, ':dummy:']\r
+                if Library == None:\r
+                    for Key in self.Platform.LibraryClasses.data.keys():\r
+                        if LibraryName.upper() == Key.upper():\r
+                            Library = self.Platform.LibraryClasses[Key, ':dummy:']\r
+                            break\r
+                    if Library == None:\r
+                        EdkLogger.warn("build", "Library [%s] is not found" % LibraryName, File=str(M),\r
+                            ExtraData="\t%s [%s]" % (str(Module), self.Arch))\r
+                        continue\r
+\r
+                if Library not in LibraryList:\r
+                    LibraryList.append(Library)\r
+                    LibraryConsumerList.append(Library)\r
+                    EdkLogger.verbose("\t" + LibraryName + " : " + str(Library) + ' ' + str(type(Library)))\r
+        return LibraryList\r
+\r
+    ## Calculate the priority value of the build option\r
+    #\r
+    # @param    Key    Build option definition contain: TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE\r
+    #\r
+    # @retval   Value  Priority value based on the priority list.\r
+    #\r
+    def CalculatePriorityValue(self, Key):\r
+        Target, ToolChain, Arch, CommandType, Attr = Key.split('_')\r
+        PriorityValue = 0x11111\r
+        if Target == "*":\r
+            PriorityValue &= 0x01111\r
+        if ToolChain == "*":\r
+            PriorityValue &= 0x10111\r
+        if Arch == "*":\r
+            PriorityValue &= 0x11011\r
+        if CommandType == "*":\r
+            PriorityValue &= 0x11101\r
+        if Attr == "*":\r
+            PriorityValue &= 0x11110\r
+\r
+        return self.PrioList["0x%0.5x" % PriorityValue]\r
+\r
+\r
+    ## Expand * in build option key\r
+    #\r
+    #   @param  Options     Options to be expanded\r
+    #\r
+    #   @retval options     Options expanded\r
+    #      \r
+    def _ExpandBuildOption(self, Options, ModuleStyle=None):\r
+        BuildOptions = {}\r
+        FamilyMatch  = False\r
+        FamilyIsNull = True\r
+\r
+        OverrideList = {}\r
+        #\r
+        # Construct a list contain the build options which need override.\r
+        #\r
+        for Key in Options:\r
+            #\r
+            # Key[0] -- tool family\r
+            # Key[1] -- TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE\r
+            #\r
+            if (Key[0] == self.BuildRuleFamily and\r
+                (ModuleStyle == None or len(Key) < 3 or (len(Key) > 2 and Key[2] == ModuleStyle))):\r
+                Target, ToolChain, Arch, CommandType, Attr = Key[1].split('_')\r
+                if Target == self.BuildTarget or Target == "*":\r
+                    if ToolChain == self.ToolChain or ToolChain == "*":\r
+                        if Arch == self.Arch or Arch == "*":\r
+                            if Options[Key].startswith("="):\r
+                                if OverrideList.get(Key[1]) != None:\r
+                                    OverrideList.pop(Key[1])\r
+                                OverrideList[Key[1]] = Options[Key]\r
+        \r
+        #\r
+        # Use the highest priority value. \r
+        #\r
+        if (len(OverrideList) >= 2):\r
+            KeyList = OverrideList.keys()\r
+            for Index in range(len(KeyList)):\r
+                NowKey = KeyList[Index]\r
+                Target1, ToolChain1, Arch1, CommandType1, Attr1 = NowKey.split("_")\r
+                for Index1 in range(len(KeyList) - Index - 1):\r
+                    NextKey = KeyList[Index1 + Index + 1]\r
+                    #\r
+                    # Compare two Key, if one is included by another, choose the higher priority one\r
+                    #                    \r
+                    Target2, ToolChain2, Arch2, CommandType2, Attr2 = NextKey.split("_")\r
+                    if Target1 == Target2 or Target1 == "*" or Target2 == "*":\r
+                        if ToolChain1 == ToolChain2 or ToolChain1 == "*" or ToolChain2 == "*":\r
+                            if Arch1 == Arch2 or Arch1 == "*" or Arch2 == "*":\r
+                                if CommandType1 == CommandType2 or CommandType1 == "*" or CommandType2 == "*":\r
+                                    if Attr1 == Attr2 or Attr1 == "*" or Attr2 == "*":\r
+                                        if self.CalculatePriorityValue(NowKey) > self.CalculatePriorityValue(NextKey):\r
+                                            if Options.get((self.BuildRuleFamily, NextKey)) != None:\r
+                                                Options.pop((self.BuildRuleFamily, NextKey))\r
+                                        else:\r
+                                            if Options.get((self.BuildRuleFamily, NowKey)) != None:\r
+                                                Options.pop((self.BuildRuleFamily, NowKey))\r
+                                                           \r
+        for Key in Options:\r
+            if ModuleStyle != None and len (Key) > 2:\r
+                # Check Module style is EDK or EDKII.\r
+                # Only append build option for the matched style module.\r
+                if ModuleStyle == EDK_NAME and Key[2] != EDK_NAME:\r
+                    continue\r
+                elif ModuleStyle == EDKII_NAME and Key[2] != EDKII_NAME:\r
+                    continue\r
+            Family = Key[0]\r
+            Target, Tag, Arch, Tool, Attr = Key[1].split("_")\r
+            # if tool chain family doesn't match, skip it\r
+            if Tool in self.ToolDefinition and Family != "":\r
+                FamilyIsNull = False\r
+                if self.ToolDefinition[Tool].get(TAB_TOD_DEFINES_BUILDRULEFAMILY, "") != "":\r
+                    if Family != self.ToolDefinition[Tool][TAB_TOD_DEFINES_BUILDRULEFAMILY]:\r
+                        continue\r
+                elif Family != self.ToolDefinition[Tool][TAB_TOD_DEFINES_FAMILY]:\r
+                    continue\r
+                FamilyMatch = True\r
+            # expand any wildcard\r
+            if Target == "*" or Target == self.BuildTarget:\r
+                if Tag == "*" or Tag == self.ToolChain:\r
+                    if Arch == "*" or Arch == self.Arch:\r
+                        if Tool not in BuildOptions:\r
+                            BuildOptions[Tool] = {}\r
+                        if Attr != "FLAGS" or Attr not in BuildOptions[Tool] or Options[Key].startswith('='):\r
+                            BuildOptions[Tool][Attr] = Options[Key]\r
+                        else:\r
+                            # append options for the same tool except PATH\r
+                            if Attr != 'PATH':\r
+                                BuildOptions[Tool][Attr] += " " + Options[Key]\r
+                            else:\r
+                                BuildOptions[Tool][Attr] = Options[Key]\r
+        # Build Option Family has been checked, which need't to be checked again for family.\r
+        if FamilyMatch or FamilyIsNull:\r
+            return BuildOptions\r
+\r
+        for Key in Options:\r
+            if ModuleStyle != None and len (Key) > 2:\r
+                # Check Module style is EDK or EDKII.\r
+                # Only append build option for the matched style module.\r
+                if ModuleStyle == EDK_NAME and Key[2] != EDK_NAME:\r
+                    continue\r
+                elif ModuleStyle == EDKII_NAME and Key[2] != EDKII_NAME:\r
+                    continue\r
+            Family = Key[0]\r
+            Target, Tag, Arch, Tool, Attr = Key[1].split("_")\r
+            # if tool chain family doesn't match, skip it\r
+            if Tool not in self.ToolDefinition or Family == "":\r
+                continue\r
+            # option has been added before\r
+            if Family != self.ToolDefinition[Tool][TAB_TOD_DEFINES_FAMILY]:\r
+                continue\r
+\r
+            # expand any wildcard\r
+            if Target == "*" or Target == self.BuildTarget:\r
+                if Tag == "*" or Tag == self.ToolChain:\r
+                    if Arch == "*" or Arch == self.Arch:\r
+                        if Tool not in BuildOptions:\r
+                            BuildOptions[Tool] = {}\r
+                        if Attr != "FLAGS" or Attr not in BuildOptions[Tool] or Options[Key].startswith('='):\r
+                            BuildOptions[Tool][Attr] = Options[Key]\r
+                        else:\r
+                            # append options for the same tool except PATH\r
+                            if Attr != 'PATH':\r
+                                BuildOptions[Tool][Attr] += " " + Options[Key]\r
+                            else:\r
+                                BuildOptions[Tool][Attr] = Options[Key]\r
+        return BuildOptions\r
+\r
+    ## Append build options in platform to a module\r
+    #\r
+    #   @param  Module  The module to which the build options will be appened\r
+    #\r
+    #   @retval options     The options appended with build options in platform\r
+    #\r
+    def ApplyBuildOption(self, Module):\r
+        # Get the different options for the different style module\r
+        if Module.AutoGenVersion < 0x00010005:\r
+            PlatformOptions = self.EdkBuildOption\r
+            ModuleTypeOptions = self.Platform.GetBuildOptionsByModuleType(EDK_NAME, Module.ModuleType)\r
+        else:\r
+            PlatformOptions = self.EdkIIBuildOption\r
+            ModuleTypeOptions = self.Platform.GetBuildOptionsByModuleType(EDKII_NAME, Module.ModuleType)\r
+        ModuleTypeOptions = self._ExpandBuildOption(ModuleTypeOptions)\r
+        ModuleOptions = self._ExpandBuildOption(Module.BuildOptions)\r
+        if Module in self.Platform.Modules:\r
+            PlatformModule = self.Platform.Modules[str(Module)]\r
+            PlatformModuleOptions = self._ExpandBuildOption(PlatformModule.BuildOptions)\r
+        else:\r
+            PlatformModuleOptions = {}\r
+\r
+        BuildRuleOrder = None\r
+        for Options in [self.ToolDefinition, ModuleOptions, PlatformOptions, ModuleTypeOptions, PlatformModuleOptions]:\r
+            for Tool in Options:\r
+                for Attr in Options[Tool]:\r
+                    if Attr == TAB_TOD_DEFINES_BUILDRULEORDER:\r
+                        BuildRuleOrder = Options[Tool][Attr]\r
+\r
+        AllTools = set(ModuleOptions.keys() + PlatformOptions.keys() +\r
+                       PlatformModuleOptions.keys() + ModuleTypeOptions.keys() +\r
+                       self.ToolDefinition.keys())\r
+        BuildOptions = {}\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
+                    # check if override is indicated\r
+                    if Value.startswith('='):\r
+                        ToolPath = Value[1:]\r
+                        ToolPath = mws.handleWsMacro(ToolPath)\r
+                        BuildOptions[Tool][Attr] = ToolPath\r
+                    else:\r
+                        Value = mws.handleWsMacro(Value)\r
+                        if Attr != 'PATH':\r
+                            BuildOptions[Tool][Attr] += " " + Value\r
+                        else:\r
+                            BuildOptions[Tool][Attr] = Value\r
+        if Module.AutoGenVersion < 0x00010005 and self.Workspace.UniFlag != 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
+    Platform            = property(_GetPlatform)\r
+    Name                = property(_GetName)\r
+    Guid                = property(_GetGuid)\r
+    Version             = property(_GetVersion)\r
+\r
+    OutputDir           = property(_GetOutputDir)\r
+    BuildDir            = property(_GetBuildDir)\r
+    MakeFileDir         = property(_GetMakeFileDir)\r
+    FdfFile             = property(_GetFdfFile)\r
+\r
+    PcdTokenNumber      = property(_GetPcdTokenNumbers)    # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber\r
+    DynamicPcdList      = property(_GetDynamicPcdList)    # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]\r
+    NonDynamicPcdList   = property(_GetNonDynamicPcdList)    # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]\r
+    NonDynamicPcdDict   = property(_GetNonDynamicPcdDict)\r
+    PackageList         = property(_GetPackageList)\r
+\r
+    ToolDefinition      = property(_GetToolDefinition)    # toolcode : tool path\r
+    ToolDefinitionFile  = property(_GetToolDefFile)    # toolcode : lib path\r
+    ToolChainFamily     = property(_GetToolChainFamily)\r
+    BuildRuleFamily     = property(_GetBuildRuleFamily)\r
+    BuildOption         = property(_GetBuildOptions)    # toolcode : option\r
+    EdkBuildOption      = property(_GetEdkBuildOptions)   # edktoolcode : option\r
+    EdkIIBuildOption    = property(_GetEdkIIBuildOptions) # edkiitoolcode : option\r
+\r
+    BuildCommand        = property(_GetBuildCommand)\r
+    BuildRule           = property(_GetBuildRule)\r
+    ModuleAutoGenList   = property(_GetModuleAutoGenList)\r
+    LibraryAutoGenList  = property(_GetLibraryAutoGenList)\r
+    GenFdsCommand       = property(_GenFdsCommand)\r
+\r
+## ModuleAutoGen class\r
+#\r
+# This class encapsules the AutoGen behaviors for the build tools. In addition to\r
+# the generation of AutoGen.h and AutoGen.c, it will generate *.depex file according\r
+# to the [depex] section in module's inf file.\r
+#\r
+class ModuleAutoGen(AutoGen):\r
+    ## Cache the timestamps of metafiles of every module in a class variable\r
+    #\r
+    TimeDict = {}\r
+\r
+    ## The real constructor of ModuleAutoGen\r
+    #\r
+    #  This method is not supposed to be called by users of ModuleAutoGen. It's\r
+    #  only used by factory method __new__() to do real initialization work for an\r
+    #  object of ModuleAutoGen\r
+    #\r
+    #   @param      Workspace           EdkIIWorkspaceBuild object\r
+    #   @param      ModuleFile          The path of module file\r
+    #   @param      Target              Build target (DEBUG, RELEASE)\r
+    #   @param      Toolchain           Name of tool chain\r
+    #   @param      Arch                The arch the module supports\r
+    #   @param      PlatformFile        Platform meta-file\r
+    #\r
+    def _Init(self, Workspace, ModuleFile, Target, Toolchain, Arch, PlatformFile):\r
+        EdkLogger.debug(EdkLogger.DEBUG_9, "AutoGen module [%s] [%s]" % (ModuleFile, Arch))\r
+        GlobalData.gProcessingFile = "%s [%s, %s, %s]" % (ModuleFile, Arch, Toolchain, Target)\r
+\r
+        self.Workspace = Workspace\r
+        self.WorkspaceDir = Workspace.WorkspaceDir\r
+\r
+        self.MetaFile = ModuleFile\r
+        self.PlatformInfo = PlatformAutoGen(Workspace, PlatformFile, Target, Toolchain, Arch)\r
+        # check if this module is employed by active platform\r
+        if not self.PlatformInfo.ValidModule(self.MetaFile):\r
+            EdkLogger.verbose("Module [%s] for [%s] is not employed by active platform\n" \\r
+                              % (self.MetaFile, Arch))\r
+            return False\r
+\r
+        self.SourceDir = self.MetaFile.SubDir\r
+        self.SourceDir = mws.relpath(self.SourceDir, self.WorkspaceDir)\r
+\r
+        self.SourceOverrideDir = None\r
+        # use overrided path defined in DSC file\r
+        if self.MetaFile.Key in GlobalData.gOverrideDir:\r
+            self.SourceOverrideDir = GlobalData.gOverrideDir[self.MetaFile.Key]\r
+\r
+        self.ToolChain = Toolchain\r
+        self.BuildTarget = Target\r
+        self.Arch = Arch\r
+        self.ToolChainFamily = self.PlatformInfo.ToolChainFamily\r
+        self.BuildRuleFamily = self.PlatformInfo.BuildRuleFamily\r
+\r
+        self.IsMakeFileCreated = False\r
+        self.IsCodeFileCreated = False\r
+        self.IsAsBuiltInfCreated = False\r
+        self.DepexGenerated = False\r
+\r
+        self.BuildDatabase = self.Workspace.BuildDatabase\r
+        self.BuildRuleOrder = None\r
+        self.BuildTime      = 0\r
+\r
+        self._Module          = None\r
+        self._Name            = None\r
+        self._Guid            = None\r
+        self._Version         = None\r
+        self._ModuleType      = None\r
+        self._ComponentType   = None\r
+        self._PcdIsDriver     = None\r
+        self._AutoGenVersion  = None\r
+        self._LibraryFlag     = None\r
+        self._CustomMakefile  = None\r
+        self._Macro           = None\r
+\r
+        self._BuildDir        = None\r
+        self._OutputDir       = None\r
+        self._FfsOutputDir    = None\r
+        self._DebugDir        = None\r
+        self._MakeFileDir     = None\r
+\r
+        self._IncludePathList = None\r
+        self._IncludePathLength = 0\r
+        self._AutoGenFileList = None\r
+        self._UnicodeFileList = None\r
+        self._VfrFileList = None\r
+        self._IdfFileList = None\r
+        self._SourceFileList  = None\r
+        self._ObjectFileList  = None\r
+        self._BinaryFileList  = None\r
+\r
+        self._DependentPackageList    = None\r
+        self._DependentLibraryList    = None\r
+        self._LibraryAutoGenList      = None\r
+        self._DerivedPackageList      = None\r
+        self._ModulePcdList           = None\r
+        self._LibraryPcdList          = None\r
+        self._PcdComments = sdict()\r
+        self._GuidList                = None\r
+        self._GuidsUsedByPcd = None\r
+        self._GuidComments = sdict()\r
+        self._ProtocolList            = None\r
+        self._ProtocolComments = sdict()\r
+        self._PpiList                 = None\r
+        self._PpiComments = sdict()\r
+        self._DepexList               = None\r
+        self._DepexExpressionList     = None\r
+        self._BuildOption             = None\r
+        self._BuildOptionIncPathList  = None\r
+        self._BuildTargets            = None\r
+        self._IntroBuildTargetList    = None\r
+        self._FinalBuildTargetList    = None\r
+        self._FileTypes               = None\r
+        self._BuildRules              = None\r
+\r
+        self._TimeStampPath           = None\r
+\r
+        self.AutoGenDepSet = set()\r
+\r
+        \r
+        ## The Modules referenced to this Library\r
+        #  Only Library has this attribute\r
+        self._ReferenceModules        = []        \r
+        \r
+        ## Store the FixedAtBuild Pcds\r
+        #  \r
+        self._FixedAtBuildPcds         = []\r
+        self.ConstPcd                  = {}\r
+        return True\r
+\r
+    def __repr__(self):\r
+        return "%s [%s]" % (self.MetaFile, self.Arch)\r
+\r
+    # Get FixedAtBuild Pcds of this Module\r
+    def _GetFixedAtBuildPcds(self):\r
+        if self._FixedAtBuildPcds:\r
+            return self._FixedAtBuildPcds\r
+        for Pcd in self.ModulePcdList:\r
+            if Pcd.Type != "FixedAtBuild":\r
+                continue\r
+            if Pcd not in self._FixedAtBuildPcds:\r
+                self._FixedAtBuildPcds.append(Pcd)\r
+                \r
+        return self._FixedAtBuildPcds        \r
+\r
+    def _GetUniqueBaseName(self):\r
+        BaseName = self.Name\r
+        for Module in self.PlatformInfo.ModuleAutoGenList:\r
+            if Module.MetaFile == self.MetaFile:\r
+                continue\r
+            if Module.Name == self.Name:\r
+                if uuid.UUID(Module.Guid) == uuid.UUID(self.Guid):\r
+                    EdkLogger.error("build", FILE_DUPLICATED, 'Modules have same BaseName and FILE_GUID:\n'\r
+                                    '  %s\n  %s' % (Module.MetaFile, self.MetaFile))\r
+                BaseName = '%s_%s' % (self.Name, self.Guid)\r
+        return BaseName\r
+\r
+    # Macros could be used in build_rule.txt (also Makefile)\r
+    def _GetMacros(self):\r
+        if self._Macro == None:\r
+            self._Macro = sdict()\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_GUID"           ] = self.Guid\r
+            self._Macro["MODULE_VERSION"        ] = self.Version\r
+            self._Macro["MODULE_TYPE"           ] = self.ModuleType\r
+            self._Macro["MODULE_FILE"           ] = str(self.MetaFile)\r
+            self._Macro["MODULE_FILE_BASE_NAME" ] = self.MetaFile.BaseName\r
+            self._Macro["MODULE_RELATIVE_DIR"   ] = self.SourceDir\r
+            self._Macro["MODULE_DIR"            ] = self.SourceDir\r
+\r
+            self._Macro["BASE_NAME"             ] = self.Name\r
+\r
+            self._Macro["ARCH"                  ] = self.Arch\r
+            self._Macro["TOOLCHAIN"             ] = self.ToolChain\r
+            self._Macro["TOOLCHAIN_TAG"         ] = self.ToolChain\r
+            self._Macro["TOOL_CHAIN_TAG"        ] = self.ToolChain\r
+            self._Macro["TARGET"                ] = self.BuildTarget\r
+\r
+            self._Macro["BUILD_DIR"             ] = self.PlatformInfo.BuildDir\r
+            self._Macro["BIN_DIR"               ] = os.path.join(self.PlatformInfo.BuildDir, self.Arch)\r
+            self._Macro["LIB_DIR"               ] = os.path.join(self.PlatformInfo.BuildDir, self.Arch)\r
+            self._Macro["MODULE_BUILD_DIR"      ] = self.BuildDir\r
+            self._Macro["OUTPUT_DIR"            ] = self.OutputDir\r
+            self._Macro["DEBUG_DIR"             ] = self.DebugDir\r
+            self._Macro["DEST_DIR_OUTPUT"       ] = self.OutputDir\r
+            self._Macro["DEST_DIR_DEBUG"        ] = self.DebugDir\r
+            self._Macro["PLATFORM_NAME"         ] = self.PlatformInfo.Name\r
+            self._Macro["PLATFORM_GUID"         ] = self.PlatformInfo.Guid\r
+            self._Macro["PLATFORM_VERSION"      ] = self.PlatformInfo.Version\r
+            self._Macro["PLATFORM_RELATIVE_DIR" ] = self.PlatformInfo.SourceDir\r
+            self._Macro["PLATFORM_DIR"          ] = mws.join(self.WorkspaceDir, self.PlatformInfo.SourceDir)\r
+            self._Macro["PLATFORM_OUTPUT_DIR"   ] = self.PlatformInfo.OutputDir\r
+            self._Macro["FFS_OUTPUT_DIR"        ] = self.FfsOutputDir\r
+        return self._Macro\r
+\r
+    ## Return the module build data object\r
+    def _GetModule(self):\r
+        if self._Module == None:\r
+            self._Module = self.Workspace.BuildDatabase[self.MetaFile, self.Arch, self.BuildTarget, self.ToolChain]\r
+        return self._Module\r
+\r
+    ## Return the module name\r
+    def _GetBaseName(self):\r
+        return self.Module.BaseName\r
+\r
+    ## Return the module DxsFile if exist\r
+    def _GetDxsFile(self):\r
+        return self.Module.DxsFile\r
+\r
+    ## Return the module SourceOverridePath\r
+    def _GetSourceOverridePath(self):\r
+        return self.Module.SourceOverridePath\r
+\r
+    ## Return the module meta-file GUID\r
+    def _GetGuid(self):\r
+        #\r
+        # To build same module more than once, the module path with FILE_GUID overridden has\r
+        # the file name FILE_GUIDmodule.inf, but the relative path (self.MetaFile.File) is the realy path\r
+        # in DSC. The overridden GUID can be retrieved from file name\r
+        #\r
+        if os.path.basename(self.MetaFile.File) != os.path.basename(self.MetaFile.Path):\r
+            #\r
+            # Length of GUID is 36\r
+            #\r
+            return os.path.basename(self.MetaFile.Path)[:36]\r
+        return self.Module.Guid\r
+\r
+    ## Return the module version\r
+    def _GetVersion(self):\r
+        return self.Module.Version\r
+\r
+    ## Return the module type\r
+    def _GetModuleType(self):\r
+        return self.Module.ModuleType\r
+\r
+    ## Return the component type (for Edk.x style of module)\r
+    def _GetComponentType(self):\r
+        return self.Module.ComponentType\r
+\r
+    ## Return the build type\r
+    def _GetBuildType(self):\r
+        return self.Module.BuildType\r
+\r
+    ## Return the PCD_IS_DRIVER setting\r
+    def _GetPcdIsDriver(self):\r
+        return self.Module.PcdIsDriver\r
+\r
+    ## Return the autogen version, i.e. module meta-file version\r
+    def _GetAutoGenVersion(self):\r
+        return self.Module.AutoGenVersion\r
+\r
+    ## Check if the module is library or not\r
+    def _IsLibrary(self):\r
+        if self._LibraryFlag == None:\r
+            if self.Module.LibraryClass != None and self.Module.LibraryClass != []:\r
+                self._LibraryFlag = True\r
+            else:\r
+                self._LibraryFlag = False\r
+        return self._LibraryFlag\r
+\r
+    ## Check if the module is binary module or not\r
+    def _IsBinaryModule(self):\r
+        return self.Module.IsBinaryModule\r
+\r
+    ## Return the directory to store intermediate files of the module\r
+    def _GetBuildDir(self):\r
+        if self._BuildDir == None:\r
+            self._BuildDir = path.join(\r
+                                    self.PlatformInfo.BuildDir,\r
+                                    self.Arch,\r
+                                    self.SourceDir,\r
+                                    self.MetaFile.BaseName\r
+                                    )\r
+            CreateDirectory(self._BuildDir)\r
+        return self._BuildDir\r
+\r
+    ## Return the directory to store the intermediate object files of the mdoule\r
+    def _GetOutputDir(self):\r
+        if self._OutputDir == None:\r
+            self._OutputDir = path.join(self.BuildDir, "OUTPUT")\r
+            CreateDirectory(self._OutputDir)\r
+        return self._OutputDir\r
+\r
+    ## Return the directory to store ffs file\r
+    def _GetFfsOutputDir(self):\r
+        if self._FfsOutputDir == None:\r
+            if GlobalData.gFdfParser != None:\r
+                self._FfsOutputDir = path.join(self.PlatformInfo.BuildDir, "FV", "Ffs", self.Guid + self.Name)\r
+            else:\r
+                self._FfsOutputDir = ''\r
+        return self._FfsOutputDir\r
+\r
+    ## Return the directory to store auto-gened source files of the mdoule\r
+    def _GetDebugDir(self):\r
+        if self._DebugDir == None:\r
+            self._DebugDir = path.join(self.BuildDir, "DEBUG")\r
+            CreateDirectory(self._DebugDir)\r
+        return self._DebugDir\r
+\r
+    ## Return the path of custom file\r
+    def _GetCustomMakefile(self):\r
+        if self._CustomMakefile == None:\r
+            self._CustomMakefile = {}\r
+            for Type in self.Module.CustomMakefile:\r
+                if Type in gMakeTypeMap:\r
+                    MakeType = gMakeTypeMap[Type]\r
+                else:\r
+                    MakeType = 'nmake'\r
+                if self.SourceOverrideDir != None:\r
+                    File = os.path.join(self.SourceOverrideDir, self.Module.CustomMakefile[Type])\r
+                    if not os.path.exists(File):\r
+                        File = os.path.join(self.SourceDir, self.Module.CustomMakefile[Type])\r
+                else:\r
+                    File = os.path.join(self.SourceDir, self.Module.CustomMakefile[Type])\r
+                self._CustomMakefile[MakeType] = File\r
+        return self._CustomMakefile\r
+\r
+    ## Return the directory of the makefile\r
+    #\r
+    #   @retval     string  The directory string of module's makefile\r
+    #\r
+    def _GetMakeFileDir(self):\r
+        return self.BuildDir\r
+\r
+    ## Return build command string\r
+    #\r
+    #   @retval     string  Build command string\r
+    #\r
+    def _GetBuildCommand(self):\r
+        return self.PlatformInfo.BuildCommand\r
+\r
+    ## Get object list of all packages the module and its dependent libraries belong to\r
+    #\r
+    #   @retval     list    The list of package object\r
+    #\r
+    def _GetDerivedPackageList(self):\r
+        PackageList = []\r
+        for M in [self.Module] + self.DependentLibraryList:\r
+            for Package in M.Packages:\r
+                if Package in PackageList:\r
+                    continue\r
+                PackageList.append(Package)\r
+        return PackageList\r
+    \r
+    ## Get the depex string\r
+    #\r
+    # @return : a string contain all depex expresion.\r
+    def _GetDepexExpresionString(self):\r
+        DepexStr = ''\r
+        DepexList = []\r
+        ## DPX_SOURCE IN Define section.\r
+        if self.Module.DxsFile:\r
+            return DepexStr\r
+        for M in [self.Module] + self.DependentLibraryList:\r
+            Filename = M.MetaFile.Path\r
+            InfObj = InfSectionParser.InfSectionParser(Filename)\r
+            DepexExpresionList = InfObj.GetDepexExpresionList()\r
+            for DepexExpresion in DepexExpresionList:\r
+                for key in DepexExpresion.keys():\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
+                    # All different DEPEX section tags would be copied into the As Built INF file\r
+                    # and there would be separate DEPEX section tags\r
+                    if self.ModuleType.upper() == SUP_MODULE_USER_DEFINED:\r
+                        if (Arch.upper() == self.Arch.upper()) and (ModuleType.upper() != TAB_ARCH_COMMON):\r
+                            DepexList.append({(Arch, ModuleType): DepexExpr})\r
+                    else:\r
+                        if Arch.upper() == TAB_ARCH_COMMON or \\r
+                          (Arch.upper() == self.Arch.upper() and \\r
+                          ModuleType.upper() in [TAB_ARCH_COMMON, self.ModuleType.upper()]):\r
+                            DepexList.append({(Arch, ModuleType): DepexExpr})\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
+                for key in Depex.keys():\r
+                    DepexStr += '[Depex.%s.%s]\n' % key\r
+                    DepexStr += '\n'.join(['# '+ val for val in Depex[key]])\r
+                    DepexStr += '\n\n'\r
+            if not DepexStr:\r
+                return '[Depex.%s]\n' % self.Arch\r
+            return DepexStr\r
+        \r
+        #the type of build module not is USER_DEFINED.\r
+        Count = 0\r
+        for Depex in DepexList:\r
+            Count += 1\r
+            if DepexStr != '':\r
+                DepexStr += ' AND '\r
+            DepexStr += '('\r
+            for D in Depex.values():\r
+                DepexStr += ' '.join([val for val in D])\r
+            Index = DepexStr.find('END')\r
+            if Index > -1 and Index == len(DepexStr) - 3:\r
+                DepexStr = DepexStr[:-3]\r
+            DepexStr = DepexStr.strip()\r
+            DepexStr += ')'\r
+        if Count == 1:\r
+            DepexStr = DepexStr.lstrip('(').rstrip(')').strip()\r
+        if not DepexStr:\r
+            return '[Depex.%s]\n' % self.Arch\r
+        return '[Depex.%s]\n#  ' % self.Arch + DepexStr\r
+    \r
+    ## Merge dependency expression\r
+    #\r
+    #   @retval     list    The token list of the dependency expression after parsed\r
+    #\r
+    def _GetDepexTokenList(self):\r
+        if self._DepexList == None:\r
+            self._DepexList = {}\r
+            if self.DxsFile or self.IsLibrary or TAB_DEPENDENCY_EXPRESSION_FILE in self.FileTypes:\r
+                return self._DepexList\r
+\r
+            self._DepexList[self.ModuleType] = []\r
+\r
+            for ModuleType in self._DepexList:\r
+                DepexList = self._DepexList[ModuleType]\r
+                #\r
+                # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion\r
+                #\r
+                for M in [self.Module] + self.DependentLibraryList:\r
+                    Inherited = False\r
+                    for D in M.Depex[self.Arch, ModuleType]:\r
+                        if DepexList != []:\r
+                            DepexList.append('AND')\r
+                        DepexList.append('(')\r
+                        DepexList.extend(D)\r
+                        if DepexList[-1] == 'END':  # no need of a END at this time\r
+                            DepexList.pop()\r
+                        DepexList.append(')')\r
+                        Inherited = True\r
+                    if Inherited:\r
+                        EdkLogger.verbose("DEPEX[%s] (+%s) = %s" % (self.Name, M.BaseName, DepexList))\r
+                    if 'BEFORE' in DepexList or 'AFTER' in DepexList:\r
+                        break\r
+                if len(DepexList) > 0:\r
+                    EdkLogger.verbose('')\r
+        return self._DepexList\r
+\r
+    ## Merge dependency expression\r
+    #\r
+    #   @retval     list    The token list of the dependency expression after parsed\r
+    #\r
+    def _GetDepexExpressionTokenList(self):\r
+        if self._DepexExpressionList == None:\r
+            self._DepexExpressionList = {}\r
+            if self.DxsFile or self.IsLibrary or TAB_DEPENDENCY_EXPRESSION_FILE in self.FileTypes:\r
+                return self._DepexExpressionList\r
+\r
+            self._DepexExpressionList[self.ModuleType] = ''\r
+\r
+            for ModuleType in self._DepexExpressionList:\r
+                DepexExpressionList = self._DepexExpressionList[ModuleType]\r
+                #\r
+                # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion\r
+                #\r
+                for M in [self.Module] + self.DependentLibraryList:\r
+                    Inherited = False\r
+                    for D in M.DepexExpression[self.Arch, ModuleType]:\r
+                        if DepexExpressionList != '':\r
+                            DepexExpressionList += ' AND '\r
+                        DepexExpressionList += '('\r
+                        DepexExpressionList += D\r
+                        DepexExpressionList = DepexExpressionList.rstrip('END').strip()\r
+                        DepexExpressionList += ')'\r
+                        Inherited = True\r
+                    if Inherited:\r
+                        EdkLogger.verbose("DEPEX[%s] (+%s) = %s" % (self.Name, M.BaseName, DepexExpressionList))\r
+                    if 'BEFORE' in DepexExpressionList or 'AFTER' in DepexExpressionList:\r
+                        break\r
+                if len(DepexExpressionList) > 0:\r
+                    EdkLogger.verbose('')\r
+                self._DepexExpressionList[ModuleType] = DepexExpressionList\r
+        return self._DepexExpressionList\r
+\r
+    # Get the tiano core user extension, it is contain dependent library.\r
+    # @retval: a list contain tiano core userextension.\r
+    #\r
+    def _GetTianoCoreUserExtensionList(self):\r
+        TianoCoreUserExtentionList = []\r
+        for M in [self.Module] + self.DependentLibraryList:\r
+            Filename = M.MetaFile.Path\r
+            InfObj = InfSectionParser.InfSectionParser(Filename)\r
+            TianoCoreUserExtenList = InfObj.GetUserExtensionTianoCore()\r
+            for TianoCoreUserExtent in TianoCoreUserExtenList:\r
+                for Section in TianoCoreUserExtent.keys():\r
+                    ItemList = Section.split(TAB_SPLIT)\r
+                    Arch = self.Arch\r
+                    if len(ItemList) == 4:\r
+                        Arch = ItemList[3]\r
+                    if Arch.upper() == TAB_ARCH_COMMON or Arch.upper() == self.Arch.upper():\r
+                        TianoCoreList = []\r
+                        TianoCoreList.extend([TAB_SECTION_START + Section + TAB_SECTION_END])\r
+                        TianoCoreList.extend(TianoCoreUserExtent[Section][:])\r
+                        TianoCoreList.append('\n')\r
+                        TianoCoreUserExtentionList.append(TianoCoreList)\r
+\r
+        return TianoCoreUserExtentionList\r
+\r
+    ## Return the list of specification version required for the module\r
+    #\r
+    #   @retval     list    The list of specification defined in module file\r
+    #\r
+    def _GetSpecification(self):\r
+        return self.Module.Specification\r
+\r
+    ## Tool option for the module build\r
+    #\r
+    #   @param      PlatformInfo    The object of PlatformBuildInfo\r
+    #   @retval     dict            The dict containing valid options\r
+    #\r
+    def _GetModuleBuildOption(self):\r
+        if self._BuildOption == None:\r
+            self._BuildOption, self.BuildRuleOrder = self.PlatformInfo.ApplyBuildOption(self.Module)\r
+            if self.BuildRuleOrder:\r
+                self.BuildRuleOrder = ['.%s' % Ext for Ext in self.BuildRuleOrder.split()]\r
+        return self._BuildOption\r
+\r
+    ## Get include path list from tool option for the module build\r
+    #\r
+    #   @retval     list            The include path list\r
+    #\r
+    def _GetBuildOptionIncPathList(self):\r
+        if self._BuildOptionIncPathList == None:\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
+            if self.PlatformInfo.ToolChainFamily in ('MSFT'):\r
+                gBuildOptIncludePattern = re.compile(r"(?:.*?)/I[ \t]*([^ ]*)", re.MULTILINE | re.DOTALL)\r
+            elif self.PlatformInfo.ToolChainFamily in ('INTEL', 'GCC', 'RVCT'):\r
+                gBuildOptIncludePattern = re.compile(r"(?:.*?)-I[ \t]*([^ ]*)", re.MULTILINE | re.DOTALL)\r
+            else:\r
+                #\r
+                # New ToolChainFamily, don't known whether there is option to specify include directories\r
+                #\r
+                self._BuildOptionIncPathList = []\r
+                return self._BuildOptionIncPathList\r
+            \r
+            BuildOptionIncPathList = []\r
+            for Tool in ('CC', 'PP', 'VFRPP', 'ASLPP', 'ASLCC', 'APP', 'ASM'):\r
+                Attr = 'FLAGS'\r
+                try:\r
+                    FlagOption = self.BuildOption[Tool][Attr]\r
+                except KeyError:\r
+                    FlagOption = ''\r
+                \r
+                if self.PlatformInfo.ToolChainFamily != 'RVCT':\r
+                    IncPathList = [NormPath(Path, self.Macros) for Path in gBuildOptIncludePattern.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
+                        PathList = GetSplitList(Path, TAB_COMMA_SPLIT)\r
+                        IncPathList += [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
+                # within the module's directory tree. Report error if violation.\r
+                #\r
+                if self.AutoGenVersion >= 0x00010005 and len(IncPathList) > 0:\r
+                    for Path in IncPathList:\r
+                        if (Path not in self.IncludePathList) and (CommonPath([Path, self.MetaFile.Dir]) != self.MetaFile.Dir):\r
+                            ErrMsg = "The include directory for the EDK II module in this line is invalid %s specified in %s FLAGS '%s'" % (Path, Tool, FlagOption)\r
+                            EdkLogger.error("build",\r
+                                            PARAMETER_INVALID,\r
+                                            ExtraData=ErrMsg,\r
+                                            File=str(self.MetaFile))\r
+\r
+                \r
+                BuildOptionIncPathList += IncPathList\r
+            \r
+            self._BuildOptionIncPathList = BuildOptionIncPathList\r
+        \r
+        return self._BuildOptionIncPathList\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
+    #  $(CONF_DIRECTORY)/build_rule.txt and toolchain family.\r
+    #\r
+    def _GetSourceFileList(self):\r
+        if self._SourceFileList == None:\r
+            self._SourceFileList = []\r
+            for F in self.Module.Sources:\r
+                # match tool chain\r
+                if F.TagName not in ("", "*", self.ToolChain):\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
+                    EdkLogger.debug(\r
+                                EdkLogger.DEBUG_0,\r
+                                "The file [%s] must be built by tools of [%s], " \\r
+                                "but current toolchain family is [%s], buildrule family is [%s]" \\r
+                                    % (str(F), F.ToolChainFamily, self.ToolChainFamily, self.BuildRuleFamily))\r
+                    continue\r
+\r
+                # add the file path into search path list for file including\r
+                if F.Dir not in self.IncludePathList and self.AutoGenVersion >= 0x00010005:\r
+                    self.IncludePathList.insert(0, F.Dir)\r
+                self._SourceFileList.append(F)\r
+\r
+            self._MatchBuildRuleOrder(self._SourceFileList)\r
+\r
+            for F in self._SourceFileList:\r
+                self._ApplyBuildRule(F, TAB_UNKNOWN_FILE)\r
+        return self._SourceFileList\r
+\r
+    def _MatchBuildRuleOrder(self, FileList):\r
+        Order_Dict = {}\r
+        self._GetModuleBuildOption()\r
+        for SingleFile in FileList:\r
+            if self.BuildRuleOrder and SingleFile.Ext in self.BuildRuleOrder and SingleFile.Ext in self.BuildRules:\r
+                key = SingleFile.Path.split(SingleFile.Ext)[0]\r
+                if key in Order_Dict:\r
+                    Order_Dict[key].append(SingleFile.Ext)\r
+                else:\r
+                    Order_Dict[key] = [SingleFile.Ext]\r
+\r
+        RemoveList = []\r
+        for F in Order_Dict:\r
+            if len(Order_Dict[F]) > 1:\r
+                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
+        for item in RemoveList:\r
+            FileList.remove(item)\r
+\r
+        return FileList\r
+\r
+    ## Return the list of unicode files\r
+    def _GetUnicodeFileList(self):\r
+        if self._UnicodeFileList == None:\r
+            if TAB_UNICODE_FILE in self.FileTypes:\r
+                self._UnicodeFileList = self.FileTypes[TAB_UNICODE_FILE]\r
+            else:\r
+                self._UnicodeFileList = []\r
+        return self._UnicodeFileList\r
+\r
+    ## Return the list of vfr files\r
+    def _GetVfrFileList(self):\r
+        if self._VfrFileList == None:\r
+            if TAB_VFR_FILE in self.FileTypes:\r
+                self._VfrFileList = self.FileTypes[TAB_VFR_FILE]\r
+            else:\r
+                self._VfrFileList = []\r
+        return self._VfrFileList\r
+\r
+    ## Return the list of Image Definition files\r
+    def _GetIdfFileList(self):\r
+        if self._IdfFileList == None:\r
+            if TAB_IMAGE_FILE in self.FileTypes:\r
+                self._IdfFileList = self.FileTypes[TAB_IMAGE_FILE]\r
+            else:\r
+                self._IdfFileList = []\r
+        return self._IdfFileList\r
+\r
+    ## Return a list of files which can be built from binary\r
+    #\r
+    #  "Build" binary files are just to copy them to build directory.\r
+    #\r
+    #   @retval     list            The list of files which can be built later\r
+    #\r
+    def _GetBinaryFiles(self):\r
+        if self._BinaryFileList == None:\r
+            self._BinaryFileList = []\r
+            for F in self.Module.Binaries:\r
+                if F.Target not in ['COMMON', '*'] and F.Target != self.BuildTarget:\r
+                    continue\r
+                self._BinaryFileList.append(F)\r
+                self._ApplyBuildRule(F, F.Type)\r
+        return self._BinaryFileList\r
+\r
+    def _GetBuildRules(self):\r
+        if self._BuildRules == None:\r
+            BuildRules = {}\r
+            BuildRuleDatabase = self.PlatformInfo.BuildRule\r
+            for Type in BuildRuleDatabase.FileTypeList:\r
+                #first try getting build rule by BuildRuleFamily\r
+                RuleObject = BuildRuleDatabase[Type, self.BuildType, self.Arch, self.BuildRuleFamily]\r
+                if not RuleObject:\r
+                    # build type is always module type, but ...\r
+                    if self.ModuleType != self.BuildType:\r
+                        RuleObject = BuildRuleDatabase[Type, self.ModuleType, self.Arch, self.BuildRuleFamily]\r
+                #second try getting build rule by ToolChainFamily\r
+                if not RuleObject:\r
+                    RuleObject = BuildRuleDatabase[Type, self.BuildType, self.Arch, self.ToolChainFamily]\r
+                    if not RuleObject:\r
+                        # build type is always module type, but ...\r
+                        if self.ModuleType != self.BuildType:\r
+                            RuleObject = BuildRuleDatabase[Type, self.ModuleType, self.Arch, self.ToolChainFamily]\r
+                if not RuleObject:\r
+                    continue\r
+                RuleObject = RuleObject.Instantiate(self.Macros)\r
+                BuildRules[Type] = RuleObject\r
+                for Ext in RuleObject.SourceFileExtList:\r
+                    BuildRules[Ext] = RuleObject\r
+            self._BuildRules = BuildRules\r
+        return self._BuildRules\r
+\r
+    def _ApplyBuildRule(self, File, FileType):\r
+        if self._BuildTargets == None:\r
+            self._IntroBuildTargetList = set()\r
+            self._FinalBuildTargetList = set()\r
+            self._BuildTargets = {}\r
+            self._FileTypes = {}\r
+\r
+        SubDirectory = os.path.join(self.OutputDir, File.SubDir)\r
+        if not os.path.exists(SubDirectory):\r
+            CreateDirectory(SubDirectory)\r
+        LastTarget = None\r
+        RuleChain = []\r
+        SourceList = [File]\r
+        Index = 0\r
+        #\r
+        # Make sure to get build rule order value\r
+        #\r
+        self._GetModuleBuildOption()\r
+\r
+        while Index < len(SourceList):\r
+            Source = SourceList[Index]\r
+            Index = Index + 1\r
+\r
+            if Source != File:\r
+                CreateDirectory(Source.Dir)\r
+\r
+            if File.IsBinary and File == Source and self._BinaryFileList != None and File in self._BinaryFileList:\r
+                # Skip all files that are not binary libraries\r
+                if not self.IsLibrary:\r
+                    continue\r
+                RuleObject = self.BuildRules[TAB_DEFAULT_BINARY_FILE]\r
+            elif FileType in self.BuildRules:\r
+                RuleObject = self.BuildRules[FileType]\r
+            elif Source.Ext in self.BuildRules:\r
+                RuleObject = self.BuildRules[Source.Ext]\r
+            else:\r
+                # stop at no more rules\r
+                if LastTarget:\r
+                    self._FinalBuildTargetList.add(LastTarget)\r
+                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
+            if self.IsLibrary and FileType == TAB_STATIC_LIBRARY:\r
+                if LastTarget:\r
+                    self._FinalBuildTargetList.add(LastTarget)\r
+                break\r
+\r
+            Target = RuleObject.Apply(Source, self.BuildRuleOrder)\r
+            if not Target:\r
+                if LastTarget:\r
+                    self._FinalBuildTargetList.add(LastTarget)\r
+                break\r
+            elif not Target.Outputs:\r
+                # 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
+                self._IntroBuildTargetList.add(Target)\r
+\r
+            # to avoid cyclic rule\r
+            if FileType in RuleChain:\r
+                break\r
+\r
+            RuleChain.append(FileType)\r
+            SourceList.extend(Target.Outputs)\r
+            LastTarget = Target\r
+            FileType = TAB_UNKNOWN_FILE\r
+\r
+    def _GetTargets(self):\r
+        if self._BuildTargets == None:\r
+            self._IntroBuildTargetList = set()\r
+            self._FinalBuildTargetList = set()\r
+            self._BuildTargets = {}\r
+            self._FileTypes = {}\r
+\r
+        #TRICK: call _GetSourceFileList to apply build rule for source files\r
+        if self.SourceFileList:\r
+            pass\r
+\r
+        #TRICK: call _GetBinaryFileList to apply build rule for binary files\r
+        if self.BinaryFileList:\r
+            pass\r
+\r
+        return self._BuildTargets\r
+\r
+    def _GetIntroTargetList(self):\r
+        self._GetTargets()\r
+        return self._IntroBuildTargetList\r
+\r
+    def _GetFinalTargetList(self):\r
+        self._GetTargets()\r
+        return self._FinalBuildTargetList\r
+\r
+    def _GetFileTypes(self):\r
+        self._GetTargets()\r
+        return self._FileTypes\r
+\r
+    ## Get the list of package object the module depends on\r
+    #\r
+    #   @retval     list    The package object list\r
+    #\r
+    def _GetDependentPackageList(self):\r
+        return self.Module.Packages\r
+\r
+    ## Return the list of auto-generated code file\r
+    #\r
+    #   @retval     list        The list of auto-generated file\r
+    #\r
+    def _GetAutoGenFileList(self):\r
+        UniStringAutoGenC = True\r
+        IdfStringAutoGenC = True\r
+        UniStringBinBuffer = StringIO()\r
+        IdfGenBinBuffer = StringIO()\r
+        if self.BuildType == 'UEFI_HII':\r
+            UniStringAutoGenC = False\r
+            IdfStringAutoGenC = False\r
+        if self._AutoGenFileList == None:\r
+            self._AutoGenFileList = {}\r
+            AutoGenC = TemplateString()\r
+            AutoGenH = TemplateString()\r
+            StringH = TemplateString()\r
+            StringIdf = TemplateString()\r
+            GenC.CreateCode(self, AutoGenC, AutoGenH, StringH, UniStringAutoGenC, UniStringBinBuffer, StringIdf, IdfStringAutoGenC, IdfGenBinBuffer)\r
+            #\r
+            # AutoGen.c is generated if there are library classes in inf, or there are object files\r
+            #\r
+            if str(AutoGenC) != "" and (len(self.Module.LibraryClasses) > 0\r
+                                        or TAB_OBJECT_FILE in self.FileTypes):\r
+                AutoFile = PathClass(gAutoGenCodeFileName, self.DebugDir)\r
+                self._AutoGenFileList[AutoFile] = str(AutoGenC)\r
+                self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)\r
+            if str(AutoGenH) != "":\r
+                AutoFile = PathClass(gAutoGenHeaderFileName, self.DebugDir)\r
+                self._AutoGenFileList[AutoFile] = str(AutoGenH)\r
+                self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)\r
+            if str(StringH) != "":\r
+                AutoFile = PathClass(gAutoGenStringFileName % {"module_name":self.Name}, self.DebugDir)\r
+                self._AutoGenFileList[AutoFile] = str(StringH)\r
+                self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)\r
+            if UniStringBinBuffer != None and UniStringBinBuffer.getvalue() != "":\r
+                AutoFile = PathClass(gAutoGenStringFormFileName % {"module_name":self.Name}, self.OutputDir)\r
+                self._AutoGenFileList[AutoFile] = UniStringBinBuffer.getvalue()\r
+                AutoFile.IsBinary = True\r
+                self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)\r
+            if UniStringBinBuffer != None:\r
+                UniStringBinBuffer.close()\r
+            if str(StringIdf) != "":\r
+                AutoFile = PathClass(gAutoGenImageDefFileName % {"module_name":self.Name}, self.DebugDir)\r
+                self._AutoGenFileList[AutoFile] = str(StringIdf)\r
+                self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)\r
+            if IdfGenBinBuffer != None and IdfGenBinBuffer.getvalue() != "":\r
+                AutoFile = PathClass(gAutoGenIdfFileName % {"module_name":self.Name}, self.OutputDir)\r
+                self._AutoGenFileList[AutoFile] = IdfGenBinBuffer.getvalue()\r
+                AutoFile.IsBinary = True\r
+                self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)\r
+            if IdfGenBinBuffer != None:\r
+                IdfGenBinBuffer.close()\r
+        return self._AutoGenFileList\r
+\r
+    ## Return the list of library modules explicitly or implicityly used by this module\r
+    def _GetLibraryList(self):\r
+        if self._DependentLibraryList == None:\r
+            # only merge library classes and PCD for non-library module\r
+            if self.IsLibrary:\r
+                self._DependentLibraryList = []\r
+            else:\r
+                if self.AutoGenVersion < 0x00010005:\r
+                    self._DependentLibraryList = self.PlatformInfo.ResolveLibraryReference(self.Module)\r
+                else:\r
+                    self._DependentLibraryList = self.PlatformInfo.ApplyLibraryInstance(self.Module)\r
+        return self._DependentLibraryList\r
+\r
+    @staticmethod\r
+    def UpdateComments(Recver, Src):\r
+        for Key in Src:\r
+            if Key not in Recver:\r
+                Recver[Key] = []\r
+            Recver[Key].extend(Src[Key])\r
+    ## Get the list of PCDs from current module\r
+    #\r
+    #   @retval     list                    The list of PCD\r
+    #\r
+    def _GetModulePcdList(self):\r
+        if self._ModulePcdList == None:\r
+            # apply PCD settings from platform\r
+            self._ModulePcdList = self.PlatformInfo.ApplyPcdSetting(self.Module, self.Module.Pcds)\r
+            self.UpdateComments(self._PcdComments, self.Module.PcdComments)\r
+        return self._ModulePcdList\r
+\r
+    ## Get the list of PCDs from dependent libraries\r
+    #\r
+    #   @retval     list                    The list of PCD\r
+    #\r
+    def _GetLibraryPcdList(self):\r
+        if self._LibraryPcdList == None:\r
+            Pcds = sdict()\r
+            if not self.IsLibrary:\r
+                # get PCDs from dependent libraries\r
+                for Library in self.DependentLibraryList:\r
+                    self.UpdateComments(self._PcdComments, Library.PcdComments)\r
+                    for Key in Library.Pcds:\r
+                        # skip duplicated PCDs\r
+                        if Key in self.Module.Pcds or Key in Pcds:\r
+                            continue\r
+                        Pcds[Key] = copy.copy(Library.Pcds[Key])\r
+                # apply PCD settings from platform\r
+                self._LibraryPcdList = self.PlatformInfo.ApplyPcdSetting(self.Module, Pcds)\r
+            else:\r
+                self._LibraryPcdList = []\r
+        return self._LibraryPcdList\r
+\r
+    ## Get the GUID value mapping\r
+    #\r
+    #   @retval     dict    The mapping between GUID cname and its value\r
+    #\r
+    def _GetGuidList(self):\r
+        if self._GuidList == None:\r
+            self._GuidList = sdict()\r
+            self._GuidList.update(self.Module.Guids)\r
+            for Library in self.DependentLibraryList:\r
+                self._GuidList.update(Library.Guids)\r
+                self.UpdateComments(self._GuidComments, Library.GuidComments)\r
+            self.UpdateComments(self._GuidComments, self.Module.GuidComments)\r
+        return self._GuidList\r
+\r
+    def GetGuidsUsedByPcd(self):\r
+        if self._GuidsUsedByPcd == None:\r
+            self._GuidsUsedByPcd = sdict()\r
+            self._GuidsUsedByPcd.update(self.Module.GetGuidsUsedByPcd())\r
+            for Library in self.DependentLibraryList:\r
+                self._GuidsUsedByPcd.update(Library.GetGuidsUsedByPcd())\r
+        return self._GuidsUsedByPcd\r
+    ## Get the protocol value mapping\r
+    #\r
+    #   @retval     dict    The mapping between protocol cname and its value\r
+    #\r
+    def _GetProtocolList(self):\r
+        if self._ProtocolList == None:\r
+            self._ProtocolList = sdict()\r
+            self._ProtocolList.update(self.Module.Protocols)\r
+            for Library in self.DependentLibraryList:\r
+                self._ProtocolList.update(Library.Protocols)\r
+                self.UpdateComments(self._ProtocolComments, Library.ProtocolComments)\r
+            self.UpdateComments(self._ProtocolComments, self.Module.ProtocolComments)\r
+        return self._ProtocolList\r
+\r
+    ## Get the PPI value mapping\r
+    #\r
+    #   @retval     dict    The mapping between PPI cname and its value\r
+    #\r
+    def _GetPpiList(self):\r
+        if self._PpiList == None:\r
+            self._PpiList = sdict()\r
+            self._PpiList.update(self.Module.Ppis)\r
+            for Library in self.DependentLibraryList:\r
+                self._PpiList.update(Library.Ppis)\r
+                self.UpdateComments(self._PpiComments, Library.PpiComments)\r
+            self.UpdateComments(self._PpiComments, self.Module.PpiComments)\r
+        return self._PpiList\r
+\r
+    ## Get the list of include search path\r
+    #\r
+    #   @retval     list                    The list path\r
+    #\r
+    def _GetIncludePathList(self):\r
+        if self._IncludePathList == None:\r
+            self._IncludePathList = []\r
+            if self.AutoGenVersion < 0x00010005:\r
+                for Inc in self.Module.Includes:\r
+                    if Inc not in self._IncludePathList:\r
+                        self._IncludePathList.append(Inc)\r
+                    # for Edk modules\r
+                    Inc = path.join(Inc, self.Arch.capitalize())\r
+                    if os.path.exists(Inc) and Inc not in self._IncludePathList:\r
+                        self._IncludePathList.append(Inc)\r
+                # Edk module needs to put DEBUG_DIR at the end of search path and not to use SOURCE_DIR all the time\r
+                self._IncludePathList.append(self.DebugDir)\r
+            else:\r
+                self._IncludePathList.append(self.MetaFile.Dir)\r
+                self._IncludePathList.append(self.DebugDir)\r
+\r
+            for Package in self.Module.Packages:\r
+                PackageDir = mws.join(self.WorkspaceDir, Package.MetaFile.Dir)\r
+                if PackageDir not in self._IncludePathList:\r
+                    self._IncludePathList.append(PackageDir)\r
+                IncludesList = Package.Includes\r
+                if Package._PrivateIncludes:\r
+                    if not self.MetaFile.Path.startswith(PackageDir):\r
+                        IncludesList = list(set(Package.Includes).difference(set(Package._PrivateIncludes)))\r
+                for Inc in IncludesList:\r
+                    if Inc not in self._IncludePathList:\r
+                        self._IncludePathList.append(str(Inc))\r
+        return self._IncludePathList\r
+\r
+    def _GetIncludePathLength(self):\r
+        self._IncludePathLength = 0\r
+        if self._IncludePathList:\r
+            for inc in self._IncludePathList:\r
+                self._IncludePathLength += len(' ' + inc)\r
+        return self._IncludePathLength\r
+\r
+    ## Get HII EX PCDs which maybe used by VFR\r
+    #\r
+    #  efivarstore used by VFR may relate with HII EX PCDs\r
+    #  Get the variable name and GUID from efivarstore and HII EX PCD\r
+    #  List the HII EX PCDs in As Built INF if both name and GUID match.\r
+    #\r
+    #  @retval    list    HII EX PCDs\r
+    #\r
+    def _GetPcdsMaybeUsedByVfr(self):\r
+        if not self.SourceFileList:\r
+            return []\r
+\r
+        NameGuids = []\r
+        for SrcFile in self.SourceFileList:\r
+            if SrcFile.Ext.lower() != '.vfr':\r
+                continue\r
+            Vfri = os.path.join(self.OutputDir, SrcFile.BaseName + '.i')\r
+            if not os.path.exists(Vfri):\r
+                continue\r
+            VfriFile = open(Vfri, 'r')\r
+            Content = VfriFile.read()\r
+            VfriFile.close()\r
+            Pos = Content.find('efivarstore')\r
+            while Pos != -1:\r
+                #\r
+                # Make sure 'efivarstore' is the start of efivarstore statement\r
+                # In case of the value of 'name' (name = efivarstore) is equal to 'efivarstore'\r
+                #\r
+                Index = Pos - 1\r
+                while Index >= 0 and Content[Index] in ' \t\r\n':\r
+                    Index -= 1\r
+                if Index >= 0 and Content[Index] != ';':\r
+                    Pos = Content.find('efivarstore', Pos + len('efivarstore'))\r
+                    continue\r
+                #\r
+                # 'efivarstore' must be followed by name and guid\r
+                #\r
+                Name = gEfiVarStoreNamePattern.search(Content, Pos)\r
+                if not Name:\r
+                    break\r
+                Guid = gEfiVarStoreGuidPattern.search(Content, Pos)\r
+                if not Guid:\r
+                    break\r
+                NameArray = ConvertStringToByteArray('L"' + Name.group(1) + '"')\r
+                NameGuids.append((NameArray, GuidStructureStringToGuidString(Guid.group(1))))\r
+                Pos = Content.find('efivarstore', Name.end())\r
+        if not NameGuids:\r
+            return []\r
+        HiiExPcds = []\r
+        for Pcd in self.PlatformInfo.Platform.Pcds.values():\r
+            if Pcd.Type != TAB_PCDS_DYNAMIC_EX_HII:\r
+                continue\r
+            for SkuName in Pcd.SkuInfoList:\r
+                SkuInfo = Pcd.SkuInfoList[SkuName]\r
+                Name = ConvertStringToByteArray(SkuInfo.VariableName)\r
+                Value = GuidValue(SkuInfo.VariableGuid, self.PlatformInfo.PackageList, self.MetaFile.Path)\r
+                if not Value:\r
+                    continue\r
+                Guid = GuidStructureStringToGuidString(Value)\r
+                if (Name, Guid) in NameGuids and Pcd not in HiiExPcds:\r
+                    HiiExPcds.append(Pcd)\r
+                    break\r
+\r
+        return HiiExPcds\r
+\r
+    def _GenOffsetBin(self):\r
+        VfrUniBaseName = {}\r
+        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
+                #\r
+                VfrUniBaseName[SourceFile.BaseName] = (SourceFile.BaseName + "Bin")\r
+            if SourceFile.Type.upper() == ".UNI" :\r
+                #\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
+        if len(VfrUniBaseName) == 0:\r
+            return None\r
+        MapFileName = os.path.join(self.OutputDir, self.Name + ".map")\r
+        EfiFileName = os.path.join(self.OutputDir, self.Name + ".efi")\r
+        VfrUniOffsetList = GetVariableOffset(MapFileName, EfiFileName, VfrUniBaseName.values())\r
+        if not VfrUniOffsetList:\r
+            return None\r
+\r
+        OutputName = '%sOffset.bin' % self.Name\r
+        UniVfrOffsetFileName    =  os.path.join( self.OutputDir, OutputName)\r
+\r
+        try:\r
+            fInputfile = open(UniVfrOffsetFileName, "wb+", 0)\r
+        except:\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
+\r
+        for Item in VfrUniOffsetList:\r
+            if (Item[0].find("Strings") != -1):\r
+                #\r
+                # UNI offset in image.\r
+                # GUID + Offset\r
+                # { 0x8913c5e0, 0x33f6, 0x4d86, { 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66 } }\r
+                #\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
+                UniValue = pack ('Q', int (Item[1], 16))\r
+                fStringIO.write (UniValue)\r
+            else:\r
+                #\r
+                # VFR binary offset in image.\r
+                # GUID + Offset\r
+                # { 0xd0bc7cb4, 0x6a47, 0x495f, { 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2 } };\r
+                #\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
+                type (Item[1]) \r
+                VfrValue = pack ('Q', int (Item[1], 16))\r
+                fStringIO.write (VfrValue)\r
+        #\r
+        # write data into file.\r
+        #\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
+\r
+        fStringIO.close ()\r
+        fInputfile.close ()\r
+        return OutputName\r
+\r
+    ## Create AsBuilt INF file the module\r
+    #\r
+    def CreateAsBuiltInf(self, IsOnlyCopy = False):\r
+        self.OutputFile = []\r
+        if IsOnlyCopy:\r
+            if GlobalData.gBinCacheDest:\r
+                self.CopyModuleToCache()\r
+                return\r
+\r
+        if self.IsAsBuiltInfCreated:\r
+            return\r
+            \r
+        # Skip the following code for EDK I inf\r
+        if self.AutoGenVersion < 0x00010005:\r
+            return\r
+            \r
+        # Skip the following code for libraries\r
+        if self.IsLibrary:\r
+            return\r
+            \r
+        # Skip the following code for modules with no source files\r
+        if self.SourceFileList == None or 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
+            return\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
+        # Also find all packages that the DynamicEx PCDs depend on\r
+        Pcds = []\r
+        PatchablePcds = []\r
+        Packages = []\r
+        PcdCheckList = []\r
+        PcdTokenSpaceList = []\r
+        for Pcd in self.ModulePcdList + self.LibraryPcdList:\r
+            if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r
+                PatchablePcds += [Pcd]\r
+                PcdCheckList.append((Pcd.TokenCName, Pcd.TokenSpaceGuidCName, 'PatchableInModule'))\r
+            elif Pcd.Type in GenC.gDynamicExPcd:\r
+                if Pcd not in Pcds:\r
+                    Pcds += [Pcd]\r
+                    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.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
+            # The GUIDs in GUIDs section should really be the GUIDs in source INF or referred by Ex an patch PCDs\r
+            if TokenSpace not in PcdTokenSpaceList and TokenSpace in GuidList:\r
+                GuidList.pop(TokenSpace)\r
+        CheckList = (GuidList, self.PpiList, self.ProtocolList, PcdCheckList)\r
+        for Package in self.DerivedPackageList:\r
+            if Package in Packages:\r
+                continue\r
+            BeChecked = (Package.Guids, Package.Ppis, Package.Protocols, Package.Pcds)\r
+            Found = False\r
+            for Index in range(len(BeChecked)):\r
+                for Item in CheckList[Index]:\r
+                    if Item in BeChecked[Index]:\r
+                        Packages += [Package]\r
+                        Found = True\r
+                        break\r
+                if Found: break\r
+\r
+        VfrPcds = self._GetPcdsMaybeUsedByVfr()\r
+        for Pkg in self.PlatformInfo.PackageList:\r
+            if Pkg in Packages:\r
+                continue\r
+            for VfrPcd in VfrPcds:\r
+                if ((VfrPcd.TokenCName, VfrPcd.TokenSpaceGuidCName, 'DynamicEx') in Pkg.Pcds or\r
+                    (VfrPcd.TokenCName, VfrPcd.TokenSpaceGuidCName, 'Dynamic') in Pkg.Pcds):\r
+                    Packages += [Pkg]\r
+                    break\r
+\r
+        ModuleType = self.ModuleType\r
+        if ModuleType == 'UEFI_DRIVER' and self.DepexGenerated:\r
+            ModuleType = 'DXE_DRIVER'\r
+\r
+        DriverType = ''\r
+        if self.PcdIsDriver != '':\r
+            DriverType = self.PcdIsDriver\r
+\r
+        Guid = self.Guid\r
+        MDefs = self.Module.Defines\r
+\r
+        AsBuiltInfDict = {\r
+          'module_name'                       : self.Name,\r
+          'module_guid'                       : Guid,\r
+          'module_module_type'                : ModuleType,\r
+          'module_version_string'             : [MDefs['VERSION_STRING']] if 'VERSION_STRING' in MDefs else [],\r
+          'pcd_is_driver_string'              : [],\r
+          'module_uefi_specification_version' : [],\r
+          'module_pi_specification_version'   : [],\r
+          'module_entry_point'                : self.Module.ModuleEntryPointList,\r
+          'module_unload_image'               : self.Module.ModuleUnloadImageList,\r
+          'module_constructor'                : self.Module.ConstructorList,\r
+          'module_destructor'                 : self.Module.DestructorList,\r
+          'module_shadow'                     : [MDefs['SHADOW']] if 'SHADOW' in MDefs else [],\r
+          'module_pci_vendor_id'              : [MDefs['PCI_VENDOR_ID']] if 'PCI_VENDOR_ID' in MDefs else [],\r
+          'module_pci_device_id'              : [MDefs['PCI_DEVICE_ID']] if 'PCI_DEVICE_ID' in MDefs else [],\r
+          'module_pci_class_code'             : [MDefs['PCI_CLASS_CODE']] if 'PCI_CLASS_CODE' in MDefs else [],\r
+          'module_pci_revision'               : [MDefs['PCI_REVISION']] if 'PCI_REVISION' in MDefs else [],\r
+          'module_build_number'               : [MDefs['BUILD_NUMBER']] if 'BUILD_NUMBER' in MDefs else [],\r
+          'module_spec'                       : [MDefs['SPEC']] if 'SPEC' in MDefs else [],\r
+          'module_uefi_hii_resource_section'  : [MDefs['UEFI_HII_RESOURCE_SECTION']] if 'UEFI_HII_RESOURCE_SECTION' in MDefs else [],\r
+          'module_uni_file'                   : [MDefs['MODULE_UNI_FILE']] if 'MODULE_UNI_FILE' in MDefs else [],\r
+          'module_arch'                       : self.Arch,\r
+          'package_item'                      : ['%s' % (Package.MetaFile.File.replace('\\', '/')) for Package in Packages],\r
+          'binary_item'                       : [],\r
+          'patchablepcd_item'                 : [],\r
+          'pcd_item'                          : [],\r
+          'protocol_item'                     : [],\r
+          'ppi_item'                          : [],\r
+          'guid_item'                         : [],\r
+          'flags_item'                        : [],\r
+          'libraryclasses_item'               : []\r
+        }\r
+\r
+        if 'MODULE_UNI_FILE' in MDefs:\r
+            UNIFile = os.path.join(self.MetaFile.Dir, MDefs['MODULE_UNI_FILE'])\r
+            if os.path.isfile(UNIFile):\r
+                shutil.copy2(UNIFile, self.OutputDir)\r
+\r
+        if self.AutoGenVersion > int(gInfSpecVersion, 0):\r
+            AsBuiltInfDict['module_inf_version'] = '0x%08x' % self.AutoGenVersion\r
+        else:\r
+            AsBuiltInfDict['module_inf_version'] = gInfSpecVersion\r
+\r
+        if DriverType:\r
+            AsBuiltInfDict['pcd_is_driver_string'] += [DriverType]\r
+\r
+        if 'UEFI_SPECIFICATION_VERSION' in self.Specification:\r
+            AsBuiltInfDict['module_uefi_specification_version'] += [self.Specification['UEFI_SPECIFICATION_VERSION']]\r
+        if 'PI_SPECIFICATION_VERSION' in self.Specification:\r
+            AsBuiltInfDict['module_pi_specification_version'] += [self.Specification['PI_SPECIFICATION_VERSION']]\r
+\r
+        OutputDir = self.OutputDir.replace('\\', '/').strip('/')\r
+        for Item in self.CodaTargetList:\r
+            File = Item.Target.Path.replace('\\', '/').strip('/').replace(OutputDir, '').strip('/')\r
+            if File not in self.OutputFile:\r
+                self.OutputFile.append(File)\r
+            if Item.Target.Ext.lower() == '.aml':\r
+                AsBuiltInfDict['binary_item'] += ['ASL|' + File]\r
+            elif Item.Target.Ext.lower() == '.acpi':\r
+                AsBuiltInfDict['binary_item'] += ['ACPI|' + File]\r
+            elif Item.Target.Ext.lower() == '.efi':\r
+                AsBuiltInfDict['binary_item'] += ['PE32|' + self.Name + '.efi']\r
+            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
+            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
+                AsBuiltInfDict['binary_item'] += ['DXE_DEPEX|' + self.Name + '.depex']\r
+            if self.ModuleType in ['DXE_SMM_DRIVER']:\r
+                AsBuiltInfDict['binary_item'] += ['SMM_DEPEX|' + self.Name + '.depex']\r
+\r
+        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
+\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
+        HeaderComments = self.Module.HeaderComments\r
+        StartPos = 0\r
+        for Index in range(len(HeaderComments)):\r
+            if HeaderComments[Index].find('@BinaryHeader') != -1:\r
+                HeaderComments[Index] = HeaderComments[Index].replace('@BinaryHeader', '@file')\r
+                StartPos = Index\r
+                break\r
+        AsBuiltInfDict['header_comments'] = '\n'.join(HeaderComments[StartPos:]).replace(':#', '://')\r
+        AsBuiltInfDict['tail_comments'] = '\n'.join(self.Module.TailComments)\r
+\r
+        GenList = [\r
+            (self.ProtocolList, self._ProtocolComments, 'protocol_item'),\r
+            (self.PpiList, self._PpiComments, 'ppi_item'),\r
+            (GuidList, self._GuidComments, 'guid_item')\r
+        ]\r
+        for Item in GenList:\r
+            for CName in Item[0]:\r
+                Comments = ''\r
+                if CName in Item[1]:\r
+                    Comments = '\n  '.join(Item[1][CName])\r
+                Entry = CName\r
+                if Comments:\r
+                    Entry = Comments + '\n  ' + CName\r
+                AsBuiltInfDict[Item[2]].append(Entry)\r
+        PatchList = parsePcdInfoFromMapFile(\r
+                            os.path.join(self.OutputDir, self.Name + '.map'),\r
+                            os.path.join(self.OutputDir, self.Name + '.efi')\r
+                        )\r
+        if PatchList:\r
+            for Pcd in PatchablePcds:\r
+                TokenCName = Pcd.TokenCName\r
+                for PcdItem in GlobalData.MixedPcd:\r
+                    if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
+                        TokenCName = PcdItem[0]\r
+                        break\r
+                for PatchPcd in PatchList:\r
+                    if TokenCName == PatchPcd[0]:\r
+                        break\r
+                else:\r
+                    continue\r
+                PcdValue = ''\r
+                if Pcd.DatumType == 'BOOLEAN':\r
+                    BoolValue = Pcd.DefaultValue.upper()\r
+                    if BoolValue == 'TRUE':\r
+                        Pcd.DefaultValue = '1'\r
+                    elif BoolValue == 'FALSE':\r
+                        Pcd.DefaultValue = '0'\r
+\r
+                if Pcd.DatumType in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']:\r
+                    HexFormat = '0x%02x'\r
+                    if Pcd.DatumType == 'UINT16':\r
+                        HexFormat = '0x%04x'\r
+                    elif Pcd.DatumType == 'UINT32':\r
+                        HexFormat = '0x%08x'\r
+                    elif Pcd.DatumType == 'UINT64':\r
+                        HexFormat = '0x%016x'\r
+                    PcdValue = HexFormat % int(Pcd.DefaultValue, 0)\r
+                else:\r
+                    if Pcd.MaxDatumSize == None or Pcd.MaxDatumSize == '':\r
+                        EdkLogger.error("build", AUTOGEN_ERROR,\r
+                                        "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd.TokenSpaceGuidCName, TokenCName)\r
+                                        )\r
+                    ArraySize = int(Pcd.MaxDatumSize, 0)\r
+                    PcdValue = Pcd.DefaultValue\r
+                    if PcdValue[0] != '{':\r
+                        Unicode = False\r
+                        if PcdValue[0] == 'L':\r
+                            Unicode = True\r
+                        PcdValue = PcdValue.lstrip('L')\r
+                        PcdValue = eval(PcdValue)\r
+                        NewValue = '{'\r
+                        for Index in range(0, len(PcdValue)):\r
+                            if Unicode:\r
+                                CharVal = ord(PcdValue[Index])\r
+                                NewValue = NewValue + '0x%02x' % (CharVal & 0x00FF) + ', ' \\r
+                                        + '0x%02x' % (CharVal >> 8) + ', '\r
+                            else:\r
+                                NewValue = NewValue + '0x%02x' % (ord(PcdValue[Index]) % 0x100) + ', '\r
+                        Padding = '0x00, '\r
+                        if Unicode:\r
+                            Padding = Padding * 2\r
+                            ArraySize = ArraySize / 2\r
+                        if ArraySize < (len(PcdValue) + 1):\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
+                        if ArraySize > len(PcdValue) + 1:\r
+                            NewValue = NewValue + Padding * (ArraySize - len(PcdValue) - 1)\r
+                        PcdValue = NewValue + Padding.strip().rstrip(',') + '}'\r
+                    elif len(PcdValue.split(',')) <= ArraySize:\r
+                        PcdValue = PcdValue.rstrip('}') + ', 0x00' * (ArraySize - len(PcdValue.split(',')))\r
+                        PcdValue += '}'\r
+                    else:\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
+                PcdItem = '%s.%s|%s|0x%X' % \\r
+                    (Pcd.TokenSpaceGuidCName, TokenCName, PcdValue, PatchPcd[1])\r
+                PcdComments = ''\r
+                if (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) in self._PcdComments:\r
+                    PcdComments = '\n  '.join(self._PcdComments[Pcd.TokenSpaceGuidCName, Pcd.TokenCName])\r
+                if PcdComments:\r
+                    PcdItem = PcdComments + '\n  ' + PcdItem\r
+                AsBuiltInfDict['patchablepcd_item'].append(PcdItem)\r
+\r
+        HiiPcds = []\r
+        for Pcd in Pcds + VfrPcds:\r
+            PcdComments = ''\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
+                    TokenCName = PcdItem[0]\r
+                    break\r
+            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
+                else:\r
+                    HiiPcds.append((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
+                UsageIndex = -1\r
+                UsageStr = ''\r
+                for Index, Comment in enumerate(PcdCommentList):\r
+                    for Usage in UsageList:\r
+                        if Comment.find(Usage) != -1:\r
+                            UsageStr = Usage\r
+                            UsageIndex = Index\r
+                            break\r
+                if UsageIndex != -1:\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
+            PcdEntry = Pcd.TokenSpaceGuidCName + '.' + TokenCName\r
+            if PcdComments:\r
+                PcdEntry = PcdComments + '\n  ' + PcdEntry\r
+            AsBuiltInfDict['pcd_item'] += [PcdEntry]\r
+        for Item in self.BuildOption:\r
+            if 'FLAGS' in self.BuildOption[Item]:\r
+                AsBuiltInfDict['flags_item'] += ['%s:%s_%s_%s_%s_FLAGS = %s' % (self.ToolChainFamily, self.BuildTarget, self.ToolChain, self.Arch, Item, self.BuildOption[Item]['FLAGS'].strip())]\r
+\r
+        # Generated LibraryClasses section in comments.\r
+        for Library in self.LibraryAutoGenList:\r
+            AsBuiltInfDict['libraryclasses_item'] += [Library.MetaFile.File.replace('\\', '/')]\r
+        \r
+        # Generated UserExtensions TianoCore section.\r
+        # All tianocore user extensions are copied.\r
+        UserExtStr = ''\r
+        for TianoCore in self._GetTianoCoreUserExtensionList():\r
+            UserExtStr += '\n'.join(TianoCore)\r
+            ExtensionFile = os.path.join(self.MetaFile.Dir, TianoCore[1])\r
+            if os.path.isfile(ExtensionFile):\r
+                shutil.copy2(ExtensionFile, self.OutputDir)\r
+        AsBuiltInfDict['userextension_tianocore_item'] = UserExtStr\r
+\r
+        # Generated depex expression section in comments.\r
+        AsBuiltInfDict['depexsection_item'] = ''\r
+        DepexExpresion = self._GetDepexExpresionString()\r
+        if DepexExpresion:\r
+            AsBuiltInfDict['depexsection_item'] = DepexExpresion\r
+        \r
+        AsBuiltInf = TemplateString()\r
+        AsBuiltInf.Append(gAsBuiltInfHeaderString.Replace(AsBuiltInfDict))\r
+        \r
+        SaveFileOnChange(os.path.join(self.OutputDir, self.Name + '.inf'), str(AsBuiltInf), False)\r
+        \r
+        self.IsAsBuiltInfCreated = True\r
+        if GlobalData.gBinCacheDest:\r
+            self.CopyModuleToCache()\r
+\r
+    def CopyModuleToCache(self):\r
+        FileDir = path.join(GlobalData.gBinCacheDest, self.Arch, self.SourceDir, self.MetaFile.BaseName)\r
+        CreateDirectory (FileDir)\r
+        HashFile = path.join(self.BuildDir, self.Name + '.hash')\r
+        ModuleFile = path.join(self.OutputDir, self.Name + '.inf')\r
+        if os.path.exists(HashFile):\r
+            shutil.copy2(HashFile, FileDir)\r
+        if os.path.exists(ModuleFile):\r
+            shutil.copy2(ModuleFile, FileDir)\r
+        if not self.OutputFile:\r
+            Ma = self.Workspace.BuildDatabase[PathClass(ModuleFile), self.Arch, self.BuildTarget, self.ToolChain]\r
+            self.OutputFile = Ma.Binaries\r
+        if self.OutputFile:\r
+            for File in self.OutputFile:\r
+                File = str(File)\r
+                if not os.path.isabs(File):\r
+                    File = os.path.join(self.OutputDir, File)\r
+                if os.path.exists(File):\r
+                    shutil.copy2(File, FileDir)\r
+\r
+    def AttemptModuleCacheCopy(self):\r
+        if self.IsBinaryModule:\r
+            return False\r
+        FileDir = path.join(GlobalData.gBinCacheSource, self.Arch, self.SourceDir, self.MetaFile.BaseName)\r
+        HashFile = path.join(FileDir, self.Name + '.hash')\r
+        if os.path.exists(HashFile):\r
+            f = open(HashFile, 'r')\r
+            CacheHash = f.read()\r
+            f.close()\r
+            if GlobalData.gModuleHash[self.Arch][self.Name]:\r
+                if CacheHash == GlobalData.gModuleHash[self.Arch][self.Name]:\r
+                    for root, dir, files in os.walk(FileDir):\r
+                        for f in files:\r
+                            if self.Name + '.hash' in f:\r
+                                shutil.copy2(HashFile, self.BuildDir)\r
+                            else:\r
+                                File = path.join(root, f)\r
+                                shutil.copy2(File, self.OutputDir)\r
+                    if self.Name == "PcdPeim" or self.Name == "PcdDxe":\r
+                        CreatePcdDatabaseCode(self, TemplateString(), TemplateString())\r
+                    return True\r
+        return False\r
+\r
+    ## Create makefile for the module and its dependent libraries\r
+    #\r
+    #   @param      CreateLibraryMakeFile   Flag indicating if or not the makefiles of\r
+    #                                       dependent libraries will be created\r
+    #\r
+    def CreateMakeFile(self, CreateLibraryMakeFile=True, GenFfsList = []):\r
+        # Ignore generating makefile when it is a binary module\r
+        if self.IsBinaryModule:\r
+            return\r
+\r
+        if self.IsMakeFileCreated:\r
+            return\r
+        self.GenFfsList = GenFfsList\r
+        if not self.IsLibrary and CreateLibraryMakeFile:\r
+            for LibraryAutoGen in self.LibraryAutoGenList:\r
+                LibraryAutoGen.CreateMakeFile()\r
+\r
+        if self.CanSkip():\r
+            return\r
+\r
+        if len(self.CustomMakefile) == 0:\r
+            Makefile = GenMake.ModuleMakefile(self)\r
+        else:\r
+            Makefile = GenMake.CustomMakefile(self)\r
+        if Makefile.Generate():\r
+            EdkLogger.debug(EdkLogger.DEBUG_9, "Generated makefile for module %s [%s]" %\r
+                            (self.Name, self.Arch))\r
+        else:\r
+            EdkLogger.debug(EdkLogger.DEBUG_9, "Skipped the generation of makefile for module %s [%s]" %\r
+                            (self.Name, self.Arch))\r
+\r
+        self.CreateTimeStamp(Makefile)\r
+        self.IsMakeFileCreated = True\r
+\r
+    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
+            CopyLongFilePath(SrcPath, DstPath)\r
+    ## Create autogen code for the module and its dependent libraries\r
+    #\r
+    #   @param      CreateLibraryCodeFile   Flag indicating if or not the code of\r
+    #                                       dependent libraries will be created\r
+    #\r
+    def CreateCodeFile(self, CreateLibraryCodeFile=True):\r
+        if self.IsCodeFileCreated:\r
+            return\r
+\r
+        # Need to generate PcdDatabase even PcdDriver is binarymodule\r
+        if self.IsBinaryModule and self.PcdIsDriver != '':\r
+            CreatePcdDatabaseCode(self, TemplateString(), TemplateString())\r
+            return\r
+        if self.IsBinaryModule:\r
+            if self.IsLibrary:\r
+                self.CopyBinaryFiles()\r
+            return\r
+\r
+        if not self.IsLibrary and CreateLibraryCodeFile:\r
+            for LibraryAutoGen in self.LibraryAutoGenList:\r
+                LibraryAutoGen.CreateCodeFile()\r
+\r
+        if self.CanSkip():\r
+            return\r
+\r
+        AutoGenList = []\r
+        IgoredAutoGenList = []\r
+\r
+        for File in self.AutoGenFileList:\r
+            if GenC.Generate(File.Path, self.AutoGenFileList[File], File.IsBinary):\r
+                #Ignore Edk AutoGen.c\r
+                if self.AutoGenVersion < 0x00010005 and File.Name == 'AutoGen.c':\r
+                        continue\r
+\r
+                AutoGenList.append(str(File))\r
+            else:\r
+                IgoredAutoGenList.append(str(File))\r
+\r
+        # Skip the following code for EDK I inf\r
+        if self.AutoGenVersion < 0x00010005:\r
+            return\r
+\r
+        for ModuleType in self.DepexList:\r
+            # Ignore empty [depex] section or [depex] section for "USER_DEFINED" module\r
+            if len(self.DepexList[ModuleType]) == 0 or ModuleType == "USER_DEFINED":\r
+                continue\r
+\r
+            Dpx = GenDepex.DependencyExpression(self.DepexList[ModuleType], ModuleType, True)\r
+            DpxFile = gAutoGenDepexFileName % {"module_name" : self.Name}\r
+\r
+            if len(Dpx.PostfixNotation) <> 0:\r
+                self.DepexGenerated = True\r
+\r
+            if Dpx.Generate(path.join(self.OutputDir, DpxFile)):\r
+                AutoGenList.append(str(DpxFile))\r
+            else:\r
+                IgoredAutoGenList.append(str(DpxFile))\r
+\r
+        if IgoredAutoGenList == []:\r
+            EdkLogger.debug(EdkLogger.DEBUG_9, "Generated [%s] files for module %s [%s]" %\r
+                            (" ".join(AutoGenList), self.Name, self.Arch))\r
+        elif AutoGenList == []:\r
+            EdkLogger.debug(EdkLogger.DEBUG_9, "Skipped the generation of [%s] files for module %s [%s]" %\r
+                            (" ".join(IgoredAutoGenList), self.Name, self.Arch))\r
+        else:\r
+            EdkLogger.debug(EdkLogger.DEBUG_9, "Generated [%s] (skipped %s) files for module %s [%s]" %\r
+                            (" ".join(AutoGenList), " ".join(IgoredAutoGenList), self.Name, self.Arch))\r
+\r
+        self.IsCodeFileCreated = True\r
+        return AutoGenList\r
+\r
+    ## Summarize the ModuleAutoGen objects of all libraries used by this module\r
+    def _GetLibraryAutoGenList(self):\r
+        if self._LibraryAutoGenList == None:\r
+            self._LibraryAutoGenList = []\r
+            for Library in self.DependentLibraryList:\r
+                La = ModuleAutoGen(\r
+                        self.Workspace,\r
+                        Library.MetaFile,\r
+                        self.BuildTarget,\r
+                        self.ToolChain,\r
+                        self.Arch,\r
+                        self.PlatformInfo.MetaFile\r
+                        )\r
+                if La not in self._LibraryAutoGenList:\r
+                    self._LibraryAutoGenList.append(La)\r
+                    for Lib in La.CodaTargetList:\r
+                        self._ApplyBuildRule(Lib.Target, TAB_UNKNOWN_FILE)\r
+        return self._LibraryAutoGenList\r
+\r
+    def GenModuleHash(self):\r
+        if self.Arch not in GlobalData.gModuleHash:\r
+            GlobalData.gModuleHash[self.Arch] = {}\r
+        m = hashlib.md5()\r
+        # Add Platform level hash\r
+        m.update(GlobalData.gPlatformHash)\r
+        # Add Package level hash\r
+        if self.DependentPackageList:\r
+            for Pkg in self.DependentPackageList:\r
+                if Pkg.PackageName in GlobalData.gPackageHash[self.Arch]:\r
+                    m.update(GlobalData.gPackageHash[self.Arch][Pkg.PackageName])\r
+\r
+        # Add Library hash\r
+        if self.LibraryAutoGenList:\r
+            for Lib in self.LibraryAutoGenList:\r
+                if Lib.Name not in GlobalData.gModuleHash[self.Arch]:\r
+                    Lib.GenModuleHash()\r
+                m.update(GlobalData.gModuleHash[self.Arch][Lib.Name])\r
+\r
+        # Add Module self\r
+        f = open(str(self.MetaFile), 'r')\r
+        Content = f.read()\r
+        f.close()\r
+        m.update(Content)\r
+        # Add Module's source files\r
+        if self.SourceFileList:\r
+            for File in self.SourceFileList:\r
+                f = open(str(File), 'r')\r
+                Content = f.read()\r
+                f.close()\r
+                m.update(Content)\r
+\r
+        ModuleHashFile = path.join(self.BuildDir, self.Name + ".hash")\r
+        if self.Name not in GlobalData.gModuleHash[self.Arch]:\r
+            GlobalData.gModuleHash[self.Arch][self.Name] = m.hexdigest()\r
+        if GlobalData.gBinCacheSource:\r
+            CacheValid = self.AttemptModuleCacheCopy()\r
+            if CacheValid:\r
+                return False\r
+        return SaveFileOnChange(ModuleHashFile, m.hexdigest(), True)\r
+\r
+    ## Decide whether we can skip the ModuleAutoGen process\r
+    def CanSkipbyHash(self):\r
+        if GlobalData.gUseHashCache:\r
+            return not self.GenModuleHash()\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 not os.path.exists(self.GetTimeStampPath()):\r
+            return False\r
+        #last creation time of the module\r
+        DstTimeStamp = os.stat(self.GetTimeStampPath())[8]\r
+\r
+        SrcTimeStamp = self.Workspace._SrcTimeStamp\r
+        if SrcTimeStamp > DstTimeStamp:\r
+            return False\r
+\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
+                    return False\r
+                if source not in ModuleAutoGen.TimeDict :\r
+                    ModuleAutoGen.TimeDict[source] = os.stat(source)[8]\r
+                if ModuleAutoGen.TimeDict[source] > DstTimeStamp:\r
+                    return False\r
+        return True\r
+\r
+    def GetTimeStampPath(self):\r
+        if self._TimeStampPath == None:\r
+            self._TimeStampPath = os.path.join(self.MakeFileDir, 'AutoGenTimeStamp')\r
+        return self._TimeStampPath\r
+    def CreateTimeStamp(self, Makefile):\r
+\r
+        FileSet = set()\r
+\r
+        FileSet.add (self.MetaFile.Path)\r
+\r
+        for SourceFile in self.Module.Sources:\r
+            FileSet.add (SourceFile.Path)\r
+\r
+        for Lib in self.DependentLibraryList:\r
+            FileSet.add (Lib.MetaFile.Path)\r
+\r
+        for f in self.AutoGenDepSet:\r
+            FileSet.add (f.Path)\r
+\r
+        if os.path.exists (self.GetTimeStampPath()):\r
+            os.remove (self.GetTimeStampPath())\r
+        with open(self.GetTimeStampPath(), 'w+') as file:\r
+            for f in FileSet:\r
+                print >> file, f\r
+\r
+    Module          = property(_GetModule)\r
+    Name            = property(_GetBaseName)\r
+    Guid            = property(_GetGuid)\r
+    Version         = property(_GetVersion)\r
+    ModuleType      = property(_GetModuleType)\r
+    ComponentType   = property(_GetComponentType)\r
+    BuildType       = property(_GetBuildType)\r
+    PcdIsDriver     = property(_GetPcdIsDriver)\r
+    AutoGenVersion  = property(_GetAutoGenVersion)\r
+    Macros          = property(_GetMacros)\r
+    Specification   = property(_GetSpecification)\r
+\r
+    IsLibrary       = property(_IsLibrary)\r
+    IsBinaryModule  = property(_IsBinaryModule)\r
+    BuildDir        = property(_GetBuildDir)\r
+    OutputDir       = property(_GetOutputDir)\r
+    FfsOutputDir    = property(_GetFfsOutputDir)\r
+    DebugDir        = property(_GetDebugDir)\r
+    MakeFileDir     = property(_GetMakeFileDir)\r
+    CustomMakefile  = property(_GetCustomMakefile)\r
+\r
+    IncludePathList = property(_GetIncludePathList)\r
+    IncludePathLength = property(_GetIncludePathLength)\r
+    AutoGenFileList = property(_GetAutoGenFileList)\r
+    UnicodeFileList = property(_GetUnicodeFileList)\r
+    VfrFileList     = property(_GetVfrFileList)\r
+    SourceFileList  = property(_GetSourceFileList)\r
+    BinaryFileList  = property(_GetBinaryFiles) # FileType : [File List]\r
+    Targets         = property(_GetTargets)\r
+    IntroTargetList = property(_GetIntroTargetList)\r
+    CodaTargetList  = property(_GetFinalTargetList)\r
+    FileTypes       = property(_GetFileTypes)\r
+    BuildRules      = property(_GetBuildRules)\r
+    IdfFileList     = property(_GetIdfFileList)\r
+\r
+    DependentPackageList    = property(_GetDependentPackageList)\r
+    DependentLibraryList    = property(_GetLibraryList)\r
+    LibraryAutoGenList      = property(_GetLibraryAutoGenList)\r
+    DerivedPackageList      = property(_GetDerivedPackageList)\r
+\r
+    ModulePcdList           = property(_GetModulePcdList)\r
+    LibraryPcdList          = property(_GetLibraryPcdList)\r
+    GuidList                = property(_GetGuidList)\r
+    ProtocolList            = property(_GetProtocolList)\r
+    PpiList                 = property(_GetPpiList)\r
+    DepexList               = property(_GetDepexTokenList)\r
+    DxsFile                 = property(_GetDxsFile)\r
+    DepexExpressionList     = property(_GetDepexExpressionTokenList)\r
+    BuildOption             = property(_GetModuleBuildOption)\r
+    BuildOptionIncPathList  = property(_GetBuildOptionIncPathList)\r
+    BuildCommand            = property(_GetBuildCommand)\r
+    \r
+    FixedAtBuildPcds         = property(_GetFixedAtBuildPcds)\r
+\r
+# This acts like the main() function for the script, unless it is 'import'ed into another script.\r
+if __name__ == '__main__':\r
+    pass\r
+\r