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