]>
Commit | Line | Data |
---|---|---|
30fdf114 LG |
1 | ## @file |
2 | # This file is used to create a database used by build tool | |
3 | # | |
4 | # Copyright (c) 2008, Intel Corporation | |
5 | # All rights reserved. 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 sqlite3 | |
18 | import os | |
19 | import os.path | |
20 | ||
21 | import Common.EdkLogger as EdkLogger | |
22 | import Common.GlobalData as GlobalData | |
23 | ||
24 | from Common.String import * | |
25 | from Common.DataType import * | |
26 | from Common.Misc import * | |
27 | ||
28 | from CommonDataClass.CommonClass import SkuInfoClass | |
29 | ||
30 | from MetaDataTable import * | |
31 | from MetaFileTable import * | |
32 | from MetaFileParser import * | |
33 | from BuildClassObject import * | |
34 | ||
35 | ## Platform build information from DSC file | |
36 | # | |
37 | # This class is used to retrieve information stored in database and convert them | |
38 | # into PlatformBuildClassObject form for easier use for AutoGen. | |
39 | # | |
40 | class DscBuildData(PlatformBuildClassObject): | |
41 | # dict used to convert PCD type in database to string used by build tool | |
42 | _PCD_TYPE_STRING_ = { | |
43 | MODEL_PCD_FIXED_AT_BUILD : "FixedAtBuild", | |
44 | MODEL_PCD_PATCHABLE_IN_MODULE : "PatchableInModule", | |
45 | MODEL_PCD_FEATURE_FLAG : "FeatureFlag", | |
46 | MODEL_PCD_DYNAMIC : "Dynamic", | |
47 | MODEL_PCD_DYNAMIC_DEFAULT : "Dynamic", | |
48 | MODEL_PCD_DYNAMIC_HII : "DynamicHii", | |
49 | MODEL_PCD_DYNAMIC_VPD : "DynamicVpd", | |
50 | MODEL_PCD_DYNAMIC_EX : "DynamicEx", | |
51 | MODEL_PCD_DYNAMIC_EX_DEFAULT : "DynamicEx", | |
52 | MODEL_PCD_DYNAMIC_EX_HII : "DynamicExHii", | |
53 | MODEL_PCD_DYNAMIC_EX_VPD : "DynamicExVpd", | |
54 | } | |
55 | ||
56 | # dict used to convert part of [Defines] to members of DscBuildData directly | |
57 | _PROPERTY_ = { | |
58 | # | |
59 | # Required Fields | |
60 | # | |
61 | TAB_DSC_DEFINES_PLATFORM_NAME : "_PlatformName", | |
62 | TAB_DSC_DEFINES_PLATFORM_GUID : "_Guid", | |
63 | TAB_DSC_DEFINES_PLATFORM_VERSION : "_Version", | |
64 | TAB_DSC_DEFINES_DSC_SPECIFICATION : "_DscSpecification", | |
65 | #TAB_DSC_DEFINES_OUTPUT_DIRECTORY : "_OutputDirectory", | |
66 | #TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES : "_SupArchList", | |
67 | #TAB_DSC_DEFINES_BUILD_TARGETS : "_BuildTargets", | |
68 | #TAB_DSC_DEFINES_SKUID_IDENTIFIER : "_SkuName", | |
69 | #TAB_DSC_DEFINES_FLASH_DEFINITION : "_FlashDefinition", | |
70 | TAB_DSC_DEFINES_BUILD_NUMBER : "_BuildNumber", | |
71 | TAB_DSC_DEFINES_MAKEFILE_NAME : "_MakefileName", | |
72 | TAB_DSC_DEFINES_BS_BASE_ADDRESS : "_BsBaseAddress", | |
73 | TAB_DSC_DEFINES_RT_BASE_ADDRESS : "_RtBaseAddress", | |
74 | } | |
75 | ||
76 | # used to compose dummy library class name for those forced library instances | |
77 | _NullLibraryNumber = 0 | |
78 | ||
79 | ## Constructor of DscBuildData | |
80 | # | |
81 | # Initialize object of DscBuildData | |
82 | # | |
83 | # @param FilePath The path of platform description file | |
84 | # @param RawData The raw data of DSC file | |
85 | # @param BuildDataBase Database used to retrieve module/package information | |
86 | # @param Arch The target architecture | |
87 | # @param Platform (not used for DscBuildData) | |
88 | # @param Macros Macros used for replacement in DSC file | |
89 | # | |
90 | def __init__(self, FilePath, RawData, BuildDataBase, Arch='COMMON', Platform='DUMMY', Macros={}): | |
91 | self.MetaFile = FilePath | |
92 | self._RawData = RawData | |
93 | self._Bdb = BuildDataBase | |
94 | self._Arch = Arch | |
95 | self._Macros = Macros | |
96 | self._Clear() | |
97 | RecordList = self._RawData[MODEL_META_DATA_DEFINE, self._Arch] | |
98 | for Record in RecordList: | |
99 | GlobalData.gEdkGlobal[Record[0]] = Record[1] | |
100 | ||
101 | ## XXX[key] = value | |
102 | def __setitem__(self, key, value): | |
103 | self.__dict__[self._PROPERTY_[key]] = value | |
104 | ||
105 | ## value = XXX[key] | |
106 | def __getitem__(self, key): | |
107 | return self.__dict__[self._PROPERTY_[key]] | |
108 | ||
109 | ## "in" test support | |
110 | def __contains__(self, key): | |
111 | return key in self._PROPERTY_ | |
112 | ||
113 | ## Set all internal used members of DscBuildData to None | |
114 | def _Clear(self): | |
115 | self._Header = None | |
116 | self._PlatformName = None | |
117 | self._Guid = None | |
118 | self._Version = None | |
119 | self._DscSpecification = None | |
120 | self._OutputDirectory = None | |
121 | self._SupArchList = None | |
122 | self._BuildTargets = None | |
123 | self._SkuName = None | |
124 | self._FlashDefinition = None | |
125 | self._BuildNumber = None | |
126 | self._MakefileName = None | |
127 | self._BsBaseAddress = None | |
128 | self._RtBaseAddress = None | |
129 | self._SkuIds = None | |
130 | self._Modules = None | |
131 | self._LibraryInstances = None | |
132 | self._LibraryClasses = None | |
133 | self._Pcds = None | |
134 | self._BuildOptions = None | |
135 | ||
136 | ## Get architecture | |
137 | def _GetArch(self): | |
138 | return self._Arch | |
139 | ||
140 | ## Set architecture | |
141 | # | |
142 | # Changing the default ARCH to another may affect all other information | |
143 | # because all information in a platform may be ARCH-related. That's | |
144 | # why we need to clear all internal used members, in order to cause all | |
145 | # information to be re-retrieved. | |
146 | # | |
147 | # @param Value The value of ARCH | |
148 | # | |
149 | def _SetArch(self, Value): | |
150 | if self._Arch == Value: | |
151 | return | |
152 | self._Arch = Value | |
153 | self._Clear() | |
154 | ||
155 | ## Retrieve all information in [Defines] section | |
156 | # | |
157 | # (Retriving all [Defines] information in one-shot is just to save time.) | |
158 | # | |
159 | def _GetHeaderInfo(self): | |
160 | RecordList = self._RawData[MODEL_META_DATA_HEADER, self._Arch] | |
161 | for Record in RecordList: | |
162 | Name = Record[0] | |
163 | # items defined _PROPERTY_ don't need additional processing | |
164 | if Name in self: | |
165 | self[Name] = Record[1] | |
166 | # some special items in [Defines] section need special treatment | |
167 | elif Name == TAB_DSC_DEFINES_OUTPUT_DIRECTORY: | |
168 | self._OutputDirectory = NormPath(Record[1], self._Macros) | |
169 | if ' ' in self._OutputDirectory: | |
170 | EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "No space is allowed in OUTPUT_DIRECTORY", | |
171 | File=self.MetaFile, Line=Record[-1], | |
172 | ExtraData=self._OutputDirectory) | |
173 | elif Name == TAB_DSC_DEFINES_FLASH_DEFINITION: | |
174 | self._FlashDefinition = PathClass(NormPath(Record[1], self._Macros), GlobalData.gWorkspace) | |
175 | ErrorCode, ErrorInfo = self._FlashDefinition.Validate('.fdf') | |
176 | if ErrorCode != 0: | |
177 | EdkLogger.error('build', ErrorCode, File=self.MetaFile, Line=Record[-1], | |
178 | ExtraData=ErrorInfo) | |
179 | elif Name == TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES: | |
180 | self._SupArchList = GetSplitValueList(Record[1], TAB_VALUE_SPLIT) | |
181 | elif Name == TAB_DSC_DEFINES_BUILD_TARGETS: | |
182 | self._BuildTargets = GetSplitValueList(Record[1]) | |
183 | elif Name == TAB_DSC_DEFINES_SKUID_IDENTIFIER: | |
184 | if self._SkuName == None: | |
185 | self._SkuName = Record[1] | |
186 | # set _Header to non-None in order to avoid database re-querying | |
187 | self._Header = 'DUMMY' | |
188 | ||
189 | ## Retrieve platform name | |
190 | def _GetPlatformName(self): | |
191 | if self._PlatformName == None: | |
192 | if self._Header == None: | |
193 | self._GetHeaderInfo() | |
194 | if self._PlatformName == None: | |
195 | EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No PLATFORM_NAME", File=self.MetaFile) | |
196 | return self._PlatformName | |
197 | ||
198 | ## Retrieve file guid | |
199 | def _GetFileGuid(self): | |
200 | if self._Guid == None: | |
201 | if self._Header == None: | |
202 | self._GetHeaderInfo() | |
203 | if self._Guid == None: | |
204 | EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No FILE_GUID", File=self.MetaFile) | |
205 | return self._Guid | |
206 | ||
207 | ## Retrieve platform version | |
208 | def _GetVersion(self): | |
209 | if self._Version == None: | |
210 | if self._Header == None: | |
211 | self._GetHeaderInfo() | |
212 | if self._Version == None: | |
213 | self._Version = '' | |
214 | return self._Version | |
215 | ||
216 | ## Retrieve platform description file version | |
217 | def _GetDscSpec(self): | |
218 | if self._DscSpecification == None: | |
219 | if self._Header == None: | |
220 | self._GetHeaderInfo() | |
221 | if self._DscSpecification == None: | |
222 | self._DscSpecification = '' | |
223 | return self._DscSpecification | |
224 | ||
225 | ## Retrieve OUTPUT_DIRECTORY | |
226 | def _GetOutpuDir(self): | |
227 | if self._OutputDirectory == None: | |
228 | if self._Header == None: | |
229 | self._GetHeaderInfo() | |
230 | if self._OutputDirectory == None: | |
231 | self._OutputDirectory = os.path.join("Build", self._PlatformName) | |
232 | return self._OutputDirectory | |
233 | ||
234 | ## Retrieve SUPPORTED_ARCHITECTURES | |
235 | def _GetSupArch(self): | |
236 | if self._SupArchList == None: | |
237 | if self._Header == None: | |
238 | self._GetHeaderInfo() | |
239 | if self._SupArchList == None: | |
240 | self._SupArchList = ARCH_LIST | |
241 | return self._SupArchList | |
242 | ||
243 | ## Retrieve BUILD_TARGETS | |
244 | def _GetBuildTarget(self): | |
245 | if self._BuildTargets == None: | |
246 | if self._Header == None: | |
247 | self._GetHeaderInfo() | |
248 | if self._BuildTargets == None: | |
249 | self._BuildTargets = ['DEBUG', 'RELEASE'] | |
250 | return self._BuildTargets | |
251 | ||
252 | ## Retrieve SKUID_IDENTIFIER | |
253 | def _GetSkuName(self): | |
254 | if self._SkuName == None: | |
255 | if self._Header == None: | |
256 | self._GetHeaderInfo() | |
257 | if self._SkuName == None or self._SkuName not in self.SkuIds: | |
258 | self._SkuName = 'DEFAULT' | |
259 | return self._SkuName | |
260 | ||
261 | ## Override SKUID_IDENTIFIER | |
262 | def _SetSkuName(self, Value): | |
263 | if Value in self.SkuIds: | |
264 | self._SkuName = Value | |
265 | ||
266 | def _GetFdfFile(self): | |
267 | if self._FlashDefinition == None: | |
268 | if self._Header == None: | |
269 | self._GetHeaderInfo() | |
270 | if self._FlashDefinition == None: | |
271 | self._FlashDefinition = '' | |
272 | return self._FlashDefinition | |
273 | ||
274 | ## Retrieve FLASH_DEFINITION | |
275 | def _GetBuildNumber(self): | |
276 | if self._BuildNumber == None: | |
277 | if self._Header == None: | |
278 | self._GetHeaderInfo() | |
279 | if self._BuildNumber == None: | |
280 | self._BuildNumber = '' | |
281 | return self._BuildNumber | |
282 | ||
283 | ## Retrieve MAKEFILE_NAME | |
284 | def _GetMakefileName(self): | |
285 | if self._MakefileName == None: | |
286 | if self._Header == None: | |
287 | self._GetHeaderInfo() | |
288 | if self._MakefileName == None: | |
289 | self._MakefileName = '' | |
290 | return self._MakefileName | |
291 | ||
292 | ## Retrieve BsBaseAddress | |
293 | def _GetBsBaseAddress(self): | |
294 | if self._BsBaseAddress == None: | |
295 | if self._Header == None: | |
296 | self._GetHeaderInfo() | |
297 | if self._BsBaseAddress == None: | |
298 | self._BsBaseAddress = '' | |
299 | return self._BsBaseAddress | |
300 | ||
301 | ## Retrieve RtBaseAddress | |
302 | def _GetRtBaseAddress(self): | |
303 | if self._RtBaseAddress == None: | |
304 | if self._Header == None: | |
305 | self._GetHeaderInfo() | |
306 | if self._RtBaseAddress == None: | |
307 | self._RtBaseAddress = '' | |
308 | return self._RtBaseAddress | |
309 | ||
310 | ## Retrieve [SkuIds] section information | |
311 | def _GetSkuIds(self): | |
312 | if self._SkuIds == None: | |
313 | self._SkuIds = {} | |
314 | RecordList = self._RawData[MODEL_EFI_SKU_ID] | |
315 | for Record in RecordList: | |
316 | if Record[0] in [None, '']: | |
317 | EdkLogger.error('build', FORMAT_INVALID, 'No Sku ID number', | |
318 | File=self.MetaFile, Line=Record[-1]) | |
319 | if Record[1] in [None, '']: | |
320 | EdkLogger.error('build', FORMAT_INVALID, 'No Sku ID name', | |
321 | File=self.MetaFile, Line=Record[-1]) | |
322 | self._SkuIds[Record[1]] = Record[0] | |
323 | if 'DEFAULT' not in self._SkuIds: | |
324 | self._SkuIds['DEFAULT'] = 0 | |
325 | return self._SkuIds | |
326 | ||
327 | ## Retrieve [Components] section information | |
328 | def _GetModules(self): | |
329 | if self._Modules != None: | |
330 | return self._Modules | |
331 | ||
332 | self._Modules = sdict() | |
333 | RecordList = self._RawData[MODEL_META_DATA_COMPONENT, self._Arch] | |
334 | Macros = {"EDK_SOURCE":GlobalData.gEcpSource, "EFI_SOURCE":GlobalData.gEfiSource} | |
335 | Macros.update(self._Macros) | |
336 | for Record in RecordList: | |
337 | ModuleFile = PathClass(NormPath(Record[0], Macros), GlobalData.gWorkspace, Arch=self._Arch) | |
338 | ModuleId = Record[5] | |
339 | LineNo = Record[6] | |
340 | ||
341 | # check the file validation | |
342 | ErrorCode, ErrorInfo = ModuleFile.Validate('.inf') | |
343 | if ErrorCode != 0: | |
344 | EdkLogger.error('build', ErrorCode, File=self.MetaFile, Line=LineNo, | |
345 | ExtraData=ErrorInfo) | |
346 | # Check duplication | |
347 | if ModuleFile in self._Modules: | |
348 | EdkLogger.error('build', FILE_DUPLICATED, File=self.MetaFile, ExtraData=str(ModuleFile), Line=LineNo) | |
349 | ||
350 | Module = ModuleBuildClassObject() | |
351 | Module.MetaFile = ModuleFile | |
352 | ||
353 | # get module override path | |
354 | RecordList = self._RawData[MODEL_META_DATA_COMPONENT_SOURCE_OVERRIDE_PATH, self._Arch, None, ModuleId] | |
355 | if RecordList != []: | |
356 | Module.SourceOverridePath = os.path.join(GlobalData.gWorkspace, NormPath(RecordList[0][0], Macros)) | |
357 | ||
358 | # Check if the source override path exists | |
359 | if not os.path.isdir(Module.SourceOverridePath): | |
360 | EdkLogger.error('build', FILE_NOT_FOUND, Message = 'Source override path does not exist:', File=self.MetaFile, ExtraData=Module.SourceOverridePath, Line=LineNo) | |
361 | ||
362 | #Add to GlobalData Variables | |
363 | GlobalData.gOverrideDir[ModuleFile.Key] = Module.SourceOverridePath | |
364 | ||
365 | # get module private library instance | |
366 | RecordList = self._RawData[MODEL_EFI_LIBRARY_CLASS, self._Arch, None, ModuleId] | |
367 | for Record in RecordList: | |
368 | LibraryClass = Record[0] | |
369 | LibraryPath = PathClass(NormPath(Record[1], Macros), GlobalData.gWorkspace, Arch=self._Arch) | |
370 | LineNo = Record[-1] | |
371 | ||
372 | # check the file validation | |
373 | ErrorCode, ErrorInfo = LibraryPath.Validate('.inf') | |
374 | if ErrorCode != 0: | |
375 | EdkLogger.error('build', ErrorCode, File=self.MetaFile, Line=LineNo, | |
376 | ExtraData=ErrorInfo) | |
377 | ||
378 | if LibraryClass == '' or LibraryClass == 'NULL': | |
379 | self._NullLibraryNumber += 1 | |
380 | LibraryClass = 'NULL%d' % self._NullLibraryNumber | |
381 | EdkLogger.verbose("Found forced library for %s\n\t%s [%s]" % (ModuleFile, LibraryPath, LibraryClass)) | |
382 | Module.LibraryClasses[LibraryClass] = LibraryPath | |
383 | if LibraryPath not in self.LibraryInstances: | |
384 | self.LibraryInstances.append(LibraryPath) | |
385 | ||
386 | # get module private PCD setting | |
387 | for Type in [MODEL_PCD_FIXED_AT_BUILD, MODEL_PCD_PATCHABLE_IN_MODULE, \ | |
388 | MODEL_PCD_FEATURE_FLAG, MODEL_PCD_DYNAMIC, MODEL_PCD_DYNAMIC_EX]: | |
389 | RecordList = self._RawData[Type, self._Arch, None, ModuleId] | |
390 | for TokenSpaceGuid, PcdCName, Setting, Dummy1, Dummy2, Dummy3, Dummy4 in RecordList: | |
391 | TokenList = GetSplitValueList(Setting) | |
392 | DefaultValue = TokenList[0] | |
393 | if len(TokenList) > 1: | |
394 | MaxDatumSize = TokenList[1] | |
395 | else: | |
396 | MaxDatumSize = '' | |
397 | TypeString = self._PCD_TYPE_STRING_[Type] | |
398 | Pcd = PcdClassObject( | |
399 | PcdCName, | |
400 | TokenSpaceGuid, | |
401 | TypeString, | |
402 | '', | |
403 | DefaultValue, | |
404 | '', | |
405 | MaxDatumSize, | |
406 | {}, | |
407 | None | |
408 | ) | |
409 | Module.Pcds[PcdCName, TokenSpaceGuid] = Pcd | |
410 | ||
411 | # get module private build options | |
412 | RecordList = self._RawData[MODEL_META_DATA_BUILD_OPTION, self._Arch, None, ModuleId] | |
413 | for ToolChainFamily, ToolChain, Option, Dummy1, Dummy2, Dummy3, Dummy4 in RecordList: | |
414 | if (ToolChainFamily, ToolChain) not in Module.BuildOptions: | |
415 | Module.BuildOptions[ToolChainFamily, ToolChain] = Option | |
416 | else: | |
417 | OptionString = Module.BuildOptions[ToolChainFamily, ToolChain] | |
418 | Module.BuildOptions[ToolChainFamily, ToolChain] = OptionString + " " + Option | |
419 | ||
420 | self._Modules[ModuleFile] = Module | |
421 | return self._Modules | |
422 | ||
423 | ## Retrieve all possible library instances used in this platform | |
424 | def _GetLibraryInstances(self): | |
425 | if self._LibraryInstances == None: | |
426 | self._GetLibraryClasses() | |
427 | return self._LibraryInstances | |
428 | ||
429 | ## Retrieve [LibraryClasses] information | |
430 | def _GetLibraryClasses(self): | |
431 | if self._LibraryClasses == None: | |
432 | self._LibraryInstances = [] | |
433 | # | |
434 | # tdict is a special dict kind of type, used for selecting correct | |
435 | # library instance for given library class and module type | |
436 | # | |
437 | LibraryClassDict = tdict(True, 3) | |
438 | # track all library class names | |
439 | LibraryClassSet = set() | |
440 | RecordList = self._RawData[MODEL_EFI_LIBRARY_CLASS, self._Arch] | |
441 | Macros = {"EDK_SOURCE":GlobalData.gEcpSource, "EFI_SOURCE":GlobalData.gEfiSource} | |
442 | Macros.update(self._Macros) | |
443 | for Record in RecordList: | |
444 | LibraryClass, LibraryInstance, Dummy, Arch, ModuleType, Dummy, LineNo = Record | |
445 | LibraryClassSet.add(LibraryClass) | |
446 | LibraryInstance = PathClass(NormPath(LibraryInstance, Macros), GlobalData.gWorkspace, Arch=self._Arch) | |
447 | # check the file validation | |
448 | ErrorCode, ErrorInfo = LibraryInstance.Validate('.inf') | |
449 | if ErrorCode != 0: | |
450 | EdkLogger.error('build', ErrorCode, File=self.MetaFile, Line=LineNo, | |
451 | ExtraData=ErrorInfo) | |
452 | ||
453 | if ModuleType != 'COMMON' and ModuleType not in SUP_MODULE_LIST: | |
454 | EdkLogger.error('build', OPTION_UNKNOWN, "Unknown module type [%s]" % ModuleType, | |
455 | File=self.MetaFile, ExtraData=LibraryInstance, Line=LineNo) | |
456 | LibraryClassDict[Arch, ModuleType, LibraryClass] = LibraryInstance | |
457 | if LibraryInstance not in self._LibraryInstances: | |
458 | self._LibraryInstances.append(LibraryInstance) | |
459 | ||
460 | # resolve the specific library instance for each class and each module type | |
461 | self._LibraryClasses = tdict(True) | |
462 | for LibraryClass in LibraryClassSet: | |
463 | # try all possible module types | |
464 | for ModuleType in SUP_MODULE_LIST: | |
465 | LibraryInstance = LibraryClassDict[self._Arch, ModuleType, LibraryClass] | |
466 | if LibraryInstance == None: | |
467 | continue | |
468 | self._LibraryClasses[LibraryClass, ModuleType] = LibraryInstance | |
469 | ||
470 | # for R8 style library instances, which are listed in different section | |
471 | RecordList = self._RawData[MODEL_EFI_LIBRARY_INSTANCE, self._Arch] | |
472 | for Record in RecordList: | |
473 | File = PathClass(NormPath(Record[0], Macros), GlobalData.gWorkspace, Arch=self._Arch) | |
474 | LineNo = Record[-1] | |
475 | # check the file validation | |
476 | ErrorCode, ErrorInfo = File.Validate('.inf') | |
477 | if ErrorCode != 0: | |
478 | EdkLogger.error('build', ErrorCode, File=self.MetaFile, Line=LineNo, | |
479 | ExtraData=ErrorInfo) | |
480 | if File not in self._LibraryInstances: | |
481 | self._LibraryInstances.append(File) | |
482 | # | |
483 | # we need the module name as the library class name, so we have | |
484 | # to parse it here. (self._Bdb[] will trigger a file parse if it | |
485 | # hasn't been parsed) | |
486 | # | |
487 | Library = self._Bdb[File, self._Arch] | |
488 | self._LibraryClasses[Library.BaseName, ':dummy:'] = Library | |
489 | return self._LibraryClasses | |
490 | ||
491 | ## Retrieve all PCD settings in platform | |
492 | def _GetPcds(self): | |
493 | if self._Pcds == None: | |
494 | self._Pcds = {} | |
495 | self._Pcds.update(self._GetPcd(MODEL_PCD_FIXED_AT_BUILD)) | |
496 | self._Pcds.update(self._GetPcd(MODEL_PCD_PATCHABLE_IN_MODULE)) | |
497 | self._Pcds.update(self._GetPcd(MODEL_PCD_FEATURE_FLAG)) | |
498 | self._Pcds.update(self._GetDynamicPcd(MODEL_PCD_DYNAMIC_DEFAULT)) | |
499 | self._Pcds.update(self._GetDynamicHiiPcd(MODEL_PCD_DYNAMIC_HII)) | |
500 | self._Pcds.update(self._GetDynamicVpdPcd(MODEL_PCD_DYNAMIC_VPD)) | |
501 | self._Pcds.update(self._GetDynamicPcd(MODEL_PCD_DYNAMIC_EX_DEFAULT)) | |
502 | self._Pcds.update(self._GetDynamicHiiPcd(MODEL_PCD_DYNAMIC_EX_HII)) | |
503 | self._Pcds.update(self._GetDynamicVpdPcd(MODEL_PCD_DYNAMIC_EX_VPD)) | |
504 | return self._Pcds | |
505 | ||
506 | ## Retrieve [BuildOptions] | |
507 | def _GetBuildOptions(self): | |
508 | if self._BuildOptions == None: | |
509 | self._BuildOptions = {} | |
510 | RecordList = self._RawData[MODEL_META_DATA_BUILD_OPTION] | |
511 | for ToolChainFamily, ToolChain, Option, Dummy1, Dummy2, Dummy3, Dummy4 in RecordList: | |
512 | self._BuildOptions[ToolChainFamily, ToolChain] = Option | |
513 | return self._BuildOptions | |
514 | ||
515 | ## Retrieve non-dynamic PCD settings | |
516 | # | |
517 | # @param Type PCD type | |
518 | # | |
519 | # @retval a dict object contains settings of given PCD type | |
520 | # | |
521 | def _GetPcd(self, Type): | |
522 | Pcds = {} | |
523 | # | |
524 | # tdict is a special dict kind of type, used for selecting correct | |
525 | # PCD settings for certain ARCH | |
526 | # | |
527 | PcdDict = tdict(True, 3) | |
528 | PcdSet = set() | |
529 | # Find out all possible PCD candidates for self._Arch | |
530 | RecordList = self._RawData[Type, self._Arch] | |
531 | for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, Dummy3, Dummy4 in RecordList: | |
532 | PcdSet.add((PcdCName, TokenSpaceGuid)) | |
533 | PcdDict[Arch, PcdCName, TokenSpaceGuid] = Setting | |
534 | # Remove redundant PCD candidates | |
535 | for PcdCName, TokenSpaceGuid in PcdSet: | |
536 | ValueList = ['', '', ''] | |
537 | Setting = PcdDict[self._Arch, PcdCName, TokenSpaceGuid] | |
538 | if Setting == None: | |
539 | continue | |
540 | TokenList = Setting.split(TAB_VALUE_SPLIT) | |
541 | ValueList[0:len(TokenList)] = TokenList | |
542 | PcdValue, DatumType, MaxDatumSize = ValueList | |
543 | Pcds[PcdCName, TokenSpaceGuid] = PcdClassObject( | |
544 | PcdCName, | |
545 | TokenSpaceGuid, | |
546 | self._PCD_TYPE_STRING_[Type], | |
547 | DatumType, | |
548 | PcdValue, | |
549 | '', | |
550 | MaxDatumSize, | |
551 | {}, | |
552 | None | |
553 | ) | |
554 | return Pcds | |
555 | ||
556 | ## Retrieve dynamic PCD settings | |
557 | # | |
558 | # @param Type PCD type | |
559 | # | |
560 | # @retval a dict object contains settings of given PCD type | |
561 | # | |
562 | def _GetDynamicPcd(self, Type): | |
563 | Pcds = {} | |
564 | # | |
565 | # tdict is a special dict kind of type, used for selecting correct | |
566 | # PCD settings for certain ARCH and SKU | |
567 | # | |
568 | PcdDict = tdict(True, 4) | |
569 | PcdSet = set() | |
570 | # Find out all possible PCD candidates for self._Arch | |
571 | RecordList = self._RawData[Type, self._Arch] | |
572 | for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, Dummy3, Dummy4 in RecordList: | |
573 | PcdSet.add((PcdCName, TokenSpaceGuid)) | |
574 | PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid] = Setting | |
575 | # Remove redundant PCD candidates, per the ARCH and SKU | |
576 | for PcdCName, TokenSpaceGuid in PcdSet: | |
577 | ValueList = ['', '', ''] | |
578 | Setting = PcdDict[self._Arch, self.SkuName, PcdCName, TokenSpaceGuid] | |
579 | if Setting == None: | |
580 | continue | |
581 | TokenList = Setting.split(TAB_VALUE_SPLIT) | |
582 | ValueList[0:len(TokenList)] = TokenList | |
583 | PcdValue, DatumType, MaxDatumSize = ValueList | |
584 | ||
585 | SkuInfo = SkuInfoClass(self.SkuName, self.SkuIds[self.SkuName], '', '', '', '', '', PcdValue) | |
586 | Pcds[PcdCName, TokenSpaceGuid] = PcdClassObject( | |
587 | PcdCName, | |
588 | TokenSpaceGuid, | |
589 | self._PCD_TYPE_STRING_[Type], | |
590 | DatumType, | |
591 | PcdValue, | |
592 | '', | |
593 | MaxDatumSize, | |
594 | {self.SkuName : SkuInfo}, | |
595 | None | |
596 | ) | |
597 | return Pcds | |
598 | ||
599 | ## Retrieve dynamic HII PCD settings | |
600 | # | |
601 | # @param Type PCD type | |
602 | # | |
603 | # @retval a dict object contains settings of given PCD type | |
604 | # | |
605 | def _GetDynamicHiiPcd(self, Type): | |
606 | Pcds = {} | |
607 | # | |
608 | # tdict is a special dict kind of type, used for selecting correct | |
609 | # PCD settings for certain ARCH and SKU | |
610 | # | |
611 | PcdDict = tdict(True, 4) | |
612 | PcdSet = set() | |
613 | RecordList = self._RawData[Type, self._Arch] | |
614 | # Find out all possible PCD candidates for self._Arch | |
615 | for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, Dummy3, Dummy4 in RecordList: | |
616 | PcdSet.add((PcdCName, TokenSpaceGuid)) | |
617 | PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid] = Setting | |
618 | # Remove redundant PCD candidates, per the ARCH and SKU | |
619 | for PcdCName, TokenSpaceGuid in PcdSet: | |
620 | ValueList = ['', '', '', ''] | |
621 | Setting = PcdDict[self._Arch, self.SkuName, PcdCName, TokenSpaceGuid] | |
622 | if Setting == None: | |
623 | continue | |
624 | TokenList = Setting.split(TAB_VALUE_SPLIT) | |
625 | ValueList[0:len(TokenList)] = TokenList | |
626 | VariableName, VariableGuid, VariableOffset, DefaultValue = ValueList | |
627 | SkuInfo = SkuInfoClass(self.SkuName, self.SkuIds[self.SkuName], VariableName, VariableGuid, VariableOffset, DefaultValue) | |
628 | Pcds[PcdCName, TokenSpaceGuid] = PcdClassObject( | |
629 | PcdCName, | |
630 | TokenSpaceGuid, | |
631 | self._PCD_TYPE_STRING_[Type], | |
632 | '', | |
633 | DefaultValue, | |
634 | '', | |
635 | '', | |
636 | {self.SkuName : SkuInfo}, | |
637 | None | |
638 | ) | |
639 | return Pcds | |
640 | ||
641 | ## Retrieve dynamic VPD PCD settings | |
642 | # | |
643 | # @param Type PCD type | |
644 | # | |
645 | # @retval a dict object contains settings of given PCD type | |
646 | # | |
647 | def _GetDynamicVpdPcd(self, Type): | |
648 | Pcds = {} | |
649 | # | |
650 | # tdict is a special dict kind of type, used for selecting correct | |
651 | # PCD settings for certain ARCH and SKU | |
652 | # | |
653 | PcdDict = tdict(True, 4) | |
654 | PcdSet = set() | |
655 | # Find out all possible PCD candidates for self._Arch | |
656 | RecordList = self._RawData[Type, self._Arch] | |
657 | for TokenSpaceGuid, PcdCName, Setting, Arch, SkuName, Dummy3, Dummy4 in RecordList: | |
658 | PcdSet.add((PcdCName, TokenSpaceGuid)) | |
659 | PcdDict[Arch, SkuName, PcdCName, TokenSpaceGuid] = Setting | |
660 | # Remove redundant PCD candidates, per the ARCH and SKU | |
661 | for PcdCName, TokenSpaceGuid in PcdSet: | |
662 | ValueList = ['', ''] | |
663 | Setting = PcdDict[self._Arch, self.SkuName, PcdCName, TokenSpaceGuid] | |
664 | if Setting == None: | |
665 | continue | |
666 | TokenList = Setting.split(TAB_VALUE_SPLIT) | |
667 | ValueList[0:len(TokenList)] = TokenList | |
668 | VpdOffset, MaxDatumSize = ValueList | |
669 | ||
670 | SkuInfo = SkuInfoClass(self.SkuName, self.SkuIds[self.SkuName], '', '', '', '', VpdOffset) | |
671 | Pcds[PcdCName, TokenSpaceGuid] = PcdClassObject( | |
672 | PcdCName, | |
673 | TokenSpaceGuid, | |
674 | self._PCD_TYPE_STRING_[Type], | |
675 | '', | |
676 | '', | |
677 | '', | |
678 | MaxDatumSize, | |
679 | {self.SkuName : SkuInfo}, | |
680 | None | |
681 | ) | |
682 | return Pcds | |
683 | ||
684 | ## Add external modules | |
685 | # | |
686 | # The external modules are mostly those listed in FDF file, which don't | |
687 | # need "build". | |
688 | # | |
689 | # @param FilePath The path of module description file | |
690 | # | |
691 | def AddModule(self, FilePath): | |
692 | FilePath = NormPath(FilePath) | |
693 | if FilePath not in self.Modules: | |
694 | Module = ModuleBuildClassObject() | |
695 | Module.MetaFile = FilePath | |
696 | self.Modules.append(Module) | |
697 | ||
698 | ## Add external PCDs | |
699 | # | |
700 | # The external PCDs are mostly those listed in FDF file to specify address | |
701 | # or offset information. | |
702 | # | |
703 | # @param Name Name of the PCD | |
704 | # @param Guid Token space guid of the PCD | |
705 | # @param Value Value of the PCD | |
706 | # | |
707 | def AddPcd(self, Name, Guid, Value): | |
708 | if (Name, Guid) not in self.Pcds: | |
709 | self.Pcds[Name, Guid] = PcdClassObject(Name, Guid, '', '', '', '', '', {}, None) | |
710 | self.Pcds[Name, Guid].DefaultValue = Value | |
711 | ||
712 | Arch = property(_GetArch, _SetArch) | |
713 | Platform = property(_GetPlatformName) | |
714 | PlatformName = property(_GetPlatformName) | |
715 | Guid = property(_GetFileGuid) | |
716 | Version = property(_GetVersion) | |
717 | DscSpecification = property(_GetDscSpec) | |
718 | OutputDirectory = property(_GetOutpuDir) | |
719 | SupArchList = property(_GetSupArch) | |
720 | BuildTargets = property(_GetBuildTarget) | |
721 | SkuName = property(_GetSkuName, _SetSkuName) | |
722 | FlashDefinition = property(_GetFdfFile) | |
723 | BuildNumber = property(_GetBuildNumber) | |
724 | MakefileName = property(_GetMakefileName) | |
725 | BsBaseAddress = property(_GetBsBaseAddress) | |
726 | RtBaseAddress = property(_GetRtBaseAddress) | |
727 | ||
728 | SkuIds = property(_GetSkuIds) | |
729 | Modules = property(_GetModules) | |
730 | LibraryInstances = property(_GetLibraryInstances) | |
731 | LibraryClasses = property(_GetLibraryClasses) | |
732 | Pcds = property(_GetPcds) | |
733 | BuildOptions = property(_GetBuildOptions) | |
734 | ||
735 | ## Platform build information from DSC file | |
736 | # | |
737 | # This class is used to retrieve information stored in database and convert them | |
738 | # into PackageBuildClassObject form for easier use for AutoGen. | |
739 | # | |
740 | class DecBuildData(PackageBuildClassObject): | |
741 | # dict used to convert PCD type in database to string used by build tool | |
742 | _PCD_TYPE_STRING_ = { | |
743 | MODEL_PCD_FIXED_AT_BUILD : "FixedAtBuild", | |
744 | MODEL_PCD_PATCHABLE_IN_MODULE : "PatchableInModule", | |
745 | MODEL_PCD_FEATURE_FLAG : "FeatureFlag", | |
746 | MODEL_PCD_DYNAMIC : "Dynamic", | |
747 | MODEL_PCD_DYNAMIC_DEFAULT : "Dynamic", | |
748 | MODEL_PCD_DYNAMIC_HII : "DynamicHii", | |
749 | MODEL_PCD_DYNAMIC_VPD : "DynamicVpd", | |
750 | MODEL_PCD_DYNAMIC_EX : "DynamicEx", | |
751 | MODEL_PCD_DYNAMIC_EX_DEFAULT : "DynamicEx", | |
752 | MODEL_PCD_DYNAMIC_EX_HII : "DynamicExHii", | |
753 | MODEL_PCD_DYNAMIC_EX_VPD : "DynamicExVpd", | |
754 | } | |
755 | ||
756 | # dict used to convert part of [Defines] to members of DecBuildData directly | |
757 | _PROPERTY_ = { | |
758 | # | |
759 | # Required Fields | |
760 | # | |
761 | TAB_DEC_DEFINES_PACKAGE_NAME : "_PackageName", | |
762 | TAB_DEC_DEFINES_PACKAGE_GUID : "_Guid", | |
763 | TAB_DEC_DEFINES_PACKAGE_VERSION : "_Version", | |
764 | } | |
765 | ||
766 | ||
767 | ## Constructor of DecBuildData | |
768 | # | |
769 | # Initialize object of DecBuildData | |
770 | # | |
771 | # @param FilePath The path of package description file | |
772 | # @param RawData The raw data of DEC file | |
773 | # @param BuildDataBase Database used to retrieve module information | |
774 | # @param Arch The target architecture | |
775 | # @param Platform (not used for DecBuildData) | |
776 | # @param Macros Macros used for replacement in DSC file | |
777 | # | |
778 | def __init__(self, File, RawData, BuildDataBase, Arch='COMMON', Platform='DUMMY', Macros={}): | |
779 | self.MetaFile = File | |
780 | self._PackageDir = File.Dir | |
781 | self._RawData = RawData | |
782 | self._Bdb = BuildDataBase | |
783 | self._Arch = Arch | |
784 | self._Macros = Macros | |
785 | self._Clear() | |
786 | ||
787 | ## XXX[key] = value | |
788 | def __setitem__(self, key, value): | |
789 | self.__dict__[self._PROPERTY_[key]] = value | |
790 | ||
791 | ## value = XXX[key] | |
792 | def __getitem__(self, key): | |
793 | return self.__dict__[self._PROPERTY_[key]] | |
794 | ||
795 | ## "in" test support | |
796 | def __contains__(self, key): | |
797 | return key in self._PROPERTY_ | |
798 | ||
799 | ## Set all internal used members of DecBuildData to None | |
800 | def _Clear(self): | |
801 | self._Header = None | |
802 | self._PackageName = None | |
803 | self._Guid = None | |
804 | self._Version = None | |
805 | self._Protocols = None | |
806 | self._Ppis = None | |
807 | self._Guids = None | |
808 | self._Includes = None | |
809 | self._LibraryClasses = None | |
810 | self._Pcds = None | |
811 | ||
812 | ## Get architecture | |
813 | def _GetArch(self): | |
814 | return self._Arch | |
815 | ||
816 | ## Set architecture | |
817 | # | |
818 | # Changing the default ARCH to another may affect all other information | |
819 | # because all information in a platform may be ARCH-related. That's | |
820 | # why we need to clear all internal used members, in order to cause all | |
821 | # information to be re-retrieved. | |
822 | # | |
823 | # @param Value The value of ARCH | |
824 | # | |
825 | def _SetArch(self, Value): | |
826 | if self._Arch == Value: | |
827 | return | |
828 | self._Arch = Value | |
829 | self._Clear() | |
830 | ||
831 | ## Retrieve all information in [Defines] section | |
832 | # | |
833 | # (Retriving all [Defines] information in one-shot is just to save time.) | |
834 | # | |
835 | def _GetHeaderInfo(self): | |
836 | RecordList = self._RawData[MODEL_META_DATA_HEADER] | |
837 | for Record in RecordList: | |
838 | Name = Record[0] | |
839 | if Name in self: | |
840 | self[Name] = Record[1] | |
841 | self._Header = 'DUMMY' | |
842 | ||
843 | ## Retrieve package name | |
844 | def _GetPackageName(self): | |
845 | if self._PackageName == None: | |
846 | if self._Header == None: | |
847 | self._GetHeaderInfo() | |
848 | if self._PackageName == None: | |
849 | EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, "No PACKAGE_NAME", File=self.MetaFile) | |
850 | return self._PackageName | |
851 | ||
852 | ## Retrieve file guid | |
853 | def _GetFileGuid(self): | |
854 | if self._Guid == None: | |
855 | if self._Header == None: | |
856 | self._GetHeaderInfo() | |
857 | if self._Guid == None: | |
858 | EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, "No PACKAGE_GUID", File=self.MetaFile) | |
859 | return self._Guid | |
860 | ||
861 | ## Retrieve package version | |
862 | def _GetVersion(self): | |
863 | if self._Version == None: | |
864 | if self._Header == None: | |
865 | self._GetHeaderInfo() | |
866 | if self._Version == None: | |
867 | self._Version = '' | |
868 | return self._Version | |
869 | ||
870 | ## Retrieve protocol definitions (name/value pairs) | |
871 | def _GetProtocol(self): | |
872 | if self._Protocols == None: | |
873 | # | |
874 | # tdict is a special kind of dict, used for selecting correct | |
875 | # protocol defition for given ARCH | |
876 | # | |
877 | ProtocolDict = tdict(True) | |
878 | NameList = [] | |
879 | # find out all protocol definitions for specific and 'common' arch | |
880 | RecordList = self._RawData[MODEL_EFI_PROTOCOL, self._Arch] | |
881 | for Name, Guid, Dummy, Arch, ID, LineNo in RecordList: | |
882 | if Name not in NameList: | |
883 | NameList.append(Name) | |
884 | ProtocolDict[Arch, Name] = Guid | |
885 | # use sdict to keep the order | |
886 | self._Protocols = sdict() | |
887 | for Name in NameList: | |
888 | # | |
889 | # limit the ARCH to self._Arch, if no self._Arch found, tdict | |
890 | # will automatically turn to 'common' ARCH for trying | |
891 | # | |
892 | self._Protocols[Name] = ProtocolDict[self._Arch, Name] | |
893 | return self._Protocols | |
894 | ||
895 | ## Retrieve PPI definitions (name/value pairs) | |
896 | def _GetPpi(self): | |
897 | if self._Ppis == None: | |
898 | # | |
899 | # tdict is a special kind of dict, used for selecting correct | |
900 | # PPI defition for given ARCH | |
901 | # | |
902 | PpiDict = tdict(True) | |
903 | NameList = [] | |
904 | # find out all PPI definitions for specific arch and 'common' arch | |
905 | RecordList = self._RawData[MODEL_EFI_PPI, self._Arch] | |
906 | for Name, Guid, Dummy, Arch, ID, LineNo in RecordList: | |
907 | if Name not in NameList: | |
908 | NameList.append(Name) | |
909 | PpiDict[Arch, Name] = Guid | |
910 | # use sdict to keep the order | |
911 | self._Ppis = sdict() | |
912 | for Name in NameList: | |
913 | # | |
914 | # limit the ARCH to self._Arch, if no self._Arch found, tdict | |
915 | # will automatically turn to 'common' ARCH for trying | |
916 | # | |
917 | self._Ppis[Name] = PpiDict[self._Arch, Name] | |
918 | return self._Ppis | |
919 | ||
920 | ## Retrieve GUID definitions (name/value pairs) | |
921 | def _GetGuid(self): | |
922 | if self._Guids == None: | |
923 | # | |
924 | # tdict is a special kind of dict, used for selecting correct | |
925 | # GUID defition for given ARCH | |
926 | # | |
927 | GuidDict = tdict(True) | |
928 | NameList = [] | |
929 | # find out all protocol definitions for specific and 'common' arch | |
930 | RecordList = self._RawData[MODEL_EFI_GUID, self._Arch] | |
931 | for Name, Guid, Dummy, Arch, ID, LineNo in RecordList: | |
932 | if Name not in NameList: | |
933 | NameList.append(Name) | |
934 | GuidDict[Arch, Name] = Guid | |
935 | # use sdict to keep the order | |
936 | self._Guids = sdict() | |
937 | for Name in NameList: | |
938 | # | |
939 | # limit the ARCH to self._Arch, if no self._Arch found, tdict | |
940 | # will automatically turn to 'common' ARCH for trying | |
941 | # | |
942 | self._Guids[Name] = GuidDict[self._Arch, Name] | |
943 | return self._Guids | |
944 | ||
945 | ## Retrieve public include paths declared in this package | |
946 | def _GetInclude(self): | |
947 | if self._Includes == None: | |
948 | self._Includes = [] | |
949 | RecordList = self._RawData[MODEL_EFI_INCLUDE, self._Arch] | |
950 | Macros = {"EDK_SOURCE":GlobalData.gEcpSource, "EFI_SOURCE":GlobalData.gEfiSource} | |
951 | Macros.update(self._Macros) | |
952 | for Record in RecordList: | |
953 | File = PathClass(NormPath(Record[0], Macros), self._PackageDir, Arch=self._Arch) | |
954 | LineNo = Record[-1] | |
955 | # validate the path | |
956 | ErrorCode, ErrorInfo = File.Validate() | |
957 | if ErrorCode != 0: | |
958 | EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo, File=self.MetaFile, Line=LineNo) | |
959 | ||
960 | # avoid duplicate include path | |
961 | if File not in self._Includes: | |
962 | self._Includes.append(File) | |
963 | return self._Includes | |
964 | ||
965 | ## Retrieve library class declarations (not used in build at present) | |
966 | def _GetLibraryClass(self): | |
967 | if self._LibraryClasses == None: | |
968 | # | |
969 | # tdict is a special kind of dict, used for selecting correct | |
970 | # library class declaration for given ARCH | |
971 | # | |
972 | LibraryClassDict = tdict(True) | |
973 | LibraryClassSet = set() | |
974 | RecordList = self._RawData[MODEL_EFI_LIBRARY_CLASS, self._Arch] | |
975 | Macros = {"EDK_SOURCE":GlobalData.gEcpSource, "EFI_SOURCE":GlobalData.gEfiSource} | |
976 | Macros.update(self._Macros) | |
977 | for LibraryClass, File, Dummy, Arch, ID, LineNo in RecordList: | |
978 | File = PathClass(NormPath(File, Macros), self._PackageDir, Arch=self._Arch) | |
979 | # check the file validation | |
980 | ErrorCode, ErrorInfo = File.Validate() | |
981 | if ErrorCode != 0: | |
982 | EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo, File=self.MetaFile, Line=LineNo) | |
983 | LibraryClassSet.add(LibraryClass) | |
984 | LibraryClassDict[Arch, LibraryClass] = File | |
985 | self._LibraryClasses = sdict() | |
986 | for LibraryClass in LibraryClassSet: | |
987 | self._LibraryClasses[LibraryClass] = LibraryClassDict[self._Arch, LibraryClass] | |
988 | return self._LibraryClasses | |
989 | ||
990 | ## Retrieve PCD declarations | |
991 | def _GetPcds(self): | |
992 | if self._Pcds == None: | |
993 | self._Pcds = {} | |
994 | self._Pcds.update(self._GetPcd(MODEL_PCD_FIXED_AT_BUILD)) | |
995 | self._Pcds.update(self._GetPcd(MODEL_PCD_PATCHABLE_IN_MODULE)) | |
996 | self._Pcds.update(self._GetPcd(MODEL_PCD_FEATURE_FLAG)) | |
997 | self._Pcds.update(self._GetPcd(MODEL_PCD_DYNAMIC)) | |
998 | self._Pcds.update(self._GetPcd(MODEL_PCD_DYNAMIC_EX)) | |
999 | return self._Pcds | |
1000 | ||
1001 | ## Retrieve PCD declarations for given type | |
1002 | def _GetPcd(self, Type): | |
1003 | Pcds = {} | |
1004 | # | |
1005 | # tdict is a special kind of dict, used for selecting correct | |
1006 | # PCD declaration for given ARCH | |
1007 | # | |
1008 | PcdDict = tdict(True, 3) | |
1009 | # for summarizing PCD | |
1010 | PcdSet = set() | |
1011 | # find out all PCDs of the 'type' | |
1012 | RecordList = self._RawData[Type, self._Arch] | |
1013 | for TokenSpaceGuid, PcdCName, Setting, Arch, Dummy1, Dummy2 in RecordList: | |
1014 | PcdDict[Arch, PcdCName, TokenSpaceGuid] = Setting | |
1015 | PcdSet.add((PcdCName, TokenSpaceGuid)) | |
1016 | ||
1017 | for PcdCName, TokenSpaceGuid in PcdSet: | |
1018 | ValueList = ['', '', ''] | |
1019 | # | |
1020 | # limit the ARCH to self._Arch, if no self._Arch found, tdict | |
1021 | # will automatically turn to 'common' ARCH and try again | |
1022 | # | |
1023 | Setting = PcdDict[self._Arch, PcdCName, TokenSpaceGuid] | |
1024 | if Setting == None: | |
1025 | continue | |
1026 | TokenList = Setting.split(TAB_VALUE_SPLIT) | |
1027 | ValueList[0:len(TokenList)] = TokenList | |
1028 | DefaultValue, DatumType, TokenNumber = ValueList | |
1029 | Pcds[PcdCName, TokenSpaceGuid, self._PCD_TYPE_STRING_[Type]] = PcdClassObject( | |
1030 | PcdCName, | |
1031 | TokenSpaceGuid, | |
1032 | self._PCD_TYPE_STRING_[Type], | |
1033 | DatumType, | |
1034 | DefaultValue, | |
1035 | TokenNumber, | |
1036 | '', | |
1037 | {}, | |
1038 | None | |
1039 | ) | |
1040 | return Pcds | |
1041 | ||
1042 | ||
1043 | Arch = property(_GetArch, _SetArch) | |
1044 | PackageName = property(_GetPackageName) | |
1045 | Guid = property(_GetFileGuid) | |
1046 | Version = property(_GetVersion) | |
1047 | ||
1048 | Protocols = property(_GetProtocol) | |
1049 | Ppis = property(_GetPpi) | |
1050 | Guids = property(_GetGuid) | |
1051 | Includes = property(_GetInclude) | |
1052 | LibraryClasses = property(_GetLibraryClass) | |
1053 | Pcds = property(_GetPcds) | |
1054 | ||
1055 | ## Module build information from INF file | |
1056 | # | |
1057 | # This class is used to retrieve information stored in database and convert them | |
1058 | # into ModuleBuildClassObject form for easier use for AutoGen. | |
1059 | # | |
1060 | class InfBuildData(ModuleBuildClassObject): | |
1061 | # dict used to convert PCD type in database to string used by build tool | |
1062 | _PCD_TYPE_STRING_ = { | |
1063 | MODEL_PCD_FIXED_AT_BUILD : "FixedAtBuild", | |
1064 | MODEL_PCD_PATCHABLE_IN_MODULE : "PatchableInModule", | |
1065 | MODEL_PCD_FEATURE_FLAG : "FeatureFlag", | |
1066 | MODEL_PCD_DYNAMIC : "Dynamic", | |
1067 | MODEL_PCD_DYNAMIC_DEFAULT : "Dynamic", | |
1068 | MODEL_PCD_DYNAMIC_HII : "DynamicHii", | |
1069 | MODEL_PCD_DYNAMIC_VPD : "DynamicVpd", | |
1070 | MODEL_PCD_DYNAMIC_EX : "DynamicEx", | |
1071 | MODEL_PCD_DYNAMIC_EX_DEFAULT : "DynamicEx", | |
1072 | MODEL_PCD_DYNAMIC_EX_HII : "DynamicExHii", | |
1073 | MODEL_PCD_DYNAMIC_EX_VPD : "DynamicExVpd", | |
1074 | } | |
1075 | ||
1076 | # dict used to convert part of [Defines] to members of InfBuildData directly | |
1077 | _PROPERTY_ = { | |
1078 | # | |
1079 | # Required Fields | |
1080 | # | |
1081 | TAB_INF_DEFINES_BASE_NAME : "_BaseName", | |
1082 | TAB_INF_DEFINES_FILE_GUID : "_Guid", | |
1083 | TAB_INF_DEFINES_MODULE_TYPE : "_ModuleType", | |
1084 | # | |
1085 | # Optional Fields | |
1086 | # | |
1087 | TAB_INF_DEFINES_INF_VERSION : "_AutoGenVersion", | |
1088 | TAB_INF_DEFINES_COMPONENT_TYPE : "_ComponentType", | |
1089 | TAB_INF_DEFINES_MAKEFILE_NAME : "_MakefileName", | |
1090 | #TAB_INF_DEFINES_CUSTOM_MAKEFILE : "_CustomMakefile", | |
1091 | TAB_INF_DEFINES_VERSION_NUMBER : "_Version", | |
1092 | TAB_INF_DEFINES_VERSION_STRING : "_Version", | |
1093 | TAB_INF_DEFINES_VERSION : "_Version", | |
1094 | TAB_INF_DEFINES_PCD_IS_DRIVER : "_PcdIsDriver", | |
1095 | TAB_INF_DEFINES_SHADOW : "_Shadow", | |
1096 | ||
1097 | TAB_COMPONENTS_SOURCE_OVERRIDE_PATH : "_SourceOverridePath", | |
1098 | } | |
1099 | ||
1100 | # dict used to convert Component type to Module type | |
1101 | _MODULE_TYPE_ = { | |
1102 | "LIBRARY" : "BASE", | |
1103 | "SECURITY_CORE" : "SEC", | |
1104 | "PEI_CORE" : "PEI_CORE", | |
1105 | "COMBINED_PEIM_DRIVER" : "PEIM", | |
1106 | "PIC_PEIM" : "PEIM", | |
1107 | "RELOCATABLE_PEIM" : "PEIM", | |
1108 | "PE32_PEIM" : "PEIM", | |
1109 | "BS_DRIVER" : "DXE_DRIVER", | |
1110 | "RT_DRIVER" : "DXE_RUNTIME_DRIVER", | |
1111 | "SAL_RT_DRIVER" : "DXE_SAL_DRIVER", | |
1112 | # "BS_DRIVER" : "DXE_SMM_DRIVER", | |
1113 | # "BS_DRIVER" : "UEFI_DRIVER", | |
1114 | "APPLICATION" : "UEFI_APPLICATION", | |
1115 | "LOGO" : "BASE", | |
1116 | } | |
1117 | ||
1118 | # regular expression for converting XXX_FLAGS in [nmake] section to new type | |
1119 | _NMAKE_FLAG_PATTERN_ = re.compile("(?:EBC_)?([A-Z]+)_(?:STD_|PROJ_|ARCH_)?FLAGS(?:_DLL|_ASL|_EXE)?", re.UNICODE) | |
1120 | # dict used to convert old tool name used in [nmake] section to new ones | |
1121 | _TOOL_CODE_ = { | |
1122 | "C" : "CC", | |
1123 | "LIB" : "SLINK", | |
1124 | "LINK" : "DLINK", | |
1125 | } | |
1126 | ||
1127 | ||
1128 | ## Constructor of DscBuildData | |
1129 | # | |
1130 | # Initialize object of DscBuildData | |
1131 | # | |
1132 | # @param FilePath The path of platform description file | |
1133 | # @param RawData The raw data of DSC file | |
1134 | # @param BuildDataBase Database used to retrieve module/package information | |
1135 | # @param Arch The target architecture | |
1136 | # @param Platform The name of platform employing this module | |
1137 | # @param Macros Macros used for replacement in DSC file | |
1138 | # | |
1139 | def __init__(self, FilePath, RawData, BuildDatabase, Arch='COMMON', Platform='COMMON', Macros={}): | |
1140 | self.MetaFile = FilePath | |
1141 | self._ModuleDir = FilePath.Dir | |
1142 | self._RawData = RawData | |
1143 | self._Bdb = BuildDatabase | |
1144 | self._Arch = Arch | |
1145 | self._Platform = 'COMMON' | |
1146 | self._Macros = Macros | |
1147 | self._SourceOverridePath = None | |
1148 | if FilePath.Key in GlobalData.gOverrideDir: | |
1149 | self._SourceOverridePath = GlobalData.gOverrideDir[FilePath.Key] | |
1150 | self._Clear() | |
1151 | ||
1152 | ## XXX[key] = value | |
1153 | def __setitem__(self, key, value): | |
1154 | self.__dict__[self._PROPERTY_[key]] = value | |
1155 | ||
1156 | ## value = XXX[key] | |
1157 | def __getitem__(self, key): | |
1158 | return self.__dict__[self._PROPERTY_[key]] | |
1159 | ||
1160 | ## "in" test support | |
1161 | def __contains__(self, key): | |
1162 | return key in self._PROPERTY_ | |
1163 | ||
1164 | ## Set all internal used members of InfBuildData to None | |
1165 | def _Clear(self): | |
1166 | self._Header_ = None | |
1167 | self._AutoGenVersion = None | |
1168 | self._BaseName = None | |
1169 | self._ModuleType = None | |
1170 | self._ComponentType = None | |
1171 | self._BuildType = None | |
1172 | self._Guid = None | |
1173 | self._Version = None | |
1174 | self._PcdIsDriver = None | |
1175 | self._BinaryModule = None | |
1176 | self._Shadow = None | |
1177 | self._MakefileName = None | |
1178 | self._CustomMakefile = None | |
1179 | self._Specification = None | |
1180 | self._LibraryClass = None | |
1181 | self._ModuleEntryPointList = None | |
1182 | self._ModuleUnloadImageList = None | |
1183 | self._ConstructorList = None | |
1184 | self._DestructorList = None | |
1185 | self._Defs = None | |
1186 | self._Binaries = None | |
1187 | self._Sources = None | |
1188 | self._LibraryClasses = None | |
1189 | self._Libraries = None | |
1190 | self._Protocols = None | |
1191 | self._Ppis = None | |
1192 | self._Guids = None | |
1193 | self._Includes = None | |
1194 | self._Packages = None | |
1195 | self._Pcds = None | |
1196 | self._BuildOptions = None | |
1197 | self._Depex = None | |
1198 | #self._SourceOverridePath = None | |
1199 | ||
1200 | ## Get architecture | |
1201 | def _GetArch(self): | |
1202 | return self._Arch | |
1203 | ||
1204 | ## Set architecture | |
1205 | # | |
1206 | # Changing the default ARCH to another may affect all other information | |
1207 | # because all information in a platform may be ARCH-related. That's | |
1208 | # why we need to clear all internal used members, in order to cause all | |
1209 | # information to be re-retrieved. | |
1210 | # | |
1211 | # @param Value The value of ARCH | |
1212 | # | |
1213 | def _SetArch(self, Value): | |
1214 | if self._Arch == Value: | |
1215 | return | |
1216 | self._Arch = Value | |
1217 | self._Clear() | |
1218 | ||
1219 | ## Return the name of platform employing this module | |
1220 | def _GetPlatform(self): | |
1221 | return self._Platform | |
1222 | ||
1223 | ## Change the name of platform employing this module | |
1224 | # | |
1225 | # Changing the default name of platform to another may affect some information | |
1226 | # because they may be PLATFORM-related. That's why we need to clear all internal | |
1227 | # used members, in order to cause all information to be re-retrieved. | |
1228 | # | |
1229 | def _SetPlatform(self, Value): | |
1230 | if self._Platform == Value: | |
1231 | return | |
1232 | self._Platform = Value | |
1233 | self._Clear() | |
1234 | ||
1235 | ## Retrieve all information in [Defines] section | |
1236 | # | |
1237 | # (Retriving all [Defines] information in one-shot is just to save time.) | |
1238 | # | |
1239 | def _GetHeaderInfo(self): | |
1240 | RecordList = self._RawData[MODEL_META_DATA_HEADER, self._Arch, self._Platform] | |
1241 | for Record in RecordList: | |
1242 | Record = ReplaceMacros(Record, GlobalData.gEdkGlobal, False) | |
1243 | Name = Record[0] | |
1244 | # items defined _PROPERTY_ don't need additional processing | |
1245 | if Name in self: | |
1246 | self[Name] = Record[1] | |
1247 | # some special items in [Defines] section need special treatment | |
1248 | elif Name == 'EFI_SPECIFICATION_VERSION': | |
1249 | if self._Specification == None: | |
1250 | self._Specification = sdict() | |
1251 | self._Specification[Name] = Record[1] | |
1252 | elif Name == 'EDK_RELEASE_VERSION': | |
1253 | if self._Specification == None: | |
1254 | self._Specification = sdict() | |
1255 | self._Specification[Name] = Record[1] | |
1256 | elif Name == 'PI_SPECIFICATION_VERSION': | |
1257 | if self._Specification == None: | |
1258 | self._Specification = sdict() | |
1259 | self._Specification[Name] = Record[1] | |
1260 | elif Name == 'LIBRARY_CLASS': | |
1261 | if self._LibraryClass == None: | |
1262 | self._LibraryClass = [] | |
1263 | ValueList = GetSplitValueList(Record[1]) | |
1264 | LibraryClass = ValueList[0] | |
1265 | if len(ValueList) > 1: | |
1266 | SupModuleList = GetSplitValueList(ValueList[1], ' ') | |
1267 | else: | |
1268 | SupModuleList = SUP_MODULE_LIST | |
1269 | self._LibraryClass.append(LibraryClassObject(LibraryClass, SupModuleList)) | |
1270 | elif Name == 'ENTRY_POINT': | |
1271 | if self._ModuleEntryPointList == None: | |
1272 | self._ModuleEntryPointList = [] | |
1273 | self._ModuleEntryPointList.append(Record[1]) | |
1274 | elif Name == 'UNLOAD_IMAGE': | |
1275 | if self._ModuleUnloadImageList == None: | |
1276 | self._ModuleUnloadImageList = [] | |
1277 | if Record[1] == '': | |
1278 | continue | |
1279 | self._ModuleUnloadImageList.append(Record[1]) | |
1280 | elif Name == 'CONSTRUCTOR': | |
1281 | if self._ConstructorList == None: | |
1282 | self._ConstructorList = [] | |
1283 | if Record[1] == '': | |
1284 | continue | |
1285 | self._ConstructorList.append(Record[1]) | |
1286 | elif Name == 'DESTRUCTOR': | |
1287 | if self._DestructorList == None: | |
1288 | self._DestructorList = [] | |
1289 | if Record[1] == '': | |
1290 | continue | |
1291 | self._DestructorList.append(Record[1]) | |
1292 | elif Name == TAB_INF_DEFINES_CUSTOM_MAKEFILE: | |
1293 | TokenList = GetSplitValueList(Record[1]) | |
1294 | if self._CustomMakefile == None: | |
1295 | self._CustomMakefile = {} | |
1296 | if len(TokenList) < 2: | |
1297 | self._CustomMakefile['MSFT'] = TokenList[0] | |
1298 | self._CustomMakefile['GCC'] = TokenList[0] | |
1299 | else: | |
1300 | if TokenList[0] not in ['MSFT', 'GCC']: | |
1301 | EdkLogger.error("build", FORMAT_NOT_SUPPORTED, | |
1302 | "No supported family [%s]" % TokenList[0], | |
1303 | File=self.MetaFile, Line=Record[-1]) | |
1304 | self._CustomMakefile[TokenList[0]] = TokenList[1] | |
1305 | else: | |
1306 | if self._Defs == None: | |
1307 | self._Defs = sdict() | |
1308 | self._Defs[Name] = Record[1] | |
1309 | ||
1310 | # | |
1311 | # Retrieve information in sections specific to R8.x modules | |
1312 | # | |
1313 | if self._AutoGenVersion >= 0x00010005: # _AutoGenVersion may be None, which is less than anything | |
1314 | if not self._ModuleType: | |
1315 | EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, | |
1316 | "MODULE_TYPE is not given", File=self.MetaFile) | |
1317 | if self._Defs and 'PCI_DEVICE_ID' in self._Defs and 'PCI_VENDOR_ID' in self._Defs \ | |
1318 | and 'PCI_CLASS_CODE' in self._Defs: | |
1319 | self._BuildType = 'UEFI_OPTIONROM' | |
1320 | else: | |
1321 | self._BuildType = self._ModuleType.upper() | |
1322 | else: | |
1323 | self._BuildType = self._ComponentType.upper() | |
1324 | if not self._ComponentType: | |
1325 | EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, | |
1326 | "COMPONENT_TYPE is not given", File=self.MetaFile) | |
1327 | if self._ComponentType in self._MODULE_TYPE_: | |
1328 | self._ModuleType = self._MODULE_TYPE_[self._ComponentType] | |
1329 | if self._ComponentType == 'LIBRARY': | |
1330 | self._LibraryClass = [LibraryClassObject(self._BaseName, SUP_MODULE_LIST)] | |
1331 | # make use some [nmake] section macros | |
1332 | RecordList = self._RawData[MODEL_META_DATA_NMAKE, self._Arch, self._Platform] | |
1333 | for Name,Value,Dummy,Arch,Platform,ID,LineNo in RecordList: | |
1334 | Value = Value.replace('$(PROCESSOR)', self._Arch) | |
1335 | Name = Name.replace('$(PROCESSOR)', self._Arch) | |
1336 | Name, Value = ReplaceMacros((Name, Value), GlobalData.gEdkGlobal, True) | |
1337 | if Name == "IMAGE_ENTRY_POINT": | |
1338 | if self._ModuleEntryPointList == None: | |
1339 | self._ModuleEntryPointList = [] | |
1340 | self._ModuleEntryPointList.append(Value) | |
1341 | elif Name == "DPX_SOURCE": | |
1342 | Macros = {"EDK_SOURCE":GlobalData.gEcpSource, "EFI_SOURCE":GlobalData.gEfiSource} | |
1343 | Macros.update(self._Macros) | |
1344 | File = PathClass(NormPath(Value, Macros), self._ModuleDir, Arch=self._Arch) | |
1345 | # check the file validation | |
1346 | ErrorCode, ErrorInfo = File.Validate(".dxs", CaseSensitive=False) | |
1347 | if ErrorCode != 0: | |
1348 | EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo, | |
1349 | File=self.MetaFile, Line=LineNo) | |
1350 | if self.Sources == None: | |
1351 | self._Sources = [] | |
1352 | self._Sources.append(File) | |
1353 | else: | |
1354 | ToolList = self._NMAKE_FLAG_PATTERN_.findall(Name) | |
1355 | if len(ToolList) == 0 or len(ToolList) != 1: | |
1356 | pass | |
1357 | # EdkLogger.warn("build", "Don't know how to do with macro [%s]" % Name, | |
1358 | # File=self.MetaFile, Line=LineNo) | |
1359 | else: | |
1360 | if self._BuildOptions == None: | |
1361 | self._BuildOptions = sdict() | |
1362 | ||
1363 | if ToolList[0] in self._TOOL_CODE_: | |
1364 | Tool = self._TOOL_CODE_[ToolList[0]] | |
1365 | else: | |
1366 | Tool = ToolList[0] | |
1367 | ToolChain = "*_*_*_%s_FLAGS" % Tool | |
1368 | ToolChainFamily = 'MSFT' # R8.x only support MSFT tool chain | |
1369 | #ignore not replaced macros in value | |
1370 | ValueList = GetSplitValueList(' ' + Value, '/D') | |
1371 | Dummy = ValueList[0] | |
1372 | for Index in range(1, len(ValueList)): | |
1373 | if ValueList[Index][-1] == '=' or ValueList[Index] == '': | |
1374 | continue | |
1375 | Dummy = Dummy + ' /D ' + ValueList[Index] | |
1376 | Value = Dummy.strip() | |
1377 | if (ToolChainFamily, ToolChain) not in self._BuildOptions: | |
1378 | self._BuildOptions[ToolChainFamily, ToolChain] = Value | |
1379 | else: | |
1380 | OptionString = self._BuildOptions[ToolChainFamily, ToolChain] | |
1381 | self._BuildOptions[ToolChainFamily, ToolChain] = OptionString + " " + Value | |
1382 | # set _Header to non-None in order to avoid database re-querying | |
1383 | self._Header_ = 'DUMMY' | |
1384 | ||
1385 | ## Retrieve file version | |
1386 | def _GetInfVersion(self): | |
1387 | if self._AutoGenVersion == None: | |
1388 | if self._Header_ == None: | |
1389 | self._GetHeaderInfo() | |
1390 | if self._AutoGenVersion == None: | |
1391 | self._AutoGenVersion = 0x00010000 | |
1392 | return self._AutoGenVersion | |
1393 | ||
1394 | ## Retrieve BASE_NAME | |
1395 | def _GetBaseName(self): | |
1396 | if self._BaseName == None: | |
1397 | if self._Header_ == None: | |
1398 | self._GetHeaderInfo() | |
1399 | if self._BaseName == None: | |
1400 | EdkLogger.error('build', ATTRIBUTE_NOT_AVAILABLE, "No BASE_NAME name", File=self.MetaFile) | |
1401 | return self._BaseName | |
1402 | ||
1403 | ## Retrieve MODULE_TYPE | |
1404 | def _GetModuleType(self): | |
1405 | if self._ModuleType == None: | |
1406 | if self._Header_ == None: | |
1407 | self._GetHeaderInfo() | |
1408 | if self._ModuleType == None: | |
1409 | self._ModuleType = 'BASE' | |
1410 | if self._ModuleType not in SUP_MODULE_LIST: | |
1411 | self._ModuleType = "USER_DEFINED" | |
1412 | return self._ModuleType | |
1413 | ||
1414 | ## Retrieve COMPONENT_TYPE | |
1415 | def _GetComponentType(self): | |
1416 | if self._ComponentType == None: | |
1417 | if self._Header_ == None: | |
1418 | self._GetHeaderInfo() | |
1419 | if self._ComponentType == None: | |
1420 | self._ComponentType = 'USER_DEFINED' | |
1421 | return self._ComponentType | |
1422 | ||
1423 | ## Retrieve "BUILD_TYPE" | |
1424 | def _GetBuildType(self): | |
1425 | if self._BuildType == None: | |
1426 | if self._Header_ == None: | |
1427 | self._GetHeaderInfo() | |
1428 | if not self._BuildType: | |
1429 | self._BuildType = "BASE" | |
1430 | return self._BuildType | |
1431 | ||
1432 | ## Retrieve file guid | |
1433 | def _GetFileGuid(self): | |
1434 | if self._Guid == None: | |
1435 | if self._Header_ == None: | |
1436 | self._GetHeaderInfo() | |
1437 | if self._Guid == None: | |
1438 | self._Guid = '00000000-0000-0000-000000000000' | |
1439 | return self._Guid | |
1440 | ||
1441 | ## Retrieve module version | |
1442 | def _GetVersion(self): | |
1443 | if self._Version == None: | |
1444 | if self._Header_ == None: | |
1445 | self._GetHeaderInfo() | |
1446 | if self._Version == None: | |
1447 | self._Version = '0.0' | |
1448 | return self._Version | |
1449 | ||
1450 | ## Retrieve PCD_IS_DRIVER | |
1451 | def _GetPcdIsDriver(self): | |
1452 | if self._PcdIsDriver == None: | |
1453 | if self._Header_ == None: | |
1454 | self._GetHeaderInfo() | |
1455 | if self._PcdIsDriver == None: | |
1456 | self._PcdIsDriver = '' | |
1457 | return self._PcdIsDriver | |
1458 | ||
1459 | ## Retrieve SHADOW | |
1460 | def _GetShadow(self): | |
1461 | if self._Shadow == None: | |
1462 | if self._Header_ == None: | |
1463 | self._GetHeaderInfo() | |
1464 | if self._Shadow != None and self._Shadow.upper() == 'TRUE': | |
1465 | self._Shadow = True | |
1466 | else: | |
1467 | self._Shadow = False | |
1468 | return self._Shadow | |
1469 | ||
1470 | ## Retrieve CUSTOM_MAKEFILE | |
1471 | def _GetMakefile(self): | |
1472 | if self._CustomMakefile == None: | |
1473 | if self._Header_ == None: | |
1474 | self._GetHeaderInfo() | |
1475 | if self._CustomMakefile == None: | |
1476 | self._CustomMakefile = {} | |
1477 | return self._CustomMakefile | |
1478 | ||
1479 | ## Retrieve EFI_SPECIFICATION_VERSION | |
1480 | def _GetSpec(self): | |
1481 | if self._Specification == None: | |
1482 | if self._Header_ == None: | |
1483 | self._GetHeaderInfo() | |
1484 | if self._Specification == None: | |
1485 | self._Specification = {} | |
1486 | return self._Specification | |
1487 | ||
1488 | ## Retrieve LIBRARY_CLASS | |
1489 | def _GetLibraryClass(self): | |
1490 | if self._LibraryClass == None: | |
1491 | if self._Header_ == None: | |
1492 | self._GetHeaderInfo() | |
1493 | if self._LibraryClass == None: | |
1494 | self._LibraryClass = [] | |
1495 | return self._LibraryClass | |
1496 | ||
1497 | ## Retrieve ENTRY_POINT | |
1498 | def _GetEntryPoint(self): | |
1499 | if self._ModuleEntryPointList == None: | |
1500 | if self._Header_ == None: | |
1501 | self._GetHeaderInfo() | |
1502 | if self._ModuleEntryPointList == None: | |
1503 | self._ModuleEntryPointList = [] | |
1504 | return self._ModuleEntryPointList | |
1505 | ||
1506 | ## Retrieve UNLOAD_IMAGE | |
1507 | def _GetUnloadImage(self): | |
1508 | if self._ModuleUnloadImageList == None: | |
1509 | if self._Header_ == None: | |
1510 | self._GetHeaderInfo() | |
1511 | if self._ModuleUnloadImageList == None: | |
1512 | self._ModuleUnloadImageList = [] | |
1513 | return self._ModuleUnloadImageList | |
1514 | ||
1515 | ## Retrieve CONSTRUCTOR | |
1516 | def _GetConstructor(self): | |
1517 | if self._ConstructorList == None: | |
1518 | if self._Header_ == None: | |
1519 | self._GetHeaderInfo() | |
1520 | if self._ConstructorList == None: | |
1521 | self._ConstructorList = [] | |
1522 | return self._ConstructorList | |
1523 | ||
1524 | ## Retrieve DESTRUCTOR | |
1525 | def _GetDestructor(self): | |
1526 | if self._DestructorList == None: | |
1527 | if self._Header_ == None: | |
1528 | self._GetHeaderInfo() | |
1529 | if self._DestructorList == None: | |
1530 | self._DestructorList = [] | |
1531 | return self._DestructorList | |
1532 | ||
1533 | ## Retrieve definies other than above ones | |
1534 | def _GetDefines(self): | |
1535 | if self._Defs == None: | |
1536 | if self._Header_ == None: | |
1537 | self._GetHeaderInfo() | |
1538 | if self._Defs == None: | |
1539 | self._Defs = sdict() | |
1540 | return self._Defs | |
1541 | ||
1542 | ## Retrieve binary files | |
1543 | def _GetBinaryFiles(self): | |
1544 | if self._Binaries == None: | |
1545 | self._Binaries = [] | |
1546 | RecordList = self._RawData[MODEL_EFI_BINARY_FILE, self._Arch, self._Platform] | |
1547 | Macros = {"EDK_SOURCE":GlobalData.gEcpSource, "EFI_SOURCE":GlobalData.gEfiSource, 'PROCESSOR':self._Arch} | |
1548 | Macros.update(self._Macros) | |
1549 | for Record in RecordList: | |
1550 | Record = ReplaceMacros(Record, GlobalData.gEdkGlobal, False) | |
1551 | FileType = Record[0] | |
1552 | LineNo = Record[-1] | |
1553 | Target = 'COMMON' | |
1554 | FeatureFlag = [] | |
1555 | if Record[2]: | |
1556 | TokenList = GetSplitValueList(Record[2], TAB_VALUE_SPLIT) | |
1557 | if TokenList: | |
1558 | Target = TokenList[0] | |
1559 | if len(TokenList) > 1: | |
1560 | FeatureFlag = Record[1:] | |
1561 | ||
1562 | File = PathClass(NormPath(Record[1], Macros), self._ModuleDir, '', FileType, True, self._Arch, '', Target) | |
1563 | # check the file validation | |
1564 | ErrorCode, ErrorInfo = File.Validate() | |
1565 | if ErrorCode != 0: | |
1566 | EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo, File=self.MetaFile, Line=LineNo) | |
1567 | self._Binaries.append(File) | |
1568 | return self._Binaries | |
1569 | ||
1570 | ## Retrieve source files | |
1571 | def _GetSourceFiles(self): | |
1572 | if self._Sources == None: | |
1573 | self._Sources = [] | |
1574 | RecordList = self._RawData[MODEL_EFI_SOURCE_FILE, self._Arch, self._Platform] | |
1575 | Macros = {"EDK_SOURCE":GlobalData.gEcpSource, "EFI_SOURCE":GlobalData.gEfiSource, 'PROCESSOR':self._Arch} | |
1576 | Macros.update(self._Macros) | |
1577 | for Record in RecordList: | |
1578 | Record = ReplaceMacros(Record, GlobalData.gEdkGlobal, False) | |
1579 | LineNo = Record[-1] | |
1580 | ToolChainFamily = Record[1] | |
1581 | TagName = Record[2] | |
1582 | ToolCode = Record[3] | |
1583 | FeatureFlag = Record[4] | |
1584 | if self._AutoGenVersion < 0x00010005: | |
1585 | # old module source files (R8) | |
1586 | File = PathClass(NormPath(Record[0], Macros), self._ModuleDir, self._SourceOverridePath, | |
1587 | '', False, self._Arch, ToolChainFamily, '', TagName, ToolCode) | |
1588 | # check the file validation | |
1589 | ErrorCode, ErrorInfo = File.Validate(CaseSensitive=False) | |
1590 | if ErrorCode != 0: | |
1591 | if File.Ext.lower() == '.h': | |
1592 | EdkLogger.warn('build', 'Include file not found', ExtraData=ErrorInfo, | |
1593 | File=self.MetaFile, Line=LineNo) | |
1594 | continue | |
1595 | else: | |
1596 | EdkLogger.error('build', ErrorCode, ExtraData=File, File=self.MetaFile, Line=LineNo) | |
1597 | else: | |
1598 | File = PathClass(NormPath(Record[0], Macros), self._ModuleDir, '', | |
1599 | '', False, self._Arch, ToolChainFamily, '', TagName, ToolCode) | |
1600 | # check the file validation | |
1601 | ErrorCode, ErrorInfo = File.Validate() | |
1602 | if ErrorCode != 0: | |
1603 | EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo, File=self.MetaFile, Line=LineNo) | |
1604 | ||
1605 | self._Sources.append(File) | |
1606 | return self._Sources | |
1607 | ||
1608 | ## Retrieve library classes employed by this module | |
1609 | def _GetLibraryClassUses(self): | |
1610 | if self._LibraryClasses == None: | |
1611 | self._LibraryClasses = sdict() | |
1612 | RecordList = self._RawData[MODEL_EFI_LIBRARY_CLASS, self._Arch, self._Platform] | |
1613 | for Record in RecordList: | |
1614 | Record = ReplaceMacros(Record, GlobalData.gEdkGlobal, False) | |
1615 | Lib = Record[0] | |
1616 | Instance = Record[1] | |
1617 | if Instance != None and Instance != '': | |
1618 | Instance = NormPath(Instance, self._Macros) | |
1619 | self._LibraryClasses[Lib] = Instance | |
1620 | return self._LibraryClasses | |
1621 | ||
1622 | ## Retrieve library names (for R8.x style of modules) | |
1623 | def _GetLibraryNames(self): | |
1624 | if self._Libraries == None: | |
1625 | self._Libraries = [] | |
1626 | RecordList = self._RawData[MODEL_EFI_LIBRARY_INSTANCE, self._Arch, self._Platform] | |
1627 | for Record in RecordList: | |
1628 | # in case of name with '.lib' extension, which is unusual in R8.x inf | |
1629 | Record = ReplaceMacros(Record, GlobalData.gEdkGlobal, False) | |
1630 | LibraryName = os.path.splitext(Record[0])[0] | |
1631 | if LibraryName not in self._Libraries: | |
1632 | self._Libraries.append(LibraryName) | |
1633 | return self._Libraries | |
1634 | ||
1635 | ## Retrieve protocols consumed/produced by this module | |
1636 | def _GetProtocols(self): | |
1637 | if self._Protocols == None: | |
1638 | self._Protocols = sdict() | |
1639 | RecordList = self._RawData[MODEL_EFI_PROTOCOL, self._Arch, self._Platform] | |
1640 | for Record in RecordList: | |
1641 | CName = Record[0] | |
1642 | Value = ProtocolValue(CName, self.Packages) | |
1643 | if Value == None: | |
1644 | PackageList = "\n\t".join([str(P) for P in self.Packages]) | |
1645 | EdkLogger.error('build', RESOURCE_NOT_AVAILABLE, | |
1646 | "Value of Protocol [%s] is not found under [Protocols] section in" % CName, | |
1647 | ExtraData=PackageList, File=self.MetaFile, Line=Record[-1]) | |
1648 | self._Protocols[CName] = Value | |
1649 | return self._Protocols | |
1650 | ||
1651 | ## Retrieve PPIs consumed/produced by this module | |
1652 | def _GetPpis(self): | |
1653 | if self._Ppis == None: | |
1654 | self._Ppis = sdict() | |
1655 | RecordList = self._RawData[MODEL_EFI_PPI, self._Arch, self._Platform] | |
1656 | for Record in RecordList: | |
1657 | CName = Record[0] | |
1658 | Value = PpiValue(CName, self.Packages) | |
1659 | if Value == None: | |
1660 | PackageList = "\n\t".join([str(P) for P in self.Packages]) | |
1661 | EdkLogger.error('build', RESOURCE_NOT_AVAILABLE, | |
1662 | "Value of PPI [%s] is not found under [Ppis] section in " % CName, | |
1663 | ExtraData=PackageList, File=self.MetaFile, Line=Record[-1]) | |
1664 | self._Ppis[CName] = Value | |
1665 | return self._Ppis | |
1666 | ||
1667 | ## Retrieve GUIDs consumed/produced by this module | |
1668 | def _GetGuids(self): | |
1669 | if self._Guids == None: | |
1670 | self._Guids = sdict() | |
1671 | RecordList = self._RawData[MODEL_EFI_GUID, self._Arch, self._Platform] | |
1672 | for Record in RecordList: | |
1673 | CName = Record[0] | |
1674 | Value = GuidValue(CName, self.Packages) | |
1675 | if Value == None: | |
1676 | PackageList = "\n\t".join([str(P) for P in self.Packages]) | |
1677 | EdkLogger.error('build', RESOURCE_NOT_AVAILABLE, | |
1678 | "Value of Guid [%s] is not found under [Guids] section in" % CName, | |
1679 | ExtraData=PackageList, File=self.MetaFile, Line=Record[-1]) | |
1680 | self._Guids[CName] = Value | |
1681 | return self._Guids | |
1682 | ||
1683 | ## Retrieve include paths necessary for this module (for R8.x style of modules) | |
1684 | def _GetIncludes(self): | |
1685 | if self._Includes == None: | |
1686 | self._Includes = [] | |
1687 | if self._SourceOverridePath: | |
1688 | self._Includes.append(self._SourceOverridePath) | |
1689 | RecordList = self._RawData[MODEL_EFI_INCLUDE, self._Arch, self._Platform] | |
1690 | # [includes] section must be used only in old (R8.x) inf file | |
1691 | if self.AutoGenVersion >= 0x00010005 and len(RecordList) > 0: | |
1692 | EdkLogger.error('build', FORMAT_NOT_SUPPORTED, "No [include] section allowed", | |
1693 | File=self.MetaFile, Line=RecordList[0][-1]-1) | |
1694 | for Record in RecordList: | |
1695 | Record = ReplaceMacros(Record, GlobalData.gEdkGlobal, False) | |
1696 | Record[0] = Record[0].replace('$(PROCESSOR)', self._Arch) | |
1697 | Record[0] = ReplaceMacro(Record[0], {'EFI_SOURCE' : GlobalData.gEfiSource}, False) | |
1698 | if Record[0].find('EDK_SOURCE') > -1: | |
1699 | File = NormPath(ReplaceMacro(Record[0], {'EDK_SOURCE' : GlobalData.gEcpSource}, False), self._Macros) | |
1700 | if File[0] == '.': | |
1701 | File = os.path.join(self._ModuleDir, File) | |
1702 | else: | |
1703 | File = os.path.join(GlobalData.gWorkspace, File) | |
1704 | File = RealPath(os.path.normpath(File)) | |
1705 | if File: | |
1706 | self._Includes.append(File) | |
1707 | ||
1708 | #TRICK: let compiler to choose correct header file | |
1709 | File = NormPath(ReplaceMacro(Record[0], {'EDK_SOURCE' : GlobalData.gEdkSource}, False), self._Macros) | |
1710 | if File[0] == '.': | |
1711 | File = os.path.join(self._ModuleDir, File) | |
1712 | else: | |
1713 | File = os.path.join(GlobalData.gWorkspace, File) | |
1714 | File = RealPath(os.path.normpath(File)) | |
1715 | if File: | |
1716 | self._Includes.append(File) | |
1717 | else: | |
1718 | File = NormPath(Record[0], self._Macros) | |
1719 | if File[0] == '.': | |
1720 | File = os.path.join(self._ModuleDir, File) | |
1721 | else: | |
1722 | File = os.path.join(GlobalData.gWorkspace, File) | |
1723 | File = RealPath(os.path.normpath(File)) | |
1724 | if File: | |
1725 | self._Includes.append(File) | |
1726 | return self._Includes | |
1727 | ||
1728 | ## Retrieve packages this module depends on | |
1729 | def _GetPackages(self): | |
1730 | if self._Packages == None: | |
1731 | self._Packages = [] | |
1732 | RecordList = self._RawData[MODEL_META_DATA_PACKAGE, self._Arch, self._Platform] | |
1733 | Macros = {"EDK_SOURCE":GlobalData.gEcpSource, "EFI_SOURCE":GlobalData.gEfiSource} | |
1734 | Macros.update(self._Macros) | |
1735 | for Record in RecordList: | |
1736 | File = PathClass(NormPath(Record[0], Macros), GlobalData.gWorkspace, Arch=self._Arch) | |
1737 | LineNo = Record[-1] | |
1738 | # check the file validation | |
1739 | ErrorCode, ErrorInfo = File.Validate('.dec') | |
1740 | if ErrorCode != 0: | |
1741 | EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo, File=self.MetaFile, Line=LineNo) | |
1742 | # parse this package now. we need it to get protocol/ppi/guid value | |
1743 | Package = self._Bdb[File, self._Arch] | |
1744 | self._Packages.append(Package) | |
1745 | return self._Packages | |
1746 | ||
1747 | ## Retrieve PCDs used in this module | |
1748 | def _GetPcds(self): | |
1749 | if self._Pcds == None: | |
1750 | self._Pcds = {} | |
1751 | self._Pcds.update(self._GetPcd(MODEL_PCD_FIXED_AT_BUILD)) | |
1752 | self._Pcds.update(self._GetPcd(MODEL_PCD_PATCHABLE_IN_MODULE)) | |
1753 | self._Pcds.update(self._GetPcd(MODEL_PCD_FEATURE_FLAG)) | |
1754 | self._Pcds.update(self._GetPcd(MODEL_PCD_DYNAMIC)) | |
1755 | self._Pcds.update(self._GetPcd(MODEL_PCD_DYNAMIC_EX)) | |
1756 | return self._Pcds | |
1757 | ||
1758 | ## Retrieve build options specific to this module | |
1759 | def _GetBuildOptions(self): | |
1760 | if self._BuildOptions == None: | |
1761 | self._BuildOptions = sdict() | |
1762 | RecordList = self._RawData[MODEL_META_DATA_BUILD_OPTION, self._Arch, self._Platform] | |
1763 | for Record in RecordList: | |
1764 | ToolChainFamily = Record[0] | |
1765 | ToolChain = Record[1] | |
1766 | Option = Record[2] | |
1767 | if (ToolChainFamily, ToolChain) not in self._BuildOptions: | |
1768 | self._BuildOptions[ToolChainFamily, ToolChain] = Option | |
1769 | else: | |
1770 | # concatenate the option string if they're for the same tool | |
1771 | OptionString = self._BuildOptions[ToolChainFamily, ToolChain] | |
1772 | self._BuildOptions[ToolChainFamily, ToolChain] = OptionString + " " + Option | |
1773 | return self._BuildOptions | |
1774 | ||
1775 | ## Retrieve depedency expression | |
1776 | def _GetDepex(self): | |
1777 | if self._Depex == None: | |
1778 | self._Depex = tdict(False, 2) | |
1779 | RecordList = self._RawData[MODEL_EFI_DEPEX, self._Arch] | |
1780 | Depex = {} | |
1781 | for Record in RecordList: | |
1782 | Record = ReplaceMacros(Record, GlobalData.gEdkGlobal, False) | |
1783 | Arch = Record[3] | |
1784 | ModuleType = Record[4] | |
1785 | TokenList = Record[0].split() | |
1786 | if (Arch, ModuleType) not in Depex: | |
1787 | Depex[Arch, ModuleType] = [] | |
1788 | DepexList = Depex[Arch, ModuleType] | |
1789 | for Token in TokenList: | |
1790 | if Token in DEPEX_SUPPORTED_OPCODE: | |
1791 | DepexList.append(Token) | |
1792 | elif Token.endswith(".inf"): # module file name | |
1793 | ModuleFile = os.path.normpath(Token) | |
1794 | Module = self.BuildDatabase[ModuleFile] | |
1795 | if Module == None: | |
1796 | EdkLogger.error('build', RESOURCE_NOT_AVAILABLE, "Module is not found in active platform", | |
1797 | ExtraData=Token, File=self.MetaFile, Line=Record[-1]) | |
1798 | DepexList.append(Module.Guid) | |
1799 | else: | |
1800 | # get the GUID value now | |
1801 | Value = ProtocolValue(Token, self.Packages) | |
1802 | if Value == None: | |
1803 | Value = PpiValue(Token, self.Packages) | |
1804 | if Value == None: | |
1805 | Value = GuidValue(Token, self.Packages) | |
1806 | if Value == None: | |
1807 | PackageList = "\n\t".join([str(P) for P in self.Packages]) | |
1808 | EdkLogger.error('build', RESOURCE_NOT_AVAILABLE, | |
1809 | "Value of [%s] is not found in" % Token, | |
1810 | ExtraData=PackageList, File=self.MetaFile, Line=Record[-1]) | |
1811 | DepexList.append(Value) | |
1812 | for Arch, ModuleType in Depex: | |
1813 | self._Depex[Arch, ModuleType] = Depex[Arch, ModuleType] | |
1814 | return self._Depex | |
1815 | ||
1816 | ## Retrieve PCD for given type | |
1817 | def _GetPcd(self, Type): | |
1818 | Pcds = {} | |
1819 | PcdDict = tdict(True, 4) | |
1820 | PcdSet = set() | |
1821 | RecordList = self._RawData[Type, self._Arch, self._Platform] | |
1822 | for TokenSpaceGuid, PcdCName, Setting, Arch, Platform, Dummy1, LineNo in RecordList: | |
1823 | PcdDict[Arch, Platform, PcdCName, TokenSpaceGuid] = (Setting, LineNo) | |
1824 | PcdSet.add((PcdCName, TokenSpaceGuid)) | |
1825 | # get the guid value | |
1826 | if TokenSpaceGuid not in self.Guids: | |
1827 | Value = GuidValue(TokenSpaceGuid, self.Packages) | |
1828 | if Value == None: | |
1829 | PackageList = "\n\t".join([str(P) for P in self.Packages]) | |
1830 | EdkLogger.error('build', RESOURCE_NOT_AVAILABLE, | |
1831 | "Value of Guid [%s] is not found under [Guids] section in" % TokenSpaceGuid, | |
1832 | ExtraData=PackageList, File=self.MetaFile, Line=LineNo) | |
1833 | self.Guids[TokenSpaceGuid] = Value | |
1834 | ||
1835 | # resolve PCD type, value, datum info, etc. by getting its definition from package | |
1836 | for PcdCName, TokenSpaceGuid in PcdSet: | |
1837 | ValueList = ['', ''] | |
1838 | Setting, LineNo = PcdDict[self._Arch, self.Platform, PcdCName, TokenSpaceGuid] | |
1839 | if Setting == None: | |
1840 | continue | |
1841 | TokenList = Setting.split(TAB_VALUE_SPLIT) | |
1842 | ValueList[0:len(TokenList)] = TokenList | |
1843 | DefaultValue = ValueList[0] | |
1844 | Pcd = PcdClassObject( | |
1845 | PcdCName, | |
1846 | TokenSpaceGuid, | |
1847 | '', | |
1848 | '', | |
1849 | DefaultValue, | |
1850 | '', | |
1851 | '', | |
1852 | {}, | |
1853 | self.Guids[TokenSpaceGuid] | |
1854 | ) | |
1855 | ||
1856 | # get necessary info from package declaring this PCD | |
1857 | for Package in self.Packages: | |
1858 | # | |
1859 | # 'dynamic' in INF means its type is determined by platform; | |
1860 | # if platform doesn't give its type, use 'lowest' one in the | |
1861 | # following order, if any | |
1862 | # | |
1863 | # "FixedAtBuild", "PatchableInModule", "FeatureFlag", "Dynamic", "DynamicEx" | |
1864 | # | |
1865 | PcdType = self._PCD_TYPE_STRING_[Type] | |
1866 | if Type in [MODEL_PCD_DYNAMIC, MODEL_PCD_DYNAMIC_EX]: | |
1867 | Pcd.Pending = True | |
1868 | for T in ["FixedAtBuild", "PatchableInModule", "FeatureFlag", "Dynamic", "DynamicEx"]: | |
1869 | if (PcdCName, TokenSpaceGuid, T) in Package.Pcds: | |
1870 | PcdType = T | |
1871 | break | |
1872 | else: | |
1873 | Pcd.Pending = False | |
1874 | ||
1875 | if (PcdCName, TokenSpaceGuid, PcdType) in Package.Pcds: | |
1876 | PcdInPackage = Package.Pcds[PcdCName, TokenSpaceGuid, PcdType] | |
1877 | Pcd.Type = PcdType | |
1878 | Pcd.TokenValue = PcdInPackage.TokenValue | |
1879 | Pcd.DatumType = PcdInPackage.DatumType | |
1880 | Pcd.MaxDatumSize = PcdInPackage.MaxDatumSize | |
1881 | if Pcd.DefaultValue in [None, '']: | |
1882 | Pcd.DefaultValue = PcdInPackage.DefaultValue | |
1883 | break | |
1884 | else: | |
1885 | EdkLogger.error( | |
1886 | 'build', | |
1887 | PARSER_ERROR, | |
1888 | "PCD [%s.%s] in [%s] is not found in dependent packages:" % (TokenSpaceGuid, PcdCName, self.MetaFile), | |
1889 | File =self.MetaFile, Line=LineNo, | |
1890 | ExtraData="\t%s" % '\n\t'.join([str(P) for P in self.Packages]) | |
1891 | ) | |
1892 | Pcds[PcdCName, TokenSpaceGuid] = Pcd | |
1893 | return Pcds | |
1894 | ||
1895 | Arch = property(_GetArch, _SetArch) | |
1896 | Platform = property(_GetPlatform, _SetPlatform) | |
1897 | ||
1898 | AutoGenVersion = property(_GetInfVersion) | |
1899 | BaseName = property(_GetBaseName) | |
1900 | ModuleType = property(_GetModuleType) | |
1901 | ComponentType = property(_GetComponentType) | |
1902 | BuildType = property(_GetBuildType) | |
1903 | Guid = property(_GetFileGuid) | |
1904 | Version = property(_GetVersion) | |
1905 | PcdIsDriver = property(_GetPcdIsDriver) | |
1906 | Shadow = property(_GetShadow) | |
1907 | CustomMakefile = property(_GetMakefile) | |
1908 | Specification = property(_GetSpec) | |
1909 | LibraryClass = property(_GetLibraryClass) | |
1910 | ModuleEntryPointList = property(_GetEntryPoint) | |
1911 | ModuleUnloadImageList = property(_GetUnloadImage) | |
1912 | ConstructorList = property(_GetConstructor) | |
1913 | DestructorList = property(_GetDestructor) | |
1914 | Defines = property(_GetDefines) | |
1915 | ||
1916 | Binaries = property(_GetBinaryFiles) | |
1917 | Sources = property(_GetSourceFiles) | |
1918 | LibraryClasses = property(_GetLibraryClassUses) | |
1919 | Libraries = property(_GetLibraryNames) | |
1920 | Protocols = property(_GetProtocols) | |
1921 | Ppis = property(_GetPpis) | |
1922 | Guids = property(_GetGuids) | |
1923 | Includes = property(_GetIncludes) | |
1924 | Packages = property(_GetPackages) | |
1925 | Pcds = property(_GetPcds) | |
1926 | BuildOptions = property(_GetBuildOptions) | |
1927 | Depex = property(_GetDepex) | |
1928 | ||
1929 | ## Database | |
1930 | # | |
1931 | # This class defined the build databse for all modules, packages and platform. | |
1932 | # It will call corresponding parser for the given file if it cannot find it in | |
1933 | # the database. | |
1934 | # | |
1935 | # @param DbPath Path of database file | |
1936 | # @param GlobalMacros Global macros used for replacement during file parsing | |
1937 | # @prarm RenewDb=False Create new database file if it's already there | |
1938 | # | |
1939 | class WorkspaceDatabase(object): | |
1940 | # file parser | |
1941 | _FILE_PARSER_ = { | |
1942 | MODEL_FILE_INF : InfParser, | |
1943 | MODEL_FILE_DEC : DecParser, | |
1944 | MODEL_FILE_DSC : DscParser, | |
1945 | MODEL_FILE_FDF : None, #FdfParser, | |
1946 | MODEL_FILE_CIF : None | |
1947 | } | |
1948 | ||
1949 | # file table | |
1950 | _FILE_TABLE_ = { | |
1951 | MODEL_FILE_INF : ModuleTable, | |
1952 | MODEL_FILE_DEC : PackageTable, | |
1953 | MODEL_FILE_DSC : PlatformTable, | |
1954 | } | |
1955 | ||
1956 | # default database file path | |
1957 | _DB_PATH_ = "Conf/.cache/build.db" | |
1958 | ||
1959 | # | |
1960 | # internal class used for call corresponding file parser and caching the result | |
1961 | # to avoid unnecessary re-parsing | |
1962 | # | |
1963 | class BuildObjectFactory(object): | |
1964 | _FILE_TYPE_ = { | |
1965 | ".inf" : MODEL_FILE_INF, | |
1966 | ".dec" : MODEL_FILE_DEC, | |
1967 | ".dsc" : MODEL_FILE_DSC, | |
1968 | ".fdf" : MODEL_FILE_FDF, | |
1969 | } | |
1970 | ||
1971 | # convert to xxxBuildData object | |
1972 | _GENERATOR_ = { | |
1973 | MODEL_FILE_INF : InfBuildData, | |
1974 | MODEL_FILE_DEC : DecBuildData, | |
1975 | MODEL_FILE_DSC : DscBuildData, | |
1976 | MODEL_FILE_FDF : None #FlashDefTable, | |
1977 | } | |
1978 | ||
1979 | _CACHE_ = {} # (FilePath, Arch) : <object> | |
1980 | ||
1981 | # constructor | |
1982 | def __init__(self, WorkspaceDb): | |
1983 | self.WorkspaceDb = WorkspaceDb | |
1984 | ||
1985 | # key = (FilePath, Arch='COMMON') | |
1986 | def __contains__(self, Key): | |
1987 | FilePath = Key[0] | |
1988 | Arch = 'COMMON' | |
1989 | if len(Key) > 1: | |
1990 | Arch = Key[1] | |
1991 | return (FilePath, Arch) in self._CACHE_ | |
1992 | ||
1993 | # key = (FilePath, Arch='COMMON') | |
1994 | def __getitem__(self, Key): | |
1995 | FilePath = Key[0] | |
1996 | Arch = 'COMMON' | |
1997 | Platform = 'COMMON' | |
1998 | if len(Key) > 1: | |
1999 | Arch = Key[1] | |
2000 | if len(Key) > 2: | |
2001 | Platform = Key[2] | |
2002 | ||
2003 | # if it's generated before, just return the cached one | |
2004 | Key = (FilePath, Arch) | |
2005 | if Key in self._CACHE_: | |
2006 | return self._CACHE_[Key] | |
2007 | ||
2008 | # check file type | |
2009 | Ext = FilePath.Ext.lower() | |
2010 | if Ext not in self._FILE_TYPE_: | |
2011 | return None | |
2012 | FileType = self._FILE_TYPE_[Ext] | |
2013 | if FileType not in self._GENERATOR_: | |
2014 | return None | |
2015 | ||
2016 | # get table for current file | |
2017 | MetaFile = self.WorkspaceDb[FilePath, FileType, self.WorkspaceDb._GlobalMacros] | |
2018 | BuildObject = self._GENERATOR_[FileType]( | |
2019 | FilePath, | |
2020 | MetaFile, | |
2021 | self, | |
2022 | Arch, | |
2023 | Platform, | |
2024 | self.WorkspaceDb._GlobalMacros, | |
2025 | ) | |
2026 | self._CACHE_[Key] = BuildObject | |
2027 | return BuildObject | |
2028 | ||
2029 | # placeholder for file format conversion | |
2030 | class TransformObjectFactory: | |
2031 | def __init__(self, WorkspaceDb): | |
2032 | self.WorkspaceDb = WorkspaceDb | |
2033 | ||
2034 | # key = FilePath, Arch | |
2035 | def __getitem__(self, Key): | |
2036 | pass | |
2037 | ||
2038 | ## Constructor of WorkspaceDatabase | |
2039 | # | |
2040 | # @param DbPath Path of database file | |
2041 | # @param GlobalMacros Global macros used for replacement during file parsing | |
2042 | # @prarm RenewDb=False Create new database file if it's already there | |
2043 | # | |
2044 | def __init__(self, DbPath, GlobalMacros={}, RenewDb=False): | |
2045 | self._GlobalMacros = GlobalMacros | |
2046 | ||
2047 | if DbPath == None or DbPath == '': | |
2048 | DbPath = os.path.normpath(os.path.join(GlobalData.gWorkspace, self._DB_PATH_)) | |
2049 | ||
2050 | # don't create necessary path for db in memory | |
2051 | if DbPath != ':memory:': | |
2052 | DbDir = os.path.split(DbPath)[0] | |
2053 | if not os.path.exists(DbDir): | |
2054 | os.makedirs(DbDir)\r | |
2055 | ||
2056 | # remove db file in case inconsistency between db and file in file system | |
2057 | if self._CheckWhetherDbNeedRenew(RenewDb, DbPath):\r | |
2058 | os.remove(DbPath)\r | |
2059 | ||
2060 | # create db with optimized parameters | |
2061 | self.Conn = sqlite3.connect(DbPath, isolation_level='DEFERRED') | |
2062 | self.Conn.execute("PRAGMA synchronous=OFF") | |
2063 | self.Conn.execute("PRAGMA temp_store=MEMORY") | |
2064 | self.Conn.execute("PRAGMA count_changes=OFF") | |
2065 | self.Conn.execute("PRAGMA cache_size=8192") | |
2066 | #self.Conn.execute("PRAGMA page_size=8192") | |
2067 | ||
2068 | # to avoid non-ascii character conversion issue | |
2069 | self.Conn.text_factory = str | |
2070 | self.Cur = self.Conn.cursor() | |
2071 | ||
2072 | # create table for internal uses | |
2073 | self.TblDataModel = TableDataModel(self.Cur) | |
2074 | self.TblFile = TableFile(self.Cur) | |
2075 | ||
2076 | # conversion object for build or file format conversion purpose | |
2077 | self.BuildObject = WorkspaceDatabase.BuildObjectFactory(self) | |
2078 | self.TransformObject = WorkspaceDatabase.TransformObjectFactory(self) | |
2079 | \r | |
2080 | ## Check whether workspace database need to be renew.\r | |
2081 | # The renew reason maybe:\r | |
2082 | # 1) If user force to renew;\r | |
2083 | # 2) If user do not force renew, and\r | |
2084 | # a) If the time of last modified python source is newer than database file;\r | |
2085 | # b) If the time of last modified frozen executable file is newer than database file;\r | |
2086 | #\r | |
2087 | # @param force User force renew database\r | |
2088 | # @param DbPath The absolute path of workspace database file\r | |
2089 | #\r | |
2090 | # @return Bool value for whether need renew workspace databse\r | |
2091 | #\r | |
2092 | def _CheckWhetherDbNeedRenew (self, force, DbPath):\r | |
2093 | # if database does not exist, we need do nothing\r | |
2094 | if not os.path.exists(DbPath): return False\r | |
2095 | \r | |
2096 | # if user force to renew database, then not check whether database is out of date\r | |
2097 | if force: return True\r | |
2098 | \r | |
2099 | # \r | |
2100 | # Check the time of last modified source file or build.exe\r | |
2101 | # if is newer than time of database, then database need to be re-created.\r | |
2102 | #\r | |
2103 | timeOfToolModified = 0\r | |
2104 | if hasattr(sys, "frozen"):\r | |
2105 | exePath = os.path.abspath(sys.executable)\r | |
2106 | timeOfToolModified = os.stat(exePath).st_mtime\r | |
2107 | else:\r | |
2108 | curPath = os.path.dirname(__file__) # curPath is the path of WorkspaceDatabase.py\r | |
2109 | rootPath = os.path.split(curPath)[0] # rootPath is root path of python source, such as /BaseTools/Source/Python\r | |
2110 | if rootPath == "" or rootPath == None:\r | |
2111 | EdkLogger.verbose("\nFail to find the root path of build.exe or python sources, so can not \\r | |
2112 | determine whether database file is out of date!\n")\r | |
2113 | \r | |
2114 | # walk the root path of source or build's binary to get the time last modified.\r | |
2115 | \r | |
2116 | for root, dirs, files in os.walk (rootPath):\r | |
2117 | for dir in dirs:\r | |
2118 | # bypass source control folder \r | |
2119 | if dir.lower() in [".svn", "_svn", "cvs"]:\r | |
2120 | dirs.remove(dir)\r | |
2121 | \r | |
2122 | for file in files:\r | |
2123 | ext = os.path.splitext(file)[1]\r | |
2124 | if ext.lower() == ".py": # only check .py files\r | |
2125 | fd = os.stat(os.path.join(root, file))\r | |
2126 | if timeOfToolModified < fd.st_mtime:\r | |
2127 | timeOfToolModified = fd.st_mtime\r | |
2128 | if timeOfToolModified > os.stat(DbPath).st_mtime:\r | |
2129 | EdkLogger.verbose("\nWorkspace database is out of data!")\r | |
2130 | return True\r | |
2131 | \r | |
2132 | return False\r | |
2133 | ||
2134 | ## Initialize build database | |
2135 | def InitDatabase(self): | |
2136 | EdkLogger.verbose("\nInitialize build database started ...") | |
2137 | ||
2138 | # | |
2139 | # Create new tables | |
2140 | # | |
2141 | self.TblDataModel.Create(False) | |
2142 | self.TblFile.Create(False) | |
2143 | ||
2144 | # | |
2145 | # Initialize table DataModel | |
2146 | # | |
2147 | self.TblDataModel.InitTable() | |
2148 | EdkLogger.verbose("Initialize build database ... DONE!") | |
2149 | ||
2150 | ## Query a table | |
2151 | # | |
2152 | # @param Table: The instance of the table to be queried | |
2153 | # | |
2154 | def QueryTable(self, Table): | |
2155 | Table.Query() | |
2156 | ||
2157 | ## Close entire database | |
2158 | # | |
2159 | # Commit all first | |
2160 | # Close the connection and cursor | |
2161 | # | |
2162 | def Close(self): | |
2163 | self.Conn.commit() | |
2164 | self.Cur.close() | |
2165 | self.Conn.close() | |
2166 | ||
2167 | ## Get unique file ID for the gvien file | |
2168 | def GetFileId(self, FilePath): | |
2169 | return self.TblFile.GetFileId(FilePath) | |
2170 | ||
2171 | ## Get file type value for the gvien file ID | |
2172 | def GetFileType(self, FileId): | |
2173 | return self.TblFile.GetFileType(FileId) | |
2174 | ||
2175 | ## Get time stamp stored in file table | |
2176 | def GetTimeStamp(self, FileId): | |
2177 | return self.TblFile.GetFileTimeStamp(FileId) | |
2178 | ||
2179 | ## Update time stamp in file table | |
2180 | def SetTimeStamp(self, FileId, TimeStamp): | |
2181 | return self.TblFile.SetFileTimeStamp(FileId, TimeStamp) | |
2182 | ||
2183 | ## Check if a table integrity flag exists or not | |
2184 | def CheckIntegrity(self, TableName): | |
2185 | try: | |
2186 | Result = self.Cur.execute("select min(ID) from %s" % (TableName)).fetchall() | |
2187 | if Result[0][0] != -1: | |
2188 | return False | |
2189 | except: | |
2190 | return False | |
2191 | return True | |
2192 | ||
2193 | ## Compose table name for given file type and file ID | |
2194 | def GetTableName(self, FileType, FileId): | |
2195 | return "_%s_%s" % (FileType, FileId) | |
2196 | ||
2197 | ## Return a temp table containing all content of the given file | |
2198 | # | |
2199 | # @param FileInfo The tuple containing path and type of a file | |
2200 | # | |
2201 | def __getitem__(self, FileInfo): | |
2202 | FilePath, FileType, Macros = FileInfo | |
2203 | if FileType not in self._FILE_TABLE_: | |
2204 | return None | |
2205 | ||
2206 | # flag used to indicate if it's parsed or not | |
2207 | FilePath = str(FilePath) | |
2208 | Parsed = False | |
2209 | FileId = self.GetFileId(FilePath) | |
2210 | if FileId != None: | |
2211 | TimeStamp = os.stat(FilePath)[8] | |
2212 | TableName = self.GetTableName(FileType, FileId) | |
2213 | if TimeStamp != self.GetTimeStamp(FileId): | |
2214 | # update the timestamp in database | |
2215 | self.SetTimeStamp(FileId, TimeStamp) | |
2216 | else: | |
2217 | # if the table exists and is integrity, don't parse it | |
2218 | Parsed = self.CheckIntegrity(TableName) | |
2219 | else: | |
2220 | FileId = self.TblFile.InsertFile(FilePath, FileType) | |
2221 | TableName = self.GetTableName(FileType, FileId) | |
2222 | ||
2223 | FileTable = self._FILE_TABLE_[FileType](self.Cur, TableName, FileId) | |
2224 | FileTable.Create(not Parsed) | |
2225 | Parser = self._FILE_PARSER_[FileType](FilePath, FileType, FileTable, Macros) | |
2226 | # set the "Finished" flag in parser in order to avoid re-parsing (if parsed) | |
2227 | Parser.Finished = Parsed | |
2228 | return Parser | |
2229 | ||
2230 | ## Summarize all packages in the database | |
2231 | def _GetPackageList(self): | |
2232 | PackageList = [] | |
2233 | for Module in self.ModuleList: | |
2234 | for Package in Module.Packages: | |
2235 | if Package not in PackageList: | |
2236 | PackageList.append(Package) | |
2237 | return PackageList | |
2238 | ||
2239 | ## Summarize all platforms in the database | |
2240 | def _GetPlatformList(self): | |
2241 | PlatformList = [] | |
2242 | for PlatformFile in self.TblFile.GetFileList(MODEL_FILE_DSC): | |
2243 | try: | |
2244 | Platform = self.BuildObject[PathClass(PlatformFile), 'COMMON'] | |
2245 | except: | |
2246 | Platform = None | |
2247 | if Platform != None: | |
2248 | PlatformList.append(Platform) | |
2249 | return PlatformList | |
2250 | ||
2251 | ## Summarize all modules in the database | |
2252 | def _GetModuleList(self): | |
2253 | ModuleList = [] | |
2254 | for ModuleFile in self.TblFile.GetFileList(MODEL_FILE_INF): | |
2255 | try: | |
2256 | Module = self.BuildObject[PathClass(ModuleFile), 'COMMON'] | |
2257 | except: | |
2258 | Module = None | |
2259 | if Module != None: | |
2260 | ModuleList.append(Module) | |
2261 | return ModuleList | |
2262 | ||
2263 | PlatformList = property(_GetPlatformList) | |
2264 | PackageList = property(_GetPackageList) | |
2265 | ModuleList = property(_GetModuleList) | |
2266 | ||
2267 | ## | |
2268 | # | |
2269 | # This acts like the main() function for the script, unless it is 'import'ed into another | |
2270 | # script. | |
2271 | # | |
2272 | if __name__ == '__main__': | |
2273 | pass | |
2274 |