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