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