]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/Eot/Eot.py
BaseTools: use built in OrderedDict instead of custom version.
[mirror_edk2.git] / BaseTools / Source / Python / Eot / Eot.py
1 ## @file
2 # This file is used to be the main entrance of EOT tool
3 #
4 # Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.<BR>
5 # This program and the accompanying materials
6 # are licensed and made available under the terms and conditions of the BSD License
7 # which accompanies this distribution. The full text of the license may be found at
8 # http://opensource.org/licenses/bsd-license.php
9 #
10 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 #
13
14 ##
15 # Import Modules
16 #
17 import Common.LongFilePathOs as os, time, glob
18 import Common.EdkLogger as EdkLogger
19 import EotGlobalData
20 from optparse import OptionParser
21 from Common.String import NormPath
22 from Common import BuildToolError
23 from Common.Misc import GuidStructureStringToGuidString
24 from InfParserLite import *
25 import c
26 import Database
27 from FvImage import *
28 from array import array
29 from Report import Report
30 from Common.Misc import ParseConsoleLog
31 from Common.BuildVersion import gBUILD_VERSION
32 from Parser import ConvertGuid
33 from Common.LongFilePathSupport import OpenLongFilePath as open
34
35 ## Class Eot
36 #
37 # This class is used to define Eot main entrance
38 #
39 # @param object: Inherited from object class
40 #
41 class Eot(object):
42 ## The constructor
43 #
44 # @param self: The object pointer
45 #
46 def __init__(self, CommandLineOption=True, IsInit=True, SourceFileList=None, \
47 IncludeDirList=None, DecFileList=None, GuidList=None, LogFile=None,
48 FvFileList="", MapFileList="", Report='Report.html', Dispatch=None):
49 # Version and Copyright
50 self.VersionNumber = ("0.02" + " " + gBUILD_VERSION)
51 self.Version = "%prog Version " + self.VersionNumber
52 self.Copyright = "Copyright (c) 2008 - 2010, Intel Corporation All rights reserved."
53 self.Report = Report
54
55 self.IsInit = IsInit
56 self.SourceFileList = SourceFileList
57 self.IncludeDirList = IncludeDirList
58 self.DecFileList = DecFileList
59 self.GuidList = GuidList
60 self.LogFile = LogFile
61 self.FvFileList = FvFileList
62 self.MapFileList = MapFileList
63 self.Dispatch = Dispatch
64
65 # Check workspace environment
66 if "EFI_SOURCE" not in os.environ:
67 if "EDK_SOURCE" not in os.environ:
68 pass
69 else:
70 EotGlobalData.gEDK_SOURCE = os.path.normpath(os.getenv("EDK_SOURCE"))
71 else:
72 EotGlobalData.gEFI_SOURCE = os.path.normpath(os.getenv("EFI_SOURCE"))
73 EotGlobalData.gEDK_SOURCE = os.path.join(EotGlobalData.gEFI_SOURCE, 'Edk')
74
75 if "WORKSPACE" not in os.environ:
76 EdkLogger.error("EOT", BuildToolError.ATTRIBUTE_NOT_AVAILABLE, "Environment variable not found",
77 ExtraData="WORKSPACE")
78 else:
79 EotGlobalData.gWORKSPACE = os.path.normpath(os.getenv("WORKSPACE"))
80
81 EotGlobalData.gMACRO['WORKSPACE'] = EotGlobalData.gWORKSPACE
82 EotGlobalData.gMACRO['EFI_SOURCE'] = EotGlobalData.gEFI_SOURCE
83 EotGlobalData.gMACRO['EDK_SOURCE'] = EotGlobalData.gEDK_SOURCE
84
85 # Parse the options and args
86 if CommandLineOption:
87 self.ParseOption()
88
89 if self.FvFileList:
90 for FvFile in GetSplitValueList(self.FvFileList, ' '):
91 FvFile = os.path.normpath(FvFile)
92 if not os.path.isfile(FvFile):
93 EdkLogger.error("Eot", EdkLogger.EOT_ERROR, "Can not find file %s " % FvFile)
94 EotGlobalData.gFV_FILE.append(FvFile)
95 else:
96 EdkLogger.error("Eot", EdkLogger.EOT_ERROR, "The fv file list of target platform was not specified")
97
98 if self.MapFileList:
99 for MapFile in GetSplitValueList(self.MapFileList, ' '):
100 MapFile = os.path.normpath(MapFile)
101 if not os.path.isfile(MapFile):
102 EdkLogger.error("Eot", EdkLogger.EOT_ERROR, "Can not find file %s " % MapFile)
103 EotGlobalData.gMAP_FILE.append(MapFile)
104
105 # Generate source file list
106 self.GenerateSourceFileList(self.SourceFileList, self.IncludeDirList)
107
108 # Generate guid list of dec file list
109 self.ParseDecFile(self.DecFileList)
110
111 # Generate guid list from GUID list file
112 self.ParseGuidList(self.GuidList)
113
114 # Init Eot database
115 EotGlobalData.gDb = Database.Database(Database.DATABASE_PATH)
116 EotGlobalData.gDb.InitDatabase(self.IsInit)
117
118 # Build ECC database
119 self.BuildDatabase()
120
121 # Parse Ppi/Protocol
122 self.ParseExecutionOrder()
123
124 # Merge Identifier tables
125 self.GenerateQueryTable()
126
127 # Generate report database
128 self.GenerateReportDatabase()
129
130 # Load Fv Info
131 self.LoadFvInfo()
132
133 # Load Map Info
134 self.LoadMapInfo()
135
136 # Generate Report
137 self.GenerateReport()
138
139 # Convert log file
140 self.ConvertLogFile(self.LogFile)
141
142 # DONE
143 EdkLogger.quiet("EOT FINISHED!")
144
145 # Close Database
146 EotGlobalData.gDb.Close()
147
148 ## ParseDecFile() method
149 #
150 # parse DEC file and get all GUID names with GUID values as {GuidName : GuidValue}
151 # The Dict is stored in EotGlobalData.gGuidDict
152 #
153 # @param self: The object pointer
154 # @param DecFileList: A list of all DEC files
155 #
156 def ParseDecFile(self, DecFileList):
157 if DecFileList:
158 path = os.path.normpath(DecFileList)
159 lfr = open(path, 'rb')
160 for line in lfr:
161 path = os.path.normpath(os.path.join(EotGlobalData.gWORKSPACE, line.strip()))
162 if os.path.exists(path):
163 dfr = open(path, 'rb')
164 for line in dfr:
165 line = CleanString(line)
166 list = line.split('=')
167 if len(list) == 2:
168 EotGlobalData.gGuidDict[list[0].strip()] = GuidStructureStringToGuidString(list[1].strip())
169
170
171 ## ParseGuidList() method
172 #
173 # Parse Guid list and get all GUID names with GUID values as {GuidName : GuidValue}
174 # The Dict is stored in EotGlobalData.gGuidDict
175 #
176 # @param self: The object pointer
177 # @param GuidList: A list of all GUID and its value
178 #
179 def ParseGuidList(self, GuidList):
180 Path = os.path.join(EotGlobalData.gWORKSPACE, GuidList)
181 if os.path.isfile(Path):
182 for Line in open(Path):
183 (GuidName, GuidValue) = Line.split()
184 EotGlobalData.gGuidDict[GuidName] = GuidValue
185
186 ## ConvertLogFile() method
187 #
188 # Parse a real running log file to get real dispatch order
189 # The result is saved to old file name + '.new'
190 #
191 # @param self: The object pointer
192 # @param LogFile: A real running log file name
193 #
194 def ConvertLogFile(self, LogFile):
195 newline = []
196 lfr = None
197 lfw = None
198 if LogFile:
199 lfr = open(LogFile, 'rb')
200 lfw = open(LogFile + '.new', 'wb')
201 for line in lfr:
202 line = line.strip()
203 line = line.replace('.efi', '')
204 index = line.find("Loading PEIM at ")
205 if index > -1:
206 newline.append(line[index + 55 : ])
207 continue
208 index = line.find("Loading driver at ")
209 if index > -1:
210 newline.append(line[index + 57 : ])
211 continue
212
213 for line in newline:
214 lfw.write(line + '\r\n')
215
216 if lfr:
217 lfr.close()
218 if lfw:
219 lfw.close()
220
221 ## GenerateSourceFileList() method
222 #
223 # Generate a list of all source files
224 # 1. Search the file list one by one
225 # 2. Store inf file name with source file names under it like
226 # { INF file name: [source file1, source file2, ...]}
227 # 3. Search the include list to find all .h files
228 # 4. Store source file list to EotGlobalData.gSOURCE_FILES
229 # 5. Store INF file list to EotGlobalData.gINF_FILES
230 #
231 # @param self: The object pointer
232 # @param SourceFileList: A list of all source files
233 # @param IncludeFileList: A list of all include files
234 #
235 def GenerateSourceFileList(self, SourceFileList, IncludeFileList):
236 EdkLogger.quiet("Generating source files list ... ")
237 mSourceFileList = []
238 mInfFileList = []
239 mDecFileList = []
240 mFileList = {}
241 mCurrentInfFile = ''
242 mCurrentSourceFileList = []
243
244 if SourceFileList:
245 sfl = open(SourceFileList, 'rb')
246 for line in sfl:
247 line = os.path.normpath(os.path.join(EotGlobalData.gWORKSPACE, line.strip()))
248 if line[-2:].upper() == '.C' or line[-2:].upper() == '.H':
249 if line not in mCurrentSourceFileList:
250 mCurrentSourceFileList.append(line)
251 mSourceFileList.append(line)
252 EotGlobalData.gOP_SOURCE_FILES.write('%s\n' % line)
253 if line[-4:].upper() == '.INF':
254 if mCurrentInfFile != '':
255 mFileList[mCurrentInfFile] = mCurrentSourceFileList
256 mCurrentSourceFileList = []
257 mCurrentInfFile = os.path.normpath(os.path.join(EotGlobalData.gWORKSPACE, line))
258 EotGlobalData.gOP_INF.write('%s\n' % mCurrentInfFile)
259 if mCurrentInfFile not in mFileList:
260 mFileList[mCurrentInfFile] = mCurrentSourceFileList
261
262 # Get all include files from packages
263 if IncludeFileList:
264 ifl = open(IncludeFileList, 'rb')
265 for line in ifl:
266 if not line.strip():
267 continue
268 newline = os.path.normpath(os.path.join(EotGlobalData.gWORKSPACE, line.strip()))
269 for Root, Dirs, Files in os.walk(str(newline)):
270 for File in Files:
271 FullPath = os.path.normpath(os.path.join(Root, File))
272 if FullPath not in mSourceFileList and File[-2:].upper() == '.H':
273 mSourceFileList.append(FullPath)
274 EotGlobalData.gOP_SOURCE_FILES.write('%s\n' % FullPath)
275 if FullPath not in mDecFileList and File.upper().find('.DEC') > -1:
276 mDecFileList.append(FullPath)
277
278 EotGlobalData.gSOURCE_FILES = mSourceFileList
279 EotGlobalData.gOP_SOURCE_FILES.close()
280
281 EotGlobalData.gINF_FILES = mFileList
282 EotGlobalData.gOP_INF.close()
283
284 EotGlobalData.gDEC_FILES = mDecFileList
285
286
287 ## GenerateReport() method
288 #
289 # Generate final HTML report
290 #
291 # @param self: The object pointer
292 #
293 def GenerateReport(self):
294 EdkLogger.quiet("Generating report file ... ")
295 Rep = Report(self.Report, EotGlobalData.gFV, self.Dispatch)
296 Rep.GenerateReport()
297
298 ## LoadMapInfo() method
299 #
300 # Load map files and parse them
301 #
302 # @param self: The object pointer
303 #
304 def LoadMapInfo(self):
305 if EotGlobalData.gMAP_FILE != []:
306 EdkLogger.quiet("Parsing Map file ... ")
307 EotGlobalData.gMap = ParseMapFile(EotGlobalData.gMAP_FILE)
308
309 ## LoadFvInfo() method
310 #
311 # Load FV binary files and parse them
312 #
313 # @param self: The object pointer
314 #
315 def LoadFvInfo(self):
316 EdkLogger.quiet("Parsing FV file ... ")
317 EotGlobalData.gFV = MultipleFv(EotGlobalData.gFV_FILE)
318 EotGlobalData.gFV.Dispatch(EotGlobalData.gDb)
319
320 for Protocol in EotGlobalData.gProtocolList:
321 EotGlobalData.gOP_UN_MATCHED_IN_LIBRARY_CALLING.write('%s\n' %Protocol)
322
323 ## GenerateReportDatabase() method
324 #
325 # Generate data for the information needed by report
326 # 1. Update name, macro and value of all found PPI/PROTOCOL GUID
327 # 2. Install hard coded PPI/PROTOCOL
328 #
329 # @param self: The object pointer
330 #
331 def GenerateReportDatabase(self):
332 EdkLogger.quiet("Generating the cross-reference table of GUID for Ppi/Protocol ... ")
333
334 # Update Protocol/Ppi Guid
335 SqlCommand = """select DISTINCT GuidName from Report"""
336 RecordSet = EotGlobalData.gDb.TblReport.Exec(SqlCommand)
337 for Record in RecordSet:
338 GuidName = Record[0]
339 GuidMacro = ''
340 GuidMacro2 = ''
341 GuidValue = ''
342
343 # Find guid value defined in Dec file
344 if GuidName in EotGlobalData.gGuidDict:
345 GuidValue = EotGlobalData.gGuidDict[GuidName]
346 SqlCommand = """update Report set GuidMacro = '%s', GuidValue = '%s' where GuidName = '%s'""" %(GuidMacro, GuidValue, GuidName)
347 EotGlobalData.gDb.TblReport.Exec(SqlCommand)
348 continue
349
350 # Search defined Macros for guid name
351 SqlCommand ="""select DISTINCT Value, Modifier from Query where Name like '%s'""" % GuidName
352 GuidMacroSet = EotGlobalData.gDb.TblReport.Exec(SqlCommand)
353 # Ignore NULL result
354 if not GuidMacroSet:
355 continue
356 GuidMacro = GuidMacroSet[0][0].strip()
357 if not GuidMacro:
358 continue
359 # Find Guid value of Guid Macro
360 SqlCommand ="""select DISTINCT Value from Query2 where Value like '%%%s%%' and Model = %s""" % (GuidMacro, MODEL_IDENTIFIER_MACRO_DEFINE)
361 GuidValueSet = EotGlobalData.gDb.TblReport.Exec(SqlCommand)
362 if GuidValueSet != []:
363 GuidValue = GuidValueSet[0][0]
364 GuidValue = GuidValue[GuidValue.find(GuidMacro) + len(GuidMacro) :]
365 GuidValue = GuidValue.lower().replace('\\', '').replace('\r', '').replace('\n', '').replace('l', '').strip()
366 GuidValue = GuidStructureStringToGuidString(GuidValue)
367 SqlCommand = """update Report set GuidMacro = '%s', GuidValue = '%s' where GuidName = '%s'""" %(GuidMacro, GuidValue, GuidName)
368 EotGlobalData.gDb.TblReport.Exec(SqlCommand)
369 continue
370
371 # Update Hard Coded Ppi/Protocol
372 SqlCommand = """select DISTINCT GuidValue, ItemType from Report where ModuleID = -2 and ItemMode = 'Produced'"""
373 RecordSet = EotGlobalData.gDb.TblReport.Exec(SqlCommand)
374 for Record in RecordSet:
375 if Record[1] == 'Ppi':
376 EotGlobalData.gPpiList[Record[0].lower()] = -2
377 if Record[1] == 'Protocol':
378 EotGlobalData.gProtocolList[Record[0].lower()] = -2
379
380 ## GenerateQueryTable() method
381 #
382 # Generate two tables improve query performance
383 #
384 # @param self: The object pointer
385 #
386 def GenerateQueryTable(self):
387 EdkLogger.quiet("Generating temp query table for analysis ... ")
388 for Identifier in EotGlobalData.gIdentifierTableList:
389 SqlCommand = """insert into Query (Name, Modifier, Value, Model)
390 select Name, Modifier, Value, Model from %s where (Model = %s or Model = %s)""" \
391 % (Identifier[0], MODEL_IDENTIFIER_VARIABLE, MODEL_IDENTIFIER_ASSIGNMENT_EXPRESSION)
392 EotGlobalData.gDb.TblReport.Exec(SqlCommand)
393 SqlCommand = """insert into Query2 (Name, Modifier, Value, Model)
394 select Name, Modifier, Value, Model from %s where Model = %s""" \
395 % (Identifier[0], MODEL_IDENTIFIER_MACRO_DEFINE)
396 EotGlobalData.gDb.TblReport.Exec(SqlCommand)
397
398 ## ParseExecutionOrder() method
399 #
400 # Get final execution order
401 # 1. Search all PPI
402 # 2. Search all PROTOCOL
403 #
404 # @param self: The object pointer
405 #
406 def ParseExecutionOrder(self):
407 EdkLogger.quiet("Searching Ppi/Protocol ... ")
408 for Identifier in EotGlobalData.gIdentifierTableList:
409 ModuleID, ModuleName, ModuleGuid, SourceFileID, SourceFileFullPath, ItemName, ItemType, ItemMode, GuidName, GuidMacro, GuidValue, BelongsToFunction, Enabled = \
410 -1, '', '', -1, '', '', '', '', '', '', '', '', 0
411
412 SourceFileID = Identifier[0].replace('Identifier', '')
413 SourceFileFullPath = Identifier[1]
414 Identifier = Identifier[0]
415
416 # Find Ppis
417 ItemMode = 'Produced'
418 SqlCommand = """select Value, Name, BelongsToFile, StartLine, EndLine from %s
419 where (Name like '%%%s%%' or Name like '%%%s%%' or Name like '%%%s%%') and Model = %s""" \
420 % (Identifier, '.InstallPpi', '->InstallPpi', 'PeiInstallPpi', MODEL_IDENTIFIER_FUNCTION_CALLING)
421 SearchPpi(SqlCommand, Identifier, SourceFileID, SourceFileFullPath, ItemMode)
422
423 ItemMode = 'Produced'
424 SqlCommand = """select Value, Name, BelongsToFile, StartLine, EndLine from %s
425 where (Name like '%%%s%%' or Name like '%%%s%%') and Model = %s""" \
426 % (Identifier, '.ReInstallPpi', '->ReInstallPpi', MODEL_IDENTIFIER_FUNCTION_CALLING)
427 SearchPpi(SqlCommand, Identifier, SourceFileID, SourceFileFullPath, ItemMode, 2)
428
429 SearchPpiCallFunction(Identifier, SourceFileID, SourceFileFullPath, ItemMode)
430
431 ItemMode = 'Consumed'
432 SqlCommand = """select Value, Name, BelongsToFile, StartLine, EndLine from %s
433 where (Name like '%%%s%%' or Name like '%%%s%%') and Model = %s""" \
434 % (Identifier, '.LocatePpi', '->LocatePpi', MODEL_IDENTIFIER_FUNCTION_CALLING)
435 SearchPpi(SqlCommand, Identifier, SourceFileID, SourceFileFullPath, ItemMode)
436
437 SearchFunctionCalling(Identifier, SourceFileID, SourceFileFullPath, 'Ppi', ItemMode)
438
439 ItemMode = 'Callback'
440 SqlCommand = """select Value, Name, BelongsToFile, StartLine, EndLine from %s
441 where (Name like '%%%s%%' or Name like '%%%s%%') and Model = %s""" \
442 % (Identifier, '.NotifyPpi', '->NotifyPpi', MODEL_IDENTIFIER_FUNCTION_CALLING)
443 SearchPpi(SqlCommand, Identifier, SourceFileID, SourceFileFullPath, ItemMode)
444
445 # Find Procotols
446 ItemMode = 'Produced'
447 SqlCommand = """select Value, Name, BelongsToFile, StartLine, EndLine from %s
448 where (Name like '%%%s%%' or Name like '%%%s%%' or Name like '%%%s%%' or Name like '%%%s%%') and Model = %s""" \
449 % (Identifier, '.InstallProtocolInterface', '.ReInstallProtocolInterface', '->InstallProtocolInterface', '->ReInstallProtocolInterface', MODEL_IDENTIFIER_FUNCTION_CALLING)
450 SearchProtocols(SqlCommand, Identifier, SourceFileID, SourceFileFullPath, ItemMode, 1)
451
452 SqlCommand = """select Value, Name, BelongsToFile, StartLine, EndLine from %s
453 where (Name like '%%%s%%' or Name like '%%%s%%') and Model = %s""" \
454 % (Identifier, '.InstallMultipleProtocolInterfaces', '->InstallMultipleProtocolInterfaces', MODEL_IDENTIFIER_FUNCTION_CALLING)
455 SearchProtocols(SqlCommand, Identifier, SourceFileID, SourceFileFullPath, ItemMode, 2)
456
457 SearchFunctionCalling(Identifier, SourceFileID, SourceFileFullPath, 'Protocol', ItemMode)
458
459 ItemMode = 'Consumed'
460 SqlCommand = """select Value, Name, BelongsToFile, StartLine, EndLine from %s
461 where (Name like '%%%s%%' or Name like '%%%s%%') and Model = %s""" \
462 % (Identifier, '.LocateProtocol', '->LocateProtocol', MODEL_IDENTIFIER_FUNCTION_CALLING)
463 SearchProtocols(SqlCommand, Identifier, SourceFileID, SourceFileFullPath, ItemMode, 0)
464
465 SqlCommand = """select Value, Name, BelongsToFile, StartLine, EndLine from %s
466 where (Name like '%%%s%%' or Name like '%%%s%%') and Model = %s""" \
467 % (Identifier, '.HandleProtocol', '->HandleProtocol', MODEL_IDENTIFIER_FUNCTION_CALLING)
468 SearchProtocols(SqlCommand, Identifier, SourceFileID, SourceFileFullPath, ItemMode, 1)
469
470 SearchFunctionCalling(Identifier, SourceFileID, SourceFileFullPath, 'Protocol', ItemMode)
471
472 ItemMode = 'Callback'
473 SqlCommand = """select Value, Name, BelongsToFile, StartLine, EndLine from %s
474 where (Name like '%%%s%%' or Name like '%%%s%%') and Model = %s""" \
475 % (Identifier, '.RegisterProtocolNotify', '->RegisterProtocolNotify', MODEL_IDENTIFIER_FUNCTION_CALLING)
476 SearchProtocols(SqlCommand, Identifier, SourceFileID, SourceFileFullPath, ItemMode, 0)
477
478 SearchFunctionCalling(Identifier, SourceFileID, SourceFileFullPath, 'Protocol', ItemMode)
479
480 # Hard Code
481 EotGlobalData.gDb.TblReport.Insert(-2, '', '', -1, '', '', 'Ppi', 'Produced', 'gEfiSecPlatformInformationPpiGuid', '', '', '', 0)
482 EotGlobalData.gDb.TblReport.Insert(-2, '', '', -1, '', '', 'Ppi', 'Produced', 'gEfiNtLoadAsDllPpiGuid', '', '', '', 0)
483 EotGlobalData.gDb.TblReport.Insert(-2, '', '', -1, '', '', 'Ppi', 'Produced', 'gNtPeiLoadFileGuid', '', '', '', 0)
484 EotGlobalData.gDb.TblReport.Insert(-2, '', '', -1, '', '', 'Ppi', 'Produced', 'gPeiNtAutoScanPpiGuid', '', '', '', 0)
485 EotGlobalData.gDb.TblReport.Insert(-2, '', '', -1, '', '', 'Ppi', 'Produced', 'gNtFwhPpiGuid', '', '', '', 0)
486 EotGlobalData.gDb.TblReport.Insert(-2, '', '', -1, '', '', 'Ppi', 'Produced', 'gPeiNtThunkPpiGuid', '', '', '', 0)
487 EotGlobalData.gDb.TblReport.Insert(-2, '', '', -1, '', '', 'Ppi', 'Produced', 'gPeiPlatformTypePpiGuid', '', '', '', 0)
488 EotGlobalData.gDb.TblReport.Insert(-2, '', '', -1, '', '', 'Ppi', 'Produced', 'gPeiFrequencySelectionCpuPpiGuid', '', '', '', 0)
489 EotGlobalData.gDb.TblReport.Insert(-2, '', '', -1, '', '', 'Ppi', 'Produced', 'gPeiCachePpiGuid', '', '', '', 0)
490
491 EotGlobalData.gDb.Conn.commit()
492
493
494 ## BuildDatabase() methoc
495 #
496 # Build the database for target
497 #
498 # @param self: The object pointer
499 #
500 def BuildDatabase(self):
501 # Clean report table
502 EotGlobalData.gDb.TblReport.Drop()
503 EotGlobalData.gDb.TblReport.Create()
504
505 # Build database
506 if self.IsInit:
507 self.BuildMetaDataFileDatabase(EotGlobalData.gINF_FILES)
508 EdkLogger.quiet("Building database for source code ...")
509 c.CreateCCodeDB(EotGlobalData.gSOURCE_FILES)
510 EdkLogger.quiet("Building database for source code done!")
511
512 EotGlobalData.gIdentifierTableList = GetTableList((MODEL_FILE_C, MODEL_FILE_H), 'Identifier', EotGlobalData.gDb)
513
514 ## BuildMetaDataFileDatabase() method
515 #
516 # Build the database for meta data files
517 #
518 # @param self: The object pointer
519 # @param Inf_Files: A list for all INF files
520 #
521 def BuildMetaDataFileDatabase(self, Inf_Files):
522 EdkLogger.quiet("Building database for meta data files ...")
523 for InfFile in Inf_Files:
524 EdkLogger.quiet("Parsing %s ..." % str(InfFile))
525 EdkInfParser(InfFile, EotGlobalData.gDb, Inf_Files[InfFile], '')
526
527 EotGlobalData.gDb.Conn.commit()
528 EdkLogger.quiet("Building database for meta data files done!")
529
530 ## ParseOption() method
531 #
532 # Parse command line options
533 #
534 # @param self: The object pointer
535 #
536 def ParseOption(self):
537 (Options, Target) = self.EotOptionParser()
538
539 # Set log level
540 self.SetLogLevel(Options)
541
542 if Options.FvFileList:
543 self.FvFileList = Options.FvFileList
544
545 if Options.MapFileList:
546 self.MapFileList = Options.FvMapFileList
547
548 if Options.SourceFileList:
549 self.SourceFileList = Options.SourceFileList
550
551 if Options.IncludeDirList:
552 self.IncludeDirList = Options.IncludeDirList
553
554 if Options.DecFileList:
555 self.DecFileList = Options.DecFileList
556
557 if Options.GuidList:
558 self.GuidList = Options.GuidList
559
560 if Options.LogFile:
561 self.LogFile = Options.LogFile
562
563 if Options.keepdatabase:
564 self.IsInit = False
565
566 ## SetLogLevel() method
567 #
568 # Set current log level of the tool based on args
569 #
570 # @param self: The object pointer
571 # @param Option: The option list including log level setting
572 #
573 def SetLogLevel(self, Option):
574 if Option.verbose is not None:
575 EdkLogger.SetLevel(EdkLogger.VERBOSE)
576 elif Option.quiet is not None:
577 EdkLogger.SetLevel(EdkLogger.QUIET)
578 elif Option.debug is not None:
579 EdkLogger.SetLevel(Option.debug + 1)
580 else:
581 EdkLogger.SetLevel(EdkLogger.INFO)
582
583 ## EotOptionParser() method
584 #
585 # Using standard Python module optparse to parse command line option of this tool.
586 #
587 # @param self: The object pointer
588 #
589 # @retval Opt A optparse.Values object containing the parsed options
590 # @retval Args Target of build command
591 #
592 def EotOptionParser(self):
593 Parser = OptionParser(description = self.Copyright, version = self.Version, prog = "Eot.exe", usage = "%prog [options]")
594 Parser.add_option("-m", "--makefile filename", action="store", type="string", dest='MakeFile',
595 help="Specify a makefile for the platform.")
596 Parser.add_option("-c", "--dsc filename", action="store", type="string", dest="DscFile",
597 help="Specify a dsc file for the platform.")
598 Parser.add_option("-f", "--fv filename", action="store", type="string", dest="FvFileList",
599 help="Specify fv file list, quoted by \"\".")
600 Parser.add_option("-a", "--map filename", action="store", type="string", dest="MapFileList",
601 help="Specify map file list, quoted by \"\".")
602 Parser.add_option("-s", "--source files", action="store", type="string", dest="SourceFileList",
603 help="Specify source file list by a file")
604 Parser.add_option("-i", "--include dirs", action="store", type="string", dest="IncludeDirList",
605 help="Specify include dir list by a file")
606 Parser.add_option("-e", "--dec files", action="store", type="string", dest="DecFileList",
607 help="Specify dec file list by a file")
608 Parser.add_option("-g", "--guid list", action="store", type="string", dest="GuidList",
609 help="Specify guid file list by a file")
610 Parser.add_option("-l", "--log filename", action="store", type="string", dest="LogFile",
611 help="Specify real execution log file")
612
613 Parser.add_option("-k", "--keepdatabase", action="store_true", type=None, help="The existing Eot database will not be cleaned except report information if this option is specified.")
614
615 Parser.add_option("-q", "--quiet", action="store_true", type=None, help="Disable all messages except FATAL ERRORS.")
616 Parser.add_option("-v", "--verbose", action="store_true", type=None, help="Turn on verbose output with informational messages printed, "\
617 "including library instances selected, final dependency expression, "\
618 "and warning messages, etc.")
619 Parser.add_option("-d", "--debug", action="store", type="int", help="Enable debug messages at specified level.")
620
621 (Opt, Args)=Parser.parse_args()
622
623 return (Opt, Args)
624
625 ##
626 #
627 # This acts like the main() function for the script, unless it is 'import'ed into another
628 # script.
629 #
630 if __name__ == '__main__':
631 # Initialize log system
632 EdkLogger.Initialize()
633 EdkLogger.IsRaiseError = False
634 EdkLogger.quiet(time.strftime("%H:%M:%S, %b.%d %Y ", time.localtime()) + "[00:00]" + "\n")
635
636 StartTime = time.clock()
637 Eot = Eot()
638 FinishTime = time.clock()
639
640 BuildDuration = time.strftime("%M:%S", time.gmtime(int(round(FinishTime - StartTime))))
641 EdkLogger.quiet("\n%s [%s]" % (time.strftime("%H:%M:%S, %b.%d %Y", time.localtime()), BuildDuration))