From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.93; helo=mga11.intel.com; envelope-from=bob.c.feng@intel.com; receiver=edk2-devel@lists.01.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id B51C72097FABF for ; Fri, 14 Sep 2018 02:51:50 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Sep 2018 02:51:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,372,1531810800"; d="scan'208";a="80404749" Received: from bfeng1-mobl1.ccr.corp.intel.com ([10.239.196.33]) by FMSMGA003.fm.intel.com with ESMTP; 14 Sep 2018 02:51:48 -0700 From: BobCF To: edk2-devel@lists.01.org Cc: Bob Feng , Liming Gao Date: Fri, 14 Sep 2018 17:51:22 +0800 Message-Id: <20180914095122.9184-1-bob.c.feng@intel.com> X-Mailer: git-send-email 2.18.0.windows.1 Subject: [Patch] BaseTool: Replace dict with OrderedDict. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 14 Sep 2018 09:51:50 -0000 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 Cc: Liming Gao --- 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