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