]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/AutoGen/AutoGen.py
CryptoPkg: Fix GCC build break for BaseCryptLib.
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / AutoGen.py
index 4ecf2eafe711f523020373a3436abbeeb9c0d5c3..8150ea0b69014ca45d2387323f5feb982d715788 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # Generate AutoGen.h, AutoGen.c and *.depex files\r
 #\r
-# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2007 - 2011, 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
@@ -53,6 +53,39 @@ gAutoGenStringFileName = "%(module_name)sStrDefs.h"
 gAutoGenStringFormFileName = "%(module_name)sStrDefs.hpk"\r
 gAutoGenDepexFileName = "%(module_name)s.depex"\r
 \r
+#\r
+# Template string to generic AsBuilt INF\r
+#\r
+gAsBuiltInfHeaderString = TemplateString("""## @file\r
+# ${module_name}\r
+#\r
+# DO NOT EDIT\r
+# FILE auto-generated Binary INF\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                = 0x00010016\r
+  BASE_NAME                  = ${module_name}\r
+  FILE_GUID                  = ${module_guid}\r
+  MODULE_TYPE                = ${module_module_type}\r
+  VERSION_STRING             = ${module_version_string}${BEGIN}\r
+  UEFI_SPECIFICATION_VERSION = ${module_uefi_specification_version}${END}${BEGIN}\r
+  PI_SPECIFICATION_VERSION   = ${module_pi_specification_version}${END}\r
+\r
+[Packages]${BEGIN}\r
+  ${package_item}${END}\r
+\r
+[Binaries.${module_arch}]${BEGIN}\r
+  ${binary_item}${END}\r
+\r
+[PcdEx]${BEGIN}\r
+  ${pcd_item}${END}\r
+\r
+## @AsBuilt${BEGIN}\r
+##   ${flags_item}${END}\r
+""")\r
+\r
 ## Base class for AutoGen\r
 #\r
 #   This class just implements the cache mechanism of AutoGen objects.\r
@@ -122,7 +155,7 @@ class AutoGen(object):
 class WorkspaceAutoGen(AutoGen):\r
     ## Real constructor of WorkspaceAutoGen\r
     #\r
-    # This method behaves the same as __init__ except that it needs explict invoke\r
+    # This method behaves the same as __init__ except that it needs explicit invoke\r
     # (in super class's __new__ method)\r
     #\r
     #   @param  WorkspaceDir            Root directory of workspace\r
@@ -136,10 +169,17 @@ class WorkspaceAutoGen(AutoGen):
     #   @param  FlashDefinitionFile     File of flash definition\r
     #   @param  Fds                     FD list to be generated\r
     #   @param  Fvs                     FV list to be generated\r
+    #   @param  Caps                    Capsule list to be generated\r
     #   @param  SkuId                   SKU id from command line\r
     #\r
     def _Init(self, WorkspaceDir, ActivePlatform, Target, Toolchain, ArchList, MetaFileDb,\r
-              BuildConfig, ToolDefinition, FlashDefinitionFile='', Fds=[], Fvs=[], SkuId='', UniFlag=None):\r
+              BuildConfig, ToolDefinition, FlashDefinitionFile='', Fds=None, Fvs=None, Caps=None, SkuId='', UniFlag=None):\r
+        if Fds is None:\r
+            Fds = []\r
+        if Fvs is None:\r
+            Fvs = []\r
+        if Caps is None:\r
+            Caps = []\r
         self.MetaFile       = ActivePlatform.MetaFile\r
         self.WorkspaceDir   = WorkspaceDir\r
         self.Platform       = ActivePlatform\r
@@ -155,6 +195,7 @@ class WorkspaceAutoGen(AutoGen):
         self.FdfFile        = FlashDefinitionFile\r
         self.FdTargetList   = Fds\r
         self.FvTargetList   = Fvs\r
+        self.CapTargetList  = Caps\r
         self.AutoGenObjectList = []\r
 \r
         # there's many relative directory operations, so ...\r
@@ -166,8 +207,13 @@ class WorkspaceAutoGen(AutoGen):
             # Make global macros available when parsing FDF file\r
             #\r
             InputMacroDict.update(self.BuildDatabase.WorkspaceDb._GlobalMacros)\r
+            #\r
+            # Mark now build in AutoGen Phase\r
+            #\r
+            GlobalData.gAutoGenPhase = True            \r
             Fdf = FdfParser(self.FdfFile.Path)\r
             Fdf.ParseFile()\r
+            GlobalData.gAutoGenPhase = False  \r
             PcdSet = Fdf.Profile.PcdDict\r
             ModuleList = Fdf.Profile.InfList\r
             self.FdfProfile = Fdf.Profile\r
@@ -195,6 +241,14 @@ class WorkspaceAutoGen(AutoGen):
         #\r
         self._CheckAllPcdsTokenValueConflict()\r
         \r
+        #\r
+        # Check PCD type and definition between DSC and DEC\r
+        #\r
+        self._CheckPcdDefineAndType()\r
+        \r
+        if self.FdfFile:\r
+            self._CheckDuplicateInFV(Fdf)\r
+        \r
         self._BuildDir = None\r
         self._FvDir = None\r
         self._MakeFileDir = None\r
@@ -202,6 +256,180 @@ class WorkspaceAutoGen(AutoGen):
 \r
         return True\r
 \r
+    ## _CheckDuplicateInFV() method\r
+    #\r
+    # Check whether there is duplicate modules/files exist in FV section. \r
+    # The check base on the file GUID;\r
+    #\r
+    def _CheckDuplicateInFV(self, Fdf):\r
+        for Fv in Fdf.Profile.FvDict:\r
+            _GuidDict = {}\r
+            for FfsFile in Fdf.Profile.FvDict[Fv].FfsList:\r
+                if FfsFile.InfFileName and FfsFile.NameGuid == None:\r
+                    #\r
+                    # Get INF file GUID\r
+                    #\r
+                    InfFoundFlag = False                   \r
+                    for Pa in self.AutoGenObjectList:\r
+                        for Module in Pa.ModuleAutoGenList:\r
+                            if path.normpath(Module.MetaFile.File) == path.normpath(FfsFile.InfFileName):\r
+                                InfFoundFlag = True\r
+                                if not Module.Guid.upper() in _GuidDict.keys():\r
+                                    _GuidDict[Module.Guid.upper()] = FfsFile\r
+                                else:\r
+                                    EdkLogger.error("build", \r
+                                                    FORMAT_INVALID,\r
+                                                    "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s"%(FfsFile.CurrentLineNum,\r
+                                                                                                                                   FfsFile.CurrentLineContent,\r
+                                                                                                                                   _GuidDict[Module.Guid.upper()].CurrentLineNum,\r
+                                                                                                                                   _GuidDict[Module.Guid.upper()].CurrentLineContent,\r
+                                                                                                                                   Module.Guid.upper()),\r
+                                                    ExtraData=self.FdfFile)\r
+                    #\r
+                    # Some INF files not have entity in DSC file. \r
+                    #\r
+                    if not InfFoundFlag:\r
+                        if FfsFile.InfFileName.find('$') == -1:\r
+                            InfPath = NormPath(FfsFile.InfFileName)\r
+                            if not os.path.exists(InfPath):\r
+                                EdkLogger.error('build', GENFDS_ERROR, "Non-existant Module %s !" % (FfsFile.InfFileName))\r
+                                \r
+                            PathClassObj = PathClass(FfsFile.InfFileName, self.WorkspaceDir)\r
+                            #\r
+                            # Here we just need to get FILE_GUID from INF file, use 'COMMON' as ARCH attribute. and use \r
+                            # BuildObject from one of AutoGenObjectList is enough.\r
+                            #\r
+                            InfObj = self.AutoGenObjectList[0].BuildDatabase.WorkspaceDb.BuildObject[PathClassObj, 'COMMON', self.BuildTarget, self.ToolChain]\r
+                            if not InfObj.Guid.upper() in _GuidDict.keys():\r
+                                _GuidDict[InfObj.Guid.upper()] = FfsFile\r
+                            else:\r
+                                EdkLogger.error("build", \r
+                                                FORMAT_INVALID,\r
+                                                "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s"%(FfsFile.CurrentLineNum,\r
+                                                                                                                               FfsFile.CurrentLineContent,\r
+                                                                                                                               _GuidDict[InfObj.Guid.upper()].CurrentLineNum,\r
+                                                                                                                               _GuidDict[InfObj.Guid.upper()].CurrentLineContent,\r
+                                                                                                                               InfObj.Guid.upper()),\r
+                                                ExtraData=self.FdfFile)\r
+                        InfFoundFlag = False\r
+                                                                   \r
+                if FfsFile.NameGuid != None:\r
+                    _CheckPCDAsGuidPattern = re.compile("^PCD\(.+\..+\)$")\r
+                    \r
+                    #\r
+                    # If the NameGuid reference a PCD name. \r
+                    # The style must match: PCD(xxxx.yyy)\r
+                    #\r
+                    if _CheckPCDAsGuidPattern.match(FfsFile.NameGuid):\r
+                        #\r
+                        # Replace the PCD value.\r
+                        #\r
+                        _PcdName = FfsFile.NameGuid.lstrip("PCD(").rstrip(")")\r
+                        PcdFoundFlag = False\r
+                        for Pa in self.AutoGenObjectList:\r
+                            if not PcdFoundFlag:\r
+                                for PcdItem in Pa.AllPcdList:\r
+                                    if (PcdItem.TokenSpaceGuidCName + "." + PcdItem.TokenCName) == _PcdName:\r
+                                        #\r
+                                        # First convert from CFormatGuid to GUID string\r
+                                        #\r
+                                        _PcdGuidString = GuidStructureStringToGuidString(PcdItem.DefaultValue)\r
+                                        \r
+                                        if not _PcdGuidString:\r
+                                            #\r
+                                            # Then try Byte array.\r
+                                            #\r
+                                            _PcdGuidString = GuidStructureByteArrayToGuidString(PcdItem.DefaultValue)\r
+                                            \r
+                                        if not _PcdGuidString:\r
+                                            #\r
+                                            # Not Byte array or CFormat GUID, raise error.\r
+                                            #\r
+                                            EdkLogger.error("build",\r
+                                                            FORMAT_INVALID,\r
+                                                            "The format of PCD value is incorrect. PCD: %s , Value: %s\n"%(_PcdName, PcdItem.DefaultValue),\r
+                                                            ExtraData=self.FdfFile)\r
+                                        \r
+                                        if not _PcdGuidString.upper() in _GuidDict.keys():    \r
+                                            _GuidDict[_PcdGuidString.upper()] = FfsFile\r
+                                            PcdFoundFlag = True\r
+                                            break\r
+                                        else:\r
+                                            EdkLogger.error("build", \r
+                                                            FORMAT_INVALID,\r
+                                                            "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s"%(FfsFile.CurrentLineNum,\r
+                                                                                                                                           FfsFile.CurrentLineContent,\r
+                                                                                                                                           _GuidDict[_PcdGuidString.upper()].CurrentLineNum,\r
+                                                                                                                                           _GuidDict[_PcdGuidString.upper()].CurrentLineContent,\r
+                                                                                                                                           FfsFile.NameGuid.upper()),\r
+                                                            ExtraData=self.FdfFile)                                                                       \r
+                \r
+                    if not FfsFile.NameGuid.upper() in _GuidDict.keys():\r
+                        _GuidDict[FfsFile.NameGuid.upper()] = FfsFile\r
+                    else:\r
+                        #\r
+                        # Two raw file GUID conflict.\r
+                        #\r
+                        EdkLogger.error("build", \r
+                                        FORMAT_INVALID,\r
+                                        "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s"%(FfsFile.CurrentLineNum,\r
+                                                                                                                       FfsFile.CurrentLineContent,\r
+                                                                                                                       _GuidDict[FfsFile.NameGuid.upper()].CurrentLineNum,\r
+                                                                                                                       _GuidDict[FfsFile.NameGuid.upper()].CurrentLineContent,\r
+                                                                                                                       FfsFile.NameGuid.upper()),\r
+                                        ExtraData=self.FdfFile)\r
+                \r
+\r
+    def _CheckPcdDefineAndType(self):\r
+        PcdTypeList = [\r
+            "FixedAtBuild", "PatchableInModule", "FeatureFlag",\r
+            "Dynamic", #"DynamicHii", "DynamicVpd",\r
+            "DynamicEx", # "DynamicExHii", "DynamicExVpd"\r
+        ]\r
+\r
+        # This dict store PCDs which are not used by any modules with specified arches\r
+        UnusedPcd = sdict()\r
+        for Pa in self.AutoGenObjectList:\r
+            # Key of DSC's Pcds dictionary is PcdCName, TokenSpaceGuid\r
+            for Pcd in Pa.Platform.Pcds:\r
+                PcdType = Pa.Platform.Pcds[Pcd].Type\r
+                \r
+                # If no PCD type, this PCD comes from FDF \r
+                if not PcdType:\r
+                    continue\r
+                \r
+                # Try to remove Hii and Vpd suffix\r
+                if PcdType.startswith("DynamicEx"):\r
+                    PcdType = "DynamicEx"\r
+                elif PcdType.startswith("Dynamic"):\r
+                    PcdType = "Dynamic"\r
+    \r
+                for Package in Pa.PackageList:\r
+                    # Key of DEC's Pcds dictionary is PcdCName, TokenSpaceGuid, PcdType\r
+                    if (Pcd[0], Pcd[1], PcdType) in Package.Pcds:\r
+                        break\r
+                    for Type in PcdTypeList:\r
+                        if (Pcd[0], Pcd[1], Type) in Package.Pcds:\r
+                            EdkLogger.error(\r
+                                'build',\r
+                                FORMAT_INVALID,\r
+                                "Type [%s] of PCD [%s.%s] in DSC file doesn't match the type [%s] defined in DEC file." \\r
+                                % (Pa.Platform.Pcds[Pcd].Type, Pcd[1], Pcd[0], Type),\r
+                                ExtraData=None\r
+                            )\r
+                            return\r
+                else:\r
+                    UnusedPcd.setdefault(Pcd, []).append(Pa.Arch)\r
+\r
+        for Pcd in UnusedPcd:\r
+            EdkLogger.warn(\r
+                'build',\r
+                "The PCD was not specified by any INF module in the platform for the given architecture.\n"\r
+                "\tPCD: [%s.%s]\n\tPlatform: [%s]\n\tArch: %s"\r
+                % (Pcd[1], Pcd[0], os.path.basename(str(self.MetaFile)), str(UnusedPcd[Pcd])),\r
+                ExtraData=None\r
+            )\r
+\r
     def __repr__(self):\r
         return "%s [%s]" % (self.MetaFile, ", ".join(self.ArchList))\r
 \r
@@ -261,8 +489,8 @@ class WorkspaceAutoGen(AutoGen):
     # @return  None\r
     #\r
     def _CheckAllPcdsTokenValueConflict(self):\r
-        if len(self.BuildDatabase.WorkspaceDb.PackageList) >= 1:\r
-            for Package in self.BuildDatabase.WorkspaceDb.PackageList:\r
+        for Pa in self.AutoGenObjectList:\r
+            for Package in Pa.PackageList:\r
                 PcdList = Package.Pcds.values()\r
                 PcdList.sort(lambda x, y: cmp(x.TokenValue, y.TokenValue)) \r
                 Count = 0\r
@@ -356,6 +584,11 @@ class WorkspaceAutoGen(AutoGen):
         for Pa in self.AutoGenObjectList:\r
             Pa.CreateCodeFile(CreateDepsCodeFile)\r
 \r
+    ## Create AsBuilt INF file the platform\r
+    #\r
+    def CreateAsBuiltInf(self):\r
+        return\r
+\r
     Name                = property(_GetName)\r
     Guid                = property(_GetGuid)\r
     Version             = property(_GetVersion)\r
@@ -499,6 +732,7 @@ class PlatformAutoGen(AutoGen):
                 Ma = ModuleAutoGen(self.Workspace, ModuleFile, self.BuildTarget,\r
                                    self.ToolChain, self.Arch, self.MetaFile)\r
                 Ma.CreateMakeFile(True)\r
