From 5f2d72936be6f8d426a1443fcce8de21a16a2ae5 Mon Sep 17 00:00:00 2001 From: Hess Chen Date: Fri, 22 Apr 2016 13:23:38 +0800 Subject: BaseTools/UPT: UPT to Support UTF-8 Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hess Chen Reviewed-by: Yonghong Zhu (cherry picked from commit 4a21fb3b67a0ef1655b43e9368b6b697bbf327af) --- BaseTools/Source/Python/UPT/Library/UniClassObject.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'BaseTools/Source') diff --git a/BaseTools/Source/Python/UPT/Library/UniClassObject.py b/BaseTools/Source/Python/UPT/Library/UniClassObject.py index c57bfdf57d..1e73d3e9a8 100644 --- a/BaseTools/Source/Python/UPT/Library/UniClassObject.py +++ b/BaseTools/Source/Python/UPT/Library/UniClassObject.py @@ -1,7 +1,7 @@ ## @file # Collect all defined strings in multiple uni files. # -# Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.
+# Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.
# # This program and the accompanying materials are licensed and made available # under the terms and conditions of the BSD License which accompanies this @@ -328,6 +328,8 @@ class UniFileClassObject(object): Lang = distutils.util.split_quoted((Line.split(u"//")[0])) if len(Lang) != 3: try: + FileIn = codecs.open(File.Path, mode='rb', encoding='utf_8').read() + except UnicodeError, Xstr: FileIn = codecs.open(File.Path, mode='rb', encoding='utf_16').read() except UnicodeError, Xstr: FileIn = codecs.open(File.Path, mode='rb', encoding='utf_16_le').read() @@ -430,11 +432,13 @@ class UniFileClassObject(object): # # Check file header of the Uni file # - if not CheckUTF16FileHeader(File.Path): - EdkLogger.Error("Unicode File Parser", ToolError.FORMAT_INVALID, - ExtraData='The file %s is either invalid UTF-16LE or it is missing the BOM.' % File.Path) +# if not CheckUTF16FileHeader(File.Path): +# EdkLogger.Error("Unicode File Parser", ToolError.FORMAT_INVALID, +# ExtraData='The file %s is either invalid UTF-16LE or it is missing the BOM.' % File.Path) try: + FileIn = codecs.open(File.Path, mode='rb', encoding='utf_8').read() + except UnicodeError, Xstr: FileIn = codecs.open(File.Path, mode='rb', encoding='utf_16').readlines() except UnicodeError: FileIn = codecs.open(File.Path, mode='rb', encoding='utf_16_le').readlines() @@ -1046,6 +1050,8 @@ class UniFileClassObject(object): ToolError.FILE_NOT_FOUND, ExtraData=FilaPath) try: + FileIn = codecs.open(FilaPath, mode='rb', encoding='utf_8').read() + except UnicodeError, Xstr: FileIn = codecs.open(FilaPath, mode='rb', encoding='utf_16').readlines() except UnicodeError: FileIn = codecs.open(FilaPath, mode='rb', encoding='utf_16_le').readlines() -- cgit v1.2.3