public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v1 0/9] BaseTools: refactoring
@ 2018-04-13 20:51 Jaben Carsey
  2018-04-13 20:51 ` [PATCH v1 1/9] BaseTools: remove unused local variable Jaben Carsey
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: Jaben Carsey @ 2018-04-13 20:51 UTC (permalink / raw)
  To: edk2-devel

group of patches for refactoring BaseTools.  removing unused functions, 
variables, and parameters.  make functions statis where apropriate.

Jaben (9):
  BaseTools: remove unused local variable.
  BaseTools: change DscBuildData functions without need for self to
    staticmethod
  BaseTools: Remove unused functions from DscBuildData
  BaseTools: move RegEx compile out of loops
  BaseTools: use dictionary.get() when we have value if not found
  BaseTools: refactor DepexSection.GenSection
  BaseTools: FdfParser refactor to remove a dictionary
  BaseTools: FdfParser - refactor functions to make static
  BaseTools: FfsInfStatement - remove unused function

 BaseTools/Source/Python/GenFds/DepexSection.py    |  14 +-
 BaseTools/Source/Python/GenFds/FdfParser.py       |  20 +--
 BaseTools/Source/Python/GenFds/FfsInfStatement.py |  27 +---
 BaseTools/Source/Python/Workspace/DscBuildData.py | 146 +++++++++-----------
 BaseTools/Source/Python/build/build.py            |   4 +-
 5 files changed, 87 insertions(+), 124 deletions(-)

-- 
2.16.2.windows.1



^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v1 1/9] BaseTools: remove unused local variable.
  2018-04-13 20:51 [PATCH v1 0/9] BaseTools: refactoring Jaben Carsey
@ 2018-04-13 20:51 ` Jaben Carsey
  2018-04-13 20:51 ` [PATCH v1 2/9] BaseTools: change DscBuildData functions without need for self to staticmethod Jaben Carsey
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Jaben Carsey @ 2018-04-13 20:51 UTC (permalink / raw)
  To: edk2-devel; +Cc: Liming Gao, Yonghong Zhu

From: Jaben <jaben.carsey@intel.com>

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/DscBuildData.py | 2 --
 1 file changed, 2 deletions(-)

diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py
index 6766f059b0f7..39ac73a04867 100644
--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
@@ -279,8 +279,6 @@ class DscBuildData(PlatformBuildClassObject):
     ## handle Override Path of Module
     def _HandleOverridePath(self):
         RecordList = self._RawData[MODEL_META_DATA_COMPONENT, self._Arch]
-        Macros = self._Macros
-        Macros["EDK_SOURCE"] = GlobalData.gEcpSource
         for Record in RecordList:
             ModuleId = Record[6]
             LineNo = Record[7]
-- 
2.16.2.windows.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v1 2/9] BaseTools: change DscBuildData functions without need for self to staticmethod
  2018-04-13 20:51 [PATCH v1 0/9] BaseTools: refactoring Jaben Carsey
  2018-04-13 20:51 ` [PATCH v1 1/9] BaseTools: remove unused local variable Jaben Carsey
@ 2018-04-13 20:51 ` Jaben Carsey
  2018-04-13 20:51 ` [PATCH v1 3/9] BaseTools: Remove unused functions from DscBuildData Jaben Carsey
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Jaben Carsey @ 2018-04-13 20:51 UTC (permalink / raw)
  To: edk2-devel; +Cc: Liming Gao, Yonghong Zhu

From: Jaben <jaben.carsey@intel.com>

prepend functiosn with @staticmethod
change calls to use class name, not self

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/DscBuildData.py | 102 ++++++++++++--------
 1 file changed, 64 insertions(+), 38 deletions(-)

diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py
index 39ac73a04867..6177a964a1ad 100644
--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
@@ -650,14 +650,17 @@ class DscBuildData(PlatformBuildClassObject):
                 if not IsValidWord(Record[1]):
                     EdkLogger.error('build', FORMAT_INVALID, "The format of the Sku ID name is invalid. The correct format is '(a-zA-Z0-9_)(a-zA-Z0-9_-.)*'",
                                     File=self.MetaFile, Line=Record[-1])
-                self._SkuIds[Record[1].upper()] = (str(self.ToInt(Record[0])), Record[1].upper(), Record[2].upper())
+                self._SkuIds[Record[1].upper()] = (str(DscBuildData.ToInt(Record[0])), Record[1].upper(), Record[2].upper())
             if 'DEFAULT' not in self._SkuIds:
                 self._SkuIds['DEFAULT'] = ("0","DEFAULT","DEFAULT")
             if 'COMMON' not in self._SkuIds:
                 self._SkuIds['COMMON'] = ("0","DEFAULT","DEFAULT")
         return self._SkuIds
-    def ToInt(self,intstr):
+
+    @staticmethod
+    def ToInt(intstr):
         return int(intstr,16) if intstr.upper().startswith("0X") else int(intstr)
+
     def _GetDefaultStores(self):
         if self.DefaultStores is None:
             self.DefaultStores = OrderedDict()
@@ -677,7 +680,7 @@ class DscBuildData(PlatformBuildClassObject):
                 if not IsValidWord(Record[1]):
                     EdkLogger.error('build', FORMAT_INVALID, "The format of the DefaultStores ID name is invalid. The correct format is '(a-zA-Z0-9_)(a-zA-Z0-9_-.)*'",
                                     File=self.MetaFile, Line=Record[-1])
-                self.DefaultStores[Record[1].upper()] = (self.ToInt(Record[0]),Record[1].upper())
+                self.DefaultStores[Record[1].upper()] = (DscBuildData.ToInt(Record[0]),Record[1].upper())
             if TAB_DEFAULT_STORES_DEFAULT not in self.DefaultStores:
                 self.DefaultStores[TAB_DEFAULT_STORES_DEFAULT] = (0,TAB_DEFAULT_STORES_DEFAULT)
             GlobalData.gDefaultStores = self.DefaultStores.keys()
@@ -1034,9 +1037,9 @@ class DscBuildData(PlatformBuildClassObject):
                         EdkLogger.error('build', AUTOGEN_ERROR, "The Pcd %s is not found in the DEC file." % (DisplayName))
                 pcdvalue = pcdvalue.replace("\\\\\\'", '\\\\\\"').replace('\\\'', '\'').replace('\\\\\\"', "\\'")
                 if FieldName:
-                    pcdvalue = self.HandleFlexiblePcd(TokenSpaceGuidCName, TokenCName, pcdvalue, PcdDatumType, self._GuidDict, FieldName)
+                    pcdvalue = DscBuildData.HandleFlexiblePcd(TokenSpaceGuidCName, TokenCName, pcdvalue, PcdDatumType, self._GuidDict, FieldName)
                 else:
