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