]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/AutoGen/AutoGen.py
Sync BaseTools Branch (version r2149) to EDKII main trunk.
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / AutoGen.py
index 4ecf2eafe711f523020373a3436abbeeb9c0d5c3..8090a06bf8c6c6a32075ef9b6f81d89e6a30d0c5 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
@@ -499,6 +532,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,9 +1070,14 @@ 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
@@ -1596,6 +1635,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
@@ -1987,6 +2028,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
@@ -2214,6 +2258,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
@@ -2278,6 +2423,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