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