From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.31; helo=mga06.intel.com; envelope-from=jaben.carsey@intel.com; receiver=edk2-devel@lists.01.org Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (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 52285226C7C35 for ; Tue, 3 Apr 2018 14:03:12 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Apr 2018 14:03:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,402,1517904000"; d="scan'208";a="47710175" Received: from jcarsey-desk1.amr.corp.intel.com ([10.7.159.144]) by orsmga002.jf.intel.com with ESMTP; 03 Apr 2018 14:03:11 -0700 From: Jaben Carsey To: edk2-devel@lists.01.org Cc: Liming Gao , Yonghong Zhu Date: Tue, 3 Apr 2018 14:03:08 -0700 Message-Id: <17db4173ab0c73eb8791ebef3ea0916c5e52a230.1522789210.git.jaben.carsey@intel.com> X-Mailer: git-send-email 2.16.2.windows.1 In-Reply-To: References: In-Reply-To: References: Subject: [PATCH v1 08/10] BaseTools: use combined version of OrderedDict 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: , X-List-Received-Date: Tue, 03 Apr 2018 21:03:12 -0000 since we need order and a default entry, use collections dicts to auto generate. Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jaben Carsey --- BaseTools/Source/Python/Workspace/WorkspaceCommon.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/BaseTools/Source/Python/Workspace/WorkspaceCommon.py b/BaseTools/Source/Python/Workspace/WorkspaceCommon.py index abe34cf9a071..8c27b4ad5b9b 100644 --- a/BaseTools/Source/Python/Workspace/WorkspaceCommon.py +++ b/BaseTools/Source/Python/Workspace/WorkspaceCommon.py @@ -12,11 +12,17 @@ # from Common.Misc import sdict +from collections import OrderedDict, defaultdict from Common.DataType import SUP_MODULE_USER_DEFINED from BuildClassObject import LibraryClassObject import Common.GlobalData as GlobalData from Workspace.BuildClassObject import StructurePcd +class OrderedListDict(OrderedDict, defaultdict): + def __init__(self, *args, **kwargs): + super(OrderedListDict, self).__init__(*args, **kwargs) + self.default_factory = list + ## Get all packages from platform for specified arch, target and toolchain # # @param Platform: DscBuildData instance @@ -106,7 +112,7 @@ def _GetModuleLibraryInstances(Module, Platform, BuildDatabase, Arch, Target, To # EdkII module LibraryConsumerList = [Module] Constructor = [] - ConsumedByList = sdict() + ConsumedByList = OrderedListDict() LibraryInstance = sdict() while len(LibraryConsumerList) > 0: @@ -145,8 +151,6 @@ def _GetModuleLibraryInstances(Module, Platform, BuildDatabase, Arch, Target, To if LibraryModule.ConstructorList != [] and LibraryModule not in Constructor: Constructor.append(LibraryModule) - if LibraryModule not in ConsumedByList: - ConsumedByList[LibraryModule] = [] # don't add current module itself to consumer list if M != Module: if M in ConsumedByList[LibraryModule]: @@ -164,7 +168,7 @@ def _GetModuleLibraryInstances(Module, Platform, BuildDatabase, Arch, Target, To for LibraryClassName in LibraryInstance: M = LibraryInstance[LibraryClassName] LibraryList.append(M) - if ConsumedByList[M] == []: + if len(ConsumedByList[M]) == 0: Q.append(M) # @@ -185,7 +189,7 @@ def _GetModuleLibraryInstances(Module, Platform, BuildDatabase, Arch, Target, To # remove edge e from the graph if Node has no constructor ConsumedByList[Item].remove(Node) EdgeRemoved = True - if ConsumedByList[Item] == []: + if len(ConsumedByList[Item]) == 0: # insert Item into Q Q.insert(0, Item) break @@ -207,7 +211,7 @@ def _GetModuleLibraryInstances(Module, Platform, BuildDatabase, Arch, Target, To # remove edge e from the graph ConsumedByList[Item].remove(Node) - if ConsumedByList[Item] != []: + if len(ConsumedByList[Item]) != 0: continue # insert Item into Q, if Item has no other incoming edges Q.insert(0, Item) @@ -216,7 +220,7 @@ 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 # for Item in LibraryList: - if ConsumedByList[Item] != [] and Item in Constructor and len(Constructor) > 1: + if len(ConsumedByList[Item]) != 0 and Item in Constructor and len(Constructor) > 1: return [] if Item not in SortedLibraryList: SortedLibraryList.append(Item) -- 2.16.2.windows.1