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