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