Revision: 17876
          http://sourceforge.net/p/edk2/code/17876
Author:   hchen30
Date:     2015-07-08 05:43:22 +0000 (Wed, 08 Jul 2015)
Log Message:
-----------
BaseTools/Upt: Add a BOM check for UNI file and fix some help message error

Add a BOM check for UNI file and fix some help message error

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hess Chen <[email protected]>
Reviewed-by: YangX Li <[email protected]>

Modified Paths:
--------------
    trunk/edk2/BaseTools/Source/Python/UPT/Library/ParserValidate.py
    trunk/edk2/BaseTools/Source/Python/UPT/Library/UniClassObject.py
    trunk/edk2/BaseTools/Source/Python/UPT/Logger/StringTable.py

Modified: trunk/edk2/BaseTools/Source/Python/UPT/Library/ParserValidate.py
===================================================================
--- trunk/edk2/BaseTools/Source/Python/UPT/Library/ParserValidate.py    
2015-07-08 03:12:58 UTC (rev 17875)
+++ trunk/edk2/BaseTools/Source/Python/UPT/Library/ParserValidate.py    
2015-07-08 05:43:22 UTC (rev 17876)
@@ -721,3 +721,12 @@
             return False
     return True
 
+#
+# Check if a UTF16-LE file has a BOM header
+#
+def CheckUTF16FileHeader(File):
+    FileIn = open(File, 'rb').read(2)
+    if FileIn != '\xff\xfe':
+        return False
+
+    return True

Modified: trunk/edk2/BaseTools/Source/Python/UPT/Library/UniClassObject.py
===================================================================
--- trunk/edk2/BaseTools/Source/Python/UPT/Library/UniClassObject.py    
2015-07-08 03:12:58 UTC (rev 17875)
+++ trunk/edk2/BaseTools/Source/Python/UPT/Library/UniClassObject.py    
2015-07-08 05:43:22 UTC (rev 17876)
@@ -27,6 +27,7 @@
 from Library.Misc import PathClass
 from Library.Misc import GetCharIndexOutStr
 from Library import DataType as DT
+from Library.ParserValidate import CheckUTF16FileHeader
 
 ##
 # Static definitions
@@ -136,6 +137,8 @@
 # @retval LangName:  Valid lanugage code in RFC 1766 format or None
 #
 def GetLanguageCode1766(LangName, File=None):
+    return LangName
+
     length = len(LangName)
     if length == 2:
         if LangName.isalpha():
@@ -424,6 +427,13 @@
                              ToolError.FILE_NOT_FOUND,
                              ExtraData=File.Path)
 
+        #
+        # 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)
+
         try:
             FileIn = codecs.open(File.Path, mode='rb', 
encoding='utf_16').readlines()
         except UnicodeError:
@@ -570,11 +580,13 @@
                      
                 StringEntryExistsFlag = 1
                 if not Line.endswith('"'):
-                    EdkLogger.Error("Unicode File Parser", 
ToolError.FORMAT_INVALID, ExtraData=File.Path)
+                    EdkLogger.Error("Unicode File Parser", 
ToolError.FORMAT_INVALID,
+                                    ExtraData='''The line %s misses '"' at the 
end of it in file %s'''
+                                              % (LineCount, File.Path))
             elif Line.startswith(u'#language'):
                 if StringEntryExistsFlag == 2:
                     EdkLogger.Error("Unicode File Parser", 
ToolError.FORMAT_INVALID, 
-                                    Message=ST.ERR_UNIPARSE_LINEFEED_UP_EXIST 
% Line, ExtraData=File.Path)
+                                    Message=ST.ERR_UNI_MISS_STRING_ENTRY % 
Line, ExtraData=File.Path)
                 StringEntryExistsFlag = 0
             else:
                 StringEntryExistsFlag = 0

Modified: trunk/edk2/BaseTools/Source/Python/UPT/Logger/StringTable.py
===================================================================
--- trunk/edk2/BaseTools/Source/Python/UPT/Logger/StringTable.py        
2015-07-08 03:12:58 UTC (rev 17875)
+++ trunk/edk2/BaseTools/Source/Python/UPT/Logger/StringTable.py        
2015-07-08 05:43:22 UTC (rev 17876)
@@ -46,9 +46,12 @@
 MSG_VERSION_COPYRIGHT = _("\n  %s\n  %s" % (MSG_VERSION, MSG_COPYRIGHT))
 MSG_USAGE = _("%s [options]\n%s" % ("UPT", MSG_VERSION_COPYRIGHT))
 MSG_DESCRIPTION = _("The UEFIUPT is used to create, " + \
-                    "install or remove a UEFI Distribution Package.")
+                    "install or remove a UEFI Distribution Package. " + \
+                    "If WORKSPACE environment variable is present, " + \
+                    "then UPT will install packages to the location specified 
by WORKSPACE, " + \
+                    "otherwise UPT will install packages to the current 
directory. " + \
+                    "Option -n will override this default installation 
location")
 
-
 #
 # INF Parser related strings.
 #
@@ -593,6 +596,7 @@
 ERR_UNIPARSE_STRTOKEN_FORMAT_ERROR = _("The String Token Type %s must be one 
of the '_PROMPT', '_HELP' and '_ERR_'.") 
 ERR_UNIPARSE_LINEFEED_UNDER_EXIST = _("Line feed should not exist under this 
line: %s.")
 ERR_UNIPARSE_LINEFEED_UP_EXIST = _("Line feed should not exist up this line: 
%s.")
+ERR_UNI_MISS_STRING_ENTRY = _("String entry missed in this Entry, %s.")
 ERR_UNI_MISS_LANGENTRY = _("Language entry missed in this Entry, %s.")
 ERR_BINARY_HEADER_ORDER           = _("Binary header must follow the file 
header.")
 ERR_NO_SOURCE_HEADER              = _("File header statement \"## @file\" must 
exist at the first place.")


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to