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