]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/AutoGen/AutoGen.py
a1e1818e3b5f5878f89a075630b55c22b20157cc
[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 - 2015, 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 ToPcd.validateranges = FromPcd.validateranges
1817 ToPcd.validlists = FromPcd.validlists
1818 ToPcd.expressions = FromPcd.expressions
1819
1820 if ToPcd.DatumType == "VOID*" and ToPcd.MaxDatumSize in ['', None]:
1821 EdkLogger.debug(EdkLogger.DEBUG_9, "No MaxDatumSize specified for PCD %s.%s" \
1822 % (ToPcd.TokenSpaceGuidCName, ToPcd.TokenCName))
1823 Value = ToPcd.DefaultValue
1824 if Value in [None, '']:
1825 ToPcd.MaxDatumSize = '1'
1826 elif Value[0] == 'L':
1827 ToPcd.MaxDatumSize = str((len(Value) - 2) * 2)
1828 elif Value[0] == '{':
1829 ToPcd.MaxDatumSize = str(len(Value.split(',')))
1830 else:
1831 ToPcd.MaxDatumSize = str(len(Value) - 1)
1832
1833 # apply default SKU for dynamic PCDS if specified one is not available
1834 if (ToPcd.Type in PCD_DYNAMIC_TYPE_LIST or ToPcd.Type in PCD_DYNAMIC_EX_TYPE_LIST) \
1835 and ToPcd.SkuInfoList in [None, {}, '']:
1836 if self.Platform.SkuName in self.Platform.SkuIds:
1837 SkuName = self.Platform.SkuName
1838 else:
1839 SkuName = 'DEFAULT'
1840 ToPcd.SkuInfoList = {
1841 SkuName : SkuInfoClass(SkuName, self.Platform.SkuIds[SkuName], '', '', '', '', '', ToPcd.DefaultValue)
1842 }
1843
1844 ## Apply PCD setting defined platform to a module
1845 #
1846 # @param Module The module from which the PCD setting will be overrided
1847 #
1848 # @retval PCD_list The list PCDs with settings from platform
1849 #
1850 def ApplyPcdSetting(self, Module, Pcds):
1851 # for each PCD in module
1852 for Name,Guid in Pcds:
1853 PcdInModule = Pcds[Name,Guid]
1854 # find out the PCD setting in platform
1855 if (Name,Guid) in self.Platform.Pcds:
1856 PcdInPlatform = self.Platform.Pcds[Name,Guid]
1857 else:
1858 PcdInPlatform = None
1859 # then override the settings if any
1860 self._OverridePcd(PcdInModule, PcdInPlatform, Module)
1861 # resolve the VariableGuid value
1862 for SkuId in PcdInModule.SkuInfoList:
1863 Sku = PcdInModule.SkuInfoList[SkuId]
1864 if Sku.VariableGuid == '': continue
1865 Sku.VariableGuidValue = GuidValue(Sku.VariableGuid, self.PackageList)
1866 if Sku.VariableGuidValue == None:
1867 PackageList = "\n\t".join([str(P) for P in self.PackageList])
1868 EdkLogger.error(
1869 'build',
1870 RESOURCE_NOT_AVAILABLE,
1871 "Value of GUID [%s] is not found in" % Sku.VariableGuid,
1872 ExtraData=PackageList + "\n\t(used with %s.%s from module %s)" \
1873 % (Guid, Name, str(Module)),
1874 File=self.MetaFile
1875 )
1876
1877 # override PCD settings with module specific setting
1878 if Module in self.Platform.Modules:
1879 PlatformModule = self.Platform.Modules[str(Module)]
1880 for Key in PlatformModule.Pcds:
1881 if Key in Pcds:
1882 self._OverridePcd(Pcds[Key], PlatformModule.Pcds[Key], Module)
1883 return Pcds.values()
1884
1885 ## Resolve library names to library modules
1886 #
1887 # (for Edk.x modules)
1888 #
1889 # @param Module The module from which the library names will be resolved
1890 #
1891 # @retval library_list The list of library modules
1892 #
1893 def ResolveLibraryReference(self, Module):
1894 EdkLogger.verbose("")
1895 EdkLogger.verbose("Library instances of module [%s] [%s]:" % (str(Module), self.Arch))
1896 LibraryConsumerList = [Module]
1897
1898 # "CompilerStub" is a must for Edk modules
1899 if Module.Libraries:
1900 Module.Libraries.append("CompilerStub")
1901 LibraryList = []
1902 while len(LibraryConsumerList) > 0:
1903 M = LibraryConsumerList.pop()
1904 for LibraryName in M.Libraries:
1905 Library = self.Platform.LibraryClasses[LibraryName, ':dummy:']
1906 if Library == None:
1907 for Key in self.Platform.LibraryClasses.data.keys():
1908 if LibraryName.upper() == Key.upper():
1909 Library = self.Platform.LibraryClasses[Key, ':dummy:']
1910 break
1911 if Library == None:
1912 EdkLogger.warn("build", "Library [%s] is not found" % LibraryName, File=str(M),
1913 ExtraData="\t%s [%s]" % (str(Module), self.Arch))
1914 continue
1915
1916 if Library not in LibraryList:
1917 LibraryList.append(Library)
1918 LibraryConsumerList.append(Library)
1919 EdkLogger.verbose("\t" + LibraryName + " : " + str(Library) + ' ' + str(type(Library)))
1920 return LibraryList
1921
1922 ## Calculate the priority value of the build option
1923 #
1924 # @param Key Build option definition contain: TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
1925 #
1926 # @retval Value Priority value based on the priority list.
1927 #
1928 def CalculatePriorityValue(self, Key):
1929 Target, ToolChain, Arch, CommandType, Attr = Key.split('_')
1930 PriorityValue = 0x11111
1931 if Target == "*":
1932 PriorityValue &= 0x01111
1933 if ToolChain == "*":
1934 PriorityValue &= 0x10111
1935 if Arch == "*":
1936 PriorityValue &= 0x11011
1937 if CommandType == "*":
1938 PriorityValue &= 0x11101
1939 if Attr == "*":
1940 PriorityValue &= 0x11110
1941
1942 return self.PrioList["0x%0.5x"%PriorityValue]
1943
1944
1945 ## Expand * in build option key
1946 #
1947 # @param Options Options to be expanded
1948 #
1949 # @retval options Options expanded
1950 #
1951 def _ExpandBuildOption(self, Options, ModuleStyle=None):
1952 BuildOptions = {}
1953 FamilyMatch = False
1954 FamilyIsNull = True
1955
1956 OverrideList = {}
1957 #
1958 # Construct a list contain the build options which need override.
1959 #
1960 for Key in Options:
1961 #
1962 # Key[0] -- tool family
1963 # Key[1] -- TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE
1964 #
1965 if Key[0] == self.BuildRuleFamily :
1966 Target, ToolChain, Arch, CommandType, Attr = Key[1].split('_')
1967 if Target == self.BuildTarget or Target == "*":
1968 if ToolChain == self.ToolChain or ToolChain == "*":
1969 if Arch == self.Arch or Arch == "*":
1970 if Options[Key].startswith("="):
1971 if OverrideList.get(Key[1]) != None:
1972 OverrideList.pop(Key[1])
1973 OverrideList[Key[1]] = Options[Key]
1974
1975 #
1976 # Use the highest priority value.
1977 #
1978 if (len(OverrideList) >= 2):
1979 KeyList = OverrideList.keys()
1980 for Index in range(len(KeyList)):
1981 NowKey = KeyList[Index]
1982 Target1, ToolChain1, Arch1, CommandType1, Attr1 = NowKey.split("_")
1983 for Index1 in range(len(KeyList) - Index - 1):
1984 NextKey = KeyList[Index1 + Index + 1]
1985 #
1986 # Compare two Key, if one is included by another, choose the higher priority one
1987 #
1988 Target2, ToolChain2, Arch2, CommandType2, Attr2 = NextKey.split("_")
1989 if Target1 == Target2 or Target1 == "*" or Target2 == "*":
1990 if ToolChain1 == ToolChain2 or ToolChain1 == "*" or ToolChain2 == "*":
1991 if Arch1 == Arch2 or Arch1 == "*" or Arch2 == "*":
1992 if CommandType1 == CommandType2 or CommandType1 == "*" or CommandType2 == "*":
1993 if Attr1 == Attr2 or Attr1 == "*" or Attr2 == "*":
1994 if self.CalculatePriorityValue(NowKey) > self.CalculatePriorityValue(NextKey):
1995 if Options.get((self.BuildRuleFamily, NextKey)) != None:
1996 Options.pop((self.BuildRuleFamily, NextKey))
1997 else:
1998 if Options.get((self.BuildRuleFamily, NowKey)) != None:
1999 Options.pop((self.BuildRuleFamily, NowKey))
2000
2001
2002 for Key in Options:
2003 if ModuleStyle != None and len (Key) > 2:
2004 # Check Module style is EDK or EDKII.
2005 # Only append build option for the matched style module.
2006 if ModuleStyle == EDK_NAME and Key[2] != EDK_NAME:
2007 continue
2008 elif ModuleStyle == EDKII_NAME and Key[2] != EDKII_NAME:
2009 continue
2010 Family = Key[0]
2011 Target, Tag, Arch, Tool, Attr = Key[1].split("_")
2012 # if tool chain family doesn't match, skip it
2013 if Tool in self.ToolDefinition and Family != "":
2014 FamilyIsNull = False
2015 if self.ToolDefinition[Tool].get(TAB_TOD_DEFINES_BUILDRULEFAMILY, "") != "":
2016 if Family != self.ToolDefinition[Tool][TAB_TOD_DEFINES_BUILDRULEFAMILY]:
2017 continue
2018 elif Family != self.ToolDefinition[Tool][TAB_TOD_DEFINES_FAMILY]:
2019 continue
2020 FamilyMatch = True
2021 # expand any wildcard
2022 if Target == "*" or Target == self.BuildTarget:
2023 if Tag == "*" or Tag == self.ToolChain:
2024 if Arch == "*" or Arch == self.Arch:
2025 if Tool not in BuildOptions:
2026 BuildOptions[Tool] = {}
2027 if Attr != "FLAGS" or Attr not in BuildOptions[Tool]:
2028 BuildOptions[Tool][Attr] = Options[Key]
2029 else:
2030 # append options for the same tool
2031 BuildOptions[Tool][Attr] += " " + Options[Key]
2032 # Build Option Family has been checked, which need't to be checked again for family.
2033 if FamilyMatch or FamilyIsNull:
2034 return BuildOptions
2035
2036 for Key in Options:
2037 if ModuleStyle != None and len (Key) > 2:
2038 # Check Module style is EDK or EDKII.
2039 # Only append build option for the matched style module.
2040 if ModuleStyle == EDK_NAME and Key[2] != EDK_NAME:
2041 continue
2042 elif ModuleStyle == EDKII_NAME and Key[2] != EDKII_NAME:
2043 continue
2044 Family = Key[0]
2045 Target, Tag, Arch, Tool, Attr = Key[1].split("_")
2046 # if tool chain family doesn't match, skip it
2047 if Tool not in self.ToolDefinition or Family =="":
2048 continue
2049 # option has been added before
2050 if Family != self.ToolDefinition[Tool][TAB_TOD_DEFINES_FAMILY]:
2051 continue
2052
2053 # expand any wildcard
2054 if Target == "*" or Target == self.BuildTarget:
2055 if Tag == "*" or Tag == self.ToolChain:
2056 if Arch == "*" or Arch == self.Arch:
2057 if Tool not in BuildOptions:
2058 BuildOptions[Tool] = {}
2059 if Attr != "FLAGS" or Attr not in BuildOptions[Tool]:
2060 BuildOptions[Tool][Attr] = Options[Key]
2061 else:
2062 # append options for the same tool
2063 BuildOptions[Tool][Attr] += " " + Options[Key]
2064 return BuildOptions
2065
2066 ## Append build options in platform to a module
2067 #
2068 # @param Module The module to which the build options will be appened
2069 #
2070 # @retval options The options appended with build options in platform
2071 #
2072 def ApplyBuildOption(self, Module):
2073 # Get the different options for the different style module
2074 if Module.AutoGenVersion < 0x00010005:
2075 PlatformOptions = self.EdkBuildOption
2076 else:
2077 PlatformOptions = self.EdkIIBuildOption
2078 ModuleOptions = self._ExpandBuildOption(Module.BuildOptions)
2079 if Module in self.Platform.Modules:
2080 PlatformModule = self.Platform.Modules[str(Module)]
2081 PlatformModuleOptions = self._ExpandBuildOption(PlatformModule.BuildOptions)
2082 else:
2083 PlatformModuleOptions = {}
2084
2085 AllTools = set(ModuleOptions.keys() + PlatformOptions.keys() + PlatformModuleOptions.keys() + self.ToolDefinition.keys())
2086 BuildOptions = {}
2087 for Tool in AllTools:
2088 if Tool not in BuildOptions:
2089 BuildOptions[Tool] = {}
2090
2091 for Options in [self.ToolDefinition, ModuleOptions, PlatformOptions, PlatformModuleOptions]:
2092 if Tool not in Options:
2093 continue
2094 for Attr in Options[Tool]:
2095 Value = Options[Tool][Attr]
2096 if Attr not in BuildOptions[Tool]:
2097 BuildOptions[Tool][Attr] = ""
2098 # check if override is indicated
2099 if Value.startswith('='):
2100 BuildOptions[Tool][Attr] = Value[1:]
2101 else:
2102 BuildOptions[Tool][Attr] += " " + Value
2103 if Module.AutoGenVersion < 0x00010005 and self.Workspace.UniFlag != None:
2104 #
2105 # Override UNI flag only for EDK module.
2106 #
2107 if 'BUILD' not in BuildOptions:
2108 BuildOptions['BUILD'] = {}
2109 BuildOptions['BUILD']['FLAGS'] = self.Workspace.UniFlag
2110 return BuildOptions
2111
2112 Platform = property(_GetPlatform)
2113 Name = property(_GetName)
2114 Guid = property(_GetGuid)
2115 Version = property(_GetVersion)
2116
2117 OutputDir = property(_GetOutputDir)
2118 BuildDir = property(_GetBuildDir)
2119 MakeFileDir = property(_GetMakeFileDir)
2120 FdfFile = property(_GetFdfFile)
2121
2122 PcdTokenNumber = property(_GetPcdTokenNumbers) # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber
2123 DynamicPcdList = property(_GetDynamicPcdList) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
2124 NonDynamicPcdList = property(_GetNonDynamicPcdList) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]
2125 NonDynamicPcdDict = property(_GetNonDynamicPcdDict)
2126 PackageList = property(_GetPackageList)
2127
2128 ToolDefinition = property(_GetToolDefinition) # toolcode : tool path
2129 ToolDefinitionFile = property(_GetToolDefFile) # toolcode : lib path
2130 ToolChainFamily = property(_GetToolChainFamily)
2131 BuildRuleFamily = property(_GetBuildRuleFamily)
2132 BuildOption = property(_GetBuildOptions) # toolcode : option
2133 EdkBuildOption = property(_GetEdkBuildOptions) # edktoolcode : option
2134 EdkIIBuildOption = property(_GetEdkIIBuildOptions) # edkiitoolcode : option
2135
2136 BuildCommand = property(_GetBuildCommand)
2137 BuildRule = property(_GetBuildRule)
2138 ModuleAutoGenList = property(_GetModuleAutoGenList)
2139 LibraryAutoGenList = property(_GetLibraryAutoGenList)
2140 GenFdsCommand = property(_GenFdsCommand)
2141
2142 ## ModuleAutoGen class
2143 #
2144 # This class encapsules the AutoGen behaviors for the build tools. In addition to
2145 # the generation of AutoGen.h and AutoGen.c, it will generate *.depex file according
2146 # to the [depex] section in module's inf file.
2147 #
2148 class ModuleAutoGen(AutoGen):
2149 ## The real constructor of ModuleAutoGen
2150 #
2151 # This method is not supposed to be called by users of ModuleAutoGen. It's
2152 # only used by factory method __new__() to do real initialization work for an
2153 # object of ModuleAutoGen
2154 #
2155 # @param Workspace EdkIIWorkspaceBuild object
2156 # @param ModuleFile The path of module file
2157 # @param Target Build target (DEBUG, RELEASE)
2158 # @param Toolchain Name of tool chain
2159 # @param Arch The arch the module supports
2160 # @param PlatformFile Platform meta-file
2161 #
2162 def _Init(self, Workspace, ModuleFile, Target, Toolchain, Arch, PlatformFile):
2163 EdkLogger.debug(EdkLogger.DEBUG_9, "AutoGen module [%s] [%s]" % (ModuleFile, Arch))
2164 GlobalData.gProcessingFile = "%s [%s, %s, %s]" % (ModuleFile, Arch, Toolchain, Target)
2165
2166 self.Workspace = Workspace
2167 self.WorkspaceDir = Workspace.WorkspaceDir
2168
2169 self.MetaFile = ModuleFile
2170 self.PlatformInfo = PlatformAutoGen(Workspace, PlatformFile, Target, Toolchain, Arch)
2171 # check if this module is employed by active platform
2172 if not self.PlatformInfo.ValidModule(self.MetaFile):
2173 EdkLogger.verbose("Module [%s] for [%s] is not employed by active platform\n" \
2174 % (self.MetaFile, Arch))
2175 return False
2176
2177 self.SourceDir = self.MetaFile.SubDir
2178 if self.SourceDir.upper().find(self.WorkspaceDir.upper()) == 0:
2179 self.SourceDir = self.SourceDir[len(self.WorkspaceDir) + 1:]
2180
2181 self.SourceOverrideDir = None
2182 # use overrided path defined in DSC file
2183 if self.MetaFile.Key in GlobalData.gOverrideDir:
2184 self.SourceOverrideDir = GlobalData.gOverrideDir[self.MetaFile.Key]
2185
2186 self.ToolChain = Toolchain
2187 self.BuildTarget = Target
2188 self.Arch = Arch
2189 self.ToolChainFamily = self.PlatformInfo.ToolChainFamily
2190 self.BuildRuleFamily = self.PlatformInfo.BuildRuleFamily
2191
2192 self.IsMakeFileCreated = False
2193 self.IsCodeFileCreated = False
2194 self.IsAsBuiltInfCreated = False
2195 self.DepexGenerated = False
2196
2197 self.BuildDatabase = self.Workspace.BuildDatabase
2198
2199 self._Module = None
2200 self._Name = None
2201 self._Guid = None
2202 self._Version = None
2203 self._ModuleType = None
2204 self._ComponentType = None
2205 self._PcdIsDriver = None
2206 self._AutoGenVersion = None
2207 self._LibraryFlag = None
2208 self._CustomMakefile = None
2209 self._Macro = None
2210
2211 self._BuildDir = None
2212 self._OutputDir = None
2213 self._DebugDir = None
2214 self._MakeFileDir = None
2215
2216 self._IncludePathList = None
2217 self._AutoGenFileList = None
2218 self._UnicodeFileList = None
2219 self._SourceFileList = None
2220 self._ObjectFileList = None
2221 self._BinaryFileList = None
2222
2223 self._DependentPackageList = None
2224 self._DependentLibraryList = None
2225 self._LibraryAutoGenList = None
2226 self._DerivedPackageList = None
2227 self._ModulePcdList = None
2228 self._LibraryPcdList = None
2229 self._PcdComments = sdict()
2230 self._GuidList = None
2231 self._GuidsUsedByPcd = None
2232 self._GuidComments = sdict()
2233 self._ProtocolList = None
2234 self._ProtocolComments = sdict()
2235 self._PpiList = None
2236 self._PpiComments = sdict()
2237 self._DepexList = None
2238 self._DepexExpressionList = None
2239 self._BuildOption = None
2240 self._BuildOptionIncPathList = None
2241 self._BuildTargets = None
2242 self._IntroBuildTargetList = None
2243 self._FinalBuildTargetList = None
2244 self._FileTypes = None
2245 self._BuildRules = None
2246
2247 ## The Modules referenced to this Library
2248 # Only Library has this attribute
2249 self._ReferenceModules = []
2250
2251 ## Store the FixedAtBuild Pcds
2252 #
2253 self._FixedAtBuildPcds = []
2254 self.ConstPcd = {}
2255 return True
2256
2257 def __repr__(self):
2258 return "%s [%s]" % (self.MetaFile, self.Arch)
2259
2260 # Get FixedAtBuild Pcds of this Module
2261 def _GetFixedAtBuildPcds(self):
2262 if self._FixedAtBuildPcds:
2263 return self._FixedAtBuildPcds
2264 for Pcd in self.ModulePcdList:
2265 if self.IsLibrary:
2266 if not (Pcd.Pending == False and Pcd.Type == "FixedAtBuild"):
2267 continue
2268 elif Pcd.Type != "FixedAtBuild":
2269 continue
2270 if Pcd not in self._FixedAtBuildPcds:
2271 self._FixedAtBuildPcds.append(Pcd)
2272
2273 return self._FixedAtBuildPcds
2274
2275 # Macros could be used in build_rule.txt (also Makefile)
2276 def _GetMacros(self):
2277 if self._Macro == None:
2278 self._Macro = sdict()
2279 self._Macro["WORKSPACE" ] = self.WorkspaceDir
2280 self._Macro["MODULE_NAME" ] = self.Name
2281 self._Macro["MODULE_GUID" ] = self.Guid
2282 self._Macro["MODULE_VERSION" ] = self.Version
2283 self._Macro["MODULE_TYPE" ] = self.ModuleType
2284 self._Macro["MODULE_FILE" ] = str(self.MetaFile)
2285 self._Macro["MODULE_FILE_BASE_NAME" ] = self.MetaFile.BaseName
2286 self._Macro["MODULE_RELATIVE_DIR" ] = self.SourceDir
2287 self._Macro["MODULE_DIR" ] = self.SourceDir
2288
2289 self._Macro["BASE_NAME" ] = self.Name
2290
2291 self._Macro["ARCH" ] = self.Arch
2292 self._Macro["TOOLCHAIN" ] = self.ToolChain
2293 self._Macro["TOOLCHAIN_TAG" ] = self.ToolChain
2294 self._Macro["TOOL_CHAIN_TAG" ] = self.ToolChain
2295 self._Macro["TARGET" ] = self.BuildTarget
2296
2297 self._Macro["BUILD_DIR" ] = self.PlatformInfo.BuildDir
2298 self._Macro["BIN_DIR" ] = os.path.join(self.PlatformInfo.BuildDir, self.Arch)
2299 self._Macro["LIB_DIR" ] = os.path.join(self.PlatformInfo.BuildDir, self.Arch)
2300 self._Macro["MODULE_BUILD_DIR" ] = self.BuildDir
2301 self._Macro["OUTPUT_DIR" ] = self.OutputDir
2302 self._Macro["DEBUG_DIR" ] = self.DebugDir
2303 return self._Macro
2304
2305 ## Return the module build data object
2306 def _GetModule(self):
2307 if self._Module == None:
2308 self._Module = self.Workspace.BuildDatabase[self.MetaFile, self.Arch, self.BuildTarget, self.ToolChain]
2309 return self._Module
2310
2311 ## Return the module name
2312 def _GetBaseName(self):
2313 return self.Module.BaseName
2314
2315 ## Return the module DxsFile if exist
2316 def _GetDxsFile(self):
2317 return self.Module.DxsFile
2318
2319 ## Return the module SourceOverridePath
2320 def _GetSourceOverridePath(self):
2321 return self.Module.SourceOverridePath
2322
2323 ## Return the module meta-file GUID
2324 def _GetGuid(self):
2325 #
2326 # To build same module more than once, the module path with FILE_GUID overridden has
2327 # the file name FILE_GUIDmodule.inf, but the relative path (self.MetaFile.File) is the realy path
2328 # in DSC. The overridden GUID can be retrieved from file name
2329 #
2330 if os.path.basename(self.MetaFile.File) != os.path.basename(self.MetaFile.Path):
2331 #
2332 # Length of GUID is 36
2333 #
2334 return os.path.basename(self.MetaFile.Path)[:36]
2335 return self.Module.Guid
2336
2337 ## Return the module version
2338 def _GetVersion(self):
2339 return self.Module.Version
2340
2341 ## Return the module type
2342 def _GetModuleType(self):
2343 return self.Module.ModuleType
2344
2345 ## Return the component type (for Edk.x style of module)
2346 def _GetComponentType(self):
2347 return self.Module.ComponentType
2348
2349 ## Return the build type
2350 def _GetBuildType(self):
2351 return self.Module.BuildType
2352
2353 ## Return the PCD_IS_DRIVER setting
2354 def _GetPcdIsDriver(self):
2355 return self.Module.PcdIsDriver
2356
2357 ## Return the autogen version, i.e. module meta-file version
2358 def _GetAutoGenVersion(self):
2359 return self.Module.AutoGenVersion
2360
2361 ## Check if the module is library or not
2362 def _IsLibrary(self):
2363 if self._LibraryFlag == None:
2364 if self.Module.LibraryClass != None and self.Module.LibraryClass != []:
2365 self._LibraryFlag = True
2366 else:
2367 self._LibraryFlag = False
2368 return self._LibraryFlag
2369
2370 ## Check if the module is binary module or not
2371 def _IsBinaryModule(self):
2372 return self.Module.IsBinaryModule
2373
2374 ## Return the directory to store intermediate files of the module
2375 def _GetBuildDir(self):
2376 if self._BuildDir == None:
2377 self._BuildDir = path.join(
2378 self.PlatformInfo.BuildDir,
2379 self.Arch,
2380 self.SourceDir,
2381 self.MetaFile.BaseName
2382 )
2383 CreateDirectory(self._BuildDir)
2384 return self._BuildDir
2385
2386 ## Return the directory to store the intermediate object files of the mdoule
2387 def _GetOutputDir(self):
2388 if self._OutputDir == None:
2389 self._OutputDir = path.join(self.BuildDir, "OUTPUT")
2390 CreateDirectory(self._OutputDir)
2391 return self._OutputDir
2392
2393 ## Return the directory to store auto-gened source files of the mdoule
2394 def _GetDebugDir(self):
2395 if self._DebugDir == None:
2396 self._DebugDir = path.join(self.BuildDir, "DEBUG")
2397 CreateDirectory(self._DebugDir)
2398 return self._DebugDir
2399
2400 ## Return the path of custom file
2401 def _GetCustomMakefile(self):
2402 if self._CustomMakefile == None:
2403 self._CustomMakefile = {}
2404 for Type in self.Module.CustomMakefile:
2405 if Type in gMakeTypeMap:
2406 MakeType = gMakeTypeMap[Type]
2407 else:
2408 MakeType = 'nmake'
2409 if self.SourceOverrideDir != None:
2410 File = os.path.join(self.SourceOverrideDir, self.Module.CustomMakefile[Type])
2411 if not os.path.exists(File):
2412 File = os.path.join(self.SourceDir, self.Module.CustomMakefile[Type])
2413 else:
2414 File = os.path.join(self.SourceDir, self.Module.CustomMakefile[Type])
2415 self._CustomMakefile[MakeType] = File
2416 return self._CustomMakefile
2417
2418 ## Return the directory of the makefile
2419 #
2420 # @retval string The directory string of module's makefile
2421 #
2422 def _GetMakeFileDir(self):
2423 return self.BuildDir
2424
2425 ## Return build command string
2426 #
2427 # @retval string Build command string
2428 #
2429 def _GetBuildCommand(self):
2430 return self.PlatformInfo.BuildCommand
2431
2432 ## Get object list of all packages the module and its dependent libraries belong to
2433 #
2434 # @retval list The list of package object
2435 #
2436 def _GetDerivedPackageList(self):
2437 PackageList = []
2438 for M in [self.Module] + self.DependentLibraryList:
2439 for Package in M.Packages:
2440 if Package in PackageList:
2441 continue
2442 PackageList.append(Package)
2443 return PackageList
2444
2445 ## Get the depex string
2446 #
2447 # @return : a string contain all depex expresion.
2448 def _GetDepexExpresionString(self):
2449 DepexStr = ''
2450 DepexList = []
2451 ## DPX_SOURCE IN Define section.
2452 if self.Module.DxsFile:
2453 return DepexStr
2454 for M in [self.Module] + self.DependentLibraryList:
2455 Filename = M.MetaFile.Path
2456 InfObj = InfSectionParser.InfSectionParser(Filename)
2457 DepexExpresionList = InfObj.GetDepexExpresionList()
2458 for DepexExpresion in DepexExpresionList:
2459 for key in DepexExpresion.keys():
2460 Arch, ModuleType = key
2461 # the type of build module is USER_DEFINED.
2462 # All different DEPEX section tags would be copied into the As Built INF file
2463 # and there would be separate DEPEX section tags
2464 if self.ModuleType.upper() == SUP_MODULE_USER_DEFINED:
2465 if (Arch.upper() == self.Arch.upper()) and (ModuleType.upper() != TAB_ARCH_COMMON):
2466 DepexList.append({(Arch, ModuleType): DepexExpresion[key][:]})
2467 else:
2468 if Arch.upper() == TAB_ARCH_COMMON or \
2469 (Arch.upper() == self.Arch.upper() and \
2470 ModuleType.upper() in [TAB_ARCH_COMMON, self.ModuleType.upper()]):
2471 DepexList.append({(Arch, ModuleType): DepexExpresion[key][:]})
2472
2473 #the type of build module is USER_DEFINED.
2474 if self.ModuleType.upper() == SUP_MODULE_USER_DEFINED:
2475 for Depex in DepexList:
2476 for key in Depex.keys():
2477 DepexStr += '[Depex.%s.%s]\n' % key
2478 DepexStr += '\n'.join(['# '+ val for val in Depex[key]])
2479 DepexStr += '\n\n'
2480 if not DepexStr:
2481 return '[Depex.%s]\n' % self.Arch
2482 return DepexStr
2483
2484 #the type of build module not is USER_DEFINED.
2485 Count = 0
2486 for Depex in DepexList:
2487 Count += 1
2488 if DepexStr != '':
2489 DepexStr += ' AND '
2490 DepexStr += '('
2491 for D in Depex.values():
2492 DepexStr += ' '.join([val for val in D])
2493 Index = DepexStr.find('END')
2494 if Index > -1 and Index == len(DepexStr) - 3:
2495 DepexStr = DepexStr[:-3]
2496 DepexStr = DepexStr.strip()
2497 DepexStr += ')'
2498 if Count == 1:
2499 DepexStr = DepexStr.lstrip('(').rstrip(')').strip()
2500 if not DepexStr:
2501 return '[Depex.%s]\n' % self.Arch
2502 return '[Depex.%s]\n# ' % self.Arch + DepexStr
2503
2504 ## Merge dependency expression
2505 #
2506 # @retval list The token list of the dependency expression after parsed
2507 #
2508 def _GetDepexTokenList(self):
2509 if self._DepexList == None:
2510 self._DepexList = {}
2511 if self.DxsFile or self.IsLibrary or TAB_DEPENDENCY_EXPRESSION_FILE in self.FileTypes:
2512 return self._DepexList
2513
2514 self._DepexList[self.ModuleType] = []
2515
2516 for ModuleType in self._DepexList:
2517 DepexList = self._DepexList[ModuleType]
2518 #
2519 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion
2520 #
2521 for M in [self.Module] + self.DependentLibraryList:
2522 Inherited = False
2523 for D in M.Depex[self.Arch, ModuleType]:
2524 if DepexList != []:
2525 DepexList.append('AND')
2526 DepexList.append('(')
2527 DepexList.extend(D)
2528 if DepexList[-1] == 'END': # no need of a END at this time
2529 DepexList.pop()
2530 DepexList.append(')')
2531 Inherited = True
2532 if Inherited:
2533 EdkLogger.verbose("DEPEX[%s] (+%s) = %s" % (self.Name, M.BaseName, DepexList))
2534 if 'BEFORE' in DepexList or 'AFTER' in DepexList:
2535 break
2536 if len(DepexList) > 0:
2537 EdkLogger.verbose('')
2538 return self._DepexList
2539
2540 ## Merge dependency expression
2541 #
2542 # @retval list The token list of the dependency expression after parsed
2543 #
2544 def _GetDepexExpressionTokenList(self):
2545 if self._DepexExpressionList == None:
2546 self._DepexExpressionList = {}
2547 if self.DxsFile or self.IsLibrary or TAB_DEPENDENCY_EXPRESSION_FILE in self.FileTypes:
2548 return self._DepexExpressionList
2549
2550 self._DepexExpressionList[self.ModuleType] = ''
2551
2552 for ModuleType in self._DepexExpressionList:
2553 DepexExpressionList = self._DepexExpressionList[ModuleType]
2554 #
2555 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion
2556 #
2557 for M in [self.Module] + self.DependentLibraryList:
2558 Inherited = False
2559 for D in M.DepexExpression[self.Arch, ModuleType]:
2560 if DepexExpressionList != '':
2561 DepexExpressionList += ' AND '
2562 DepexExpressionList += '('
2563 DepexExpressionList += D
2564 DepexExpressionList = DepexExpressionList.rstrip('END').strip()
2565 DepexExpressionList += ')'
2566 Inherited = True
2567 if Inherited:
2568 EdkLogger.verbose("DEPEX[%s] (+%s) = %s" % (self.Name, M.BaseName, DepexExpressionList))
2569 if 'BEFORE' in DepexExpressionList or 'AFTER' in DepexExpressionList:
2570 break
2571 if len(DepexExpressionList) > 0:
2572 EdkLogger.verbose('')
2573 self._DepexExpressionList[ModuleType] = DepexExpressionList
2574 return self._DepexExpressionList
2575
2576 ## Return the list of specification version required for the module
2577 #
2578 # @retval list The list of specification defined in module file
2579 #
2580 def _GetSpecification(self):
2581 return self.Module.Specification
2582
2583 ## Tool option for the module build
2584 #
2585 # @param PlatformInfo The object of PlatformBuildInfo
2586 # @retval dict The dict containing valid options
2587 #
2588 def _GetModuleBuildOption(self):
2589 if self._BuildOption == None:
2590 self._BuildOption = self.PlatformInfo.ApplyBuildOption(self.Module)
2591 return self._BuildOption
2592
2593 ## Get include path list from tool option for the module build
2594 #
2595 # @retval list The include path list
2596 #
2597 def _GetBuildOptionIncPathList(self):
2598 if self._BuildOptionIncPathList == None:
2599 #
2600 # Regular expression for finding Include Directories, the difference between MSFT and INTEL/GCC/RVCT
2601 # is the former use /I , the Latter used -I to specify include directories
2602 #
2603 if self.PlatformInfo.ToolChainFamily in ('MSFT'):
2604 gBuildOptIncludePattern = re.compile(r"(?:.*?)/I[ \t]*([^ ]*)", re.MULTILINE|re.DOTALL)
2605 elif self.PlatformInfo.ToolChainFamily in ('INTEL', 'GCC', 'RVCT'):
2606 gBuildOptIncludePattern = re.compile(r"(?:.*?)-I[ \t]*([^ ]*)", re.MULTILINE|re.DOTALL)
2607 else:
2608 #
2609 # New ToolChainFamily, don't known whether there is option to specify include directories
2610 #
2611 self._BuildOptionIncPathList = []
2612 return self._BuildOptionIncPathList
2613
2614 BuildOptionIncPathList = []
2615 for Tool in ('CC', 'PP', 'VFRPP', 'ASLPP', 'ASLCC', 'APP', 'ASM'):
2616 Attr = 'FLAGS'
2617 try:
2618 FlagOption = self.BuildOption[Tool][Attr]
2619 except KeyError:
2620 FlagOption = ''
2621
2622 if self.PlatformInfo.ToolChainFamily != 'RVCT':
2623 IncPathList = [NormPath(Path, self.Macros) for Path in gBuildOptIncludePattern.findall(FlagOption)]
2624 else:
2625 #
2626 # RVCT may specify a list of directory seperated by commas
2627 #
2628 IncPathList = []
2629 for Path in gBuildOptIncludePattern.findall(FlagOption):
2630 PathList = GetSplitList(Path, TAB_COMMA_SPLIT)
2631 IncPathList += [NormPath(PathEntry, self.Macros) for PathEntry in PathList]
2632
2633 #
2634 # EDK II modules must not reference header files outside of the packages they depend on or
2635 # within the module's directory tree. Report error if violation.
2636 #
2637 if self.AutoGenVersion >= 0x00010005 and len(IncPathList) > 0:
2638 for Path in IncPathList:
2639 if (Path not in self.IncludePathList) and (CommonPath([Path, self.MetaFile.Dir]) != self.MetaFile.Dir):
2640 ErrMsg = "The include directory for the EDK II module in this line is invalid %s specified in %s FLAGS '%s'" % (Path, Tool, FlagOption)
2641 EdkLogger.error("build",
2642 PARAMETER_INVALID,
2643 ExtraData = ErrMsg,
2644 File = str(self.MetaFile))
2645
2646
2647 BuildOptionIncPathList += IncPathList
2648
2649 self._BuildOptionIncPathList = BuildOptionIncPathList
2650
2651 return self._BuildOptionIncPathList
2652
2653 ## Return a list of files which can be built from source
2654 #
2655 # What kind of files can be built is determined by build rules in
2656 # $(CONF_DIRECTORY)/build_rule.txt and toolchain family.
2657 #
2658 def _GetSourceFileList(self):
2659 if self._SourceFileList == None:
2660 self._SourceFileList = []
2661 for F in self.Module.Sources:
2662 # match tool chain
2663 if F.TagName not in ("", "*", self.ToolChain):
2664 EdkLogger.debug(EdkLogger.DEBUG_9, "The toolchain [%s] for processing file [%s] is found, "
2665 "but [%s] is needed" % (F.TagName, str(F), self.ToolChain))
2666 continue
2667 # match tool chain family
2668 if F.ToolChainFamily not in ("", "*", self.ToolChainFamily):
2669 EdkLogger.debug(
2670 EdkLogger.DEBUG_0,
2671 "The file [%s] must be built by tools of [%s], " \
2672 "but current toolchain family is [%s]" \
2673 % (str(F), F.ToolChainFamily, self.ToolChainFamily))
2674 continue
2675
2676 # add the file path into search path list for file including
2677 if F.Dir not in self.IncludePathList and self.AutoGenVersion >= 0x00010005:
2678 self.IncludePathList.insert(0, F.Dir)
2679 self._SourceFileList.append(F)
2680 self._ApplyBuildRule(F, TAB_UNKNOWN_FILE)
2681 return self._SourceFileList
2682
2683 ## Return the list of unicode files
2684 def _GetUnicodeFileList(self):
2685 if self._UnicodeFileList == None:
2686 if TAB_UNICODE_FILE in self.FileTypes:
2687 self._UnicodeFileList = self.FileTypes[TAB_UNICODE_FILE]
2688 else:
2689 self._UnicodeFileList = []
2690 return self._UnicodeFileList
2691
2692 ## Return a list of files which can be built from binary
2693 #
2694 # "Build" binary files are just to copy them to build directory.
2695 #
2696 # @retval list The list of files which can be built later
2697 #
2698 def _GetBinaryFiles(self):
2699 if self._BinaryFileList == None:
2700 self._BinaryFileList = []
2701 for F in self.Module.Binaries:
2702 if F.Target not in ['COMMON', '*'] and F.Target != self.BuildTarget:
2703 continue
2704 self._BinaryFileList.append(F)
2705 self._ApplyBuildRule(F, F.Type)
2706 return self._BinaryFileList
2707
2708 def _GetBuildRules(self):
2709 if self._BuildRules == None:
2710 BuildRules = {}
2711 BuildRuleDatabase = self.PlatformInfo.BuildRule
2712 for Type in BuildRuleDatabase.FileTypeList:
2713 #first try getting build rule by BuildRuleFamily
2714 RuleObject = BuildRuleDatabase[Type, self.BuildType, self.Arch, self.BuildRuleFamily]
2715 if not RuleObject:
2716 # build type is always module type, but ...
2717 if self.ModuleType != self.BuildType:
2718 RuleObject = BuildRuleDatabase[Type, self.ModuleType, self.Arch, self.BuildRuleFamily]
2719 #second try getting build rule by ToolChainFamily
2720 if not RuleObject:
2721 RuleObject = BuildRuleDatabase[Type, self.BuildType, self.Arch, self.ToolChainFamily]
2722 if not RuleObject:
2723 # build type is always module type, but ...
2724 if self.ModuleType != self.BuildType:
2725 RuleObject = BuildRuleDatabase[Type, self.ModuleType, self.Arch, self.ToolChainFamily]
2726 if not RuleObject:
2727 continue
2728 RuleObject = RuleObject.Instantiate(self.Macros)
2729 BuildRules[Type] = RuleObject
2730 for Ext in RuleObject.SourceFileExtList:
2731 BuildRules[Ext] = RuleObject
2732 self._BuildRules = BuildRules
2733 return self._BuildRules
2734
2735 def _ApplyBuildRule(self, File, FileType):
2736 if self._BuildTargets == None:
2737 self._IntroBuildTargetList = set()
2738 self._FinalBuildTargetList = set()
2739 self._BuildTargets = {}
2740 self._FileTypes = {}
2741
2742 SubDirectory = os.path.join(self.OutputDir, File.SubDir)
2743 if not os.path.exists(SubDirectory):
2744 CreateDirectory(SubDirectory)
2745 LastTarget = None
2746 RuleChain = []
2747 SourceList = [File]
2748 Index = 0
2749 while Index < len(SourceList):
2750 Source = SourceList[Index]
2751 Index = Index + 1
2752
2753 if Source != File:
2754 CreateDirectory(Source.Dir)
2755
2756 if File.IsBinary and File == Source and self._BinaryFileList != None and File in self._BinaryFileList:
2757 # Skip all files that are not binary libraries
2758 if not self.IsLibrary:
2759 continue
2760 RuleObject = self.BuildRules[TAB_DEFAULT_BINARY_FILE]
2761 elif FileType in self.BuildRules:
2762 RuleObject = self.BuildRules[FileType]
2763 elif Source.Ext in self.BuildRules:
2764 RuleObject = self.BuildRules[Source.Ext]
2765 else:
2766 # stop at no more rules
2767 if LastTarget:
2768 self._FinalBuildTargetList.add(LastTarget)
2769 break
2770
2771 FileType = RuleObject.SourceFileType
2772 if FileType not in self._FileTypes:
2773 self._FileTypes[FileType] = set()
2774 self._FileTypes[FileType].add(Source)
2775
2776 # stop at STATIC_LIBRARY for library
2777 if self.IsLibrary and FileType == TAB_STATIC_LIBRARY:
2778 if LastTarget:
2779 self._FinalBuildTargetList.add(LastTarget)
2780 break
2781
2782 Target = RuleObject.Apply(Source)
2783 if not Target:
2784 if LastTarget:
2785 self._FinalBuildTargetList.add(LastTarget)
2786 break
2787 elif not Target.Outputs:
2788 # Only do build for target with outputs
2789 self._FinalBuildTargetList.add(Target)
2790
2791 if FileType not in self._BuildTargets:
2792 self._BuildTargets[FileType] = set()
2793 self._BuildTargets[FileType].add(Target)
2794
2795 if not Source.IsBinary and Source == File:
2796 self._IntroBuildTargetList.add(Target)
2797
2798 # to avoid cyclic rule
2799 if FileType in RuleChain:
2800 break
2801
2802 RuleChain.append(FileType)
2803 SourceList.extend(Target.Outputs)
2804 LastTarget = Target
2805 FileType = TAB_UNKNOWN_FILE
2806
2807 def _GetTargets(self):
2808 if self._BuildTargets == None:
2809 self._IntroBuildTargetList = set()
2810 self._FinalBuildTargetList = set()
2811 self._BuildTargets = {}
2812 self._FileTypes = {}
2813
2814 #TRICK: call _GetSourceFileList to apply build rule for source files
2815 if self.SourceFileList:
2816 pass
2817
2818 #TRICK: call _GetBinaryFileList to apply build rule for binary files
2819 if self.BinaryFileList:
2820 pass
2821
2822 return self._BuildTargets
2823
2824 def _GetIntroTargetList(self):
2825 self._GetTargets()
2826 return self._IntroBuildTargetList
2827
2828 def _GetFinalTargetList(self):
2829 self._GetTargets()
2830 return self._FinalBuildTargetList
2831
2832 def _GetFileTypes(self):
2833 self._GetTargets()
2834 return self._FileTypes
2835
2836 ## Get the list of package object the module depends on
2837 #
2838 # @retval list The package object list
2839 #
2840 def _GetDependentPackageList(self):
2841 return self.Module.Packages
2842
2843 ## Return the list of auto-generated code file
2844 #
2845 # @retval list The list of auto-generated file
2846 #
2847 def _GetAutoGenFileList(self):
2848 UniStringAutoGenC = True
2849 UniStringBinBuffer = StringIO()
2850 if self.BuildType == 'UEFI_HII':
2851 UniStringAutoGenC = False
2852 if self._AutoGenFileList == None:
2853 self._AutoGenFileList = {}
2854 AutoGenC = TemplateString()
2855 AutoGenH = TemplateString()
2856 StringH = TemplateString()
2857 GenC.CreateCode(self, AutoGenC, AutoGenH, StringH, UniStringAutoGenC, UniStringBinBuffer)
2858 #
2859 # AutoGen.c is generated if there are library classes in inf, or there are object files
2860 #
2861 if str(AutoGenC) != "" and (len(self.Module.LibraryClasses) > 0
2862 or TAB_OBJECT_FILE in self.FileTypes):
2863 AutoFile = PathClass(gAutoGenCodeFileName, self.DebugDir)
2864 self._AutoGenFileList[AutoFile] = str(AutoGenC)
2865 self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)
2866 if str(AutoGenH) != "":
2867 AutoFile = PathClass(gAutoGenHeaderFileName, self.DebugDir)
2868 self._AutoGenFileList[AutoFile] = str(AutoGenH)
2869 self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)
2870 if str(StringH) != "":
2871 AutoFile = PathClass(gAutoGenStringFileName % {"module_name":self.Name}, self.DebugDir)
2872 self._AutoGenFileList[AutoFile] = str(StringH)
2873 self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)
2874 if UniStringBinBuffer != None and UniStringBinBuffer.getvalue() != "":
2875 AutoFile = PathClass(gAutoGenStringFormFileName % {"module_name":self.Name}, self.OutputDir)
2876 self._AutoGenFileList[AutoFile] = UniStringBinBuffer.getvalue()
2877 AutoFile.IsBinary = True
2878 self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)
2879 if UniStringBinBuffer != None:
2880 UniStringBinBuffer.close()
2881 return self._AutoGenFileList
2882
2883 ## Return the list of library modules explicitly or implicityly used by this module
2884 def _GetLibraryList(self):
2885 if self._DependentLibraryList == None:
2886 # only merge library classes and PCD for non-library module
2887 if self.IsLibrary:
2888 self._DependentLibraryList = []
2889 else:
2890 if self.AutoGenVersion < 0x00010005:
2891 self._DependentLibraryList = self.PlatformInfo.ResolveLibraryReference(self.Module)
2892 else:
2893 self._DependentLibraryList = self.PlatformInfo.ApplyLibraryInstance(self.Module)
2894 return self._DependentLibraryList
2895
2896 @staticmethod
2897 def UpdateComments(Recver, Src):
2898 for Key in Src:
2899 if Key not in Recver:
2900 Recver[Key] = []
2901 Recver[Key].extend(Src[Key])
2902 ## Get the list of PCDs from current module
2903 #
2904 # @retval list The list of PCD
2905 #
2906 def _GetModulePcdList(self):
2907 if self._ModulePcdList == None:
2908 # apply PCD settings from platform
2909 self._ModulePcdList = self.PlatformInfo.ApplyPcdSetting(self.Module, self.Module.Pcds)
2910 self.UpdateComments(self._PcdComments, self.Module.PcdComments)
2911 return self._ModulePcdList
2912
2913 ## Get the list of PCDs from dependent libraries
2914 #
2915 # @retval list The list of PCD
2916 #
2917 def _GetLibraryPcdList(self):
2918 if self._LibraryPcdList == None:
2919 Pcds = sdict()
2920 if not self.IsLibrary:
2921 # get PCDs from dependent libraries
2922 for Library in self.DependentLibraryList:
2923 self.UpdateComments(self._PcdComments, Library.PcdComments)
2924 for Key in Library.Pcds:
2925 # skip duplicated PCDs
2926 if Key in self.Module.Pcds or Key in Pcds:
2927 continue
2928 Pcds[Key] = copy.copy(Library.Pcds[Key])
2929 # apply PCD settings from platform
2930 self._LibraryPcdList = self.PlatformInfo.ApplyPcdSetting(self.Module, Pcds)
2931 else:
2932 self._LibraryPcdList = []
2933 return self._LibraryPcdList
2934
2935 ## Get the GUID value mapping
2936 #
2937 # @retval dict The mapping between GUID cname and its value
2938 #
2939 def _GetGuidList(self):
2940 if self._GuidList == None:
2941 self._GuidList = sdict()
2942 self._GuidList.update(self.Module.Guids)
2943 for Library in self.DependentLibraryList:
2944 self._GuidList.update(Library.Guids)
2945 self.UpdateComments(self._GuidComments, Library.GuidComments)
2946 self.UpdateComments(self._GuidComments, self.Module.GuidComments)
2947 return self._GuidList
2948
2949 def GetGuidsUsedByPcd(self):
2950 if self._GuidsUsedByPcd == None:
2951 self._GuidsUsedByPcd = sdict()
2952 self._GuidsUsedByPcd.update(self.Module.GetGuidsUsedByPcd())
2953 for Library in self.DependentLibraryList:
2954 self._GuidsUsedByPcd.update(Library.GetGuidsUsedByPcd())
2955 return self._GuidsUsedByPcd
2956 ## Get the protocol value mapping
2957 #
2958 # @retval dict The mapping between protocol cname and its value
2959 #
2960 def _GetProtocolList(self):
2961 if self._ProtocolList == None:
2962 self._ProtocolList = sdict()
2963 self._ProtocolList.update(self.Module.Protocols)
2964 for Library in self.DependentLibraryList:
2965 self._ProtocolList.update(Library.Protocols)
2966 self.UpdateComments(self._ProtocolComments, Library.ProtocolComments)
2967 self.UpdateComments(self._ProtocolComments, self.Module.ProtocolComments)
2968 return self._ProtocolList
2969
2970 ## Get the PPI value mapping
2971 #
2972 # @retval dict The mapping between PPI cname and its value
2973 #
2974 def _GetPpiList(self):
2975 if self._PpiList == None:
2976 self._PpiList = sdict()
2977 self._PpiList.update(self.Module.Ppis)
2978 for Library in self.DependentLibraryList:
2979 self._PpiList.update(Library.Ppis)
2980 self.UpdateComments(self._PpiComments, Library.PpiComments)
2981 self.UpdateComments(self._PpiComments, self.Module.PpiComments)
2982 return self._PpiList
2983
2984 ## Get the list of include search path
2985 #
2986 # @retval list The list path
2987 #
2988 def _GetIncludePathList(self):
2989 if self._IncludePathList == None:
2990 self._IncludePathList = []
2991 if self.AutoGenVersion < 0x00010005:
2992 for Inc in self.Module.Includes:
2993 if Inc not in self._IncludePathList:
2994 self._IncludePathList.append(Inc)
2995 # for Edk modules
2996 Inc = path.join(Inc, self.Arch.capitalize())
2997 if os.path.exists(Inc) and Inc not in self._IncludePathList:
2998 self._IncludePathList.append(Inc)
2999 # Edk module needs to put DEBUG_DIR at the end of search path and not to use SOURCE_DIR all the time
3000 self._IncludePathList.append(self.DebugDir)
3001 else:
3002 self._IncludePathList.append(self.MetaFile.Dir)
3003 self._IncludePathList.append(self.DebugDir)
3004
3005 for Package in self.Module.Packages:
3006 PackageDir = path.join(self.WorkspaceDir, Package.MetaFile.Dir)
3007 if PackageDir not in self._IncludePathList:
3008 self._IncludePathList.append(PackageDir)
3009 for Inc in Package.Includes:
3010 if Inc not in self._IncludePathList:
3011 self._IncludePathList.append(str(Inc))
3012 return self._IncludePathList
3013
3014 ## Get HII EX PCDs which maybe used by VFR
3015 #
3016 # efivarstore used by VFR may relate with HII EX PCDs
3017 # Get the variable name and GUID from efivarstore and HII EX PCD
3018 # List the HII EX PCDs in As Built INF if both name and GUID match.
3019 #
3020 # @retval list HII EX PCDs
3021 #
3022 def _GetPcdsMaybeUsedByVfr(self):
3023 if not self.SourceFileList:
3024 return []
3025
3026 NameGuids = []
3027 for SrcFile in self.SourceFileList:
3028 if SrcFile.Ext.lower() != '.vfr':
3029 continue
3030 Vfri = os.path.join(self.OutputDir, SrcFile.BaseName + '.i')
3031 if not os.path.exists(Vfri):
3032 continue
3033 VfriFile = open(Vfri, 'r')
3034 Content = VfriFile.read()
3035 VfriFile.close()
3036 Pos = Content.find('efivarstore')
3037 while Pos != -1:
3038 #
3039 # Make sure 'efivarstore' is the start of efivarstore statement
3040 # In case of the value of 'name' (name = efivarstore) is equal to 'efivarstore'
3041 #
3042 Index = Pos - 1
3043 while Index >= 0 and Content[Index] in ' \t\r\n':
3044 Index -= 1
3045 if Index >= 0 and Content[Index] != ';':
3046 Pos = Content.find('efivarstore', Pos + len('efivarstore'))
3047 continue
3048 #
3049 # 'efivarstore' must be followed by name and guid
3050 #
3051 Name = gEfiVarStoreNamePattern.search(Content, Pos)
3052 if not Name:
3053 break
3054 Guid = gEfiVarStoreGuidPattern.search(Content, Pos)
3055 if not Guid:
3056 break
3057 NameArray = ConvertStringToByteArray('L"' + Name.group(1) + '"')
3058 NameGuids.append((NameArray, GuidStructureStringToGuidString(Guid.group(1))))
3059 Pos = Content.find('efivarstore', Name.end())
3060 if not NameGuids:
3061 return []
3062 HiiExPcds = []
3063 for Pcd in self.PlatformInfo.Platform.Pcds.values():
3064 if Pcd.Type != TAB_PCDS_DYNAMIC_EX_HII:
3065 continue
3066 for SkuName in Pcd.SkuInfoList:
3067 SkuInfo = Pcd.SkuInfoList[SkuName]
3068 Name = ConvertStringToByteArray(SkuInfo.VariableName)
3069 Value = GuidValue(SkuInfo.VariableGuid, self.PlatformInfo.PackageList)
3070 if not Value:
3071 continue
3072 Guid = GuidStructureStringToGuidString(Value)
3073 if (Name, Guid) in NameGuids and Pcd not in HiiExPcds:
3074 HiiExPcds.append(Pcd)
3075 break
3076
3077 return HiiExPcds
3078
3079 ## Create AsBuilt INF file the module
3080 #
3081 def CreateAsBuiltInf(self):
3082 if self.IsAsBuiltInfCreated:
3083 return
3084
3085 # Skip the following code for EDK I inf
3086 if self.AutoGenVersion < 0x00010005:
3087 return
3088
3089 # Skip the following code for libraries
3090 if self.IsLibrary:
3091 return
3092
3093 # Skip the following code for modules with no source files
3094 if self.SourceFileList == None or self.SourceFileList == []:
3095 return
3096
3097 # Skip the following code for modules without any binary files
3098 if self.BinaryFileList <> None and self.BinaryFileList <> []:
3099 return
3100
3101 ### TODO: How to handles mixed source and binary modules
3102
3103 # Find all DynamicEx and PatchableInModule PCDs used by this module and dependent libraries
3104 # Also find all packages that the DynamicEx PCDs depend on
3105 Pcds = []
3106 PatchablePcds = {}
3107 Packages = []
3108 PcdCheckList = []
3109 PcdTokenSpaceList = []
3110 for Pcd in self.ModulePcdList + self.LibraryPcdList:
3111 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:
3112 PatchablePcds[Pcd.TokenCName] = Pcd
3113 PcdCheckList.append((Pcd.TokenCName, Pcd.TokenSpaceGuidCName, 'PatchableInModule'))
3114 elif Pcd.Type in GenC.gDynamicExPcd:
3115 if Pcd not in Pcds:
3116 Pcds += [Pcd]
3117 PcdCheckList.append((Pcd.TokenCName, Pcd.TokenSpaceGuidCName, 'DynamicEx'))
3118 PcdCheckList.append((Pcd.TokenCName, Pcd.TokenSpaceGuidCName, 'Dynamic'))
3119 PcdTokenSpaceList.append(Pcd.TokenSpaceGuidCName)
3120 GuidList = sdict()
3121 GuidList.update(self.GuidList)
3122 for TokenSpace in self.GetGuidsUsedByPcd():
3123 # If token space is not referred by patch PCD or Ex PCD, remove the GUID from GUID list
3124 # The GUIDs in GUIDs section should really be the GUIDs in source INF or referred by Ex an patch PCDs
3125 if TokenSpace not in PcdTokenSpaceList and TokenSpace in GuidList:
3126 GuidList.pop(TokenSpace)
3127 CheckList = (GuidList, self.PpiList, self.ProtocolList, PcdCheckList)
3128 for Package in self.DerivedPackageList:
3129 if Package in Packages:
3130 continue
3131 BeChecked = (Package.Guids, Package.Ppis, Package.Protocols, Package.Pcds)
3132 Found = False
3133 for Index in range(len(BeChecked)):
3134 for Item in CheckList[Index]:
3135 if Item in BeChecked[Index]:
3136 Packages += [Package]
3137 Found = True
3138 break
3139 if Found: break
3140
3141 VfrPcds = self._GetPcdsMaybeUsedByVfr()
3142 for Pkg in self.PlatformInfo.PackageList:
3143 if Pkg in Packages:
3144 continue
3145 for VfrPcd in VfrPcds:
3146 if ((VfrPcd.TokenCName, VfrPcd.TokenSpaceGuidCName, 'DynamicEx') in Pkg.Pcds or
3147 (VfrPcd.TokenCName, VfrPcd.TokenSpaceGuidCName, 'Dynamic') in Pkg.Pcds):
3148 Packages += [Pkg]
3149 break
3150
3151 ModuleType = self.ModuleType
3152 if ModuleType == 'UEFI_DRIVER' and self.DepexGenerated:
3153 ModuleType = 'DXE_DRIVER'
3154
3155 DriverType = ''
3156 if self.PcdIsDriver != '':
3157 DriverType = self.PcdIsDriver
3158
3159 Guid = self.Guid
3160 MDefs = self.Module.Defines
3161
3162 AsBuiltInfDict = {
3163 'module_name' : self.Name,
3164 'module_guid' : Guid,
3165 'module_module_type' : ModuleType,
3166 'module_version_string' : [MDefs['VERSION_STRING']] if 'VERSION_STRING' in MDefs else [],
3167 'pcd_is_driver_string' : [],
3168 'module_uefi_specification_version' : [],
3169 'module_pi_specification_version' : [],
3170 'module_entry_point' : self.Module.ModuleEntryPointList,
3171 'module_unload_image' : self.Module.ModuleUnloadImageList,
3172 'module_constructor' : self.Module.ConstructorList,
3173 'module_destructor' : self.Module.DestructorList,
3174 'module_shadow' : [MDefs['SHADOW']] if 'SHADOW' in MDefs else [],
3175 'module_pci_vendor_id' : [MDefs['PCI_VENDOR_ID']] if 'PCI_VENDOR_ID' in MDefs else [],
3176 'module_pci_device_id' : [MDefs['PCI_DEVICE_ID']] if 'PCI_DEVICE_ID' in MDefs else [],
3177 'module_pci_class_code' : [MDefs['PCI_CLASS_CODE']] if 'PCI_CLASS_CODE' in MDefs else [],
3178 'module_pci_revision' : [MDefs['PCI_REVISION']] if 'PCI_REVISION' in MDefs else [],
3179 'module_build_number' : [MDefs['BUILD_NUMBER']] if 'BUILD_NUMBER' in MDefs else [],
3180 'module_spec' : [MDefs['SPEC']] if 'SPEC' in MDefs else [],
3181 'module_uefi_hii_resource_section' : [MDefs['UEFI_HII_RESOURCE_SECTION']] if 'UEFI_HII_RESOURCE_SECTION' in MDefs else [],
3182 'module_uni_file' : [MDefs['MODULE_UNI_FILE']] if 'MODULE_UNI_FILE' in MDefs else [],
3183 'module_arch' : self.Arch,
3184 'package_item' : ['%s' % (Package.MetaFile.File.replace('\\','/')) for Package in Packages],
3185 'binary_item' : [],
3186 'patchablepcd_item' : [],
3187 'pcd_item' : [],
3188 'protocol_item' : [],
3189 'ppi_item' : [],
3190 'guid_item' : [],
3191 'flags_item' : [],
3192 'libraryclasses_item' : []
3193 }
3194
3195 if self.AutoGenVersion > int(gInfSpecVersion, 0):
3196 AsBuiltInfDict['module_inf_version'] = '0x%08x' % self.AutoGenVersion
3197 else:
3198 AsBuiltInfDict['module_inf_version'] = gInfSpecVersion
3199
3200 if DriverType:
3201 AsBuiltInfDict['pcd_is_driver_string'] += [DriverType]
3202
3203 if 'UEFI_SPECIFICATION_VERSION' in self.Specification:
3204 AsBuiltInfDict['module_uefi_specification_version'] += [self.Specification['UEFI_SPECIFICATION_VERSION']]
3205 if 'PI_SPECIFICATION_VERSION' in self.Specification:
3206 AsBuiltInfDict['module_pi_specification_version'] += [self.Specification['PI_SPECIFICATION_VERSION']]
3207
3208 OutputDir = self.OutputDir.replace('\\','/').strip('/')
3209 if self.ModuleType in ['BASE', 'USER_DEFINED']:
3210 for Item in self.CodaTargetList:
3211 File = Item.Target.Path.replace('\\','/').strip('/').replace(OutputDir,'').strip('/')
3212 if Item.Target.Ext.lower() == '.aml':
3213 AsBuiltInfDict['binary_item'] += ['ASL|' + File]
3214 elif Item.Target.Ext.lower() == '.acpi':
3215 AsBuiltInfDict['binary_item'] += ['ACPI|' + File]
3216 else:
3217 AsBuiltInfDict['binary_item'] += ['BIN|' + File]
3218 else:
3219 for Item in self.CodaTargetList:
3220 File = Item.Target.Path.replace('\\','/').strip('/').replace(OutputDir,'').strip('/')
3221 if Item.Target.Ext.lower() == '.efi':
3222 AsBuiltInfDict['binary_item'] += ['PE32|' + self.Name + '.efi']
3223 else:
3224 AsBuiltInfDict['binary_item'] += ['BIN|' + File]
3225 if self.DepexGenerated:
3226 if self.ModuleType in ['PEIM']:
3227 AsBuiltInfDict['binary_item'] += ['PEI_DEPEX|' + self.Name + '.depex']
3228 if self.ModuleType in ['DXE_DRIVER','DXE_RUNTIME_DRIVER','DXE_SAL_DRIVER','UEFI_DRIVER']:
3229 AsBuiltInfDict['binary_item'] += ['DXE_DEPEX|' + self.Name + '.depex']
3230 if self.ModuleType in ['DXE_SMM_DRIVER']:
3231 AsBuiltInfDict['binary_item'] += ['SMM_DEPEX|' + self.Name + '.depex']
3232
3233 for Root, Dirs, Files in os.walk(OutputDir):
3234 for File in Files:
3235 if File.lower().endswith('.pdb'):
3236 AsBuiltInfDict['binary_item'] += ['DISPOSABLE|' + File]
3237 HeaderComments = self.Module.HeaderComments
3238 StartPos = 0
3239 for Index in range(len(HeaderComments)):
3240 if HeaderComments[Index].find('@BinaryHeader') != -1:
3241 HeaderComments[Index] = HeaderComments[Index].replace('@BinaryHeader', '@file')
3242 StartPos = Index
3243 break
3244 AsBuiltInfDict['header_comments'] = '\n'.join(HeaderComments[StartPos:]).replace(':#', '://')
3245 AsBuiltInfDict['tail_comments'] = '\n'.join(self.Module.TailComments)
3246
3247 GenList = [
3248 (self.ProtocolList, self._ProtocolComments, 'protocol_item'),
3249 (self.PpiList, self._PpiComments, 'ppi_item'),
3250 (GuidList, self._GuidComments, 'guid_item')
3251 ]
3252 for Item in GenList:
3253 for CName in Item[0]:
3254 Comments = ''
3255 if CName in Item[1]:
3256 Comments = '\n '.join(Item[1][CName])
3257 Entry = CName
3258 if Comments:
3259 Entry = Comments + '\n ' + CName
3260 AsBuiltInfDict[Item[2]].append(Entry)
3261 PatchList = parsePcdInfoFromMapFile(
3262 os.path.join(self.OutputDir, self.Name + '.map'),
3263 os.path.join(self.OutputDir, self.Name + '.efi')
3264 )
3265 if PatchList:
3266 for PatchPcd in PatchList:
3267 if PatchPcd[0] not in PatchablePcds:
3268 continue
3269 Pcd = PatchablePcds[PatchPcd[0]]
3270 PcdValue = ''
3271 if Pcd.DatumType != 'VOID*':
3272 HexFormat = '0x%02x'
3273 if Pcd.DatumType == 'UINT16':
3274 HexFormat = '0x%04x'
3275 elif Pcd.DatumType == 'UINT32':
3276 HexFormat = '0x%08x'
3277 elif Pcd.DatumType == 'UINT64':
3278 HexFormat = '0x%016x'
3279 PcdValue = HexFormat % int(Pcd.DefaultValue, 0)
3280 else:
3281 if Pcd.MaxDatumSize == None or Pcd.MaxDatumSize == '':
3282 EdkLogger.error("build", AUTOGEN_ERROR,
3283 "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)
3284 )
3285 ArraySize = int(Pcd.MaxDatumSize, 0)
3286 PcdValue = Pcd.DefaultValue
3287 if PcdValue[0] != '{':
3288 Unicode = False
3289 if PcdValue[0] == 'L':
3290 Unicode = True
3291 PcdValue = PcdValue.lstrip('L')
3292 PcdValue = eval(PcdValue)
3293 NewValue = '{'
3294 for Index in range(0, len(PcdValue)):
3295 if Unicode:
3296 CharVal = ord(PcdValue[Index])
3297 NewValue = NewValue + '0x%02x' % (CharVal & 0x00FF) + ', ' \
3298 + '0x%02x' % (CharVal >> 8) + ', '
3299 else:
3300 NewValue = NewValue + '0x%02x' % (ord(PcdValue[Index]) % 0x100) + ', '
3301 Padding = '0x00, '
3302 if Unicode:
3303 Padding = Padding * 2
3304 ArraySize = ArraySize / 2
3305 if ArraySize < (len(PcdValue) + 1):
3306 EdkLogger.error("build", AUTOGEN_ERROR,
3307 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)
3308 )
3309 if ArraySize > len(PcdValue) + 1:
3310 NewValue = NewValue + Padding * (ArraySize - len(PcdValue) - 1)
3311 PcdValue = NewValue + Padding.strip().rstrip(',') + '}'
3312 elif len(PcdValue.split(',')) <= ArraySize:
3313 PcdValue = PcdValue.rstrip('}') + ', 0x00' * (ArraySize - len(PcdValue.split(',')))
3314 PcdValue += '}'
3315 else:
3316 EdkLogger.error("build", AUTOGEN_ERROR,
3317 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)
3318 )
3319 PcdItem = '%s.%s|%s|0x%X' % \
3320 (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, PcdValue, PatchPcd[1])
3321 PcdComments = ''
3322 if (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) in self._PcdComments:
3323 PcdComments = '\n '.join(self._PcdComments[Pcd.TokenSpaceGuidCName, Pcd.TokenCName])
3324 if PcdComments:
3325 PcdItem = PcdComments + '\n ' + PcdItem
3326 AsBuiltInfDict['patchablepcd_item'].append(PcdItem)
3327
3328 HiiPcds = []
3329 for Pcd in Pcds + VfrPcds:
3330 PcdComments = ''
3331 PcdCommentList = []
3332 HiiInfo = ''
3333 SkuId = ''
3334 if Pcd.Type == TAB_PCDS_DYNAMIC_EX_HII:
3335 for SkuName in Pcd.SkuInfoList:
3336 SkuInfo = Pcd.SkuInfoList[SkuName]
3337 SkuId = SkuInfo.SkuId
3338 HiiInfo = '## %s|%s|%s' % (SkuInfo.VariableName, SkuInfo.VariableGuid, SkuInfo.VariableOffset)
3339 break
3340 if SkuId:
3341 #
3342 # Don't generate duplicated HII PCD
3343 #
3344 if (SkuId, Pcd.TokenSpaceGuidCName, Pcd.TokenCName) in HiiPcds:
3345 continue
3346 else:
3347 HiiPcds.append((SkuId, Pcd.TokenSpaceGuidCName, Pcd.TokenCName))
3348 if (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) in self._PcdComments:
3349 PcdCommentList = self._PcdComments[Pcd.TokenSpaceGuidCName, Pcd.TokenCName][:]
3350 if HiiInfo:
3351 UsageIndex = -1
3352 UsageStr = ''
3353 for Index, Comment in enumerate(PcdCommentList):
3354 for Usage in UsageList:
3355 if Comment.find(Usage) != -1:
3356 UsageStr = Usage
3357 UsageIndex = Index
3358 break
3359 if UsageIndex != -1:
3360 PcdCommentList[UsageIndex] = '## %s %s %s' % (UsageStr, HiiInfo, PcdCommentList[UsageIndex].replace(UsageStr, ''))
3361 else:
3362 PcdCommentList.append('## UNDEFINED ' + HiiInfo)
3363 PcdComments = '\n '.join(PcdCommentList)
3364 PcdEntry = Pcd.TokenSpaceGuidCName + '.' + Pcd.TokenCName
3365 if PcdComments:
3366 PcdEntry = PcdComments + '\n ' + PcdEntry
3367 AsBuiltInfDict['pcd_item'] += [PcdEntry]
3368 for Item in self.BuildOption:
3369 if 'FLAGS' in self.BuildOption[Item]:
3370 AsBuiltInfDict['flags_item'] += ['%s:%s_%s_%s_%s_FLAGS = %s' % (self.ToolChainFamily, self.BuildTarget, self.ToolChain, self.Arch, Item, self.BuildOption[Item]['FLAGS'].strip())]
3371
3372 # Generated LibraryClasses section in comments.
3373 for Library in self.LibraryAutoGenList:
3374 AsBuiltInfDict['libraryclasses_item'] += [Library.MetaFile.File.replace('\\', '/')]
3375
3376 # Generated depex expression section in comments.
3377 AsBuiltInfDict['depexsection_item'] = ''
3378 DepexExpresion = self._GetDepexExpresionString()
3379 if DepexExpresion:
3380 AsBuiltInfDict['depexsection_item'] = DepexExpresion
3381
3382 AsBuiltInf = TemplateString()
3383 AsBuiltInf.Append(gAsBuiltInfHeaderString.Replace(AsBuiltInfDict))
3384
3385 SaveFileOnChange(os.path.join(self.OutputDir, self.Name + '.inf'), str(AsBuiltInf), False)
3386
3387 self.IsAsBuiltInfCreated = True
3388
3389 ## Create makefile for the module and its dependent libraries
3390 #
3391 # @param CreateLibraryMakeFile Flag indicating if or not the makefiles of
3392 # dependent libraries will be created
3393 #
3394 def CreateMakeFile(self, CreateLibraryMakeFile=True):
3395 # Ignore generating makefile when it is a binary module
3396 if self.IsBinaryModule:
3397 return
3398
3399 if self.IsMakeFileCreated:
3400 return
3401
3402 if not self.IsLibrary and CreateLibraryMakeFile:
3403 for LibraryAutoGen in self.LibraryAutoGenList:
3404 LibraryAutoGen.CreateMakeFile()
3405
3406 if len(self.CustomMakefile) == 0:
3407 Makefile = GenMake.ModuleMakefile(self)
3408 else:
3409 Makefile = GenMake.CustomMakefile(self)
3410 if Makefile.Generate():
3411 EdkLogger.debug(EdkLogger.DEBUG_9, "Generated makefile for module %s [%s]" %
3412 (self.Name, self.Arch))
3413 else:
3414 EdkLogger.debug(EdkLogger.DEBUG_9, "Skipped the generation of makefile for module %s [%s]" %
3415 (self.Name, self.Arch))
3416
3417 self.IsMakeFileCreated = True
3418
3419 def CopyBinaryFiles(self):
3420 for File in self.Module.Binaries:
3421 SrcPath = File.Path
3422 DstPath = os.path.join(self.OutputDir , os.path.basename(SrcPath))
3423 CopyLongFilePath(SrcPath, DstPath)
3424 ## Create autogen code for the module and its dependent libraries
3425 #
3426 # @param CreateLibraryCodeFile Flag indicating if or not the code of
3427 # dependent libraries will be created
3428 #
3429 def CreateCodeFile(self, CreateLibraryCodeFile=True):
3430 if self.IsCodeFileCreated:
3431 return
3432
3433 # Need to generate PcdDatabase even PcdDriver is binarymodule
3434 if self.IsBinaryModule and self.PcdIsDriver != '':
3435 CreatePcdDatabaseCode(self, TemplateString(), TemplateString())
3436 return
3437 if self.IsBinaryModule:
3438 if self.IsLibrary:
3439 self.CopyBinaryFiles()
3440 return
3441
3442 if not self.IsLibrary and CreateLibraryCodeFile:
3443 for LibraryAutoGen in self.LibraryAutoGenList:
3444 LibraryAutoGen.CreateCodeFile()
3445
3446 AutoGenList = []
3447 IgoredAutoGenList = []
3448
3449 for File in self.AutoGenFileList:
3450 if GenC.Generate(File.Path, self.AutoGenFileList[File], File.IsBinary):
3451 #Ignore Edk AutoGen.c
3452 if self.AutoGenVersion < 0x00010005 and File.Name == 'AutoGen.c':
3453 continue
3454
3455 AutoGenList.append(str(File))
3456 else:
3457 IgoredAutoGenList.append(str(File))
3458
3459 # Skip the following code for EDK I inf
3460 if self.AutoGenVersion < 0x00010005:
3461 return
3462
3463 for ModuleType in self.DepexList:
3464 # Ignore empty [depex] section or [depex] section for "USER_DEFINED" module
3465 if len(self.DepexList[ModuleType]) == 0 or ModuleType == "USER_DEFINED":
3466 continue
3467
3468 Dpx = GenDepex.DependencyExpression(self.DepexList[ModuleType], ModuleType, True)
3469 DpxFile = gAutoGenDepexFileName % {"module_name" : self.Name}
3470
3471 if len(Dpx.PostfixNotation) <> 0:
3472 self.DepexGenerated = True
3473
3474 if Dpx.Generate(path.join(self.OutputDir, DpxFile)):
3475 AutoGenList.append(str(DpxFile))
3476 else:
3477 IgoredAutoGenList.append(str(DpxFile))
3478
3479 if IgoredAutoGenList == []:
3480 EdkLogger.debug(EdkLogger.DEBUG_9, "Generated [%s] files for module %s [%s]" %
3481 (" ".join(AutoGenList), self.Name, self.Arch))
3482 elif AutoGenList == []:
3483 EdkLogger.debug(EdkLogger.DEBUG_9, "Skipped the generation of [%s] files for module %s [%s]" %
3484 (" ".join(IgoredAutoGenList), self.Name, self.Arch))
3485 else:
3486 EdkLogger.debug(EdkLogger.DEBUG_9, "Generated [%s] (skipped %s) files for module %s [%s]" %
3487 (" ".join(AutoGenList), " ".join(IgoredAutoGenList), self.Name, self.Arch))
3488
3489 self.IsCodeFileCreated = True
3490 return AutoGenList
3491
3492 ## Summarize the ModuleAutoGen objects of all libraries used by this module
3493 def _GetLibraryAutoGenList(self):
3494 if self._LibraryAutoGenList == None:
3495 self._LibraryAutoGenList = []
3496 for Library in self.DependentLibraryList:
3497 La = ModuleAutoGen(
3498 self.Workspace,
3499 Library.MetaFile,
3500 self.BuildTarget,
3501 self.ToolChain,
3502 self.Arch,
3503 self.PlatformInfo.MetaFile
3504 )
3505 if La not in self._LibraryAutoGenList:
3506 self._LibraryAutoGenList.append(La)
3507 for Lib in La.CodaTargetList:
3508 self._ApplyBuildRule(Lib.Target, TAB_UNKNOWN_FILE)
3509 return self._LibraryAutoGenList
3510
3511 Module = property(_GetModule)
3512 Name = property(_GetBaseName)
3513 Guid = property(_GetGuid)
3514 Version = property(_GetVersion)
3515 ModuleType = property(_GetModuleType)
3516 ComponentType = property(_GetComponentType)
3517 BuildType = property(_GetBuildType)
3518 PcdIsDriver = property(_GetPcdIsDriver)
3519 AutoGenVersion = property(_GetAutoGenVersion)
3520 Macros = property(_GetMacros)
3521 Specification = property(_GetSpecification)
3522
3523 IsLibrary = property(_IsLibrary)
3524 IsBinaryModule = property(_IsBinaryModule)
3525 BuildDir = property(_GetBuildDir)
3526 OutputDir = property(_GetOutputDir)
3527 DebugDir = property(_GetDebugDir)
3528 MakeFileDir = property(_GetMakeFileDir)
3529 CustomMakefile = property(_GetCustomMakefile)
3530
3531 IncludePathList = property(_GetIncludePathList)
3532 AutoGenFileList = property(_GetAutoGenFileList)
3533 UnicodeFileList = property(_GetUnicodeFileList)
3534 SourceFileList = property(_GetSourceFileList)
3535 BinaryFileList = property(_GetBinaryFiles) # FileType : [File List]
3536 Targets = property(_GetTargets)
3537 IntroTargetList = property(_GetIntroTargetList)
3538 CodaTargetList = property(_GetFinalTargetList)
3539 FileTypes = property(_GetFileTypes)
3540 BuildRules = property(_GetBuildRules)
3541
3542 DependentPackageList = property(_GetDependentPackageList)
3543 DependentLibraryList = property(_GetLibraryList)
3544 LibraryAutoGenList = property(_GetLibraryAutoGenList)
3545 DerivedPackageList = property(_GetDerivedPackageList)
3546
3547 ModulePcdList = property(_GetModulePcdList)
3548 LibraryPcdList = property(_GetLibraryPcdList)
3549 GuidList = property(_GetGuidList)
3550 ProtocolList = property(_GetProtocolList)
3551 PpiList = property(_GetPpiList)
3552 DepexList = property(_GetDepexTokenList)
3553 DxsFile = property(_GetDxsFile)
3554 DepexExpressionList = property(_GetDepexExpressionTokenList)
3555 BuildOption = property(_GetModuleBuildOption)
3556 BuildOptionIncPathList = property(_GetBuildOptionIncPathList)
3557 BuildCommand = property(_GetBuildCommand)
3558
3559 FixedAtBuildPcds = property(_GetFixedAtBuildPcds)
3560
3561 # This acts like the main() function for the script, unless it is 'import'ed into another script.
3562 if __name__ == '__main__':
3563 pass
3564