## @file\r
# Common routines used by workspace\r
#\r
-# Copyright (c) 2012 - 2017, Intel Corporation. All rights reserved.<BR>\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
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
#\r
\r
-from Common.Misc import sdict\r
+from collections import OrderedDict, defaultdict\r
from Common.DataType import SUP_MODULE_USER_DEFINED\r
from BuildClassObject import LibraryClassObject\r
import Common.GlobalData as GlobalData\r
from Workspace.BuildClassObject import StructurePcd\r
\r
+class OrderedListDict(OrderedDict, defaultdict):\r
+ def __init__(self, *args, **kwargs):\r
+ super(OrderedListDict, self).__init__(*args, **kwargs)\r
+ self.default_factory = list\r
+\r
## Get all packages from platform for specified arch, target and toolchain\r
#\r
# @param Platform: DscBuildData instance\r
PcdCName = Pcd[0]\r
PcdTokenName = Pcd[1]\r
if GlobalData.MixedPcd:\r
- for PcdItem in GlobalData.MixedPcd.keys():\r
+ for PcdItem in GlobalData.MixedPcd:\r
if (PcdCName, PcdTokenName) in GlobalData.MixedPcd[PcdItem]:\r
PcdCName = PcdItem[0]\r
break\r
- if (PcdCName, PcdTokenName) not in DecPcds.keys():\r
+ if (PcdCName, PcdTokenName) not in DecPcds:\r
DecPcds[PcdCName, PcdTokenName] = Pkg.Pcds[Pcd]\r
return DecPcds, GuidDict\r
\r
# EdkII module\r
LibraryConsumerList = [Module]\r
Constructor = []\r
- ConsumedByList = sdict()\r
- LibraryInstance = sdict()\r
+ ConsumedByList = OrderedListDict()\r
+ LibraryInstance = OrderedDict()\r
\r
while len(LibraryConsumerList) > 0:\r
M = LibraryConsumerList.pop()\r
LibraryPath = PlatformModule.LibraryClasses[LibraryClassName]\r
else:\r
LibraryPath = Platform.LibraryClasses[LibraryClassName, ModuleType]\r
- if LibraryPath == None or LibraryPath == "":\r
+ if LibraryPath is None or LibraryPath == "":\r
LibraryPath = M.LibraryClasses[LibraryClassName]\r
- if LibraryPath == None or LibraryPath == "":\r
+ if LibraryPath is None or LibraryPath == "":\r
return []\r
\r
LibraryModule = BuildDatabase[LibraryPath, Arch, Target, Toolchain]\r
# for those forced library instance (NULL library), add a fake library class\r
if LibraryClassName.startswith("NULL"):\r
LibraryModule.LibraryClass.append(LibraryClassObject(LibraryClassName, [ModuleType]))\r
- elif LibraryModule.LibraryClass == None \\r
+ elif LibraryModule.LibraryClass is None \\r
or len(LibraryModule.LibraryClass) == 0 \\r
- or (ModuleType != 'USER_DEFINED'\r
+ or (ModuleType != SUP_MODULE_USER_DEFINED\r
and ModuleType not in LibraryModule.LibraryClass[0].SupModList):\r
# only USER_DEFINED can link against any library instance despite of its SupModList\r
return []\r
else:\r
LibraryModule = LibraryInstance[LibraryClassName]\r
\r
- if LibraryModule == None:\r
+ if LibraryModule is None:\r
continue\r
\r
if LibraryModule.ConstructorList != [] and LibraryModule not in Constructor:\r
Constructor.append(LibraryModule)\r
\r
- if LibraryModule not in ConsumedByList:\r
- ConsumedByList[LibraryModule] = []\r
# don't add current module itself to consumer list\r
if M != Module:\r
if M in ConsumedByList[LibraryModule]:\r
for LibraryClassName in LibraryInstance:\r
M = LibraryInstance[LibraryClassName]\r
LibraryList.append(M)\r
- if ConsumedByList[M] == []:\r
+ if len(ConsumedByList[M]) == 0:\r
Q.append(M)\r
\r
#\r
# remove edge e from the graph if Node has no constructor\r
ConsumedByList[Item].remove(Node)\r
EdgeRemoved = True\r
- if ConsumedByList[Item] == []:\r
+ if len(ConsumedByList[Item]) == 0:\r
# insert Item into Q\r
Q.insert(0, Item)\r
break\r
# remove edge e from the graph\r
ConsumedByList[Item].remove(Node)\r
\r
- if ConsumedByList[Item] != []:\r
+ if len(ConsumedByList[Item]) != 0:\r
continue\r
# insert Item into Q, if Item has no other incoming edges\r
Q.insert(0, Item)\r
# if any remaining node Item in the graph has a constructor and an incoming edge, then the graph has a cycle\r
#\r
for Item in LibraryList:\r
- if ConsumedByList[Item] != [] and Item in Constructor and len(Constructor) > 1:\r
+ if len(ConsumedByList[Item]) != 0 and Item in Constructor and len(Constructor) > 1:\r
return []\r
if Item not in SortedLibraryList:\r
SortedLibraryList.append(Item)\r
M = LibraryConsumerList.pop()\r
for LibraryName in M.Libraries:\r
Library = Platform.LibraryClasses[LibraryName, ':dummy:']\r
- if Library == None:\r
- for Key in Platform.LibraryClasses.data.keys():\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 == None:\r
+ if Library is None:\r
continue\r
\r
if Library not in LibraryList:\r