From: Carsey, Jaben Date: Tue, 3 Apr 2018 21:03:08 +0000 (+0800) Subject: BaseTools: use combined version of OrderedDict X-Git-Tag: edk2-stable201903~1970 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=1f1c67128430bfd8a57213f7147d56f194880a51 BaseTools: use combined version of OrderedDict 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 Reviewed-by: Yonghong Zhu --- diff --git a/BaseTools/Source/Python/Workspace/WorkspaceCommon.py b/BaseTools/Source/Python/Workspace/WorkspaceCommon.py index abe34cf9a0..8c27b4ad5b 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)