public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [Patch] BaseTools: Enhance DEC Defines section format check
@ 2017-06-22  8:10 Yonghong Zhu
  2017-06-23  7:51 ` Gao, Liming
  0 siblings, 1 reply; 3+ messages in thread
From: Yonghong Zhu @ 2017-06-22  8:10 UTC (permalink / raw)
  To: edk2-devel; +Cc: Yunhua Feng, Liming Gao

From: Yunhua Feng <yunhuax.feng@intel.com>

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>
---
 BaseTools/Source/Python/Workspace/MetaFileParser.py | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py b/BaseTools/Source/Python/Workspace/MetaFileParser.py
index d094403..6e236e6 100644
--- a/BaseTools/Source/Python/Workspace/MetaFileParser.py
+++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py
@@ -1654,10 +1654,11 @@ class DecParser(MetaFileParser):
         try:
             Content = open(str(self.MetaFile), 'r').readlines()
         except:
             EdkLogger.error("Parser", FILE_READ_FAILURE, ExtraData=self.MetaFile)
 
+        self._DefinesCount = 0
         for Index in range(0, len(Content)):
             Line, Comment = CleanString2(Content[Index])
             self._CurrentLine = Line
             self._LineIndex = Index
 
@@ -1669,12 +1670,19 @@ class DecParser(MetaFileParser):
                 continue
 
             # section header
             if Line[0] == TAB_SECTION_START and Line[-1] == TAB_SECTION_END:
                 self._SectionHeaderParser()
+                if self._SectionName == TAB_DEC_DEFINES.upper():
+                    self._DefinesCount += 1
                 self._Comments = []
                 continue
+            if self._SectionType == MODEL_UNKNOWN:
+                EdkLogger.error("Parser", FORMAT_INVALID,
+                                ""
+                                "Not able to determine \"%s\" in which section."%self._CurrentLine,
+                                self.MetaFile, self._LineIndex + 1)
             elif len(self._SectionType) == 0:
                 self._Comments = []
                 continue
 
             # section content
@@ -1718,10 +1726,14 @@ class DecParser(MetaFileParser):
                         LineNo,
                         - 1,
                         0
                         )
             self._Comments = []
+        if self._DefinesCount > 1:
+            EdkLogger.error('Parser', FORMAT_INVALID, 'Multiple [Defines] section is exist.', self.MetaFile )
+        if self._DefinesCount == 0:
+            EdkLogger.error('Parser', FORMAT_INVALID, 'No [Defines] section exist.',self.MetaFile)
         self._Done()
 
 
     ## Section header parser
     #
@@ -1743,10 +1755,13 @@ class DecParser(MetaFileParser):
                                 self.MetaFile, self._LineIndex + 1, self._CurrentLine)
             ItemList = Item.split(TAB_SPLIT)
 
             # different types of PCD are permissible in one section
             self._SectionName = ItemList[0].upper()
+            if self._SectionName == TAB_DEC_DEFINES.upper() and (len(ItemList) > 1 or len(Line.split(TAB_COMMA_SPLIT)) > 1):
+                EdkLogger.error("Parser", FORMAT_INVALID, "Defines section format is invalid",
+                                self.MetaFile, self._LineIndex + 1, self._CurrentLine)
             if self._SectionName in self.DataType:
                 if self.DataType[self._SectionName] not in self._SectionType:
                     self._SectionType.append(self.DataType[self._SectionName])
             else:
                 EdkLogger.error("Parser", FORMAT_UNKNOWN_ERROR, "%s is not a valid section name" % Item,
-- 
2.6.1.windows.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Patch] BaseTools: Enhance DEC Defines section format check
  2017-06-22  8:10 [Patch] BaseTools: Enhance DEC Defines section format check Yonghong Zhu
@ 2017-06-23  7:51 ` Gao, Liming
  2017-06-23  7:52   ` Gao, Liming
  0 siblings, 1 reply; 3+ messages in thread
From: Gao, Liming @ 2017-06-23  7:51 UTC (permalink / raw)
  To: Zhu, Yonghong, edk2-devel@lists.01.org; +Cc: Feng, YunhuaX

c:\r9tip\allpkg\edk2\mdemodulepkg\universal\pcd\pei\Service.h

>-----Original Message-----
>From: Zhu, Yonghong
>Sent: Thursday, June 22, 2017 4:10 PM
>To: edk2-devel@lists.01.org
>Cc: Feng, YunhuaX <yunhuax.feng@intel.com>; Gao, Liming
><liming.gao@intel.com>
>Subject: [Patch] BaseTools: Enhance DEC Defines section format check
>
>From: Yunhua Feng <yunhuax.feng@intel.com>
>
>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>
>---
> BaseTools/Source/Python/Workspace/MetaFileParser.py | 15
>+++++++++++++++
> 1 file changed, 15 insertions(+)
>
>diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py
>b/BaseTools/Source/Python/Workspace/MetaFileParser.py
>index d094403..6e236e6 100644
>--- a/BaseTools/Source/Python/Workspace/MetaFileParser.py
>+++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py
>@@ -1654,10 +1654,11 @@ class DecParser(MetaFileParser):
>         try:
>             Content = open(str(self.MetaFile), 'r').readlines()
>         except:
>             EdkLogger.error("Parser", FILE_READ_FAILURE,
>ExtraData=self.MetaFile)
>
>+        self._DefinesCount = 0
>         for Index in range(0, len(Content)):
>             Line, Comment = CleanString2(Content[Index])
>             self._CurrentLine = Line
>             self._LineIndex = Index
>
>@@ -1669,12 +1670,19 @@ class DecParser(MetaFileParser):
>                 continue
>
>             # section header
>             if Line[0] == TAB_SECTION_START and Line[-1] == TAB_SECTION_END:
>                 self._SectionHeaderParser()
>+                if self._SectionName == TAB_DEC_DEFINES.upper():
>+                    self._DefinesCount += 1
>                 self._Comments = []
>                 continue
>+            if self._SectionType == MODEL_UNKNOWN:
>+                EdkLogger.error("Parser", FORMAT_INVALID,
>+                                ""
>+                                "Not able to determine \"%s\" in which
>section."%self._CurrentLine,
>+                                self.MetaFile, self._LineIndex + 1)
>             elif len(self._SectionType) == 0:
>                 self._Comments = []
>                 continue
>
>             # section content
>@@ -1718,10 +1726,14 @@ class DecParser(MetaFileParser):
>                         LineNo,
>                         - 1,
>                         0
>                         )
>             self._Comments = []
>+        if self._DefinesCount > 1:
>+            EdkLogger.error('Parser', FORMAT_INVALID, 'Multiple [Defines]
>section is exist.', self.MetaFile )
>+        if self._DefinesCount == 0:
>+            EdkLogger.error('Parser', FORMAT_INVALID, 'No [Defines] section
>exist.',self.MetaFile)
>         self._Done()
>
>
>     ## Section header parser
>     #
>@@ -1743,10 +1755,13 @@ class DecParser(MetaFileParser):
>                                 self.MetaFile, self._LineIndex + 1, self._CurrentLine)
>             ItemList = Item.split(TAB_SPLIT)
>
>             # different types of PCD are permissible in one section
>             self._SectionName = ItemList[0].upper()
>+            if self._SectionName == TAB_DEC_DEFINES.upper() and (len(ItemList) >
>1 or len(Line.split(TAB_COMMA_SPLIT)) > 1):
>+                EdkLogger.error("Parser", FORMAT_INVALID, "Defines section
>format is invalid",
>+                                self.MetaFile, self._LineIndex + 1, self._CurrentLine)
>             if self._SectionName in self.DataType:
>                 if self.DataType[self._SectionName] not in self._SectionType:
>                     self._SectionType.append(self.DataType[self._SectionName])
>             else:
>                 EdkLogger.error("Parser", FORMAT_UNKNOWN_ERROR, "%s is not a
>valid section name" % Item,
>--
>2.6.1.windows.1



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Patch] BaseTools: Enhance DEC Defines section format check
  2017-06-23  7:51 ` Gao, Liming
