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