## @file\r
# This file is used to define checkpoints used by ECC tool\r
#\r
-# Copyright (c) 2008 - 2017, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2008 - 2018, 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
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
#\r
+from __future__ import absolute_import\r
import Common.LongFilePathOs as os\r
import re\r
from CommonDataClass.DataClass import *\r
import Common.DataType as DT\r
-from EccToolError import *\r
-from MetaDataParser import ParseHeaderCommentSection\r
-import EccGlobalData\r
-import c\r
+from .EccToolError import *\r
+from .MetaDataParser import ParseHeaderCommentSection\r
+from . import EccGlobalData\r
+from . import c\r
from Common.LongFilePathSupport import OpenLongFilePath as open\r
from Common.MultipleWorkspace import MultipleWorkspace as mws\r
\r
def GeneralCheck(self):\r
self.GeneralCheckNonAcsii()\r
self.UniCheck()\r
+ self.GeneralCheckNoTab()\r
+ self.GeneralCheckLineEnding()\r
+ self.GeneralCheckTrailingWhiteSpaceLine()\r
+\r
+ # Check whether NO Tab is used, replaced with spaces\r
+ def GeneralCheckNoTab(self):\r
+ if EccGlobalData.gConfig.GeneralCheckNoTab == '1' or EccGlobalData.gConfig.GeneralCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
+ EdkLogger.quiet("Checking No TAB used in file ...")\r
+ SqlCommand = """select ID, FullPath, ExtName from File where ExtName in ('.dec', '.inf', '.dsc', 'c', 'h')"""\r
+ RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r
+ for Record in RecordSet:\r
+ if Record[2].upper() not in EccGlobalData.gConfig.BinaryExtList:\r
+ op = open(Record[1]).readlines()\r
+ IndexOfLine = 0\r
+ for Line in op:\r
+ IndexOfLine += 1\r
+ IndexOfChar = 0\r
+ for Char in Line:\r
+ IndexOfChar += 1\r
+ if Char == '\t':\r
+ OtherMsg = "File %s has TAB char at line %s column %s" % (Record[1], IndexOfLine, IndexOfChar)\r
+ EccGlobalData.gDb.TblReport.Insert(ERROR_GENERAL_CHECK_NO_TAB, OtherMsg=OtherMsg, BelongsToTable='File', BelongsToItem=Record[0])\r
+\r
+ # Check Only use CRLF (Carriage Return Line Feed) line endings.\r
+ def GeneralCheckLineEnding(self):\r
+ if EccGlobalData.gConfig.GeneralCheckLineEnding == '1' or EccGlobalData.gConfig.GeneralCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
+ EdkLogger.quiet("Checking line ending in file ...")\r
+ SqlCommand = """select ID, FullPath, ExtName from File where ExtName in ('.dec', '.inf', '.dsc', 'c', 'h')"""\r
+ RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r
+ for Record in RecordSet:\r
+ if Record[2].upper() not in EccGlobalData.gConfig.BinaryExtList:\r
+ op = open(Record[1], 'rb').readlines()\r
+ IndexOfLine = 0\r
+ for Line in op:\r
+ IndexOfLine += 1\r
+ if not Line.endswith('\r\n'):\r
+ OtherMsg = "File %s has invalid line ending at line %s" % (Record[1], IndexOfLine)\r
+ EccGlobalData.gDb.TblReport.Insert(ERROR_GENERAL_CHECK_INVALID_LINE_ENDING, OtherMsg=OtherMsg, BelongsToTable='File', BelongsToItem=Record[0])\r
+\r
+ # Check if there is no trailing white space in one line.\r
+ def GeneralCheckTrailingWhiteSpaceLine(self):\r
+ if EccGlobalData.gConfig.GeneralCheckTrailingWhiteSpaceLine == '1' or EccGlobalData.gConfig.GeneralCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
+ EdkLogger.quiet("Checking trailing white space line in file ...")\r
+ SqlCommand = """select ID, FullPath, ExtName from File where ExtName in ('.dec', '.inf', '.dsc', 'c', 'h')"""\r
+ RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r
+ for Record in RecordSet:\r
+ if Record[2].upper() not in EccGlobalData.gConfig.BinaryExtList:\r
+ op = open(Record[1], 'rb').readlines()\r
+ IndexOfLine = 0\r
+ for Line in op:\r
+ IndexOfLine += 1\r
+ if Line.replace('\r', '').replace('\n', '').endswith(' '):\r
+ OtherMsg = "File %s has trailing white spaces at line %s" % (Record[1], IndexOfLine)\r
+ EccGlobalData.gDb.TblReport.Insert(ERROR_GENERAL_CHECK_TRAILING_WHITE_SPACE_LINE, OtherMsg=OtherMsg, BelongsToTable='File', BelongsToItem=Record[0])\r
\r
# Check whether file has non ACSII char\r
def GeneralCheckNonAcsii(self):\r
op = open(FullName).readlines()\r
FileLinesList = op\r
LineNo = 0\r
- CurrentSection = MODEL_UNKNOWN \r
+ CurrentSection = MODEL_UNKNOWN\r
HeaderSectionLines = []\r
- HeaderCommentStart = False \r
+ HeaderCommentStart = False\r
HeaderCommentEnd = False\r
- \r
+\r
for Line in FileLinesList:\r
LineNo = LineNo + 1\r
Line = Line.strip()\r
if (LineNo < len(FileLinesList) - 1):\r
NextLine = FileLinesList[LineNo].strip()\r
- \r
+\r
#\r
# blank line\r
#\r
#\r
HeaderSectionLines.append((Line, LineNo))\r
HeaderCommentStart = True\r
- continue \r
- \r
+ continue\r
+\r
#\r
# Collect Header content.\r
#\r
if EccGlobalData.gConfig.HeaderCheckFileCommentEnd == '1' or EccGlobalData.gConfig.HeaderCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
EccGlobalData.gDb.TblReport.Insert(ERROR_DOXYGEN_CHECK_FILE_HEADER, Msg, "File", Result[0])\r
\r
- \r
+\r
\r
# Check whether the function headers are followed Doxygen special documentation blocks in section 2.3.5\r
def DoxygenCheckFunctionHeader(self):\r
if Item not in LibraryClasses[List[0]]:\r
LibraryClasses[List[0]].append(Item)\r
\r
- if Record[2] != 'BASE' and Record[2] not in SupModType:\r
+ if Record[2] != DT.SUP_MODULE_BASE and Record[2] not in SupModType:\r
EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_LIBRARY_INSTANCE_2, OtherMsg="The Library Class '%s' does not specify its supported module types" % (List[0]), BelongsToTable='Inf', BelongsToItem=Record[0])\r
\r
SqlCommand = """select A.ID, A.Value1, B.Value3 from Inf as A left join Inf as B\r
\r
for Record in RecordSet:\r
if Record[1] in LibraryClasses:\r
- if Record[2] not in LibraryClasses[Record[1]] and 'BASE' not in RecordDict[Record[1]]:\r
+ if Record[2] not in LibraryClasses[Record[1]] and DT.SUP_MODULE_BASE not in RecordDict[Record[1]]:\r
if not EccGlobalData.gException.IsException(ERROR_META_DATA_FILE_CHECK_LIBRARY_INSTANCE_1, Record[1]):\r
EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_LIBRARY_INSTANCE_1, OtherMsg="The type of Library Class [%s] defined in Inf file does not match the type of the module" % (Record[1]), BelongsToTable='Inf', BelongsToItem=Record[0])\r
else:\r
continue\r
SqlCommand = """select Value3 from Inf where BelongsToFile =\r
(select ID from File where lower(FullPath) = lower('%s'))\r
- and Value2 = '%s'""" % (LibraryIns, 'LIBRARY_CLASS')\r
+ and Value2 = '%s'""" % (LibraryIns, DT.PLATFORM_COMPONENT_TYPE_LIBRARY_CLASS)\r
RecordSet = EccGlobalData.gDb.TblInf.Exec(SqlCommand)\r
IsFound = False\r
for Record in RecordSet:\r
EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_LIBRARY_NO_USE, OtherMsg="The Library Class [%s] is not used in any platform" % (Record[1]), BelongsToTable='Inf', BelongsToItem=Record[0])\r
SqlCommand = """\r
select A.ID, A.Value1, A.BelongsToFile, A.StartLine, B.StartLine from Dsc as A left join Dsc as B\r
- where A.Model = %s and B.Model = %s and A.Scope1 = B.Scope1 and A.Scope2 = B.Scope2 and A.ID <> B.ID\r
- and A.Value1 = B.Value1 and A.Value2 <> B.Value2 and A.BelongsToItem = -1 and B.BelongsToItem = -1 and A.StartLine <> B.StartLine and B.BelongsToFile = A.BelongsToFile""" \\r
+ where A.Model = %s and B.Model = %s and A.Scope1 = B.Scope1 and A.Scope2 = B.Scope2 and A.ID != B.ID\r
+ and A.Value1 = B.Value1 and A.Value2 != B.Value2 and A.BelongsToItem = -1 and B.BelongsToItem = -1 and A.StartLine != B.StartLine and B.BelongsToFile = A.BelongsToFile""" \\r
% (MODEL_EFI_LIBRARY_CLASS, MODEL_EFI_LIBRARY_CLASS)\r
RecordSet = EccGlobalData.gDb.TblDsc.Exec(SqlCommand)\r
for Record in RecordSet:\r
for FilePath in FilePathList:\r
if not EccGlobalData.gException.IsException(ERROR_META_DATA_FILE_CHECK_LIBRARY_NAME_DUPLICATE, Record[1]):\r
EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_LIBRARY_NAME_DUPLICATE, OtherMsg="The Library Class [%s] is duplicated in '%s' line %s and line %s." % (Record[1], FilePath, Record[3], Record[4]), BelongsToTable='Dsc', BelongsToItem=Record[0])\r
- \r
+\r
# Check the header file in Include\Library directory whether be defined in the package DEC file.\r
def MetaDataFileCheckLibraryDefinedInDec(self):\r
if EccGlobalData.gConfig.MetaDataFileCheckLibraryDefinedInDec == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
if not LibraryDec:\r
if not EccGlobalData.gException.IsException(ERROR_META_DATA_FILE_CHECK_LIBRARY_NOT_DEFINED, LibraryInInf):\r
EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_LIBRARY_NOT_DEFINED, \\r
- OtherMsg="The Library Class [%s] in %s line is not defined in the associated package file." % (LibraryInInf, Line), \r
+ OtherMsg="The Library Class [%s] in %s line is not defined in the associated package file." % (LibraryInInf, Line),\r
BelongsToTable='Inf', BelongsToItem=ID)\r
- \r
+\r
# Check whether an Inf file is specified in the FDF file, but not in the Dsc file, then the Inf file must be for a Binary module only\r
def MetaDataFileCheckBinaryInfInFdf(self):\r
if EccGlobalData.gConfig.MetaDataFileCheckBinaryInfInFdf == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
and A.Value1 = B.Value1\r
and A.Value2 = B.Value2\r
and A.Scope1 = B.Scope1\r
- and A.ID <> B.ID\r
+ and A.ID != B.ID\r
and A.Model = B.Model\r
and A.Enabled > -1\r
and B.Enabled > -1\r
SqlCommand = """\r
select A.ID, A.Value3, A.BelongsToFile, B.BelongsToFile from %s as A, %s as B\r
where A.Value2 = 'FILE_GUID' and B.Value2 = 'FILE_GUID' and\r
- A.Value3 = B.Value3 and A.ID <> B.ID group by A.ID\r
+ A.Value3 = B.Value3 and A.ID != B.ID group by A.ID\r
""" % (Table.Table, Table.Table)\r
RecordSet = Table.Exec(SqlCommand)\r
for Record in RecordSet:\r
SqlCommand = """\r
select A.ID, A.Value1 from %s as A, %s as B\r
where A.Model = %s and B.Model = %s\r
- and A.Value1 like B.Value1 and A.ID <> B.ID\r
+ and A.Value1 like B.Value1 and A.ID != B.ID\r
and A.Scope1 = B.Scope1\r
and A.Enabled > -1\r
and B.Enabled > -1\r
SqlCommand = """\r
select A.ID, A.Value1, A.Value2 from %s as A, %s as B\r
where A.Model = %s and B.Model = %s\r
- and A.Value2 like B.Value2 and A.ID <> B.ID\r
- and A.Scope1 = B.Scope1 and A.Value1 <> B.Value1\r
+ and A.Value2 like B.Value2 and A.ID != B.ID\r
+ and A.Scope1 = B.Scope1 and A.Value1 != B.Value1\r
group by A.ID\r
""" % (Table.Table, Table.Table, Model, Model)\r
RecordSet = Table.Exec(SqlCommand)\r
- for Record in RecordSet: \r
+ for Record in RecordSet:\r
if not EccGlobalData.gException.IsException(ErrorID, Record[2]):\r
EccGlobalData.gDb.TblReport.Insert(ErrorID, OtherMsg="The %s value [%s] is used more than one time" % (Name.upper(), Record[2]), BelongsToTable=Table.Table, BelongsToItem=Record[0])\r
\r
RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r
for Record in RecordSet:\r
Name = Record[1].strip()\r
- if Name != '' and Name != None:\r
+ if Name != '' and Name is not None:\r
if Name[0] == '(':\r
Name = Name[1:Name.find(')')]\r
if Name.find('(') > -1:\r