]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/AutoGen/AutoGen.py
MdePkg/DevicePathLib: Fix FromText bug for multi-instance devicepath
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / AutoGen.py
index 8da441f6b9cb4f3d67bcd236a98d493b37c26501..06e674a5067b3c06566c921805b2272cc819c9fa 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # Generate AutoGen.h, AutoGen.c and *.depex files\r
 #\r
-# Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>\r
 # This program and the accompanying materials\r
 # are licensed and made available under the terms and conditions of the BSD License\r
 # which accompanies this distribution.  The full text of the license may be found at\r
@@ -72,7 +72,8 @@ gAutoGenHeaderFileName = "AutoGen.h"
 gAutoGenStringFileName = "%(module_name)sStrDefs.h"\r
 gAutoGenStringFormFileName = "%(module_name)sStrDefs.hpk"\r
 gAutoGenDepexFileName = "%(module_name)s.depex"\r
-\r
+gAutoGenImageDefFileName = "%(module_name)sImgDefs.h"\r
+gAutoGenIdfFileName = "%(module_name)sIdf.hpk"\r
 gInfSpecVersion = "0x00010017"\r
 \r
 #\r
@@ -329,6 +330,43 @@ class WorkspaceAutoGen(AutoGen):
                 if fvname.upper() not in self.FdfProfile.FvDict:\r
                     EdkLogger.error("build", OPTION_VALUE_INVALID,\r
                                     "No such an FV in FDF file: %s" % fvname)\r
+\r
+            # In DSC file may use FILE_GUID to override the module, then in the Platform.Modules use FILE_GUIDmodule.inf as key,\r
+            # but the path (self.MetaFile.Path) is the real path\r
+            for key in self.FdfProfile.InfDict:\r
+                if key == 'ArchTBD':\r
+                    Platform_cache = {}\r
+                    MetaFile_cache = {}\r
+                    for Arch in self.ArchList:\r
+                        Platform_cache[Arch] = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain]\r
+                        MetaFile_cache[Arch] = []\r
+                        for Pkey in Platform_cache[Arch].Modules.keys():\r
+                            MetaFile_cache[Arch].append(Platform_cache[Arch].Modules[Pkey].MetaFile)\r
+                    for Inf in self.FdfProfile.InfDict[key]:\r
+                        ModuleFile = PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch)\r
+                        for Arch in self.ArchList:\r
+                            if ModuleFile in MetaFile_cache[Arch]:\r
+                                break\r
+                        else:\r
+                            ModuleData = self.BuildDatabase[ModuleFile, Arch, Target, Toolchain]\r
+                            if not ModuleData.IsBinaryModule:\r
+                                EdkLogger.error('build', PARSER_ERROR, "Module %s NOT found in DSC file; Is it really a binary module?" % ModuleFile)\r
+\r
+                else:\r
+                    for Arch in self.ArchList:\r
+                        if Arch == key:\r
+                            Platform = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain]\r
+                            MetaFileList = []\r
+                            for Pkey in Platform.Modules.keys():\r
+                                MetaFileList.append(Platform.Modules[Pkey].MetaFile)\r
+                            for Inf in self.FdfProfile.InfDict[key]:\r
+                                ModuleFile = PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch)\r
+                                if ModuleFile in MetaFileList:\r
+                                    continue\r
+                                ModuleData = self.BuildDatabase[ModuleFile, Arch, Target, Toolchain]\r
+                                if not ModuleData.IsBinaryModule:\r
+                                    EdkLogger.error('build', PARSER_ERROR, "Module %s NOT found in DSC file; Is it really a binary module?" % ModuleFile)\r
+\r
         else:\r
             PcdSet = {}\r
             ModuleList = []\r
@@ -1680,7 +1718,10 @@ class PlatformAutoGen(AutoGen):
                         if self.BuildOption[Tool][Attr].startswith('='):\r
                             Value = self.BuildOption[Tool][Attr][1:]\r
                         else:\r
-                            Value += " " + self.BuildOption[Tool][Attr]\r
+                            if Attr != 'PATH':\r
+                                Value += " " + self.BuildOption[Tool][Attr]\r
+                            else:\r
+                                Value = self.BuildOption[Tool][Attr]\r
 \r
                     if Attr == "PATH":\r
                         # Don't put MAKE definition in the file\r
@@ -1914,6 +1955,10 @@ class PlatformAutoGen(AutoGen):
     #   @retval library_list    List of library instances sorted\r
     #\r
     def ApplyLibraryInstance(self, Module):\r
