From a09f4c91f785e36f0987aa3a6d7656ba51e6aeda Mon Sep 17 00:00:00 2001 From: Yunhua Feng Date: Fri, 27 Jul 2018 16:02:05 +0800 Subject: BaseTools: fix the open file's read and write bugs Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Yunhua Feng Reviewed-by: Liming Gao --- BaseTools/Source/Python/AutoGen/GenMake.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'BaseTools/Source/Python/AutoGen/GenMake.py') diff --git a/BaseTools/Source/Python/AutoGen/GenMake.py b/BaseTools/Source/Python/AutoGen/GenMake.py index 75b4e2247a..b168a6663d 100644 --- a/BaseTools/Source/Python/AutoGen/GenMake.py +++ b/BaseTools/Source/Python/AutoGen/GenMake.py @@ -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() -- cgit v1.2.3