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