]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/AutoGen/ModuleAutoGenHelper.py
BaseTools: Fixed issue for IgnoreAutoGen
[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
482 def ApplyPcdSetting(self, Module, Pcds, Library=""):\r
483 # for each PCD in module\r
484 for Name, Guid in Pcds:\r
485 PcdInModule = Pcds[Name, Guid]\r
486 # find out the PCD setting in platform\r
487 if (Name, Guid) in self.Pcds:\r
488 PcdInPlatform = self.Pcds[Name, Guid]\r
489 else:\r
490 PcdInPlatform = None\r
491 # then override the settings if any\r
492 self._OverridePcd(PcdInModule, PcdInPlatform, Module, Msg="DSC PCD sections", Library=Library)\r
493 # resolve the VariableGuid value\r
494 for SkuId in PcdInModule.SkuInfoList:\r
495 Sku = PcdInModule.SkuInfoList[SkuId]\r
496 if Sku.VariableGuid == '': continue\r
497 Sku.VariableGuidValue = GuidValue(Sku.VariableGuid, self.PackageList, self.MetaFile.Path)\r
498 if Sku.VariableGuidValue is None:\r
499 PackageList = "\n\t".join(str(P) for P in self.PackageList)\r
500 EdkLogger.error(\r
501 'build',\r
502 RESOURCE_NOT_AVAILABLE,\r
503 "Value of GUID [%s] is not found in" % Sku.VariableGuid,\r
504 ExtraData=PackageList + "\n\t(used with %s.%s from module %s)" \\r
505 % (Guid, Name, str(Module)),\r
506 File=self.MetaFile\r
507 )\r
508\r
509 # override PCD settings with module specific setting\r
510 if Module in self.Platform.Modules:\r
511 PlatformModule = self.Platform.Modules[str(Module)]\r
512 for Key in PlatformModule.Pcds:\r
513 if self.BuildOptionPcd:\r
514 for pcd in self.BuildOptionPcd:\r
515 (TokenSpaceGuidCName, TokenCName, FieldName, pcdvalue, _) = pcd\r
516 if (TokenCName, TokenSpaceGuidCName) == Key and FieldName =="":\r
517 PlatformModule.Pcds[Key].DefaultValue = pcdvalue\r
518 PlatformModule.Pcds[Key].PcdValueFromComm = pcdvalue\r
519 break\r
520 Flag = False\r
521 if Key in Pcds:\r
522 ToPcd = Pcds[Key]\r
523 Flag = True\r
524 elif Key in self.MixedPcd:\r
525 for PcdItem in self.MixedPcd[Key]:\r
526 if PcdItem in Pcds:\r
527 ToPcd = Pcds[PcdItem]\r
528 Flag = True\r
529 break\r
530 if Flag:\r
531 self._OverridePcd(ToPcd, PlatformModule.Pcds[Key], Module, Msg="DSC Components Module scoped PCD section", Library=Library)\r
532 # use PCD value to calculate the MaxDatumSize when it is not specified\r
533 for Name, Guid in Pcds:\r
534 Pcd = Pcds[Name, Guid]\r
535 if Pcd.DatumType == TAB_VOID and not Pcd.MaxDatumSize:\r
536 Pcd.MaxSizeUserSet = None\r
537 Value = Pcd.DefaultValue\r
538 if not Value:\r
539 Pcd.MaxDatumSize = '1'\r
540 elif Value[0] == 'L':\r
541 Pcd.MaxDatumSize = str((len(Value) - 2) * 2)\r
542 elif Value[0] == '{':\r
543 Pcd.MaxDatumSize = str(len(Value.split(',')))\r
544 else:\r
545 Pcd.MaxDatumSize = str(len(Value) - 1)\r
546 return list(Pcds.values())\r
547\r
548 @cached_property\r
549 def Pcds(self):\r
550 PlatformPcdData = self.DataPipe.Get("PLA_PCD")\r
551# for pcd in PlatformPcdData:\r
552# for skuid in pcd.SkuInfoList:\r
553# pcd.SkuInfoList[skuid] = self.CreateSkuInfoFromDict(pcd.SkuInfoList[skuid])\r
554 return {(pcddata.TokenCName,pcddata.TokenSpaceGuidCName):pcddata for pcddata in PlatformPcdData}\r
555\r
556 def CreateSkuInfoFromDict(self,SkuInfoDict):\r
557 return SkuInfoClass(\r
558 SkuInfoDict.get("SkuIdName"),\r
559 SkuInfoDict.get("SkuId"),\r
560 SkuInfoDict.get("VariableName"),\r
561 SkuInfoDict.get("VariableGuid"),\r
562 SkuInfoDict.get("VariableOffset"),\r
563 SkuInfoDict.get("HiiDefaultValue"),\r
564 SkuInfoDict.get("VpdOffset"),\r
565 SkuInfoDict.get("DefaultValue"),\r
566 SkuInfoDict.get("VariableGuidValue"),\r
567 SkuInfoDict.get("VariableAttribute",""),\r
568 SkuInfoDict.get("DefaultStore",None)\r
569 )\r
570 @cached_property\r
571 def MixedPcd(self):\r
572 return self.DataPipe.Get("MixedPcd")\r
573 @cached_property\r
574 def _GuidDict(self):\r
575 RetVal = self.DataPipe.Get("GuidDict")\r
576 if RetVal is None:\r
577 RetVal = {}\r
578 return RetVal\r
579 @cached_property\r
580 def BuildOptionPcd(self):\r
581 return self.DataPipe.Get("BuildOptPcd")\r
582 def ApplyBuildOption(self,module):\r
583 PlatformOptions = self.DataPipe.Get("PLA_BO")\r
584 ModuleBuildOptions = self.DataPipe.Get("MOL_BO")\r
585 ModuleOptionFromDsc = ModuleBuildOptions.get((module.MetaFile.File,module.MetaFile.Root))\r
586 if ModuleOptionFromDsc:\r
587 ModuleTypeOptions, PlatformModuleOptions = ModuleOptionFromDsc["ModuleTypeOptions"],ModuleOptionFromDsc["PlatformModuleOptions"]\r
588 else:\r
589 ModuleTypeOptions, PlatformModuleOptions = {}, {}\r
590 ToolDefinition = self.DataPipe.Get("TOOLDEF")\r
591 ModuleOptions = self._ExpandBuildOption(module.BuildOptions)\r
592 BuildRuleOrder = None\r
593 for Options in [ToolDefinition, ModuleOptions, PlatformOptions, ModuleTypeOptions, PlatformModuleOptions]:\r
594 for Tool in Options:\r
595 for Attr in Options[Tool]:\r
596 if Attr == TAB_TOD_DEFINES_BUILDRULEORDER:\r
597 BuildRuleOrder = Options[Tool][Attr]\r
598\r
599 AllTools = set(list(ModuleOptions.keys()) + list(PlatformOptions.keys()) +\r
600 list(PlatformModuleOptions.keys()) + list(ModuleTypeOptions.keys()) +\r
601 list(ToolDefinition.keys()))\r
602 BuildOptions = defaultdict(lambda: defaultdict(str))\r
603 for Tool in AllTools:\r
604 for Options in [ToolDefinition, ModuleOptions, PlatformOptions, ModuleTypeOptions, PlatformModuleOptions]:\r
605 if Tool not in Options:\r
606 continue\r
607 for Attr in Options[Tool]:\r
608 #\r
609 # Do not generate it in Makefile\r
610 #\r
611 if Attr == TAB_TOD_DEFINES_BUILDRULEORDER:\r
612 continue\r
613 Value = Options[Tool][Attr]\r
614 # check if override is indicated\r
615 if Value.startswith('='):\r
616 BuildOptions[Tool][Attr] = mws.handleWsMacro(Value[1:])\r
617 else:\r
618 if Attr != 'PATH':\r
619 BuildOptions[Tool][Attr] += " " + mws.handleWsMacro(Value)\r
620 else:\r
621 BuildOptions[Tool][Attr] = mws.handleWsMacro(Value)\r
622\r
623 return BuildOptions, BuildRuleOrder\r
624\r
625 def ApplyLibraryInstance(self,module):\r
626 alldeps = self.DataPipe.Get("DEPS")\r
627 if alldeps is None:\r
628 alldeps = {}\r
629 mod_libs = alldeps.get((module.MetaFile.File,module.MetaFile.Root,module.Arch,module.MetaFile.Path),[])\r
630 retVal = []\r
631 for (file_path,root,arch,abs_path) in mod_libs:\r
632 libMetaFile = PathClass(file_path,root)\r
633 libMetaFile.OriginalPath = PathClass(file_path,root)\r
634 libMetaFile.Path = abs_path\r
635 retVal.append(self.Wa.BuildDatabase[libMetaFile, arch, self.Target,self.ToolChain])\r
636 return retVal\r
637\r
638 ## Parse build_rule.txt in Conf Directory.\r
639 #\r
640 # @retval BuildRule object\r
641 #\r
642 @cached_property\r
643 def BuildRule(self):\r
644 WInfo = self.DataPipe.Get("P_Info")\r
645 RetVal = WInfo.get("BuildRuleFile")\r
646 if RetVal._FileVersion == "":\r
647 RetVal._FileVersion = AutoGenReqBuildRuleVerNum\r
648 return RetVal\r