From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 6C1A821BBC436 for ; Thu, 22 Jun 2017 01:09:03 -0700 (PDT) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga104.jf.intel.com with ESMTP; 22 Jun 2017 01:10:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.39,372,1493708400"; d="scan'208";a="1185643224" Received: from shwdeopenpsi168.ccr.corp.intel.com ([10.239.158.121]) by fmsmga002.fm.intel.com with ESMTP; 22 Jun 2017 01:10:26 -0700 From: Yonghong Zhu To: edk2-devel@lists.01.org Cc: Yunhua Feng , Liming Gao Date: Thu, 22 Jun 2017 16:10:23 +0800 Message-Id: <1498119023-8276-1-git-send-email-yonghong.zhu@intel.com> X-Mailer: git-send-email 2.6.1.windows.1 Subject: [Patch] BaseTools: Enhance DEC Defines section format check X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 Jun 2017 08:09:03 -0000 From: Yunhua Feng 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 Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Yunhua Feng --- 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