+        # Cover the case that the binary INF file is list in the FDF file but not DSC file, return empty list directly\r
+        if str(Module) not in self.Platform.Modules:\r
+            return []\r
+\r
         ModuleType = Module.ModuleType\r
 \r
         # for overridding library instances with module specific setting\r
@@ -2339,8 +2384,11 @@ class PlatformAutoGen(AutoGen):
                         if Attr != "FLAGS" or Attr not in BuildOptions[Tool] or Options[Key].startswith('='):\r
                             BuildOptions[Tool][Attr] = Options[Key]\r
                         else:\r
-                            # append options for the same tool\r
-                            BuildOptions[Tool][Attr] += " " + Options[Key]\r
+                            # append options for the same tool except PATH\r
+                            if Attr != 'PATH':\r
+                                BuildOptions[Tool][Attr] += " " + Options[Key]\r
+                            else:\r
+                                BuildOptions[Tool][Attr] = Options[Key]\r
         # Build Option Family has been checked, which need't to be checked again for family.\r
         if FamilyMatch or FamilyIsNull:\r
             return BuildOptions\r
@@ -2371,8 +2419,11 @@ class PlatformAutoGen(AutoGen):
                         if Attr != "FLAGS" or Attr not in BuildOptions[Tool] or Options[Key].startswith('='):\r
                             BuildOptions[Tool][Attr] = Options[Key]\r
                         else:\r
-                            # append options for the same tool\r
-                            BuildOptions[Tool][Attr] += " " + Options[Key]\r
+                            # append options for the same tool except PATH\r
+                            if Attr != 'PATH':\r
+                                BuildOptions[Tool][Attr] += " " + Options[Key]\r
+                            else:\r
+                                BuildOptions[Tool][Attr] = Options[Key]\r
         return BuildOptions\r
 \r
     ## Append build options in platform to a module\r
@@ -2431,7 +2482,10 @@ class PlatformAutoGen(AutoGen):
                         BuildOptions[Tool][Attr] = ToolPath\r
                     else:\r
                         Value = mws.handleWsMacro(Value)\r
-                        BuildOptions[Tool][Attr] += " " + Value\r
+                        if Attr != 'PATH':\r
+                            BuildOptions[Tool][Attr] += " " + Value\r
+                        else:\r
+                            BuildOptions[Tool][Attr] = Value\r
         if Module.AutoGenVersion < 0x00010005 and self.Workspace.UniFlag != None:\r
             #\r
             # Override UNI flag only for EDK module.\r
@@ -2549,6 +2603,8 @@ class ModuleAutoGen(AutoGen):
         self._IncludePathLength = 0\r
         self._AutoGenFileList = None\r
         self._UnicodeFileList = None\r
+        self._VfrFileList = None\r
+        self._IdfFileList = None\r
         self._SourceFileList  = None\r
         self._ObjectFileList  = None\r
         self._BinaryFileList  = None\r
@@ -3073,6 +3129,24 @@ class ModuleAutoGen(AutoGen):
                 self._UnicodeFileList = []\r
         return self._UnicodeFileList\r
 \r
+    ## Return the list of vfr files\r
+    def _GetVfrFileList(self):\r
+        if self._VfrFileList == None:\r
+            if TAB_VFR_FILE in self.FileTypes:\r
+                self._VfrFileList = self.FileTypes[TAB_VFR_FILE]\r
+            else:\r
+                self._VfrFileList = []\r
+        return self._VfrFileList\r
+\r
+    ## Return the list of Image Definition files\r
+    def _GetIdfFileList(self):\r
+        if self._IdfFileList == None:\r
+            if TAB_IMAGE_FILE in self.FileTypes:\r
+                self._IdfFileList = self.FileTypes[TAB_IMAGE_FILE]\r
+            else:\r
+                self._IdfFileList = []\r
+        return self._IdfFileList\r
+\r
     ## Return a list of files which can be built from binary\r
     #\r
     #  "Build" binary files are just to copy them to build directory.\r
@@ -3235,15 +3309,19 @@ class ModuleAutoGen(AutoGen):
     #\r
     def _GetAutoGenFileList(self):\r
         UniStringAutoGenC = True\r
+        IdfStringAutoGenC = True\r
         UniStringBinBuffer = StringIO()\r
+        IdfGenBinBuffer = StringIO()\r
         if self.BuildType == 'UEFI_HII':\r
             UniStringAutoGenC = False\r
+            IdfStringAutoGenC = False\r
         if self._AutoGenFileList == None:\r
             self._AutoGenFileList = {}\r
             AutoGenC = TemplateString()\r
             AutoGenH = TemplateString()\r
             StringH = TemplateString()\r