+                Ma.CreateAsBuiltInf()\r
 \r
         # no need to create makefile for the platform more than once\r
         if self.IsMakeFileCreated:\r
@@ -1036,16 +1270,21 @@ class PlatformAutoGen(AutoGen):
         PlatformModule = self.Platform.Modules[str(Module)]\r
 \r
         # add forced library instances (specified under LibraryClasses sections)\r
-        for LibraryClass in self.Platform.LibraryClasses.GetKeys():\r
-            if LibraryClass.startswith("NULL"):\r
-                Module.LibraryClasses[LibraryClass] = self.Platform.LibraryClasses[LibraryClass]\r
+        #\r
+        # If a module has a MODULE_TYPE of USER_DEFINED,\r
+        # do not link in NULL library class instances from the global [LibraryClasses.*] sections.\r
+        #\r
+        if Module.ModuleType != SUP_MODULE_USER_DEFINED:\r
+            for LibraryClass in self.Platform.LibraryClasses.GetKeys():\r
+                if LibraryClass.startswith("NULL") and self.Platform.LibraryClasses[LibraryClass, Module.ModuleType]:\r
+                    Module.LibraryClasses[LibraryClass] = self.Platform.LibraryClasses[LibraryClass, Module.ModuleType]\r
 \r
         # add forced library instances (specified in module overrides)\r
         for LibraryClass in PlatformModule.LibraryClasses:\r
             if LibraryClass.startswith("NULL"):\r
                 Module.LibraryClasses[LibraryClass] = PlatformModule.LibraryClasses[LibraryClass]\r
 \r
