]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools/UPT: UPT to Support UTF-8
authorHess Chen <hesheng.chen@intel.com>
Fri, 22 Apr 2016 05:23:38 +0000 (13:23 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Tue, 26 Apr 2016 04:02:02 +0000 (12:02 +0800)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hess Chen <hesheng.chen@intel.com>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
BaseTools/Source/Python/UPT/Library/UniClassObject.py

index c57bfdf57d9fcf4f95bc4c45505c3dcc31bdfcef..1e73d3e9a8d9ea3991f5003afc28fd76510df471 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # Collect all defined strings in multiple uni files.\r
 #\r
-# Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.<BR>\r
 #\r
 # This program and the accompanying materials are licensed and made available \r
 # under the terms and conditions of the BSD License which accompanies this \r
@@ -328,6 +328,8 @@ class UniFileClassObject(object):
         Lang = distutils.util.split_quoted((Line.split(u"//")[0]))\r
         if len(Lang) != 3:\r
             try:\r
+                FileIn = codecs.open(File.Path, mode='rb', encoding='utf_8').read()\r
+            except UnicodeError, Xstr:\r
                 FileIn = codecs.open(File.Path, mode='rb', encoding='utf_16').read()\r
             except UnicodeError, Xstr:\r
                 FileIn = codecs.open(File.Path, mode='rb', encoding='utf_16_le').read()\r
@@ -430,11 +432,13 @@ class UniFileClassObject(object):
         #\r
         # Check file header of the Uni file\r
         #\r
-        if not CheckUTF16FileHeader(File.Path):\r
-            EdkLogger.Error("Unicode File Parser", ToolError.FORMAT_INVALID,\r
-                            ExtraData='The file %s is either invalid UTF-16LE or it is missing the BOM.' % File.Path)\r
+        if not CheckUTF16FileHeader(File.Path):\r
+            EdkLogger.Error("Unicode File Parser", ToolError.FORMAT_INVALID,\r
+                            ExtraData='The file %s is either invalid UTF-16LE or it is missing the BOM.' % File.Path)\r
 \r
         try:\r
+            FileIn = codecs.open(File.Path, mode='rb', encoding='utf_8').read()\r
+        except UnicodeError, Xstr:\r
             FileIn = codecs.open(File.Path, mode='rb', encoding='utf_16').readlines()\r
         except UnicodeError:\r
             FileIn = codecs.open(File.Path, mode='rb', encoding='utf_16_le').readlines()\r
@@ -1046,6 +1050,8 @@ class UniFileClassObject(object):
                              ToolError.FILE_NOT_FOUND,\r
                              ExtraData=FilaPath)\r
         try:\r
+            FileIn = codecs.open(FilaPath, mode='rb', encoding='utf_8').read()\r
+        except UnicodeError, Xstr:\r
             FileIn = codecs.open(FilaPath, mode='rb', encoding='utf_16').readlines()\r
         except UnicodeError:\r
             FileIn = codecs.open(FilaPath, mode='rb', encoding='utf_16_le').readlines()\r