]>
Commit | Line | Data |
---|---|---|
30fdf114 LG |
1 | ## @file\r |
2 | # This file is used to define checkpoints used by ECC tool\r | |
3 | #\r | |
8bb63e37 | 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 | |
b6f6b636 | 13 | from __future__ import absolute_import\r |
1be2ed90 | 14 | import Common.LongFilePathOs as os\r |
30fdf114 LG |
15 | import re\r |
16 | from CommonDataClass.DataClass import *\r | |
b3d07ff8 | 17 | import Common.DataType as DT\r |
855698fb | 18 | from Ecc.EccToolError import *\r |
19 | from Ecc.MetaDataParser import ParseHeaderCommentSection\r | |
20 | from Ecc import EccGlobalData\r | |
21 | from Ecc import c\r | |
b3d07ff8 | 22 | from Common.LongFilePathSupport import OpenLongFilePath as open\r |
c4f52e12 | 23 | from Common.MultipleWorkspace import MultipleWorkspace as mws\r |
30fdf114 LG |
24 | \r |
25 | ## Check\r | |
26 | #\r | |
27 | # This class is to define checkpoints used by ECC tool\r | |
28 | #\r | |
29 | # @param object: Inherited from object class\r | |
30 | #\r | |
31 | class Check(object):\r | |
32 | def __init__(self):\r | |
33 | pass\r | |
34 | \r | |
35 | # Check all required checkpoints\r | |
36 | def Check(self):\r | |
e56468c0 | 37 | self.GeneralCheck()\r |
30fdf114 LG |
38 | self.MetaDataFileCheck()\r |
39 | self.DoxygenCheck()\r | |
40 | self.IncludeFileCheck()\r | |
41 | self.PredicateExpressionCheck()\r | |
42 | self.DeclAndDataTypeCheck()\r | |
43 | self.FunctionLayoutCheck()\r | |
44 | self.NamingConventionCheck()\r | |
703ef6cf HC |
45 | self.SmmCommParaCheck()\r |
46 | \r | |
47 | def SmmCommParaCheck(self):\r | |
48 | self.SmmCommParaCheckBufferType()\r | |
49 | \r | |
50 | \r | |
51 | # Check if SMM communication function has correct parameter type\r | |
52 | # 1. Get function calling with instance./->Communicate() interface\r | |
53 | # and make sure the protocol instance is of type EFI_SMM_COMMUNICATION_PROTOCOL.\r | |
54 | # 2. Find the origin of the 2nd parameter of Communicate() interface, if -\r | |
55 | # a. it is a local buffer on stack\r | |
56 | # report error.\r | |
57 | # b. it is a global buffer, check the driver that holds the global buffer is of type DXE_RUNTIME_DRIVER\r | |
58 | # report success.\r | |
59 | # c. it is a buffer by AllocatePage/AllocatePool (may be wrapped by nested function calls),\r | |
60 | # check the EFI_MEMORY_TYPE to be EfiRuntimeServicesCode,EfiRuntimeServicesData,\r | |
61 | # EfiACPIMemoryNVS or EfiReservedMemoryType\r | |
62 | # report success.\r | |
63 | # d. it is a buffer located via EFI_SYSTEM_TABLE.ConfigurationTable (may be wrapped by nested function calls)\r | |
64 | # report warning to indicate human code review.\r | |
65 | # e. it is a buffer from other kind of pointers (may need to trace into nested function calls to locate),\r | |
66 | # repeat checks in a.b.c and d.\r | |
67 | def SmmCommParaCheckBufferType(self):\r | |
68 | if EccGlobalData.gConfig.SmmCommParaCheckBufferType == '1' or EccGlobalData.gConfig.SmmCommParaCheckAll == '1':\r | |
69 | EdkLogger.quiet("Checking SMM communication parameter type ...")\r | |
70 | # Get all EFI_SMM_COMMUNICATION_PROTOCOL interface\r | |
71 | CommApiList = []\r | |
72 | for IdentifierTable in EccGlobalData.gIdentifierTableList:\r | |
73 | SqlCommand = """select ID, Name, BelongsToFile from %s\r | |
74 | where Modifier = 'EFI_SMM_COMMUNICATION_PROTOCOL*' """ % (IdentifierTable)\r | |
75 | RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r | |
76 | if RecordSet:\r | |
77 | for Record in RecordSet:\r | |
78 | if Record[1] not in CommApiList:\r | |
79 | CommApiList.append(Record[1])\r | |
80 | # For each interface, check the second parameter\r | |
81 | for CommApi in CommApiList:\r | |
82 | for IdentifierTable in EccGlobalData.gIdentifierTableList:\r | |
83 | SqlCommand = """select ID, Name, Value, BelongsToFile, StartLine from %s\r | |
84 | where Name = '%s->Communicate' and Model = %s""" \\r | |
85 | % (IdentifierTable, CommApi, MODEL_IDENTIFIER_FUNCTION_CALLING)\r | |
86 | RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r | |
87 | if RecordSet:\r | |
88 | # print IdentifierTable\r | |
89 | for Record in RecordSet:\r | |
90 | # Get the second parameter for Communicate function\r | |
91 | SecondPara = Record[2].split(',')[1].strip()\r | |
92 | SecondParaIndex = None\r | |
93 | if SecondPara.startswith('&'):\r | |
94 | SecondPara = SecondPara[1:]\r | |
95 | if SecondPara.endswith(']'):\r | |
96 | SecondParaIndex = SecondPara[SecondPara.find('[') + 1:-1]\r | |
97 | SecondPara = SecondPara[:SecondPara.find('[')]\r | |
98 | # Get the ID\r | |
99 | Id = Record[0]\r | |
100 | # Get the BelongsToFile\r | |
101 | BelongsToFile = Record[3]\r | |
102 | # Get the source file path\r | |
103 | SqlCommand = """select FullPath from File where ID = %s""" % BelongsToFile\r | |
104 | NewRecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r | |
105 | FullPath = NewRecordSet[0][0]\r | |
106 | # Get the line no of function calling\r | |
107 | StartLine = Record[4]\r | |
108 | # Get the module type\r | |
109 | SqlCommand = """select Value3 from INF where BelongsToFile = (select ID from File\r | |
110 | where Path = (select Path from File where ID = %s) and Model = 1011)\r | |
111 | and Value2 = 'MODULE_TYPE'""" % BelongsToFile\r | |
112 | NewRecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r | |
113 | ModuleType = NewRecordSet[0][0] if NewRecordSet else None\r | |
114 | \r | |
115 | # print BelongsToFile, FullPath, StartLine, ModuleType, SecondPara\r | |
116 | \r | |
117 | Value = FindPara(FullPath, SecondPara, StartLine)\r | |
118 | # Find the value of the parameter\r | |
119 | if Value:\r | |
120 | if 'AllocatePage' in Value \\r | |
121 | or 'AllocatePool' in Value \\r | |
122 | or 'AllocateRuntimePool' in Value \\r | |
123 | or 'AllocateZeroPool' in Value:\r | |
124 | pass\r | |
125 | else:\r | |
126 | if '->' in Value:\r | |
127 | if not EccGlobalData.gException.IsException(\r | |
128 | ERROR_SMM_COMM_PARA_CHECK_BUFFER_TYPE, Value):\r | |
129 | EccGlobalData.gDb.TblReport.Insert(ERROR_SMM_COMM_PARA_CHECK_BUFFER_TYPE,\r | |
130 | OtherMsg="Please review the buffer type"\r | |
131 | + "is correct or not. If it is correct" +\r | |
132 | " please add [%s] to exception list"\r | |
133 | % Value,\r | |
134 | BelongsToTable=IdentifierTable,\r | |
135 | BelongsToItem=Id)\r | |
136 | else:\r | |
137 | if not EccGlobalData.gException.IsException(\r | |
138 | ERROR_SMM_COMM_PARA_CHECK_BUFFER_TYPE, Value):\r | |
139 | EccGlobalData.gDb.TblReport.Insert(ERROR_SMM_COMM_PARA_CHECK_BUFFER_TYPE,\r | |
140 | OtherMsg="Please review the buffer type"\r | |
141 | + "is correct or not. If it is correct" +\r | |
142 | " please add [%s] to exception list"\r | |
143 | % Value,\r | |
144 | BelongsToTable=IdentifierTable,\r | |
145 | BelongsToItem=Id)\r | |
146 | \r | |
147 | \r | |
148 | # Not find the value of the parameter\r | |
149 | else:\r | |
150 | SqlCommand = """select ID, Modifier, Name, Value, Model, BelongsToFunction from %s\r | |
151 | where Name = '%s' and StartLine < %s order by StartLine DESC""" \\r | |
152 | % (IdentifierTable, SecondPara, StartLine)\r | |
153 | NewRecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r | |
154 | if NewRecordSet:\r | |
155 | Value = NewRecordSet[0][1]\r | |
156 | if 'AllocatePage' in Value \\r | |
157 | or 'AllocatePool' in Value \\r | |
158 | or 'AllocateRuntimePool' in Value \\r | |
159 | or 'AllocateZeroPool' in Value:\r | |
160 | pass\r | |
161 | else:\r | |
162 | if not EccGlobalData.gException.IsException(\r | |
163 | ERROR_SMM_COMM_PARA_CHECK_BUFFER_TYPE, Value):\r | |
164 | EccGlobalData.gDb.TblReport.Insert(ERROR_SMM_COMM_PARA_CHECK_BUFFER_TYPE,\r | |
165 | OtherMsg="Please review the buffer type"\r | |
166 | + "is correct or not. If it is correct" +\r | |
167 | " please add [%s] to exception list"\r | |
168 | % Value,\r | |
169 | BelongsToTable=IdentifierTable,\r | |
170 | BelongsToItem=Id)\r | |
171 | else:\r | |
172 | pass\r | |
30fdf114 | 173 | \r |
b3d07ff8 HC |
174 | # Check UNI files\r |
175 | def UniCheck(self):\r | |
176 | if EccGlobalData.gConfig.GeneralCheckUni == '1' or EccGlobalData.gConfig.GeneralCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
177 | EdkLogger.quiet("Checking whether UNI file is UTF-16 ...")\r | |
178 | SqlCommand = """select ID, FullPath, ExtName from File where ExtName like 'uni'"""\r | |
179 | RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r | |
180 | for Record in RecordSet:\r | |
181 | File = Record[1]\r | |
182 | FileIn = open(File, 'rb').read(2)\r | |
183 | if FileIn != '\xff\xfe':\r | |
184 | OtherMsg = "File %s is not a valid UTF-16 UNI file" % Record[1]\r | |
185 | EccGlobalData.gDb.TblReport.Insert(ERROR_GENERAL_CHECK_UNI, OtherMsg=OtherMsg, BelongsToTable='File', BelongsToItem=Record[0])\r | |
186 | \r | |
e56468c0 | 187 | # General Checking\r |
188 | def GeneralCheck(self):\r | |
189 | self.GeneralCheckNonAcsii()\r | |
b3d07ff8 | 190 | self.UniCheck()\r |
a1583a87 HC |
191 | self.GeneralCheckNoTab()\r |
192 | self.GeneralCheckLineEnding()\r | |
193 | self.GeneralCheckTrailingWhiteSpaceLine()\r | |
194 | \r | |
195 | # Check whether NO Tab is used, replaced with spaces\r | |
196 | def GeneralCheckNoTab(self):\r | |
197 | if EccGlobalData.gConfig.GeneralCheckNoTab == '1' or EccGlobalData.gConfig.GeneralCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
198 | EdkLogger.quiet("Checking No TAB used in file ...")\r | |
199 | SqlCommand = """select ID, FullPath, ExtName from File where ExtName in ('.dec', '.inf', '.dsc', 'c', 'h')"""\r | |
200 | RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r | |
201 | for Record in RecordSet:\r | |
202 | if Record[2].upper() not in EccGlobalData.gConfig.BinaryExtList:\r | |
203 | op = open(Record[1]).readlines()\r | |
204 | IndexOfLine = 0\r | |
205 | for Line in op:\r | |
206 | IndexOfLine += 1\r | |
207 | IndexOfChar = 0\r | |
208 | for Char in Line:\r | |
209 | IndexOfChar += 1\r | |
210 | if Char == '\t':\r | |
211 | OtherMsg = "File %s has TAB char at line %s column %s" % (Record[1], IndexOfLine, IndexOfChar)\r | |
212 | EccGlobalData.gDb.TblReport.Insert(ERROR_GENERAL_CHECK_NO_TAB, OtherMsg=OtherMsg, BelongsToTable='File', BelongsToItem=Record[0])\r | |
213 | \r | |
214 | # Check Only use CRLF (Carriage Return Line Feed) line endings.\r | |
215 | def GeneralCheckLineEnding(self):\r | |
216 | if EccGlobalData.gConfig.GeneralCheckLineEnding == '1' or EccGlobalData.gConfig.GeneralCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
217 | EdkLogger.quiet("Checking line ending in file ...")\r | |
218 | SqlCommand = """select ID, FullPath, ExtName from File where ExtName in ('.dec', '.inf', '.dsc', 'c', 'h')"""\r | |
219 | RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r | |
220 | for Record in RecordSet:\r | |
221 | if Record[2].upper() not in EccGlobalData.gConfig.BinaryExtList:\r | |
222 | op = open(Record[1], 'rb').readlines()\r | |
223 | IndexOfLine = 0\r | |
224 | for Line in op:\r | |
225 | IndexOfLine += 1\r | |
1ccc4d89 | 226 | if not Line.endswith('\r\n'):\r |
a1583a87 HC |
227 | OtherMsg = "File %s has invalid line ending at line %s" % (Record[1], IndexOfLine)\r |
228 | EccGlobalData.gDb.TblReport.Insert(ERROR_GENERAL_CHECK_INVALID_LINE_ENDING, OtherMsg=OtherMsg, BelongsToTable='File', BelongsToItem=Record[0])\r | |
229 | \r | |
230 | # Check if there is no trailing white space in one line.\r | |
231 | def GeneralCheckTrailingWhiteSpaceLine(self):\r | |
232 | if EccGlobalData.gConfig.GeneralCheckTrailingWhiteSpaceLine == '1' or EccGlobalData.gConfig.GeneralCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
233 | EdkLogger.quiet("Checking trailing white space line in file ...")\r | |
234 | SqlCommand = """select ID, FullPath, ExtName from File where ExtName in ('.dec', '.inf', '.dsc', 'c', 'h')"""\r | |
235 | RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r | |
236 | for Record in RecordSet:\r | |
237 | if Record[2].upper() not in EccGlobalData.gConfig.BinaryExtList:\r | |
1ccc4d89 | 238 | op = open(Record[1], 'rb').readlines()\r |
a1583a87 HC |
239 | IndexOfLine = 0\r |
240 | for Line in op:\r | |
241 | IndexOfLine += 1\r | |
242 | if Line.replace('\r', '').replace('\n', '').endswith(' '):\r | |
243 | OtherMsg = "File %s has trailing white spaces at line %s" % (Record[1], IndexOfLine)\r | |
244 | EccGlobalData.gDb.TblReport.Insert(ERROR_GENERAL_CHECK_TRAILING_WHITE_SPACE_LINE, OtherMsg=OtherMsg, BelongsToTable='File', BelongsToItem=Record[0])\r | |
e56468c0 | 245 | \r |
246 | # Check whether file has non ACSII char\r | |
247 | def GeneralCheckNonAcsii(self):\r | |
248 | if EccGlobalData.gConfig.GeneralCheckNonAcsii == '1' or EccGlobalData.gConfig.GeneralCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
249 | EdkLogger.quiet("Checking Non-ACSII char in file ...")\r | |
8d62ae35 | 250 | SqlCommand = """select ID, FullPath, ExtName from File where ExtName in ('.dec', '.inf', '.dsc', 'c', 'h')"""\r |
d0acc87a | 251 | RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r |
e56468c0 | 252 | for Record in RecordSet:\r |
253 | if Record[2].upper() not in EccGlobalData.gConfig.BinaryExtList:\r | |
254 | op = open(Record[1]).readlines()\r | |
255 | IndexOfLine = 0\r | |
256 | for Line in op:\r | |
257 | IndexOfLine += 1\r | |
258 | IndexOfChar = 0\r | |
259 | for Char in Line:\r | |
260 | IndexOfChar += 1\r | |
261 | if ord(Char) > 126:\r | |
d40b2ee6 LG |
262 | OtherMsg = "File %s has Non-ASCII char at line %s column %s" % (Record[1], IndexOfLine, IndexOfChar)\r |
263 | EccGlobalData.gDb.TblReport.Insert(ERROR_GENERAL_CHECK_NON_ACSII, OtherMsg=OtherMsg, BelongsToTable='File', BelongsToItem=Record[0])\r | |
e56468c0 | 264 | \r |
30fdf114 LG |
265 | # C Function Layout Checking\r |
266 | def FunctionLayoutCheck(self):\r | |
267 | self.FunctionLayoutCheckReturnType()\r | |
268 | self.FunctionLayoutCheckModifier()\r | |
269 | self.FunctionLayoutCheckName()\r | |
270 | self.FunctionLayoutCheckPrototype()\r | |
271 | self.FunctionLayoutCheckBody()\r | |
272 | self.FunctionLayoutCheckLocalVariable()\r | |
33a211d0 HC |
273 | self.FunctionLayoutCheckDeprecated()\r |
274 | \r | |
275 | # To check if the deprecated functions are used\r | |
276 | def FunctionLayoutCheckDeprecated(self):\r | |
277 | if EccGlobalData.gConfig.CFunctionLayoutCheckNoDeprecated == '1' or EccGlobalData.gConfig.CFunctionLayoutCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
278 | EdkLogger.quiet("Checking function no deprecated one being used ...")\r | |
279 | \r | |
280 | DeprecatedFunctionSet = ('UnicodeValueToString',\r | |
281 | 'AsciiValueToString',\r | |
282 | 'StrCpy',\r | |
283 | 'StrnCpy',\r | |
284 | 'StrCat',\r | |
285 | 'StrnCat',\r | |
286 | 'UnicodeStrToAsciiStr',\r | |
287 | 'AsciiStrCpy',\r | |
288 | 'AsciiStrnCpy',\r | |
289 | 'AsciiStrCat',\r | |
290 | 'AsciiStrnCat',\r | |
291 | 'AsciiStrToUnicodeStr',\r | |
292 | 'PcdSet8',\r | |
293 | 'PcdSet16',\r | |
294 | 'PcdSet32',\r | |
295 | 'PcdSet64',\r | |
296 | 'PcdSetPtr',\r | |
297 | 'PcdSetBool',\r | |
298 | 'PcdSetEx8',\r | |
299 | 'PcdSetEx16',\r | |
300 | 'PcdSetEx32',\r | |
301 | 'PcdSetEx64',\r | |
302 | 'PcdSetExPtr',\r | |
303 | 'PcdSetExBool',\r | |
304 | 'LibPcdSet8',\r | |
305 | 'LibPcdSet16',\r | |
306 | 'LibPcdSet32',\r | |
307 | 'LibPcdSet64',\r | |
308 | 'LibPcdSetPtr',\r | |
309 | 'LibPcdSetBool',\r | |
310 | 'LibPcdSetEx8',\r | |
311 | 'LibPcdSetEx16',\r | |
312 | 'LibPcdSetEx32',\r | |
313 | 'LibPcdSetEx64',\r | |
314 | 'LibPcdSetExPtr',\r | |
315 | 'LibPcdSetExBool',\r | |
316 | 'GetVariable',\r | |
317 | 'GetEfiGlobalVariable',\r | |
318 | )\r | |
319 | \r | |
320 | for IdentifierTable in EccGlobalData.gIdentifierTableList:\r | |
321 | SqlCommand = """select ID, Name, BelongsToFile from %s\r | |
322 | where Model = %s """ % (IdentifierTable, MODEL_IDENTIFIER_FUNCTION_CALLING)\r | |
323 | RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r | |
324 | for Record in RecordSet:\r | |
325 | for Key in DeprecatedFunctionSet:\r | |
326 | if Key == Record[1]:\r | |
327 | if not EccGlobalData.gException.IsException(ERROR_C_FUNCTION_LAYOUT_CHECK_NO_DEPRECATE, Key):\r | |
328 | OtherMsg = 'The function [%s] is deprecated which should NOT be used' % Key\r | |
329 | EccGlobalData.gDb.TblReport.Insert(ERROR_C_FUNCTION_LAYOUT_CHECK_NO_DEPRECATE,\r | |
330 | OtherMsg=OtherMsg,\r | |
331 | BelongsToTable=IdentifierTable,\r | |
332 | BelongsToItem=Record[0])\r | |
30fdf114 LG |
333 | \r |
334 | def WalkTree(self):\r | |
335 | IgnoredPattern = c.GetIgnoredDirListPattern()\r | |
336 | for Dirpath, Dirnames, Filenames in os.walk(EccGlobalData.gTarget):\r | |
337 | for Dir in Dirnames:\r | |
338 | Dirname = os.path.join(Dirpath, Dir)\r | |
339 | if os.path.islink(Dirname):\r | |
340 | Dirname = os.path.realpath(Dirname)\r | |
341 | if os.path.isdir(Dirname):\r | |
342 | # symlinks to directories are treated as directories\r | |
343 | Dirnames.remove(Dir)\r | |
344 | Dirnames.append(Dirname)\r | |
345 | if IgnoredPattern.match(Dirpath.upper()):\r | |
346 | continue\r | |
8c3f9b4e HC |
347 | for f in Filenames[:]:\r |
348 | if f.lower() in EccGlobalData.gConfig.SkipFileList:\r | |
349 | Filenames.remove(f)\r | |
30fdf114 LG |
350 | yield (Dirpath, Dirnames, Filenames)\r |
351 | \r | |
352 | # Check whether return type exists and in the first line\r | |
353 | def FunctionLayoutCheckReturnType(self):\r | |
354 | if EccGlobalData.gConfig.CFunctionLayoutCheckReturnType == '1' or EccGlobalData.gConfig.CFunctionLayoutCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
355 | EdkLogger.quiet("Checking function layout return type ...")\r | |
356 | \r | |
e56468c0 | 357 | # for Dirpath, Dirnames, Filenames in self.WalkTree():\r |
358 | # for F in Filenames:\r | |
359 | # if os.path.splitext(F)[1] in ('.c', '.h'):\r | |
360 | # FullName = os.path.join(Dirpath, F)\r | |
361 | # c.CheckFuncLayoutReturnType(FullName)\r | |
362 | for FullName in EccGlobalData.gCFileList + EccGlobalData.gHFileList:\r | |
363 | c.CheckFuncLayoutReturnType(FullName)\r | |
30fdf114 LG |
364 | \r |
365 | # Check whether any optional functional modifiers exist and next to the return type\r | |
366 | def FunctionLayoutCheckModifier(self):\r | |
367 | if EccGlobalData.gConfig.CFunctionLayoutCheckOptionalFunctionalModifier == '1' or EccGlobalData.gConfig.CFunctionLayoutCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
368 | EdkLogger.quiet("Checking function layout modifier ...")\r | |
369 | \r | |
e56468c0 | 370 | # for Dirpath, Dirnames, Filenames in self.WalkTree():\r |
371 | # for F in Filenames:\r | |
372 | # if os.path.splitext(F)[1] in ('.c', '.h'):\r | |
373 | # FullName = os.path.join(Dirpath, F)\r | |
374 | # c.CheckFuncLayoutModifier(FullName)\r | |
375 | for FullName in EccGlobalData.gCFileList + EccGlobalData.gHFileList:\r | |
376 | c.CheckFuncLayoutModifier(FullName)\r | |
30fdf114 LG |
377 | \r |
378 | # Check whether the next line contains the function name, left justified, followed by the beginning of the parameter list\r | |
379 | # Check whether the closing parenthesis is on its own line and also indented two spaces\r | |
380 | def FunctionLayoutCheckName(self):\r | |
381 | if EccGlobalData.gConfig.CFunctionLayoutCheckFunctionName == '1' or EccGlobalData.gConfig.CFunctionLayoutCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
382 | EdkLogger.quiet("Checking function layout function name ...")\r | |
383 | \r | |
e56468c0 | 384 | # for Dirpath, Dirnames, Filenames in self.WalkTree():\r |
385 | # for F in Filenames:\r | |
386 | # if os.path.splitext(F)[1] in ('.c', '.h'):\r | |
387 | # FullName = os.path.join(Dirpath, F)\r | |
388 | # c.CheckFuncLayoutName(FullName)\r | |
389 | for FullName in EccGlobalData.gCFileList + EccGlobalData.gHFileList:\r | |
390 | c.CheckFuncLayoutName(FullName)\r | |
391 | \r | |
30fdf114 LG |
392 | # Check whether the function prototypes in include files have the same form as function definitions\r |
393 | def FunctionLayoutCheckPrototype(self):\r | |
394 | if EccGlobalData.gConfig.CFunctionLayoutCheckFunctionPrototype == '1' or EccGlobalData.gConfig.CFunctionLayoutCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
395 | EdkLogger.quiet("Checking function layout function prototype ...")\r | |
396 | \r | |
e56468c0 | 397 | # for Dirpath, Dirnames, Filenames in self.WalkTree():\r |
398 | # for F in Filenames:\r | |
399 | # if os.path.splitext(F)[1] in ('.c'):\r | |
400 | # FullName = os.path.join(Dirpath, F)\r | |
401 | # EdkLogger.quiet("[PROTOTYPE]" + FullName)\r | |
402 | # c.CheckFuncLayoutPrototype(FullName)\r | |
403 | for FullName in EccGlobalData.gCFileList:\r | |
404 | EdkLogger.quiet("[PROTOTYPE]" + FullName)\r | |
405 | c.CheckFuncLayoutPrototype(FullName)\r | |
30fdf114 LG |
406 | \r |
407 | # Check whether the body of a function is contained by open and close braces that must be in the first column\r | |
408 | def FunctionLayoutCheckBody(self):\r | |
409 | if EccGlobalData.gConfig.CFunctionLayoutCheckFunctionBody == '1' or EccGlobalData.gConfig.CFunctionLayoutCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
410 | EdkLogger.quiet("Checking function layout function body ...")\r | |
411 | \r | |
e56468c0 | 412 | # for Dirpath, Dirnames, Filenames in self.WalkTree():\r |
413 | # for F in Filenames:\r | |
414 | # if os.path.splitext(F)[1] in ('.c'):\r | |
415 | # FullName = os.path.join(Dirpath, F)\r | |
416 | # c.CheckFuncLayoutBody(FullName)\r | |
417 | for FullName in EccGlobalData.gCFileList:\r | |
418 | c.CheckFuncLayoutBody(FullName)\r | |
30fdf114 LG |
419 | \r |
420 | # Check whether the data declarations is the first code in a module.\r | |
421 | # self.CFunctionLayoutCheckDataDeclaration = 1\r | |
422 | # Check whether no initialization of a variable as part of its declaration\r | |
423 | def FunctionLayoutCheckLocalVariable(self):\r | |
424 | if EccGlobalData.gConfig.CFunctionLayoutCheckNoInitOfVariable == '1' or EccGlobalData.gConfig.CFunctionLayoutCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
425 | EdkLogger.quiet("Checking function layout local variables ...")\r | |
426 | \r | |
e56468c0 | 427 | # for Dirpath, Dirnames, Filenames in self.WalkTree():\r |
428 | # for F in Filenames:\r | |
429 | # if os.path.splitext(F)[1] in ('.c'):\r | |
430 | # FullName = os.path.join(Dirpath, F)\r | |
431 | # c.CheckFuncLayoutLocalVariable(FullName)\r | |
432 | \r | |
433 | for FullName in EccGlobalData.gCFileList:\r | |
434 | c.CheckFuncLayoutLocalVariable(FullName)\r | |
30fdf114 LG |
435 | \r |
436 | # Check whether no use of STATIC for functions\r | |
437 | # self.CFunctionLayoutCheckNoStatic = 1\r | |
438 | \r | |
439 | # Declarations and Data Types Checking\r | |
440 | def DeclAndDataTypeCheck(self):\r | |
441 | self.DeclCheckNoUseCType()\r | |
442 | self.DeclCheckInOutModifier()\r | |
443 | self.DeclCheckEFIAPIModifier()\r | |
444 | self.DeclCheckEnumeratedType()\r | |
445 | self.DeclCheckStructureDeclaration()\r | |
446 | self.DeclCheckSameStructure()\r | |
447 | self.DeclCheckUnionType()\r | |
448 | \r | |
449 | \r | |
450 | # Check whether no use of int, unsigned, char, void, static, long in any .c, .h or .asl files.\r | |
451 | def DeclCheckNoUseCType(self):\r | |
452 | if EccGlobalData.gConfig.DeclarationDataTypeCheckNoUseCType == '1' or EccGlobalData.gConfig.DeclarationDataTypeCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
453 | EdkLogger.quiet("Checking Declaration No use C type ...")\r | |
454 | \r | |
e56468c0 | 455 | # for Dirpath, Dirnames, Filenames in self.WalkTree():\r |
456 | # for F in Filenames:\r | |
457 | # if os.path.splitext(F)[1] in ('.h', '.c'):\r | |
458 | # FullName = os.path.join(Dirpath, F)\r | |
459 | # c.CheckDeclNoUseCType(FullName)\r | |
460 | for FullName in EccGlobalData.gCFileList + EccGlobalData.gHFileList:\r | |
461 | c.CheckDeclNoUseCType(FullName)\r | |
30fdf114 LG |
462 | \r |
463 | # 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 | |
464 | def DeclCheckInOutModifier(self):\r | |
465 | if EccGlobalData.gConfig.DeclarationDataTypeCheckInOutModifier == '1' or EccGlobalData.gConfig.DeclarationDataTypeCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
466 | EdkLogger.quiet("Checking Declaration argument modifier ...")\r | |
467 | \r | |
e56468c0 | 468 | # for Dirpath, Dirnames, Filenames in self.WalkTree():\r |
469 | # for F in Filenames:\r | |
470 | # if os.path.splitext(F)[1] in ('.h', '.c'):\r | |
471 | # FullName = os.path.join(Dirpath, F)\r | |
472 | # c.CheckDeclArgModifier(FullName)\r | |
473 | for FullName in EccGlobalData.gCFileList + EccGlobalData.gHFileList:\r | |
474 | c.CheckDeclArgModifier(FullName)\r | |
30fdf114 LG |
475 | \r |
476 | # Check whether the EFIAPI modifier should be used at the entry of drivers, events, and member functions of protocols\r | |
477 | def DeclCheckEFIAPIModifier(self):\r | |
478 | if EccGlobalData.gConfig.DeclarationDataTypeCheckEFIAPIModifier == '1' or EccGlobalData.gConfig.DeclarationDataTypeCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
479 | pass\r | |
480 | \r | |
481 | # Check whether Enumerated Type has a 'typedef' and the name is capital\r | |
482 | def DeclCheckEnumeratedType(self):\r | |
483 | if EccGlobalData.gConfig.DeclarationDataTypeCheckEnumeratedType == '1' or EccGlobalData.gConfig.DeclarationDataTypeCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
484 | EdkLogger.quiet("Checking Declaration enum typedef ...")\r | |
485 | \r | |
e56468c0 | 486 | # for Dirpath, Dirnames, Filenames in self.WalkTree():\r |
487 | # for F in Filenames:\r | |
488 | # if os.path.splitext(F)[1] in ('.h', '.c'):\r | |
489 | # FullName = os.path.join(Dirpath, F)\r | |
490 | # EdkLogger.quiet("[ENUM]" + FullName)\r | |
491 | # c.CheckDeclEnumTypedef(FullName)\r | |
492 | for FullName in EccGlobalData.gCFileList + EccGlobalData.gHFileList:\r | |
493 | EdkLogger.quiet("[ENUM]" + FullName)\r | |
494 | c.CheckDeclEnumTypedef(FullName)\r | |
30fdf114 LG |
495 | \r |
496 | # Check whether Structure Type has a 'typedef' and the name is capital\r | |
497 | def DeclCheckStructureDeclaration(self):\r | |
498 | if EccGlobalData.gConfig.DeclarationDataTypeCheckStructureDeclaration == '1' or EccGlobalData.gConfig.DeclarationDataTypeCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
499 | EdkLogger.quiet("Checking Declaration struct typedef ...")\r | |
500 | \r | |
e56468c0 | 501 | # for Dirpath, Dirnames, Filenames in self.WalkTree():\r |
502 | # for F in Filenames:\r | |
503 | # if os.path.splitext(F)[1] in ('.h', '.c'):\r | |
504 | # FullName = os.path.join(Dirpath, F)\r | |
505 | # EdkLogger.quiet("[STRUCT]" + FullName)\r | |
506 | # c.CheckDeclStructTypedef(FullName)\r | |
507 | for FullName in EccGlobalData.gCFileList + EccGlobalData.gHFileList:\r | |
508 | EdkLogger.quiet("[STRUCT]" + FullName)\r | |
509 | c.CheckDeclStructTypedef(FullName)\r | |
30fdf114 LG |
510 | \r |
511 | # Check whether having same Structure\r | |
512 | def DeclCheckSameStructure(self):\r | |
513 | if EccGlobalData.gConfig.DeclarationDataTypeCheckSameStructure == '1' or EccGlobalData.gConfig.DeclarationDataTypeCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
514 | EdkLogger.quiet("Checking same struct ...")\r | |
515 | AllStructure = {}\r | |
516 | for IdentifierTable in EccGlobalData.gIdentifierTableList:\r | |
d40b2ee6 | 517 | SqlCommand = """select ID, Name, BelongsToFile from %s where Model = %s""" % (IdentifierTable, MODEL_IDENTIFIER_STRUCTURE)\r |
30fdf114 LG |
518 | RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r |
519 | for Record in RecordSet:\r | |
520 | if Record[1] != '':\r | |
521 | if Record[1] not in AllStructure.keys():\r | |
522 | AllStructure[Record[1]] = Record[2]\r | |
523 | else:\r | |
524 | ID = AllStructure[Record[1]]\r | |
525 | SqlCommand = """select FullPath from File where ID = %s """ % ID\r | |
526 | NewRecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r | |
527 | OtherMsg = "The structure name '%s' is duplicate" % Record[1]\r | |
528 | if NewRecordSet != []:\r | |
529 | OtherMsg = "The structure name [%s] is duplicate with the one defined in %s, maybe struct NOT typedefed or the typedef new type NOT used to qualify variables" % (Record[1], NewRecordSet[0][0])\r | |
530 | if not EccGlobalData.gException.IsException(ERROR_DECLARATION_DATA_TYPE_CHECK_SAME_STRUCTURE, Record[1]):\r | |
d40b2ee6 | 531 | EccGlobalData.gDb.TblReport.Insert(ERROR_DECLARATION_DATA_TYPE_CHECK_SAME_STRUCTURE, OtherMsg=OtherMsg, BelongsToTable=IdentifierTable, BelongsToItem=Record[0])\r |
30fdf114 LG |
532 | \r |
533 | # Check whether Union Type has a 'typedef' and the name is capital\r | |
534 | def DeclCheckUnionType(self):\r | |
535 | if EccGlobalData.gConfig.DeclarationDataTypeCheckUnionType == '1' or EccGlobalData.gConfig.DeclarationDataTypeCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
536 | EdkLogger.quiet("Checking Declaration union typedef ...")\r | |
537 | \r | |
e56468c0 | 538 | # for Dirpath, Dirnames, Filenames in self.WalkTree():\r |
539 | # for F in Filenames:\r | |
540 | # if os.path.splitext(F)[1] in ('.h', '.c'):\r | |
541 | # FullName = os.path.join(Dirpath, F)\r | |
542 | # EdkLogger.quiet("[UNION]" + FullName)\r | |
543 | # c.CheckDeclUnionTypedef(FullName)\r | |
544 | for FullName in EccGlobalData.gCFileList + EccGlobalData.gHFileList:\r | |
545 | EdkLogger.quiet("[UNION]" + FullName)\r | |
546 | c.CheckDeclUnionTypedef(FullName)\r | |
30fdf114 LG |
547 | \r |
548 | # Predicate Expression Checking\r | |
549 | def PredicateExpressionCheck(self):\r | |
550 | self.PredicateExpressionCheckBooleanValue()\r | |
551 | self.PredicateExpressionCheckNonBooleanOperator()\r | |
552 | self.PredicateExpressionCheckComparisonNullType()\r | |
553 | \r | |
554 | # Check whether Boolean values, variable type BOOLEAN not use explicit comparisons to TRUE or FALSE\r | |
555 | def PredicateExpressionCheckBooleanValue(self):\r | |
556 | if EccGlobalData.gConfig.PredicateExpressionCheckBooleanValue == '1' or EccGlobalData.gConfig.PredicateExpressionCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
557 | EdkLogger.quiet("Checking predicate expression Boolean value ...")\r | |
558 | \r | |
e56468c0 | 559 | # for Dirpath, Dirnames, Filenames in self.WalkTree():\r |
560 | # for F in Filenames:\r | |
561 | # if os.path.splitext(F)[1] in ('.c'):\r | |
562 | # FullName = os.path.join(Dirpath, F)\r | |
563 | # EdkLogger.quiet("[BOOLEAN]" + FullName)\r | |
564 | # c.CheckBooleanValueComparison(FullName)\r | |
565 | for FullName in EccGlobalData.gCFileList:\r | |
566 | EdkLogger.quiet("[BOOLEAN]" + FullName)\r | |
567 | c.CheckBooleanValueComparison(FullName)\r | |
30fdf114 LG |
568 | \r |
569 | # Check whether Non-Boolean comparisons use a compare operator (==, !=, >, < >=, <=).\r | |
570 | def PredicateExpressionCheckNonBooleanOperator(self):\r | |
571 | if EccGlobalData.gConfig.PredicateExpressionCheckNonBooleanOperator == '1' or EccGlobalData.gConfig.PredicateExpressionCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
572 | EdkLogger.quiet("Checking predicate expression Non-Boolean variable...")\r | |
573 | \r | |
e56468c0 | 574 | # for Dirpath, Dirnames, Filenames in self.WalkTree():\r |
575 | # for F in Filenames:\r | |
576 | # if os.path.splitext(F)[1] in ('.c'):\r | |
577 | # FullName = os.path.join(Dirpath, F)\r | |
578 | # EdkLogger.quiet("[NON-BOOLEAN]" + FullName)\r | |
579 | # c.CheckNonBooleanValueComparison(FullName)\r | |
580 | for FullName in EccGlobalData.gCFileList:\r | |
581 | EdkLogger.quiet("[NON-BOOLEAN]" + FullName)\r | |
582 | c.CheckNonBooleanValueComparison(FullName)\r | |
583 | \r | |
30fdf114 LG |
584 | # Check whether a comparison of any pointer to zero must be done via the NULL type\r |
585 | def PredicateExpressionCheckComparisonNullType(self):\r | |
586 | if EccGlobalData.gConfig.PredicateExpressionCheckComparisonNullType == '1' or EccGlobalData.gConfig.PredicateExpressionCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
587 | EdkLogger.quiet("Checking predicate expression NULL pointer ...")\r | |
588 | \r | |
e56468c0 | 589 | # for Dirpath, Dirnames, Filenames in self.WalkTree():\r |
590 | # for F in Filenames:\r | |
591 | # if os.path.splitext(F)[1] in ('.c'):\r | |
592 | # FullName = os.path.join(Dirpath, F)\r | |
593 | # EdkLogger.quiet("[POINTER]" + FullName)\r | |
594 | # c.CheckPointerNullComparison(FullName)\r | |
595 | for FullName in EccGlobalData.gCFileList:\r | |
596 | EdkLogger.quiet("[POINTER]" + FullName)\r | |
597 | c.CheckPointerNullComparison(FullName)\r | |
598 | \r | |
30fdf114 LG |
599 | # Include file checking\r |
600 | def IncludeFileCheck(self):\r | |
601 | self.IncludeFileCheckIfndef()\r | |
602 | self.IncludeFileCheckData()\r | |
603 | self.IncludeFileCheckSameName()\r | |
604 | \r | |
605 | # Check whether having include files with same name\r | |
606 | def IncludeFileCheckSameName(self):\r | |
607 | if EccGlobalData.gConfig.IncludeFileCheckSameName == '1' or EccGlobalData.gConfig.IncludeFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
608 | EdkLogger.quiet("Checking same header file name ...")\r | |
609 | SqlCommand = """select ID, FullPath from File\r | |
610 | where Model = 1002 order by Name """\r | |
611 | RecordDict = {}\r | |
612 | RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r | |
613 | for Record in RecordSet:\r | |
614 | List = Record[1].replace('/', '\\').split('\\')\r | |
615 | if len(List) >= 2:\r | |
616 | Key = List[-2] + '\\' + List[-1]\r | |
617 | else:\r | |
618 | Key = List[0]\r | |
619 | if Key not in RecordDict:\r | |
620 | RecordDict[Key] = [Record]\r | |
621 | else:\r | |
622 | RecordDict[Key].append(Record)\r | |
623 | \r | |
624 | for Key in RecordDict:\r | |
625 | if len(RecordDict[Key]) > 1:\r | |
626 | for Item in RecordDict[Key]:\r | |
c4f52e12 | 627 | Path = mws.relpath(Item[1], EccGlobalData.gWorkspace)\r |
52302d4d | 628 | if not EccGlobalData.gException.IsException(ERROR_INCLUDE_FILE_CHECK_NAME, Path):\r |
d40b2ee6 | 629 | EccGlobalData.gDb.TblReport.Insert(ERROR_INCLUDE_FILE_CHECK_NAME, OtherMsg="The file name for [%s] is duplicate" % Path, BelongsToTable='File', BelongsToItem=Item[0])\r |
30fdf114 LG |
630 | \r |
631 | # Check whether all include file contents is guarded by a #ifndef statement.\r | |
632 | def IncludeFileCheckIfndef(self):\r | |
633 | if EccGlobalData.gConfig.IncludeFileCheckIfndefStatement == '1' or EccGlobalData.gConfig.IncludeFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
634 | EdkLogger.quiet("Checking header file ifndef ...")\r | |
635 | \r | |
e56468c0 | 636 | # for Dirpath, Dirnames, Filenames in self.WalkTree():\r |
637 | # for F in Filenames:\r | |
638 | # if os.path.splitext(F)[1] in ('.h'):\r | |
639 | # FullName = os.path.join(Dirpath, F)\r | |
640 | # MsgList = c.CheckHeaderFileIfndef(FullName)\r | |
641 | for FullName in EccGlobalData.gHFileList:\r | |
642 | MsgList = c.CheckHeaderFileIfndef(FullName)\r | |
30fdf114 LG |
643 | \r |
644 | # Check whether include files NOT contain code or define data variables\r | |
645 | def IncludeFileCheckData(self):\r | |
646 | if EccGlobalData.gConfig.IncludeFileCheckData == '1' or EccGlobalData.gConfig.IncludeFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
647 | EdkLogger.quiet("Checking header file data ...")\r | |
648 | \r | |
3a244b8d HC |
649 | # Get all typedef functions\r |
650 | gAllTypedefFun = []\r | |
651 | for IdentifierTable in EccGlobalData.gIdentifierTableList:\r | |
652 | SqlCommand = """select Name from %s\r | |
653 | where Model = %s """ % (IdentifierTable, MODEL_IDENTIFIER_TYPEDEF)\r | |
654 | RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r | |
655 | for Record in RecordSet:\r | |
656 | if Record[0].startswith('('):\r | |
657 | gAllTypedefFun.append(Record[0])\r | |
658 | \r | |
e56468c0 | 659 | # for Dirpath, Dirnames, Filenames in self.WalkTree():\r |
660 | # for F in Filenames:\r | |
661 | # if os.path.splitext(F)[1] in ('.h'):\r | |
662 | # FullName = os.path.join(Dirpath, F)\r | |
663 | # MsgList = c.CheckHeaderFileData(FullName)\r | |
664 | for FullName in EccGlobalData.gHFileList:\r | |
3a244b8d | 665 | MsgList = c.CheckHeaderFileData(FullName, gAllTypedefFun)\r |
30fdf114 LG |
666 | \r |
667 | # Doxygen document checking\r | |
668 | def DoxygenCheck(self):\r | |
669 | self.DoxygenCheckFileHeader()\r | |
670 | self.DoxygenCheckFunctionHeader()\r | |
671 | self.DoxygenCheckCommentDescription()\r | |
672 | self.DoxygenCheckCommentFormat()\r | |
673 | self.DoxygenCheckCommand()\r | |
674 | \r | |
675 | # Check whether the file headers are followed Doxygen special documentation blocks in section 2.3.5\r | |
676 | def DoxygenCheckFileHeader(self):\r | |
677 | if EccGlobalData.gConfig.DoxygenCheckFileHeader == '1' or EccGlobalData.gConfig.DoxygenCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
678 | EdkLogger.quiet("Checking Doxygen file header ...")\r | |
679 | \r | |
680 | for Dirpath, Dirnames, Filenames in self.WalkTree():\r | |
681 | for F in Filenames:\r | |
40d841f6 LG |
682 | Ext = os.path.splitext(F)[1]\r |
683 | if Ext in ('.h', '.c'):\r | |
30fdf114 LG |
684 | FullName = os.path.join(Dirpath, F)\r |
685 | MsgList = c.CheckFileHeaderDoxygenComments(FullName)\r | |
40d841f6 LG |
686 | elif Ext in ('.inf', '.dec', '.dsc', '.fdf'):\r |
687 | FullName = os.path.join(Dirpath, F)\r | |
e56468c0 | 688 | op = open(FullName).readlines()\r |
d0acc87a LG |
689 | FileLinesList = op\r |
690 | LineNo = 0\r | |
f7496d71 | 691 | CurrentSection = MODEL_UNKNOWN\r |
d0acc87a | 692 | HeaderSectionLines = []\r |
f7496d71 | 693 | HeaderCommentStart = False\r |
d0acc87a | 694 | HeaderCommentEnd = False\r |
f7496d71 | 695 | \r |
d0acc87a LG |
696 | for Line in FileLinesList:\r |
697 | LineNo = LineNo + 1\r | |
698 | Line = Line.strip()\r | |
699 | if (LineNo < len(FileLinesList) - 1):\r | |
700 | NextLine = FileLinesList[LineNo].strip()\r | |
f7496d71 | 701 | \r |
d0acc87a LG |
702 | #\r |
703 | # blank line\r | |
704 | #\r | |
705 | if (Line == '' or not Line) and LineNo == len(FileLinesList):\r | |
706 | LastSectionFalg = True\r | |
707 | \r | |
708 | #\r | |
709 | # check whether file header comment section started\r | |
710 | #\r | |
711 | if Line.startswith('#') and \\r | |
712 | (Line.find('@file') > -1) and \\r | |
713 | not HeaderCommentStart:\r | |
714 | if CurrentSection != MODEL_UNKNOWN:\r | |
715 | SqlStatement = """ select ID from File where FullPath like '%s'""" % FullName\r | |
716 | ResultSet = EccGlobalData.gDb.TblFile.Exec(SqlStatement)\r | |
717 | for Result in ResultSet:\r | |
718 | Msg = 'INF/DEC/DSC/FDF file header comment should begin with ""## @file"" or ""# @file""at the very top file'\r | |
719 | EccGlobalData.gDb.TblReport.Insert(ERROR_DOXYGEN_CHECK_FILE_HEADER, Msg, "File", Result[0])\r | |
720 | \r | |
721 | else:\r | |
722 | CurrentSection = MODEL_IDENTIFIER_FILE_HEADER\r | |
723 | #\r | |
724 | # Append the first line to section lines.\r | |
725 | #\r | |
726 | HeaderSectionLines.append((Line, LineNo))\r | |
727 | HeaderCommentStart = True\r | |
f7496d71 LG |
728 | continue\r |
729 | \r | |
d0acc87a LG |
730 | #\r |
731 | # Collect Header content.\r | |
732 | #\r | |
733 | if (Line.startswith('#') and CurrentSection == MODEL_IDENTIFIER_FILE_HEADER) and\\r | |
734 | HeaderCommentStart and not Line.startswith('##') and not\\r | |
735 | HeaderCommentEnd and NextLine != '':\r | |
736 | HeaderSectionLines.append((Line, LineNo))\r | |
737 | continue\r | |
738 | #\r | |
739 | # Header content end\r | |
740 | #\r | |
741 | if (Line.startswith('##') or not Line.strip().startswith("#")) and HeaderCommentStart \\r | |
742 | and not HeaderCommentEnd:\r | |
743 | if Line.startswith('##'):\r | |
744 | HeaderCommentEnd = True\r | |
745 | HeaderSectionLines.append((Line, LineNo))\r | |
746 | ParseHeaderCommentSection(HeaderSectionLines, FullName)\r | |
747 | break\r | |
748 | if HeaderCommentStart == False:\r | |
40d841f6 LG |
749 | SqlStatement = """ select ID from File where FullPath like '%s'""" % FullName\r |
750 | ResultSet = EccGlobalData.gDb.TblFile.Exec(SqlStatement)\r | |
751 | for Result in ResultSet:\r | |
d0acc87a | 752 | Msg = 'INF/DEC/DSC/FDF file header comment should begin with ""## @file"" or ""# @file"" at the very top file'\r |
40d841f6 | 753 | EccGlobalData.gDb.TblReport.Insert(ERROR_DOXYGEN_CHECK_FILE_HEADER, Msg, "File", Result[0])\r |
d0acc87a LG |
754 | if HeaderCommentEnd == False:\r |
755 | SqlStatement = """ select ID from File where FullPath like '%s'""" % FullName\r | |
756 | ResultSet = EccGlobalData.gDb.TblFile.Exec(SqlStatement)\r | |
757 | for Result in ResultSet:\r | |
758 | Msg = 'INF/DEC/DSC/FDF file header comment should end with ""##"" at the end of file header comment block'\r | |
759 | # Check whether File header Comment End with '##'\r | |
760 | if EccGlobalData.gConfig.HeaderCheckFileCommentEnd == '1' or EccGlobalData.gConfig.HeaderCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
761 | EccGlobalData.gDb.TblReport.Insert(ERROR_DOXYGEN_CHECK_FILE_HEADER, Msg, "File", Result[0])\r | |
e56468c0 | 762 | \r |
f7496d71 | 763 | \r |
30fdf114 LG |
764 | \r |
765 | # Check whether the function headers are followed Doxygen special documentation blocks in section 2.3.5\r | |
766 | def DoxygenCheckFunctionHeader(self):\r | |
767 | if EccGlobalData.gConfig.DoxygenCheckFunctionHeader == '1' or EccGlobalData.gConfig.DoxygenCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
768 | EdkLogger.quiet("Checking Doxygen function header ...")\r | |
769 | \r | |
e56468c0 | 770 | # for Dirpath, Dirnames, Filenames in self.WalkTree():\r |
771 | # for F in Filenames:\r | |
772 | # if os.path.splitext(F)[1] in ('.h', '.c'):\r | |
773 | # FullName = os.path.join(Dirpath, F)\r | |
774 | # MsgList = c.CheckFuncHeaderDoxygenComments(FullName)\r | |
775 | for FullName in EccGlobalData.gCFileList + EccGlobalData.gHFileList:\r | |
776 | MsgList = c.CheckFuncHeaderDoxygenComments(FullName)\r | |
777 | \r | |
30fdf114 LG |
778 | \r |
779 | # Check whether the first line of text in a comment block is a brief description of the element being documented.\r | |
780 | # The brief description must end with a period.\r | |
781 | def DoxygenCheckCommentDescription(self):\r | |
782 | if EccGlobalData.gConfig.DoxygenCheckCommentDescription == '1' or EccGlobalData.gConfig.DoxygenCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
783 | pass\r | |
784 | \r | |
785 | # Check whether comment lines with '///< ... text ...' format, if it is used, it should be after the code section.\r | |
786 | def DoxygenCheckCommentFormat(self):\r | |
787 | if EccGlobalData.gConfig.DoxygenCheckCommentFormat == '1' or EccGlobalData.gConfig.DoxygenCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
788 | EdkLogger.quiet("Checking Doxygen comment ///< ...")\r | |
789 | \r | |
e56468c0 | 790 | # for Dirpath, Dirnames, Filenames in self.WalkTree():\r |
791 | # for F in Filenames:\r | |
792 | # if os.path.splitext(F)[1] in ('.h', '.c'):\r | |
793 | # FullName = os.path.join(Dirpath, F)\r | |
794 | # MsgList = c.CheckDoxygenTripleForwardSlash(FullName)\r | |
795 | for FullName in EccGlobalData.gCFileList + EccGlobalData.gHFileList:\r | |
796 | MsgList = c.CheckDoxygenTripleForwardSlash(FullName)\r | |
30fdf114 LG |
797 | \r |
798 | # Check whether only Doxygen commands allowed to mark the code are @bug and @todo.\r | |
799 | def DoxygenCheckCommand(self):\r | |
800 | if EccGlobalData.gConfig.DoxygenCheckCommand == '1' or EccGlobalData.gConfig.DoxygenCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
801 | EdkLogger.quiet("Checking Doxygen command ...")\r | |
802 | \r | |
e56468c0 | 803 | # for Dirpath, Dirnames, Filenames in self.WalkTree():\r |
804 | # for F in Filenames:\r | |
805 | # if os.path.splitext(F)[1] in ('.h', '.c'):\r | |
806 | # FullName = os.path.join(Dirpath, F)\r | |
807 | # MsgList = c.CheckDoxygenCommand(FullName)\r | |
808 | for FullName in EccGlobalData.gCFileList + EccGlobalData.gHFileList:\r | |
809 | MsgList = c.CheckDoxygenCommand(FullName)\r | |
30fdf114 LG |
810 | \r |
811 | # Meta-Data File Processing Checking\r | |
812 | def MetaDataFileCheck(self):\r | |
813 | self.MetaDataFileCheckPathName()\r | |
814 | self.MetaDataFileCheckGenerateFileList()\r | |
815 | self.MetaDataFileCheckLibraryInstance()\r | |
816 | self.MetaDataFileCheckLibraryInstanceDependent()\r | |
817 | self.MetaDataFileCheckLibraryInstanceOrder()\r | |
818 | self.MetaDataFileCheckLibraryNoUse()\r | |
14239f66 | 819 | self.MetaDataFileCheckLibraryDefinedInDec()\r |
30fdf114 LG |
820 | self.MetaDataFileCheckBinaryInfInFdf()\r |
821 | self.MetaDataFileCheckPcdDuplicate()\r | |
822 | self.MetaDataFileCheckPcdFlash()\r | |
823 | self.MetaDataFileCheckPcdNoUse()\r | |
824 | self.MetaDataFileCheckGuidDuplicate()\r | |
825 | self.MetaDataFileCheckModuleFileNoUse()\r | |
826 | self.MetaDataFileCheckPcdType()\r | |
40d841f6 | 827 | self.MetaDataFileCheckModuleFileGuidDuplication()\r |
b3d07ff8 HC |
828 | self.MetaDataFileCheckModuleFileGuidFormat()\r |
829 | self.MetaDataFileCheckModuleFileProtocolFormat()\r | |
830 | self.MetaDataFileCheckModuleFilePpiFormat()\r | |
831 | self.MetaDataFileCheckModuleFilePcdFormat()\r | |
30fdf114 LG |
832 | \r |
833 | # Check whether each file defined in meta-data exists\r | |
834 | def MetaDataFileCheckPathName(self):\r | |
835 | if EccGlobalData.gConfig.MetaDataFileCheckPathName == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
836 | # This item is covered when parsing Inf/Dec/Dsc files\r | |
837 | pass\r | |
838 | \r | |
839 | # Generate a list for all files defined in meta-data files\r | |
840 | def MetaDataFileCheckGenerateFileList(self):\r | |
841 | if EccGlobalData.gConfig.MetaDataFileCheckGenerateFileList == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
842 | # This item is covered when parsing Inf/Dec/Dsc files\r | |
843 | pass\r | |
844 | \r | |
845 | # Check whether all Library Instances defined for a given module (or dependent library instance) match the module's type.\r | |
846 | # Each Library Instance must specify the Supported Module Types in its Inf file,\r | |
847 | # and any module specifying the library instance must be one of the supported types.\r | |
848 | def MetaDataFileCheckLibraryInstance(self):\r | |
849 | if EccGlobalData.gConfig.MetaDataFileCheckLibraryInstance == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
850 | EdkLogger.quiet("Checking for library instance type issue ...")\r | |
d0acc87a LG |
851 | SqlCommand = """select A.ID, A.Value3, B.Value3 from Inf as A left join Inf as B\r |
852 | where A.Value2 = 'LIBRARY_CLASS' and A.Model = %s\r | |
853 | and B.Value2 = 'MODULE_TYPE' and B.Model = %s and A.BelongsToFile = B.BelongsToFile\r | |
30fdf114 LG |
854 | group by A.BelongsToFile""" % (MODEL_META_DATA_HEADER, MODEL_META_DATA_HEADER)\r |
855 | RecordSet = EccGlobalData.gDb.TblInf.Exec(SqlCommand)\r | |
856 | LibraryClasses = {}\r | |
857 | for Record in RecordSet:\r | |
858 | List = Record[1].split('|', 1)\r | |
859 | SupModType = []\r | |
860 | if len(List) == 1:\r | |
b3d07ff8 | 861 | SupModType = DT.SUP_MODULE_LIST_STRING.split(DT.TAB_VALUE_SPLIT)\r |
30fdf114 LG |
862 | elif len(List) == 2:\r |
863 | SupModType = List[1].split()\r | |
864 | \r | |
865 | if List[0] not in LibraryClasses:\r | |
866 | LibraryClasses[List[0]] = SupModType\r | |
867 | else:\r | |
868 | for Item in SupModType:\r | |
869 | if Item not in LibraryClasses[List[0]]:\r | |
870 | LibraryClasses[List[0]].append(Item)\r | |
871 | \r | |
8bb63e37 | 872 | if Record[2] != DT.SUP_MODULE_BASE and Record[2] not in SupModType:\r |
d40b2ee6 | 873 | EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_LIBRARY_INSTANCE_2, OtherMsg="The Library Class '%s' does not specify its supported module types" % (List[0]), BelongsToTable='Inf', BelongsToItem=Record[0])\r |
30fdf114 | 874 | \r |
d0acc87a LG |
875 | SqlCommand = """select A.ID, A.Value1, B.Value3 from Inf as A left join Inf as B\r |
876 | where A.Model = %s and B.Value2 = '%s' and B.Model = %s\r | |
30fdf114 LG |
877 | and B.BelongsToFile = A.BelongsToFile""" \\r |
878 | % (MODEL_EFI_LIBRARY_CLASS, 'MODULE_TYPE', MODEL_META_DATA_HEADER)\r | |
879 | RecordSet = EccGlobalData.gDb.TblInf.Exec(SqlCommand)\r | |
880 | # Merge all LibraryClasses' supmodlist\r | |
881 | RecordDict = {}\r | |
882 | for Record in RecordSet:\r | |
883 | if Record[1] not in RecordDict:\r | |
884 | RecordDict[Record[1]] = [str(Record[2])]\r | |
885 | else:\r | |
886 | if Record[2] not in RecordDict[Record[1]]:\r | |
887 | RecordDict[Record[1]].append(Record[2])\r | |
888 | \r | |
889 | for Record in RecordSet:\r | |
890 | if Record[1] in LibraryClasses:\r | |
8bb63e37 | 891 | if Record[2] not in LibraryClasses[Record[1]] and DT.SUP_MODULE_BASE not in RecordDict[Record[1]]:\r |
30fdf114 | 892 | if not EccGlobalData.gException.IsException(ERROR_META_DATA_FILE_CHECK_LIBRARY_INSTANCE_1, Record[1]):\r |
d40b2ee6 | 893 | EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_LIBRARY_INSTANCE_1, OtherMsg="The type of Library Class [%s] defined in Inf file does not match the type of the module" % (Record[1]), BelongsToTable='Inf', BelongsToItem=Record[0])\r |
30fdf114 LG |
894 | else:\r |
895 | if not EccGlobalData.gException.IsException(ERROR_META_DATA_FILE_CHECK_LIBRARY_INSTANCE_1, Record[1]):\r | |
d40b2ee6 | 896 | EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_LIBRARY_INSTANCE_1, OtherMsg="The type of Library Class [%s] defined in Inf file does not match the type of the module" % (Record[1]), BelongsToTable='Inf', BelongsToItem=Record[0])\r |
30fdf114 LG |
897 | \r |
898 | # Check whether a Library Instance has been defined for all dependent library classes\r | |
899 | def MetaDataFileCheckLibraryInstanceDependent(self):\r | |
900 | if EccGlobalData.gConfig.MetaDataFileCheckLibraryInstanceDependent == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
901 | EdkLogger.quiet("Checking for library instance dependent issue ...")\r | |
902 | SqlCommand = """select ID, Value1, Value2 from Dsc where Model = %s""" % MODEL_EFI_LIBRARY_CLASS\r | |
903 | LibraryClasses = EccGlobalData.gDb.TblDsc.Exec(SqlCommand)\r | |
904 | for LibraryClass in LibraryClasses:\r | |
d0acc87a LG |
905 | if LibraryClass[1].upper() == 'NULL' or LibraryClass[1].startswith('!ifdef') or LibraryClass[1].startswith('!ifndef') or LibraryClass[1].endswith('!endif'):\r |
906 | continue\r | |
907 | else:\r | |
c4f52e12 | 908 | LibraryIns = os.path.normpath(mws.join(EccGlobalData.gWorkspace, LibraryClass[2]))\r |
044f6017 HC |
909 | SkipDirString = '|'.join(EccGlobalData.gConfig.SkipDirList)\r |
910 | p = re.compile(r'.*[\\/](?:%s^\S)[\\/]?.*' % SkipDirString)\r | |
911 | if p.match(os.path.split(LibraryIns)[0].upper()):\r | |
912 | continue\r | |
d0acc87a | 913 | SqlCommand = """select Value3 from Inf where BelongsToFile =\r |
30fdf114 | 914 | (select ID from File where lower(FullPath) = lower('%s'))\r |
1beb268a | 915 | and Value2 = '%s'""" % (LibraryIns, DT.PLATFORM_COMPONENT_TYPE_LIBRARY_CLASS)\r |
30fdf114 LG |
916 | RecordSet = EccGlobalData.gDb.TblInf.Exec(SqlCommand)\r |
917 | IsFound = False\r | |
918 | for Record in RecordSet:\r | |
919 | LibName = Record[0].split('|', 1)[0]\r | |
920 | if LibraryClass[1] == LibName:\r | |
921 | IsFound = True\r | |
922 | if not IsFound:\r | |
923 | if not EccGlobalData.gException.IsException(ERROR_META_DATA_FILE_CHECK_LIBRARY_INSTANCE_DEPENDENT, LibraryClass[1]):\r | |
d40b2ee6 | 924 | EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_LIBRARY_INSTANCE_DEPENDENT, OtherMsg="The Library Class [%s] is not specified in '%s'" % (LibraryClass[1], LibraryClass[2]), BelongsToTable='Dsc', BelongsToItem=LibraryClass[0])\r |
30fdf114 LG |
925 | \r |
926 | # Check whether the Library Instances specified by the LibraryClasses sections are listed in order of dependencies\r | |
927 | def MetaDataFileCheckLibraryInstanceOrder(self):\r | |
928 | if EccGlobalData.gConfig.MetaDataFileCheckLibraryInstanceOrder == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
929 | # This checkpoint is not necessary for Ecc check\r | |
930 | pass\r | |
931 | \r | |
932 | # Check whether the unnecessary inclusion of library classes in the Inf file\r | |
2bcc713e | 933 | # Check whether the unnecessary duplication of library classe names in the DSC file\r |
30fdf114 LG |
934 | def MetaDataFileCheckLibraryNoUse(self):\r |
935 | if EccGlobalData.gConfig.MetaDataFileCheckLibraryNoUse == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
936 | EdkLogger.quiet("Checking for library instance not used ...")\r | |
937 | SqlCommand = """select ID, Value1 from Inf as A where A.Model = %s and A.Value1 not in (select B.Value1 from Dsc as B where Model = %s)""" % (MODEL_EFI_LIBRARY_CLASS, MODEL_EFI_LIBRARY_CLASS)\r | |
938 | RecordSet = EccGlobalData.gDb.TblInf.Exec(SqlCommand)\r | |
939 | for Record in RecordSet:\r | |
940 | if not EccGlobalData.gException.IsException(ERROR_META_DATA_FILE_CHECK_LIBRARY_NO_USE, Record[1]):\r | |
d40b2ee6 | 941 | EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_LIBRARY_NO_USE, OtherMsg="The Library Class [%s] is not used in any platform" % (Record[1]), BelongsToTable='Inf', BelongsToItem=Record[0])\r |
2bcc713e LG |
942 | SqlCommand = """\r |
943 | select A.ID, A.Value1, A.BelongsToFile, A.StartLine, B.StartLine from Dsc as A left join Dsc as B\r | |
87d2afd0 GL |
944 | where A.Model = %s and B.Model = %s and A.Scope1 = B.Scope1 and A.Scope2 = B.Scope2 and A.ID != B.ID\r |
945 | and A.Value1 = B.Value1 and A.Value2 != B.Value2 and A.BelongsToItem = -1 and B.BelongsToItem = -1 and A.StartLine != B.StartLine and B.BelongsToFile = A.BelongsToFile""" \\r | |
2bcc713e LG |
946 | % (MODEL_EFI_LIBRARY_CLASS, MODEL_EFI_LIBRARY_CLASS)\r |
947 | RecordSet = EccGlobalData.gDb.TblDsc.Exec(SqlCommand)\r | |
948 | for Record in RecordSet:\r | |
e7ae4a7c | 949 | if Record[3] and Record[4] and Record[3] != Record[4] and Record[1] != 'NULL':\r |
2bcc713e LG |
950 | SqlCommand = """select FullPath from File where ID = %s""" % (Record[2])\r |
951 | FilePathList = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r | |
952 | for FilePath in FilePathList:\r | |
953 | if not EccGlobalData.gException.IsException(ERROR_META_DATA_FILE_CHECK_LIBRARY_NAME_DUPLICATE, Record[1]):\r | |
954 | EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_LIBRARY_NAME_DUPLICATE, OtherMsg="The Library Class [%s] is duplicated in '%s' line %s and line %s." % (Record[1], FilePath, Record[3], Record[4]), BelongsToTable='Dsc', BelongsToItem=Record[0])\r | |
f7496d71 | 955 | \r |
14239f66 HC |
956 | # Check the header file in Include\Library directory whether be defined in the package DEC file.\r |
957 | def MetaDataFileCheckLibraryDefinedInDec(self):\r | |
958 | if EccGlobalData.gConfig.MetaDataFileCheckLibraryDefinedInDec == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
959 | EdkLogger.quiet("Checking for library instance whether be defined in the package dec file ...")\r | |
960 | SqlCommand = """\r | |
961 | select A.Value1, A.StartLine, A.ID, B.Value1 from Inf as A left join Dec as B\r | |
962 | on A.Model = B.Model and A.Value1 = B.Value1 where A.Model=%s\r | |
963 | """ % MODEL_EFI_LIBRARY_CLASS\r | |
964 | RecordSet = EccGlobalData.gDb.TblDsc.Exec(SqlCommand)\r | |
965 | for Record in RecordSet:\r | |
966 | LibraryInInf, Line, ID, LibraryDec = Record\r | |
967 | if not LibraryDec:\r | |
968 | if not EccGlobalData.gException.IsException(ERROR_META_DATA_FILE_CHECK_LIBRARY_NOT_DEFINED, LibraryInInf):\r | |
969 | EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_LIBRARY_NOT_DEFINED, \\r | |
f7496d71 | 970 | OtherMsg="The Library Class [%s] in %s line is not defined in the associated package file." % (LibraryInInf, Line),\r |
14239f66 | 971 | BelongsToTable='Inf', BelongsToItem=ID)\r |
f7496d71 | 972 | \r |
30fdf114 LG |
973 | # 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 |
974 | def MetaDataFileCheckBinaryInfInFdf(self):\r | |
975 | if EccGlobalData.gConfig.MetaDataFileCheckBinaryInfInFdf == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
976 | EdkLogger.quiet("Checking for non-binary modules defined in FDF files ...")\r | |
977 | SqlCommand = """select A.ID, A.Value1 from Fdf as A\r | |
978 | where A.Model = %s\r | |
979 | and A.Enabled > -1\r | |
980 | and A.Value1 not in\r | |
981 | (select B.Value1 from Dsc as B\r | |
982 | where B.Model = %s\r | |
983 | and B.Enabled > -1)""" % (MODEL_META_DATA_COMPONENT, MODEL_META_DATA_COMPONENT)\r | |
984 | RecordSet = EccGlobalData.gDb.TblFdf.Exec(SqlCommand)\r | |
985 | for Record in RecordSet:\r | |
986 | FdfID = Record[0]\r | |
987 | FilePath = Record[1]\r | |
c4f52e12 | 988 | FilePath = os.path.normpath(mws.join(EccGlobalData.gWorkspace, FilePath))\r |
30fdf114 LG |
989 | SqlCommand = """select ID from Inf where Model = %s and BelongsToFile = (select ID from File where FullPath like '%s')\r |
990 | """ % (MODEL_EFI_SOURCE_FILE, FilePath)\r | |
991 | NewRecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r | |
d40b2ee6 | 992 | if NewRecordSet != []:\r |
30fdf114 | 993 | if not EccGlobalData.gException.IsException(ERROR_META_DATA_FILE_CHECK_BINARY_INF_IN_FDF, FilePath):\r |
d40b2ee6 | 994 | EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_BINARY_INF_IN_FDF, OtherMsg="File [%s] defined in FDF file and not in DSC file must be a binary module" % (FilePath), BelongsToTable='Fdf', BelongsToItem=FdfID)\r |
30fdf114 LG |
995 | \r |
996 | # Check whether a PCD is set in a Dsc file or the FDF file, but not in both.\r | |
997 | def MetaDataFileCheckPcdDuplicate(self):\r | |
998 | if EccGlobalData.gConfig.MetaDataFileCheckPcdDuplicate == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
999 | EdkLogger.quiet("Checking for duplicate PCDs defined in both DSC and FDF files ...")\r | |
1000 | SqlCommand = """\r | |
d0acc87a | 1001 | select A.ID, A.Value1, A.Value2, A.BelongsToFile, B.ID, B.Value1, B.Value2, B.BelongsToFile from Dsc as A, Fdf as B\r |
30fdf114 LG |
1002 | where A.Model >= %s and A.Model < %s\r |
1003 | and B.Model >= %s and B.Model < %s\r | |
d0acc87a | 1004 | and A.Value1 = B.Value1\r |
30fdf114 LG |
1005 | and A.Value2 = B.Value2\r |
1006 | and A.Enabled > -1\r | |
1007 | and B.Enabled > -1\r | |
1008 | group by A.ID\r | |
d40b2ee6 | 1009 | """ % (MODEL_PCD, MODEL_META_DATA_HEADER, MODEL_PCD, MODEL_META_DATA_HEADER)\r |
30fdf114 LG |
1010 | RecordSet = EccGlobalData.gDb.TblDsc.Exec(SqlCommand)\r |
1011 | for Record in RecordSet:\r | |
d0acc87a LG |
1012 | SqlCommand1 = """select Name from File where ID = %s""" % Record[3]\r |
1013 | SqlCommand2 = """select Name from File where ID = %s""" % Record[7]\r | |
52302d4d LG |
1014 | DscFileName = os.path.splitext(EccGlobalData.gDb.TblDsc.Exec(SqlCommand1)[0][0])[0]\r |
1015 | FdfFileName = os.path.splitext(EccGlobalData.gDb.TblDsc.Exec(SqlCommand2)[0][0])[0]\r | |
52302d4d LG |
1016 | if DscFileName != FdfFileName:\r |
1017 | continue\r | |
d0acc87a LG |
1018 | if not EccGlobalData.gException.IsException(ERROR_META_DATA_FILE_CHECK_PCD_DUPLICATE, Record[1] + '.' + Record[2]):\r |
1019 | EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_PCD_DUPLICATE, OtherMsg="The PCD [%s] is defined in both FDF file and DSC file" % (Record[1] + '.' + Record[2]), BelongsToTable='Dsc', BelongsToItem=Record[0])\r | |
1020 | if not EccGlobalData.gException.IsException(ERROR_META_DATA_FILE_CHECK_PCD_DUPLICATE, Record[5] + '.' + Record[6]):\r | |
1021 | EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_PCD_DUPLICATE, OtherMsg="The PCD [%s] is defined in both FDF file and DSC file" % (Record[5] + '.' + Record[6]), BelongsToTable='Fdf', BelongsToItem=Record[4])\r | |
30fdf114 LG |
1022 | \r |
1023 | EdkLogger.quiet("Checking for duplicate PCDs defined in DEC files ...")\r | |
1024 | SqlCommand = """\r | |
d0acc87a | 1025 | select A.ID, A.Value1, A.Value2, A.Model, B.Model from Dec as A left join Dec as B\r |
30fdf114 LG |
1026 | where A.Model >= %s and A.Model < %s\r |
1027 | and B.Model >= %s and B.Model < %s\r | |
d0acc87a | 1028 | and A.Value1 = B.Value1\r |
30fdf114 | 1029 | and A.Value2 = B.Value2\r |
d0acc87a | 1030 | and A.Scope1 = B.Scope1\r |
87d2afd0 | 1031 | and A.ID != B.ID\r |
d0acc87a | 1032 | and A.Model = B.Model\r |
30fdf114 LG |
1033 | and A.Enabled > -1\r |
1034 | and B.Enabled > -1\r | |
1035 | and A.BelongsToFile = B.BelongsToFile\r | |
1036 | group by A.ID\r | |
d40b2ee6 | 1037 | """ % (MODEL_PCD, MODEL_META_DATA_HEADER, MODEL_PCD, MODEL_META_DATA_HEADER)\r |
d0acc87a | 1038 | RecordSet = EccGlobalData.gDb.TblDec.Exec(SqlCommand)\r |
30fdf114 | 1039 | for Record in RecordSet:\r |
d0acc87a LG |
1040 | RecordCat = Record[1] + '.' + Record[2]\r |
1041 | if not EccGlobalData.gException.IsException(ERROR_META_DATA_FILE_CHECK_PCD_DUPLICATE, RecordCat):\r | |
1042 | EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_PCD_DUPLICATE, OtherMsg="The PCD [%s] is defined duplicated in DEC file" % RecordCat, BelongsToTable='Dec', BelongsToItem=Record[0])\r | |
30fdf114 LG |
1043 | \r |
1044 | # Check whether PCD settings in the FDF file can only be related to flash.\r | |
1045 | def MetaDataFileCheckPcdFlash(self):\r | |
1046 | if EccGlobalData.gConfig.MetaDataFileCheckPcdFlash == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
1047 | EdkLogger.quiet("Checking only Flash related PCDs are used in FDF ...")\r | |
1048 | SqlCommand = """\r | |
d0acc87a | 1049 | select ID, Value1, Value2, BelongsToFile from Fdf as A\r |
30fdf114 LG |
1050 | where A.Model >= %s and Model < %s\r |
1051 | and A.Enabled > -1\r | |
1052 | and A.Value2 not like '%%Flash%%'\r | |
d40b2ee6 | 1053 | """ % (MODEL_PCD, MODEL_META_DATA_HEADER)\r |
30fdf114 LG |
1054 | RecordSet = EccGlobalData.gDb.TblFdf.Exec(SqlCommand)\r |
1055 | for Record in RecordSet:\r | |
d0acc87a LG |
1056 | if not EccGlobalData.gException.IsException(ERROR_META_DATA_FILE_CHECK_PCD_FLASH, Record[1] + '.' + Record[2]):\r |
1057 | EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_PCD_FLASH, OtherMsg="The PCD [%s] defined in FDF file is not related to Flash" % (Record[1] + '.' + Record[2]), BelongsToTable='Fdf', BelongsToItem=Record[0])\r | |
30fdf114 LG |
1058 | \r |
1059 | # Check whether PCDs used in Inf files but not specified in Dsc or FDF files\r | |
1060 | def MetaDataFileCheckPcdNoUse(self):\r | |
1061 | if EccGlobalData.gConfig.MetaDataFileCheckPcdNoUse == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
1062 | EdkLogger.quiet("Checking for non-specified PCDs ...")\r | |
1063 | SqlCommand = """\r | |
d0acc87a | 1064 | select ID, Value1, Value2, BelongsToFile from Inf as A\r |
30fdf114 LG |
1065 | where A.Model >= %s and Model < %s\r |
1066 | and A.Enabled > -1\r | |
d0acc87a LG |
1067 | and (A.Value1, A.Value2) not in\r |
1068 | (select Value1, Value2 from Dsc as B\r | |
30fdf114 LG |
1069 | where B.Model >= %s and B.Model < %s\r |
1070 | and B.Enabled > -1)\r | |
d0acc87a LG |
1071 | and (A.Value1, A.Value2) not in\r |
1072 | (select Value1, Value2 from Fdf as C\r | |
30fdf114 LG |
1073 | where C.Model >= %s and C.Model < %s\r |
1074 | and C.Enabled > -1)\r | |
d40b2ee6 | 1075 | """ % (MODEL_PCD, MODEL_META_DATA_HEADER, MODEL_PCD, MODEL_META_DATA_HEADER, MODEL_PCD, MODEL_META_DATA_HEADER)\r |
30fdf114 LG |
1076 | RecordSet = EccGlobalData.gDb.TblInf.Exec(SqlCommand)\r |
1077 | for Record in RecordSet:\r | |
d0acc87a LG |
1078 | if not EccGlobalData.gException.IsException(ERROR_META_DATA_FILE_CHECK_PCD_NO_USE, Record[1] + '.' + Record[2]):\r |
1079 | EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_PCD_NO_USE, OtherMsg="The PCD [%s] defined in INF file is not specified in either DSC or FDF files" % (Record[1] + '.' + Record[2]), BelongsToTable='Inf', BelongsToItem=Record[0])\r | |
30fdf114 LG |
1080 | \r |
1081 | # Check whether having duplicate guids defined for Guid/Protocol/Ppi\r | |
1082 | def MetaDataFileCheckGuidDuplicate(self):\r | |
1083 | if EccGlobalData.gConfig.MetaDataFileCheckGuidDuplicate == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
1084 | EdkLogger.quiet("Checking for duplicate GUID/PPI/PROTOCOL ...")\r | |
1085 | # Check Guid\r | |
1086 | self.CheckGuidProtocolPpi(ERROR_META_DATA_FILE_CHECK_DUPLICATE_GUID, MODEL_EFI_GUID, EccGlobalData.gDb.TblDec)\r | |
1087 | self.CheckGuidProtocolPpi(ERROR_META_DATA_FILE_CHECK_DUPLICATE_GUID, MODEL_EFI_GUID, EccGlobalData.gDb.TblDsc)\r | |
1088 | self.CheckGuidProtocolPpiValue(ERROR_META_DATA_FILE_CHECK_DUPLICATE_GUID, MODEL_EFI_GUID)\r | |
1089 | # Check protocol\r | |
1090 | self.CheckGuidProtocolPpi(ERROR_META_DATA_FILE_CHECK_DUPLICATE_PROTOCOL, MODEL_EFI_PROTOCOL, EccGlobalData.gDb.TblDec)\r | |
1091 | self.CheckGuidProtocolPpi(ERROR_META_DATA_FILE_CHECK_DUPLICATE_PROTOCOL, MODEL_EFI_PROTOCOL, EccGlobalData.gDb.TblDsc)\r | |
1092 | self.CheckGuidProtocolPpiValue(ERROR_META_DATA_FILE_CHECK_DUPLICATE_PROTOCOL, MODEL_EFI_PROTOCOL)\r | |
1093 | # Check ppi\r | |
1094 | self.CheckGuidProtocolPpi(ERROR_META_DATA_FILE_CHECK_DUPLICATE_PPI, MODEL_EFI_PPI, EccGlobalData.gDb.TblDec)\r | |
1095 | self.CheckGuidProtocolPpi(ERROR_META_DATA_FILE_CHECK_DUPLICATE_PPI, MODEL_EFI_PPI, EccGlobalData.gDb.TblDsc)\r | |
1096 | self.CheckGuidProtocolPpiValue(ERROR_META_DATA_FILE_CHECK_DUPLICATE_PPI, MODEL_EFI_PPI)\r | |
1097 | \r | |
1098 | # Check whether all files under module directory are described in INF files\r | |
1099 | def MetaDataFileCheckModuleFileNoUse(self):\r | |
1100 | if EccGlobalData.gConfig.MetaDataFileCheckModuleFileNoUse == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
1101 | EdkLogger.quiet("Checking for no used module files ...")\r | |
1102 | SqlCommand = """\r | |
d0acc87a | 1103 | select upper(Path) from File where ID in (select BelongsToFile from Inf where BelongsToFile != -1)\r |
30fdf114 LG |
1104 | """\r |
1105 | InfPathSet = EccGlobalData.gDb.TblInf.Exec(SqlCommand)\r | |
1106 | InfPathList = []\r | |
1107 | for Item in InfPathSet:\r | |
1108 | if Item[0] not in InfPathList:\r | |
1109 | InfPathList.append(Item[0])\r | |
1110 | SqlCommand = """\r | |
1111 | select ID, Path, FullPath from File where upper(FullPath) not in\r | |
1112 | (select upper(A.Path) || '\\' || upper(B.Value1) from File as A, INF as B\r | |
1113 | where A.ID in (select BelongsToFile from INF where Model = %s group by BelongsToFile) and\r | |
1114 | B.BelongsToFile = A.ID and B.Model = %s)\r | |
1115 | and (Model = %s or Model = %s)\r | |
1116 | """ % (MODEL_EFI_SOURCE_FILE, MODEL_EFI_SOURCE_FILE, MODEL_FILE_C, MODEL_FILE_H)\r | |
1117 | RecordSet = EccGlobalData.gDb.TblInf.Exec(SqlCommand)\r | |
1118 | for Record in RecordSet:\r | |
1119 | Path = Record[1]\r | |
b3d07ff8 | 1120 | Path = Path.upper().replace('\X64', '').replace('\IA32', '').replace('\EBC', '').replace('\IPF', '').replace('\ARM', '')\r |
30fdf114 LG |
1121 | if Path in InfPathList:\r |
1122 | if not EccGlobalData.gException.IsException(ERROR_META_DATA_FILE_CHECK_MODULE_FILE_NO_USE, Record[2]):\r | |
d40b2ee6 | 1123 | EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_MODULE_FILE_NO_USE, OtherMsg="The source file [%s] is existing in module directory but it is not described in INF file." % (Record[2]), BelongsToTable='File', BelongsToItem=Record[0])\r |
30fdf114 LG |
1124 | \r |
1125 | # Check whether the PCD is correctly used in C function via its type\r | |
1126 | def MetaDataFileCheckPcdType(self):\r | |
1127 | if EccGlobalData.gConfig.MetaDataFileCheckPcdType == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
1128 | EdkLogger.quiet("Checking for pcd type in c code function usage ...")\r | |
1129 | SqlCommand = """\r | |
d0acc87a | 1130 | select ID, Model, Value1, Value2, BelongsToFile from INF where Model > %s and Model < %s\r |
30fdf114 LG |
1131 | """ % (MODEL_PCD, MODEL_META_DATA_HEADER)\r |
1132 | PcdSet = EccGlobalData.gDb.TblInf.Exec(SqlCommand)\r | |
1133 | for Pcd in PcdSet:\r | |
1134 | Model = Pcd[1]\r | |
1135 | PcdName = Pcd[2]\r | |
d0acc87a LG |
1136 | if Pcd[3]:\r |
1137 | PcdName = Pcd[3]\r | |
1138 | BelongsToFile = Pcd[4]\r | |
30fdf114 LG |
1139 | SqlCommand = """\r |
1140 | select ID from File where FullPath in\r | |
1141 | (select B.Path || '\\' || A.Value1 from INF as A, File as B where A.Model = %s and A.BelongsToFile = %s\r | |
e56468c0 | 1142 | and B.ID = %s and (B.Model = %s or B.Model = %s))\r |
d40b2ee6 | 1143 | """ % (MODEL_EFI_SOURCE_FILE, BelongsToFile, BelongsToFile, MODEL_FILE_C, MODEL_FILE_H)\r |
30fdf114 LG |
1144 | TableSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r |
1145 | for Tbl in TableSet:\r | |
1146 | TblName = 'Identifier' + str(Tbl[0])\r | |
1147 | SqlCommand = """\r | |
52302d4d | 1148 | select Name, ID from %s where value like '%s' and Model = %s\r |
30fdf114 LG |
1149 | """ % (TblName, PcdName, MODEL_IDENTIFIER_FUNCTION_CALLING)\r |
1150 | RecordSet = EccGlobalData.gDb.TblInf.Exec(SqlCommand)\r | |
1151 | TblNumber = TblName.replace('Identifier', '')\r | |
1152 | for Record in RecordSet:\r | |
1153 | FunName = Record[0]\r | |
1154 | if not EccGlobalData.gException.IsException(ERROR_META_DATA_FILE_CHECK_PCD_TYPE, FunName):\r | |
1155 | if Model in [MODEL_PCD_FIXED_AT_BUILD] and not FunName.startswith('FixedPcdGet'):\r | |
d40b2ee6 | 1156 | EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_PCD_TYPE, OtherMsg="The pcd '%s' is defined as a FixPcd but now it is called by c function [%s]" % (PcdName, FunName), BelongsToTable=TblName, BelongsToItem=Record[1])\r |
30fdf114 | 1157 | if Model in [MODEL_PCD_FEATURE_FLAG] and (not FunName.startswith('FeaturePcdGet') and not FunName.startswith('FeaturePcdSet')):\r |
d40b2ee6 | 1158 | EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_PCD_TYPE, OtherMsg="The pcd '%s' is defined as a FeaturePcd but now it is called by c function [%s]" % (PcdName, FunName), BelongsToTable=TblName, BelongsToItem=Record[1])\r |
30fdf114 | 1159 | if Model in [MODEL_PCD_PATCHABLE_IN_MODULE] and (not FunName.startswith('PatchablePcdGet') and not FunName.startswith('PatchablePcdSet')):\r |
d40b2ee6 | 1160 | EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_PCD_TYPE, OtherMsg="The pcd '%s' is defined as a PatchablePcd but now it is called by c function [%s]" % (PcdName, FunName), BelongsToTable=TblName, BelongsToItem=Record[1])\r |
30fdf114 LG |
1161 | \r |
1162 | #ERROR_META_DATA_FILE_CHECK_PCD_TYPE\r | |
1163 | pass\r | |
1164 | \r | |
40d841f6 LG |
1165 | # Internal worker function to get the INF workspace relative path from FileID\r |
1166 | def GetInfFilePathFromID(self, FileID):\r | |
1167 | Table = EccGlobalData.gDb.TblFile\r | |
1168 | SqlCommand = """select A.FullPath from %s as A where A.ID = %s""" % (Table.Table, FileID)\r | |
1169 | RecordSet = Table.Exec(SqlCommand)\r | |
1170 | Path = ""\r | |
1171 | for Record in RecordSet:\r | |
c4f52e12 | 1172 | Path = mws.relpath(Record[0], EccGlobalData.gWorkspace)\r |
40d841f6 | 1173 | return Path\r |
e56468c0 | 1174 | \r |
40d841f6 LG |
1175 | # Check whether two module INFs under one workspace has the same FILE_GUID value\r |
1176 | def MetaDataFileCheckModuleFileGuidDuplication(self):\r | |
1177 | if EccGlobalData.gConfig.MetaDataFileCheckModuleFileGuidDuplication == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
1178 | EdkLogger.quiet("Checking for pcd type in c code function usage ...")\r | |
1179 | Table = EccGlobalData.gDb.TblInf\r | |
1180 | SqlCommand = """\r | |
d0acc87a LG |
1181 | select A.ID, A.Value3, A.BelongsToFile, B.BelongsToFile from %s as A, %s as B\r |
1182 | where A.Value2 = 'FILE_GUID' and B.Value2 = 'FILE_GUID' and\r | |
87d2afd0 | 1183 | A.Value3 = B.Value3 and A.ID != B.ID group by A.ID\r |
40d841f6 LG |
1184 | """ % (Table.Table, Table.Table)\r |
1185 | RecordSet = Table.Exec(SqlCommand)\r | |
1186 | for Record in RecordSet:\r | |
1187 | InfPath1 = self.GetInfFilePathFromID(Record[2])\r | |
1188 | InfPath2 = self.GetInfFilePathFromID(Record[3])\r | |
1189 | if InfPath1 and InfPath2:\r | |
1190 | if not EccGlobalData.gException.IsException(ERROR_META_DATA_FILE_CHECK_MODULE_FILE_GUID_DUPLICATION, InfPath1):\r | |
1191 | Msg = "The FILE_GUID of INF file [%s] is duplicated with that of %s" % (InfPath1, InfPath2)\r | |
d40b2ee6 | 1192 | EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_MODULE_FILE_GUID_DUPLICATION, OtherMsg=Msg, BelongsToTable=Table.Table, BelongsToItem=Record[0])\r |
e56468c0 | 1193 | \r |
40d841f6 | 1194 | \r |
b3d07ff8 HC |
1195 | # Check Guid Format in module INF\r |
1196 | def MetaDataFileCheckModuleFileGuidFormat(self):\r | |
f8c1facf | 1197 | if EccGlobalData.gConfig.MetaDataFileCheckModuleFileGuidFormat == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r |
b3d07ff8 HC |
1198 | EdkLogger.quiet("Check Guid Format in module INF ...")\r |
1199 | Table = EccGlobalData.gDb.TblInf\r | |
1200 | SqlCommand = """\r | |
1201 | select ID, Value1, Usage, BelongsToFile from %s where Model = %s group by ID\r | |
1202 | """ % (Table.Table, MODEL_EFI_GUID)\r | |
1203 | RecordSet = Table.Exec(SqlCommand)\r | |
1204 | for Record in RecordSet:\r | |
1205 | Value1 = Record[1]\r | |
1206 | Value2 = Record[2]\r | |
1207 | GuidCommentList = []\r | |
1208 | InfPath = self.GetInfFilePathFromID(Record[3])\r | |
1209 | Msg = "The GUID format of %s in INF file [%s] does not follow rules" % (Value1, InfPath)\r | |
1210 | if Value2.startswith(DT.TAB_SPECIAL_COMMENT):\r | |
1211 | GuidCommentList = Value2[2:].split(DT.TAB_SPECIAL_COMMENT)\r | |
1212 | if GuidCommentList[0].strip().startswith(DT.TAB_INF_USAGE_UNDEFINED):\r | |
1213 | continue\r | |
1214 | elif len(GuidCommentList) > 1:\r | |
1215 | if not GuidCommentList[0].strip().startswith((DT.TAB_INF_USAGE_PRO,\r | |
1216 | DT.TAB_INF_USAGE_SOME_PRO,\r | |
1217 | DT.TAB_INF_USAGE_CON,\r | |
1218 | DT.TAB_INF_USAGE_SOME_CON)):\r | |
1219 | EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_FORMAT_GUID, OtherMsg=Msg, BelongsToTable=Table.Table, BelongsToItem=Record[0])\r | |
1220 | if not (GuidCommentList[1].strip()).startswith(DT.TAB_INF_GUIDTYPE_VAR) and \\r | |
1221 | not GuidCommentList[1].strip().startswith((DT.TAB_INF_GUIDTYPE_EVENT,\r | |
1222 | DT.TAB_INF_GUIDTYPE_HII,\r | |
1223 | DT.TAB_INF_GUIDTYPE_FILE,\r | |
1224 | DT.TAB_INF_GUIDTYPE_HOB,\r | |
1225 | DT.TAB_INF_GUIDTYPE_FV,\r | |
1226 | DT.TAB_INF_GUIDTYPE_ST,\r | |
1227 | DT.TAB_INF_GUIDTYPE_TSG,\r | |
1228 | DT.TAB_INF_GUIDTYPE_GUID,\r | |
1229 | DT.TAB_INF_GUIDTYPE_PROTOCOL,\r | |
1230 | DT.TAB_INF_GUIDTYPE_PPI,\r | |
1231 | DT.TAB_INF_USAGE_UNDEFINED)):\r | |
1232 | EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_FORMAT_GUID, OtherMsg=Msg, BelongsToTable=Table.Table, BelongsToItem=Record[0])\r | |
1233 | else:\r | |
1234 | EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_FORMAT_GUID, OtherMsg=Msg, BelongsToTable=Table.Table, BelongsToItem=Record[0])\r | |
1235 | else:\r | |
1236 | EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_FORMAT_GUID, OtherMsg=Msg, BelongsToTable=Table.Table, BelongsToItem=Record[0])\r | |
1237 | \r | |
1238 | # Check Protocol Format in module INF\r | |
1239 | def MetaDataFileCheckModuleFileProtocolFormat(self):\r | |
f8c1facf | 1240 | if EccGlobalData.gConfig.MetaDataFileCheckModuleFileProtocolFormat == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r |
b3d07ff8 HC |
1241 | EdkLogger.quiet("Check Protocol Format in module INF ...")\r |
1242 | Table = EccGlobalData.gDb.TblInf\r | |
1243 | SqlCommand = """\r | |
1244 | select ID, Value1, Usage, BelongsToFile from %s where Model = %s group by ID\r | |
1245 | """ % (Table.Table, MODEL_EFI_PROTOCOL)\r | |
1246 | RecordSet = Table.Exec(SqlCommand)\r | |
1247 | for Record in RecordSet:\r | |
1248 | Value1 = Record[1]\r | |
1249 | Value2 = Record[2]\r | |
1250 | GuidCommentList = []\r | |
1251 | InfPath = self.GetInfFilePathFromID(Record[3])\r | |
1252 | Msg = "The Protocol format of %s in INF file [%s] does not follow rules" % (Value1, InfPath)\r | |
1253 | if Value2.startswith(DT.TAB_SPECIAL_COMMENT):\r | |
1254 | GuidCommentList = Value2[2:].split(DT.TAB_SPECIAL_COMMENT)\r | |
1255 | if len(GuidCommentList) >= 1:\r | |
1256 | if not GuidCommentList[0].strip().startswith((DT.TAB_INF_USAGE_PRO,\r | |
1257 | DT.TAB_INF_USAGE_SOME_PRO,\r | |
1258 | DT.TAB_INF_USAGE_CON,\r | |
1259 | DT.TAB_INF_USAGE_SOME_CON,\r | |
1260 | DT.TAB_INF_USAGE_NOTIFY,\r | |
1261 | DT.TAB_INF_USAGE_TO_START,\r | |
1262 | DT.TAB_INF_USAGE_BY_START,\r | |
1263 | DT.TAB_INF_USAGE_UNDEFINED)):\r | |
1264 | EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_FORMAT_PROTOCOL, OtherMsg=Msg, BelongsToTable=Table.Table, BelongsToItem=Record[0])\r | |
1265 | else:\r | |
1266 | EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_FORMAT_PROTOCOL, OtherMsg=Msg, BelongsToTable=Table.Table, BelongsToItem=Record[0])\r | |
1267 | \r | |
1268 | \r | |
1269 | # Check Ppi Format in module INF\r | |
1270 | def MetaDataFileCheckModuleFilePpiFormat(self):\r | |
f8c1facf | 1271 | if EccGlobalData.gConfig.MetaDataFileCheckModuleFilePpiFormat == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r |
b3d07ff8 HC |
1272 | EdkLogger.quiet("Check Ppi Format in module INF ...")\r |
1273 | Table = EccGlobalData.gDb.TblInf\r | |
1274 | SqlCommand = """\r | |
1275 | select ID, Value1, Usage, BelongsToFile from %s where Model = %s group by ID\r | |
1276 | """ % (Table.Table, MODEL_EFI_PPI)\r | |
1277 | RecordSet = Table.Exec(SqlCommand)\r | |
1278 | for Record in RecordSet:\r | |
1279 | Value1 = Record[1]\r | |
1280 | Value2 = Record[2]\r | |
1281 | GuidCommentList = []\r | |
1282 | InfPath = self.GetInfFilePathFromID(Record[3])\r | |
1283 | Msg = "The Ppi format of %s in INF file [%s] does not follow rules" % (Value1, InfPath)\r | |
1284 | if Value2.startswith(DT.TAB_SPECIAL_COMMENT):\r | |
1285 | GuidCommentList = Value2[2:].split(DT.TAB_SPECIAL_COMMENT)\r | |
1286 | if len(GuidCommentList) >= 1:\r | |
1287 | if not GuidCommentList[0].strip().startswith((DT.TAB_INF_USAGE_PRO,\r | |
1288 | DT.TAB_INF_USAGE_SOME_PRO,\r | |
1289 | DT.TAB_INF_USAGE_CON,\r | |
1290 | DT.TAB_INF_USAGE_SOME_CON,\r | |
1291 | DT.TAB_INF_USAGE_NOTIFY,\r | |
1292 | DT.TAB_INF_USAGE_UNDEFINED)):\r | |
1293 | EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_FORMAT_PPI, OtherMsg=Msg, BelongsToTable=Table.Table, BelongsToItem=Record[0])\r | |
1294 | else:\r | |
1295 | EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_FORMAT_PPI, OtherMsg=Msg, BelongsToTable=Table.Table, BelongsToItem=Record[0])\r | |
1296 | \r | |
1297 | # Check Pcd Format in module INF\r | |
1298 | def MetaDataFileCheckModuleFilePcdFormat(self):\r | |
f8c1facf | 1299 | if EccGlobalData.gConfig.MetaDataFileCheckModuleFilePcdFormat == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r |
b3d07ff8 HC |
1300 | EdkLogger.quiet("Check Pcd Format in module INF ...")\r |
1301 | Table = EccGlobalData.gDb.TblInf\r | |
1302 | SqlCommand = """\r | |
1303 | select ID, Model, Value1, Value2, Usage, BelongsToFile from %s where Model >= %s and Model < %s group by ID\r | |
1304 | """ % (Table.Table, MODEL_PCD, MODEL_META_DATA_HEADER)\r | |
1305 | RecordSet = Table.Exec(SqlCommand)\r | |
1306 | for Record in RecordSet:\r | |
1307 | Model = Record[1]\r | |
1308 | PcdName = Record[2] + '.' + Record[3]\r | |
1309 | Usage = Record[4]\r | |
1310 | PcdCommentList = []\r | |
1311 | InfPath = self.GetInfFilePathFromID(Record[5])\r | |
1312 | Msg = "The Pcd format of %s in INF file [%s] does not follow rules" % (PcdName, InfPath)\r | |
1313 | if Usage.startswith(DT.TAB_SPECIAL_COMMENT):\r | |
1314 | PcdCommentList = Usage[2:].split(DT.TAB_SPECIAL_COMMENT)\r | |
1315 | if len(PcdCommentList) >= 1:\r | |
1316 | if Model in [MODEL_PCD_FIXED_AT_BUILD, MODEL_PCD_FEATURE_FLAG] \\r | |
1317 | and not PcdCommentList[0].strip().startswith((DT.TAB_INF_USAGE_SOME_PRO,\r | |
1318 | DT.TAB_INF_USAGE_CON,\r | |
1319 | DT.TAB_INF_USAGE_UNDEFINED)):\r | |
1320 | EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_FORMAT_PCD, OtherMsg=Msg, BelongsToTable=Table.Table, BelongsToItem=Record[0])\r | |
1321 | if Model in [MODEL_PCD_PATCHABLE_IN_MODULE, MODEL_PCD_DYNAMIC, MODEL_PCD_DYNAMIC_EX] \\r | |
1322 | and not PcdCommentList[0].strip().startswith((DT.TAB_INF_USAGE_PRO,\r | |
1323 | DT.TAB_INF_USAGE_SOME_PRO,\r | |
1324 | DT.TAB_INF_USAGE_CON,\r | |
1325 | DT.TAB_INF_USAGE_SOME_CON,\r | |
1326 | DT.TAB_INF_USAGE_UNDEFINED)):\r | |
1327 | EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_FORMAT_PCD, OtherMsg=Msg, BelongsToTable=Table.Table, BelongsToItem=Record[0])\r | |
1328 | else:\r | |
1329 | EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_FORMAT_PCD, OtherMsg=Msg, BelongsToTable=Table.Table, BelongsToItem=Record[0])\r | |
1330 | \r | |
30fdf114 LG |
1331 | # Check whether these is duplicate Guid/Ppi/Protocol name\r |
1332 | def CheckGuidProtocolPpi(self, ErrorID, Model, Table):\r | |
1333 | Name = ''\r | |
1334 | if Model == MODEL_EFI_GUID:\r | |
1335 | Name = 'guid'\r | |
1336 | if Model == MODEL_EFI_PROTOCOL:\r | |
1337 | Name = 'protocol'\r | |
1338 | if Model == MODEL_EFI_PPI:\r | |
1339 | Name = 'ppi'\r | |
1340 | SqlCommand = """\r | |
1341 | select A.ID, A.Value1 from %s as A, %s as B\r | |
1342 | where A.Model = %s and B.Model = %s\r | |
87d2afd0 | 1343 | and A.Value1 like B.Value1 and A.ID != B.ID\r |
d0acc87a | 1344 | and A.Scope1 = B.Scope1\r |
30fdf114 LG |
1345 | and A.Enabled > -1\r |
1346 | and B.Enabled > -1\r | |
1347 | group by A.ID\r | |
1348 | """ % (Table.Table, Table.Table, Model, Model)\r | |
1349 | RecordSet = Table.Exec(SqlCommand)\r | |
1350 | for Record in RecordSet:\r | |
1351 | if not EccGlobalData.gException.IsException(ErrorID, Record[1]):\r | |
d40b2ee6 | 1352 | EccGlobalData.gDb.TblReport.Insert(ErrorID, OtherMsg="The %s name [%s] is defined more than one time" % (Name.upper(), Record[1]), BelongsToTable=Table.Table, BelongsToItem=Record[0])\r |
30fdf114 LG |
1353 | \r |
1354 | # Check whether these is duplicate Guid/Ppi/Protocol value\r | |
1355 | def CheckGuidProtocolPpiValue(self, ErrorID, Model):\r | |
1356 | Name = ''\r | |
1357 | Table = EccGlobalData.gDb.TblDec\r | |
1358 | if Model == MODEL_EFI_GUID:\r | |
1359 | Name = 'guid'\r | |
1360 | if Model == MODEL_EFI_PROTOCOL:\r | |
1361 | Name = 'protocol'\r | |
1362 | if Model == MODEL_EFI_PPI:\r | |
1363 | Name = 'ppi'\r | |
1364 | SqlCommand = """\r | |
d0acc87a | 1365 | select A.ID, A.Value1, A.Value2 from %s as A, %s as B\r |
30fdf114 | 1366 | where A.Model = %s and B.Model = %s\r |
87d2afd0 GL |
1367 | and A.Value2 like B.Value2 and A.ID != B.ID\r |
1368 | and A.Scope1 = B.Scope1 and A.Value1 != B.Value1\r | |
30fdf114 LG |
1369 | group by A.ID\r |
1370 | """ % (Table.Table, Table.Table, Model, Model)\r | |
1371 | RecordSet = Table.Exec(SqlCommand)\r | |
f7496d71 | 1372 | for Record in RecordSet:\r |
e84d2b70 | 1373 | if not EccGlobalData.gException.IsException(ErrorID, Record[2]):\r |
d0acc87a | 1374 | EccGlobalData.gDb.TblReport.Insert(ErrorID, OtherMsg="The %s value [%s] is used more than one time" % (Name.upper(), Record[2]), BelongsToTable=Table.Table, BelongsToItem=Record[0])\r |
30fdf114 LG |
1375 | \r |
1376 | # Naming Convention Check\r | |
1377 | def NamingConventionCheck(self):\r | |
52302d4d LG |
1378 | if EccGlobalData.gConfig.NamingConventionCheckDefineStatement == '1' \\r |
1379 | or EccGlobalData.gConfig.NamingConventionCheckTypedefStatement == '1' \\r | |
1380 | or EccGlobalData.gConfig.NamingConventionCheckIfndefStatement == '1' \\r | |
1381 | or EccGlobalData.gConfig.NamingConventionCheckVariableName == '1' \\r | |
1382 | or EccGlobalData.gConfig.NamingConventionCheckSingleCharacterVariable == '1' \\r | |
1383 | or EccGlobalData.gConfig.NamingConventionCheckAll == '1'\\r | |
1384 | or EccGlobalData.gConfig.CheckAll == '1':\r | |
1385 | for Dirpath, Dirnames, Filenames in self.WalkTree():\r | |
1386 | for F in Filenames:\r | |
1387 | if os.path.splitext(F)[1] in ('.h', '.c'):\r | |
1388 | FullName = os.path.join(Dirpath, F)\r | |
1389 | Id = c.GetTableID(FullName)\r | |
1390 | if Id < 0:\r | |
1391 | continue\r | |
1392 | FileTable = 'Identifier' + str(Id)\r | |
1393 | self.NamingConventionCheckDefineStatement(FileTable)\r | |
1394 | self.NamingConventionCheckTypedefStatement(FileTable)\r | |
52302d4d LG |
1395 | self.NamingConventionCheckVariableName(FileTable)\r |
1396 | self.NamingConventionCheckSingleCharacterVariable(FileTable)\r | |
f8c1facf HC |
1397 | if os.path.splitext(F)[1] in ('.h'):\r |
1398 | self.NamingConventionCheckIfndefStatement(FileTable)\r | |
30fdf114 LG |
1399 | \r |
1400 | self.NamingConventionCheckPathName()\r | |
1401 | self.NamingConventionCheckFunctionName()\r | |
52302d4d | 1402 | \r |
30fdf114 LG |
1403 | # Check whether only capital letters are used for #define declarations\r |
1404 | def NamingConventionCheckDefineStatement(self, FileTable):\r | |
1405 | if EccGlobalData.gConfig.NamingConventionCheckDefineStatement == '1' or EccGlobalData.gConfig.NamingConventionCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
1406 | EdkLogger.quiet("Checking naming covention of #define statement ...")\r | |
52302d4d | 1407 | \r |
d40b2ee6 | 1408 | SqlCommand = """select ID, Value from %s where Model = %s""" % (FileTable, MODEL_IDENTIFIER_MACRO_DEFINE)\r |
30fdf114 LG |
1409 | RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r |
1410 | for Record in RecordSet:\r | |
1411 | Name = Record[1].strip().split()[1]\r | |
1412 | if Name.find('(') != -1:\r | |
1413 | Name = Name[0:Name.find('(')]\r | |
1414 | if Name.upper() != Name:\r | |
1415 | if not EccGlobalData.gException.IsException(ERROR_NAMING_CONVENTION_CHECK_DEFINE_STATEMENT, Name):\r | |
d40b2ee6 | 1416 | EccGlobalData.gDb.TblReport.Insert(ERROR_NAMING_CONVENTION_CHECK_DEFINE_STATEMENT, OtherMsg="The #define name [%s] does not follow the rules" % (Name), BelongsToTable=FileTable, BelongsToItem=Record[0])\r |
30fdf114 LG |
1417 | \r |
1418 | # Check whether only capital letters are used for typedef declarations\r | |
1419 | def NamingConventionCheckTypedefStatement(self, FileTable):\r | |
1420 | if EccGlobalData.gConfig.NamingConventionCheckTypedefStatement == '1' or EccGlobalData.gConfig.NamingConventionCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
1421 | EdkLogger.quiet("Checking naming covention of #typedef statement ...")\r | |
52302d4d | 1422 | \r |
d40b2ee6 | 1423 | SqlCommand = """select ID, Name from %s where Model = %s""" % (FileTable, MODEL_IDENTIFIER_TYPEDEF)\r |
30fdf114 LG |
1424 | RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r |
1425 | for Record in RecordSet:\r | |
1426 | Name = Record[1].strip()\r | |
4231a819 | 1427 | if Name != '' and Name is not None:\r |
30fdf114 LG |
1428 | if Name[0] == '(':\r |
1429 | Name = Name[1:Name.find(')')]\r | |
1430 | if Name.find('(') > -1:\r | |
1431 | Name = Name[Name.find('(') + 1 : Name.find(')')]\r | |
1432 | Name = Name.replace('WINAPI', '')\r | |
1433 | Name = Name.replace('*', '').strip()\r | |
1434 | if Name.upper() != Name:\r | |
1435 | if not EccGlobalData.gException.IsException(ERROR_NAMING_CONVENTION_CHECK_TYPEDEF_STATEMENT, Name):\r | |
d40b2ee6 | 1436 | EccGlobalData.gDb.TblReport.Insert(ERROR_NAMING_CONVENTION_CHECK_TYPEDEF_STATEMENT, OtherMsg="The #typedef name [%s] does not follow the rules" % (Name), BelongsToTable=FileTable, BelongsToItem=Record[0])\r |
30fdf114 LG |
1437 | \r |
1438 | # Check whether the #ifndef at the start of an include file uses both prefix and postfix underscore characters, '_'.\r | |
1439 | def NamingConventionCheckIfndefStatement(self, FileTable):\r | |
f8c1facf | 1440 | if EccGlobalData.gConfig.NamingConventionCheckIfndefStatement == '1' or EccGlobalData.gConfig.NamingConventionCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r |
30fdf114 | 1441 | EdkLogger.quiet("Checking naming covention of #ifndef statement ...")\r |
52302d4d | 1442 | \r |
d40b2ee6 | 1443 | SqlCommand = """select ID, Value from %s where Model = %s""" % (FileTable, MODEL_IDENTIFIER_MACRO_IFNDEF)\r |
30fdf114 LG |
1444 | RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r |
1445 | for Record in RecordSet:\r | |
1446 | Name = Record[1].replace('#ifndef', '').strip()\r | |
7a57490c | 1447 | if Name[-1] != '_':\r |
30fdf114 | 1448 | if not EccGlobalData.gException.IsException(ERROR_NAMING_CONVENTION_CHECK_IFNDEF_STATEMENT, Name):\r |
d40b2ee6 | 1449 | EccGlobalData.gDb.TblReport.Insert(ERROR_NAMING_CONVENTION_CHECK_IFNDEF_STATEMENT, OtherMsg="The #ifndef name [%s] does not follow the rules" % (Name), BelongsToTable=FileTable, BelongsToItem=Record[0])\r |
30fdf114 LG |
1450 | \r |
1451 | # Rule for path name, variable name and function name\r | |
1452 | # 1. First character should be upper case\r | |
1453 | # 2. Existing lower case in a word\r | |
1454 | # 3. No space existence\r | |
1455 | # Check whether the path name followed the rule\r | |
1456 | def NamingConventionCheckPathName(self):\r | |
1457 | if EccGlobalData.gConfig.NamingConventionCheckPathName == '1' or EccGlobalData.gConfig.NamingConventionCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
1458 | EdkLogger.quiet("Checking naming covention of file path name ...")\r | |
1459 | Pattern = re.compile(r'^[A-Z]+\S*[a-z]\S*$')\r | |
1460 | SqlCommand = """select ID, Name from File"""\r | |
1461 | RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r | |
1462 | for Record in RecordSet:\r | |
1463 | if not Pattern.match(Record[1]):\r | |
1464 | if not EccGlobalData.gException.IsException(ERROR_NAMING_CONVENTION_CHECK_PATH_NAME, Record[1]):\r | |
d40b2ee6 | 1465 | EccGlobalData.gDb.TblReport.Insert(ERROR_NAMING_CONVENTION_CHECK_PATH_NAME, OtherMsg="The file path [%s] does not follow the rules" % (Record[1]), BelongsToTable='File', BelongsToItem=Record[0])\r |
30fdf114 LG |
1466 | \r |
1467 | # Rule for path name, variable name and function name\r | |
1468 | # 1. First character should be upper case\r | |
1469 | # 2. Existing lower case in a word\r | |
1470 | # 3. No space existence\r | |
1471 | # 4. Global variable name must start with a 'g'\r | |
1472 | # Check whether the variable name followed the rule\r | |
1473 | def NamingConventionCheckVariableName(self, FileTable):\r | |
1474 | if EccGlobalData.gConfig.NamingConventionCheckVariableName == '1' or EccGlobalData.gConfig.NamingConventionCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
1475 | EdkLogger.quiet("Checking naming covention of variable name ...")\r | |
1476 | Pattern = re.compile(r'^[A-Zgm]+\S*[a-z]\S*$')\r | |
52302d4d | 1477 | \r |
d40b2ee6 | 1478 | SqlCommand = """select ID, Name from %s where Model = %s""" % (FileTable, MODEL_IDENTIFIER_VARIABLE)\r |
30fdf114 LG |
1479 | RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r |
1480 | for Record in RecordSet:\r | |
00261e1d HC |
1481 | Var = Record[1]\r |
1482 | if Var.startswith('CONST'):\r | |
1483 | Var = Var[5:].lstrip()\r | |
1484 | if not Pattern.match(Var):\r | |
30fdf114 | 1485 | if not EccGlobalData.gException.IsException(ERROR_NAMING_CONVENTION_CHECK_VARIABLE_NAME, Record[1]):\r |
d40b2ee6 | 1486 | EccGlobalData.gDb.TblReport.Insert(ERROR_NAMING_CONVENTION_CHECK_VARIABLE_NAME, OtherMsg="The variable name [%s] does not follow the rules" % (Record[1]), BelongsToTable=FileTable, BelongsToItem=Record[0])\r |
30fdf114 LG |
1487 | \r |
1488 | # Rule for path name, variable name and function name\r | |
1489 | # 1. First character should be upper case\r | |
1490 | # 2. Existing lower case in a word\r | |
1491 | # 3. No space existence\r | |
1492 | # Check whether the function name followed the rule\r | |
1493 | def NamingConventionCheckFunctionName(self):\r | |
1494 | if EccGlobalData.gConfig.NamingConventionCheckFunctionName == '1' or EccGlobalData.gConfig.NamingConventionCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
1495 | EdkLogger.quiet("Checking naming covention of function name ...")\r | |
1496 | Pattern = re.compile(r'^[A-Z]+\S*[a-z]\S*$')\r | |
1497 | SqlCommand = """select ID, Name from Function"""\r | |
1498 | RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r | |
1499 | for Record in RecordSet:\r | |
1500 | if not Pattern.match(Record[1]):\r | |
1501 | if not EccGlobalData.gException.IsException(ERROR_NAMING_CONVENTION_CHECK_FUNCTION_NAME, Record[1]):\r | |
d40b2ee6 | 1502 | EccGlobalData.gDb.TblReport.Insert(ERROR_NAMING_CONVENTION_CHECK_FUNCTION_NAME, OtherMsg="The function name [%s] does not follow the rules" % (Record[1]), BelongsToTable='Function', BelongsToItem=Record[0])\r |
30fdf114 LG |
1503 | \r |
1504 | # Check whether NO use short variable name with single character\r | |
1505 | def NamingConventionCheckSingleCharacterVariable(self, FileTable):\r | |
1506 | if EccGlobalData.gConfig.NamingConventionCheckSingleCharacterVariable == '1' or EccGlobalData.gConfig.NamingConventionCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r | |
1507 | EdkLogger.quiet("Checking naming covention of single character variable name ...")\r | |
52302d4d | 1508 | \r |
d40b2ee6 | 1509 | SqlCommand = """select ID, Name from %s where Model = %s""" % (FileTable, MODEL_IDENTIFIER_VARIABLE)\r |
30fdf114 LG |
1510 | RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r |
1511 | for Record in RecordSet:\r | |
1512 | Variable = Record[1].replace('*', '')\r | |
1513 | if len(Variable) == 1:\r | |
1514 | if not EccGlobalData.gException.IsException(ERROR_NAMING_CONVENTION_CHECK_SINGLE_CHARACTER_VARIABLE, Record[1]):\r | |
d40b2ee6 | 1515 | EccGlobalData.gDb.TblReport.Insert(ERROR_NAMING_CONVENTION_CHECK_SINGLE_CHARACTER_VARIABLE, OtherMsg="The variable name [%s] does not follow the rules" % (Record[1]), BelongsToTable=FileTable, BelongsToItem=Record[0])\r |
30fdf114 | 1516 | \r |
703ef6cf HC |
1517 | def FindPara(FilePath, Para, CallingLine):\r |
1518 | Lines = open(FilePath).readlines()\r | |
1519 | Line = ''\r | |
1520 | for Index in range(CallingLine - 1, 0, -1):\r | |
1521 | # Find the nearest statement for Para\r | |
1522 | Line = Lines[Index].strip()\r | |
1523 | if Line.startswith('%s = ' % Para):\r | |
1524 | Line = Line.strip()\r | |
1525 | return Line\r | |
1526 | break\r | |
1527 | \r | |
1528 | return ''\r | |
1529 | \r | |
30fdf114 LG |
1530 | ##\r |
1531 | #\r | |
1532 | # This acts like the main() function for the script, unless it is 'import'ed into another\r | |
1533 | # script.\r | |
1534 | #\r | |
1535 | if __name__ == '__main__':\r | |
1536 | Check = Check()\r | |
1537 | Check.Check()\r |