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