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