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