]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/AutoGen/ModuleAutoGenHelper.py
BaseTools: Enable Module Scope Structure Pcd
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / ModuleAutoGenHelper.py
CommitLineData
e8449e1d
FB
1## @file\r
2# Create makefile for MS nmake and GNU make\r
3#\r
4# Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r
5# SPDX-License-Identifier: BSD-2-Clause-Patent\r
6#\r
7from __future__ import absolute_import\r
8from Workspace.WorkspaceDatabase import WorkspaceDatabase,BuildDB\r
9from Common.caching import cached_property\r
10from AutoGen.BuildEngine import BuildRule,AutoGenReqBuildRuleVerNum\r
11from AutoGen.AutoGen import CalculatePriorityValue\r
12from Common.Misc import CheckPcdDatum,GuidValue\r
13from Common.Expression import ValueExpressionEx\r
14from Common.DataType import *\r
15from CommonDataClass.Exceptions import *\r
16from CommonDataClass.CommonClass import SkuInfoClass\r
17import Common.EdkLogger as EdkLogger\r
18from Common.BuildToolError import OPTION_CONFLICT,FORMAT_INVALID,RESOURCE_NOT_AVAILABLE\r
19from Common.MultipleWorkspace import MultipleWorkspace as mws\r
20from collections import defaultdict\r
21from Common.Misc import PathClass\r
22import os\r
23\r
24\r
25#\r
26# The priority list while override build option\r
27#\r
28PrioList = {"0x11111" : 16, # TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE (Highest)\r
29 "0x01111" : 15, # ******_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE\r
30 "0x10111" : 14, # TARGET_*********_ARCH_COMMANDTYPE_ATTRIBUTE\r
31 "0x00111" : 13, # ******_*********_ARCH_COMMANDTYPE_ATTRIBUTE\r
32 "0x11011" : 12, # TARGET_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE\r
33 "0x01011" : 11, # ******_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE\r
34 "0x10011" : 10, # TARGET_*********_****_COMMANDTYPE_ATTRIBUTE\r
35 "0x00011" : 9, # ******_*********_****_COMMANDTYPE_ATTRIBUTE\r
36 "0x11101" : 8, # TARGET_TOOLCHAIN_ARCH_***********_ATTRIBUTE\r
37 "0x01101" : 7, # ******_TOOLCHAIN_ARCH_***********_ATTRIBUTE\r
38 "0x10101" : 6, # TARGET_*********_ARCH_***********_ATTRIBUTE\r
39 "0x00101" : 5, # ******_*********_ARCH_***********_ATTRIBUTE\r
40 "0x11001" : 4, # TARGET_TOOLCHAIN_****_***********_ATTRIBUTE\r
41 "0x01001" : 3, # ******_TOOLCHAIN_****_***********_ATTRIBUTE\r
42 "0x10001" : 2, # TARGET_*********_****_***********_ATTRIBUTE\r
43 "0x00001" : 1} # ******_*********_****_***********_ATTRIBUTE (Lowest)\r
44## Base class for AutoGen\r
45#\r
46# This class just implements the cache mechanism of AutoGen objects.\r
47#\r
48class AutoGenInfo(object):\r
49 # database to maintain the objects in each child class\r
50 __ObjectCache = {} # (BuildTarget, ToolChain, ARCH, platform file): AutoGen object\r
51\r
52 ## Factory method\r
53 #\r
54 # @param Class class object of real AutoGen class\r
55 # (WorkspaceAutoGen, ModuleAutoGen or PlatformAutoGen)\r
56 # @param Workspace Workspace directory or WorkspaceAutoGen object\r
57 # @param MetaFile The path of meta file\r
58 # @param Target Build target\r
59 # @param Toolchain Tool chain name\r
60 # @param Arch Target arch\r
61 # @param *args The specific class related parameters\r
62 # @param **kwargs The specific class related dict parameters\r
63 #\r
64 @classmethod\r
65 def GetCache(cls):\r
66 return cls.__ObjectCache\r
67 def __new__(cls, Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs):\r
68 # check if the object has been created\r
69 Key = (Target, Toolchain, Arch, MetaFile)\r
70 if Key in cls.__ObjectCache:\r
71 # if it exists, just return it directly\r
72 return cls.__ObjectCache[Key]\r
73 # it didnt exist. create it, cache it, then return it\r
74 RetVal = cls.__ObjectCache[Key] = super(AutoGenInfo, cls).__new__(cls)\r
75 return RetVal\r
76\r
77\r
78 ## hash() operator\r
79 #\r
80 # The file path of platform file will be used to represent hash value of this object\r
81 #\r
82 # @retval int Hash value of the file path of platform file\r
83 #\r
84 def __hash__(self):\r
85 return hash(self.MetaFile)\r
86\r
87 ## str() operator\r
88 #\r
89 # The file path of platform file will be used to represent this object\r
90 #\r
91 # @retval string String of platform file path\r
92 #\r
93 def __str__(self):\r
94 return str(self.MetaFile)\r
95\r
96 ## "==" operator\r
97 def __eq__(self, Other):\r
98 return Other and self.MetaFile == Other\r
99\r
100 ## Expand * in build option key\r
101 #\r
102 # @param Options Options to be expanded\r
103 # @param ToolDef Use specified ToolDef instead of full version.\r
104 # This is needed during initialization to prevent\r
105 # infinite recursion betweeh BuildOptions,\r
106 # ToolDefinition, and this function.\r
107 #\r
108 # @retval options Options expanded\r
109 #\r
110 def _ExpandBuildOption(self, Options, ModuleStyle=None, ToolDef=None):\r
111 if not ToolDef:\r
112 ToolDef = self.ToolDefinition\r
113 BuildOptions = {}\r
114 FamilyMatch = False\r
115 FamilyIsNull = True\r
116\r
117 OverrideList = {}\r
118 #\r
119 # Construct a list contain the build options which need override.\r
120 #\r
121 for Key in Options:\r
122 #\r
123 # Key[0] -- tool family\r
124 # Key[1] -- TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE\r
125 #\r
126 if (Key[0] == self.BuildRuleFamily and\r
127 (ModuleStyle is None or len(Key) < 3 or (len(Key) > 2 and Key[2] == ModuleStyle))):\r
128 Target, ToolChain, Arch, CommandType, Attr = Key[1].split('_')\r
129 if (Target == self.BuildTarget or Target == TAB_STAR) and\\r
130 (ToolChain == self.ToolChain or ToolChain == TAB_STAR) and\\r
131 (Arch == self.Arch or Arch == TAB_STAR) and\\r
132 Options[Key].startswith("="):\r
133\r
134 if OverrideList.get(Key[1]) is not None:\r
135 OverrideList.pop(Key[1])\r
136 OverrideList[Key[1]] = Options[Key]\r
137\r
138 #\r
139 # Use the highest priority value.\r
140 #\r
141 if (len(OverrideList) >= 2):\r
142 KeyList = list(OverrideList.keys())\r
143 for Index in range(len(KeyList)):\r
144 NowKey = KeyList[Index]\r
145 Target1, ToolChain1, Arch1, CommandType1, Attr1 = NowKey.split("_")\r
146 for Index1 in range(len(KeyList) - Index - 1):\r
147 NextKey = KeyList[Index1 + Index + 1]\r
148 #\r
149 # Compare two Key, if one is included by another, choose the higher priority one\r
150 #\r
151 Target2, ToolChain2, Arch2, CommandType2, Attr2 = NextKey.split("_")\r
152 if (Target1 == Target2 or Target1 == TAB_STAR or Target2 == TAB_STAR) and\\r
153 (ToolChain1 == ToolChain2 or ToolChain1 == TAB_STAR or ToolChain2 == TAB_STAR) and\\r
154 (Arch1 == Arch2 or Arch1 == TAB_STAR or Arch2 == TAB_STAR) and\\r
155 (CommandType1 == CommandType2 or CommandType1 == TAB_STAR or CommandType2 == TAB_STAR) and\\r
156 (Attr1 == Attr2 or Attr1 == TAB_STAR or Attr2 == TAB_STAR):\r
157\r
158 if CalculatePriorityValue(NowKey) > CalculatePriorityValue(NextKey):\r
159 if Options.get((self.BuildRuleFamily, NextKey)) is not None:\r
160 Options.pop((self.BuildRuleFamily, NextKey))\r
161 else:\r
162 if Options.get((self.BuildRuleFamily, NowKey)) is not None:\r
163 Options.pop((self.BuildRuleFamily, NowKey))\r
164\r
165 for Key in Options:\r
166 if ModuleStyle is not None and len (Key) > 2:\r
167 # Check Module style is EDK or EDKII.\r
168 # Only append build option for the matched style module.\r
169 if ModuleStyle == EDK_NAME and Key[2] != EDK_NAME:\r
170 continue\r
171 elif ModuleStyle == EDKII_NAME and Key[2] != EDKII_NAME:\r
172 continue\r
173 Family = Key[0]\r
174 Target, Tag, Arch, Tool, Attr = Key[1].split("_")\r
175 # if tool chain family doesn't match, skip it\r
176 if Tool in ToolDef and Family != "":\r
177 FamilyIsNull = False\r
178 if ToolDef[Tool].get(TAB_TOD_DEFINES_BUILDRULEFAMILY, "") != "":\r
179 if Family != ToolDef[Tool][TAB_TOD_DEFINES_BUILDRULEFAMILY]:\r
180 continue\r
181 elif Family != ToolDef[Tool][TAB_TOD_DEFINES_FAMILY]:\r
182 continue\r
183 FamilyMatch = True\r
184 # expand any wildcard\r
185 if Target == TAB_STAR or Target == self.BuildTarget:\r
186 if Tag == TAB_STAR or Tag == self.ToolChain:\r
187 if Arch == TAB_STAR or Arch == self.Arch:\r
188 if Tool not in BuildOptions:\r
189 BuildOptions[Tool] = {}\r
190 if Attr != "FLAGS" or Attr not in BuildOptions[Tool] or Options[Key].startswith('='):\r
191 BuildOptions[Tool][Attr] = Options[Key]\r
192 else:\r
193 # append options for the same tool except PATH\r
194 if Attr != 'PATH':\r
195 BuildOptions[Tool][Attr] += " " + Options[Key]\r
196 else:\r
197 BuildOptions[Tool][Attr] = Options[Key]\r
198 # Build Option Family has been checked, which need't to be checked again for family.\r
199 if FamilyMatch or FamilyIsNull:\r
200 return BuildOptions\r
201\r
202 for Key in Options:\r
203 if ModuleStyle is not None and len (Key) > 2:\r
204 # Check Module style is EDK or EDKII.\r
205 # Only append build option for the matched style module.\r
206 if ModuleStyle == EDK_NAME and Key[2] != EDK_NAME:\r
207 continue\r
208 elif ModuleStyle == EDKII_NAME and Key[2] != EDKII_NAME:\r
209 continue\r
210 Family = Key[0]\r
211 Target, Tag, Arch, Tool, Attr = Key[1].split("_")\r
212 # if tool chain family doesn't match, skip it\r
213 if Tool not in ToolDef or Family == "":\r
214 continue\r
215 # option has been added before\r
216 if Family != ToolDef[Tool][TAB_TOD_DEFINES_FAMILY]:\r
217 continue\r
218\r
219 # expand any wildcard\r
220 if Target == TAB_STAR or Target == self.BuildTarget:\r
221 if Tag == TAB_STAR or Tag == self.ToolChain:\r
222 if Arch == TAB_STAR or Arch == self.Arch:\r
223 if Tool not in BuildOptions:\r
224 BuildOptions[Tool] = {}\r
225 if Attr != "FLAGS" or Attr not in BuildOptions[Tool] or Options[Key].startswith('='):\r
226 BuildOptions[Tool][Attr] = Options[Key]\r
227 else:\r
228 # append options for the same tool except PATH\r
229 if Attr != 'PATH':\r
230 BuildOptions[Tool][Attr] += " " + Options[Key]\r
231 else:\r
232 BuildOptions[Tool][Attr] = Options[Key]\r
233 return BuildOptions\r
234#\r
235#This class is the pruned WorkSpaceAutoGen for ModuleAutoGen in multiple thread\r
236#\r
237class WorkSpaceInfo(AutoGenInfo):\r
238 def __init__(self,Workspace, MetaFile, Target, ToolChain, Arch):\r
373298ca
FB
239 if not hasattr(self, "_Init"):\r
240 self.do_init(Workspace, MetaFile, Target, ToolChain, Arch)\r
241 self._Init = True\r
242 def do_init(self,Workspace, MetaFile, Target, ToolChain, Arch):\r
e8449e1d
FB
243 self._SrcTimeStamp = 0\r
244 self.Db = BuildDB\r
245 self.BuildDatabase = self.Db.BuildObject\r
246 self.Target = Target\r
247 self.ToolChain = ToolChain\r
248 self.WorkspaceDir = Workspace\r
249 self.ActivePlatform = MetaFile\r
250 self.ArchList = Arch\r
373298ca
FB
251 self.AutoGenObjectList = []\r
252 @property\r
253 def BuildDir(self):\r
254 return self.AutoGenObjectList[0].BuildDir\r
e8449e1d 255\r
373298ca
FB
256 @property\r
257 def Name(self):\r
258 return self.AutoGenObjectList[0].Platform.PlatformName\r
259\r
260 @property\r
261 def FlashDefinition(self):\r
262 return self.AutoGenObjectList[0].Platform.FlashDefinition\r
263 @property\r
264 def GenFdsCommandDict(self):\r
265 FdsCommandDict = self.AutoGenObjectList[0].DataPipe.Get("FdsCommandDict")\r
266 if FdsCommandDict:\r
267 return FdsCommandDict\r
268 return {}\r
269\r
270 @cached_property\r
271 def FvDir(self):\r
272 return os.path.join(self.BuildDir, TAB_FV_DIRECTORY)\r
e8449e1d
FB
273\r
274class PlatformInfo(AutoGenInfo):\r
275 def __init__(self, Workspace, MetaFile, Target, ToolChain, Arch,DataPipe):\r
373298ca
FB
276 if not hasattr(self, "_Init"):\r
277 self.do_init(Workspace, MetaFile, Target, ToolChain, Arch,DataPipe)\r
278 self._Init = True\r
279 def do_init(self,Workspace, MetaFile, Target, ToolChain, Arch,DataPipe):\r
e8449e1d
FB
280 self.Wa = Workspace\r
281 self.WorkspaceDir = self.Wa.WorkspaceDir\r
282 self.MetaFile = MetaFile\r
283 self.Arch = Arch\r
284 self.Target = Target\r
285 self.BuildTarget = Target\r
286 self.ToolChain = ToolChain\r
287 self.Platform = self.Wa.BuildDatabase[self.MetaFile, self.Arch, self.Target, self.ToolChain]\r
288\r
289 self.SourceDir = MetaFile.SubDir\r
290 self.DataPipe = DataPipe\r
291 @cached_property\r
292 def _AsBuildModuleList(self):\r
293 retVal = self.DataPipe.Get("AsBuildModuleList")\r
294 if retVal is None:\r
295 retVal = {}\r
296 return retVal\r
297\r
298 ## Test if a module is supported by the platform\r
299 #\r
300 # An error will be raised directly if the module or its arch is not supported\r
301 # by the platform or current configuration\r
302 #\r
303 def ValidModule(self, Module):\r
304 return Module in self.Platform.Modules or Module in self.Platform.LibraryInstances \\r
305 or Module in self._AsBuildModuleList\r
306\r
307 @cached_property\r
308 def ToolChainFamily(self):\r
309 retVal = self.DataPipe.Get("ToolChainFamily")\r
310 if retVal is None:\r
311 retVal = {}\r
312 return retVal\r
313\r
314 @cached_property\r
315 def BuildRuleFamily(self):\r
316 retVal = self.DataPipe.Get("BuildRuleFamily")\r
317 if retVal is None:\r
318 retVal = {}\r
319 return retVal\r
320\r
321 @cached_property\r
322 def _MbList(self):\r
323 return [self.Wa.BuildDatabase[m, self.Arch, self.BuildTarget, self.ToolChain] for m in self.Platform.Modules]\r
324\r
325 @cached_property\r
326 def PackageList(self):\r
327 RetVal = set()\r
328 for dec_file,Arch in self.DataPipe.Get("PackageList"):\r
329 RetVal.add(self.Wa.BuildDatabase[dec_file,Arch,self.BuildTarget, self.ToolChain])\r
330 return list(RetVal)\r
331\r
332 ## Return the directory to store all intermediate and final files built\r
333 @cached_property\r
334 def BuildDir(self):\r
335 if os.path.isabs(self.OutputDir):\r
336 RetVal = os.path.join(\r
337 os.path.abspath(self.OutputDir),\r
338 self.Target + "_" + self.ToolChain,\r
339 )\r
340 else:\r
341 RetVal = os.path.join(\r
342 self.WorkspaceDir,\r
343 self.OutputDir,\r
344 self.Target + "_" + self.ToolChain,\r
345 )\r
346 return RetVal\r
347\r
348 ## Return the build output directory platform specifies\r
349 @cached_property\r
350 def OutputDir(self):\r
351 return self.Platform.OutputDirectory\r
352\r
353 ## Return platform name\r
354 @cached_property\r
355 def Name(self):\r
356 return self.Platform.PlatformName\r
357\r
358 ## Return meta-file GUID\r
359 @cached_property\r
360 def Guid(self):\r
361 return self.Platform.Guid\r
362\r
363 ## Return platform version\r
364 @cached_property\r
365 def Version(self):\r
366 return self.Platform.Version\r
367\r
368 ## Return paths of tools\r
369 @cached_property\r
370 def ToolDefinition(self):\r
371 retVal = self.DataPipe.Get("TOOLDEF")\r
372 if retVal is None:\r
373 retVal = {}\r
374 return retVal\r
375\r
376 ## Return build command string\r
377 #\r
378 # @retval string Build command string\r
379 #\r
380 @cached_property\r
381 def BuildCommand(self):\r
382 retVal = self.DataPipe.Get("BuildCommand")\r
383 if retVal is None:\r
384 retVal = []\r
385 return retVal\r
386\r
387 @cached_property\r
388 def PcdTokenNumber(self):\r
389 retVal = self.DataPipe.Get("PCD_TNUM")\r
390 if retVal is None:\r
391 retVal = {}\r
392 return retVal\r
393\r
394 ## Override PCD setting (type, value, ...)\r
395 #\r
396 # @param ToPcd The PCD to be overridden\r
397 # @param FromPcd The PCD overriding from\r
398 #\r
399 def _OverridePcd(self, ToPcd, FromPcd, Module="", Msg="", Library=""):\r
400 #\r
401 # in case there's PCDs coming from FDF file, which have no type given.\r
402 # at this point, ToPcd.Type has the type found from dependent\r
403 # package\r
404 #\r
405 TokenCName = ToPcd.TokenCName\r
406 for PcdItem in self.MixedPcd:\r
407 if (ToPcd.TokenCName, ToPcd.TokenSpaceGuidCName) in self.MixedPcd[PcdItem]:\r
408 TokenCName = PcdItem[0]\r
409 break\r
410 if FromPcd is not None:\r
411 if ToPcd.Pending and FromPcd.Type:\r
412 ToPcd.Type = FromPcd.Type\r
413 elif ToPcd.Type and FromPcd.Type\\r
414 and ToPcd.Type != FromPcd.Type and ToPcd.Type in FromPcd.Type:\r
415 if ToPcd.Type.strip() == TAB_PCDS_DYNAMIC_EX:\r
416 ToPcd.Type = FromPcd.Type\r
417 elif ToPcd.Type and FromPcd.Type \\r
418 and ToPcd.Type != FromPcd.Type:\r
419 if Library:\r
420 Module = str(Module) + " 's library file (" + str(Library) + ")"\r
421 EdkLogger.error("build", OPTION_CONFLICT, "Mismatched PCD type",\r
422 ExtraData="%s.%s is used as [%s] in module %s, but as [%s] in %s."\\r
423 % (ToPcd.TokenSpaceGuidCName, TokenCName,\r
424 ToPcd.Type, Module, FromPcd.Type, Msg),\r
425 File=self.MetaFile)\r
426\r
427 if FromPcd.MaxDatumSize:\r
428 ToPcd.MaxDatumSize = FromPcd.MaxDatumSize\r
429 ToPcd.MaxSizeUserSet = FromPcd.MaxDatumSize\r
430 if FromPcd.DefaultValue:\r
431 ToPcd.DefaultValue = FromPcd.DefaultValue\r
432 if FromPcd.TokenValue:\r
433 ToPcd.TokenValue = FromPcd.TokenValue\r
434 if FromPcd.DatumType:\r
435 ToPcd.DatumType = FromPcd.DatumType\r
436 if FromPcd.SkuInfoList:\r
437 ToPcd.SkuInfoList = FromPcd.SkuInfoList\r
438 if FromPcd.UserDefinedDefaultStoresFlag:\r
439 ToPcd.UserDefinedDefaultStoresFlag = FromPcd.UserDefinedDefaultStoresFlag\r
440 # Add Flexible PCD format parse\r
441 if ToPcd.DefaultValue:\r
442 try:\r
443 ToPcd.DefaultValue = ValueExpressionEx(ToPcd.DefaultValue, ToPcd.DatumType, self._GuidDict)(True)\r
444 except BadExpression as Value:\r
445 EdkLogger.error('Parser', FORMAT_INVALID, 'PCD [%s.%s] Value "%s", %s' %(ToPcd.TokenSpaceGuidCName, ToPcd.TokenCName, ToPcd.DefaultValue, Value),\r
446 File=self.MetaFile)\r
447\r
448 # check the validation of datum\r
449 IsValid, Cause = CheckPcdDatum(ToPcd.DatumType, ToPcd.DefaultValue)\r
450 if not IsValid:\r
451 EdkLogger.error('build', FORMAT_INVALID, Cause, File=self.MetaFile,\r
452 ExtraData="%s.%s" % (ToPcd.TokenSpaceGuidCName, TokenCName))\r
453 ToPcd.validateranges = FromPcd.validateranges\r
454 ToPcd.validlists = FromPcd.validlists\r
455 ToPcd.expressions = FromPcd.expressions\r
456 ToPcd.CustomAttribute = FromPcd.CustomAttribute\r
457\r
458 if FromPcd is not None and ToPcd.DatumType == TAB_VOID and not ToPcd.MaxDatumSize:\r
459 EdkLogger.debug(EdkLogger.DEBUG_9, "No MaxDatumSize specified for PCD %s.%s" \\r
460 % (ToPcd.TokenSpaceGuidCName, TokenCName))\r
461 Value = ToPcd.DefaultValue\r
462 if not Value:\r
463 ToPcd.MaxDatumSize = '1'\r
464 elif Value[0] == 'L':\r
465 ToPcd.MaxDatumSize = str((len(Value) - 2) * 2)\r
466 elif Value[0] == '{':\r
467 ToPcd.MaxDatumSize = str(len(Value.split(',')))\r
468 else:\r
469 ToPcd.MaxDatumSize = str(len(Value) - 1)\r
470\r
471 # apply default SKU for dynamic PCDS if specified one is not available\r
472 if (ToPcd.Type in PCD_DYNAMIC_TYPE_SET or ToPcd.Type in PCD_DYNAMIC_EX_TYPE_SET) \\r
473 and not ToPcd.SkuInfoList:\r
474 if self.Platform.SkuName in self.Platform.SkuIds:\r
475 SkuName = self.Platform.SkuName\r
476 else:\r
477 SkuName = TAB_DEFAULT\r
478 ToPcd.SkuInfoList = {\r
479 SkuName : SkuInfoClass(SkuName, self.Platform.SkuIds[SkuName][0], '', '', '', '', '', ToPcd.DefaultValue)\r
480 }\r
481\r
09af9bd9 482 def ApplyPcdSetting(self, Ma, Pcds, Library=""):\r
e8449e1d 483 # for each PCD in module\r
09af9bd9 484 Module=Ma.Module\r
e8449e1d
FB
485 for Name, Guid in Pcds:\r
486 PcdInModule = Pcds[Name, Guid]\r
487 # find out the PCD setting in platform\r
488 if (Name, Guid) in self.Pcds:\r
489 PcdInPlatform = self.Pcds[Name, Guid]\r
490 else:\r
491 PcdInPlatform = None\r
492 # then override the settings if any\r
493 self._OverridePcd(PcdInModule, PcdInPlatform, Module, Msg="DSC PCD sections", Library=Library)\r
494 # resolve the VariableGuid value\r
495 for SkuId in PcdInModule.SkuInfoList:\r
496 Sku = PcdInModule.SkuInfoList[SkuId]\r
497 if Sku.VariableGuid == '': continue\r
498 Sku.VariableGuidValue = GuidValue(Sku.VariableGuid, self.PackageList, self.MetaFile.Path)\r
499 if Sku.VariableGuidValue is None:\r
500 PackageList = "\n\t".join(str(P) for P in self.PackageList)\r
501 EdkLogger.error(\r
502 'build',\r
503 RESOURCE_NOT_AVAILABLE,\r
504 "Value of GUID [%s] is not found in" % Sku.VariableGuid,\r
505 ExtraData=PackageList + "\n\t(used with %s.%s from module %s)" \\r
506 % (Guid, Name, str(Module)),\r
507 File=self.MetaFile\r
508 )\r
509\r
510 # override PCD settings with module specific setting\r
09af9bd9 511 ModuleScopePcds = self.DataPipe.Get("MOL_PCDS")\r
e8449e1d
FB
512 if Module in self.Platform.Modules:\r
513 PlatformModule = self.Platform.Modules[str(Module)]\r
09af9bd9
BF
514 PCD_DATA = ModuleScopePcds.get(Ma.Guid,{})\r
515 mPcds = {(pcd.TokenCName,pcd.TokenSpaceGuidCName): pcd for pcd in PCD_DATA}\r
516 for Key in mPcds:\r
e8449e1d
FB
517 if self.BuildOptionPcd:\r
518 for pcd in self.BuildOptionPcd:\r
519 (TokenSpaceGuidCName, TokenCName, FieldName, pcdvalue, _) = pcd\r
520 if (TokenCName, TokenSpaceGuidCName) == Key and FieldName =="":\r
521 PlatformModule.Pcds[Key].DefaultValue = pcdvalue\r
522 PlatformModule.Pcds[Key].PcdValueFromComm = pcdvalue\r
523 break\r
524 Flag = False\r
525 if Key in Pcds:\r
526 ToPcd = Pcds[Key]\r
527 Flag = True\r
528 elif Key in self.MixedPcd:\r
529 for PcdItem in self.MixedPcd[Key]:\r
530 if PcdItem in Pcds:\r
531 ToPcd = Pcds[PcdItem]\r
532 Flag = True\r
533 break\r
534 if Flag:\r
09af9bd9 535 self._OverridePcd(ToPcd, mPcds[Key], Module, Msg="DSC Components Module scoped PCD section", Library=Library)\r
e8449e1d
FB
536 # use PCD value to calculate the MaxDatumSize when it is not specified\r
537 for Name, Guid in Pcds:\r
538 Pcd = Pcds[Name, Guid]\r
539 if Pcd.DatumType == TAB_VOID and not Pcd.MaxDatumSize:\r
540 Pcd.MaxSizeUserSet = None\r
541 Value = Pcd.DefaultValue\r
542 if not Value:\r
543 Pcd.MaxDatumSize = '1'\r
544 elif Value[0] == 'L':\r
545 Pcd.MaxDatumSize = str((len(Value) - 2) * 2)\r
546 elif Value[0] == '{':\r
547 Pcd.MaxDatumSize = str(len(Value.split(',')))\r
548 else:\r
549 Pcd.MaxDatumSize = str(len(Value) - 1)\r
550 return list(Pcds.values())\r
551\r
552 @cached_property\r
553 def Pcds(self):\r
554 PlatformPcdData = self.DataPipe.Get("PLA_PCD")\r
555# for pcd in PlatformPcdData:\r
556# for skuid in pcd.SkuInfoList:\r
557# pcd.SkuInfoList[skuid] = self.CreateSkuInfoFromDict(pcd.SkuInfoList[skuid])\r
558 return {(pcddata.TokenCName,pcddata.TokenSpaceGuidCName):pcddata for pcddata in PlatformPcdData}\r
559\r
560 def CreateSkuInfoFromDict(self,SkuInfoDict):\r
561 return SkuInfoClass(\r
562 SkuInfoDict.get("SkuIdName"),\r
563 SkuInfoDict.get("SkuId"),\r
564 SkuInfoDict.get("VariableName"),\r
565 SkuInfoDict.get("VariableGuid"),\r
566 SkuInfoDict.get("VariableOffset"),\r
567 SkuInfoDict.get("HiiDefaultValue"),\r
568 SkuInfoDict.get("VpdOffset"),\r
569 SkuInfoDict.get("DefaultValue"),\r
570 SkuInfoDict.get("VariableGuidValue"),\r
571 SkuInfoDict.get("VariableAttribute",""),\r
572 SkuInfoDict.get("DefaultStore",None)\r
573 )\r
574 @cached_property\r
575 def MixedPcd(self):\r
576 return self.DataPipe.Get("MixedPcd")\r
577 @cached_property\r
578 def _GuidDict(self):\r
579 RetVal = self.DataPipe.Get("GuidDict")\r
580 if RetVal is None:\r
581 RetVal = {}\r
582 return RetVal\r
583 @cached_property\r
584 def BuildOptionPcd(self):\r
585 return self.DataPipe.Get("BuildOptPcd")\r
586 def ApplyBuildOption(self,module):\r
587 PlatformOptions = self.DataPipe.Get("PLA_BO")\r
588 ModuleBuildOptions = self.DataPipe.Get("MOL_BO")\r
589 ModuleOptionFromDsc = ModuleBuildOptions.get((module.MetaFile.File,module.MetaFile.Root))\r
590 if ModuleOptionFromDsc:\r
591 ModuleTypeOptions, PlatformModuleOptions = ModuleOptionFromDsc["ModuleTypeOptions"],ModuleOptionFromDsc["PlatformModuleOptions"]\r
592 else:\r
593 ModuleTypeOptions, PlatformModuleOptions = {}, {}\r
594 ToolDefinition = self.DataPipe.Get("TOOLDEF")\r
595 ModuleOptions = self._ExpandBuildOption(module.BuildOptions)\r
596 BuildRuleOrder = None\r
597 for Options in [ToolDefinition, ModuleOptions, PlatformOptions, ModuleTypeOptions, PlatformModuleOptions]:\r
598 for Tool in Options:\r
599 for Attr in Options[Tool]:\r
600 if Attr == TAB_TOD_DEFINES_BUILDRULEORDER:\r
601 BuildRuleOrder = Options[Tool][Attr]\r
602\r
603 AllTools = set(list(ModuleOptions.keys()) + list(PlatformOptions.keys()) +\r
604 list(PlatformModuleOptions.keys()) + list(ModuleTypeOptions.keys()) +\r
605 list(ToolDefinition.keys()))\r
606 BuildOptions = defaultdict(lambda: defaultdict(str))\r
607 for Tool in AllTools:\r
608 for Options in [ToolDefinition, ModuleOptions, PlatformOptions, ModuleTypeOptions, PlatformModuleOptions]:\r
609 if Tool not in Options:\r
610 continue\r
611 for Attr in Options[Tool]:\r
612 #\r
613 # Do not generate it in Makefile\r
614 #\r
615 if Attr == TAB_TOD_DEFINES_BUILDRULEORDER:\r
616 continue\r
617 Value = Options[Tool][Attr]\r
618 # check if override is indicated\r
619 if Value.startswith('='):\r
620 BuildOptions[Tool][Attr] = mws.handleWsMacro(Value[1:])\r
621 else:\r
622 if Attr != 'PATH':\r
623 BuildOptions[Tool][Attr] += " " + mws.handleWsMacro(Value)\r
624 else:\r
625 BuildOptions[Tool][Attr] = mws.handleWsMacro(Value)\r
626\r
627 return BuildOptions, BuildRuleOrder\r
628\r
629 def ApplyLibraryInstance(self,module):\r
630 alldeps = self.DataPipe.Get("DEPS")\r
631 if alldeps is None:\r
632 alldeps = {}\r
633 mod_libs = alldeps.get((module.MetaFile.File,module.MetaFile.Root,module.Arch,module.MetaFile.Path),[])\r
634 retVal = []\r
635 for (file_path,root,arch,abs_path) in mod_libs:\r
636 libMetaFile = PathClass(file_path,root)\r
637 libMetaFile.OriginalPath = PathClass(file_path,root)\r
638 libMetaFile.Path = abs_path\r
639 retVal.append(self.Wa.BuildDatabase[libMetaFile, arch, self.Target,self.ToolChain])\r
640 return retVal\r
641\r
642 ## Parse build_rule.txt in Conf Directory.\r
643 #\r
644 # @retval BuildRule object\r
645 #\r
646 @cached_property\r
647 def BuildRule(self):\r
648 WInfo = self.DataPipe.Get("P_Info")\r
649 RetVal = WInfo.get("BuildRuleFile")\r
650 if RetVal._FileVersion == "":\r
651 RetVal._FileVersion = AutoGenReqBuildRuleVerNum\r
652 return RetVal\r