-                    pcdvalue = self.HandleFlexiblePcd(TokenSpaceGuidCName, TokenCName, pcdvalue, PcdDatumType, self._GuidDict)
+                    pcdvalue = DscBuildData.HandleFlexiblePcd(TokenSpaceGuidCName, TokenCName, pcdvalue, PcdDatumType, self._GuidDict)
                     IsValid, Cause = CheckPcdDatum(PcdDatumType, pcdvalue)
                     if not IsValid:
                         EdkLogger.error("build", FORMAT_INVALID, Cause, ExtraData="%s.%s" % (TokenSpaceGuidCName, TokenCName))
@@ -1050,7 +1053,8 @@ class DscBuildData(PlatformBuildClassObject):
                         if (TokenSpaceGuidCName, TokenCName) == (PcdItem.TokenSpaceGuidCName, PcdItem.TokenCName) and FieldName =="":
                             PcdItem.DefaultValue = pcdvalue
 
-    def HandleFlexiblePcd(self, TokenSpaceGuidCName, TokenCName, PcdValue, PcdDatumType, GuidDict, FieldName=''):
+    @staticmethod
+    def HandleFlexiblePcd(TokenSpaceGuidCName, TokenCName, PcdValue, PcdDatumType, GuidDict, FieldName=''):
         if FieldName:
             IsArray = False
             TokenCName += '.' + FieldName
@@ -1203,7 +1207,9 @@ class DscBuildData(PlatformBuildClassObject):
             structure_pcd_data[(item[0],item[1])].append(item)
 
         return structure_pcd_data
-    def OverrideByFdfComm(self,StruPcds):
+    
+    @staticmethod
+    def OverrideByFdfComm(StruPcds):
         StructurePcdInCom = OrderedDict()
         for item in GlobalData.BuildOptionPcd:
             if len(item) == 5 and (item[1],item[0]) in StruPcds:
@@ -1223,6 +1229,7 @@ class DscBuildData(PlatformBuildClassObject):
                 Pcd.PcdFieldValueFromComm[field][1] = FieldValues[field][1][0]
                 Pcd.PcdFieldValueFromComm[field][2] = FieldValues[field][1][1]
         return StruPcds
+
     def OverrideByFdfCommOverAll(self,AllPcds):
         def CheckStructureInComm(commpcds):
             if not commpcds:
@@ -1379,7 +1386,7 @@ class DscBuildData(PlatformBuildClassObject):
                         if defaultstoreid not in stru_pcd.SkuOverrideValues[skuid]:
                             stru_pcd.SkuOverrideValues[skuid][defaultstoreid] = copy.deepcopy(stru_pcd.SkuOverrideValues[nextskuid][mindefaultstorename])
                             stru_pcd.ValueChain[(skuid,defaultstoreid)]= (nextskuid,mindefaultstorename)
-        S_pcd_set = self.OverrideByFdfComm(S_pcd_set)
+        S_pcd_set = DscBuildData.OverrideByFdfComm(S_pcd_set)
         Str_Pcd_Values = self.GenerateByteArrayValue(S_pcd_set)
         if Str_Pcd_Values:
             for (skuname,StoreName,PcdGuid,PcdName,PcdValue) in Str_Pcd_Values:
@@ -1551,7 +1558,8 @@ class DscBuildData(PlatformBuildClassObject):
 
         return str(max([pcd_size for pcd_size in [get_length(item) for item in sku_values]]))
 