-            GenC.CreateCode(self, AutoGenC, AutoGenH, StringH, UniStringAutoGenC, UniStringBinBuffer)\r
+            StringIdf = TemplateString()\r
+            GenC.CreateCode(self, AutoGenC, AutoGenH, StringH, UniStringAutoGenC, UniStringBinBuffer, StringIdf, IdfStringAutoGenC, IdfGenBinBuffer)\r
             #\r
             # AutoGen.c is generated if there are library classes in inf, or there are object files\r
             #\r
@@ -3267,6 +3345,17 @@ class ModuleAutoGen(AutoGen):
                 self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)\r
             if UniStringBinBuffer != None:\r
                 UniStringBinBuffer.close()\r
+            if str(StringIdf) != "":\r
+                AutoFile = PathClass(gAutoGenImageDefFileName % {"module_name":self.Name}, self.DebugDir)\r
+                self._AutoGenFileList[AutoFile] = str(StringIdf)\r
+                self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)\r
+            if IdfGenBinBuffer != None and IdfGenBinBuffer.getvalue() != "":\r
+                AutoFile = PathClass(gAutoGenIdfFileName % {"module_name":self.Name}, self.OutputDir)\r
+                self._AutoGenFileList[AutoFile] = IdfGenBinBuffer.getvalue()\r
+                AutoFile.IsBinary = True\r
+                self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)\r
+            if IdfGenBinBuffer != None:\r
+                IdfGenBinBuffer.close()\r
         return self._AutoGenFileList\r
 \r
     ## Return the list of library modules explicitly or implicityly used by this module\r
@@ -3573,13 +3662,13 @@ class ModuleAutoGen(AutoGen):
         # Find all DynamicEx and PatchableInModule PCDs used by this module and dependent libraries\r
         # Also find all packages that the DynamicEx PCDs depend on\r
         Pcds = []\r
-        PatchablePcds = {}\r
+        PatchablePcds = []\r
         Packages = []\r
         PcdCheckList = []\r
         PcdTokenSpaceList = []\r
         for Pcd in self.ModulePcdList + self.LibraryPcdList:\r
             if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r
-                PatchablePcds[Pcd.TokenCName] = Pcd\r
+                PatchablePcds += [Pcd]\r
                 PcdCheckList.append((Pcd.TokenCName, Pcd.TokenSpaceGuidCName, 'PatchableInModule'))\r
             elif Pcd.Type in GenC.gDynamicExPcd:\r
                 if Pcd not in Pcds:\r
@@ -3732,15 +3821,17 @@ class ModuleAutoGen(AutoGen):
                             os.path.join(self.OutputDir, self.Name + '.efi')\r
                         )\r
         if PatchList:\r
-            for PatchPcd in PatchList:\r
-                if PatchPcd[0] in PatchablePcds:\r
-                    key = PatchPcd[0]\r
-                elif PatchPcd[0] + '_PatchableInModule' in PatchablePcds:\r
-                    key = PatchPcd[0] + '_PatchableInModule'\r
+            for Pcd in PatchablePcds:\r
+                TokenCName = Pcd.TokenCName\r
+                for PcdItem in GlobalData.MixedPcd:\r
+                    if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
+                        TokenCName = PcdItem[0]\r
+                        break\r
+                for PatchPcd in PatchList:\r
+                    if TokenCName == PatchPcd[0]:\r
+                        break\r
                 else:\r
                     continue\r
-                Pcd = PatchablePcds[key]\r
-                TokenCName = PatchPcd[0]\r
                 PcdValue = ''\r
                 if Pcd.DatumType != 'VOID*':\r
                     HexFormat = '0x%02x'\r
@@ -4011,6 +4102,7 @@ class ModuleAutoGen(AutoGen):
     IncludePathLength = property(_GetIncludePathLength)\r
     AutoGenFileList = property(_GetAutoGenFileList)\r
     UnicodeFileList = property(_GetUnicodeFileList)\r
+    VfrFileList     = property(_GetVfrFileList)\r
     SourceFileList  = property(_GetSourceFileList)\r
     BinaryFileList  = property(_GetBinaryFiles) # FileType : [File List]\r
     Targets         = property(_GetTargets)\r
@@ -4018,6 +4110,7 @@ class ModuleAutoGen(AutoGen):
     CodaTargetList  = property(_GetFinalTargetList)\r
     FileTypes       = property(_GetFileTypes)\r
     BuildRules      = property(_GetBuildRules)\r
+    IdfFileList     = property(_GetIdfFileList)\r
 \r
     DependentPackageList    = property(_GetDependentPackageList)\r
     DependentLibraryList    = property(_GetLibraryList)\r