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