]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Workspace/WorkspaceCommon.py
BaseTools: Use absolute import in Workspace
[mirror_edk2.git] / BaseTools / Source / Python / Workspace / WorkspaceCommon.py
index 60acc914e9d262f6ab15c960ed854ed3a9272f6c..d987bbf441eab71c149a88b5d7f4658c7d8cc52a 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # Common routines used by workspace\r
 #\r
-# Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2012 - 2018, 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
 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 #\r
 \r
-from Common.Misc import sdict\r
+from __future__ import absolute_import\r
+from collections import OrderedDict, defaultdict\r
 from Common.DataType import SUP_MODULE_USER_DEFINED\r
-from BuildClassObject import LibraryClassObject\r
+from .BuildClassObject import LibraryClassObject\r
+import Common.GlobalData as GlobalData\r
+from Workspace.BuildClassObject import StructurePcd\r
+from Common.BuildToolError import RESOURCE_NOT_AVAILABLE\r
+from Common.BuildToolError import OPTION_MISSING\r
+from Common.BuildToolError import BUILD_ERROR\r
+\r
+class OrderedListDict(OrderedDict, defaultdict):\r
+    def __init__(self, *args, **kwargs):\r
+        super(OrderedListDict, self).__init__(*args, **kwargs)\r
+        self.default_factory = list\r
 \r
 ## Get all packages from platform for specified arch, target and toolchain\r
 #\r
@@ -41,14 +52,28 @@ def GetPackageList(Platform, BuildDatabase, Arch, Target, Toolchain):
 #  @param Target: Current target\r
 #  @param Toolchain: Current toolchain\r
 #  @retval: A dictionary contains instances of PcdClassObject with key (PcdCName, TokenSpaceGuid)\r
+#  @retval: A dictionary contains real GUIDs of TokenSpaceGuid\r
 #\r
-def GetDeclaredPcd(Platform, BuildDatabase, Arch, Target, Toolchain):\r
+def GetDeclaredPcd(Platform, BuildDatabase, Arch, Target, Toolchain, additionalPkgs):\r
     PkgList = GetPackageList(Platform, BuildDatabase, Arch, Target, Toolchain)\r
+    PkgList = set(PkgList)\r
+    PkgList |= additionalPkgs\r
     DecPcds = {}\r
+    GuidDict = {}\r
     for Pkg in PkgList:\r
+        Guids = Pkg.Guids\r
+        GuidDict.update(Guids)\r
         for Pcd in Pkg.Pcds:\r
-            DecPcds[Pcd[0], Pcd[1]] = Pkg.Pcds[Pcd]\r
-    return DecPcds\r
+            PcdCName = Pcd[0]\r
+            PcdTokenName = Pcd[1]\r
+            if GlobalData.MixedPcd:\r
+                for PcdItem in GlobalData.MixedPcd:\r
+                    if (PcdCName, PcdTokenName) in GlobalData.MixedPcd[PcdItem]:\r
+                        PcdCName = PcdItem[0]\r
+                        break\r
+            if (PcdCName, PcdTokenName) not in DecPcds:\r
+                DecPcds[PcdCName, PcdTokenName] = Pkg.Pcds[Pcd]\r
+    return DecPcds, GuidDict\r
 \r
 ## Get all dependent libraries for a module\r
 #\r
@@ -62,16 +87,13 @@ def GetDeclaredPcd(Platform, BuildDatabase, Arch, Target, Toolchain):
 #\r
 def GetLiabraryInstances(Module, Platform, BuildDatabase, Arch, Target, Toolchain):\r
     if Module.AutoGenVersion >= 0x00010005:\r
-        return _GetModuleLibraryInstances(Module, Platform, BuildDatabase, Arch, Target, Toolchain)\r
+        return GetModuleLibInstances(Module, Platform, BuildDatabase, Arch, Target, Toolchain)\r
     else:\r
         return _ResolveLibraryReference(Module, Platform)\r
 \r
-def _GetModuleLibraryInstances(Module, Platform, BuildDatabase, Arch, Target, Toolchain):\r
+def GetModuleLibInstances(Module, Platform, BuildDatabase, Arch, Target, Toolchain, FileName = '', EdkLogger = None):\r
     ModuleType = Module.ModuleType\r
 \r
-    # for overriding library instances with module specific setting\r
-    PlatformModule = 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
@@ -83,54 +105,70 @@ def _GetModuleLibraryInstances(Module, Platform, BuildDatabase, Arch, Target, To
                 Module.LibraryClasses[LibraryClass] = Platform.LibraryClasses[LibraryClass, Module.ModuleType]\r
 \r
     # add forced library instances (specified in module overrides)\r
-    for LibraryClass in PlatformModule.LibraryClasses:\r
+    for LibraryClass in Platform.Modules[str(Module)].LibraryClasses:\r
         if LibraryClass.startswith("NULL"):\r
-            Module.LibraryClasses[LibraryClass] = PlatformModule.LibraryClasses[LibraryClass]\r
+            Module.LibraryClasses[LibraryClass] = Platform.Modules[str(Module)].LibraryClasses[LibraryClass]\r
 \r
     # EdkII module\r
     LibraryConsumerList = [Module]\r
     Constructor = []\r
-    ConsumedByList = sdict()\r
-    LibraryInstance = sdict()\r
+    ConsumedByList = OrderedListDict()\r
+    LibraryInstance = OrderedDict()\r
+\r
+    if FileName:\r
+        EdkLogger.verbose("")\r
+        EdkLogger.verbose("Library instances of module [%s] [%s]:" % (str(Module), Arch))\r
 \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
+                if LibraryClassName in Platform.Modules[str(Module)].LibraryClasses:\r
+                    LibraryPath = Platform.Modules[str(Module)].LibraryClasses[LibraryClassName]\r
                 else:\r
                     LibraryPath = Platform.LibraryClasses[LibraryClassName, ModuleType]\r
-                if LibraryPath == None or LibraryPath == "":\r
+                if LibraryPath is None or LibraryPath == "":\r
                     LibraryPath = M.LibraryClasses[LibraryClassName]\r
-                    if LibraryPath == None or LibraryPath == "":\r
-                        return []\r
+                    if LibraryPath is None or LibraryPath == "":\r
+                        if FileName:\r
+                            EdkLogger.error("build", RESOURCE_NOT_AVAILABLE,\r
+                                            "Instance of library class [%s] is not found" % LibraryClassName,\r
+                                            File=FileName,\r
+                                            ExtraData="in [%s] [%s]\n\tconsumed by module [%s]" % (str(M), Arch, str(Module)))\r
+                        else:\r
+                            return []\r
 \r
                 LibraryModule = BuildDatabase[LibraryPath, Arch, Target, 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 == None \\r
+                elif LibraryModule.LibraryClass is None \\r
                      or len(LibraryModule.LibraryClass) == 0 \\r
-                     or (ModuleType != 'USER_DEFINED'\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
-                    return []\r
+                    if FileName:\r
+                        EdkLogger.error("build", OPTION_MISSING,\r
+                                        "Module type [%s] is not supported by library instance [%s]" \\r
+                                        % (ModuleType, LibraryPath), File=FileName,\r
+                                        ExtraData="consumed by [%s]" % str(Module))\r
+                    else:\r
+                        return []\r
 \r
                 LibraryInstance[LibraryClassName] = LibraryModule\r
                 LibraryConsumerList.append(LibraryModule)\r
+                if FileName:\r
+                    EdkLogger.verbose("\t" + str(LibraryClassName) + " : " + str(LibraryModule))\r
             else:\r
                 LibraryModule = LibraryInstance[LibraryClassName]\r
 \r
-            if LibraryModule == None:\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
@@ -148,7 +186,7 @@ def _GetModuleLibraryInstances(Module, Platform, BuildDatabase, Arch, Target, To
     for LibraryClassName in LibraryInstance:\r
         M = LibraryInstance[LibraryClassName]\r
         LibraryList.append(M)\r
-        if ConsumedByList[M] == []:\r
+        if not ConsumedByList[M]:\r
             Q.append(M)\r
 \r
     #\r
@@ -169,7 +207,7 @@ def _GetModuleLibraryInstances(Module, Platform, BuildDatabase, Arch, Target, To
                     # remove edge e from the graph if Node has no constructor\r
                     ConsumedByList[Item].remove(Node)\r
                     EdgeRemoved = True\r
-                    if ConsumedByList[Item] == []:\r
+                    if not ConsumedByList[Item]:\r
                         # insert Item into Q\r
                         Q.insert(0, Item)\r
                         break\r
@@ -191,7 +229,7 @@ def _GetModuleLibraryInstances(Module, Platform, BuildDatabase, Arch, Target, To
             # remove edge e from the graph\r
             ConsumedByList[Item].remove(Node)\r
 \r
-            if ConsumedByList[Item] != []:\r
+            if ConsumedByList[Item]:\r
                 continue\r
             # insert Item into Q, if Item has no other incoming edges\r
             Q.insert(0, Item)\r
@@ -200,8 +238,13 @@ def _GetModuleLibraryInstances(Module, Platform, BuildDatabase, Arch, Target, To
     # 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
-            return []\r
+        if ConsumedByList[Item] and Item in Constructor and len(Constructor) > 1:\r
+            if FileName:\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=FileName)\r
+            else:\r
+                return []\r
         if Item not in SortedLibraryList:\r
             SortedLibraryList.append(Item)\r
 \r
@@ -223,12 +266,12 @@ def _ResolveLibraryReference(Module, Platform):
         M = LibraryConsumerList.pop()\r
         for LibraryName in M.Libraries:\r
             Library = Platform.LibraryClasses[LibraryName, ':dummy:']\r
-            if Library == None:\r
-                for Key in Platform.LibraryClasses.data.keys():\r
+            if Library is None:\r
+                for Key in Platform.LibraryClasses.data:\r
                     if LibraryName.upper() == Key.upper():\r
                         Library = Platform.LibraryClasses[Key, ':dummy:']\r
                         break\r
-                if Library == None:\r
+                if Library is None:\r
                     continue\r
 \r
             if Library not in LibraryList:\r