]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/AutoGen/AutoGen.py
70c6c9118671c99bf63a7519000961f28eae4b07
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / AutoGen.py
1 ## @file
2 # Generate AutoGen.h, AutoGen.c and *.depex files
3 #
4 # Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
5 # This program and the accompanying materials
6 # are licensed and made available under the terms and conditions of the BSD License
7 # which accompanies this distribution. The full text of the license may be found at
8 # http://opensource.org/licenses/bsd-license.php
9 #
10 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 #
13
14 ## Import Modules
15 #
16 import Common.LongFilePathOs as os
17 import re
18 import os.path as path
19 import copy
20 import uuid
21
22 import GenC
23 import GenMake
24 import GenDepex
25 from StringIO import StringIO
26
27 from StrGather import *
28 from BuildEngine import BuildRule
29
30 from Common.LongFilePathSupport import CopyLongFilePath
31 from Common.BuildToolError import *
32 from Common.DataType import *
33 from Common.Misc import *
34 from Common.String import *
35 import Common.GlobalData as GlobalData
36 from GenFds.FdfParser import *
37 from CommonDataClass.CommonClass import SkuInfoClass
38 from Workspace.BuildClassObject import *
39 from GenPatchPcdTable.GenPatchPcdTable import parsePcdInfoFromMapFile
40 import Common.VpdInfoFile as VpdInfoFile
41 from GenPcdDb import CreatePcdDatabaseCode
42 from Workspace.MetaFileCommentParser import UsageList
43 from Common.MultipleWorkspace import MultipleWorkspace as mws
44 import InfSectionParser
45 import datetime
46
47 ## Regular expression for splitting Dependency Expression string into tokens
48 gDepexTokenPattern = re.compile("(\(|\)|\w+| \S+\.inf)")
49
50 #
51 # Match name = variable
52 #
53 gEfiVarStoreNamePattern = re.compile("\s*name\s*=\s*(\w+)")
54 #
55 # The format of guid in efivarstore statement likes following and must be correct:
56 # guid = {0xA04A27f4, 0xDF00, 0x4D42, {0xB5, 0x52, 0x39, 0x51, 0x13, 0x02, 0x11, 0x3D}}
57 #
58 gEfiVarStoreGuidPattern = re.compile("\s*guid\s*=\s*({.*?{.*?}\s*})")
59
60 ## Mapping Makefile type
61 gMakeTypeMap = {"MSFT":"nmake", "GCC":"gmake"}
62
63
64 ## Build rule configuration file
65 gDefaultBuildRuleFile = 'Conf/build_rule.txt'
66
67 ## Build rule default version
68 AutoGenReqBuildRuleVerNum = "0.1"
69
70 ## default file name for AutoGen
71 gAutoGenCodeFileName = "AutoGen.c"
72 gAutoGenHeaderFileName = "AutoGen.h"
73 gAutoGenStringFileName = "%(module_name)sStrDefs.h"
74 gAutoGenStringFormFileName = "%(module_name)sStrDefs.hpk"
75 gAutoGenDepexFileName = "%(module_name)s.depex"
76 gAutoGenImageDefFileName = "%(module_name)sImgDefs.h"
77 gAutoGenIdfFileName = "%(module_name)sIdf.hpk"
78 gInfSpecVersion = "0x00010017"
79
80 #
81 # Template string to generic AsBuilt INF
82 #
83 gAsBuiltInfHeaderString = TemplateString("""${header_comments}
84
85 # DO NOT EDIT
86 # FILE auto-generated
87
88 [Defines]
89 INF_VERSION = ${module_inf_version}
90 BASE_NAME = ${module_name}
91 FILE_GUID = ${module_guid}
92 MODULE_TYPE = ${module_module_type}${BEGIN}
93 VERSION_STRING = ${module_version_string}${END}${BEGIN}
94 PCD_IS_DRIVER = ${pcd_is_driver_string}${END}${BEGIN}
95 UEFI_SPECIFICATION_VERSION = ${module_uefi_specification_version}${END}${BEGIN}
96 PI_SPECIFICATION_VERSION = ${module_pi_specification_version}${END}${BEGIN}
97 ENTRY_POINT = ${module_entry_point}${END}${BEGIN}
98 UNLOAD_IMAGE = ${module_unload_image}${END}${BEGIN}
99 CONSTRUCTOR = ${module_constructor}${END}${BEGIN}
100 DESTRUCTOR = ${module_destructor}${END}${BEGIN}
101 SHADOW = ${module_shadow}${END}${BEGIN}
102 PCI_VENDOR_ID = ${module_pci_vendor_id}${END}${BEGIN}
103 PCI_DEVICE_ID = ${module_pci_device_id}${END}${BEGIN}
104 PCI_CLASS_CODE = ${module_pci_class_code}${END}${BEGIN}
105 PCI_REVISION = ${module_pci_revision}${END}${BEGIN}
106 BUILD_NUMBER = ${module_build_number}${END}${BEGIN}
107 SPEC = ${module_spec}${END}${BEGIN}
108 UEFI_HII_RESOURCE_SECTION = ${module_uefi_hii_resource_section}${END}${BEGIN}
109 MODULE_UNI_FILE = ${module_uni_file}${END}
110
111 [Packages.${module_arch}]${BEGIN}
112 ${package_item}${END}
113
114 [Binaries.${module_arch}]${BEGIN}
115 ${binary_item}${END}
116
117 [PatchPcd.${module_arch}]${BEGIN}
118 ${patchablepcd_item}
119 ${END}
120
121 [Protocols.${module_arch}]${BEGIN}
122 ${protocol_item}
123 ${END}
124
125 [Ppis.${module_arch}]${BEGIN}
126 ${ppi_item}
127 ${END}
128
129 [Guids.${module_arch}]${BEGIN}
130 ${guid_item}
131 ${END}
132
133 [PcdEx.${module_arch}]${BEGIN}
134 ${pcd_item}
135 ${END}
136
137 [LibraryClasses.${module_arch}]
138 ## @LIB_INSTANCES${BEGIN}
139 # ${libraryclasses_item}${END}
140
141 ${depexsection_item}
142
143 ${tail_comments}
144
145 [BuildOptions.${module_arch}]
146 ## @AsBuilt${BEGIN}
147 ## ${flags_item}${END}
148 """)
149
150 ## Base class for AutoGen
151 #
152 # This class just implements the cache mechanism of AutoGen objects.
153 #
154 class AutoGen(object):
155 # database to maintain the objects of xxxAutoGen
156 _CACHE_ = {} # (BuildTarget, ToolChain) : {ARCH : {platform file: AutoGen object}}}
157
158 ## Factory method
159 #
160 # @param Class class object of real AutoGen class
161 # (WorkspaceAutoGen, ModuleAutoGen or PlatformAutoGen)
162 # @param Workspace Workspace directory or WorkspaceAutoGen object
163 # @param MetaFile The path of meta file
164 # @param Target Build target
165 # @param Toolchain Tool chain name
166 # @param Arch Target arch
167 # @param *args The specific class related parameters
168 # @param **kwargs The specific class related dict parameters
169 #
170 def __new__(Class, Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs):
171 # check if the object has been created
172 Key = (Target, Toolchain)
173 if Key not in Class._CACHE_ or Arch not in Class._CACHE_[Key] \
174 or MetaFile not in Class._CACHE_[Key][Arch]:
175 AutoGenObject = super(AutoGen, Class).__new__(Class)
176 # call real constructor
177 if not AutoGenObject._Init(Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs):
178 return None
179 if Key not in Class._CACHE_:
180 Class._CACHE_[Key] = {}
181 if Arch not in Class._CACHE_[Key]:
182 Class._CACHE_[Key][Arch] = {}
183 Class._CACHE_[Key][Arch][MetaFile] = AutoGenObject
184 else:
185 AutoGenObject = Class._CACHE_[Key][Arch][MetaFile]
186
187 return AutoGenObject
188
189 ## hash() operator
190 #
191 # The file path of platform file will be used to represent hash value of this object
192 #
193 # @retval int Hash value of the file path of platform file
194 #
195 def __hash__(self):
196 return hash(self.MetaFile)
197
198 ## str() operator
199 #
200 # The file path of platform file will be used to represent this object
201 #
202 # @retval string String of platform file path
203 #
204 def __str__(self):
205 return str(self.MetaFile)
206
207 ## "==" operator
208 def __eq__(self, Other):
209 return Other and self.MetaFile == Other
210
211 ## Workspace AutoGen class
212 #
213 # This class is used mainly to control the whole platform build for different
214 # architecture. This class will generate top level makefile.
215 #
216 class WorkspaceAutoGen(AutoGen):
217 ## Real constructor of WorkspaceAutoGen
218 #
219 # This method behaves the same as __init__ except that it needs explicit invoke
220 # (in super class's __new__ method)
221 #
222 # @param WorkspaceDir Root directory of workspace
223 # @param ActivePlatform Meta-file of active platform
224 # @param Target Build target
225 # @param Toolchain Tool chain name
226 # @param ArchList List of architecture of current build
227 # @param MetaFileDb Database containing meta-files
228 # @param BuildConfig Configuration of build
229 # @param ToolDefinition Tool chain definitions
230 # @param FlashDefinitionFile File of flash definition
231 # @param Fds FD list to be generated
232 # @param Fvs FV list to be generated
233 # @param Caps Capsule list to be generated
234 # @param SkuId SKU id from command line
235 #
236 def _Init(self, WorkspaceDir, ActivePlatform, Target, Toolchain, ArchList, MetaFileDb,
237 BuildConfig, ToolDefinition, FlashDefinitionFile='', Fds=None, Fvs=None, Caps=None, SkuId='', UniFlag=None,
238 Progress=None, BuildModule=None):
239 if Fds is None:
240 Fds = []
241 if Fvs is None:
242 Fvs = []
243 if Caps is None:
244 Caps = []
245 self.BuildDatabase = MetaFileDb
246 self.MetaFile = ActivePlatform
247 self.WorkspaceDir = WorkspaceDir
248 self.Platform = self.BuildDatabase[self.MetaFile, 'COMMON', Target, Toolchain]
249 GlobalData.gActivePlatform = self.Platform
250 self.BuildTarget = Target
251 self.ToolChain = Toolchain
252 self.ArchList = ArchList
253 self.SkuId = SkuId
254 self.UniFlag = UniFlag
255
256 self.TargetTxt = BuildConfig
257 self.ToolDef = ToolDefinition
258 self.FdfFile = FlashDefinitionFile
259 self.FdTargetList = Fds
260 self.FvTargetList = Fvs
261 self.CapTargetList = Caps
262 self.AutoGenObjectList = []
263
264 # there's many relative directory operations, so ...
265 os.chdir(self.WorkspaceDir)
266
267 #
268 # Merge Arch
269 #
270 if not self.ArchList:
271 ArchList = set(self.Platform.SupArchList)
272 else:
273 ArchList = set(self.ArchList) & set(self.Platform.SupArchList)
274 if not ArchList:
275 EdkLogger.error("build", PARAMETER_INVALID,
276 ExtraData = "Invalid ARCH specified. [Valid ARCH: %s]" % (" ".join(self.Platform.SupArchList)))
277 elif self.ArchList and len(ArchList) != len(self.ArchList):
278 SkippedArchList = set(self.ArchList).symmetric_difference(set(self.Platform.SupArchList))
279 EdkLogger.verbose("\nArch [%s] is ignored because the platform supports [%s] only!"
280 % (" ".join(SkippedArchList), " ".join(self.Platform.SupArchList)))
281 self.ArchList = tuple(ArchList)
282
283 # Validate build target
284 if self.BuildTarget not in self.Platform.BuildTargets:
285 EdkLogger.error("build", PARAMETER_INVALID,
286 ExtraData="Build target [%s] is not supported by the platform. [Valid target: %s]"
287 % (self.BuildTarget, " ".join(self.Platform.BuildTargets)))
288
289
290 # parse FDF file to get PCDs in it, if any
291 if not self.FdfFile:
292 self.FdfFile = self.Platform.FlashDefinition
293
294 EdkLogger.info("")
295 if self.ArchList:
296 EdkLogger.info('%-16s = %s' % ("Architecture(s)", ' '.join(self.ArchList)))
297 EdkLogger.info('%-16s = %s' % ("Build target", self.BuildTarget))
298 EdkLogger.info('%-16s = %s' % ("Toolchain", self.ToolChain))
299
300 EdkLogger.info('\n%-24s = %s' % ("Active Platform", self.Platform))
301 if BuildModule:
302 EdkLogger.info('%-24s = %s' % ("Active Module", BuildModule))
303
304 if self.FdfFile:
305 EdkLogger.info('%-24s = %s' % ("Flash Image Definition", self.FdfFile))
306
307 EdkLogger.verbose("\nFLASH_DEFINITION = %s" % self.FdfFile)
308
309 if Progress:
310 Progress.Start("\nProcessing meta-data")
311
312 if self.FdfFile:
313 #
314 # Mark now build in AutoGen Phase
315 #
316 GlobalData.gAutoGenPhase = True
317 Fdf = FdfParser(self.FdfFile.Path)
318 Fdf.ParseFile()
319 GlobalData.gFdfParser = Fdf
320 GlobalData.gAutoGenPhase = False
321 PcdSet = Fdf.Profile.PcdDict
322 if Fdf.CurrentFdName and Fdf.CurrentFdName in Fdf.Profile.FdDict:
323 FdDict = Fdf.Profile.FdDict[Fdf.CurrentFdName]
324 for FdRegion in FdDict.RegionList:
325 if str(FdRegion.RegionType) is 'FILE' and self.Platform.VpdToolGuid in str(FdRegion.RegionDataList):
326 if int(FdRegion.Offset) % 8 != 0:
327 EdkLogger.error("build", FORMAT_INVALID, 'The VPD Base Address %s must be 8-byte aligned.' % (FdRegion.Offset))
328 ModuleList = Fdf.Profile.InfList
329 self.FdfProfile = Fdf.Profile
330 for fvname in self.FvTargetList:
331 if fvname.upper() not in self.FdfProfile.FvDict:
332 EdkLogger.error("build", OPTION_VALUE_INVALID,
333 "No such an FV in FDF file: %s" % fvname)
334
335 # In DSC file may use FILE_GUID to override the module, then in the Platform.Modules use FILE_GUIDmodule.inf as key,
336 # but the path (self.MetaFile.Path) is the real path
337 for key in self.FdfProfile.InfDict:
338 if key == 'ArchTBD':
339 Platform_cache = {}
340 MetaFile_cache = {}
341 for Arch in self.ArchList:
342 Platform_cache[Arch] = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain]
343 MetaFile_cache[Arch] = []
344 for Pkey in Platform_cache[Arch].Modules.keys():
345 MetaFile_cache[Arch].append(Platform_cache[Arch].Modules[Pkey].MetaFile)
346 for Inf in self.FdfProfile.InfDict[key]:
347 ModuleFile = PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch)
348 for Arch in self.ArchList:
349 if ModuleFile in MetaFile_cache[Arch]:
350 break
351 else:
352 ModuleData = self.BuildDatabase[ModuleFile, Arch, Target, Toolchain]
353 if not ModuleData.IsBinaryModule:
354 EdkLogger.error('build', PARSER_ERROR, "Module %s NOT found in DSC file; Is it really a binary module?" % ModuleFile)
355
356 else:
357 for Arch in self.ArchList:
358 if Arch == key:
359 Platform = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain]
360 MetaFileList = []
361 for Pkey in Platform.Modules.keys():
362 MetaFileList.append(Platform.Modules[Pkey].MetaFile)
363 for Inf in self.FdfProfile.InfDict[key]:
364 ModuleFile = PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch)
365 if ModuleFile in MetaFileList:
366 continue
367 ModuleData = self.BuildDatabase[ModuleFile, Arch, Target, Toolchain]
368 if not ModuleData.IsBinaryModule:
369 EdkLogger.error('build', PARSER_ERROR, "Module %s NOT found in DSC file; Is it really a binary module?" % ModuleFile)
370
371 else:
372 PcdSet = {}
373 ModuleList = []
374 self.FdfProfile = None
375 if self.FdTargetList:
376 EdkLogger.info("No flash definition file found. FD [%s] will be ignored." % " ".join(self.FdTargetList))
377 self.FdTargetList = []
378 if self.FvTargetList:
379 EdkLogger.info("No flash definition file found. FV [%s] will be ignored." % " ".join(self.FvTargetList))
380 self.FvTargetList = []
381 if self.CapTargetList:
382 EdkLogger.info("No flash definition file found. Capsule [%s] will be ignored." % " ".join(self.CapTargetList))
383 self.CapTargetList = []
384
385 # apply SKU and inject PCDs from Flash Definition file
386 for Arch in self.ArchList:
387 Platform = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain]
388
389 DecPcds = {}
390 DecPcdsKey = set()
391 PGen = PlatformAutoGen(self, self.MetaFile, Target, Toolchain, Arch)
392 if GlobalData.BuildOptionPcd:
393 for i, pcd in enumerate(GlobalData.BuildOptionPcd):
394 if type(pcd) is tuple:
395 continue
396 (pcdname, pcdvalue) = pcd.split('=')
397 if not pcdvalue:
398 EdkLogger.error('build', AUTOGEN_ERROR, "No Value specified for the PCD %s." % (pcdname))
399 if '.' in pcdname:
400 (TokenSpaceGuidCName, TokenCName) = pcdname.split('.')
401 HasTokenSpace = True
402 else:
403 TokenCName = pcdname
404 TokenSpaceGuidCName = ''
405 HasTokenSpace = False
406 TokenSpaceGuidCNameList = []
407 FoundFlag = False
408 PcdDatumType = ''
409 NewValue = ''
410 for package in PGen.PackageList:
411 for key in package.Pcds:
412 PcdItem = package.Pcds[key]
413 if HasTokenSpace:
414 if (PcdItem.TokenCName, PcdItem.TokenSpaceGuidCName) == (TokenCName, TokenSpaceGuidCName):
415 PcdDatumType = PcdItem.DatumType
416 NewValue = self._BuildOptionPcdValueFormat(TokenSpaceGuidCName, TokenCName, PcdDatumType, pcdvalue)
417 FoundFlag = True
418 else:
419 if PcdItem.TokenCName == TokenCName:
420 if not PcdItem.TokenSpaceGuidCName in TokenSpaceGuidCNameList:
421 if len (TokenSpaceGuidCNameList) < 1:
422 TokenSpaceGuidCNameList.append(PcdItem.TokenSpaceGuidCName)
423 PcdDatumType = PcdItem.DatumType
424 TokenSpaceGuidCName = PcdItem.TokenSpaceGuidCName
425 NewValue = self._BuildOptionPcdValueFormat(TokenSpaceGuidCName, TokenCName, PcdDatumType, pcdvalue)
426 FoundFlag = True
427 else:
428 EdkLogger.error(
429 'build',
430 AUTOGEN_ERROR,
431 "The Pcd %s is found under multiple different TokenSpaceGuid: %s and %s." % (TokenCName, PcdItem.TokenSpaceGuidCName, TokenSpaceGuidCNameList[0])
432 )
433
434 GlobalData.BuildOptionPcd[i] = (TokenSpaceGuidCName, TokenCName, NewValue)
435
436 if not FoundFlag:
437 if HasTokenSpace:
438 EdkLogger.error('build', AUTOGEN_ERROR, "The Pcd %s.%s is not found in the DEC file." % (TokenSpaceGuidCName, TokenCName))
439 else:
440 EdkLogger.error('build', AUTOGEN_ERROR, "The Pcd %s is not found in the DEC file." % (TokenCName))
441
442 for BuildData in PGen.BuildDatabase._CACHE_.values():
443 if BuildData.Arch != Arch:
444 continue
445 if BuildData.MetaFile.Ext == '.dec':
446 continue
447 for key in BuildData.Pcds:
448 PcdItem = BuildData.Pcds[key]
449 if (TokenSpaceGuidCName, TokenCName) == (PcdItem.TokenSpaceGuidCName, PcdItem.TokenCName):
450 PcdItem.DefaultValue = NewValue
451
452 if (TokenCName, TokenSpaceGuidCName) in PcdSet:
453 PcdSet[(TokenCName, TokenSpaceGuidCName)] = NewValue
454
455 SourcePcdDict = {'DynamicEx':[], 'PatchableInModule':[],'Dynamic':[],'FixedAtBuild':[]}
456 BinaryPcdDict = {'DynamicEx':[], 'PatchableInModule':[]}
457 SourcePcdDict_Keys = SourcePcdDict.keys()
458 BinaryPcdDict_Keys = BinaryPcdDict.keys()
459
460 # generate the SourcePcdDict and BinaryPcdDict
461 for BuildData in PGen.BuildDatabase._CACHE_.values():
462 if BuildData.Arch != Arch:
463 continue
464 if BuildData.MetaFile.Ext == '.inf':
465 for key in BuildData.Pcds:
466 if BuildData.Pcds[key].Pending:
467 if key in Platform.Pcds:
468 PcdInPlatform = Platform.Pcds[key]
469 if PcdInPlatform.Type not in [None, '']:
470 BuildData.Pcds[key].Type = PcdInPlatform.Type
471
472 if BuildData.MetaFile in Platform.Modules:
473 PlatformModule = Platform.Modules[str(BuildData.MetaFile)]
474 if key in PlatformModule.Pcds:
475 PcdInPlatform = PlatformModule.Pcds[key]
476 if PcdInPlatform.Type not in [None, '']:
477 BuildData.Pcds[key].Type = PcdInPlatform.Type
478
479 if 'DynamicEx' in BuildData.Pcds[key].Type:
480 if BuildData.IsBinaryModule:
481 if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in BinaryPcdDict['DynamicEx']:
482 BinaryPcdDict['DynamicEx'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))
483 else:
484 if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in SourcePcdDict['DynamicEx']:
485 SourcePcdDict['DynamicEx'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))
486
487 elif 'PatchableInModule' in BuildData.Pcds[key].Type:
488 if BuildData.MetaFile.Ext == '.inf':
489 if BuildData.IsBinaryModule:
490 if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in BinaryPcdDict['PatchableInModule']:
491 BinaryPcdDict['PatchableInModule'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))
492 else:
493 if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in SourcePcdDict['PatchableInModule']:
494 SourcePcdDict['PatchableInModule'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))
495
496 elif 'Dynamic' in BuildData.Pcds[key].Type:
497 if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in SourcePcdDict['Dynamic']:
498 SourcePcdDict['Dynamic'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))
499 elif 'FixedAtBuild' in BuildData.Pcds[key].Type:
500 if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in SourcePcdDict['FixedAtBuild']:
501 SourcePcdDict['FixedAtBuild'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))
502 else:
503 pass
504
505 #
506 # intersection the BinaryPCD for Mixed PCD
507 #
508 for i in BinaryPcdDict_Keys:
509 for j in BinaryPcdDict_Keys:
510 if i != j:
511 IntersectionList = list(set(BinaryPcdDict[i]).intersection(set(BinaryPcdDict[j])))
512 for item in IntersectionList:
513 NewPcd1 = (item[0] + '_' + i, item[1])
514 NewPcd2 = (item[0] + '_' + j, item[1])
515 if item not in GlobalData.MixedPcd:
516 GlobalData.MixedPcd[item] = [NewPcd1, NewPcd2]
517 else:
518 if NewPcd1 not in GlobalData.MixedPcd[item]:
519 GlobalData.MixedPcd[item].append(NewPcd1)
520 if NewPcd2 not in GlobalData.MixedPcd[item]:
521 GlobalData.MixedPcd[item].append(NewPcd2)
522 else:
523 pass
524
525 #
526 # intersection the SourcePCD and BinaryPCD for Mixed PCD
527 #
528 for i in SourcePcdDict_Keys:
529 for j in BinaryPcdDict_Keys:
530 if i != j:
531 IntersectionList = list(set(SourcePcdDict[i]).intersection(set(BinaryPcdDict[j])))
532 for item in IntersectionList:
533 NewPcd1 = (item[0] + '_' + i, item[1])
534 NewPcd2 = (item[0] + '_' + j, item[1])
535 if item not in GlobalData.MixedPcd:
536 GlobalData.MixedPcd[item] = [NewPcd1, NewPcd2]
537 else:
538 if NewPcd1 not in GlobalData.MixedPcd[item]:
539 GlobalData.MixedPcd[item].append(NewPcd1)
540 if NewPcd2 not in GlobalData.MixedPcd[item]:
541 GlobalData.MixedPcd[item].append(NewPcd2)
542 else:
543 pass
544
545 for BuildData in PGen.BuildDatabase._CACHE_.values():
546 if BuildData.Arch != Arch:
547 continue
548 for key in BuildData.Pcds:
549 for SinglePcd in GlobalData.MixedPcd:
550 if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) == SinglePcd:
551 for item in GlobalData.MixedPcd[SinglePcd]:
552 Pcd_Type = item[0].split('_')[-1]
553 if (Pcd_Type == BuildData.Pcds[key].Type) or (Pcd_Type == TAB_PCDS_DYNAMIC_EX and BuildData.Pcds[key].Type in GenC.gDynamicExPcd) or \
554 (Pcd_Type == TAB_PCDS_DYNAMIC and BuildData.Pcds[key].Type in GenC.gDynamicPcd):
555 Value = BuildData.Pcds[key]
556 Value.TokenCName = BuildData.Pcds[key].TokenCName + '_' + Pcd_Type
557 if len(key) == 2:
558 newkey = (Value.TokenCName, key[1])
559 elif len(key) == 3:
560 newkey = (Value.TokenCName, key[1], key[2])
561 del BuildData.Pcds[key]
562 BuildData.Pcds[newkey] = Value
563 break
564 else:
565 pass
566 break
567 else:
568 pass
569
570 # handle the mixed pcd in FDF file
571 for key in PcdSet:
572 if key in GlobalData.MixedPcd:
573 Value = PcdSet[key]
574 del PcdSet[key]
575 for item in GlobalData.MixedPcd[key]:
576 PcdSet[item] = Value
577
578 #Collect package set information from INF of FDF
579 PkgSet = set()
580 for Inf in ModuleList:
581 ModuleFile = PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch)
582 if ModuleFile in Platform.Modules:
583 continue
584 ModuleData = self.BuildDatabase[ModuleFile, Arch, Target, Toolchain]
585 PkgSet.update(ModuleData.Packages)
586 Pkgs = list(PkgSet) + list(PGen.PackageList)
587 for Pkg in Pkgs:
588 for Pcd in Pkg.Pcds:
589 DecPcds[Pcd[0], Pcd[1]] = Pkg.Pcds[Pcd]
590 DecPcdsKey.add((Pcd[0], Pcd[1], Pcd[2]))
591
592 Platform.SkuName = self.SkuId
593 for Name, Guid in PcdSet:
594 if (Name, Guid) not in DecPcds:
595 EdkLogger.error(
596 'build',
597 PARSER_ERROR,
598 "PCD (%s.%s) used in FDF is not declared in DEC files." % (Guid, Name),
599 File = self.FdfProfile.PcdFileLineDict[Name, Guid][0],
600 Line = self.FdfProfile.PcdFileLineDict[Name, Guid][1]
601 )
602 else:
603 # Check whether Dynamic or DynamicEx PCD used in FDF file. If used, build break and give a error message.
604 if (Name, Guid, TAB_PCDS_FIXED_AT_BUILD) in DecPcdsKey \
605 or (Name, Guid, TAB_PCDS_PATCHABLE_IN_MODULE) in DecPcdsKey \
606 or (Name, Guid, TAB_PCDS_FEATURE_FLAG) in DecPcdsKey:
607 Platform.AddPcd(Name, Guid, PcdSet[Name, Guid])
608 continue
609 elif (Name, Guid, TAB_PCDS_DYNAMIC) in DecPcdsKey or (Name, Guid, TAB_PCDS_DYNAMIC_EX) in DecPcdsKey:
610 EdkLogger.error(
611 'build',
612 PARSER_ERROR,
613 "Using Dynamic or DynamicEx type of PCD [%s.%s] in FDF file is not allowed." % (Guid, Name),
614 File = self.FdfProfile.PcdFileLineDict[Name, Guid][0],
615 Line = self.FdfProfile.PcdFileLineDict[Name, Guid][1]
616 )
617
618 Pa = PlatformAutoGen(self, self.MetaFile, Target, Toolchain, Arch)
619 #
620 # Explicitly collect platform's dynamic PCDs
621 #
622 Pa.CollectPlatformDynamicPcds()
623 Pa.CollectFixedAtBuildPcds()
624 self.AutoGenObjectList.append(Pa)
625
626 #
627 # Check PCDs token value conflict in each DEC file.
628 #
629 self._CheckAllPcdsTokenValueConflict()
630
631 #
632 # Check PCD type and definition between DSC and DEC
633 #
634 self._CheckPcdDefineAndType()
635
636 # if self.FdfFile:
637 # self._CheckDuplicateInFV(Fdf)
638
639 self._BuildDir = None
640 self._FvDir = None
641 self._MakeFileDir = None
642 self._BuildCommand = None
643
644 #
645 # Create BuildOptions Macro & PCD metafile.
646 #
647 content = 'gCommandLineDefines: '
648 content += str(GlobalData.gCommandLineDefines)
649 content += os.linesep
650 content += 'BuildOptionPcd: '
651 content += str(GlobalData.BuildOptionPcd)
652 SaveFileOnChange(os.path.join(self.BuildDir, 'BuildOptions'), content, False)
653
654 #
655 # Get set of workspace metafiles
656 #
657 AllWorkSpaceMetaFiles = self._GetMetaFiles(Target, Toolchain, Arch)
658
659 #
660 # Retrieve latest modified time of all metafiles
661 #
662 SrcTimeStamp = 0
663 for f in AllWorkSpaceMetaFiles:
664 if os.stat(f)[8] > SrcTimeStamp:
665 SrcTimeStamp = os.stat(f)[8]
666 self._SrcTimeStamp = SrcTimeStamp
667
668 #
669 # Write metafile list to build directory
670 #
671 AutoGenFilePath = os.path.join(self.BuildDir, 'AutoGen')
672 if os.path.exists (AutoGenFilePath):
673 os.remove(AutoGenFilePath)
674 if not os.path.exists(self.BuildDir):
675 os.makedirs(self.BuildDir)
676 with open(os.path.join(self.BuildDir, 'AutoGen'), 'w+') as file:
677 for f in AllWorkSpaceMetaFiles:
678 print >> file, f
679 return True
680
681 def _BuildOptionPcdValueFormat(self, TokenSpaceGuidCName, TokenCName, PcdDatumType, Value):
682 if PcdDatumType == 'VOID*':
683 if Value.startswith('L'):
684 if not Value[1]:
685 EdkLogger.error('build', OPTION_VALUE_INVALID, 'For Void* type PCD, when specify the Value in the command line, please use the following format: "string", L"string", B"{...}"')
686 Value = Value[0] + '"' + Value[1:] + '"'
687 elif Value.startswith('B'):
688 if not Value[1]:
689 EdkLogger.error('build', OPTION_VALUE_INVALID, 'For Void* type PCD, when specify the Value in the command line, please use the following format: "string", L"string", B"{...}"')
690 Value = Value[1:]
691 else:
692 if not Value[0]:
693 EdkLogger.error('build', OPTION_VALUE_INVALID, 'For Void* type PCD, when specify the Value in the command line, please use the following format: "string", L"string", B"{...}"')
694 Value = '"' + Value + '"'
695
696 IsValid, Cause = CheckPcdDatum(PcdDatumType, Value)
697 if not IsValid:
698 EdkLogger.error('build', FORMAT_INVALID, Cause, ExtraData="%s.%s" % (TokenSpaceGuidCName, TokenCName))
699 if PcdDatumType == 'BOOLEAN':
700 Value = Value.upper()
701 if Value == 'TRUE' or Value == '1':
702 Value = '1'
703 elif Value == 'FALSE' or Value == '0':
704 Value = '0'
705 return Value
706
707 def _GetMetaFiles(self, Target, Toolchain, Arch):
708 AllWorkSpaceMetaFiles = set()
709 #
710 # add fdf
711 #
712 if self.FdfFile:
713 AllWorkSpaceMetaFiles.add (self.FdfFile.Path)
714 if self.FdfFile:
715 FdfFiles = GlobalData.gFdfParser.GetAllIncludedFile()
716 for f in FdfFiles:
717 AllWorkSpaceMetaFiles.add (f.FileName)
718 #
719 # add dsc
720 #
721 AllWorkSpaceMetaFiles.add(self.MetaFile.Path)
722
723 #
724 # add BuildOption metafile
725 #
726 AllWorkSpaceMetaFiles.add(os.path.join(self.BuildDir, 'BuildOptions'))
727
728 for Arch in self.ArchList:
729 Platform = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain]
730 PGen = PlatformAutoGen(self, self.MetaFile, Target, Toolchain, Arch)
731
732 #
733 # add dec
734 #
735 for Package in PGen.PackageList:
736 AllWorkSpaceMetaFiles.add(Package.MetaFile.Path)
737
738 #
739 # add included dsc
740 #
741 for filePath in Platform._RawData.IncludedFiles:
742 AllWorkSpaceMetaFiles.add(filePath.Path)
743
744 return AllWorkSpaceMetaFiles
745
746 ## _CheckDuplicateInFV() method
747 #
748 # Check whether there is duplicate modules/files exist in FV section.
749 # The check base on the file GUID;
750 #
751 def _CheckDuplicateInFV(self, Fdf):
752 for Fv in Fdf.Profile.FvDict:
753 _GuidDict = {}
754 for FfsFile in Fdf.Profile.FvDict[Fv].FfsList:
755 if FfsFile.InfFileName and FfsFile.NameGuid == None:
756 #
757 # Get INF file GUID
758 #
759 InfFoundFlag = False
760 for Pa in self.AutoGenObjectList:
761 if InfFoundFlag:
762 break
763 for Module in Pa.ModuleAutoGenList:
764 if path.normpath(Module.MetaFile.File) == path.normpath(FfsFile.InfFileName):
765 InfFoundFlag = True
766 if not Module.Guid.upper() in _GuidDict.keys():
767 _GuidDict[Module.Guid.upper()] = FfsFile
768 break
769 else:
770 EdkLogger.error("build",
771 FORMAT_INVALID,
772 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile.CurrentLineNum,
773 FfsFile.CurrentLineContent,
774 _GuidDict[Module.Guid.upper()].CurrentLineNum,
775 _GuidDict[Module.Guid.upper()].CurrentLineContent,
776 Module.Guid.upper()),
777 ExtraData=self.FdfFile)
778 #
779 # Some INF files not have entity in DSC file.
780 #
781 if not InfFoundFlag:
782 if FfsFile.InfFileName.find('$') == -1:
783 InfPath = NormPath(FfsFile.InfFileName)
784 if not os.path.exists(InfPath):
785 EdkLogger.error('build', GENFDS_ERROR, "Non-existant Module %s !" % (FfsFile.InfFileName))
786
787 PathClassObj = PathClass(FfsFile.InfFileName, self.WorkspaceDir)
788 #
789 # Here we just need to get FILE_GUID from INF file, use 'COMMON' as ARCH attribute. and use
790 # BuildObject from one of AutoGenObjectList is enough.
791 #
792 InfObj = self.AutoGenObjectList[0].BuildDatabase.WorkspaceDb.BuildObject[PathClassObj, 'COMMON', self.BuildTarget, self.ToolChain]
793 if not InfObj.Guid.upper() in _GuidDict.keys():
794 _GuidDict[InfObj.Guid.upper()] = FfsFile
795 else:
796 EdkLogger.error("build",
797 FORMAT_INVALID,
798 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile.CurrentLineNum,
799 FfsFile.CurrentLineContent,
800 _GuidDict[InfObj.Guid.upper()].CurrentLineNum,
801 _GuidDict[InfObj.Guid.upper()].CurrentLineContent,
802 InfObj.Guid.upper()),
803 ExtraData=self.FdfFile)
804 InfFoundFlag = False
805
806 if FfsFile.NameGuid != None:
807 _CheckPCDAsGuidPattern = re.compile("^PCD\(.+\..+\)$")
808
809 #
810 # If the NameGuid reference a PCD name.
811 # The style must match: PCD(xxxx.yyy)
812 #
813 if _CheckPCDAsGuidPattern.match(FfsFile.NameGuid):
814 #
815 # Replace the PCD value.
816 #
817 _PcdName = FfsFile.NameGuid.lstrip("PCD(").rstrip(")")
818 PcdFoundFlag = False
819 for Pa in self.AutoGenObjectList:
820 if not PcdFoundFlag:
821 for PcdItem in Pa.AllPcdList:
822 if (PcdItem.TokenSpaceGuidCName + "." + PcdItem.TokenCName) == _PcdName:
823 #
824 # First convert from CFormatGuid to GUID string
825 #
826 _PcdGuidString = GuidStructureStringToGuidString(PcdItem.DefaultValue)
827
828 if not _PcdGuidString:
829 #
830 # Then try Byte array.
831 #
832 _PcdGuidString = GuidStructureByteArrayToGuidString(PcdItem.DefaultValue)
833
834 if not _PcdGuidString:
835 #
836 # Not Byte array or CFormat GUID, raise error.
837 #
838 EdkLogger.error("build",
839 FORMAT_INVALID,
840 "The format of PCD value is incorrect. PCD: %s , Value: %s\n" % (_PcdName, PcdItem.DefaultValue),
841 ExtraData=self.FdfFile)
842
843 if not _PcdGuidString.upper() in _GuidDict.keys():
844 _GuidDict[_PcdGuidString.upper()] = FfsFile
845 PcdFoundFlag = True
846 break
847 else:
848 EdkLogger.error("build",
849 FORMAT_INVALID,
850 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile.CurrentLineNum,
851 FfsFile.CurrentLineContent,
852 _GuidDict[_PcdGuidString.upper()].CurrentLineNum,
853 _GuidDict[_PcdGuidString.upper()].CurrentLineContent,
854 FfsFile.NameGuid.upper()),
855 ExtraData=self.FdfFile)
856
857 if not FfsFile.NameGuid.upper() in _GuidDict.keys():
858 _GuidDict[FfsFile.NameGuid.upper()] = FfsFile
859 else:
860 #
861 # Two raw file GUID conflict.
862 #
863 EdkLogger.error("build",
864 FORMAT_INVALID,
865 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile.CurrentLineNum,
866 FfsFile.CurrentLineContent,
867 _GuidDict[FfsFile.NameGuid.upper()].CurrentLineNum,
868 _GuidDict[FfsFile.NameGuid.upper()].CurrentLineContent,
869 FfsFile.NameGuid.upper()),
870 ExtraData=self.FdfFile)
871
872
873 def _CheckPcdDefineAndType(self):
874 PcdTypeList = [
875 "FixedAtBuild", "PatchableInModule", "FeatureFlag",
876 "Dynamic", #"DynamicHii", "DynamicVpd",
877 "DynamicEx", # "DynamicExHii", "DynamicExVpd"
878 ]
879
880 # This dict store PCDs which are not used by any modules with specified arches
881 UnusedPcd = sdict()
882 for Pa in self.AutoGenObjectList:
883 # Key of DSC's Pcds dictionary is PcdCName, TokenSpaceGuid
884 for Pcd in Pa.Platform.Pcds:
885 PcdType = Pa.Platform.Pcds[Pcd].Type
886
887 # If no PCD type, this PCD comes from FDF
888 if not PcdType:
889 continue
890
891 # Try to remove Hii and Vpd suffix
892 if PcdType.startswith("DynamicEx"):
893 PcdType = "DynamicEx"
894 elif PcdType.startswith("Dynamic"):
895 PcdType = "Dynamic"
896
897 for Package in Pa.PackageList:
898 # Key of DEC's Pcds dictionary is PcdCName, TokenSpaceGuid, PcdType
899 if (Pcd[0], Pcd[1], PcdType) in Package.Pcds:
900 break
901 for Type in PcdTypeList:
902 if (Pcd[0], Pcd[1], Type) in Package.Pcds:
903 EdkLogger.error(
904 'build',
905 FORMAT_INVALID,
906 "Type [%s] of PCD [%s.%s] in DSC file doesn't match the type [%s] defined in DEC file." \
907 % (Pa.Platform.Pcds[Pcd].Type, Pcd[1], Pcd[0], Type),
908 ExtraData=None
909 )
910 return
911 else:
912 UnusedPcd.setdefault(Pcd, []).append(Pa.Arch)
913
914 for Pcd in UnusedPcd:
915 EdkLogger.warn(
916 'build',
917 "The PCD was not specified by any INF module in the platform for the given architecture.\n"
918 "\tPCD: [%s.%s]\n\tPlatform: [%s]\n\tArch: %s"
919 % (Pcd[1], Pcd[0], os.path.basename(str(self.MetaFile)), str(UnusedPcd[Pcd])),
920 ExtraData=None
921 )
922
923 def __repr__(self):
924 return "%s [%s]" % (self.MetaFile, ", ".join(self.ArchList))
925
926 ## Return the directory to store FV files
927 def _GetFvDir(self):
928 if self._FvDir == None:
929 self._FvDir = path.join(self.BuildDir, 'FV')
930 return self._FvDir
931
932 ## Return the directory to store all intermediate and final files built
933 def _GetBuildDir(self):
934 return self.AutoGenObjectList[0].BuildDir
935
936 ## Return the build output directory platform specifies
937 def _GetOutputDir(self):
938 return self.Platform.OutputDirectory
939
940 ## Return platform name
941 def _GetName(self):
942 return self.Platform.PlatformName
943
944 ## Return meta-file GUID
945 def _GetGuid(self):
946 return self.Platform.Guid
947
948 ## Return platform version
949 def _GetVersion(self):
950 return self.Platform.Version
951
952 ## Return paths of tools
953 def _GetToolDefinition(self):
954 return self.AutoGenObjectList[0].ToolDefinition
955
956 ## Return directory of platform makefile
957 #
958 # @retval string Makefile directory
959 #
960 def _GetMakeFileDir(self):
961 if self._MakeFileDir == None:
962 self._MakeFileDir = self.BuildDir
963 return self._MakeFileDir
964
965 ## Return build command string
966 #
967 # @retval string Build command string
968 #
969 def _GetBuildCommand(self):
970 if self._BuildCommand == None:
971 # BuildCommand should be all the same. So just get one from platform AutoGen
972 self._BuildCommand = self.AutoGenObjectList[0].BuildCommand
973 return self._BuildCommand
974
975 ## Check the PCDs token value conflict in each DEC file.
976 #
977 # Will cause build break and raise error message while two PCDs conflict.
978 #
979 # @return None
980 #
981 def _CheckAllPcdsTokenValueConflict(self):
982 for Pa in self.AutoGenObjectList:
983 for Package in Pa.PackageList:
984 PcdList = Package.Pcds.values()
985 PcdList.sort(lambda x, y: cmp(int(x.TokenValue, 0), int(y.TokenValue, 0)))
986 Count = 0
987 while (Count < len(PcdList) - 1) :
988 Item = PcdList[Count]
989 ItemNext = PcdList[Count + 1]
990 #
991 # Make sure in the same token space the TokenValue should be unique
992 #
993 if (int(Item.TokenValue, 0) == int(ItemNext.TokenValue, 0)):
994 SameTokenValuePcdList = []
995 SameTokenValuePcdList.append(Item)
996 SameTokenValuePcdList.append(ItemNext)
997 RemainPcdListLength = len(PcdList) - Count - 2
998 for ValueSameCount in range(RemainPcdListLength):
999 if int(PcdList[len(PcdList) - RemainPcdListLength + ValueSameCount].TokenValue, 0) == int(Item.TokenValue, 0):
1000 SameTokenValuePcdList.append(PcdList[len(PcdList) - RemainPcdListLength + ValueSameCount])
1001 else:
1002 break;
1003 #
1004 # Sort same token value PCD list with TokenGuid and TokenCName
1005 #
1006 SameTokenValuePcdList.sort(lambda x, y: cmp("%s.%s" % (x.TokenSpaceGuidCName, x.TokenCName), "%s.%s" % (y.TokenSpaceGuidCName, y.TokenCName)))
1007 SameTokenValuePcdListCount = 0
1008 while (SameTokenValuePcdListCount < len(SameTokenValuePcdList) - 1):
1009 Flag = False
1010 TemListItem = SameTokenValuePcdList[SameTokenValuePcdListCount]
1011 TemListItemNext = SameTokenValuePcdList[SameTokenValuePcdListCount + 1]
1012
1013 if (TemListItem.TokenSpaceGuidCName == TemListItemNext.TokenSpaceGuidCName) and (TemListItem.TokenCName != TemListItemNext.TokenCName):
1014 for PcdItem in GlobalData.MixedPcd:
1015 if (TemListItem.TokenCName, TemListItem.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem] or \
1016 (TemListItemNext.TokenCName, TemListItemNext.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:
1017 Flag = True
1018 if not Flag:
1019 EdkLogger.error(
1020 'build',
1021 FORMAT_INVALID,
1022 "The TokenValue [%s] of PCD [%s.%s] is conflict with: [%s.%s] in %s"\
1023 % (TemListItem.TokenValue, TemListItem.TokenSpaceGuidCName, TemListItem.TokenCName, TemListItemNext.TokenSpaceGuidCName, TemListItemNext.TokenCName, Package),
1024 ExtraData=None
1025 )
1026 SameTokenValuePcdListCount += 1
1027 Count += SameTokenValuePcdListCount
1028 Count += 1
1029
1030 PcdList = Package.Pcds.values()
1031 PcdList.sort(lambda x, y: cmp("%s.%s" % (x.TokenSpaceGuidCName, x.TokenCName), "%s.%s" % (y.TokenSpaceGuidCName, y.TokenCName)))
1032 Count = 0
1033 while (Count < len(PcdList) - 1) :
1034 Item = PcdList[Count]
1035 ItemNext = PcdList[Count + 1]
1036 #
1037 # Check PCDs with same TokenSpaceGuidCName.TokenCName have same token value as well.
1038 #
1039 if (Item.TokenSpaceGuidCName == ItemNext.TokenSpaceGuidCName) and (Item.TokenCName == ItemNext.TokenCName) and (int(Item.TokenValue, 0) != int(ItemNext.TokenValue, 0)):
1040 EdkLogger.error(
1041 'build',
1042 FORMAT_INVALID,
1043 "The TokenValue [%s] of PCD [%s.%s] in %s defined in two places should be same as well."\
1044 % (Item.TokenValue, Item.TokenSpaceGuidCName, Item.TokenCName, Package),
1045 ExtraData=None
1046 )
1047 Count += 1
1048 ## Generate fds command
1049 def _GenFdsCommand(self):
1050 return (GenMake.TopLevelMakefile(self)._TEMPLATE_.Replace(GenMake.TopLevelMakefile(self)._TemplateDict)).strip()
1051
1052 ## Create makefile for the platform and modules in it
1053 #
1054 # @param CreateDepsMakeFile Flag indicating if the makefile for
1055 # modules will be created as well
1056 #
1057 def CreateMakeFile(self, CreateDepsMakeFile=False):
1058 if CreateDepsMakeFile:
1059 for Pa in self.AutoGenObjectList:
1060 Pa.CreateMakeFile(CreateDepsMakeFile)
1061
1062 ## Create autogen code for platform and modules
1063 #
1064 # Since there's no autogen code for platform, this method will do nothing
1065 # if CreateModuleCodeFile is set to False.
1066 #
1067 # @param CreateDepsCodeFile Flag indicating if creating module's
1068 # autogen code file or not
1069 #
1070 def CreateCodeFile(self, CreateDepsCodeFile=False):
1071 if not CreateDepsCodeFile:
1072 return
1073 for Pa in self.AutoGenObjectList:
1074 Pa.CreateCodeFile(CreateDepsCodeFile)
1075
1076 ## Create AsBuilt INF file the platform
1077 #
1078 def CreateAsBuiltInf(self):
1079 return
1080
1081 Name = property(_GetName)
1082 Guid = property(_GetGuid)
1083 Version = property(_GetVersion)
1084 OutputDir = property(_GetOutputDir)
1085
1086 ToolDefinition = property(_GetToolDefinition) # toolcode : tool path
1087
1088 BuildDir = property(_GetBuildDir)
1089 FvDir = property(_GetFvDir)
1090 MakeFileDir = property(_GetMakeFileDir)
1091 BuildCommand = property(_GetBuildCommand)
1092 GenFdsCommand = property(_GenFdsCommand)
1093
1094 ## AutoGen class for platform
1095 #
1096 # PlatformAutoGen class will process the original information in platform
1097 # file in order to generate makefile for platform.
1098 #
1099 class PlatformAutoGen(AutoGen):
1100 #
1101 # Used to store all PCDs for both PEI and DXE phase, in order to generate
1102 # correct PCD database
1103 #
1104 _DynaPcdList_ = []
1105 _NonDynaPcdList_ = []
1106 _PlatformPcds = {}
1107
1108 #
1109 # The priority list while override build option
1110 #
1111 PrioList = {"0x11111" : 16, # TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE (Highest)
1112 "0x01111" : 15, # ******_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
1113 "0x10111" : 14, # TARGET_*********_ARCH_COMMANDTYPE_ATTRIBUTE
1114 "0x00111" : 13, # ******_*********_ARCH_COMMANDTYPE_ATTRIBUTE
1115 "0x11011" : 12, # TARGET_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE
1116 "0x01011" : 11, # ******_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE
1117 "0x10011" : 10, # TARGET_*********_****_COMMANDTYPE_ATTRIBUTE
1118 "0x00011" : 9, # ******_*********_****_COMMANDTYPE_ATTRIBUTE
1119 "0x11101" : 8, # TARGET_TOOLCHAIN_ARCH_***********_ATTRIBUTE
1120 "0x01101" : 7, # ******_TOOLCHAIN_ARCH_***********_ATTRIBUTE
1121 "0x10101" : 6, # TARGET_*********_ARCH_***********_ATTRIBUTE
1122 "0x00101" : 5, # ******_*********_ARCH_***********_ATTRIBUTE
1123 "0x11001" : 4, # TARGET_TOOLCHAIN_****_***********_ATTRIBUTE
1124 "0x01001" : 3, # ******_TOOLCHAIN_****_***********_ATTRIBUTE
1125 "0x10001" : 2, # TARGET_*********_****_***********_ATTRIBUTE
1126 "0x00001" : 1} # ******_*********_****_***********_ATTRIBUTE (Lowest)
1127
1128 ## The real constructor of PlatformAutoGen
1129 #
1130 # This method is not supposed to be called by users of PlatformAutoGen. It's
1131 # only used by factory method __new__() to do real initialization work for an
1132 # object of PlatformAutoGen
1133 #
1134 # @param Workspace WorkspaceAutoGen object
1135 # @param PlatformFile Platform file (DSC file)
1136 # @param Target Build target (DEBUG, RELEASE)
1137 # @param Toolchain Name of tool chain
1138 # @param Arch arch of the platform supports
1139 #
1140 def _Init(self, Workspace, PlatformFile, Target, Toolchain, Arch):
1141 EdkLogger.debug(EdkLogger.DEBUG_9, "AutoGen platform [%s] [%s]" % (PlatformFile, Arch))
1142 GlobalData.gProcessingFile = "%s [%s, %s, %s]" % (PlatformFile, Arch, Toolchain, Target)
1143
1144 self.MetaFile = PlatformFile
1145 self.Workspace = Workspace
1146 self.WorkspaceDir = Workspace.WorkspaceDir
1147 self.ToolChain = Toolchain
1148 self.BuildTarget = Target
1149 self.Arch = Arch
1150 self.SourceDir = PlatformFile.SubDir
1151 self.SourceOverrideDir = None
1152 self.FdTargetList = self.Workspace.FdTargetList
1153 self.FvTargetList = self.Workspace.FvTargetList
1154 self.AllPcdList = []
1155 # get the original module/package/platform objects
1156 self.BuildDatabase = Workspace.BuildDatabase
1157
1158 # flag indicating if the makefile/C-code file has been created or not
1159 self.IsMakeFileCreated = False
1160 self.IsCodeFileCreated = False
1161
1162 self._Platform = None
1163 self._Name = None
1164 self._Guid = None
1165 self._Version = None
1166
1167 self._BuildRule = None
1168 self._SourceDir = None
1169 self._BuildDir = None
1170 self._OutputDir = None
1171 self._FvDir = None
1172 self._MakeFileDir = None
1173 self._FdfFile = None
1174
1175 self._PcdTokenNumber = None # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber
1176 self._DynamicPcdList = None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
1177 self._NonDynamicPcdList = None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
1178 self._NonDynamicPcdDict = {}
1179
1180 self._ToolDefinitions = None
1181 self._ToolDefFile = None # toolcode : tool path
1182 self._ToolChainFamily = None
1183 self._BuildRuleFamily = None
1184 self._BuildOption = None # toolcode : option
1185 self._EdkBuildOption = None # edktoolcode : option
1186 self._EdkIIBuildOption = None # edkiitoolcode : option
1187 self._PackageList = None
1188 self._ModuleAutoGenList = None
1189 self._LibraryAutoGenList = None
1190 self._BuildCommand = None
1191 self._AsBuildInfList = []
1192 self._AsBuildModuleList = []
1193 if GlobalData.gFdfParser != None:
1194 self._AsBuildInfList = GlobalData.gFdfParser.Profile.InfList
1195 for Inf in self._AsBuildInfList:
1196 InfClass = PathClass(NormPath(Inf), GlobalData.gWorkspace, self.Arch)
1197 M = self.BuildDatabase[InfClass, self.Arch, self.BuildTarget, self.ToolChain]
1198 if not M.IsSupportedArch:
1199 continue
1200 self._AsBuildModuleList.append(InfClass)
1201 # get library/modules for build
1202 self.LibraryBuildDirectoryList = []
1203 self.ModuleBuildDirectoryList = []
1204 return True
1205
1206 def __repr__(self):
1207 return "%s [%s]" % (self.MetaFile, self.Arch)
1208
1209 ## Create autogen code for platform and modules
1210 #
1211 # Since there's no autogen code for platform, this method will do nothing
1212 # if CreateModuleCodeFile is set to False.
1213 #
1214 # @param CreateModuleCodeFile Flag indicating if creating module's
1215 # autogen code file or not
1216 #
1217 def CreateCodeFile(self, CreateModuleCodeFile=False):
1218 # only module has code to be greated, so do nothing if CreateModuleCodeFile is False
1219 if self.IsCodeFileCreated or not CreateModuleCodeFile:
1220 return
1221
1222 for Ma in self.ModuleAutoGenList:
1223 Ma.CreateCodeFile(True)
1224
1225 # don't do this twice
1226 self.IsCodeFileCreated = True
1227
1228 ## Generate Fds Command
1229 def _GenFdsCommand(self):
1230 return self.Workspace.GenFdsCommand
1231
1232 ## Create makefile for the platform and mdoules in it
1233 #
1234 # @param CreateModuleMakeFile Flag indicating if the makefile for
1235 # modules will be created as well
1236 #
1237 def CreateMakeFile(self, CreateModuleMakeFile=False):
1238 if CreateModuleMakeFile:
1239 for ModuleFile in self.Platform.Modules:
1240 Ma = ModuleAutoGen(self.Workspace, ModuleFile, self.BuildTarget,
1241 self.ToolChain, self.Arch, self.MetaFile)
1242 Ma.CreateMakeFile(True)
1243 #Ma.CreateAsBuiltInf()
1244
1245 # no need to create makefile for the platform more than once
1246 if self.IsMakeFileCreated:
1247 return
1248
1249 # create library/module build dirs for platform
1250 Makefile = GenMake.PlatformMakefile(self)
1251 self.LibraryBuildDirectoryList = Makefile.GetLibraryBuildDirectoryList()
1252 self.ModuleBuildDirectoryList = Makefile.GetModuleBuildDirectoryList()
1253
1254 self.IsMakeFileCreated = True
1255
1256 ## Deal with Shared FixedAtBuild Pcds
1257 #
1258 def CollectFixedAtBuildPcds(self):
1259 for LibAuto in self.LibraryAutoGenList:
1260 FixedAtBuildPcds = {}
1261 ShareFixedAtBuildPcdsSameValue = {}
1262 for Module in LibAuto._ReferenceModules:
1263 for Pcd in Module.FixedAtBuildPcds + LibAuto.FixedAtBuildPcds:
1264 key = ".".join((Pcd.TokenSpaceGuidCName,Pcd.TokenCName))
1265 if key not in FixedAtBuildPcds:
1266 ShareFixedAtBuildPcdsSameValue[key] = True
1267 FixedAtBuildPcds[key] = Pcd.DefaultValue
1268 else:
1269 if FixedAtBuildPcds[key] != Pcd.DefaultValue:
1270 ShareFixedAtBuildPcdsSameValue[key] = False
1271 for Pcd in LibAuto.FixedAtBuildPcds:
1272 key = ".".join((Pcd.TokenSpaceGuidCName,Pcd.TokenCName))
1273 if (Pcd.TokenCName,Pcd.TokenSpaceGuidCName) not in self.NonDynamicPcdDict:
1274 continue
1275 else:
1276 DscPcd = self.NonDynamicPcdDict[(Pcd.TokenCName,Pcd.TokenSpaceGuidCName)]
1277 if DscPcd.Type != "FixedAtBuild":
1278 continue
1279 if key in ShareFixedAtBuildPcdsSameValue and ShareFixedAtBuildPcdsSameValue[key]:
1280 LibAuto.ConstPcd[key] = Pcd.DefaultValue
1281
1282 ## Collect dynamic PCDs
1283 #
1284 # Gather dynamic PCDs list from each module and their settings from platform
1285 # This interface should be invoked explicitly when platform action is created.
1286 #
1287 def CollectPlatformDynamicPcds(self):
1288 # Override the platform Pcd's value by build option
1289 if GlobalData.BuildOptionPcd:
1290 for key in self.Platform.Pcds:
1291 PlatformPcd = self.Platform.Pcds[key]
1292 for PcdItem in GlobalData.BuildOptionPcd:
1293 if (PlatformPcd.TokenSpaceGuidCName, PlatformPcd.TokenCName) == (PcdItem[0], PcdItem[1]):
1294 PlatformPcd.DefaultValue = PcdItem[2]
1295 if PlatformPcd.SkuInfoList:
1296 Sku = PlatformPcd.SkuInfoList[PlatformPcd.SkuInfoList.keys()[0]]
1297 Sku.DefaultValue = PcdItem[2]
1298 break
1299
1300 for key in self.Platform.Pcds:
1301 for SinglePcd in GlobalData.MixedPcd:
1302 if (self.Platform.Pcds[key].TokenCName, self.Platform.Pcds[key].TokenSpaceGuidCName) == SinglePcd:
1303 for item in GlobalData.MixedPcd[SinglePcd]:
1304 Pcd_Type = item[0].split('_')[-1]
1305 if (Pcd_Type == self.Platform.Pcds[key].Type) or (Pcd_Type == TAB_PCDS_DYNAMIC_EX and self.Platform.Pcds[key].Type in GenC.gDynamicExPcd) or \
1306 (Pcd_Type == TAB_PCDS_DYNAMIC and self.Platform.Pcds[key].Type in GenC.gDynamicPcd):
1307 Value = self.Platform.Pcds[key]
1308 Value.TokenCName = self.Platform.Pcds[key].TokenCName + '_' + Pcd_Type
1309 if len(key) == 2:
1310 newkey = (Value.TokenCName, key[1])
1311 elif len(key) == 3:
1312 newkey = (Value.TokenCName, key[1], key[2])
1313 del self.Platform.Pcds[key]
1314 self.Platform.Pcds[newkey] = Value
1315 break
1316 else:
1317 pass
1318 break
1319 else:
1320 pass
1321
1322 # for gathering error information
1323 NoDatumTypePcdList = set()
1324 PcdNotInDb = []
1325 self._GuidValue = {}
1326 FdfModuleList = []
1327 for InfName in self._AsBuildInfList:
1328 InfName = mws.join(self.WorkspaceDir, InfName)
1329 FdfModuleList.append(os.path.normpath(InfName))
1330 for F in self.Platform.Modules.keys():
1331 M = ModuleAutoGen(self.Workspace, F, self.BuildTarget, self.ToolChain, self.Arch, self.MetaFile)
1332 #GuidValue.update(M.Guids)
1333
1334 self.Platform.Modules[F].M = M
1335
1336 for PcdFromModule in M.ModulePcdList + M.LibraryPcdList:
1337 # make sure that the "VOID*" kind of datum has MaxDatumSize set
1338 if PcdFromModule.DatumType == "VOID*" and PcdFromModule.MaxDatumSize in [None, '']:
1339 NoDatumTypePcdList.add("%s.%s [%s]" % (PcdFromModule.TokenSpaceGuidCName, PcdFromModule.TokenCName, F))
1340
1341 # Check the PCD from Binary INF or Source INF
1342 if M.IsBinaryModule == True:
1343 PcdFromModule.IsFromBinaryInf = True
1344
1345 # Check the PCD from DSC or not
1346 if (PcdFromModule.TokenCName, PcdFromModule.TokenSpaceGuidCName) in self.Platform.Pcds.keys():
1347 PcdFromModule.IsFromDsc = True
1348 else:
1349 PcdFromModule.IsFromDsc = False
1350 if PcdFromModule.Type in GenC.gDynamicPcd or PcdFromModule.Type in GenC.gDynamicExPcd:
1351 if F.Path not in FdfModuleList:
1352 # If one of the Source built modules listed in the DSC is not listed
1353 # in FDF modules, and the INF lists a PCD can only use the PcdsDynamic
1354 # access method (it is only listed in the DEC file that declares the
1355 # PCD as PcdsDynamic), then build tool will report warning message
1356 # notify the PI that they are attempting to build a module that must
1357 # be included in a flash image in order to be functional. These Dynamic
1358 # PCD will not be added into the Database unless it is used by other
1359 # modules that are included in the FDF file.
1360 if PcdFromModule.Type in GenC.gDynamicPcd and \
1361 PcdFromModule.IsFromBinaryInf == False:
1362 # Print warning message to let the developer make a determine.
1363 if PcdFromModule not in PcdNotInDb:
1364 PcdNotInDb.append(PcdFromModule)
1365 continue
1366 # If one of the Source built modules listed in the DSC is not listed in
1367 # FDF modules, and the INF lists a PCD can only use the PcdsDynamicEx
1368 # access method (it is only listed in the DEC file that declares the
1369 # PCD as PcdsDynamicEx), then DO NOT break the build; DO NOT add the
1370 # PCD to the Platform's PCD Database.
1371 if PcdFromModule.Type in GenC.gDynamicExPcd:
1372 if PcdFromModule not in PcdNotInDb:
1373 PcdNotInDb.append(PcdFromModule)
1374 continue
1375 #
1376 # If a dynamic PCD used by a PEM module/PEI module & DXE module,
1377 # it should be stored in Pcd PEI database, If a dynamic only
1378 # used by DXE module, it should be stored in DXE PCD database.
1379 # The default Phase is DXE
1380 #
1381 if M.ModuleType in ["PEIM", "PEI_CORE"]:
1382 PcdFromModule.Phase = "PEI"
1383 if PcdFromModule not in self._DynaPcdList_:
1384 self._DynaPcdList_.append(PcdFromModule)
1385 elif PcdFromModule.Phase == 'PEI':
1386 # overwrite any the same PCD existing, if Phase is PEI
1387 Index = self._DynaPcdList_.index(PcdFromModule)
1388 self._DynaPcdList_[Index] = PcdFromModule
1389 elif PcdFromModule not in self._NonDynaPcdList_:
1390 self._NonDynaPcdList_.append(PcdFromModule)
1391 elif PcdFromModule in self._NonDynaPcdList_ and PcdFromModule.IsFromBinaryInf == True:
1392 Index = self._NonDynaPcdList_.index(PcdFromModule)
1393 if self._NonDynaPcdList_[Index].IsFromBinaryInf == False:
1394 #The PCD from Binary INF will override the same one from source INF
1395 self._NonDynaPcdList_.remove (self._NonDynaPcdList_[Index])
1396 PcdFromModule.Pending = False
1397 self._NonDynaPcdList_.append (PcdFromModule)
1398 # Parse the DynamicEx PCD from the AsBuild INF module list of FDF.
1399 DscModuleList = []
1400 for ModuleInf in self.Platform.Modules.keys():
1401 DscModuleList.append (os.path.normpath(ModuleInf.Path))
1402 # add the PCD from modules that listed in FDF but not in DSC to Database
1403 for InfName in FdfModuleList:
1404 if InfName not in DscModuleList:
1405 InfClass = PathClass(InfName)
1406 M = self.BuildDatabase[InfClass, self.Arch, self.BuildTarget, self.ToolChain]
1407 # If a module INF in FDF but not in current arch's DSC module list, it must be module (either binary or source)
1408 # for different Arch. PCDs in source module for different Arch is already added before, so skip the source module here.
1409 # For binary module, if in current arch, we need to list the PCDs into database.
1410 if not M.IsSupportedArch:
1411 continue
1412 # Override the module PCD setting by platform setting
1413 ModulePcdList = self.ApplyPcdSetting(M, M.Pcds)
1414 for PcdFromModule in ModulePcdList:
1415 PcdFromModule.IsFromBinaryInf = True
1416 PcdFromModule.IsFromDsc = False
1417 # Only allow the DynamicEx and Patchable PCD in AsBuild INF
1418 if PcdFromModule.Type not in GenC.gDynamicExPcd and PcdFromModule.Type not in TAB_PCDS_PATCHABLE_IN_MODULE:
1419 EdkLogger.error("build", AUTOGEN_ERROR, "PCD setting error",
1420 File=self.MetaFile,
1421 ExtraData="\n\tExisted %s PCD %s in:\n\t\t%s\n"
1422 % (PcdFromModule.Type, PcdFromModule.TokenCName, InfName))
1423 # make sure that the "VOID*" kind of datum has MaxDatumSize set
1424 if PcdFromModule.DatumType == "VOID*" and PcdFromModule.MaxDatumSize in [None, '']:
1425 NoDatumTypePcdList.add("%s.%s [%s]" % (PcdFromModule.TokenSpaceGuidCName, PcdFromModule.TokenCName, InfName))
1426 if M.ModuleType in ["PEIM", "PEI_CORE"]:
1427 PcdFromModule.Phase = "PEI"
1428 if PcdFromModule not in self._DynaPcdList_ and PcdFromModule.Type in GenC.gDynamicExPcd:
1429 self._DynaPcdList_.append(PcdFromModule)
1430 elif PcdFromModule not in self._NonDynaPcdList_ and PcdFromModule.Type in TAB_PCDS_PATCHABLE_IN_MODULE:
1431 self._NonDynaPcdList_.append(PcdFromModule)
1432 if PcdFromModule in self._DynaPcdList_ and PcdFromModule.Phase == 'PEI' and PcdFromModule.Type in GenC.gDynamicExPcd:
1433 # Overwrite the phase of any the same PCD existing, if Phase is PEI.
1434 # It is to solve the case that a dynamic PCD used by a PEM module/PEI
1435 # module & DXE module at a same time.
1436 # Overwrite the type of the PCDs in source INF by the type of AsBuild
1437 # INF file as DynamicEx.
1438 Index = self._DynaPcdList_.index(PcdFromModule)
1439 self._DynaPcdList_[Index].Phase = PcdFromModule.Phase
1440 self._DynaPcdList_[Index].Type = PcdFromModule.Type
1441 for PcdFromModule in self._NonDynaPcdList_:
1442 # If a PCD is not listed in the DSC file, but binary INF files used by
1443 # this platform all (that use this PCD) list the PCD in a [PatchPcds]
1444 # section, AND all source INF files used by this platform the build
1445 # that use the PCD list the PCD in either a [Pcds] or [PatchPcds]
1446 # section, then the tools must NOT add the PCD to the Platform's PCD
1447 # Database; the build must assign the access method for this PCD as
1448 # PcdsPatchableInModule.
1449 if PcdFromModule not in self._DynaPcdList_:
1450 continue
1451 Index = self._DynaPcdList_.index(PcdFromModule)
1452 if PcdFromModule.IsFromDsc == False and \
1453 PcdFromModule.Type in TAB_PCDS_PATCHABLE_IN_MODULE and \
1454 PcdFromModule.IsFromBinaryInf == True and \
1455 self._DynaPcdList_[Index].IsFromBinaryInf == False:
1456 Index = self._DynaPcdList_.index(PcdFromModule)
1457 self._DynaPcdList_.remove (self._DynaPcdList_[Index])
1458
1459 # print out error information and break the build, if error found
1460 if len(NoDatumTypePcdList) > 0:
1461 NoDatumTypePcdListString = "\n\t\t".join(NoDatumTypePcdList)
1462 EdkLogger.error("build", AUTOGEN_ERROR, "PCD setting error",
1463 File=self.MetaFile,
1464 ExtraData="\n\tPCD(s) without MaxDatumSize:\n\t\t%s\n"
1465 % NoDatumTypePcdListString)
1466 self._NonDynamicPcdList = self._NonDynaPcdList_
1467 self._DynamicPcdList = self._DynaPcdList_
1468 #
1469 # Sort dynamic PCD list to:
1470 # 1) If PCD's datum type is VOID* and value is unicode string which starts with L, the PCD item should
1471 # try to be put header of dynamicd List
1472 # 2) If PCD is HII type, the PCD item should be put after unicode type PCD
1473 #
1474 # The reason of sorting is make sure the unicode string is in double-byte alignment in string table.
1475 #
1476 UnicodePcdArray = []
1477 HiiPcdArray = []
1478 OtherPcdArray = []
1479 VpdPcdDict = {}
1480 VpdFile = VpdInfoFile.VpdInfoFile()
1481 NeedProcessVpdMapFile = False
1482
1483 for pcd in self.Platform.Pcds.keys():
1484 if pcd not in self._PlatformPcds.keys():
1485 self._PlatformPcds[pcd] = self.Platform.Pcds[pcd]
1486
1487 if (self.Workspace.ArchList[-1] == self.Arch):
1488 for Pcd in self._DynamicPcdList:
1489 # just pick the a value to determine whether is unicode string type
1490 Sku = Pcd.SkuInfoList[Pcd.SkuInfoList.keys()[0]]
1491 Sku.VpdOffset = Sku.VpdOffset.strip()
1492
1493 PcdValue = Sku.DefaultValue
1494 if Pcd.DatumType == 'VOID*' and PcdValue.startswith("L"):
1495 # if found PCD which datum value is unicode string the insert to left size of UnicodeIndex
1496 UnicodePcdArray.append(Pcd)
1497 elif len(Sku.VariableName) > 0:
1498 # if found HII type PCD then insert to right of UnicodeIndex
1499 HiiPcdArray.append(Pcd)
1500 else:
1501 OtherPcdArray.append(Pcd)
1502 if Pcd.Type in [TAB_PCDS_DYNAMIC_VPD, TAB_PCDS_DYNAMIC_EX_VPD]:
1503 VpdPcdDict[(Pcd.TokenCName, Pcd.TokenSpaceGuidCName)] = Pcd
1504
1505 PlatformPcds = self._PlatformPcds.keys()
1506 PlatformPcds.sort()
1507 #
1508 # Add VPD type PCD into VpdFile and determine whether the VPD PCD need to be fixed up.
1509 #
1510 for PcdKey in PlatformPcds:
1511 Pcd = self._PlatformPcds[PcdKey]
1512 if Pcd.Type in [TAB_PCDS_DYNAMIC_VPD, TAB_PCDS_DYNAMIC_EX_VPD] and \
1513 PcdKey in VpdPcdDict:
1514 Pcd = VpdPcdDict[PcdKey]
1515 for (SkuName,Sku) in Pcd.SkuInfoList.items():
1516 Sku.VpdOffset = Sku.VpdOffset.strip()
1517 PcdValue = Sku.DefaultValue
1518 if PcdValue == "":
1519 PcdValue = Pcd.DefaultValue
1520 if Sku.VpdOffset != '*':
1521 if PcdValue.startswith("{"):
1522 Alignment = 8
1523 elif PcdValue.startswith("L"):
1524 Alignment = 2
1525 else:
1526 Alignment = 1
1527 try:
1528 VpdOffset = int(Sku.VpdOffset)
1529 except:
1530 try:
1531 VpdOffset = int(Sku.VpdOffset, 16)
1532 except:
1533 EdkLogger.error("build", FORMAT_INVALID, "Invalid offset value %s for PCD %s.%s." % (Sku.VpdOffset, Pcd.TokenSpaceGuidCName, Pcd.TokenCName))
1534 if VpdOffset % Alignment != 0:
1535 if PcdValue.startswith("{"):
1536 EdkLogger.warn("build", "The offset value of PCD %s.%s is not 8-byte aligned!" %(Pcd.TokenSpaceGuidCName, Pcd.TokenCName), File=self.MetaFile)
1537 else:
1538 EdkLogger.error("build", FORMAT_INVALID, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, Alignment))
1539 VpdFile.Add(Pcd, Sku.VpdOffset)
1540 # if the offset of a VPD is *, then it need to be fixed up by third party tool.
1541 if not NeedProcessVpdMapFile and Sku.VpdOffset == "*":
1542 NeedProcessVpdMapFile = True
1543 if self.Platform.VpdToolGuid == None or self.Platform.VpdToolGuid == '':
1544 EdkLogger.error("Build", FILE_NOT_FOUND, \
1545 "Fail to find third-party BPDG tool to process VPD PCDs. BPDG Guid tool need to be defined in tools_def.txt and VPD_TOOL_GUID need to be provided in DSC file.")
1546
1547
1548 #
1549 # Fix the PCDs define in VPD PCD section that never referenced by module.
1550 # An example is PCD for signature usage.
1551 #
1552 for DscPcd in PlatformPcds:
1553 DscPcdEntry = self._PlatformPcds[DscPcd]
1554 if DscPcdEntry.Type in [TAB_PCDS_DYNAMIC_VPD, TAB_PCDS_DYNAMIC_EX_VPD]:
1555 if not (self.Platform.VpdToolGuid == None or self.Platform.VpdToolGuid == ''):
1556 FoundFlag = False
1557 for VpdPcd in VpdFile._VpdArray.keys():
1558 # This PCD has been referenced by module
1559 if (VpdPcd.TokenSpaceGuidCName == DscPcdEntry.TokenSpaceGuidCName) and \
1560 (VpdPcd.TokenCName == DscPcdEntry.TokenCName):
1561 FoundFlag = True
1562
1563 # Not found, it should be signature
1564 if not FoundFlag :
1565 # just pick the a value to determine whether is unicode string type
1566 for (SkuName,Sku) in DscPcdEntry.SkuInfoList.items():
1567 Sku.VpdOffset = Sku.VpdOffset.strip()
1568
1569 # Need to iterate DEC pcd information to get the value & datumtype
1570 for eachDec in self.PackageList:
1571 for DecPcd in eachDec.Pcds:
1572 DecPcdEntry = eachDec.Pcds[DecPcd]
1573 if (DecPcdEntry.TokenSpaceGuidCName == DscPcdEntry.TokenSpaceGuidCName) and \
1574 (DecPcdEntry.TokenCName == DscPcdEntry.TokenCName):
1575 # Print warning message to let the developer make a determine.
1576 EdkLogger.warn("build", "Unreferenced vpd pcd used!",
1577 File=self.MetaFile, \
1578 ExtraData = "PCD: %s.%s used in the DSC file %s is unreferenced." \
1579 %(DscPcdEntry.TokenSpaceGuidCName, DscPcdEntry.TokenCName, self.Platform.MetaFile.Path))
1580
1581 DscPcdEntry.DatumType = DecPcdEntry.DatumType
1582 DscPcdEntry.DefaultValue = DecPcdEntry.DefaultValue
1583 DscPcdEntry.TokenValue = DecPcdEntry.TokenValue
1584 DscPcdEntry.TokenSpaceGuidValue = eachDec.Guids[DecPcdEntry.TokenSpaceGuidCName]
1585 # Only fix the value while no value provided in DSC file.
1586 if (Sku.DefaultValue == "" or Sku.DefaultValue==None):
1587 DscPcdEntry.SkuInfoList[DscPcdEntry.SkuInfoList.keys()[0]].DefaultValue = DecPcdEntry.DefaultValue
1588
1589 if DscPcdEntry not in self._DynamicPcdList:
1590 self._DynamicPcdList.append(DscPcdEntry)
1591 # Sku = DscPcdEntry.SkuInfoList[DscPcdEntry.SkuInfoList.keys()[0]]
1592 Sku.VpdOffset = Sku.VpdOffset.strip()
1593 PcdValue = Sku.DefaultValue
1594 if PcdValue == "":
1595 PcdValue = DscPcdEntry.DefaultValue
1596 if Sku.VpdOffset != '*':
1597 if PcdValue.startswith("{"):
1598 Alignment = 8
1599 elif PcdValue.startswith("L"):
1600 Alignment = 2
1601 else:
1602 Alignment = 1
1603 try:
1604 VpdOffset = int(Sku.VpdOffset)
1605 except:
1606 try:
1607 VpdOffset = int(Sku.VpdOffset, 16)
1608 except:
1609 EdkLogger.error("build", FORMAT_INVALID, "Invalid offset value %s for PCD %s.%s." % (Sku.VpdOffset, DscPcdEntry.TokenSpaceGuidCName, DscPcdEntry.TokenCName))
1610 if VpdOffset % Alignment != 0:
1611 if PcdValue.startswith("{"):
1612 EdkLogger.warn("build", "The offset value of PCD %s.%s is not 8-byte aligned!" %(DscPcdEntry.TokenSpaceGuidCName, DscPcdEntry.TokenCName), File=self.MetaFile)
1613 else:
1614 EdkLogger.error("build", FORMAT_INVALID, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (DscPcdEntry.TokenSpaceGuidCName, DscPcdEntry.TokenCName, Alignment))
1615 VpdFile.Add(DscPcdEntry, Sku.VpdOffset)
1616 if not NeedProcessVpdMapFile and Sku.VpdOffset == "*":
1617 NeedProcessVpdMapFile = True
1618 if DscPcdEntry.DatumType == 'VOID*' and PcdValue.startswith("L"):
1619 UnicodePcdArray.append(DscPcdEntry)
1620 elif len(Sku.VariableName) > 0:
1621 HiiPcdArray.append(DscPcdEntry)
1622 else:
1623 OtherPcdArray.append(DscPcdEntry)
1624
1625 # if the offset of a VPD is *, then it need to be fixed up by third party tool.
1626
1627
1628
1629 if (self.Platform.FlashDefinition == None or self.Platform.FlashDefinition == '') and \
1630 VpdFile.GetCount() != 0:
1631 EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE,
1632 "Fail to get FLASH_DEFINITION definition in DSC file %s which is required when DSC contains VPD PCD." % str(self.Platform.MetaFile))
1633
1634 if VpdFile.GetCount() != 0:
1635 FvPath = os.path.join(self.BuildDir, "FV")
1636 if not os.path.exists(FvPath):
1637 try:
1638 os.makedirs(FvPath)
1639 except:
1640 EdkLogger.error("build", FILE_WRITE_FAILURE, "Fail to create FV folder under %s" % self.BuildDir)
1641
1642 VpdFilePath = os.path.join(FvPath, "%s.txt" % self.Platform.VpdToolGuid)
1643
1644 if VpdFile.Write(VpdFilePath):
1645 # retrieve BPDG tool's path from tool_def.txt according to VPD_TOOL_GUID defined in DSC file.
1646 BPDGToolName = None
1647 for ToolDef in self.ToolDefinition.values():
1648 if ToolDef.has_key("GUID") and ToolDef["GUID"] == self.Platform.VpdToolGuid:
1649 if not ToolDef.has_key("PATH"):
1650 EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, "PATH attribute was not provided for BPDG guid tool %s in tools_def.txt" % self.Platform.VpdToolGuid)
1651 BPDGToolName = ToolDef["PATH"]
1652 break
1653 # Call third party GUID BPDG tool.
1654 if BPDGToolName != None:
1655 VpdInfoFile.CallExtenalBPDGTool(BPDGToolName, VpdFilePath)
1656 else:
1657 EdkLogger.error("Build", FILE_NOT_FOUND, "Fail to find third-party BPDG tool to process VPD PCDs. BPDG Guid tool need to be defined in tools_def.txt and VPD_TOOL_GUID need to be provided in DSC file.")
1658
1659 # Process VPD map file generated by third party BPDG tool
1660 if NeedProcessVpdMapFile:
1661 VpdMapFilePath = os.path.join(self.BuildDir, "FV", "%s.map" % self.Platform.VpdToolGuid)
1662 if os.path.exists(VpdMapFilePath):
1663 VpdFile.Read(VpdMapFilePath)
1664
1665 # Fixup "*" offset
1666 for Pcd in self._DynamicPcdList:
1667 # just pick the a value to determine whether is unicode string type
1668 i = 0
1669 for (SkuName,Sku) in Pcd.SkuInfoList.items():
1670 if Sku.VpdOffset == "*":
1671 Sku.VpdOffset = VpdFile.GetOffset(Pcd)[i].strip()
1672 i += 1
1673 else:
1674 EdkLogger.error("build", FILE_READ_FAILURE, "Can not find VPD map file %s to fix up VPD offset." % VpdMapFilePath)
1675
1676 # Delete the DynamicPcdList At the last time enter into this function
1677 del self._DynamicPcdList[:]
1678 self._DynamicPcdList.extend(UnicodePcdArray)
1679 self._DynamicPcdList.extend(HiiPcdArray)
1680 self._DynamicPcdList.extend(OtherPcdArray)
1681 self.AllPcdList = self._NonDynamicPcdList + self._DynamicPcdList
1682
1683 ## Return the platform build data object
1684 def _GetPlatform(self):
1685 if self._Platform == None:
1686 self._Platform = self.BuildDatabase[self.MetaFile, self.Arch, self.BuildTarget, self.ToolChain]
1687 return self._Platform
1688
1689 ## Return platform name
1690 def _GetName(self):
1691 return self.Platform.PlatformName
1692
1693 ## Return the meta file GUID
1694 def _GetGuid(self):
1695 return self.Platform.Guid
1696
1697 ## Return the platform version
1698 def _GetVersion(self):
1699 return self.Platform.Version
1700
1701 ## Return the FDF file name
1702 def _GetFdfFile(self):
1703 if self._FdfFile == None:
1704 if self.Workspace.FdfFile != "":
1705 self._FdfFile= mws.join(self.WorkspaceDir, self.Workspace.FdfFile)
1706 else:
1707 self._FdfFile = ''
1708 return self._FdfFile
1709
1710 ## Return the build output directory platform specifies
1711 def _GetOutputDir(self):
1712 return self.Platform.OutputDirectory
1713
1714 ## Return the directory to store all intermediate and final files built
1715 def _GetBuildDir(self):
1716 if self._BuildDir == None:
1717 if os.path.isabs(self.OutputDir):
1718 self._BuildDir = path.join(
1719 path.abspath(self.OutputDir),
1720 self.BuildTarget + "_" + self.ToolChain,
1721 )
1722 else:
1723 self._BuildDir = path.join(
1724 self.WorkspaceDir,
1725 self.OutputDir,
1726 self.BuildTarget + "_" + self.ToolChain,
1727 )
1728 return self._BuildDir
1729
1730 ## Return directory of platform makefile
1731 #
1732 # @retval string Makefile directory
1733 #
1734 def _GetMakeFileDir(self):
1735 if self._MakeFileDir == None:
1736 self._MakeFileDir = path.join(self.BuildDir, self.Arch)
1737 return self._MakeFileDir
1738
1739 ## Return build command string
1740 #
1741 # @retval string Build command string
1742 #
1743 def _GetBuildCommand(self):
1744 if self._BuildCommand == None:
1745 self._BuildCommand = []
1746 if "MAKE" in self.ToolDefinition and "PATH" in self.ToolDefinition["MAKE"]:
1747 self._BuildCommand += SplitOption(self.ToolDefinition["MAKE"]["PATH"])
1748 if "FLAGS" in self.ToolDefinition["MAKE"]:
1749 NewOption = self.ToolDefinition["MAKE"]["FLAGS"].strip()
1750 if NewOption != '':
1751 self._BuildCommand += SplitOption(NewOption)
1752 return self._BuildCommand
1753
1754 ## Get tool chain definition
1755 #
1756 # Get each tool defition for given tool chain from tools_def.txt and platform
1757 #
1758 def _GetToolDefinition(self):
1759 if self._ToolDefinitions == None:
1760 ToolDefinition = self.Workspace.ToolDef.ToolsDefTxtDictionary
1761 if TAB_TOD_DEFINES_COMMAND_TYPE not in self.Workspace.ToolDef.ToolsDefTxtDatabase:
1762 EdkLogger.error('build', RESOURCE_NOT_AVAILABLE, "No tools found in configuration",
1763 ExtraData="[%s]" % self.MetaFile)
1764 self._ToolDefinitions = {}
1765 DllPathList = set()
1766 for Def in ToolDefinition:
1767 Target, Tag, Arch, Tool, Attr = Def.split("_")
1768 if Target != self.BuildTarget or Tag != self.ToolChain or Arch != self.Arch:
1769 continue
1770
1771 Value = ToolDefinition[Def]
1772 # don't record the DLL
1773 if Attr == "DLL":
1774 DllPathList.add(Value)
1775 continue
1776
1777 if Tool not in self._ToolDefinitions:
1778 self._ToolDefinitions[Tool] = {}
1779 self._ToolDefinitions[Tool][Attr] = Value
1780
1781 ToolsDef = ''
1782 MakePath = ''
1783 if GlobalData.gOptions.SilentMode and "MAKE" in self._ToolDefinitions:
1784 if "FLAGS" not in self._ToolDefinitions["MAKE"]:
1785 self._ToolDefinitions["MAKE"]["FLAGS"] = ""
1786 self._ToolDefinitions["MAKE"]["FLAGS"] += " -s"
1787 MakeFlags = ''
1788 for Tool in self._ToolDefinitions:
1789 for Attr in self._ToolDefinitions[Tool]:
1790 Value = self._ToolDefinitions[Tool][Attr]
1791 if Tool in self.BuildOption and Attr in self.BuildOption[Tool]:
1792 # check if override is indicated
1793 if self.BuildOption[Tool][Attr].startswith('='):
1794 Value = self.BuildOption[Tool][Attr][1:]
1795 else:
1796 if Attr != 'PATH':
1797 Value += " " + self.BuildOption[Tool][Attr]
1798 else:
1799 Value = self.BuildOption[Tool][Attr]
1800
1801 if Attr == "PATH":
1802 # Don't put MAKE definition in the file
1803 if Tool == "MAKE":
1804 MakePath = Value
1805 else:
1806 ToolsDef += "%s = %s\n" % (Tool, Value)
1807 elif Attr != "DLL":
1808 # Don't put MAKE definition in the file
1809 if Tool == "MAKE":
1810 if Attr == "FLAGS":
1811 MakeFlags = Value
1812 else:
1813 ToolsDef += "%s_%s = %s\n" % (Tool, Attr, Value)
1814 ToolsDef += "\n"
1815
1816 SaveFileOnChange(self.ToolDefinitionFile, ToolsDef)
1817 for DllPath in DllPathList:
1818 os.environ["PATH"] = DllPath + os.pathsep + os.environ["PATH"]
1819 os.environ["MAKE_FLAGS"] = MakeFlags
1820
1821 return self._ToolDefinitions
1822
1823 ## Return the paths of tools
1824 def _GetToolDefFile(self):
1825 if self._ToolDefFile == None:
1826 self._ToolDefFile = os.path.join(self.MakeFileDir, "TOOLS_DEF." + self.Arch)
1827 return self._ToolDefFile
1828
1829 ## Retrieve the toolchain family of given toolchain tag. Default to 'MSFT'.
1830 def _GetToolChainFamily(self):
1831 if self._ToolChainFamily == None:
1832 ToolDefinition = self.Workspace.ToolDef.ToolsDefTxtDatabase
1833 if TAB_TOD_DEFINES_FAMILY not in ToolDefinition \
1834 or self.ToolChain not in ToolDefinition[TAB_TOD_DEFINES_FAMILY] \
1835 or not ToolDefinition[TAB_TOD_DEFINES_FAMILY][self.ToolChain]:
1836 EdkLogger.verbose("No tool chain family found in configuration for %s. Default to MSFT." \
1837 % self.ToolChain)
1838 self._ToolChainFamily = "MSFT"
1839 else:
1840 self._ToolChainFamily = ToolDefinition[TAB_TOD_DEFINES_FAMILY][self.ToolChain]
1841 return self._ToolChainFamily
1842
1843 def _GetBuildRuleFamily(self):
1844 if self._BuildRuleFamily == None:
1845 ToolDefinition = self.Workspace.ToolDef.ToolsDefTxtDatabase
1846 if TAB_TOD_DEFINES_BUILDRULEFAMILY not in ToolDefinition \
1847 or self.ToolChain not in ToolDefinition[TAB_TOD_DEFINES_BUILDRULEFAMILY] \
1848 or not ToolDefinition[TAB_TOD_DEFINES_BUILDRULEFAMILY][self.ToolChain]:
1849 EdkLogger.verbose("No tool chain family found in configuration for %s. Default to MSFT." \
1850 % self.ToolChain)
1851 self._BuildRuleFamily = "MSFT"
1852 else:
1853 self._BuildRuleFamily = ToolDefinition[TAB_TOD_DEFINES_BUILDRULEFAMILY][self.ToolChain]
1854 return self._BuildRuleFamily
1855
1856 ## Return the build options specific for all modules in this platform
1857 def _GetBuildOptions(self):
1858 if self._BuildOption == None:
1859 self._BuildOption = self._ExpandBuildOption(self.Platform.BuildOptions)
1860 return self._BuildOption
1861
1862 ## Return the build options specific for EDK modules in this platform
1863 def _GetEdkBuildOptions(self):
1864 if self._EdkBuildOption == None:
1865 self._EdkBuildOption = self._ExpandBuildOption(self.Platform.BuildOptions, EDK_NAME)
1866 return self._EdkBuildOption
1867
1868 ## Return the build options specific for EDKII modules in this platform
1869 def _GetEdkIIBuildOptions(self):
1870 if self._EdkIIBuildOption == None:
1871 self._EdkIIBuildOption = self._ExpandBuildOption(self.Platform.BuildOptions, EDKII_NAME)
1872 return self._EdkIIBuildOption
1873
1874 ## Parse build_rule.txt in Conf Directory.
1875 #
1876 # @retval BuildRule object
1877 #
1878 def _GetBuildRule(self):
1879 if self._BuildRule == None:
1880 BuildRuleFile = None
1881 if TAB_TAT_DEFINES_BUILD_RULE_CONF in self.Workspace.TargetTxt.TargetTxtDictionary:
1882 BuildRuleFile = self.Workspace.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_BUILD_RULE_CONF]
1883 if BuildRuleFile in [None, '']:
1884 BuildRuleFile = gDefaultBuildRuleFile
1885 self._BuildRule = BuildRule(BuildRuleFile)
1886 if self._BuildRule._FileVersion == "":
1887 self._BuildRule._FileVersion = AutoGenReqBuildRuleVerNum
1888 else:
1889 if self._BuildRule._FileVersion < AutoGenReqBuildRuleVerNum :
1890 # If Build Rule's version is less than the version number required by the tools, halting the build.
1891 EdkLogger.error("build", AUTOGEN_ERROR,
1892 ExtraData="The version number [%s] of build_rule.txt is less than the version number required by the AutoGen.(the minimum required version number is [%s])"\
1893 % (self._BuildRule._FileVersion, AutoGenReqBuildRuleVerNum))
1894
1895 return self._BuildRule
1896
1897 ## Summarize the packages used by modules in this platform
1898 def _GetPackageList(self):
1899 if self._PackageList == None:
1900 self._PackageList = set()
1901 for La in self.LibraryAutoGenList:
1902 self._PackageList.update(La.DependentPackageList)
1903 for Ma in self.ModuleAutoGenList:
1904 self._PackageList.update(Ma.DependentPackageList)
1905 #Collect package set information from INF of FDF
1906 PkgSet = set()
1907 for ModuleFile in self._AsBuildModuleList:
1908 if ModuleFile in self.Platform.Modules:
1909 continue
1910 ModuleData = self.BuildDatabase[ModuleFile, self.Arch, self.BuildTarget, self.ToolChain]
1911 PkgSet.update(ModuleData.Packages)
1912 self._PackageList = list(self._PackageList) + list (PkgSet)
1913 return self._PackageList
1914
1915 def _GetNonDynamicPcdDict(self):
1916 if self._NonDynamicPcdDict:
1917 return self._NonDynamicPcdDict
1918 for Pcd in self.NonDynamicPcdList:
1919 self._NonDynamicPcdDict[(Pcd.TokenCName,Pcd.TokenSpaceGuidCName)] = Pcd
1920 return self._NonDynamicPcdDict
1921
1922 ## Get list of non-dynamic PCDs
1923 def _GetNonDynamicPcdList(self):
1924 if self._NonDynamicPcdList == None:
1925 self.CollectPlatformDynamicPcds()
1926 return self._NonDynamicPcdList
1927
1928 ## Get list of dynamic PCDs
1929 def _GetDynamicPcdList(self):
1930 if self._DynamicPcdList == None:
1931 self.CollectPlatformDynamicPcds()
1932 return self._DynamicPcdList
1933
1934 ## Generate Token Number for all PCD
1935 def _GetPcdTokenNumbers(self):
1936 if self._PcdTokenNumber == None:
1937 self._PcdTokenNumber = sdict()
1938 TokenNumber = 1
1939 #
1940 # Make the Dynamic and DynamicEx PCD use within different TokenNumber area.
1941 # Such as:
1942 #
1943 # Dynamic PCD:
1944 # TokenNumber 0 ~ 10
1945 # DynamicEx PCD:
1946 # TokeNumber 11 ~ 20
1947 #
1948 for Pcd in self.DynamicPcdList:
1949 if Pcd.Phase == "PEI":
1950 if Pcd.Type in ["Dynamic", "DynamicDefault", "DynamicVpd", "DynamicHii"]:
1951 EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))
1952 self._PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber
1953 TokenNumber += 1
1954
1955 for Pcd in self.DynamicPcdList:
1956 if Pcd.Phase == "PEI":
1957 if Pcd.Type in ["DynamicEx", "DynamicExDefault", "DynamicExVpd", "DynamicExHii"]:
1958 EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))
1959 self._PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber
1960 TokenNumber += 1
1961
1962 for Pcd in self.DynamicPcdList:
1963 if Pcd.Phase == "DXE":
1964 if Pcd.Type in ["Dynamic", "DynamicDefault", "DynamicVpd", "DynamicHii"]:
1965 EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))
1966 self._PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber
1967 TokenNumber += 1
1968
1969 for Pcd in self.DynamicPcdList:
1970 if Pcd.Phase == "DXE":
1971 if Pcd.Type in ["DynamicEx", "DynamicExDefault", "DynamicExVpd", "DynamicExHii"]:
1972 EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))
1973 self._PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber
1974 TokenNumber += 1
1975
1976 for Pcd in self.NonDynamicPcdList:
1977 self._PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber
1978 TokenNumber += 1
1979 return self._PcdTokenNumber
1980
1981 ## Summarize ModuleAutoGen objects of all modules/libraries to be built for this platform
1982 def _GetAutoGenObjectList(self):
1983 self._ModuleAutoGenList = []
1984 self._LibraryAutoGenList = []
1985 for ModuleFile in self.Platform.Modules:
1986 Ma = ModuleAutoGen(
1987 self.Workspace,
1988 ModuleFile,
1989 self.BuildTarget,
1990 self.ToolChain,
1991 self.Arch,
1992 self.MetaFile
1993 )
1994 if Ma not in self._ModuleAutoGenList:
1995 self._ModuleAutoGenList.append(Ma)
1996 for La in Ma.LibraryAutoGenList:
1997 if La not in self._LibraryAutoGenList:
1998 self._LibraryAutoGenList.append(La)
1999 if Ma not in La._ReferenceModules:
2000 La._ReferenceModules.append(Ma)
2001
2002 ## Summarize ModuleAutoGen objects of all modules to be built for this platform
2003 def _GetModuleAutoGenList(self):
2004 if self._ModuleAutoGenList == None:
2005 self._GetAutoGenObjectList()
2006 return self._ModuleAutoGenList
2007
2008 ## Summarize ModuleAutoGen objects of all libraries to be built for this platform
2009 def _GetLibraryAutoGenList(self):
2010 if self._LibraryAutoGenList == None:
2011 self._GetAutoGenObjectList()
2012 return self._LibraryAutoGenList
2013
2014 ## Test if a module is supported by the platform
2015 #
2016 # An error will be raised directly if the module or its arch is not supported
2017 # by the platform or current configuration
2018 #
2019 def ValidModule(self, Module):
2020 return Module in self.Platform.Modules or Module in self.Platform.LibraryInstances \
2021 or Module in self._AsBuildModuleList
2022
2023 ## Resolve the library classes in a module to library instances
2024 #
2025 # This method will not only resolve library classes but also sort the library
2026 # instances according to the dependency-ship.
2027 #
2028 # @param Module The module from which the library classes will be resolved
2029 #
2030 # @retval library_list List of library instances sorted
2031 #
2032 def ApplyLibraryInstance(self, Module):
2033 # Cover the case that the binary INF file is list in the FDF file but not DSC file, return empty list directly
2034 if str(Module) not in self.Platform.Modules:
2035 return []
2036
2037 ModuleType = Module.ModuleType
2038
2039 # for overridding library instances with module specific setting
2040 PlatformModule = self.Platform.Modules[str(Module)]
2041
2042 # add forced library instances (specified under LibraryClasses sections)
2043 #
2044 # If a module has a MODULE_TYPE of USER_DEFINED,
2045 # do not link in NULL library class instances from the global [LibraryClasses.*] sections.
2046 #
2047 if Module.ModuleType != SUP_MODULE_USER_DEFINED:
2048 for LibraryClass in self.Platform.LibraryClasses.GetKeys():
2049 if LibraryClass.startswith("NULL") and self.Platform.LibraryClasses[LibraryClass, Module.ModuleType]:
2050 Module.LibraryClasses[LibraryClass] = self.Platform.LibraryClasses[LibraryClass, Module.ModuleType]
2051
2052 # add forced library instances (specified in module overrides)
2053 for LibraryClass in PlatformModule.LibraryClasses:
2054 if LibraryClass.startswith("NULL"):
2055 Module.LibraryClasses[LibraryClass] = PlatformModule.LibraryClasses[LibraryClass]
2056
2057 # EdkII module
2058 LibraryConsumerList = [Module]
2059 Constructor = []
2060 ConsumedByList = sdict()
2061 LibraryInstance = sdict()
2062
2063 EdkLogger.verbose("")
2064 EdkLogger.verbose("Library instances of module [%s] [%s]:" % (str(Module), self.Arch))
2065 while len(LibraryConsumerList) > 0:
2066 M = LibraryConsumerList.pop()
2067 for LibraryClassName in M.LibraryClasses:
2068 if LibraryClassName not in LibraryInstance:
2069 # override library instance for this module
2070 if LibraryClassName in PlatformModule.LibraryClasses:
2071 LibraryPath = PlatformModule.LibraryClasses[LibraryClassName]
2072 else:
2073 LibraryPath = self.Platform.LibraryClasses[LibraryClassName, ModuleType]
2074 if LibraryPath == None or LibraryPath == "":
2075 LibraryPath = M.LibraryClasses[LibraryClassName]
2076 if LibraryPath == None or LibraryPath == "":
2077 EdkLogger.error("build", RESOURCE_NOT_AVAILABLE,
2078 "Instance of library class [%s] is not found" % LibraryClassName,
2079 File=self.MetaFile,
2080 ExtraData="in [%s] [%s]\n\tconsumed by module [%s]" % (str(M), self.Arch, str(Module)))
2081
2082 LibraryModule = self.BuildDatabase[LibraryPath, self.Arch, self.BuildTarget, self.ToolChain]
2083 # for those forced library instance (NULL library), add a fake library class
2084 if LibraryClassName.startswith("NULL"):
2085 LibraryModule.LibraryClass.append(LibraryClassObject(LibraryClassName, [ModuleType]))
2086 elif LibraryModule.LibraryClass == None \
2087 or len(LibraryModule.LibraryClass) == 0 \
2088 or (ModuleType != 'USER_DEFINED'
2089 and ModuleType not in LibraryModule.LibraryClass[0].SupModList):
2090 # only USER_DEFINED can link against any library instance despite of its SupModList
2091 EdkLogger.error("build", OPTION_MISSING,
2092 "Module type [%s] is not supported by library instance [%s]" \
2093 % (ModuleType, LibraryPath), File=self.MetaFile,
2094 ExtraData="consumed by [%s]" % str(Module))
2095
2096 LibraryInstance[LibraryClassName] = LibraryModule
2097 LibraryConsumerList.append(LibraryModule)
2098 EdkLogger.verbose("\t" + str(LibraryClassName) + " : " + str(LibraryModule))
2099 else:
2100 LibraryModule = LibraryInstance[LibraryClassName]
2101
2102 if LibraryModule == None:
2103 continue
2104
2105 if LibraryModule.ConstructorList != [] and LibraryModule not in Constructor:
2106 Constructor.append(LibraryModule)
2107
2108 if LibraryModule not in ConsumedByList:
2109 ConsumedByList[LibraryModule] = []
2110 # don't add current module itself to consumer list
2111 if M != Module:
2112 if M in ConsumedByList[LibraryModule]:
2113 continue
2114 ConsumedByList[LibraryModule].append(M)
2115 #
2116 # Initialize the sorted output list to the empty set
2117 #
2118 SortedLibraryList = []
2119 #
2120 # Q <- Set of all nodes with no incoming edges
2121 #
2122 LibraryList = [] #LibraryInstance.values()
2123 Q = []
2124 for LibraryClassName in LibraryInstance:
2125 M = LibraryInstance[LibraryClassName]
2126 LibraryList.append(M)
2127 if ConsumedByList[M] == []:
2128 Q.append(M)
2129
2130 #
2131 # start the DAG algorithm
2132 #
2133 while True:
2134 EdgeRemoved = True
2135 while Q == [] and EdgeRemoved:
2136 EdgeRemoved = False
2137 # for each node Item with a Constructor
2138 for Item in LibraryList:
2139 if Item not in Constructor:
2140 continue
2141 # for each Node without a constructor with an edge e from Item to Node
2142 for Node in ConsumedByList[Item]:
2143 if Node in Constructor:
2144 continue
2145 # remove edge e from the graph if Node has no constructor
2146 ConsumedByList[Item].remove(Node)
2147 EdgeRemoved = True
2148 if ConsumedByList[Item] == []:
2149 # insert Item into Q
2150 Q.insert(0, Item)
2151 break
2152 if Q != []:
2153 break
2154 # DAG is done if there's no more incoming edge for all nodes
2155 if Q == []:
2156 break
2157
2158 # remove node from Q
2159 Node = Q.pop()
2160 # output Node
2161 SortedLibraryList.append(Node)
2162
2163 # for each node Item with an edge e from Node to Item do
2164 for Item in LibraryList:
2165 if Node not in ConsumedByList[Item]:
2166 continue
2167 # remove edge e from the graph
2168 ConsumedByList[Item].remove(Node)
2169
2170 if ConsumedByList[Item] != []:
2171 continue
2172 # insert Item into Q, if Item has no other incoming edges
2173 Q.insert(0, Item)
2174
2175 #
2176 # if any remaining node Item in the graph has a constructor and an incoming edge, then the graph has a cycle
2177 #
2178 for Item in LibraryList:
2179 if ConsumedByList[Item] != [] and Item in Constructor and len(Constructor) > 1:
2180 ErrorMessage = "\tconsumed by " + "\n\tconsumed by ".join([str(L) for L in ConsumedByList[Item]])
2181 EdkLogger.error("build", BUILD_ERROR, 'Library [%s] with constructors has a cycle' % str(Item),
2182 ExtraData=ErrorMessage, File=self.MetaFile)
2183 if Item not in SortedLibraryList:
2184 SortedLibraryList.append(Item)
2185
2186 #
2187 # Build the list of constructor and destructir names
2188 # The DAG Topo sort produces the destructor order, so the list of constructors must generated in the reverse order
2189 #
2190 SortedLibraryList.reverse()
2191 return SortedLibraryList
2192
2193
2194 ## Override PCD setting (type, value, ...)
2195 #
2196 # @param ToPcd The PCD to be overrided
2197 # @param FromPcd The PCD overrideing from
2198 #
2199 def _OverridePcd(self, ToPcd, FromPcd, Module=""):
2200 #
2201 # in case there's PCDs coming from FDF file, which have no type given.
2202 # at this point, ToPcd.Type has the type found from dependent
2203 # package
2204 #
2205 TokenCName = ToPcd.TokenCName
2206 for PcdItem in GlobalData.MixedPcd:
2207 if (ToPcd.TokenCName, ToPcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:
2208 TokenCName = PcdItem[0]
2209 break
2210 if FromPcd != None:
2211 if GlobalData.BuildOptionPcd:
2212 for pcd in GlobalData.BuildOptionPcd:
2213 if (FromPcd.TokenSpaceGuidCName, FromPcd.TokenCName) == (pcd[0], pcd[1]):
2214 FromPcd.DefaultValue = pcd[2]
2215 break
2216 if ToPcd.Pending and FromPcd.Type not in [None, '']:
2217 ToPcd.Type = FromPcd.Type
2218 elif (ToPcd.Type not in [None, '']) and (FromPcd.Type not in [None, ''])\
2219 and (ToPcd.Type != FromPcd.Type) and (ToPcd.Type in FromPcd.Type):
2220 if ToPcd.Type.strip() == "DynamicEx":
2221 ToPcd.Type = FromPcd.Type
2222 elif ToPcd.Type not in [None, ''] and FromPcd.Type not in [None, ''] \
2223 and ToPcd.Type != FromPcd.Type:
2224 EdkLogger.error("build", OPTION_CONFLICT, "Mismatched PCD type",
2225 ExtraData="%s.%s is defined as [%s] in module %s, but as [%s] in platform."\
2226 % (ToPcd.TokenSpaceGuidCName, TokenCName,
2227 ToPcd.Type, Module, FromPcd.Type),
2228 File=self.MetaFile)
2229
2230 if FromPcd.MaxDatumSize not in [None, '']:
2231 ToPcd.MaxDatumSize = FromPcd.MaxDatumSize
2232 if FromPcd.DefaultValue not in [None, '']:
2233 ToPcd.DefaultValue = FromPcd.DefaultValue
2234 if FromPcd.TokenValue not in [None, '']:
2235 ToPcd.TokenValue = FromPcd.TokenValue
2236 if FromPcd.MaxDatumSize not in [None, '']:
2237 ToPcd.MaxDatumSize = FromPcd.MaxDatumSize
2238 if FromPcd.DatumType not in [None, '']:
2239 ToPcd.DatumType = FromPcd.DatumType
2240 if FromPcd.SkuInfoList not in [None, '', []]:
2241 ToPcd.SkuInfoList = FromPcd.SkuInfoList
2242
2243 # check the validation of datum
2244 IsValid, Cause = CheckPcdDatum(ToPcd.DatumType, ToPcd.DefaultValue)
2245 if not IsValid:
2246 EdkLogger.error('build', FORMAT_INVALID, Cause, File=self.MetaFile,
2247 ExtraData="%s.%s" % (ToPcd.TokenSpaceGuidCName, TokenCName))
2248 ToPcd.validateranges = FromPcd.validateranges
2249 ToPcd.validlists = FromPcd.validlists
2250 ToPcd.expressions = FromPcd.expressions
2251
2252 if ToPcd.DatumType == "VOID*" and ToPcd.MaxDatumSize in ['', None]:
2253 EdkLogger.debug(EdkLogger.DEBUG_9, "No MaxDatumSize specified for PCD %s.%s" \
2254 % (ToPcd.TokenSpaceGuidCName, TokenCName))
2255 Value = ToPcd.DefaultValue
2256 if Value in [None, '']:
2257 ToPcd.MaxDatumSize = '1'
2258 elif Value[0] == 'L':
2259 ToPcd.MaxDatumSize = str((len(Value) - 2) * 2)
2260 elif Value[0] == '{':
2261 ToPcd.MaxDatumSize = str(len(Value.split(',')))
2262 else:
2263 ToPcd.MaxDatumSize = str(len(Value) - 1)
2264
2265 # apply default SKU for dynamic PCDS if specified one is not available
2266 if (ToPcd.Type in PCD_DYNAMIC_TYPE_LIST or ToPcd.Type in PCD_DYNAMIC_EX_TYPE_LIST) \
2267 and ToPcd.SkuInfoList in [None, {}, '']:
2268 if self.Platform.SkuName in self.Platform.SkuIds:
2269 SkuName = self.Platform.SkuName
2270 else:
2271 SkuName = 'DEFAULT'
2272 ToPcd.SkuInfoList = {
2273 SkuName : SkuInfoClass(SkuName, self.Platform.SkuIds[SkuName], '', '', '', '', '', ToPcd.DefaultValue)
2274 }
2275
2276 ## Apply PCD setting defined platform to a module
2277 #
2278 # @param Module The module from which the PCD setting will be overrided
2279 #
2280 # @retval PCD_list The list PCDs with settings from platform
2281 #
2282 def ApplyPcdSetting(self, Module, Pcds):
2283 # for each PCD in module
2284 for Name, Guid in Pcds:
2285 PcdInModule = Pcds[Name, Guid]
2286 # find out the PCD setting in platform
2287 if (Name, Guid) in self.Platform.Pcds:
2288 PcdInPlatform = self.Platform.Pcds[Name, Guid]
2289 else:
2290 PcdInPlatform = None
2291 # then override the settings if any
2292 self._OverridePcd(PcdInModule, PcdInPlatform, Module)
2293 # resolve the VariableGuid value
2294 for SkuId in PcdInModule.SkuInfoList:
2295 Sku = PcdInModule.SkuInfoList[SkuId]
2296 if Sku.VariableGuid == '': continue
2297 Sku.VariableGuidValue = GuidValue(Sku.VariableGuid, self.PackageList, self.MetaFile.Path)
2298 if Sku.VariableGuidValue == None:
2299 PackageList = "\n\t".join([str(P) for P in self.PackageList])
2300 EdkLogger.error(
2301 'build',
2302 RESOURCE_NOT_AVAILABLE,
2303 "Value of GUID [%s] is not found in" % Sku.VariableGuid,
2304 ExtraData=PackageList + "\n\t(used with %s.%s from module %s)" \
2305 % (Guid, Name, str(Module)),
2306 File=self.MetaFile
2307 )
2308
2309 # override PCD settings with module specific setting
2310 if Module in self.Platform.Modules:
2311 PlatformModule = self.Platform.Modules[str(Module)]
2312 for Key in PlatformModule.Pcds:
2313 if Key in Pcds:
2314 self._OverridePcd(Pcds[Key], PlatformModule.Pcds[Key], Module)
2315 return Pcds.values()
2316
2317 ## Resolve library names to library modules
2318 #
2319 # (for Edk.x modules)
2320 #
2321 # @param Module The module from which the library names will be resolved
2322 #
2323 # @retval library_list The list of library modules
2324 #
2325 def ResolveLibraryReference(self, Module):
2326 EdkLogger.verbose("")
2327 EdkLogger.verbose("Library instances of module [%s] [%s]:" % (str(Module), self.Arch))
2328 LibraryConsumerList = [Module]
2329
2330 # "CompilerStub" is a must for Edk modules
2331 if Module.Libraries:
2332 Module.Libraries.append("CompilerStub")
2333 LibraryList = []
2334 while len(LibraryConsumerList) > 0:
2335 M = LibraryConsumerList.pop()
2336 for LibraryName in M.Libraries:
2337 Library = self.Platform.LibraryClasses[LibraryName, ':dummy:']
2338 if Library == None:
2339 for Key in self.Platform.LibraryClasses.data.keys():
2340 if LibraryName.upper() == Key.upper():
2341 Library = self.Platform.LibraryClasses[Key, ':dummy:']
2342 break
2343 if Library == None:
2344 EdkLogger.warn("build", "Library [%s] is not found" % LibraryName, File=str(M),
2345 ExtraData="\t%s [%s]" % (str(Module), self.Arch))
2346 continue
2347
2348 if Library not in LibraryList:
2349 LibraryList.append(Library)
2350 LibraryConsumerList.append(Library)
2351 EdkLogger.verbose("\t" + LibraryName + " : " + str(Library) + ' ' + str(type(Library)))
2352 return LibraryList
2353
2354 ## Calculate the priority value of the build option
2355 #
2356 # @param Key Build option definition contain: TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
2357 #
2358 # @retval Value Priority value based on the priority list.
2359 #
2360 def CalculatePriorityValue(self, Key):
2361 Target, ToolChain, Arch, CommandType, Attr = Key.split('_')
2362 PriorityValue = 0x11111
2363 if Target == "*":
2364 PriorityValue &= 0x01111
2365 if ToolChain == "*":
2366 PriorityValue &= 0x10111
2367 if Arch == "*":
2368 PriorityValue &= 0x11011
2369 if CommandType == "*":
2370 PriorityValue &= 0x11101
2371 if Attr == "*":
2372 PriorityValue &= 0x11110
2373
2374 return self.PrioList["0x%0.5x" % PriorityValue]
2375
2376
2377 ## Expand * in build option key
2378 #
2379 # @param Options Options to be expanded
2380 #
2381 # @retval options Options expanded
2382 #
2383 def _ExpandBuildOption(self, Options, ModuleStyle=None):
2384 BuildOptions = {}
2385 FamilyMatch = False
2386 FamilyIsNull = True
2387
2388 OverrideList = {}
2389 #
2390 # Construct a list contain the build options which need override.
2391 #
2392 for Key in Options:
2393 #
2394 # Key[0] -- tool family
2395 # Key[1] -- TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
2396 #
2397 if (Key[0] == self.BuildRuleFamily and
2398 (ModuleStyle == None or len(Key) < 3 or (len(Key) > 2 and Key[2] == ModuleStyle))):
2399 Target, ToolChain, Arch, CommandType, Attr = Key[1].split('_')
2400 if Target == self.BuildTarget or Target == "*":
2401 if ToolChain == self.ToolChain or ToolChain == "*":
2402 if Arch == self.Arch or Arch == "*":
2403 if Options[Key].startswith("="):
2404 if OverrideList.get(Key[1]) != None:
2405 OverrideList.pop(Key[1])
2406 OverrideList[Key[1]] = Options[Key]
2407
2408 #
2409 # Use the highest priority value.
2410 #
2411 if (len(OverrideList) >= 2):
2412 KeyList = OverrideList.keys()
2413 for Index in range(len(KeyList)):
2414 NowKey = KeyList[Index]
2415 Target1, ToolChain1, Arch1, CommandType1, Attr1 = NowKey.split("_")
2416 for Index1 in range(len(KeyList) - Index - 1):
2417 NextKey = KeyList[Index1 + Index + 1]
2418 #
2419 # Compare two Key, if one is included by another, choose the higher priority one
2420 #
2421 Target2, ToolChain2, Arch2, CommandType2, Attr2 = NextKey.split("_")
2422 if Target1 == Target2 or Target1 == "*" or Target2 == "*":
2423 if ToolChain1 == ToolChain2 or ToolChain1 == "*" or ToolChain2 == "*":
2424 if Arch1 == Arch2 or Arch1 == "*" or Arch2 == "*":
2425 if CommandType1 == CommandType2 or CommandType1 == "*" or CommandType2 == "*":
2426 if Attr1 == Attr2 or Attr1 == "*" or Attr2 == "*":
2427 if self.CalculatePriorityValue(NowKey) > self.CalculatePriorityValue(NextKey):
2428 if Options.get((self.BuildRuleFamily, NextKey)) != None:
2429 Options.pop((self.BuildRuleFamily, NextKey))
2430 else:
2431 if Options.get((self.BuildRuleFamily, NowKey)) != None:
2432 Options.pop((self.BuildRuleFamily, NowKey))
2433
2434 for Key in Options:
2435 if ModuleStyle != None and len (Key) > 2:
2436 # Check Module style is EDK or EDKII.
2437 # Only append build option for the matched style module.
2438 if ModuleStyle == EDK_NAME and Key[2] != EDK_NAME:
2439 continue
2440 elif ModuleStyle == EDKII_NAME and Key[2] != EDKII_NAME:
2441 continue
2442 Family = Key[0]
2443 Target, Tag, Arch, Tool, Attr = Key[1].split("_")
2444 # if tool chain family doesn't match, skip it
2445 if Tool in self.ToolDefinition and Family != "":
2446 FamilyIsNull = False
2447 if self.ToolDefinition[Tool].get(TAB_TOD_DEFINES_BUILDRULEFAMILY, "") != "":
2448 if Family != self.ToolDefinition[Tool][TAB_TOD_DEFINES_BUILDRULEFAMILY]:
2449 continue
2450 elif Family != self.ToolDefinition[Tool][TAB_TOD_DEFINES_FAMILY]:
2451 continue
2452 FamilyMatch = True
2453 # expand any wildcard
2454 if Target == "*" or Target == self.BuildTarget:
2455 if Tag == "*" or Tag == self.ToolChain:
2456 if Arch == "*" or Arch == self.Arch:
2457 if Tool not in BuildOptions:
2458 BuildOptions[Tool] = {}
2459 if Attr != "FLAGS" or Attr not in BuildOptions[Tool] or Options[Key].startswith('='):
2460 BuildOptions[Tool][Attr] = Options[Key]
2461 else:
2462 # append options for the same tool except PATH
2463 if Attr != 'PATH':
2464 BuildOptions[Tool][Attr] += " " + Options[Key]
2465 else:
2466 BuildOptions[Tool][Attr] = Options[Key]
2467 # Build Option Family has been checked, which need't to be checked again for family.
2468 if FamilyMatch or FamilyIsNull:
2469 return BuildOptions
2470
2471 for Key in Options:
2472 if ModuleStyle != None and len (Key) > 2:
2473 # Check Module style is EDK or EDKII.
2474 # Only append build option for the matched style module.
2475 if ModuleStyle == EDK_NAME and Key[2] != EDK_NAME:
2476 continue
2477 elif ModuleStyle == EDKII_NAME and Key[2] != EDKII_NAME:
2478 continue
2479 Family = Key[0]
2480 Target, Tag, Arch, Tool, Attr = Key[1].split("_")
2481 # if tool chain family doesn't match, skip it
2482 if Tool not in self.ToolDefinition or Family == "":
2483 continue
2484 # option has been added before
2485 if Family != self.ToolDefinition[Tool][TAB_TOD_DEFINES_FAMILY]:
2486 continue
2487
2488 # expand any wildcard
2489 if Target == "*" or Target == self.BuildTarget:
2490 if Tag == "*" or Tag == self.ToolChain:
2491 if Arch == "*" or Arch == self.Arch:
2492 if Tool not in BuildOptions:
2493 BuildOptions[Tool] = {}
2494 if Attr != "FLAGS" or Attr not in BuildOptions[Tool] or Options[Key].startswith('='):
2495 BuildOptions[Tool][Attr] = Options[Key]
2496 else:
2497 # append options for the same tool except PATH
2498 if Attr != 'PATH':
2499 BuildOptions[Tool][Attr] += " " + Options[Key]
2500 else:
2501 BuildOptions[Tool][Attr] = Options[Key]
2502 return BuildOptions
2503
2504 ## Append build options in platform to a module
2505 #
2506 # @param Module The module to which the build options will be appened
2507 #
2508 # @retval options The options appended with build options in platform
2509 #
2510 def ApplyBuildOption(self, Module):
2511 # Get the different options for the different style module
2512 if Module.AutoGenVersion < 0x00010005:
2513 PlatformOptions = self.EdkBuildOption
2514 ModuleTypeOptions = self.Platform.GetBuildOptionsByModuleType(EDK_NAME, Module.ModuleType)
2515 else:
2516 PlatformOptions = self.EdkIIBuildOption
2517 ModuleTypeOptions = self.Platform.GetBuildOptionsByModuleType(EDKII_NAME, Module.ModuleType)
2518 ModuleTypeOptions = self._ExpandBuildOption(ModuleTypeOptions)
2519 ModuleOptions = self._ExpandBuildOption(Module.BuildOptions)
2520 if Module in self.Platform.Modules:
2521 PlatformModule = self.Platform.Modules[str(Module)]
2522 PlatformModuleOptions = self._ExpandBuildOption(PlatformModule.BuildOptions)
2523 else:
2524 PlatformModuleOptions = {}
2525
2526 BuildRuleOrder = None
2527 for Options in [self.ToolDefinition, ModuleOptions, PlatformOptions, ModuleTypeOptions, PlatformModuleOptions]:
2528 for Tool in Options:
2529 for Attr in Options[Tool]:
2530 if Attr == TAB_TOD_DEFINES_BUILDRULEORDER:
2531 BuildRuleOrder = Options[Tool][Attr]
2532
2533 AllTools = set(ModuleOptions.keys() + PlatformOptions.keys() +
2534 PlatformModuleOptions.keys() + ModuleTypeOptions.keys() +
2535 self.ToolDefinition.keys())
2536 BuildOptions = {}
2537 for Tool in AllTools:
2538 if Tool not in BuildOptions:
2539 BuildOptions[Tool] = {}
2540
2541 for Options in [self.ToolDefinition, ModuleOptions, PlatformOptions, ModuleTypeOptions, PlatformModuleOptions]:
2542 if Tool not in Options:
2543 continue
2544 for Attr in Options[Tool]:
2545 Value = Options[Tool][Attr]
2546 #
2547 # Do not generate it in Makefile
2548 #
2549 if Attr == TAB_TOD_DEFINES_BUILDRULEORDER:
2550 continue
2551 if Attr not in BuildOptions[Tool]:
2552 BuildOptions[Tool][Attr] = ""
2553 # check if override is indicated
2554 if Value.startswith('='):
2555 ToolPath = Value[1:]
2556 ToolPath = mws.handleWsMacro(ToolPath)
2557 BuildOptions[Tool][Attr] = ToolPath
2558 else:
2559 Value = mws.handleWsMacro(Value)
2560 if Attr != 'PATH':
2561 BuildOptions[Tool][Attr] += " " + Value
2562 else:
2563 BuildOptions[Tool][Attr] = Value
2564 if Module.AutoGenVersion < 0x00010005 and self.Workspace.UniFlag != None:
2565 #
2566 # Override UNI flag only for EDK module.
2567 #
2568 if 'BUILD' not in BuildOptions:
2569 BuildOptions['BUILD'] = {}
2570 BuildOptions['BUILD']['FLAGS'] = self.Workspace.UniFlag
2571 return BuildOptions, BuildRuleOrder
2572
2573 Platform = property(_GetPlatform)
2574 Name = property(_GetName)
2575 Guid = property(_GetGuid)
2576 Version = property(_GetVersion)
2577
2578 OutputDir = property(_GetOutputDir)
2579 BuildDir = property(_GetBuildDir)
2580 MakeFileDir = property(_GetMakeFileDir)
2581 FdfFile = property(_GetFdfFile)
2582
2583 PcdTokenNumber = property(_GetPcdTokenNumbers) # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber
2584 DynamicPcdList = property(_GetDynamicPcdList) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
2585 NonDynamicPcdList = property(_GetNonDynamicPcdList) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
2586 NonDynamicPcdDict = property(_GetNonDynamicPcdDict)
2587 PackageList = property(_GetPackageList)
2588
2589 ToolDefinition = property(_GetToolDefinition) # toolcode : tool path
2590 ToolDefinitionFile = property(_GetToolDefFile) # toolcode : lib path
2591 ToolChainFamily = property(_GetToolChainFamily)
2592 BuildRuleFamily = property(_GetBuildRuleFamily)
2593 BuildOption = property(_GetBuildOptions) # toolcode : option
2594 EdkBuildOption = property(_GetEdkBuildOptions) # edktoolcode : option
2595 EdkIIBuildOption = property(_GetEdkIIBuildOptions) # edkiitoolcode : option
2596
2597 BuildCommand = property(_GetBuildCommand)
2598 BuildRule = property(_GetBuildRule)
2599 ModuleAutoGenList = property(_GetModuleAutoGenList)
2600 LibraryAutoGenList = property(_GetLibraryAutoGenList)
2601 GenFdsCommand = property(_GenFdsCommand)
2602
2603 ## ModuleAutoGen class
2604 #
2605 # This class encapsules the AutoGen behaviors for the build tools. In addition to
2606 # the generation of AutoGen.h and AutoGen.c, it will generate *.depex file according
2607 # to the [depex] section in module's inf file.
2608 #
2609 class ModuleAutoGen(AutoGen):
2610 ## Cache the timestamps of metafiles of every module in a class variable
2611 #
2612 TimeDict = {}
2613
2614 ## The real constructor of ModuleAutoGen
2615 #
2616 # This method is not supposed to be called by users of ModuleAutoGen. It's
2617 # only used by factory method __new__() to do real initialization work for an
2618 # object of ModuleAutoGen
2619 #
2620 # @param Workspace EdkIIWorkspaceBuild object
2621 # @param ModuleFile The path of module file
2622 # @param Target Build target (DEBUG, RELEASE)
2623 # @param Toolchain Name of tool chain
2624 # @param Arch The arch the module supports
2625 # @param PlatformFile Platform meta-file
2626 #
2627 def _Init(self, Workspace, ModuleFile, Target, Toolchain, Arch, PlatformFile):
2628 EdkLogger.debug(EdkLogger.DEBUG_9, "AutoGen module [%s] [%s]" % (ModuleFile, Arch))
2629 GlobalData.gProcessingFile = "%s [%s, %s, %s]" % (ModuleFile, Arch, Toolchain, Target)
2630
2631 self.Workspace = Workspace
2632 self.WorkspaceDir = Workspace.WorkspaceDir
2633
2634 self.MetaFile = ModuleFile
2635 self.PlatformInfo = PlatformAutoGen(Workspace, PlatformFile, Target, Toolchain, Arch)
2636 # check if this module is employed by active platform
2637 if not self.PlatformInfo.ValidModule(self.MetaFile):
2638 EdkLogger.verbose("Module [%s] for [%s] is not employed by active platform\n" \
2639 % (self.MetaFile, Arch))
2640 return False
2641
2642 self.SourceDir = self.MetaFile.SubDir
2643 self.SourceDir = mws.relpath(self.SourceDir, self.WorkspaceDir)
2644
2645 self.SourceOverrideDir = None
2646 # use overrided path defined in DSC file
2647 if self.MetaFile.Key in GlobalData.gOverrideDir:
2648 self.SourceOverrideDir = GlobalData.gOverrideDir[self.MetaFile.Key]
2649
2650 self.ToolChain = Toolchain
2651 self.BuildTarget = Target
2652 self.Arch = Arch
2653 self.ToolChainFamily = self.PlatformInfo.ToolChainFamily
2654 self.BuildRuleFamily = self.PlatformInfo.BuildRuleFamily
2655
2656 self.IsMakeFileCreated = False
2657 self.IsCodeFileCreated = False
2658 self.IsAsBuiltInfCreated = False
2659 self.DepexGenerated = False
2660
2661 self.BuildDatabase = self.Workspace.BuildDatabase
2662 self.BuildRuleOrder = None
2663
2664 self._Module = None
2665 self._Name = None
2666 self._Guid = None
2667 self._Version = None
2668 self._ModuleType = None
2669 self._ComponentType = None
2670 self._PcdIsDriver = None
2671 self._AutoGenVersion = None
2672 self._LibraryFlag = None
2673 self._CustomMakefile = None
2674 self._Macro = None
2675
2676 self._BuildDir = None
2677 self._OutputDir = None
2678 self._DebugDir = None
2679 self._MakeFileDir = None
2680
2681 self._IncludePathList = None
2682 self._IncludePathLength = 0
2683 self._AutoGenFileList = None
2684 self._UnicodeFileList = None
2685 self._VfrFileList = None
2686 self._IdfFileList = None
2687 self._SourceFileList = None
2688 self._ObjectFileList = None
2689 self._BinaryFileList = None
2690
2691 self._DependentPackageList = None
2692 self._DependentLibraryList = None
2693 self._LibraryAutoGenList = None
2694 self._DerivedPackageList = None
2695 self._ModulePcdList = None
2696 self._LibraryPcdList = None
2697 self._PcdComments = sdict()
2698 self._GuidList = None
2699 self._GuidsUsedByPcd = None
2700 self._GuidComments = sdict()
2701 self._ProtocolList = None
2702 self._ProtocolComments = sdict()
2703 self._PpiList = None
2704 self._PpiComments = sdict()
2705 self._DepexList = None
2706 self._DepexExpressionList = None
2707 self._BuildOption = None
2708 self._BuildOptionIncPathList = None
2709 self._BuildTargets = None
2710 self._IntroBuildTargetList = None
2711 self._FinalBuildTargetList = None
2712 self._FileTypes = None
2713 self._BuildRules = None
2714
2715 self._TimeStampPath = None
2716
2717 self.AutoGenDepSet = set()
2718
2719
2720 ## The Modules referenced to this Library
2721 # Only Library has this attribute
2722 self._ReferenceModules = []
2723
2724 ## Store the FixedAtBuild Pcds
2725 #
2726 self._FixedAtBuildPcds = []
2727 self.ConstPcd = {}
2728 return True
2729
2730 def __repr__(self):
2731 return "%s [%s]" % (self.MetaFile, self.Arch)
2732
2733 # Get FixedAtBuild Pcds of this Module
2734 def _GetFixedAtBuildPcds(self):
2735 if self._FixedAtBuildPcds:
2736 return self._FixedAtBuildPcds
2737 for Pcd in self.ModulePcdList:
2738 if self.IsLibrary:
2739 if not (Pcd.Pending == False and Pcd.Type == "FixedAtBuild"):
2740 continue
2741 elif Pcd.Type != "FixedAtBuild":
2742 continue
2743 if Pcd not in self._FixedAtBuildPcds:
2744 self._FixedAtBuildPcds.append(Pcd)
2745
2746 return self._FixedAtBuildPcds
2747
2748 def _GetUniqueBaseName(self):
2749 BaseName = self.Name
2750 for Module in self.PlatformInfo.ModuleAutoGenList:
2751 if Module.MetaFile == self.MetaFile:
2752 continue
2753 if Module.Name == self.Name:
2754 if uuid.UUID(Module.Guid) == uuid.UUID(self.Guid):
2755 EdkLogger.error("build", FILE_DUPLICATED, 'Modules have same BaseName and FILE_GUID:\n'
2756 ' %s\n %s' % (Module.MetaFile, self.MetaFile))
2757 BaseName = '%s_%s' % (self.Name, self.Guid)
2758 return BaseName
2759
2760 # Macros could be used in build_rule.txt (also Makefile)
2761 def _GetMacros(self):
2762 if self._Macro == None:
2763 self._Macro = sdict()
2764 self._Macro["WORKSPACE" ] = self.WorkspaceDir
2765 self._Macro["MODULE_NAME" ] = self.Name
2766 self._Macro["MODULE_NAME_GUID" ] = self._GetUniqueBaseName()
2767 self._Macro["MODULE_GUID" ] = self.Guid
2768 self._Macro["MODULE_VERSION" ] = self.Version
2769 self._Macro["MODULE_TYPE" ] = self.ModuleType
2770 self._Macro["MODULE_FILE" ] = str(self.MetaFile)
2771 self._Macro["MODULE_FILE_BASE_NAME" ] = self.MetaFile.BaseName
2772 self._Macro["MODULE_RELATIVE_DIR" ] = self.SourceDir
2773 self._Macro["MODULE_DIR" ] = self.SourceDir
2774
2775 self._Macro["BASE_NAME" ] = self.Name
2776
2777 self._Macro["ARCH" ] = self.Arch
2778 self._Macro["TOOLCHAIN" ] = self.ToolChain
2779 self._Macro["TOOLCHAIN_TAG" ] = self.ToolChain
2780 self._Macro["TOOL_CHAIN_TAG" ] = self.ToolChain
2781 self._Macro["TARGET" ] = self.BuildTarget
2782
2783 self._Macro["BUILD_DIR" ] = self.PlatformInfo.BuildDir
2784 self._Macro["BIN_DIR" ] = os.path.join(self.PlatformInfo.BuildDir, self.Arch)
2785 self._Macro["LIB_DIR" ] = os.path.join(self.PlatformInfo.BuildDir, self.Arch)
2786 self._Macro["MODULE_BUILD_DIR" ] = self.BuildDir
2787 self._Macro["OUTPUT_DIR" ] = self.OutputDir
2788 self._Macro["DEBUG_DIR" ] = self.DebugDir
2789 self._Macro["DEST_DIR_OUTPUT" ] = self.OutputDir
2790 self._Macro["DEST_DIR_DEBUG" ] = self.DebugDir
2791 self._Macro["PLATFORM_NAME" ] = self.PlatformInfo.Name
2792 self._Macro["PLATFORM_GUID" ] = self.PlatformInfo.Guid
2793 self._Macro["PLATFORM_VERSION" ] = self.PlatformInfo.Version
2794 self._Macro["PLATFORM_RELATIVE_DIR" ] = self.PlatformInfo.SourceDir
2795 self._Macro["PLATFORM_DIR" ] = mws.join(self.WorkspaceDir, self.PlatformInfo.SourceDir)
2796 self._Macro["PLATFORM_OUTPUT_DIR" ] = self.PlatformInfo.OutputDir
2797 return self._Macro
2798
2799 ## Return the module build data object
2800 def _GetModule(self):
2801 if self._Module == None:
2802 self._Module = self.Workspace.BuildDatabase[self.MetaFile, self.Arch, self.BuildTarget, self.ToolChain]
2803 return self._Module
2804
2805 ## Return the module name
2806 def _GetBaseName(self):
2807 return self.Module.BaseName
2808
2809 ## Return the module DxsFile if exist
2810 def _GetDxsFile(self):
2811 return self.Module.DxsFile
2812
2813 ## Return the module SourceOverridePath
2814 def _GetSourceOverridePath(self):
2815 return self.Module.SourceOverridePath
2816
2817 ## Return the module meta-file GUID
2818 def _GetGuid(self):
2819 #
2820 # To build same module more than once, the module path with FILE_GUID overridden has
2821 # the file name FILE_GUIDmodule.inf, but the relative path (self.MetaFile.File) is the realy path
2822 # in DSC. The overridden GUID can be retrieved from file name
2823 #
2824 if os.path.basename(self.MetaFile.File) != os.path.basename(self.MetaFile.Path):
2825 #
2826 # Length of GUID is 36
2827 #
2828 return os.path.basename(self.MetaFile.Path)[:36]
2829 return self.Module.Guid
2830
2831 ## Return the module version
2832 def _GetVersion(self):
2833 return self.Module.Version
2834
2835 ## Return the module type
2836 def _GetModuleType(self):
2837 return self.Module.ModuleType
2838
2839 ## Return the component type (for Edk.x style of module)
2840 def _GetComponentType(self):
2841 return self.Module.ComponentType
2842
2843 ## Return the build type
2844 def _GetBuildType(self):
2845 return self.Module.BuildType
2846
2847 ## Return the PCD_IS_DRIVER setting
2848 def _GetPcdIsDriver(self):
2849 return self.Module.PcdIsDriver
2850
2851 ## Return the autogen version, i.e. module meta-file version
2852 def _GetAutoGenVersion(self):
2853 return self.Module.AutoGenVersion
2854
2855 ## Check if the module is library or not
2856 def _IsLibrary(self):
2857 if self._LibraryFlag == None:
2858 if self.Module.LibraryClass != None and self.Module.LibraryClass != []:
2859 self._LibraryFlag = True
2860 else:
2861 self._LibraryFlag = False
2862 return self._LibraryFlag
2863
2864 ## Check if the module is binary module or not
2865 def _IsBinaryModule(self):
2866 return self.Module.IsBinaryModule
2867
2868 ## Return the directory to store intermediate files of the module
2869 def _GetBuildDir(self):
2870 if self._BuildDir == None:
2871 self._BuildDir = path.join(
2872 self.PlatformInfo.BuildDir,
2873 self.Arch,
2874 self.SourceDir,
2875 self.MetaFile.BaseName
2876 )
2877 CreateDirectory(self._BuildDir)
2878 return self._BuildDir
2879
2880 ## Return the directory to store the intermediate object files of the mdoule
2881 def _GetOutputDir(self):
2882 if self._OutputDir == None:
2883 self._OutputDir = path.join(self.BuildDir, "OUTPUT")
2884 CreateDirectory(self._OutputDir)
2885 return self._OutputDir
2886
2887 ## Return the directory to store auto-gened source files of the mdoule
2888 def _GetDebugDir(self):
2889 if self._DebugDir == None:
2890 self._DebugDir = path.join(self.BuildDir, "DEBUG")
2891 CreateDirectory(self._DebugDir)
2892 return self._DebugDir
2893
2894 ## Return the path of custom file
2895 def _GetCustomMakefile(self):
2896 if self._CustomMakefile == None:
2897 self._CustomMakefile = {}
2898 for Type in self.Module.CustomMakefile:
2899 if Type in gMakeTypeMap:
2900 MakeType = gMakeTypeMap[Type]
2901 else:
2902 MakeType = 'nmake'
2903 if self.SourceOverrideDir != None:
2904 File = os.path.join(self.SourceOverrideDir, self.Module.CustomMakefile[Type])
2905 if not os.path.exists(File):
2906 File = os.path.join(self.SourceDir, self.Module.CustomMakefile[Type])
2907 else:
2908 File = os.path.join(self.SourceDir, self.Module.CustomMakefile[Type])
2909 self._CustomMakefile[MakeType] = File
2910 return self._CustomMakefile
2911
2912 ## Return the directory of the makefile
2913 #
2914 # @retval string The directory string of module's makefile
2915 #
2916 def _GetMakeFileDir(self):
2917 return self.BuildDir
2918
2919 ## Return build command string
2920 #
2921 # @retval string Build command string
2922 #
2923 def _GetBuildCommand(self):
2924 return self.PlatformInfo.BuildCommand
2925
2926 ## Get object list of all packages the module and its dependent libraries belong to
2927 #
2928 # @retval list The list of package object
2929 #
2930 def _GetDerivedPackageList(self):
2931 PackageList = []
2932 for M in [self.Module] + self.DependentLibraryList:
2933 for Package in M.Packages:
2934 if Package in PackageList:
2935 continue
2936 PackageList.append(Package)
2937 return PackageList
2938
2939 ## Get the depex string
2940 #
2941 # @return : a string contain all depex expresion.
2942 def _GetDepexExpresionString(self):
2943 DepexStr = ''
2944 DepexList = []
2945 ## DPX_SOURCE IN Define section.
2946 if self.Module.DxsFile:
2947 return DepexStr
2948 for M in [self.Module] + self.DependentLibraryList:
2949 Filename = M.MetaFile.Path
2950 InfObj = InfSectionParser.InfSectionParser(Filename)
2951 DepexExpresionList = InfObj.GetDepexExpresionList()
2952 for DepexExpresion in DepexExpresionList:
2953 for key in DepexExpresion.keys():
2954 Arch, ModuleType = key
2955 DepexExpr = [x for x in DepexExpresion[key] if not str(x).startswith('#')]
2956 # the type of build module is USER_DEFINED.
2957 # All different DEPEX section tags would be copied into the As Built INF file
2958 # and there would be separate DEPEX section tags
2959 if self.ModuleType.upper() == SUP_MODULE_USER_DEFINED:
2960 if (Arch.upper() == self.Arch.upper()) and (ModuleType.upper() != TAB_ARCH_COMMON):
2961 DepexList.append({(Arch, ModuleType): DepexExpr})
2962 else:
2963 if Arch.upper() == TAB_ARCH_COMMON or \
2964 (Arch.upper() == self.Arch.upper() and \
2965 ModuleType.upper() in [TAB_ARCH_COMMON, self.ModuleType.upper()]):
2966 DepexList.append({(Arch, ModuleType): DepexExpr})
2967
2968 #the type of build module is USER_DEFINED.
2969 if self.ModuleType.upper() == SUP_MODULE_USER_DEFINED:
2970 for Depex in DepexList:
2971 for key in Depex.keys():
2972 DepexStr += '[Depex.%s.%s]\n' % key
2973 DepexStr += '\n'.join(['# '+ val for val in Depex[key]])
2974 DepexStr += '\n\n'
2975 if not DepexStr:
2976 return '[Depex.%s]\n' % self.Arch
2977 return DepexStr
2978
2979 #the type of build module not is USER_DEFINED.
2980 Count = 0
2981 for Depex in DepexList:
2982 Count += 1
2983 if DepexStr != '':
2984 DepexStr += ' AND '
2985 DepexStr += '('
2986 for D in Depex.values():
2987 DepexStr += ' '.join([val for val in D])
2988 Index = DepexStr.find('END')
2989 if Index > -1 and Index == len(DepexStr) - 3:
2990 DepexStr = DepexStr[:-3]
2991 DepexStr = DepexStr.strip()
2992 DepexStr += ')'
2993 if Count == 1:
2994 DepexStr = DepexStr.lstrip('(').rstrip(')').strip()
2995 if not DepexStr:
2996 return '[Depex.%s]\n' % self.Arch
2997 return '[Depex.%s]\n# ' % self.Arch + DepexStr
2998
2999 ## Merge dependency expression
3000 #
3001 # @retval list The token list of the dependency expression after parsed
3002 #
3003 def _GetDepexTokenList(self):
3004 if self._DepexList == None:
3005 self._DepexList = {}
3006 if self.DxsFile or self.IsLibrary or TAB_DEPENDENCY_EXPRESSION_FILE in self.FileTypes:
3007 return self._DepexList
3008
3009 self._DepexList[self.ModuleType] = []
3010
3011 for ModuleType in self._DepexList:
3012 DepexList = self._DepexList[ModuleType]
3013 #
3014 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion
3015 #
3016 for M in [self.Module] + self.DependentLibraryList:
3017 Inherited = False
3018 for D in M.Depex[self.Arch, ModuleType]:
3019 if DepexList != []:
3020 DepexList.append('AND')
3021 DepexList.append('(')
3022 DepexList.extend(D)
3023 if DepexList[-1] == 'END': # no need of a END at this time
3024 DepexList.pop()
3025 DepexList.append(')')
3026 Inherited = True
3027 if Inherited:
3028 EdkLogger.verbose("DEPEX[%s] (+%s) = %s" % (self.Name, M.BaseName, DepexList))
3029 if 'BEFORE' in DepexList or 'AFTER' in DepexList:
3030 break
3031 if len(DepexList) > 0:
3032 EdkLogger.verbose('')
3033 return self._DepexList
3034
3035 ## Merge dependency expression
3036 #
3037 # @retval list The token list of the dependency expression after parsed
3038 #
3039 def _GetDepexExpressionTokenList(self):
3040 if self._DepexExpressionList == None:
3041 self._DepexExpressionList = {}
3042 if self.DxsFile or self.IsLibrary or TAB_DEPENDENCY_EXPRESSION_FILE in self.FileTypes:
3043 return self._DepexExpressionList
3044
3045 self._DepexExpressionList[self.ModuleType] = ''
3046
3047 for ModuleType in self._DepexExpressionList:
3048 DepexExpressionList = self._DepexExpressionList[ModuleType]
3049 #
3050 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion
3051 #
3052 for M in [self.Module] + self.DependentLibraryList:
3053 Inherited = False
3054 for D in M.DepexExpression[self.Arch, ModuleType]:
3055 if DepexExpressionList != '':
3056 DepexExpressionList += ' AND '
3057 DepexExpressionList += '('
3058 DepexExpressionList += D
3059 DepexExpressionList = DepexExpressionList.rstrip('END').strip()
3060 DepexExpressionList += ')'
3061 Inherited = True
3062 if Inherited:
3063 EdkLogger.verbose("DEPEX[%s] (+%s) = %s" % (self.Name, M.BaseName, DepexExpressionList))
3064 if 'BEFORE' in DepexExpressionList or 'AFTER' in DepexExpressionList:
3065 break
3066 if len(DepexExpressionList) > 0:
3067 EdkLogger.verbose('')
3068 self._DepexExpressionList[ModuleType] = DepexExpressionList
3069 return self._DepexExpressionList
3070
3071 ## Return the list of specification version required for the module
3072 #
3073 # @retval list The list of specification defined in module file
3074 #
3075 def _GetSpecification(self):
3076 return self.Module.Specification
3077
3078 ## Tool option for the module build
3079 #
3080 # @param PlatformInfo The object of PlatformBuildInfo
3081 # @retval dict The dict containing valid options
3082 #
3083 def _GetModuleBuildOption(self):
3084 if self._BuildOption == None:
3085 self._BuildOption, self.BuildRuleOrder = self.PlatformInfo.ApplyBuildOption(self.Module)
3086 if self.BuildRuleOrder:
3087 self.BuildRuleOrder = ['.%s' % Ext for Ext in self.BuildRuleOrder.split()]
3088 return self._BuildOption
3089
3090 ## Get include path list from tool option for the module build
3091 #
3092 # @retval list The include path list
3093 #
3094 def _GetBuildOptionIncPathList(self):
3095 if self._BuildOptionIncPathList == None:
3096 #
3097 # Regular expression for finding Include Directories, the difference between MSFT and INTEL/GCC/RVCT
3098 # is the former use /I , the Latter used -I to specify include directories
3099 #
3100 if self.PlatformInfo.ToolChainFamily in ('MSFT'):
3101 gBuildOptIncludePattern = re.compile(r"(?:.*?)/I[ \t]*([^ ]*)", re.MULTILINE | re.DOTALL)
3102 elif self.PlatformInfo.ToolChainFamily in ('INTEL', 'GCC', 'RVCT'):
3103 gBuildOptIncludePattern = re.compile(r"(?:.*?)-I[ \t]*([^ ]*)", re.MULTILINE | re.DOTALL)
3104 else:
3105 #
3106 # New ToolChainFamily, don't known whether there is option to specify include directories
3107 #
3108 self._BuildOptionIncPathList = []
3109 return self._BuildOptionIncPathList
3110
3111 BuildOptionIncPathList = []
3112 for Tool in ('CC', 'PP', 'VFRPP', 'ASLPP', 'ASLCC', 'APP', 'ASM'):
3113 Attr = 'FLAGS'
3114 try:
3115 FlagOption = self.BuildOption[Tool][Attr]
3116 except KeyError:
3117 FlagOption = ''
3118
3119 if self.PlatformInfo.ToolChainFamily != 'RVCT':
3120 IncPathList = [NormPath(Path, self.Macros) for Path in gBuildOptIncludePattern.findall(FlagOption)]
3121 else:
3122 #
3123 # RVCT may specify a list of directory seperated by commas
3124 #
3125 IncPathList = []
3126 for Path in gBuildOptIncludePattern.findall(FlagOption):
3127 PathList = GetSplitList(Path, TAB_COMMA_SPLIT)
3128 IncPathList += [NormPath(PathEntry, self.Macros) for PathEntry in PathList]
3129
3130 #
3131 # EDK II modules must not reference header files outside of the packages they depend on or
3132 # within the module's directory tree. Report error if violation.
3133 #
3134 if self.AutoGenVersion >= 0x00010005 and len(IncPathList) > 0:
3135 for Path in IncPathList:
3136 if (Path not in self.IncludePathList) and (CommonPath([Path, self.MetaFile.Dir]) != self.MetaFile.Dir):
3137 ErrMsg = "The include directory for the EDK II module in this line is invalid %s specified in %s FLAGS '%s'" % (Path, Tool, FlagOption)
3138 EdkLogger.error("build",
3139 PARAMETER_INVALID,
3140 ExtraData=ErrMsg,
3141 File=str(self.MetaFile))
3142
3143
3144 BuildOptionIncPathList += IncPathList
3145
3146 self._BuildOptionIncPathList = BuildOptionIncPathList
3147
3148 return self._BuildOptionIncPathList
3149
3150 ## Return a list of files which can be built from source
3151 #
3152 # What kind of files can be built is determined by build rules in
3153 # $(CONF_DIRECTORY)/build_rule.txt and toolchain family.
3154 #
3155 def _GetSourceFileList(self):
3156 if self._SourceFileList == None:
3157 self._SourceFileList = []
3158 for F in self.Module.Sources:
3159 # match tool chain
3160 if F.TagName not in ("", "*", self.ToolChain):
3161 EdkLogger.debug(EdkLogger.DEBUG_9, "The toolchain [%s] for processing file [%s] is found, "
3162 "but [%s] is needed" % (F.TagName, str(F), self.ToolChain))
3163 continue
3164 # match tool chain family
3165 if F.ToolChainFamily not in ("", "*", self.ToolChainFamily):
3166 EdkLogger.debug(
3167 EdkLogger.DEBUG_0,
3168 "The file [%s] must be built by tools of [%s], " \
3169 "but current toolchain family is [%s]" \
3170 % (str(F), F.ToolChainFamily, self.ToolChainFamily))
3171 continue
3172
3173 # add the file path into search path list for file including
3174 if F.Dir not in self.IncludePathList and self.AutoGenVersion >= 0x00010005:
3175 self.IncludePathList.insert(0, F.Dir)
3176 self._SourceFileList.append(F)
3177
3178 self._MatchBuildRuleOrder(self._SourceFileList)
3179
3180 for F in self._SourceFileList:
3181 self._ApplyBuildRule(F, TAB_UNKNOWN_FILE)
3182 return self._SourceFileList
3183
3184 def _MatchBuildRuleOrder(self, FileList):
3185 Order_Dict = {}
3186 self._GetModuleBuildOption()
3187 for SingleFile in FileList:
3188 if self.BuildRuleOrder and SingleFile.Ext in self.BuildRuleOrder and SingleFile.Ext in self.BuildRules:
3189 key = SingleFile.Path.split(SingleFile.Ext)[0]
3190 if key in Order_Dict:
3191 Order_Dict[key].append(SingleFile.Ext)
3192 else:
3193 Order_Dict[key] = [SingleFile.Ext]
3194
3195 RemoveList = []
3196 for F in Order_Dict:
3197 if len(Order_Dict[F]) > 1:
3198 Order_Dict[F].sort(key=lambda i: self.BuildRuleOrder.index(i))
3199 for Ext in Order_Dict[F][1:]:
3200 RemoveList.append(F + Ext)
3201
3202 for item in RemoveList:
3203 FileList.remove(item)
3204
3205 return FileList
3206
3207 ## Return the list of unicode files
3208 def _GetUnicodeFileList(self):
3209 if self._UnicodeFileList == None:
3210 if TAB_UNICODE_FILE in self.FileTypes:
3211 self._UnicodeFileList = self.FileTypes[TAB_UNICODE_FILE]
3212 else:
3213 self._UnicodeFileList = []
3214 return self._UnicodeFileList
3215
3216 ## Return the list of vfr files
3217 def _GetVfrFileList(self):
3218 if self._VfrFileList == None:
3219 if TAB_VFR_FILE in self.FileTypes:
3220 self._VfrFileList = self.FileTypes[TAB_VFR_FILE]
3221 else:
3222 self._VfrFileList = []
3223 return self._VfrFileList
3224
3225 ## Return the list of Image Definition files
3226 def _GetIdfFileList(self):
3227 if self._IdfFileList == None:
3228 if TAB_IMAGE_FILE in self.FileTypes:
3229 self._IdfFileList = self.FileTypes[TAB_IMAGE_FILE]
3230 else:
3231 self._IdfFileList = []
3232 return self._IdfFileList
3233
3234 ## Return a list of files which can be built from binary
3235 #
3236 # "Build" binary files are just to copy them to build directory.
3237 #
3238 # @retval list The list of files which can be built later
3239 #
3240 def _GetBinaryFiles(self):
3241 if self._BinaryFileList == None:
3242 self._BinaryFileList = []
3243 for F in self.Module.Binaries:
3244 if F.Target not in ['COMMON', '*'] and F.Target != self.BuildTarget:
3245 continue
3246 self._BinaryFileList.append(F)
3247 self._ApplyBuildRule(F, F.Type)
3248 return self._BinaryFileList
3249
3250 def _GetBuildRules(self):
3251 if self._BuildRules == None:
3252 BuildRules = {}
3253 BuildRuleDatabase = self.PlatformInfo.BuildRule
3254 for Type in BuildRuleDatabase.FileTypeList:
3255 #first try getting build rule by BuildRuleFamily
3256 RuleObject = BuildRuleDatabase[Type, self.BuildType, self.Arch, self.BuildRuleFamily]
3257 if not RuleObject:
3258 # build type is always module type, but ...
3259 if self.ModuleType != self.BuildType:
3260 RuleObject = BuildRuleDatabase[Type, self.ModuleType, self.Arch, self.BuildRuleFamily]
3261 #second try getting build rule by ToolChainFamily
3262 if not RuleObject:
3263 RuleObject = BuildRuleDatabase[Type, self.BuildType, self.Arch, self.ToolChainFamily]
3264 if not RuleObject:
3265 # build type is always module type, but ...
3266 if self.ModuleType != self.BuildType:
3267 RuleObject = BuildRuleDatabase[Type, self.ModuleType, self.Arch, self.ToolChainFamily]
3268 if not RuleObject:
3269 continue
3270 RuleObject = RuleObject.Instantiate(self.Macros)
3271 BuildRules[Type] = RuleObject
3272 for Ext in RuleObject.SourceFileExtList:
3273 BuildRules[Ext] = RuleObject
3274 self._BuildRules = BuildRules
3275 return self._BuildRules
3276
3277 def _ApplyBuildRule(self, File, FileType):
3278 if self._BuildTargets == None:
3279 self._IntroBuildTargetList = set()
3280 self._FinalBuildTargetList = set()
3281 self._BuildTargets = {}
3282 self._FileTypes = {}
3283
3284 SubDirectory = os.path.join(self.OutputDir, File.SubDir)
3285 if not os.path.exists(SubDirectory):
3286 CreateDirectory(SubDirectory)
3287 LastTarget = None
3288 RuleChain = []
3289 SourceList = [File]
3290 Index = 0
3291 #
3292 # Make sure to get build rule order value
3293 #
3294 self._GetModuleBuildOption()
3295
3296 while Index < len(SourceList):
3297 Source = SourceList[Index]
3298 Index = Index + 1
3299
3300 if Source != File:
3301 CreateDirectory(Source.Dir)
3302
3303 if File.IsBinary and File == Source and self._BinaryFileList != None and File in self._BinaryFileList:
3304 # Skip all files that are not binary libraries
3305 if not self.IsLibrary:
3306 continue
3307 RuleObject = self.BuildRules[TAB_DEFAULT_BINARY_FILE]
3308 elif FileType in self.BuildRules:
3309 RuleObject = self.BuildRules[FileType]
3310 elif Source.Ext in self.BuildRules:
3311 RuleObject = self.BuildRules[Source.Ext]
3312 else:
3313 # stop at no more rules
3314 if LastTarget:
3315 self._FinalBuildTargetList.add(LastTarget)
3316 break
3317
3318 FileType = RuleObject.SourceFileType
3319 if FileType not in self._FileTypes:
3320 self._FileTypes[FileType] = set()
3321 self._FileTypes[FileType].add(Source)
3322
3323 # stop at STATIC_LIBRARY for library
3324 if self.IsLibrary and FileType == TAB_STATIC_LIBRARY:
3325 if LastTarget:
3326 self._FinalBuildTargetList.add(LastTarget)
3327 break
3328
3329 Target = RuleObject.Apply(Source, self.BuildRuleOrder)
3330 if not Target:
3331 if LastTarget:
3332 self._FinalBuildTargetList.add(LastTarget)
3333 break
3334 elif not Target.Outputs:
3335 # Only do build for target with outputs
3336 self._FinalBuildTargetList.add(Target)
3337
3338 if FileType not in self._BuildTargets:
3339 self._BuildTargets[FileType] = set()
3340 self._BuildTargets[FileType].add(Target)
3341
3342 if not Source.IsBinary and Source == File:
3343 self._IntroBuildTargetList.add(Target)
3344
3345 # to avoid cyclic rule
3346 if FileType in RuleChain:
3347 break
3348
3349 RuleChain.append(FileType)
3350 SourceList.extend(Target.Outputs)
3351 LastTarget = Target
3352 FileType = TAB_UNKNOWN_FILE
3353
3354 def _GetTargets(self):
3355 if self._BuildTargets == None:
3356 self._IntroBuildTargetList = set()
3357 self._FinalBuildTargetList = set()
3358 self._BuildTargets = {}
3359 self._FileTypes = {}
3360
3361 #TRICK: call _GetSourceFileList to apply build rule for source files
3362 if self.SourceFileList:
3363 pass
3364
3365 #TRICK: call _GetBinaryFileList to apply build rule for binary files
3366 if self.BinaryFileList:
3367 pass
3368
3369 return self._BuildTargets
3370
3371 def _GetIntroTargetList(self):
3372 self._GetTargets()
3373 return self._IntroBuildTargetList
3374
3375 def _GetFinalTargetList(self):
3376 self._GetTargets()
3377 return self._FinalBuildTargetList
3378
3379 def _GetFileTypes(self):
3380 self._GetTargets()
3381 return self._FileTypes
3382
3383 ## Get the list of package object the module depends on
3384 #
3385 # @retval list The package object list
3386 #
3387 def _GetDependentPackageList(self):
3388 return self.Module.Packages
3389
3390 ## Return the list of auto-generated code file
3391 #
3392 # @retval list The list of auto-generated file
3393 #
3394 def _GetAutoGenFileList(self):
3395 UniStringAutoGenC = True
3396 IdfStringAutoGenC = True
3397 UniStringBinBuffer = StringIO()
3398 IdfGenBinBuffer = StringIO()
3399 if self.BuildType == 'UEFI_HII':
3400 UniStringAutoGenC = False
3401 IdfStringAutoGenC = False
3402 if self._AutoGenFileList == None:
3403 self._AutoGenFileList = {}
3404 AutoGenC = TemplateString()
3405 AutoGenH = TemplateString()
3406 StringH = TemplateString()
3407 StringIdf = TemplateString()
3408 GenC.CreateCode(self, AutoGenC, AutoGenH, StringH, UniStringAutoGenC, UniStringBinBuffer, StringIdf, IdfStringAutoGenC, IdfGenBinBuffer)
3409 #
3410 # AutoGen.c is generated if there are library classes in inf, or there are object files
3411 #
3412 if str(AutoGenC) != "" and (len(self.Module.LibraryClasses) > 0
3413 or TAB_OBJECT_FILE in self.FileTypes):
3414 AutoFile = PathClass(gAutoGenCodeFileName, self.DebugDir)
3415 self._AutoGenFileList[AutoFile] = str(AutoGenC)
3416 self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)
3417 if str(AutoGenH) != "":
3418 AutoFile = PathClass(gAutoGenHeaderFileName, self.DebugDir)
3419 self._AutoGenFileList[AutoFile] = str(AutoGenH)
3420 self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)
3421 if str(StringH) != "":
3422 AutoFile = PathClass(gAutoGenStringFileName % {"module_name":self.Name}, self.DebugDir)
3423 self._AutoGenFileList[AutoFile] = str(StringH)
3424 self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)
3425 if UniStringBinBuffer != None and UniStringBinBuffer.getvalue() != "":
3426 AutoFile = PathClass(gAutoGenStringFormFileName % {"module_name":self.Name}, self.OutputDir)
3427 self._AutoGenFileList[AutoFile] = UniStringBinBuffer.getvalue()
3428 AutoFile.IsBinary = True
3429 self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)
3430 if UniStringBinBuffer != None:
3431 UniStringBinBuffer.close()
3432 if str(StringIdf) != "":
3433 AutoFile = PathClass(gAutoGenImageDefFileName % {"module_name":self.Name}, self.DebugDir)
3434 self._AutoGenFileList[AutoFile] = str(StringIdf)
3435 self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)
3436 if IdfGenBinBuffer != None and IdfGenBinBuffer.getvalue() != "":
3437 AutoFile = PathClass(gAutoGenIdfFileName % {"module_name":self.Name}, self.OutputDir)
3438 self._AutoGenFileList[AutoFile] = IdfGenBinBuffer.getvalue()
3439 AutoFile.IsBinary = True
3440 self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)
3441 if IdfGenBinBuffer != None:
3442 IdfGenBinBuffer.close()
3443 return self._AutoGenFileList
3444
3445 ## Return the list of library modules explicitly or implicityly used by this module
3446 def _GetLibraryList(self):
3447 if self._DependentLibraryList == None:
3448 # only merge library classes and PCD for non-library module
3449 if self.IsLibrary:
3450 self._DependentLibraryList = []
3451 else:
3452 if self.AutoGenVersion < 0x00010005:
3453 self._DependentLibraryList = self.PlatformInfo.ResolveLibraryReference(self.Module)
3454 else:
3455 self._DependentLibraryList = self.PlatformInfo.ApplyLibraryInstance(self.Module)
3456 return self._DependentLibraryList
3457
3458 @staticmethod
3459 def UpdateComments(Recver, Src):
3460 for Key in Src:
3461 if Key not in Recver:
3462 Recver[Key] = []
3463 Recver[Key].extend(Src[Key])
3464 ## Get the list of PCDs from current module
3465 #
3466 # @retval list The list of PCD
3467 #
3468 def _GetModulePcdList(self):
3469 if self._ModulePcdList == None:
3470 # apply PCD settings from platform
3471 self._ModulePcdList = self.PlatformInfo.ApplyPcdSetting(self.Module, self.Module.Pcds)
3472 self.UpdateComments(self._PcdComments, self.Module.PcdComments)
3473 return self._ModulePcdList
3474
3475 ## Get the list of PCDs from dependent libraries
3476 #
3477 # @retval list The list of PCD
3478 #
3479 def _GetLibraryPcdList(self):
3480 if self._LibraryPcdList == None:
3481 Pcds = sdict()
3482 if not self.IsLibrary:
3483 # get PCDs from dependent libraries
3484 for Library in self.DependentLibraryList:
3485 self.UpdateComments(self._PcdComments, Library.PcdComments)
3486 for Key in Library.Pcds:
3487 # skip duplicated PCDs
3488 if Key in self.Module.Pcds or Key in Pcds:
3489 continue
3490 Pcds[Key] = copy.copy(Library.Pcds[Key])
3491 # apply PCD settings from platform
3492 self._LibraryPcdList = self.PlatformInfo.ApplyPcdSetting(self.Module, Pcds)
3493 else:
3494 self._LibraryPcdList = []
3495 return self._LibraryPcdList
3496
3497 ## Get the GUID value mapping
3498 #
3499 # @retval dict The mapping between GUID cname and its value
3500 #
3501 def _GetGuidList(self):
3502 if self._GuidList == None:
3503 self._GuidList = sdict()
3504 self._GuidList.update(self.Module.Guids)
3505 for Library in self.DependentLibraryList:
3506 self._GuidList.update(Library.Guids)
3507 self.UpdateComments(self._GuidComments, Library.GuidComments)
3508 self.UpdateComments(self._GuidComments, self.Module.GuidComments)
3509 return self._GuidList
3510
3511 def GetGuidsUsedByPcd(self):
3512 if self._GuidsUsedByPcd == None:
3513 self._GuidsUsedByPcd = sdict()
3514 self._GuidsUsedByPcd.update(self.Module.GetGuidsUsedByPcd())
3515 for Library in self.DependentLibraryList:
3516 self._GuidsUsedByPcd.update(Library.GetGuidsUsedByPcd())
3517 return self._GuidsUsedByPcd
3518 ## Get the protocol value mapping
3519 #
3520 # @retval dict The mapping between protocol cname and its value
3521 #
3522 def _GetProtocolList(self):
3523 if self._ProtocolList == None:
3524 self._ProtocolList = sdict()
3525 self._ProtocolList.update(self.Module.Protocols)
3526 for Library in self.DependentLibraryList:
3527 self._ProtocolList.update(Library.Protocols)
3528 self.UpdateComments(self._ProtocolComments, Library.ProtocolComments)
3529 self.UpdateComments(self._ProtocolComments, self.Module.ProtocolComments)
3530 return self._ProtocolList
3531
3532 ## Get the PPI value mapping
3533 #
3534 # @retval dict The mapping between PPI cname and its value
3535 #
3536 def _GetPpiList(self):
3537 if self._PpiList == None:
3538 self._PpiList = sdict()
3539 self._PpiList.update(self.Module.Ppis)
3540 for Library in self.DependentLibraryList:
3541 self._PpiList.update(Library.Ppis)
3542 self.UpdateComments(self._PpiComments, Library.PpiComments)
3543 self.UpdateComments(self._PpiComments, self.Module.PpiComments)
3544 return self._PpiList
3545
3546 ## Get the list of include search path
3547 #
3548 # @retval list The list path
3549 #
3550 def _GetIncludePathList(self):
3551 if self._IncludePathList == None:
3552 self._IncludePathList = []
3553 if self.AutoGenVersion < 0x00010005:
3554 for Inc in self.Module.Includes:
3555 if Inc not in self._IncludePathList:
3556 self._IncludePathList.append(Inc)
3557 # for Edk modules
3558 Inc = path.join(Inc, self.Arch.capitalize())
3559 if os.path.exists(Inc) and Inc not in self._IncludePathList:
3560 self._IncludePathList.append(Inc)
3561 # Edk module needs to put DEBUG_DIR at the end of search path and not to use SOURCE_DIR all the time
3562 self._IncludePathList.append(self.DebugDir)
3563 else:
3564 self._IncludePathList.append(self.MetaFile.Dir)
3565 self._IncludePathList.append(self.DebugDir)
3566
3567 for Package in self.Module.Packages:
3568 PackageDir = mws.join(self.WorkspaceDir, Package.MetaFile.Dir)
3569 if PackageDir not in self._IncludePathList:
3570 self._IncludePathList.append(PackageDir)
3571 IncludesList = Package.Includes
3572 if Package._PrivateIncludes:
3573 if not self.MetaFile.Path.startswith(PackageDir):
3574 IncludesList = list(set(Package.Includes).difference(set(Package._PrivateIncludes)))
3575 for Inc in IncludesList:
3576 if Inc not in self._IncludePathList:
3577 self._IncludePathList.append(str(Inc))
3578 return self._IncludePathList
3579
3580 def _GetIncludePathLength(self):
3581 self._IncludePathLength = 0
3582 if self._IncludePathList:
3583 for inc in self._IncludePathList:
3584 self._IncludePathLength += len(' ' + inc)
3585 return self._IncludePathLength
3586
3587 ## Get HII EX PCDs which maybe used by VFR
3588 #
3589 # efivarstore used by VFR may relate with HII EX PCDs
3590 # Get the variable name and GUID from efivarstore and HII EX PCD
3591 # List the HII EX PCDs in As Built INF if both name and GUID match.
3592 #
3593 # @retval list HII EX PCDs
3594 #
3595 def _GetPcdsMaybeUsedByVfr(self):
3596 if not self.SourceFileList:
3597 return []
3598
3599 NameGuids = []
3600 for SrcFile in self.SourceFileList:
3601 if SrcFile.Ext.lower() != '.vfr':
3602 continue
3603 Vfri = os.path.join(self.OutputDir, SrcFile.BaseName + '.i')
3604 if not os.path.exists(Vfri):
3605 continue
3606 VfriFile = open(Vfri, 'r')
3607 Content = VfriFile.read()
3608 VfriFile.close()
3609 Pos = Content.find('efivarstore')
3610 while Pos != -1:
3611 #
3612 # Make sure 'efivarstore' is the start of efivarstore statement
3613 # In case of the value of 'name' (name = efivarstore) is equal to 'efivarstore'
3614 #
3615 Index = Pos - 1
3616 while Index >= 0 and Content[Index] in ' \t\r\n':
3617 Index -= 1
3618 if Index >= 0 and Content[Index] != ';':
3619 Pos = Content.find('efivarstore', Pos + len('efivarstore'))
3620 continue
3621 #
3622 # 'efivarstore' must be followed by name and guid
3623 #
3624 Name = gEfiVarStoreNamePattern.search(Content, Pos)
3625 if not Name:
3626 break
3627 Guid = gEfiVarStoreGuidPattern.search(Content, Pos)
3628 if not Guid:
3629 break
3630 NameArray = ConvertStringToByteArray('L"' + Name.group(1) + '"')
3631 NameGuids.append((NameArray, GuidStructureStringToGuidString(Guid.group(1))))
3632 Pos = Content.find('efivarstore', Name.end())
3633 if not NameGuids:
3634 return []
3635 HiiExPcds = []
3636 for Pcd in self.PlatformInfo.Platform.Pcds.values():
3637 if Pcd.Type != TAB_PCDS_DYNAMIC_EX_HII:
3638 continue
3639 for SkuName in Pcd.SkuInfoList:
3640 SkuInfo = Pcd.SkuInfoList[SkuName]
3641 Name = ConvertStringToByteArray(SkuInfo.VariableName)
3642 Value = GuidValue(SkuInfo.VariableGuid, self.PlatformInfo.PackageList, self.MetaFile.Path)
3643 if not Value:
3644 continue
3645 Guid = GuidStructureStringToGuidString(Value)
3646 if (Name, Guid) in NameGuids and Pcd not in HiiExPcds:
3647 HiiExPcds.append(Pcd)
3648 break
3649
3650 return HiiExPcds
3651
3652 def _GenOffsetBin(self):
3653 VfrUniBaseName = {}
3654 for SourceFile in self.Module.Sources:
3655 if SourceFile.Type.upper() == ".VFR" :
3656 #
3657 # search the .map file to find the offset of vfr binary in the PE32+/TE file.
3658 #
3659 VfrUniBaseName[SourceFile.BaseName] = (SourceFile.BaseName + "Bin")
3660 if SourceFile.Type.upper() == ".UNI" :
3661 #
3662 # search the .map file to find the offset of Uni strings binary in the PE32+/TE file.
3663 #
3664 VfrUniBaseName["UniOffsetName"] = (self.Name + "Strings")
3665
3666 if len(VfrUniBaseName) == 0:
3667 return None
3668 MapFileName = os.path.join(self.OutputDir, self.Name + ".map")
3669 EfiFileName = os.path.join(self.OutputDir, self.Name + ".efi")
3670 VfrUniOffsetList = GetVariableOffset(MapFileName, EfiFileName, VfrUniBaseName.values())
3671 if not VfrUniOffsetList:
3672 return None
3673
3674 OutputName = '%sOffset.bin' % self.Name
3675 UniVfrOffsetFileName = os.path.join( self.OutputDir, OutputName)
3676
3677 try:
3678 fInputfile = open(UniVfrOffsetFileName, "wb+", 0)
3679 except:
3680 EdkLogger.error("build", FILE_OPEN_FAILURE, "File open failed for %s" % UniVfrOffsetFileName,None)
3681
3682 # Use a instance of StringIO to cache data
3683 fStringIO = StringIO('')
3684
3685 for Item in VfrUniOffsetList:
3686 if (Item[0].find("Strings") != -1):
3687 #
3688 # UNI offset in image.
3689 # GUID + Offset
3690 # { 0x8913c5e0, 0x33f6, 0x4d86, { 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66 } }
3691 #
3692 UniGuid = [0xe0, 0xc5, 0x13, 0x89, 0xf6, 0x33, 0x86, 0x4d, 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66]
3693 UniGuid = [chr(ItemGuid) for ItemGuid in UniGuid]
3694 fStringIO.write(''.join(UniGuid))
3695 UniValue = pack ('Q', int (Item[1], 16))
3696 fStringIO.write (UniValue)
3697 else:
3698 #
3699 # VFR binary offset in image.
3700 # GUID + Offset
3701 # { 0xd0bc7cb4, 0x6a47, 0x495f, { 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2 } };
3702 #
3703 VfrGuid = [0xb4, 0x7c, 0xbc, 0xd0, 0x47, 0x6a, 0x5f, 0x49, 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2]
3704 VfrGuid = [chr(ItemGuid) for ItemGuid in VfrGuid]
3705 fStringIO.write(''.join(VfrGuid))
3706 type (Item[1])
3707 VfrValue = pack ('Q', int (Item[1], 16))
3708 fStringIO.write (VfrValue)
3709 #
3710 # write data into file.
3711 #
3712 try :
3713 fInputfile.write (fStringIO.getvalue())
3714 except:
3715 EdkLogger.error("build", FILE_WRITE_FAILURE, "Write data to file %s failed, please check whether the "
3716 "file been locked or using by other applications." %UniVfrOffsetFileName,None)
3717
3718 fStringIO.close ()
3719 fInputfile.close ()
3720 return OutputName
3721
3722 ## Create AsBuilt INF file the module
3723 #
3724 def CreateAsBuiltInf(self):
3725 if self.IsAsBuiltInfCreated:
3726 return
3727
3728 # Skip the following code for EDK I inf
3729 if self.AutoGenVersion < 0x00010005:
3730 return
3731
3732 # Skip the following code for libraries
3733 if self.IsLibrary:
3734 return
3735
3736 # Skip the following code for modules with no source files
3737 if self.SourceFileList == None or self.SourceFileList == []:
3738 return
3739
3740 # Skip the following code for modules without any binary files
3741 if self.BinaryFileList <> None and self.BinaryFileList <> []:
3742 return
3743
3744 ### TODO: How to handles mixed source and binary modules
3745
3746 # Find all DynamicEx and PatchableInModule PCDs used by this module and dependent libraries
3747 # Also find all packages that the DynamicEx PCDs depend on
3748 Pcds = []
3749 PatchablePcds = []
3750 Packages = []
3751 PcdCheckList = []
3752 PcdTokenSpaceList = []
3753 for Pcd in self.ModulePcdList + self.LibraryPcdList:
3754 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:
3755 PatchablePcds += [Pcd]
3756 PcdCheckList.append((Pcd.TokenCName, Pcd.TokenSpaceGuidCName, 'PatchableInModule'))
3757 elif Pcd.Type in GenC.gDynamicExPcd:
3758 if Pcd not in Pcds:
3759 Pcds += [Pcd]
3760 PcdCheckList.append((Pcd.TokenCName, Pcd.TokenSpaceGuidCName, 'DynamicEx'))
3761 PcdCheckList.append((Pcd.TokenCName, Pcd.TokenSpaceGuidCName, 'Dynamic'))
3762 PcdTokenSpaceList.append(Pcd.TokenSpaceGuidCName)
3763 GuidList = sdict()
3764 GuidList.update(self.GuidList)
3765 for TokenSpace in self.GetGuidsUsedByPcd():
3766 # If token space is not referred by patch PCD or Ex PCD, remove the GUID from GUID list
3767 # The GUIDs in GUIDs section should really be the GUIDs in source INF or referred by Ex an patch PCDs
3768 if TokenSpace not in PcdTokenSpaceList and TokenSpace in GuidList:
3769 GuidList.pop(TokenSpace)
3770 CheckList = (GuidList, self.PpiList, self.ProtocolList, PcdCheckList)
3771 for Package in self.DerivedPackageList:
3772 if Package in Packages:
3773 continue
3774 BeChecked = (Package.Guids, Package.Ppis, Package.Protocols, Package.Pcds)
3775 Found = False
3776 for Index in range(len(BeChecked)):
3777 for Item in CheckList[Index]:
3778 if Item in BeChecked[Index]:
3779 Packages += [Package]
3780 Found = True
3781 break
3782 if Found: break
3783
3784 VfrPcds = self._GetPcdsMaybeUsedByVfr()
3785 for Pkg in self.PlatformInfo.PackageList:
3786 if Pkg in Packages:
3787 continue
3788 for VfrPcd in VfrPcds:
3789 if ((VfrPcd.TokenCName, VfrPcd.TokenSpaceGuidCName, 'DynamicEx') in Pkg.Pcds or
3790 (VfrPcd.TokenCName, VfrPcd.TokenSpaceGuidCName, 'Dynamic') in Pkg.Pcds):
3791 Packages += [Pkg]
3792 break
3793
3794 ModuleType = self.ModuleType
3795 if ModuleType == 'UEFI_DRIVER' and self.DepexGenerated:
3796 ModuleType = 'DXE_DRIVER'
3797
3798 DriverType = ''
3799 if self.PcdIsDriver != '':
3800 DriverType = self.PcdIsDriver
3801
3802 Guid = self.Guid
3803 MDefs = self.Module.Defines
3804
3805 AsBuiltInfDict = {
3806 'module_name' : self.Name,
3807 'module_guid' : Guid,
3808 'module_module_type' : ModuleType,
3809 'module_version_string' : [MDefs['VERSION_STRING']] if 'VERSION_STRING' in MDefs else [],
3810 'pcd_is_driver_string' : [],
3811 'module_uefi_specification_version' : [],
3812 'module_pi_specification_version' : [],
3813 'module_entry_point' : self.Module.ModuleEntryPointList,
3814 'module_unload_image' : self.Module.ModuleUnloadImageList,
3815 'module_constructor' : self.Module.ConstructorList,
3816 'module_destructor' : self.Module.DestructorList,
3817 'module_shadow' : [MDefs['SHADOW']] if 'SHADOW' in MDefs else [],
3818 'module_pci_vendor_id' : [MDefs['PCI_VENDOR_ID']] if 'PCI_VENDOR_ID' in MDefs else [],
3819 'module_pci_device_id' : [MDefs['PCI_DEVICE_ID']] if 'PCI_DEVICE_ID' in MDefs else [],
3820 'module_pci_class_code' : [MDefs['PCI_CLASS_CODE']] if 'PCI_CLASS_CODE' in MDefs else [],
3821 'module_pci_revision' : [MDefs['PCI_REVISION']] if 'PCI_REVISION' in MDefs else [],
3822 'module_build_number' : [MDefs['BUILD_NUMBER']] if 'BUILD_NUMBER' in MDefs else [],
3823 'module_spec' : [MDefs['SPEC']] if 'SPEC' in MDefs else [],
3824 'module_uefi_hii_resource_section' : [MDefs['UEFI_HII_RESOURCE_SECTION']] if 'UEFI_HII_RESOURCE_SECTION' in MDefs else [],
3825 'module_uni_file' : [MDefs['MODULE_UNI_FILE']] if 'MODULE_UNI_FILE' in MDefs else [],
3826 'module_arch' : self.Arch,
3827 'package_item' : ['%s' % (Package.MetaFile.File.replace('\\', '/')) for Package in Packages],
3828 'binary_item' : [],
3829 'patchablepcd_item' : [],
3830 'pcd_item' : [],
3831 'protocol_item' : [],
3832 'ppi_item' : [],
3833 'guid_item' : [],
3834 'flags_item' : [],
3835 'libraryclasses_item' : []
3836 }
3837
3838 if self.AutoGenVersion > int(gInfSpecVersion, 0):
3839 AsBuiltInfDict['module_inf_version'] = '0x%08x' % self.AutoGenVersion
3840 else:
3841 AsBuiltInfDict['module_inf_version'] = gInfSpecVersion
3842
3843 if DriverType:
3844 AsBuiltInfDict['pcd_is_driver_string'] += [DriverType]
3845
3846 if 'UEFI_SPECIFICATION_VERSION' in self.Specification:
3847 AsBuiltInfDict['module_uefi_specification_version'] += [self.Specification['UEFI_SPECIFICATION_VERSION']]
3848 if 'PI_SPECIFICATION_VERSION' in self.Specification:
3849 AsBuiltInfDict['module_pi_specification_version'] += [self.Specification['PI_SPECIFICATION_VERSION']]
3850
3851 OutputDir = self.OutputDir.replace('\\', '/').strip('/')
3852
3853 for Item in self.CodaTargetList:
3854 File = Item.Target.Path.replace('\\', '/').strip('/').replace(OutputDir, '').strip('/')
3855 if Item.Target.Ext.lower() == '.aml':
3856 AsBuiltInfDict['binary_item'] += ['ASL|' + File]
3857 elif Item.Target.Ext.lower() == '.acpi':
3858 AsBuiltInfDict['binary_item'] += ['ACPI|' + File]
3859 elif Item.Target.Ext.lower() == '.efi':
3860 AsBuiltInfDict['binary_item'] += ['PE32|' + self.Name + '.efi']
3861 else:
3862 AsBuiltInfDict['binary_item'] += ['BIN|' + File]
3863 if self.DepexGenerated:
3864 if self.ModuleType in ['PEIM']:
3865 AsBuiltInfDict['binary_item'] += ['PEI_DEPEX|' + self.Name + '.depex']
3866 if self.ModuleType in ['DXE_DRIVER', 'DXE_RUNTIME_DRIVER', 'DXE_SAL_DRIVER', 'UEFI_DRIVER']:
3867 AsBuiltInfDict['binary_item'] += ['DXE_DEPEX|' + self.Name + '.depex']
3868 if self.ModuleType in ['DXE_SMM_DRIVER']:
3869 AsBuiltInfDict['binary_item'] += ['SMM_DEPEX|' + self.Name + '.depex']
3870
3871 Bin = self._GenOffsetBin()
3872 if Bin:
3873 AsBuiltInfDict['binary_item'] += ['BIN|%s' % Bin]
3874
3875 for Root, Dirs, Files in os.walk(OutputDir):
3876 for File in Files:
3877 if File.lower().endswith('.pdb'):
3878 AsBuiltInfDict['binary_item'] += ['DISPOSABLE|' + File]
3879 HeaderComments = self.Module.HeaderComments
3880 StartPos = 0
3881 for Index in range(len(HeaderComments)):
3882 if HeaderComments[Index].find('@BinaryHeader') != -1:
3883 HeaderComments[Index] = HeaderComments[Index].replace('@BinaryHeader', '@file')
3884 StartPos = Index
3885 break
3886 AsBuiltInfDict['header_comments'] = '\n'.join(HeaderComments[StartPos:]).replace(':#', '://')
3887 AsBuiltInfDict['tail_comments'] = '\n'.join(self.Module.TailComments)
3888
3889 GenList = [
3890 (self.ProtocolList, self._ProtocolComments, 'protocol_item'),
3891 (self.PpiList, self._PpiComments, 'ppi_item'),
3892 (GuidList, self._GuidComments, 'guid_item')
3893 ]
3894 for Item in GenList:
3895 for CName in Item[0]:
3896 Comments = ''
3897 if CName in Item[1]:
3898 Comments = '\n '.join(Item[1][CName])
3899 Entry = CName
3900 if Comments:
3901 Entry = Comments + '\n ' + CName
3902 AsBuiltInfDict[Item[2]].append(Entry)
3903 PatchList = parsePcdInfoFromMapFile(
3904 os.path.join(self.OutputDir, self.Name + '.map'),
3905 os.path.join(self.OutputDir, self.Name + '.efi')
3906 )
3907 if PatchList:
3908 for Pcd in PatchablePcds:
3909 TokenCName = Pcd.TokenCName
3910 for PcdItem in GlobalData.MixedPcd:
3911 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:
3912 TokenCName = PcdItem[0]
3913 break
3914 for PatchPcd in PatchList:
3915 if TokenCName == PatchPcd[0]:
3916 break
3917 else:
3918 continue
3919 PcdValue = ''
3920 if Pcd.DatumType != 'VOID*':
3921 HexFormat = '0x%02x'
3922 if Pcd.DatumType == 'UINT16':
3923 HexFormat = '0x%04x'
3924 elif Pcd.DatumType == 'UINT32':
3925 HexFormat = '0x%08x'
3926 elif Pcd.DatumType == 'UINT64':
3927 HexFormat = '0x%016x'
3928 PcdValue = HexFormat % int(Pcd.DefaultValue, 0)
3929 else:
3930 if Pcd.MaxDatumSize == None or Pcd.MaxDatumSize == '':
3931 EdkLogger.error("build", AUTOGEN_ERROR,
3932 "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd.TokenSpaceGuidCName, TokenCName)
3933 )
3934 ArraySize = int(Pcd.MaxDatumSize, 0)
3935 PcdValue = Pcd.DefaultValue
3936 if PcdValue[0] != '{':
3937 Unicode = False
3938 if PcdValue[0] == 'L':
3939 Unicode = True
3940 PcdValue = PcdValue.lstrip('L')
3941 PcdValue = eval(PcdValue)
3942 NewValue = '{'
3943 for Index in range(0, len(PcdValue)):
3944 if Unicode:
3945 CharVal = ord(PcdValue[Index])
3946 NewValue = NewValue + '0x%02x' % (CharVal & 0x00FF) + ', ' \
3947 + '0x%02x' % (CharVal >> 8) + ', '
3948 else:
3949 NewValue = NewValue + '0x%02x' % (ord(PcdValue[Index]) % 0x100) + ', '
3950 Padding = '0x00, '
3951 if Unicode:
3952 Padding = Padding * 2
3953 ArraySize = ArraySize / 2
3954 if ArraySize < (len(PcdValue) + 1):
3955 EdkLogger.error("build", AUTOGEN_ERROR,
3956 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, TokenCName)
3957 )
3958 if ArraySize > len(PcdValue) + 1:
3959 NewValue = NewValue + Padding * (ArraySize - len(PcdValue) - 1)
3960 PcdValue = NewValue + Padding.strip().rstrip(',') + '}'
3961 elif len(PcdValue.split(',')) <= ArraySize:
3962 PcdValue = PcdValue.rstrip('}') + ', 0x00' * (ArraySize - len(PcdValue.split(',')))
3963 PcdValue += '}'
3964 else:
3965 EdkLogger.error("build", AUTOGEN_ERROR,
3966 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, TokenCName)
3967 )
3968 PcdItem = '%s.%s|%s|0x%X' % \
3969 (Pcd.TokenSpaceGuidCName, TokenCName, PcdValue, PatchPcd[1])
3970 PcdComments = ''
3971 if (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) in self._PcdComments:
3972 PcdComments = '\n '.join(self._PcdComments[Pcd.TokenSpaceGuidCName, Pcd.TokenCName])
3973 if PcdComments:
3974 PcdItem = PcdComments + '\n ' + PcdItem
3975 AsBuiltInfDict['patchablepcd_item'].append(PcdItem)
3976
3977 HiiPcds = []
3978 for Pcd in Pcds + VfrPcds:
3979 PcdComments = ''
3980 PcdCommentList = []
3981 HiiInfo = ''
3982 SkuId = ''
3983 TokenCName = Pcd.TokenCName
3984 for PcdItem in GlobalData.MixedPcd:
3985 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:
3986 TokenCName = PcdItem[0]
3987 break
3988 if Pcd.Type == TAB_PCDS_DYNAMIC_EX_HII:
3989 for SkuName in Pcd.SkuInfoList:
3990 SkuInfo = Pcd.SkuInfoList[SkuName]
3991 SkuId = SkuInfo.SkuId
3992 HiiInfo = '## %s|%s|%s' % (SkuInfo.VariableName, SkuInfo.VariableGuid, SkuInfo.VariableOffset)
3993 break
3994 if SkuId:
3995 #
3996 # Don't generate duplicated HII PCD
3997 #
3998 if (SkuId, Pcd.TokenSpaceGuidCName, Pcd.TokenCName) in HiiPcds:
3999 continue
4000 else:
4001 HiiPcds.append((SkuId, Pcd.TokenSpaceGuidCName, Pcd.TokenCName))
4002 if (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) in self._PcdComments:
4003 PcdCommentList = self._PcdComments[Pcd.TokenSpaceGuidCName, Pcd.TokenCName][:]
4004 if HiiInfo:
4005 UsageIndex = -1
4006 UsageStr = ''
4007 for Index, Comment in enumerate(PcdCommentList):
4008 for Usage in UsageList:
4009 if Comment.find(Usage) != -1:
4010 UsageStr = Usage
4011 UsageIndex = Index
4012 break
4013 if UsageIndex != -1:
4014 PcdCommentList[UsageIndex] = '## %s %s %s' % (UsageStr, HiiInfo, PcdCommentList[UsageIndex].replace(UsageStr, ''))
4015 else:
4016 PcdCommentList.append('## UNDEFINED ' + HiiInfo)
4017 PcdComments = '\n '.join(PcdCommentList)
4018 PcdEntry = Pcd.TokenSpaceGuidCName + '.' + TokenCName
4019 if PcdComments:
4020 PcdEntry = PcdComments + '\n ' + PcdEntry
4021 AsBuiltInfDict['pcd_item'] += [PcdEntry]
4022 for Item in self.BuildOption:
4023 if 'FLAGS' in self.BuildOption[Item]:
4024 AsBuiltInfDict['flags_item'] += ['%s:%s_%s_%s_%s_FLAGS = %s' % (self.ToolChainFamily, self.BuildTarget, self.ToolChain, self.Arch, Item, self.BuildOption[Item]['FLAGS'].strip())]
4025
4026 # Generated LibraryClasses section in comments.
4027 for Library in self.LibraryAutoGenList:
4028 AsBuiltInfDict['libraryclasses_item'] += [Library.MetaFile.File.replace('\\', '/')]
4029
4030 # Generated depex expression section in comments.
4031 AsBuiltInfDict['depexsection_item'] = ''
4032 DepexExpresion = self._GetDepexExpresionString()
4033 if DepexExpresion:
4034 AsBuiltInfDict['depexsection_item'] = DepexExpresion
4035
4036 AsBuiltInf = TemplateString()
4037 AsBuiltInf.Append(gAsBuiltInfHeaderString.Replace(AsBuiltInfDict))
4038
4039 SaveFileOnChange(os.path.join(self.OutputDir, self.Name + '.inf'), str(AsBuiltInf), False)
4040
4041 self.IsAsBuiltInfCreated = True
4042
4043 ## Create makefile for the module and its dependent libraries
4044 #
4045 # @param CreateLibraryMakeFile Flag indicating if or not the makefiles of
4046 # dependent libraries will be created
4047 #
4048 def CreateMakeFile(self, CreateLibraryMakeFile=True):
4049 # Ignore generating makefile when it is a binary module
4050 if self.IsBinaryModule:
4051 return
4052
4053 if self.IsMakeFileCreated:
4054 return
4055 if self.CanSkip():
4056 return
4057
4058 if not self.IsLibrary and CreateLibraryMakeFile:
4059 for LibraryAutoGen in self.LibraryAutoGenList:
4060 LibraryAutoGen.CreateMakeFile()
4061
4062 if len(self.CustomMakefile) == 0:
4063 Makefile = GenMake.ModuleMakefile(self)
4064 else:
4065 Makefile = GenMake.CustomMakefile(self)
4066 if Makefile.Generate():
4067 EdkLogger.debug(EdkLogger.DEBUG_9, "Generated makefile for module %s [%s]" %
4068 (self.Name, self.Arch))
4069 else:
4070 EdkLogger.debug(EdkLogger.DEBUG_9, "Skipped the generation of makefile for module %s [%s]" %
4071 (self.Name, self.Arch))
4072
4073 self.CreateTimeStamp(Makefile)
4074 self.IsMakeFileCreated = True
4075
4076 def CopyBinaryFiles(self):
4077 for File in self.Module.Binaries:
4078 SrcPath = File.Path
4079 DstPath = os.path.join(self.OutputDir , os.path.basename(SrcPath))
4080 CopyLongFilePath(SrcPath, DstPath)
4081 ## Create autogen code for the module and its dependent libraries
4082 #
4083 # @param CreateLibraryCodeFile Flag indicating if or not the code of
4084 # dependent libraries will be created
4085 #
4086 def CreateCodeFile(self, CreateLibraryCodeFile=True):
4087 if self.IsCodeFileCreated:
4088 return
4089 if self.CanSkip():
4090 return
4091
4092 # Need to generate PcdDatabase even PcdDriver is binarymodule
4093 if self.IsBinaryModule and self.PcdIsDriver != '':
4094 CreatePcdDatabaseCode(self, TemplateString(), TemplateString())
4095 return
4096 if self.IsBinaryModule:
4097 if self.IsLibrary:
4098 self.CopyBinaryFiles()
4099 return
4100
4101 if not self.IsLibrary and CreateLibraryCodeFile:
4102 for LibraryAutoGen in self.LibraryAutoGenList:
4103 LibraryAutoGen.CreateCodeFile()
4104
4105 AutoGenList = []
4106 IgoredAutoGenList = []
4107
4108 for File in self.AutoGenFileList:
4109 if GenC.Generate(File.Path, self.AutoGenFileList[File], File.IsBinary):
4110 #Ignore Edk AutoGen.c
4111 if self.AutoGenVersion < 0x00010005 and File.Name == 'AutoGen.c':
4112 continue
4113
4114 AutoGenList.append(str(File))
4115 else:
4116 IgoredAutoGenList.append(str(File))
4117
4118 # Skip the following code for EDK I inf
4119 if self.AutoGenVersion < 0x00010005:
4120 return
4121
4122 for ModuleType in self.DepexList:
4123 # Ignore empty [depex] section or [depex] section for "USER_DEFINED" module
4124 if len(self.DepexList[ModuleType]) == 0 or ModuleType == "USER_DEFINED":
4125 continue
4126
4127 Dpx = GenDepex.DependencyExpression(self.DepexList[ModuleType], ModuleType, True)
4128 DpxFile = gAutoGenDepexFileName % {"module_name" : self.Name}
4129
4130 if len(Dpx.PostfixNotation) <> 0:
4131 self.DepexGenerated = True
4132
4133 if Dpx.Generate(path.join(self.OutputDir, DpxFile)):
4134 AutoGenList.append(str(DpxFile))
4135 else:
4136 IgoredAutoGenList.append(str(DpxFile))
4137
4138 if IgoredAutoGenList == []:
4139 EdkLogger.debug(EdkLogger.DEBUG_9, "Generated [%s] files for module %s [%s]" %
4140 (" ".join(AutoGenList), self.Name, self.Arch))
4141 elif AutoGenList == []:
4142 EdkLogger.debug(EdkLogger.DEBUG_9, "Skipped the generation of [%s] files for module %s [%s]" %
4143 (" ".join(IgoredAutoGenList), self.Name, self.Arch))
4144 else:
4145 EdkLogger.debug(EdkLogger.DEBUG_9, "Generated [%s] (skipped %s) files for module %s [%s]" %
4146 (" ".join(AutoGenList), " ".join(IgoredAutoGenList), self.Name, self.Arch))
4147
4148 self.IsCodeFileCreated = True
4149 return AutoGenList
4150
4151 ## Summarize the ModuleAutoGen objects of all libraries used by this module
4152 def _GetLibraryAutoGenList(self):
4153 if self._LibraryAutoGenList == None:
4154 self._LibraryAutoGenList = []
4155 for Library in self.DependentLibraryList:
4156 La = ModuleAutoGen(
4157 self.Workspace,
4158 Library.MetaFile,
4159 self.BuildTarget,
4160 self.ToolChain,
4161 self.Arch,
4162 self.PlatformInfo.MetaFile
4163 )
4164 if La not in self._LibraryAutoGenList:
4165 self._LibraryAutoGenList.append(La)
4166 for Lib in La.CodaTargetList:
4167 self._ApplyBuildRule(Lib.Target, TAB_UNKNOWN_FILE)
4168 return self._LibraryAutoGenList
4169
4170 ## Decide whether we can skip the ModuleAutoGen process
4171 # If any source file is newer than the modeule than we cannot skip
4172 #
4173 def CanSkip(self):
4174 if not os.path.exists(self.GetTimeStampPath()):
4175 return False
4176 #last creation time of the module
4177 DstTimeStamp = os.stat(self.GetTimeStampPath())[8]
4178
4179 SrcTimeStamp = self.Workspace._SrcTimeStamp
4180 if SrcTimeStamp > DstTimeStamp:
4181 return False
4182
4183 with open(self.GetTimeStampPath(),'r') as f:
4184 for source in f:
4185 source = source.rstrip('\n')
4186 if source not in ModuleAutoGen.TimeDict :
4187 ModuleAutoGen.TimeDict[source] = os.stat(source)[8]
4188 if ModuleAutoGen.TimeDict[source] > DstTimeStamp:
4189 return False
4190 return True
4191
4192 def GetTimeStampPath(self):
4193 if self._TimeStampPath == None:
4194 self._TimeStampPath = os.path.join(self.MakeFileDir, 'AutoGenTimeStamp')
4195 return self._TimeStampPath
4196 def CreateTimeStamp(self, Makefile):
4197
4198 FileSet = set()
4199
4200 FileSet.add (self.MetaFile.Path)
4201
4202 for SourceFile in self.Module.Sources:
4203 FileSet.add (SourceFile.Path)
4204
4205 for Lib in self.DependentLibraryList:
4206 FileSet.add (Lib.MetaFile.Path)
4207
4208 for f in self.AutoGenDepSet:
4209 FileSet.add (f.Path)
4210
4211 if os.path.exists (self.GetTimeStampPath()):
4212 os.remove (self.GetTimeStampPath())
4213 with open(self.GetTimeStampPath(), 'w+') as file:
4214 for f in FileSet:
4215 print >> file, f
4216
4217 Module = property(_GetModule)
4218 Name = property(_GetBaseName)
4219 Guid = property(_GetGuid)
4220 Version = property(_GetVersion)
4221 ModuleType = property(_GetModuleType)
4222 ComponentType = property(_GetComponentType)
4223 BuildType = property(_GetBuildType)
4224 PcdIsDriver = property(_GetPcdIsDriver)
4225 AutoGenVersion = property(_GetAutoGenVersion)
4226 Macros = property(_GetMacros)
4227 Specification = property(_GetSpecification)
4228
4229 IsLibrary = property(_IsLibrary)
4230 IsBinaryModule = property(_IsBinaryModule)
4231 BuildDir = property(_GetBuildDir)
4232 OutputDir = property(_GetOutputDir)
4233 DebugDir = property(_GetDebugDir)
4234 MakeFileDir = property(_GetMakeFileDir)
4235 CustomMakefile = property(_GetCustomMakefile)
4236
4237 IncludePathList = property(_GetIncludePathList)
4238 IncludePathLength = property(_GetIncludePathLength)
4239 AutoGenFileList = property(_GetAutoGenFileList)
4240 UnicodeFileList = property(_GetUnicodeFileList)
4241 VfrFileList = property(_GetVfrFileList)
4242 SourceFileList = property(_GetSourceFileList)
4243 BinaryFileList = property(_GetBinaryFiles) # FileType : [File List]
4244 Targets = property(_GetTargets)
4245 IntroTargetList = property(_GetIntroTargetList)
4246 CodaTargetList = property(_GetFinalTargetList)
4247 FileTypes = property(_GetFileTypes)
4248 BuildRules = property(_GetBuildRules)
4249 IdfFileList = property(_GetIdfFileList)
4250
4251 DependentPackageList = property(_GetDependentPackageList)
4252 DependentLibraryList = property(_GetLibraryList)
4253 LibraryAutoGenList = property(_GetLibraryAutoGenList)
4254 DerivedPackageList = property(_GetDerivedPackageList)
4255
4256 ModulePcdList = property(_GetModulePcdList)
4257 LibraryPcdList = property(_GetLibraryPcdList)
4258 GuidList = property(_GetGuidList)
4259 ProtocolList = property(_GetProtocolList)
4260 PpiList = property(_GetPpiList)
4261 DepexList = property(_GetDepexTokenList)
4262 DxsFile = property(_GetDxsFile)
4263 DepexExpressionList = property(_GetDepexExpressionTokenList)
4264 BuildOption = property(_GetModuleBuildOption)
4265 BuildOptionIncPathList = property(_GetBuildOptionIncPathList)
4266 BuildCommand = property(_GetBuildCommand)
4267
4268 FixedAtBuildPcds = property(_GetFixedAtBuildPcds)
4269
4270 # This acts like the main() function for the script, unless it is 'import'ed into another script.
4271 if __name__ == '__main__':
4272 pass
4273