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