BaseTools/GenFds: cleanup GenFds
1) remove wildcard imports and use explicit imports 2) refactor to use shared variables from Common/DataType 3) rename to not shadow imports 4) don't assign a variable in a loop (just do final assignment) 5) remove spaces, parens, unused or commented out code, etc. 6) merge unnecessary parent classes into child 7) refactor to share DXE and PEI apriori GUIDs from one place this includes changes to Build and EOT files 8) for PEP8, dont use __ for custom methods. Cc: Yonghong Zhu <yonghong.zhu@intel.com> Cc: Liming Gao <liming.gao@intel.com> Cc: Bob C Feng <bob.c.feng@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jaben Carsey <jaben.carsey@intel.com> Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
This commit is contained in:
committed by
Yonghong Zhu
parent
0019375fbc
commit
9e47e6f908
@ -16,26 +16,22 @@
|
||||
# Import Modules
|
||||
#
|
||||
from __future__ import absolute_import
|
||||
from . import Ffs
|
||||
from . import Rule
|
||||
import Common.LongFilePathOs as os
|
||||
from io import BytesIO
|
||||
import subprocess
|
||||
|
||||
from .GenFdsGlobalVariable import GenFdsGlobalVariable
|
||||
from struct import pack
|
||||
from CommonDataClass.FdfClass import FileStatementClassObject
|
||||
from Common import EdkLogger
|
||||
from Common.BuildToolError import *
|
||||
from Common.Misc import GuidStructureByteArrayToGuidString
|
||||
from Common.BuildToolError import GENFDS_ERROR
|
||||
from Common.Misc import GuidStructureByteArrayToGuidString, SaveFileOnChange
|
||||
import Common.LongFilePathOs as os
|
||||
from .GuidSection import GuidSection
|
||||
from .FvImageSection import FvImageSection
|
||||
from Common.Misc import SaveFileOnChange
|
||||
from struct import *
|
||||
from .Ffs import FdfFvFileTypeToFileType
|
||||
from .GenFdsGlobalVariable import GenFdsGlobalVariable
|
||||
|
||||
## generate FFS from FILE
|
||||
#
|
||||
#
|
||||
class FileStatement (FileStatementClassObject) :
|
||||
class FileStatement (FileStatementClassObject):
|
||||
## The constructor
|
||||
#
|
||||
# @param self The object pointer
|
||||
@ -60,7 +56,7 @@ class FileStatement (FileStatementClassObject) :
|
||||
#
|
||||
def GenFfs(self, Dict = {}, FvChildAddr=[], FvParentAddr=None, IsMakefile=False, FvName=None):
|
||||
|
||||
if self.NameGuid is not None and self.NameGuid.startswith('PCD('):
|
||||
if self.NameGuid and self.NameGuid.startswith('PCD('):
|
||||
PcdValue = GenFdsGlobalVariable.GetPcdValue(self.NameGuid)
|
||||
if len(PcdValue) == 0:
|
||||
EdkLogger.error("GenFds", GENFDS_ERROR, '%s NOT defined.' \
|
||||
@ -82,7 +78,7 @@ class FileStatement (FileStatementClassObject) :
|
||||
|
||||
Dict.update(self.DefineVarDict)
|
||||
SectionAlignments = None
|
||||
if self.FvName is not None :
|
||||
if self.FvName:
|
||||
Buffer = BytesIO('')
|
||||
if self.FvName.upper() not in GenFdsGlobalVariable.FdfParser.Profile.FvDict:
|
||||
EdkLogger.error("GenFds", GENFDS_ERROR, "FV (%s) is NOT described in FDF file!" % (self.FvName))
|
||||
@ -90,14 +86,14 @@ class FileStatement (FileStatementClassObject) :
|
||||
FileName = Fv.AddToBuffer(Buffer)
|
||||
SectionFiles = [FileName]
|
||||
|
||||
elif self.FdName is not None:
|
||||
elif self.FdName:
|
||||
if self.FdName.upper() not in GenFdsGlobalVariable.FdfParser.Profile.FdDict:
|
||||
EdkLogger.error("GenFds", GENFDS_ERROR, "FD (%s) is NOT described in FDF file!" % (self.FdName))
|
||||
Fd = GenFdsGlobalVariable.FdfParser.Profile.FdDict.get(self.FdName.upper())
|
||||
FileName = Fd.GenFd()
|
||||
SectionFiles = [FileName]
|
||||
|
||||
elif self.FileName is not None:
|
||||
elif self.FileName:
|
||||
if hasattr(self, 'FvFileType') and self.FvFileType == 'RAW':
|
||||
if isinstance(self.FileName, list) and isinstance(self.SubAlignment, list) and len(self.FileName) == len(self.SubAlignment):
|
||||
FileContent = ''
|
||||
@ -111,7 +107,7 @@ class FileStatement (FileStatementClassObject) :
|
||||
Content = f.read()
|
||||
f.close()
|
||||
AlignValue = 1
|
||||
if self.SubAlignment[Index] is not None:
|
||||
if self.SubAlignment[Index]:
|
||||
AlignValue = GenFdsGlobalVariable.GetAlignment(self.SubAlignment[Index])
|
||||
if AlignValue > MaxAlignValue:
|
||||
MaxAlignIndex = Index
|
||||
@ -143,7 +139,7 @@ class FileStatement (FileStatementClassObject) :
|
||||
SectionFiles = []
|
||||
Index = 0
|
||||
SectionAlignments = []
|
||||
for section in self.SectionList :
|
||||
for section in self.SectionList:
|
||||
Index = Index + 1
|
||||
SecIndex = '%d' %Index
|
||||
# process the inside FvImage from FvSection or GuidSection
|
||||
@ -152,7 +148,7 @@ class FileStatement (FileStatementClassObject) :
|
||||
section.FvAddr = FvChildAddr.pop(0)
|
||||
elif isinstance(section, GuidSection):
|
||||
section.FvAddr = FvChildAddr
|
||||
if FvParentAddr is not None and isinstance(section, GuidSection):
|
||||
if FvParentAddr and isinstance(section, GuidSection):
|
||||
section.FvParentAddr = FvParentAddr
|
||||
|
||||
if self.KeepReloc == False:
|
||||
@ -168,7 +164,7 @@ class FileStatement (FileStatementClassObject) :
|
||||
#
|
||||
FfsFileOutput = os.path.join(OutputDir, self.NameGuid + '.ffs')
|
||||
GenFdsGlobalVariable.GenerateFfs(FfsFileOutput, SectionFiles,
|
||||
Ffs.Ffs.FdfFvFileTypeToFileType.get(self.FvFileType),
|
||||
FdfFvFileTypeToFileType.get(self.FvFileType),
|
||||
self.NameGuid,
|
||||
Fixed=self.Fixed,
|
||||
CheckSum=self.CheckSum,
|
||||
@ -177,6 +173,3 @@ class FileStatement (FileStatementClassObject) :
|
||||
)
|
||||
|
||||
return FfsFileOutput
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user