BaseTools: fix the open file's read and write bugs

Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yunhua Feng <yunhuax.feng@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
This commit is contained in:
Yunhua Feng
2018-07-27 16:02:05 +08:00
committed by Yonghong Zhu
parent fe3991d635
commit a09f4c91f7
7 changed files with 38 additions and 20 deletions

View File

@ -1031,7 +1031,7 @@ cleanlib:
CurrentFileDependencyList = DepDb[F]
else:
try:
Fd = open(F.Path, 'r')
Fd = open(F.Path, 'rb')
except BaseException as X:
EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData=F.Path + "\n\t" + str(X))
@ -1041,8 +1041,14 @@ cleanlib:
continue
if FileContent[0] == 0xff or FileContent[0] == 0xfe:
FileContent = unicode(FileContent, "utf-16")
IncludedFileList = gIncludePattern.findall(FileContent)
FileContent = str(FileContent, encoding="utf-16")
IncludedFileList = gIncludePattern.findall(FileContent)
else:
try:
FileContent = str(FileContent, encoding="utf-8")
IncludedFileList = gIncludePattern.findall(FileContent)
except:
continue
for Inc in IncludedFileList:
Inc = Inc.strip()