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