]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Workspace/WorkspaceDatabase.py
BaseTools: Add support to merge Prebuild and Postbuild into build Process
[mirror_edk2.git] / BaseTools / Source / Python / Workspace / WorkspaceDatabase.py
index 348d219aa9efd30907bbf6ef9c74a0e238d3049b..b2c4d6e4dafbf7657b2ef202eaebb0b9adbdc3f1 100644 (file)
-## @file
-# This file is used to create a database used by build tool
-#
-# Copyright (c) 2008 - 2009, 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 sqlite3
-import os
-import os.path
-import pickle
-
-import Common.EdkLogger as EdkLogger
-import Common.GlobalData as GlobalData
-
-from Common.String import *
-from Common.DataType import *
-from Common.Misc import *
-from types import *
-
-from CommonDataClass.CommonClass import SkuInfoClass
-
-from MetaDataTable import *
-from MetaFileTable import *
-from MetaFileParser import *
-from BuildClassObject import *
-
-## Platform build information from DSC file
-#
-#  This class is used to retrieve information stored in database and convert them
-# into PlatformBuildClassObject form for easier use for AutoGen.
-#
-class DscBuildData(PlatformBuildClassObject):
-    # dict used to convert PCD type in database to string used by build tool
-    _PCD_TYPE_STRING_ = {
-        MODEL_PCD_FIXED_AT_BUILD        :   "FixedAtBuild",
-        MODEL_PCD_PATCHABLE_IN_MODULE   :   "PatchableInModule",
-        MODEL_PCD_FEATURE_FLAG          :   "FeatureFlag",
-        MODEL_PCD_DYNAMIC               :   "Dynamic",
-        MODEL_PCD_DYNAMIC_DEFAULT       :   "Dynamic",
-        MODEL_PCD_DYNAMIC_HII           :   "DynamicHii",
-        MODEL_PCD_DYNAMIC_VPD           :   "DynamicVpd",
-        MODEL_PCD_DYNAMIC_EX            :   "DynamicEx",
-        MODEL_PCD_DYNAMIC_EX_DEFAULT    :   "DynamicEx",
-        MODEL_PCD_DYNAMIC_EX_HII        :   "DynamicExHii",
-        MODEL_PCD_DYNAMIC_EX_VPD        :   "DynamicExVpd",
-    }
-
-    # dict used to convert part of [Defines] to members of DscBuildData directly
-    _PROPERTY_ = {
-        #
-        # Required Fields
-        #
-        TAB_DSC_DEFINES_PLATFORM_NAME           :   "_PlatformName",
-        TAB_DSC_DEFINES_PLATFORM_GUID           :   "_Guid",
-        TAB_DSC_DEFINES_PLATFORM_VERSION        :   "_Version",
-        TAB_DSC_DEFINES_DSC_SPECIFICATION       :   "_DscSpecification",
-        #TAB_DSC_DEFINES_OUTPUT_DIRECTORY        :   "_OutputDirectory",
-        #TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES :   "_SupArchList",
-        #TAB_DSC_DEFINES_BUILD_TARGETS           :   "_BuildTargets",
-        #TAB_DSC_DEFINES_SKUID_IDENTIFIER        :   "_SkuName",
-        #TAB_DSC_DEFINES_FLASH_DEFINITION        :   "_FlashDefinition",
-        TAB_DSC_DEFINES_BUILD_NUMBER            :   "_BuildNumber",
-        TAB_DSC_DEFINES_MAKEFILE_NAME           :   "_MakefileName",
-        TAB_DSC_DEFINES_BS_BASE_ADDRESS         :   "_BsBaseAddress",
-        TAB_DSC_DEFINES_RT_BASE_ADDRESS         :   "_RtBaseAddress",
-    }
-
-    # used to compose dummy library class name for those forced library instances
-    _NullLibraryNumber = 0
-
-    ## Constructor of DscBuildData
-    #
-    #  Initialize object of DscBuildData
-    #
-    #   @param      FilePath        The path of platform description file
-    #   @param      RawData         The raw data of DSC file
-    #   @param      BuildDataBase   Database used to retrieve module/package information
-    #   @param      Arch            The target architecture
-    #   @param      Platform        (not used for DscBuildData)
-    #   @param      Macros          Macros used for replacement in DSC file
-    #
-    def __init__(self, FilePath, RawData, BuildDataBase, Arch='COMMON', Platform='DUMMY', Macros={}):
-        self.MetaFile = FilePath
-        self._RawData = RawData
-        self._Bdb = BuildDataBase
-        self._Arch = Arch
-        self._Macros = Macros
-        self._Clear()
-        RecordList = self._RawData[MODEL_META_DATA_DEFINE, self._Arch]
-        for Record in RecordList:
-            GlobalData.gEdkGlobal[Record[0]] = Record[1]
-
-    ## XXX[key] = value
-    def __setitem__(self, key, value):
-        self.__dict__[self._PROPERTY_[key]] = value
-
-    ## value = XXX[key]
-    def __getitem__(self, key):
-        return self.__dict__[self._PROPERTY_[key]]
-
-    ## "in" test support
-    def __contains__(self, key):
-        return key in self._PROPERTY_
-
-    ## Set all internal used members of DscBuildData to None
-    def _Clear(self):
-        self._Header            = None
-        self._PlatformName      = None
-        self._Guid              = None
-        self._Version           = None
-        self._DscSpecification  = None
-        self._OutputDirectory   = None
-        self._SupArchList       = None
-        self._BuildTargets      = None
-        self._SkuName           = None
-        self._FlashDefinition   = None
-        self._BuildNumber       = None
-        self._MakefileName      = None
-        self._BsBaseAddress     = None
-        self._RtBaseAddress     = None
-        self._SkuIds            = None
-        self._Modules           = None
-        self._LibraryInstances  = None
-        self._LibraryClasses    = None
-        self._Pcds              = None
-        self._BuildOptions      = None
-
-    ## Get architecture
-    def _GetArch(self):
-        return self._Arch
-
-    ## Set architecture
-    #
-    #   Changing the default ARCH to another may affect all other information
-    # because all information in a platform may be ARCH-related. That's
-    # why we need to clear all internal used members, in order to cause all
-    # information to be re-retrieved.
-    #
-    #   @param  Value   The value of ARCH
-    #
-    def _SetArch(self, Value):
-        if self._Arch == Value:
-            return
-        self._Arch = Value
-        self._Clear()
-
-    ## Retrieve all information in [Defines] section
-    #
-    #   (Retriving all [Defines] information in one-shot is just to save time.)
-    #
-    def _GetHeaderInfo(self):
-        RecordList = self._RawData[MODEL_META_DATA_HEADER, self._Arch]
-        for Record in RecordList:
-            Name = Record[0]
-            # items defined _PROPERTY_ don't need additional processing
-            if Name in self:
-                self[Name] = Record[1]
-            # some special items in [Defines] section need special treatment
-            elif Name == TAB_DSC_DEFINES_OUTPUT_DIRECTORY:
-                self._OutputDirectory = NormPath(Record[1], self._Macros)
-                if ' ' in self._OutputDirectory:
-                    EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "No space is allowed in OUTPUT_DIRECTORY",
-                                    File=self.MetaFile, Line=Record[-1],
-                                    ExtraData=self._OutputDirectory)
-            elif Name == TAB_DSC_DEFINES_FLASH_DEFINITION:
-                self._FlashDefinition = PathClass(NormPath(Record[1], self._Macros), GlobalData.gWorkspace)
-                ErrorCode, ErrorInfo = self._FlashDefinition.Validate('.fdf')
-                if ErrorCode != 0:
-                    EdkLogger.error('build', ErrorCode, File=self.MetaFile, Line=Record[-1],
-                                    ExtraData=ErrorInfo)
-            elif Name == TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES:
-                self._SupArchList = GetSplitValueList(Record[1], TAB_VALUE_SPLIT)
-            elif Name == TAB_DSC_DEFINES_BUILD_TARGETS:
-                self._BuildTargets = GetSplitValueList(Record[1])
-            elif Name == TAB_DSC_DEFINES_SKUID_IDENTIFIER:
-                if self._SkuName == None:
-                    self._SkuName = Record[1]
-        # set _Header to non-None in order to avoid database re-querying
-        self._Header = 'DUMMY'
-
-    ## Retrieve platform name
-    def _GetPlatformName(self):
-        if self._PlatformName == None:
-            if self._Header == None:
-                self._GetHeaderInfo()
-            if self._PlatformName == None:
-                EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No PLATFORM_NAME", File=self.MetaFile)
-        return self._PlatformName
-
-    ## Retrieve file guid
-    def _GetFileGuid(self):
-        if self._Guid == None:
-            if self._Header == None:
-                self._GetHeaderInfo()
-            if self._Guid == None:
-                EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No FILE_GUID", File=self.MetaFile)
-        return self._Guid
-
-    ## Retrieve platform version
-    def _GetVersion(self):
-        if self._Version == None:
-            if self._Header == None:
-                self._GetHeaderInfo()
-            if self._Version == None:
-                self._Version = ''
-        return self._Version
-
-    ## Retrieve platform description file version
-    def _GetDscSpec(self):
-        if self._DscSpecification == None:
-            if self._Header == None:
-                self._GetHeaderInfo()
-            if self._DscSpecification == None:
-                self._DscSpecification = ''
-        return self._DscSpecification
-
-    ## Retrieve OUTPUT_DIRECTORY
-    def _GetOutpuDir(self):
-        if self._OutputDirectory == None:
-            if self._Header == None:
-                self._GetHeaderInfo()
-            if self._OutputDirectory == None:
-                self._OutputDirectory = os.path.join("Build", self._PlatformName)
-        return self._OutputDirectory
-
-    ## Retrieve SUPPORTED_ARCHITECTURES
-    def _GetSupArch(self):
-        if self._SupArchList == None:
-            if self._Header == None:
-                self._GetHeaderInfo()
-            if self._SupArchList == None:
-                self._SupArchList = ARCH_LIST
-        return self._SupArchList
-
-    ## Retrieve BUILD_TARGETS
-    def _GetBuildTarget(self):
-        if self._BuildTargets == None:
-            if self._Header == None:
-                self._GetHeaderInfo()
-            if self._BuildTargets == None:
-                self._BuildTargets = ['DEBUG', 'RELEASE']
-        return self._BuildTargets
-
-    ## Retrieve SKUID_IDENTIFIER
-    def _GetSkuName(self):
-        if self._SkuName == None:
-            if self._Header == None:
-                self._GetHeaderInfo()
-            if self._SkuName == None or self._SkuName not in self.SkuIds:
-                self._SkuName = 'DEFAULT'
-        return self._SkuName
-
-    ## Override SKUID_IDENTIFIER
-    def _SetSkuName(self, Value):
-        if Value in self.SkuIds:
-            self._SkuName = Value
-
-    def _GetFdfFile(self):
-        if self._FlashDefinition == None:
-            if self._Header == None:
-                self._GetHeaderInfo()
-            if self._FlashDefinition == None:
-                self._FlashDefinition = ''
-        return self._FlashDefinition
-
-    ## Retrieve FLASH_DEFINITION
-    def _GetBuildNumber(self):
-        if self._BuildNumber == None:
-            if self._Header == None:
-                self._GetHeaderInfo()
-            if self._BuildNumber == None:
-                self._BuildNumber = ''
-        return self._BuildNumber
-
-    ## Retrieve MAKEFILE_NAME
-    def _GetMakefileName(self):
-        if self._MakefileName == None:
-            if self._Header == None:
-                self._GetHeaderInfo()
-            if self._MakefileName == None:
-                self._MakefileName = ''
-        return self._MakefileName
-
-    ## Retrieve BsBaseAddress
-    def _GetBsBaseAddress(self):
-        if self._BsBaseAddress == None:
-            if self._Header == None:
-                self._GetHeaderInfo()
-            if self._BsBaseAddress == None:
-                self._BsBaseAddress = ''
-        return self._BsBaseAddress
-
-    ## Retrieve RtBaseAddress
-    def _GetRtBaseAddress(self):
-        if self._RtBaseAddress == None:
-            if self._Header == None:
-                self._GetHeaderInfo()
-            if self._RtBaseAddress == None:
-                self._RtBaseAddress = ''
-        return self._RtBaseAddress
-
-    ## Retrieve [SkuIds] section information
-    def _GetSkuIds(self):
-        if self._SkuIds == None:
-            self._SkuIds = {}
-            RecordList = self._RawData[MODEL_EFI_SKU_ID]
-            for Record in RecordList:
-                if Record[0] in [None, '']:
-                    EdkLogger.error('build', FORMAT_INVALID, 'No Sku ID number',
-                                    File=self.MetaFile, Line=Record[-1])
-                if Record[1] in [None, '']:
-                    EdkLogger.error('build', FORMAT_INVALID, 'No Sku ID name',
-                                    File=self.MetaFile, Line=Record[-1])
-                self._SkuIds[Record[1]] = Record[0]
-            if 'DEFAULT' not in self._SkuIds:
-                self._SkuIds['DEFAULT'] = 0
-        return self._SkuIds
-
-    ## Retrieve [Components] section information
-    def _GetModules(self):
-        if self._Modules != None:
-            return self._Modules
-
-        self._Modules = sdict()
-        RecordList = self._RawData[MODEL_META_DATA_COMPONENT, self._Arch]
-        Macros = {"EDK_SOURCE":GlobalData.gEcpSource, "EFI_SOURCE":GlobalData.gEfiSource}
-        Macros.update(self._Macros)
-        for Record in RecordList:
-            ModuleFile = PathClass(NormPath(Record[0], Macros), GlobalData.gWorkspace, Arch=self._Arch)
-            ModuleId = Record[5]
-            LineNo = Record[6]
-
-            # check the file validation
-            ErrorCode, ErrorInfo = ModuleFile.Validate('.inf')
-            if ErrorCode != 0:
-                EdkLogger.error('build', ErrorCode, File=self.MetaFile, Line=LineNo,
-                                ExtraData=ErrorInfo)
-            # Check duplication
-            if ModuleFile in self._Modules:
-                EdkLogger.error('build', FILE_DUPLICATED, File=self.MetaFile, ExtraData=str(ModuleFile), Line=LineNo)
-
-            Module = ModuleBuildClassObject()
-            Module.MetaFile = ModuleFile
-
-            # get module override path
-            RecordList = self._RawData[MODEL_META_DATA_COMPONENT_SOURCE_OVERRIDE_PATH, self._Arch, None, ModuleId]
-            if RecordList != []:
-                Module.SourceOverridePath = os.path.join(GlobalData.gWorkspace, NormPath(RecordList[0][0], Macros))
-
-                # Check if the source override path exists
-                if not os.path.isdir(Module.SourceOverridePath):
-                    EdkLogger.error('build', FILE_NOT_FOUND, Message = 'Source override path does not exist:', File=self.MetaFile, ExtraData=Module.SourceOverridePath, Line=LineNo)
-                
-                #Add to GlobalData Variables
-                GlobalData.gOverrideDir[ModuleFile.Key] = Module.SourceOverridePath
-
-            # get module private library instance
-            RecordList = self._RawData[MODEL_EFI_LIBRARY_CLASS, self._Arch, None, ModuleId]
-            for Record in RecordList:
-                LibraryClass = Record[0]
-                LibraryPath = PathClass(NormPath(Record[1], Macros), GlobalData.gWorkspace, Arch=self._Arch)
-                LineNo = Record[-1]
-
-                # check the file validation
-                ErrorCode, ErrorInfo = LibraryPath.Validate('.inf')
-                if ErrorCode != 0:
-                    EdkLogger.error('build', ErrorCode, File=self.MetaFile, Line=LineNo,
-                                    ExtraData=ErrorInfo)
-
-                if LibraryClass == '' or LibraryClass == 'NULL':
-                    self._NullLibraryNumber += 1
-                    LibraryClass = 'NULL%d' % self._NullLibraryNumber
-                    EdkLogger.verbose("Found forced library for %s\n\t%s [%s]" % (ModuleFile, LibraryPath, LibraryClass))
-                Module.LibraryClasses[LibraryClass] = LibraryPath
-                if LibraryPath not in self.LibraryInstances:
-                    self.LibraryInstances.append(LibraryPath)
-
-            # get module private PCD setting
-            for Type in [MODEL_PCD_FIXED_AT_BUILD, MODEL_PCD_PATCHABLE_IN_MODULE, \
-                         MODEL_PCD_FEATURE_FLAG, MODEL_PCD_DYNAMIC, MODEL_PCD_DYNAMIC_EX]:
-                RecordList = self._RawData[Type, self._Arch, None, ModuleId]
-                for TokenSpaceGuid, PcdCName, Setting, Dummy1, Dummy2, Dummy3, Dummy4 in RecordList:
-                    TokenList = GetSplitValueList(Setting)
-                    DefaultValue = TokenList[0]
-                    if len(TokenList) > 1:
-                        MaxDatumSize = TokenList[1]
-                    else:
-                        MaxDatumSize = ''
-                    TypeString = self._PCD_TYPE_STRING_[Type]
-                    Pcd = PcdClassObject(
-                            PcdCName,
-                            TokenSpaceGuid,
-                            TypeString,
-                            '',
-                            DefaultValue,
-                            '',
-                            MaxDatumSize,
-                            {},
-                            None
-                            )
-                    Module.Pcds[PcdCName, TokenSpaceGuid] = Pcd
-
-            # get module private build options
-            RecordList = self._RawData[MODEL_META_DATA_BUILD_OPTION, self._Arch, None, ModuleId]
-            for ToolChainFamily, ToolChain, Option, Dummy1, Dummy2, Dummy3, Dummy4 in RecordList:
-                if (ToolChainFamily, ToolChain) not in Module.BuildOptions:
-                    Module.BuildOptions[ToolChainFamily, ToolChain] = Option
-                else:
-                    OptionString = Module.BuildOptions[ToolChainFamily, ToolChain]
-                    Module.BuildOptions[ToolChainFamily, ToolChain] = OptionString + " " + Option
-
-            self._Modules[ModuleFile] = Module
-        return self._Modules
-
-    ## Retrieve all possible library instances used in this platform
-    def _GetLibraryInstances(self):
-        if self._LibraryInstances == None:
-            self._GetLibraryClasses()
-        return self._LibraryInstances
-
-    ## Retrieve [LibraryClasses] information
-    def _GetLibraryClasses(self):
-        if self._LibraryClasses == None:
-            self._LibraryInstances = []
-            #
-            # tdict is a special dict kind of type, used for selecting correct
-            # library instance for given library class and module type
-            #
-            LibraryClassDict = tdict(True, 3)
-            # track all library class names
-            LibraryClassSet = set()
-            RecordList = self._RawData[MODEL_EFI_LIBRARY_CLASS, self._Arch]
-            Macros = {"EDK_SOURCE":GlobalData.gEcpSource, "EFI_SOURCE":GlobalData.gEfiSource}
-            Macros.update(self._Macros)
-            for Record in RecordList:
-                LibraryClass, LibraryInstance, Dummy, Arch, ModuleType, Dummy, LineNo = Record
-                LibraryClassSet.add(LibraryClass)
-                LibraryInstance = PathClass(NormPath(LibraryInstance, Macros), GlobalData.gWorkspace, Arch=self._Arch)
-                # check the file validation
-                ErrorCode, ErrorInfo = LibraryInstance.Validate('.inf')
-                if ErrorCode != 0:
-                    EdkLogger.error('build', ErrorCode, File=self.MetaFile, Line=LineNo,
-                                    ExtraData=ErrorInfo)
-
-                if ModuleType != 'COMMON' and ModuleType not in SUP_MODULE_LIST:
-                    EdkLogger.error('build', OPTION_UNKNOWN, "Unknown module type [%s]" % ModuleType,
-                                    File=self.MetaFile, ExtraData=LibraryInstance, Line=LineNo)
-                LibraryClassDict[Arch, ModuleType, LibraryClass] = LibraryInstance
-                if LibraryInstance not in self._LibraryInstances:
-                    self._LibraryInstances.append(LibraryInstance)
-
-            # resolve the specific library instance for each class and each module type
-            self._LibraryClasses = tdict(True)
-            for LibraryClass in LibraryClassSet:
-                # try all possible module types
-                for ModuleType in SUP_MODULE_LIST:
-                    LibraryInstance = LibraryClassDict[self._Arch, ModuleType, LibraryClass]
-                    if LibraryInstance == None:
-                        continue
-                    self._LibraryClasses[LibraryClass, ModuleType] = LibraryInstance
-
-            # for R8 style library instances, which are listed in different section
-            RecordList = self._RawData[MODEL_EFI_LIBRARY_INSTANCE, self._Arch]
-            for Record in RecordList:
-                File = PathClass(NormPath(Record[0], Macros), GlobalData.gWorkspace, Arch=self._Arch)
-                LineNo = Record[-1]
-                # check the file validation
-                ErrorCode, ErrorInfo = File.Validate('.inf')
-                if ErrorCode != 0:
-                    EdkLogger.error('build', ErrorCode, File=self.MetaFile, Line=LineNo,
-                                    ExtraData=ErrorInfo)
-                if File not in self._LibraryInstances:
-                    self._LibraryInstances.append(File)
-                #
-                # we need the module name as the library class name, so we have
-                # to parse it here. (self._Bdb[] will trigger a file parse if it
-                # hasn't been parsed)
-                #
-                Library = self._Bdb[File, self._Arch]
-                self._LibraryClasses[Library.BaseName, ':dummy:'] = Library
-        return self._LibraryClasses
-
-    ## Retrieve all PCD settings in platform
-    def _GetPcds(self):
-        if self._Pcds == None:
-            self._Pcds = {}
-            self._Pcds.update(self._GetPcd(MODEL_PCD_FIXED_AT_BUILD))
-            self._Pcds.update(self._GetPcd(MODEL_PCD_PATCHABLE_IN_MODULE))
-            self._Pcds.update(self._GetPcd(MODEL_PCD_FEATURE_FLAG))
-            self._Pcds.update(self._GetDynamicPcd(MODEL_PCD_DYNAMIC_DEFAULT))
-            self._Pcds.update(self._GetDynamicHiiPcd(MODEL_PCD_DYNAMIC_HII))
-            self._Pcds.update(self._GetDynamicVpdPcd(MODEL_PCD_DYNAMIC_VPD))
-            self._Pcds.update(self._GetDynamicPcd(MODEL_PCD_DYNAMIC_EX_DEFAULT))
-            self._Pcds.update(self._GetDynamicHiiPcd(MODEL_PCD_DYNAMIC_EX_HII))
-            self._Pcds.update(self._GetDynamicVpdPcd(MODEL_PCD_DYNAMIC_EX_VPD))
-        return self._Pcds
-
-    ## Retrieve [BuildOptions]
-    def _GetBuildOptions(self):
-        if self._BuildOptions == None:
-            self._BuildOptions = {}
-            RecordList = self._RawData[MODEL_META_DATA_BUILD_OPTION]
-            for ToolChainFamily, ToolChain, Option, Dummy1, Dummy2, Dummy3, Dummy4 in RecordList:
-                self._BuildOptions[ToolChainFamily, ToolChain] = Option
-        return self._BuildOptions
-
-    ## Retrieve non-dynamic PCD settings
-    #
-    #   @param  Type    PCD type
-    #
-    #   @retval a dict object contains settings of given PCD type
-    #
-    def _GetPcd(self, Type):
-        Pcds = {}
-        #
-        # tdict is a special dict kind of type, used for selecting correct
-        # PCD settings for certain ARCH
-        #
-        PcdDict = tdict(True, 3)
-        PcdSet = set()
-        # Find out all possible PCD candidates for self._Arch
-        RecordList = self._RawData[Type, self._Arch]
-        for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, Dummy3, Dummy4 in RecordList:
-            PcdSet.add((PcdCName, TokenSpaceGuid))
-            PcdDict[Arch, PcdCName, TokenSpaceGuid] = Setting
-        # Remove redundant PCD candidates
-        for PcdCName, TokenSpaceGuid in PcdSet:
-            ValueList = ['', '', '']
-            Setting = PcdDict[self._Arch, PcdCName, TokenSpaceGuid]
-            if Setting == None:
-                continue
-            TokenList = Setting.split(TAB_VALUE_SPLIT)
-            ValueList[0:len(TokenList)] = TokenList
-            PcdValue, DatumType, MaxDatumSize = ValueList
-            Pcds[PcdCName, TokenSpaceGuid] = PcdClassObject(
-                                                PcdCName,
-                                                TokenSpaceGuid,
-                                                self._PCD_TYPE_STRING_[Type],
-                                                DatumType,
-                                                PcdValue,
-                                                '',
-                                                MaxDatumSize,
-                                                {},
-                                                None
-                                                )
-        return Pcds
-
-    ## Retrieve dynamic PCD settings
-    #
-    #   @param  Type    PCD type
-    #
-    #   @retval a dict object contains settings of given PCD type
-    #
-    def _GetDynamicPcd(self, Type):
-        Pcds = {}
-        #
-        # tdict is a special dict kind of type, used for selecting correct
-        # PCD settings for certain ARCH and SKU
-        #
-        PcdDict = tdict(True, 4)
-        PcdSet = set()
-        # Find out all possible PCD candidates for self._Arch
-        RecordList = self._RawData[Type, self._Arch]
-        for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, Dummy3, Dummy4 in RecordList:
-            PcdSet.add((PcdCName, TokenSpaceGuid))
-            PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid] = Setting
-        # Remove redundant PCD candidates, per the ARCH and SKU
-        for PcdCName, TokenSpaceGuid in PcdSet:
-            ValueList = ['', '', '']
-            Setting = PcdDict[self._Arch, self.SkuName, PcdCName, TokenSpaceGuid]
-            if Setting == None:
-                continue
-            TokenList = Setting.split(TAB_VALUE_SPLIT)
-            ValueList[0:len(TokenList)] = TokenList
-            PcdValue, DatumType, MaxDatumSize = ValueList
-
-            SkuInfo = SkuInfoClass(self.SkuName, self.SkuIds[self.SkuName], '', '', '', '', '', PcdValue)
-            Pcds[PcdCName, TokenSpaceGuid] = PcdClassObject(
-                                                PcdCName,
-                                                TokenSpaceGuid,
-                                                self._PCD_TYPE_STRING_[Type],
-                                                DatumType,
-                                                PcdValue,
-                                                '',
-                                                MaxDatumSize,
-                                                {self.SkuName : SkuInfo},
-                                                None
-                                                )
-        return Pcds
-
-    ## Retrieve dynamic HII PCD settings
-    #
-    #   @param  Type    PCD type
-    #
-    #   @retval a dict object contains settings of given PCD type
-    #
-    def _GetDynamicHiiPcd(self, Type):
-        Pcds = {}
-        #
-        # tdict is a special dict kind of type, used for selecting correct
-        # PCD settings for certain ARCH and SKU
-        #
-        PcdDict = tdict(True, 4)
-        PcdSet = set()
-        RecordList = self._RawData[Type, self._Arch]
-        # Find out all possible PCD candidates for self._Arch
-        for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, Dummy3, Dummy4 in RecordList:
-            PcdSet.add((PcdCName, TokenSpaceGuid))
-            PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid] = Setting
-        # Remove redundant PCD candidates, per the ARCH and SKU
-        for PcdCName, TokenSpaceGuid in PcdSet:
-            ValueList = ['', '', '', '']
-            Setting = PcdDict[self._Arch, self.SkuName, PcdCName, TokenSpaceGuid]
-            if Setting == None:
-                continue
-            TokenList = Setting.split(TAB_VALUE_SPLIT)
-            ValueList[0:len(TokenList)] = TokenList
-            VariableName, VariableGuid, VariableOffset, DefaultValue = ValueList
-            SkuInfo = SkuInfoClass(self.SkuName, self.SkuIds[self.SkuName], VariableName, VariableGuid, VariableOffset, DefaultValue)
-            Pcds[PcdCName, TokenSpaceGuid] = PcdClassObject(
-                                                PcdCName,
-                                                TokenSpaceGuid,
-                                                self._PCD_TYPE_STRING_[Type],
-                                                '',
-                                                DefaultValue,
-                                                '',
-                                                '',
-                                                {self.SkuName : SkuInfo},
-                                                None
-                                                )
-        return Pcds
-
-    ## Retrieve dynamic VPD PCD settings
-    #
-    #   @param  Type    PCD type
-    #
-    #   @retval a dict object contains settings of given PCD type
-    #
-    def _GetDynamicVpdPcd(self, Type):
-        Pcds = {}
-        #
-        # tdict is a special dict kind of type, used for selecting correct
-        # PCD settings for certain ARCH and SKU
-        #
-        PcdDict = tdict(True, 4)
-        PcdSet = set()
-        # Find out all possible PCD candidates for self._Arch
-        RecordList = self._RawData[Type, self._Arch]
-        for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, Dummy3, Dummy4 in RecordList:
-            PcdSet.add((PcdCName, TokenSpaceGuid))
-            PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid] = Setting
-        # Remove redundant PCD candidates, per the ARCH and SKU
-        for PcdCName, TokenSpaceGuid in PcdSet:
-            ValueList = ['', '']
-            Setting = PcdDict[self._Arch, self.SkuName, PcdCName, TokenSpaceGuid]
-            if Setting == None:
-                continue
-            TokenList = Setting.split(TAB_VALUE_SPLIT)
-            ValueList[0:len(TokenList)] = TokenList
-            VpdOffset, MaxDatumSize = ValueList
-
-            SkuInfo = SkuInfoClass(self.SkuName, self.SkuIds[self.SkuName], '', '', '', '', VpdOffset)
-            Pcds[PcdCName, TokenSpaceGuid] = PcdClassObject(
-                                                PcdCName,
-                                                TokenSpaceGuid,
-                                                self._PCD_TYPE_STRING_[Type],
-                                                '',
-                                                '',
-                                                '',
-                                                MaxDatumSize,
-                                                {self.SkuName : SkuInfo},
-                                                None
-                                                )
-        return Pcds
-
-    ## Add external modules
-    #
-    #   The external modules are mostly those listed in FDF file, which don't
-    # need "build".
-    #
-    #   @param  FilePath    The path of module description file
-    #
-    def AddModule(self, FilePath):
-        FilePath = NormPath(FilePath)
-        if FilePath not in self.Modules:
-            Module = ModuleBuildClassObject()
-            Module.MetaFile = FilePath
-            self.Modules.append(Module)
-
-    ## Add external PCDs
-    #
-    #   The external PCDs are mostly those listed in FDF file to specify address
-    # or offset information.
-    #
-    #   @param  Name    Name of the PCD
-    #   @param  Guid    Token space guid of the PCD
-    #   @param  Value   Value of the PCD
-    #
-    def AddPcd(self, Name, Guid, Value):
-        if (Name, Guid) not in self.Pcds:
-            self.Pcds[Name, Guid] = PcdClassObject(Name, Guid, '', '', '', '', '', {}, None)
-        self.Pcds[Name, Guid].DefaultValue = Value
-
-    Arch                = property(_GetArch, _SetArch)
-    Platform            = property(_GetPlatformName)
-    PlatformName        = property(_GetPlatformName)
-    Guid                = property(_GetFileGuid)
-    Version             = property(_GetVersion)
-    DscSpecification    = property(_GetDscSpec)
-    OutputDirectory     = property(_GetOutpuDir)
-    SupArchList         = property(_GetSupArch)
-    BuildTargets        = property(_GetBuildTarget)
-    SkuName             = property(_GetSkuName, _SetSkuName)
-    FlashDefinition     = property(_GetFdfFile)
-    BuildNumber         = property(_GetBuildNumber)
-    MakefileName        = property(_GetMakefileName)
-    BsBaseAddress       = property(_GetBsBaseAddress)
-    RtBaseAddress       = property(_GetRtBaseAddress)
-
-    SkuIds              = property(_GetSkuIds)
-    Modules             = property(_GetModules)
-    LibraryInstances    = property(_GetLibraryInstances)
-    LibraryClasses      = property(_GetLibraryClasses)
-    Pcds                = property(_GetPcds)
-    BuildOptions        = property(_GetBuildOptions)
-
-## Platform build information from DSC file
-#
-#  This class is used to retrieve information stored in database and convert them
-# into PackageBuildClassObject form for easier use for AutoGen.
-#
-class DecBuildData(PackageBuildClassObject):
-    # dict used to convert PCD type in database to string used by build tool
-    _PCD_TYPE_STRING_ = {
-        MODEL_PCD_FIXED_AT_BUILD        :   "FixedAtBuild",
-        MODEL_PCD_PATCHABLE_IN_MODULE   :   "PatchableInModule",
-        MODEL_PCD_FEATURE_FLAG          :   "FeatureFlag",
-        MODEL_PCD_DYNAMIC               :   "Dynamic",
-        MODEL_PCD_DYNAMIC_DEFAULT       :   "Dynamic",
-        MODEL_PCD_DYNAMIC_HII           :   "DynamicHii",
-        MODEL_PCD_DYNAMIC_VPD           :   "DynamicVpd",
-        MODEL_PCD_DYNAMIC_EX            :   "DynamicEx",
-        MODEL_PCD_DYNAMIC_EX_DEFAULT    :   "DynamicEx",
-        MODEL_PCD_DYNAMIC_EX_HII        :   "DynamicExHii",
-        MODEL_PCD_DYNAMIC_EX_VPD        :   "DynamicExVpd",
-    }
-
-    # dict used to convert part of [Defines] to members of DecBuildData directly
-    _PROPERTY_ = {
-        #
-        # Required Fields
-        #
-        TAB_DEC_DEFINES_PACKAGE_NAME                : "_PackageName",
-        TAB_DEC_DEFINES_PACKAGE_GUID                : "_Guid",
-        TAB_DEC_DEFINES_PACKAGE_VERSION             : "_Version",
-    }
-
-
-    ## Constructor of DecBuildData
-    #
-    #  Initialize object of DecBuildData
-    #
-    #   @param      FilePath        The path of package description file
-    #   @param      RawData         The raw data of DEC file
-    #   @param      BuildDataBase   Database used to retrieve module information
-    #   @param      Arch            The target architecture
-    #   @param      Platform        (not used for DecBuildData)
-    #   @param      Macros          Macros used for replacement in DSC file
-    #
-    def __init__(self, File, RawData, BuildDataBase, Arch='COMMON', Platform='DUMMY', Macros={}):
-        self.MetaFile = File
-        self._PackageDir = File.Dir
-        self._RawData = RawData
-        self._Bdb = BuildDataBase
-        self._Arch = Arch
-        self._Macros = Macros
-        self._Clear()
-
-    ## XXX[key] = value
-    def __setitem__(self, key, value):
-        self.__dict__[self._PROPERTY_[key]] = value
-
-    ## value = XXX[key]
-    def __getitem__(self, key):
-        return self.__dict__[self._PROPERTY_[key]]
-
-    ## "in" test support
-    def __contains__(self, key):
-        return key in self._PROPERTY_
-
-    ## Set all internal used members of DecBuildData to None
-    def _Clear(self):
-        self._Header            = None
-        self._PackageName       = None
-        self._Guid              = None
-        self._Version           = None
-        self._Protocols         = None
-        self._Ppis              = None
-        self._Guids             = None
-        self._Includes          = None
-        self._LibraryClasses    = None
-        self._Pcds              = None
-
-    ## Get architecture
-    def _GetArch(self):
-        return self._Arch
-
-    ## Set architecture
-    #
-    #   Changing the default ARCH to another may affect all other information
-    # because all information in a platform may be ARCH-related. That's
-    # why we need to clear all internal used members, in order to cause all
-    # information to be re-retrieved.
-    #
-    #   @param  Value   The value of ARCH
-    #
-    def _SetArch(self, Value):
-        if self._Arch == Value:
-            return
-        self._Arch = Value
-        self._Clear()
-
-    ## Retrieve all information in [Defines] section
-    #
-    #   (Retriving all [Defines] information in one-shot is just to save time.)
-    #
-    def _GetHeaderInfo(self):
-        RecordList = self._RawData[MODEL_META_DATA_HEADER]
-        for Record in RecordList:
-            Name = Record[0]
-            if Name in self:
-                self[Name] = Record[1]
-        self._Header = 'DUMMY'
-
-    ## Retrieve package name
-    def _GetPackageName(self):
-        if self._PackageName == None:
-            if self._Header == None:
-                self._GetHeaderInfo()
-            if self._PackageName == None:
-                EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, "No PACKAGE_NAME", File=self.MetaFile)
-        return self._PackageName
-
-    ## Retrieve file guid
-    def _GetFileGuid(self):
-        if self._Guid == None:
-            if self._Header == None:
-                self._GetHeaderInfo()
-            if self._Guid == None:
-                EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, "No PACKAGE_GUID", File=self.MetaFile)
-        return self._Guid
-
-    ## Retrieve package version
-    def _GetVersion(self):
-        if self._Version == None:
-            if self._Header == None:
-                self._GetHeaderInfo()
-            if self._Version == None:
-                self._Version = ''
-        return self._Version
-
-    ## Retrieve protocol definitions (name/value pairs)
-    def _GetProtocol(self):
-        if self._Protocols == None:
-            #
-            # tdict is a special kind of dict, used for selecting correct
-            # protocol defition for given ARCH
-            #
-            ProtocolDict = tdict(True)
-            NameList = []
-            # find out all protocol definitions for specific and 'common' arch
-            RecordList = self._RawData[MODEL_EFI_PROTOCOL, self._Arch]
-            for Name, Guid, Dummy, Arch, ID, LineNo in RecordList:
-                if Name not in NameList:
-                    NameList.append(Name)
-                ProtocolDict[Arch, Name] = Guid
-            # use sdict to keep the order
-            self._Protocols = sdict()
-            for Name in NameList:
-                #
-                # limit the ARCH to self._Arch, if no self._Arch found, tdict
-                # will automatically turn to 'common' ARCH for trying
-                #
-                self._Protocols[Name] = ProtocolDict[self._Arch, Name]
-        return self._Protocols
-
-    ## Retrieve PPI definitions (name/value pairs)
-    def _GetPpi(self):
-        if self._Ppis == None:
-            #
-            # tdict is a special kind of dict, used for selecting correct
-            # PPI defition for given ARCH
-            #
-            PpiDict = tdict(True)
-            NameList = []
-            # find out all PPI definitions for specific arch and 'common' arch
-            RecordList = self._RawData[MODEL_EFI_PPI, self._Arch]
-            for Name, Guid, Dummy, Arch, ID, LineNo in RecordList:
-                if Name not in NameList:
-                    NameList.append(Name)
-                PpiDict[Arch, Name] = Guid
-            # use sdict to keep the order
-            self._Ppis = sdict()
-            for Name in NameList:
-                #
-                # limit the ARCH to self._Arch, if no self._Arch found, tdict
-                # will automatically turn to 'common' ARCH for trying
-                #
-                self._Ppis[Name] = PpiDict[self._Arch, Name]
-        return self._Ppis
-
-    ## Retrieve GUID definitions (name/value pairs)
-    def _GetGuid(self):
-        if self._Guids == None:
-            #
-            # tdict is a special kind of dict, used for selecting correct
-            # GUID defition for given ARCH
-            #
-            GuidDict = tdict(True)
-            NameList = []
-            # find out all protocol definitions for specific and 'common' arch
-            RecordList = self._RawData[MODEL_EFI_GUID, self._Arch]
-            for Name, Guid, Dummy, Arch, ID, LineNo in RecordList:
-                if Name not in NameList:
-                    NameList.append(Name)
-                GuidDict[Arch, Name] = Guid
-            # use sdict to keep the order
-            self._Guids = sdict()
-            for Name in NameList:
-                #
-                # limit the ARCH to self._Arch, if no self._Arch found, tdict
-                # will automatically turn to 'common' ARCH for trying
-                #
-                self._Guids[Name] = GuidDict[self._Arch, Name]
-        return self._Guids
-
-    ## Retrieve public include paths declared in this package
-    def _GetInclude(self):
-        if self._Includes == None:
-            self._Includes = []
-            RecordList = self._RawData[MODEL_EFI_INCLUDE, self._Arch]
-            Macros = {"EDK_SOURCE":GlobalData.gEcpSource, "EFI_SOURCE":GlobalData.gEfiSource}
-            Macros.update(self._Macros)
-            for Record in RecordList:
-                File = PathClass(NormPath(Record[0], Macros), self._PackageDir, Arch=self._Arch)
-                LineNo = Record[-1]
-                # validate the path
-                ErrorCode, ErrorInfo = File.Validate()
-                if ErrorCode != 0:
-                    EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo, File=self.MetaFile, Line=LineNo)
-
-                # avoid duplicate include path
-                if File not in self._Includes:
-                    self._Includes.append(File)
-        return self._Includes
-
-    ## Retrieve library class declarations (not used in build at present)
-    def _GetLibraryClass(self):
-        if self._LibraryClasses == None:
-            #
-            # tdict is a special kind of dict, used for selecting correct
-            # library class declaration for given ARCH
-            #
-            LibraryClassDict = tdict(True)
-            LibraryClassSet = set()
-            RecordList = self._RawData[MODEL_EFI_LIBRARY_CLASS, self._Arch]
-            Macros = {"EDK_SOURCE":GlobalData.gEcpSource, "EFI_SOURCE":GlobalData.gEfiSource}
-            Macros.update(self._Macros)
-            for LibraryClass, File, Dummy, Arch, ID, LineNo in RecordList:
-                File = PathClass(NormPath(File, Macros), self._PackageDir, Arch=self._Arch)
-                # check the file validation
-                ErrorCode, ErrorInfo = File.Validate()
-                if ErrorCode != 0:
-                    EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo, File=self.MetaFile, Line=LineNo)
-                LibraryClassSet.add(LibraryClass)
-                LibraryClassDict[Arch, LibraryClass] = File
-            self._LibraryClasses = sdict()
-            for LibraryClass in LibraryClassSet:
-                self._LibraryClasses[LibraryClass] = LibraryClassDict[self._Arch, LibraryClass]
-        return self._LibraryClasses
-
-    ## Retrieve PCD declarations
-    def _GetPcds(self):
-        if self._Pcds == None:
-            self._Pcds = {}
-            self._Pcds.update(self._GetPcd(MODEL_PCD_FIXED_AT_BUILD))
-            self._Pcds.update(self._GetPcd(MODEL_PCD_PATCHABLE_IN_MODULE))
-            self._Pcds.update(self._GetPcd(MODEL_PCD_FEATURE_FLAG))
-            self._Pcds.update(self._GetPcd(MODEL_PCD_DYNAMIC))
-            self._Pcds.update(self._GetPcd(MODEL_PCD_DYNAMIC_EX))
-        return self._Pcds
-
-    ## Retrieve PCD declarations for given type
-    def _GetPcd(self, Type):
-        Pcds = {}
-        #
-        # tdict is a special kind of dict, used for selecting correct
-        # PCD declaration for given ARCH
-        #
-        PcdDict = tdict(True, 3)
-        # for summarizing PCD
-        PcdSet = set()
-        # find out all PCDs of the 'type'
-        RecordList = self._RawData[Type, self._Arch]
-        for TokenSpaceGuid, PcdCName, Setting, Arch, Dummy1, Dummy2 in RecordList:
-            PcdDict[Arch, PcdCName, TokenSpaceGuid] = Setting
-            PcdSet.add((PcdCName, TokenSpaceGuid))
-
-        for PcdCName, TokenSpaceGuid in PcdSet:
-            ValueList = ['', '', '']
-            #
-            # limit the ARCH to self._Arch, if no self._Arch found, tdict
-            # will automatically turn to 'common' ARCH and try again
-            #
-            Setting = PcdDict[self._Arch, PcdCName, TokenSpaceGuid]
-            if Setting == None:
-                continue
-            TokenList = Setting.split(TAB_VALUE_SPLIT)
-            ValueList[0:len(TokenList)] = TokenList
-            DefaultValue, DatumType, TokenNumber = ValueList
-            Pcds[PcdCName, TokenSpaceGuid, self._PCD_TYPE_STRING_[Type]] = PcdClassObject(
-                                                                            PcdCName,
-                                                                            TokenSpaceGuid,
-                                                                            self._PCD_TYPE_STRING_[Type],
-                                                                            DatumType,
-                                                                            DefaultValue,
-                                                                            TokenNumber,
-                                                                            '',
-                                                                            {},
-                                                                            None
-                                                                            )
-        return Pcds
-
-
-    Arch            = property(_GetArch, _SetArch)
-    PackageName     = property(_GetPackageName)
-    Guid            = property(_GetFileGuid)
-    Version         = property(_GetVersion)
-
-    Protocols       = property(_GetProtocol)
-    Ppis            = property(_GetPpi)
-    Guids           = property(_GetGuid)
-    Includes        = property(_GetInclude)
-    LibraryClasses  = property(_GetLibraryClass)
-    Pcds            = property(_GetPcds)
-
-## Module build information from INF file
-#
-#  This class is used to retrieve information stored in database and convert them
-# into ModuleBuildClassObject form for easier use for AutoGen.
-#
-class InfBuildData(ModuleBuildClassObject):
-    # dict used to convert PCD type in database to string used by build tool
-    _PCD_TYPE_STRING_ = {
-        MODEL_PCD_FIXED_AT_BUILD        :   "FixedAtBuild",
-        MODEL_PCD_PATCHABLE_IN_MODULE   :   "PatchableInModule",
-        MODEL_PCD_FEATURE_FLAG          :   "FeatureFlag",
-        MODEL_PCD_DYNAMIC               :   "Dynamic",
-        MODEL_PCD_DYNAMIC_DEFAULT       :   "Dynamic",
-        MODEL_PCD_DYNAMIC_HII           :   "DynamicHii",
-        MODEL_PCD_DYNAMIC_VPD           :   "DynamicVpd",
-        MODEL_PCD_DYNAMIC_EX            :   "DynamicEx",
-        MODEL_PCD_DYNAMIC_EX_DEFAULT    :   "DynamicEx",
-        MODEL_PCD_DYNAMIC_EX_HII        :   "DynamicExHii",
-        MODEL_PCD_DYNAMIC_EX_VPD        :   "DynamicExVpd",
-    }
-
-    # dict used to convert part of [Defines] to members of InfBuildData directly
-    _PROPERTY_ = {
-        #
-        # Required Fields
-        #
-        TAB_INF_DEFINES_BASE_NAME                   : "_BaseName",
-        TAB_INF_DEFINES_FILE_GUID                   : "_Guid",
-        TAB_INF_DEFINES_MODULE_TYPE                 : "_ModuleType",
-        #
-        # Optional Fields
-        #
-        TAB_INF_DEFINES_INF_VERSION                 : "_AutoGenVersion",
-        TAB_INF_DEFINES_COMPONENT_TYPE              : "_ComponentType",
-        TAB_INF_DEFINES_MAKEFILE_NAME               : "_MakefileName",
-        #TAB_INF_DEFINES_CUSTOM_MAKEFILE             : "_CustomMakefile",
-        TAB_INF_DEFINES_VERSION_NUMBER              : "_Version",
-        TAB_INF_DEFINES_VERSION_STRING              : "_Version",
-        TAB_INF_DEFINES_VERSION                     : "_Version",
-        TAB_INF_DEFINES_PCD_IS_DRIVER               : "_PcdIsDriver",
-        TAB_INF_DEFINES_SHADOW                      : "_Shadow",
-
-        TAB_COMPONENTS_SOURCE_OVERRIDE_PATH         : "_SourceOverridePath",
-    }
-
-    # dict used to convert Component type to Module type
-    _MODULE_TYPE_ = {
-        "LIBRARY"               :   "BASE",
-        "SECURITY_CORE"         :   "SEC",
-        "PEI_CORE"              :   "PEI_CORE",
-        "COMBINED_PEIM_DRIVER"  :   "PEIM",
-        "PIC_PEIM"              :   "PEIM",
-        "RELOCATABLE_PEIM"      :   "PEIM",
-        "PE32_PEIM"             :   "PEIM",
-        "BS_DRIVER"             :   "DXE_DRIVER",
-        "RT_DRIVER"             :   "DXE_RUNTIME_DRIVER",
-        "SAL_RT_DRIVER"         :   "DXE_SAL_DRIVER",
-        "SMM_DRIVER"            :   "SMM_DRIVER",
-    #    "BS_DRIVER"             :   "DXE_SMM_DRIVER",
-    #    "BS_DRIVER"             :   "UEFI_DRIVER",
-        "APPLICATION"           :   "UEFI_APPLICATION",
-        "LOGO"                  :   "BASE",
-    }
-
-    # regular expression for converting XXX_FLAGS in [nmake] section to new type
-    _NMAKE_FLAG_PATTERN_ = re.compile("(?:EBC_)?([A-Z]+)_(?:STD_|PROJ_|ARCH_)?FLAGS(?:_DLL|_ASL|_EXE)?", re.UNICODE)
-    # dict used to convert old tool name used in [nmake] section to new ones
-    _TOOL_CODE_ = {
-        "C"         :   "CC",
-        "LIB"       :   "SLINK",
-        "LINK"      :   "DLINK",
-    }
-
-
-    ## Constructor of DscBuildData
-    #
-    #  Initialize object of DscBuildData
-    #
-    #   @param      FilePath        The path of platform description file
-    #   @param      RawData         The raw data of DSC file
-    #   @param      BuildDataBase   Database used to retrieve module/package information
-    #   @param      Arch            The target architecture
-    #   @param      Platform        The name of platform employing this module
-    #   @param      Macros          Macros used for replacement in DSC file
-    #
-    def __init__(self, FilePath, RawData, BuildDatabase, Arch='COMMON', Platform='COMMON', Macros={}):
-        self.MetaFile = FilePath
-        self._ModuleDir = FilePath.Dir
-        self._RawData = RawData
-        self._Bdb = BuildDatabase
-        self._Arch = Arch
-        self._Platform = 'COMMON'
-        self._Macros = Macros
-        self._SourceOverridePath = None
-        if FilePath.Key in GlobalData.gOverrideDir:
-            self._SourceOverridePath = GlobalData.gOverrideDir[FilePath.Key]
-        self._Clear()
-
-    ## XXX[key] = value
-    def __setitem__(self, key, value):
-        self.__dict__[self._PROPERTY_[key]] = value
-
-    ## value = XXX[key]
-    def __getitem__(self, key):
-        return self.__dict__[self._PROPERTY_[key]]
-
-    ## "in" test support
-    def __contains__(self, key):
-        return key in self._PROPERTY_
-
-    ## Set all internal used members of InfBuildData to None
-    def _Clear(self):
-        self._Header_               = None
-        self._AutoGenVersion        = None
-        self._BaseName              = None
-        self._ModuleType            = None
-        self._ComponentType         = None
-        self._BuildType             = None
-        self._Guid                  = None
-        self._Version               = None
-        self._PcdIsDriver           = None
-        self._BinaryModule          = None
-        self._Shadow                = None
-        self._MakefileName          = None
-        self._CustomMakefile        = None
-        self._Specification         = None
-        self._LibraryClass          = None
-        self._ModuleEntryPointList  = None
-        self._ModuleUnloadImageList = None
-        self._ConstructorList       = None
-        self._DestructorList        = None
-        self._Defs                  = None
-        self._Binaries              = None
-        self._Sources               = None
-        self._LibraryClasses        = None
-        self._Libraries             = None
-        self._Protocols             = None
-        self._Ppis                  = None
-        self._Guids                 = None
-        self._Includes              = None
-        self._Packages              = None
-        self._Pcds                  = None
-        self._BuildOptions          = None
-        self._Depex                 = None
-        #self._SourceOverridePath    = None
-
-    ## Get architecture
-    def _GetArch(self):
-        return self._Arch
-
-    ## Set architecture
-    #
-    #   Changing the default ARCH to another may affect all other information
-    # because all information in a platform may be ARCH-related. That's
-    # why we need to clear all internal used members, in order to cause all
-    # information to be re-retrieved.
-    #
-    #   @param  Value   The value of ARCH
-    #
-    def _SetArch(self, Value):
-        if self._Arch == Value:
-            return
-        self._Arch = Value
-        self._Clear()
-
-    ## Return the name of platform employing this module
-    def _GetPlatform(self):
-        return self._Platform
-
-    ## Change the name of platform employing this module
-    #
-    #   Changing the default name of platform to another may affect some information
-    # because they may be PLATFORM-related. That's why we need to clear all internal
-    # used members, in order to cause all information to be re-retrieved.
-    #
-    def _SetPlatform(self, Value):
-        if self._Platform == Value:
-            return
-        self._Platform = Value
-        self._Clear()
-
-    ## Retrieve all information in [Defines] section
-    #
-    #   (Retriving all [Defines] information in one-shot is just to save time.)
-    #
-    def _GetHeaderInfo(self):
-        RecordList = self._RawData[MODEL_META_DATA_HEADER, self._Arch, self._Platform]
-        for Record in RecordList:
-            Record = ReplaceMacros(Record, GlobalData.gEdkGlobal, False)
-            Name = Record[0]
-            # items defined _PROPERTY_ don't need additional processing
-            if Name in self:
-                self[Name] = Record[1]
-            # some special items in [Defines] section need special treatment
-            elif Name == 'EFI_SPECIFICATION_VERSION':
-                if self._Specification == None:
-                    self._Specification = sdict()
-                self._Specification[Name] = Record[1]
-            elif Name == 'EDK_RELEASE_VERSION':
-                if self._Specification == None:
-                    self._Specification = sdict()
-                self._Specification[Name] = Record[1]
-            elif Name == 'PI_SPECIFICATION_VERSION':
-                if self._Specification == None:
-                    self._Specification = sdict()
-                self._Specification[Name] = Record[1]
-            elif Name == 'LIBRARY_CLASS':
-                if self._LibraryClass == None:
-                    self._LibraryClass = []
-                ValueList = GetSplitValueList(Record[1])
-                LibraryClass = ValueList[0]
-                if len(ValueList) > 1:
-                    SupModuleList = GetSplitValueList(ValueList[1], ' ')
-                else:
-                    SupModuleList = SUP_MODULE_LIST
-                self._LibraryClass.append(LibraryClassObject(LibraryClass, SupModuleList))
-            elif Name == 'ENTRY_POINT':
-                if self._ModuleEntryPointList == None:
-                    self._ModuleEntryPointList = []
-                self._ModuleEntryPointList.append(Record[1])
-            elif Name == 'UNLOAD_IMAGE':
-                if self._ModuleUnloadImageList == None:
-                    self._ModuleUnloadImageList = []
-                if Record[1] == '':
-                    continue
-                self._ModuleUnloadImageList.append(Record[1])
-            elif Name == 'CONSTRUCTOR':
-                if self._ConstructorList == None:
-                    self._ConstructorList = []
-                if Record[1] == '':
-                    continue
-                self._ConstructorList.append(Record[1])
-            elif Name == 'DESTRUCTOR':
-                if self._DestructorList == None:
-                    self._DestructorList = []
-                if Record[1] == '':
-                    continue
-                self._DestructorList.append(Record[1])
-            elif Name == TAB_INF_DEFINES_CUSTOM_MAKEFILE:
-                TokenList = GetSplitValueList(Record[1])
-                if self._CustomMakefile == None:
-                    self._CustomMakefile = {}
-                if len(TokenList) < 2:
-                    self._CustomMakefile['MSFT'] = TokenList[0]
-                    self._CustomMakefile['GCC'] = TokenList[0]
-                else:
-                    if TokenList[0] not in ['MSFT', 'GCC']:
-                        EdkLogger.error("build", FORMAT_NOT_SUPPORTED,
-                                        "No supported family [%s]" % TokenList[0],
-                                        File=self.MetaFile, Line=Record[-1])
-                    self._CustomMakefile[TokenList[0]] = TokenList[1]
-            else:
-                if self._Defs == None:
-                    self._Defs = sdict()
-                self._Defs[Name] = Record[1]
-
-        #
-        # Retrieve information in sections specific to R8.x modules
-        #
-        if self._AutoGenVersion >= 0x00010005:   # _AutoGenVersion may be None, which is less than anything
-            if not self._ModuleType:
-                EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE,
-                                "MODULE_TYPE is not given", File=self.MetaFile)
-            if self._Defs and 'PCI_DEVICE_ID' in self._Defs and 'PCI_VENDOR_ID' in self._Defs \
-               and 'PCI_CLASS_CODE' in self._Defs:
-                self._BuildType = 'UEFI_OPTIONROM'
-            else:
-                self._BuildType = self._ModuleType.upper()
-        else:
-            self._BuildType = self._ComponentType.upper()
-            if not self._ComponentType:
-                EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE,
-                                "COMPONENT_TYPE is not given", File=self.MetaFile)
-            if self._ComponentType in self._MODULE_TYPE_:
-                self._ModuleType = self._MODULE_TYPE_[self._ComponentType]
-            if self._ComponentType == 'LIBRARY':
-                self._LibraryClass = [LibraryClassObject(self._BaseName, SUP_MODULE_LIST)]
-            # make use some [nmake] section macros
-            RecordList = self._RawData[MODEL_META_DATA_NMAKE, self._Arch, self._Platform]
-            for Name,Value,Dummy,Arch,Platform,ID,LineNo in RecordList:
-                Value = Value.replace('$(PROCESSOR)', self._Arch)
-                Name = Name.replace('$(PROCESSOR)', self._Arch)
-                Name, Value = ReplaceMacros((Name, Value), GlobalData.gEdkGlobal, True)
-                if Name == "IMAGE_ENTRY_POINT":
-                    if self._ModuleEntryPointList == None:
-                        self._ModuleEntryPointList = []
-                    self._ModuleEntryPointList.append(Value)
-                elif Name == "DPX_SOURCE":
-                    Macros = {"EDK_SOURCE":GlobalData.gEcpSource, "EFI_SOURCE":GlobalData.gEfiSource}
-                    Macros.update(self._Macros)
-                    File = PathClass(NormPath(Value, Macros), self._ModuleDir, Arch=self._Arch)
-                    # check the file validation
-                    ErrorCode, ErrorInfo = File.Validate(".dxs", CaseSensitive=False)
-                    if ErrorCode != 0:
-                        EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo,
-                                        File=self.MetaFile, Line=LineNo)
-                    if self.Sources == None:
-                        self._Sources = []
-                    self._Sources.append(File)
-                else:
-                    ToolList = self._NMAKE_FLAG_PATTERN_.findall(Name)
-                    if len(ToolList) == 0 or len(ToolList) != 1:
-                        pass
-#                        EdkLogger.warn("build", "Don't know how to do with macro [%s]" % Name,
-#                                       File=self.MetaFile, Line=LineNo)
-                    else:
-                        if self._BuildOptions == None:
-                            self._BuildOptions = sdict()
-
-                        if ToolList[0] in self._TOOL_CODE_:
-                            Tool = self._TOOL_CODE_[ToolList[0]]
-                        else:
-                            Tool = ToolList[0]
-                        ToolChain = "*_*_*_%s_FLAGS" % Tool
-                        ToolChainFamily = 'MSFT'    # R8.x only support MSFT tool chain
-                        #ignore not replaced macros in value
-                        ValueList = GetSplitValueList(' ' + Value, '/D')
-                        Dummy = ValueList[0]
-                        for Index in range(1, len(ValueList)):
-                            if ValueList[Index][-1] == '=' or ValueList[Index] == '':
-                                continue
-                            Dummy = Dummy + ' /D ' + ValueList[Index]
-                        Value = Dummy.strip()
-                        if (ToolChainFamily, ToolChain) not in self._BuildOptions:
-                            self._BuildOptions[ToolChainFamily, ToolChain] = Value
-                        else:
-                            OptionString = self._BuildOptions[ToolChainFamily, ToolChain]
-                            self._BuildOptions[ToolChainFamily, ToolChain] = OptionString + " " + Value
-        # set _Header to non-None in order to avoid database re-querying
-        self._Header_ = 'DUMMY'
-
-    ## Retrieve file version
-    def _GetInfVersion(self):
-        if self._AutoGenVersion == None:
-            if self._Header_ == None:
-                self._GetHeaderInfo()
-            if self._AutoGenVersion == None:
-                self._AutoGenVersion = 0x00010000
-        return self._AutoGenVersion
-
-    ## Retrieve BASE_NAME
-    def _GetBaseName(self):
-        if self._BaseName == None:
-            if self._Header_ == None:
-                self._GetHeaderInfo()
-            if self._BaseName == None:
-                EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No BASE_NAME name", File=self.MetaFile)
-        return self._BaseName
-
-    ## Retrieve MODULE_TYPE
-    def _GetModuleType(self):
-        if self._ModuleType == None:
-            if self._Header_ == None:
-                self._GetHeaderInfo()
-            if self._ModuleType == None:
-                self._ModuleType = 'BASE'
-            if self._ModuleType not in SUP_MODULE_LIST:
-                self._ModuleType = "USER_DEFINED"
-        return self._ModuleType
-
-    ## Retrieve COMPONENT_TYPE
-    def _GetComponentType(self):
-        if self._ComponentType == None:
-            if self._Header_ == None:
-                self._GetHeaderInfo()
-            if self._ComponentType == None:
-                self._ComponentType = 'USER_DEFINED'
-        return self._ComponentType
-
-    ## Retrieve "BUILD_TYPE"
-    def _GetBuildType(self):
-        if self._BuildType == None:
-            if self._Header_ == None:
-                self._GetHeaderInfo()
-            if not self._BuildType:
-                self._BuildType = "BASE"
-        return self._BuildType
-
-    ## Retrieve file guid
-    def _GetFileGuid(self):
-        if self._Guid == None:
-            if self._Header_ == None:
-                self._GetHeaderInfo()
-            if self._Guid == None:
-                self._Guid = '00000000-0000-0000-000000000000'
-        return self._Guid
-
-    ## Retrieve module version
-    def _GetVersion(self):
-        if self._Version == None:
-            if self._Header_ == None:
-                self._GetHeaderInfo()
-            if self._Version == None:
-                self._Version = '0.0'
-        return self._Version
-
-    ## Retrieve PCD_IS_DRIVER
-    def _GetPcdIsDriver(self):
-        if self._PcdIsDriver == None:
-            if self._Header_ == None:
-                self._GetHeaderInfo()
-            if self._PcdIsDriver == None:
-                self._PcdIsDriver = ''
-        return self._PcdIsDriver
-
-    ## Retrieve SHADOW
-    def _GetShadow(self):
-        if self._Shadow == None:
-            if self._Header_ == None:
-                self._GetHeaderInfo()
-            if self._Shadow != None and self._Shadow.upper() == 'TRUE':
-                self._Shadow = True
-            else:
-                self._Shadow = False
-        return self._Shadow
-
-    ## Retrieve CUSTOM_MAKEFILE
-    def _GetMakefile(self):
-        if self._CustomMakefile == None:
-            if self._Header_ == None:
-                self._GetHeaderInfo()
-            if self._CustomMakefile == None:
-                self._CustomMakefile = {}
-        return self._CustomMakefile
-
-    ## Retrieve EFI_SPECIFICATION_VERSION
-    def _GetSpec(self):
-        if self._Specification == None:
-            if self._Header_ == None:
-                self._GetHeaderInfo()
-            if self._Specification == None:
-                self._Specification = {}
-        return self._Specification
-
-    ## Retrieve LIBRARY_CLASS
-    def _GetLibraryClass(self):
-        if self._LibraryClass == None:
-            if self._Header_ == None:
-                self._GetHeaderInfo()
-            if self._LibraryClass == None:
-                self._LibraryClass = []
-        return self._LibraryClass
-
-    ## Retrieve ENTRY_POINT
-    def _GetEntryPoint(self):
-        if self._ModuleEntryPointList == None:
-            if self._Header_ == None:
-                self._GetHeaderInfo()
-            if self._ModuleEntryPointList == None:
-                self._ModuleEntryPointList = []
-        return self._ModuleEntryPointList
-
-    ## Retrieve UNLOAD_IMAGE
-    def _GetUnloadImage(self):
-        if self._ModuleUnloadImageList == None:
-            if self._Header_ == None:
-                self._GetHeaderInfo()
-            if self._ModuleUnloadImageList == None:
-                self._ModuleUnloadImageList = []
-        return self._ModuleUnloadImageList
-
-    ## Retrieve CONSTRUCTOR
-    def _GetConstructor(self):
-        if self._ConstructorList == None:
-            if self._Header_ == None:
-                self._GetHeaderInfo()
-            if self._ConstructorList == None:
-                self._ConstructorList = []
-        return self._ConstructorList
-
-    ## Retrieve DESTRUCTOR
-    def _GetDestructor(self):
-        if self._DestructorList == None:
-            if self._Header_ == None:
-                self._GetHeaderInfo()
-            if self._DestructorList == None:
-                self._DestructorList = []
-        return self._DestructorList
-
-    ## Retrieve definies other than above ones
-    def _GetDefines(self):
-        if self._Defs == None:
-            if self._Header_ == None:
-                self._GetHeaderInfo()
-            if self._Defs == None:
-                self._Defs = sdict()
-        return self._Defs
-
-    ## Retrieve binary files
-    def _GetBinaryFiles(self):
-        if self._Binaries == None:
-            self._Binaries = []
-            RecordList = self._RawData[MODEL_EFI_BINARY_FILE, self._Arch, self._Platform]
-            Macros = {"EDK_SOURCE":GlobalData.gEcpSource, "EFI_SOURCE":GlobalData.gEfiSource, 'PROCESSOR':self._Arch}
-            Macros.update(self._Macros)
-            for Record in RecordList:
-                Record = ReplaceMacros(Record, GlobalData.gEdkGlobal, False)
-                FileType = Record[0]
-                LineNo = Record[-1]
-                Target = 'COMMON'
-                FeatureFlag = []
-                if Record[2]:
-                    TokenList = GetSplitValueList(Record[2], TAB_VALUE_SPLIT)
-                    if TokenList:
-                        Target = TokenList[0]
-                    if len(TokenList) > 1:
-                        FeatureFlag = Record[1:]
-
-                File = PathClass(NormPath(Record[1], Macros), self._ModuleDir, '', FileType, True, self._Arch, '', Target)
-                # check the file validation
-                ErrorCode, ErrorInfo = File.Validate()
-                if ErrorCode != 0:
-                    EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo, File=self.MetaFile, Line=LineNo)
-                self._Binaries.append(File)
-        return self._Binaries
-
-    ## Retrieve source files
-    def _GetSourceFiles(self):
-        if self._Sources == None:
-            self._Sources = []
-            RecordList = self._RawData[MODEL_EFI_SOURCE_FILE, self._Arch, self._Platform]
-            Macros = {"EDK_SOURCE":GlobalData.gEcpSource, "EFI_SOURCE":GlobalData.gEfiSource, 'PROCESSOR':self._Arch}
-            Macros.update(self._Macros)
-            for Record in RecordList:
-                Record = ReplaceMacros(Record, GlobalData.gEdkGlobal, False)
-                LineNo = Record[-1]
-                ToolChainFamily = Record[1]
-                TagName = Record[2]
-                ToolCode = Record[3]
-                FeatureFlag = Record[4]
-                if self._AutoGenVersion < 0x00010005:
-                    # old module source files (R8)
-                    File = PathClass(NormPath(Record[0], Macros), self._ModuleDir, self._SourceOverridePath,
-                                     '', False, self._Arch, ToolChainFamily, '', TagName, ToolCode)
-                    # check the file validation
-                    ErrorCode, ErrorInfo = File.Validate(CaseSensitive=False)
-                    if ErrorCode != 0:
-                        if File.Ext.lower() == '.h':
-                            EdkLogger.warn('build', 'Include file not found', ExtraData=ErrorInfo,
-                                           File=self.MetaFile, Line=LineNo)
-                            continue
-                        else:
-                            EdkLogger.error('build', ErrorCode, ExtraData=File, File=self.MetaFile, Line=LineNo)
-                else:
-                    File = PathClass(NormPath(Record[0], Macros), self._ModuleDir, '',
-                                     '', False, self._Arch, ToolChainFamily, '', TagName, ToolCode)
-                    # check the file validation
-                    ErrorCode, ErrorInfo = File.Validate()
-                    if ErrorCode != 0:
-                        EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo, File=self.MetaFile, Line=LineNo)
-
-                self._Sources.append(File)
-        return self._Sources
-
-    ## Retrieve library classes employed by this module
-    def _GetLibraryClassUses(self):
-        if self._LibraryClasses == None:
-            self._LibraryClasses = sdict()
-            RecordList = self._RawData[MODEL_EFI_LIBRARY_CLASS, self._Arch, self._Platform]
-            for Record in RecordList:
-                Record = ReplaceMacros(Record, GlobalData.gEdkGlobal, False)
-                Lib = Record[0]
-                Instance = Record[1]
-                if Instance != None and Instance != '':
-                    Instance = NormPath(Instance, self._Macros)
-                self._LibraryClasses[Lib] = Instance
-        return self._LibraryClasses
-
-    ## Retrieve library names (for R8.x style of modules)
-    def _GetLibraryNames(self):
-        if self._Libraries == None:
-            self._Libraries = []
-            RecordList = self._RawData[MODEL_EFI_LIBRARY_INSTANCE, self._Arch, self._Platform]
-            for Record in RecordList:
-                # in case of name with '.lib' extension, which is unusual in R8.x inf
-                Record = ReplaceMacros(Record, GlobalData.gEdkGlobal, False)
-                LibraryName = os.path.splitext(Record[0])[0]
-                if LibraryName not in self._Libraries:
-                    self._Libraries.append(LibraryName)
-        return self._Libraries
-
-    ## Retrieve protocols consumed/produced by this module
-    def _GetProtocols(self):
-        if self._Protocols == None:
-            self._Protocols = sdict()
-            RecordList = self._RawData[MODEL_EFI_PROTOCOL, self._Arch, self._Platform]
-            for Record in RecordList:
-                CName = Record[0]
-                Value = ProtocolValue(CName, self.Packages)
-                if Value == None:
-                    PackageList = "\n\t".join([str(P) for P in self.Packages])
-                    EdkLogger.error('build', RESOURCE_NOT_AVAILABLE,
-                                    "Value of Protocol [%s] is not found under [Protocols] section in" % CName,
-                                    ExtraData=PackageList, File=self.MetaFile, Line=Record[-1])
-                self._Protocols[CName] = Value
-        return self._Protocols
-
-    ## Retrieve PPIs consumed/produced by this module
-    def _GetPpis(self):
-        if self._Ppis == None:
-            self._Ppis = sdict()
-            RecordList = self._RawData[MODEL_EFI_PPI, self._Arch, self._Platform]
-            for Record in RecordList:
-                CName = Record[0]
-                Value = PpiValue(CName, self.Packages)
-                if Value == None:
-                    PackageList = "\n\t".join([str(P) for P in self.Packages])
-                    EdkLogger.error('build', RESOURCE_NOT_AVAILABLE,
-                                    "Value of PPI [%s] is not found under [Ppis] section in " % CName,
-                                    ExtraData=PackageList, File=self.MetaFile, Line=Record[-1])
-                self._Ppis[CName] = Value
-        return self._Ppis
-
-    ## Retrieve GUIDs consumed/produced by this module
-    def _GetGuids(self):
-        if self._Guids == None:
-            self._Guids = sdict()
-            RecordList = self._RawData[MODEL_EFI_GUID, self._Arch, self._Platform]
-            for Record in RecordList:
-                CName = Record[0]
-                Value = GuidValue(CName, self.Packages)
-                if Value == None:
-                    PackageList = "\n\t".join([str(P) for P in self.Packages])
-                    EdkLogger.error('build', RESOURCE_NOT_AVAILABLE,
-                                    "Value of Guid [%s] is not found under [Guids] section in" % CName,
-                                    ExtraData=PackageList, File=self.MetaFile, Line=Record[-1])
-                self._Guids[CName] = Value
-        return self._Guids
-
-    ## Retrieve include paths necessary for this module (for R8.x style of modules)
-    def _GetIncludes(self):
-        if self._Includes == None:
-            self._Includes = []
-            if self._SourceOverridePath:
-                self._Includes.append(self._SourceOverridePath)
-            RecordList = self._RawData[MODEL_EFI_INCLUDE, self._Arch, self._Platform]
-            # [includes] section must be used only in old (R8.x) inf file
-            if self.AutoGenVersion >= 0x00010005 and len(RecordList) > 0:
-                EdkLogger.error('build', FORMAT_NOT_SUPPORTED, "No [include] section allowed",
-                                File=self.MetaFile, Line=RecordList[0][-1]-1)
-            for Record in RecordList:
-                Record = ReplaceMacros(Record, GlobalData.gEdkGlobal, False)
-                Record[0] = Record[0].replace('$(PROCESSOR)', self._Arch)
-                Record[0] = ReplaceMacro(Record[0], {'EFI_SOURCE' : GlobalData.gEfiSource}, False)
-                if Record[0].find('EDK_SOURCE') > -1:
-                    File = NormPath(ReplaceMacro(Record[0], {'EDK_SOURCE' : GlobalData.gEcpSource}, False), self._Macros)
-                    if File[0] == '.':
-                        File = os.path.join(self._ModuleDir, File)
-                    else:
-                        File = os.path.join(GlobalData.gWorkspace, File)
-                    File = RealPath(os.path.normpath(File))
-                    if File:
-                        self._Includes.append(File)
-
-                    #TRICK: let compiler to choose correct header file
-                    File = NormPath(ReplaceMacro(Record[0], {'EDK_SOURCE' : GlobalData.gEdkSource}, False), self._Macros)
-                    if File[0] == '.':
-                        File = os.path.join(self._ModuleDir, File)
-                    else:
-                        File = os.path.join(GlobalData.gWorkspace, File)
-                    File = RealPath(os.path.normpath(File))
-                    if File:
-                        self._Includes.append(File)
-                else:
-                    File = NormPath(Record[0], self._Macros)
-                    if File[0] == '.':
-                        File = os.path.join(self._ModuleDir, File)
-                    else:
-                        File = os.path.join(GlobalData.gWorkspace, File)
-                    File = RealPath(os.path.normpath(File))
-                    if File:
-                        self._Includes.append(File)
-        return self._Includes
-
-    ## Retrieve packages this module depends on
-    def _GetPackages(self):
-        if self._Packages == None:
-            self._Packages = []
-            RecordList = self._RawData[MODEL_META_DATA_PACKAGE, self._Arch, self._Platform]
-            Macros = {"EDK_SOURCE":GlobalData.gEcpSource, "EFI_SOURCE":GlobalData.gEfiSource}
-            Macros.update(self._Macros)
-            for Record in RecordList:
-                File = PathClass(NormPath(Record[0], Macros), GlobalData.gWorkspace, Arch=self._Arch)
-                LineNo = Record[-1]
-                # check the file validation
-                ErrorCode, ErrorInfo = File.Validate('.dec')
-                if ErrorCode != 0:
-                    EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo, File=self.MetaFile, Line=LineNo)
-                # parse this package now. we need it to get protocol/ppi/guid value
-                Package = self._Bdb[File, self._Arch]
-                self._Packages.append(Package)
-        return self._Packages
-
-    ## Retrieve PCDs used in this module
-    def _GetPcds(self):
-        if self._Pcds == None:
-            self._Pcds = {}
-            self._Pcds.update(self._GetPcd(MODEL_PCD_FIXED_AT_BUILD))
-            self._Pcds.update(self._GetPcd(MODEL_PCD_PATCHABLE_IN_MODULE))
-            self._Pcds.update(self._GetPcd(MODEL_PCD_FEATURE_FLAG))
-            self._Pcds.update(self._GetPcd(MODEL_PCD_DYNAMIC))
-            self._Pcds.update(self._GetPcd(MODEL_PCD_DYNAMIC_EX))
-        return self._Pcds
-
-    ## Retrieve build options specific to this module
-    def _GetBuildOptions(self):
-        if self._BuildOptions == None:
-            self._BuildOptions = sdict()
-            RecordList = self._RawData[MODEL_META_DATA_BUILD_OPTION, self._Arch, self._Platform]
-            for Record in RecordList:
-                ToolChainFamily = Record[0]
-                ToolChain = Record[1]
-                Option = Record[2]
-                if (ToolChainFamily, ToolChain) not in self._BuildOptions:
-                    self._BuildOptions[ToolChainFamily, ToolChain] = Option
-                else:
-                    # concatenate the option string if they're for the same tool
-                    OptionString = self._BuildOptions[ToolChainFamily, ToolChain]
-                    self._BuildOptions[ToolChainFamily, ToolChain] = OptionString + " " + Option
-        return self._BuildOptions
-
-    ## Retrieve depedency expression
-    def _GetDepex(self):
-        if self._Depex == None:
-            self._Depex = tdict(False, 2)
-            RecordList = self._RawData[MODEL_EFI_DEPEX, self._Arch]
-
-            # PEIM and DXE drivers must have a valid [Depex] section
-            if len(self.LibraryClass) == 0 and len(RecordList) == 0:
-                if self.ModuleType == 'DXE_DRIVER' or self.ModuleType == 'PEIM' or self.ModuleType == 'DXE_SMM_DRIVER' or \
-                    self.ModuleType == 'DXE_SAL_DRIVER' or self.ModuleType == 'DXE_RUNTIME_DRIVER':
-                    EdkLogger.error('build', RESOURCE_NOT_AVAILABLE, "No [Depex] section or no valid expression in [Depex] section for [%s] module" \
-                                    % self.ModuleType, File=self.MetaFile)
-
-            Depex = {}
-            for Record in RecordList:
-                Record = ReplaceMacros(Record, GlobalData.gEdkGlobal, False)
-                Arch = Record[3]
-                ModuleType = Record[4]
-                TokenList = Record[0].split()
-                if (Arch, ModuleType) not in Depex:
-                    Depex[Arch, ModuleType] = []
-                DepexList = Depex[Arch, ModuleType]
-                for Token in TokenList:
-                    if Token in DEPEX_SUPPORTED_OPCODE:
-                        DepexList.append(Token)
-                    elif Token.endswith(".inf"):    # module file name
-                        ModuleFile = os.path.normpath(Token)
-                        Module = self.BuildDatabase[ModuleFile]
-                        if Module == None:
-                            EdkLogger.error('build', RESOURCE_NOT_AVAILABLE, "Module is not found in active platform",
-                                            ExtraData=Token, File=self.MetaFile, Line=Record[-1])
-                        DepexList.append(Module.Guid)
-                    else:
-                        # get the GUID value now
-                        Value = ProtocolValue(Token, self.Packages)
-                        if Value == None:
-                            Value = PpiValue(Token, self.Packages)
-                            if Value == None:
-                                Value = GuidValue(Token, self.Packages)
-                        if Value == None:
-                            PackageList = "\n\t".join([str(P) for P in self.Packages])
-                            EdkLogger.error('build', RESOURCE_NOT_AVAILABLE,
-                                            "Value of [%s] is not found in" % Token,
-                                            ExtraData=PackageList, File=self.MetaFile, Line=Record[-1])
-                        DepexList.append(Value)
-            for Arch, ModuleType in Depex:
-                self._Depex[Arch, ModuleType] = Depex[Arch, ModuleType]
-        return self._Depex
-
-    ## Retrieve PCD for given type
-    def _GetPcd(self, Type):
-        Pcds = {}
-        PcdDict = tdict(True, 4)
-        PcdSet = set()
-        RecordList = self._RawData[Type, self._Arch, self._Platform]
-        for TokenSpaceGuid, PcdCName, Setting, Arch, Platform, Dummy1, LineNo in RecordList:
-            PcdDict[Arch, Platform, PcdCName, TokenSpaceGuid] = (Setting, LineNo)
-            PcdSet.add((PcdCName, TokenSpaceGuid))
-            # get the guid value
-            if TokenSpaceGuid not in self.Guids:
-                Value = GuidValue(TokenSpaceGuid, self.Packages)
-                if Value == None:
-                    PackageList = "\n\t".join([str(P) for P in self.Packages])
-                    EdkLogger.error('build', RESOURCE_NOT_AVAILABLE,
-                                    "Value of Guid [%s] is not found under [Guids] section in" % TokenSpaceGuid,
-                                    ExtraData=PackageList, File=self.MetaFile, Line=LineNo)
-                self.Guids[TokenSpaceGuid] = Value
-
-        # resolve PCD type, value, datum info, etc. by getting its definition from package
-        for PcdCName, TokenSpaceGuid in PcdSet:
-            ValueList = ['', '']
-            Setting, LineNo = PcdDict[self._Arch, self.Platform, PcdCName, TokenSpaceGuid]
-            if Setting == None:
-                continue
-            TokenList = Setting.split(TAB_VALUE_SPLIT)
-            ValueList[0:len(TokenList)] = TokenList
-            DefaultValue = ValueList[0]
-            Pcd = PcdClassObject(
-                    PcdCName,
-                    TokenSpaceGuid,
-                    '',
-                    '',
-                    DefaultValue,
-                    '',
-                    '',
-                    {},
-                    self.Guids[TokenSpaceGuid]
-                    )
-
-            # get necessary info from package declaring this PCD
-            for Package in self.Packages:
-                #
-                # 'dynamic' in INF means its type is determined by platform;
-                # if platform doesn't give its type, use 'lowest' one in the
-                # following order, if any
-                #
-                #   "FixedAtBuild", "PatchableInModule", "FeatureFlag", "Dynamic", "DynamicEx"
-                #
-                PcdType = self._PCD_TYPE_STRING_[Type]
-                if Type in [MODEL_PCD_DYNAMIC, MODEL_PCD_DYNAMIC_EX]:
-                    Pcd.Pending = True
-                    for T in ["FixedAtBuild", "PatchableInModule", "FeatureFlag", "Dynamic", "DynamicEx"]:
-                        if (PcdCName, TokenSpaceGuid, T) in Package.Pcds:
-                            PcdType = T
-                            break
-                else:
-                    Pcd.Pending = False
-
-                if (PcdCName, TokenSpaceGuid, PcdType) in Package.Pcds:
-                    PcdInPackage = Package.Pcds[PcdCName, TokenSpaceGuid, PcdType]
-                    Pcd.Type = PcdType
-                    Pcd.TokenValue = PcdInPackage.TokenValue
-                    Pcd.DatumType = PcdInPackage.DatumType
-                    Pcd.MaxDatumSize = PcdInPackage.MaxDatumSize
-                    if Pcd.DefaultValue in [None, '']:
-                        Pcd.DefaultValue = PcdInPackage.DefaultValue
-                    break
-            else:
-                EdkLogger.error(
-                            'build',
-                            PARSER_ERROR,
-                            "PCD [%s.%s] in [%s] is not found in dependent packages:" % (TokenSpaceGuid, PcdCName, self.MetaFile),
-                            File =self.MetaFile, Line=LineNo,
-                            ExtraData="\t%s" % '\n\t'.join([str(P) for P in self.Packages])
-                            )
-            Pcds[PcdCName, TokenSpaceGuid] = Pcd
-        return Pcds
-
-    Arch                    = property(_GetArch, _SetArch)
-    Platform                = property(_GetPlatform, _SetPlatform)
-
-    AutoGenVersion          = property(_GetInfVersion)
-    BaseName                = property(_GetBaseName)
-    ModuleType              = property(_GetModuleType)
-    ComponentType           = property(_GetComponentType)
-    BuildType               = property(_GetBuildType)
-    Guid                    = property(_GetFileGuid)
-    Version                 = property(_GetVersion)
-    PcdIsDriver             = property(_GetPcdIsDriver)
-    Shadow                  = property(_GetShadow)
-    CustomMakefile          = property(_GetMakefile)
-    Specification           = property(_GetSpec)
-    LibraryClass            = property(_GetLibraryClass)
-    ModuleEntryPointList    = property(_GetEntryPoint)
-    ModuleUnloadImageList   = property(_GetUnloadImage)
-    ConstructorList         = property(_GetConstructor)
-    DestructorList          = property(_GetDestructor)
-    Defines                 = property(_GetDefines)
-
-    Binaries                = property(_GetBinaryFiles)
-    Sources                 = property(_GetSourceFiles)
-    LibraryClasses          = property(_GetLibraryClassUses)
-    Libraries               = property(_GetLibraryNames)
-    Protocols               = property(_GetProtocols)
-    Ppis                    = property(_GetPpis)
-    Guids                   = property(_GetGuids)
-    Includes                = property(_GetIncludes)
-    Packages                = property(_GetPackages)
-    Pcds                    = property(_GetPcds)
-    BuildOptions            = property(_GetBuildOptions)
-    Depex                   = property(_GetDepex)
-
-## Database
-#
-#   This class defined the build databse for all modules, packages and platform.
-# It will call corresponding parser for the given file if it cannot find it in
-# the database.
-#
-# @param DbPath             Path of database file
-# @param GlobalMacros       Global macros used for replacement during file parsing
-# @prarm RenewDb=False      Create new database file if it's already there
-#
-class WorkspaceDatabase(object):
-    # file parser
-    _FILE_PARSER_ = {
-        MODEL_FILE_INF  :   InfParser,
-        MODEL_FILE_DEC  :   DecParser,
-        MODEL_FILE_DSC  :   DscParser,
-        MODEL_FILE_FDF  :   None, #FdfParser,
-        MODEL_FILE_CIF  :   None
-    }
-
-    # file table
-    _FILE_TABLE_ = {
-        MODEL_FILE_INF  :   ModuleTable,
-        MODEL_FILE_DEC  :   PackageTable,
-        MODEL_FILE_DSC  :   PlatformTable,
-    }
-
-    # default database file path
-    _DB_PATH_ = "Conf/.cache/build.db"
-
-    #
-    # internal class used for call corresponding file parser and caching the result
-    # to avoid unnecessary re-parsing
-    #
-    class BuildObjectFactory(object):
-        _FILE_TYPE_ = {
-            ".inf"  : MODEL_FILE_INF,
-            ".dec"  : MODEL_FILE_DEC,
-            ".dsc"  : MODEL_FILE_DSC,
-            ".fdf"  : MODEL_FILE_FDF,
-        }
-
-        # convert to xxxBuildData object
-        _GENERATOR_ = {
-            MODEL_FILE_INF  :   InfBuildData,
-            MODEL_FILE_DEC  :   DecBuildData,
-            MODEL_FILE_DSC  :   DscBuildData,
-            MODEL_FILE_FDF  :   None #FlashDefTable,
-        }
-
-        _CACHE_ = {}    # (FilePath, Arch)  : <object>
-
-        # constructor
-        def __init__(self, WorkspaceDb):
-            self.WorkspaceDb = WorkspaceDb
-
-        # key = (FilePath, Arch='COMMON')
-        def __contains__(self, Key):
-            FilePath = Key[0]
-            Arch = 'COMMON'
-            if len(Key) > 1:
-                Arch = Key[1]
-            return (FilePath, Arch) in self._CACHE_
-
-        # key = (FilePath, Arch='COMMON')
-        def __getitem__(self, Key):
-            FilePath = Key[0]
-            Arch = 'COMMON'
-            Platform = 'COMMON'
-            if len(Key) > 1:
-                Arch = Key[1]
-            if len(Key) > 2:
-                Platform = Key[2]
-
-            # if it's generated before, just return the cached one
-            Key = (FilePath, Arch)
-            if Key in self._CACHE_:
-                return self._CACHE_[Key]
-
-            # check file type
-            Ext = FilePath.Ext.lower()
-            if Ext not in self._FILE_TYPE_:
-                return None
-            FileType = self._FILE_TYPE_[Ext]
-            if FileType not in self._GENERATOR_:
-                return None
-
-            # get table for current file
-            MetaFile = self.WorkspaceDb[FilePath, FileType, self.WorkspaceDb._GlobalMacros]
-            BuildObject = self._GENERATOR_[FileType](
-                                    FilePath,
-                                    MetaFile,
-                                    self,
-                                    Arch,
-                                    Platform,
-                                    self.WorkspaceDb._GlobalMacros,
-                                    )
-            self._CACHE_[Key] = BuildObject
-            return BuildObject
-
-    # placeholder for file format conversion
-    class TransformObjectFactory:
-        def __init__(self, WorkspaceDb):
-            self.WorkspaceDb = WorkspaceDb
-
-        # key = FilePath, Arch
-        def __getitem__(self, Key):
-            pass
-
-    ## Constructor of WorkspaceDatabase
-    #
-    # @param DbPath             Path of database file
-    # @param GlobalMacros       Global macros used for replacement during file parsing
-    # @prarm RenewDb=False      Create new database file if it's already there
-    #
-    def __init__(self, DbPath, GlobalMacros={}, RenewDb=False):
-        self._GlobalMacros = GlobalMacros
-
-        if DbPath == None or DbPath == '':
-            DbPath = os.path.normpath(os.path.join(GlobalData.gWorkspace, self._DB_PATH_))
-
-        # don't create necessary path for db in memory
-        if DbPath != ':memory:':
-            DbDir = os.path.split(DbPath)[0]
-            if not os.path.exists(DbDir):
-                os.makedirs(DbDir)
-
-            # remove db file in case inconsistency between db and file in file system
-            if self._CheckWhetherDbNeedRenew(RenewDb, DbPath):
-                os.remove(DbPath)
-        
-        # create db with optimized parameters
-        self.Conn = sqlite3.connect(DbPath, isolation_level='DEFERRED')
-        self.Conn.execute("PRAGMA synchronous=OFF")
-        self.Conn.execute("PRAGMA temp_store=MEMORY")
-        self.Conn.execute("PRAGMA count_changes=OFF")
-        self.Conn.execute("PRAGMA cache_size=8192")
-        #self.Conn.execute("PRAGMA page_size=8192")
-
-        # to avoid non-ascii character conversion issue
-        self.Conn.text_factory = str
-        self.Cur = self.Conn.cursor()
-
-        # create table for internal uses
-        self.TblDataModel = TableDataModel(self.Cur)
-        self.TblFile = TableFile(self.Cur)
-
-        # conversion object for build or file format conversion purpose
-        self.BuildObject = WorkspaceDatabase.BuildObjectFactory(self)
-        self.TransformObject = WorkspaceDatabase.TransformObjectFactory(self)
-
-    ## Check whether workspace database need to be renew.
-    #  The renew reason maybe:
-    #  1) If user force to renew;
-    #  2) If user do not force renew, and
-    #     a) If the time of last modified python source is newer than database file;
-    #     b) If the time of last modified frozen executable file is newer than database file;
-    #
-    #  @param force     User force renew database
-    #  @param DbPath    The absolute path of workspace database file
-    #
-    #  @return Bool value for whether need renew workspace databse
-    #
-    def _CheckWhetherDbNeedRenew (self, force, DbPath):
-        DbDir = os.path.split(DbPath)[0]
-        MacroFilePath = os.path.normpath(os.path.join(DbDir, "build.mac"))
-        MacroMatch = False
-        if os.path.exists(MacroFilePath) and os.path.isfile(MacroFilePath):
-            LastMacros = None
-            try:
-                f = open(MacroFilePath,'r')
-                LastMacros = pickle.load(f)
-                f.close()
-            except IOError:
-                pass
-            except:
-                f.close()
-
-            if LastMacros != None and type(LastMacros) is DictType:
-                if LastMacros == self._GlobalMacros:
-                    MacroMatch = True
-                    for Macro in LastMacros.keys():
-                        if not (Macro in self._GlobalMacros and LastMacros[Macro] == self._GlobalMacros[Macro]):
-                            MacroMatch = False;
-                            break;
-
-        if not MacroMatch:
-            # save command line macros to file
-            try:
-                f = open(MacroFilePath,'w')
-                pickle.dump(self._GlobalMacros, f, 2)
-                f.close()
-            except IOError:
-                pass
-            except:
-                f.close()
-
-            force = True
-
-        # if database does not exist, we need do nothing
-        if not os.path.exists(DbPath): return False
-            
-        # if user force to renew database, then not check whether database is out of date
-        if force: return True
-        
-        #    
-        # Check the time of last modified source file or build.exe
-        # if is newer than time of database, then database need to be re-created.
-        #
-        timeOfToolModified = 0
-        if hasattr(sys, "frozen"):
-            exePath             = os.path.abspath(sys.executable)
-            timeOfToolModified  = os.stat(exePath).st_mtime
-        else:
-            curPath  = os.path.dirname(__file__) # curPath is the path of WorkspaceDatabase.py
-            rootPath = os.path.split(curPath)[0] # rootPath is root path of python source, such as /BaseTools/Source/Python
-            if rootPath == "" or rootPath == None:
-                EdkLogger.verbose("\nFail to find the root path of build.exe or python sources, so can not \
-determine whether database file is out of date!\n")
-        
-            # walk the root path of source or build's binary to get the time last modified.
-        
-            for root, dirs, files in os.walk (rootPath):
-                for dir in dirs:
-                    # bypass source control folder 
-                    if dir.lower() in [".svn", "_svn", "cvs"]:
-                        dirs.remove(dir)
-                        
-                for file in files:
-                    ext = os.path.splitext(file)[1]
-                    if ext.lower() == ".py":            # only check .py files
-                        fd = os.stat(os.path.join(root, file))
-                        if timeOfToolModified < fd.st_mtime:
-                            timeOfToolModified = fd.st_mtime
-        if timeOfToolModified > os.stat(DbPath).st_mtime:
-            EdkLogger.verbose("\nWorkspace database is out of data!")
-            return True
-            
-        return False
-            
-    ## Initialize build database
-    def InitDatabase(self):
-        EdkLogger.verbose("\nInitialize build database started ...")
-
-        #
-        # Create new tables
-        #
-        self.TblDataModel.Create(False)
-        self.TblFile.Create(False)
-
-        #
-        # Initialize table DataModel
-        #
-        self.TblDataModel.InitTable()
-        EdkLogger.verbose("Initialize build database ... DONE!")
-
-    ## Query a table
-    #
-    # @param Table:  The instance of the table to be queried
-    #
-    def QueryTable(self, Table):
-        Table.Query()
-
-    ## Close entire database
-    #
-    # Commit all first
-    # Close the connection and cursor
-    #
-    def Close(self):
-        self.Conn.commit()
-        self.Cur.close()
-        self.Conn.close()
-
-    ## Get unique file ID for the gvien file
-    def GetFileId(self, FilePath):
-        return self.TblFile.GetFileId(FilePath)
-
-    ## Get file type value for the gvien file ID
-    def GetFileType(self, FileId):
-        return self.TblFile.GetFileType(FileId)
-
-    ## Get time stamp stored in file table
-    def GetTimeStamp(self, FileId):
-        return self.TblFile.GetFileTimeStamp(FileId)
-
-    ## Update time stamp in file table
-    def SetTimeStamp(self, FileId, TimeStamp):
-        return self.TblFile.SetFileTimeStamp(FileId, TimeStamp)
-
-    ## Check if a table integrity flag exists or not
-    def CheckIntegrity(self, TableName):
-        try:
-            Result = self.Cur.execute("select min(ID) from %s" % (TableName)).fetchall()
-            if Result[0][0] != -1:
-                return False
-        except:
-            return False
-        return True
-
-    ## Compose table name for given file type and file ID
-    def GetTableName(self, FileType, FileId):
-        return "_%s_%s" % (FileType, FileId)
-
-    ## Return a temp table containing all content of the given file
-    #
-    #   @param  FileInfo    The tuple containing path and type of a file
-    #
-    def __getitem__(self, FileInfo):
-        FilePath, FileType, Macros = FileInfo
-        if FileType not in self._FILE_TABLE_:
-            return None
-
-        # flag used to indicate if it's parsed or not
-        FilePath = str(FilePath)
-        Parsed = False
-        FileId = self.GetFileId(FilePath)
-        if FileId != None:
-            TimeStamp = os.stat(FilePath)[8]
-            TableName = self.GetTableName(FileType, FileId)
-            if TimeStamp != self.GetTimeStamp(FileId):
-                # update the timestamp in database
-                self.SetTimeStamp(FileId, TimeStamp)
-            else:
-                # if the table exists and is integrity, don't parse it
-                Parsed = self.CheckIntegrity(TableName)
-        else:
-            FileId = self.TblFile.InsertFile(FilePath, FileType)
-            TableName = self.GetTableName(FileType, FileId)
-
-        FileTable = self._FILE_TABLE_[FileType](self.Cur, TableName, FileId)
-        FileTable.Create(not Parsed)
-        Parser = self._FILE_PARSER_[FileType](FilePath, FileType, FileTable, Macros)
-        # set the "Finished" flag in parser in order to avoid re-parsing (if parsed)
-        Parser.Finished = Parsed
-        return Parser
-
-    ## Summarize all packages in the database
-    def _GetPackageList(self):
-        PackageList = []
-        for Module in self.ModuleList:
-            for Package in Module.Packages:
-                if Package not in PackageList:
-                    PackageList.append(Package)
-        return PackageList
-
-    ## Summarize all platforms in the database
-    def _GetPlatformList(self):
-        PlatformList = []
-        for PlatformFile in self.TblFile.GetFileList(MODEL_FILE_DSC):
-            try:
-                Platform = self.BuildObject[PathClass(PlatformFile), 'COMMON']
-            except:
-                Platform = None
-            if Platform != None:
-                PlatformList.append(Platform)
-        return PlatformList
-
-    ## Summarize all modules in the database
-    def _GetModuleList(self):
-        ModuleList = []
-        for ModuleFile in self.TblFile.GetFileList(MODEL_FILE_INF):
-            try:
-                Module = self.BuildObject[PathClass(ModuleFile), 'COMMON']
-            except:
-                Module = None
-            if Module != None:
-                ModuleList.append(Module)
-        return ModuleList
-
-    PlatformList = property(_GetPlatformList)
-    PackageList = property(_GetPackageList)
-    ModuleList = property(_GetModuleList)
-
-##
-#
-# This acts like the main() function for the script, unless it is 'import'ed into another
-# script.
-#
-if __name__ == '__main__':
-    pass
-
+## @file\r
+# This file is used to create a database used by build tool\r
+#\r
+# Copyright (c) 2008 - 2016, 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
+##\r
+# Import Modules\r
+#\r
+import sqlite3\r
+import Common.LongFilePathOs as os\r
+import pickle\r
+import uuid\r
+\r
+import Common.EdkLogger as EdkLogger\r
+import Common.GlobalData as GlobalData\r
+from Common.MultipleWorkspace import MultipleWorkspace as mws\r
+\r
+from Common.String import *\r
+from Common.DataType import *\r
+from Common.Misc import *\r
+from types import *\r
+\r
+from CommonDataClass.CommonClass import SkuInfoClass\r
+\r
+from MetaDataTable import *\r
+from MetaFileTable import *\r
+from MetaFileParser import *\r
+from BuildClassObject import *\r
+from WorkspaceCommon import GetDeclaredPcd\r
+from Common.Misc import AnalyzeDscPcd\r
+from Common.Misc import ProcessDuplicatedInf\r
+import re\r
+from Common.Parsing import IsValidWord\r
+from Common.VariableAttributes import VariableAttributes\r
+import Common.GlobalData as GlobalData\r
+\r
+## Platform build information from DSC file\r
+#\r
+#  This class is used to retrieve information stored in database and convert them\r
+# into PlatformBuildClassObject form for easier use for AutoGen.\r
+#\r
+class DscBuildData(PlatformBuildClassObject):\r
+    # dict used to convert PCD type in database to string used by build tool\r
+    _PCD_TYPE_STRING_ = {\r
+        MODEL_PCD_FIXED_AT_BUILD        :   "FixedAtBuild",\r
+        MODEL_PCD_PATCHABLE_IN_MODULE   :   "PatchableInModule",\r
+        MODEL_PCD_FEATURE_FLAG          :   "FeatureFlag",\r
+        MODEL_PCD_DYNAMIC               :   "Dynamic",\r
+        MODEL_PCD_DYNAMIC_DEFAULT       :   "Dynamic",\r
+        MODEL_PCD_DYNAMIC_HII           :   "DynamicHii",\r
+        MODEL_PCD_DYNAMIC_VPD           :   "DynamicVpd",\r
+        MODEL_PCD_DYNAMIC_EX            :   "DynamicEx",\r
+        MODEL_PCD_DYNAMIC_EX_DEFAULT    :   "DynamicEx",\r
+        MODEL_PCD_DYNAMIC_EX_HII        :   "DynamicExHii",\r
+        MODEL_PCD_DYNAMIC_EX_VPD        :   "DynamicExVpd",\r
+    }\r
+\r
+    # dict used to convert part of [Defines] to members of DscBuildData directly\r
+    _PROPERTY_ = {\r
+        #\r
+        # Required Fields\r
+        #\r
+        TAB_DSC_DEFINES_PLATFORM_NAME           :   "_PlatformName",\r
+        TAB_DSC_DEFINES_PLATFORM_GUID           :   "_Guid",\r
+        TAB_DSC_DEFINES_PLATFORM_VERSION        :   "_Version",\r
+        TAB_DSC_DEFINES_DSC_SPECIFICATION       :   "_DscSpecification",\r
+        #TAB_DSC_DEFINES_OUTPUT_DIRECTORY        :   "_OutputDirectory",\r
+        #TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES :   "_SupArchList",\r
+        #TAB_DSC_DEFINES_BUILD_TARGETS           :   "_BuildTargets",\r
+        TAB_DSC_DEFINES_SKUID_IDENTIFIER        :   "_SkuName",\r
+        #TAB_DSC_DEFINES_FLASH_DEFINITION        :   "_FlashDefinition",\r
+        TAB_DSC_DEFINES_BUILD_NUMBER            :   "_BuildNumber",\r
+        TAB_DSC_DEFINES_MAKEFILE_NAME           :   "_MakefileName",\r
+        TAB_DSC_DEFINES_BS_BASE_ADDRESS         :   "_BsBaseAddress",\r
+        TAB_DSC_DEFINES_RT_BASE_ADDRESS         :   "_RtBaseAddress",\r
+        #TAB_DSC_DEFINES_RFC_LANGUAGES           :   "_RFCLanguages",\r
+        #TAB_DSC_DEFINES_ISO_LANGUAGES           :   "_ISOLanguages",\r
+    }\r
+\r
+    # used to compose dummy library class name for those forced library instances\r
+    _NullLibraryNumber = 0\r
+\r
+    ## Constructor of DscBuildData\r
+    #\r
+    #  Initialize object of DscBuildData\r
+    #\r
+    #   @param      FilePath        The path of platform description file\r
+    #   @param      RawData         The raw data of DSC file\r
+    #   @param      BuildDataBase   Database used to retrieve module/package information\r
+    #   @param      Arch            The target architecture\r
+    #   @param      Platform        (not used for DscBuildData)\r
+    #   @param      Macros          Macros used for replacement in DSC file\r
+    #\r
+    def __init__(self, FilePath, RawData, BuildDataBase, Arch='COMMON', Target=None, Toolchain=None):\r
+        self.MetaFile = FilePath\r
+        self._RawData = RawData\r
+        self._Bdb = BuildDataBase\r
+        self._Arch = Arch\r
+        self._Target = Target\r
+        self._Toolchain = Toolchain\r
+        self._Clear()\r
+        self._HandleOverridePath()\r
+\r
+    ## XXX[key] = value\r
+    def __setitem__(self, key, value):\r
+        self.__dict__[self._PROPERTY_[key]] = value\r
+\r
+    ## value = XXX[key]\r
+    def __getitem__(self, key):\r
+        return self.__dict__[self._PROPERTY_[key]]\r
+\r
+    ## "in" test support\r
+    def __contains__(self, key):\r
+        return key in self._PROPERTY_\r
+\r
+    ## Set all internal used members of DscBuildData to None\r
+    def _Clear(self):\r
+        self._Header            = None\r
+        self._PlatformName      = None\r
+        self._Guid              = None\r
+        self._Version           = None\r
+        self._DscSpecification  = None\r
+        self._OutputDirectory   = None\r
+        self._SupArchList       = None\r
+        self._BuildTargets      = None\r
+        self._SkuName           = None\r
+        self._SkuIdentifier     = None\r
+        self._AvilableSkuIds = None\r
+        self._PcdInfoFlag       = None\r
+        self._VarCheckFlag = None\r
+        self._FlashDefinition   = None\r
+        self._Prebuild          = None\r
+        self._Postbuild         = None\r
+        self._BuildNumber       = None\r
+        self._MakefileName      = None\r
+        self._BsBaseAddress     = None\r
+        self._RtBaseAddress     = None\r
+        self._SkuIds            = None\r
+        self._Modules           = None\r
+        self._LibraryInstances  = None\r
+        self._LibraryClasses    = None\r
+        self._Pcds              = None\r
+        self._DecPcds           = None\r
+        self._BuildOptions      = None\r
+        self._ModuleTypeOptions = None\r
+        self._LoadFixAddress    = None\r
+        self._RFCLanguages      = None\r
+        self._ISOLanguages      = None\r
+        self._VpdToolGuid       = None\r
+        self.__Macros            = None\r
+\r
+\r
+    ## handle Override Path of Module\r
+    def _HandleOverridePath(self):\r
+        RecordList = self._RawData[MODEL_META_DATA_COMPONENT, self._Arch]\r
+        Macros = self._Macros\r
+        Macros["EDK_SOURCE"] = GlobalData.gEcpSource\r
+        for Record in RecordList:\r
+            ModuleId = Record[5]\r
+            LineNo = Record[6]\r
+            ModuleFile = PathClass(NormPath(Record[0]), GlobalData.gWorkspace, Arch=self._Arch)\r
+            RecordList = self._RawData[MODEL_META_DATA_COMPONENT_SOURCE_OVERRIDE_PATH, self._Arch, None, ModuleId]\r
+            if RecordList != []:\r
+                SourceOverridePath = mws.join(GlobalData.gWorkspace, NormPath(RecordList[0][0]))\r
+\r
+                # Check if the source override path exists\r
+                if not os.path.isdir(SourceOverridePath):\r
+                    EdkLogger.error('build', FILE_NOT_FOUND, Message='Source override path does not exist:', File=self.MetaFile, ExtraData=SourceOverridePath, Line=LineNo)\r
+\r
+                #Add to GlobalData Variables\r
+                GlobalData.gOverrideDir[ModuleFile.Key] = SourceOverridePath\r
+\r
+    ## Get current effective macros\r
+    def _GetMacros(self):\r
+        if self.__Macros == None:\r
+            self.__Macros = {}\r
+            self.__Macros.update(GlobalData.gPlatformDefines)\r
+            self.__Macros.update(GlobalData.gGlobalDefines)\r
+            self.__Macros.update(GlobalData.gCommandLineDefines)\r
+        return self.__Macros\r
+\r
+    ## Get architecture\r
+    def _GetArch(self):\r
+        return self._Arch\r
+\r
+    ## Set architecture\r
+    #\r
+    #   Changing the default ARCH to another may affect all other information\r
+    # because all information in a platform may be ARCH-related. That's\r
+    # why we need to clear all internal used members, in order to cause all\r
+    # information to be re-retrieved.\r
+    #\r
+    #   @param  Value   The value of ARCH\r
+    #\r
+    def _SetArch(self, Value):\r
+        if self._Arch == Value:\r
+            return\r
+        self._Arch = Value\r
+        self._Clear()\r
+\r
+    ## Retrieve all information in [Defines] section\r
+    #\r
+    #   (Retriving all [Defines] information in one-shot is just to save time.)\r
+    #\r
+    def _GetHeaderInfo(self):\r
+        RecordList = self._RawData[MODEL_META_DATA_HEADER, self._Arch]\r
+        for Record in RecordList:\r
+            Name = Record[1]\r
+            # items defined _PROPERTY_ don't need additional processing\r
+            \r
+            # some special items in [Defines] section need special treatment\r
+            if Name == TAB_DSC_DEFINES_OUTPUT_DIRECTORY:\r
+                self._OutputDirectory = NormPath(Record[2], self._Macros)\r
+                if ' ' in self._OutputDirectory:\r
+                    EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "No space is allowed in OUTPUT_DIRECTORY",\r
+                                    File=self.MetaFile, Line=Record[-1],\r
+                                    ExtraData=self._OutputDirectory)\r
+            elif Name == TAB_DSC_DEFINES_FLASH_DEFINITION:\r
+                self._FlashDefinition = PathClass(NormPath(Record[2], self._Macros), GlobalData.gWorkspace)\r
+                ErrorCode, ErrorInfo = self._FlashDefinition.Validate('.fdf')\r
+                if ErrorCode != 0:\r
+                    EdkLogger.error('build', ErrorCode, File=self.MetaFile, Line=Record[-1],\r
+                                    ExtraData=ErrorInfo)\r
+            elif Name == TAB_DSC_PREBUILD:\r
+                self._Prebuild = PathClass(NormPath(Record[2], self._Macros), GlobalData.gWorkspace)\r
+            elif Name == TAB_DSC_POSTBUILD:\r
+                self._Postbuild = PathClass(NormPath(Record[2], self._Macros), GlobalData.gWorkspace)\r
+            elif Name == TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES:\r
+                self._SupArchList = GetSplitValueList(Record[2], TAB_VALUE_SPLIT)\r
+            elif Name == TAB_DSC_DEFINES_BUILD_TARGETS:\r
+                self._BuildTargets = GetSplitValueList(Record[2])\r
+            elif Name == TAB_DSC_DEFINES_SKUID_IDENTIFIER:\r
+                if self._SkuName == None:\r
+                    self._SkuName = Record[2]\r
+                self._SkuIdentifier = Record[2]\r
+                self._AvilableSkuIds = Record[2]\r
+            elif Name == TAB_DSC_DEFINES_PCD_INFO_GENERATION:\r
+                self._PcdInfoFlag = Record[2]\r
+            elif Name == TAB_DSC_DEFINES_PCD_VAR_CHECK_GENERATION:\r
+                self._VarCheckFlag = Record[2]\r
+            elif Name == TAB_FIX_LOAD_TOP_MEMORY_ADDRESS:\r
+                try:\r
+                    self._LoadFixAddress = int (Record[2], 0)\r
+                except:\r
+                    EdkLogger.error("build", PARAMETER_INVALID, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (Record[2]))\r
+            elif Name == TAB_DSC_DEFINES_RFC_LANGUAGES:\r
+                if not Record[2] or Record[2][0] != '"' or Record[2][-1] != '"' or len(Record[2]) == 1:\r
+                    EdkLogger.error('build', FORMAT_NOT_SUPPORTED, 'language code for RFC_LANGUAGES must have double quotes around it, for example: RFC_LANGUAGES = "en-us;zh-hans"',\r
+                                    File=self.MetaFile, Line=Record[-1])\r
+                LanguageCodes = Record[2][1:-1]\r
+                if not LanguageCodes:\r
+                    EdkLogger.error('build', FORMAT_NOT_SUPPORTED, 'one or more RFC4646 format language code must be provided for RFC_LANGUAGES statement',\r
+                                    File=self.MetaFile, Line=Record[-1])                \r
+                LanguageList = GetSplitValueList(LanguageCodes, TAB_SEMI_COLON_SPLIT)\r
+                # check whether there is empty entries in the list\r
+                if None in LanguageList:\r
+                    EdkLogger.error('build', FORMAT_NOT_SUPPORTED, 'one or more empty language code is in RFC_LANGUAGES statement',\r
+                                    File=self.MetaFile, Line=Record[-1])                      \r
+                self._RFCLanguages = LanguageList\r
+            elif Name == TAB_DSC_DEFINES_ISO_LANGUAGES:\r
+                if not Record[2] or Record[2][0] != '"' or Record[2][-1] != '"' or len(Record[2]) == 1:\r
+                    EdkLogger.error('build', FORMAT_NOT_SUPPORTED, 'language code for ISO_LANGUAGES must have double quotes around it, for example: ISO_LANGUAGES = "engchn"',\r
+                                    File=self.MetaFile, Line=Record[-1])\r
+                LanguageCodes = Record[2][1:-1]\r
+                if not LanguageCodes:\r
+                    EdkLogger.error('build', FORMAT_NOT_SUPPORTED, 'one or more ISO639-2 format language code must be provided for ISO_LANGUAGES statement',\r
+                                    File=self.MetaFile, Line=Record[-1])                    \r
+                if len(LanguageCodes)%3:\r
+                    EdkLogger.error('build', FORMAT_NOT_SUPPORTED, 'bad ISO639-2 format for ISO_LANGUAGES',\r
+                                    File=self.MetaFile, Line=Record[-1])\r
+                LanguageList = []\r
+                for i in range(0, len(LanguageCodes), 3):\r
+                    LanguageList.append(LanguageCodes[i:i+3])\r
+                self._ISOLanguages = LanguageList               \r
+            elif Name == TAB_DSC_DEFINES_VPD_TOOL_GUID:\r
+                #\r
+                # try to convert GUID to a real UUID value to see whether the GUID is format \r
+                # for VPD_TOOL_GUID is correct.\r
+                #\r
+                try:\r
+                    uuid.UUID(Record[2])\r
+                except:\r
+                    EdkLogger.error("build", FORMAT_INVALID, "Invalid GUID format for VPD_TOOL_GUID", File=self.MetaFile)\r
+                self._VpdToolGuid = Record[2]                   \r
+            elif Name in self:\r
+                self[Name] = Record[2]                 \r
+        # set _Header to non-None in order to avoid database re-querying\r
+        self._Header = 'DUMMY'\r
+\r
+    ## Retrieve platform name\r
+    def _GetPlatformName(self):\r
+        if self._PlatformName == None:\r
+            if self._Header == None:\r
+                self._GetHeaderInfo()\r
+            if self._PlatformName == None:\r
+                EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No PLATFORM_NAME", File=self.MetaFile)\r
+        return self._PlatformName\r
+\r
+    ## Retrieve file guid\r
+    def _GetFileGuid(self):\r
+        if self._Guid == None:\r
+            if self._Header == None:\r
+                self._GetHeaderInfo()\r
+            if self._Guid == None:\r
+                EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No PLATFORM_GUID", File=self.MetaFile)\r
+        return self._Guid\r
+\r
+    ## Retrieve platform version\r
+    def _GetVersion(self):\r
+        if self._Version == None:\r
+            if self._Header == None:\r
+                self._GetHeaderInfo()\r
+            if self._Version == None:\r
+                EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No PLATFORM_VERSION", File=self.MetaFile)\r
+        return self._Version\r
+\r
+    ## Retrieve platform description file version\r
+    def _GetDscSpec(self):\r
+        if self._DscSpecification == None:\r
+            if self._Header == None:\r
+                self._GetHeaderInfo()\r
+            if self._DscSpecification == None:\r
+                EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No DSC_SPECIFICATION", File=self.MetaFile)                \r
+        return self._DscSpecification\r
+\r
+    ## Retrieve OUTPUT_DIRECTORY\r
+    def _GetOutpuDir(self):\r
+        if self._OutputDirectory == None:\r
+            if self._Header == None:\r
+                self._GetHeaderInfo()\r
+            if self._OutputDirectory == None:\r
+                self._OutputDirectory = os.path.join("Build", self._PlatformName)\r
+        return self._OutputDirectory\r
+\r
+    ## Retrieve SUPPORTED_ARCHITECTURES\r
+    def _GetSupArch(self):\r
+        if self._SupArchList == None:\r
+            if self._Header == None:\r
+                self._GetHeaderInfo()\r
+            if self._SupArchList == None:\r
+                EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No SUPPORTED_ARCHITECTURES", File=self.MetaFile)\r
+        return self._SupArchList\r
+\r
+    ## Retrieve BUILD_TARGETS\r
+    def _GetBuildTarget(self):\r
+        if self._BuildTargets == None:\r
+            if self._Header == None:\r
+                self._GetHeaderInfo()\r
+            if self._BuildTargets == None:\r
+                EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No BUILD_TARGETS", File=self.MetaFile)\r
+        return self._BuildTargets\r
+    \r
+    def _GetPcdInfoFlag(self):\r
+        if self._PcdInfoFlag == None or self._PcdInfoFlag.upper() == 'FALSE':\r
+            return False\r
+        elif self._PcdInfoFlag.upper() == 'TRUE':\r
+            return True\r
+        else:\r
+            return False\r
+    def _GetVarCheckFlag(self):  \r
+        if self._VarCheckFlag == None or self._VarCheckFlag.upper() == 'FALSE':\r
+            return False\r
+        elif self._VarCheckFlag.upper() == 'TRUE':\r
+            return True\r
+        else:\r
+            return False\r
+    def _GetAviableSkuIds(self):\r
+        if self._AvilableSkuIds:\r
+            return self._AvilableSkuIds\r
+        return self.SkuIdentifier\r
+    def _GetSkuIdentifier(self):\r
+        if self._SkuName:\r
+            return self._SkuName\r
+        if self._SkuIdentifier == None:\r
+            if self._Header == None:\r
+                self._GetHeaderInfo()\r
+        return self._SkuIdentifier\r
+    ## Retrieve SKUID_IDENTIFIER\r
+    def _GetSkuName(self):\r
+        if self._SkuName == None:\r
+            if self._Header == None:\r
+                self._GetHeaderInfo()\r
+            if (self._SkuName == None or self._SkuName not in self.SkuIds):\r
+                self._SkuName = 'DEFAULT'\r
+        return self._SkuName\r
+\r
+    ## Override SKUID_IDENTIFIER\r
+    def _SetSkuName(self, Value):\r
+        self._SkuName = Value\r
+        self._Pcds = None\r
+\r
+    def _GetFdfFile(self):\r
+        if self._FlashDefinition == None:\r
+            if self._Header == None:\r
+                self._GetHeaderInfo()\r
+            if self._FlashDefinition == None:\r
+                self._FlashDefinition = ''\r
+        return self._FlashDefinition\r
+\r
+    def _GetPrebuild(self):\r
+        if self._Prebuild == None:\r
+            if self._Header == None:\r
+                self._GetHeaderInfo()\r
+            if self._Prebuild == None:\r
+                self._Prebuild = ''\r
+        return self._Prebuild\r
+\r
+    def _GetPostbuild(self):\r
+        if self._Postbuild == None:\r
+            if self._Header == None:\r
+                self._GetHeaderInfo()\r
+            if self._Postbuild == None:\r
+                self._Postbuild = ''\r
+        return self._Postbuild\r
+\r
+    ## Retrieve FLASH_DEFINITION\r
+    def _GetBuildNumber(self):\r
+        if self._BuildNumber == None:\r
+            if self._Header == None:\r
+                self._GetHeaderInfo()\r
+            if self._BuildNumber == None:\r
+                self._BuildNumber = ''\r
+        return self._BuildNumber\r
+\r
+    ## Retrieve MAKEFILE_NAME\r
+    def _GetMakefileName(self):\r
+        if self._MakefileName == None:\r
+            if self._Header == None:\r
+                self._GetHeaderInfo()\r
+            if self._MakefileName == None:\r
+                self._MakefileName = ''\r
+        return self._MakefileName\r
+\r
+    ## Retrieve BsBaseAddress\r
+    def _GetBsBaseAddress(self):\r
+        if self._BsBaseAddress == None:\r
+            if self._Header == None:\r
+                self._GetHeaderInfo()\r
+            if self._BsBaseAddress == None:\r
+                self._BsBaseAddress = ''\r
+        return self._BsBaseAddress\r
+\r
+    ## Retrieve RtBaseAddress\r
+    def _GetRtBaseAddress(self):\r
+        if self._RtBaseAddress == None:\r
+            if self._Header == None:\r
+                self._GetHeaderInfo()\r
+            if self._RtBaseAddress == None:\r
+                self._RtBaseAddress = ''\r
+        return self._RtBaseAddress\r
+\r
+    ## Retrieve the top address for the load fix address\r
+    def _GetLoadFixAddress(self):\r
+        if self._LoadFixAddress == None:\r
+            if self._Header == None:\r
+                self._GetHeaderInfo()\r
+\r
+            if self._LoadFixAddress == None:\r
+                self._LoadFixAddress = self._Macros.get(TAB_FIX_LOAD_TOP_MEMORY_ADDRESS, '0')\r
+\r
+            try:\r
+                self._LoadFixAddress = int (self._LoadFixAddress, 0)\r
+            except:\r
+                EdkLogger.error("build", PARAMETER_INVALID, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (self._LoadFixAddress))\r
+         \r
+        #\r
+        # If command line defined, should override the value in DSC file.\r
+        #\r
+        if 'FIX_LOAD_TOP_MEMORY_ADDRESS' in GlobalData.gCommandLineDefines.keys():\r
+            try:\r
+                self._LoadFixAddress = int(GlobalData.gCommandLineDefines['FIX_LOAD_TOP_MEMORY_ADDRESS'], 0)\r
+            except:\r
+                EdkLogger.error("build", PARAMETER_INVALID, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (GlobalData.gCommandLineDefines['FIX_LOAD_TOP_MEMORY_ADDRESS']))\r
+                \r
+        if self._LoadFixAddress < 0:\r
+            EdkLogger.error("build", PARAMETER_INVALID, "FIX_LOAD_TOP_MEMORY_ADDRESS is set to the invalid negative value 0x%x" % (self._LoadFixAddress))\r
+        if self._LoadFixAddress != 0xFFFFFFFFFFFFFFFF and self._LoadFixAddress % 0x1000 != 0:\r
+            EdkLogger.error("build", PARAMETER_INVALID, "FIX_LOAD_TOP_MEMORY_ADDRESS is set to the invalid unaligned 4K value 0x%x" % (self._LoadFixAddress))\r
+            \r
+        return self._LoadFixAddress\r
+\r
+    ## Retrieve RFCLanguage filter\r
+    def _GetRFCLanguages(self):\r
+        if self._RFCLanguages == None:\r
+            if self._Header == None:\r
+                self._GetHeaderInfo()\r
+            if self._RFCLanguages == None:\r
+                self._RFCLanguages = []\r
+        return self._RFCLanguages\r
+\r
+    ## Retrieve ISOLanguage filter\r
+    def _GetISOLanguages(self):\r
+        if self._ISOLanguages == None:\r
+            if self._Header == None:\r
+                self._GetHeaderInfo()\r
+            if self._ISOLanguages == None:\r
+                self._ISOLanguages = []\r
+        return self._ISOLanguages\r
+    ## Retrieve the GUID string for VPD tool\r
+    def _GetVpdToolGuid(self):\r
+        if self._VpdToolGuid == None:\r
+            if self._Header == None:\r
+                self._GetHeaderInfo()\r
+            if self._VpdToolGuid == None:\r
+                self._VpdToolGuid = ''\r
+        return self._VpdToolGuid\r
+      \r
+    ## Retrieve [SkuIds] section information\r
+    def _GetSkuIds(self):\r
+        if self._SkuIds == None:\r
+            self._SkuIds = sdict()\r
+            RecordList = self._RawData[MODEL_EFI_SKU_ID, self._Arch]\r
+            for Record in RecordList:\r
+                if Record[0] in [None, '']:\r
+                    EdkLogger.error('build', FORMAT_INVALID, 'No Sku ID number',\r
+                                    File=self.MetaFile, Line=Record[-1])\r
+                if Record[1] in [None, '']:\r
+                    EdkLogger.error('build', FORMAT_INVALID, 'No Sku ID name',\r
+                                    File=self.MetaFile, Line=Record[-1])\r
+                self._SkuIds[Record[1]] = Record[0]\r
+            if 'DEFAULT' not in self._SkuIds:\r
+                self._SkuIds['DEFAULT'] = '0'\r
+            if 'COMMON' not in self._SkuIds:\r
+                self._SkuIds['COMMON'] = '0'\r
+        return self._SkuIds\r
+\r
+    ## Retrieve [Components] section information\r
+    def _GetModules(self):\r
+        if self._Modules != None:\r
+            return self._Modules\r
+\r
+        self._Modules = sdict()\r
+        RecordList = self._RawData[MODEL_META_DATA_COMPONENT, self._Arch]\r
+        Macros = self._Macros\r
+        Macros["EDK_SOURCE"] = GlobalData.gEcpSource\r
+        for Record in RecordList:\r
+            DuplicatedFile = False\r
+            ModuleFile = PathClass(NormPath(Record[0], Macros), GlobalData.gWorkspace, Arch=self._Arch)\r
+            ModuleId = Record[5]\r
+            LineNo = Record[6]\r
+\r
+            # check the file validation\r
+            ErrorCode, ErrorInfo = ModuleFile.Validate('.inf')\r
+            if ErrorCode != 0:\r
+                EdkLogger.error('build', ErrorCode, File=self.MetaFile, Line=LineNo,\r
+                                ExtraData=ErrorInfo)\r
+            # Check duplication\r
+            # If arch is COMMON, no duplicate module is checked since all modules in all component sections are selected\r
+            if self._Arch != 'COMMON' and ModuleFile in self._Modules:\r
+                DuplicatedFile = True\r
+\r
+            Module = ModuleBuildClassObject()\r
+            Module.MetaFile = ModuleFile\r
+\r
+            # get module private library instance\r
+            RecordList = self._RawData[MODEL_EFI_LIBRARY_CLASS, self._Arch, None, ModuleId]\r
+            for Record in RecordList:\r
+                LibraryClass = Record[0]\r
+                LibraryPath = PathClass(NormPath(Record[1], Macros), GlobalData.gWorkspace, Arch=self._Arch)\r
+                LineNo = Record[-1]\r
+\r
+                # check the file validation\r
+                ErrorCode, ErrorInfo = LibraryPath.Validate('.inf')\r
+                if ErrorCode != 0:\r
+                    EdkLogger.error('build', ErrorCode, File=self.MetaFile, Line=LineNo,\r
+                                    ExtraData=ErrorInfo)\r
+\r
+                if LibraryClass == '' or LibraryClass == 'NULL':\r
+                    self._NullLibraryNumber += 1\r
+                    LibraryClass = 'NULL%d' % self._NullLibraryNumber\r
+                    EdkLogger.verbose("Found forced library for %s\n\t%s [%s]" % (ModuleFile, LibraryPath, LibraryClass))\r
+                Module.LibraryClasses[LibraryClass] = LibraryPath\r
+                if LibraryPath not in self.LibraryInstances:\r
+                    self.LibraryInstances.append(LibraryPath)\r
+\r
+            # get module private PCD setting\r
+            for Type in [MODEL_PCD_FIXED_AT_BUILD, MODEL_PCD_PATCHABLE_IN_MODULE, \\r
+                         MODEL_PCD_FEATURE_FLAG, MODEL_PCD_DYNAMIC, MODEL_PCD_DYNAMIC_EX]:\r
+                RecordList = self._RawData[Type, self._Arch, None, ModuleId]\r
+                for TokenSpaceGuid, PcdCName, Setting, Dummy1, Dummy2, Dummy3, Dummy4 in RecordList:\r
+                    TokenList = GetSplitValueList(Setting)\r
+                    DefaultValue = TokenList[0]\r
+                    if len(TokenList) > 1:\r
+                        MaxDatumSize = TokenList[1]\r
+                    else:\r
+                        MaxDatumSize = ''\r
+                    TypeString = self._PCD_TYPE_STRING_[Type]\r
+                    Pcd = PcdClassObject(\r
+                            PcdCName,\r
+                            TokenSpaceGuid,\r
+                            TypeString,\r
+                            '',\r
+                            DefaultValue,\r
+                            '',\r
+                            MaxDatumSize,\r
+                            {},\r
+                            False,\r
+                            None\r
+                            )\r
+                    Module.Pcds[PcdCName, TokenSpaceGuid] = Pcd\r
+\r
+            # get module private build options\r
+            RecordList = self._RawData[MODEL_META_DATA_BUILD_OPTION, self._Arch, None, ModuleId]\r
+            for ToolChainFamily, ToolChain, Option, Dummy1, Dummy2, Dummy3, Dummy4 in RecordList:\r
+                if (ToolChainFamily, ToolChain) not in Module.BuildOptions:\r
+                    Module.BuildOptions[ToolChainFamily, ToolChain] = Option\r
+                else:\r
+                    OptionString = Module.BuildOptions[ToolChainFamily, ToolChain]\r
+                    Module.BuildOptions[ToolChainFamily, ToolChain] = OptionString + " " + Option\r
+\r
+            RecordList = self._RawData[MODEL_META_DATA_HEADER, self._Arch, None, ModuleId]\r
+            if DuplicatedFile and not RecordList:\r
+                EdkLogger.error('build', FILE_DUPLICATED, File=self.MetaFile, ExtraData=str(ModuleFile), Line=LineNo)\r
+            if RecordList:\r
+                if len(RecordList) != 1:\r
+                    EdkLogger.error('build', OPTION_UNKNOWN, 'Only FILE_GUID can be listed in <Defines> section.',\r
+                                    File=self.MetaFile, ExtraData=str(ModuleFile), Line=LineNo)\r
+                ModuleFile = ProcessDuplicatedInf(ModuleFile, RecordList[0][2], GlobalData.gWorkspace)\r
+                ModuleFile.Arch = self._Arch\r
+\r
+            self._Modules[ModuleFile] = Module\r
+        return self._Modules\r
+\r
+    ## Retrieve all possible library instances used in this platform\r
+    def _GetLibraryInstances(self):\r
+        if self._LibraryInstances == None:\r
+            self._GetLibraryClasses()\r
+        return self._LibraryInstances\r
+\r
+    ## Retrieve [LibraryClasses] information\r
+    def _GetLibraryClasses(self):\r
+        if self._LibraryClasses == None:\r
+            self._LibraryInstances = []\r
+            #\r
+            # tdict is a special dict kind of type, used for selecting correct\r
+            # library instance for given library class and module type\r
+            #\r
+            LibraryClassDict = tdict(True, 3)\r
+            # track all library class names\r
+            LibraryClassSet = set()\r
+            RecordList = self._RawData[MODEL_EFI_LIBRARY_CLASS, self._Arch, None, -1]\r
+            Macros = self._Macros\r
+            for Record in RecordList:\r
+                LibraryClass, LibraryInstance, Dummy, Arch, ModuleType, Dummy, LineNo = Record\r
+                if LibraryClass == '' or LibraryClass == 'NULL':\r
+                    self._NullLibraryNumber += 1\r
+                    LibraryClass = 'NULL%d' % self._NullLibraryNumber\r
+                    EdkLogger.verbose("Found forced library for arch=%s\n\t%s [%s]" % (Arch, LibraryInstance, LibraryClass))\r
+                LibraryClassSet.add(LibraryClass)\r
+                LibraryInstance = PathClass(NormPath(LibraryInstance, Macros), GlobalData.gWorkspace, Arch=self._Arch)\r
+                # check the file validation\r
+                ErrorCode, ErrorInfo = LibraryInstance.Validate('.inf')\r
+                if ErrorCode != 0:\r
+                    EdkLogger.error('build', ErrorCode, File=self.MetaFile, Line=LineNo,\r
+                                    ExtraData=ErrorInfo)\r
+\r
+                if ModuleType != 'COMMON' and ModuleType not in SUP_MODULE_LIST:\r
+                    EdkLogger.error('build', OPTION_UNKNOWN, "Unknown module type [%s]" % ModuleType,\r
+                                    File=self.MetaFile, ExtraData=LibraryInstance, Line=LineNo)\r
+                LibraryClassDict[Arch, ModuleType, LibraryClass] = LibraryInstance\r
+                if LibraryInstance not in self._LibraryInstances:\r
+                    self._LibraryInstances.append(LibraryInstance)\r
+\r
+            # resolve the specific library instance for each class and each module type\r
+            self._LibraryClasses = tdict(True)\r
+            for LibraryClass in LibraryClassSet:\r
+                # try all possible module types\r
+                for ModuleType in SUP_MODULE_LIST:\r
+                    LibraryInstance = LibraryClassDict[self._Arch, ModuleType, LibraryClass]\r
+                    if LibraryInstance == None:\r
+                        continue\r
+                    self._LibraryClasses[LibraryClass, ModuleType] = LibraryInstance\r
+\r
+            # for Edk style library instances, which are listed in different section\r
+            Macros["EDK_SOURCE"] = GlobalData.gEcpSource\r
+            RecordList = self._RawData[MODEL_EFI_LIBRARY_INSTANCE, self._Arch]\r
+            for Record in RecordList:\r
+                File = PathClass(NormPath(Record[0], Macros), GlobalData.gWorkspace, Arch=self._Arch)\r
+                LineNo = Record[-1]\r
+                # check the file validation\r
+                ErrorCode, ErrorInfo = File.Validate('.inf')\r
+                if ErrorCode != 0:\r
+                    EdkLogger.error('build', ErrorCode, File=self.MetaFile, Line=LineNo,\r
+                                    ExtraData=ErrorInfo)\r
+                if File not in self._LibraryInstances:\r
+                    self._LibraryInstances.append(File)\r
+                #\r
+                # we need the module name as the library class name, so we have\r
+                # to parse it here. (self._Bdb[] will trigger a file parse if it\r
+                # hasn't been parsed)\r
+                #\r
+                Library = self._Bdb[File, self._Arch, self._Target, self._Toolchain]\r
+                self._LibraryClasses[Library.BaseName, ':dummy:'] = Library\r
+        return self._LibraryClasses\r
+\r
+    def _ValidatePcd(self, PcdCName, TokenSpaceGuid, Setting, PcdType, LineNo):\r
+        if self._DecPcds == None:\r
+            self._DecPcds = GetDeclaredPcd(self, self._Bdb, self._Arch, self._Target, self._Toolchain)\r
+            FdfInfList = []\r
+            if GlobalData.gFdfParser:\r
+                FdfInfList = GlobalData.gFdfParser.Profile.InfList\r
+\r
+            PkgSet = set()\r
+            for Inf in FdfInfList:\r
+                ModuleFile = PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch=self._Arch)\r
+                if ModuleFile in self._Modules:\r
+                    continue\r
+                ModuleData = self._Bdb[ModuleFile, self._Arch, self._Target, self._Toolchain]\r
+                PkgSet.update(ModuleData.Packages)\r
+            DecPcds = {}\r
+            for Pkg in PkgSet:\r
+                for Pcd in Pkg.Pcds:\r
+                    DecPcds[Pcd[0], Pcd[1]] = Pkg.Pcds[Pcd]\r
+            self._DecPcds.update(DecPcds)\r
+\r
+        if (PcdCName, TokenSpaceGuid) not in self._DecPcds:\r
+            EdkLogger.error('build', PARSER_ERROR,\r
+                            "Pcd (%s.%s) defined in DSC is not declared in DEC files. Arch: ['%s']" % (TokenSpaceGuid, PcdCName, self._Arch),\r
+                            File=self.MetaFile, Line=LineNo)\r
+        ValueList, IsValid, Index = AnalyzeDscPcd(Setting, PcdType, self._DecPcds[PcdCName, TokenSpaceGuid].DatumType)\r
+        if not IsValid and PcdType not in [MODEL_PCD_FEATURE_FLAG, MODEL_PCD_FIXED_AT_BUILD]:\r
+            EdkLogger.error('build', FORMAT_INVALID, "Pcd format incorrect.", File=self.MetaFile, Line=LineNo,\r
+                            ExtraData="%s.%s|%s" % (TokenSpaceGuid, PcdCName, Setting))\r
+        if ValueList[Index] and PcdType not in [MODEL_PCD_FEATURE_FLAG, MODEL_PCD_FIXED_AT_BUILD]:\r
+            try:\r
+                ValueList[Index] = ValueExpression(ValueList[Index], GlobalData.gPlatformPcds)(True)\r
+            except WrnExpression, Value:\r
+                ValueList[Index] = Value.result\r
+            except EvaluationException, Excpt:\r
+                if hasattr(Excpt, 'Pcd'):\r
+                    if Excpt.Pcd in GlobalData.gPlatformOtherPcds:\r
+                        EdkLogger.error('Parser', FORMAT_INVALID, "Cannot use this PCD (%s) in an expression as"\r
+                                        " it must be defined in a [PcdsFixedAtBuild] or [PcdsFeatureFlag] section"\r
+                                        " of the DSC file" % Excpt.Pcd,\r
+                                        File=self.MetaFile, Line=LineNo)\r
+                    else:\r
+                        EdkLogger.error('Parser', FORMAT_INVALID, "PCD (%s) is not defined in DSC file" % Excpt.Pcd,\r
+                                        File=self.MetaFile, Line=LineNo)\r
+                else:\r
+                    EdkLogger.error('Parser', FORMAT_INVALID, "Invalid expression: %s" % str(Excpt),\r
+                                    File=self.MetaFile, Line=LineNo)\r
+            if ValueList[Index] == 'True':\r
+                ValueList[Index] = '1'\r
+            elif ValueList[Index] == 'False':\r
+                ValueList[Index] = '0'\r
+        if ValueList[Index]:\r
+            Valid, ErrStr = CheckPcdDatum(self._DecPcds[PcdCName, TokenSpaceGuid].DatumType, ValueList[Index])\r
+            if not Valid:\r
+                EdkLogger.error('build', FORMAT_INVALID, ErrStr, File=self.MetaFile, Line=LineNo,\r
+                                ExtraData="%s.%s" % (TokenSpaceGuid, PcdCName))\r
+        return ValueList\r
+\r
+    ## Retrieve all PCD settings in platform\r
+    def _GetPcds(self):\r
+        if self._Pcds == None:\r
+            self._Pcds = sdict()\r
+            self._Pcds.update(self._GetPcd(MODEL_PCD_FIXED_AT_BUILD))\r
+            self._Pcds.update(self._GetPcd(MODEL_PCD_PATCHABLE_IN_MODULE))\r
+            self._Pcds.update(self._GetPcd(MODEL_PCD_FEATURE_FLAG))\r
+            self._Pcds.update(self._GetDynamicPcd(MODEL_PCD_DYNAMIC_DEFAULT))\r
+            self._Pcds.update(self._GetDynamicHiiPcd(MODEL_PCD_DYNAMIC_HII))\r
+            self._Pcds.update(self._GetDynamicVpdPcd(MODEL_PCD_DYNAMIC_VPD))\r
+            self._Pcds.update(self._GetDynamicPcd(MODEL_PCD_DYNAMIC_EX_DEFAULT))\r
+            self._Pcds.update(self._GetDynamicHiiPcd(MODEL_PCD_DYNAMIC_EX_HII))\r
+            self._Pcds.update(self._GetDynamicVpdPcd(MODEL_PCD_DYNAMIC_EX_VPD))\r
+        return self._Pcds\r
+\r
+    ## Retrieve [BuildOptions]\r
+    def _GetBuildOptions(self):\r
+        if self._BuildOptions == None:\r
+            self._BuildOptions = sdict()\r
+            #\r
+            # Retrieve build option for EDKII and EDK style module\r
+            #\r
+            for CodeBase in (EDKII_NAME, EDK_NAME):\r
+                RecordList = self._RawData[MODEL_META_DATA_BUILD_OPTION, self._Arch, CodeBase]\r
+                for ToolChainFamily, ToolChain, Option, Dummy1, Dummy2, Dummy3, Dummy4 in RecordList:\r
+                    CurKey = (ToolChainFamily, ToolChain, CodeBase)\r
+                    #\r
+                    # Only flags can be appended\r
+                    #\r
+                    if CurKey not in self._BuildOptions or not ToolChain.endswith('_FLAGS') or Option.startswith('='):\r
+                        self._BuildOptions[CurKey] = Option\r
+                    else:\r
+                        self._BuildOptions[CurKey] += ' ' + Option\r
+        return self._BuildOptions\r
+\r
+    def GetBuildOptionsByModuleType(self, Edk, ModuleType):\r
+        if self._ModuleTypeOptions == None:\r
+            self._ModuleTypeOptions = sdict()\r
+        if (Edk, ModuleType) not in self._ModuleTypeOptions:\r
+            options = sdict()\r
+            self._ModuleTypeOptions[Edk, ModuleType] = options\r
+            DriverType = '%s.%s' % (Edk, ModuleType)\r
+            RecordList = self._RawData[MODEL_META_DATA_BUILD_OPTION, self._Arch, DriverType]\r
+            for ToolChainFamily, ToolChain, Option, Arch, Type, Dummy3, Dummy4 in RecordList:\r
+                if Type == DriverType:\r
+                    Key = (ToolChainFamily, ToolChain, Edk)\r
+                    if Key not in options or not ToolChain.endswith('_FLAGS') or Option.startswith('='):\r
+                        options[Key] = Option\r
+                    else:\r
+                        options[Key] += ' ' + Option\r
+        return self._ModuleTypeOptions[Edk, ModuleType]\r
+\r
+    ## Retrieve non-dynamic PCD settings\r
+    #\r
+    #   @param  Type    PCD type\r
+    #\r
+    #   @retval a dict object contains settings of given PCD type\r
+    #\r
+    def _GetPcd(self, Type):\r
+        Pcds = sdict()\r
+        #\r
+        # tdict is a special dict kind of type, used for selecting correct\r
+        # PCD settings for certain ARCH\r
+        #\r
+        \r
+        SkuObj = SkuClass(self.SkuIdentifier,self.SkuIds)\r
+        \r
+        PcdDict = tdict(True, 3)\r
+        PcdSet = set()\r
+        # Find out all possible PCD candidates for self._Arch\r
+        RecordList = self._RawData[Type, self._Arch]\r
+        PcdValueDict = sdict()\r
+        for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, Dummy3, Dummy4 in RecordList:\r
+            if SkuName in (SkuObj.SystemSkuId,'DEFAULT','COMMON'):\r
+                PcdSet.add((PcdCName, TokenSpaceGuid, SkuName,Dummy4))\r
+                PcdDict[Arch, PcdCName, TokenSpaceGuid,SkuName] = Setting\r
+        \r
+        #handle pcd value override        \r
+        for PcdCName, TokenSpaceGuid, SkuName,Dummy4 in PcdSet:\r
+            Setting = PcdDict[self._Arch, PcdCName, TokenSpaceGuid,SkuName]\r
+            if Setting == None:\r
+                continue\r
+            PcdValue, DatumType, MaxDatumSize = self._ValidatePcd(PcdCName, TokenSpaceGuid, Setting, Type, Dummy4)\r
+            if (PcdCName, TokenSpaceGuid) in PcdValueDict:\r
+                PcdValueDict[PcdCName, TokenSpaceGuid][SkuName] = (PcdValue,DatumType,MaxDatumSize) \r
+            else:\r
+                PcdValueDict[PcdCName, TokenSpaceGuid] = {SkuName:(PcdValue,DatumType,MaxDatumSize)}       \r
+        \r
+        PcdsKeys = PcdValueDict.keys()\r
+        for PcdCName,TokenSpaceGuid in PcdsKeys:\r
+            \r
+            PcdSetting = PcdValueDict[PcdCName, TokenSpaceGuid]\r
+            PcdValue = None\r
+            DatumType = None\r
+            MaxDatumSize = None\r
+            if 'COMMON' in PcdSetting:\r
+                PcdValue,DatumType,MaxDatumSize = PcdSetting['COMMON']\r
+            if 'DEFAULT' in PcdSetting:\r
+                PcdValue,DatumType,MaxDatumSize = PcdSetting['DEFAULT']\r
+            if SkuObj.SystemSkuId in PcdSetting:\r
+                PcdValue,DatumType,MaxDatumSize = PcdSetting[SkuObj.SystemSkuId]\r
+                \r
+            Pcds[PcdCName, TokenSpaceGuid] = PcdClassObject(\r
+                                                PcdCName,\r
+                                                TokenSpaceGuid,\r
+                                                self._PCD_TYPE_STRING_[Type],\r
+                                                DatumType,\r
+                                                PcdValue,\r
+                                                '',\r
+                                                MaxDatumSize,\r
+                                                {},\r
+                                                False,\r
+                                                None\r
+                                                )\r
+        return Pcds\r
+\r
+    ## Retrieve dynamic PCD settings\r
+    #\r
+    #   @param  Type    PCD type\r
+    #\r
+    #   @retval a dict object contains settings of given PCD type\r
+    #\r
+    def _GetDynamicPcd(self, Type):\r
+        \r
+        SkuObj = SkuClass(self.SkuIdentifier,self.SkuIds)\r
+        \r
+        Pcds = sdict()\r
+        #\r
+        # tdict is a special dict kind of type, used for selecting correct\r
+        # PCD settings for certain ARCH and SKU\r
+        #\r
+        PcdDict = tdict(True, 4)\r
+        PcdList = []\r
+        # Find out all possible PCD candidates for self._Arch\r
+        RecordList = self._RawData[Type, self._Arch]\r
+        AvailableSkuIdSet = SkuObj.AvailableSkuIdSet.copy()\r
+        \r
+        AvailableSkuIdSet.update({'DEFAULT':0,'COMMON':0})\r
+        for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, Dummy3, Dummy4 in RecordList:\r
+            if SkuName not in AvailableSkuIdSet:\r
+                continue\r
+            \r
+            PcdList.append((PcdCName, TokenSpaceGuid, SkuName,Dummy4))\r
+            PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid] = Setting\r
+        # Remove redundant PCD candidates, per the ARCH and SKU\r
+        for PcdCName, TokenSpaceGuid, SkuName, Dummy4 in PcdList:\r
+            \r
+            Setting = PcdDict[self._Arch, SkuName, PcdCName, TokenSpaceGuid]\r
+            if Setting == None:\r
+                continue\r
+                      \r
+            PcdValue, DatumType, MaxDatumSize = self._ValidatePcd(PcdCName, TokenSpaceGuid, Setting, Type, Dummy4)\r
+            SkuInfo = SkuInfoClass(SkuName, self.SkuIds[SkuName], '', '', '', '', '', PcdValue)\r
+            if (PcdCName,TokenSpaceGuid) in Pcds.keys(): \r
+                pcdObject = Pcds[PcdCName,TokenSpaceGuid]\r
+                pcdObject.SkuInfoList[SkuName] = SkuInfo\r
+                if MaxDatumSize.strip():\r
+                    CurrentMaxSize = int(MaxDatumSize.strip(),0)\r
+                else:\r
+                    CurrentMaxSize = 0\r
+                if pcdObject.MaxDatumSize:\r
+                    PcdMaxSize = int(pcdObject.MaxDatumSize,0)\r
+                else:\r
+                    PcdMaxSize = 0\r
+                if CurrentMaxSize > PcdMaxSize:\r
+                    pcdObject.MaxDatumSize = str(CurrentMaxSize)\r
+            else:               \r
+                Pcds[PcdCName, TokenSpaceGuid] = PcdClassObject(\r
+                                                    PcdCName,\r
+                                                    TokenSpaceGuid,\r
+                                                    self._PCD_TYPE_STRING_[Type],\r
+                                                    DatumType,\r
+                                                    PcdValue,\r
+                                                    '',\r
+                                                    MaxDatumSize,\r
+                                                    {SkuName : SkuInfo},\r
+                                                    False,\r
+                                                    None\r
+                                                    )\r
+        \r
+        for pcd in Pcds.values():\r
+            pcdDecObject = self._DecPcds[pcd.TokenCName,pcd.TokenSpaceGuidCName]\r
+            if 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' not in pcd.SkuInfoList.keys():                \r
+                valuefromDec = pcdDecObject.DefaultValue\r
+                SkuInfo = SkuInfoClass('DEFAULT', '0', '', '', '', '', '', valuefromDec)\r
+                pcd.SkuInfoList['DEFAULT'] = SkuInfo\r
+            elif 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' in pcd.SkuInfoList.keys():\r
+                pcd.SkuInfoList['DEFAULT'] = pcd.SkuInfoList['COMMON']\r
+                del(pcd.SkuInfoList['COMMON'])\r
+            elif 'DEFAULT' in pcd.SkuInfoList.keys() and 'COMMON' in pcd.SkuInfoList.keys():\r
+                del(pcd.SkuInfoList['COMMON'])\r
+            if SkuObj.SkuUsageType == SkuObj.SINGLE:\r
+                if 'DEFAULT' in pcd.SkuInfoList.keys() and SkuObj.SystemSkuId not in pcd.SkuInfoList.keys():\r
+                    pcd.SkuInfoList[SkuObj.SystemSkuId] = pcd.SkuInfoList['DEFAULT']\r
+                del(pcd.SkuInfoList['DEFAULT'])\r
+               \r
+        return Pcds\r
+\r
+    def CompareVarAttr(self, Attr1, Attr2):\r
+        if not Attr1 or not Attr2:  # for empty string\r
+            return True\r
+        Attr1s = [attr.strip() for attr in Attr1.split(",")]\r
+        Attr1Set = set(Attr1s)\r
+        Attr2s = [attr.strip() for attr in Attr2.split(",")]\r
+        Attr2Set = set(Attr2s)\r
+        if Attr2Set == Attr1Set:\r
+            return True\r
+        else:\r
+            return False\r
+    ## Retrieve dynamic HII PCD settings\r
+    #\r
+    #   @param  Type    PCD type\r
+    #\r
+    #   @retval a dict object contains settings of given PCD type\r
+    #\r
+    def _GetDynamicHiiPcd(self, Type):\r
+        \r
+        SkuObj = SkuClass(self.SkuIdentifier,self.SkuIds)\r
+        VariableAttrs = {}\r
+        \r
+        Pcds = sdict()\r
+        #\r
+        # tdict is a special dict kind of type, used for selecting correct\r
+        # PCD settings for certain ARCH and SKU\r
+        #\r
+        PcdDict = tdict(True, 4)\r
+        PcdSet = set()\r
+        RecordList = self._RawData[Type, self._Arch]\r
+        # Find out all possible PCD candidates for self._Arch\r
+        AvailableSkuIdSet = SkuObj.AvailableSkuIdSet.copy()\r
+        \r
+        AvailableSkuIdSet.update({'DEFAULT':0,'COMMON':0})\r
+        for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, Dummy3, Dummy4 in RecordList:\r
+            if SkuName not in AvailableSkuIdSet:\r
+                continue\r
+            PcdSet.add((PcdCName, TokenSpaceGuid, SkuName,Dummy4))\r
+            PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid] = Setting\r
+        # Remove redundant PCD candidates, per the ARCH and SKU\r
+        for PcdCName, TokenSpaceGuid,SkuName, Dummy4 in PcdSet:\r
+            \r
+            Setting = PcdDict[self._Arch, SkuName, PcdCName, TokenSpaceGuid]\r
+            if Setting == None:\r
+                continue\r
+            VariableName, VariableGuid, VariableOffset, DefaultValue, VarAttribute = self._ValidatePcd(PcdCName, TokenSpaceGuid, Setting, Type, Dummy4)\r
+            \r
+            rt, Msg = VariableAttributes.ValidateVarAttributes(VarAttribute)\r
+            if not rt:\r
+                EdkLogger.error("build", PCD_VARIABLE_ATTRIBUTES_ERROR, "Variable attributes settings for %s is incorrect.\n %s" % (".".join((TokenSpaceGuid, PcdCName)), Msg),\r
+                        ExtraData = "[%s]" % VarAttribute)\r
+            ExceedMax = False\r
+            FormatCorrect = True\r
+            if VariableOffset.isdigit():\r
+                if int(VariableOffset,10) > 0xFFFF:\r
+                    ExceedMax = True\r
+            elif re.match(r'[\t\s]*0[xX][a-fA-F0-9]+$',VariableOffset):\r
+                if int(VariableOffset,16) > 0xFFFF:\r
+                    ExceedMax = True\r
+            # For Offset written in "A.B"\r
+            elif VariableOffset.find('.') > -1:\r
+                VariableOffsetList = VariableOffset.split(".")\r
+                if not (len(VariableOffsetList) == 2\r
+                        and IsValidWord(VariableOffsetList[0])\r
+                        and IsValidWord(VariableOffsetList[1])):\r
+                    FormatCorrect = False\r
+            else:\r
+                FormatCorrect = False\r
+            if not FormatCorrect:\r
+                EdkLogger.error('Build', FORMAT_INVALID, "Invalid syntax or format of the variable offset value is incorrect for %s." % ".".join((TokenSpaceGuid,PcdCName)))\r
+            \r
+            if ExceedMax:\r
+                EdkLogger.error('Build', OPTION_VALUE_INVALID, "The variable offset value must not exceed the maximum value of 0xFFFF (UINT16) for %s." % ".".join((TokenSpaceGuid,PcdCName)))\r
+            if (VariableName, VariableGuid) not in VariableAttrs:\r
+                VariableAttrs[(VariableName, VariableGuid)] = VarAttribute\r
+            else:\r
+                if not self.CompareVarAttr(VariableAttrs[(VariableName, VariableGuid)], VarAttribute):\r
+                    EdkLogger.error('Build', PCD_VARIABLE_ATTRIBUTES_CONFLICT_ERROR, "The variable %s.%s for DynamicHii PCDs has conflicting attributes [%s] and [%s] " % (VariableGuid, VariableName, VarAttribute, VariableAttrs[(VariableName, VariableGuid)]))\r
+            \r
+            SkuInfo = SkuInfoClass(SkuName, self.SkuIds[SkuName], VariableName, VariableGuid, VariableOffset, DefaultValue, VariableAttribute = VarAttribute)\r
+            pcdDecObject = self._DecPcds[PcdCName, TokenSpaceGuid]\r
+            if (PcdCName,TokenSpaceGuid) in Pcds.keys():  \r
+                pcdObject = Pcds[PcdCName,TokenSpaceGuid]\r
+                pcdObject.SkuInfoList[SkuName] = SkuInfo\r
+            else:\r
+                Pcds[PcdCName, TokenSpaceGuid] = PcdClassObject(\r
+                                                PcdCName,\r
+                                                TokenSpaceGuid,\r
+                                                self._PCD_TYPE_STRING_[Type],\r
+                                                '',\r
+                                                DefaultValue,\r
+                                                '',\r
+                                                '',\r
+                                                {SkuName : SkuInfo},\r
+                                                False,\r
+                                                None,\r
+                                                pcdDecObject.validateranges,\r
+                                                pcdDecObject.validlists,\r
+                                                pcdDecObject.expressions\r
+                                                )\r
+                \r
+\r
+        for pcd in Pcds.values():\r
+            SkuInfoObj = pcd.SkuInfoList.values()[0]\r
+            pcdDecObject = self._DecPcds[pcd.TokenCName,pcd.TokenSpaceGuidCName]\r
+            # Only fix the value while no value provided in DSC file.\r
+            for sku in pcd.SkuInfoList.values():\r
+                if (sku.HiiDefaultValue == "" or sku.HiiDefaultValue==None):\r
+                    sku.HiiDefaultValue = pcdDecObject.DefaultValue\r
+            if 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' not in pcd.SkuInfoList.keys():              \r
+                valuefromDec = pcdDecObject.DefaultValue\r
+                SkuInfo = SkuInfoClass('DEFAULT', '0', SkuInfoObj.VariableName, SkuInfoObj.VariableGuid, SkuInfoObj.VariableOffset, valuefromDec)\r
+                pcd.SkuInfoList['DEFAULT'] = SkuInfo\r
+            elif 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' in pcd.SkuInfoList.keys():\r
+                pcd.SkuInfoList['DEFAULT'] = pcd.SkuInfoList['COMMON']\r
+                del(pcd.SkuInfoList['COMMON'])\r
+            elif 'DEFAULT' in pcd.SkuInfoList.keys() and 'COMMON' in pcd.SkuInfoList.keys():\r
+                del(pcd.SkuInfoList['COMMON'])\r
+                \r
+            if SkuObj.SkuUsageType == SkuObj.SINGLE:\r
+                if 'DEFAULT' in pcd.SkuInfoList.keys() and SkuObj.SystemSkuId not in pcd.SkuInfoList.keys():\r
+                    pcd.SkuInfoList[SkuObj.SystemSkuId] = pcd.SkuInfoList['DEFAULT']\r
+                del(pcd.SkuInfoList['DEFAULT'])\r
+            \r
+            \r
+            if pcd.MaxDatumSize.strip(): \r
+                MaxSize = int(pcd.MaxDatumSize,0)\r
+            else:\r
+                MaxSize = 0\r
+            if pcdDecObject.DatumType == 'VOID*':\r
+                for (skuname,skuobj) in pcd.SkuInfoList.items():\r
+                    datalen = 0\r
+                    if skuobj.HiiDefaultValue.startswith("L"):\r
+                        datalen = (len(skuobj.HiiDefaultValue)- 3 + 1) * 2\r
+                    elif skuobj.HiiDefaultValue.startswith("{"):\r
+                        datalen = len(skuobj.HiiDefaultValue.split(","))\r
+                    else:\r
+                        datalen = len(skuobj.HiiDefaultValue) -2 + 1 \r
+                    if datalen>MaxSize:\r
+                        MaxSize = datalen\r
+                pcd.MaxDatumSize = str(MaxSize)\r
+        return Pcds\r
+\r
+    ## Retrieve dynamic VPD PCD settings\r
+    #\r
+    #   @param  Type    PCD type\r
+    #\r
+    #   @retval a dict object contains settings of given PCD type\r
+    #\r
+    def _GetDynamicVpdPcd(self, Type):\r
+        \r
+        SkuObj = SkuClass(self.SkuIdentifier,self.SkuIds)\r
+        \r
+        Pcds = sdict()\r
+        #\r
+        # tdict is a special dict kind of type, used for selecting correct\r
+        # PCD settings for certain ARCH and SKU\r
+        #\r
+        PcdDict = tdict(True, 4)\r
+        PcdList = []\r
+        # Find out all possible PCD candidates for self._Arch\r
+        RecordList = self._RawData[Type, self._Arch]\r
+        AvailableSkuIdSet = SkuObj.AvailableSkuIdSet.copy()\r
+        \r
+        AvailableSkuIdSet.update({'DEFAULT':0,'COMMON':0})\r
+        for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, Dummy3, Dummy4 in RecordList:\r
+            if SkuName not in AvailableSkuIdSet:\r
+                continue\r
+\r
+            PcdList.append((PcdCName, TokenSpaceGuid,SkuName, Dummy4))\r
+            PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid] = Setting\r
+        # Remove redundant PCD candidates, per the ARCH and SKU\r
+        for PcdCName, TokenSpaceGuid, SkuName,Dummy4 in PcdList:\r
+            Setting = PcdDict[self._Arch, SkuName, PcdCName, TokenSpaceGuid]\r
+            if Setting == None:\r
+                continue\r
+            #\r
+            # For the VOID* type, it can have optional data of MaxDatumSize and InitialValue\r
+            # For the Integer & Boolean type, the optional data can only be InitialValue.\r
+            # At this point, we put all the data into the PcdClssObject for we don't know the PCD's datumtype\r
+            # until the DEC parser has been called.\r
+            # \r
+            VpdOffset, MaxDatumSize, InitialValue = self._ValidatePcd(PcdCName, TokenSpaceGuid, Setting, Type, Dummy4)\r
+            SkuInfo = SkuInfoClass(SkuName, self.SkuIds[SkuName], '', '', '', '', VpdOffset, InitialValue)\r
+            if (PcdCName,TokenSpaceGuid) in Pcds.keys():  \r
+                pcdObject = Pcds[PcdCName,TokenSpaceGuid]\r
+                pcdObject.SkuInfoList[SkuName] = SkuInfo\r
+                if MaxDatumSize.strip():\r
+                    CurrentMaxSize = int(MaxDatumSize.strip(),0)\r
+                else:\r
+                    CurrentMaxSize = 0\r
+                if pcdObject.MaxDatumSize:\r
+                    PcdMaxSize = int(pcdObject.MaxDatumSize,0)\r
+                else:\r
+                    PcdMaxSize = 0\r
+                if CurrentMaxSize > PcdMaxSize:\r
+                    pcdObject.MaxDatumSize = str(CurrentMaxSize)\r
+            else:\r
+                Pcds[PcdCName, TokenSpaceGuid] = PcdClassObject(\r
+                                                PcdCName,\r
+                                                TokenSpaceGuid,\r
+                                                self._PCD_TYPE_STRING_[Type],\r
+                                                '',\r
+                                                InitialValue,\r
+                                                '',\r
+                                                MaxDatumSize,\r
+                                                {SkuName : SkuInfo},\r
+                                                False,\r
+                                                None\r
+                                                )\r
+        for pcd in Pcds.values():\r
+            SkuInfoObj = pcd.SkuInfoList.values()[0]\r
+            pcdDecObject = self._DecPcds[pcd.TokenCName,pcd.TokenSpaceGuidCName]\r
+            if 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' not in pcd.SkuInfoList.keys():\r
+                valuefromDec = pcdDecObject.DefaultValue\r
+                SkuInfo = SkuInfoClass('DEFAULT', '0', '', '', '','',SkuInfoObj.VpdOffset, valuefromDec)\r
+                pcd.SkuInfoList['DEFAULT'] = SkuInfo\r
+            elif 'DEFAULT' not in pcd.SkuInfoList.keys() and 'COMMON' in pcd.SkuInfoList.keys():\r
+                pcd.SkuInfoList['DEFAULT'] = pcd.SkuInfoList['COMMON']\r
+                del(pcd.SkuInfoList['COMMON'])\r
+            elif 'DEFAULT' in pcd.SkuInfoList.keys() and 'COMMON' in pcd.SkuInfoList.keys():\r
+                del(pcd.SkuInfoList['COMMON'])\r
+            if SkuObj.SkuUsageType == SkuObj.SINGLE:\r
+                if 'DEFAULT' in pcd.SkuInfoList.keys() and SkuObj.SystemSkuId not in pcd.SkuInfoList.keys():\r
+                    pcd.SkuInfoList[SkuObj.SystemSkuId] = pcd.SkuInfoList['DEFAULT']\r
+                del(pcd.SkuInfoList['DEFAULT'])\r
+            \r
+        return Pcds\r
+\r
+    ## Add external modules\r
+    #\r
+    #   The external modules are mostly those listed in FDF file, which don't\r
+    # need "build".\r
+    #\r
+    #   @param  FilePath    The path of module description file\r
+    #\r
+    def AddModule(self, FilePath):\r
+        FilePath = NormPath(FilePath)\r
+        if FilePath not in self.Modules:\r
+            Module = ModuleBuildClassObject()\r
+            Module.MetaFile = FilePath\r
+            self.Modules.append(Module)\r
+\r
+    ## Add external PCDs\r
+    #\r
+    #   The external PCDs are mostly those listed in FDF file to specify address\r
+    # or offset information.\r
+    #\r
+    #   @param  Name    Name of the PCD\r
+    #   @param  Guid    Token space guid of the PCD\r
+    #   @param  Value   Value of the PCD\r
+    #\r
+    def AddPcd(self, Name, Guid, Value):\r
+        if (Name, Guid) not in self.Pcds:\r
+            self.Pcds[Name, Guid] = PcdClassObject(Name, Guid, '', '', '', '', '', {}, False, None)\r
+        self.Pcds[Name, Guid].DefaultValue = Value\r
+\r
+    _Macros             = property(_GetMacros)\r
+    Arch                = property(_GetArch, _SetArch)\r
+    Platform            = property(_GetPlatformName)\r
+    PlatformName        = property(_GetPlatformName)\r
+    Guid                = property(_GetFileGuid)\r
+    Version             = property(_GetVersion)\r
+    DscSpecification    = property(_GetDscSpec)\r
+    OutputDirectory     = property(_GetOutpuDir)\r
+    SupArchList         = property(_GetSupArch)\r
+    BuildTargets        = property(_GetBuildTarget)\r
+    SkuName             = property(_GetSkuName, _SetSkuName)\r
+    SkuIdentifier       = property(_GetSkuIdentifier)\r
+    AvilableSkuIds = property(_GetAviableSkuIds)\r
+    PcdInfoFlag         = property(_GetPcdInfoFlag)\r
+    VarCheckFlag = property(_GetVarCheckFlag)\r
+    FlashDefinition     = property(_GetFdfFile)\r
+    Prebuild            = property(_GetPrebuild)\r
+    Postbuild           = property(_GetPostbuild)\r
+    BuildNumber         = property(_GetBuildNumber)\r
+    MakefileName        = property(_GetMakefileName)\r
+    BsBaseAddress       = property(_GetBsBaseAddress)\r
+    RtBaseAddress       = property(_GetRtBaseAddress)\r
+    LoadFixAddress      = property(_GetLoadFixAddress)\r
+    RFCLanguages        = property(_GetRFCLanguages)\r
+    ISOLanguages        = property(_GetISOLanguages)\r
+    VpdToolGuid         = property(_GetVpdToolGuid)   \r
+    SkuIds              = property(_GetSkuIds)\r
+    Modules             = property(_GetModules)\r
+    LibraryInstances    = property(_GetLibraryInstances)\r
+    LibraryClasses      = property(_GetLibraryClasses)\r
+    Pcds                = property(_GetPcds)\r
+    BuildOptions        = property(_GetBuildOptions)\r
+\r
+## Platform build information from DEC file\r
+#\r
+#  This class is used to retrieve information stored in database and convert them\r
+# into PackageBuildClassObject form for easier use for AutoGen.\r
+#\r
+class DecBuildData(PackageBuildClassObject):\r
+    # dict used to convert PCD type in database to string used by build tool\r
+    _PCD_TYPE_STRING_ = {\r
+        MODEL_PCD_FIXED_AT_BUILD        :   "FixedAtBuild",\r
+        MODEL_PCD_PATCHABLE_IN_MODULE   :   "PatchableInModule",\r
+        MODEL_PCD_FEATURE_FLAG          :   "FeatureFlag",\r
+        MODEL_PCD_DYNAMIC               :   "Dynamic",\r
+        MODEL_PCD_DYNAMIC_DEFAULT       :   "Dynamic",\r
+        MODEL_PCD_DYNAMIC_HII           :   "DynamicHii",\r
+        MODEL_PCD_DYNAMIC_VPD           :   "DynamicVpd",\r
+        MODEL_PCD_DYNAMIC_EX            :   "DynamicEx",\r
+        MODEL_PCD_DYNAMIC_EX_DEFAULT    :   "DynamicEx",\r
+        MODEL_PCD_DYNAMIC_EX_HII        :   "DynamicExHii",\r
+        MODEL_PCD_DYNAMIC_EX_VPD        :   "DynamicExVpd",\r
+    }\r
+\r
+    # dict used to convert part of [Defines] to members of DecBuildData directly\r
+    _PROPERTY_ = {\r
+        #\r
+        # Required Fields\r
+        #\r
+        TAB_DEC_DEFINES_PACKAGE_NAME                : "_PackageName",\r
+        TAB_DEC_DEFINES_PACKAGE_GUID                : "_Guid",\r
+        TAB_DEC_DEFINES_PACKAGE_VERSION             : "_Version",\r
+        TAB_DEC_DEFINES_PKG_UNI_FILE                : "_PkgUniFile",\r
+    }\r
+\r
+\r
+    ## Constructor of DecBuildData\r
+    #\r
+    #  Initialize object of DecBuildData\r
+    #\r
+    #   @param      FilePath        The path of package description file\r
+    #   @param      RawData         The raw data of DEC file\r
+    #   @param      BuildDataBase   Database used to retrieve module information\r
+    #   @param      Arch            The target architecture\r
+    #   @param      Platform        (not used for DecBuildData)\r
+    #   @param      Macros          Macros used for replacement in DSC file\r
+    #\r
+    def __init__(self, File, RawData, BuildDataBase, Arch='COMMON', Target=None, Toolchain=None):\r
+        self.MetaFile = File\r
+        self._PackageDir = File.Dir\r
+        self._RawData = RawData\r
+        self._Bdb = BuildDataBase\r
+        self._Arch = Arch\r
+        self._Target = Target\r
+        self._Toolchain = Toolchain\r
+        self._Clear()\r
+\r
+    ## XXX[key] = value\r
+    def __setitem__(self, key, value):\r
+        self.__dict__[self._PROPERTY_[key]] = value\r
+\r
+    ## value = XXX[key]\r
+    def __getitem__(self, key):\r
+        return self.__dict__[self._PROPERTY_[key]]\r
+\r
+    ## "in" test support\r
+    def __contains__(self, key):\r
+        return key in self._PROPERTY_\r
+\r
+    ## Set all internal used members of DecBuildData to None\r
+    def _Clear(self):\r
+        self._Header            = None\r
+        self._PackageName       = None\r
+        self._Guid              = None\r
+        self._Version           = None\r
+        self._PkgUniFile        = None\r
+        self._Protocols         = None\r
+        self._Ppis              = None\r
+        self._Guids             = None\r
+        self._Includes          = None\r
+        self._LibraryClasses    = None\r
+        self._Pcds              = None\r
+        self.__Macros           = None\r
+\r
+    ## Get current effective macros\r
+    def _GetMacros(self):\r
+        if self.__Macros == None:\r
+            self.__Macros = {}\r
+            self.__Macros.update(GlobalData.gGlobalDefines)\r
+        return self.__Macros\r
+\r
+    ## Get architecture\r
+    def _GetArch(self):\r
+        return self._Arch\r
+\r
+    ## Set architecture\r
+    #\r
+    #   Changing the default ARCH to another may affect all other information\r
+    # because all information in a platform may be ARCH-related. That's\r
+    # why we need to clear all internal used members, in order to cause all\r
+    # information to be re-retrieved.\r
+    #\r
+    #   @param  Value   The value of ARCH\r
+    #\r
+    def _SetArch(self, Value):\r
+        if self._Arch == Value:\r
+            return\r
+        self._Arch = Value\r
+        self._Clear()\r
+\r
+    ## Retrieve all information in [Defines] section\r
+    #\r
+    #   (Retriving all [Defines] information in one-shot is just to save time.)\r
+    #\r
+    def _GetHeaderInfo(self):\r
+        RecordList = self._RawData[MODEL_META_DATA_HEADER, self._Arch]\r
+        for Record in RecordList:\r
+            Name = Record[1]\r
+            if Name in self:\r
+                self[Name] = Record[2]\r
+        self._Header = 'DUMMY'\r
+\r
+    ## Retrieve package name\r
+    def _GetPackageName(self):\r
+        if self._PackageName == None:\r
+            if self._Header == None:\r
+                self._GetHeaderInfo()\r
+            if self._PackageName == None:\r
+                EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, "No PACKAGE_NAME", File=self.MetaFile)\r
+        return self._PackageName\r
+\r
+    ## Retrieve file guid\r
+    def _GetFileGuid(self):\r
+        if self._Guid == None:\r
+            if self._Header == None:\r
+                self._GetHeaderInfo()\r
+            if self._Guid == None:\r
+                EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, "No PACKAGE_GUID", File=self.MetaFile)\r
+        return self._Guid\r
+\r
+    ## Retrieve package version\r
+    def _GetVersion(self):\r
+        if self._Version == None:\r
+            if self._Header == None:\r
+                self._GetHeaderInfo()\r
+            if self._Version == None:\r
+                self._Version = ''\r
+        return self._Version\r
+\r
+    ## Retrieve protocol definitions (name/value pairs)\r
+    def _GetProtocol(self):\r
+        if self._Protocols == None:\r
+            #\r
+            # tdict is a special kind of dict, used for selecting correct\r
+            # protocol defition for given ARCH\r
+            #\r
+            ProtocolDict = tdict(True)\r
+            NameList = []\r
+            # find out all protocol definitions for specific and 'common' arch\r
+            RecordList = self._RawData[MODEL_EFI_PROTOCOL, self._Arch]\r
+            for Name, Guid, Dummy, Arch, ID, LineNo in RecordList:\r
+                if Name not in NameList:\r
+                    NameList.append(Name)\r
+                ProtocolDict[Arch, Name] = Guid\r
+            # use sdict to keep the order\r
+            self._Protocols = sdict()\r
+            for Name in NameList:\r
+                #\r
+                # limit the ARCH to self._Arch, if no self._Arch found, tdict\r
+                # will automatically turn to 'common' ARCH for trying\r
+                #\r
+                self._Protocols[Name] = ProtocolDict[self._Arch, Name]\r
+        return self._Protocols\r
+\r
+    ## Retrieve PPI definitions (name/value pairs)\r
+    def _GetPpi(self):\r
+        if self._Ppis == None:\r
+            #\r
+            # tdict is a special kind of dict, used for selecting correct\r
+            # PPI defition for given ARCH\r
+            #\r
+            PpiDict = tdict(True)\r
+            NameList = []\r
+            # find out all PPI definitions for specific arch and 'common' arch\r
+            RecordList = self._RawData[MODEL_EFI_PPI, self._Arch]\r
+            for Name, Guid, Dummy, Arch, ID, LineNo in RecordList:\r
+                if Name not in NameList:\r
+                    NameList.append(Name)\r
+                PpiDict[Arch, Name] = Guid\r
+            # use sdict to keep the order\r
+            self._Ppis = sdict()\r
+            for Name in NameList:\r
+                #\r
+                # limit the ARCH to self._Arch, if no self._Arch found, tdict\r
+                # will automatically turn to 'common' ARCH for trying\r
+                #\r
+                self._Ppis[Name] = PpiDict[self._Arch, Name]\r
+        return self._Ppis\r
+\r
+    ## Retrieve GUID definitions (name/value pairs)\r
+    def _GetGuid(self):\r
+        if self._Guids == None:\r
+            #\r
+            # tdict is a special kind of dict, used for selecting correct\r
+            # GUID defition for given ARCH\r
+            #\r
+            GuidDict = tdict(True)\r
+            NameList = []\r
+            # find out all protocol definitions for specific and 'common' arch\r
+            RecordList = self._RawData[MODEL_EFI_GUID, self._Arch]\r
+            for Name, Guid, Dummy, Arch, ID, LineNo in RecordList:\r
+                if Name not in NameList:\r
+                    NameList.append(Name)\r
+                GuidDict[Arch, Name] = Guid\r
+            # use sdict to keep the order\r
+            self._Guids = sdict()\r
+            for Name in NameList:\r
+                #\r
+                # limit the ARCH to self._Arch, if no self._Arch found, tdict\r
+                # will automatically turn to 'common' ARCH for trying\r
+                #\r
+                self._Guids[Name] = GuidDict[self._Arch, Name]\r
+        return self._Guids\r
+\r
+    ## Retrieve public include paths declared in this package\r
+    def _GetInclude(self):\r
+        if self._Includes == None:\r
+            self._Includes = []\r
+            RecordList = self._RawData[MODEL_EFI_INCLUDE, self._Arch]\r
+            Macros = self._Macros\r
+            Macros["EDK_SOURCE"] = GlobalData.gEcpSource\r
+            for Record in RecordList:\r
+                File = PathClass(NormPath(Record[0], Macros), self._PackageDir, Arch=self._Arch)\r
+                LineNo = Record[-1]\r
+                # validate the path\r
+                ErrorCode, ErrorInfo = File.Validate()\r
+                if ErrorCode != 0:\r
+                    EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo, File=self.MetaFile, Line=LineNo)\r
+\r
+                # avoid duplicate include path\r
+                if File not in self._Includes:\r
+                    self._Includes.append(File)\r
+        return self._Includes\r
+\r
+    ## Retrieve library class declarations (not used in build at present)\r
+    def _GetLibraryClass(self):\r
+        if self._LibraryClasses == None:\r
+            #\r
+            # tdict is a special kind of dict, used for selecting correct\r
+            # library class declaration for given ARCH\r
+            #\r
+            LibraryClassDict = tdict(True)\r
+            LibraryClassSet = set()\r
+            RecordList = self._RawData[MODEL_EFI_LIBRARY_CLASS, self._Arch]\r
+            Macros = self._Macros\r
+            for LibraryClass, File, Dummy, Arch, ID, LineNo in RecordList:\r
+                File = PathClass(NormPath(File, Macros), self._PackageDir, Arch=self._Arch)\r
+                # check the file validation\r
+                ErrorCode, ErrorInfo = File.Validate()\r
+                if ErrorCode != 0:\r
+                    EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo, File=self.MetaFile, Line=LineNo)\r
+                LibraryClassSet.add(LibraryClass)\r
+                LibraryClassDict[Arch, LibraryClass] = File\r
+            self._LibraryClasses = sdict()\r
+            for LibraryClass in LibraryClassSet:\r
+                self._LibraryClasses[LibraryClass] = LibraryClassDict[self._Arch, LibraryClass]\r
+        return self._LibraryClasses\r
+\r
+    ## Retrieve PCD declarations\r
+    def _GetPcds(self):\r
+        if self._Pcds == None:\r
+            self._Pcds = sdict()\r
+            self._Pcds.update(self._GetPcd(MODEL_PCD_FIXED_AT_BUILD))\r
+            self._Pcds.update(self._GetPcd(MODEL_PCD_PATCHABLE_IN_MODULE))\r
+            self._Pcds.update(self._GetPcd(MODEL_PCD_FEATURE_FLAG))\r
+            self._Pcds.update(self._GetPcd(MODEL_PCD_DYNAMIC))\r
+            self._Pcds.update(self._GetPcd(MODEL_PCD_DYNAMIC_EX))\r
+        return self._Pcds\r
+\r
+    ## Retrieve PCD declarations for given type\r
+    def _GetPcd(self, Type):\r
+        Pcds = sdict()\r
+        #\r
+        # tdict is a special kind of dict, used for selecting correct\r
+        # PCD declaration for given ARCH\r
+        #\r
+        PcdDict = tdict(True, 3)\r
+        # for summarizing PCD\r
+        PcdSet = set()\r
+        # find out all PCDs of the 'type'\r
+        RecordList = self._RawData[Type, self._Arch]\r
+        for TokenSpaceGuid, PcdCName, Setting, Arch, Dummy1, Dummy2 in RecordList:\r
+            PcdDict[Arch, PcdCName, TokenSpaceGuid] = Setting\r
+            PcdSet.add((PcdCName, TokenSpaceGuid))\r
+\r
+        for PcdCName, TokenSpaceGuid in PcdSet:\r
+            #\r
+            # limit the ARCH to self._Arch, if no self._Arch found, tdict\r
+            # will automatically turn to 'common' ARCH and try again\r
+            #\r
+            Setting = PcdDict[self._Arch, PcdCName, TokenSpaceGuid]\r
+            if Setting == None:\r
+                continue\r
+\r
+            DefaultValue, DatumType, TokenNumber = AnalyzePcdData(Setting)\r
+                                       \r
+            validateranges, validlists, expressions = self._RawData.GetValidExpression(TokenSpaceGuid, PcdCName)                          \r
+            Pcds[PcdCName, TokenSpaceGuid, self._PCD_TYPE_STRING_[Type]] = PcdClassObject(\r
+                                                                            PcdCName,\r
+                                                                            TokenSpaceGuid,\r
+                                                                            self._PCD_TYPE_STRING_[Type],\r
+                                                                            DatumType,\r
+                                                                            DefaultValue,\r
+                                                                            TokenNumber,\r
+                                                                            '',\r
+                                                                            {},\r
+                                                                            False,\r
+                                                                            None,\r
+                                                                            list(validateranges),\r
+                                                                            list(validlists),\r
+                                                                            list(expressions)\r
+                                                                            )\r
+        return Pcds\r
+\r
+\r
+    _Macros         = property(_GetMacros)\r
+    Arch            = property(_GetArch, _SetArch)\r
+    PackageName     = property(_GetPackageName)\r
+    Guid            = property(_GetFileGuid)\r
+    Version         = property(_GetVersion)\r
+\r
+    Protocols       = property(_GetProtocol)\r
+    Ppis            = property(_GetPpi)\r
+    Guids           = property(_GetGuid)\r
+    Includes        = property(_GetInclude)\r
+    LibraryClasses  = property(_GetLibraryClass)\r
+    Pcds            = property(_GetPcds)\r
+\r
+## Module build information from INF file\r
+#\r
+#  This class is used to retrieve information stored in database and convert them\r
+# into ModuleBuildClassObject form for easier use for AutoGen.\r
+#\r
+class InfBuildData(ModuleBuildClassObject):\r
+    # dict used to convert PCD type in database to string used by build tool\r
+    _PCD_TYPE_STRING_ = {\r
+        MODEL_PCD_FIXED_AT_BUILD        :   "FixedAtBuild",\r
+        MODEL_PCD_PATCHABLE_IN_MODULE   :   "PatchableInModule",\r
+        MODEL_PCD_FEATURE_FLAG          :   "FeatureFlag",\r
+        MODEL_PCD_DYNAMIC               :   "Dynamic",\r
+        MODEL_PCD_DYNAMIC_DEFAULT       :   "Dynamic",\r
+        MODEL_PCD_DYNAMIC_HII           :   "DynamicHii",\r
+        MODEL_PCD_DYNAMIC_VPD           :   "DynamicVpd",\r
+        MODEL_PCD_DYNAMIC_EX            :   "DynamicEx",\r
+        MODEL_PCD_DYNAMIC_EX_DEFAULT    :   "DynamicEx",\r
+        MODEL_PCD_DYNAMIC_EX_HII        :   "DynamicExHii",\r
+        MODEL_PCD_DYNAMIC_EX_VPD        :   "DynamicExVpd",\r
+    }\r
+\r
+    # dict used to convert part of [Defines] to members of InfBuildData directly\r
+    _PROPERTY_ = {\r
+        #\r
+        # Required Fields\r
+        #\r
+        TAB_INF_DEFINES_BASE_NAME                   : "_BaseName",\r
+        TAB_INF_DEFINES_FILE_GUID                   : "_Guid",\r
+        TAB_INF_DEFINES_MODULE_TYPE                 : "_ModuleType",\r
+        #\r
+        # Optional Fields\r
+        #\r
+        #TAB_INF_DEFINES_INF_VERSION                 : "_AutoGenVersion",\r
+        TAB_INF_DEFINES_COMPONENT_TYPE              : "_ComponentType",\r
+        TAB_INF_DEFINES_MAKEFILE_NAME               : "_MakefileName",\r
+        #TAB_INF_DEFINES_CUSTOM_MAKEFILE             : "_CustomMakefile",\r
+        TAB_INF_DEFINES_DPX_SOURCE                  :"_DxsFile",\r
+        TAB_INF_DEFINES_VERSION_NUMBER              : "_Version",\r
+        TAB_INF_DEFINES_VERSION_STRING              : "_Version",\r
+        TAB_INF_DEFINES_VERSION                     : "_Version",\r
+        TAB_INF_DEFINES_PCD_IS_DRIVER               : "_PcdIsDriver",\r
+        TAB_INF_DEFINES_SHADOW                      : "_Shadow",\r
+\r
+        TAB_COMPONENTS_SOURCE_OVERRIDE_PATH         : "_SourceOverridePath",\r
+    }\r
+\r
+    # dict used to convert Component type to Module type\r
+    _MODULE_TYPE_ = {\r
+        "LIBRARY"               :   "BASE",\r
+        "SECURITY_CORE"         :   "SEC",\r
+        "PEI_CORE"              :   "PEI_CORE",\r
+        "COMBINED_PEIM_DRIVER"  :   "PEIM",\r
+        "PIC_PEIM"              :   "PEIM",\r
+        "RELOCATABLE_PEIM"      :   "PEIM",\r
+        "PE32_PEIM"             :   "PEIM",\r
+        "BS_DRIVER"             :   "DXE_DRIVER",\r
+        "RT_DRIVER"             :   "DXE_RUNTIME_DRIVER",\r
+        "SAL_RT_DRIVER"         :   "DXE_SAL_DRIVER",\r
+        "DXE_SMM_DRIVER"        :   "DXE_SMM_DRIVER",\r
+    #    "SMM_DRIVER"            :   "DXE_SMM_DRIVER",\r
+    #    "BS_DRIVER"             :   "DXE_SMM_DRIVER",\r
+    #    "BS_DRIVER"             :   "UEFI_DRIVER",\r
+        "APPLICATION"           :   "UEFI_APPLICATION",\r
+        "LOGO"                  :   "BASE",\r
+    }\r
+\r
+    # regular expression for converting XXX_FLAGS in [nmake] section to new type\r
+    _NMAKE_FLAG_PATTERN_ = re.compile("(?:EBC_)?([A-Z]+)_(?:STD_|PROJ_|ARCH_)?FLAGS(?:_DLL|_ASL|_EXE)?", re.UNICODE)\r
+    # dict used to convert old tool name used in [nmake] section to new ones\r
+    _TOOL_CODE_ = {\r
+        "C"         :   "CC",\r
+        "LIB"       :   "SLINK",\r
+        "LINK"      :   "DLINK",\r
+    }\r
+\r
+\r
+    ## Constructor of DscBuildData\r
+    #\r
+    #  Initialize object of DscBuildData\r
+    #\r
+    #   @param      FilePath        The path of platform description file\r
+    #   @param      RawData         The raw data of DSC file\r
+    #   @param      BuildDataBase   Database used to retrieve module/package information\r
+    #   @param      Arch            The target architecture\r
+    #   @param      Platform        The name of platform employing this module\r
+    #   @param      Macros          Macros used for replacement in DSC file\r
+    #\r
+    def __init__(self, FilePath, RawData, BuildDatabase, Arch='COMMON', Target=None, Toolchain=None):\r
+        self.MetaFile = FilePath\r
+        self._ModuleDir = FilePath.Dir\r
+        self._RawData = RawData\r
+        self._Bdb = BuildDatabase\r
+        self._Arch = Arch\r
+        self._Target = Target\r
+        self._Toolchain = Toolchain\r
+        self._Platform = 'COMMON'\r
+        self._SourceOverridePath = None\r
+        if FilePath.Key in GlobalData.gOverrideDir:\r
+            self._SourceOverridePath = GlobalData.gOverrideDir[FilePath.Key]\r
+        self._Clear()\r
+\r
+    ## XXX[key] = value\r
+    def __setitem__(self, key, value):\r
+        self.__dict__[self._PROPERTY_[key]] = value\r
+\r
+    ## value = XXX[key]\r
+    def __getitem__(self, key):\r
+        return self.__dict__[self._PROPERTY_[key]]\r
+\r
+    ## "in" test support\r
+    def __contains__(self, key):\r
+        return key in self._PROPERTY_\r
+\r
+    ## Set all internal used members of InfBuildData to None\r
+    def _Clear(self):\r
+        self._HeaderComments = None\r
+        self._TailComments = None\r
+        self._Header_               = None\r
+        self._AutoGenVersion        = None\r
+        self._BaseName              = None\r
+        self._DxsFile               = None\r
+        self._ModuleType            = None\r
+        self._ComponentType         = None\r
+        self._BuildType             = None\r
+        self._Guid                  = None\r
+        self._Version               = None\r
+        self._PcdIsDriver           = None\r
+        self._BinaryModule          = None\r
+        self._Shadow                = None\r
+        self._MakefileName          = None\r
+        self._CustomMakefile        = None\r
+        self._Specification         = None\r
+        self._LibraryClass          = None\r
+        self._ModuleEntryPointList  = None\r
+        self._ModuleUnloadImageList = None\r
+        self._ConstructorList       = None\r
+        self._DestructorList        = None\r
+        self._Defs                  = None\r
+        self._Binaries              = None\r
+        self._Sources               = None\r
+        self._LibraryClasses        = None\r
+        self._Libraries             = None\r
+        self._Protocols             = None\r
+        self._ProtocolComments = None\r
+        self._Ppis                  = None\r
+        self._PpiComments = None\r
+        self._Guids                 = None\r
+        self._GuidsUsedByPcd = sdict()\r
+        self._GuidComments = None\r
+        self._Includes              = None\r
+        self._Packages              = None\r
+        self._Pcds                  = None\r
+        self._PcdComments = None\r
+        self._BuildOptions          = None\r
+        self._Depex                 = None\r
+        self._DepexExpression       = None\r
+        self.__Macros               = None\r
+\r
+    ## Get current effective macros\r
+    def _GetMacros(self):\r
+        if self.__Macros == None:\r
+            self.__Macros = {}\r
+            # EDK_GLOBAL defined macros can be applied to EDK module\r
+            if self.AutoGenVersion < 0x00010005:\r
+                self.__Macros.update(GlobalData.gEdkGlobal)\r
+                self.__Macros.update(GlobalData.gGlobalDefines)\r
+        return self.__Macros\r
+\r
+    ## Get architecture\r
+    def _GetArch(self):\r
+        return self._Arch\r
+\r
+    ## Set architecture\r
+    #\r
+    #   Changing the default ARCH to another may affect all other information\r
+    # because all information in a platform may be ARCH-related. That's\r
+    # why we need to clear all internal used members, in order to cause all\r
+    # information to be re-retrieved.\r
+    #\r
+    #   @param  Value   The value of ARCH\r
+    #\r
+    def _SetArch(self, Value):\r
+        if self._Arch == Value:\r
+            return\r
+        self._Arch = Value\r
+        self._Clear()\r
+\r
+    ## Return the name of platform employing this module\r
+    def _GetPlatform(self):\r
+        return self._Platform\r
+\r
+    ## Change the name of platform employing this module\r
+    #\r
+    #   Changing the default name of platform to another may affect some information\r
+    # because they may be PLATFORM-related. That's why we need to clear all internal\r
+    # used members, in order to cause all information to be re-retrieved.\r
+    #\r
+    def _SetPlatform(self, Value):\r
+        if self._Platform == Value:\r
+            return\r
+        self._Platform = Value\r
+        self._Clear()\r
+    def _GetHeaderComments(self):\r
+        if not self._HeaderComments:\r
+            self._HeaderComments = []\r
+            RecordList = self._RawData[MODEL_META_DATA_HEADER_COMMENT]\r
+            for Record in RecordList:\r
+                self._HeaderComments.append(Record[0])\r
+        return self._HeaderComments\r
+    def _GetTailComments(self):\r
+        if not self._TailComments:\r
+            self._TailComments = []\r
+            RecordList = self._RawData[MODEL_META_DATA_TAIL_COMMENT]\r
+            for Record in RecordList:\r
+                self._TailComments.append(Record[0])\r
+        return self._TailComments\r
+    ## Retrieve all information in [Defines] section\r
+    #\r
+    #   (Retriving all [Defines] information in one-shot is just to save time.)\r
+    #\r
+    def _GetHeaderInfo(self):\r
+        RecordList = self._RawData[MODEL_META_DATA_HEADER, self._Arch, self._Platform]\r
+        for Record in RecordList:\r
+            Name, Value = Record[1], ReplaceMacro(Record[2], self._Macros, False)\r
+            # items defined _PROPERTY_ don't need additional processing\r
+            if Name in self:\r
+                self[Name] = Value\r
+                if self._Defs == None:\r
+                    self._Defs = sdict()\r
+                self._Defs[Name] = Value\r
+            # some special items in [Defines] section need special treatment\r
+            elif Name in ('EFI_SPECIFICATION_VERSION', 'UEFI_SPECIFICATION_VERSION', 'EDK_RELEASE_VERSION', 'PI_SPECIFICATION_VERSION'):\r
+                if Name in ('EFI_SPECIFICATION_VERSION', 'UEFI_SPECIFICATION_VERSION'):\r
+                    Name = 'UEFI_SPECIFICATION_VERSION'\r
+                if self._Specification == None:\r
+                    self._Specification = sdict()\r
+                self._Specification[Name] = GetHexVerValue(Value)\r
+                if self._Specification[Name] == None:\r
+                    EdkLogger.error("build", FORMAT_NOT_SUPPORTED,\r
+                                    "'%s' format is not supported for %s" % (Value, Name),\r
+                                    File=self.MetaFile, Line=Record[-1])\r
+            elif Name == 'LIBRARY_CLASS':\r
+                if self._LibraryClass == None:\r
+                    self._LibraryClass = []\r
+                ValueList = GetSplitValueList(Value)\r
+                LibraryClass = ValueList[0]\r
+                if len(ValueList) > 1:\r
+                    SupModuleList = GetSplitValueList(ValueList[1], ' ')\r
+                else:\r
+                    SupModuleList = SUP_MODULE_LIST\r
+                self._LibraryClass.append(LibraryClassObject(LibraryClass, SupModuleList))\r
+            elif Name == 'ENTRY_POINT':\r
+                if self._ModuleEntryPointList == None:\r
+                    self._ModuleEntryPointList = []\r
+                self._ModuleEntryPointList.append(Value)\r
+            elif Name == 'UNLOAD_IMAGE':\r
+                if self._ModuleUnloadImageList == None:\r
+                    self._ModuleUnloadImageList = []\r
+                if not Value:\r
+                    continue\r
+                self._ModuleUnloadImageList.append(Value)\r
+            elif Name == 'CONSTRUCTOR':\r
+                if self._ConstructorList == None:\r
+                    self._ConstructorList = []\r
+                if not Value:\r
+                    continue\r
+                self._ConstructorList.append(Value)\r
+            elif Name == 'DESTRUCTOR':\r
+                if self._DestructorList == None:\r
+                    self._DestructorList = []\r
+                if not Value:\r
+                    continue\r
+                self._DestructorList.append(Value)\r
+            elif Name == TAB_INF_DEFINES_CUSTOM_MAKEFILE:\r
+                TokenList = GetSplitValueList(Value)\r
+                if self._CustomMakefile == None:\r
+                    self._CustomMakefile = {}\r
+                if len(TokenList) < 2:\r
+                    self._CustomMakefile['MSFT'] = TokenList[0]\r
+                    self._CustomMakefile['GCC'] = TokenList[0]\r
+                else:\r
+                    if TokenList[0] not in ['MSFT', 'GCC']:\r
+                        EdkLogger.error("build", FORMAT_NOT_SUPPORTED,\r
+                                        "No supported family [%s]" % TokenList[0],\r
+                                        File=self.MetaFile, Line=Record[-1])\r
+                    self._CustomMakefile[TokenList[0]] = TokenList[1]\r
+            else:\r
+                if self._Defs == None:\r
+                    self._Defs = sdict()\r
+                self._Defs[Name] = Value\r
+\r
+        #\r
+        # Retrieve information in sections specific to Edk.x modules\r
+        #\r
+        if self.AutoGenVersion >= 0x00010005:\r
+            if not self._ModuleType:\r
+                EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE,\r
+                                "MODULE_TYPE is not given", File=self.MetaFile)\r
+            if self._ModuleType not in SUP_MODULE_LIST:\r
+                RecordList = self._RawData[MODEL_META_DATA_HEADER, self._Arch, self._Platform]\r
+                for Record in RecordList:\r
+                    Name = Record[1]\r
+                    if Name == "MODULE_TYPE":\r
+                        LineNo = Record[6]\r
+                        break\r
+                EdkLogger.error("build", FORMAT_NOT_SUPPORTED,\r
+                                "MODULE_TYPE %s is not supported for EDK II, valid values are:\n %s" % (self._ModuleType, ' '.join(l for l in SUP_MODULE_LIST)),\r
+                                File=self.MetaFile, Line=LineNo)\r
+            if (self._Specification == None) or (not 'PI_SPECIFICATION_VERSION' in self._Specification) or (int(self._Specification['PI_SPECIFICATION_VERSION'], 16) < 0x0001000A):\r
+                if self._ModuleType == SUP_MODULE_SMM_CORE:\r
+                    EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "SMM_CORE module type can't be used in the module with PI_SPECIFICATION_VERSION less than 0x0001000A", File=self.MetaFile)\r
+            if self._Defs and 'PCI_DEVICE_ID' in self._Defs and 'PCI_VENDOR_ID' in self._Defs \\r
+               and 'PCI_CLASS_CODE' in self._Defs:\r
+                self._BuildType = 'UEFI_OPTIONROM'\r
+            elif self._Defs and 'UEFI_HII_RESOURCE_SECTION' in self._Defs \\r
+               and self._Defs['UEFI_HII_RESOURCE_SECTION'] == 'TRUE':\r
+                self._BuildType = 'UEFI_HII'\r
+            else:\r
+                self._BuildType = self._ModuleType.upper()\r
+\r
+            if self._DxsFile:\r
+                File = PathClass(NormPath(self._DxsFile), self._ModuleDir, Arch=self._Arch)\r
+                # check the file validation\r
+                ErrorCode, ErrorInfo = File.Validate(".dxs", CaseSensitive=False)\r
+                if ErrorCode != 0:\r
+                    EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo,\r
+                                    File=self.MetaFile, Line=LineNo)\r
+                if self.Sources == None:\r
+                    self._Sources = []\r
+                self._Sources.append(File)\r
+        else:  \r
+            if not self._ComponentType:\r
+                EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE,\r
+                                "COMPONENT_TYPE is not given", File=self.MetaFile)\r
+            self._BuildType = self._ComponentType.upper()\r
+            if self._ComponentType in self._MODULE_TYPE_:\r
+                self._ModuleType = self._MODULE_TYPE_[self._ComponentType]\r
+            if self._ComponentType == 'LIBRARY':\r
+                self._LibraryClass = [LibraryClassObject(self._BaseName, SUP_MODULE_LIST)]\r
+            # make use some [nmake] section macros\r
+            Macros = self._Macros\r
+            Macros["EDK_SOURCE"] = GlobalData.gEcpSource\r
+            Macros['PROCESSOR'] = self._Arch\r
+            RecordList = self._RawData[MODEL_META_DATA_NMAKE, self._Arch, self._Platform]\r
+            for Name, Value, Dummy, Arch, Platform, ID, LineNo in RecordList:\r
+                Value = ReplaceMacro(Value, Macros, True)\r
+                if Name == "IMAGE_ENTRY_POINT":\r
+                    if self._ModuleEntryPointList == None:\r
+                        self._ModuleEntryPointList = []\r
+                    self._ModuleEntryPointList.append(Value)\r
+                elif Name == "DPX_SOURCE":\r
+                    File = PathClass(NormPath(Value), self._ModuleDir, Arch=self._Arch)\r
+                    # check the file validation\r
+                    ErrorCode, ErrorInfo = File.Validate(".dxs", CaseSensitive=False)\r
+                    if ErrorCode != 0:\r
+                        EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo,\r
+                                        File=self.MetaFile, Line=LineNo)\r
+                    if self.Sources == None:\r
+                        self._Sources = []\r
+                    self._Sources.append(File)\r
+                else:\r
+                    ToolList = self._NMAKE_FLAG_PATTERN_.findall(Name)\r
+                    if len(ToolList) == 0 or len(ToolList) != 1:\r
+                        pass\r
+#                        EdkLogger.warn("build", "Don't know how to do with macro [%s]" % Name,\r
+#                                       File=self.MetaFile, Line=LineNo)\r
+                    else:\r
+                        if self._BuildOptions == None:\r
+                            self._BuildOptions = sdict()\r
+\r
+                        if ToolList[0] in self._TOOL_CODE_:\r
+                            Tool = self._TOOL_CODE_[ToolList[0]]\r
+                        else:\r
+                            Tool = ToolList[0]\r
+                        ToolChain = "*_*_*_%s_FLAGS" % Tool\r
+                        ToolChainFamily = 'MSFT'    # Edk.x only support MSFT tool chain\r
+                        #ignore not replaced macros in value\r
+                        ValueList = GetSplitList(' ' + Value, '/D')\r
+                        Dummy = ValueList[0]\r
+                        for Index in range(1, len(ValueList)):\r
+                            if ValueList[Index][-1] == '=' or ValueList[Index] == '':\r
+                                continue\r
+                            Dummy = Dummy + ' /D ' + ValueList[Index]\r
+                        Value = Dummy.strip()\r
+                        if (ToolChainFamily, ToolChain) not in self._BuildOptions:\r
+                            self._BuildOptions[ToolChainFamily, ToolChain] = Value\r
+                        else:\r
+                            OptionString = self._BuildOptions[ToolChainFamily, ToolChain]\r
+                            self._BuildOptions[ToolChainFamily, ToolChain] = OptionString + " " + Value\r
+        # set _Header to non-None in order to avoid database re-querying\r
+        self._Header_ = 'DUMMY'\r
+\r
+    ## Retrieve file version\r
+    def _GetInfVersion(self):\r
+        if self._AutoGenVersion == None:\r
+            RecordList = self._RawData[MODEL_META_DATA_HEADER, self._Arch, self._Platform]\r
+            for Record in RecordList:\r
+                if Record[1] == TAB_INF_DEFINES_INF_VERSION:\r
+                    if '.' in Record[2]:\r
+                        ValueList = Record[2].split('.')\r
+                        Major = '%04o' % int(ValueList[0], 0)\r
+                        Minor = '%04o' % int(ValueList[1], 0)\r
+                        self._AutoGenVersion = int('0x' + Major + Minor, 0)\r
+                    else:\r
+                        self._AutoGenVersion = int(Record[2], 0)\r
+                    break\r
+            if self._AutoGenVersion == None:\r
+                self._AutoGenVersion = 0x00010000\r
+        return self._AutoGenVersion\r
+\r
+    ## Retrieve BASE_NAME\r
+    def _GetBaseName(self):\r
+        if self._BaseName == None:\r
+            if self._Header_ == None:\r
+                self._GetHeaderInfo()\r
+            if self._BaseName == None:\r
+                EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No BASE_NAME name", File=self.MetaFile)\r
+        return self._BaseName\r
+\r
+    ## Retrieve DxsFile\r
+    def _GetDxsFile(self):\r
+        if self._DxsFile == None:\r
+            if self._Header_ == None:\r
+                self._GetHeaderInfo()\r
+            if self._DxsFile == None:\r
+                self._DxsFile = ''\r
+        return self._DxsFile\r
+\r
+    ## Retrieve MODULE_TYPE\r
+    def _GetModuleType(self):\r
+        if self._ModuleType == None:\r
+            if self._Header_ == None:\r
+                self._GetHeaderInfo()\r
+            if self._ModuleType == None:\r
+                self._ModuleType = 'BASE'\r
+            if self._ModuleType not in SUP_MODULE_LIST:\r
+                self._ModuleType = "USER_DEFINED"\r
+        return self._ModuleType\r
+\r
+    ## Retrieve COMPONENT_TYPE\r
+    def _GetComponentType(self):\r
+        if self._ComponentType == None:\r
+            if self._Header_ == None:\r
+                self._GetHeaderInfo()\r
+            if self._ComponentType == None:\r
+                self._ComponentType = 'USER_DEFINED'\r
+        return self._ComponentType\r
+\r
+    ## Retrieve "BUILD_TYPE"\r
+    def _GetBuildType(self):\r
+        if self._BuildType == None:\r
+            if self._Header_ == None:\r
+                self._GetHeaderInfo()\r
+            if not self._BuildType:\r
+                self._BuildType = "BASE"\r
+        return self._BuildType\r
+\r
+    ## Retrieve file guid\r
+    def _GetFileGuid(self):\r
+        if self._Guid == None:\r
+            if self._Header_ == None:\r
+                self._GetHeaderInfo()\r
+            if self._Guid == None:\r
+                self._Guid = '00000000-0000-0000-0000-000000000000'\r
+        return self._Guid\r
+\r
+    ## Retrieve module version\r
+    def _GetVersion(self):\r
+        if self._Version == None:\r
+            if self._Header_ == None:\r
+                self._GetHeaderInfo()\r
+            if self._Version == None:\r
+                self._Version = '0.0'\r
+        return self._Version\r
+\r
+    ## Retrieve PCD_IS_DRIVER\r
+    def _GetPcdIsDriver(self):\r
+        if self._PcdIsDriver == None:\r
+            if self._Header_ == None:\r
+                self._GetHeaderInfo()\r
+            if self._PcdIsDriver == None:\r
+                self._PcdIsDriver = ''\r
+        return self._PcdIsDriver\r
+\r
+    ## Retrieve SHADOW\r
+    def _GetShadow(self):\r
+        if self._Shadow == None:\r
+            if self._Header_ == None:\r
+                self._GetHeaderInfo()\r
+            if self._Shadow != None and self._Shadow.upper() == 'TRUE':\r
+                self._Shadow = True\r
+            else:\r
+                self._Shadow = False\r
+        return self._Shadow\r
+\r
+    ## Retrieve CUSTOM_MAKEFILE\r
+    def _GetMakefile(self):\r
+        if self._CustomMakefile == None:\r
+            if self._Header_ == None:\r
+                self._GetHeaderInfo()\r
+            if self._CustomMakefile == None:\r
+                self._CustomMakefile = {}\r
+        return self._CustomMakefile\r
+\r
+    ## Retrieve EFI_SPECIFICATION_VERSION\r
+    def _GetSpec(self):\r
+        if self._Specification == None:\r
+            if self._Header_ == None:\r
+                self._GetHeaderInfo()\r
+            if self._Specification == None:\r
+                self._Specification = {}\r
+        return self._Specification\r
+\r
+    ## Retrieve LIBRARY_CLASS\r
+    def _GetLibraryClass(self):\r
+        if self._LibraryClass == None:\r
+            if self._Header_ == None:\r
+                self._GetHeaderInfo()\r
+            if self._LibraryClass == None:\r
+                self._LibraryClass = []\r
+        return self._LibraryClass\r
+\r
+    ## Retrieve ENTRY_POINT\r
+    def _GetEntryPoint(self):\r
+        if self._ModuleEntryPointList == None:\r
+            if self._Header_ == None:\r
+                self._GetHeaderInfo()\r
+            if self._ModuleEntryPointList == None:\r
+                self._ModuleEntryPointList = []\r
+        return self._ModuleEntryPointList\r
+\r
+    ## Retrieve UNLOAD_IMAGE\r
+    def _GetUnloadImage(self):\r
+        if self._ModuleUnloadImageList == None:\r
+            if self._Header_ == None:\r
+                self._GetHeaderInfo()\r
+            if self._ModuleUnloadImageList == None:\r
+                self._ModuleUnloadImageList = []\r
+        return self._ModuleUnloadImageList\r
+\r
+    ## Retrieve CONSTRUCTOR\r
+    def _GetConstructor(self):\r
+        if self._ConstructorList == None:\r
+            if self._Header_ == None:\r
+                self._GetHeaderInfo()\r
+            if self._ConstructorList == None:\r
+                self._ConstructorList = []\r
+        return self._ConstructorList\r
+\r
+    ## Retrieve DESTRUCTOR\r
+    def _GetDestructor(self):\r
+        if self._DestructorList == None:\r
+            if self._Header_ == None:\r
+                self._GetHeaderInfo()\r
+            if self._DestructorList == None:\r
+                self._DestructorList = []\r
+        return self._DestructorList\r
+\r
+    ## Retrieve definies other than above ones\r
+    def _GetDefines(self):\r
+        if self._Defs == None:\r
+            if self._Header_ == None:\r
+                self._GetHeaderInfo()\r
+            if self._Defs == None:\r
+                self._Defs = sdict()\r
+        return self._Defs\r
+\r
+    ## Retrieve binary files\r
+    def _GetBinaries(self):\r
+        if self._Binaries == None:\r
+            self._Binaries = []\r
+            RecordList = self._RawData[MODEL_EFI_BINARY_FILE, self._Arch, self._Platform]\r
+            Macros = self._Macros\r
+            Macros["EDK_SOURCE"] = GlobalData.gEcpSource\r
+            Macros['PROCESSOR'] = self._Arch\r
+            for Record in RecordList:\r
+                FileType = Record[0]\r
+                LineNo = Record[-1]\r
+                Target = 'COMMON'\r
+                FeatureFlag = []\r
+                if Record[2]:\r
+                    TokenList = GetSplitValueList(Record[2], TAB_VALUE_SPLIT)\r
+                    if TokenList:\r
+                        Target = TokenList[0]\r
+                    if len(TokenList) > 1:\r
+                        FeatureFlag = Record[1:]\r
+\r
+                File = PathClass(NormPath(Record[1], Macros), self._ModuleDir, '', FileType, True, self._Arch, '', Target)\r
+                # check the file validation\r
+                ErrorCode, ErrorInfo = File.Validate()\r
+                if ErrorCode != 0:\r
+                    EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo, File=self.MetaFile, Line=LineNo)\r
+                self._Binaries.append(File)\r
+        return self._Binaries\r
+\r
+    ## Retrieve binary files with error check.\r
+    def _GetBinaryFiles(self):\r
+        Binaries = self._GetBinaries()\r
+        if GlobalData.gIgnoreSource and Binaries == []:\r
+            ErrorInfo = "The INF file does not contain any Binaries to use in creating the image\n"\r
+            EdkLogger.error('build', RESOURCE_NOT_AVAILABLE, ExtraData=ErrorInfo, File=self.MetaFile)\r
+\r
+        return Binaries\r
+    ## Check whether it exists the binaries with current ARCH in AsBuild INF\r
+    def _IsSupportedArch(self):\r
+        if self._GetBinaries() and not self._GetSourceFiles():\r
+            return True\r
+        else:\r
+            return False\r
+    ## Retrieve source files\r
+    def _GetSourceFiles(self):\r
+        #Ignore all source files in a binary build mode\r
+        if GlobalData.gIgnoreSource:\r
+            self._Sources = []\r
+            return self._Sources\r
+\r
+        if self._Sources == None:\r
+            self._Sources = []\r
+            RecordList = self._RawData[MODEL_EFI_SOURCE_FILE, self._Arch, self._Platform]\r
+            Macros = self._Macros\r
+            for Record in RecordList:\r
+                LineNo = Record[-1]\r
+                ToolChainFamily = Record[1]\r
+                TagName = Record[2]\r
+                ToolCode = Record[3]\r
+                FeatureFlag = Record[4]\r
+                if self.AutoGenVersion < 0x00010005:\r
+                    Macros["EDK_SOURCE"] = GlobalData.gEcpSource\r
+                    Macros['PROCESSOR'] = self._Arch\r
+                    SourceFile = NormPath(Record[0], Macros)\r
+                    if SourceFile[0] == os.path.sep:\r
+                        SourceFile = mws.join(GlobalData.gWorkspace, SourceFile[1:])\r
+                    # old module source files (Edk)\r
+                    File = PathClass(SourceFile, self._ModuleDir, self._SourceOverridePath,\r
+                                     '', False, self._Arch, ToolChainFamily, '', TagName, ToolCode)\r
+                    # check the file validation\r
+                    ErrorCode, ErrorInfo = File.Validate(CaseSensitive=False)\r
+                    if ErrorCode != 0:\r
+                        if File.Ext.lower() == '.h':\r
+                            EdkLogger.warn('build', 'Include file not found', ExtraData=ErrorInfo,\r
+                                           File=self.MetaFile, Line=LineNo)\r
+                            continue\r
+                        else:\r
+                            EdkLogger.error('build', ErrorCode, ExtraData=File, File=self.MetaFile, Line=LineNo)\r
+                else:\r
+                    File = PathClass(NormPath(Record[0], Macros), self._ModuleDir, '',\r
+                                     '', False, self._Arch, ToolChainFamily, '', TagName, ToolCode)\r
+                    # check the file validation\r
+                    ErrorCode, ErrorInfo = File.Validate()\r
+                    if ErrorCode != 0:\r
+                        EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo, File=self.MetaFile, Line=LineNo)\r
+\r
+                self._Sources.append(File)\r
+        return self._Sources\r
+\r
+    ## Retrieve library classes employed by this module\r
+    def _GetLibraryClassUses(self):\r
+        if self._LibraryClasses == None:\r
+            self._LibraryClasses = sdict()\r
+            RecordList = self._RawData[MODEL_EFI_LIBRARY_CLASS, self._Arch, self._Platform]\r
+            for Record in RecordList:\r
+                Lib = Record[0]\r
+                Instance = Record[1]\r
+                if Instance:\r
+                    Instance = NormPath(Instance, self._Macros)\r
+                self._LibraryClasses[Lib] = Instance\r
+        return self._LibraryClasses\r
+\r
+    ## Retrieve library names (for Edk.x style of modules)\r
+    def _GetLibraryNames(self):\r
+        if self._Libraries == None:\r
+            self._Libraries = []\r
+            RecordList = self._RawData[MODEL_EFI_LIBRARY_INSTANCE, self._Arch, self._Platform]\r
+            for Record in RecordList:\r
+                LibraryName = ReplaceMacro(Record[0], self._Macros, False)\r
+                # in case of name with '.lib' extension, which is unusual in Edk.x inf\r
+                LibraryName = os.path.splitext(LibraryName)[0]\r
+                if LibraryName not in self._Libraries:\r
+                    self._Libraries.append(LibraryName)\r
+        return self._Libraries\r
+\r
+    def _GetProtocolComments(self):\r
+        self._GetProtocols()\r
+        return self._ProtocolComments\r
+    ## Retrieve protocols consumed/produced by this module\r
+    def _GetProtocols(self):\r
+        if self._Protocols == None:\r
+            self._Protocols = sdict()\r
+            self._ProtocolComments = sdict()\r
+            RecordList = self._RawData[MODEL_EFI_PROTOCOL, self._Arch, self._Platform]\r
+            for Record in RecordList:\r
+                CName = Record[0]\r
+                Value = ProtocolValue(CName, self.Packages)\r
+                if Value == None:\r
+                    PackageList = "\n\t".join([str(P) for P in self.Packages])\r
+                    EdkLogger.error('build', RESOURCE_NOT_AVAILABLE,\r
+                                    "Value of Protocol [%s] is not found under [Protocols] section in" % CName,\r
+                                    ExtraData=PackageList, File=self.MetaFile, Line=Record[-1])\r
+                self._Protocols[CName] = Value\r
+                CommentRecords = self._RawData[MODEL_META_DATA_COMMENT, self._Arch, self._Platform, Record[5]]\r
+                Comments = []\r
+                for CmtRec in CommentRecords:\r
+                    Comments.append(CmtRec[0])\r
+                self._ProtocolComments[CName] = Comments\r
+        return self._Protocols\r
+\r
+    def _GetPpiComments(self):\r
+        self._GetPpis()\r
+        return self._PpiComments\r
+    ## Retrieve PPIs consumed/produced by this module\r
+    def _GetPpis(self):\r
+        if self._Ppis == None:\r
+            self._Ppis = sdict()\r
+            self._PpiComments = sdict()\r
+            RecordList = self._RawData[MODEL_EFI_PPI, self._Arch, self._Platform]\r
+            for Record in RecordList:\r
+                CName = Record[0]\r
+                Value = PpiValue(CName, self.Packages)\r
+                if Value == None:\r
+                    PackageList = "\n\t".join([str(P) for P in self.Packages])\r
+                    EdkLogger.error('build', RESOURCE_NOT_AVAILABLE,\r
+                                    "Value of PPI [%s] is not found under [Ppis] section in " % CName,\r
+                                    ExtraData=PackageList, File=self.MetaFile, Line=Record[-1])\r
+                self._Ppis[CName] = Value\r
+                CommentRecords = self._RawData[MODEL_META_DATA_COMMENT, self._Arch, self._Platform, Record[5]]\r
+                Comments = []\r
+                for CmtRec in CommentRecords:\r
+                    Comments.append(CmtRec[0])\r
+                self._PpiComments[CName] = Comments\r
+        return self._Ppis\r
+\r
+    def _GetGuidComments(self):\r
+        self._GetGuids()\r
+        return self._GuidComments\r
+    ## Retrieve GUIDs consumed/produced by this module\r
+    def _GetGuids(self):\r
+        if self._Guids == None:\r
+            self._Guids = sdict()\r
+            self._GuidComments = sdict()\r
+            RecordList = self._RawData[MODEL_EFI_GUID, self._Arch, self._Platform]\r
+            for Record in RecordList:\r
+                CName = Record[0]\r
+                Value = GuidValue(CName, self.Packages)\r
+                if Value == None:\r
+                    PackageList = "\n\t".join([str(P) for P in self.Packages])\r
+                    EdkLogger.error('build', RESOURCE_NOT_AVAILABLE,\r
+                                    "Value of Guid [%s] is not found under [Guids] section in" % CName,\r
+                                    ExtraData=PackageList, File=self.MetaFile, Line=Record[-1])\r
+                self._Guids[CName] = Value\r
+                CommentRecords = self._RawData[MODEL_META_DATA_COMMENT, self._Arch, self._Platform, Record[5]]\r
+                Comments = []\r
+                for CmtRec in CommentRecords:\r
+                    Comments.append(CmtRec[0])\r
+                self._GuidComments[CName] = Comments\r
+        return self._Guids\r
+\r
+    ## Retrieve include paths necessary for this module (for Edk.x style of modules)\r
+    def _GetIncludes(self):\r
+        if self._Includes == None:\r
+            self._Includes = []\r
+            if self._SourceOverridePath:\r
+                self._Includes.append(self._SourceOverridePath)\r
+\r
+            Macros = self._Macros\r
+            if 'PROCESSOR' in GlobalData.gEdkGlobal.keys():\r
+                Macros['PROCESSOR'] = GlobalData.gEdkGlobal['PROCESSOR']\r
+            else:\r
+                Macros['PROCESSOR'] = self._Arch\r
+            RecordList = self._RawData[MODEL_EFI_INCLUDE, self._Arch, self._Platform]\r
+            for Record in RecordList:\r
+                if Record[0].find('EDK_SOURCE') > -1:\r
+                    Macros['EDK_SOURCE'] = GlobalData.gEcpSource\r
+                    File = NormPath(Record[0], self._Macros)\r
+                    if File[0] == '.':\r
+                        File = os.path.join(self._ModuleDir, File)\r
+                    else:\r
+                        File = os.path.join(GlobalData.gWorkspace, File)\r
+                    File = RealPath(os.path.normpath(File))\r
+                    if File:\r
+                        self._Includes.append(File)\r
+\r
+                    #TRICK: let compiler to choose correct header file\r
+                    Macros['EDK_SOURCE'] = GlobalData.gEdkSource\r
+                    File = NormPath(Record[0], self._Macros)\r
+                    if File[0] == '.':\r
+                        File = os.path.join(self._ModuleDir, File)\r
+                    else:\r
+                        File = os.path.join(GlobalData.gWorkspace, File)\r
+                    File = RealPath(os.path.normpath(File))\r
+                    if File:\r
+                        self._Includes.append(File)\r
+                else:\r
+                    File = NormPath(Record[0], Macros)\r
+                    if File[0] == '.':\r
+                        File = os.path.join(self._ModuleDir, File)\r
+                    else:\r
+                        File = mws.join(GlobalData.gWorkspace, File)\r
+                    File = RealPath(os.path.normpath(File))\r
+                    if File:\r
+                        self._Includes.append(File)\r
+                    if not File and Record[0].find('EFI_SOURCE') > -1:\r
+                        # tricky to regard WorkSpace as EFI_SOURCE\r
+                        Macros['EFI_SOURCE'] = GlobalData.gWorkspace\r
+                        File = NormPath(Record[0], Macros)\r
+                        if File[0] == '.':\r
+                            File = os.path.join(self._ModuleDir, File)\r
+                        else:\r
+                            File = os.path.join(GlobalData.gWorkspace, File)\r
+                        File = RealPath(os.path.normpath(File))\r
+                        if File:\r
+                            self._Includes.append(File)\r
+        return self._Includes\r
+\r
+    ## Retrieve packages this module depends on\r
+    def _GetPackages(self):\r
+        if self._Packages == None:\r
+            self._Packages = []\r
+            RecordList = self._RawData[MODEL_META_DATA_PACKAGE, self._Arch, self._Platform]\r
+            Macros = self._Macros\r
+            Macros['EDK_SOURCE'] = GlobalData.gEcpSource\r
+            for Record in RecordList:\r
+                File = PathClass(NormPath(Record[0], Macros), GlobalData.gWorkspace, Arch=self._Arch)\r
+                LineNo = Record[-1]\r
+                # check the file validation\r
+                ErrorCode, ErrorInfo = File.Validate('.dec')\r
+                if ErrorCode != 0:\r
+                    EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo, File=self.MetaFile, Line=LineNo)\r
+                # parse this package now. we need it to get protocol/ppi/guid value\r
+                Package = self._Bdb[File, self._Arch, self._Target, self._Toolchain]\r
+                self._Packages.append(Package)\r
+        return self._Packages\r
+\r
+    ## Retrieve PCD comments\r
+    def _GetPcdComments(self):\r
+        self._GetPcds()\r
+        return self._PcdComments\r
+    ## Retrieve PCDs used in this module\r
+    def _GetPcds(self):\r
+        if self._Pcds == None:\r
+            self._Pcds = sdict()\r
+            self._PcdComments = sdict()\r
+            self._Pcds.update(self._GetPcd(MODEL_PCD_FIXED_AT_BUILD))\r
+            self._Pcds.update(self._GetPcd(MODEL_PCD_PATCHABLE_IN_MODULE))\r
+            self._Pcds.update(self._GetPcd(MODEL_PCD_FEATURE_FLAG))\r
+            self._Pcds.update(self._GetPcd(MODEL_PCD_DYNAMIC))\r
+            self._Pcds.update(self._GetPcd(MODEL_PCD_DYNAMIC_EX))\r
+        return self._Pcds\r
+\r
+    ## Retrieve build options specific to this module\r
+    def _GetBuildOptions(self):\r
+        if self._BuildOptions == None:\r
+            self._BuildOptions = sdict()\r
+            RecordList = self._RawData[MODEL_META_DATA_BUILD_OPTION, self._Arch, self._Platform]\r
+            for Record in RecordList:\r
+                ToolChainFamily = Record[0]\r
+                ToolChain = Record[1]\r
+                Option = Record[2]\r
+                if (ToolChainFamily, ToolChain) not in self._BuildOptions or Option.startswith('='):\r
+                    self._BuildOptions[ToolChainFamily, ToolChain] = Option\r
+                else:\r
+                    # concatenate the option string if they're for the same tool\r
+                    OptionString = self._BuildOptions[ToolChainFamily, ToolChain]\r
+                    self._BuildOptions[ToolChainFamily, ToolChain] = OptionString + " " + Option\r
+        return self._BuildOptions\r
+\r
+    ## Retrieve dependency expression\r
+    def _GetDepex(self):\r
+        if self._Depex == None:\r
+            self._Depex = tdict(False, 2)\r
+            RecordList = self._RawData[MODEL_EFI_DEPEX, self._Arch]\r
+            \r
+            # If the module has only Binaries and no Sources, then ignore [Depex] \r
+            if self.Sources == None or self.Sources == []:\r
+                if self.Binaries != None and self.Binaries != []:\r
+                    return self._Depex\r
+                \r
+            # PEIM and DXE drivers must have a valid [Depex] section\r
+            if len(self.LibraryClass) == 0 and len(RecordList) == 0:\r
+                if self.ModuleType == 'DXE_DRIVER' or self.ModuleType == 'PEIM' or self.ModuleType == 'DXE_SMM_DRIVER' or \\r
+                    self.ModuleType == 'DXE_SAL_DRIVER' or self.ModuleType == 'DXE_RUNTIME_DRIVER':\r
+                    EdkLogger.error('build', RESOURCE_NOT_AVAILABLE, "No [Depex] section or no valid expression in [Depex] section for [%s] module" \\r
+                                    % self.ModuleType, File=self.MetaFile)\r
+\r
+            if len(RecordList) != 0 and self.ModuleType == 'USER_DEFINED':\r
+                for Record in RecordList:\r
+                    if Record[4] not in ['PEIM', 'DXE_DRIVER', 'DXE_SMM_DRIVER']:\r
+                        EdkLogger.error('build', FORMAT_INVALID,\r
+                                        "'%s' module must specify the type of [Depex] section" % self.ModuleType,\r
+                                        File=self.MetaFile)\r
+\r
+            Depex = sdict()\r
+            for Record in RecordList:\r
+                DepexStr = ReplaceMacro(Record[0], self._Macros, False)\r
+                Arch = Record[3]\r
+                ModuleType = Record[4]\r
+                TokenList = DepexStr.split()\r
+                if (Arch, ModuleType) not in Depex:\r
+                    Depex[Arch, ModuleType] = []\r
+                DepexList = Depex[Arch, ModuleType]\r
+                for Token in TokenList:\r
+                    if Token in DEPEX_SUPPORTED_OPCODE:\r
+                        DepexList.append(Token)\r
+                    elif Token.endswith(".inf"):    # module file name\r
+                        ModuleFile = os.path.normpath(Token)\r
+                        Module = self.BuildDatabase[ModuleFile]\r
+                        if Module == None:\r
+                            EdkLogger.error('build', RESOURCE_NOT_AVAILABLE, "Module is not found in active platform",\r
+                                            ExtraData=Token, File=self.MetaFile, Line=Record[-1])\r
+                        DepexList.append(Module.Guid)\r
+                    else:\r
+                        # get the GUID value now\r
+                        Value = ProtocolValue(Token, self.Packages)\r
+                        if Value == None:\r
+                            Value = PpiValue(Token, self.Packages)\r
+                            if Value == None:\r
+                                Value = GuidValue(Token, self.Packages)\r
+                        if Value == None:\r
+                            PackageList = "\n\t".join([str(P) for P in self.Packages])\r
+                            EdkLogger.error('build', RESOURCE_NOT_AVAILABLE,\r
+                                            "Value of [%s] is not found in" % Token,\r
+                                            ExtraData=PackageList, File=self.MetaFile, Line=Record[-1])\r
+                        DepexList.append(Value)\r
+            for Arch, ModuleType in Depex:\r
+                self._Depex[Arch, ModuleType] = Depex[Arch, ModuleType]\r
+        return self._Depex\r
+\r
+    ## Retrieve depedency expression\r
+    def _GetDepexExpression(self):\r
+        if self._DepexExpression == None:\r
+            self._DepexExpression = tdict(False, 2)\r
+            RecordList = self._RawData[MODEL_EFI_DEPEX, self._Arch]\r
+            DepexExpression = sdict()\r
+            for Record in RecordList:\r
+                DepexStr = ReplaceMacro(Record[0], self._Macros, False)\r
+                Arch = Record[3]\r
+                ModuleType = Record[4]\r
+                TokenList = DepexStr.split()\r
+                if (Arch, ModuleType) not in DepexExpression:\r
+                    DepexExpression[Arch, ModuleType] = ''\r
+                for Token in TokenList:\r
+                    DepexExpression[Arch, ModuleType] = DepexExpression[Arch, ModuleType] + Token.strip() + ' '\r
+            for Arch, ModuleType in DepexExpression:\r
+                self._DepexExpression[Arch, ModuleType] = DepexExpression[Arch, ModuleType]\r
+        return self._DepexExpression\r
+\r
+    def GetGuidsUsedByPcd(self):\r
+        return self._GuidsUsedByPcd\r
+    ## Retrieve PCD for given type\r
+    def _GetPcd(self, Type):\r
+        Pcds = sdict()\r
+        PcdDict = tdict(True, 4)\r
+        PcdList = []\r
+        RecordList = self._RawData[Type, self._Arch, self._Platform]\r
+        for TokenSpaceGuid, PcdCName, Setting, Arch, Platform, Id, LineNo in RecordList:\r
+            PcdDict[Arch, Platform, PcdCName, TokenSpaceGuid] = (Setting, LineNo)\r
+            PcdList.append((PcdCName, TokenSpaceGuid))\r
+            # get the guid value\r
+            if TokenSpaceGuid not in self.Guids:\r
+                Value = GuidValue(TokenSpaceGuid, self.Packages)\r
+                if Value == None:\r
+                    PackageList = "\n\t".join([str(P) for P in self.Packages])\r
+                    EdkLogger.error('build', RESOURCE_NOT_AVAILABLE,\r
+                                    "Value of Guid [%s] is not found under [Guids] section in" % TokenSpaceGuid,\r
+                                    ExtraData=PackageList, File=self.MetaFile, Line=LineNo)\r
+                self.Guids[TokenSpaceGuid] = Value\r
+                self._GuidsUsedByPcd[TokenSpaceGuid] = Value\r
+            CommentRecords = self._RawData[MODEL_META_DATA_COMMENT, self._Arch, self._Platform, Id]\r
+            Comments = []\r
+            for CmtRec in CommentRecords:\r
+                Comments.append(CmtRec[0])\r
+            self._PcdComments[TokenSpaceGuid, PcdCName] = Comments\r
+\r
+        # resolve PCD type, value, datum info, etc. by getting its definition from package\r
+        for PcdCName, TokenSpaceGuid in PcdList:\r
+            Setting, LineNo = PcdDict[self._Arch, self.Platform, PcdCName, TokenSpaceGuid]\r
+            if Setting == None:\r
+                continue\r
+            ValueList = AnalyzePcdData(Setting)\r
+            DefaultValue = ValueList[0]\r
+            Pcd = PcdClassObject(\r
+                    PcdCName,\r
+                    TokenSpaceGuid,\r
+                    '',\r
+                    '',\r
+                    DefaultValue,\r
+                    '',\r
+                    '',\r
+                    {},\r
+                    False,\r
+                    self.Guids[TokenSpaceGuid]\r
+                    )\r
+            if Type == MODEL_PCD_PATCHABLE_IN_MODULE and ValueList[1]:\r
+                # Patch PCD: TokenSpace.PcdCName|Value|Offset\r
+                Pcd.Offset = ValueList[1]\r
+\r
+            # get necessary info from package declaring this PCD\r
+            for Package in self.Packages:\r
+                #\r
+                # 'dynamic' in INF means its type is determined by platform;\r
+                # if platform doesn't give its type, use 'lowest' one in the\r
+                # following order, if any\r
+                #\r
+                #   "FixedAtBuild", "PatchableInModule", "FeatureFlag", "Dynamic", "DynamicEx"\r
+                #\r
+                PcdType = self._PCD_TYPE_STRING_[Type]\r
+                if Type == MODEL_PCD_DYNAMIC:\r
+                    Pcd.Pending = True\r
+                    for T in ["FixedAtBuild", "PatchableInModule", "FeatureFlag", "Dynamic", "DynamicEx"]:\r
+                        if (PcdCName, TokenSpaceGuid, T) in Package.Pcds:\r
+                            PcdType = T\r
+                            break\r
+                else:\r
+                    Pcd.Pending = False\r
+\r
+                if (PcdCName, TokenSpaceGuid, PcdType) in Package.Pcds:\r
+                    PcdInPackage = Package.Pcds[PcdCName, TokenSpaceGuid, PcdType]\r
+                    Pcd.Type = PcdType\r
+                    Pcd.TokenValue = PcdInPackage.TokenValue\r
+                    \r
+                    #\r
+                    # Check whether the token value exist or not.\r
+                    #\r
+                    if Pcd.TokenValue == None or Pcd.TokenValue == "":\r
+                        EdkLogger.error(\r
+                                'build',\r
+                                FORMAT_INVALID,\r
+                                "No TokenValue for PCD [%s.%s] in [%s]!" % (TokenSpaceGuid, PcdCName, str(Package)),\r
+                                File=self.MetaFile, Line=LineNo,\r
+                                ExtraData=None\r
+                                )                        \r
+                    #\r
+                    # Check hexadecimal token value length and format.\r
+                    #\r
+                    ReIsValidPcdTokenValue = re.compile(r"^[0][x|X][0]*[0-9a-fA-F]{1,8}$", re.DOTALL)\r
+                    if Pcd.TokenValue.startswith("0x") or Pcd.TokenValue.startswith("0X"):\r
+                        if ReIsValidPcdTokenValue.match(Pcd.TokenValue) == None:\r
+                            EdkLogger.error(\r
+                                    'build',\r
+                                    FORMAT_INVALID,\r
+                                    "The format of TokenValue [%s] of PCD [%s.%s] in [%s] is invalid:" % (Pcd.TokenValue, TokenSpaceGuid, PcdCName, str(Package)),\r
+                                    File=self.MetaFile, Line=LineNo,\r
+                                    ExtraData=None\r
+                                    )\r
+                            \r
+                    #\r
+                    # Check decimal token value length and format.\r
+                    #                            \r
+                    else:\r
+                        try:\r
+                            TokenValueInt = int (Pcd.TokenValue, 10)\r
+                            if (TokenValueInt < 0 or TokenValueInt > 4294967295):\r
+                                EdkLogger.error(\r
+                                            'build',\r
+                                            FORMAT_INVALID,\r
+                                            "The format of TokenValue [%s] of PCD [%s.%s] in [%s] is invalid, as a decimal it should between: 0 - 4294967295!" % (Pcd.TokenValue, TokenSpaceGuid, PcdCName, str(Package)),\r
+                                            File=self.MetaFile, Line=LineNo,\r
+                                            ExtraData=None\r
+                                            )\r
+                        except:\r
+                            EdkLogger.error(\r
+                                        'build',\r
+                                        FORMAT_INVALID,\r
+                                        "The format of TokenValue [%s] of PCD [%s.%s] in [%s] is invalid, it should be hexadecimal or decimal!" % (Pcd.TokenValue, TokenSpaceGuid, PcdCName, str(Package)),\r
+                                        File=self.MetaFile, Line=LineNo,\r
+                                        ExtraData=None\r
+                                        )\r
+\r
+                    Pcd.DatumType = PcdInPackage.DatumType\r
+                    Pcd.MaxDatumSize = PcdInPackage.MaxDatumSize\r
+                    Pcd.InfDefaultValue = Pcd.DefaultValue\r
+                    if Pcd.DefaultValue in [None, '']:\r
+                        Pcd.DefaultValue = PcdInPackage.DefaultValue\r
+                    break\r
+            else:\r
+                EdkLogger.error(\r
+                            'build',\r
+                            FORMAT_INVALID,\r
+                            "PCD [%s.%s] in [%s] is not found in dependent packages:" % (TokenSpaceGuid, PcdCName, self.MetaFile),\r
+                            File=self.MetaFile, Line=LineNo,\r
+                            ExtraData="\t%s" % '\n\t'.join([str(P) for P in self.Packages])\r
+                            )\r
+            Pcds[PcdCName, TokenSpaceGuid] = Pcd\r
+\r
+        return Pcds\r
+\r
+    ## check whether current module is binary module\r
+    def _IsBinaryModule(self):\r
+        if self.Binaries and not self.Sources:\r
+            return True\r
+        elif GlobalData.gIgnoreSource:\r
+            return True\r
+        else:\r
+            return False\r
+\r
+    _Macros = property(_GetMacros)\r
+    Arch = property(_GetArch, _SetArch)\r
+    Platform = property(_GetPlatform, _SetPlatform)\r
+\r
+    HeaderComments = property(_GetHeaderComments)\r
+    TailComments = property(_GetTailComments)\r
+    AutoGenVersion          = property(_GetInfVersion)\r
+    BaseName                = property(_GetBaseName)\r
+    ModuleType              = property(_GetModuleType)\r
+    ComponentType           = property(_GetComponentType)\r
+    BuildType               = property(_GetBuildType)\r
+    Guid                    = property(_GetFileGuid)\r
+    Version                 = property(_GetVersion)\r
+    PcdIsDriver             = property(_GetPcdIsDriver)\r
+    Shadow                  = property(_GetShadow)\r
+    CustomMakefile          = property(_GetMakefile)\r
+    Specification           = property(_GetSpec)\r
+    LibraryClass            = property(_GetLibraryClass)\r
+    ModuleEntryPointList    = property(_GetEntryPoint)\r
+    ModuleUnloadImageList   = property(_GetUnloadImage)\r
+    ConstructorList         = property(_GetConstructor)\r
+    DestructorList          = property(_GetDestructor)\r
+    Defines                 = property(_GetDefines)\r
+    DxsFile                 = property(_GetDxsFile)\r
+    \r
+    Binaries                = property(_GetBinaryFiles)\r
+    Sources                 = property(_GetSourceFiles)\r
+    LibraryClasses          = property(_GetLibraryClassUses)\r
+    Libraries               = property(_GetLibraryNames)\r
+    Protocols               = property(_GetProtocols)\r
+    ProtocolComments = property(_GetProtocolComments)\r
+    Ppis                    = property(_GetPpis)\r
+    PpiComments = property(_GetPpiComments)\r
+    Guids                   = property(_GetGuids)\r
+    GuidComments = property(_GetGuidComments)\r
+    Includes                = property(_GetIncludes)\r
+    Packages                = property(_GetPackages)\r
+    Pcds                    = property(_GetPcds)\r
+    PcdComments = property(_GetPcdComments)\r
+    BuildOptions            = property(_GetBuildOptions)\r
+    Depex                   = property(_GetDepex)\r
+    DepexExpression         = property(_GetDepexExpression)\r
+    IsBinaryModule = property(_IsBinaryModule)\r
+    IsSupportedArch = property(_IsSupportedArch)\r
+\r
+## Database\r
+#\r
+#   This class defined the build database for all modules, packages and platform.\r
+# It will call corresponding parser for the given file if it cannot find it in\r
+# the database.\r
+#\r
+# @param DbPath             Path of database file\r
+# @param GlobalMacros       Global macros used for replacement during file parsing\r
+# @prarm RenewDb=False      Create new database file if it's already there\r
+#\r
+class WorkspaceDatabase(object):\r
+\r
+\r
+    #\r
+    # internal class used for call corresponding file parser and caching the result\r
+    # to avoid unnecessary re-parsing\r
+    #\r
+    class BuildObjectFactory(object):\r
+\r
+        _FILE_TYPE_ = {\r
+            ".inf"  : MODEL_FILE_INF,\r
+            ".dec"  : MODEL_FILE_DEC,\r
+            ".dsc"  : MODEL_FILE_DSC,\r
+        }\r
+\r
+        # file parser\r
+        _FILE_PARSER_ = {\r
+            MODEL_FILE_INF  :   InfParser,\r
+            MODEL_FILE_DEC  :   DecParser,\r
+            MODEL_FILE_DSC  :   DscParser,\r
+        }\r
+\r
+        # convert to xxxBuildData object\r
+        _GENERATOR_ = {\r
+            MODEL_FILE_INF  :   InfBuildData,\r
+            MODEL_FILE_DEC  :   DecBuildData,\r
+            MODEL_FILE_DSC  :   DscBuildData,\r
+        }\r
+\r
+        _CACHE_ = {}    # (FilePath, Arch)  : <object>\r
+\r
+        # constructor\r
+        def __init__(self, WorkspaceDb):\r
+            self.WorkspaceDb = WorkspaceDb\r
+\r
+        # key = (FilePath, Arch=None)\r
+        def __contains__(self, Key):\r
+            FilePath = Key[0]\r
+            if len(Key) > 1:\r
+                Arch = Key[1]\r
+            else:\r
+                Arch = None\r
+            return (FilePath, Arch) in self._CACHE_\r
+\r
+        # key = (FilePath, Arch=None, Target=None, Toochain=None)\r
+        def __getitem__(self, Key):\r
+            FilePath = Key[0]\r
+            KeyLength = len(Key)\r
+            if KeyLength > 1:\r
+                Arch = Key[1]\r
+            else:\r
+                Arch = None\r
+            if KeyLength > 2:\r
+                Target = Key[2]\r
+            else:\r
+                Target = None\r
+            if KeyLength > 3:\r
+                Toolchain = Key[3]\r
+            else:\r
+                Toolchain = None\r
+\r
+            # if it's generated before, just return the cached one\r
+            Key = (FilePath, Arch, Target, Toolchain)\r
+            if Key in self._CACHE_:\r
+                return self._CACHE_[Key]\r
+\r
+            # check file type\r
+            Ext = FilePath.Type\r
+            if Ext not in self._FILE_TYPE_:\r
+                return None\r
+            FileType = self._FILE_TYPE_[Ext]\r
+            if FileType not in self._GENERATOR_:\r
+                return None\r
+\r
+            # get the parser ready for this file\r
+            MetaFile = self._FILE_PARSER_[FileType](\r
+                                FilePath, \r
+                                FileType, \r
+                                MetaFileStorage(self.WorkspaceDb.Cur, FilePath, FileType)\r
+                                )\r
+            # alwasy do post-process, in case of macros change\r
+            MetaFile.DoPostProcess()\r
+            # object the build is based on\r
+            BuildObject = self._GENERATOR_[FileType](\r
+                                    FilePath,\r
+                                    MetaFile,\r
+                                    self,\r
+                                    Arch,\r
+                                    Target,\r
+                                    Toolchain\r
+                                    )\r
+            self._CACHE_[Key] = BuildObject\r
+            return BuildObject\r
+\r
+    # placeholder for file format conversion\r
+    class TransformObjectFactory:\r
+        def __init__(self, WorkspaceDb):\r
+            self.WorkspaceDb = WorkspaceDb\r
+\r
+        # key = FilePath, Arch\r
+        def __getitem__(self, Key):\r
+            pass\r
+\r
+    ## Constructor of WorkspaceDatabase\r
+    #\r
+    # @param DbPath             Path of database file\r
+    # @param GlobalMacros       Global macros used for replacement during file parsing\r
+    # @prarm RenewDb=False      Create new database file if it's already there\r
+    #\r
+    def __init__(self, DbPath, RenewDb=False):\r
+        self._DbClosedFlag = False\r
+        if not DbPath:\r
+            DbPath = os.path.normpath(mws.join(GlobalData.gWorkspace, 'Conf', GlobalData.gDatabasePath))\r
+\r
+        # don't create necessary path for db in memory\r
+        if DbPath != ':memory:':\r
+            DbDir = os.path.split(DbPath)[0]\r
+            if not os.path.exists(DbDir):\r
+                os.makedirs(DbDir)\r
+\r
+            # remove db file in case inconsistency between db and file in file system\r
+            if self._CheckWhetherDbNeedRenew(RenewDb, DbPath):\r
+                os.remove(DbPath)\r
+        \r
+        # create db with optimized parameters\r
+        self.Conn = sqlite3.connect(DbPath, isolation_level='DEFERRED')\r
+        self.Conn.execute("PRAGMA synchronous=OFF")\r
+        self.Conn.execute("PRAGMA temp_store=MEMORY")\r
+        self.Conn.execute("PRAGMA count_changes=OFF")\r
+        self.Conn.execute("PRAGMA cache_size=8192")\r
+        #self.Conn.execute("PRAGMA page_size=8192")\r
+\r
+        # to avoid non-ascii character conversion issue\r
+        self.Conn.text_factory = str\r
+        self.Cur = self.Conn.cursor()\r
+\r
+        # create table for internal uses\r
+        self.TblDataModel = TableDataModel(self.Cur)\r
+        self.TblFile = TableFile(self.Cur)\r
+        self.Platform = None\r
+\r
+        # conversion object for build or file format conversion purpose\r
+        self.BuildObject = WorkspaceDatabase.BuildObjectFactory(self)\r
+        self.TransformObject = WorkspaceDatabase.TransformObjectFactory(self)\r
+\r
+    ## Check whether workspace database need to be renew.\r
+    #  The renew reason maybe:\r
+    #  1) If user force to renew;\r
+    #  2) If user do not force renew, and\r
+    #     a) If the time of last modified python source is newer than database file;\r
+    #     b) If the time of last modified frozen executable file is newer than database file;\r
+    #\r
+    #  @param force     User force renew database\r
+    #  @param DbPath    The absolute path of workspace database file\r
+    #\r
+    #  @return Bool value for whether need renew workspace databse\r
+    #\r
+    def _CheckWhetherDbNeedRenew (self, force, DbPath):\r
+        # if database does not exist, we need do nothing\r
+        if not os.path.exists(DbPath): return False\r
+            \r
+        # if user force to renew database, then not check whether database is out of date\r
+        if force: return True\r
+        \r
+        #    \r
+        # Check the time of last modified source file or build.exe\r
+        # if is newer than time of database, then database need to be re-created.\r
+        #\r
+        timeOfToolModified = 0\r
+        if hasattr(sys, "frozen"):\r
+            exePath             = os.path.abspath(sys.executable)\r
+            timeOfToolModified  = os.stat(exePath).st_mtime\r
+        else:\r
+            curPath  = os.path.dirname(__file__) # curPath is the path of WorkspaceDatabase.py\r
+            rootPath = os.path.split(curPath)[0] # rootPath is root path of python source, such as /BaseTools/Source/Python\r
+            if rootPath == "" or rootPath == None:\r
+                EdkLogger.verbose("\nFail to find the root path of build.exe or python sources, so can not \\r
+determine whether database file is out of date!\n")\r
+        \r
+            # walk the root path of source or build's binary to get the time last modified.\r
+        \r
+            for root, dirs, files in os.walk (rootPath):\r
+                for dir in dirs:\r
+                    # bypass source control folder \r
+                    if dir.lower() in [".svn", "_svn", "cvs"]:\r
+                        dirs.remove(dir)\r
+                        \r
+                for file in files:\r
+                    ext = os.path.splitext(file)[1]\r
+                    if ext.lower() == ".py":            # only check .py files\r
+                        fd = os.stat(os.path.join(root, file))\r
+                        if timeOfToolModified < fd.st_mtime:\r
+                            timeOfToolModified = fd.st_mtime\r
+        if timeOfToolModified > os.stat(DbPath).st_mtime:\r
+            EdkLogger.verbose("\nWorkspace database is out of data!")\r
+            return True\r
+            \r
+        return False\r
+            \r
+    ## Initialize build database\r
+    def InitDatabase(self):\r
+        EdkLogger.verbose("\nInitialize build database started ...")\r
+\r
+        #\r
+        # Create new tables\r
+        #\r
+        self.TblDataModel.Create(False)\r
+        self.TblFile.Create(False)\r
+\r
+        #\r
+        # Initialize table DataModel\r
+        #\r
+        self.TblDataModel.InitTable()\r
+        EdkLogger.verbose("Initialize build database ... DONE!")\r
+\r
+    ## Query a table\r
+    #\r
+    # @param Table:  The instance of the table to be queried\r
+    #\r
+    def QueryTable(self, Table):\r
+        Table.Query()\r
+\r
+    def __del__(self):\r
+        self.Close()\r
+\r
+    ## Close entire database\r
+    #\r
+    # Commit all first\r
+    # Close the connection and cursor\r
+    #\r
+    def Close(self):\r
+        if not self._DbClosedFlag:\r
+            self.Conn.commit()\r
+            self.Cur.close()\r
+            self.Conn.close()\r
+            self._DbClosedFlag = True\r
+\r
+    ## Summarize all packages in the database\r
+    def GetPackageList(self, Platform, Arch, TargetName, ToolChainTag):\r
+        self.Platform = Platform\r
+        PackageList = []\r
+        Pa = self.BuildObject[self.Platform, 'COMMON']\r
+        #\r
+        # Get Package related to Modules\r
+        #\r
+        for Module in Pa.Modules:\r
+            ModuleObj = self.BuildObject[Module, Arch, TargetName, ToolChainTag]\r
+            for Package in ModuleObj.Packages:\r
+                if Package not in PackageList:\r
+                    PackageList.append(Package)\r
+        #\r
+        # Get Packages related to Libraries\r
+        #\r
+        for Lib in Pa.LibraryInstances:\r
+            LibObj = self.BuildObject[Lib, Arch, TargetName, ToolChainTag]\r
+            for Package in LibObj.Packages:\r
+                if Package not in PackageList:\r
+                    PackageList.append(Package)\r
+\r
+        return PackageList\r
+\r
+    ## Summarize all platforms in the database\r
+    def _GetPlatformList(self):\r
+        PlatformList = []\r
+        for PlatformFile in self.TblFile.GetFileList(MODEL_FILE_DSC):\r
+            try:\r
+                Platform = self.BuildObject[PathClass(PlatformFile), 'COMMON']\r
+            except:\r
+                Platform = None\r
+            if Platform != None:\r
+                PlatformList.append(Platform)\r
+        return PlatformList\r
+\r
+    def _MapPlatform(self, Dscfile):\r
+        try:\r
+            Platform = self.BuildObject[PathClass(Dscfile), 'COMMON']\r
+        except:\r
+            Platform = None\r
+        return Platform\r
+\r
+    PlatformList = property(_GetPlatformList)\r
+\r
+##\r
+#\r
+# This acts like the main() function for the script, unless it is 'import'ed into another\r
+# script.\r
+#\r
+if __name__ == '__main__':\r
+    pass\r
+\r