-    def ExecuteCommand (self, Command):
+    @staticmethod
+    def ExecuteCommand (Command):
         try:
             Process = subprocess.Popen(Command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
         except:
@@ -1559,7 +1567,8 @@ class DscBuildData(PlatformBuildClassObject):
         Result = Process.communicate()
         return Process.returncode, Result[0], Result[1]
 
-    def IntToCString(self, Value, ValueSize):
+    @staticmethod
+    def IntToCString(Value, ValueSize):
         Result = '"'
         if not isinstance (Value, str):
             for Index in range(0, ValueSize):
@@ -1568,7 +1577,8 @@ class DscBuildData(PlatformBuildClassObject):
         Result = Result + '"'
         return Result
 
-    def GetPcdMaxSize(self,Pcd):
+    @staticmethod
+    def GetPcdMaxSize(Pcd):
         MaxSize = int(Pcd.MaxDatumSize,10) if Pcd.MaxDatumSize else 0
         if Pcd.DatumType not in ['BOOLEAN','UINT8','UINT16','UINT32','UINT64']:
             if Pcd.PcdValueFromComm:
@@ -1589,6 +1599,7 @@ class DscBuildData(PlatformBuildClassObject):
         elif Pcd.DatumType  == 'UINT64':
             MaxSize = 8
         return MaxSize
+
     def GenerateSizeFunction(self,Pcd):
         CApp = "// Default Value in Dec \n"
         CApp = CApp + "void Cal_%s_%s_Size(UINT32 *Size){\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)
@@ -1671,13 +1682,16 @@ class DscBuildData(PlatformBuildClassObject):
                 while '[' in FieldName:
                     FieldName = FieldName.rsplit('[', 1)[0]
                     CApp = CApp + '  __FLEXIBLE_SIZE(*Size, %s, %s, %d); // From %s Line %d Value %s \n' % (Pcd.DatumType, FieldName.strip("."), ArrayIndex + 1, Pcd.PcdFieldValueFromComm[FieldName_ori][1], Pcd.PcdFieldValueFromComm[FieldName_ori][2], Pcd.PcdFieldValueFromComm[FieldName_ori][0])
-        CApp = CApp + "  *Size = (%d > *Size ? %d : *Size); // The Pcd maxsize is %d \n" % (self.GetPcdMaxSize(Pcd),self.GetPcdMaxSize(Pcd),self.GetPcdMaxSize(Pcd))
+        CApp = CApp + "  *Size = (%d > *Size ? %d : *Size); // The Pcd maxsize is %d \n" % (DscBuildData.GetPcdMaxSize(Pcd),DscBuildData.GetPcdMaxSize(Pcd),DscBuildData.GetPcdMaxSize(Pcd))
         CApp = CApp + "}\n"
         return CApp
-    def GenerateSizeStatments(self,Pcd):
+    
+    @staticmethod
+    def GenerateSizeStatments(Pcd):
         CApp = '  Size = sizeof(%s);\n' % (Pcd.DatumType)
         CApp = CApp + '  Cal_%s_%s_Size(&Size);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)
         return CApp
+
     def GenerateDefaultValueAssignFunction(self,Pcd):
         CApp = "// Default value in Dec \n"
         CApp = CApp + "void Assign_%s_%s_Default_Value(%s *Pcd){\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType)
@@ -1699,7 +1713,7 @@ class DscBuildData(PlatformBuildClassObject):
         #
         # Use memcpy() to copy value into field
         #
-            CApp = CApp + '  Value     = %s; // From DEC Default Value %s\n' % (self.IntToCString(Value, ValueSize), Pcd.DefaultValueFromDec)
+            CApp = CApp + '  Value     = %s; // From DEC Default Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.DefaultValueFromDec)
             CApp = CApp + '  memcpy (Pcd, Value, %d);\n' % (ValueSize)
         for FieldList in [Pcd.DefaultValues]:
             if not FieldList:
@@ -1724,7 +1738,7 @@ class DscBuildData(PlatformBuildClassObject):
                     # Use memcpy() to copy value into field
                     #
                     CApp = CApp + '  FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.DatumType, FieldName)
-                    CApp = CApp + '  Value     = %s; // From %s Line %d Value %s\n' % (self.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
+                    CApp = CApp + '  Value     = %s; // From %s Line %d Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
                     CApp = CApp + '  memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)
                 else:
                     if ValueSize > 4:
@@ -1733,9 +1747,12 @@ class DscBuildData(PlatformBuildClassObject):
                         CApp = CApp + '  Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
         CApp = CApp + "}\n"
         return CApp
-    def GenerateDefaultValueAssignStatement(self,Pcd):
+    
+    @staticmethod
+    def GenerateDefaultValueAssignStatement(Pcd):
         CApp = '  Assign_%s_%s_Default_Value(Pcd);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)
         return CApp
+
     def GenerateInitValueFunction(self,Pcd,SkuName,DefaultStoreName):
         CApp = "// Value in Dsc for Sku: %s, DefaultStore %s\n" % (SkuName,DefaultStoreName)
         CApp = CApp + "void Assign_%s_%s_%s_%s_Value(%s *Pcd){\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName,DefaultStoreName,Pcd.DatumType)
@@ -1771,7 +1788,7 @@ class DscBuildData(PlatformBuildClassObject):
                     #
                     # Use memcpy() to copy value into field
                     #
-                        CApp = CApp + '  Value     = %s; // From DSC Default Value %s\n' % (self.IntToCString(Value, ValueSize), Pcd.DefaultFromDSC.get('DEFAULT',{}).get('STANDARD', Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue)
+                        CApp = CApp + '  Value     = %s; // From DSC Default Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.DefaultFromDSC.get('DEFAULT',{}).get('STANDARD', Pcd.DefaultValue) if Pcd.DefaultFromDSC else Pcd.DefaultValue)
                         CApp = CApp + '  memcpy (Pcd, Value, %d);\n' % (ValueSize)
                 else:
                     if isinstance(Value, str):
@@ -1780,7 +1797,7 @@ class DscBuildData(PlatformBuildClassObject):
                     #
                     # Use memcpy() to copy value into field
                     #
-                        CApp = CApp + '  Value     = %s; // From DSC Default Value %s\n' % (self.IntToCString(Value, ValueSize), Pcd.DscRawValue.get(SkuName,{}).get(DefaultStoreName))
+                        CApp = CApp + '  Value     = %s; // From DSC Default Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), Pcd.DscRawValue.get(SkuName,{}).get(DefaultStoreName))
                         CApp = CApp + '  memcpy (Pcd, Value, %d);\n' % (ValueSize)
                 continue
             if (SkuName,DefaultStoreName) == ('DEFAULT','STANDARD') or (( (SkuName,'') not in Pcd.ValueChain) and ( (SkuName,DefaultStoreName) not in Pcd.ValueChain )):
@@ -1803,7 +1820,7 @@ class DscBuildData(PlatformBuildClassObject):
                     # Use memcpy() to copy value into field
                     #
                         CApp = CApp + '  FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.DatumType, FieldName)
-                        CApp = CApp + '  Value     = %s; // From %s Line %d Value %s\n' % (self.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
+                        CApp = CApp + '  Value     = %s; // From %s Line %d Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
                         CApp = CApp + '  memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)
                     else:
                         if ValueSize > 4:
@@ -1812,9 +1829,12 @@ class DscBuildData(PlatformBuildClassObject):
                             CApp = CApp + '  Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
         CApp = CApp + "}\n"
         return CApp
-    def GenerateInitValueStatement(self,Pcd,SkuName,DefaultStoreName):
+    
+    @staticmethod
+    def GenerateInitValueStatement(Pcd,SkuName,DefaultStoreName):
         CApp = '  Assign_%s_%s_%s_%s_Value(Pcd);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,SkuName,DefaultStoreName)
         return CApp
+
     def GenerateCommandLineValue(self,Pcd):
         CApp = "// Value in CommandLine\n"
         CApp = CApp + "void Assign_%s_%s_CommandLine_Value(%s *Pcd){\n" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName,Pcd.DatumType)
@@ -1841,7 +1861,7 @@ class DscBuildData(PlatformBuildClassObject):
                 #
                 # Use memcpy() to copy value into field
                 #
-                    CApp = CApp + '  Value     = %s; // From Command Line.\n' % (self.IntToCString(Value, ValueSize))
+                    CApp = CApp + '  Value     = %s; // From Command Line.\n' % (DscBuildData.IntToCString(Value, ValueSize))
                     CApp = CApp + '  memcpy (Pcd, Value, %d);\n' % (ValueSize)
                 continue
             for FieldName in FieldList:
@@ -1865,7 +1885,7 @@ class DscBuildData(PlatformBuildClassObject):
                 # Use memcpy() to copy value into field
                 #
                     CApp = CApp + '  FieldSize = __FIELD_SIZE(%s, %s);\n' % (Pcd.DatumType, FieldName)
-                    CApp = CApp + '  Value     = %s; // From %s Line %d Value %s\n' % (self.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
+                    CApp = CApp + '  Value     = %s; // From %s Line %d Value %s\n' % (DscBuildData.IntToCString(Value, ValueSize), FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
                     CApp = CApp + '  memcpy (&Pcd->%s, Value, (FieldSize > 0 && FieldSize < %d) ? FieldSize : %d);\n' % (FieldName, ValueSize, ValueSize)
                 else:
                     if ValueSize > 4:
@@ -1874,9 +1894,12 @@ class DscBuildData(PlatformBuildClassObject):
                         CApp = CApp + '  Pcd->%s = %d; // From %s Line %d Value %s\n' % (FieldName, Value, FieldList[FieldName][1], FieldList[FieldName][2], FieldList[FieldName][0])
         CApp = CApp + "}\n"
         return CApp
-    def GenerateCommandLineValueStatement(self,Pcd):
+    
+    @staticmethod
+    def GenerateCommandLineValueStatement(Pcd):
         CApp = '  Assign_%s_%s_CommandLine_Value(Pcd);\n' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)
         return CApp
+
     def GenerateInitializeFunc(self, SkuName, DefaultStore, Pcd, InitByteValue, CApp):
         OverrideValues = {DefaultStore:""}
         if Pcd.SkuOverrideValues:
@@ -1916,7 +1939,7 @@ class DscBuildData(PlatformBuildClassObject):
             # in a structure.  The size formula for this case is:
             # OFFSET_OF(FlexbleArrayField) + sizeof(FlexibleArray[0]) * (HighestIndex + 1)
             #
-            CApp = CApp + self.GenerateSizeStatments(Pcd)
+            CApp = CApp + DscBuildData.GenerateSizeStatments(Pcd)
 
             #
             # Allocate and zero buffer for the PCD
@@ -1935,20 +1958,20 @@ class DscBuildData(PlatformBuildClassObject):
             #
             # Assign field values in PCD
             #
-            CApp = CApp + self.GenerateDefaultValueAssignStatement(Pcd)
+            CApp = CApp + DscBuildData.GenerateDefaultValueAssignStatement(Pcd)
             if Pcd.Type not in [self._PCD_TYPE_STRING_[MODEL_PCD_FIXED_AT_BUILD],
                         self._PCD_TYPE_STRING_[MODEL_PCD_PATCHABLE_IN_MODULE]]:
                 for skuname in self.SkuIdMgr.GetSkuChain(SkuName):
                     storeset = [DefaultStoreName] if DefaultStoreName == 'STANDARD' else ['STANDARD', DefaultStoreName]
                     for defaultstorenameitem in storeset:
                         CApp = CApp + "// SkuName: %s,  DefaultStoreName: %s \n" % (skuname, defaultstorenameitem)
-                        CApp = CApp + self.GenerateInitValueStatement(Pcd,skuname,defaultstorenameitem)
+                        CApp = CApp + DscBuildData.GenerateInitValueStatement(Pcd,skuname,defaultstorenameitem)
                     if skuname == SkuName:
                         break
             else:
                 CApp = CApp + "// SkuName: %s,  DefaultStoreName: STANDARD \n" % self.SkuIdMgr.SystemSkuId
-                CApp = CApp + self.GenerateInitValueStatement(Pcd,self.SkuIdMgr.SystemSkuId,"STANDARD")
-            CApp = CApp + self.GenerateCommandLineValueStatement(Pcd)
+                CApp = CApp + DscBuildData.GenerateInitValueStatement(Pcd,self.SkuIdMgr.SystemSkuId,"STANDARD")
+            CApp = CApp + DscBuildData.GenerateCommandLineValueStatement(Pcd)
             #
             # Set new PCD value and size
             #
@@ -2143,11 +2166,11 @@ class DscBuildData(PlatformBuildClassObject):
         Messages = ''
         if sys.platform == "win32":
             MakeCommand = 'nmake -f %s' % (MakeFileName)
-            returncode, StdOut, StdErr = self.ExecuteCommand (MakeCommand)
+            returncode, StdOut, StdErr = DscBuildData.ExecuteCommand (MakeCommand)
             Messages = StdOut
         else:
             MakeCommand = 'make -f %s' % (MakeFileName)
-            returncode, StdOut, StdErr = self.ExecuteCommand (MakeCommand)
+            returncode, StdOut, StdErr = DscBuildData.ExecuteCommand (MakeCommand)
             Messages = StdErr
         Messages = Messages.split('\n')
         MessageGroup = []
@@ -2193,9 +2216,9 @@ class DscBuildData(PlatformBuildClassObject):
             else:
                 EdkLogger.error('Build', COMMAND_FAILURE, 'Can not execute command: %s' % MakeCommand)
 
-        if self.NeedUpdateOutput(OutputValueFile, PcdValueInitExe ,InputValueFile):
+        if DscBuildData.NeedUpdateOutput(OutputValueFile, PcdValueInitExe ,InputValueFile):
             Command = PcdValueInitExe + ' -i %s -o %s' % (InputValueFile, OutputValueFile)
-            returncode, StdOut, StdErr = self.ExecuteCommand (Command)
+            returncode, StdOut, StdErr = DscBuildData.ExecuteCommand (Command)
             if returncode <> 0:
                 EdkLogger.warn('Build', COMMAND_FAILURE, 'Can not collect output from command: %s' % Command)
 
@@ -2210,7 +2233,8 @@ class DscBuildData(PlatformBuildClassObject):
             StructurePcdSet.append((PcdInfo[0],PcdInfo[1], PcdInfo[2], PcdInfo[3], PcdValue[2].strip()))
         return StructurePcdSet
 
-    def NeedUpdateOutput(self,OutputFile, ValueCFile, StructureInput):
+    @staticmethod
+    def NeedUpdateOutput(OutputFile, ValueCFile, StructureInput):
         if not os.path.exists(OutputFile):
             return True
         if os.stat(OutputFile).st_mtime <= os.stat(ValueCFile).st_mtime:
@@ -2320,8 +2344,8 @@ class DscBuildData(PlatformBuildClassObject):
 
         return PcdObj
 
-
-    def CompareVarAttr(self, Attr1, Attr2):
+    @staticmethod
+    def CompareVarAttr(Attr1, Attr2):
         if not Attr1 or not Attr2:  # for empty string
             return True
         Attr1s = [attr.strip() for attr in Attr1.split(",")]
@@ -2332,6 +2356,7 @@ class DscBuildData(PlatformBuildClassObject):
             return True
         else:
             return False
+
     def CopyDscRawValue(self,Pcd):
         if Pcd.DscRawValue is None:
             Pcd.DscRawValue = dict()
@@ -2459,7 +2484,7 @@ class DscBuildData(PlatformBuildClassObject):
             if (VariableName, VariableGuid) not in VariableAttrs:
                 VariableAttrs[(VariableName, VariableGuid)] = VarAttribute
             else:
-                if not self.CompareVarAttr(VariableAttrs[(VariableName, VariableGuid)], VarAttribute):
+                if not DscBuildData.CompareVarAttr(VariableAttrs[(VariableName, VariableGuid)], VarAttribute):
                     EdkLogger.error('Build', PCD_VARIABLE_ATTRIBUTES_CONFLICT_ERROR, "The variable %s.%s for DynamicHii PCDs has conflicting attributes [%s] and [%s] " % (VariableGuid, VariableName, VarAttribute, VariableAttrs[(VariableName, VariableGuid)]))
 
             pcdDecObject = self._DecPcds[PcdCName, TokenSpaceGuid]
@@ -2526,7 +2551,7 @@ class DscBuildData(PlatformBuildClassObject):
                         skuobj.DefaultStoreDict[defaultst] = StringToArray(skuobj.DefaultStoreDict[defaultst])
                 pcd.DefaultValue = StringToArray(pcd.DefaultValue)
                 pcd.MaxDatumSize = str(MaxSize)
-        rt, invalidhii = self.CheckVariableNameAssignment(Pcds)
+        rt, invalidhii = DscBuildData.CheckVariableNameAssignment(Pcds)
         if not rt:
             invalidpcd = ",".join(invalidhii)
             EdkLogger.error('build', PCD_VARIABLE_INFO_ERROR, Message='The same HII PCD must map to the same EFI variable for all SKUs', File=self.MetaFile, ExtraData=invalidpcd)
@@ -2535,7 +2560,8 @@ class DscBuildData(PlatformBuildClassObject):
 
         return Pcds
 
-    def CheckVariableNameAssignment(self,Pcds):
+    @staticmethod
+    def CheckVariableNameAssignment(Pcds):
         invalidhii = []
         for pcdname in Pcds:
             pcd = Pcds[pcdname]
-- 
2.16.2.windows.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v1 3/9] BaseTools: Remove unused functions from DscBuildData
  2018-04-13 20:51 [PATCH v1 0/9] BaseTools: refactoring Jaben Carsey
  2018-04-13 20:51 ` [PATCH v1 1/9] BaseTools: remove unused local variable Jaben Carsey
  2018-04-13 20:51 ` [PATCH v1 2/9] BaseTools: change DscBuildData functions without need for self to staticmethod Jaben Carsey
@ 2018-04-13 20:51 ` Jaben Carsey
  2018-04-13 20:51 ` [PATCH v1 4/9] BaseTools: move RegEx compile out of loops Jaben Carsey
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Jaben Carsey @ 2018-04-13 20:51 UTC (permalink / raw)
  To: edk2-devel; +Cc: Liming Gao, Yonghong Zhu

From: Jaben <jaben.carsey@intel.com>

3 functions were never called:
_dumpPcdInfo
__STRING2OCTList
__UNICODE2OCTList

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/DscBuildData.py | 31 --------------------
 1 file changed, 31 deletions(-)

diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py
index 6177a964a1ad..ea001eef0281 100644
--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
@@ -1145,17 +1145,6 @@ class DscBuildData(PlatformBuildClassObject):
             self.RecoverCommandLinePcd()
         return self._Pcds
 
-    def _dumpPcdInfo(self,Pcds):
-        for pcd in Pcds:
-            pcdobj = Pcds[pcd]
-            if not pcdobj.TokenCName.startswith("Test"):
-                continue
-            for skuid in pcdobj.SkuInfoList:
-                if pcdobj.Type in (self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII],self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]):
-                    for storename in pcdobj.SkuInfoList[skuid].DefaultStoreDict:
-                        print "PcdCName: %s, SkuName: %s, StoreName: %s, Value: %s" % (".".join((pcdobj.TokenSpaceGuidCName, pcdobj.TokenCName)), skuid,storename,str(pcdobj.SkuInfoList[skuid].DefaultStoreDict[storename]))
-                else:
-                    print "PcdCName: %s, SkuName: %s, Value: %s" % (".".join((pcdobj.TokenSpaceGuidCName, pcdobj.TokenCName)), skuid,str(pcdobj.SkuInfoList[skuid].DefaultValue))
     ## Retrieve [BuildOptions]
     def _GetBuildOptions(self):
         if self._BuildOptions is None:
@@ -1514,26 +1503,6 @@ class DscBuildData(PlatformBuildClassObject):
 
         return Pcds
 
-    def __UNICODE2OCTList(self,Value):
-        Value = Value.strip()
-        Value = Value[2:-1]
-        List = []
-        for Item in Value:
-            Temp = '%04X' % ord(Item)
-            List.append('0x' + Temp[2:4])
-            List.append('0x' + Temp[0:2])
-        List.append('0x00')
-        List.append('0x00')
-        return List
-    def __STRING2OCTList(self,Value):
-        OCTList = []
-        Value = Value.strip('"')
-        for char in Value:
-            Temp = '%02X' % ord(char)
-            OCTList.append('0x' + Temp)
-        OCTList.append('0x00')
-        return OCTList
-
     def GetStructurePcdMaxSize(self, str_pcd):
         pcd_default_value = str_pcd.DefaultValue
         sku_values = [skuobj.HiiDefaultValue if str_pcd.Type in [self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_HII], self._PCD_TYPE_STRING_[MODEL_PCD_DYNAMIC_EX_HII]] else skuobj.DefaultValue for skuobj in str_pcd.SkuInfoList.values()]
