]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/AutoGen/AutoGen.py
BaseTools: refactor to remove functions
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / AutoGen.py
index 14d5a94afae2f4166e3adcba01d074f49ce4ece1..0b5b3dcf465725c26398485dd8ca26ff0fbc091c 100644 (file)
@@ -33,7 +33,7 @@ from Common.LongFilePathSupport import CopyLongFilePath
 from Common.BuildToolError import *\r
 from Common.DataType import *\r
 from Common.Misc import *\r
-from Common.String import *\r
+from Common.StringUtils import *\r
 import Common.GlobalData as GlobalData\r
 from GenFds.FdfParser import *\r
 from CommonDataClass.CommonClass import SkuInfoClass\r
@@ -42,6 +42,7 @@ from GenPatchPcdTable.GenPatchPcdTable import parsePcdInfoFromMapFile
 import Common.VpdInfoFile as VpdInfoFile\r
 from GenPcdDb import CreatePcdDatabaseCode\r
 from Workspace.MetaFileCommentParser import UsageList\r
+from Workspace.WorkspaceCommon import GetModuleLibInstances\r
 from Common.MultipleWorkspace import MultipleWorkspace as mws\r
 import InfSectionParser\r
 import datetime\r
@@ -2174,169 +2175,21 @@ class PlatformAutoGen(AutoGen):
         if str(Module) not in self.Platform.Modules:\r
             return []\r
 \r
