From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.65; helo=mga03.intel.com; envelope-from=yonghong.zhu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (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 AD22E210BFF68 for ; Wed, 25 Jul 2018 17:40:48 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Jul 2018 17:40:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,403,1526367600"; d="scan'208";a="75982896" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by orsmga001.jf.intel.com with ESMTP; 25 Jul 2018 17:40:33 -0700 Received: from fmsmsx111.amr.corp.intel.com (10.18.116.5) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 25 Jul 2018 17:40:29 -0700 Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by fmsmsx111.amr.corp.intel.com (10.18.116.5) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 25 Jul 2018 17:40:29 -0700 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.100]) by SHSMSX104.ccr.corp.intel.com ([169.254.5.81]) with mapi id 14.03.0319.002; Thu, 26 Jul 2018 08:40:27 +0800 From: "Zhu, Yonghong" To: "Zhu, Yonghong" , "edk2-devel@lists.01.org" CC: "Chen, Hesheng" , "Zhu, Yonghong" Thread-Topic: [edk2] [PATCH] BaseTools/Ecc: Add some new checkpoints Thread-Index: AQHUIkrkQhOmMXmNMUum3FNe9gpcU6SgrdTQ Date: Thu, 26 Jul 2018 00:40:27 +0000 Message-ID: References: <1532325782-11224-1-git-send-email-yonghong.zhu@intel.com> In-Reply-To: <1532325782-11224-1-git-send-email-yonghong.zhu@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH] BaseTools/Ecc: Add some new checkpoints X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Jul 2018 00:40:48 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Yonghong Zhu =20 Best Regards, Zhu Yonghong -----Original Message----- From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Yong= hong Zhu Sent: Monday, July 23, 2018 2:03 PM To: edk2-devel@lists.01.org Cc: Chen, Hesheng Subject: [edk2] [PATCH] BaseTools/Ecc: Add some new checkpoints From: hchen30 1. Add a checkpoint to check NO TABs. 2. Add a checkpoint to check line ending with CRLF. 3. Add a checkpoint to check no trailing spaces. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hess Chen --- BaseTools/Source/Python/Ecc/Check.py | 54 ++++++++++++++++++++++++= ++++ BaseTools/Source/Python/Ecc/Configuration.py | 4 +++ BaseTools/Source/Py= thon/Ecc/EccToolError.py | 8 +++-- BaseTools/Source/Python/Ecc/config.ini | 4 +++ 4 files changed, 68 insertions(+), 2 deletions(-) diff --git a/BaseTools/Source/Python/Ecc/Check.py b/BaseTools/Source/Python= /Ecc/Check.py index 0b81013d77..6803afdfdd 100644 --- a/BaseTools/Source/Python/Ecc/Check.py +++ b/BaseTools/Source/Python/Ecc/Check.py @@ -188,6 +188,60 @@ class Check(object): def GeneralCheck(self): self.GeneralCheckNonAcsii() self.UniCheck() + self.GeneralCheckNoTab() + self.GeneralCheckLineEnding() + self.GeneralCheckTrailingWhiteSpaceLine() + + # Check whether NO Tab is used, replaced with spaces + def GeneralCheckNoTab(self): + if EccGlobalData.gConfig.GeneralCheckNoTab =3D=3D '1' or EccGlobal= Data.gConfig.GeneralCheckAll =3D=3D '1' or EccGlobalData.gConfig.CheckAll = =3D=3D '1': + EdkLogger.quiet("Checking No TAB used in file ...") + SqlCommand =3D """select ID, FullPath, ExtName from File where= ExtName in ('.dec', '.inf', '.dsc', 'c', 'h')""" + RecordSet =3D EccGlobalData.gDb.TblFile.Exec(SqlCommand) + for Record in RecordSet: + if Record[2].upper() not in EccGlobalData.gConfig.BinaryEx= tList: + op =3D open(Record[1]).readlines() + IndexOfLine =3D 0 + for Line in op: + IndexOfLine +=3D 1 + IndexOfChar =3D 0 + for Char in Line: + IndexOfChar +=3D 1 + if Char =3D=3D '\t': + OtherMsg =3D "File %s has TAB char at line= %s column %s" % (Record[1], IndexOfLine, IndexOfChar) + =20 + EccGlobalData.gDb.TblReport.Insert(ERROR_GENERAL_CHECK_NO_TAB,=20 + OtherMsg=3DOtherMsg, BelongsToTable=3D'File', BelongsToItem=3DRecord[0]) + + # Check Only use CRLF (Carriage Return Line Feed) line endings. + def GeneralCheckLineEnding(self): + if EccGlobalData.gConfig.GeneralCheckLineEnding =3D=3D '1' or EccG= lobalData.gConfig.GeneralCheckAll =3D=3D '1' or EccGlobalData.gConfig.Check= All =3D=3D '1': + EdkLogger.quiet("Checking line ending in file ...") + SqlCommand =3D """select ID, FullPath, ExtName from File where= ExtName in ('.dec', '.inf', '.dsc', 'c', 'h')""" + RecordSet =3D EccGlobalData.gDb.TblFile.Exec(SqlCommand) + for Record in RecordSet: + if Record[2].upper() not in EccGlobalData.gConfig.BinaryEx= tList: + op =3D open(Record[1], 'rb').readlines() + IndexOfLine =3D 0 + for Line in op: + IndexOfLine +=3D 1 + if not Line.endswith('\r\n'): + OtherMsg =3D "File %s has invalid line ending = at line %s" % (Record[1], IndexOfLine) + =20 + EccGlobalData.gDb.TblReport.Insert(ERROR_GENERAL_CHECK_INVALID_LINE_EN + DING, OtherMsg=3DOtherMsg, BelongsToTable=3D'File',=20 + BelongsToItem=3DRecord[0]) + + # Check if there is no trailing white space in one line. + def GeneralCheckTrailingWhiteSpaceLine(self): + if EccGlobalData.gConfig.GeneralCheckTrailingWhiteSpaceLine =3D=3D= '1' or EccGlobalData.gConfig.GeneralCheckAll =3D=3D '1' or EccGlobalData.g= Config.CheckAll =3D=3D '1': + EdkLogger.quiet("Checking trailing white space line in file ..= .") + SqlCommand =3D """select ID, FullPath, ExtName from File where= ExtName in ('.dec', '.inf', '.dsc', 'c', 'h')""" + RecordSet =3D EccGlobalData.gDb.TblFile.Exec(SqlCommand) + for Record in RecordSet: + if Record[2].upper() not in EccGlobalData.gConfig.BinaryEx= tList: + op =3D open(Record[1], 'rb').readlines() + IndexOfLine =3D 0 + for Line in op: + IndexOfLine +=3D 1 + if Line.replace('\r', '').replace('\n', '').endswi= th(' '): + OtherMsg =3D "File %s has trailing white space= s at line %s" % (Record[1], IndexOfLine) + =20 + EccGlobalData.gDb.TblReport.Insert(ERROR_GENERAL_CHECK_TRAILING_WHITE_ + SPACE_LINE, OtherMsg=3DOtherMsg, BelongsToTable=3D'File',=20 + BelongsToItem=3DRecord[0]) =20 # Check whether file has non ACSII char def GeneralCheckNonAcsii(self): diff --git a/BaseTools/Source/Python/Ecc/Configuration.py b/BaseTools/Sourc= e/Python/Ecc/Configuration.py index 29a1220761..f58adbf736 100644 --- a/BaseTools/Source/Python/Ecc/Configuration.py +++ b/BaseTools/Source/Python/Ecc/Configuration.py @@ -186,6 +186,10 @@ class Configuration(object): self.GeneralCheckNonAcsii =3D 1 # Check whether UNI file is valid self.GeneralCheckUni =3D 1 + # Check Only use CRLF (Carriage Return Line Feed) line endings. + self.GeneralCheckLineEnding =3D 1 + # Check if there is no trailing white space in one line. + self.GeneralCheckTrailingWhiteSpaceLine =3D 1 =20 ## Space Checking self.SpaceCheckAll =3D 1 diff --git a/BaseTools/Source/Python/Ecc/EccToolError.py b/BaseTools/Source= /Python/Ecc/EccToolError.py index 1d51da3ae1..ae0a31af8a 100644 --- a/BaseTools/Source/Python/Ecc/EccToolError.py +++ b/BaseTools/Source/Python/Ecc/EccToolError.py @@ -1,7 +1,7 @@ ## @file # Standardized Error Hanlding infrastructures. # -# Copyright (c) 2008 - 2017, Intel Corporation. All rights reserved.
+# Copyright (c) 2008 - 2018, Intel Corporation. All rights=20 +reserved.
# This program and the accompanying materials # are licensed and made ava= ilable under the terms and conditions of the BSD License # which accompani= es this distribution. The full text of the license may be found at @@ -22,= 6 +22,8 @@ ERROR_GENERAL_CHECK_FILE_EXISTENCE =3D 1007 ERROR_GENERAL_CHECK= _NON_ACSII =3D 1008 ERROR_GENERAL_CHECK_UNI =3D 1009 ERROR_GENERAL_CHECK_= UNI_HELP_INFO =3D 1010 +ERROR_GENERAL_CHECK_INVALID_LINE_ENDING =3D 1011=20 +ERROR_GENERAL_CHECK_TRAILING_WHITE_SPACE_LINE =3D 1012 =20 ERROR_SPACE_CHECK_ALL =3D 2000 =20 @@ -109,7 +111,7 @@ ERROR_SMM_COMM_PARA_CHECK_BUFFER_TYPE =3D 12001 =20 gEccErrorMessage =3D { ERROR_GENERAL_CHECK_ALL : "", - ERROR_GENERAL_CHECK_NO_TAB : "'TAB' character is not allowed in source= code, please replace each 'TAB' with two spaces", + ERROR_GENERAL_CHECK_NO_TAB : "'TAB' character is not allowed in=20 + source code, please replace each 'TAB' with two spaces.", ERROR_GENERAL_CHECK_INDENTATION : "Indentation does not follow coding = style", ERROR_GENERAL_CHECK_LINE : "The width of each line does not follow cod= ing style", ERROR_GENERAL_CHECK_NO_ASM : "There should be no use of _asm in the so= urce file", @@ -119,6 +121,8 @@ gEccErrorMessage =3D { ERROR_GENERAL_CHECK_NON_ACSII : "File has invalid Non-ACSII char", ERROR_GENERAL_CHECK_UNI : "File is not a valid UTF-16 UNI file", ERROR_GENERAL_CHECK_UNI_HELP_INFO : "UNI file that is associated by IN= F or DEC file need define the prompt and help information.", + ERROR_GENERAL_CHECK_INVALID_LINE_ENDING : "Only CRLF (Carriage Return = Line Feed) is allowed to line ending.", + ERROR_GENERAL_CHECK_TRAILING_WHITE_SPACE_LINE : "There should be no=20 + trailing white space in one line.", =20 ERROR_SPACE_CHECK_ALL : "", =20 diff --git a/BaseTools/Source/Python/Ecc/config.ini b/BaseTools/Source/Pyth= on/Ecc/config.ini index 9a431bf124..6c86da74d6 100644 --- a/BaseTools/Source/Python/Ecc/config.ini +++ b/BaseTools/Source/Python/Ecc/config.ini @@ -72,6 +72,10 @@ GeneralCheckFileExistence =3D 1 GeneralCheckNonAcsii = =3D 1 # Check whether UNI file is valid GeneralCheckUni =3D 1 +# Check Only use CRLF (Carriage Return Line Feed) line endings. +self.GeneralCheckLineEnding =3D 1 +# Check if there is no trailing white space in one line. +self.GeneralCheckTrailingWhiteSpaceLine =3D 1 =20 # # Space Checking -- 2.14.2.windows.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel