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