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