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