-        # R9 module\r
+        # EdkII module\r
         LibraryConsumerList = [Module]\r
         Constructor         = []\r
         ConsumedByList      = sdict()\r
@@ -1294,7 +1533,7 @@ class PlatformAutoGen(AutoGen):
 \r
     ## Resolve library names to library modules\r
     #\r
-    # (for R8.x modules)\r
+    # (for Edk.x modules)\r
     #\r
     #   @param  Module  The module from which the library names will be resolved\r
     #\r
@@ -1305,7 +1544,7 @@ class PlatformAutoGen(AutoGen):
         EdkLogger.verbose("Library instances of module [%s] [%s]:" % (str(Module), self.Arch))\r
         LibraryConsumerList = [Module]\r
 \r
-        # "CompilerStub" is a must for R8 modules\r
+        # "CompilerStub" is a must for Edk modules\r
         if Module.Libraries:\r
             Module.Libraries.append("CompilerStub")\r
         LibraryList = []\r
@@ -1596,6 +1835,8 @@ class ModuleAutoGen(AutoGen):
 \r
         self.IsMakeFileCreated = False\r
         self.IsCodeFileCreated = False\r
+        self.IsAsBuiltInfCreated = False\r
+        self.DepexGenerated = False\r
 \r
         self.BuildDatabase = self.Workspace.BuildDatabase\r
 \r
@@ -1635,6 +1876,7 @@ class ModuleAutoGen(AutoGen):
         self._DepexList               = None\r
         self._DepexExpressionList     = None\r
         self._BuildOption             = None\r
+        self._BuildOptionIncPathList  = None\r
         self._BuildTargets            = None\r
         self._IntroBuildTargetList    = None\r
         self._FinalBuildTargetList    = None\r
@@ -1685,6 +1927,10 @@ class ModuleAutoGen(AutoGen):
     def _GetBaseName(self):\r
         return self.Module.BaseName\r
 \r
+    ## Return the module DxsFile if exist\r
+    def _GetDxsFile(self):\r
+        return self.Module.DxsFile\r
+\r
     ## Return the module SourceOverridePath\r
     def _GetSourceOverridePath(self):\r
         return self.Module.SourceOverridePath\r
@@ -1701,7 +1947,7 @@ class ModuleAutoGen(AutoGen):
     def _GetModuleType(self):\r
         return self.Module.ModuleType\r
 \r
-    ## Return the component type (for R8.x style of module)\r
+    ## Return the component type (for Edk.x style of module)\r
     def _GetComponentType(self):\r
         return self.Module.ComponentType\r
 \r
@@ -1804,7 +2050,7 @@ class ModuleAutoGen(AutoGen):
     def _GetDepexTokenList(self):\r
         if self._DepexList == None:\r
             self._DepexList = {}\r
-            if self.IsLibrary or TAB_DEPENDENCY_EXPRESSION_FILE in self.FileTypes:\r
+            if self.DxsFile or self.IsLibrary or TAB_DEPENDENCY_EXPRESSION_FILE in self.FileTypes:\r
                 return self._DepexList\r
 \r
             self._DepexList[self.ModuleType] = []\r
@@ -1840,7 +2086,7 @@ class ModuleAutoGen(AutoGen):
     def _GetDepexExpressionTokenList(self):\r
         if self._DepexExpressionList == None:\r
             self._DepexExpressionList = {}\r
-            if self.IsLibrary or TAB_DEPENDENCY_EXPRESSION_FILE in self.FileTypes:\r
+            if self.DxsFile or self.IsLibrary or TAB_DEPENDENCY_EXPRESSION_FILE in self.FileTypes:\r
                 return self._DepexExpressionList\r
 \r
             self._DepexExpressionList[self.ModuleType] = ''\r
@@ -1886,6 +2132,50 @@ class ModuleAutoGen(AutoGen):
             self._BuildOption = self.PlatformInfo.ApplyBuildOption(self.Module)\r
         return self._BuildOption\r
 \r