-        ModuleType = Module.ModuleType\r
-\r
-        # for overridding library instances with module specific setting\r
-        PlatformModule = self.Platform.Modules[str(Module)]\r
-\r
-        # add forced library instances (specified under LibraryClasses sections)\r
-        #\r
-        # If a module has a MODULE_TYPE of USER_DEFINED,\r
-        # do not link in NULL library class instances from the global [LibraryClasses.*] sections.\r
-        #\r
-        if Module.ModuleType != SUP_MODULE_USER_DEFINED:\r
-            for LibraryClass in self.Platform.LibraryClasses.GetKeys():\r
-                if LibraryClass.startswith("NULL") and self.Platform.LibraryClasses[LibraryClass, Module.ModuleType]:\r
-                    Module.LibraryClasses[LibraryClass] = self.Platform.LibraryClasses[LibraryClass, Module.ModuleType]\r
-\r
-        # add forced library instances (specified in module overrides)\r
-        for LibraryClass in PlatformModule.LibraryClasses:\r
-            if LibraryClass.startswith("NULL"):\r
-                Module.LibraryClasses[LibraryClass] = PlatformModule.LibraryClasses[LibraryClass]\r
-\r
-        # EdkII module\r
-        LibraryConsumerList = [Module]\r
-        Constructor         = []\r
-        ConsumedByList      = OrderedDict()\r
-        LibraryInstance     = OrderedDict()\r
-\r
-        EdkLogger.verbose("")\r
-        EdkLogger.verbose("Library instances of module [%s] [%s]:" % (str(Module), self.Arch))\r
-        while len(LibraryConsumerList) > 0:\r
-            M = LibraryConsumerList.pop()\r
-            for LibraryClassName in M.LibraryClasses:\r
-                if LibraryClassName not in LibraryInstance:\r
-                    # override library instance for this module\r
-                    if LibraryClassName in PlatformModule.LibraryClasses:\r
-                        LibraryPath = PlatformModule.LibraryClasses[LibraryClassName]\r
-                    else:\r
-                        LibraryPath = self.Platform.LibraryClasses[LibraryClassName, ModuleType]\r
-                    if LibraryPath is None or LibraryPath == "":\r
-                        LibraryPath = M.LibraryClasses[LibraryClassName]\r
-                        if LibraryPath is None or LibraryPath == "":\r
-                            EdkLogger.error("build", RESOURCE_NOT_AVAILABLE,\r
-                                            "Instance of library class [%s] is not found" % LibraryClassName,\r
-                                            File=self.MetaFile,\r
-                                            ExtraData="in [%s] [%s]\n\tconsumed by module [%s]" % (str(M), self.Arch, str(Module)))\r
-\r
-                    LibraryModule = self.BuildDatabase[LibraryPath, self.Arch, self.BuildTarget, self.ToolChain]\r
-                    # for those forced library instance (NULL library), add a fake library class\r
-                    if LibraryClassName.startswith("NULL"):\r
-                        LibraryModule.LibraryClass.append(LibraryClassObject(LibraryClassName, [ModuleType]))\r
-                    elif LibraryModule.LibraryClass is None \\r
-                         or len(LibraryModule.LibraryClass) == 0 \\r
-                         or (ModuleType != SUP_MODULE_USER_DEFINED\r
-                             and ModuleType not in LibraryModule.LibraryClass[0].SupModList):\r
-                        # only USER_DEFINED can link against any library instance despite of its SupModList\r
-                        EdkLogger.error("build", OPTION_MISSING,\r
-                                        "Module type [%s] is not supported by library instance [%s]" \\r
-                                        % (ModuleType, LibraryPath), File=self.MetaFile,\r
-                                        ExtraData="consumed by [%s]" % str(Module))\r
-\r
-                    LibraryInstance[LibraryClassName] = LibraryModule\r
-                    LibraryConsumerList.append(LibraryModule)\r
-                    EdkLogger.verbose("\t" + str(LibraryClassName) + " : " + str(LibraryModule))\r
-                else:\r
-                    LibraryModule = LibraryInstance[LibraryClassName]\r
-\r
-                if LibraryModule is None:\r
-                    continue\r
-\r
-                if LibraryModule.ConstructorList != [] and LibraryModule not in Constructor:\r
-                    Constructor.append(LibraryModule)\r
-\r
-                if LibraryModule not in ConsumedByList:\r
-                    ConsumedByList[LibraryModule] = []\r
-                # don't add current module itself to consumer list\r
-                if M != Module:\r
-                    if M in ConsumedByList[LibraryModule]:\r
-                        continue\r
-                    ConsumedByList[LibraryModule].append(M)\r
-        #\r
-        # Initialize the sorted output list to the empty set\r
-        #\r
-        SortedLibraryList = []\r
-        #\r
-        # Q <- Set of all nodes with no incoming edges\r
-        #\r
-        LibraryList = [] #LibraryInstance.values()\r
-        Q = []\r
-        for LibraryClassName in LibraryInstance:\r
-            M = LibraryInstance[LibraryClassName]\r
-            LibraryList.append(M)\r
-            if ConsumedByList[M] == []:\r
-                Q.append(M)\r
-\r
-        #\r
-        # start the  DAG algorithm\r
-        #\r
-        while True:\r
-            EdgeRemoved = True\r
-            while Q == [] and EdgeRemoved:\r
-                EdgeRemoved = False\r
-                # for each node Item with a Constructor\r
-                for Item in LibraryList:\r
-                    if Item not in Constructor:\r
-                        continue\r
-                    # for each Node without a constructor with an edge e from Item to Node\r
-                    for Node in ConsumedByList[Item]:\r
-                        if Node in Constructor:\r
-                            continue\r
-                        # remove edge e from the graph if Node has no constructor\r
-                        ConsumedByList[Item].remove(Node)\r
-                        EdgeRemoved = True\r
-                        if ConsumedByList[Item] == []:\r
-                            # insert Item into Q\r
-                            Q.insert(0, Item)\r
-                            break\r
-                    if Q != []:\r
-                        break\r
-            # DAG is done if there's no more incoming edge for all nodes\r
-            if Q == []:\r
-                break\r
-\r
-            # remove node from Q\r
-            Node = Q.pop()\r
-            # output Node\r
-            SortedLibraryList.append(Node)\r
-\r
-            # for each node Item with an edge e from Node to Item do\r
-            for Item in LibraryList:\r
-                if Node not in ConsumedByList[Item]:\r
-                    continue\r
-                # remove edge e from the graph\r
-                ConsumedByList[Item].remove(Node)\r
-\r
-                if ConsumedByList[Item] != []:\r
-                    continue\r
-                # insert Item into Q, if Item has no other incoming edges\r
-                Q.insert(0, Item)\r
-\r
-        #\r
-        # if any remaining node Item in the graph has a constructor and an incoming edge, then the graph has a cycle\r
-        #\r
-        for Item in LibraryList:\r
-            if ConsumedByList[Item] != [] and Item in Constructor and len(Constructor) > 1:\r
-                ErrorMessage = "\tconsumed by " + "\n\tconsumed by ".join(str(L) for L in ConsumedByList[Item])\r
-                EdkLogger.error("build", BUILD_ERROR, 'Library [%s] with constructors has a cycle' % str(Item),\r
-                                ExtraData=ErrorMessage, File=self.MetaFile)\r
-            if Item not in SortedLibraryList:\r
-                SortedLibraryList.append(Item)\r
-\r
-        #\r
-        # Build the list of constructor and destructir names\r
-        # The DAG Topo sort produces the destructor order, so the list of constructors must generated in the reverse order\r
-        #\r
-        SortedLibraryList.reverse()\r
-        return SortedLibraryList\r
-\r
+        return GetModuleLibInstances(Module,\r
+                                     self.Platform,\r
+                                     self.BuildDatabase,\r
+                                     self.Arch,\r
+                                     self.BuildTarget,\r
+                                     self.ToolChain,\r
+                                     self.MetaFile,\r
+                                     EdkLogger)\r
 \r
     ## Override PCD setting (type, value, ...)\r
     #\r
     #   @param  ToPcd       The PCD to be overrided\r
     #   @param  FromPcd     The PCD overrideing from\r
     #\r
