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