public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: BobCF <bob.c.feng@intel.com>
To: edk2-devel@lists.01.org
Cc: Bob Feng <bob.c.feng@intel.com>, Liming Gao <liming.gao@intel.com>
Subject: [Patch] BaseTool: Replace dict with OrderedDict.
Date: Fri, 14 Sep 2018 17:51:22 +0800	[thread overview]
Message-ID: <20180914095122.9184-1-bob.c.feng@intel.com> (raw)

Replace dict with OrderedDict for PCD so that
the pcd list has same order.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
---
 BaseTools/Source/Python/GenFds/FdfParser.py   |  7 +++--
 .../Python/Workspace/BuildClassObject.py      | 11 ++++---
 .../Source/Python/Workspace/DscBuildData.py   | 31 +++++++++++--------
 3 files changed, 28 insertions(+), 21 deletions(-)

diff --git a/BaseTools/Source/Python/GenFds/FdfParser.py b/BaseTools/Source/Python/GenFds/FdfParser.py
index 8de0b48ff6..7d1cd0d133 100644
--- a/BaseTools/Source/Python/GenFds/FdfParser.py
+++ b/BaseTools/Source/Python/GenFds/FdfParser.py
@@ -62,10 +62,11 @@ from Common.MultipleWorkspace import MultipleWorkspace as mws
 import Common.LongFilePathOs as os
 from Common.LongFilePathSupport import OpenLongFilePath as open
 from .Capsule import EFI_CERT_TYPE_PKCS7_GUID
 from .Capsule import EFI_CERT_TYPE_RSA2048_SHA256_GUID
 from Common.RangeExpression import RangeExpression
+from collections import OrderedDict
 
 ##define T_CHAR_SPACE                ' '
 ##define T_CHAR_NULL                 '\0'
 ##define T_CHAR_CR                   '\r'
 ##define T_CHAR_TAB                  '\t'
@@ -225,12 +226,12 @@ class FileProfile :
 
         except:
             EdkLogger.error("FdfParser", FILE_OPEN_FAILURE, ExtraData=FileName)
 
         self.FileName = FileName
-        self.PcdDict = {}
-        self.PcdLocalDict = {}
+        self.PcdDict = OrderedDict()
+        self.PcdLocalDict = OrderedDict()
         self.InfList = []
         self.InfDict = {'ArchTBD':[]}
         # ECC will use this Dict and List information
         self.PcdFileLineDict = {}
         self.InfFileLineList = []
@@ -272,11 +273,11 @@ class FdfParser:
         # Used to section info
         self.__CurSection = []
         # Key: [section name, UI name, arch]
         # Value: {MACRO_NAME : MACRO_VALUE}
         self.__MacroDict = tdict(True, 3)
-        self.__PcdDict = {}
+        self.__PcdDict = OrderedDict()
 
         self.__WipeOffArea = []
         if GenFdsGlobalVariable.WorkSpaceDir == '':
             GenFdsGlobalVariable.WorkSpaceDir = os.getenv("WORKSPACE")
 
diff --git a/BaseTools/Source/Python/Workspace/BuildClassObject.py b/BaseTools/Source/Python/Workspace/BuildClassObject.py
index e6f5650279..4aaf8da408 100644
--- a/BaseTools/Source/Python/Workspace/BuildClassObject.py
+++ b/BaseTools/Source/Python/Workspace/BuildClassObject.py
@@ -12,10 +12,11 @@
 #
 
 from Common.DataType import *
 import collections
 import re
+from collections import OrderedDict
 StructPattern = re.compile(r'[_a-zA-Z][0-9A-Za-z_\[\]]*$')
 ArrayIndex = re.compile("\[\s*\d{0,1}\s*\]")
 ## PcdClassObject
 #
 # This Class is used for PcdObject
@@ -41,29 +42,29 @@ ArrayIndex = re.compile("\[\s*\d{0,1}\s*\]")
 # @var SkuInfoList:          To store value for SkuInfoList
 # @var IsOverrided:          To store value for IsOverrided
 # @var Phase:                To store value for Phase, default is "DXE"
 #
 class PcdClassObject(object):
