## @file\r
# This file is used to define class Configuration\r
#\r
-# Copyright (c) 2008, Intel Corporation\r
-# All rights reserved. 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
-# http://opensource.org/licenses/bsd-license.php\r
-#\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
+# Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
#\r
\r
##\r
# Import Modules\r
#\r
-import os\r
+from __future__ import print_function\r
+import Common.LongFilePathOs as os\r
import Common.EdkLogger as EdkLogger\r
from Common.DataType import *\r
-from Common.String import *\r
+from Common.StringUtils import *\r
+from Common.LongFilePathSupport import OpenLongFilePath as open\r
+\r
+_ConfigFileToInternalTranslation = {\r
+ # not same\r
+ "ModifierList":"ModifierSet",\r
+\r
+ # same\r
+ # please keep this in correct alphabetical order.\r
+ "AutoCorrect":"AutoCorrect",\r
+ "BinaryExtList":"BinaryExtList",\r
+ "CFunctionLayoutCheckAll":"CFunctionLayoutCheckAll",\r
+ "CFunctionLayoutCheckDataDeclaration":"CFunctionLayoutCheckDataDeclaration",\r
+ "CFunctionLayoutCheckFunctionBody":"CFunctionLayoutCheckFunctionBody",\r
+ "CFunctionLayoutCheckFunctionName":"CFunctionLayoutCheckFunctionName",\r
+ "CFunctionLayoutCheckFunctionPrototype":"CFunctionLayoutCheckFunctionPrototype",\r
+ "CFunctionLayoutCheckNoInitOfVariable":"CFunctionLayoutCheckNoInitOfVariable",\r
+ "CFunctionLayoutCheckNoStatic":"CFunctionLayoutCheckNoStatic",\r
+ "CFunctionLayoutCheckOptionalFunctionalModifier":"CFunctionLayoutCheckOptionalFunctionalModifier",\r
+ "CFunctionLayoutCheckReturnType":"CFunctionLayoutCheckReturnType",\r
+ "CheckAll":"CheckAll",\r
+ "Copyright":"Copyright",\r
+ "DeclarationDataTypeCheckAll":"DeclarationDataTypeCheckAll",\r
+ "DeclarationDataTypeCheckEFIAPIModifier":"DeclarationDataTypeCheckEFIAPIModifier",\r
+ "DeclarationDataTypeCheckEnumeratedType":"DeclarationDataTypeCheckEnumeratedType",\r
+ "DeclarationDataTypeCheckInOutModifier":"DeclarationDataTypeCheckInOutModifier",\r
+ "DeclarationDataTypeCheckNoUseCType":"DeclarationDataTypeCheckNoUseCType",\r
+ "DeclarationDataTypeCheckSameStructure":"DeclarationDataTypeCheckSameStructure",\r
+ "DeclarationDataTypeCheckStructureDeclaration":"DeclarationDataTypeCheckStructureDeclaration",\r
+ "DeclarationDataTypeCheckUnionType":"DeclarationDataTypeCheckUnionType",\r
+ "DoxygenCheckAll":"DoxygenCheckAll",\r
+ "DoxygenCheckCommand":"DoxygenCheckCommand",\r
+ "DoxygenCheckCommentDescription":"DoxygenCheckCommentDescription",\r
+ "DoxygenCheckCommentFormat":"DoxygenCheckCommentFormat",\r
+ "DoxygenCheckFileHeader":"DoxygenCheckFileHeader",\r
+ "DoxygenCheckFunctionHeader":"DoxygenCheckFunctionHeader",\r
+ "GeneralCheckAll":"GeneralCheckAll",\r
+ "GeneralCheckCarriageReturn":"GeneralCheckCarriageReturn",\r
+ "GeneralCheckFileExistence":"GeneralCheckFileExistence",\r
+ "GeneralCheckIndentation":"GeneralCheckIndentation",\r
+ "GeneralCheckIndentationWidth":"GeneralCheckIndentationWidth",\r
+ "GeneralCheckLine":"GeneralCheckLine",\r
+ "GeneralCheckLineEnding":"GeneralCheckLineEnding",\r
+ "GeneralCheckLineWidth":"GeneralCheckLineWidth",\r
+ "GeneralCheckNoProgma":"GeneralCheckNoProgma",\r
+ "GeneralCheckNoTab":"GeneralCheckNoTab",\r
+ "GeneralCheckNo_Asm":"GeneralCheckNo_Asm",\r
+ "GeneralCheckNonAcsii":"GeneralCheckNonAcsii",\r
+ "GeneralCheckTabWidth":"GeneralCheckTabWidth",\r
+ "GeneralCheckTrailingWhiteSpaceLine":"GeneralCheckTrailingWhiteSpaceLine",\r
+ "GeneralCheckUni":"GeneralCheckUni",\r
+ "HeaderCheckAll":"HeaderCheckAll",\r
+ "HeaderCheckCFileCommentLicenseFormat":"HeaderCheckCFileCommentLicenseFormat",\r
+ "HeaderCheckCFileCommentReferenceFormat":"HeaderCheckCFileCommentReferenceFormat",\r
+ "HeaderCheckCFileCommentStartSpacesNum":"HeaderCheckCFileCommentStartSpacesNum",\r
+ "HeaderCheckFile":"HeaderCheckFile",\r
+ "HeaderCheckFileCommentEnd":"HeaderCheckFileCommentEnd",\r
+ "HeaderCheckFunction":"HeaderCheckFunction",\r
+ "IncludeFileCheckAll":"IncludeFileCheckAll",\r
+ "IncludeFileCheckData":"IncludeFileCheckData",\r
+ "IncludeFileCheckIfndefStatement":"IncludeFileCheckIfndefStatement",\r
+ "IncludeFileCheckSameName":"IncludeFileCheckSameName",\r
+ "MetaDataFileCheckAll":"MetaDataFileCheckAll",\r
+ "MetaDataFileCheckBinaryInfInFdf":"MetaDataFileCheckBinaryInfInFdf",\r
+ "MetaDataFileCheckGenerateFileList":"MetaDataFileCheckGenerateFileList",\r
+ "MetaDataFileCheckGuidDuplicate":"MetaDataFileCheckGuidDuplicate",\r
+ "MetaDataFileCheckLibraryDefinedInDec":"MetaDataFileCheckLibraryDefinedInDec",\r
+ "MetaDataFileCheckLibraryInstance":"MetaDataFileCheckLibraryInstance",\r
+ "MetaDataFileCheckLibraryInstanceDependent":"MetaDataFileCheckLibraryInstanceDependent",\r
+ "MetaDataFileCheckLibraryInstanceOrder":"MetaDataFileCheckLibraryInstanceOrder",\r
+ "MetaDataFileCheckLibraryNoUse":"MetaDataFileCheckLibraryNoUse",\r
+ "MetaDataFileCheckModuleFileGuidDuplication":"MetaDataFileCheckModuleFileGuidDuplication",\r
+ "MetaDataFileCheckModuleFileGuidFormat":"MetaDataFileCheckModuleFileGuidFormat",\r
+ "MetaDataFileCheckModuleFileNoUse":"MetaDataFileCheckModuleFileNoUse",\r
+ "MetaDataFileCheckModuleFilePcdFormat":"MetaDataFileCheckModuleFilePcdFormat",\r
+ "MetaDataFileCheckModuleFilePpiFormat":"MetaDataFileCheckModuleFilePpiFormat",\r
+ "MetaDataFileCheckModuleFileProtocolFormat":"MetaDataFileCheckModuleFileProtocolFormat",\r
+ "MetaDataFileCheckPathName":"MetaDataFileCheckPathName",\r
+ "MetaDataFileCheckPathOfGenerateFileList":"MetaDataFileCheckPathOfGenerateFileList",\r
+ "MetaDataFileCheckPcdDuplicate":"MetaDataFileCheckPcdDuplicate",\r
+ "MetaDataFileCheckPcdFlash":"MetaDataFileCheckPcdFlash",\r
+ "MetaDataFileCheckPcdNoUse":"MetaDataFileCheckPcdNoUse",\r
+ "MetaDataFileCheckPcdType":"MetaDataFileCheckPcdType",\r
+ "NamingConventionCheckAll":"NamingConventionCheckAll",\r
+ "NamingConventionCheckDefineStatement":"NamingConventionCheckDefineStatement",\r
+ "NamingConventionCheckFunctionName":"NamingConventionCheckFunctionName",\r
+ "NamingConventionCheckIfndefStatement":"NamingConventionCheckIfndefStatement",\r
+ "NamingConventionCheckPathName":"NamingConventionCheckPathName",\r
+ "NamingConventionCheckSingleCharacterVariable":"NamingConventionCheckSingleCharacterVariable",\r
+ "NamingConventionCheckTypedefStatement":"NamingConventionCheckTypedefStatement",\r
+ "NamingConventionCheckVariableName":"NamingConventionCheckVariableName",\r
+ "PredicateExpressionCheckAll":"PredicateExpressionCheckAll",\r
+ "PredicateExpressionCheckBooleanValue":"PredicateExpressionCheckBooleanValue",\r
+ "PredicateExpressionCheckComparisonNullType":"PredicateExpressionCheckComparisonNullType",\r
+ "PredicateExpressionCheckNonBooleanOperator":"PredicateExpressionCheckNonBooleanOperator",\r
+ "ScanOnlyDirList":"ScanOnlyDirList",\r
+ "SkipDirList":"SkipDirList",\r
+ "SkipFileList":"SkipFileList",\r
+ "SmmCommParaCheckAll":"SmmCommParaCheckAll",\r
+ "SmmCommParaCheckBufferType":"SmmCommParaCheckBufferType",\r
+ "SpaceCheckAll":"SpaceCheckAll",\r
+ "SpellingCheckAll":"SpellingCheckAll",\r
+ "UniCheckAll":"UniCheckAll",\r
+ "UniCheckHelpInfo":"UniCheckHelpInfo",\r
+ "UniCheckPCDInfo":"UniCheckPCDInfo",\r
+ "Version":"Version"\r
+ }\r
\r
## Configuration\r
#\r
class Configuration(object):\r
def __init__(self, Filename):\r
self.Filename = Filename\r
- \r
+\r
self.Version = 0.1\r
\r
## Identify to if check all items\r
# SpaceCheckAll\r
#\r
self.AutoCorrect = 0\r
- \r
+\r
# List customized Modifer here, split with ','\r
# Defaultly use the definition in class DataType\r
- self.ModifierList = MODIFIER_LIST\r
- \r
+ self.ModifierSet = MODIFIER_SET\r
+\r
## General Checking\r
self.GeneralCheckAll = 0\r
- \r
+\r
# Check whether NO Tab is used, replaced with spaces\r
self.GeneralCheckNoTab = 1\r
# The width of Tab\r
self.GeneralCheckCarriageReturn = 1\r
# Check whether the file exists\r
self.GeneralCheckFileExistence = 1\r
- \r
+ # Check whether file has non ACSII char\r
+ self.GeneralCheckNonAcsii = 1\r
+ # Check whether UNI file is valid\r
+ self.GeneralCheckUni = 1\r
+ # Check Only use CRLF (Carriage Return Line Feed) line endings.\r
+ self.GeneralCheckLineEnding = 1\r
+ # Check if there is no trailing white space in one line.\r
+ self.GeneralCheckTrailingWhiteSpaceLine = 1\r
+\r
+ self.CFunctionLayoutCheckNoDeprecated = 1\r
+\r
## Space Checking\r
self.SpaceCheckAll = 1\r
- \r
+\r
## Predicate Expression Checking\r
self.PredicateExpressionCheckAll = 0\r
- \r
+\r
# Check whether Boolean values, variable type BOOLEAN not use explicit comparisons to TRUE or FALSE\r
self.PredicateExpressionCheckBooleanValue = 1\r
- # Check whether Non-Boolean comparisons use a compare operator (==, !=, >, < >=, <=). \r
+ # Check whether Non-Boolean comparisons use a compare operator (==, !=, >, < >=, <=).\r
self.PredicateExpressionCheckNonBooleanOperator = 1\r
# Check whether a comparison of any pointer to zero must be done via the NULL type\r
self.PredicateExpressionCheckComparisonNullType = 1\r
- \r
+\r
## Headers Checking\r
self.HeaderCheckAll = 0\r
- \r
+\r
# Check whether File header exists\r
self.HeaderCheckFile = 1\r
# Check whether Function header exists\r
self.HeaderCheckFunction = 1\r
- \r
+ # Check whether Meta data File header Comment End with '##'\r
+ self.HeaderCheckFileCommentEnd = 1\r
+ # Check whether C File header Comment content start with two spaces\r
+ self.HeaderCheckCFileCommentStartSpacesNum = 1\r
+ # Check whether C File header Comment's each reference at list should begin with a bullet character '-'\r
+ self.HeaderCheckCFileCommentReferenceFormat = 1\r
+ # Check whether C File header Comment have the License immediately after the ""Copyright"" line\r
+ self.HeaderCheckCFileCommentLicenseFormat = 1\r
+\r
## C Function Layout Checking\r
self.CFunctionLayoutCheckAll = 0\r
- \r
+\r
# Check whether return type exists and in the first line\r
self.CFunctionLayoutCheckReturnType = 1\r
# Check whether any optional functional modifiers exist and next to the return type\r
self.CFunctionLayoutCheckNoInitOfVariable = 1\r
# Check whether no use of STATIC for functions\r
self.CFunctionLayoutCheckNoStatic = 1\r
- \r
+\r
## Include Files Checking\r
self.IncludeFileCheckAll = 0\r
- \r
+\r
#Check whether having include files with same name\r
self.IncludeFileCheckSameName = 1\r
# Check whether all include file contents is guarded by a #ifndef statement.\r
# Check whether include files contain only public or only private data\r
# Check whether include files NOT contain code or define data variables\r
self.IncludeFileCheckData = 1\r
- \r
+\r
## Declarations and Data Types Checking\r
self.DeclarationDataTypeCheckAll = 0\r
- \r
+\r
# Check whether no use of int, unsigned, char, void, static, long in any .c, .h or .asl files.\r
self.DeclarationDataTypeCheckNoUseCType = 1\r
# Check whether the modifiers IN, OUT, OPTIONAL, and UNALIGNED are used only to qualify arguments to a function and should not appear in a data type declaration\r
self.DeclarationDataTypeCheckSameStructure = 1\r
# Check whether Union Type has a 'typedef' and the name is capital\r
self.DeclarationDataTypeCheckUnionType = 1\r
- \r
+\r
## Naming Conventions Checking\r
self.NamingConventionCheckAll = 0\r
- \r
+\r
# Check whether only capital letters are used for #define declarations\r
self.NamingConventionCheckDefineStatement = 1\r
# Check whether only capital letters are used for typedef declarations\r
self.NamingConventionCheckFunctionName = 1\r
# Check whether NO use short variable name with single character\r
self.NamingConventionCheckSingleCharacterVariable = 1\r
- \r
+\r
## Doxygen Checking\r
self.DoxygenCheckAll = 0\r
- \r
+\r
# Check whether the file headers are followed Doxygen special documentation blocks in section 2.3.5\r
self.DoxygenCheckFileHeader = 1\r
# Check whether the function headers are followed Doxygen special documentation blocks in section 2.3.5\r
self.DoxygenCheckFunctionHeader = 1\r
- # Check whether the first line of text in a comment block is a brief description of the element being documented. \r
+ # Check whether the first line of text in a comment block is a brief description of the element being documented.\r
# The brief description must end with a period.\r
self.DoxygenCheckCommentDescription = 1\r
# Check whether comment lines with '///< ... text ...' format, if it is used, it should be after the code section.\r
self.DoxygenCheckCommentFormat = 1\r
# Check whether only Doxygen commands allowed to mark the code are @bug and @todo.\r
self.DoxygenCheckCommand = 1\r
- \r
+\r
## Meta-Data File Processing Checking\r
self.MetaDataFileCheckAll = 0\r
- \r
+\r
# Check whether each file defined in meta-data exists\r
self.MetaDataFileCheckPathName = 1\r
# Generate a list for all files defined in meta-data files\r
self.MetaDataFileCheckGenerateFileList = 1\r
# The path of log file\r
self.MetaDataFileCheckPathOfGenerateFileList = 'File.log'\r
- # Check whether all Library Instances defined for a given module (or dependent library instance) match the module's type. \r
- # Each Library Instance must specify the Supported Module Types in its INF file, \r
+ # Check whether all Library Instances defined for a given module (or dependent library instance) match the module's type.\r
+ # Each Library Instance must specify the Supported Module Types in its INF file,\r
# and any module specifying the library instance must be one of the supported types.\r
self.MetaDataFileCheckLibraryInstance = 1\r
# Check whether a Library Instance has been defined for all dependent library classes\r
self.MetaDataFileCheckLibraryInstanceOrder = 1\r
# Check whether the unnecessary inclusion of library classes in the INF file\r
self.MetaDataFileCheckLibraryNoUse = 1\r
+ # Check the header file in Include\Library directory whether be defined in the package DEC file.\r
+ self.MetaDataFileCheckLibraryDefinedInDec = 1\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
self.MetaDataFileCheckBinaryInfInFdf = 1\r
# Not to report error and warning related OS include file such as "windows.h" and "stdio.h"\r
self.MetaDataFileCheckModuleFileNoUse = 1\r
# Check whether the PCD is correctly used in C function via its type\r
self.MetaDataFileCheckPcdType = 1\r
- \r
+ # Check whether there are FILE_GUID duplication among different INF files\r
+ self.MetaDataFileCheckModuleFileGuidDuplication = 1\r
+\r
+ # Check Guid Format in INF files\r
+ self.MetaDataFileCheckModuleFileGuidFormat = 1\r
+ # Check Protocol Format in INF files\r
+ self.MetaDataFileCheckModuleFileProtocolFormat = 1\r
+ # Check Ppi Format in INF files\r
+ self.MetaDataFileCheckModuleFilePpiFormat = 1\r
+ # Check Pcd Format in INF files\r
+ self.MetaDataFileCheckModuleFilePcdFormat = 1\r
+\r
+ # Check UNI file\r
+ self.UniCheckAll = 0\r
+ # Check INF or DEC file whether defined the localized information in the associated UNI file.\r
+ self.UniCheckHelpInfo = 1\r
+ # Check PCD whether defined the prompt, help in the DEC file and localized information in the associated UNI file.\r
+ self.UniCheckPCDInfo = 1\r
+\r
+ # Check SMM communication function parameter\r
+ self.SmmCommParaCheckAll = 0\r
+ # Check if the EFI_SMM_COMMUNICATION_PROTOCOL parameter buffer type is Reserved / ACPI NVS or UEFI RT code/data\r
+ self.SmmCommParaCheckBufferType = -1\r
+\r
#\r
# The check points in this section are reserved\r
#\r
# The directory listed here will not be parsed, split with ','\r
self.SkipDirList = []\r
\r
+ # The file listed here will not be parsed, split with ','\r
+ self.SkipFileList = []\r
+\r
+ # A list for binary file ext name\r
+ self.BinaryExtList = []\r
+\r
+ # A list for only scanned folders\r
+ self.ScanOnlyDirList = []\r
+\r
+ # A list for Copyright format\r
+ self.Copyright = []\r
+\r
self.ParseConfig()\r
- \r
+\r
def ParseConfig(self):\r
Filepath = os.path.normpath(self.Filename)\r
if not os.path.isfile(Filepath):\r
ErrorMsg = "Can't find configuration file '%s'" % Filepath\r
EdkLogger.error("Ecc", EdkLogger.ECC_ERROR, ErrorMsg, File = Filepath)\r
- \r
+\r
LineNo = 0\r
for Line in open(Filepath, 'r'):\r
LineNo = LineNo + 1\r
Line = CleanString(Line)\r
if Line != '':\r
List = GetSplitValueList(Line, TAB_EQUAL_SPLIT)\r
- if List[0] not in self.__dict__:\r
+ if List[0] not in _ConfigFileToInternalTranslation:\r
ErrorMsg = "Invalid configuration option '%s' was found" % List[0]\r
EdkLogger.error("Ecc", EdkLogger.ECC_ERROR, ErrorMsg, File = Filepath, Line = LineNo)\r
+ assert _ConfigFileToInternalTranslation[List[0]] in self.__dict__\r
if List[0] == 'ModifierList':\r
List[1] = GetSplitValueList(List[1], TAB_COMMA_SPLIT)\r
if List[0] == 'MetaDataFileCheckPathOfGenerateFileList' and List[1] == "":\r
continue\r
if List[0] == 'SkipDirList':\r
List[1] = GetSplitValueList(List[1], TAB_COMMA_SPLIT)\r
- self.__dict__[List[0]] = List[1]\r
- \r
+ if List[0] == 'SkipFileList':\r
+ List[1] = GetSplitValueList(List[1], TAB_COMMA_SPLIT)\r
+ if List[0] == 'BinaryExtList':\r
+ List[1] = GetSplitValueList(List[1], TAB_COMMA_SPLIT)\r
+ if List[0] == 'Copyright':\r
+ List[1] = GetSplitValueList(List[1], TAB_COMMA_SPLIT)\r
+ self.__dict__[_ConfigFileToInternalTranslation[List[0]]] = List[1]\r
+\r
def ShowMe(self):\r
- print self.Filename\r
+ print(self.Filename)\r
for Key in self.__dict__.keys():\r
- print Key, '=', self.__dict__[Key]\r
+ print(Key, '=', self.__dict__[Key])\r
+\r
+#\r
+# test that our dict and out class still match in contents.\r
+#\r
+if __name__ == '__main__':\r
+ myconfig = Configuration("BaseTools\Source\Python\Ecc\config.ini")\r
+ for each in myconfig.__dict__:\r
+ if each == "Filename":\r
+ continue\r
+ assert each in _ConfigFileToInternalTranslation.values()\r
+ for each in _ConfigFileToInternalTranslation.values():\r
+ assert each in myconfig.__dict__\r