]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Workspace/WorkspaceCommon.py
BaseTools: Add the FeatureFlagExpression usage to the Source Section
[mirror_edk2.git] / BaseTools / Source / Python / Workspace / WorkspaceCommon.py
index d987bbf441eab71c149a88b5d7f4658c7d8cc52a..6564a34ba7241316f893bdb85cb9bada77a06948 100644 (file)
@@ -1,31 +1,31 @@
 ## @file\r
 # Common routines used by workspace\r
 #\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
-# http://opensource.org/licenses/bsd-license.php\r
-#\r
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+# Copyright (c) 2012 - 2020, Intel Corporation. All rights reserved.<BR>\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
 #\r
 \r
 from __future__ import absolute_import\r
 from collections import OrderedDict, defaultdict\r
 from Common.DataType import SUP_MODULE_USER_DEFINED\r
+from Common.DataType import SUP_MODULE_HOST_APPLICATION\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
+import Common.EdkLogger as EdkLogger\r
 \r
-class OrderedListDict(OrderedDict, defaultdict):\r
+class OrderedListDict(OrderedDict):\r
     def __init__(self, *args, **kwargs):\r
         super(OrderedListDict, self).__init__(*args, **kwargs)\r
         self.default_factory = list\r
 \r
+    def __missing__(self, key):\r
+        self[key] = Value = self.default_factory()\r
+        return Value\r
+\r
 ## Get all packages from platform for specified arch, target and toolchain\r
 #\r
 #  @param Platform: DscBuildData instance\r
@@ -37,6 +37,8 @@ class OrderedListDict(OrderedDict, defaultdict):
 #\r
 def GetPackageList(Platform, BuildDatabase, Arch, Target, Toolchain):\r
     PkgSet = set()\r
+    if Platform.Packages:\r
+        PkgSet.update(Platform.Packages)\r
     for ModuleFile in Platform.Modules:\r
         Data = BuildDatabase[ModuleFile, Arch, Target, Toolchain]\r
         PkgSet.update(Data.Packages)\r
@@ -73,6 +75,11 @@ def GetDeclaredPcd(Platform, BuildDatabase, Arch, Target, Toolchain, additionalP
                         break\r
             if (PcdCName, PcdTokenName) not in DecPcds:\r
                 DecPcds[PcdCName, PcdTokenName] = Pkg.Pcds[Pcd]\r
+    if not GlobalData.gPlatformFinalPcds.get(Arch):\r
+        GlobalData.gPlatformFinalPcds[Arch] = OrderedDict()\r
+    for Name,Guid in DecPcds:\r
+        if DecPcds[Name,Guid].Type == 'FeatureFlag' or DecPcds[Name, Guid].Type == 'FixedAtBuild':\r
+            GlobalData.gPlatformFinalPcds[Arch]['%s.%s'%(Guid, Name)]=DecPcds[Name, Guid].DefaultValue\r
     return DecPcds, GuidDict\r
 \r
 ## Get all dependent libraries for a module\r
@@ -86,12 +93,11 @@ def GetDeclaredPcd(Platform, BuildDatabase, Arch, Target, Toolchain, additionalP
 #  @retval: List of dependent libraries which are InfBuildData instances\r
 #\r
 def GetLiabraryInstances(Module, Platform, BuildDatabase, Arch, Target, Toolchain):\r
-    if Module.AutoGenVersion >= 0x00010005:\r
-        return GetModuleLibInstances(Module, Platform, BuildDatabase, Arch, Target, Toolchain)\r
-    else:\r
-        return _ResolveLibraryReference(Module, Platform)\r
+    return GetModuleLibInstances(Module, Platform, BuildDatabase, Arch, Target, Toolchain,Platform.MetaFile,EdkLogger)\r
 \r
 def GetModuleLibInstances(Module, Platform, BuildDatabase, Arch, Target, Toolchain, FileName = '', EdkLogger = None):\r
+    if Module.LibInstances:\r
+        return Module.LibInstances\r
     ModuleType = Module.ModuleType\r
 \r
     # add forced library instances (specified under LibraryClasses sections)\r
@@ -115,7 +121,7 @@ def GetModuleLibInstances(Module, Platform, BuildDatabase, Arch, Target, Toolcha
     ConsumedByList = OrderedListDict()\r
     LibraryInstance = OrderedDict()\r
 \r
-    if FileName:\r
+    if not Module.LibraryClass:\r
         EdkLogger.verbose("")\r
         EdkLogger.verbose("Library instances of module [%s] [%s]:" % (str(Module), Arch))\r
 \r
@@ -124,14 +130,11 @@ def GetModuleLibInstances(Module, Platform, BuildDatabase, Arch, Target, Toolcha
         for LibraryClassName in M.LibraryClasses:\r
             if LibraryClassName not in LibraryInstance:\r
                 # override library instance for this module\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 is None or LibraryPath == "":\r
-                    LibraryPath = M.LibraryClasses[LibraryClassName]\r
-                    if LibraryPath is None or LibraryPath == "":\r
-                        if FileName:\r
+                LibraryPath = Platform.Modules[str(Module)].LibraryClasses.get(LibraryClassName,Platform.LibraryClasses[LibraryClassName, ModuleType])\r
+                if LibraryPath is None:\r
+                    LibraryPath = M.LibraryClasses.get(LibraryClassName)\r
+                    if LibraryPath is None:\r
+                        if not Module.LibraryClass:\r
                             EdkLogger.error("build", RESOURCE_NOT_AVAILABLE,\r
                                             "Instance of library class [%s] is not found" % LibraryClassName,\r
                                             File=FileName,\r
@@ -145,10 +148,10 @@ def GetModuleLibInstances(Module, Platform, BuildDatabase, Arch, Target, Toolcha
                     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
+                     or (ModuleType != SUP_MODULE_USER_DEFINED and ModuleType != SUP_MODULE_HOST_APPLICATION\r
                          and ModuleType not in LibraryModule.LibraryClass[0].SupModList):\r
                     # only USER_DEFINED can link against any library instance despite of its SupModList\r
-                    if FileName:\r
+                    if not Module.LibraryClass:\r
                         EdkLogger.error("build", OPTION_MISSING,\r
                                         "Module type [%s] is not supported by library instance [%s]" \\r
                                         % (ModuleType, LibraryPath), File=FileName,\r
@@ -158,7 +161,7 @@ def GetModuleLibInstances(Module, Platform, BuildDatabase, Arch, Target, Toolcha
 \r
                 LibraryInstance[LibraryClassName] = LibraryModule\r
                 LibraryConsumerList.append(LibraryModule)\r
-                if FileName:\r
+                if not Module.LibraryClass:\r
                     EdkLogger.verbose("\t" + str(LibraryClassName) + " : " + str(LibraryModule))\r
             else:\r
                 LibraryModule = LibraryInstance[LibraryClassName]\r
@@ -239,7 +242,7 @@ def GetModuleLibInstances(Module, Platform, BuildDatabase, Arch, Target, Toolcha
     #\r
     for Item in LibraryList:\r
         if ConsumedByList[Item] and Item in Constructor and len(Constructor) > 1:\r
-            if FileName:\r
+            if not Module.LibraryClass:\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
@@ -249,32 +252,10 @@ def GetModuleLibInstances(Module, Platform, BuildDatabase, Arch, Target, Toolcha
             SortedLibraryList.append(Item)\r
 \r
     #\r
-    # Build the list of constructor and destructir names\r
+    # Build the list of constructor and destructor 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
+    Module.LibInstances = SortedLibraryList\r
+    SortedLibraryList = [lib.SetReferenceModule(Module) for lib in SortedLibraryList]\r
     return SortedLibraryList\r
-\r
-def _ResolveLibraryReference(Module, Platform):\r
-    LibraryConsumerList = [Module]\r
-\r
-    # "CompilerStub" is a must for Edk modules\r
-    if Module.Libraries:\r
-        Module.Libraries.append("CompilerStub")\r
-    LibraryList = []\r
-    while len(LibraryConsumerList) > 0:\r
-        M = LibraryConsumerList.pop()\r
-        for LibraryName in M.Libraries:\r
-            Library = Platform.LibraryClasses[LibraryName, ':dummy:']\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 is None:\r
-                    continue\r
-\r
-            if Library not in LibraryList:\r
-                LibraryList.append(Library)\r
-                LibraryConsumerList.append(Library)\r
-    return LibraryList\r