@ 2017-06-23  7:52   ` Gao, Liming
  0 siblings, 0 replies; 3+ messages in thread
From: Gao, Liming @ 2017-06-23  7:52 UTC (permalink / raw)
  To: Gao, Liming, Zhu, Yonghong, edk2-devel@lists.01.org; +Cc: Feng, YunhuaX

Please ignore the previous mail. It is my mistake.

For this patch, Reviewed-by: Liming Gao <liming.gao@intel.com>

>-----Original Message-----
>From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Gao,
>Liming
>Sent: Friday, June 23, 2017 3:51 PM
>To: Zhu, Yonghong <yonghong.zhu@intel.com>; edk2-devel@lists.01.org
>Cc: Feng, YunhuaX <yunhuax.feng@intel.com>
>Subject: Re: [edk2] [Patch] BaseTools: Enhance DEC Defines section format
>check
>
>c:\r9tip\allpkg\edk2\mdemodulepkg\universal\pcd\pei\Service.h
>
>>-----Original Message-----
>>From: Zhu, Yonghong
>>Sent: Thursday, June 22, 2017 4:10 PM
>>To: edk2-devel@lists.01.org
>>Cc: Feng, YunhuaX <yunhuax.feng@intel.com>; Gao, Liming
>><liming.gao@intel.com>
>>Subject: [Patch] BaseTools: Enhance DEC Defines section format check
>>
>>From: Yunhua Feng <yunhuax.feng@intel.com>
>>
>>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>
>>---
>> BaseTools/Source/Python/Workspace/MetaFileParser.py | 15
>>+++++++++++++++
>> 1 file changed, 15 insertions(+)
>>
>>diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py
>>b/BaseTools/Source/Python/Workspace/MetaFileParser.py
>>index d094403..6e236e6 100644
>>--- a/BaseTools/Source/Python/Workspace/MetaFileParser.py
>>+++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py
>>@@ -1654,10 +1654,11 @@ class DecParser(MetaFileParser):
>>         try:
>>             Content = open(str(self.MetaFile), 'r').readlines()
>>         except:
>>             EdkLogger.error("Parser", FILE_READ_FAILURE,
>>ExtraData=self.MetaFile)
>>
>>+        self._DefinesCount = 0
>>         for Index in range(0, len(Content)):
>>             Line, Comment = CleanString2(Content[Index])
>>             self._CurrentLine = Line
>>             self._LineIndex = Index
>>
>>@@ -1669,12 +1670,19 @@ class DecParser(MetaFileParser):
>>                 continue
>>
>>             # section header
>>             if Line[0] == TAB_SECTION_START and Line[-1] == TAB_SECTION_END:
>>                 self._SectionHeaderParser()
>>+                if self._SectionName == TAB_DEC_DEFINES.upper():
>>+                    self._DefinesCount += 1
>>                 self._Comments = []
>>                 continue
>>+            if self._SectionType == MODEL_UNKNOWN:
>>+                EdkLogger.error("Parser", FORMAT_INVALID,
>>+                                ""
>>+                                "Not able to determine \"%s\" in which
>>section."%self._CurrentLine,
>>+                                self.MetaFile, self._LineIndex + 1)
>>             elif len(self._SectionType) == 0:
>>                 self._Comments = []
>>                 continue
>>
>>             # section content
>>@@ -1718,10 +1726,14 @@ class DecParser(MetaFileParser):
>>                         LineNo,
>>                         - 1,
>>                         0
>>                         )
>>             self._Comments = []
>>+        if self._DefinesCount > 1:
>>+            EdkLogger.error('Parser', FORMAT_INVALID, 'Multiple [Defines]
>>section is exist.', self.MetaFile )
>>+        if self._DefinesCount == 0:
>>+            EdkLogger.error('Parser', FORMAT_INVALID, 'No [Defines] section
>>exist.',self.MetaFile)
>>         self._Done()
>>
>>
>>     ## Section header parser
>>     #
>>@@ -1743,10 +1755,13 @@ class DecParser(MetaFileParser):
>>                                 self.MetaFile, self._LineIndex + 1, self._CurrentLine)
>>             ItemList = Item.split(TAB_SPLIT)
>>
>>             # different types of PCD are permissible in one section
>>             self._SectionName = ItemList[0].upper()
>>+            if self._SectionName == TAB_DEC_DEFINES.upper() and
>(len(ItemList) >
>>1 or len(Line.split(TAB_COMMA_SPLIT)) > 1):
>>+                EdkLogger.error("Parser", FORMAT_INVALID, "Defines section
>>format is invalid",
>>+                                self.MetaFile, self._LineIndex + 1, self._CurrentLine)
>>             if self._SectionName in self.DataType:
>>                 if self.DataType[self._SectionName] not in self._SectionType:
>>                     self._SectionType.append(self.DataType[self._SectionName])
>>             else:
>>                 EdkLogger.error("Parser", FORMAT_UNKNOWN_ERROR, "%s is not
>a
>>valid section name" % Item,
>>--
>>2.6.1.windows.1
>
>_______________________________________________
>edk2-devel mailing list
>edk2-devel@lists.01.org
>https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-06-23  7:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-22  8:10 [Patch] BaseTools: Enhance DEC Defines section format check Yonghong Zhu
2017-06-23  7:51 ` Gao, Liming
2017-06-23  7:52   ` Gao, Liming

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox