]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/Ecc/Configuration.py
BaseTools/Capsule: Do not support -o with --dump-info
[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 - 2018, 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 from __future__ import print_function
18 import Common.LongFilePathOs as os
19 import Common.EdkLogger as EdkLogger
20 from Common.DataType import *
21 from Common.StringUtils import *
22 from Common.LongFilePathSupport import OpenLongFilePath as open
23
24 _ConfigFileToInternalTranslation = {
25 # not same
26 "ModifierList":"ModifierSet",
27
28 # same
29 # please keep this in correct alphabetical order.
30 "AutoCorrect":"AutoCorrect",
31 "BinaryExtList":"BinaryExtList",
32 "CFunctionLayoutCheckAll":"CFunctionLayoutCheckAll",
33 "CFunctionLayoutCheckDataDeclaration":"CFunctionLayoutCheckDataDeclaration",
34 "CFunctionLayoutCheckFunctionBody":"CFunctionLayoutCheckFunctionBody",
35 "CFunctionLayoutCheckFunctionName":"CFunctionLayoutCheckFunctionName",
36 "CFunctionLayoutCheckFunctionPrototype":"CFunctionLayoutCheckFunctionPrototype",
37 "CFunctionLayoutCheckNoInitOfVariable":"CFunctionLayoutCheckNoInitOfVariable",
38 "CFunctionLayoutCheckNoStatic":"CFunctionLayoutCheckNoStatic",
39 "CFunctionLayoutCheckOptionalFunctionalModifier":"CFunctionLayoutCheckOptionalFunctionalModifier",
40 "CFunctionLayoutCheckReturnType":"CFunctionLayoutCheckReturnType",
41 "CheckAll":"CheckAll",
42 "Copyright":"Copyright",
43 "DeclarationDataTypeCheckAll":"DeclarationDataTypeCheckAll",
44 "DeclarationDataTypeCheckEFIAPIModifier":"DeclarationDataTypeCheckEFIAPIModifier",
45 "DeclarationDataTypeCheckEnumeratedType":"DeclarationDataTypeCheckEnumeratedType",
46 "DeclarationDataTypeCheckInOutModifier":"DeclarationDataTypeCheckInOutModifier",
47 "DeclarationDataTypeCheckNoUseCType":"DeclarationDataTypeCheckNoUseCType",
48 "DeclarationDataTypeCheckSameStructure":"DeclarationDataTypeCheckSameStructure",
49 "DeclarationDataTypeCheckStructureDeclaration":"DeclarationDataTypeCheckStructureDeclaration",
50 "DeclarationDataTypeCheckUnionType":"DeclarationDataTypeCheckUnionType",
51 "DoxygenCheckAll":"DoxygenCheckAll",
52 "DoxygenCheckCommand":"DoxygenCheckCommand",
53 "DoxygenCheckCommentDescription":"DoxygenCheckCommentDescription",
54 "DoxygenCheckCommentFormat":"DoxygenCheckCommentFormat",
55 "DoxygenCheckFileHeader":"DoxygenCheckFileHeader",
56 "DoxygenCheckFunctionHeader":"DoxygenCheckFunctionHeader",
57 "GeneralCheckAll":"GeneralCheckAll",
58 "GeneralCheckCarriageReturn":"GeneralCheckCarriageReturn",
59 "GeneralCheckFileExistence":"GeneralCheckFileExistence",
60 "GeneralCheckIndentation":"GeneralCheckIndentation",
61 "GeneralCheckIndentationWidth":"GeneralCheckIndentationWidth",
62 "GeneralCheckLine":"GeneralCheckLine",
63 "GeneralCheckLineWidth":"GeneralCheckLineWidth",
64 "GeneralCheckNoProgma":"GeneralCheckNoProgma",
65 "GeneralCheckNoTab":"GeneralCheckNoTab",
66 "GeneralCheckNo_Asm":"GeneralCheckNo_Asm",
67 "GeneralCheckNonAcsii":"GeneralCheckNonAcsii",
68 "GeneralCheckTabWidth":"GeneralCheckTabWidth",
69 "GeneralCheckUni":"GeneralCheckUni",
70 "HeaderCheckAll":"HeaderCheckAll",
71 "HeaderCheckCFileCommentLicenseFormat":"HeaderCheckCFileCommentLicenseFormat",
72 "HeaderCheckCFileCommentReferenceFormat":"HeaderCheckCFileCommentReferenceFormat",
73 "HeaderCheckCFileCommentStartSpacesNum":"HeaderCheckCFileCommentStartSpacesNum",
74 "HeaderCheckFile":"HeaderCheckFile",
75 "HeaderCheckFileCommentEnd":"HeaderCheckFileCommentEnd",
76 "HeaderCheckFunction":"HeaderCheckFunction",
77 "IncludeFileCheckAll":"IncludeFileCheckAll",
78 "IncludeFileCheckData":"IncludeFileCheckData",
79 "IncludeFileCheckIfndefStatement":"IncludeFileCheckIfndefStatement",
80 "IncludeFileCheckSameName":"IncludeFileCheckSameName",
81 "MetaDataFileCheckAll":"MetaDataFileCheckAll",
82 "MetaDataFileCheckBinaryInfInFdf":"MetaDataFileCheckBinaryInfInFdf",
83 "MetaDataFileCheckGenerateFileList":"MetaDataFileCheckGenerateFileList",
84 "MetaDataFileCheckGuidDuplicate":"MetaDataFileCheckGuidDuplicate",
85 "MetaDataFileCheckLibraryDefinedInDec":"MetaDataFileCheckLibraryDefinedInDec",
86 "MetaDataFileCheckLibraryInstance":"MetaDataFileCheckLibraryInstance",
87 "MetaDataFileCheckLibraryInstanceDependent":"MetaDataFileCheckLibraryInstanceDependent",
88 "MetaDataFileCheckLibraryInstanceOrder":"MetaDataFileCheckLibraryInstanceOrder",
89 "MetaDataFileCheckLibraryNoUse":"MetaDataFileCheckLibraryNoUse",
90 "MetaDataFileCheckModuleFileGuidDuplication":"MetaDataFileCheckModuleFileGuidDuplication",
91 "MetaDataFileCheckModuleFileGuidFormat":"MetaDataFileCheckModuleFileGuidFormat",
92 "MetaDataFileCheckModuleFileNoUse":"MetaDataFileCheckModuleFileNoUse",
93 "MetaDataFileCheckModuleFilePcdFormat":"MetaDataFileCheckModuleFilePcdFormat",
94 "MetaDataFileCheckModuleFilePpiFormat":"MetaDataFileCheckModuleFilePpiFormat",
95 "MetaDataFileCheckModuleFileProtocolFormat":"MetaDataFileCheckModuleFileProtocolFormat",
96 "MetaDataFileCheckPathName":"MetaDataFileCheckPathName",
97 "MetaDataFileCheckPathOfGenerateFileList":"MetaDataFileCheckPathOfGenerateFileList",
98 "MetaDataFileCheckPcdDuplicate":"MetaDataFileCheckPcdDuplicate",
99 "MetaDataFileCheckPcdFlash":"MetaDataFileCheckPcdFlash",
100 "MetaDataFileCheckPcdNoUse":"MetaDataFileCheckPcdNoUse",
101 "MetaDataFileCheckPcdType":"MetaDataFileCheckPcdType",
102 "NamingConventionCheckAll":"NamingConventionCheckAll",
103 "NamingConventionCheckDefineStatement":"NamingConventionCheckDefineStatement",
104 "NamingConventionCheckFunctionName":"NamingConventionCheckFunctionName",
105 "NamingConventionCheckIfndefStatement":"NamingConventionCheckIfndefStatement",
106 "NamingConventionCheckPathName":"NamingConventionCheckPathName",
107 "NamingConventionCheckSingleCharacterVariable":"NamingConventionCheckSingleCharacterVariable",
108 "NamingConventionCheckTypedefStatement":"NamingConventionCheckTypedefStatement",
109 "NamingConventionCheckVariableName":"NamingConventionCheckVariableName",
110 "PredicateExpressionCheckAll":"PredicateExpressionCheckAll",
111 "PredicateExpressionCheckBooleanValue":"PredicateExpressionCheckBooleanValue",
112 "PredicateExpressionCheckComparisonNullType":"PredicateExpressionCheckComparisonNullType",
113 "PredicateExpressionCheckNonBooleanOperator":"PredicateExpressionCheckNonBooleanOperator",
114 "ScanOnlyDirList":"ScanOnlyDirList",
115 "SkipDirList":"SkipDirList",
116 "SkipFileList":"SkipFileList",
117 "SmmCommParaCheckAll":"SmmCommParaCheckAll",
118 "SmmCommParaCheckBufferType":"SmmCommParaCheckBufferType",
119 "SpaceCheckAll":"SpaceCheckAll",
120 "SpellingCheckAll":"SpellingCheckAll",
121 "UniCheckAll":"UniCheckAll",
122 "UniCheckHelpInfo":"UniCheckHelpInfo",
123 "UniCheckPCDInfo":"UniCheckPCDInfo",
124 "Version":"Version"
125 }
126
127 ## Configuration
128 #
129 # This class is used to define all items in configuration file
130 #
131 # @param Filename: The name of configuration file, the default is config.ini
132 #
133 class Configuration(object):
134 def __init__(self, Filename):
135 self.Filename = Filename
136
137 self.Version = 0.1
138
139 ## Identify to if check all items
140 # 1 - Check all items and ignore all other detailed items
141 # 0 - Not check all items, the tool will go through all other detailed items to decide to check or not
142 #
143 self.CheckAll = 0
144
145 ## Identify to if automatically correct mistakes
146 # 1 - Automatically correct
147 # 0 - Not automatically correct
148 # Only the following check points can be automatically corrected, others not listed below are not supported even it is 1
149 #
150 # GeneralCheckTab
151 # GeneralCheckIndentation
152 # GeneralCheckLine
153 # GeneralCheckCarriageReturn
154 # SpaceCheckAll
155 #
156 self.AutoCorrect = 0
157
158 # List customized Modifer here, split with ','
159 # Defaultly use the definition in class DataType
160 self.ModifierSet = MODIFIER_SET
161
162 ## General Checking
163 self.GeneralCheckAll = 0
164
165 # Check whether NO Tab is used, replaced with spaces
166 self.GeneralCheckNoTab = 1
167 # The width of Tab
168 self.GeneralCheckTabWidth = 2
169 # Check whether the indentation is followed coding style
170 self.GeneralCheckIndentation = 1
171 # The width of indentation
172 self.GeneralCheckIndentationWidth = 2
173 # Check whether no line is exceeding defined widty
174 self.GeneralCheckLine = 1
175 # The width of a line
176 self.GeneralCheckLineWidth = 120
177 # Check whether no use of _asm in the source file
178 self.GeneralCheckNo_Asm = 1
179 # Check whether no use of "#progma" in source file except "#pragma pack(#)".
180 self.GeneralCheckNoProgma = 1
181 # Check whether there is a carriage return at the end of the file
182 self.GeneralCheckCarriageReturn = 1
183 # Check whether the file exists
184 self.GeneralCheckFileExistence = 1
185 # Check whether file has non ACSII char
186 self.GeneralCheckNonAcsii = 1
187 # Check whether UNI file is valid
188 self.GeneralCheckUni = 1
189 # Check Only use CRLF (Carriage Return Line Feed) line endings.
190 self.GeneralCheckLineEnding = 1
191 # Check if there is no trailing white space in one line.
192 self.GeneralCheckTrailingWhiteSpaceLine = 1
193
194 ## Space Checking
195 self.SpaceCheckAll = 1
196
197 ## Predicate Expression Checking
198 self.PredicateExpressionCheckAll = 0
199
200 # Check whether Boolean values, variable type BOOLEAN not use explicit comparisons to TRUE or FALSE
201 self.PredicateExpressionCheckBooleanValue = 1
202 # Check whether Non-Boolean comparisons use a compare operator (==, !=, >, < >=, <=).
203 self.PredicateExpressionCheckNonBooleanOperator = 1
204 # Check whether a comparison of any pointer to zero must be done via the NULL type
205 self.PredicateExpressionCheckComparisonNullType = 1
206
207 ## Headers Checking
208 self.HeaderCheckAll = 0
209
210 # Check whether File header exists
211 self.HeaderCheckFile = 1
212 # Check whether Function header exists
213 self.HeaderCheckFunction = 1
214 # Check whether Meta data File header Comment End with '##'
215 self.HeaderCheckFileCommentEnd = 1
216 # Check whether C File header Comment content start with two spaces
217 self.HeaderCheckCFileCommentStartSpacesNum = 1
218 # Check whether C File header Comment's each reference at list should begin with a bullet character '-'
219 self.HeaderCheckCFileCommentReferenceFormat = 1
220 # Check whether C File header Comment have the License immediately after the ""Copyright"" line
221 self.HeaderCheckCFileCommentLicenseFormat = 1
222
223 ## C Function Layout Checking
224 self.CFunctionLayoutCheckAll = 0
225
226 # Check whether return type exists and in the first line
227 self.CFunctionLayoutCheckReturnType = 1
228 # Check whether any optional functional modifiers exist and next to the return type
229 self.CFunctionLayoutCheckOptionalFunctionalModifier = 1
230 # Check whether the next line contains the function name, left justified, followed by the beginning of the parameter list
231 # Check whether the closing parenthesis is on its own line and also indented two spaces
232 self.CFunctionLayoutCheckFunctionName = 1
233 # Check whether the function prototypes in include files have the same form as function definitions
234 self.CFunctionLayoutCheckFunctionPrototype = 1
235 # Check whether the body of a function is contained by open and close braces that must be in the first column
236 self.CFunctionLayoutCheckFunctionBody = 1
237 # Check whether the data declarations is the first code in a module.
238 self.CFunctionLayoutCheckDataDeclaration = 1
239 # Check whether no initialization of a variable as part of its declaration
240 self.CFunctionLayoutCheckNoInitOfVariable = 1
241 # Check whether no use of STATIC for functions
242 self.CFunctionLayoutCheckNoStatic = 1
243
244 ## Include Files Checking
245 self.IncludeFileCheckAll = 0
246
247 #Check whether having include files with same name
248 self.IncludeFileCheckSameName = 1
249 # Check whether all include file contents is guarded by a #ifndef statement.
250 # the #ifndef must be the first line of code following the file header comment
251 # the #endif must appear on the last line in the file
252 self.IncludeFileCheckIfndefStatement = 1
253 # Check whether include files contain only public or only private data
254 # Check whether include files NOT contain code or define data variables
255 self.IncludeFileCheckData = 1
256
257 ## Declarations and Data Types Checking
258 self.DeclarationDataTypeCheckAll = 0
259
260 # Check whether no use of int, unsigned, char, void, static, long in any .c, .h or .asl files.
261 self.DeclarationDataTypeCheckNoUseCType = 1
262 # 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
263 self.DeclarationDataTypeCheckInOutModifier = 1
264 # Check whether the EFIAPI modifier should be used at the entry of drivers, events, and member functions of protocols
265 self.DeclarationDataTypeCheckEFIAPIModifier = 1
266 # Check whether Enumerated Type has a 'typedef' and the name is capital
267 self.DeclarationDataTypeCheckEnumeratedType = 1
268 # Check whether Structure Type has a 'typedef' and the name is capital
269 self.DeclarationDataTypeCheckStructureDeclaration = 1
270 # Check whether having same Structure
271 self.DeclarationDataTypeCheckSameStructure = 1
272 # Check whether Union Type has a 'typedef' and the name is capital
273 self.DeclarationDataTypeCheckUnionType = 1
274
275 ## Naming Conventions Checking
276 self.NamingConventionCheckAll = 0
277
278 # Check whether only capital letters are used for #define declarations
279 self.NamingConventionCheckDefineStatement = 1
280 # Check whether only capital letters are used for typedef declarations
281 self.NamingConventionCheckTypedefStatement = 1
282 # Check whether the #ifndef at the start of an include file uses both prefix and postfix underscore characters, '_'.
283 self.NamingConventionCheckIfndefStatement = 1
284 # Rule for path name, variable name and function name
285 # 1. First character should be upper case
286 # 2. Existing lower case in a word
287 # 3. No space existence
288 # Check whether the path name followed the rule
289 self.NamingConventionCheckPathName = 1
290 # Check whether the variable name followed the rule
291 self.NamingConventionCheckVariableName = 1
292 # Check whether the function name followed the rule
293 self.NamingConventionCheckFunctionName = 1
294 # Check whether NO use short variable name with single character
295 self.NamingConventionCheckSingleCharacterVariable = 1
296
297 ## Doxygen Checking
298 self.DoxygenCheckAll = 0
299
300 # Check whether the file headers are followed Doxygen special documentation blocks in section 2.3.5
301 self.DoxygenCheckFileHeader = 1
302 # Check whether the function headers are followed Doxygen special documentation blocks in section 2.3.5
303 self.DoxygenCheckFunctionHeader = 1
304 # Check whether the first line of text in a comment block is a brief description of the element being documented.
305 # The brief description must end with a period.
306 self.DoxygenCheckCommentDescription = 1
307 # Check whether comment lines with '///< ... text ...' format, if it is used, it should be after the code section.
308 self.DoxygenCheckCommentFormat = 1
309 # Check whether only Doxygen commands allowed to mark the code are @bug and @todo.
310 self.DoxygenCheckCommand = 1
311
312 ## Meta-Data File Processing Checking
313 self.MetaDataFileCheckAll = 0
314
315 # Check whether each file defined in meta-data exists
316 self.MetaDataFileCheckPathName = 1
317 # Generate a list for all files defined in meta-data files
318 self.MetaDataFileCheckGenerateFileList = 1
319 # The path of log file
320 self.MetaDataFileCheckPathOfGenerateFileList = 'File.log'
321 # Check whether all Library Instances defined for a given module (or dependent library instance) match the module's type.
322 # Each Library Instance must specify the Supported Module Types in its INF file,
323 # and any module specifying the library instance must be one of the supported types.
324 self.MetaDataFileCheckLibraryInstance = 1
325 # Check whether a Library Instance has been defined for all dependent library classes
326 self.MetaDataFileCheckLibraryInstanceDependent = 1
327 # Check whether the Library Instances specified by the LibraryClasses sections are listed in order of dependencies
328 self.MetaDataFileCheckLibraryInstanceOrder = 1
329 # Check whether the unnecessary inclusion of library classes in the INF file
330 self.MetaDataFileCheckLibraryNoUse = 1
331 # Check the header file in Include\Library directory whether be defined in the package DEC file.
332 self.MetaDataFileCheckLibraryDefinedInDec = 1
333 # 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
334 self.MetaDataFileCheckBinaryInfInFdf = 1
335 # Not to report error and warning related OS include file such as "windows.h" and "stdio.h"
336 # Check whether a PCD is set in a DSC file or the FDF file, but not in both.
337 self.MetaDataFileCheckPcdDuplicate = 1
338 # Check whether PCD settings in the FDF file can only be related to flash.
339 self.MetaDataFileCheckPcdFlash = 1
340 # Check whether PCDs used in INF files but not specified in DSC or FDF files
341 self.MetaDataFileCheckPcdNoUse = 1
342 # Check whether having duplicate guids defined for Guid/Protocol/Ppi
343 self.MetaDataFileCheckGuidDuplicate = 1
344 # Check whether all files under module directory are described in INF files
345 self.MetaDataFileCheckModuleFileNoUse = 1
346 # Check whether the PCD is correctly used in C function via its type
347 self.MetaDataFileCheckPcdType = 1
348 # Check whether there are FILE_GUID duplication among different INF files
349 self.MetaDataFileCheckModuleFileGuidDuplication = 1
350
351 # Check Guid Format in INF files
352 self.MetaDataFileCheckModuleFileGuidFormat = 1
353 # Check Protocol Format in INF files
354 self.MetaDataFileCheckModuleFileProtocolFormat = 1
355 # Check Ppi Format in INF files
356 self.MetaDataFileCheckModuleFilePpiFormat = 1
357 # Check Pcd Format in INF files
358 self.MetaDataFileCheckModuleFilePcdFormat = 1
359
360 # Check UNI file
361 self.UniCheckAll = 0
362 # Check INF or DEC file whether defined the localized information in the associated UNI file.
363 self.UniCheckHelpInfo = 1
364 # Check PCD whether defined the prompt, help in the DEC file and localized information in the associated UNI file.
365 self.UniCheckPCDInfo = 1
366
367 # Check SMM communication function parameter
368 self.SmmCommParaCheckAll = 0
369 # Check if the EFI_SMM_COMMUNICATION_PROTOCOL parameter buffer type is Reserved / ACPI NVS or UEFI RT code/data
370 self.SmmCommParaCheckBufferType = -1
371
372 #
373 # The check points in this section are reserved
374 #
375 # GotoStatementCheckAll = 0
376 #
377 self.SpellingCheckAll = 0
378
379 # The directory listed here will not be parsed, split with ','
380 self.SkipDirList = []
381
382 # The file listed here will not be parsed, split with ','
383 self.SkipFileList = []
384
385 # A list for binary file ext name
386 self.BinaryExtList = []
387
388 # A list for only scanned folders
389 self.ScanOnlyDirList = []
390
391 # A list for Copyright format
392 self.Copyright = []
393
394 self.ParseConfig()
395
396 def ParseConfig(self):
397 Filepath = os.path.normpath(self.Filename)
398 if not os.path.isfile(Filepath):
399 ErrorMsg = "Can't find configuration file '%s'" % Filepath
400 EdkLogger.error("Ecc", EdkLogger.ECC_ERROR, ErrorMsg, File = Filepath)
401
402 LineNo = 0
403 for Line in open(Filepath, 'r'):
404 LineNo = LineNo + 1
405 Line = CleanString(Line)
406 if Line != '':
407 List = GetSplitValueList(Line, TAB_EQUAL_SPLIT)
408 if List[0] not in _ConfigFileToInternalTranslation:
409 ErrorMsg = "Invalid configuration option '%s' was found" % List[0]
410 EdkLogger.error("Ecc", EdkLogger.ECC_ERROR, ErrorMsg, File = Filepath, Line = LineNo)
411 assert _ConfigFileToInternalTranslation[List[0]] in self.__dict__
412 if List[0] == 'ModifierList':
413 List[1] = GetSplitValueList(List[1], TAB_COMMA_SPLIT)
414 if List[0] == 'MetaDataFileCheckPathOfGenerateFileList' and List[1] == "":
415 continue
416 if List[0] == 'SkipDirList':
417 List[1] = GetSplitValueList(List[1], TAB_COMMA_SPLIT)
418 if List[0] == 'SkipFileList':
419 List[1] = GetSplitValueList(List[1], TAB_COMMA_SPLIT)
420 if List[0] == 'BinaryExtList':
421 List[1] = GetSplitValueList(List[1], TAB_COMMA_SPLIT)
422 if List[0] == 'Copyright':
423 List[1] = GetSplitValueList(List[1], TAB_COMMA_SPLIT)
424 self.__dict__[_ConfigFileToInternalTranslation[List[0]]] = List[1]
425
426 def ShowMe(self):
427 print(self.Filename)
428 for Key in self.__dict__.keys():
429 print(Key, '=', self.__dict__[Key])
430
431 #
432 # test that our dict and out class still match in contents.
433 #
434 if __name__ == '__main__':
435 myconfig = Configuration("BaseTools\Source\Python\Ecc\config.ini")
436 for each in myconfig.__dict__:
437 if each == "Filename":
438 continue
439 assert each in _ConfigFileToInternalTranslation.values()
440 for each in _ConfigFileToInternalTranslation.values():
441 assert each in myconfig.__dict__