public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Jaben Carsey <jaben.carsey@intel.com>
To: edk2-devel@lists.01.org
Cc: Liming Gao <liming.gao@intel.com>, Yonghong Zhu <yonghong.zhu@intel.com>
Subject: [PATCH v1 08/10] BaseTools: use combined version of OrderedDict
Date: Tue,  3 Apr 2018 14:03:08 -0700	[thread overview]
Message-ID: <17db4173ab0c73eb8791ebef3ea0916c5e52a230.1522789210.git.jaben.carsey@intel.com> (raw)
In-Reply-To: <cover.1522789210.git.jaben.carsey@intel.com>
In-Reply-To: <cover.1522789210.git.jaben.carsey@intel.com>

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>
---
 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



  parent reply	other threads:[~2018-04-03 21:03 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-03 21:03 [PATCH v1 00/10] BaseTools: refactor code Jaben Carsey
2018-04-03 21:03 ` [PATCH v1 01/10] BaseTools: Use local variable for list of constants Jaben Carsey
2018-04-03 21:03 ` [PATCH v1 02/10] BaseTools: use built in dict instead of custom version Jaben Carsey
2018-04-03 21:03 ` [PATCH v1 03/10] BaseTools: Eot tool never populates this dictionary Jaben Carsey
2018-04-03 21:03 ` [PATCH v1 04/10] BaseTools: remove unused import statement Jaben Carsey
2018-04-03 21:03 ` [PATCH v1 05/10] BaseTools - AutoGen - replace custom dictionary class with python standard one Jaben Carsey
2018-04-03 21:03 ` [PATCH v1 06/10] BaseTools: Eot remove unused code Jaben Carsey
2018-04-03 21:03 ` [PATCH v1 07/10] BaseTools: use built in OrderedDict instead of custom version Jaben Carsey
2018-04-03 21:03 ` Jaben Carsey [this message]
2018-04-03 21:03 ` [PATCH v1 09/10] BaseTools: Workspace - " Jaben Carsey
2018-04-03 21:03 ` [PATCH v1 10/10] BaseTools: Remove unused code from Misc Jaben Carsey
2018-04-08  6:40 ` [PATCH v1 00/10] BaseTools: refactor code Zhu, Yonghong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=17db4173ab0c73eb8791ebef3ea0916c5e52a230.1522789210.git.jaben.carsey@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox