From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.100; helo=mga07.intel.com; envelope-from=jaben.carsey@intel.com; receiver=edk2-devel@lists.01.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (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 3B66520969677 for ; Mon, 14 May 2018 11:09:25 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 May 2018 11:09:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,401,1520924400"; d="scan'208";a="55814271" Received: from jcarsey-desk1.amr.corp.intel.com ([10.7.159.144]) by orsmga001.jf.intel.com with ESMTP; 14 May 2018 11:09:23 -0700 From: Jaben Carsey To: edk2-devel@lists.01.org Cc: Liming Gao , Yonghong Zhu Date: Mon, 14 May 2018 11:09:15 -0700 Message-Id: <10fc6ddcc1a79a8cd26c26871c9b52cbea15c1b3.1526321052.git.jaben.carsey@intel.com> X-Mailer: git-send-email 2.16.2.windows.1 In-Reply-To: References: In-Reply-To: References: Subject: [PATCH v1 06/11] BaseTools: refactor section generation X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 May 2018 18:09:25 -0000 use with for opening files remove unneeded variables dont seek to 0 for just opened file Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jaben Carsey --- BaseTools/Source/Python/Common/DataType.py | 1 + BaseTools/Source/Python/GenFds/CompressSection.py | 18 +- BaseTools/Source/Python/GenFds/DataSection.py | 28 +-- BaseTools/Source/Python/GenFds/DepexSection.py | 2 +- BaseTools/Source/Python/GenFds/EfiSection.py | 109 +++++---- BaseTools/Source/Python/GenFds/FfsInfStatement.py | 10 +- BaseTools/Source/Python/GenFds/FvImageSection.py | 28 +-- BaseTools/Source/Python/GenFds/GuidSection.py | 8 +- BaseTools/Source/Python/GenFds/OptRomInfStatement.py | 4 +- BaseTools/Source/Python/GenFds/Section.py | 231 ++++++++------------ BaseTools/Source/Python/GenFds/UiSection.py | 18 +- BaseTools/Source/Python/GenFds/VerSection.py | 22 +- 12 files changed, 206 insertions(+), 273 deletions(-) diff --git a/BaseTools/Source/Python/Common/DataType.py b/BaseTools/Source/Python/Common/DataType.py index a72c7e6f067f..93136dff0db2 100644 --- a/BaseTools/Source/Python/Common/DataType.py +++ b/BaseTools/Source/Python/Common/DataType.py @@ -50,6 +50,7 @@ TAB_EDK_SOURCE = '$(EDK_SOURCE)' TAB_EFI_SOURCE = '$(EFI_SOURCE)' TAB_WORKSPACE = '$(WORKSPACE)' TAB_FV_DIRECTORY = 'FV' +TAB_SEC_DIRECTORY = 'SEC' TAB_ARCH_NULL = '' TAB_ARCH_COMMON = 'COMMON' diff --git a/BaseTools/Source/Python/GenFds/CompressSection.py b/BaseTools/Source/Python/GenFds/CompressSection.py index cdae74c52fd9..b7aa72e43992 100644 --- a/BaseTools/Source/Python/GenFds/CompressSection.py +++ b/BaseTools/Source/Python/GenFds/CompressSection.py @@ -56,7 +56,7 @@ class CompressSection (CompressSectionClassObject) : # def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = {}, IsMakefile = False): - if FfsInf is not None: + if FfsInf: self.CompType = FfsInf.__ExtendMacro__(self.CompType) self.Alignment = FfsInf.__ExtendMacro__(self.Alignment) @@ -68,13 +68,13 @@ class CompressSection (CompressSectionClassObject) : Index = Index + 1 SecIndex = '%s.%d' %(SecNum, Index) ReturnSectList, AlignValue = Sect.GenSection(OutputPath, ModuleName, SecIndex, KeyStringList, FfsInf, Dict, IsMakefile=IsMakefile) - if AlignValue is not None: - if MaxAlign is None: + if AlignValue: + if not MaxAlign: MaxAlign = AlignValue if GenFdsGlobalVariable.GetAlignment (AlignValue) > GenFdsGlobalVariable.GetAlignment (MaxAlign): MaxAlign = AlignValue if ReturnSectList != []: - if AlignValue is None: + if not AlignValue: AlignValue = "1" for FileData in ReturnSectList: SectFiles += (FileData,) @@ -83,17 +83,13 @@ class CompressSection (CompressSectionClassObject) : OutputFile = OutputPath + \ os.sep + \ ModuleName + \ - SUP_MODULE_SEC + \ + SUP_MODULE_SEC + \ SecNum + \ SectionSuffix['COMPRESS'] OutputFile = os.path.normpath(OutputFile) DummyFile = OutputFile + '.dummy' GenFdsGlobalVariable.GenerateSection(DummyFile, SectFiles, InputAlign=SectAlign, IsMakefile=IsMakefile) - GenFdsGlobalVariable.GenerateSection(OutputFile, [DummyFile], Section.Section.SectionType['COMPRESS'], + GenFdsGlobalVariable.GenerateSection(OutputFile, [DummyFile], Section.SectionType['COMPRESS'], CompressionType=self.CompTypeDict[self.CompType], IsMakefile=IsMakefile) - OutputFileList = [] - OutputFileList.append(OutputFile) - return OutputFileList, self.Alignment - - + return [OutputFile], self.Alignment diff --git a/BaseTools/Source/Python/GenFds/DataSection.py b/BaseTools/Source/Python/GenFds/DataSection.py index f0e5efab4178..71c2796b0b39 100644 --- a/BaseTools/Source/Python/GenFds/DataSection.py +++ b/BaseTools/Source/Python/GenFds/DataSection.py @@ -50,39 +50,39 @@ class DataSection (DataSectionClassObject): # @retval tuple (Generated file name list, section alignment) # def GenSection(self, OutputPath, ModuleName, SecNum, keyStringList, FfsFile = None, Dict = {}, IsMakefile = False): + + self.SectFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.SectFileName) # # Prepare the parameter of GenSection # - if FfsFile is not None: - self.SectFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.SectFileName) + if FfsFile: self.SectFileName = GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict, FfsFile.CurrentArch) else: - self.SectFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.SectFileName) self.SectFileName = GenFdsGlobalVariable.MacroExtend(self.SectFileName, Dict) - """Check Section file exist or not !""" - + # + # Check Section file exist or not + # if not os.path.exists(self.SectFileName): self.SectFileName = os.path.join (GenFdsGlobalVariable.WorkSpaceDir, self.SectFileName) - """Copy Map file to Ffs output""" + # + # Copy Map file to Ffs output + # Filename = GenFdsGlobalVariable.MacroExtend(self.SectFileName) - if Filename[(len(Filename)-4):] == '.efi': + if Filename.endswith('.efi'): MapFile = Filename.replace('.efi', '.map') CopyMapFile = os.path.join(OutputPath, ModuleName + '.map') if IsMakefile: - if GenFdsGlobalVariable.CopyList == []: - GenFdsGlobalVariable.CopyList = [(MapFile, CopyMapFile)] - else: - GenFdsGlobalVariable.CopyList.append((MapFile, CopyMapFile)) + GenFdsGlobalVariable.CopyList.append((MapFile, CopyMapFile)) else: if os.path.exists(MapFile): if not os.path.exists(CopyMapFile) or (os.path.getmtime(MapFile) > os.path.getmtime(CopyMapFile)): CopyLongFilePath(MapFile, CopyMapFile) #Get PE Section alignment when align is set to AUTO - if self.Alignment == 'Auto' and self.SecType in (BINARY_FILE_TYPE_TE, BINARY_FILE_TYPE_PE32): + if self.Alignment == 'Auto' and self.SecType in {BINARY_FILE_TYPE_TE, BINARY_FILE_TYPE_PE32}: ImageObj = PeImageClass (Filename) if ImageObj.SectionAlignment < 0x400: self.Alignment = str (ImageObj.SectionAlignment) @@ -120,8 +120,8 @@ class DataSection (DataSectionClassObject): ) self.SectFileName = TeFile - OutputFile = os.path.join (OutputPath, ModuleName + 'SEC' + SecNum + SectionSuffix.get(self.SecType)) + OutputFile = os.path.join (OutputPath, ModuleName + TAB_SEC_DIRECTORY + SecNum + SectionSuffix.get(self.SecType)) OutputFile = os.path.normpath(OutputFile) - GenFdsGlobalVariable.GenerateSection(OutputFile, [self.SectFileName], Section.Section.SectionType.get(self.SecType), IsMakefile = IsMakefile) + GenFdsGlobalVariable.GenerateSection(OutputFile, [self.SectFileName], Section.SectionType.get(self.SecType), IsMakefile = IsMakefile) FileList = [OutputFile] return FileList, self.Alignment diff --git a/BaseTools/Source/Python/GenFds/DepexSection.py b/BaseTools/Source/Python/GenFds/DepexSection.py index 6e63cb97e51d..4392b9c62409 100644 --- a/BaseTools/Source/Python/GenFds/DepexSection.py +++ b/BaseTools/Source/Python/GenFds/DepexSection.py @@ -114,5 +114,5 @@ class DepexSection (DepexSectionClassObject): OutputFile = os.path.join (OutputPath, ModuleName + SUP_MODULE_SEC + SecNum + '.dpx') OutputFile = os.path.normpath(OutputFile) - GenFdsGlobalVariable.GenerateSection(OutputFile, [InputFile], Section.Section.SectionType.get (SecType), IsMakefile=IsMakefile) + GenFdsGlobalVariable.GenerateSection(OutputFile, [InputFile], Section.SectionType.get (SecType), IsMakefile=IsMakefile) return [OutputFile], self.Alignment diff --git a/BaseTools/Source/Python/GenFds/EfiSection.py b/BaseTools/Source/Python/GenFds/EfiSection.py index 0064196a5a4e..5e8379548d27 100644 --- a/BaseTools/Source/Python/GenFds/EfiSection.py +++ b/BaseTools/Source/Python/GenFds/EfiSection.py @@ -58,8 +58,11 @@ class EfiSection (EfiSectionClassObject): if self.FileName is not None and self.FileName.startswith('PCD('): self.FileName = GenFdsGlobalVariable.GetPcdValue(self.FileName) - """Prepare the parameter of GenSection""" - if FfsInf is not None : + + # + # Prepare the parameter of GenSection + # + if FfsInf: InfFileName = FfsInf.InfFileName SectionType = FfsInf.__ExtendMacro__(self.SectionType) Filename = FfsInf.__ExtendMacro__(self.FileName) @@ -67,21 +70,23 @@ class EfiSection (EfiSectionClassObject): StringData = FfsInf.__ExtendMacro__(self.StringData) ModuleNameStr = FfsInf.__ExtendMacro__('$(MODULE_NAME)') NoStrip = True - if FfsInf.ModuleType in (SUP_MODULE_SEC, SUP_MODULE_PEI_CORE, SUP_MODULE_PEIM) and SectionType in (BINARY_FILE_TYPE_TE, BINARY_FILE_TYPE_PE32): - if FfsInf.KeepReloc is not None: + if FfsInf.ModuleType in {SUP_MODULE_SEC, SUP_MODULE_PEI_CORE, SUP_MODULE_PEIM} and SectionType in {BINARY_FILE_TYPE_TE, BINARY_FILE_TYPE_PE32}: + if FfsInf.KeepReloc: NoStrip = FfsInf.KeepReloc - elif FfsInf.KeepRelocFromRule is not None: + elif FfsInf.KeepRelocFromRule: NoStrip = FfsInf.KeepRelocFromRule - elif self.KeepReloc is not None: + elif self.KeepReloc: NoStrip = self.KeepReloc - elif FfsInf.ShadowFromInfFile is not None: + elif FfsInf.ShadowFromInfFile: NoStrip = FfsInf.ShadowFromInfFile else: EdkLogger.error("GenFds", GENFDS_ERROR, "Module %s apply rule for None!" %ModuleName) - """If the file name was pointed out, add it in FileList""" + # + # If the file name was pointed out, add it in FileList + # FileList = [] - if Filename is not None: + if Filename: Filename = GenFdsGlobalVariable.MacroExtend(Filename, Dict) # check if the path is absolute or relative if os.path.isabs(Filename): @@ -98,34 +103,26 @@ class EfiSection (EfiSectionClassObject): if '.depex' in SuffixMap: FileList.append(Filename) else: - FileList, IsSect = Section.Section.GetFileList(FfsInf, self.FileType, self.FileExtension, Dict, IsMakefile=IsMakefile) + FileList, IsSect = Section.GetSectionFileList(FfsInf, self.FileType, self.FileExtension, Dict, IsMakefile=IsMakefile) if IsSect : return FileList, self.Alignment Index = 0 Align = self.Alignment - """ If Section type is 'VERSION'""" + # + # If Section type is 'VERSION' + # OutputFileList = [] if SectionType == 'VERSION': - InfOverrideVerString = False - if FfsInf.Version is not None: - #StringData = FfsInf.Version + if FfsInf.Version: BuildNum = FfsInf.Version InfOverrideVerString = True if InfOverrideVerString: - #VerTuple = ('-n', '"' + StringData + '"') - if BuildNum is not None and BuildNum != '': - BuildNumTuple = ('-j', BuildNum) - else: - BuildNumTuple = tuple() - - Num = SecNum - OutputFile = os.path.join( OutputPath, ModuleName + 'SEC' + str(Num) + SectionSuffix.get(SectionType)) + OutputFile = os.path.join( OutputPath, ModuleName + TAB_SEC_DIRECTORY + str(SecNum) + SectionSuffix.get(SectionType)) GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_VERSION', - #Ui=StringData, Ver=BuildNum, IsMakefile=IsMakefile) OutputFileList.append(OutputFile) @@ -134,38 +131,31 @@ class EfiSection (EfiSectionClassObject): for File in FileList: Index = Index + 1 Num = '%s.%d' %(SecNum , Index) - OutputFile = os.path.join(OutputPath, ModuleName + 'SEC' + Num + SectionSuffix.get(SectionType)) - f = open(File, 'r') - VerString = f.read() - f.close() + OutputFile = os.path.join(OutputPath, ModuleName + TAB_SEC_DIRECTORY + Num + SectionSuffix.get(SectionType)) + with open(File, 'r') as f: + VerString = f.read() BuildNum = VerString - if BuildNum is not None and BuildNum != '': - BuildNumTuple = ('-j', BuildNum) GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_VERSION', - #Ui=VerString, Ver=BuildNum, IsMakefile=IsMakefile) OutputFileList.append(OutputFile) else: BuildNum = StringData - if BuildNum is not None and BuildNum != '': + if BuildNum: BuildNumTuple = ('-j', BuildNum) else: BuildNumTuple = tuple() BuildNumString = ' ' + ' '.join(BuildNumTuple) - #if VerString == '' and if BuildNumString == '': if self.Optional == True : GenFdsGlobalVariable.VerboseLogger( "Optional Section don't exist!") return [], None else: EdkLogger.error("GenFds", GENFDS_ERROR, "File: %s miss Version Section value" %InfFileName) - Num = SecNum - OutputFile = os.path.join( OutputPath, ModuleName + 'SEC' + str(Num) + SectionSuffix.get(SectionType)) + OutputFile = os.path.join( OutputPath, ModuleName + TAB_SEC_DIRECTORY + str(SecNum) + SectionSuffix.get(SectionType)) GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_VERSION', - #Ui=VerString, Ver=BuildNum, IsMakefile=IsMakefile) OutputFileList.append(OutputFile) @@ -176,15 +166,14 @@ class EfiSection (EfiSectionClassObject): elif SectionType == BINARY_FILE_TYPE_UI: InfOverrideUiString = False - if FfsInf.Ui is not None: + if FfsInf.Ui: StringData = FfsInf.Ui InfOverrideUiString = True if InfOverrideUiString: - Num = SecNum if IsMakefile and StringData == ModuleNameStr: StringData = "$(MODULE_NAME)" - OutputFile = os.path.join( OutputPath, ModuleName + 'SEC' + str(Num) + SectionSuffix.get(SectionType)) + OutputFile = os.path.join( OutputPath, ModuleName + TAB_SEC_DIRECTORY + str(SecNum) + SectionSuffix.get(SectionType)) GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_USER_INTERFACE', Ui=StringData, IsMakefile=IsMakefile) OutputFileList.append(OutputFile) @@ -193,38 +182,34 @@ class EfiSection (EfiSectionClassObject): for File in FileList: Index = Index + 1 Num = '%s.%d' %(SecNum , Index) - OutputFile = os.path.join(OutputPath, ModuleName + 'SEC' + Num + SectionSuffix.get(SectionType)) - f = open(File, 'r') - UiString = f.read() - f.close() + OutputFile = os.path.join(OutputPath, ModuleName + TAB_SEC_DIRECTORY + Num + SectionSuffix.get(SectionType)) + with open(File, 'r') as f: + UiString = f.read() if IsMakefile and UiString == ModuleNameStr: UiString = "$(MODULE_NAME)" GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_USER_INTERFACE', Ui=UiString, IsMakefile=IsMakefile) OutputFileList.append(OutputFile) else: - if StringData is not None and len(StringData) > 0: - UiTuple = ('-n', '"' + StringData + '"') - else: - UiTuple = tuple() - + if not StringData: if self.Optional == True : GenFdsGlobalVariable.VerboseLogger( "Optional Section don't exist!") return '', None else: EdkLogger.error("GenFds", GENFDS_ERROR, "File: %s miss UI Section value" %InfFileName) - Num = SecNum if IsMakefile and StringData == ModuleNameStr: StringData = "$(MODULE_NAME)" - OutputFile = os.path.join( OutputPath, ModuleName + 'SEC' + str(Num) + SectionSuffix.get(SectionType)) + OutputFile = os.path.join( OutputPath, ModuleName + TAB_SEC_DIRECTORY + str(SecNum) + SectionSuffix.get(SectionType)) GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_USER_INTERFACE', Ui=StringData, IsMakefile=IsMakefile) OutputFileList.append(OutputFile) else: - """If File List is empty""" + # + # If File List is empty + # if FileList == [] : if self.Optional == True: GenFdsGlobalVariable.VerboseLogger("Optional Section don't exist!") @@ -233,16 +218,20 @@ class EfiSection (EfiSectionClassObject): EdkLogger.error("GenFds", GENFDS_ERROR, "Output file for %s section could not be found for %s" % (SectionType, InfFileName)) else: - """Convert the File to Section file one by one """ + # + # Convert the File to Section file one by one + # for File in FileList: - """ Copy Map file to FFS output path """ + # + # Copy Map file to FFS output path + # Index = Index + 1 Num = '%s.%d' %(SecNum , Index) - OutputFile = os.path.join( OutputPath, ModuleName + 'SEC' + Num + SectionSuffix.get(SectionType)) + OutputFile = os.path.join( OutputPath, ModuleName + TAB_SEC_DIRECTORY + Num + SectionSuffix.get(SectionType)) File = GenFdsGlobalVariable.MacroExtend(File, Dict) #Get PE Section alignment when align is set to AUTO - if self.Alignment == 'Auto' and (SectionType == BINARY_FILE_TYPE_PE32 or SectionType == BINARY_FILE_TYPE_TE): + if self.Alignment == 'Auto' and SectionType in {BINARY_FILE_TYPE_PE32, BINARY_FILE_TYPE_TE}: ImageObj = PeImageClass (File) if ImageObj.SectionAlignment < 0x400: Align = str (ImageObj.SectionAlignment) @@ -251,7 +240,7 @@ class EfiSection (EfiSectionClassObject): else: Align = str (ImageObj.SectionAlignment / 0x100000) + 'M' - if File[(len(File)-4):] == '.efi': + if File.endswith('.efi'): MapFile = File.replace('.efi', '.map') CopyMapFile = os.path.join(OutputPath, ModuleName + '.map') if IsMakefile: @@ -285,7 +274,9 @@ class EfiSection (EfiSectionClassObject): ) File = StrippedFile - """For TE Section call GenFw to generate TE image""" + # + # For TE Section call GenFw to generate TE image + # if SectionType == BINARY_FILE_TYPE_TE: TeFile = os.path.join( OutputPath, ModuleName + 'Te.raw') @@ -297,10 +288,12 @@ class EfiSection (EfiSectionClassObject): ) File = TeFile - """Call GenSection""" + # + # Call GenSection + # GenFdsGlobalVariable.GenerateSection(OutputFile, [File], - Section.Section.SectionType.get (SectionType), + Section.SectionType.get (SectionType), IsMakefile=IsMakefile ) OutputFileList.append(OutputFile) diff --git a/BaseTools/Source/Python/GenFds/FfsInfStatement.py b/BaseTools/Source/Python/GenFds/FfsInfStatement.py index f76563d736f6..39426b939b4a 100644 --- a/BaseTools/Source/Python/GenFds/FfsInfStatement.py +++ b/BaseTools/Source/Python/GenFds/FfsInfStatement.py @@ -731,7 +731,7 @@ class FfsInfStatement(FfsInfStatementClassObject): else: GenSecInputFile = os.path.normpath(os.path.join(self.EfiOutputPath, GenSecInputFile)) else: - FileList, IsSect = Section.Section.GetFileList(self, '', Rule.FileExtension) + FileList, IsSect = Section.GetSectionFileList(self, '', Rule.FileExtension) Index = 1 SectionType = Rule.SectionType @@ -761,7 +761,7 @@ class FfsInfStatement(FfsInfStatementClassObject): SecNum = '%d' %Index GenSecOutputFile= self.__ExtendMacro__(Rule.NameGuid) + \ - SectionSuffix[SectionType] + 'SEC' + SecNum + SectionSuffix[SectionType] + TAB_SEC_DIRECTORY + SecNum Index = Index + 1 OutputFile = os.path.join(self.OutputPath, GenSecOutputFile) File = GenFdsGlobalVariable.MacroExtend(File, Dict, self.CurrentArch) @@ -799,12 +799,12 @@ class FfsInfStatement(FfsInfStatementClassObject): IsMakefile=IsMakefile ) File = TeFile - GenFdsGlobalVariable.GenerateSection(OutputFile, [File], Section.Section.SectionType[SectionType], IsMakefile=IsMakefile) + GenFdsGlobalVariable.GenerateSection(OutputFile, [File], Section.SectionType[SectionType], IsMakefile=IsMakefile) OutputFileList.append(OutputFile) else: SecNum = '%d' %Index GenSecOutputFile= self.__ExtendMacro__(Rule.NameGuid) + \ - SectionSuffix[SectionType] + 'SEC' + SecNum + SectionSuffix[SectionType] + TAB_SEC_DIRECTORY + SecNum OutputFile = os.path.join(self.OutputPath, GenSecOutputFile) GenSecInputFile = GenFdsGlobalVariable.MacroExtend(GenSecInputFile, Dict, self.CurrentArch) @@ -842,7 +842,7 @@ class FfsInfStatement(FfsInfStatementClassObject): IsMakefile=IsMakefile ) GenSecInputFile = TeFile - GenFdsGlobalVariable.GenerateSection(OutputFile, [GenSecInputFile], Section.Section.SectionType[SectionType], IsMakefile=IsMakefile) + GenFdsGlobalVariable.GenerateSection(OutputFile, [GenSecInputFile], Section.SectionType[SectionType], IsMakefile=IsMakefile) OutputFileList.append(OutputFile) return OutputFileList diff --git a/BaseTools/Source/Python/GenFds/FvImageSection.py b/BaseTools/Source/Python/GenFds/FvImageSection.py index 380fbe56f1c4..dc5dcb7f8e0d 100644 --- a/BaseTools/Source/Python/GenFds/FvImageSection.py +++ b/BaseTools/Source/Python/GenFds/FvImageSection.py @@ -54,28 +54,24 @@ class FvImageSection(FvImageSectionClassObject): def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = {}, IsMakefile = False): OutputFileList = [] - if self.FvFileType is not None: - FileList, IsSect = Section.Section.GetFileList(FfsInf, self.FvFileType, self.FvFileExtension) + if self.FvFileType: + FileList, IsSect = Section.GetSectionFileList(FfsInf, self.FvFileType, self.FvFileExtension) if IsSect : return FileList, self.Alignment - Num = SecNum - MaxFvAlignment = 0 for FvFileName in FileList: FvAlignmentValue = 0 if os.path.isfile(FvFileName): - FvFileObj = open (FvFileName,'rb') - FvFileObj.seek(0) + with open (FvFileName,'rb') as FvFileObj: # PI FvHeader is 0x48 byte FvHeaderBuffer = FvFileObj.read(0x48) # FV alignment position. FvAlignmentValue = 1 << (ord (FvHeaderBuffer[0x2E]) & 0x1F) - FvFileObj.close() if FvAlignmentValue > MaxFvAlignment: MaxFvAlignment = FvAlignmentValue - OutputFile = os.path.join(OutputPath, ModuleName + 'SEC' + Num + SectionSuffix["FV_IMAGE"]) + OutputFile = os.path.join(OutputPath, ModuleName + TAB_SEC_DIRECTORY + SecNum + SectionSuffix["FV_IMAGE"]) GenFdsGlobalVariable.GenerateSection(OutputFile, [FvFileName], 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE', IsMakefile=IsMakefile) OutputFileList.append(OutputFile) @@ -97,24 +93,23 @@ class FvImageSection(FvImageSectionClassObject): # # Generate Fv # - if self.FvName is not None: + if self.FvName: Buffer = StringIO.StringIO('') Fv = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(self.FvName) - if Fv is not None: + if Fv: self.Fv = Fv FvFileName = Fv.AddToBuffer(Buffer, self.FvAddr, MacroDict = Dict, Flag=IsMakefile) - if Fv.FvAlignment is not None: - if self.Alignment is None: + if Fv.FvAlignment: + if not self.Alignment: self.Alignment = Fv.FvAlignment else: if GenFdsGlobalVariable.GetAlignment (Fv.FvAlignment) > GenFdsGlobalVariable.GetAlignment (self.Alignment): self.Alignment = Fv.FvAlignment else: - if self.FvFileName is not None: + if self.FvFileName: FvFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FvFileName) if os.path.isfile(FvFileName): - FvFileObj = open (FvFileName,'rb') - FvFileObj.seek(0) + with open (FvFileName,'rb') as FvFileObj: # PI FvHeader is 0x48 byte FvHeaderBuffer = FvFileObj.read(0x48) # FV alignment position. @@ -132,14 +127,13 @@ class FvImageSection(FvImageSectionClassObject): else: # FvAlignmentValue is less than 1K self.Alignment = str (FvAlignmentValue) - FvFileObj.close() else: EdkLogger.error("GenFds", GENFDS_ERROR, "FvImageSection Failed! %s NOT found in FDF" % self.FvName) # # Prepare the parameter of GenSection # - OutputFile = os.path.join(OutputPath, ModuleName + 'SEC' + SecNum + SectionSuffix["FV_IMAGE"]) + OutputFile = os.path.join(OutputPath, ModuleName + TAB_SEC_DIRECTORY + SecNum + SectionSuffix["FV_IMAGE"]) GenFdsGlobalVariable.GenerateSection(OutputFile, [FvFileName], 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE', IsMakefile=IsMakefile) OutputFileList.append(OutputFile) diff --git a/BaseTools/Source/Python/GenFds/GuidSection.py b/BaseTools/Source/Python/GenFds/GuidSection.py index 104650d16781..bc95c7cd9d42 100644 --- a/BaseTools/Source/Python/GenFds/GuidSection.py +++ b/BaseTools/Source/Python/GenFds/GuidSection.py @@ -139,7 +139,7 @@ class GuidSection(GuidSectionClassObject) : # if self.NameGuid is None : GenFdsGlobalVariable.VerboseLogger("Use GenSection function Generate CRC32 Section") - GenFdsGlobalVariable.GenerateSection(OutputFile, SectFile, Section.Section.SectionType[self.SectionType], InputAlign=SectAlign, IsMakefile=IsMakefile) + GenFdsGlobalVariable.GenerateSection(OutputFile, SectFile, Section.SectionType[self.SectionType], InputAlign=SectAlign, IsMakefile=IsMakefile) OutputFileList = [] OutputFileList.append(OutputFile) return OutputFileList, self.Alignment @@ -243,7 +243,7 @@ class GuidSection(GuidSectionClassObject) : if self.AuthStatusValid in ("TRUE", "1"): Attribute.append('AUTH_STATUS_VALID') - GenFdsGlobalVariable.GenerateSection(OutputFile, [TempFile], Section.Section.SectionType['GUIDED'], + GenFdsGlobalVariable.GenerateSection(OutputFile, [TempFile], Section.SectionType['GUIDED'], Guid=self.NameGuid, GuidAttr=Attribute, GuidHdrLen=HeaderLength) else: @@ -256,14 +256,14 @@ class GuidSection(GuidSectionClassObject) : if self.AuthStatusValid in ("TRUE", "1"): Attribute.append('AUTH_STATUS_VALID') if self.ProcessRequired == "NONE" and HeaderLength is None: - GenFdsGlobalVariable.GenerateSection(OutputFile, [TempFile], Section.Section.SectionType['GUIDED'], + GenFdsGlobalVariable.GenerateSection(OutputFile, [TempFile], Section.SectionType['GUIDED'], Guid=self.NameGuid, GuidAttr=Attribute, GuidHdrLen=HeaderLength, DummyFile=DummyFile, IsMakefile=IsMakefile) else: if self.ProcessRequired in ("TRUE", "1"): if 'PROCESSING_REQUIRED' not in Attribute: Attribute.append('PROCESSING_REQUIRED') - GenFdsGlobalVariable.GenerateSection(OutputFile, [TempFile], Section.Section.SectionType['GUIDED'], + GenFdsGlobalVariable.GenerateSection(OutputFile, [TempFile], Section.SectionType['GUIDED'], Guid=self.NameGuid, GuidAttr=Attribute, GuidHdrLen=HeaderLength, IsMakefile=IsMakefile) diff --git a/BaseTools/Source/Python/GenFds/OptRomInfStatement.py b/BaseTools/Source/Python/GenFds/OptRomInfStatement.py index 6179bfa181cb..93c4456eb89f 100644 --- a/BaseTools/Source/Python/GenFds/OptRomInfStatement.py +++ b/BaseTools/Source/Python/GenFds/OptRomInfStatement.py @@ -119,7 +119,7 @@ class OptRomInfStatement (FfsInfStatement): GenSecInputFile = self.__ExtendMacro__(Rule.FileName) OutputFileList.append(GenSecInputFile) else: - OutputFileList, IsSect = Section.Section.GetFileList(self, '', Rule.FileExtension) + OutputFileList, IsSect = Section.GetSectionFileList(self, '', Rule.FileExtension) return OutputFileList @@ -141,7 +141,7 @@ class OptRomInfStatement (FfsInfStatement): GenSecInputFile = self.__ExtendMacro__(Sect.FileName) OutputFileList.append(GenSecInputFile) else: - FileList, IsSect = Section.Section.GetFileList(self, '', Sect.FileExtension) + FileList, IsSect = Section.GetSectionFileList(self, '', Sect.FileExtension) OutputFileList.extend(FileList) return OutputFileList diff --git a/BaseTools/Source/Python/GenFds/Section.py b/BaseTools/Source/Python/GenFds/Section.py index 5895998158b6..92d49da333eb 100644 --- a/BaseTools/Source/Python/GenFds/Section.py +++ b/BaseTools/Source/Python/GenFds/Section.py @@ -22,148 +22,107 @@ from Common import EdkLogger from Common.BuildToolError import * from Common.DataType import * -## section base class -# -# -class Section (SectionClassObject): - SectionType = { - 'RAW' : 'EFI_SECTION_RAW', - 'FREEFORM' : 'EFI_SECTION_FREEFORM_SUBTYPE_GUID', - BINARY_FILE_TYPE_PE32 : 'EFI_SECTION_PE32', - BINARY_FILE_TYPE_PIC : 'EFI_SECTION_PIC', - BINARY_FILE_TYPE_TE : 'EFI_SECTION_TE', - 'FV_IMAGE' : 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE', - BINARY_FILE_TYPE_DXE_DEPEX : 'EFI_SECTION_DXE_DEPEX', - BINARY_FILE_TYPE_PEI_DEPEX : 'EFI_SECTION_PEI_DEPEX', - 'GUIDED' : 'EFI_SECTION_GUID_DEFINED', - 'COMPRESS' : 'EFI_SECTION_COMPRESSION', - BINARY_FILE_TYPE_UI : 'EFI_SECTION_USER_INTERFACE', - BINARY_FILE_TYPE_SMM_DEPEX : 'EFI_SECTION_SMM_DEPEX' - } - - BinFileType = { - BINARY_FILE_TYPE_GUID : '.guid', - 'ACPI' : '.acpi', - 'ASL' : '.asl' , - BINARY_FILE_TYPE_UEFI_APP : '.app', - BINARY_FILE_TYPE_LIB : '.lib', - BINARY_FILE_TYPE_PE32 : '.pe32', - BINARY_FILE_TYPE_PIC : '.pic', - BINARY_FILE_TYPE_PEI_DEPEX : '.depex', - 'SEC_PEI_DEPEX' : '.depex', - BINARY_FILE_TYPE_TE : '.te', - BINARY_FILE_TYPE_UNI_VER : '.ver', - BINARY_FILE_TYPE_VER : '.ver', - BINARY_FILE_TYPE_UNI_UI : '.ui', - BINARY_FILE_TYPE_UI : '.ui', - BINARY_FILE_TYPE_BIN : '.bin', - 'RAW' : '.raw', - 'COMPAT16' : '.comp16', - BINARY_FILE_TYPE_FV : '.fv' - } - - SectFileType = { - 'SEC_GUID' : '.sec' , - 'SEC_PE32' : '.sec' , - 'SEC_PIC' : '.sec', - 'SEC_TE' : '.sec', - 'SEC_VER' : '.sec', - 'SEC_UI' : '.sec', - 'SEC_COMPAT16' : '.sec', - 'SEC_BIN' : '.sec' - } +SectionType = { + 'RAW' : 'EFI_SECTION_RAW', + 'FREEFORM' : 'EFI_SECTION_FREEFORM_SUBTYPE_GUID', + BINARY_FILE_TYPE_PE32 : 'EFI_SECTION_PE32', + BINARY_FILE_TYPE_PIC : 'EFI_SECTION_PIC', + BINARY_FILE_TYPE_TE : 'EFI_SECTION_TE', + 'FV_IMAGE' : 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE', + BINARY_FILE_TYPE_DXE_DEPEX : 'EFI_SECTION_DXE_DEPEX', + BINARY_FILE_TYPE_PEI_DEPEX : 'EFI_SECTION_PEI_DEPEX', + 'GUIDED' : 'EFI_SECTION_GUID_DEFINED', + 'COMPRESS' : 'EFI_SECTION_COMPRESSION', + BINARY_FILE_TYPE_UI : 'EFI_SECTION_USER_INTERFACE', + BINARY_FILE_TYPE_SMM_DEPEX : 'EFI_SECTION_SMM_DEPEX' +} - ToolGuid = { - '0xa31280ad-0x481e-0x41b6-0x95e8-0x127f-0x4c984779' : 'TianoCompress', - '0xee4e5898-0x3914-0x4259-0x9d6e-0xdc7b-0xd79403cf' : 'LzmaCompress' - } +BinFileType = { + BINARY_FILE_TYPE_GUID : '.guid', + 'ACPI' : '.acpi', + 'ASL' : '.asl' , + BINARY_FILE_TYPE_UEFI_APP : '.app', + BINARY_FILE_TYPE_LIB : '.lib', + BINARY_FILE_TYPE_PE32 : '.pe32', + BINARY_FILE_TYPE_PIC : '.pic', + BINARY_FILE_TYPE_PEI_DEPEX : '.depex', + 'SEC_PEI_DEPEX' : '.depex', + BINARY_FILE_TYPE_TE : '.te', + BINARY_FILE_TYPE_UNI_VER : '.ver', + BINARY_FILE_TYPE_VER : '.ver', + BINARY_FILE_TYPE_UNI_UI : '.ui', + BINARY_FILE_TYPE_UI : '.ui', + BINARY_FILE_TYPE_BIN : '.bin', + 'RAW' : '.raw', + 'COMPAT16' : '.comp16', + BINARY_FILE_TYPE_FV : '.fv' +} - ## The constructor - # - # @param self The object pointer - # - def __init__(self): - SectionClassObject.__init__(self) +SectValidFileType = {'SEC_GUID', 'SEC_PE32', 'SEC_PIC', 'SEC_TE', 'SEC_VER', 'SEC_UI', 'SEC_COMPAT16', 'SEC_BIN'} - ## GenSection() method - # - # virtual function - # - # @param self The object pointer - # @param OutputPath Where to place output file - # @param ModuleName Which module this section belongs to - # @param SecNum Index of section - # @param KeyStringList Filter for inputs of section generation - # @param FfsInf FfsInfStatement object that contains this section data - # @param Dict dictionary contains macro and its value - # - def GenSection(self, OutputPath, GuidName, SecNum, keyStringList, FfsInf = None, Dict = {}): - pass - - ## GetFileList() method - # - # Generate compressed section - # - # @param self The object pointer - # @param FfsInf FfsInfStatement object that contains file list - # @param FileType File type to get - # @param FileExtension File extension to get - # @param Dict dictionary contains macro and its value - # @retval tuple (File list, boolean) - # - def GetFileList(FfsInf, FileType, FileExtension, Dict = {}, IsMakefile=False): - IsSect = FileType in Section.SectFileType +## GetFileList() method +# +# Generate compressed section +# +# @param self The object pointer +# @param FfsInf FfsInfStatement object that contains file list +# @param FileType File type to get +# @param FileExtension File extension to get +# @param Dict dictionary contains macro and its value +# @retval tuple (File list, boolean) +# +def GetSectionFileList(FfsInf, FileType, FileExtension, Dict = {}, IsMakefile=False): + IsSect = FileType in SectValidFileType - if FileExtension is not None: - Suffix = FileExtension - elif IsSect : - Suffix = Section.SectionType.get(FileType) - else: - Suffix = Section.BinFileType.get(FileType) - if FfsInf is None: - EdkLogger.error("GenFds", GENFDS_ERROR, 'Inf File does not exist!') + if FileExtension: + Suffix = FileExtension + elif IsSect: + Suffix = SectionType.get(FileType) + else: + Suffix = BinFileType.get(FileType) + if FfsInf is None: + EdkLogger.error("GenFds", GENFDS_ERROR, 'Inf File does not exist!') - FileList = [] - if FileType is not None: - for File in FfsInf.BinFileList: - if File.Arch == TAB_ARCH_COMMON or FfsInf.CurrentArch == File.Arch: - if File.Type == FileType or (int(FfsInf.PiSpecVersion, 16) >= 0x0001000A \ - and FileType == 'DXE_DPEX' and File.Type == BINARY_FILE_TYPE_SMM_DEPEX) \ - or (FileType == BINARY_FILE_TYPE_TE and File.Type == BINARY_FILE_TYPE_PE32): - if '*' in FfsInf.TargetOverrideList or File.Target == '*' or File.Target in FfsInf.TargetOverrideList or FfsInf.TargetOverrideList == []: - FileList.append(FfsInf.PatchEfiFile(File.Path, File.Type)) - else: - GenFdsGlobalVariable.InfLogger ("\nBuild Target \'%s\' of File %s is not in the Scope of %s specified by INF %s in FDF" %(File.Target, File.File, FfsInf.TargetOverrideList, FfsInf.InfFileName)) + FileList = [] + if FileType is not None: + for File in FfsInf.BinFileList: + if File.Arch == TAB_ARCH_COMMON or FfsInf.CurrentArch == File.Arch: + if File.Type == FileType or (int(FfsInf.PiSpecVersion, 16) >= 0x0001000A \ + and FileType == 'DXE_DPEX' and File.Type == BINARY_FILE_TYPE_SMM_DEPEX) \ + or (FileType == BINARY_FILE_TYPE_TE and File.Type == BINARY_FILE_TYPE_PE32): + if '*' in FfsInf.TargetOverrideList or File.Target == '*' or File.Target in FfsInf.TargetOverrideList or FfsInf.TargetOverrideList == []: + FileList.append(FfsInf.PatchEfiFile(File.Path, File.Type)) else: - GenFdsGlobalVariable.VerboseLogger ("\nFile Type \'%s\' of File %s in %s is not same with file type \'%s\' from Rule in FDF" %(File.Type, File.File, FfsInf.InfFileName, FileType)) + GenFdsGlobalVariable.InfLogger ("\nBuild Target \'%s\' of File %s is not in the Scope of %s specified by INF %s in FDF" %(File.Target, File.File, FfsInf.TargetOverrideList, FfsInf.InfFileName)) else: - GenFdsGlobalVariable.InfLogger ("\nCurrent ARCH \'%s\' of File %s is not in the Support Arch Scope of %s specified by INF %s in FDF" %(FfsInf.CurrentArch, File.File, File.Arch, FfsInf.InfFileName)) + GenFdsGlobalVariable.VerboseLogger ("\nFile Type \'%s\' of File %s in %s is not same with file type \'%s\' from Rule in FDF" %(File.Type, File.File, FfsInf.InfFileName, FileType)) + else: + GenFdsGlobalVariable.InfLogger ("\nCurrent ARCH \'%s\' of File %s is not in the Support Arch Scope of %s specified by INF %s in FDF" %(FfsInf.CurrentArch, File.File, File.Arch, FfsInf.InfFileName)) - if (not IsMakefile and Suffix is not None and os.path.exists(FfsInf.EfiOutputPath)) or (IsMakefile and Suffix is not None): - # - # Get Makefile path and time stamp - # - MakefileDir = FfsInf.EfiOutputPath[:-len('OUTPUT')] - Makefile = os.path.join(MakefileDir, 'Makefile') - if not os.path.exists(Makefile): - Makefile = os.path.join(MakefileDir, 'GNUmakefile') - if os.path.exists(Makefile): - # Update to search files with suffix in all sub-dirs. - Tuple = os.walk(FfsInf.EfiOutputPath) - for Dirpath, Dirnames, Filenames in Tuple: - for F in Filenames: - if os.path.splitext(F)[1] == Suffix: - FullName = os.path.join(Dirpath, F) - if os.path.getmtime(FullName) > os.path.getmtime(Makefile): - FileList.append(FullName) - if not FileList: - SuffixMap = FfsInf.GetFinalTargetSuffixMap() - if Suffix in SuffixMap: - FileList.extend(SuffixMap[Suffix]) - - #Process the file lists is alphabetical for a same section type - if len (FileList) > 1: - FileList.sort() + if (not IsMakefile and Suffix is not None and os.path.exists(FfsInf.EfiOutputPath)) or (IsMakefile and Suffix is not None): + # + # Get Makefile path and time stamp + # + MakefileDir = FfsInf.EfiOutputPath[:-len('OUTPUT')] + Makefile = os.path.join(MakefileDir, 'Makefile') + if not os.path.exists(Makefile): + Makefile = os.path.join(MakefileDir, 'GNUmakefile') + if os.path.exists(Makefile): + # Update to search files with suffix in all sub-dirs. + Tuple = os.walk(FfsInf.EfiOutputPath) + for Dirpath, Dirnames, Filenames in Tuple: + for F in Filenames: + if os.path.splitext(F)[1] == Suffix: + FullName = os.path.join(Dirpath, F) + if os.path.getmtime(FullName) > os.path.getmtime(Makefile): + FileList.append(FullName) + if not FileList: + SuffixMap = FfsInf.GetFinalTargetSuffixMap() + if Suffix in SuffixMap: + FileList.extend(SuffixMap[Suffix]) + + #Process the file lists is alphabetical for a same section type + if len (FileList) > 1: + FileList.sort() - return FileList, IsSect - GetFileList = staticmethod(GetFileList) + return FileList, IsSect diff --git a/BaseTools/Source/Python/GenFds/UiSection.py b/BaseTools/Source/Python/GenFds/UiSection.py index fe1e026f5edf..f8b5cdbf7cf9 100644 --- a/BaseTools/Source/Python/GenFds/UiSection.py +++ b/BaseTools/Source/Python/GenFds/UiSection.py @@ -15,7 +15,6 @@ ## # Import Modules # -import Section from Ffs import SectionSuffix import subprocess import Common.LongFilePathOs as os @@ -53,25 +52,22 @@ class UiSection (UiSectionClassObject): # # Prepare the parameter of GenSection # - if FfsInf is not None: + if FfsInf: self.Alignment = FfsInf.__ExtendMacro__(self.Alignment) self.StringData = FfsInf.__ExtendMacro__(self.StringData) self.FileName = FfsInf.__ExtendMacro__(self.FileName) - OutputFile = os.path.join(OutputPath, ModuleName + 'SEC' + SecNum + SectionSuffix['UI']) + OutputFile = os.path.join(OutputPath, ModuleName + TAB_SEC_DIRECTORY + SecNum + SectionSuffix['UI']) - if self.StringData is not None : + if self.StringData: NameString = self.StringData - elif self.FileName is not None: + elif self.FileName: FileNameStr = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FileName) FileNameStr = GenFdsGlobalVariable.MacroExtend(FileNameStr, Dict) - FileObj = open(FileNameStr, 'r') - NameString = FileObj.read() - FileObj.close() + with open(FileNameStr, 'r') as FileObj: + NameString = FileObj.read() else: NameString = '' GenFdsGlobalVariable.GenerateSection(OutputFile, None, 'EFI_SECTION_USER_INTERFACE', Ui=NameString, IsMakefile=IsMakefile) - OutputFileList = [] - OutputFileList.append(OutputFile) - return OutputFileList, self.Alignment + return [OutputFile], self.Alignment diff --git a/BaseTools/Source/Python/GenFds/VerSection.py b/BaseTools/Source/Python/GenFds/VerSection.py index 1bcdc8110d30..e6e79cff5be3 100644 --- a/BaseTools/Source/Python/GenFds/VerSection.py +++ b/BaseTools/Source/Python/GenFds/VerSection.py @@ -16,13 +16,12 @@ # Import Modules # from Ffs import SectionSuffix -import Section import Common.LongFilePathOs as os import subprocess from GenFdsGlobalVariable import GenFdsGlobalVariable from CommonDataClass.FdfClass import VerSectionClassObject from Common.LongFilePathSupport import OpenLongFilePath as open -from Common.DataType import SUP_MODULE_SEC +from Common.DataType import TAB_SEC_DIRECTORY ## generate version section # @@ -53,31 +52,26 @@ class VerSection (VerSectionClassObject): # # Prepare the parameter of GenSection # - if FfsInf is not None: + if FfsInf: self.Alignment = FfsInf.__ExtendMacro__(self.Alignment) self.BuildNum = FfsInf.__ExtendMacro__(self.BuildNum) self.StringData = FfsInf.__ExtendMacro__(self.StringData) self.FileName = FfsInf.__ExtendMacro__(self.FileName) OutputFile = os.path.join(OutputPath, - ModuleName + 'SEC' + SecNum + SectionSuffix['VERSION']) + ModuleName + TAB_SEC_DIRECTORY + SecNum + SectionSuffix['VERSION']) OutputFile = os.path.normpath(OutputFile) # Get String Data - StringData = '' - if self.StringData is not None: + if self.StringData: StringData = self.StringData - elif self.FileName is not None: + elif self.FileName: FileNameStr = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FileName) FileNameStr = GenFdsGlobalVariable.MacroExtend(FileNameStr, Dict) - FileObj = open(FileNameStr, 'r') - StringData = FileObj.read() - StringData = '"' + StringData + '"' - FileObj.close() + with open(FileNameStr, 'r') as FileObj: + StringData = '"' + FileObj.read() + '"' else: StringData = '' GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_VERSION', Ver=StringData, BuildNumber=self.BuildNum, IsMakefile=IsMakefile) - OutputFileList = [] - OutputFileList.append(OutputFile) - return OutputFileList, self.Alignment + return [OutputFile], self.Alignment -- 2.16.2.windows.1