From nobody Sun Sep 7 12:24:20 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 152632138076595.4367920607142; Mon, 14 May 2018 11:09:40 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id E68DF21E11D1A; Mon, 14 May 2018 11:09:26 -0700 (PDT) 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) 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 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 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; 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 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,401,1520924400"; d="scan'208";a="55814271" From: Jaben Carsey To: edk2-devel@lists.01.org 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: [edk2] [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: , Cc: Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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 =3D '$(EDK_SOURCE)' TAB_EFI_SOURCE =3D '$(EFI_SOURCE)' TAB_WORKSPACE =3D '$(WORKSPACE)' TAB_FV_DIRECTORY =3D 'FV' +TAB_SEC_DIRECTORY =3D 'SEC' =20 TAB_ARCH_NULL =3D '' TAB_ARCH_COMMON =3D '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, Ff= sInf =3D None, Dict =3D {}, IsMakefile =3D False): =20 - if FfsInf is not None: + if FfsInf: self.CompType =3D FfsInf.__ExtendMacro__(self.CompType) self.Alignment =3D FfsInf.__ExtendMacro__(self.Alignment) =20 @@ -68,13 +68,13 @@ class CompressSection (CompressSectionClassObject) : Index =3D Index + 1 SecIndex =3D '%s.%d' %(SecNum, Index) ReturnSectList, AlignValue =3D Sect.GenSection(OutputPath, Mod= uleName, SecIndex, KeyStringList, FfsInf, Dict, IsMakefile=3DIsMakefile) - if AlignValue is not None: - if MaxAlign is None: + if AlignValue: + if not MaxAlign: MaxAlign =3D AlignValue if GenFdsGlobalVariable.GetAlignment (AlignValue) > GenFds= GlobalVariable.GetAlignment (MaxAlign): MaxAlign =3D AlignValue if ReturnSectList !=3D []: - if AlignValue is None: + if not AlignValue: AlignValue =3D "1" for FileData in ReturnSectList: SectFiles +=3D (FileData,) @@ -83,17 +83,13 @@ class CompressSection (CompressSectionClassObject) : OutputFile =3D OutputPath + \ os.sep + \ ModuleName + \ - SUP_MODULE_SEC + \ + SUP_MODULE_SEC + \ SecNum + \ SectionSuffix['COMPRESS'] OutputFile =3D os.path.normpath(OutputFile) DummyFile =3D OutputFile + '.dummy' GenFdsGlobalVariable.GenerateSection(DummyFile, SectFiles, InputAl= ign=3DSectAlign, IsMakefile=3DIsMakefile) =20 - GenFdsGlobalVariable.GenerateSection(OutputFile, [DummyFile], Sect= ion.Section.SectionType['COMPRESS'], + GenFdsGlobalVariable.GenerateSection(OutputFile, [DummyFile], Sect= ion.SectionType['COMPRESS'], CompressionType=3Dself.CompTy= peDict[self.CompType], IsMakefile=3DIsMakefile) - OutputFileList =3D [] - OutputFileList.append(OutputFile) - return OutputFileList, self.Alignment - - + return [OutputFile], self.Alignment diff --git a/BaseTools/Source/Python/GenFds/DataSection.py b/BaseTools/Sour= ce/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, Ff= sFile =3D None, Dict =3D {}, IsMakefile =3D False): + + self.SectFileName =3D GenFdsGlobalVariable.ReplaceWorkspaceMacro(s= elf.SectFileName) # # Prepare the parameter of GenSection # - if FfsFile is not None: - self.SectFileName =3D GenFdsGlobalVariable.ReplaceWorkspaceMac= ro(self.SectFileName) + if FfsFile: self.SectFileName =3D GenFdsGlobalVariable.MacroExtend(self.Se= ctFileName, Dict, FfsFile.CurrentArch) else: - self.SectFileName =3D GenFdsGlobalVariable.ReplaceWorkspaceMac= ro(self.SectFileName) self.SectFileName =3D GenFdsGlobalVariable.MacroExtend(self.Se= ctFileName, Dict) =20 - """Check Section file exist or not !""" - + # + # Check Section file exist or not + # if not os.path.exists(self.SectFileName): self.SectFileName =3D os.path.join (GenFdsGlobalVariable.WorkS= paceDir, self.SectFileName) =20 - """Copy Map file to Ffs output""" + # + # Copy Map file to Ffs output + # Filename =3D GenFdsGlobalVariable.MacroExtend(self.SectFileName) - if Filename[(len(Filename)-4):] =3D=3D '.efi': + if Filename.endswith('.efi'): MapFile =3D Filename.replace('.efi', '.map') CopyMapFile =3D os.path.join(OutputPath, ModuleName + '.map') if IsMakefile: - if GenFdsGlobalVariable.CopyList =3D=3D []: - GenFdsGlobalVariable.CopyList =3D [(MapFile, CopyMapFi= le)] - else: - GenFdsGlobalVariable.CopyList.append((MapFile, CopyMap= File)) + GenFdsGlobalVariable.CopyList.append((MapFile, CopyMapFile= )) else: if os.path.exists(MapFile): if not os.path.exists(CopyMapFile) or (os.path.getmtim= e(MapFile) > os.path.getmtime(CopyMapFile)): CopyLongFilePath(MapFile, CopyMapFile) =20 #Get PE Section alignment when align is set to AUTO - if self.Alignment =3D=3D 'Auto' and self.SecType in (BINARY_FILE_T= YPE_TE, BINARY_FILE_TYPE_PE32): + if self.Alignment =3D=3D 'Auto' and self.SecType in {BINARY_FILE_T= YPE_TE, BINARY_FILE_TYPE_PE32}: ImageObj =3D PeImageClass (Filename) if ImageObj.SectionAlignment < 0x400: self.Alignment =3D str (ImageObj.SectionAlignment) @@ -120,8 +120,8 @@ class DataSection (DataSectionClassObject): ) self.SectFileName =3D TeFile =20 - OutputFile =3D os.path.join (OutputPath, ModuleName + 'SEC' + SecN= um + SectionSuffix.get(self.SecType)) + OutputFile =3D os.path.join (OutputPath, ModuleName + TAB_SEC_DIRE= CTORY + SecNum + SectionSuffix.get(self.SecType)) OutputFile =3D os.path.normpath(OutputFile) - GenFdsGlobalVariable.GenerateSection(OutputFile, [self.SectFileNam= e], Section.Section.SectionType.get(self.SecType), IsMakefile =3D IsMakefil= e) + GenFdsGlobalVariable.GenerateSection(OutputFile, [self.SectFileNam= e], Section.SectionType.get(self.SecType), IsMakefile =3D IsMakefile) FileList =3D [OutputFile] return FileList, self.Alignment diff --git a/BaseTools/Source/Python/GenFds/DepexSection.py b/BaseTools/Sou= rce/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 =3D os.path.join (OutputPath, ModuleName + SUP_MODULE_S= EC + SecNum + '.dpx') OutputFile =3D os.path.normpath(OutputFile) =20 - GenFdsGlobalVariable.GenerateSection(OutputFile, [InputFile], Sect= ion.Section.SectionType.get (SecType), IsMakefile=3DIsMakefile) + GenFdsGlobalVariable.GenerateSection(OutputFile, [InputFile], Sect= ion.SectionType.get (SecType), IsMakefile=3DIsMakefile) return [OutputFile], self.Alignment diff --git a/BaseTools/Source/Python/GenFds/EfiSection.py b/BaseTools/Sourc= e/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): =20 if self.FileName is not None and self.FileName.startswith('PCD('): self.FileName =3D GenFdsGlobalVariable.GetPcdValue(self.FileNa= me) - """Prepare the parameter of GenSection""" - if FfsInf is not None : + =20 + # + # Prepare the parameter of GenSection + # + if FfsInf: InfFileName =3D FfsInf.InfFileName SectionType =3D FfsInf.__ExtendMacro__(self.SectionType) Filename =3D FfsInf.__ExtendMacro__(self.FileName) @@ -67,21 +70,23 @@ class EfiSection (EfiSectionClassObject): StringData =3D FfsInf.__ExtendMacro__(self.StringData) ModuleNameStr =3D FfsInf.__ExtendMacro__('$(MODULE_NAME)') NoStrip =3D 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 =3D FfsInf.KeepReloc - elif FfsInf.KeepRelocFromRule is not None: + elif FfsInf.KeepRelocFromRule: NoStrip =3D FfsInf.KeepRelocFromRule - elif self.KeepReloc is not None: + elif self.KeepReloc: NoStrip =3D self.KeepReloc - elif FfsInf.ShadowFromInfFile is not None: + elif FfsInf.ShadowFromInfFile: NoStrip =3D FfsInf.ShadowFromInfFile else: EdkLogger.error("GenFds", GENFDS_ERROR, "Module %s apply rule = for None!" %ModuleName) =20 - """If the file name was pointed out, add it in FileList""" + # + # If the file name was pointed out, add it in FileList + # FileList =3D [] - if Filename is not None: + if Filename: Filename =3D 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 =3D Section.Section.GetFileList(FfsInf, self.= FileType, self.FileExtension, Dict, IsMakefile=3DIsMakefile) + FileList, IsSect =3D Section.GetSectionFileList(FfsInf, self.F= ileType, self.FileExtension, Dict, IsMakefile=3DIsMakefile) if IsSect : return FileList, self.Alignment =20 Index =3D 0 Align =3D self.Alignment =20 - """ If Section type is 'VERSION'""" + # + # If Section type is 'VERSION' + # OutputFileList =3D [] if SectionType =3D=3D 'VERSION': - InfOverrideVerString =3D False - if FfsInf.Version is not None: - #StringData =3D FfsInf.Version + if FfsInf.Version: BuildNum =3D FfsInf.Version InfOverrideVerString =3D True =20 if InfOverrideVerString: - #VerTuple =3D ('-n', '"' + StringData + '"') - if BuildNum is not None and BuildNum !=3D '': - BuildNumTuple =3D ('-j', BuildNum) - else: - BuildNumTuple =3D tuple() - - Num =3D SecNum - OutputFile =3D os.path.join( OutputPath, ModuleName + 'SEC= ' + str(Num) + SectionSuffix.get(SectionType)) + OutputFile =3D os.path.join( OutputPath, ModuleName + TAB_= SEC_DIRECTORY + str(SecNum) + SectionSuffix.get(SectionType)) GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_= SECTION_VERSION', - #Ui=3DStringData, Ver=3DBuildNum, IsMakefile=3DIsMakefil= e) OutputFileList.append(OutputFile) @@ -134,38 +131,31 @@ class EfiSection (EfiSectionClassObject): for File in FileList: Index =3D Index + 1 Num =3D '%s.%d' %(SecNum , Index) - OutputFile =3D os.path.join(OutputPath, ModuleName + '= SEC' + Num + SectionSuffix.get(SectionType)) - f =3D open(File, 'r') - VerString =3D f.read() - f.close() + OutputFile =3D os.path.join(OutputPath, ModuleName + T= AB_SEC_DIRECTORY + Num + SectionSuffix.get(SectionType)) + with open(File, 'r') as f: + VerString =3D f.read() BuildNum =3D VerString - if BuildNum is not None and BuildNum !=3D '': - BuildNumTuple =3D ('-j', BuildNum) GenFdsGlobalVariable.GenerateSection(OutputFile, [], '= EFI_SECTION_VERSION', - #Ui=3DVerString, Ver=3DBuildNum, IsMakefile=3DIsMak= efile) OutputFileList.append(OutputFile) =20 else: BuildNum =3D StringData - if BuildNum is not None and BuildNum !=3D '': + if BuildNum: BuildNumTuple =3D ('-j', BuildNum) else: BuildNumTuple =3D tuple() BuildNumString =3D ' ' + ' '.join(BuildNumTuple) =20 - #if VerString =3D=3D '' and=20 if BuildNumString =3D=3D '': if self.Optional =3D=3D True : GenFdsGlobalVariable.VerboseLogger( "Optional Sect= ion don't exist!") return [], None else: EdkLogger.error("GenFds", GENFDS_ERROR, "File: %s = miss Version Section value" %InfFileName) - Num =3D SecNum - OutputFile =3D os.path.join( OutputPath, ModuleName + 'SEC= ' + str(Num) + SectionSuffix.get(SectionType)) + OutputFile =3D os.path.join( OutputPath, ModuleName + TAB_= SEC_DIRECTORY + str(SecNum) + SectionSuffix.get(SectionType)) GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_= SECTION_VERSION', - #Ui=3DVerString, Ver=3DBuildNum, IsMakefile=3DIsMakefil= e) OutputFileList.append(OutputFile) @@ -176,15 +166,14 @@ class EfiSection (EfiSectionClassObject): elif SectionType =3D=3D BINARY_FILE_TYPE_UI: =20 InfOverrideUiString =3D False - if FfsInf.Ui is not None: + if FfsInf.Ui: StringData =3D FfsInf.Ui InfOverrideUiString =3D True =20 if InfOverrideUiString: - Num =3D SecNum if IsMakefile and StringData =3D=3D ModuleNameStr: StringData =3D "$(MODULE_NAME)" - OutputFile =3D os.path.join( OutputPath, ModuleName + 'SEC= ' + str(Num) + SectionSuffix.get(SectionType)) + OutputFile =3D os.path.join( OutputPath, ModuleName + TAB_= SEC_DIRECTORY + str(SecNum) + SectionSuffix.get(SectionType)) GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_= SECTION_USER_INTERFACE', Ui=3DStringData, IsMa= kefile=3DIsMakefile) OutputFileList.append(OutputFile) @@ -193,38 +182,34 @@ class EfiSection (EfiSectionClassObject): for File in FileList: Index =3D Index + 1 Num =3D '%s.%d' %(SecNum , Index) - OutputFile =3D os.path.join(OutputPath, ModuleName + '= SEC' + Num + SectionSuffix.get(SectionType)) - f =3D open(File, 'r') - UiString =3D f.read() - f.close() + OutputFile =3D os.path.join(OutputPath, ModuleName + T= AB_SEC_DIRECTORY + Num + SectionSuffix.get(SectionType)) + with open(File, 'r') as f: + UiString =3D f.read() if IsMakefile and UiString =3D=3D ModuleNameStr: UiString =3D "$(MODULE_NAME)" GenFdsGlobalVariable.GenerateSection(OutputFile, [], '= EFI_SECTION_USER_INTERFACE', Ui=3DUiString, IsM= akefile=3DIsMakefile) OutputFileList.append(OutputFile) else: - if StringData is not None and len(StringData) > 0: - UiTuple =3D ('-n', '"' + StringData + '"') - else: - UiTuple =3D tuple() - + if not StringData: if self.Optional =3D=3D True : GenFdsGlobalVariable.VerboseLogger( "Optional Sect= ion don't exist!") return '', None else: EdkLogger.error("GenFds", GENFDS_ERROR, "File: %s = miss UI Section value" %InfFileName) =20 - Num =3D SecNum if IsMakefile and StringData =3D=3D ModuleNameStr: StringData =3D "$(MODULE_NAME)" - OutputFile =3D os.path.join( OutputPath, ModuleName + 'SEC= ' + str(Num) + SectionSuffix.get(SectionType)) + OutputFile =3D os.path.join( OutputPath, ModuleName + TAB_= SEC_DIRECTORY + str(SecNum) + SectionSuffix.get(SectionType)) GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_= SECTION_USER_INTERFACE', Ui=3DStringData, IsMa= kefile=3DIsMakefile) OutputFileList.append(OutputFile) =20 =20 else: - """If File List is empty""" + # + # If File List is empty + # if FileList =3D=3D [] : if self.Optional =3D=3D True: GenFdsGlobalVariable.VerboseLogger("Optional Section d= on't exist!") @@ -233,16 +218,20 @@ class EfiSection (EfiSectionClassObject): EdkLogger.error("GenFds", GENFDS_ERROR, "Output file f= or %s section could not be found for %s" % (SectionType, InfFileName)) =20 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 =3D Index + 1 Num =3D '%s.%d' %(SecNum , Index) - OutputFile =3D os.path.join( OutputPath, ModuleName + = 'SEC' + Num + SectionSuffix.get(SectionType)) + OutputFile =3D os.path.join( OutputPath, ModuleName + = TAB_SEC_DIRECTORY + Num + SectionSuffix.get(SectionType)) File =3D GenFdsGlobalVariable.MacroExtend(File, Dict) =20 #Get PE Section alignment when align is set to AUTO - if self.Alignment =3D=3D 'Auto' and (SectionType =3D= =3D BINARY_FILE_TYPE_PE32 or SectionType =3D=3D BINARY_FILE_TYPE_TE): + if self.Alignment =3D=3D 'Auto' and SectionType in {BI= NARY_FILE_TYPE_PE32, BINARY_FILE_TYPE_TE}: ImageObj =3D PeImageClass (File) if ImageObj.SectionAlignment < 0x400: Align =3D str (ImageObj.SectionAlignment) @@ -251,7 +240,7 @@ class EfiSection (EfiSectionClassObject): else: Align =3D str (ImageObj.SectionAlignment / 0x1= 00000) + 'M' =20 - if File[(len(File)-4):] =3D=3D '.efi': + if File.endswith('.efi'): MapFile =3D File.replace('.efi', '.map') CopyMapFile =3D os.path.join(OutputPath, ModuleNam= e + '.map') if IsMakefile: @@ -285,7 +274,9 @@ class EfiSection (EfiSectionClassObject): ) File =3D StrippedFile =20 - """For TE Section call GenFw to generate TE image""" + # + # For TE Section call GenFw to generate TE image + # =20 if SectionType =3D=3D BINARY_FILE_TYPE_TE: TeFile =3D os.path.join( OutputPath, ModuleName + = 'Te.raw') @@ -297,10 +288,12 @@ class EfiSection (EfiSectionClassObject): ) File =3D TeFile =20 - """Call GenSection""" + # + # Call GenSection + # GenFdsGlobalVariable.GenerateSection(OutputFile, [File], - Section.Section.Se= ctionType.get (SectionType), + Section.SectionTyp= e.get (SectionType), IsMakefile=3DIsMak= efile ) 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 =3D os.path.normpath(os.path.join(self.Efi= OutputPath, GenSecInputFile)) else: - FileList, IsSect =3D Section.Section.GetFileList(self, '', Rul= e.FileExtension) + FileList, IsSect =3D Section.GetSectionFileList(self, '', Rule= .FileExtension) =20 Index =3D 1 SectionType =3D Rule.SectionType @@ -761,7 +761,7 @@ class FfsInfStatement(FfsInfStatementClassObject): =20 SecNum =3D '%d' %Index GenSecOutputFile=3D self.__ExtendMacro__(Rule.NameGuid) + \ - SectionSuffix[SectionType] + 'SEC' + SecNum + SectionSuffix[SectionType] + TAB_SEC_DIRECTO= RY + SecNum Index =3D Index + 1 OutputFile =3D os.path.join(self.OutputPath, GenSecOutputF= ile) File =3D GenFdsGlobalVariable.MacroExtend(File, Dict, self= .CurrentArch) @@ -799,12 +799,12 @@ class FfsInfStatement(FfsInfStatementClassObject): IsMakefile=3DIsMakefile ) File =3D TeFile - GenFdsGlobalVariable.GenerateSection(OutputFile, [File], S= ection.Section.SectionType[SectionType], IsMakefile=3DIsMakefile) + GenFdsGlobalVariable.GenerateSection(OutputFile, [File], S= ection.SectionType[SectionType], IsMakefile=3DIsMakefile) OutputFileList.append(OutputFile) else: SecNum =3D '%d' %Index GenSecOutputFile=3D self.__ExtendMacro__(Rule.NameGuid) + \ - SectionSuffix[SectionType] + 'SEC' + SecNum + SectionSuffix[SectionType] + TAB_SEC_DIRECTO= RY + SecNum OutputFile =3D os.path.join(self.OutputPath, GenSecOutputFile) GenSecInputFile =3D GenFdsGlobalVariable.MacroExtend(GenSecInp= utFile, Dict, self.CurrentArch) =20 @@ -842,7 +842,7 @@ class FfsInfStatement(FfsInfStatementClassObject): IsMakefile=3DIsMakefile ) GenSecInputFile =3D TeFile - GenFdsGlobalVariable.GenerateSection(OutputFile, [GenSecInputF= ile], Section.Section.SectionType[SectionType], IsMakefile=3DIsMakefile) + GenFdsGlobalVariable.GenerateSection(OutputFile, [GenSecInputF= ile], Section.SectionType[SectionType], IsMakefile=3DIsMakefile) OutputFileList.append(OutputFile) =20 return OutputFileList diff --git a/BaseTools/Source/Python/GenFds/FvImageSection.py b/BaseTools/S= ource/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, Ff= sInf =3D None, Dict =3D {}, IsMakefile =3D False): =20 OutputFileList =3D [] - if self.FvFileType is not None: - FileList, IsSect =3D Section.Section.GetFileList(FfsInf, self.= FvFileType, self.FvFileExtension) + if self.FvFileType: + FileList, IsSect =3D Section.GetSectionFileList(FfsInf, self.F= vFileType, self.FvFileExtension) if IsSect : return FileList, self.Alignment =20 - Num =3D SecNum - MaxFvAlignment =3D 0 for FvFileName in FileList: FvAlignmentValue =3D 0 if os.path.isfile(FvFileName): - FvFileObj =3D open (FvFileName,'rb') - FvFileObj.seek(0) + with open (FvFileName,'rb') as FvFileObj: # PI FvHeader is 0x48 byte FvHeaderBuffer =3D FvFileObj.read(0x48) # FV alignment position. FvAlignmentValue =3D 1 << (ord (FvHeaderBuffer[0x2E]) = & 0x1F) - FvFileObj.close() if FvAlignmentValue > MaxFvAlignment: MaxFvAlignment =3D FvAlignmentValue =20 - OutputFile =3D os.path.join(OutputPath, ModuleName + 'SEC'= + Num + SectionSuffix["FV_IMAGE"]) + OutputFile =3D os.path.join(OutputPath, ModuleName + TAB_S= EC_DIRECTORY + SecNum + SectionSuffix["FV_IMAGE"]) GenFdsGlobalVariable.GenerateSection(OutputFile, [FvFileNa= me], 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE', IsMakefile=3DIsMakefile) OutputFileList.append(OutputFile) =20 @@ -97,24 +93,23 @@ class FvImageSection(FvImageSectionClassObject): # # Generate Fv # - if self.FvName is not None: + if self.FvName: Buffer =3D StringIO.StringIO('') Fv =3D GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(self.= FvName) - if Fv is not None: + if Fv: self.Fv =3D Fv FvFileName =3D Fv.AddToBuffer(Buffer, self.FvAddr, MacroDi= ct =3D Dict, Flag=3DIsMakefile) - if Fv.FvAlignment is not None: - if self.Alignment is None: + if Fv.FvAlignment: + if not self.Alignment: self.Alignment =3D Fv.FvAlignment else: if GenFdsGlobalVariable.GetAlignment (Fv.FvAlignme= nt) > GenFdsGlobalVariable.GetAlignment (self.Alignment): self.Alignment =3D Fv.FvAlignment else: - if self.FvFileName is not None: + if self.FvFileName: FvFileName =3D GenFdsGlobalVariable.ReplaceWorkspaceMa= cro(self.FvFileName) if os.path.isfile(FvFileName): - FvFileObj =3D open (FvFileName,'rb') - FvFileObj.seek(0) + with open (FvFileName,'rb') as FvFileObj: # PI FvHeader is 0x48 byte FvHeaderBuffer =3D FvFileObj.read(0x48) # FV alignment position. @@ -132,14 +127,13 @@ class FvImageSection(FvImageSectionClassObject): else: # FvAlignmentValue is less than 1K self.Alignment =3D str (FvAlignmentValue) - FvFileObj.close() else: EdkLogger.error("GenFds", GENFDS_ERROR, "FvImageSectio= n Failed! %s NOT found in FDF" % self.FvName) =20 # # Prepare the parameter of GenSection # - OutputFile =3D os.path.join(OutputPath, ModuleName + 'SEC' + S= ecNum + SectionSuffix["FV_IMAGE"]) + OutputFile =3D os.path.join(OutputPath, ModuleName + TAB_SEC_D= IRECTORY + SecNum + SectionSuffix["FV_IMAGE"]) GenFdsGlobalVariable.GenerateSection(OutputFile, [FvFileName],= 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE', IsMakefile=3DIsMakefile) OutputFileList.append(OutputFile) =20 diff --git a/BaseTools/Source/Python/GenFds/GuidSection.py b/BaseTools/Sour= ce/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 Ge= nerate CRC32 Section") - GenFdsGlobalVariable.GenerateSection(OutputFile, SectFile, Sec= tion.Section.SectionType[self.SectionType], InputAlign=3DSectAlign, IsMakef= ile=3DIsMakefile) + GenFdsGlobalVariable.GenerateSection(OutputFile, SectFile, Sec= tion.SectionType[self.SectionType], InputAlign=3DSectAlign, IsMakefile=3DIs= Makefile) OutputFileList =3D [] OutputFileList.append(OutputFile) return OutputFileList, self.Alignment @@ -243,7 +243,7 @@ class GuidSection(GuidSectionClassObject) : =20 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=3Dself.NameGuid,= GuidAttr=3DAttribute, GuidHdrLen=3DHeaderLength) =20 else: @@ -256,14 +256,14 @@ class GuidSection(GuidSectionClassObject) : if self.AuthStatusValid in ("TRUE", "1"): Attribute.append('AUTH_STATUS_VALID') if self.ProcessRequired =3D=3D "NONE" and HeaderLength is = None: - GenFdsGlobalVariable.GenerateSection(OutputFile, [Temp= File], Section.Section.SectionType['GUIDED'], + GenFdsGlobalVariable.GenerateSection(OutputFile, [Temp= File], Section.SectionType['GUIDED'], Guid=3Dself.NameG= uid, GuidAttr=3DAttribute, GuidHdrLen=3DHead= erLength, DummyFile=3DDummyFile, IsMakefile=3DIsMakefile) else: if self.ProcessRequired in ("TRUE", "1"): if 'PROCESSING_REQUIRED' not in Attribute: Attribute.append('PROCESSING_REQUIRED') - GenFdsGlobalVariable.GenerateSection(OutputFile, [Temp= File], Section.Section.SectionType['GUIDED'], + GenFdsGlobalVariable.GenerateSection(OutputFile, [Temp= File], Section.SectionType['GUIDED'], Guid=3Dself.NameG= uid, GuidAttr=3DAttribute, GuidHdrLen=3DHead= erLength, IsMakefile=3DIsMakefile) =20 diff --git a/BaseTools/Source/Python/GenFds/OptRomInfStatement.py b/BaseToo= ls/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 =3D self.__ExtendMacro__(Rule.FileName) OutputFileList.append(GenSecInputFile) else: - OutputFileList, IsSect =3D Section.Section.GetFileList(self, '= ', Rule.FileExtension) + OutputFileList, IsSect =3D Section.GetSectionFileList(self, ''= , Rule.FileExtension) =20 return OutputFileList =20 @@ -141,7 +141,7 @@ class OptRomInfStatement (FfsInfStatement): GenSecInputFile =3D self.__ExtendMacro__(Sect.FileName) OutputFileList.append(GenSecInputFile) else: - FileList, IsSect =3D Section.Section.GetFileList(self,= '', Sect.FileExtension) + FileList, IsSect =3D Section.GetSectionFileList(self, = '', Sect.FileExtension) OutputFileList.extend(FileList) =20 =20 return OutputFileList diff --git a/BaseTools/Source/Python/GenFds/Section.py b/BaseTools/Source/P= ython/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 * =20 -## section base class -# -# -class Section (SectionClassObject): - SectionType =3D { - '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 =3D { - 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 =3D { - '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 =3D { + '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' +} =20 - ToolGuid =3D { - '0xa31280ad-0x481e-0x41b6-0x95e8-0x127f-0x4c984779' : 'TianoCompre= ss', - '0xee4e5898-0x3914-0x4259-0x9d6e-0xdc7b-0xd79403cf' : 'LzmaCompres= s' - } +BinFileType =3D { + 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' +} =20 - ## The constructor - # - # @param self The object pointer - # - def __init__(self): - SectionClassObject.__init__(self) +SectValidFileType =3D {'SEC_GUID', 'SEC_PE32', 'SEC_PIC', 'SEC_TE', 'SEC_V= ER', 'SEC_UI', 'SEC_COMPAT16', 'SEC_BIN'} =20 - ## 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 sect= ion data - # @param Dict dictionary contains macro and its value - # - def GenSection(self, OutputPath, GuidName, SecNum, keyStringList, FfsI= nf =3D None, Dict =3D {}): - 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 =3D {}, IsMakefi= le=3DFalse): - IsSect =3D 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 =3D {}, IsMak= efile=3DFalse): + IsSect =3D FileType in SectValidFileType =20 - if FileExtension is not None: - Suffix =3D FileExtension - elif IsSect : - Suffix =3D Section.SectionType.get(FileType) - else: - Suffix =3D Section.BinFileType.get(FileType) - if FfsInf is None: - EdkLogger.error("GenFds", GENFDS_ERROR, 'Inf File does not exi= st!') + if FileExtension: + Suffix =3D FileExtension + elif IsSect: + Suffix =3D SectionType.get(FileType) + else: + Suffix =3D BinFileType.get(FileType) + if FfsInf is None: + EdkLogger.error("GenFds", GENFDS_ERROR, 'Inf File does not exist!') =20 - FileList =3D [] - if FileType is not None: - for File in FfsInf.BinFileList: - if File.Arch =3D=3D TAB_ARCH_COMMON or FfsInf.CurrentArch = =3D=3D File.Arch: - if File.Type =3D=3D FileType or (int(FfsInf.PiSpecVers= ion, 16) >=3D 0x0001000A \ - and FileType =3D=3D 'DXE_= DPEX' and File.Type =3D=3D BINARY_FILE_TYPE_SMM_DEPEX) \ - or (FileType =3D=3D BINAR= Y_FILE_TYPE_TE and File.Type =3D=3D BINARY_FILE_TYPE_PE32): - if '*' in FfsInf.TargetOverrideList or File.Target= =3D=3D '*' or File.Target in FfsInf.TargetOverrideList or FfsInf.TargetOve= rrideList =3D=3D []: - FileList.append(FfsInf.PatchEfiFile(File.Path,= File.Type)) - else: - GenFdsGlobalVariable.InfLogger ("\nBuild Targe= t \'%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 =3D [] + if FileType is not None: + for File in FfsInf.BinFileList: + if File.Arch =3D=3D TAB_ARCH_COMMON or FfsInf.CurrentArch =3D= =3D File.Arch: + if File.Type =3D=3D FileType or (int(FfsInf.PiSpecVersion,= 16) >=3D 0x0001000A \ + and FileType =3D=3D 'DXE_DPEX= ' and File.Type =3D=3D BINARY_FILE_TYPE_SMM_DEPEX) \ + or (FileType =3D=3D BINARY_FI= LE_TYPE_TE and File.Type =3D=3D BINARY_FILE_TYPE_PE32): + if '*' in FfsInf.TargetOverrideList or File.Target =3D= =3D '*' or File.Target in FfsInf.TargetOverrideList or FfsInf.TargetOverrid= eList =3D=3D []: + FileList.append(FfsInf.PatchEfiFile(File.Path, Fil= e.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" %(Fil= e.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 F= DF" %(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" %(Fi= le.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)) =20 - if (not IsMakefile and Suffix is not None and os.path.exists(FfsIn= f.EfiOutputPath)) or (IsMakefile and Suffix is not None): - # - # Get Makefile path and time stamp - # - MakefileDir =3D FfsInf.EfiOutputPath[:-len('OUTPUT')] - Makefile =3D os.path.join(MakefileDir, 'Makefile') - if not os.path.exists(Makefile): - Makefile =3D os.path.join(MakefileDir, 'GNUmakefile') - if os.path.exists(Makefile): - # Update to search files with suffix in all sub-dirs. - Tuple =3D os.walk(FfsInf.EfiOutputPath) - for Dirpath, Dirnames, Filenames in Tuple: - for F in Filenames: - if os.path.splitext(F)[1] =3D=3D Suffix: - FullName =3D os.path.join(Dirpath, F) - if os.path.getmtime(FullName) > os.path.getmti= me(Makefile): - FileList.append(FullName) - if not FileList: - SuffixMap =3D FfsInf.GetFinalTargetSuffixMap() - if Suffix in SuffixMap: - FileList.extend(SuffixMap[Suffix]) - =20 - #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.Ef= iOutputPath)) or (IsMakefile and Suffix is not None): + # + # Get Makefile path and time stamp + # + MakefileDir =3D FfsInf.EfiOutputPath[:-len('OUTPUT')] + Makefile =3D os.path.join(MakefileDir, 'Makefile') + if not os.path.exists(Makefile): + Makefile =3D os.path.join(MakefileDir, 'GNUmakefile') + if os.path.exists(Makefile): + # Update to search files with suffix in all sub-dirs. + Tuple =3D os.walk(FfsInf.EfiOutputPath) + for Dirpath, Dirnames, Filenames in Tuple: + for F in Filenames: + if os.path.splitext(F)[1] =3D=3D Suffix: + FullName =3D os.path.join(Dirpath, F) + if os.path.getmtime(FullName) > os.path.getmtime(M= akefile): + FileList.append(FullName) + if not FileList: + SuffixMap =3D FfsInf.GetFinalTargetSuffixMap() + if Suffix in SuffixMap: + FileList.extend(SuffixMap[Suffix]) + =20 + #Process the file lists is alphabetical for a same section type + if len (FileList) > 1: + FileList.sort() =20 - return FileList, IsSect - GetFileList =3D 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 =3D FfsInf.__ExtendMacro__(self.Alignment) self.StringData =3D FfsInf.__ExtendMacro__(self.StringData) self.FileName =3D FfsInf.__ExtendMacro__(self.FileName) =20 - OutputFile =3D os.path.join(OutputPath, ModuleName + 'SEC' + SecNu= m + SectionSuffix['UI']) + OutputFile =3D os.path.join(OutputPath, ModuleName + TAB_SEC_DIREC= TORY + SecNum + SectionSuffix['UI']) =20 - if self.StringData is not None : + if self.StringData: NameString =3D self.StringData - elif self.FileName is not None: + elif self.FileName: FileNameStr =3D GenFdsGlobalVariable.ReplaceWorkspaceMacro(sel= f.FileName) FileNameStr =3D GenFdsGlobalVariable.MacroExtend(FileNameStr, = Dict) - FileObj =3D open(FileNameStr, 'r') - NameString =3D FileObj.read() - FileObj.close() + with open(FileNameStr, 'r') as FileObj: + NameString =3D FileObj.read() else: NameString =3D '' GenFdsGlobalVariable.GenerateSection(OutputFile, None, 'EFI_SECTIO= N_USER_INTERFACE', Ui=3DNameString, IsMakefile=3DIsMakefile) =20 - OutputFileList =3D [] - OutputFileList.append(OutputFile) - return OutputFileList, self.Alignment + return [OutputFile], self.Alignment diff --git a/BaseTools/Source/Python/GenFds/VerSection.py b/BaseTools/Sourc= e/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 =20 ## generate version section # @@ -53,31 +52,26 @@ class VerSection (VerSectionClassObject): # # Prepare the parameter of GenSection # - if FfsInf is not None: + if FfsInf: self.Alignment =3D FfsInf.__ExtendMacro__(self.Alignment) self.BuildNum =3D FfsInf.__ExtendMacro__(self.BuildNum) self.StringData =3D FfsInf.__ExtendMacro__(self.StringData) self.FileName =3D FfsInf.__ExtendMacro__(self.FileName) =20 OutputFile =3D os.path.join(OutputPath, - ModuleName + 'SEC' + SecNum + SectionSuf= fix['VERSION']) + ModuleName + TAB_SEC_DIRECTORY + SecNum = + SectionSuffix['VERSION']) OutputFile =3D os.path.normpath(OutputFile) =20 # Get String Data - StringData =3D '' - if self.StringData is not None: + if self.StringData: StringData =3D self.StringData - elif self.FileName is not None: + elif self.FileName: FileNameStr =3D GenFdsGlobalVariable.ReplaceWorkspaceMacro(sel= f.FileName) FileNameStr =3D GenFdsGlobalVariable.MacroExtend(FileNameStr, = Dict) - FileObj =3D open(FileNameStr, 'r') - StringData =3D FileObj.read() - StringData =3D '"' + StringData + '"' - FileObj.close() + with open(FileNameStr, 'r') as FileObj: + StringData =3D '"' + FileObj.read() + '"' else: StringData =3D '' GenFdsGlobalVariable.GenerateSection(OutputFile, [], 'EFI_SECTION_= VERSION', Ver=3DStringData, BuildNumber= =3Dself.BuildNum, IsMakefile=3DIsMakefile) - OutputFileList =3D [] - OutputFileList.append(OutputFile) - return OutputFileList, self.Alignment + return [OutputFile], self.Alignment --=20 2.16.2.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel