Check In tool source code based on Build tool project revision r1655.
[mirror_edk2.git] / BaseTools / Source / Python / Common / InfClassObject.py
CommitLineData
30fdf114
LG
1## @file\r
2# This file is used to define each component of INF file\r
3#\r
4# Copyright (c) 2007, Intel Corporation\r
5# All rights reserved. This program and the accompanying materials\r
6# are licensed and made available under the terms and conditions of the BSD License\r
7# which accompanies this distribution. The full text of the license may be found at\r
8# http://opensource.org/licenses/bsd-license.php\r
9#\r
10# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12#\r
13\r
14##\r
15# Import Modules\r
16#\r
17import os\r
18import re\r
19import EdkLogger\r
20from CommonDataClass.CommonClass import LibraryClassClass\r
21from CommonDataClass.ModuleClass import *\r
22from String import *\r
23from DataType import *\r
24from Identification import *\r
25from Dictionary import *\r
26from BuildToolError import *\r
27from Misc import sdict\r
28import GlobalData\r
29from Table.TableInf import TableInf\r
30import Database\r
31from Parsing import *\r
32\r
33#\r
34# Global variable\r
35#\r
36Section = {TAB_UNKNOWN.upper() : MODEL_UNKNOWN,\r
37 TAB_INF_DEFINES.upper() : MODEL_META_DATA_HEADER,\r
38 TAB_BUILD_OPTIONS.upper() : MODEL_META_DATA_BUILD_OPTION,\r
39 TAB_INCLUDES.upper() : MODEL_EFI_INCLUDE,\r
40 TAB_LIBRARIES.upper() : MODEL_EFI_LIBRARY_INSTANCE,\r
41 TAB_LIBRARY_CLASSES.upper() : MODEL_EFI_LIBRARY_CLASS,\r
42 TAB_PACKAGES.upper() : MODEL_META_DATA_PACKAGE,\r
43 TAB_NMAKE.upper() : MODEL_META_DATA_NMAKE,\r
44 TAB_INF_FIXED_PCD.upper() : MODEL_PCD_FIXED_AT_BUILD,\r
45 TAB_INF_PATCH_PCD.upper() : MODEL_PCD_PATCHABLE_IN_MODULE,\r
46 TAB_INF_FEATURE_PCD.upper() : MODEL_PCD_FEATURE_FLAG,\r
47 TAB_INF_PCD_EX.upper() : MODEL_PCD_DYNAMIC_EX,\r
48 TAB_INF_PCD.upper() : MODEL_PCD_DYNAMIC,\r
49 TAB_SOURCES.upper() : MODEL_EFI_SOURCE_FILE,\r
50 TAB_GUIDS.upper() : MODEL_EFI_GUID,\r
51 TAB_PROTOCOLS.upper() : MODEL_EFI_PROTOCOL,\r
52 TAB_PPIS.upper() : MODEL_EFI_PPI,\r
53 TAB_DEPEX.upper() : MODEL_EFI_DEPEX,\r
54 TAB_BINARIES.upper() : MODEL_EFI_BINARY_FILE,\r
55 TAB_USER_EXTENSIONS.upper() : MODEL_META_DATA_USER_EXTENSION\r
56 }\r
57\r
58gComponentType2ModuleType = {\r
59 "LIBRARY" : "BASE",\r
60 "SECURITY_CORE" : "SEC",\r
61 "PEI_CORE" : "PEI_CORE",\r
62 "COMBINED_PEIM_DRIVER" : "PEIM",\r
63 "PIC_PEIM" : "PEIM",\r
64 "RELOCATABLE_PEIM" : "PEIM",\r
65 "PE32_PEIM" : "PEIM",\r
66 "BS_DRIVER" : "DXE_DRIVER",\r
67 "RT_DRIVER" : "DXE_RUNTIME_DRIVER",\r
68 "SAL_RT_DRIVER" : "DXE_SAL_DRIVER",\r
69# "BS_DRIVER" : "DXE_SMM_DRIVER",\r
70# "BS_DRIVER" : "UEFI_DRIVER",\r
71 "APPLICATION" : "UEFI_APPLICATION",\r
72 "LOGO" : "BASE",\r
73}\r
74\r
75gNmakeFlagPattern = re.compile("(?:EBC_)?([A-Z]+)_(?:STD_|PROJ_|ARCH_)?FLAGS(?:_DLL|_ASL|_EXE)?", re.UNICODE)\r
76gNmakeFlagName2ToolCode = {\r
77 "C" : "CC",\r
78 "LIB" : "SLINK",\r
79 "LINK" : "DLINK",\r
80}\r
81\r
82class InfHeader(ModuleHeaderClass):\r
83 _Mapping_ = {\r
84 #\r
85 # Required Fields\r
86 #\r
87 TAB_INF_DEFINES_BASE_NAME : "Name",\r
88 TAB_INF_DEFINES_FILE_GUID : "Guid",\r
89 TAB_INF_DEFINES_MODULE_TYPE : "ModuleType",\r
90 TAB_INF_DEFINES_EFI_SPECIFICATION_VERSION : "EfiSpecificationVersion",\r
91 TAB_INF_DEFINES_EDK_RELEASE_VERSION : "EdkReleaseVersion",\r
92 #\r
93 # Optional Fields\r
94 #\r
95 TAB_INF_DEFINES_INF_VERSION : "InfVersion",\r
96 TAB_INF_DEFINES_BINARY_MODULE : "BinaryModule",\r
97 TAB_INF_DEFINES_COMPONENT_TYPE : "ComponentType",\r
98 TAB_INF_DEFINES_MAKEFILE_NAME : "MakefileName",\r
99 TAB_INF_DEFINES_BUILD_NUMBER : "BuildNumber",\r
100 TAB_INF_DEFINES_BUILD_TYPE : "BuildType",\r
101 TAB_INF_DEFINES_FFS_EXT : "FfsExt",\r
102 TAB_INF_DEFINES_FV_EXT : "FvExt",\r
103 TAB_INF_DEFINES_SOURCE_FV : "SourceFv",\r
104 TAB_INF_DEFINES_VERSION_NUMBER : "VersionNumber",\r
105 TAB_INF_DEFINES_VERSION_STRING : "VersionString",\r
106 TAB_INF_DEFINES_VERSION : "Version",\r
107 TAB_INF_DEFINES_PCD_IS_DRIVER : "PcdIsDriver",\r
108 TAB_INF_DEFINES_TIANO_R8_FLASHMAP_H : "TianoR8FlashMap_h",\r
109 TAB_INF_DEFINES_SHADOW : "Shadow",\r
110# TAB_INF_DEFINES_LIBRARY_CLASS : "LibraryClass",\r
111# TAB_INF_DEFINES_ENTRY_POINT : "ExternImages",\r
112# TAB_INF_DEFINES_UNLOAD_IMAGE : "ExternImages",\r
113# TAB_INF_DEFINES_CONSTRUCTOR : ,\r
114# TAB_INF_DEFINES_DESTRUCTOR : ,\r
115# TAB_INF_DEFINES_DEFINE : "Define",\r
116# TAB_INF_DEFINES_SPEC : "Specification",\r
117# TAB_INF_DEFINES_CUSTOM_MAKEFILE : "CustomMakefile",\r
118# TAB_INF_DEFINES_MACRO :\r
119 }\r
120\r
121 def __init__(self):\r
122 ModuleHeaderClass.__init__(self)\r
123 self.VersionNumber = ''\r
124 self.VersionString = ''\r
125 #print self.__dict__\r
126 def __setitem__(self, key, value):\r
127 self.__dict__[self._Mapping_[key]] = value\r
128 def __getitem__(self, key):\r
129 return self.__dict__[self._Mapping_[key]]\r
130 ## "in" test support\r
131 def __contains__(self, key):\r
132 return key in self._Mapping_\r
133\r
134## InfObject\r
135#\r
136# This class defined basic Inf object which is used by inheriting\r
137#\r
138# @param object: Inherited from object class\r
139#\r
140class InfObject(object):\r
141 def __init__(self):\r
142 object.__init__()\r
143\r
144## Inf\r
145#\r
146# This class defined the structure used in Inf object\r
147#\r
148# @param InfObject: Inherited from InfObject class\r
149# @param Ffilename: Input value for Ffilename of Inf file, default is None\r
150# @param IsMergeAllArches: Input value for IsMergeAllArches\r
151# True is to merge all arches\r
152# Fales is not to merge all arches\r
153# default is False\r
154# @param IsToModule: Input value for IsToModule\r
155# True is to transfer to ModuleObject automatically\r
156# False is not to transfer to ModuleObject automatically\r
157# default is False\r
158# @param WorkspaceDir: Input value for current workspace directory, default is None\r
159#\r
160# @var Identification: To store value for Identification, it is a structure as Identification\r
161# @var UserExtensions: To store value for UserExtensions\r
162# @var Module: To store value for Module, it is a structure as ModuleClass\r
163# @var WorkspaceDir: To store value for WorkspaceDir\r
164# @var KeyList: To store value for KeyList, a list for all Keys used in Inf\r
165#\r
166class Inf(InfObject):\r
167 def __init__(self, Filename = None, IsToDatabase = False, IsToModule = False, WorkspaceDir = None, Database = None, SupArchList = DataType.ARCH_LIST):\r
168 self.Identification = Identification()\r
169 self.Module = ModuleClass()\r
170 self.UserExtensions = ''\r
171 self.WorkspaceDir = WorkspaceDir\r
172 self.SupArchList = SupArchList\r
173 self.IsToDatabase = IsToDatabase\r
174\r
175 self.Cur = Database.Cur\r
176 self.TblFile = Database.TblFile\r
177 self.TblInf = Database.TblInf\r
178 self.FileID = -1\r
179 #self.TblInf = TableInf(Database.Cur)\r
180\r
181 self.KeyList = [\r
182 TAB_SOURCES, TAB_BUILD_OPTIONS, TAB_BINARIES, TAB_INCLUDES, TAB_GUIDS,\r
183 TAB_PROTOCOLS, TAB_PPIS, TAB_LIBRARY_CLASSES, TAB_PACKAGES, TAB_LIBRARIES,\r
184 TAB_INF_FIXED_PCD, TAB_INF_PATCH_PCD, TAB_INF_FEATURE_PCD, TAB_INF_PCD,\r
185 TAB_INF_PCD_EX, TAB_DEPEX, TAB_NMAKE, TAB_INF_DEFINES\r
186 ]\r
187 #\r
188 # Upper all KEYs to ignore case sensitive when parsing\r
189 #\r
190 self.KeyList = map(lambda c: c.upper(), self.KeyList)\r
191\r
192 #\r
193 # Init RecordSet\r
194 #\r
195 self.RecordSet = {}\r
196 for Key in self.KeyList:\r
197 self.RecordSet[Section[Key]] = []\r
198\r
199 #\r
200 # Load Inf file if filename is not None\r
201 #\r
202 if Filename != None:\r
203 self.LoadInfFile(Filename)\r
204\r
205 #\r
206 # Transfer to Module Object if IsToModule is True\r
207 #\r
208 if IsToModule:\r
209 self.InfToModule()\r
210\r
211 ## Transfer to Module Object\r
212 #\r
213 # Transfer all contents of an Inf file to a standard Module Object\r
214 #\r
215 def InfToModule(self):\r
216 #\r
217 # Init global information for the file\r
218 #\r
219 ContainerFile = self.Identification.FileFullPath\r
220\r
221 #\r
222 # Generate Package Header\r
223 #\r
224 self.GenModuleHeader(ContainerFile)\r
225\r
226 #\r
227 # Generate BuildOptions\r
228 #\r
229 self.GenBuildOptions(ContainerFile)\r
230\r
231 #\r
232 # Generate Includes\r
233 #\r
234 self.GenIncludes(ContainerFile)\r
235\r
236 #\r
237 # Generate Libraries\r
238 #\r
239 self.GenLibraries(ContainerFile)\r
240\r
241 #\r
242 # Generate LibraryClasses\r
243 #\r
244 self.GenLibraryClasses(ContainerFile)\r
245\r
246 #\r
247 # Generate Packages\r
248 #\r
249 self.GenPackages(ContainerFile)\r
250\r
251 #\r
252 # Generate Nmakes\r
253 #\r
254 self.GenNmakes(ContainerFile)\r
255\r
256 #\r
257 # Generate Pcds\r
258 #\r
259 self.GenPcds(ContainerFile)\r
260\r
261 #\r
262 # Generate Sources\r
263 #\r
264 self.GenSources(ContainerFile)\r
265\r
266 #\r
267 # Generate UserExtensions\r
268 #\r
269 self.GenUserExtensions(ContainerFile)\r
270\r
271 #\r
272 # Generate Guids\r
273 #\r
274 self.GenGuidProtocolPpis(DataType.TAB_GUIDS, ContainerFile)\r
275\r
276 #\r
277 # Generate Protocols\r
278 #\r
279 self.GenGuidProtocolPpis(DataType.TAB_PROTOCOLS, ContainerFile)\r
280\r
281 #\r
282 # Generate Ppis\r
283 #\r
284 self.GenGuidProtocolPpis(DataType.TAB_PPIS, ContainerFile)\r
285\r
286 #\r
287 # Generate Depexes\r
288 #\r
289 self.GenDepexes(ContainerFile)\r
290\r
291 #\r
292 # Generate Binaries\r
293 #\r
294 self.GenBinaries(ContainerFile)\r
295\r
296 ## Parse [Defines] section\r
297 #\r
298 # Parse [Defines] section into InfDefines object\r
299 #\r
300 # @param InfFile The path of the INF file\r
301 # @param Section The title of "Defines" section\r
302 # @param Lines The content of "Defines" section\r
303 #\r
304 def ParseDefines(self, InfFile, Section, Lines):\r
305 TokenList = Section.split(TAB_SPLIT)\r
306 if len(TokenList) == 3:\r
307 RaiseParserError(Section, "Defines", InfFile, "[xx.yy.%s] format (with platform) is not supported")\r
308 if len(TokenList) == 2:\r
309 Arch = TokenList[1].upper()\r
310 else:\r
311 Arch = TAB_ARCH_COMMON\r
312\r
313 if Arch not in self.Defines:\r
314 self.Defines[Arch] = InfDefines()\r
315 GetSingleValueOfKeyFromLines(Lines, self.Defines[Arch].DefinesDictionary,\r
316 TAB_COMMENT_SPLIT, TAB_EQUAL_SPLIT, False, None)\r
317\r
318 ## Load Inf file\r
319 #\r
320 # Load the file if it exists\r
321 #\r
322 # @param Filename: Input value for filename of Inf file\r
323 #\r
324 def LoadInfFile(self, Filename):\r
325 #\r
326 # Insert a record for file\r
327 #\r
328 Filename = NormPath(Filename)\r
329 self.Identification.FileFullPath = Filename\r
330 (self.Identification.FileRelativePath, self.Identification.FileName) = os.path.split(Filename)\r
331 self.FileID = self.TblFile.InsertFile(Filename, MODEL_FILE_INF)\r
332\r
333 #\r
334 # Init InfTable\r
335 #\r
336 #self.TblInf.Table = "Inf%s" % self.FileID\r
337 #self.TblInf.Create()\r
338\r
339 #\r
340 # Init common datas\r
341 #\r
342 IfDefList, SectionItemList, CurrentSection, ArchList, ThirdList, IncludeFiles = \\r
343 [], [], TAB_UNKNOWN, [], [], []\r
344 LineNo = 0\r
345\r
346 #\r
347 # Parse file content\r
348 #\r
349 IsFindBlockComment = False\r
350 ReservedLine = ''\r
351 for Line in open(Filename, 'r'):\r
352 LineNo = LineNo + 1\r
353 #\r
354 # Remove comment block\r
355 #\r
356 if Line.find(TAB_COMMENT_R8_START) > -1:\r
357 ReservedLine = GetSplitValueList(Line, TAB_COMMENT_R8_START, 1)[0]\r
358 IsFindBlockComment = True\r
359 if Line.find(TAB_COMMENT_R8_END) > -1:\r
360 Line = ReservedLine + GetSplitValueList(Line, TAB_COMMENT_R8_END, 1)[1]\r
361 ReservedLine = ''\r
362 IsFindBlockComment = False\r
363 if IsFindBlockComment:\r
364 continue\r
365\r
366 #\r
367 # Remove comments at tail and remove spaces again\r
368 #\r
369 Line = CleanString(Line)\r
370 if Line == '':\r
371 continue\r
372\r
373 #\r
374 # Find a new section tab\r
375 # First insert previous section items\r
376 # And then parse the content of the new section\r
377 #\r
378 if Line.startswith(TAB_SECTION_START) and Line.endswith(TAB_SECTION_END):\r
379 if Line[1:3] == "--":\r
380 continue\r
381 Model = Section[CurrentSection.upper()]\r
382 #\r
383 # Insert items data of previous section\r
384 #\r
385 InsertSectionItemsIntoDatabase(self.TblInf, self.FileID, Filename, Model, CurrentSection, SectionItemList, ArchList, ThirdList, IfDefList, self.RecordSet)\r
386 #\r
387 # Parse the new section\r
388 #\r
389 SectionItemList = []\r
390 ArchList = []\r
391 ThirdList = []\r
392\r
393 CurrentSection = ''\r
394 LineList = GetSplitValueList(Line[len(TAB_SECTION_START):len(Line) - len(TAB_SECTION_END)], TAB_COMMA_SPLIT)\r
395 for Item in LineList:\r
396 ItemList = GetSplitValueList(Item, TAB_SPLIT)\r
397 if CurrentSection == '':\r
398 CurrentSection = ItemList[0]\r
399 else:\r
400 if CurrentSection != ItemList[0]:\r
401 EdkLogger.error("Parser", PARSER_ERROR, "Different section names '%s' and '%s' are found in one section definition, this is not allowed." % (CurrentSection, ItemList[0]), File=Filename, Line=LineNo, RaiseError = EdkLogger.IsRaiseError)\r
402 if CurrentSection.upper() not in self.KeyList:\r
403 RaiseParserError(Line, CurrentSection, Filename, '', LineNo)\r
404 CurrentSection = TAB_UNKNOWN\r
405 continue\r
406 ItemList.append('')\r
407 ItemList.append('')\r
408 if len(ItemList) > 5:\r
409 RaiseParserError(Line, CurrentSection, Filename, '', LineNo)\r
410 else:\r
411 if ItemList[1] != '' and ItemList[1].upper() not in ARCH_LIST_FULL:\r
412 EdkLogger.error("Parser", PARSER_ERROR, "Invalid Arch definition '%s' found" % ItemList[1], File=Filename, Line=LineNo, RaiseError = EdkLogger.IsRaiseError)\r
413 ArchList.append(ItemList[1].upper())\r
414 ThirdList.append(ItemList[2])\r
415\r
416 continue\r
417\r
418 #\r
419 # Not in any defined section\r
420 #\r
421 if CurrentSection == TAB_UNKNOWN:\r
422 ErrorMsg = "%s is not in any defined section" % Line\r
423 EdkLogger.error("Parser", PARSER_ERROR, ErrorMsg, File=Filename, Line=LineNo, RaiseError = EdkLogger.IsRaiseError)\r
424\r
425 #\r
426 # Add a section item\r
427 #\r
428 SectionItemList.append([Line, LineNo])\r
429 # End of parse\r
430 #End of For\r
431\r
432 #\r
433 # Insert items data of last section\r
434 #\r
435 Model = Section[CurrentSection.upper()]\r
436 InsertSectionItemsIntoDatabase(self.TblInf, self.FileID, Filename, Model, CurrentSection, SectionItemList, ArchList, ThirdList, IfDefList, self.RecordSet)\r
437\r
438 #\r
439 # Replace all DEFINE macros with its actual values\r
440 #\r
441 ParseDefineMacro2(self.TblInf, self.RecordSet, GlobalData.gGlobalDefines)\r
442\r
443 ## Show detailed information of Module\r
444 #\r
445 # Print all members and their values of Module class\r
446 #\r
447 def ShowModule(self):\r
448 M = self.Module\r
449 for Arch in M.Header.keys():\r
450 print '\nArch =', Arch\r
451 print 'Filename =', M.Header[Arch].FileName\r
452 print 'FullPath =', M.Header[Arch].FullPath\r
453 print 'BaseName =', M.Header[Arch].Name\r
454 print 'Guid =', M.Header[Arch].Guid\r
455 print 'Version =', M.Header[Arch].Version\r
456 print 'InfVersion =', M.Header[Arch].InfVersion\r
457 print 'EfiSpecificationVersion =', M.Header[Arch].EfiSpecificationVersion\r
458 print 'EdkReleaseVersion =', M.Header[Arch].EdkReleaseVersion\r
459 print 'ModuleType =', M.Header[Arch].ModuleType\r
460 print 'BinaryModule =', M.Header[Arch].BinaryModule\r
461 print 'ComponentType =', M.Header[Arch].ComponentType\r
462 print 'MakefileName =', M.Header[Arch].MakefileName\r
463 print 'BuildNumber =', M.Header[Arch].BuildNumber\r
464 print 'BuildType =', M.Header[Arch].BuildType\r
465 print 'FfsExt =', M.Header[Arch].FfsExt\r
466 print 'FvExt =', M.Header[Arch].FvExt\r
467 print 'SourceFv =', M.Header[Arch].SourceFv\r
468 print 'PcdIsDriver =', M.Header[Arch].PcdIsDriver\r
469 print 'TianoR8FlashMap_h =', M.Header[Arch].TianoR8FlashMap_h\r
470 print 'Shadow =', M.Header[Arch].Shadow\r
471 print 'LibraryClass =', M.Header[Arch].LibraryClass\r
472 for Item in M.Header[Arch].LibraryClass:\r
473 print Item.LibraryClass, DataType.TAB_VALUE_SPLIT.join(Item.SupModuleList)\r
474 print 'CustomMakefile =', M.Header[Arch].CustomMakefile\r
475 print 'Define =', M.Header[Arch].Define\r
476 print 'Specification =', M.Header[Arch].Specification\r
477 for Item in self.Module.ExternImages:\r
478 print '\nEntry_Point = %s, UnloadImage = %s' % (Item.ModuleEntryPoint, Item.ModuleUnloadImage)\r
479 for Item in self.Module.ExternLibraries:\r
480 print 'Constructor = %s, Destructor = %s' % (Item.Constructor, Item.Destructor)\r
481 print '\nBuildOptions =', M.BuildOptions\r
482 for Item in M.BuildOptions:\r
483 print Item.ToolChainFamily, Item.ToolChain, Item.Option, Item.SupArchList\r
484 print '\nIncludes =', M.Includes\r
485 for Item in M.Includes:\r
486 print Item.FilePath, Item.SupArchList\r
487 print '\nLibraries =', M.Libraries\r
488 for Item in M.Libraries:\r
489 print Item.Library, Item.SupArchList\r
490 print '\nLibraryClasses =', M.LibraryClasses\r
491 for Item in M.LibraryClasses:\r
492 print Item.LibraryClass, Item.RecommendedInstance, Item.FeatureFlag, Item.SupModuleList, Item.SupArchList, Item.Define\r
493 print '\nPackageDependencies =', M.PackageDependencies\r
494 for Item in M.PackageDependencies:\r
495 print Item.FilePath, Item.SupArchList, Item.FeatureFlag\r
496 print '\nNmake =', M.Nmake\r
497 for Item in M.Nmake:\r
498 print Item.Name, Item.Value, Item.SupArchList\r
499 print '\nPcds =', M.PcdCodes\r
500 for Item in M.PcdCodes:\r
501 print '\tCName=',Item.CName, 'TokenSpaceGuidCName=', Item.TokenSpaceGuidCName, 'DefaultValue=', Item.DefaultValue, 'ItemType=', Item.ItemType, Item.SupArchList\r
502 print '\nSources =', M.Sources\r
503 for Source in M.Sources:\r
504 print Source.SourceFile, 'Fam=', Source.ToolChainFamily, 'Pcd=', Source.FeatureFlag, 'Tag=', Source.TagName, 'ToolCode=', Source.ToolCode, Source.SupArchList\r
505 print '\nUserExtensions =', M.UserExtensions\r
506 for UserExtension in M.UserExtensions:\r
507 print UserExtension.UserID, UserExtension.Identifier,UserExtension.Content\r
508 print '\nGuids =', M.Guids\r
509 for Item in M.Guids:\r
510 print Item.CName, Item.SupArchList, Item.FeatureFlag\r
511 print '\nProtocols =', M.Protocols\r
512 for Item in M.Protocols:\r
513 print Item.CName, Item.SupArchList, Item.FeatureFlag\r
514 print '\nPpis =', M.Ppis\r
515 for Item in M.Ppis:\r
516 print Item.CName, Item.SupArchList, Item.FeatureFlag\r
517 print '\nDepex =', M.Depex\r
518 for Item in M.Depex:\r
519 print Item.Depex, Item.SupArchList, Item.Define\r
520 print '\nBinaries =', M.Binaries\r
521 for Binary in M.Binaries:\r
522 print 'Type=', Binary.FileType, 'Target=', Binary.Target, 'Name=', Binary.BinaryFile, 'FeatureFlag=', Binary.FeatureFlag, 'SupArchList=', Binary.SupArchList\r
523\r
524 ## Convert [Defines] section content to ModuleHeaderClass\r
525 #\r
526 # Convert [Defines] section content to ModuleHeaderClass\r
527 #\r
528 # @param Defines The content under [Defines] section\r
529 # @param ModuleHeader An object of ModuleHeaderClass\r
530 # @param Arch The supported ARCH\r
531 #\r
532 def GenModuleHeader(self, ContainerFile):\r
533 EdkLogger.debug(2, "Generate ModuleHeader ...")\r
534 File = self.Identification.FileFullPath\r
535 #\r
536 # Update all defines item in database\r
537 #\r
538 RecordSet = self.RecordSet[MODEL_META_DATA_HEADER]\r
539 for Record in RecordSet:\r
540 ValueList = GetSplitValueList(Record[0], TAB_EQUAL_SPLIT)\r
541 if len(ValueList) != 2:\r
542 RaiseParserError(Record[0], 'Defines', ContainerFile, '<Key> = <Value>', Record[2])\r
543 ID, Value1, Value2, Arch, LineNo = Record[3], ValueList[0], ValueList[1], Record[1], Record[2]\r
544 SqlCommand = """update %s set Value1 = '%s', Value2 = '%s'\r
545 where ID = %s""" % (self.TblInf.Table, ConvertToSqlString2(Value1), ConvertToSqlString2(Value2), ID)\r
546 self.TblInf.Exec(SqlCommand)\r
547\r
548 for Arch in DataType.ARCH_LIST:\r
549 ModuleHeader = InfHeader()\r
550 ModuleHeader.FileName = self.Identification.FileName\r
551 ModuleHeader.FullPath = self.Identification.FileFullPath\r
552 DefineList = QueryDefinesItem2(self.TblInf, Arch, self.FileID)\r
553\r
554 NotProcessedDefineList = []\r
555 for D in DefineList:\r
556 if D[0] in ModuleHeader:\r
557 ModuleHeader[D[0]] = GetSplitValueList(D[1])[0]\r
558 else:\r
559 NotProcessedDefineList.append(D)\r
560\r
561 if ModuleHeader.ComponentType == "LIBRARY":\r
562 Lib = LibraryClassClass()\r
563 Lib.LibraryClass = ModuleHeader.Name\r
564 Lib.SupModuleList = DataType.SUP_MODULE_LIST\r
565 ModuleHeader.LibraryClass.append(Lib)\r
566\r
567 # we need to make some key defines resolved first\r
568 for D in NotProcessedDefineList:\r
569 if D[0] == TAB_INF_DEFINES_LIBRARY_CLASS:\r
570 List = GetSplitValueList(D[1], DataType.TAB_VALUE_SPLIT, 1)\r
571 Lib = LibraryClassClass()\r
572 Lib.LibraryClass = CleanString(List[0])\r
573 if len(List) == 1:\r
574 Lib.SupModuleList = DataType.SUP_MODULE_LIST\r
575 elif len(List) == 2:\r
576 Lib.SupModuleList = GetSplitValueList(CleanString(List[1]), ' ')\r
577 ModuleHeader.LibraryClass.append(Lib)\r
578 elif D[0] == TAB_INF_DEFINES_CUSTOM_MAKEFILE:\r
579 List = D[1].split(DataType.TAB_VALUE_SPLIT)\r
580 if len(List) == 2:\r
581 ModuleHeader.CustomMakefile[CleanString(List[0])] = CleanString(List[1])\r
582 else:\r
583 RaiseParserError(D[1], 'CUSTOM_MAKEFILE of Defines', File, 'CUSTOM_MAKEFILE=<Family>|<Filename>', D[2])\r
584 elif D[0] == TAB_INF_DEFINES_ENTRY_POINT:\r
585 Image = ModuleExternImageClass()\r
586 Image.ModuleEntryPoint = CleanString(D[1])\r
587 self.Module.ExternImages.append(Image)\r
588 elif D[0] == TAB_INF_DEFINES_UNLOAD_IMAGE:\r
589 Image = ModuleExternImageClass()\r
590 Image.ModuleUnloadImage = CleanString(D[1])\r
591 self.Module.ExternImages.append(Image)\r
592 elif D[0] == TAB_INF_DEFINES_CONSTRUCTOR:\r
593 LibraryClass = ModuleExternLibraryClass()\r
594 LibraryClass.Constructor = CleanString(D[1])\r
595 self.Module.ExternLibraries.append(LibraryClass)\r
596 elif D[0] == TAB_INF_DEFINES_DESTRUCTOR:\r
597 LibraryClass = ModuleExternLibraryClass()\r
598 LibraryClass.Destructor = CleanString(D[1])\r
599 self.Module.ExternLibraries.append(LibraryClass)\r
600 elif D[0] == TAB_INF_DEFINES_DEFINE:\r
601 List = D[1].split(DataType.TAB_EQUAL_SPLIT)\r
602 if len(List) != 2:\r
603 RaiseParserError(Item, 'DEFINE of Defines', File, 'DEFINE <Word> = <Word>', D[2])\r
604 else:\r
605 ModuleHeader.Define[CleanString(List[0])] = CleanString(List[1])\r
606 elif D[0] == TAB_INF_DEFINES_SPEC:\r
607 List = D[1].split(DataType.TAB_EQUAL_SPLIT)\r
608 if len(List) != 2:\r
609 RaiseParserError(Item, 'SPEC of Defines', File, 'SPEC <Word> = <Version>', D[2])\r
610 else:\r
611 ModuleHeader.Specification[CleanString(List[0])] = CleanString(List[1])\r
612\r
613 #\r
614 # Get version of INF\r
615 #\r
616 if ModuleHeader.InfVersion != "":\r
617 # R9 inf\r
618 VersionNumber = ModuleHeader.VersionNumber\r
619 VersionString = ModuleHeader.VersionString\r
620 if len(VersionNumber) > 0 and len(VersionString) == 0:\r
621 EdkLogger.warn(2000, 'VERSION_NUMBER depricated; INF file %s should be modified to use VERSION_STRING instead.' % self.Identification.FileFullPath)\r
622 ModuleHeader.Version = VersionNumber\r
623 if len(VersionString) > 0:\r
624 if len(VersionNumber) > 0:\r
625 EdkLogger.warn(2001, 'INF file %s defines both VERSION_NUMBER and VERSION_STRING, using VERSION_STRING' % self.Identification.FileFullPath)\r
626 ModuleHeader.Version = VersionString\r
627 else:\r
628 # R8 inf\r
629 ModuleHeader.InfVersion = "0x00010000"\r
630 if ModuleHeader.ComponentType in gComponentType2ModuleType:\r
631 ModuleHeader.ModuleType = gComponentType2ModuleType[ModuleHeader.ComponentType]\r
632 elif ModuleHeader.ComponentType != '':\r
633 EdkLogger.error("Parser", PARSER_ERROR, "Unsupported R8 component type [%s]" % ModuleHeader.ComponentType, ExtraData=File, RaiseError = EdkLogger.IsRaiseError)\r
634\r
635 self.Module.Header[Arch] = ModuleHeader\r
636\r
637\r
638 ## GenBuildOptions\r
639 #\r
640 # Gen BuildOptions of Inf\r
641 # [<Family>:]<ToolFlag>=Flag\r
642 #\r
643 # @param ContainerFile: The Inf file full path\r
644 #\r
645 def GenBuildOptions(self, ContainerFile):\r
646 EdkLogger.debug(2, "Generate %s ..." % TAB_BUILD_OPTIONS)\r
647 BuildOptions = {}\r
648 #\r
649 # Get all BuildOptions\r
650 #\r
651 RecordSet = self.RecordSet[MODEL_META_DATA_BUILD_OPTION]\r
652\r
653 #\r
654 # Go through each arch\r
655 #\r
656 for Arch in self.SupArchList:\r
657 for Record in RecordSet:\r
658 if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
659 (Family, ToolChain, Flag) = GetBuildOption(Record[0], ContainerFile, Record[2])\r
660 MergeArches(BuildOptions, (Family, ToolChain, Flag), Arch)\r
661 #\r
662 # Update to Database\r
663 #\r
664 if self.IsToDatabase:\r
665 SqlCommand = """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s'\r
666 where ID = %s""" % (self.TblInf.Table, ConvertToSqlString2(Family), ConvertToSqlString2(ToolChain), ConvertToSqlString2(Flag), Record[3])\r
667 self.TblInf.Exec(SqlCommand)\r
668\r
669 for Key in BuildOptions.keys():\r
670 BuildOption = BuildOptionClass(Key[0], Key[1], Key[2])\r
671 BuildOption.SupArchList = BuildOptions[Key]\r
672 self.Module.BuildOptions.append(BuildOption)\r
673\r
674 ## GenIncludes\r
675 #\r
676 # Gen Includes of Inf\r
677 #\r
678 #\r
679 # @param ContainerFile: The Inf file full path\r
680 #\r
681 def GenIncludes(self, ContainerFile):\r
682 EdkLogger.debug(2, "Generate %s ..." % TAB_INCLUDES)\r
683 Includes = sdict()\r
684 #\r
685 # Get all Includes\r
686 #\r
687 RecordSet = self.RecordSet[MODEL_EFI_INCLUDE]\r
688\r
689 #\r
690 # Go through each arch\r
691 #\r
692 for Arch in self.SupArchList:\r
693 for Record in RecordSet:\r
694 if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
695 MergeArches(Includes, Record[0], Arch)\r
696\r
697 for Key in Includes.keys():\r
698 Include = IncludeClass()\r
699 Include.FilePath = NormPath(Key)\r
700 Include.SupArchList = Includes[Key]\r
701 self.Module.Includes.append(Include)\r
702\r
703 ## GenLibraries\r
704 #\r
705 # Gen Libraries of Inf\r
706 #\r
707 #\r
708 # @param ContainerFile: The Inf file full path\r
709 #\r
710 def GenLibraries(self, ContainerFile):\r
711 EdkLogger.debug(2, "Generate %s ..." % TAB_LIBRARIES)\r
712 Libraries = sdict()\r
713 #\r
714 # Get all Includes\r
715 #\r
716 RecordSet = self.RecordSet[MODEL_EFI_LIBRARY_INSTANCE]\r
717\r
718 #\r
719 # Go through each arch\r
720 #\r
721 for Arch in self.SupArchList:\r
722 for Record in RecordSet:\r
723 if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
724 MergeArches(Libraries, Record[0], Arch)\r
725\r
726 for Key in Libraries.keys():\r
727 Library = ModuleLibraryClass()\r
728 # replace macro and remove file extension\r
729 Library.Library = Key.rsplit('.', 1)[0]\r
730 Library.SupArchList = Libraries[Key]\r
731 self.Module.Libraries.append(Library)\r
732\r
733 ## GenLibraryClasses\r
734 #\r
735 # Get LibraryClass of Inf\r
736 # <LibraryClassKeyWord>|<LibraryInstance>\r
737 #\r
738 # @param ContainerFile: The Inf file full path\r
739 #\r
740 def GenLibraryClasses(self, ContainerFile):\r
741 EdkLogger.debug(2, "Generate %s ..." % TAB_LIBRARY_CLASSES)\r
742 LibraryClasses = {}\r
743 #\r
744 # Get all LibraryClasses\r
745 #\r
746 RecordSet = self.RecordSet[MODEL_EFI_LIBRARY_CLASS]\r
747\r
748 #\r
749 # Go through each arch\r
750 #\r
751 for Arch in self.SupArchList:\r
752 for Record in RecordSet:\r
753 if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
754 (LibClassName, LibClassIns, Pcd, SupModelList) = GetLibraryClassOfInf([Record[0], Record[4]], ContainerFile, self.WorkspaceDir, Record[2])\r
755 MergeArches(LibraryClasses, (LibClassName, LibClassIns, Pcd, SupModelList), Arch)\r
756 #\r
757 # Update to Database\r
758 #\r
759 if self.IsToDatabase:\r
760 SqlCommand = """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s'\r
761 where ID = %s""" % (self.TblInf.Table, ConvertToSqlString2(LibClassName), ConvertToSqlString2(LibClassIns), ConvertToSqlString2(SupModelList), Record[3])\r
762 self.TblInf.Exec(SqlCommand)\r
763\r
764 for Key in LibraryClasses.keys():\r
765 KeyList = Key[0].split(DataType.TAB_VALUE_SPLIT)\r
766 LibraryClass = LibraryClassClass()\r
767 LibraryClass.LibraryClass = Key[0]\r
768 LibraryClass.RecommendedInstance = NormPath(Key[1])\r
769 LibraryClass.FeatureFlag = Key[2]\r
770 LibraryClass.SupArchList = LibraryClasses[Key]\r
771 LibraryClass.SupModuleList = GetSplitValueList(Key[3])\r
772 self.Module.LibraryClasses.append(LibraryClass)\r
773\r
774 ## GenPackages\r
775 #\r
776 # Gen Packages of Inf\r
777 #\r
778 #\r
779 # @param ContainerFile: The Inf file full path\r
780 #\r
781 def GenPackages(self, ContainerFile):\r
782 EdkLogger.debug(2, "Generate %s ..." % TAB_PACKAGES)\r
783 Packages = {}\r
784 #\r
785 # Get all Packages\r
786 #\r
787 RecordSet = self.RecordSet[MODEL_META_DATA_PACKAGE]\r
788\r
789 #\r
790 # Go through each arch\r
791 #\r
792 for Arch in self.SupArchList:\r
793 for Record in RecordSet:\r
794 if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
795 (Package, Pcd) = GetPackage(Record[0], ContainerFile, self.WorkspaceDir, Record[2])\r
796 MergeArches(Packages, (Package, Pcd), Arch)\r
797 if self.IsToDatabase:\r
798 SqlCommand = """update %s set Value1 = '%s', Value2 = '%s'\r
799 where ID = %s""" % (self.TblInf.Table, ConvertToSqlString2(Package), ConvertToSqlString2(Pcd), Record[3])\r
800 self.TblInf.Exec(SqlCommand)\r
801\r
802\r
803 for Key in Packages.keys():\r
804 Package = ModulePackageDependencyClass()\r
805 Package.FilePath = NormPath(Key[0])\r
806 Package.SupArchList = Packages[Key]\r
807 Package.FeatureFlag = Key[1]\r
808 self.Module.PackageDependencies.append(Package)\r
809\r
810 ## GenNmakes\r
811 #\r
812 # Gen Nmakes of Inf\r
813 #\r
814 #\r
815 # @param ContainerFile: The Inf file full path\r
816 #\r
817 def GenNmakes(self, ContainerFile):\r
818 EdkLogger.debug(2, "Generate %s ..." % TAB_NMAKE)\r
819 Nmakes = sdict()\r
820 #\r
821 # Get all Nmakes\r
822 #\r
823 RecordSet = self.RecordSet[MODEL_META_DATA_NMAKE]\r
824\r
825\r
826 #\r
827 # Go through each arch\r
828 #\r
829 for Arch in self.SupArchList:\r
830 for Record in RecordSet:\r
831 if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
832 MergeArches(Nmakes, Record[0], Arch)\r
833\r
834 for Key in Nmakes.keys():\r
835 List = GetSplitValueList(Key, DataType.TAB_EQUAL_SPLIT, MaxSplit=1)\r
836 if len(List) != 2:\r
837 RaiseParserError(Key, 'Nmake', ContainerFile, '<MacroName> = <Value>')\r
838 continue\r
839 Nmake = ModuleNmakeClass()\r
840 Nmake.Name = List[0]\r
841 Nmake.Value = List[1]\r
842 Nmake.SupArchList = Nmakes[Key]\r
843 self.Module.Nmake.append(Nmake)\r
844\r
845 # convert R8 format to R9 format\r
846 if Nmake.Name == "IMAGE_ENTRY_POINT":\r
847 Image = ModuleExternImageClass()\r
848 Image.ModuleEntryPoint = Nmake.Value\r
849 self.Module.ExternImages.append(Image)\r
850 elif Nmake.Name == "DPX_SOURCE":\r
851 Source = ModuleSourceFileClass(NormPath(Nmake.Value), "", "", "", "", Nmake.SupArchList)\r
852 self.Module.Sources.append(Source)\r
853 else:\r
854 ToolList = gNmakeFlagPattern.findall(Nmake.Name)\r
855 if len(ToolList) == 0 or len(ToolList) != 1:\r
856 EdkLogger.warn("\nParser", "Don't know how to do with MACRO: %s" % Nmake.Name,\r
857 ExtraData=ContainerFile)\r
858 else:\r
859 if ToolList[0] in gNmakeFlagName2ToolCode:\r
860 Tool = gNmakeFlagName2ToolCode[ToolList[0]]\r
861 else:\r
862 Tool = ToolList[0]\r
863 BuildOption = BuildOptionClass("MSFT", "*_*_*_%s_FLAGS" % Tool, Nmake.Value)\r
864 BuildOption.SupArchList = Nmake.SupArchList\r
865 self.Module.BuildOptions.append(BuildOption)\r
866\r
867 ## GenPcds\r
868 #\r
869 # Gen Pcds of Inf\r
870 # <TokenSpaceGuidCName>.<PcdCName>[|<Value>]\r
871 #\r
872 # @param ContainerFile: The Dec file full path\r
873 #\r
874 def GenPcds(self, ContainerFile):\r
875 EdkLogger.debug(2, "Generate %s ..." % TAB_PCDS)\r
876 Pcds = {}\r
877 PcdToken = {}\r
878\r
879 #\r
880 # Get all Guids\r
881 #\r
882 RecordSet1 = self.RecordSet[MODEL_PCD_FIXED_AT_BUILD]\r
883 RecordSet2 = self.RecordSet[MODEL_PCD_PATCHABLE_IN_MODULE]\r
884 RecordSet3 = self.RecordSet[MODEL_PCD_FEATURE_FLAG]\r
885 RecordSet4 = self.RecordSet[MODEL_PCD_DYNAMIC_EX]\r
886 RecordSet5 = self.RecordSet[MODEL_PCD_DYNAMIC]\r
887\r
888 #\r
889 # Go through each arch\r
890 #\r
891 for Arch in self.SupArchList:\r
892 for Record in RecordSet1:\r
893 if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
894 if self.Module.Header[Arch].LibraryClass != {}:\r
895 pass\r
896 (TokenGuidCName, TokenName, Value, Type) = GetPcdOfInf(Record[0], TAB_PCDS_FIXED_AT_BUILD, ContainerFile, Record[2])\r
897 MergeArches(Pcds, (TokenGuidCName, TokenName, Value, Type), Arch)\r
898 PcdToken[Record[3]] = (TokenGuidCName, TokenName)\r
899 for Record in RecordSet2:\r
900 if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
901 (TokenGuidCName, TokenName, Value, Type) = GetPcdOfInf(Record[0], TAB_PCDS_PATCHABLE_IN_MODULE, ContainerFile, Record[2])\r
902 MergeArches(Pcds, (TokenGuidCName, TokenName, Value, Type), Arch)\r
903 PcdToken[Record[3]] = (TokenGuidCName, TokenName)\r
904 for Record in RecordSet3:\r
905 if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
906 (TokenGuidCName, TokenName, Value, Type) = GetPcdOfInf(Record[0], TAB_PCDS_FEATURE_FLAG, ContainerFile, Record[2])\r
907 MergeArches(Pcds, (TokenGuidCName, TokenName, Value, Type), Arch)\r
908 PcdToken[Record[3]] = (TokenGuidCName, TokenName)\r
909 for Record in RecordSet4:\r
910 if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
911 (TokenGuidCName, TokenName, Value, Type) = GetPcdOfInf(Record[0], TAB_PCDS_DYNAMIC_EX, ContainerFile, Record[2])\r
912 MergeArches(Pcds, (TokenGuidCName, TokenName, Value, Type), Arch)\r
913 PcdToken[Record[3]] = (TokenGuidCName, TokenName)\r
914 for Record in RecordSet5:\r
915 if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
916 (TokenGuidCName, TokenName, Value, Type) = GetPcdOfInf(Record[0], "", ContainerFile, Record[2])\r
917 MergeArches(Pcds, (TokenGuidCName, TokenName, Value, Type), Arch)\r
918 PcdToken[Record[3]] = (TokenGuidCName, TokenName)\r
919 #\r
920 # Update to database\r
921 #\r
922 if self.IsToDatabase:\r
923 for Key in PcdToken.keys():\r
924 SqlCommand = """update %s set Value2 = '%s' where ID = %s""" % (self.TblInf.Table, ".".join((PcdToken[Key][0], PcdToken[Key][1])), Key)\r
925 self.TblInf.Exec(SqlCommand)\r
926\r
927 for Key in Pcds.keys():\r
928 Pcd = PcdClass()\r
929 Pcd.CName = Key[1]\r
930 Pcd.TokenSpaceGuidCName = Key[0]\r
931 Pcd.DefaultValue = Key[2]\r
932 Pcd.ItemType = Key[3]\r
933 Pcd.SupArchList = Pcds[Key]\r
934 self.Module.PcdCodes.append(Pcd)\r
935\r
936 ## GenSources\r
937 #\r
938 # Gen Sources of Inf\r
939 # <Filename>[|<Family>[|<TagName>[|<ToolCode>[|<PcdFeatureFlag>]]]]\r
940 #\r
941 # @param ContainerFile: The Dec file full path\r
942 #\r
943 def GenSources(self, ContainerFile):\r
944 EdkLogger.debug(2, "Generate %s ..." % TAB_SOURCES)\r
945 Sources = {}\r
946\r
947 #\r
948 # Get all Nmakes\r
949 #\r
950 RecordSet = self.RecordSet[MODEL_EFI_SOURCE_FILE]\r
951\r
952 #\r
953 # Go through each arch\r
954 #\r
955 for Arch in self.SupArchList:\r
956 for Record in RecordSet:\r
957 if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
958 (Filename, Family, TagName, ToolCode, Pcd) = GetSource(Record[0], ContainerFile, self.Identification.FileRelativePath, Record[2])\r
959 MergeArches(Sources, (Filename, Family, TagName, ToolCode, Pcd), Arch)\r
960 if self.IsToDatabase:\r
961 SqlCommand = """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s', Value4 = '%s', Value5 = '%s'\r
962 where ID = %s""" % (self.TblInf.Table, ConvertToSqlString2(Filename), ConvertToSqlString2(Family), ConvertToSqlString2(TagName), ConvertToSqlString2(ToolCode), ConvertToSqlString2(Pcd), Record[3])\r
963 self.TblInf.Exec(SqlCommand)\r
964\r
965 for Key in Sources.keys():\r
966 Source = ModuleSourceFileClass(Key[0], Key[2], Key[3], Key[1], Key[4], Sources[Key])\r
967 self.Module.Sources.append(Source)\r
968\r
969 ## GenUserExtensions\r
970 #\r
971 # Gen UserExtensions of Inf\r
972 #\r
973 def GenUserExtensions(self, ContainerFile):\r
974# #\r
975# # UserExtensions\r
976# #\r
977# if self.UserExtensions != '':\r
978# UserExtension = UserExtensionsClass()\r
979# Lines = self.UserExtensions.splitlines()\r
980# List = GetSplitValueList(Lines[0], DataType.TAB_SPLIT, 2)\r
981# if len(List) != 3:\r
982# RaiseParserError(Lines[0], 'UserExtensions', File, "UserExtensions.UserId.'Identifier'")\r
983# else:\r
984# UserExtension.UserID = List[1]\r
985# UserExtension.Identifier = List[2][0:-1].replace("'", '').replace('\"', '')\r
986# for Line in Lines[1:]:\r
987# UserExtension.Content = UserExtension.Content + CleanString(Line) + '\n'\r
988# self.Module.UserExtensions.append(UserExtension)\r
989 pass\r
990\r
991 ## GenDepexes\r
992 #\r
993 # Gen Depex of Inf\r
994 #\r
995 # @param ContainerFile: The Inf file full path\r
996 #\r
997 def GenDepexes(self, ContainerFile):\r
998 EdkLogger.debug(2, "Generate %s ..." % TAB_DEPEX)\r
999 Depex = {}\r
1000 #\r
1001 # Get all Depexes\r
1002 #\r
1003 RecordSet = self.RecordSet[MODEL_EFI_DEPEX]\r
1004\r
1005 #\r
1006 # Go through each arch\r
1007 #\r
1008 for Arch in self.SupArchList:\r
1009 Line = ''\r
1010 for Record in RecordSet:\r
1011 if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
1012 Line = Line + Record[0] + ' '\r
1013 if Line != '':\r
1014 MergeArches(Depex, Line, Arch)\r
1015\r
1016 for Key in Depex.keys():\r
1017 Dep = ModuleDepexClass()\r
1018 Dep.Depex = Key\r
1019 Dep.SupArchList = Depex[Key]\r
1020 self.Module.Depex.append(Dep)\r
1021\r
1022 ## GenBinaries\r
1023 #\r
1024 # Gen Binary of Inf\r
1025 # <FileType>|<Filename>|<Target>[|<TokenSpaceGuidCName>.<PcdCName>]\r
1026 #\r
1027 # @param ContainerFile: The Dec file full path\r
1028 #\r
1029 def GenBinaries(self, ContainerFile):\r
1030 EdkLogger.debug(2, "Generate %s ..." % TAB_BINARIES)\r
1031 Binaries = {}\r
1032\r
1033 #\r
1034 # Get all Guids\r
1035 #\r
1036 RecordSet = self.RecordSet[MODEL_EFI_BINARY_FILE]\r
1037\r
1038 #\r
1039 # Go through each arch\r
1040 #\r
1041 for Arch in self.SupArchList:\r
1042 for Record in RecordSet:\r
1043 if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
1044 (FileType, Filename, Target, Pcd) = GetBinary(Record[0], ContainerFile, self.Identification.FileRelativePath, Record[2])\r
1045 MergeArches(Binaries, (FileType, Filename, Target, Pcd), Arch)\r
1046 if self.IsToDatabase:\r
1047 SqlCommand = """update %s set Value1 = '%s', Value2 = '%s', Value3 = '%s', Value4 = '%s'\r
1048 where ID = %s""" % (self.TblInf.Table, ConvertToSqlString2(FileType), ConvertToSqlString2(Filename), ConvertToSqlString2(Target), ConvertToSqlString2(Pcd), Record[3])\r
1049 self.TblInf.Exec(SqlCommand)\r
1050\r
1051 for Key in Binaries.keys():\r
1052 Binary = ModuleBinaryFileClass(NormPath(Key[1]), Key[0], Key[2], Key[3], Binaries[Key])\r
1053 self.Module.Binaries.append(Binary)\r
1054\r
1055 ## GenGuids\r
1056 #\r
1057 # Gen Guids of Inf\r
1058 # <CName>=<GuidValue>\r
1059 #\r
1060 # @param ContainerFile: The Inf file full path\r
1061 #\r
1062 def GenGuidProtocolPpis(self, Type, ContainerFile):\r
1063 EdkLogger.debug(2, "Generate %s ..." % Type)\r
1064 Lists = {}\r
1065 #\r
1066 # Get all Items\r
1067 #\r
1068 RecordSet = self.RecordSet[Section[Type.upper()]]\r
1069\r
1070 #\r
1071 # Go through each arch\r
1072 #\r
1073 for Arch in self.SupArchList:\r
1074 for Record in RecordSet:\r
1075 if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
1076 (Name, Value) = GetGuidsProtocolsPpisOfInf(Record[0], Type, ContainerFile, Record[2])\r
1077 MergeArches(Lists, (Name, Value), Arch)\r
1078 if self.IsToDatabase:\r
1079 SqlCommand = """update %s set Value1 = '%s', Value2 = '%s'\r
1080 where ID = %s""" % (self.TblInf.Table, ConvertToSqlString2(Name), ConvertToSqlString2(Value), Record[3])\r
1081 self.TblInf.Exec(SqlCommand)\r
1082\r
1083 ListMember = None\r
1084 if Type == TAB_GUIDS:\r
1085 ListMember = self.Module.Guids\r
1086 elif Type == TAB_PROTOCOLS:\r
1087 ListMember = self.Module.Protocols\r
1088 elif Type == TAB_PPIS:\r
1089 ListMember = self.Module.Ppis\r
1090\r
1091 for Key in Lists.keys():\r
1092 ListClass = GuidProtocolPpiCommonClass()\r
1093 ListClass.CName = Key[0]\r
1094 ListClass.SupArchList = Lists[Key]\r
1095 ListClass.FeatureFlag = Key[1]\r
1096 ListMember.append(ListClass)\r
1097\r
1098##\r
1099#\r
1100# This acts like the main() function for the script, unless it is 'import'ed into another\r
1101# script.\r
1102#\r
1103if __name__ == '__main__':\r
1104 EdkLogger.Initialize()\r
1105 EdkLogger.SetLevel(EdkLogger.DEBUG_0)\r
1106\r
1107 W = os.getenv('WORKSPACE')\r
1108 F = os.path.join(W, 'MdeModulePkg/Application/HelloWorld/HelloWorld.inf')\r
1109\r
1110 Db = Database.Database('Inf.db')\r
1111 Db.InitDatabase()\r
1112\r
1113 P = Inf(os.path.normpath(F), True, True, W, Db)\r
1114 P.ShowModule()\r
1115\r
1116 Db.Close()\r