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