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