-    def __init__(self, Name = None, Guid = None, Type = None, DatumType = None, Value = None, Token = None, MaxDatumSize = None, SkuInfoList = {}, IsOverrided = False, GuidValue = None, validateranges = [], validlists = [], expressions = [], IsDsc = False):
+    def __init__(self, Name = None, Guid = None, Type = None, DatumType = None, Value = None, Token = None, MaxDatumSize = None, SkuInfoList = None, IsOverrided = False, GuidValue = None, validateranges = None, validlists = None, expressions = None, IsDsc = False):
         self.TokenCName = Name
         self.TokenSpaceGuidCName = Guid
         self.TokenSpaceGuidValue = GuidValue
         self.Type = Type
         self._DatumType = DatumType
         self.DefaultValue = Value
         self.TokenValue = Token
         self.MaxDatumSize = MaxDatumSize
         self.MaxSizeUserSet = None
-        self.SkuInfoList = SkuInfoList
+        self.SkuInfoList = SkuInfoList if SkuInfoList is not None else OrderedDict()
         self.Phase = "DXE"
         self.Pending = False
         self.IsOverrided = IsOverrided
         self.IsFromBinaryInf = False
         self.IsFromDsc = False
-        self.validateranges = validateranges
-        self.validlists = validlists
-        self.expressions = expressions
+        self.validateranges = validateranges if validateranges is not None else []
+        self.validlists = validlists if validlists is not None else []
+        self.expressions = expressions if expressions is not None else []
         self.DscDefaultValue = None
         self.DscRawValue = None
         if IsDsc:
             self.DscDefaultValue = Value
         self.PcdValueFromComm = ""
diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py
index ed32dd0343..7b3f3bf23e 100644
--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
@@ -1234,16 +1234,21 @@ class DscBuildData(PlatformBuildClassObject):
             if not commpcds:
                 return False
             if len(commpcds[0]) == 5:
                 return True
             return False
-
+        NoFiledValues = OrderedDict()
         if CheckStructureInComm(GlobalData.BuildOptionPcd):
-            StructurePcdInCom = {(item[0], item[1], item[2] ):(item[3], item[4]) for item in GlobalData.BuildOptionPcd } if GlobalData.BuildOptionPcd else {}
-            NoFiledValues = {(item[0], item[1]):StructurePcdInCom[item] for item in StructurePcdInCom if not item[2]}
+            StructurePcdInCom = OrderedDict()
+            for item in GlobalData.BuildOptionPcd:
+                StructurePcdInCom[(item[0], item[1], item[2] )] = (item[3], item[4])
+            for item in StructurePcdInCom:
+                if not item[2]:
+                    NoFiledValues[(item[0], item[1])] = StructurePcdInCom[item]
         else:
-            NoFiledValues = {(item[0], item[1]):[item[2]] for item in GlobalData.BuildOptionPcd}
+            for item in GlobalData.BuildOptionPcd:
+                NoFiledValues[(item[0], item[1])] = [item[2]]
         for Guid, Name in NoFiledValues:
             if (Name, Guid) in AllPcds:
                 Pcd = AllPcds.get((Name, Guid))
                 if isinstance(self._DecPcds.get((Pcd.TokenCName, Pcd.TokenSpaceGuidCName), None), StructurePcd):
                     self._DecPcds.get((Pcd.TokenCName, Pcd.TokenSpaceGuidCName)).PcdValueFromComm = NoFiledValues[(Pcd.TokenSpaceGuidCName, Pcd.TokenCName)][0]
@@ -2291,11 +2296,11 @@ class DscBuildData(PlatformBuildClassObject):
             MakeApp = MakeApp + PcdGccMakefile
             MakeApp = MakeApp + 'APPNAME = %s\n' % (PcdValueInitName) + 'OBJECTS = %s/%s.o\n' % (self.OutputPath, PcdValueInitName) + \
                       'include $(MAKEROOT)/Makefiles/app.makefile\n' + 'INCLUDE +='
 
         IncSearchList = []
-        PlatformInc = {}
+        PlatformInc = OrderedDict()
         for Cache in self._Bdb._CACHE_.values():
             if Cache.MetaFile.Ext.lower() != '.dec':
                 continue
             if Cache.Includes:
                 if str(Cache.MetaFile.Path) not in PlatformInc:
@@ -2321,11 +2326,11 @@ class DscBuildData(PlatformBuildClassObject):
         MakeApp = MakeApp + '\n'
 
         CC_FLAGS = LinuxCFLAGS
         if sys.platform == "win32":
             CC_FLAGS = WindowsCFLAGS
-        BuildOptions = {}
+        BuildOptions = OrderedDict()
         for Options in self.BuildOptions:
             if Options[2] != EDKII_NAME:
                 continue
             Family = Options[0]
             if Family and Family != self.ToolChainFamily:
@@ -2336,11 +2341,11 @@ class DscBuildData(PlatformBuildClassObject):
 
             if Target == "*" or Target == self._Target:
                 if Tag == "*" or Tag == self._Toolchain:
                     if Arch == "*" or Arch == self.Arch:
                         if Tool not in BuildOptions:
-                            BuildOptions[Tool] = {}
+                            BuildOptions[Tool] = OrderedDict()
                         if Attr != "FLAGS" or Attr not in BuildOptions[Tool] or self.BuildOptions[Options].startswith('='):
                             BuildOptions[Tool][Attr] = self.BuildOptions[Options]
                         else:
                             # append options for the same tool except PATH
                             if Attr != 'PATH':
@@ -2541,11 +2546,11 @@ class DscBuildData(PlatformBuildClassObject):
                                                     self._PCD_TYPE_STRING_[Type],
                                                     DatumType,
                                                     PcdValue,
                                                     '',
                                                     MaxDatumSize,
-                                                    {SkuName : SkuInfo},
+                                                    OrderedDict({SkuName : SkuInfo}),
                                                     False,
                                                     None,
                                                     IsDsc=True)
 
         for pcd in Pcds.values():
@@ -2598,21 +2603,21 @@ class DscBuildData(PlatformBuildClassObject):
     def CopyDscRawValue(self, Pcd):
         if Pcd.DscRawValue is None:
             Pcd.DscRawValue = dict()
         if Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD], self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:
             if self.SkuIdMgr.SystemSkuId not in Pcd.DscRawValue:
-                Pcd.DscRawValue[self.SkuIdMgr.SystemSkuId] = {}
+                Pcd.DscRawValue[self.SkuIdMgr.SystemSkuId] = OrderedDict()
             Pcd.DscRawValue[self.SkuIdMgr.SystemSkuId][TAB_DEFAULT_STORES_DEFAULT] = Pcd.DefaultValue
         for skuname in Pcd.SkuInfoList:
-            Pcd.DscRawValue[skuname] = {}
+            Pcd.DscRawValue[skuname] = OrderedDict()
             if Pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]]:
                 for defaultstore in Pcd.SkuInfoList[skuname].DefaultStoreDict:
                     Pcd.DscRawValue[skuname][defaultstore] = Pcd.SkuInfoList[skuname].DefaultStoreDict[defaultstore]
             else:
                 Pcd.DscRawValue[skuname][TAB_DEFAULT_STORES_DEFAULT] = Pcd.SkuInfoList[skuname].DefaultValue
     def CompletePcdValues(self, PcdSet):
-        Pcds = {}
+        Pcds = OrderedDict()
         DefaultStoreObj = DefaultStore(self._GetDefaultStores())
         SkuIds = {skuname:skuid for skuname, skuid in self.SkuIdMgr.AvailableSkuIdSet.items() if skuname != TAB_COMMON}
         DefaultStores = set(storename for pcdobj in PcdSet.values() for skuobj in pcdobj.SkuInfoList.values() for storename in skuobj.DefaultStoreDict)
         for PcdCName, TokenSpaceGuid in PcdSet:
             PcdObj = PcdSet[(PcdCName, TokenSpaceGuid)]
@@ -2742,11 +2747,11 @@ class DscBuildData(PlatformBuildClassObject):
                                                 self._PCD_TYPE_STRING_[Type],
                                                 '',
                                                 DefaultValue,
                                                 '',
                                                 '',
-                                                {SkuName : SkuInfo},
+                                                OrderedDict({SkuName : SkuInfo}),
                                                 False,
                                                 None,
                                                 pcdDecObject.validateranges,
                                                 pcdDecObject.validlists,
                                                 pcdDecObject.expressions,
@@ -2881,11 +2886,11 @@ class DscBuildData(PlatformBuildClassObject):
                                                 self._PCD_TYPE_STRING_[Type],
                                                 '',
                                                 InitialValue,
                                                 '',
                                                 MaxDatumSize,
-                                                {SkuName : SkuInfo},
+                                                OrderedDict({SkuName : SkuInfo}),
                                                 False,
                                                 None,
                                                 IsDsc=True)
         for pcd in Pcds.values():
             SkuInfoObj = pcd.SkuInfoList.values()[0]
-- 
2.18.0.windows.1



                 reply	other threads:[~2018-09-14  9:51 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20180914095122.9184-1-bob.c.feng@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