-    def _OverridePcd(self, ToPcd, FromPcd, Module=""):\r
+    def _OverridePcd(self, ToPcd, FromPcd, Module="", Msg="", Library=""):\r
         #\r
         # in case there's PCDs coming from FDF file, which have no type given.\r
         # at this point, ToPcd.Type has the type found from dependent\r
@@ -2356,10 +2209,12 @@ class PlatformAutoGen(AutoGen):
                     ToPcd.Type = FromPcd.Type\r
             elif ToPcd.Type and FromPcd.Type \\r
                 and ToPcd.Type != FromPcd.Type:\r
+                if Library:\r
+                    Module = str(Module) + " 's library file (" + str(Library) + ")"\r
                 EdkLogger.error("build", OPTION_CONFLICT, "Mismatched PCD type",\r
-                                ExtraData="%s.%s is defined as [%s] in module %s, but as [%s] in platform."\\r
+                                ExtraData="%s.%s is used as [%s] in module %s, but as [%s] in %s."\\r
                                           % (ToPcd.TokenSpaceGuidCName, TokenCName,\r
-                                             ToPcd.Type, Module, FromPcd.Type),\r
+                                             ToPcd.Type, Module, FromPcd.Type, Msg),\r
                                           File=self.MetaFile)\r
 \r
             if FromPcd.MaxDatumSize:\r
@@ -2420,7 +2275,7 @@ class PlatformAutoGen(AutoGen):
     #\r
     #   @retval PCD_list    The list PCDs with settings from platform\r
     #\r
-    def ApplyPcdSetting(self, Module, Pcds):\r
+    def ApplyPcdSetting(self, Module, Pcds, Library=""):\r
         # for each PCD in module\r
         for Name, Guid in Pcds:\r
             PcdInModule = Pcds[Name, Guid]\r
@@ -2430,7 +2285,7 @@ class PlatformAutoGen(AutoGen):
             else:\r
                 PcdInPlatform = None\r
             # then override the settings if any\r
-            self._OverridePcd(PcdInModule, PcdInPlatform, Module)\r
+            self._OverridePcd(PcdInModule, PcdInPlatform, Module, Msg="DSC PCD sections", Library=Library)\r
             # resolve the VariableGuid value\r
             for SkuId in PcdInModule.SkuInfoList:\r
                 Sku = PcdInModule.SkuInfoList[SkuId]\r
@@ -2462,7 +2317,7 @@ class PlatformAutoGen(AutoGen):
                             Flag = True\r
                             break\r
                 if Flag:\r
-                    self._OverridePcd(ToPcd, PlatformModule.Pcds[Key], Module)\r
+                    self._OverridePcd(ToPcd, PlatformModule.Pcds[Key], Module, Msg="DSC Components Module scoped PCD section", Library=Library)\r
         # use PCD value to calculate the MaxDatumSize when it is not specified\r
         for Name, Guid in Pcds:\r
             Pcd = Pcds[Name, Guid]\r
@@ -3675,15 +3530,17 @@ class ModuleAutoGen(AutoGen):
             Pcds = OrderedDict()\r
             if not self.IsLibrary:\r
                 # get PCDs from dependent libraries\r
+                self._LibraryPcdList = []\r
                 for Library in self.DependentLibraryList:\r
+                    PcdsInLibrary = OrderedDict()\r
                     self.UpdateComments(self._PcdComments, Library.PcdComments)\r
                     for Key in Library.Pcds:\r
                         # skip duplicated PCDs\r
                         if Key in self.Module.Pcds or Key in Pcds:\r
                             continue\r
                         Pcds[Key] = copy.copy(Library.Pcds[Key])\r
-                # apply PCD settings from platform\r
-                self._LibraryPcdList = self.PlatformInfo.ApplyPcdSetting(self.Module, Pcds)\r
+                        PcdsInLibrary[Key] = Pcds[Key]\r
+                    self._LibraryPcdList.extend(self.PlatformInfo.ApplyPcdSetting(self.Module, PcdsInLibrary, Library=Library))\r
             else:\r
                 self._LibraryPcdList = []\r
         return self._LibraryPcdList\r