BaseTools: use combined version of OrderedDict

since we need order and a default entry, use collections dicts to
auto generate.

Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
This commit is contained in:
Carsey, Jaben 2018-04-04 05:03:08 +08:00 committed by Yonghong Zhu
parent 6e6d767edf
commit 1f1c671284
1 changed files with 11 additions and 7 deletions

View File

@ -12,11 +12,17 @@
# #
from Common.Misc import sdict from Common.Misc import sdict
from collections import OrderedDict, defaultdict
from Common.DataType import SUP_MODULE_USER_DEFINED from Common.DataType import SUP_MODULE_USER_DEFINED
from BuildClassObject import LibraryClassObject from BuildClassObject import LibraryClassObject
import Common.GlobalData as GlobalData import Common.GlobalData as GlobalData
from Workspace.BuildClassObject import StructurePcd 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 ## Get all packages from platform for specified arch, target and toolchain
# #
# @param Platform: DscBuildData instance # @param Platform: DscBuildData instance
@ -106,7 +112,7 @@ def _GetModuleLibraryInstances(Module, Platform, BuildDatabase, Arch, Target, To
# EdkII module # EdkII module
LibraryConsumerList = [Module] LibraryConsumerList = [Module]
Constructor = [] Constructor = []
ConsumedByList = sdict() ConsumedByList = OrderedListDict()
LibraryInstance = sdict() LibraryInstance = sdict()
while len(LibraryConsumerList) > 0: while len(LibraryConsumerList) > 0:
@ -145,8 +151,6 @@ def _GetModuleLibraryInstances(Module, Platform, BuildDatabase, Arch, Target, To
if LibraryModule.ConstructorList != [] and LibraryModule not in Constructor: if LibraryModule.ConstructorList != [] and LibraryModule not in Constructor:
Constructor.append(LibraryModule) Constructor.append(LibraryModule)
if LibraryModule not in ConsumedByList:
ConsumedByList[LibraryModule] = []
# don't add current module itself to consumer list # don't add current module itself to consumer list
if M != Module: if M != Module:
if M in ConsumedByList[LibraryModule]: if M in ConsumedByList[LibraryModule]:
@ -164,7 +168,7 @@ def _GetModuleLibraryInstances(Module, Platform, BuildDatabase, Arch, Target, To
for LibraryClassName in LibraryInstance: for LibraryClassName in LibraryInstance:
M = LibraryInstance[LibraryClassName] M = LibraryInstance[LibraryClassName]
LibraryList.append(M) LibraryList.append(M)
if ConsumedByList[M] == []: if len(ConsumedByList[M]) == 0:
Q.append(M) 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 # remove edge e from the graph if Node has no constructor
ConsumedByList[Item].remove(Node) ConsumedByList[Item].remove(Node)
EdgeRemoved = True EdgeRemoved = True
if ConsumedByList[Item] == []: if len(ConsumedByList[Item]) == 0:
# insert Item into Q # insert Item into Q
Q.insert(0, Item) Q.insert(0, Item)
break break
@ -207,7 +211,7 @@ def _GetModuleLibraryInstances(Module, Platform, BuildDatabase, Arch, Target, To
# remove edge e from the graph # remove edge e from the graph
ConsumedByList[Item].remove(Node) ConsumedByList[Item].remove(Node)
if ConsumedByList[Item] != []: if len(ConsumedByList[Item]) != 0:
continue continue
# insert Item into Q, if Item has no other incoming edges # insert Item into Q, if Item has no other incoming edges
Q.insert(0, Item) 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 # 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: 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 [] return []
if Item not in SortedLibraryList: if Item not in SortedLibraryList:
SortedLibraryList.append(Item) SortedLibraryList.append(Item)