]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools: Enhance DEC Defines section format check
authorYunhua Feng <yunhuax.feng@intel.com>
Thu, 22 Jun 2017 03:19:47 +0000 (11:19 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Sat, 24 Jun 2017 15:01:37 +0000 (23:01 +0800)
1. break if Dec Defines Section is missing
2. break if Dec have more than one Defines Section
3. break if Dec Defines Section have arch attribute
4. break if no section head, like as:
#[Defines]
 DEC_SPECIFICATION              = 0x00010005
 PACKAGE_NAME                   = Nt32Pkg

Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Yunhua Feng <yunhuax.feng@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
BaseTools/Source/Python/Workspace/MetaFileParser.py

index d094403a001d2e4895cc65e4502d24e9700d359d..6e236e68b07f82b2d9d9d54a24b8e4edb6a2cadc 100644 (file)
@@ -1656,6 +1656,7 @@ class DecParser(MetaFileParser):
         except:\r
             EdkLogger.error("Parser", FILE_READ_FAILURE, ExtraData=self.MetaFile)\r
 \r
+        self._DefinesCount = 0\r
         for Index in range(0, len(Content)):\r
             Line, Comment = CleanString2(Content[Index])\r
             self._CurrentLine = Line\r
@@ -1671,8 +1672,15 @@ class DecParser(MetaFileParser):
             # section header\r
             if Line[0] == TAB_SECTION_START and Line[-1] == TAB_SECTION_END:\r
                 self._SectionHeaderParser()\r
+                if self._SectionName == TAB_DEC_DEFINES.upper():\r
+                    self._DefinesCount += 1\r
                 self._Comments = []\r
                 continue\r
+            if self._SectionType == MODEL_UNKNOWN:\r
+                EdkLogger.error("Parser", FORMAT_INVALID,\r
+                                ""\r
+                                "Not able to determine \"%s\" in which section."%self._CurrentLine,\r
+                                self.MetaFile, self._LineIndex + 1)\r
             elif len(self._SectionType) == 0:\r
                 self._Comments = []\r
                 continue\r
@@ -1720,6 +1728,10 @@ class DecParser(MetaFileParser):
                         0\r
                         )\r
             self._Comments = []\r
+        if self._DefinesCount > 1:\r
+            EdkLogger.error('Parser', FORMAT_INVALID, 'Multiple [Defines] section is exist.', self.MetaFile )\r
+        if self._DefinesCount == 0:\r
+            EdkLogger.error('Parser', FORMAT_INVALID, 'No [Defines] section exist.',self.MetaFile)\r
         self._Done()\r
 \r
 \r
@@ -1745,6 +1757,9 @@ class DecParser(MetaFileParser):
 \r
             # different types of PCD are permissible in one section\r
             self._SectionName = ItemList[0].upper()\r
+            if self._SectionName == TAB_DEC_DEFINES.upper() and (len(ItemList) > 1 or len(Line.split(TAB_COMMA_SPLIT)) > 1):\r
+                EdkLogger.error("Parser", FORMAT_INVALID, "Defines section format is invalid",\r
+                                self.MetaFile, self._LineIndex + 1, self._CurrentLine)\r
             if self._SectionName in self.DataType:\r
                 if self.DataType[self._SectionName] not in self._SectionType:\r
                     self._SectionType.append(self.DataType[self._SectionName])\r