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