From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.120, mailfrom: bob.c.feng@intel.com) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by groups.io with SMTP; Tue, 10 Sep 2019 02:17:15 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Sep 2019 02:17:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,489,1559545200"; d="scan'208";a="189285062" Received: from shwdepsi1121.ccr.corp.intel.com ([10.239.158.47]) by orsmga006.jf.intel.com with ESMTP; 10 Sep 2019 02:17:13 -0700 From: "Bob Feng" To: devel@edk2.groups.io Cc: Liming Gao , Bob Feng Subject: [Patch 2/3] BaseTools: remove unnecessary calls of os.exist Date: Tue, 10 Sep 2019 17:17:06 +0800 Message-Id: <20190910091706.4060-1-bob.c.feng@intel.com> X-Mailer: git-send-email 2.20.1.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2101 This patch is going to remove unnecessary calls of os.exist() Cc: Liming Gao Signed-off-by: Bob Feng --- .../Source/Python/AutoGen/AutoGenWorker.py | 7 +- BaseTools/Source/Python/AutoGen/GenC.py | 97 ++++++++++--------- BaseTools/Source/Python/AutoGen/GenMake.py | 6 +- .../Source/Python/AutoGen/PlatformAutoGen.py | 8 +- .../Source/Python/AutoGen/UniClassObject.py | 5 +- 5 files changed, 63 insertions(+), 60 deletions(-) diff --git a/BaseTools/Source/Python/AutoGen/AutoGenWorker.py b/BaseTools/Source/Python/AutoGen/AutoGenWorker.py index f488ae9d5f80..79069d603eb9 100755 --- a/BaseTools/Source/Python/AutoGen/AutoGenWorker.py +++ b/BaseTools/Source/Python/AutoGen/AutoGenWorker.py @@ -153,14 +153,15 @@ class AutoGenWorkerInProcess(mp.Process): return self.PlatformMetaFileSet[(filepath,root)] def run(self): try: taskname = "Init" with self.file_lock: - if not os.path.exists(self.data_pipe_file_path): + try: + self.data_pipe = MemoryDataPipe() + self.data_pipe.load(self.data_pipe_file_path) + except: self.feedback_q.put(taskname + ":" + "load data pipe %s failed." % self.data_pipe_file_path) - self.data_pipe = MemoryDataPipe() - self.data_pipe.load(self.data_pipe_file_path) EdkLogger.LogClientInitialize(self.log_q) loglevel = self.data_pipe.Get("LogLevel") if not loglevel: loglevel = EdkLogger.INFO EdkLogger.SetLevel(loglevel) diff --git a/BaseTools/Source/Python/AutoGen/GenC.py b/BaseTools/Source/Python/AutoGen/GenC.py index 910c8fe3706c..5e0d11e165a3 100755 --- a/BaseTools/Source/Python/AutoGen/GenC.py +++ b/BaseTools/Source/Python/AutoGen/GenC.py @@ -1746,63 +1746,64 @@ def CreateIdfFileCode(Info, AutoGenC, StringH, IdfGenCFlag, IdfGenBinBuffer): EdkLogger.error("build", AUTOGEN_ERROR, "The %s in %s is not defined in the driver's [Sources] section" % (FileObj.FileName, Idf), ExtraData="[%s]" % str(Info)) for FileObj in ImageFiles.ImageFilesDict[Idf]: ID = FileObj.ImageID File = FileObj.File - if not os.path.exists(File.Path) or not os.path.isfile(File.Path): - EdkLogger.error("build", FILE_NOT_FOUND, ExtraData=File.Path) - SearchImageID (FileObj, FileList) - if FileObj.Referenced: - if (ValueStartPtr - len(DEFINE_STR + ID)) <= 0: - Line = DEFINE_STR + ' ' + ID + ' ' + DecToHexStr(Index, 4) + '\n' - else: - Line = DEFINE_STR + ' ' + ID + ' ' * (ValueStartPtr - len(DEFINE_STR + ID)) + DecToHexStr(Index, 4) + '\n' + try: + SearchImageID (FileObj, FileList) + if FileObj.Referenced: + if (ValueStartPtr - len(DEFINE_STR + ID)) <= 0: + Line = DEFINE_STR + ' ' + ID + ' ' + DecToHexStr(Index, 4) + '\n' + else: + Line = DEFINE_STR + ' ' + ID + ' ' * (ValueStartPtr - len(DEFINE_STR + ID)) + DecToHexStr(Index, 4) + '\n' - if File not in FileDict: - FileDict[File] = Index - else: - DuplicateBlock = pack('B', EFI_HII_IIBT_DUPLICATE) - DuplicateBlock += pack('H', FileDict[File]) - ImageBuffer += DuplicateBlock + if File not in FileDict: + FileDict[File] = Index + else: + DuplicateBlock = pack('B', EFI_HII_IIBT_DUPLICATE) + DuplicateBlock += pack('H', FileDict[File]) + ImageBuffer += DuplicateBlock + BufferStr = WriteLine(BufferStr, '// %s: %s: %s' % (DecToHexStr(Index, 4), ID, DecToHexStr(Index, 4))) + TempBufferList = AscToHexList(DuplicateBlock) + BufferStr = WriteLine(BufferStr, CreateArrayItem(TempBufferList, 16) + '\n') + StringH.Append(Line) + Index += 1 + continue + + TmpFile = open(File.Path, 'rb') + Buffer = TmpFile.read() + TmpFile.close() + if File.Ext.upper() == '.PNG': + TempBuffer = pack('B', EFI_HII_IIBT_IMAGE_PNG) + TempBuffer += pack('I', len(Buffer)) + TempBuffer += Buffer + elif File.Ext.upper() == '.JPG': + ImageType, = struct.unpack('4s', Buffer[6:10]) + if ImageType != b'JFIF': + EdkLogger.error("build", FILE_TYPE_MISMATCH, "The file %s is not a standard JPG file." % File.Path) + TempBuffer = pack('B', EFI_HII_IIBT_IMAGE_JPEG) + TempBuffer += pack('I', len(Buffer)) + TempBuffer += Buffer + elif File.Ext.upper() == '.BMP': + TempBuffer, TempPalette = BmpImageDecoder(File, Buffer, PaletteIndex, FileObj.TransParent) + if len(TempPalette) > 1: + PaletteIndex += 1 + NewPalette = pack('H', len(TempPalette)) + NewPalette += TempPalette + PaletteBuffer += NewPalette + PaletteStr = WriteLine(PaletteStr, '// %s: %s: %s' % (DecToHexStr(PaletteIndex - 1, 4), ID, DecToHexStr(PaletteIndex - 1, 4))) + TempPaletteList = AscToHexList(NewPalette) + PaletteStr = WriteLine(PaletteStr, CreateArrayItem(TempPaletteList, 16) + '\n') + ImageBuffer += TempBuffer BufferStr = WriteLine(BufferStr, '// %s: %s: %s' % (DecToHexStr(Index, 4), ID, DecToHexStr(Index, 4))) - TempBufferList = AscToHexList(DuplicateBlock) + TempBufferList = AscToHexList(TempBuffer) BufferStr = WriteLine(BufferStr, CreateArrayItem(TempBufferList, 16) + '\n') + StringH.Append(Line) Index += 1 - continue - - TmpFile = open(File.Path, 'rb') - Buffer = TmpFile.read() - TmpFile.close() - if File.Ext.upper() == '.PNG': - TempBuffer = pack('B', EFI_HII_IIBT_IMAGE_PNG) - TempBuffer += pack('I', len(Buffer)) - TempBuffer += Buffer - elif File.Ext.upper() == '.JPG': - ImageType, = struct.unpack('4s', Buffer[6:10]) - if ImageType != b'JFIF': - EdkLogger.error("build", FILE_TYPE_MISMATCH, "The file %s is not a standard JPG file." % File.Path) - TempBuffer = pack('B', EFI_HII_IIBT_IMAGE_JPEG) - TempBuffer += pack('I', len(Buffer)) - TempBuffer += Buffer - elif File.Ext.upper() == '.BMP': - TempBuffer, TempPalette = BmpImageDecoder(File, Buffer, PaletteIndex, FileObj.TransParent) - if len(TempPalette) > 1: - PaletteIndex += 1 - NewPalette = pack('H', len(TempPalette)) - NewPalette += TempPalette - PaletteBuffer += NewPalette - PaletteStr = WriteLine(PaletteStr, '// %s: %s: %s' % (DecToHexStr(PaletteIndex - 1, 4), ID, DecToHexStr(PaletteIndex - 1, 4))) - TempPaletteList = AscToHexList(NewPalette) - PaletteStr = WriteLine(PaletteStr, CreateArrayItem(TempPaletteList, 16) + '\n') - ImageBuffer += TempBuffer - BufferStr = WriteLine(BufferStr, '// %s: %s: %s' % (DecToHexStr(Index, 4), ID, DecToHexStr(Index, 4))) - TempBufferList = AscToHexList(TempBuffer) - BufferStr = WriteLine(BufferStr, CreateArrayItem(TempBufferList, 16) + '\n') - - StringH.Append(Line) - Index += 1 + except IOError: + EdkLogger.error("build", FILE_NOT_FOUND, ExtraData=File.Path) BufferStr = WriteLine(BufferStr, '// End of the Image Info') BufferStr = WriteLine(BufferStr, CreateArrayItem(DecToHexList(EFI_HII_IIBT_END, 2)) + '\n') ImageEnd = pack('B', EFI_HII_IIBT_END) ImageBuffer += ImageEnd diff --git a/BaseTools/Source/Python/AutoGen/GenMake.py b/BaseTools/Source/Python/AutoGen/GenMake.py index 5d02d9a05694..234ea169c923 100755 --- a/BaseTools/Source/Python/AutoGen/GenMake.py +++ b/BaseTools/Source/Python/AutoGen/GenMake.py @@ -632,15 +632,17 @@ cleanlib: current_dir = self.Macros["WORKSPACE"] found = False while not found and os.sep in package_rel_dir: index = package_rel_dir.index(os.sep) current_dir = mws.join(current_dir, package_rel_dir[:index]) - if os.path.exists(current_dir): + try: for fl in os.listdir(current_dir): if fl.endswith('.dec'): found = True break + except: + EdkLogger.error('build', FILE_NOT_FOUND, "WORKSPACE does not exist.") package_rel_dir = package_rel_dir[index + 1:] MakefileTemplateDict = { "makefile_header" : self._FILE_HEADER_[self._FileType], "makefile_path" : os.path.join("$(MODULE_BUILD_DIR)", MakefileName), @@ -1763,6 +1765,6 @@ def GetDependencyList(AutoGenObject, FileCache, File, ForceList, SearchPathList) return DependencyList # This acts like the main() function for the script, unless it is 'import'ed into another script. if __name__ == '__main__': - pass \ No newline at end of file + pass diff --git a/BaseTools/Source/Python/AutoGen/PlatformAutoGen.py b/BaseTools/Source/Python/AutoGen/PlatformAutoGen.py index 0e424ee40fb9..debeb46f5858 100644 --- a/BaseTools/Source/Python/AutoGen/PlatformAutoGen.py +++ b/BaseTools/Source/Python/AutoGen/PlatformAutoGen.py @@ -273,15 +273,15 @@ class PlatformAutoGen(AutoGen): if self.VariableInfo: VpdMapFilePath = os.path.join(self.BuildDir, TAB_FV_DIRECTORY, "%s.map" % self.Platform.VpdToolGuid) PcdNvStoreDfBuffer = [item for item in self._DynamicPcdList if item.TokenCName == "PcdNvStoreDefaultValueBuffer" and item.TokenSpaceGuidCName == "gEfiMdeModulePkgTokenSpaceGuid"] if PcdNvStoreDfBuffer: - if os.path.exists(VpdMapFilePath): + try: OrgVpdFile.Read(VpdMapFilePath) PcdItems = OrgVpdFile.GetOffset(PcdNvStoreDfBuffer[0]) NvStoreOffset = list(PcdItems.values())[0].strip() if PcdItems else '0' - else: + except: EdkLogger.error("build", FILE_READ_FAILURE, "Can not find VPD map file %s to fix up VPD offset." % VpdMapFilePath) NvStoreOffset = int(NvStoreOffset, 16) if NvStoreOffset.upper().startswith("0X") else int(NvStoreOffset) default_skuobj = PcdNvStoreDfBuffer[0].SkuInfoList.get(TAB_DEFAULT) maxsize = self.VariableInfo.VpdRegionSize - NvStoreOffset if self.VariableInfo.VpdRegionSize else len(default_skuobj.DefaultValue.split(",")) @@ -663,11 +663,11 @@ class PlatformAutoGen(AutoGen): VpdSkuMap[(PcdName,PcdGuid)] = {DefaultSku.DefaultValue:[SkuObj for SkuObj in PcdNvStoreDfBuffer[0].SkuInfoList.values() ]} # Process VPD map file generated by third party BPDG tool if NeedProcessVpdMapFile: VpdMapFilePath = os.path.join(self.BuildDir, TAB_FV_DIRECTORY, "%s.map" % self.Platform.VpdToolGuid) - if os.path.exists(VpdMapFilePath): + try: VpdFile.Read(VpdMapFilePath) # Fixup TAB_STAR offset for pcd in VpdSkuMap: vpdinfo = VpdFile.GetVpdInfo(pcd) @@ -677,11 +677,11 @@ class PlatformAutoGen(AutoGen): for pcdvalue in VpdSkuMap[pcd]: for sku in VpdSkuMap[pcd][pcdvalue]: for item in vpdinfo: if item[2] == pcdvalue: sku.VpdOffset = item[1] - else: + except: EdkLogger.error("build", FILE_READ_FAILURE, "Can not find VPD map file %s to fix up VPD offset." % VpdMapFilePath) # Delete the DynamicPcdList At the last time enter into this function for Pcd in self._DynamicPcdList: # just pick the a value to determine whether is unicode string type diff --git a/BaseTools/Source/Python/AutoGen/UniClassObject.py b/BaseTools/Source/Python/AutoGen/UniClassObject.py index 9f6a2715668c..b2895f7e5c63 100644 --- a/BaseTools/Source/Python/AutoGen/UniClassObject.py +++ b/BaseTools/Source/Python/AutoGen/UniClassObject.py @@ -369,17 +369,16 @@ class UniFileClassObject(object): # # Pre-process before parse .uni file # def PreProcess(self, File): - if not os.path.exists(File.Path) or not os.path.isfile(File.Path): - EdkLogger.error("Unicode File Parser", FILE_NOT_FOUND, ExtraData=File.Path) - try: FileIn = UniFileClassObject.OpenUniFile(LongFilePath(File.Path)) except UnicodeError as X: EdkLogger.error("build", FILE_READ_FAILURE, "File read failure: %s" % str(X), ExtraData=File.Path); + except OSError: + EdkLogger.error("Unicode File Parser", FILE_NOT_FOUND, ExtraData=File.Path) except: EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData=File.Path); Lines = [] # -- 2.20.1.windows.1