From nobody Mon Feb 9 18:19:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1526602019172515.0014190830425; Thu, 17 May 2018 17:06:59 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 8ABC6208AE405; Thu, 17 May 2018 17:06:56 -0700 (PDT) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 727CD20837995 for ; Thu, 17 May 2018 17:06:55 -0700 (PDT) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 May 2018 17:06:55 -0700 Received: from jcarsey-desk1.amr.corp.intel.com ([10.7.159.144]) by orsmga001.jf.intel.com with ESMTP; 17 May 2018 17:06:54 -0700 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.136; helo=mga12.intel.com; envelope-from=jaben.carsey@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,413,1520924400"; d="scan'208";a="56905106" From: Jaben Carsey To: edk2-devel@lists.01.org Date: Thu, 17 May 2018 17:06:51 -0700 Message-Id: X-Mailer: git-send-email 2.16.2.windows.1 In-Reply-To: References: In-Reply-To: References: Subject: [edk2] [PATCH v1 1/2] BaseTools: refactor to remove functions X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" refactoring almost identical functions to delete and use the other. Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jaben Carsey --- BaseTools/Source/Python/AutoGen/AutoGen.py | 165 ++-------------= ----- BaseTools/Source/Python/Workspace/WorkspaceCommon.py | 52 ++++-- 2 files changed, 45 insertions(+), 172 deletions(-) diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py b/BaseTools/Source/= Python/AutoGen/AutoGen.py index 1e6511cdb5d2..d1801bff9c83 100644 --- a/BaseTools/Source/Python/AutoGen/AutoGen.py +++ b/BaseTools/Source/Python/AutoGen/AutoGen.py @@ -42,6 +42,7 @@ from GenPatchPcdTable.GenPatchPcdTable import parsePcdInf= oFromMapFile import Common.VpdInfoFile as VpdInfoFile from GenPcdDb import CreatePcdDatabaseCode from Workspace.MetaFileCommentParser import UsageList +from Workspace.WorkspaceCommon import GetModuleLibInstances from Common.MultipleWorkspace import MultipleWorkspace as mws import InfSectionParser import datetime @@ -2156,162 +2157,14 @@ class PlatformAutoGen(AutoGen): if str(Module) not in self.Platform.Modules: return [] =20 - ModuleType =3D Module.ModuleType - - # for overridding library instances with module specific setting - PlatformModule =3D self.Platform.Modules[str(Module)] - - # add forced library instances (specified under LibraryClasses sec= tions) - # - # If a module has a MODULE_TYPE of USER_DEFINED, - # do not link in NULL library class instances from the global [Lib= raryClasses.*] sections. - # - if Module.ModuleType !=3D SUP_MODULE_USER_DEFINED: - for LibraryClass in self.Platform.LibraryClasses.GetKeys(): - if LibraryClass.startswith("NULL") and self.Platform.Libra= ryClasses[LibraryClass, Module.ModuleType]: - Module.LibraryClasses[LibraryClass] =3D self.Platform.= LibraryClasses[LibraryClass, Module.ModuleType] - - # add forced library instances (specified in module overrides) - for LibraryClass in PlatformModule.LibraryClasses: - if LibraryClass.startswith("NULL"): - Module.LibraryClasses[LibraryClass] =3D PlatformModule.Lib= raryClasses[LibraryClass] - - # EdkII module - LibraryConsumerList =3D [Module] - Constructor =3D [] - ConsumedByList =3D OrderedDict() - LibraryInstance =3D OrderedDict() - - EdkLogger.verbose("") - EdkLogger.verbose("Library instances of module [%s] [%s]:" % (str(= Module), self.Arch)) - while len(LibraryConsumerList) > 0: - M =3D LibraryConsumerList.pop() - for LibraryClassName in M.LibraryClasses: - if LibraryClassName not in LibraryInstance: - # override library instance for this module - if LibraryClassName in PlatformModule.LibraryClasses: - LibraryPath =3D PlatformModule.LibraryClasses[Libr= aryClassName] - else: - LibraryPath =3D self.Platform.LibraryClasses[Libra= ryClassName, ModuleType] - if LibraryPath is None or LibraryPath =3D=3D "": - LibraryPath =3D M.LibraryClasses[LibraryClassName] - if LibraryPath is None or LibraryPath =3D=3D "": - EdkLogger.error("build", RESOURCE_NOT_AVAILABL= E, - "Instance of library class [%s= ] is not found" % LibraryClassName, - File=3Dself.MetaFile, - ExtraData=3D"in [%s] [%s]\n\tc= onsumed by module [%s]" % (str(M), self.Arch, str(Module))) - - LibraryModule =3D self.BuildDatabase[LibraryPath, self= .Arch, self.BuildTarget, self.ToolChain] - # for those forced library instance (NULL library), ad= d a fake library class - if LibraryClassName.startswith("NULL"): - LibraryModule.LibraryClass.append(LibraryClassObje= ct(LibraryClassName, [ModuleType])) - elif LibraryModule.LibraryClass is None \ - or len(LibraryModule.LibraryClass) =3D=3D 0 \ - or (ModuleType !=3D SUP_MODULE_USER_DEFINED - and ModuleType not in LibraryModule.LibraryCl= ass[0].SupModList): - # only USER_DEFINED can link against any library i= nstance despite of its SupModList - EdkLogger.error("build", OPTION_MISSING, - "Module type [%s] is not supported= by library instance [%s]" \ - % (ModuleType, LibraryPath), File= =3Dself.MetaFile, - ExtraData=3D"consumed by [%s]" % s= tr(Module)) - - LibraryInstance[LibraryClassName] =3D LibraryModule - LibraryConsumerList.append(LibraryModule) - EdkLogger.verbose("\t" + str(LibraryClassName) + " : "= + str(LibraryModule)) - else: - LibraryModule =3D LibraryInstance[LibraryClassName] - - if LibraryModule is None: - continue - - if LibraryModule.ConstructorList !=3D [] and LibraryModule= not in Constructor: - Constructor.append(LibraryModule) - - if LibraryModule not in ConsumedByList: - ConsumedByList[LibraryModule] =3D [] - # don't add current module itself to consumer list - if M !=3D Module: - if M in ConsumedByList[LibraryModule]: - continue - ConsumedByList[LibraryModule].append(M) - # - # Initialize the sorted output list to the empty set - # - SortedLibraryList =3D [] - # - # Q <- Set of all nodes with no incoming edges - # - LibraryList =3D [] #LibraryInstance.values() - Q =3D [] - for LibraryClassName in LibraryInstance: - M =3D LibraryInstance[LibraryClassName] - LibraryList.append(M) - if ConsumedByList[M] =3D=3D []: - Q.append(M) - - # - # start the DAG algorithm - # - while True: - EdgeRemoved =3D True - while Q =3D=3D [] and EdgeRemoved: - EdgeRemoved =3D False - # for each node Item with a Constructor - for Item in LibraryList: - if Item not in Constructor: - continue - # for each Node without a constructor with an edge e f= rom Item to Node - for Node in ConsumedByList[Item]: - if Node in Constructor: - continue - # remove edge e from the graph if Node has no cons= tructor - ConsumedByList[Item].remove(Node) - EdgeRemoved =3D True - if ConsumedByList[Item] =3D=3D []: - # insert Item into Q - Q.insert(0, Item) - break - if Q !=3D []: - break - # DAG is done if there's no more incoming edge for all nodes - if Q =3D=3D []: - break - - # remove node from Q - Node =3D Q.pop() - # output Node - SortedLibraryList.append(Node) - - # for each node Item with an edge e from Node to Item do - for Item in LibraryList: - if Node not in ConsumedByList[Item]: - continue - # remove edge e from the graph - ConsumedByList[Item].remove(Node) - - if ConsumedByList[Item] !=3D []: - continue - # insert Item into Q, if Item has no other incoming edges - Q.insert(0, Item) - - # - # if any remaining node Item in the graph has a constructor and an= incoming edge, then the graph has a cycle - # - for Item in LibraryList: - if ConsumedByList[Item] !=3D [] and Item in Constructor and le= n(Constructor) > 1: - ErrorMessage =3D "\tconsumed by " + "\n\tconsumed by ".joi= n(str(L) for L in ConsumedByList[Item]) - EdkLogger.error("build", BUILD_ERROR, 'Library [%s] with c= onstructors has a cycle' % str(Item), - ExtraData=3DErrorMessage, File=3Dself.Meta= File) - if Item not in SortedLibraryList: - SortedLibraryList.append(Item) - - # - # Build the list of constructor and destructir names - # The DAG Topo sort produces the destructor order, so the list of = constructors must generated in the reverse order - # - SortedLibraryList.reverse() - return SortedLibraryList - + return GetModuleLibInstances(Module, + self.Platform, + self.BuildDatabase, + self.Arch, + self.BuildTarget, + self.ToolChain, + self.MetaFile, + EdkLogger) =20 ## Override PCD setting (type, value, ...) # diff --git a/BaseTools/Source/Python/Workspace/WorkspaceCommon.py b/BaseToo= ls/Source/Python/Workspace/WorkspaceCommon.py index 573100081815..a28fbdf03021 100644 --- a/BaseTools/Source/Python/Workspace/WorkspaceCommon.py +++ b/BaseTools/Source/Python/Workspace/WorkspaceCommon.py @@ -83,16 +83,13 @@ def GetDeclaredPcd(Platform, BuildDatabase, Arch, Targe= t, Toolchain,additionalPk # def GetLiabraryInstances(Module, Platform, BuildDatabase, Arch, Target, To= olchain): if Module.AutoGenVersion >=3D 0x00010005: - return _GetModuleLibraryInstances(Module, Platform, BuildDatabase,= Arch, Target, Toolchain) + return GetModuleLibInstances(Module, Platform, BuildDatabase, Arch= , Target, Toolchain) else: return _ResolveLibraryReference(Module, Platform) =20 -def _GetModuleLibraryInstances(Module, Platform, BuildDatabase, Arch, Targ= et, Toolchain): +def GetModuleLibInstances(Module, Platform, BuildDatabase, Arch, Target, T= oolchain, FileName =3D '', EdkLogger =3D None): ModuleType =3D Module.ModuleType =20 - # for overriding library instances with module specific setting - PlatformModule =3D Platform.Modules[str(Module)] - # add forced library instances (specified under LibraryClasses section= s) # # If a module has a MODULE_TYPE of USER_DEFINED, @@ -104,9 +101,9 @@ def _GetModuleLibraryInstances(Module, Platform, BuildD= atabase, Arch, Target, To Module.LibraryClasses[LibraryClass] =3D Platform.LibraryCl= asses[LibraryClass, Module.ModuleType] =20 # add forced library instances (specified in module overrides) - for LibraryClass in PlatformModule.LibraryClasses: + for LibraryClass in Platform.Modules[str(Module)].LibraryClasses: if LibraryClass.startswith("NULL"): - Module.LibraryClasses[LibraryClass] =3D PlatformModule.Library= Classes[LibraryClass] + Module.LibraryClasses[LibraryClass] =3D Platform.Modules[str(M= odule)].LibraryClasses[LibraryClass] =20 # EdkII module LibraryConsumerList =3D [Module] @@ -114,19 +111,29 @@ def _GetModuleLibraryInstances(Module, Platform, Buil= dDatabase, Arch, Target, To ConsumedByList =3D OrderedListDict() LibraryInstance =3D OrderedDict() =20 + if FileName: + EdkLogger.verbose("") + EdkLogger.verbose("Library instances of module [%s] [%s]:" % (str(= Module), Arch)) + while len(LibraryConsumerList) > 0: M =3D LibraryConsumerList.pop() for LibraryClassName in M.LibraryClasses: if LibraryClassName not in LibraryInstance: # override library instance for this module - if LibraryClassName in PlatformModule.LibraryClasses: - LibraryPath =3D PlatformModule.LibraryClasses[LibraryC= lassName] + if LibraryClassName in Platform.Modules[str(Module)].Libra= ryClasses: + LibraryPath =3D Platform.Modules[str(Module)].LibraryC= lasses[LibraryClassName] else: LibraryPath =3D Platform.LibraryClasses[LibraryClassNa= me, ModuleType] if LibraryPath is None or LibraryPath =3D=3D "": LibraryPath =3D M.LibraryClasses[LibraryClassName] if LibraryPath is None or LibraryPath =3D=3D "": - return [] + if FileName: + EdkLogger.error("build", RESOURCE_NOT_AVAILABL= E, + "Instance of library class [%s= ] is not found" % LibraryClassName, + File=3DFileName, + ExtraData=3D"in [%s] [%s]\n\tc= onsumed by module [%s]" % (str(M), Arch, str(Module))) + else: + return [] =20 LibraryModule =3D BuildDatabase[LibraryPath, Arch, Target,= Toolchain] # for those forced library instance (NULL library), add a = fake library class @@ -137,10 +144,18 @@ def _GetModuleLibraryInstances(Module, Platform, Buil= dDatabase, Arch, Target, To or (ModuleType !=3D SUP_MODULE_USER_DEFINED and ModuleType not in LibraryModule.LibraryClass[= 0].SupModList): # only USER_DEFINED can link against any library insta= nce despite of its SupModList - return [] + if FileName: + EdkLogger.error("build", OPTION_MISSING, + "Module type [%s] is not supported= by library instance [%s]" \ + % (ModuleType, LibraryPath), File= =3DFileName, + ExtraData=3D"consumed by [%s]" % s= tr(Module)) + else: + return [] =20 LibraryInstance[LibraryClassName] =3D LibraryModule LibraryConsumerList.append(LibraryModule) + if FileName: + EdkLogger.verbose("\t" + str(LibraryClassName) + " : "= + str(LibraryModule)) else: LibraryModule =3D LibraryInstance[LibraryClassName] =20 @@ -167,7 +182,7 @@ def _GetModuleLibraryInstances(Module, Platform, BuildD= atabase, Arch, Target, To for LibraryClassName in LibraryInstance: M =3D LibraryInstance[LibraryClassName] LibraryList.append(M) - if len(ConsumedByList[M]) =3D=3D 0: + if not ConsumedByList[M]: Q.append(M) =20 # @@ -188,7 +203,7 @@ def _GetModuleLibraryInstances(Module, Platform, BuildD= atabase, Arch, Target, To # remove edge e from the graph if Node has no construc= tor ConsumedByList[Item].remove(Node) EdgeRemoved =3D True - if len(ConsumedByList[Item]) =3D=3D 0: + if not ConsumedByList[Item]: # insert Item into Q Q.insert(0, Item) break @@ -210,7 +225,7 @@ def _GetModuleLibraryInstances(Module, Platform, BuildD= atabase, Arch, Target, To # remove edge e from the graph ConsumedByList[Item].remove(Node) =20 - if len(ConsumedByList[Item]) !=3D 0: + if ConsumedByList[Item]: continue # insert Item into Q, if Item has no other incoming edges Q.insert(0, Item) @@ -219,8 +234,13 @@ def _GetModuleLibraryInstances(Module, Platform, Build= Database, Arch, Target, To # if any remaining node Item in the graph has a constructor and an inc= oming edge, then the graph has a cycle # for Item in LibraryList: - if len(ConsumedByList[Item]) !=3D 0 and Item in Constructor and le= n(Constructor) > 1: - return [] + if ConsumedByList[Item] and Item in Constructor and len(Constructo= r) > 1: + if FileName: + ErrorMessage =3D "\tconsumed by " + "\n\tconsumed by ".joi= n(str(L) for L in ConsumedByList[Item]) + EdkLogger.error("build", BUILD_ERROR, 'Library [%s] with c= onstructors has a cycle' % str(Item), + ExtraData=3DErrorMessage, File=3DFileName) + else: + return [] if Item not in SortedLibraryList: SortedLibraryList.append(Item) =20 --=20 2.16.2.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel