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