2 # This file is used to define class Configuration
4 # Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.<BR>
5 # This program and the accompanying materials
6 # are licensed and made available under the terms and conditions of the BSD License
7 # which accompanies this distribution. The full text of the license may be found at
8 # http://opensource.org/licenses/bsd-license.php
10 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 import Common
.EdkLogger
as EdkLogger
19 from Common
.DataType
import *
20 from Common
.String
import *
24 # This class is used to define all items in configuration file
26 # @param Filename: The name of configuration file, the default is config.ini
28 class Configuration(object):
29 def __init__(self
, Filename
):
30 self
.Filename
= Filename
34 ## Identify to if check all items
35 # 1 - Check all items and ignore all other detailed items
36 # 0 - Not check all items, the tool will go through all other detailed items to decide to check or not
40 ## Identify to if automatically correct mistakes
41 # 1 - Automatically correct
42 # 0 - Not automatically correct
43 # Only the following check points can be automatically corrected, others not listed below are not supported even it is 1
46 # GeneralCheckIndentation
48 # GeneralCheckCarriageReturn
53 # List customized Modifer here, split with ','
54 # Defaultly use the definition in class DataType
55 self
.ModifierList
= MODIFIER_LIST
58 self
.GeneralCheckAll
= 0
60 # Check whether NO Tab is used, replaced with spaces
61 self
.GeneralCheckNoTab
= 1
63 self
.GeneralCheckTabWidth
= 2
64 # Check whether the indentation is followed coding style
65 self
.GeneralCheckIndentation
= 1
66 # The width of indentation
67 self
.GeneralCheckIndentationWidth
= 2
68 # Check whether no line is exceeding defined widty
69 self
.GeneralCheckLine
= 1
71 self
.GeneralCheckLineWidth
= 120
72 # Check whether no use of _asm in the source file
73 self
.GeneralCheckNo_Asm
= 1
74 # Check whether no use of "#progma" in source file except "#pragma pack(#)".
75 self
.GeneralCheckNoProgma
= 1
76 # Check whether there is a carriage return at the end of the file
77 self
.GeneralCheckCarriageReturn
= 1
78 # Check whether the file exists
79 self
.GeneralCheckFileExistence
= 1
80 # Check whether file has non ACSII char
81 self
.GeneralCheckNonAcsii
= 1
84 self
.SpaceCheckAll
= 1
86 ## Predicate Expression Checking
87 self
.PredicateExpressionCheckAll
= 0
89 # Check whether Boolean values, variable type BOOLEAN not use explicit comparisons to TRUE or FALSE
90 self
.PredicateExpressionCheckBooleanValue
= 1
91 # Check whether Non-Boolean comparisons use a compare operator (==, !=, >, < >=, <=).
92 self
.PredicateExpressionCheckNonBooleanOperator
= 1
93 # Check whether a comparison of any pointer to zero must be done via the NULL type
94 self
.PredicateExpressionCheckComparisonNullType
= 1
97 self
.HeaderCheckAll
= 0
99 # Check whether File header exists
100 self
.HeaderCheckFile
= 1
101 # Check whether Function header exists
102 self
.HeaderCheckFunction
= 1
103 # Check whether Meta data File header Comment End with '##'
104 self
.HeaderCheckFileCommentEnd
= 1
105 # Check whether C File header Comment content start with two spaces
106 self
.HeaderCheckCFileCommentStartSpacesNum
= 1
107 # Check whether C File header Comment's each reference at list should begin with a bullet character '-'
108 self
.HeaderCheckCFileCommentReferenceFormat
= 1
109 # Check whether C File header Comment have the License immediately after the ""Copyright"" line
110 self
.HeaderCheckCFileCommentLicenseFormat
= 1
112 ## C Function Layout Checking
113 self
.CFunctionLayoutCheckAll
= 0
115 # Check whether return type exists and in the first line
116 self
.CFunctionLayoutCheckReturnType
= 1
117 # Check whether any optional functional modifiers exist and next to the return type
118 self
.CFunctionLayoutCheckOptionalFunctionalModifier
= 1
119 # Check whether the next line contains the function name, left justified, followed by the beginning of the parameter list
120 # Check whether the closing parenthesis is on its own line and also indented two spaces
121 self
.CFunctionLayoutCheckFunctionName
= 1
122 # Check whether the function prototypes in include files have the same form as function definitions
123 self
.CFunctionLayoutCheckFunctionPrototype
= 1
124 # Check whether the body of a function is contained by open and close braces that must be in the first column
125 self
.CFunctionLayoutCheckFunctionBody
= 1
126 # Check whether the data declarations is the first code in a module.
127 self
.CFunctionLayoutCheckDataDeclaration
= 1
128 # Check whether no initialization of a variable as part of its declaration
129 self
.CFunctionLayoutCheckNoInitOfVariable
= 1
130 # Check whether no use of STATIC for functions
131 self
.CFunctionLayoutCheckNoStatic
= 1
133 ## Include Files Checking
134 self
.IncludeFileCheckAll
= 0
136 #Check whether having include files with same name
137 self
.IncludeFileCheckSameName
= 1
138 # Check whether all include file contents is guarded by a #ifndef statement.
139 # the #ifndef must be the first line of code following the file header comment
140 # the #endif must appear on the last line in the file
141 self
.IncludeFileCheckIfndefStatement
= 1
142 # Check whether include files contain only public or only private data
143 # Check whether include files NOT contain code or define data variables
144 self
.IncludeFileCheckData
= 1
146 ## Declarations and Data Types Checking
147 self
.DeclarationDataTypeCheckAll
= 0
149 # Check whether no use of int, unsigned, char, void, static, long in any .c, .h or .asl files.
150 self
.DeclarationDataTypeCheckNoUseCType
= 1
151 # 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
152 self
.DeclarationDataTypeCheckInOutModifier
= 1
153 # Check whether the EFIAPI modifier should be used at the entry of drivers, events, and member functions of protocols
154 self
.DeclarationDataTypeCheckEFIAPIModifier
= 1
155 # Check whether Enumerated Type has a 'typedef' and the name is capital
156 self
.DeclarationDataTypeCheckEnumeratedType
= 1
157 # Check whether Structure Type has a 'typedef' and the name is capital
158 self
.DeclarationDataTypeCheckStructureDeclaration
= 1
159 # Check whether having same Structure
160 self
.DeclarationDataTypeCheckSameStructure
= 1
161 # Check whether Union Type has a 'typedef' and the name is capital
162 self
.DeclarationDataTypeCheckUnionType
= 1
164 ## Naming Conventions Checking
165 self
.NamingConventionCheckAll
= 0
167 # Check whether only capital letters are used for #define declarations
168 self
.NamingConventionCheckDefineStatement
= 1
169 # Check whether only capital letters are used for typedef declarations
170 self
.NamingConventionCheckTypedefStatement
= 1
171 # Check whether the #ifndef at the start of an include file uses both prefix and postfix underscore characters, '_'.
172 self
.NamingConventionCheckIfndefStatement
= 1
173 # Rule for path name, variable name and function name
174 # 1. First character should be upper case
175 # 2. Existing lower case in a word
176 # 3. No space existence
177 # Check whether the path name followed the rule
178 self
.NamingConventionCheckPathName
= 1
179 # Check whether the variable name followed the rule
180 self
.NamingConventionCheckVariableName
= 1
181 # Check whether the function name followed the rule
182 self
.NamingConventionCheckFunctionName
= 1
183 # Check whether NO use short variable name with single character
184 self
.NamingConventionCheckSingleCharacterVariable
= 1
187 self
.DoxygenCheckAll
= 0
189 # Check whether the file headers are followed Doxygen special documentation blocks in section 2.3.5
190 self
.DoxygenCheckFileHeader
= 1
191 # Check whether the function headers are followed Doxygen special documentation blocks in section 2.3.5
192 self
.DoxygenCheckFunctionHeader
= 1
193 # Check whether the first line of text in a comment block is a brief description of the element being documented.
194 # The brief description must end with a period.
195 self
.DoxygenCheckCommentDescription
= 1
196 # Check whether comment lines with '///< ... text ...' format, if it is used, it should be after the code section.
197 self
.DoxygenCheckCommentFormat
= 1
198 # Check whether only Doxygen commands allowed to mark the code are @bug and @todo.
199 self
.DoxygenCheckCommand
= 1
201 ## Meta-Data File Processing Checking
202 self
.MetaDataFileCheckAll
= 0
204 # Check whether each file defined in meta-data exists
205 self
.MetaDataFileCheckPathName
= 1
206 # Generate a list for all files defined in meta-data files
207 self
.MetaDataFileCheckGenerateFileList
= 1
208 # The path of log file
209 self
.MetaDataFileCheckPathOfGenerateFileList
= 'File.log'
210 # Check whether all Library Instances defined for a given module (or dependent library instance) match the module's type.
211 # Each Library Instance must specify the Supported Module Types in its INF file,
212 # and any module specifying the library instance must be one of the supported types.
213 self
.MetaDataFileCheckLibraryInstance
= 1
214 # Check whether a Library Instance has been defined for all dependent library classes
215 self
.MetaDataFileCheckLibraryInstanceDependent
= 1
216 # Check whether the Library Instances specified by the LibraryClasses sections are listed in order of dependencies
217 self
.MetaDataFileCheckLibraryInstanceOrder
= 1
218 # Check whether the unnecessary inclusion of library classes in the INF file
219 self
.MetaDataFileCheckLibraryNoUse
= 1
220 # 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
221 self
.MetaDataFileCheckBinaryInfInFdf
= 1
222 # Not to report error and warning related OS include file such as "windows.h" and "stdio.h"
223 # Check whether a PCD is set in a DSC file or the FDF file, but not in both.
224 self
.MetaDataFileCheckPcdDuplicate
= 1
225 # Check whether PCD settings in the FDF file can only be related to flash.
226 self
.MetaDataFileCheckPcdFlash
= 1
227 # Check whether PCDs used in INF files but not specified in DSC or FDF files
228 self
.MetaDataFileCheckPcdNoUse
= 1
229 # Check whether having duplicate guids defined for Guid/Protocol/Ppi
230 self
.MetaDataFileCheckGuidDuplicate
= 1
231 # Check whether all files under module directory are described in INF files
232 self
.MetaDataFileCheckModuleFileNoUse
= 1
233 # Check whether the PCD is correctly used in C function via its type
234 self
.MetaDataFileCheckPcdType
= 1
235 # Check whether there are FILE_GUID duplication among different INF files
236 self
.MetaDataFileCheckModuleFileGuidDuplication
= 1
239 # The check points in this section are reserved
241 # GotoStatementCheckAll = 0
243 self
.SpellingCheckAll
= 0
245 # The directory listed here will not be parsed, split with ','
246 self
.SkipDirList
= []
248 # A list for binary file ext name
249 self
.BinaryExtList
= []
251 # A list for only scanned folders
252 self
.ScanOnlyDirList
= []
256 def ParseConfig(self
):
257 Filepath
= os
.path
.normpath(self
.Filename
)
258 if not os
.path
.isfile(Filepath
):
259 ErrorMsg
= "Can't find configuration file '%s'" % Filepath
260 EdkLogger
.error("Ecc", EdkLogger
.ECC_ERROR
, ErrorMsg
, File
= Filepath
)
263 for Line
in open(Filepath
, 'r'):
265 Line
= CleanString(Line
)
267 List
= GetSplitValueList(Line
, TAB_EQUAL_SPLIT
)
268 if List
[0] not in self
.__dict
__:
269 ErrorMsg
= "Invalid configuration option '%s' was found" % List
[0]
270 EdkLogger
.error("Ecc", EdkLogger
.ECC_ERROR
, ErrorMsg
, File
= Filepath
, Line
= LineNo
)
271 if List
[0] == 'ModifierList':
272 List
[1] = GetSplitValueList(List
[1], TAB_COMMA_SPLIT
)
273 if List
[0] == 'MetaDataFileCheckPathOfGenerateFileList' and List
[1] == "":
275 if List
[0] == 'SkipDirList':
276 List
[1] = GetSplitValueList(List
[1], TAB_COMMA_SPLIT
)
277 if List
[0] == 'BinaryExtList':
278 List
[1] = GetSplitValueList(List
[1], TAB_COMMA_SPLIT
)
279 self
.__dict
__[List
[0]] = List
[1]
283 for Key
in self
.__dict
__.keys():
284 print Key
, '=', self
.__dict
__[Key
]