+    ## Get include path list from tool option for the module build\r
+    #\r
+    #   @retval     list            The include path list\r
+    #\r
+    def _GetBuildOptionIncPathList(self):\r
+        if self._BuildOptionIncPathList == None:\r
+            #\r
+            # Regular expression for finding Include Directories, the difference between MSFT and INTEL/GCC\r
+            # is the former use /I , the Latter used -I to specify include directories\r
+            #\r
+            if self.PlatformInfo.ToolChainFamily in ('MSFT'):\r
+                gBuildOptIncludePattern = re.compile(r"(?:.*?)/I[ \t]*([^ ]*)", re.MULTILINE|re.DOTALL)\r
+            elif self.PlatformInfo.ToolChainFamily in ('INTEL', 'GCC'):\r
+                gBuildOptIncludePattern = re.compile(r"(?:.*?)-I[ \t]*([^ ]*)", re.MULTILINE|re.DOTALL)\r
+            \r
+            BuildOptionIncPathList = []\r
+            for Tool in ('CC', 'PP', 'VFRPP', 'ASLPP', 'ASLCC', 'APP', 'ASM'):\r
+                Attr = 'FLAGS'\r
+                try:\r
+                    FlagOption = self.BuildOption[Tool][Attr]\r
+                except KeyError:\r
+                    FlagOption = ''\r
+                \r
+                IncPathList = [NormPath(Path, self.Macros) for Path in gBuildOptIncludePattern.findall(FlagOption)]\r
+                #\r
+                # EDK II modules must not reference header files outside of the packages they depend on or \r
+                # within the module's directory tree. Report error if violation.\r
+                #\r
+                if self.AutoGenVersion >= 0x00010005 and len(IncPathList) > 0:\r
+                    for Path in IncPathList:\r
+                        if (Path not in self.IncludePathList) and (CommonPath([Path, self.MetaFile.Dir]) != self.MetaFile.Dir):\r
+                            ErrMsg = "The include directory for the EDK II module in this line is invalid %s specified in %s FLAGS '%s'" % (Path, Tool, FlagOption) \r
+                            EdkLogger.error("build", \r
+                                            PARAMETER_INVALID,\r
+                                            ExtraData = ErrMsg, \r
+                                            File = str(self.MetaFile))\r
+\r
+                \r
+                BuildOptionIncPathList += IncPathList\r
+            \r
+            self._BuildOptionIncPathList = BuildOptionIncPathList\r
+        \r
+        return self._BuildOptionIncPathList\r
+        \r
     ## Return a list of files which can be built from source\r
     #\r
     #  What kind of files can be built is determined by build rules in\r
@@ -1987,6 +2277,9 @@ class ModuleAutoGen(AutoGen):
                 CreateDirectory(Source.Dir)\r
 \r
             if File.IsBinary and File == Source and self._BinaryFileList != None and File in self._BinaryFileList:\r
+                # Skip all files that are not binary libraries\r
+                if not self.IsLibrary:\r
+                    continue\r
                 RuleObject = self.BuildRules[TAB_DEFAULT_BINARY_FILE]\r
             elif FileType in self.BuildRules:\r
                 RuleObject = self.BuildRules[FileType]\r
@@ -2041,7 +2334,7 @@ class ModuleAutoGen(AutoGen):
             self._BuildTargets = {}\r
             self._FileTypes = {}\r
 \r
-        #TRICK: call _GetSourceFileList to apply build rule for binary files\r
+        #TRICK: call _GetSourceFileList to apply build rule for source files\r
         if self.SourceFileList:\r
             pass\r
 \r
@@ -2076,9 +2369,8 @@ class ModuleAutoGen(AutoGen):
     #\r
     def _GetAutoGenFileList(self):\r
         UniStringAutoGenC = True\r
-        UniStringBinBuffer = None\r
+        UniStringBinBuffer = StringIO()\r
         if self.BuildType == 'UEFI_HII':\r
-            UniStringBinBuffer = StringIO()\r
             UniStringAutoGenC = False\r
         if self._AutoGenFileList == None:\r
             self._AutoGenFileList = {}\r
@@ -2136,7 +2428,7 @@ class ModuleAutoGen(AutoGen):
     #\r
     def _GetLibraryPcdList(self):\r
         if self._LibraryPcdList == None:\r
-            Pcds = {}\r
+            Pcds = sdict()\r
             if not self.IsLibrary:\r
                 # get PCDs from dependent libraries\r
                 for Library in self.DependentLibraryList:\r
@@ -2195,11 +2487,11 @@ class ModuleAutoGen(AutoGen):
                 for Inc in self.Module.Includes:\r
                     if Inc not in self._IncludePathList:\r
                         self._IncludePathList.append(Inc)\r
-                    # for r8 modules\r
+                    # for Edk modules\r
                     Inc = path.join(Inc, self.Arch.capitalize())\r
                     if os.path.exists(Inc) and Inc not in self._IncludePathList:\r
                         self._IncludePathList.append(Inc)\r
-                # r8 module needs to put DEBUG_DIR at the end of search path and not to use SOURCE_DIR all the time\r
+                # Edk module needs to put DEBUG_DIR at the end of search path and not to use SOURCE_DIR all the time\r
                 self._IncludePathList.append(self.DebugDir)\r
             else:\r
                 self._IncludePathList.append(self.MetaFile.Dir)\r
@@ -2214,6 +2506,107 @@ class ModuleAutoGen(AutoGen):
                         self._IncludePathList.append(str(Inc))\r
         return self._IncludePathList\r
 \r
+    ## Create AsBuilt INF file the module\r
+    #\r
+    def CreateAsBuiltInf(self):\r
+        if self.IsAsBuiltInfCreated:\r
+            return\r
+            \r
+        # Skip the following code for EDK I inf\r
+        if self.AutoGenVersion < 0x00010005:\r
+            return\r
+            \r
+        # Skip the following code for libraries\r
+        if self.IsLibrary:\r
+            return\r
+            \r
+        # Skip the following code for modules with no source files\r
+        if self.SourceFileList == None or self.SourceFileList == []:\r
+            return\r
+\r
+        # Skip the following code for modules without any binary files\r
+        if self.BinaryFileList <> None and self.BinaryFileList <> []:\r
+            return\r
+            \r
+        ### TODO: How to handles mixed source and binary modules\r
+\r
+        # Find all DynamicEx PCDs used by this module and dependent libraries\r
+        # Also find all packages that the DynamicEx PCDs depend on\r
+        Pcds = []\r
+        Packages = []        \r
+        for Pcd in self.ModulePcdList + self.LibraryPcdList:\r
+          if Pcd.Type in GenC.gDynamicExPcd:\r
+            if Pcd not in Pcds:\r
+              Pcds += [Pcd]\r
+            for Package in self.DerivedPackageList:\r
+              if Package not in Packages:\r
+                if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, 'DynamicEx') in Package.Pcds:\r
+                  Packages += [Package]\r
+                elif (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, 'Dynamic') in Package.Pcds:\r
+                  Packages += [Package]\r
+\r
+        ModuleType = self.ModuleType\r
+        if ModuleType == 'UEFI_DRIVER' and self.DepexGenerated:\r
+          ModuleType = 'DXE_DRIVER'\r
+\r
+        AsBuiltInfDict = {\r
+          'module_name'                       : self.Name,\r
+          'module_guid'                       : self.Guid,\r
+          'module_module_type'                : ModuleType,\r
+          'module_version_string'             : self.Version,\r
+          'module_uefi_specification_version' : [],\r
+          'module_pi_specification_version'   : [],\r
+          'module_arch'                       : self.Arch,\r
+          'package_item'                      : ['%s' % (Package.MetaFile.File.replace('\\','/')) for Package in Packages],\r
+          'binary_item'                       : [],\r
+          'pcd_item'                          : [],\r
+          'flags_item'                        : []\r
+        }\r
+\r
+        if 'UEFI_SPECIFICATION_VERSION' in self.Specification:\r
+          AsBuiltInfDict['module_uefi_specification_version'] += [self.Specification['UEFI_SPECIFICATION_VERSION']]\r
+        if 'PI_SPECIFICATION_VERSION' in self.Specification:\r
+          AsBuiltInfDict['module_pi_specification_version'] += [self.Specification['PI_SPECIFICATION_VERSION']]\r
+\r
+        OutputDir = self.OutputDir.replace('\\','/').strip('/')\r
+        if self.ModuleType in ['BASE', 'USER_DEFINED']:\r
+          for Item in self.CodaTargetList:\r
+            File = Item.Target.Path.replace('\\','/').strip('/').replace(OutputDir,'').strip('/')\r
+            if Item.Target.Ext.lower() == '.aml': \r
+              AsBuiltInfDict['binary_item'] += ['ASL|' + File]\r
+            elif Item.Target.Ext.lower() == '.acpi': \r
+              AsBuiltInfDict['binary_item'] += ['ACPI|' + File]\r
+            else:\r
+              AsBuiltInfDict['binary_item'] += ['BIN|' + File]\r
+        else:\r
+          for Item in self.CodaTargetList:\r
+            File = Item.Target.Path.replace('\\','/').strip('/').replace(OutputDir,'').strip('/')\r
+            if Item.Target.Ext.lower() == '.efi': \r
+              AsBuiltInfDict['binary_item'] += ['PE32|' + self.Name + '.efi']\r
+            else:\r
+              AsBuiltInfDict['binary_item'] += ['BIN|' + File]\r
+          if self.DepexGenerated:\r
+            if self.ModuleType in ['PEIM']:\r
+              AsBuiltInfDict['binary_item'] += ['PEI_DEPEX|' + self.Name + '.depex']\r
+            if self.ModuleType in ['DXE_DRIVER','DXE_RUNTIME_DRIVER','DXE_SAL_DRIVER','UEFI_DRIVER']:\r
+              AsBuiltInfDict['binary_item'] += ['DXE_DEPEX|' + self.Name + '.depex']\r
+            if self.ModuleType in ['DXE_SMM_DRIVER']:\r
+              AsBuiltInfDict['binary_item'] += ['SMM_DEPEX|' + self.Name + '.depex']\r
+\r
+        for Pcd in Pcds:\r
+          AsBuiltInfDict['pcd_item'] += [Pcd.TokenSpaceGuidCName + '.' + Pcd.TokenCName]\r
+         \r
+        for Item in self.BuildOption:\r
+          if 'FLAGS' in self.BuildOption[Item]:\r
+            AsBuiltInfDict['flags_item'] += ['%s:%s_%s_%s_%s_FLAGS = %s' % (self.ToolChainFamily, self.BuildTarget, self.ToolChain, self.Arch, Item, self.BuildOption[Item]['FLAGS'].strip())]\r
+        \r
+        AsBuiltInf = TemplateString()\r
+        AsBuiltInf.Append(gAsBuiltInfHeaderString.Replace(AsBuiltInfDict))\r
+        \r
+        SaveFileOnChange(os.path.join(self.OutputDir, self.Name + '.inf'), str(AsBuiltInf), False)\r
+        \r
+        self.IsAsBuiltInfCreated = True\r
+        \r
     ## Create makefile for the module and its dependent libraries\r
     #\r
     #   @param      CreateLibraryMakeFile   Flag indicating if or not the makefiles of\r
@@ -2258,7 +2651,7 @@ class ModuleAutoGen(AutoGen):
 \r
         for File in self.AutoGenFileList:\r
             if GenC.Generate(File.Path, self.AutoGenFileList[File], File.IsBinary):\r
-                #Ignore R8 AutoGen.c\r
+                #Ignore Edk AutoGen.c\r
                 if self.AutoGenVersion < 0x00010005 and File.Name == 'AutoGen.c':\r
                         continue\r
 \r
@@ -2278,6 +2671,9 @@ class ModuleAutoGen(AutoGen):
             Dpx = GenDepex.DependencyExpression(self.DepexList[ModuleType], ModuleType, True)\r
             DpxFile = gAutoGenDepexFileName % {"module_name" : self.Name}\r
 \r
+            if len(Dpx.PostfixNotation) <> 0:\r
+              self.DepexGenerated = True\r
+\r
             if Dpx.Generate(path.join(self.OutputDir, DpxFile)):\r
                 AutoGenList.append(str(DpxFile))\r
             else:\r
@@ -2357,8 +2753,10 @@ class ModuleAutoGen(AutoGen):
     ProtocolList            = property(_GetProtocolList)\r
     PpiList                 = property(_GetPpiList)\r
     DepexList               = property(_GetDepexTokenList)\r
+    DxsFile                 = property(_GetDxsFile)\r
     DepexExpressionList     = property(_GetDepexExpressionTokenList)\r
     BuildOption             = property(_GetModuleBuildOption)\r
+    BuildOptionIncPathList  = property(_GetBuildOptionIncPathList)\r
     BuildCommand            = property(_GetBuildCommand)\r
 \r
 # This acts like the main() function for the script, unless it is 'import'ed into another script.\r