]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/UPT/Library/UniClassObject.py
BaseTools/Upt: Add a BOM check for UNI file and fix some help message error
[mirror_edk2.git] / BaseTools / Source / Python / UPT / Library / UniClassObject.py
index 332ae273c78eb0eb3ef7cd04f206ac68f69361c3..c57bfdf57d9fcf4f95bc4c45505c3dcc31bdfcef 100644 (file)
@@ -27,6 +27,7 @@ from Library.String import GetLineNo
 from Library.Misc import PathClass\r
 from Library.Misc import GetCharIndexOutStr\r
 from Library import DataType as DT\r
+from Library.ParserValidate import CheckUTF16FileHeader\r
 \r
 ##\r
 # Static definitions\r
@@ -136,6 +137,8 @@ def ConvertSpecialUnicodes(Uni):
 # @retval LangName:  Valid lanugage code in RFC 1766 format or None\r
 #\r
 def GetLanguageCode1766(LangName, File=None):\r
+    return LangName\r
+\r
     length = len(LangName)\r
     if length == 2:\r
         if LangName.isalpha():\r
@@ -424,6 +427,13 @@ class UniFileClassObject(object):
                              ToolError.FILE_NOT_FOUND,\r
                              ExtraData=File.Path)\r
 \r
+        #\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
+\r
         try:\r
             FileIn = codecs.open(File.Path, mode='rb', encoding='utf_16').readlines()\r
         except UnicodeError:\r
@@ -570,11 +580,13 @@ class UniFileClassObject(object):
                      \r
                 StringEntryExistsFlag = 1\r
                 if not Line.endswith('"'):\r
-                    EdkLogger.Error("Unicode File Parser", ToolError.FORMAT_INVALID, ExtraData=File.Path)\r
+                    EdkLogger.Error("Unicode File Parser", ToolError.FORMAT_INVALID,\r
+                                    ExtraData='''The line %s misses '"' at the end of it in file %s'''\r
+                                              % (LineCount, File.Path))\r
             elif Line.startswith(u'#language'):\r
                 if StringEntryExistsFlag == 2:\r
                     EdkLogger.Error("Unicode File Parser", ToolError.FORMAT_INVALID, \r
-                                    Message=ST.ERR_UNIPARSE_LINEFEED_UP_EXIST % Line, ExtraData=File.Path)\r
+                                    Message=ST.ERR_UNI_MISS_STRING_ENTRY % Line, ExtraData=File.Path)\r
                 StringEntryExistsFlag = 0\r
             else:\r
                 StringEntryExistsFlag = 0\r