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