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