From 5ce48c03cbb428bac53e31973e844b07730b9ca8 Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Tue, 17 Feb 2026 11:10:41 -0500 Subject: [PATCH] BaseTools/Ecc: Remove #ifndef include guard checks The codebase has moved from traditional `#ifndef` include guards to `#pragma once`. Remove the ECC checks that validated include guard presence and naming conventions since they are no longer applicable. The following checks are removed: - IncludeFileCheckIfndefStatement: Verified all header file contents were guarded by a `#ifndef` statement, that the `#ifndef` was the first line of code after the file header comment, and that the `#endif` appeared on the last line. - NamingConventionCheckIfndefStatement: Verified that the `#ifndef` guard name at the start of an include file used a postfix underscore and no prefix underscore character. Also removed related error codes and configuration settings that were specific to these checks. Signed-off-by: Michael Kubacki --- BaseTools/Source/Python/Ecc/Check.py | 32 ----------------- BaseTools/Source/Python/Ecc/Configuration.py | 8 ----- BaseTools/Source/Python/Ecc/EccToolError.py | 8 ----- BaseTools/Source/Python/Ecc/c.py | 38 -------------------- BaseTools/Source/Python/Ecc/config.ini | 6 ---- 5 files changed, 92 deletions(-) diff --git a/BaseTools/Source/Python/Ecc/Check.py b/BaseTools/Source/Python/Ecc/Check.py index 8a4cf34903..e0db6cb142 100644 --- a/BaseTools/Source/Python/Ecc/Check.py +++ b/BaseTools/Source/Python/Ecc/Check.py @@ -573,7 +573,6 @@ class Check(object): # Include file checking def IncludeFileCheck(self): - self.IncludeFileCheckIfndef() self.IncludeFileCheckData() self.IncludeFileCheckSameName() @@ -603,19 +602,6 @@ class Check(object): if not EccGlobalData.gException.IsException(ERROR_INCLUDE_FILE_CHECK_NAME, Path): EccGlobalData.gDb.TblReport.Insert(ERROR_INCLUDE_FILE_CHECK_NAME, OtherMsg="The file name for [%s] is duplicate" % Path, BelongsToTable='File', BelongsToItem=Item[0]) - # Check whether all include file contents is guarded by a #ifndef statement. - def IncludeFileCheckIfndef(self): - if EccGlobalData.gConfig.IncludeFileCheckIfndefStatement == '1' or EccGlobalData.gConfig.IncludeFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1': - EdkLogger.quiet("Checking header file ifndef ...") - -# for Dirpath, Dirnames, Filenames in self.WalkTree(): -# for F in Filenames: -# if os.path.splitext(F)[1] in ('.h'): -# FullName = os.path.join(Dirpath, F) -# MsgList = c.CheckHeaderFileIfndef(FullName) - for FullName in EccGlobalData.gHFileList: - MsgList = c.CheckHeaderFileIfndef(FullName) - # Check whether include files NOT contain code or define data variables def IncludeFileCheckData(self): if EccGlobalData.gConfig.IncludeFileCheckData == '1' or EccGlobalData.gConfig.IncludeFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1': @@ -1352,7 +1338,6 @@ class Check(object): def NamingConventionCheck(self): if EccGlobalData.gConfig.NamingConventionCheckDefineStatement == '1' \ or EccGlobalData.gConfig.NamingConventionCheckTypedefStatement == '1' \ - or EccGlobalData.gConfig.NamingConventionCheckIfndefStatement == '1' \ or EccGlobalData.gConfig.NamingConventionCheckVariableName == '1' \ or EccGlobalData.gConfig.NamingConventionCheckSingleCharacterVariable == '1' \ or EccGlobalData.gConfig.NamingConventionCheckAll == '1'\ @@ -1369,8 +1354,6 @@ class Check(object): self.NamingConventionCheckTypedefStatement(FileTable) self.NamingConventionCheckVariableName(FileTable) self.NamingConventionCheckSingleCharacterVariable(FileTable) - if os.path.splitext(F)[1] in ('.h'): - self.NamingConventionCheckIfndefStatement(FileTable) self.NamingConventionCheckPathName() self.NamingConventionCheckFunctionName() @@ -1410,21 +1393,6 @@ class Check(object): if not EccGlobalData.gException.IsException(ERROR_NAMING_CONVENTION_CHECK_TYPEDEF_STATEMENT, Name): EccGlobalData.gDb.TblReport.Insert(ERROR_NAMING_CONVENTION_CHECK_TYPEDEF_STATEMENT, OtherMsg="The #typedef name [%s] does not follow the rules" % (Name), BelongsToTable=FileTable, BelongsToItem=Record[0]) - # Check whether the #ifndef at the start of an include file uses both prefix and postfix underscore characters, '_'. - def NamingConventionCheckIfndefStatement(self, FileTable): - if EccGlobalData.gConfig.NamingConventionCheckIfndefStatement == '1' or EccGlobalData.gConfig.NamingConventionCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1': - EdkLogger.quiet("Checking naming convention of #ifndef statement ...") - - SqlCommand = """select ID, Value from %s where Model = %s""" % (FileTable, MODEL_IDENTIFIER_MACRO_IFNDEF) - RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand) - if RecordSet: - # Only check the first ifndef statement of the file - FirstDefine = sorted(RecordSet, key=lambda Record: Record[0])[0] - Name = FirstDefine[1].replace('#ifndef', '').strip() - if Name[0] == '_' or Name[-1] != '_' or Name[-2] == '_': - if not EccGlobalData.gException.IsException(ERROR_NAMING_CONVENTION_CHECK_IFNDEF_STATEMENT, Name): - EccGlobalData.gDb.TblReport.Insert(ERROR_NAMING_CONVENTION_CHECK_IFNDEF_STATEMENT, OtherMsg="The #ifndef name [%s] does not follow the rules" % (Name), BelongsToTable=FileTable, BelongsToItem=FirstDefine[0]) - # Rule for path name, variable name and function name # 1. First character should be upper case # 2. Existing lower case in a word diff --git a/BaseTools/Source/Python/Ecc/Configuration.py b/BaseTools/Source/Python/Ecc/Configuration.py index 9a9ca49eee..974d3c1b1b 100644 --- a/BaseTools/Source/Python/Ecc/Configuration.py +++ b/BaseTools/Source/Python/Ecc/Configuration.py @@ -71,7 +71,6 @@ _ConfigFileToInternalTranslation = { "HeaderCheckFunction":"HeaderCheckFunction", "IncludeFileCheckAll":"IncludeFileCheckAll", "IncludeFileCheckData":"IncludeFileCheckData", - "IncludeFileCheckIfndefStatement":"IncludeFileCheckIfndefStatement", "IncludeFileCheckSameName":"IncludeFileCheckSameName", "MetaDataFileCheckAll":"MetaDataFileCheckAll", "MetaDataFileCheckBinaryInfInFdf":"MetaDataFileCheckBinaryInfInFdf", @@ -97,7 +96,6 @@ _ConfigFileToInternalTranslation = { "NamingConventionCheckAll":"NamingConventionCheckAll", "NamingConventionCheckDefineStatement":"NamingConventionCheckDefineStatement", "NamingConventionCheckFunctionName":"NamingConventionCheckFunctionName", - "NamingConventionCheckIfndefStatement":"NamingConventionCheckIfndefStatement", "NamingConventionCheckPathName":"NamingConventionCheckPathName", "NamingConventionCheckSingleCharacterVariable":"NamingConventionCheckSingleCharacterVariable", "NamingConventionCheckTypedefStatement":"NamingConventionCheckTypedefStatement", @@ -242,10 +240,6 @@ class Configuration(object): #Check whether having include files with same name self.IncludeFileCheckSameName = 1 - # Check whether all include file contents is guarded by a #ifndef statement. - # the #ifndef must be the first line of code following the file header comment - # the #endif must appear on the last line in the file - self.IncludeFileCheckIfndefStatement = 1 # Check whether include files contain only public or only private data # Check whether include files NOT contain code or define data variables self.IncludeFileCheckData = 1 @@ -275,8 +269,6 @@ class Configuration(object): self.NamingConventionCheckDefineStatement = 1 # Check whether only capital letters are used for typedef declarations self.NamingConventionCheckTypedefStatement = 1 - # Check whether the #ifndef at the start of an include file uses both prefix and postfix underscore characters, '_'. - self.NamingConventionCheckIfndefStatement = 1 # Rule for path name, variable name and function name # 1. First character should be upper case # 2. Existing lower case in a word diff --git a/BaseTools/Source/Python/Ecc/EccToolError.py b/BaseTools/Source/Python/Ecc/EccToolError.py index ba0bcfff57..1b179fc9a2 100644 --- a/BaseTools/Source/Python/Ecc/EccToolError.py +++ b/BaseTools/Source/Python/Ecc/EccToolError.py @@ -43,9 +43,6 @@ ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_PROTO_TYPE_2 = 5009 ERROR_C_FUNCTION_LAYOUT_CHECK_FUNCTION_PROTO_TYPE_3 = 5010 ERROR_INCLUDE_FILE_CHECK_ALL = 6000 -ERROR_INCLUDE_FILE_CHECK_IFNDEF_STATEMENT_1 = 6001 -ERROR_INCLUDE_FILE_CHECK_IFNDEF_STATEMENT_2 = 6002 -ERROR_INCLUDE_FILE_CHECK_IFNDEF_STATEMENT_3 = 6003 ERROR_INCLUDE_FILE_CHECK_DATA = 6004 ERROR_INCLUDE_FILE_CHECK_NAME = 6005 @@ -62,7 +59,6 @@ ERROR_DECLARATION_DATA_TYPE_CHECK_NESTED_STRUCTURE = 7008 ERROR_NAMING_CONVENTION_CHECK_ALL = 8000 ERROR_NAMING_CONVENTION_CHECK_DEFINE_STATEMENT = 8001 ERROR_NAMING_CONVENTION_CHECK_TYPEDEF_STATEMENT = 8002 -ERROR_NAMING_CONVENTION_CHECK_IFNDEF_STATEMENT = 8003 ERROR_NAMING_CONVENTION_CHECK_PATH_NAME = 8004 ERROR_NAMING_CONVENTION_CHECK_VARIABLE_NAME = 8005 ERROR_NAMING_CONVENTION_CHECK_FUNCTION_NAME = 8006 @@ -141,9 +137,6 @@ gEccErrorMessage = { ERROR_C_FUNCTION_LAYOUT_CHECK_NO_STATIC : "There should be no use of STATIC for functions", ERROR_INCLUDE_FILE_CHECK_ALL : "", - ERROR_INCLUDE_FILE_CHECK_IFNDEF_STATEMENT_1 : "All include file contents should be guarded by a #ifndef statement.", - ERROR_INCLUDE_FILE_CHECK_IFNDEF_STATEMENT_2 : "The #ifndef must be the first line of code following the file header comment", - ERROR_INCLUDE_FILE_CHECK_IFNDEF_STATEMENT_3 : "The #endif must appear on the last line in the file", ERROR_INCLUDE_FILE_CHECK_DATA : "Include files should contain only public or only private data and cannot contain code or define data variables", ERROR_INCLUDE_FILE_CHECK_NAME : "No permission for the include file with same names", @@ -160,7 +153,6 @@ gEccErrorMessage = { ERROR_NAMING_CONVENTION_CHECK_ALL : "", ERROR_NAMING_CONVENTION_CHECK_DEFINE_STATEMENT : "Only capital letters are allowed to be used for #define declarations", ERROR_NAMING_CONVENTION_CHECK_TYPEDEF_STATEMENT : "Only capital letters are allowed to be used for typedef declarations", - ERROR_NAMING_CONVENTION_CHECK_IFNDEF_STATEMENT : "The #ifndef at the start of an include file should have one postfix underscore, and no prefix underscore character '_'", ERROR_NAMING_CONVENTION_CHECK_PATH_NAME : """Path name does not follow the rules: 1. First character should be upper case 2. Must contain lower case characters 3. No white space characters""", ERROR_NAMING_CONVENTION_CHECK_VARIABLE_NAME : """Variable name does not follow the rules: 1. First character should be upper case 2. Must contain lower case characters 3. No white space characters 4. Global variable name must start with a 'g'""", ERROR_NAMING_CONVENTION_CHECK_FUNCTION_NAME : """Function name does not follow the rules: 1. First character should be upper case 2. Must contain lower case characters 3. No white space characters""", diff --git a/BaseTools/Source/Python/Ecc/c.py b/BaseTools/Source/Python/Ecc/c.py index a6b9076f91..a3c6a021ad 100644 --- a/BaseTools/Source/Python/Ecc/c.py +++ b/BaseTools/Source/Python/Ecc/c.py @@ -2167,44 +2167,6 @@ def CheckHeaderFileData(FullFileName, AllTypedefFun=[]): return ErrorMsgList -def CheckHeaderFileIfndef(FullFileName): - ErrorMsgList = [] - - FileID = GetTableID(FullFileName, ErrorMsgList) - if FileID < 0: - return ErrorMsgList - - Db = GetDB() - FileTable = 'Identifier' + str(FileID) - SqlStatement = """ select Value, StartLine - from %s - where Model = %d order by StartLine - """ % (FileTable, DataClass.MODEL_IDENTIFIER_MACRO_IFNDEF) - ResultSet = Db.TblFile.Exec(SqlStatement) - if len(ResultSet) == 0: - PrintErrorMsg(ERROR_INCLUDE_FILE_CHECK_IFNDEF_STATEMENT_1, '', 'File', FileID) - return ErrorMsgList - for Result in ResultSet: - SqlStatement = """ select Value, EndLine - from %s - where EndLine < %d - """ % (FileTable, Result[1]) - ResultSet = Db.TblFile.Exec(SqlStatement) - for Result in ResultSet: - if not Result[0].startswith('/*') and not Result[0].startswith('//'): - PrintErrorMsg(ERROR_INCLUDE_FILE_CHECK_IFNDEF_STATEMENT_2, '', 'File', FileID) - break - - SqlStatement = """ select Value - from %s - where StartLine > (select max(EndLine) from %s where Model = %d) - """ % (FileTable, FileTable, DataClass.MODEL_IDENTIFIER_MACRO_ENDIF) - ResultSet = Db.TblFile.Exec(SqlStatement) - for Result in ResultSet: - if not Result[0].startswith('/*') and not Result[0].startswith('//'): - PrintErrorMsg(ERROR_INCLUDE_FILE_CHECK_IFNDEF_STATEMENT_3, '', 'File', FileID) - return ErrorMsgList - def CheckDoxygenCommand(FullFileName): ErrorMsgList = [] diff --git a/BaseTools/Source/Python/Ecc/config.ini b/BaseTools/Source/Python/Ecc/config.ini index ba4346e25b..943a87af0a 100644 --- a/BaseTools/Source/Python/Ecc/config.ini +++ b/BaseTools/Source/Python/Ecc/config.ini @@ -134,10 +134,6 @@ IncludeFileCheckAll = 0 #Check whether having include files with same name IncludeFileCheckSameName = 1 -# Check whether all include file contents is guarded by a #ifndef statement. -# the #ifndef must be the first line of code following the file header comment -# the #endif must appear on the last line in the file -IncludeFileCheckIfndefStatement = 1 # Check whether include files contain only public or only private data # Check whether include files NOT contain code or define data variables IncludeFileCheckData = 1 @@ -172,8 +168,6 @@ NamingConventionCheckAll = 0 NamingConventionCheckDefineStatement = 1 # Check whether only capital letters are used for typedef declarations NamingConventionCheckTypedefStatement = 1 -# Check whether the #ifndef at the start of an include file uses both prefix and postfix underscore characters, '_'. -NamingConventionCheckIfndefStatement = 1 # Rule for path name, variable name and function name # 1. First character should be upper case # 2. Existing lower case in a word