mirror of https://github.com/acidanthera/audk.git
BaseTools: remove unnecessary calls of os.exist
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2101 This patch is going to remove unnecessary calls of os.exist() Cc: Liming Gao <liming.gao@intel.com> Signed-off-by: Bob Feng <bob.c.feng@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
This commit is contained in:
parent
bc9e4194cf
commit
0075ab2cec
|
@ -155,10 +155,11 @@ class AutoGenWorkerInProcess(mp.Process):
|
|||
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:
|
||||
|
|
|
@ -1748,59 +1748,60 @@ def CreateIdfFileCode(Info, AutoGenC, StringH, IdfGenCFlag, IdfGenBinBuffer):
|
|||
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')
|
||||
|
|
|
@ -636,11 +636,13 @@ cleanlib:
|
|||
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 = {
|
||||
|
|
|
@ -275,11 +275,11 @@ class PlatformAutoGen(AutoGen):
|
|||
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)
|
||||
|
@ -665,7 +665,7 @@ class PlatformAutoGen(AutoGen):
|
|||
# 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
|
||||
|
@ -679,7 +679,7 @@ class PlatformAutoGen(AutoGen):
|
|||
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
|
||||
|
|
|
@ -371,13 +371,12 @@ 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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue