]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Ecc/MetaFileWorkspace/MetaFileParser.py
BaseTools/Ecc: Add a checkpoint for invalid UNI file.
[mirror_edk2.git] / BaseTools / Source / Python / Ecc / MetaFileWorkspace / MetaFileParser.py
index 9f31d4d4de07a7386c2e35c5445467562c621241..dbe7f2a2960555949729cea5be4b4a0fcebe6ab9 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # This file is used to parse meta files\r
 #\r
-# Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2008 - 2015, Intel Corporation. All rights reserved.<BR>\r
 # This program and the accompanying materials\r
 # are licensed and made available under the terms and conditions of the BSD License\r
 # which accompanies this distribution.  The full text of the license may be found at\r
@@ -33,6 +33,7 @@ from CommonDataClass.Exceptions import *
 from MetaFileTable import MetaFileStorage\r
 from GenFds.FdfParser import FdfParser\r
 from Common.LongFilePathSupport import OpenLongFilePath as open\r
+from Common.LongFilePathSupport import CodecOpenLongFilePath\r
 \r
 ## A decorator used to parse macro definition\r
 def ParseMacro(Parser):\r
@@ -174,6 +175,9 @@ class MetaFileParser(object):
         self._PostProcessed = False\r
         # Different version of meta-file has different way to parse.\r
         self._Version = 0\r
+        # UNI object and extra UNI object\r
+        self._UniObj = None\r
+        self._UniExtraObj = None\r
 \r
     ## Store the parsed data in table\r
     def _Store(self, *Args):\r
@@ -258,8 +262,16 @@ class MetaFileParser(object):
 \r
     ## Skip unsupported data\r
     def _Skip(self):\r
-        EdkLogger.warn("Parser", "Unrecognized content", File=self.MetaFile,\r
-                        Line=self._LineIndex+1, ExtraData=self._CurrentLine);\r
+        if self._SectionName == TAB_USER_EXTENSIONS.upper() and self._CurrentLine.upper().endswith('.UNI'):\r
+            if EccGlobalData.gConfig.UniCheckHelpInfo == '1' or EccGlobalData.gConfig.UniCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
+                ExtraUni = self._CurrentLine.strip()\r
+                ExtraUniFile = os.path.join(os.path.dirname(self.MetaFile), ExtraUni)\r
+                IsModuleUni = self.MetaFile.upper().endswith('.INF')\r
+                self._UniExtraObj = UniParser(ExtraUniFile, IsExtraUni=True, IsModuleUni=IsModuleUni)\r
+                self._UniExtraObj.Start()\r
+        else:\r
+            EdkLogger.warn("Parser", "Unrecognized content", File=self.MetaFile,\r
+                            Line=self._LineIndex + 1, ExtraData=self._CurrentLine);\r
         self._ValueList[0:1] = [self._CurrentLine]\r
 \r
     ## Section header parser\r
@@ -328,7 +340,20 @@ class MetaFileParser(object):
             except:\r
                 EdkLogger.error('Parser', FORMAT_INVALID, "Invalid version number",\r
                                 ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1)\r
-\r
+        elif Name == 'MODULE_UNI_FILE':\r
+            UniFile = os.path.join(os.path.dirname(self.MetaFile), Value)\r
+            if os.path.exists(UniFile):\r
+                self._UniObj = UniParser(UniFile, IsExtraUni=False, IsModuleUni=True)\r
+                self._UniObj.Start()\r
+            else:\r
+                EdkLogger.error('Parser', FILE_NOT_FOUND, "Module UNI file %s is missing." % Value,\r
+                                ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1,\r
+                                RaiseError=False)\r
+        elif Name == 'PACKAGE_UNI_FILE':\r
+            UniFile = os.path.join(os.path.dirname(self.MetaFile), Value)\r
+            if os.path.exists(UniFile):\r
+                self._UniObj = UniParser(UniFile, IsExtraUni=False, IsModuleUni=False)\r
+        \r
         if type(self) == InfParser and self._Version < 0x00010005:\r
             # EDK module allows using defines as macros\r
             self._FileLocalMacros[Name] = Value\r
@@ -1873,6 +1898,69 @@ class Fdf(FdfObject):
                 BelongsToFile = self.InsertFile(FileName)\r
                 self.TblFdf.Insert(Model, Value1, Value2, Value3, Scope1, Scope2, BelongsToItem, BelongsToFile, StartLine, StartColumn, EndLine, EndColumn, Enabled)\r
 \r
+class UniParser(object):\r
+    # IsExtraUni defined the UNI file is Module UNI or extra Module UNI\r
+    # IsModuleUni defined the UNI file is Module UNI or Package UNI\r
+    def __init__(self, FilePath, IsExtraUni=False, IsModuleUni=True):\r
+        self.FilePath = FilePath\r
+        self.FileName = os.path.basename(FilePath)\r
+        self.IsExtraUni = IsExtraUni\r
+        self.IsModuleUni = IsModuleUni\r
+        self.FileIn = None\r
+        self.Missing = []\r
+        self.__read()\r
+    \r
+    def __read(self):\r
+        try:\r
+            self.FileIn = CodecOpenLongFilePath(self.FilePath, Mode = 'rb', Encoding = 'utf_16').read()\r
+        except UnicodeError:\r
+            self.FileIn = CodecOpenLongFilePath(self.FilePath, Mode = 'rb', Encoding = 'utf_16_le').read()\r
+        except IOError:\r
+            self.FileIn = ""\r
+    \r
+    def Start(self):\r
+        if self.IsModuleUni:\r
+            if self.IsExtraUni:\r
+                ModuleName = self.CheckKeyValid('STR_PROPERTIES_MODULE_NAME')\r
+                self.PrintLog('STR_PROPERTIES_MODULE_NAME', ModuleName)\r
+            else:\r
+                ModuleAbstract = self.CheckKeyValid('STR_MODULE_ABSTRACT')\r
+                self.PrintLog('STR_MODULE_ABSTRACT', ModuleAbstract)\r
+                ModuleDescription = self.CheckKeyValid('STR_MODULE_DESCRIPTION')\r
+                self.PrintLog('STR_MODULE_DESCRIPTION', ModuleDescription)\r
+        else:\r
+            if self.IsExtraUni:\r
+                PackageName = self.CheckKeyValid('STR_PROPERTIES_PACKAGE_NAME')\r
+                self.PrintLog('STR_PROPERTIES_PACKAGE_NAME', PackageName)\r
+            else:\r
+                PackageAbstract = self.CheckKeyValid('STR_PACKAGE_ABSTRACT')\r
+                self.PrintLog('STR_PACKAGE_ABSTRACT', PackageAbstract)\r
+                PackageDescription = self.CheckKeyValid('STR_PACKAGE_DESCRIPTION')\r
+                self.PrintLog('STR_PACKAGE_DESCRIPTION', PackageDescription)\r
+                \r
+    def CheckKeyValid(self, Key, Contents=None):\r
+        if not Contents:\r
+            Contents = self.FileIn\r
+        KeyPattern = re.compile('#string\s+%s\s+.*?#language.*?".*?"' % Key, re.S)\r
+        if KeyPattern.search(Contents):\r
+            return True\r
+        return False\r
+    \r
+    def CheckPcdInfo(self, PcdCName):\r
+        PromptKey = 'STR_%s_PROMPT' % PcdCName.replace('.', '_')\r
+        PcdPrompt = self.CheckKeyValid(PromptKey)\r
+        self.PrintLog(PromptKey, PcdPrompt)\r
+        HelpKey = 'STR_%s_HELP' % PcdCName.replace('.', '_')\r
+        PcdHelp = self.CheckKeyValid(HelpKey)\r
+        self.PrintLog(HelpKey, PcdHelp)\r
+    \r
+    def PrintLog(self, Key, Value):\r
+        if not Value and Key not in self.Missing:\r
+            Msg = '%s is missing in the %s file.' % (Key, self.FileName)\r
+            EdkLogger.warn('Parser', Msg)\r
+            EccGlobalData.gDb.TblReport.Insert(EccToolError.ERROR_GENERAL_CHECK_UNI_HELP_INFO, OtherMsg=Msg, BelongsToTable='File', BelongsToItem=-2)\r
+            self.Missing.append(Key)\r
+\r
 ##\r
 #\r
 # This acts like the main() function for the script, unless it is 'import'ed into another\r