-- 
2.16.2.windows.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v1 4/9] BaseTools: move RegEx compile out of loops
  2018-04-13 20:51 [PATCH v1 0/9] BaseTools: refactoring Jaben Carsey
                   ` (2 preceding siblings ...)
  2018-04-13 20:51 ` [PATCH v1 3/9] BaseTools: Remove unused functions from DscBuildData Jaben Carsey
@ 2018-04-13 20:51 ` Jaben Carsey
  2018-04-13 20:51 ` [PATCH v1 5/9] BaseTools: use dictionary.get() when we have value if not found Jaben Carsey
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Jaben Carsey @ 2018-04-13 20:51 UTC (permalink / raw)
  To: edk2-devel; +Cc: Liming Gao, Yonghong Zhu

From: Jaben <jaben.carsey@intel.com>

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/DscBuildData.py | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py
index ea001eef0281..fb0def46f331 100644
--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
@@ -95,6 +95,9 @@ MAKEROOT ?= $(EDK_TOOLS_PATH)/Source/C
 LIBS = -lCommon
 '''
 
+## regular expressions for finding decimal and hex numbers
+Pattern = re.compile('^[1-9]\d*|0$')
+HexPattern = re.compile(r'0[xX][0-9a-fA-F]+$')
 ## Regular expression for finding header file inclusions
 from AutoGen.GenMake import gIncludePattern
 
@@ -642,9 +645,7 @@ class DscBuildData(PlatformBuildClassObject):
                 if Record[1] in [None, '']:
                     EdkLogger.error('build', FORMAT_INVALID, 'No Sku ID name',
                                     File=self.MetaFile, Line=Record[-1])
-                Pattern = re.compile('^[1-9]\d*|0$')
-                HexPattern = re.compile(r'0[xX][0-9a-fA-F]+$')
-                if Pattern.match(Record[0]) is None and HexPattern.match(Record[0]) is None:
+                if not Pattern.match(Record[0]) and not HexPattern.match(Record[0]):
                     EdkLogger.error('build', FORMAT_INVALID, "The format of the Sku ID number is invalid. It only support Integer and HexNumber",
                                     File=self.MetaFile, Line=Record[-1])
                 if not IsValidWord(Record[1]):
@@ -672,9 +673,7 @@ class DscBuildData(PlatformBuildClassObject):
                 if Record[1] in [None, '']:
                     EdkLogger.error('build', FORMAT_INVALID, 'No DefaultStores ID name',
                                     File=self.MetaFile, Line=Record[-1])
-                Pattern = re.compile('^[1-9]\d*|0$')
-                HexPattern = re.compile(r'0[xX][0-9a-fA-F]+$')
-                if Pattern.match(Record[0]) is None and HexPattern.match(Record[0]) is None:
+                if not Pattern.match(Record[0]) and not HexPattern.match(Record[0]):
                     EdkLogger.error('build', FORMAT_INVALID, "The format of the DefaultStores ID number is invalid. It only support Integer and HexNumber",
                                     File=self.MetaFile, Line=Record[-1])
                 if not IsValidWord(Record[1]):
-- 
2.16.2.windows.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v1 5/9] BaseTools: use dictionary.get() when we have value if not found
  2018-04-13 20:51 [PATCH v1 0/9] BaseTools: refactoring Jaben Carsey
                   ` (3 preceding siblings ...)
  2018-04-13 20:51 ` [PATCH v1 4/9] BaseTools: move RegEx compile out of loops Jaben Carsey
@ 2018-04-13 20:51 ` Jaben Carsey
  2018-04-13 20:51 ` [PATCH v1 6/9] BaseTools: refactor DepexSection.GenSection Jaben Carsey
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Jaben Carsey @ 2018-04-13 20:51 UTC (permalink / raw)
  To: edk2-devel; +Cc: Liming Gao, Yonghong Zhu

From: Jaben <jaben.carsey@intel.com>

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/build/build.py | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/BaseTools/Source/Python/build/build.py b/BaseTools/Source/Python/build/build.py
index 6fb2e0ed3d09..ede963bc231a 100644
--- a/BaseTools/Source/Python/build/build.py
+++ b/BaseTools/Source/Python/build/build.py
@@ -1604,9 +1604,7 @@ class Build():
                         SmmModuleList[Module.MetaFile] = ImageInfo
                         SmmSize += ImageInfo.Image.Size
                         if Module.ModuleType == 'DXE_SMM_DRIVER':
-                            PiSpecVersion = '0x00000000'
-                            if 'PI_SPECIFICATION_VERSION' in Module.Module.Specification:
-                                PiSpecVersion = Module.Module.Specification['PI_SPECIFICATION_VERSION']
+                            PiSpecVersion = Module.Module.Specification.get('PI_SPECIFICATION_VERSION', '0x00000000')
                             # for PI specification < PI1.1, DXE_SMM_DRIVER also runs as BOOT time driver.
                             if int(PiSpecVersion, 16) < 0x0001000A:
                                 BtModuleList[Module.MetaFile] = ImageInfo
-- 
2.16.2.windows.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v1 6/9] BaseTools: refactor DepexSection.GenSection
  2018-04-13 20:51 [PATCH v1 0/9] BaseTools: refactoring Jaben Carsey
                   ` (4 preceding siblings ...)
  2018-04-13 20:51 ` [PATCH v1 5/9] BaseTools: use dictionary.get() when we have value if not found Jaben Carsey
@ 2018-04-13 20:51 ` Jaben Carsey
  2018-04-13 20:51 ` [PATCH v1 7/9] BaseTools: FdfParser refactor to remove a dictionary Jaben Carsey
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Jaben Carsey @ 2018-04-13 20:51 UTC (permalink / raw)
  To: edk2-devel; +Cc: Liming Gao, Yonghong Zhu

From: Jaben <jaben.carsey@intel.com>

change default parameter value to None since the parameter isn't used.
remove temporary dictionary and just do the reaplce call.

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/GenFds/DepexSection.py | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/BaseTools/Source/Python/GenFds/DepexSection.py b/BaseTools/Source/Python/GenFds/DepexSection.py
index ef30a2f083c6..4ed1aa779292 100644
--- a/BaseTools/Source/Python/GenFds/DepexSection.py
+++ b/BaseTools/Source/Python/GenFds/DepexSection.py
@@ -1,7 +1,7 @@
 ## @file
 # process depex section generation
 #
-#  Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
+#  Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
 #
 #  This program and the accompanying materials
 #  are licensed and made available under the terms and conditions of the BSD License
@@ -76,12 +76,10 @@ class DepexSection (DepexSectionClassObject):
     #   @param  Dict        dictionary contains macro and its value
     #   @retval tuple       (Generated file name list, section alignment)
     #
-    def GenSection(self, OutputPath, ModuleName, SecNum, keyStringList, FfsFile = None, Dict = {}, IsMakefile = False):
-        
+    def GenSection(self, OutputPath, ModuleName, SecNum, keyStringList, FfsFile = None, Dict = None, IsMakefile = False):
         if self.ExpressionProcessed == False:
             self.Expression = self.Expression.replace("\n", " ").replace("\r", " ")
             ExpList = self.Expression.split()
-            ExpGuidDict = {}
 
             for Exp in ExpList:
                 if Exp.upper() not in ('AND', 'OR', 'NOT', 'TRUE', 'FALSE', 'SOR', 'BEFORE', 'AFTER', 'END'):
@@ -90,10 +88,7 @@ class DepexSection (DepexSectionClassObject):
                         EdkLogger.error("GenFds", RESOURCE_NOT_AVAILABLE,
                                         "Depex GUID %s could not be found in build DB! (ModuleName: %s)" % (Exp, ModuleName))
 
-                    ExpGuidDict[Exp] = GuidStr
-
-            for Item in ExpGuidDict:
-                self.Expression = self.Expression.replace(Item, ExpGuidDict[Item])
+                    self.Expression = self.Expression.replace(Exp, GuidStr)
 
             self.Expression = self.Expression.strip()
             self.ExpressionProcessed = True
@@ -120,5 +115,4 @@ class DepexSection (DepexSectionClassObject):
         OutputFile = os.path.normpath(OutputFile)
 
         GenFdsGlobalVariable.GenerateSection(OutputFile, [InputFile], Section.Section.SectionType.get (SecType), IsMakefile=IsMakefile)
-        FileList = [OutputFile]
-        return FileList, self.Alignment
+        return [OutputFile], self.Alignment
-- 
2.16.2.windows.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v1 7/9] BaseTools: FdfParser refactor to remove a dictionary
  2018-04-13 20:51 [PATCH v1 0/9] BaseTools: refactoring Jaben Carsey
                   ` (5 preceding siblings ...)
  2018-04-13 20:51 ` [PATCH v1 6/9] BaseTools: refactor DepexSection.GenSection Jaben Carsey
@ 2018-04-13 20:51 ` Jaben Carsey
  2018-04-13 20:51 ` [PATCH v1 8/9] BaseTools: FdfParser - refactor functions to make static Jaben Carsey
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Jaben Carsey @ 2018-04-13 20:51 UTC (permalink / raw)
  To: edk2-devel; +Cc: Liming Gao, Yonghong Zhu

From: Jaben <jaben.carsey@intel.com>

__GetInfStatement() does not use the dict parameter, so remove it
from the API and from all callers.

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/GenFds/FdfParser.py | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/BaseTools/Source/Python/GenFds/FdfParser.py b/BaseTools/Source/Python/GenFds/FdfParser.py
index 0427b80b2460..662c232c86e4 100644
--- a/BaseTools/Source/Python/GenFds/FdfParser.py
+++ b/BaseTools/Source/Python/GenFds/FdfParser.py
@@ -2158,7 +2158,7 @@ class FdfParser:
         self.__GetAprioriSection(FvObj, FvObj.DefineVarDict.copy())
 
         while True:
-            isInf = self.__GetInfStatement(FvObj, MacroDict = FvObj.DefineVarDict.copy())
+            isInf = self.__GetInfStatement(FvObj)
             isFile = self.__GetFileStatement(FvObj, MacroDict = FvObj.DefineVarDict.copy())
             if not isInf and not isFile:
                 break
@@ -2423,7 +2423,7 @@ class FdfParser:
         MacroDict.update(AprSectionObj.DefineVarDict)
 
         while True:
-            IsInf = self.__GetInfStatement( AprSectionObj, MacroDict = MacroDict)
+            IsInf = self.__GetInfStatement(AprSectionObj)
             IsFile = self.__GetFileStatement( AprSectionObj)
             if not IsInf and not IsFile:
                 break
@@ -2486,11 +2486,10 @@ class FdfParser:
     #
     #   @param  self        The object pointer
     #   @param  Obj         for whom inf statement is got
-    #   @param  MacroDict   dictionary used to replace macro
     #   @retval True        Successfully find inf statement
     #   @retval False       Not able to find inf statement
     #
-    def __GetInfStatement(self, Obj, ForCapsule=False, MacroDict={}):
+    def __GetInfStatement(self, Obj, ForCapsule=False):
         ffsInf = self.__ParseInfStatement()
         if not ffsInf:
             return False
@@ -2926,7 +2925,7 @@ class FdfParser:
                 self.__GetAprioriSection(FvObj, MacroDict.copy())
 
                 while True:
-                    IsInf = self.__GetInfStatement(FvObj, MacroDict.copy())
+                    IsInf = self.__GetInfStatement(FvObj)
                     IsFile = self.__GetFileStatement(FvObj, MacroDict.copy())
                     if not IsInf and not IsFile:
                         break
-- 
2.16.2.windows.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v1 8/9] BaseTools: FdfParser - refactor functions to make static
  2018-04-13 20:51 [PATCH v1 0/9] BaseTools: refactoring Jaben Carsey
                   ` (6 preceding siblings ...)
  2018-04-13 20:51 ` [PATCH v1 7/9] BaseTools: FdfParser refactor to remove a dictionary Jaben Carsey
@ 2018-04-13 20:51 ` Jaben Carsey
  2018-04-13 20:51 ` [PATCH v1 9/9] BaseTools: FfsInfStatement - remove unused function Jaben Carsey
  2018-04-17 13:18 ` [PATCH v1 0/9] BaseTools: refactoring Zhu, Yonghong
  9 siblings, 0 replies; 11+ messages in thread
From: Jaben Carsey @ 2018-04-13 20:51 UTC (permalink / raw)
  To: edk2-devel; +Cc: Liming Gao, Yonghong Zhu

From: Jaben <jaben.carsey@intel.com>

make functions that doesn't use self into @staticmethod

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/GenFds/FdfParser.py       | 11 ++++++-----
 BaseTools/Source/Python/GenFds/FfsInfStatement.py | 10 +++++-----
 2 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/BaseTools/Source/Python/GenFds/FdfParser.py b/BaseTools/Source/Python/GenFds/FdfParser.py
index 662c232c86e4..dce41701a510 100644
--- a/BaseTools/Source/Python/GenFds/FdfParser.py
+++ b/BaseTools/Source/Python/GenFds/FdfParser.py
@@ -1131,7 +1131,8 @@ class FdfParser:
             self.__UndoToken()
             return False
 
-    def __Verify(self, Name, Value, Scope):
+    @staticmethod
+    def __Verify(Name, Value, Scope):
         if Scope in ['UINT64', 'UINT8']:
             ValueNumber = 0
             try:
@@ -3200,16 +3201,16 @@ class FdfParser:
                     raise Warning("expected value of %s" % Name, self.FileName, self.CurrentLineNumber)
                 Value = self.__Token
                 if Name == 'IMAGE_HEADER_INIT_VERSION':
-                    if self.__Verify(Name, Value, 'UINT8'):
+                    if FdfParser.__Verify(Name, Value, 'UINT8'):
                         FmpData.Version = Value
                 elif Name == 'IMAGE_INDEX':
-                    if self.__Verify(Name, Value, 'UINT8'):
+                    if FdfParser.__Verify(Name, Value, 'UINT8'):
                         FmpData.ImageIndex = Value
                 elif Name == 'HARDWARE_INSTANCE':
-                    if self.__Verify(Name, Value, 'UINT8'):
+                    if FdfParser.__Verify(Name, Value, 'UINT8'):
                         FmpData.HardwareInstance = Value
                 elif Name == 'MONOTONIC_COUNT':
-                    if self.__Verify(Name, Value, 'UINT64'):
+                    if FdfParser.__Verify(Name, Value, 'UINT64'):
                         FmpData.MonotonicCount = Value
                         if FmpData.MonotonicCount.upper().startswith('0X'):
                             FmpData.MonotonicCount = (long)(FmpData.MonotonicCount, 16)
diff --git a/BaseTools/Source/Python/GenFds/FfsInfStatement.py b/BaseTools/Source/Python/GenFds/FfsInfStatement.py
index 5364569b96d7..4f9936a97342 100644
--- a/BaseTools/Source/Python/GenFds/FfsInfStatement.py
+++ b/BaseTools/Source/Python/GenFds/FfsInfStatement.py
@@ -1011,7 +1011,7 @@ class FfsInfStatement(FfsInfStatementClassObject):
                         if VfrUniOffsetList:
                             UniVfrOffsetFileName = os.path.join(self.OutputPath, self.BaseName + '.offset')
                             UniVfrOffsetFileSection = os.path.join(self.OutputPath, self.BaseName + 'Offset' + '.raw')
-                            self.__GenUniVfrOffsetFile (VfrUniOffsetList, UniVfrOffsetFileName)
+                            FfsInfStatement.__GenUniVfrOffsetFile (VfrUniOffsetList, UniVfrOffsetFileName)
                             UniVfrOffsetFileNameList = []
                             UniVfrOffsetFileNameList.append(UniVfrOffsetFileName)
                             """Call GenSection"""
@@ -1069,11 +1069,11 @@ class FfsInfStatement(FfsInfStatementClassObject):
     #
     #   Create parameter string for GenFfs
     #
-    #   @param  self        The object pointer
     #   @param  Rule        The rule object used to generate section
     #   @retval tuple       (FileType, Fixed, CheckSum, Alignment)
     #
-    def __GetGenFfsCmdParameter__(self, Rule):
+    @staticmethod
+    def __GetGenFfsCmdParameter__(Rule):
         result = tuple()
         result += ('-t', Ffs.Ffs.FdfFvFileTypeToFileType[Rule.FvFileType])
         if Rule.Fixed != False:
@@ -1103,11 +1103,11 @@ class FfsInfStatement(FfsInfStatementClassObject):
     #
     #   Generate the offset file for the module which contain VFR or UNI file.
     #
-    #   @param  self                    The object pointer
     #   @param  VfrUniOffsetList        A list contain the VFR/UNI offsets in the EFI image file.
     #   @param  UniVfrOffsetFileName    The output offset file name.
     #
-    def __GenUniVfrOffsetFile(self, VfrUniOffsetList, UniVfrOffsetFileName):
+    @staticmethod
+    def __GenUniVfrOffsetFile(VfrUniOffsetList, UniVfrOffsetFileName):
 
         # Use a instance of StringIO to cache data
         fStringIO = StringIO.StringIO('')  
-- 
2.16.2.windows.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v1 9/9] BaseTools: FfsInfStatement - remove unused function
  2018-04-13 20:51 [PATCH v1 0/9] BaseTools: refactoring Jaben Carsey
                   ` (7 preceding siblings ...)
  2018-04-13 20:51 ` [PATCH v1 8/9] BaseTools: FdfParser - refactor functions to make static Jaben Carsey
@ 2018-04-13 20:51 ` Jaben Carsey
  2018-04-17 13:18 ` [PATCH v1 0/9] BaseTools: refactoring Zhu, Yonghong
  9 siblings, 0 replies; 11+ messages in thread
From: Jaben Carsey @ 2018-04-13 20:51 UTC (permalink / raw)
  To: edk2-devel; +Cc: Liming Gao, Yonghong Zhu

From: Jaben <jaben.carsey@intel.com>

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/GenFds/FfsInfStatement.py | 21 --------------------
 1 file changed, 21 deletions(-)

diff --git a/BaseTools/Source/Python/GenFds/FfsInfStatement.py b/BaseTools/Source/Python/GenFds/FfsInfStatement.py
index 4f9936a97342..8ae29b285d06 100644
--- a/BaseTools/Source/Python/GenFds/FfsInfStatement.py
+++ b/BaseTools/Source/Python/GenFds/FfsInfStatement.py
@@ -1065,27 +1065,6 @@ class FfsInfStatement(FfsInfStatementClassObject):
                                              )
         return FfsOutput
 
-    ## __GetGenFfsCmdParameter__() method
-    #
-    #   Create parameter string for GenFfs
-    #
-    #   @param  Rule        The rule object used to generate section
-    #   @retval tuple       (FileType, Fixed, CheckSum, Alignment)
-    #
-    @staticmethod
-    def __GetGenFfsCmdParameter__(Rule):
-        result = tuple()
-        result += ('-t', Ffs.Ffs.FdfFvFileTypeToFileType[Rule.FvFileType])
-        if Rule.Fixed != False:
-            result += ('-x',)
-        if Rule.CheckSum != False:
-            result += ('-s',)
-
-        if Rule.Alignment is not None and Rule.Alignment != '':
-            result += ('-a', Rule.Alignment)
-
-        return result
- 
     ## __GetBuildOutputMapFileVfrUniInfo() method
     #
     #   Find the offset of UNI/INF object offset in the EFI image file.
-- 
2.16.2.windows.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH v1 0/9] BaseTools: refactoring
  2018-04-13 20:51 [PATCH v1 0/9] BaseTools: refactoring Jaben Carsey
                   ` (8 preceding siblings ...)
  2018-04-13 20:51 ` [PATCH v1 9/9] BaseTools: FfsInfStatement - remove unused function Jaben Carsey
@ 2018-04-17 13:18 ` Zhu, Yonghong
  9 siblings, 0 replies; 11+ messages in thread
From: Zhu, Yonghong @ 2018-04-17 13:18 UTC (permalink / raw)
  To: Carsey, Jaben, edk2-devel@lists.01.org

Reviewed this series patch.
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com> 

Best Regards,
Zhu Yonghong


-----Original Message-----
From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Jaben Carsey
Sent: Saturday, April 14, 2018 4:51 AM
To: edk2-devel@lists.01.org
Subject: [edk2] [PATCH v1 0/9] BaseTools: refactoring

group of patches for refactoring BaseTools.  removing unused functions, variables, and parameters.  make functions statis where apropriate.

Jaben (9):
  BaseTools: remove unused local variable.
  BaseTools: change DscBuildData functions without need for self to
    staticmethod
  BaseTools: Remove unused functions from DscBuildData
  BaseTools: move RegEx compile out of loops
  BaseTools: use dictionary.get() when we have value if not found
  BaseTools: refactor DepexSection.GenSection
  BaseTools: FdfParser refactor to remove a dictionary
  BaseTools: FdfParser - refactor functions to make static
  BaseTools: FfsInfStatement - remove unused function

 BaseTools/Source/Python/GenFds/DepexSection.py    |  14 +-
 BaseTools/Source/Python/GenFds/FdfParser.py       |  20 +--
 BaseTools/Source/Python/GenFds/FfsInfStatement.py |  27 +---  BaseTools/Source/Python/Workspace/DscBuildData.py | 146 +++++++++-----------
 BaseTools/Source/Python/build/build.py            |   4 +-
 5 files changed, 87 insertions(+), 124 deletions(-)

--
2.16.2.windows.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2018-04-17 13:18 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-13 20:51 [PATCH v1 0/9] BaseTools: refactoring Jaben Carsey
2018-04-13 20:51 ` [PATCH v1 1/9] BaseTools: remove unused local variable Jaben Carsey
2018-04-13 20:51 ` [PATCH v1 2/9] BaseTools: change DscBuildData functions without need for self to staticmethod Jaben Carsey
2018-04-13 20:51 ` [PATCH v1 3/9] BaseTools: Remove unused functions from DscBuildData Jaben Carsey
2018-04-13 20:51 ` [PATCH v1 4/9] BaseTools: move RegEx compile out of loops Jaben Carsey
2018-04-13 20:51 ` [PATCH v1 5/9] BaseTools: use dictionary.get() when we have value if not found Jaben Carsey
2018-04-13 20:51 ` [PATCH v1 6/9] BaseTools: refactor DepexSection.GenSection Jaben Carsey
2018-04-13 20:51 ` [PATCH v1 7/9] BaseTools: FdfParser refactor to remove a dictionary Jaben Carsey
2018-04-13 20:51 ` [PATCH v1 8/9] BaseTools: FdfParser - refactor functions to make static Jaben Carsey
2018-04-13 20:51 ` [PATCH v1 9/9] BaseTools: FfsInfStatement - remove unused function Jaben Carsey
2018-04-17 13:18 ` [PATCH v1 0/9] BaseTools: refactoring Zhu, Yonghong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox