BaseTools: Enhance BaseTools supports FixedAtBuild usage in VFR file
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / AutoGen.py
CommitLineData
52302d4d
LG
1## @file\r
2# Generate AutoGen.h, AutoGen.c and *.depex files\r
3#\r
5b97eb4c 4# Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>\r
40d841f6 5# This program and the accompanying materials\r
52302d4d
LG
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
1be2ed90 16import Common.LongFilePathOs as os\r
52302d4d
LG
17import re\r
18import os.path as path\r
19import copy\r
867d1cd4 20import uuid\r
52302d4d
LG
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
1be2ed90 30from Common.LongFilePathSupport import CopyLongFilePath\r
52302d4d
LG
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
e8a47801 39from GenPatchPcdTable.GenPatchPcdTable import parsePcdInfoFromMapFile\r
e56468c0 40import Common.VpdInfoFile as VpdInfoFile\r
e8a47801
LG
41from GenPcdDb import CreatePcdDatabaseCode\r
42from Workspace.MetaFileCommentParser import UsageList\r
05cc51ad 43from Common.MultipleWorkspace import MultipleWorkspace as mws\r
97fa0ee9
YL
44import InfSectionParser\r
45\r
e8a47801 46## Regular expression for splitting Dependency Expression string into tokens\r
52302d4d
LG
47gDepexTokenPattern = re.compile("(\(|\)|\w+| \S+\.inf)")\r
48\r
97fa0ee9
YL
49#\r
50# Match name = variable\r
51#\r
52gEfiVarStoreNamePattern = re.compile("\s*name\s*=\s*(\w+)")\r
53#\r
54# The format of guid in efivarstore statement likes following and must be correct:\r
55# guid = {0xA04A27f4, 0xDF00, 0x4D42, {0xB5, 0x52, 0x39, 0x51, 0x13, 0x02, 0x11, 0x3D}}\r
56#\r
57gEfiVarStoreGuidPattern = re.compile("\s*guid\s*=\s*({.*?{.*?}\s*})")\r
58\r
52302d4d
LG
59## Mapping Makefile type\r
60gMakeTypeMap = {"MSFT":"nmake", "GCC":"gmake"}\r
61\r
62\r
63## Build rule configuration file\r
97fa0ee9 64gDefaultBuildRuleFile = 'Conf/build_rule.txt'\r
52302d4d 65\r
64b2609f
LG
66## Build rule default version\r
67AutoGenReqBuildRuleVerNum = "0.1"\r
68\r
52302d4d
LG
69## default file name for AutoGen\r
70gAutoGenCodeFileName = "AutoGen.c"\r
71gAutoGenHeaderFileName = "AutoGen.h"\r
72gAutoGenStringFileName = "%(module_name)sStrDefs.h"\r
73gAutoGenStringFormFileName = "%(module_name)sStrDefs.hpk"\r
74gAutoGenDepexFileName = "%(module_name)s.depex"\r
333ba578
YZ
75gAutoGenImageDefFileName = "%(module_name)sImgDefs.h"\r
76gAutoGenIdfFileName = "%(module_name)sIdf.hpk"\r
97fa0ee9
YL
77gInfSpecVersion = "0x00010017"\r
78\r
da92f276
LG
79#\r
80# Template string to generic AsBuilt INF\r
81#\r
e8a47801 82gAsBuiltInfHeaderString = TemplateString("""${header_comments}\r
da92f276 83\r
97fa0ee9
YL
84# DO NOT EDIT\r
85# FILE auto-generated\r
86\r
da92f276 87[Defines]\r
97fa0ee9 88 INF_VERSION = ${module_inf_version}\r
da92f276
LG
89 BASE_NAME = ${module_name}\r
90 FILE_GUID = ${module_guid}\r
97fa0ee9
YL
91 MODULE_TYPE = ${module_module_type}${BEGIN}\r
92 VERSION_STRING = ${module_version_string}${END}${BEGIN}\r
e8a47801 93 PCD_IS_DRIVER = ${pcd_is_driver_string}${END}${BEGIN}\r
da92f276 94 UEFI_SPECIFICATION_VERSION = ${module_uefi_specification_version}${END}${BEGIN}\r
97fa0ee9
YL
95 PI_SPECIFICATION_VERSION = ${module_pi_specification_version}${END}${BEGIN}\r
96 ENTRY_POINT = ${module_entry_point}${END}${BEGIN}\r
97 UNLOAD_IMAGE = ${module_unload_image}${END}${BEGIN}\r
98 CONSTRUCTOR = ${module_constructor}${END}${BEGIN}\r
99 DESTRUCTOR = ${module_destructor}${END}${BEGIN}\r
100 SHADOW = ${module_shadow}${END}${BEGIN}\r
101 PCI_VENDOR_ID = ${module_pci_vendor_id}${END}${BEGIN}\r
102 PCI_DEVICE_ID = ${module_pci_device_id}${END}${BEGIN}\r
103 PCI_CLASS_CODE = ${module_pci_class_code}${END}${BEGIN}\r
104 PCI_REVISION = ${module_pci_revision}${END}${BEGIN}\r
105 BUILD_NUMBER = ${module_build_number}${END}${BEGIN}\r
106 SPEC = ${module_spec}${END}${BEGIN}\r
107 UEFI_HII_RESOURCE_SECTION = ${module_uefi_hii_resource_section}${END}${BEGIN}\r
108 MODULE_UNI_FILE = ${module_uni_file}${END}\r
109\r
110[Packages.${module_arch}]${BEGIN}\r
da92f276
LG
111 ${package_item}${END}\r
112\r
113[Binaries.${module_arch}]${BEGIN}\r
114 ${binary_item}${END}\r
115\r
e8a47801
LG
116[PatchPcd.${module_arch}]${BEGIN}\r
117 ${patchablepcd_item}\r
118${END}\r
97fa0ee9 119\r
e8a47801
LG
120[Protocols.${module_arch}]${BEGIN}\r
121 ${protocol_item}\r
122${END}\r
97fa0ee9 123\r
e8a47801
LG
124[Ppis.${module_arch}]${BEGIN}\r
125 ${ppi_item}\r
126${END}\r
97fa0ee9 127\r
e8a47801
LG
128[Guids.${module_arch}]${BEGIN}\r
129 ${guid_item}\r
130${END}\r
97fa0ee9 131\r
e8a47801
LG
132[PcdEx.${module_arch}]${BEGIN}\r
133 ${pcd_item}\r
134${END}\r
da92f276 135\r
97fa0ee9
YL
136[LibraryClasses.${module_arch}]\r
137## @LIB_INSTANCES${BEGIN}\r
138# ${libraryclasses_item}${END}\r
139\r
140${depexsection_item}\r
141\r
142${tail_comments}\r
143\r
144[BuildOptions.${module_arch}]\r
da92f276
LG
145## @AsBuilt${BEGIN}\r
146## ${flags_item}${END}\r
147""")\r
148\r
52302d4d
LG
149## Base class for AutoGen\r
150#\r
151# This class just implements the cache mechanism of AutoGen objects.\r
152#\r
153class AutoGen(object):\r
154 # database to maintain the objects of xxxAutoGen\r
155 _CACHE_ = {} # (BuildTarget, ToolChain) : {ARCH : {platform file: AutoGen object}}}\r
156\r
157 ## Factory method\r
158 #\r
159 # @param Class class object of real AutoGen class\r
160 # (WorkspaceAutoGen, ModuleAutoGen or PlatformAutoGen)\r
161 # @param Workspace Workspace directory or WorkspaceAutoGen object\r
162 # @param MetaFile The path of meta file\r
163 # @param Target Build target\r
164 # @param Toolchain Tool chain name\r
165 # @param Arch Target arch\r
166 # @param *args The specific class related parameters\r
167 # @param **kwargs The specific class related dict parameters\r
168 #\r
169 def __new__(Class, Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs):\r
170 # check if the object has been created\r
171 Key = (Target, Toolchain)\r
172 if Key not in Class._CACHE_ or Arch not in Class._CACHE_[Key] \\r
173 or MetaFile not in Class._CACHE_[Key][Arch]:\r
174 AutoGenObject = super(AutoGen, Class).__new__(Class)\r
175 # call real constructor\r
176 if not AutoGenObject._Init(Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs):\r
177 return None\r
178 if Key not in Class._CACHE_:\r
179 Class._CACHE_[Key] = {}\r
180 if Arch not in Class._CACHE_[Key]:\r
181 Class._CACHE_[Key][Arch] = {}\r
182 Class._CACHE_[Key][Arch][MetaFile] = AutoGenObject\r
183 else:\r
184 AutoGenObject = Class._CACHE_[Key][Arch][MetaFile]\r
185\r
186 return AutoGenObject\r
187\r
188 ## hash() operator\r
189 #\r
190 # The file path of platform file will be used to represent hash value of this object\r
191 #\r
192 # @retval int Hash value of the file path of platform file\r
193 #\r
194 def __hash__(self):\r
195 return hash(self.MetaFile)\r
196\r
197 ## str() operator\r
198 #\r
199 # The file path of platform file will be used to represent this object\r
200 #\r
201 # @retval string String of platform file path\r
202 #\r
203 def __str__(self):\r
204 return str(self.MetaFile)\r
205\r
206 ## "==" operator\r
207 def __eq__(self, Other):\r
208 return Other and self.MetaFile == Other\r
209\r
210## Workspace AutoGen class\r
211#\r
212# This class is used mainly to control the whole platform build for different\r
213# architecture. This class will generate top level makefile.\r
214#\r
215class WorkspaceAutoGen(AutoGen):\r
216 ## Real constructor of WorkspaceAutoGen\r
217 #\r
79b74a03 218 # This method behaves the same as __init__ except that it needs explicit invoke\r
52302d4d
LG
219 # (in super class's __new__ method)\r
220 #\r
221 # @param WorkspaceDir Root directory of workspace\r
222 # @param ActivePlatform Meta-file of active platform\r
223 # @param Target Build target\r
224 # @param Toolchain Tool chain name\r
225 # @param ArchList List of architecture of current build\r
226 # @param MetaFileDb Database containing meta-files\r
227 # @param BuildConfig Configuration of build\r
228 # @param ToolDefinition Tool chain definitions\r
229 # @param FlashDefinitionFile File of flash definition\r
230 # @param Fds FD list to be generated\r
231 # @param Fvs FV list to be generated\r
4234283c 232 # @param Caps Capsule list to be generated\r
52302d4d
LG
233 # @param SkuId SKU id from command line\r
234 #\r
235 def _Init(self, WorkspaceDir, ActivePlatform, Target, Toolchain, ArchList, MetaFileDb,\r
47fea6af 236 BuildConfig, ToolDefinition, FlashDefinitionFile='', Fds=None, Fvs=None, Caps=None, SkuId='', UniFlag=None,\r
9508d0fa 237 Progress=None, BuildModule=None):\r
4234283c
LG
238 if Fds is None:\r
239 Fds = []\r
240 if Fvs is None:\r
241 Fvs = []\r
242 if Caps is None:\r
243 Caps = []\r
0d2711a6
LG
244 self.BuildDatabase = MetaFileDb\r
245 self.MetaFile = ActivePlatform\r
52302d4d 246 self.WorkspaceDir = WorkspaceDir\r
0d2711a6 247 self.Platform = self.BuildDatabase[self.MetaFile, 'COMMON', Target, Toolchain]\r
d0acc87a 248 GlobalData.gActivePlatform = self.Platform\r
52302d4d
LG
249 self.BuildTarget = Target\r
250 self.ToolChain = Toolchain\r
251 self.ArchList = ArchList\r
252 self.SkuId = SkuId\r
f3decdc3 253 self.UniFlag = UniFlag\r
52302d4d 254\r
52302d4d
LG
255 self.TargetTxt = BuildConfig\r
256 self.ToolDef = ToolDefinition\r
257 self.FdfFile = FlashDefinitionFile\r
258 self.FdTargetList = Fds\r
259 self.FvTargetList = Fvs\r
4234283c 260 self.CapTargetList = Caps\r
52302d4d
LG
261 self.AutoGenObjectList = []\r
262\r
263 # there's many relative directory operations, so ...\r
264 os.chdir(self.WorkspaceDir)\r
265\r
0d2711a6
LG
266 #\r
267 # Merge Arch\r
268 #\r
269 if not self.ArchList:\r
270 ArchList = set(self.Platform.SupArchList)\r
271 else:\r
272 ArchList = set(self.ArchList) & set(self.Platform.SupArchList)\r
273 if not ArchList:\r
274 EdkLogger.error("build", PARAMETER_INVALID,\r
275 ExtraData = "Invalid ARCH specified. [Valid ARCH: %s]" % (" ".join(self.Platform.SupArchList)))\r
276 elif self.ArchList and len(ArchList) != len(self.ArchList):\r
277 SkippedArchList = set(self.ArchList).symmetric_difference(set(self.Platform.SupArchList))\r
278 EdkLogger.verbose("\nArch [%s] is ignored because the platform supports [%s] only!"\r
279 % (" ".join(SkippedArchList), " ".join(self.Platform.SupArchList)))\r
280 self.ArchList = tuple(ArchList)\r
281\r
282 # Validate build target\r
283 if self.BuildTarget not in self.Platform.BuildTargets:\r
47fea6af 284 EdkLogger.error("build", PARAMETER_INVALID,\r
0d2711a6
LG
285 ExtraData="Build target [%s] is not supported by the platform. [Valid target: %s]"\r
286 % (self.BuildTarget, " ".join(self.Platform.BuildTargets)))\r
287\r
12d37ace 288 \r
52302d4d 289 # parse FDF file to get PCDs in it, if any\r
0d2711a6
LG
290 if not self.FdfFile:\r
291 self.FdfFile = self.Platform.FlashDefinition\r
47fea6af 292\r
9508d0fa
LG
293 EdkLogger.info("")\r
294 if self.ArchList:\r
295 EdkLogger.info('%-16s = %s' % ("Architecture(s)", ' '.join(self.ArchList)))\r
296 EdkLogger.info('%-16s = %s' % ("Build target", self.BuildTarget))\r
47fea6af
YZ
297 EdkLogger.info('%-16s = %s' % ("Toolchain", self.ToolChain))\r
298\r
9508d0fa
LG
299 EdkLogger.info('\n%-24s = %s' % ("Active Platform", self.Platform))\r
300 if BuildModule:\r
301 EdkLogger.info('%-24s = %s' % ("Active Module", BuildModule))\r
47fea6af 302\r
9508d0fa
LG
303 if self.FdfFile:\r
304 EdkLogger.info('%-24s = %s' % ("Flash Image Definition", self.FdfFile))\r
0d2711a6 305\r
9508d0fa 306 EdkLogger.verbose("\nFLASH_DEFINITION = %s" % self.FdfFile)\r
47fea6af 307\r
9508d0fa
LG
308 if Progress:\r
309 Progress.Start("\nProcessing meta-data")\r
47fea6af 310\r
0d2711a6 311 if self.FdfFile:\r
df692f02
LG
312 #\r
313 # Mark now build in AutoGen Phase\r
314 #\r
47fea6af 315 GlobalData.gAutoGenPhase = True\r
52302d4d
LG
316 Fdf = FdfParser(self.FdfFile.Path)\r
317 Fdf.ParseFile()\r
a0a2cd1e 318 GlobalData.gFdfParser = Fdf\r
0d2711a6 319 GlobalData.gAutoGenPhase = False\r
52302d4d 320 PcdSet = Fdf.Profile.PcdDict\r
cb04330e
YZ
321 if Fdf.CurrentFdName and Fdf.CurrentFdName in Fdf.Profile.FdDict:\r
322 FdDict = Fdf.Profile.FdDict[Fdf.CurrentFdName]\r
323 for FdRegion in FdDict.RegionList:\r
324 if str(FdRegion.RegionType) is 'FILE' and self.Platform.VpdToolGuid in str(FdRegion.RegionDataList):\r
325 if int(FdRegion.Offset) % 8 != 0:\r
326 EdkLogger.error("build", FORMAT_INVALID, 'The VPD Base Address %s must be 8-byte aligned.' % (FdRegion.Offset))\r
52302d4d
LG
327 ModuleList = Fdf.Profile.InfList\r
328 self.FdfProfile = Fdf.Profile\r
0d2711a6
LG
329 for fvname in self.FvTargetList:\r
330 if fvname.upper() not in self.FdfProfile.FvDict:\r
331 EdkLogger.error("build", OPTION_VALUE_INVALID,\r
332 "No such an FV in FDF file: %s" % fvname)\r
2502b735 333\r
622b1758
YZ
334 # In DSC file may use FILE_GUID to override the module, then in the Platform.Modules use FILE_GUIDmodule.inf as key,\r
335 # but the path (self.MetaFile.Path) is the real path\r
2502b735
YZ
336 for key in self.FdfProfile.InfDict:\r
337 if key == 'ArchTBD':\r
338 Platform_cache = {}\r
622b1758 339 MetaFile_cache = {}\r
2502b735
YZ
340 for Arch in self.ArchList:\r
341 Platform_cache[Arch] = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain]\r
622b1758
YZ
342 MetaFile_cache[Arch] = []\r
343 for Pkey in Platform_cache[Arch].Modules.keys():\r
344 MetaFile_cache[Arch].append(Platform_cache[Arch].Modules[Pkey].MetaFile)\r
2502b735
YZ
345 for Inf in self.FdfProfile.InfDict[key]:\r
346 ModuleFile = PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch)\r
347 for Arch in self.ArchList:\r
622b1758 348 if ModuleFile in MetaFile_cache[Arch]:\r
2502b735
YZ
349 break\r
350 else:\r
351 ModuleData = self.BuildDatabase[ModuleFile, Arch, Target, Toolchain]\r
352 if not ModuleData.IsBinaryModule:\r
353 EdkLogger.error('build', PARSER_ERROR, "Module %s NOT found in DSC file; Is it really a binary module?" % ModuleFile)\r
354\r
355 else:\r
356 for Arch in self.ArchList:\r
357 if Arch == key:\r
358 Platform = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain]\r
622b1758
YZ
359 MetaFileList = []\r
360 for Pkey in Platform.Modules.keys():\r
361 MetaFileList.append(Platform.Modules[Pkey].MetaFile)\r
2502b735
YZ
362 for Inf in self.FdfProfile.InfDict[key]:\r
363 ModuleFile = PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch)\r
622b1758 364 if ModuleFile in MetaFileList:\r
2502b735
YZ
365 continue\r
366 ModuleData = self.BuildDatabase[ModuleFile, Arch, Target, Toolchain]\r
367 if not ModuleData.IsBinaryModule:\r
368 EdkLogger.error('build', PARSER_ERROR, "Module %s NOT found in DSC file; Is it really a binary module?" % ModuleFile)\r
369\r
52302d4d
LG
370 else:\r
371 PcdSet = {}\r
372 ModuleList = []\r
373 self.FdfProfile = None\r
0d2711a6
LG
374 if self.FdTargetList:\r
375 EdkLogger.info("No flash definition file found. FD [%s] will be ignored." % " ".join(self.FdTargetList))\r
376 self.FdTargetList = []\r
377 if self.FvTargetList:\r
378 EdkLogger.info("No flash definition file found. FV [%s] will be ignored." % " ".join(self.FvTargetList))\r
379 self.FvTargetList = []\r
380 if self.CapTargetList:\r
381 EdkLogger.info("No flash definition file found. Capsule [%s] will be ignored." % " ".join(self.CapTargetList))\r
382 self.CapTargetList = []\r
47fea6af 383\r
52302d4d
LG
384 # apply SKU and inject PCDs from Flash Definition file\r
385 for Arch in self.ArchList:\r
0d2711a6 386 Platform = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain]\r
64b2609f 387\r
25918452 388 DecPcds = {}\r
4afd3d04 389 DecPcdsKey = set()\r
64b2609f 390 PGen = PlatformAutoGen(self, self.MetaFile, Target, Toolchain, Arch)\r
763e8edf
YZ
391 if GlobalData.BuildOptionPcd:\r
392 for i, pcd in enumerate(GlobalData.BuildOptionPcd):\r
d7cd3356
YZ
393 if type(pcd) is tuple:\r
394 continue\r
763e8edf
YZ
395 (pcdname, pcdvalue) = pcd.split('=')\r
396 if not pcdvalue:\r
397 EdkLogger.error('build', AUTOGEN_ERROR, "No Value specified for the PCD %s." % (pcdname))\r
398 if '.' in pcdname:\r
399 (TokenSpaceGuidCName, TokenCName) = pcdname.split('.')\r
400 HasTokenSpace = True\r
401 else:\r
402 TokenCName = pcdname\r
403 TokenSpaceGuidCName = ''\r
404 HasTokenSpace = False\r
405 TokenSpaceGuidCNameList = []\r
406 FoundFlag = False\r
407 PcdDatumType = ''\r
408 NewValue = ''\r
409 for package in PGen.PackageList:\r
410 for key in package.Pcds:\r
411 PcdItem = package.Pcds[key]\r
412 if HasTokenSpace:\r
413 if (PcdItem.TokenCName, PcdItem.TokenSpaceGuidCName) == (TokenCName, TokenSpaceGuidCName):\r
414 PcdDatumType = PcdItem.DatumType\r
415 NewValue = self._BuildOptionPcdValueFormat(TokenSpaceGuidCName, TokenCName, PcdDatumType, pcdvalue)\r
416 FoundFlag = True\r
417 else:\r
418 if PcdItem.TokenCName == TokenCName:\r
419 if not PcdItem.TokenSpaceGuidCName in TokenSpaceGuidCNameList:\r
420 if len (TokenSpaceGuidCNameList) < 1:\r
421 TokenSpaceGuidCNameList.append(PcdItem.TokenSpaceGuidCName)\r
422 PcdDatumType = PcdItem.DatumType\r
423 TokenSpaceGuidCName = PcdItem.TokenSpaceGuidCName\r
424 NewValue = self._BuildOptionPcdValueFormat(TokenSpaceGuidCName, TokenCName, PcdDatumType, pcdvalue)\r
425 FoundFlag = True\r
426 else:\r
427 EdkLogger.error(\r
428 'build',\r
429 AUTOGEN_ERROR,\r
430 "The Pcd %s is found under multiple different TokenSpaceGuid: %s and %s." % (TokenCName, PcdItem.TokenSpaceGuidCName, TokenSpaceGuidCNameList[0])\r
431 )\r
432\r
433 GlobalData.BuildOptionPcd[i] = (TokenSpaceGuidCName, TokenCName, NewValue)\r
434\r
435 if not FoundFlag:\r
436 if HasTokenSpace:\r
437 EdkLogger.error('build', AUTOGEN_ERROR, "The Pcd %s.%s is not found in the DEC file." % (TokenSpaceGuidCName, TokenCName))\r
438 else:\r
439 EdkLogger.error('build', AUTOGEN_ERROR, "The Pcd %s is not found in the DEC file." % (TokenCName))\r
440\r
441 for BuildData in PGen.BuildDatabase._CACHE_.values():\r
442 if BuildData.Arch != Arch:\r
443 continue\r
444 if BuildData.MetaFile.Ext == '.dec':\r
445 continue\r
446 for key in BuildData.Pcds:\r
447 PcdItem = BuildData.Pcds[key]\r
448 if (TokenSpaceGuidCName, TokenCName) == (PcdItem.TokenSpaceGuidCName, PcdItem.TokenCName):\r
449 PcdItem.DefaultValue = NewValue\r
450\r
451 if (TokenCName, TokenSpaceGuidCName) in PcdSet:\r
452 PcdSet[(TokenCName, TokenSpaceGuidCName)] = NewValue\r
453\r
2a29017e
YZ
454 SourcePcdDict = {'DynamicEx':[], 'PatchableInModule':[],'Dynamic':[],'FixedAtBuild':[]}\r
455 BinaryPcdDict = {'DynamicEx':[], 'PatchableInModule':[]}\r
456 SourcePcdDict_Keys = SourcePcdDict.keys()\r
457 BinaryPcdDict_Keys = BinaryPcdDict.keys()\r
458\r
459 # generate the SourcePcdDict and BinaryPcdDict\r
460 for BuildData in PGen.BuildDatabase._CACHE_.values():\r
461 if BuildData.Arch != Arch:\r
462 continue\r
463 if BuildData.MetaFile.Ext == '.inf':\r
464 for key in BuildData.Pcds:\r
465 if BuildData.Pcds[key].Pending:\r
466 if key in Platform.Pcds:\r
467 PcdInPlatform = Platform.Pcds[key]\r
468 if PcdInPlatform.Type not in [None, '']:\r
469 BuildData.Pcds[key].Type = PcdInPlatform.Type\r
470\r
471 if BuildData.MetaFile in Platform.Modules:\r
472 PlatformModule = Platform.Modules[str(BuildData.MetaFile)]\r
473 if key in PlatformModule.Pcds:\r
474 PcdInPlatform = PlatformModule.Pcds[key]\r
475 if PcdInPlatform.Type not in [None, '']:\r
476 BuildData.Pcds[key].Type = PcdInPlatform.Type\r
477\r
478 if 'DynamicEx' in BuildData.Pcds[key].Type:\r
479 if BuildData.IsBinaryModule:\r
480 if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in BinaryPcdDict['DynamicEx']:\r
481 BinaryPcdDict['DynamicEx'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
482 else:\r
483 if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in SourcePcdDict['DynamicEx']:\r
484 SourcePcdDict['DynamicEx'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
485\r
486 elif 'PatchableInModule' in BuildData.Pcds[key].Type:\r
487 if BuildData.MetaFile.Ext == '.inf':\r
488 if BuildData.IsBinaryModule:\r
489 if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in BinaryPcdDict['PatchableInModule']:\r
490 BinaryPcdDict['PatchableInModule'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
491 else:\r
492 if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in SourcePcdDict['PatchableInModule']:\r
493 SourcePcdDict['PatchableInModule'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
494\r
495 elif 'Dynamic' in BuildData.Pcds[key].Type:\r
496 if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in SourcePcdDict['Dynamic']:\r
497 SourcePcdDict['Dynamic'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
498 elif 'FixedAtBuild' in BuildData.Pcds[key].Type:\r
499 if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) not in SourcePcdDict['FixedAtBuild']:\r
500 SourcePcdDict['FixedAtBuild'].append((BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName))\r
501 else:\r
502 pass\r
503\r
504 #\r
505 # intersection the BinaryPCD for Mixed PCD\r
506 #\r
507 for i in BinaryPcdDict_Keys:\r
508 for j in BinaryPcdDict_Keys:\r
509 if i != j:\r
510 IntersectionList = list(set(BinaryPcdDict[i]).intersection(set(BinaryPcdDict[j])))\r
511 for item in IntersectionList:\r
512 NewPcd1 = (item[0] + '_' + i, item[1])\r
513 NewPcd2 = (item[0] + '_' + j, item[1])\r
514 if item not in GlobalData.MixedPcd:\r
515 GlobalData.MixedPcd[item] = [NewPcd1, NewPcd2]\r
516 else:\r
517 if NewPcd1 not in GlobalData.MixedPcd[item]:\r
518 GlobalData.MixedPcd[item].append(NewPcd1)\r
519 if NewPcd2 not in GlobalData.MixedPcd[item]:\r
520 GlobalData.MixedPcd[item].append(NewPcd2)\r
521 else:\r
522 pass\r
523\r
524 #\r
525 # intersection the SourcePCD and BinaryPCD for Mixed PCD\r
526 #\r
527 for i in SourcePcdDict_Keys:\r
528 for j in BinaryPcdDict_Keys:\r
529 if i != j:\r
530 IntersectionList = list(set(SourcePcdDict[i]).intersection(set(BinaryPcdDict[j])))\r
531 for item in IntersectionList:\r
532 NewPcd1 = (item[0] + '_' + i, item[1])\r
533 NewPcd2 = (item[0] + '_' + j, item[1])\r
534 if item not in GlobalData.MixedPcd:\r
535 GlobalData.MixedPcd[item] = [NewPcd1, NewPcd2]\r
536 else:\r
537 if NewPcd1 not in GlobalData.MixedPcd[item]:\r
538 GlobalData.MixedPcd[item].append(NewPcd1)\r
539 if NewPcd2 not in GlobalData.MixedPcd[item]:\r
540 GlobalData.MixedPcd[item].append(NewPcd2)\r
541 else:\r
542 pass\r
543\r
544 for BuildData in PGen.BuildDatabase._CACHE_.values():\r
545 if BuildData.Arch != Arch:\r
546 continue\r
547 for key in BuildData.Pcds:\r
548 for SinglePcd in GlobalData.MixedPcd:\r
549 if (BuildData.Pcds[key].TokenCName, BuildData.Pcds[key].TokenSpaceGuidCName) == SinglePcd:\r
550 for item in GlobalData.MixedPcd[SinglePcd]:\r
551 Pcd_Type = item[0].split('_')[-1]\r
552 if (Pcd_Type == BuildData.Pcds[key].Type) or (Pcd_Type == TAB_PCDS_DYNAMIC_EX and BuildData.Pcds[key].Type in GenC.gDynamicExPcd) or \\r
553 (Pcd_Type == TAB_PCDS_DYNAMIC and BuildData.Pcds[key].Type in GenC.gDynamicPcd):\r
554 Value = BuildData.Pcds[key]\r
555 Value.TokenCName = BuildData.Pcds[key].TokenCName + '_' + Pcd_Type\r
556 if len(key) == 2:\r
557 newkey = (Value.TokenCName, key[1])\r
558 elif len(key) == 3:\r
559 newkey = (Value.TokenCName, key[1], key[2])\r
560 del BuildData.Pcds[key]\r
561 BuildData.Pcds[newkey] = Value\r
562 break\r
563 else:\r
564 pass\r
565 break\r
566 else:\r
567 pass\r
568\r
569 # handle the mixed pcd in FDF file\r
570 for key in PcdSet:\r
571 if key in GlobalData.MixedPcd:\r
572 Value = PcdSet[key]\r
573 del PcdSet[key]\r
574 for item in GlobalData.MixedPcd[key]:\r
575 PcdSet[item] = Value\r
576\r
97fa0ee9 577 #Collect package set information from INF of FDF\r
a0a2cd1e
FB
578 PkgSet = set()\r
579 for Inf in ModuleList:\r
580 ModuleFile = PathClass(NormPath(Inf), GlobalData.gWorkspace, Arch)\r
581 if ModuleFile in Platform.Modules:\r
582 continue\r
583 ModuleData = self.BuildDatabase[ModuleFile, Arch, Target, Toolchain]\r
584 PkgSet.update(ModuleData.Packages)\r
585 Pkgs = list(PkgSet) + list(PGen.PackageList)\r
64b2609f 586 for Pkg in Pkgs:\r
25918452
LG
587 for Pcd in Pkg.Pcds:\r
588 DecPcds[Pcd[0], Pcd[1]] = Pkg.Pcds[Pcd]\r
4afd3d04 589 DecPcdsKey.add((Pcd[0], Pcd[1], Pcd[2]))\r
64b2609f 590\r
52302d4d
LG
591 Platform.SkuName = self.SkuId\r
592 for Name, Guid in PcdSet:\r
64b2609f
LG
593 if (Name, Guid) not in DecPcds:\r
594 EdkLogger.error(\r
595 'build',\r
596 PARSER_ERROR,\r
597 "PCD (%s.%s) used in FDF is not declared in DEC files." % (Guid, Name),\r
598 File = self.FdfProfile.PcdFileLineDict[Name, Guid][0],\r
599 Line = self.FdfProfile.PcdFileLineDict[Name, Guid][1]\r
600 )\r
4afd3d04
LG
601 else:\r
602 # Check whether Dynamic or DynamicEx PCD used in FDF file. If used, build break and give a error message.\r
603 if (Name, Guid, TAB_PCDS_FIXED_AT_BUILD) in DecPcdsKey \\r
604 or (Name, Guid, TAB_PCDS_PATCHABLE_IN_MODULE) in DecPcdsKey \\r
605 or (Name, Guid, TAB_PCDS_FEATURE_FLAG) in DecPcdsKey:\r
606 Platform.AddPcd(Name, Guid, PcdSet[Name, Guid])\r
607 continue\r
608 elif (Name, Guid, TAB_PCDS_DYNAMIC) in DecPcdsKey or (Name, Guid, TAB_PCDS_DYNAMIC_EX) in DecPcdsKey:\r
609 EdkLogger.error(\r
610 'build',\r
611 PARSER_ERROR,\r
612 "Using Dynamic or DynamicEx type of PCD [%s.%s] in FDF file is not allowed." % (Guid, Name),\r
613 File = self.FdfProfile.PcdFileLineDict[Name, Guid][0],\r
614 Line = self.FdfProfile.PcdFileLineDict[Name, Guid][1]\r
615 )\r
52302d4d
LG
616\r
617 Pa = PlatformAutoGen(self, self.MetaFile, Target, Toolchain, Arch)\r
618 #\r
619 # Explicitly collect platform's dynamic PCDs\r
620 #\r
621 Pa.CollectPlatformDynamicPcds()\r
2bc3256c 622 Pa.CollectFixedAtBuildPcds()\r
52302d4d 623 self.AutoGenObjectList.append(Pa)\r
47fea6af 624\r
6780eef1
LG
625 #\r
626 # Check PCDs token value conflict in each DEC file.\r
627 #\r
628 self._CheckAllPcdsTokenValueConflict()\r
47fea6af 629\r
4234283c
LG
630 #\r
631 # Check PCD type and definition between DSC and DEC\r
632 #\r
633 self._CheckPcdDefineAndType()\r
97fa0ee9
YL
634\r
635# if self.FdfFile:\r
636# self._CheckDuplicateInFV(Fdf)\r
637\r
52302d4d
LG
638 self._BuildDir = None\r
639 self._FvDir = None\r
640 self._MakeFileDir = None\r
641 self._BuildCommand = None\r
642\r
643 return True\r
644\r
763e8edf
YZ
645 def _BuildOptionPcdValueFormat(self, TokenSpaceGuidCName, TokenCName, PcdDatumType, Value):\r
646 if PcdDatumType == 'VOID*':\r
647 if Value.startswith('L'):\r
648 if not Value[1]:\r
649 EdkLogger.error('build', OPTION_VALUE_INVALID, 'For Void* type PCD, when specify the Value in the command line, please use the following format: "string", L"string", B"{...}"')\r
650 Value = Value[0] + '"' + Value[1:] + '"'\r
651 elif Value.startswith('B'):\r
652 if not Value[1]:\r
653 EdkLogger.error('build', OPTION_VALUE_INVALID, 'For Void* type PCD, when specify the Value in the command line, please use the following format: "string", L"string", B"{...}"')\r
654 Value = Value[1:]\r
655 else:\r
656 if not Value[0]:\r
657 EdkLogger.error('build', OPTION_VALUE_INVALID, 'For Void* type PCD, when specify the Value in the command line, please use the following format: "string", L"string", B"{...}"')\r
658 Value = '"' + Value + '"'\r
659\r
660 IsValid, Cause = CheckPcdDatum(PcdDatumType, Value)\r
661 if not IsValid:\r
662 EdkLogger.error('build', FORMAT_INVALID, Cause, ExtraData="%s.%s" % (TokenSpaceGuidCName, TokenCName))\r
663 if PcdDatumType == 'BOOLEAN':\r
664 Value = Value.upper()\r
665 if Value == 'TRUE' or Value == '1':\r
666 Value = '1'\r
667 elif Value == 'FALSE' or Value == '0':\r
668 Value = '0'\r
669 return Value\r
670\r
79b74a03
LG
671 ## _CheckDuplicateInFV() method\r
672 #\r
673 # Check whether there is duplicate modules/files exist in FV section. \r
674 # The check base on the file GUID;\r
675 #\r
676 def _CheckDuplicateInFV(self, Fdf):\r
677 for Fv in Fdf.Profile.FvDict:\r
678 _GuidDict = {}\r
679 for FfsFile in Fdf.Profile.FvDict[Fv].FfsList:\r
680 if FfsFile.InfFileName and FfsFile.NameGuid == None:\r
681 #\r
682 # Get INF file GUID\r
683 #\r
47fea6af 684 InfFoundFlag = False\r
79b74a03 685 for Pa in self.AutoGenObjectList:\r
64b2609f
LG
686 if InfFoundFlag:\r
687 break\r
79b74a03
LG
688 for Module in Pa.ModuleAutoGenList:\r
689 if path.normpath(Module.MetaFile.File) == path.normpath(FfsFile.InfFileName):\r
690 InfFoundFlag = True\r
691 if not Module.Guid.upper() in _GuidDict.keys():\r
692 _GuidDict[Module.Guid.upper()] = FfsFile\r
64b2609f 693 break\r
79b74a03 694 else:\r
47fea6af 695 EdkLogger.error("build",\r
79b74a03 696 FORMAT_INVALID,\r
47fea6af 697 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile.CurrentLineNum,\r
79b74a03
LG
698 FfsFile.CurrentLineContent,\r
699 _GuidDict[Module.Guid.upper()].CurrentLineNum,\r
700 _GuidDict[Module.Guid.upper()].CurrentLineContent,\r
701 Module.Guid.upper()),\r
702 ExtraData=self.FdfFile)\r
703 #\r
704 # Some INF files not have entity in DSC file. \r
705 #\r
706 if not InfFoundFlag:\r
707 if FfsFile.InfFileName.find('$') == -1:\r
708 InfPath = NormPath(FfsFile.InfFileName)\r
709 if not os.path.exists(InfPath):\r
710 EdkLogger.error('build', GENFDS_ERROR, "Non-existant Module %s !" % (FfsFile.InfFileName))\r
47fea6af 711\r
79b74a03
LG
712 PathClassObj = PathClass(FfsFile.InfFileName, self.WorkspaceDir)\r
713 #\r
714 # Here we just need to get FILE_GUID from INF file, use 'COMMON' as ARCH attribute. and use \r
715 # BuildObject from one of AutoGenObjectList is enough.\r
716 #\r
717 InfObj = self.AutoGenObjectList[0].BuildDatabase.WorkspaceDb.BuildObject[PathClassObj, 'COMMON', self.BuildTarget, self.ToolChain]\r
718 if not InfObj.Guid.upper() in _GuidDict.keys():\r
719 _GuidDict[InfObj.Guid.upper()] = FfsFile\r
720 else:\r
47fea6af 721 EdkLogger.error("build",\r
79b74a03 722 FORMAT_INVALID,\r
47fea6af 723 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile.CurrentLineNum,\r
79b74a03
LG
724 FfsFile.CurrentLineContent,\r
725 _GuidDict[InfObj.Guid.upper()].CurrentLineNum,\r
726 _GuidDict[InfObj.Guid.upper()].CurrentLineContent,\r
727 InfObj.Guid.upper()),\r
728 ExtraData=self.FdfFile)\r
729 InfFoundFlag = False\r
47fea6af 730\r
79b74a03
LG
731 if FfsFile.NameGuid != None:\r
732 _CheckPCDAsGuidPattern = re.compile("^PCD\(.+\..+\)$")\r
47fea6af 733\r
79b74a03
LG
734 #\r
735 # If the NameGuid reference a PCD name. \r
736 # The style must match: PCD(xxxx.yyy)\r
737 #\r
738 if _CheckPCDAsGuidPattern.match(FfsFile.NameGuid):\r
739 #\r
740 # Replace the PCD value.\r
741 #\r
742 _PcdName = FfsFile.NameGuid.lstrip("PCD(").rstrip(")")\r
743 PcdFoundFlag = False\r
744 for Pa in self.AutoGenObjectList:\r
745 if not PcdFoundFlag:\r
746 for PcdItem in Pa.AllPcdList:\r
747 if (PcdItem.TokenSpaceGuidCName + "." + PcdItem.TokenCName) == _PcdName:\r
748 #\r
749 # First convert from CFormatGuid to GUID string\r
750 #\r
751 _PcdGuidString = GuidStructureStringToGuidString(PcdItem.DefaultValue)\r
47fea6af 752\r
79b74a03
LG
753 if not _PcdGuidString:\r
754 #\r
755 # Then try Byte array.\r
756 #\r
757 _PcdGuidString = GuidStructureByteArrayToGuidString(PcdItem.DefaultValue)\r
47fea6af 758\r
79b74a03
LG
759 if not _PcdGuidString:\r
760 #\r
761 # Not Byte array or CFormat GUID, raise error.\r
762 #\r
763 EdkLogger.error("build",\r
764 FORMAT_INVALID,\r
47fea6af 765 "The format of PCD value is incorrect. PCD: %s , Value: %s\n" % (_PcdName, PcdItem.DefaultValue),\r
79b74a03 766 ExtraData=self.FdfFile)\r
47fea6af
YZ
767\r
768 if not _PcdGuidString.upper() in _GuidDict.keys():\r
79b74a03
LG
769 _GuidDict[_PcdGuidString.upper()] = FfsFile\r
770 PcdFoundFlag = True\r
771 break\r
772 else:\r
47fea6af 773 EdkLogger.error("build",\r
79b74a03 774 FORMAT_INVALID,\r
47fea6af 775 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile.CurrentLineNum,\r
79b74a03
LG
776 FfsFile.CurrentLineContent,\r
777 _GuidDict[_PcdGuidString.upper()].CurrentLineNum,\r
778 _GuidDict[_PcdGuidString.upper()].CurrentLineContent,\r
779 FfsFile.NameGuid.upper()),\r
47fea6af
YZ
780 ExtraData=self.FdfFile)\r
781\r
79b74a03
LG
782 if not FfsFile.NameGuid.upper() in _GuidDict.keys():\r
783 _GuidDict[FfsFile.NameGuid.upper()] = FfsFile\r
784 else:\r
785 #\r
786 # Two raw file GUID conflict.\r
787 #\r
47fea6af 788 EdkLogger.error("build",\r
79b74a03 789 FORMAT_INVALID,\r
47fea6af 790 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s" % (FfsFile.CurrentLineNum,\r
79b74a03
LG
791 FfsFile.CurrentLineContent,\r
792 _GuidDict[FfsFile.NameGuid.upper()].CurrentLineNum,\r
793 _GuidDict[FfsFile.NameGuid.upper()].CurrentLineContent,\r
794 FfsFile.NameGuid.upper()),\r
795 ExtraData=self.FdfFile)\r
47fea6af 796\r
79b74a03 797\r
4234283c
LG
798 def _CheckPcdDefineAndType(self):\r
799 PcdTypeList = [\r
800 "FixedAtBuild", "PatchableInModule", "FeatureFlag",\r
801 "Dynamic", #"DynamicHii", "DynamicVpd",\r
802 "DynamicEx", # "DynamicExHii", "DynamicExVpd"\r
803 ]\r
804\r
805 # This dict store PCDs which are not used by any modules with specified arches\r
806 UnusedPcd = sdict()\r
807 for Pa in self.AutoGenObjectList:\r
808 # Key of DSC's Pcds dictionary is PcdCName, TokenSpaceGuid\r
809 for Pcd in Pa.Platform.Pcds:\r
810 PcdType = Pa.Platform.Pcds[Pcd].Type\r
47fea6af 811\r
4234283c
LG
812 # If no PCD type, this PCD comes from FDF \r
813 if not PcdType:\r
814 continue\r
47fea6af 815\r
4234283c
LG
816 # Try to remove Hii and Vpd suffix\r
817 if PcdType.startswith("DynamicEx"):\r
818 PcdType = "DynamicEx"\r
819 elif PcdType.startswith("Dynamic"):\r
820 PcdType = "Dynamic"\r
47fea6af 821\r
4234283c
LG
822 for Package in Pa.PackageList:\r
823 # Key of DEC's Pcds dictionary is PcdCName, TokenSpaceGuid, PcdType\r
824 if (Pcd[0], Pcd[1], PcdType) in Package.Pcds:\r
825 break\r
826 for Type in PcdTypeList:\r
827 if (Pcd[0], Pcd[1], Type) in Package.Pcds:\r
828 EdkLogger.error(\r
829 'build',\r
830 FORMAT_INVALID,\r
831 "Type [%s] of PCD [%s.%s] in DSC file doesn't match the type [%s] defined in DEC file." \\r
832 % (Pa.Platform.Pcds[Pcd].Type, Pcd[1], Pcd[0], Type),\r
833 ExtraData=None\r
834 )\r
835 return\r
836 else:\r
837 UnusedPcd.setdefault(Pcd, []).append(Pa.Arch)\r
838\r
839 for Pcd in UnusedPcd:\r
840 EdkLogger.warn(\r
841 'build',\r
842 "The PCD was not specified by any INF module in the platform for the given architecture.\n"\r
843 "\tPCD: [%s.%s]\n\tPlatform: [%s]\n\tArch: %s"\r
844 % (Pcd[1], Pcd[0], os.path.basename(str(self.MetaFile)), str(UnusedPcd[Pcd])),\r
845 ExtraData=None\r
846 )\r
847\r
52302d4d
LG
848 def __repr__(self):\r
849 return "%s [%s]" % (self.MetaFile, ", ".join(self.ArchList))\r
850\r
851 ## Return the directory to store FV files\r
852 def _GetFvDir(self):\r
853 if self._FvDir == None:\r
854 self._FvDir = path.join(self.BuildDir, 'FV')\r
855 return self._FvDir\r
856\r
857 ## Return the directory to store all intermediate and final files built\r
858 def _GetBuildDir(self):\r
859 return self.AutoGenObjectList[0].BuildDir\r
860\r
861 ## Return the build output directory platform specifies\r
862 def _GetOutputDir(self):\r
863 return self.Platform.OutputDirectory\r
864\r
865 ## Return platform name\r
866 def _GetName(self):\r
867 return self.Platform.PlatformName\r
868\r
869 ## Return meta-file GUID\r
870 def _GetGuid(self):\r
871 return self.Platform.Guid\r
872\r
873 ## Return platform version\r
874 def _GetVersion(self):\r
875 return self.Platform.Version\r
876\r
877 ## Return paths of tools\r
878 def _GetToolDefinition(self):\r
879 return self.AutoGenObjectList[0].ToolDefinition\r
880\r
881 ## Return directory of platform makefile\r
882 #\r
883 # @retval string Makefile directory\r
884 #\r
885 def _GetMakeFileDir(self):\r
886 if self._MakeFileDir == None:\r
887 self._MakeFileDir = self.BuildDir\r
888 return self._MakeFileDir\r
889\r
890 ## Return build command string\r
891 #\r
892 # @retval string Build command string\r
893 #\r
894 def _GetBuildCommand(self):\r
895 if self._BuildCommand == None:\r
896 # BuildCommand should be all the same. So just get one from platform AutoGen\r
897 self._BuildCommand = self.AutoGenObjectList[0].BuildCommand\r
898 return self._BuildCommand\r
47fea6af 899\r
6780eef1
LG
900 ## Check the PCDs token value conflict in each DEC file.\r
901 #\r
902 # Will cause build break and raise error message while two PCDs conflict.\r
903 # \r
904 # @return None\r
905 #\r
906 def _CheckAllPcdsTokenValueConflict(self):\r
b36d134f
LG
907 for Pa in self.AutoGenObjectList:\r
908 for Package in Pa.PackageList:\r
6780eef1 909 PcdList = Package.Pcds.values()\r
f827cd07 910 PcdList.sort(lambda x, y: cmp(int(x.TokenValue, 0), int(y.TokenValue, 0))) \r
6780eef1
LG
911 Count = 0\r
912 while (Count < len(PcdList) - 1) :\r
913 Item = PcdList[Count]\r
914 ItemNext = PcdList[Count + 1]\r
915 #\r
916 # Make sure in the same token space the TokenValue should be unique\r
917 #\r
f827cd07 918 if (int(Item.TokenValue, 0) == int(ItemNext.TokenValue, 0)):\r
6780eef1
LG
919 SameTokenValuePcdList = []\r
920 SameTokenValuePcdList.append(Item)\r
921 SameTokenValuePcdList.append(ItemNext)\r
922 RemainPcdListLength = len(PcdList) - Count - 2\r
923 for ValueSameCount in range(RemainPcdListLength):\r
f827cd07 924 if int(PcdList[len(PcdList) - RemainPcdListLength + ValueSameCount].TokenValue, 0) == int(Item.TokenValue, 0):\r
6780eef1
LG
925 SameTokenValuePcdList.append(PcdList[len(PcdList) - RemainPcdListLength + ValueSameCount])\r
926 else:\r
927 break;\r
928 #\r
929 # Sort same token value PCD list with TokenGuid and TokenCName\r
930 #\r
47fea6af
YZ
931 SameTokenValuePcdList.sort(lambda x, y: cmp("%s.%s" % (x.TokenSpaceGuidCName, x.TokenCName), "%s.%s" % (y.TokenSpaceGuidCName, y.TokenCName)))\r
932 SameTokenValuePcdListCount = 0\r
6780eef1 933 while (SameTokenValuePcdListCount < len(SameTokenValuePcdList) - 1):\r
2a29017e 934 Flag = False\r
47fea6af
YZ
935 TemListItem = SameTokenValuePcdList[SameTokenValuePcdListCount]\r
936 TemListItemNext = SameTokenValuePcdList[SameTokenValuePcdListCount + 1]\r
937\r
6780eef1 938 if (TemListItem.TokenSpaceGuidCName == TemListItemNext.TokenSpaceGuidCName) and (TemListItem.TokenCName != TemListItemNext.TokenCName):\r
2a29017e
YZ
939 for PcdItem in GlobalData.MixedPcd:\r
940 if (TemListItem.TokenCName, TemListItem.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem] or \\r
941 (TemListItemNext.TokenCName, TemListItemNext.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
942 Flag = True\r
943 if not Flag:\r
944 EdkLogger.error(\r
945 'build',\r
946 FORMAT_INVALID,\r
947 "The TokenValue [%s] of PCD [%s.%s] is conflict with: [%s.%s] in %s"\\r
948 % (TemListItem.TokenValue, TemListItem.TokenSpaceGuidCName, TemListItem.TokenCName, TemListItemNext.TokenSpaceGuidCName, TemListItemNext.TokenCName, Package),\r
949 ExtraData=None\r
950 )\r
6780eef1
LG
951 SameTokenValuePcdListCount += 1\r
952 Count += SameTokenValuePcdListCount\r
953 Count += 1\r
47fea6af 954\r
6780eef1 955 PcdList = Package.Pcds.values()\r
47fea6af 956 PcdList.sort(lambda x, y: cmp("%s.%s" % (x.TokenSpaceGuidCName, x.TokenCName), "%s.%s" % (y.TokenSpaceGuidCName, y.TokenCName)))\r
6780eef1
LG
957 Count = 0\r
958 while (Count < len(PcdList) - 1) :\r
959 Item = PcdList[Count]\r
47fea6af 960 ItemNext = PcdList[Count + 1]\r
6780eef1
LG
961 #\r
962 # Check PCDs with same TokenSpaceGuidCName.TokenCName have same token value as well.\r
963 #\r
f827cd07 964 if (Item.TokenSpaceGuidCName == ItemNext.TokenSpaceGuidCName) and (Item.TokenCName == ItemNext.TokenCName) and (int(Item.TokenValue, 0) != int(ItemNext.TokenValue, 0)):\r
6780eef1
LG
965 EdkLogger.error(\r
966 'build',\r
967 FORMAT_INVALID,\r
968 "The TokenValue [%s] of PCD [%s.%s] in %s defined in two places should be same as well."\\r
969 % (Item.TokenValue, Item.TokenSpaceGuidCName, Item.TokenCName, Package),\r
970 ExtraData=None\r
971 )\r
972 Count += 1\r
97fa0ee9 973 ## Generate fds command\r
03af2753
HC
974 def _GenFdsCommand(self):\r
975 return (GenMake.TopLevelMakefile(self)._TEMPLATE_.Replace(GenMake.TopLevelMakefile(self)._TemplateDict)).strip()\r
52302d4d 976\r
e56468c0 977 ## Create makefile for the platform and modules in it\r
52302d4d
LG
978 #\r
979 # @param CreateDepsMakeFile Flag indicating if the makefile for\r
980 # modules will be created as well\r
981 #\r
982 def CreateMakeFile(self, CreateDepsMakeFile=False):\r
52302d4d
LG
983 if CreateDepsMakeFile:\r
984 for Pa in self.AutoGenObjectList:\r
985 Pa.CreateMakeFile(CreateDepsMakeFile)\r
986\r
987 ## Create autogen code for platform and modules\r
988 #\r
989 # Since there's no autogen code for platform, this method will do nothing\r
990 # if CreateModuleCodeFile is set to False.\r
991 #\r
992 # @param CreateDepsCodeFile Flag indicating if creating module's\r
993 # autogen code file or not\r
994 #\r
995 def CreateCodeFile(self, CreateDepsCodeFile=False):\r
996 if not CreateDepsCodeFile:\r
997 return\r
998 for Pa in self.AutoGenObjectList:\r
999 Pa.CreateCodeFile(CreateDepsCodeFile)\r
1000\r
7c1fd323
LG
1001 ## Create AsBuilt INF file the platform\r
1002 #\r
1003 def CreateAsBuiltInf(self):\r
1004 return\r
1005\r
52302d4d
LG
1006 Name = property(_GetName)\r
1007 Guid = property(_GetGuid)\r
1008 Version = property(_GetVersion)\r
1009 OutputDir = property(_GetOutputDir)\r
1010\r
1011 ToolDefinition = property(_GetToolDefinition) # toolcode : tool path\r
1012\r
1013 BuildDir = property(_GetBuildDir)\r
1014 FvDir = property(_GetFvDir)\r
1015 MakeFileDir = property(_GetMakeFileDir)\r
1016 BuildCommand = property(_GetBuildCommand)\r
03af2753 1017 GenFdsCommand = property(_GenFdsCommand)\r
52302d4d
LG
1018\r
1019## AutoGen class for platform\r
1020#\r
1021# PlatformAutoGen class will process the original information in platform\r
1022# file in order to generate makefile for platform.\r
1023#\r
1024class PlatformAutoGen(AutoGen):\r
1025 #\r
1026 # Used to store all PCDs for both PEI and DXE phase, in order to generate \r
1027 # correct PCD database\r
1028 # \r
1029 _DynaPcdList_ = []\r
1030 _NonDynaPcdList_ = []\r
61ee1dff 1031 _PlatformPcds = {}\r
6780eef1
LG
1032 \r
1033 #\r
1034 # The priority list while override build option \r
1035 #\r
1036 PrioList = {"0x11111" : 16, # TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE (Highest)\r
1037 "0x01111" : 15, # ******_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE\r
1038 "0x10111" : 14, # TARGET_*********_ARCH_COMMANDTYPE_ATTRIBUTE\r
1039 "0x00111" : 13, # ******_*********_ARCH_COMMANDTYPE_ATTRIBUTE \r
1040 "0x11011" : 12, # TARGET_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE\r
1041 "0x01011" : 11, # ******_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE\r
1042 "0x10011" : 10, # TARGET_*********_****_COMMANDTYPE_ATTRIBUTE\r
1043 "0x00011" : 9, # ******_*********_****_COMMANDTYPE_ATTRIBUTE\r
1044 "0x11101" : 8, # TARGET_TOOLCHAIN_ARCH_***********_ATTRIBUTE\r
1045 "0x01101" : 7, # ******_TOOLCHAIN_ARCH_***********_ATTRIBUTE\r
1046 "0x10101" : 6, # TARGET_*********_ARCH_***********_ATTRIBUTE\r
1047 "0x00101" : 5, # ******_*********_ARCH_***********_ATTRIBUTE\r
1048 "0x11001" : 4, # TARGET_TOOLCHAIN_****_***********_ATTRIBUTE\r
1049 "0x01001" : 3, # ******_TOOLCHAIN_****_***********_ATTRIBUTE\r
1050 "0x10001" : 2, # TARGET_*********_****_***********_ATTRIBUTE\r
1051 "0x00001" : 1} # ******_*********_****_***********_ATTRIBUTE (Lowest)\r
47fea6af 1052\r
52302d4d
LG
1053 ## The real constructor of PlatformAutoGen\r
1054 #\r
1055 # This method is not supposed to be called by users of PlatformAutoGen. It's\r
1056 # only used by factory method __new__() to do real initialization work for an\r
1057 # object of PlatformAutoGen\r
1058 #\r
1059 # @param Workspace WorkspaceAutoGen object\r
1060 # @param PlatformFile Platform file (DSC file)\r
1061 # @param Target Build target (DEBUG, RELEASE)\r
1062 # @param Toolchain Name of tool chain\r
1063 # @param Arch arch of the platform supports\r
1064 #\r
1065 def _Init(self, Workspace, PlatformFile, Target, Toolchain, Arch):\r
1066 EdkLogger.debug(EdkLogger.DEBUG_9, "AutoGen platform [%s] [%s]" % (PlatformFile, Arch))\r
1067 GlobalData.gProcessingFile = "%s [%s, %s, %s]" % (PlatformFile, Arch, Toolchain, Target)\r
1068\r
1069 self.MetaFile = PlatformFile\r
1070 self.Workspace = Workspace\r
1071 self.WorkspaceDir = Workspace.WorkspaceDir\r
1072 self.ToolChain = Toolchain\r
1073 self.BuildTarget = Target\r
1074 self.Arch = Arch\r
1075 self.SourceDir = PlatformFile.SubDir\r
1076 self.SourceOverrideDir = None\r
1077 self.FdTargetList = self.Workspace.FdTargetList\r
1078 self.FvTargetList = self.Workspace.FvTargetList\r
1079 self.AllPcdList = []\r
a0a2cd1e
FB
1080 # get the original module/package/platform objects\r
1081 self.BuildDatabase = Workspace.BuildDatabase\r
52302d4d
LG
1082\r
1083 # flag indicating if the makefile/C-code file has been created or not\r
1084 self.IsMakeFileCreated = False\r
1085 self.IsCodeFileCreated = False\r
1086\r
1087 self._Platform = None\r
1088 self._Name = None\r
1089 self._Guid = None\r
1090 self._Version = None\r
1091\r
1092 self._BuildRule = None\r
1093 self._SourceDir = None\r
1094 self._BuildDir = None\r
1095 self._OutputDir = None\r
1096 self._FvDir = None\r
1097 self._MakeFileDir = None\r
1098 self._FdfFile = None\r
1099\r
1100 self._PcdTokenNumber = None # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber\r
1101 self._DynamicPcdList = None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]\r
1102 self._NonDynamicPcdList = None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]\r
2bc3256c 1103 self._NonDynamicPcdDict = {}\r
52302d4d
LG
1104\r
1105 self._ToolDefinitions = None\r
1106 self._ToolDefFile = None # toolcode : tool path\r
1107 self._ToolChainFamily = None\r
1108 self._BuildRuleFamily = None\r
1109 self._BuildOption = None # toolcode : option\r
1110 self._EdkBuildOption = None # edktoolcode : option\r
1111 self._EdkIIBuildOption = None # edkiitoolcode : option\r
1112 self._PackageList = None\r
1113 self._ModuleAutoGenList = None\r
1114 self._LibraryAutoGenList = None\r
1115 self._BuildCommand = None\r
a0a2cd1e
FB
1116 self._AsBuildInfList = []\r
1117 self._AsBuildModuleList = []\r
1118 if GlobalData.gFdfParser != None:\r
1119 self._AsBuildInfList = GlobalData.gFdfParser.Profile.InfList\r
1120 for Inf in self._AsBuildInfList:\r
1121 InfClass = PathClass(NormPath(Inf), GlobalData.gWorkspace, self.Arch)\r
1122 M = self.BuildDatabase[InfClass, self.Arch, self.BuildTarget, self.ToolChain]\r
1123 if not M.IsSupportedArch:\r
1124 continue\r
1125 self._AsBuildModuleList.append(InfClass)\r
03af2753
HC
1126 # get library/modules for build\r
1127 self.LibraryBuildDirectoryList = []\r
1128 self.ModuleBuildDirectoryList = []\r
52302d4d
LG
1129 return True\r
1130\r
1131 def __repr__(self):\r
1132 return "%s [%s]" % (self.MetaFile, self.Arch)\r
1133\r
1134 ## Create autogen code for platform and modules\r
1135 #\r
1136 # Since there's no autogen code for platform, this method will do nothing\r
1137 # if CreateModuleCodeFile is set to False.\r
1138 #\r
1139 # @param CreateModuleCodeFile Flag indicating if creating module's\r
1140 # autogen code file or not\r
1141 #\r
1142 def CreateCodeFile(self, CreateModuleCodeFile=False):\r
1143 # only module has code to be greated, so do nothing if CreateModuleCodeFile is False\r
1144 if self.IsCodeFileCreated or not CreateModuleCodeFile:\r
1145 return\r
1146\r
1147 for Ma in self.ModuleAutoGenList:\r
1148 Ma.CreateCodeFile(True)\r
1149\r
1150 # don't do this twice\r
1151 self.IsCodeFileCreated = True\r
1152\r
03af2753
HC
1153 ## Generate Fds Command\r
1154 def _GenFdsCommand(self):\r
1155 return self.Workspace.GenFdsCommand\r
481252bb 1156\r
52302d4d
LG
1157 ## Create makefile for the platform and mdoules in it\r
1158 #\r
1159 # @param CreateModuleMakeFile Flag indicating if the makefile for\r
1160 # modules will be created as well\r
1161 #\r
1162 def CreateMakeFile(self, CreateModuleMakeFile=False):\r
1163 if CreateModuleMakeFile:\r
1164 for ModuleFile in self.Platform.Modules:\r
1165 Ma = ModuleAutoGen(self.Workspace, ModuleFile, self.BuildTarget,\r
1166 self.ToolChain, self.Arch, self.MetaFile)\r
1167 Ma.CreateMakeFile(True)\r
97fa0ee9 1168 #Ma.CreateAsBuiltInf()\r
52302d4d
LG
1169\r
1170 # no need to create makefile for the platform more than once\r
1171 if self.IsMakeFileCreated:\r
1172 return\r
1173\r
03af2753 1174 # create library/module build dirs for platform\r
52302d4d 1175 Makefile = GenMake.PlatformMakefile(self)\r
03af2753
HC
1176 self.LibraryBuildDirectoryList = Makefile.GetLibraryBuildDirectoryList()\r
1177 self.ModuleBuildDirectoryList = Makefile.GetModuleBuildDirectoryList()\r
1178\r
52302d4d
LG
1179 self.IsMakeFileCreated = True\r
1180\r
2bc3256c
LG
1181 ## Deal with Shared FixedAtBuild Pcds\r
1182 #\r
1183 def CollectFixedAtBuildPcds(self):\r
1184 for LibAuto in self.LibraryAutoGenList:\r
1185 FixedAtBuildPcds = {} \r
1186 ShareFixedAtBuildPcdsSameValue = {} \r
1187 for Module in LibAuto._ReferenceModules: \r
1188 for Pcd in Module.FixedAtBuildPcds + LibAuto.FixedAtBuildPcds:\r
1189 key = ".".join((Pcd.TokenSpaceGuidCName,Pcd.TokenCName)) \r
1190 if key not in FixedAtBuildPcds:\r
1191 ShareFixedAtBuildPcdsSameValue[key] = True\r
1192 FixedAtBuildPcds[key] = Pcd.DefaultValue\r
1193 else:\r
1194 if FixedAtBuildPcds[key] != Pcd.DefaultValue:\r
1195 ShareFixedAtBuildPcdsSameValue[key] = False \r
1196 for Pcd in LibAuto.FixedAtBuildPcds:\r
1197 key = ".".join((Pcd.TokenSpaceGuidCName,Pcd.TokenCName))\r
1198 if (Pcd.TokenCName,Pcd.TokenSpaceGuidCName) not in self.NonDynamicPcdDict:\r
1199 continue\r
1200 else:\r
1201 DscPcd = self.NonDynamicPcdDict[(Pcd.TokenCName,Pcd.TokenSpaceGuidCName)]\r
1202 if DscPcd.Type != "FixedAtBuild":\r
1203 continue\r
1204 if key in ShareFixedAtBuildPcdsSameValue and ShareFixedAtBuildPcdsSameValue[key]: \r
1205 LibAuto.ConstPcd[key] = Pcd.DefaultValue\r
1206\r
52302d4d
LG
1207 ## Collect dynamic PCDs\r
1208 #\r
1209 # Gather dynamic PCDs list from each module and their settings from platform\r
1210 # This interface should be invoked explicitly when platform action is created.\r
1211 #\r
1212 def CollectPlatformDynamicPcds(self):\r
763e8edf
YZ
1213 # Override the platform Pcd's value by build option\r
1214 if GlobalData.BuildOptionPcd:\r
1215 for key in self.Platform.Pcds:\r
1216 PlatformPcd = self.Platform.Pcds[key]\r
1217 for PcdItem in GlobalData.BuildOptionPcd:\r
1218 if (PlatformPcd.TokenSpaceGuidCName, PlatformPcd.TokenCName) == (PcdItem[0], PcdItem[1]):\r
1219 PlatformPcd.DefaultValue = PcdItem[2]\r
1220 if PlatformPcd.SkuInfoList:\r
1221 Sku = PlatformPcd.SkuInfoList[PlatformPcd.SkuInfoList.keys()[0]]\r
1222 Sku.DefaultValue = PcdItem[2]\r
1223 break\r
1224\r
2a29017e
YZ
1225 for key in self.Platform.Pcds:\r
1226 for SinglePcd in GlobalData.MixedPcd:\r
1227 if (self.Platform.Pcds[key].TokenCName, self.Platform.Pcds[key].TokenSpaceGuidCName) == SinglePcd:\r
1228 for item in GlobalData.MixedPcd[SinglePcd]:\r
1229 Pcd_Type = item[0].split('_')[-1]\r
1230 if (Pcd_Type == self.Platform.Pcds[key].Type) or (Pcd_Type == TAB_PCDS_DYNAMIC_EX and self.Platform.Pcds[key].Type in GenC.gDynamicExPcd) or \\r
1231 (Pcd_Type == TAB_PCDS_DYNAMIC and self.Platform.Pcds[key].Type in GenC.gDynamicPcd):\r
1232 Value = self.Platform.Pcds[key]\r
1233 Value.TokenCName = self.Platform.Pcds[key].TokenCName + '_' + Pcd_Type\r
1234 if len(key) == 2:\r
1235 newkey = (Value.TokenCName, key[1])\r
1236 elif len(key) == 3:\r
1237 newkey = (Value.TokenCName, key[1], key[2])\r
1238 del self.Platform.Pcds[key]\r
1239 self.Platform.Pcds[newkey] = Value\r
1240 break\r
1241 else:\r
1242 pass\r
1243 break\r
1244 else:\r
1245 pass\r
1246\r
52302d4d
LG
1247 # for gathering error information\r
1248 NoDatumTypePcdList = set()\r
a0a2cd1e 1249 PcdNotInDb = []\r
52302d4d 1250 self._GuidValue = {}\r
a0a2cd1e
FB
1251 FdfModuleList = []\r
1252 for InfName in self._AsBuildInfList:\r
05cc51ad 1253 InfName = mws.join(self.WorkspaceDir, InfName)\r
a0a2cd1e 1254 FdfModuleList.append(os.path.normpath(InfName))\r
52302d4d
LG
1255 for F in self.Platform.Modules.keys():\r
1256 M = ModuleAutoGen(self.Workspace, F, self.BuildTarget, self.ToolChain, self.Arch, self.MetaFile)\r
1257 #GuidValue.update(M.Guids)\r
1258 \r
1259 self.Platform.Modules[F].M = M\r
47fea6af
YZ
1260\r
1261 for PcdFromModule in M.ModulePcdList + M.LibraryPcdList:\r
52302d4d 1262 # make sure that the "VOID*" kind of datum has MaxDatumSize set\r
e8a47801 1263 if PcdFromModule.DatumType == "VOID*" and PcdFromModule.MaxDatumSize in [None, '']:\r
52302d4d
LG
1264 NoDatumTypePcdList.add("%s.%s [%s]" % (PcdFromModule.TokenSpaceGuidCName, PcdFromModule.TokenCName, F))\r
1265\r
97fa0ee9 1266 # Check the PCD from Binary INF or Source INF\r
a0a2cd1e
FB
1267 if M.IsBinaryModule == True:\r
1268 PcdFromModule.IsFromBinaryInf = True\r
97fa0ee9
YL
1269\r
1270 # Check the PCD from DSC or not \r
a0a2cd1e
FB
1271 if (PcdFromModule.TokenCName, PcdFromModule.TokenSpaceGuidCName) in self.Platform.Pcds.keys():\r
1272 PcdFromModule.IsFromDsc = True\r
1273 else:\r
1274 PcdFromModule.IsFromDsc = False\r
52302d4d 1275 if PcdFromModule.Type in GenC.gDynamicPcd or PcdFromModule.Type in GenC.gDynamicExPcd:\r
a0a2cd1e
FB
1276 if F.Path not in FdfModuleList:\r
1277 # If one of the Source built modules listed in the DSC is not listed \r
1278 # in FDF modules, and the INF lists a PCD can only use the PcdsDynamic \r
1279 # access method (it is only listed in the DEC file that declares the \r
1280 # PCD as PcdsDynamic), then build tool will report warning message\r
1281 # notify the PI that they are attempting to build a module that must \r
1282 # be included in a flash image in order to be functional. These Dynamic \r
1283 # PCD will not be added into the Database unless it is used by other \r
1284 # modules that are included in the FDF file.\r
1285 if PcdFromModule.Type in GenC.gDynamicPcd and \\r
1286 PcdFromModule.IsFromBinaryInf == False:\r
1287 # Print warning message to let the developer make a determine.\r
1288 if PcdFromModule not in PcdNotInDb:\r
a0a2cd1e
FB
1289 PcdNotInDb.append(PcdFromModule)\r
1290 continue\r
1291 # If one of the Source built modules listed in the DSC is not listed in \r
1292 # FDF modules, and the INF lists a PCD can only use the PcdsDynamicEx \r
1293 # access method (it is only listed in the DEC file that declares the \r
1294 # PCD as PcdsDynamicEx), then DO NOT break the build; DO NOT add the \r
1295 # PCD to the Platform's PCD Database.\r
1296 if PcdFromModule.Type in GenC.gDynamicExPcd:\r
1297 if PcdFromModule not in PcdNotInDb:\r
1298 PcdNotInDb.append(PcdFromModule)\r
1299 continue\r
52302d4d
LG
1300 #\r
1301 # If a dynamic PCD used by a PEM module/PEI module & DXE module,\r
1302 # it should be stored in Pcd PEI database, If a dynamic only\r
1303 # used by DXE module, it should be stored in DXE PCD database.\r
1304 # The default Phase is DXE\r
1305 #\r
1306 if M.ModuleType in ["PEIM", "PEI_CORE"]:\r
1307 PcdFromModule.Phase = "PEI"\r
1308 if PcdFromModule not in self._DynaPcdList_:\r
1309 self._DynaPcdList_.append(PcdFromModule)\r
1310 elif PcdFromModule.Phase == 'PEI':\r
1311 # overwrite any the same PCD existing, if Phase is PEI\r
1312 Index = self._DynaPcdList_.index(PcdFromModule)\r
1313 self._DynaPcdList_[Index] = PcdFromModule\r
1314 elif PcdFromModule not in self._NonDynaPcdList_:\r
1315 self._NonDynaPcdList_.append(PcdFromModule)\r
a0a2cd1e
FB
1316 elif PcdFromModule in self._NonDynaPcdList_ and PcdFromModule.IsFromBinaryInf == True:\r
1317 Index = self._NonDynaPcdList_.index(PcdFromModule)\r
1318 if self._NonDynaPcdList_[Index].IsFromBinaryInf == False:\r
1319 #The PCD from Binary INF will override the same one from source INF\r
1320 self._NonDynaPcdList_.remove (self._NonDynaPcdList_[Index])\r
1321 PcdFromModule.Pending = False\r
1322 self._NonDynaPcdList_.append (PcdFromModule)\r
1323 # Parse the DynamicEx PCD from the AsBuild INF module list of FDF.\r
1324 DscModuleList = []\r
1325 for ModuleInf in self.Platform.Modules.keys():\r
1326 DscModuleList.append (os.path.normpath(ModuleInf.Path))\r
1327 # add the PCD from modules that listed in FDF but not in DSC to Database \r
1328 for InfName in FdfModuleList:\r
1329 if InfName not in DscModuleList:\r
1330 InfClass = PathClass(InfName)\r
1331 M = self.BuildDatabase[InfClass, self.Arch, self.BuildTarget, self.ToolChain]\r
1332 # If a module INF in FDF but not in current arch's DSC module list, it must be module (either binary or source) \r
1333 # for different Arch. PCDs in source module for different Arch is already added before, so skip the source module here. \r
1334 # For binary module, if in current arch, we need to list the PCDs into database. \r
1335 if not M.IsSupportedArch:\r
1336 continue\r
1337 # Override the module PCD setting by platform setting\r
1338 ModulePcdList = self.ApplyPcdSetting(M, M.Pcds)\r
1339 for PcdFromModule in ModulePcdList:\r
1340 PcdFromModule.IsFromBinaryInf = True\r
1341 PcdFromModule.IsFromDsc = False\r
1342 # Only allow the DynamicEx and Patchable PCD in AsBuild INF\r
1343 if PcdFromModule.Type not in GenC.gDynamicExPcd and PcdFromModule.Type not in TAB_PCDS_PATCHABLE_IN_MODULE:\r
1344 EdkLogger.error("build", AUTOGEN_ERROR, "PCD setting error",\r
1345 File=self.MetaFile,\r
1346 ExtraData="\n\tExisted %s PCD %s in:\n\t\t%s\n"\r
1347 % (PcdFromModule.Type, PcdFromModule.TokenCName, InfName))\r
1348 # make sure that the "VOID*" kind of datum has MaxDatumSize set\r
1349 if PcdFromModule.DatumType == "VOID*" and PcdFromModule.MaxDatumSize in [None, '']:\r
1350 NoDatumTypePcdList.add("%s.%s [%s]" % (PcdFromModule.TokenSpaceGuidCName, PcdFromModule.TokenCName, InfName))\r
1351 if M.ModuleType in ["PEIM", "PEI_CORE"]:\r
1352 PcdFromModule.Phase = "PEI"\r
1353 if PcdFromModule not in self._DynaPcdList_ and PcdFromModule.Type in GenC.gDynamicExPcd:\r
1354 self._DynaPcdList_.append(PcdFromModule)\r
1355 elif PcdFromModule not in self._NonDynaPcdList_ and PcdFromModule.Type in TAB_PCDS_PATCHABLE_IN_MODULE:\r
1356 self._NonDynaPcdList_.append(PcdFromModule)\r
1357 if PcdFromModule in self._DynaPcdList_ and PcdFromModule.Phase == 'PEI' and PcdFromModule.Type in GenC.gDynamicExPcd:\r
97fa0ee9
YL
1358 # Overwrite the phase of any the same PCD existing, if Phase is PEI.\r
1359 # It is to solve the case that a dynamic PCD used by a PEM module/PEI \r
1360 # module & DXE module at a same time.\r
1361 # Overwrite the type of the PCDs in source INF by the type of AsBuild\r
1362 # INF file as DynamicEx. \r
a0a2cd1e
FB
1363 Index = self._DynaPcdList_.index(PcdFromModule)\r
1364 self._DynaPcdList_[Index].Phase = PcdFromModule.Phase\r
1365 self._DynaPcdList_[Index].Type = PcdFromModule.Type\r
1366 for PcdFromModule in self._NonDynaPcdList_:\r
1367 # If a PCD is not listed in the DSC file, but binary INF files used by \r
1368 # this platform all (that use this PCD) list the PCD in a [PatchPcds] \r
1369 # section, AND all source INF files used by this platform the build \r
1370 # that use the PCD list the PCD in either a [Pcds] or [PatchPcds] \r
1371 # section, then the tools must NOT add the PCD to the Platform's PCD\r
1372 # Database; the build must assign the access method for this PCD as \r
1373 # PcdsPatchableInModule.\r
1374 if PcdFromModule not in self._DynaPcdList_:\r
1375 continue\r
1376 Index = self._DynaPcdList_.index(PcdFromModule)\r
1377 if PcdFromModule.IsFromDsc == False and \\r
1378 PcdFromModule.Type in TAB_PCDS_PATCHABLE_IN_MODULE and \\r
1379 PcdFromModule.IsFromBinaryInf == True and \\r
1380 self._DynaPcdList_[Index].IsFromBinaryInf == False:\r
1381 Index = self._DynaPcdList_.index(PcdFromModule)\r
1382 self._DynaPcdList_.remove (self._DynaPcdList_[Index])\r
52302d4d
LG
1383\r
1384 # print out error information and break the build, if error found\r
1385 if len(NoDatumTypePcdList) > 0:\r
1386 NoDatumTypePcdListString = "\n\t\t".join(NoDatumTypePcdList)\r
1387 EdkLogger.error("build", AUTOGEN_ERROR, "PCD setting error",\r
1388 File=self.MetaFile,\r
1389 ExtraData="\n\tPCD(s) without MaxDatumSize:\n\t\t%s\n"\r
1390 % NoDatumTypePcdListString)\r
1391 self._NonDynamicPcdList = self._NonDynaPcdList_\r
1392 self._DynamicPcdList = self._DynaPcdList_\r
52302d4d
LG
1393 #\r
1394 # Sort dynamic PCD list to:\r
1395 # 1) If PCD's datum type is VOID* and value is unicode string which starts with L, the PCD item should \r
1396 # try to be put header of dynamicd List\r
1397 # 2) If PCD is HII type, the PCD item should be put after unicode type PCD\r
1398 #\r
1399 # The reason of sorting is make sure the unicode string is in double-byte alignment in string table.\r
1400 #\r
1401 UnicodePcdArray = []\r
1402 HiiPcdArray = []\r
1403 OtherPcdArray = []\r
6780eef1 1404 VpdPcdDict = {}\r
e56468c0 1405 VpdFile = VpdInfoFile.VpdInfoFile()\r
61ee1dff
YZ
1406 NeedProcessVpdMapFile = False\r
1407\r
1408 for pcd in self.Platform.Pcds.keys():\r
1409 if pcd not in self._PlatformPcds.keys():\r
1410 self._PlatformPcds[pcd] = self.Platform.Pcds[pcd]\r
1411\r
e56468c0 1412 if (self.Workspace.ArchList[-1] == self.Arch): \r
1413 for Pcd in self._DynamicPcdList:\r
e56468c0 1414 # just pick the a value to determine whether is unicode string type\r
47fea6af 1415 Sku = Pcd.SkuInfoList[Pcd.SkuInfoList.keys()[0]]\r
e56468c0 1416 Sku.VpdOffset = Sku.VpdOffset.strip()\r
47fea6af 1417\r
e56468c0 1418 PcdValue = Sku.DefaultValue\r
1419 if Pcd.DatumType == 'VOID*' and PcdValue.startswith("L"):\r
1420 # if found PCD which datum value is unicode string the insert to left size of UnicodeIndex\r
1421 UnicodePcdArray.append(Pcd)\r
1422 elif len(Sku.VariableName) > 0:\r
1423 # if found HII type PCD then insert to right of UnicodeIndex\r
1424 HiiPcdArray.append(Pcd)\r
1425 else:\r
1426 OtherPcdArray.append(Pcd)\r
e56468c0 1427 if Pcd.Type in [TAB_PCDS_DYNAMIC_VPD, TAB_PCDS_DYNAMIC_EX_VPD]:\r
47fea6af
YZ
1428 VpdPcdDict[(Pcd.TokenCName, Pcd.TokenSpaceGuidCName)] = Pcd\r
1429\r
61ee1dff 1430 PlatformPcds = self._PlatformPcds.keys()\r
47fea6af 1431 PlatformPcds.sort()\r
6780eef1
LG
1432 #\r
1433 # Add VPD type PCD into VpdFile and determine whether the VPD PCD need to be fixed up.\r
1434 #\r
1435 for PcdKey in PlatformPcds:\r
61ee1dff 1436 Pcd = self._PlatformPcds[PcdKey]\r
e8a47801
LG
1437 if Pcd.Type in [TAB_PCDS_DYNAMIC_VPD, TAB_PCDS_DYNAMIC_EX_VPD] and \\r
1438 PcdKey in VpdPcdDict:\r
1439 Pcd = VpdPcdDict[PcdKey]\r
1440 for (SkuName,Sku) in Pcd.SkuInfoList.items():\r
1441 Sku.VpdOffset = Sku.VpdOffset.strip()\r
5a13737a
YZ
1442 PcdValue = Sku.DefaultValue\r
1443 if PcdValue == "":\r
1444 PcdValue = Pcd.DefaultValue\r
1445 if Sku.VpdOffset != '*':\r
1446 if PcdValue.startswith("{"):\r
1447 Alignment = 8\r
1448 elif PcdValue.startswith("L"):\r
1449 Alignment = 2\r
1450 else:\r
1451 Alignment = 1\r
ca85291f
YZ
1452 try:\r
1453 VpdOffset = int(Sku.VpdOffset)\r
1454 except:\r
1455 try:\r
1456 VpdOffset = int(Sku.VpdOffset, 16)\r
1457 except:\r
1458 EdkLogger.error("build", FORMAT_INVALID, "Invalid offset value %s for PCD %s.%s." % (Sku.VpdOffset, Pcd.TokenSpaceGuidCName, Pcd.TokenCName))\r
1459 if VpdOffset % Alignment != 0:\r
815ada26
YZ
1460 if PcdValue.startswith("{"):\r
1461 EdkLogger.warn("build", "The offset value of PCD %s.%s is not 8-byte aligned!" %(Pcd.TokenSpaceGuidCName, Pcd.TokenCName), File=self.MetaFile)\r
1462 else:\r
1463 EdkLogger.error("build", FORMAT_INVALID, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, Alignment))\r
e8a47801
LG
1464 VpdFile.Add(Pcd, Sku.VpdOffset)\r
1465 # if the offset of a VPD is *, then it need to be fixed up by third party tool.\r
1466 if not NeedProcessVpdMapFile and Sku.VpdOffset == "*":\r
1467 NeedProcessVpdMapFile = True\r
1468 if self.Platform.VpdToolGuid == None or self.Platform.VpdToolGuid == '':\r
1469 EdkLogger.error("Build", FILE_NOT_FOUND, \\r
1470 "Fail to find third-party BPDG tool to process VPD PCDs. BPDG Guid tool need to be defined in tools_def.txt and VPD_TOOL_GUID need to be provided in DSC file.")\r
47fea6af
YZ
1471\r
1472\r
e56468c0 1473 #\r
1474 # Fix the PCDs define in VPD PCD section that never referenced by module.\r
1475 # An example is PCD for signature usage.\r
6780eef1
LG
1476 # \r
1477 for DscPcd in PlatformPcds:\r
61ee1dff 1478 DscPcdEntry = self._PlatformPcds[DscPcd]\r
e56468c0 1479 if DscPcdEntry.Type in [TAB_PCDS_DYNAMIC_VPD, TAB_PCDS_DYNAMIC_EX_VPD]:\r
1480 if not (self.Platform.VpdToolGuid == None or self.Platform.VpdToolGuid == ''):\r
1481 FoundFlag = False\r
1482 for VpdPcd in VpdFile._VpdArray.keys():\r
1483 # This PCD has been referenced by module\r
1484 if (VpdPcd.TokenSpaceGuidCName == DscPcdEntry.TokenSpaceGuidCName) and \\r
1485 (VpdPcd.TokenCName == DscPcdEntry.TokenCName):\r
1486 FoundFlag = True\r
47fea6af 1487\r
e56468c0 1488 # Not found, it should be signature\r
1489 if not FoundFlag :\r
1490 # just pick the a value to determine whether is unicode string type\r
e8a47801
LG
1491 for (SkuName,Sku) in DscPcdEntry.SkuInfoList.items():\r
1492 Sku.VpdOffset = Sku.VpdOffset.strip() \r
1493 \r
1494 # Need to iterate DEC pcd information to get the value & datumtype\r
1495 for eachDec in self.PackageList:\r
1496 for DecPcd in eachDec.Pcds:\r
1497 DecPcdEntry = eachDec.Pcds[DecPcd]\r
1498 if (DecPcdEntry.TokenSpaceGuidCName == DscPcdEntry.TokenSpaceGuidCName) and \\r
1499 (DecPcdEntry.TokenCName == DscPcdEntry.TokenCName):\r
1500 # Print warning message to let the developer make a determine.\r
1501 EdkLogger.warn("build", "Unreferenced vpd pcd used!",\r
1502 File=self.MetaFile, \\r
1503 ExtraData = "PCD: %s.%s used in the DSC file %s is unreferenced." \\r
1504 %(DscPcdEntry.TokenSpaceGuidCName, DscPcdEntry.TokenCName, self.Platform.MetaFile.Path)) \r
1505 \r
1506 DscPcdEntry.DatumType = DecPcdEntry.DatumType\r
1507 DscPcdEntry.DefaultValue = DecPcdEntry.DefaultValue\r
1508 DscPcdEntry.TokenValue = DecPcdEntry.TokenValue\r
1509 DscPcdEntry.TokenSpaceGuidValue = eachDec.Guids[DecPcdEntry.TokenSpaceGuidCName]\r
1510 # Only fix the value while no value provided in DSC file.\r
1511 if (Sku.DefaultValue == "" or Sku.DefaultValue==None):\r
1512 DscPcdEntry.SkuInfoList[DscPcdEntry.SkuInfoList.keys()[0]].DefaultValue = DecPcdEntry.DefaultValue\r
1513 \r
1514 if DscPcdEntry not in self._DynamicPcdList:\r
1515 self._DynamicPcdList.append(DscPcdEntry)\r
1516# Sku = DscPcdEntry.SkuInfoList[DscPcdEntry.SkuInfoList.keys()[0]]\r
1517 Sku.VpdOffset = Sku.VpdOffset.strip()\r
1518 PcdValue = Sku.DefaultValue\r
5a13737a
YZ
1519 if PcdValue == "":\r
1520 PcdValue = DscPcdEntry.DefaultValue\r
1521 if Sku.VpdOffset != '*':\r
1522 if PcdValue.startswith("{"):\r
1523 Alignment = 8\r
1524 elif PcdValue.startswith("L"):\r
1525 Alignment = 2\r
1526 else:\r
1527 Alignment = 1\r
ca85291f
YZ
1528 try:\r
1529 VpdOffset = int(Sku.VpdOffset)\r
1530 except:\r
1531 try:\r
1532 VpdOffset = int(Sku.VpdOffset, 16)\r
1533 except:\r
1534 EdkLogger.error("build", FORMAT_INVALID, "Invalid offset value %s for PCD %s.%s." % (Sku.VpdOffset, DscPcdEntry.TokenSpaceGuidCName, DscPcdEntry.TokenCName))\r
1535 if VpdOffset % Alignment != 0:\r
815ada26
YZ
1536 if PcdValue.startswith("{"):\r
1537 EdkLogger.warn("build", "The offset value of PCD %s.%s is not 8-byte aligned!" %(DscPcdEntry.TokenSpaceGuidCName, DscPcdEntry.TokenCName), File=self.MetaFile)\r
1538 else:\r
1539 EdkLogger.error("build", FORMAT_INVALID, 'The offset value of PCD %s.%s should be %s-byte aligned.' % (DscPcdEntry.TokenSpaceGuidCName, DscPcdEntry.TokenCName, Alignment))\r
e8a47801
LG
1540 VpdFile.Add(DscPcdEntry, Sku.VpdOffset)\r
1541 if not NeedProcessVpdMapFile and Sku.VpdOffset == "*":\r
1542 NeedProcessVpdMapFile = True \r
1543 if DscPcdEntry.DatumType == 'VOID*' and PcdValue.startswith("L"):\r
1544 UnicodePcdArray.append(DscPcdEntry)\r
1545 elif len(Sku.VariableName) > 0:\r
1546 HiiPcdArray.append(DscPcdEntry)\r
1547 else:\r
1548 OtherPcdArray.append(DscPcdEntry)\r
1549 \r
1550 # if the offset of a VPD is *, then it need to be fixed up by third party tool.\r
e56468c0 1551 \r
e56468c0 1552 \r
1553 \r
1554 if (self.Platform.FlashDefinition == None or self.Platform.FlashDefinition == '') and \\r
1555 VpdFile.GetCount() != 0:\r
1556 EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, \r
1557 "Fail to get FLASH_DEFINITION definition in DSC file %s which is required when DSC contains VPD PCD." % str(self.Platform.MetaFile))\r
47fea6af 1558\r
e56468c0 1559 if VpdFile.GetCount() != 0:\r
e56468c0 1560 FvPath = os.path.join(self.BuildDir, "FV")\r
1561 if not os.path.exists(FvPath):\r
1562 try:\r
1563 os.makedirs(FvPath)\r
1564 except:\r
1565 EdkLogger.error("build", FILE_WRITE_FAILURE, "Fail to create FV folder under %s" % self.BuildDir)\r
47fea6af 1566\r
08dd311f
LG
1567 VpdFilePath = os.path.join(FvPath, "%s.txt" % self.Platform.VpdToolGuid)\r
1568\r
e459de78 1569 if VpdFile.Write(VpdFilePath):\r
e56468c0 1570 # retrieve BPDG tool's path from tool_def.txt according to VPD_TOOL_GUID defined in DSC file.\r
1571 BPDGToolName = None\r
1572 for ToolDef in self.ToolDefinition.values():\r
1573 if ToolDef.has_key("GUID") and ToolDef["GUID"] == self.Platform.VpdToolGuid:\r
1574 if not ToolDef.has_key("PATH"):\r
1575 EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, "PATH attribute was not provided for BPDG guid tool %s in tools_def.txt" % self.Platform.VpdToolGuid)\r
1576 BPDGToolName = ToolDef["PATH"]\r
1577 break\r
1578 # Call third party GUID BPDG tool.\r
1579 if BPDGToolName != None:\r
08dd311f 1580 VpdInfoFile.CallExtenalBPDGTool(BPDGToolName, VpdFilePath)\r
e56468c0 1581 else:\r
1582 EdkLogger.error("Build", FILE_NOT_FOUND, "Fail to find third-party BPDG tool to process VPD PCDs. BPDG Guid tool need to be defined in tools_def.txt and VPD_TOOL_GUID need to be provided in DSC file.")\r
47fea6af 1583\r
e56468c0 1584 # Process VPD map file generated by third party BPDG tool\r
1585 if NeedProcessVpdMapFile:\r
08dd311f 1586 VpdMapFilePath = os.path.join(self.BuildDir, "FV", "%s.map" % self.Platform.VpdToolGuid)\r
e56468c0 1587 if os.path.exists(VpdMapFilePath):\r
1588 VpdFile.Read(VpdMapFilePath)\r
47fea6af 1589\r
e56468c0 1590 # Fixup "*" offset\r
1591 for Pcd in self._DynamicPcdList:\r
1592 # just pick the a value to determine whether is unicode string type\r
e8a47801
LG
1593 i = 0\r
1594 for (SkuName,Sku) in Pcd.SkuInfoList.items(): \r
1595 if Sku.VpdOffset == "*":\r
1596 Sku.VpdOffset = VpdFile.GetOffset(Pcd)[i].strip()\r
1597 i += 1\r
e56468c0 1598 else:\r
1599 EdkLogger.error("build", FILE_READ_FAILURE, "Can not find VPD map file %s to fix up VPD offset." % VpdMapFilePath)\r
47fea6af 1600\r
e56468c0 1601 # Delete the DynamicPcdList At the last time enter into this function \r
47fea6af 1602 del self._DynamicPcdList[:]\r
52302d4d
LG
1603 self._DynamicPcdList.extend(UnicodePcdArray)\r
1604 self._DynamicPcdList.extend(HiiPcdArray)\r
1605 self._DynamicPcdList.extend(OtherPcdArray)\r
a0a2cd1e 1606 self.AllPcdList = self._NonDynamicPcdList + self._DynamicPcdList\r
52302d4d
LG
1607 \r
1608 ## Return the platform build data object\r
1609 def _GetPlatform(self):\r
1610 if self._Platform == None:\r
0d2711a6 1611 self._Platform = self.BuildDatabase[self.MetaFile, self.Arch, self.BuildTarget, self.ToolChain]\r
52302d4d
LG
1612 return self._Platform\r
1613\r
1614 ## Return platform name\r
1615 def _GetName(self):\r
1616 return self.Platform.PlatformName\r
1617\r
1618 ## Return the meta file GUID\r
1619 def _GetGuid(self):\r
1620 return self.Platform.Guid\r
1621\r
1622 ## Return the platform version\r
1623 def _GetVersion(self):\r
1624 return self.Platform.Version\r
1625\r
1626 ## Return the FDF file name\r
1627 def _GetFdfFile(self):\r
1628 if self._FdfFile == None:\r
1629 if self.Workspace.FdfFile != "":\r
05cc51ad 1630 self._FdfFile= mws.join(self.WorkspaceDir, self.Workspace.FdfFile)\r
52302d4d
LG
1631 else:\r
1632 self._FdfFile = ''\r
1633 return self._FdfFile\r
1634\r
1635 ## Return the build output directory platform specifies\r
1636 def _GetOutputDir(self):\r
1637 return self.Platform.OutputDirectory\r
1638\r
1639 ## Return the directory to store all intermediate and final files built\r
1640 def _GetBuildDir(self):\r
1641 if self._BuildDir == None:\r
1642 if os.path.isabs(self.OutputDir):\r
1643 self._BuildDir = path.join(\r
1644 path.abspath(self.OutputDir),\r
1645 self.BuildTarget + "_" + self.ToolChain,\r
1646 )\r
1647 else:\r
1648 self._BuildDir = path.join(\r
1649 self.WorkspaceDir,\r
1650 self.OutputDir,\r
1651 self.BuildTarget + "_" + self.ToolChain,\r
1652 )\r
1653 return self._BuildDir\r
1654\r
1655 ## Return directory of platform makefile\r
1656 #\r
1657 # @retval string Makefile directory\r
1658 #\r
1659 def _GetMakeFileDir(self):\r
1660 if self._MakeFileDir == None:\r
1661 self._MakeFileDir = path.join(self.BuildDir, self.Arch)\r
1662 return self._MakeFileDir\r
1663\r
1664 ## Return build command string\r
1665 #\r
1666 # @retval string Build command string\r
1667 #\r
1668 def _GetBuildCommand(self):\r
1669 if self._BuildCommand == None:\r
1670 self._BuildCommand = []\r
1671 if "MAKE" in self.ToolDefinition and "PATH" in self.ToolDefinition["MAKE"]:\r
1672 self._BuildCommand += SplitOption(self.ToolDefinition["MAKE"]["PATH"])\r
1673 if "FLAGS" in self.ToolDefinition["MAKE"]:\r
1674 NewOption = self.ToolDefinition["MAKE"]["FLAGS"].strip()\r
1675 if NewOption != '':\r
6780eef1 1676 self._BuildCommand += SplitOption(NewOption)\r
52302d4d
LG
1677 return self._BuildCommand\r
1678\r
1679 ## Get tool chain definition\r
1680 #\r
1681 # Get each tool defition for given tool chain from tools_def.txt and platform\r
1682 #\r
1683 def _GetToolDefinition(self):\r
1684 if self._ToolDefinitions == None:\r
1685 ToolDefinition = self.Workspace.ToolDef.ToolsDefTxtDictionary\r
1686 if TAB_TOD_DEFINES_COMMAND_TYPE not in self.Workspace.ToolDef.ToolsDefTxtDatabase:\r
1687 EdkLogger.error('build', RESOURCE_NOT_AVAILABLE, "No tools found in configuration",\r
1688 ExtraData="[%s]" % self.MetaFile)\r
1689 self._ToolDefinitions = {}\r
1690 DllPathList = set()\r
1691 for Def in ToolDefinition:\r
1692 Target, Tag, Arch, Tool, Attr = Def.split("_")\r
1693 if Target != self.BuildTarget or Tag != self.ToolChain or Arch != self.Arch:\r
1694 continue\r
1695\r
1696 Value = ToolDefinition[Def]\r
1697 # don't record the DLL\r
1698 if Attr == "DLL":\r
1699 DllPathList.add(Value)\r
1700 continue\r
1701\r
1702 if Tool not in self._ToolDefinitions:\r
1703 self._ToolDefinitions[Tool] = {}\r
1704 self._ToolDefinitions[Tool][Attr] = Value\r
1705\r
1706 ToolsDef = ''\r
1707 MakePath = ''\r
1708 if GlobalData.gOptions.SilentMode and "MAKE" in self._ToolDefinitions:\r
1709 if "FLAGS" not in self._ToolDefinitions["MAKE"]:\r
1710 self._ToolDefinitions["MAKE"]["FLAGS"] = ""\r
1711 self._ToolDefinitions["MAKE"]["FLAGS"] += " -s"\r
1712 MakeFlags = ''\r
1713 for Tool in self._ToolDefinitions:\r
1714 for Attr in self._ToolDefinitions[Tool]:\r
1715 Value = self._ToolDefinitions[Tool][Attr]\r
1716 if Tool in self.BuildOption and Attr in self.BuildOption[Tool]:\r
1717 # check if override is indicated\r
1718 if self.BuildOption[Tool][Attr].startswith('='):\r
1719 Value = self.BuildOption[Tool][Attr][1:]\r
1720 else:\r
1721 Value += " " + self.BuildOption[Tool][Attr]\r
1722\r
1723 if Attr == "PATH":\r
1724 # Don't put MAKE definition in the file\r
1725 if Tool == "MAKE":\r
1726 MakePath = Value\r
1727 else:\r
1728 ToolsDef += "%s = %s\n" % (Tool, Value)\r
1729 elif Attr != "DLL":\r
1730 # Don't put MAKE definition in the file\r
1731 if Tool == "MAKE":\r
1732 if Attr == "FLAGS":\r
1733 MakeFlags = Value\r
1734 else:\r
1735 ToolsDef += "%s_%s = %s\n" % (Tool, Attr, Value)\r
1736 ToolsDef += "\n"\r
1737\r
1738 SaveFileOnChange(self.ToolDefinitionFile, ToolsDef)\r
1739 for DllPath in DllPathList:\r
1740 os.environ["PATH"] = DllPath + os.pathsep + os.environ["PATH"]\r
1741 os.environ["MAKE_FLAGS"] = MakeFlags\r
1742\r
1743 return self._ToolDefinitions\r
1744\r
1745 ## Return the paths of tools\r
1746 def _GetToolDefFile(self):\r
1747 if self._ToolDefFile == None:\r
1748 self._ToolDefFile = os.path.join(self.MakeFileDir, "TOOLS_DEF." + self.Arch)\r
1749 return self._ToolDefFile\r
1750\r
1751 ## Retrieve the toolchain family of given toolchain tag. Default to 'MSFT'.\r
1752 def _GetToolChainFamily(self):\r
1753 if self._ToolChainFamily == None:\r
1754 ToolDefinition = self.Workspace.ToolDef.ToolsDefTxtDatabase\r
1755 if TAB_TOD_DEFINES_FAMILY not in ToolDefinition \\r
1756 or self.ToolChain not in ToolDefinition[TAB_TOD_DEFINES_FAMILY] \\r
1757 or not ToolDefinition[TAB_TOD_DEFINES_FAMILY][self.ToolChain]:\r
1758 EdkLogger.verbose("No tool chain family found in configuration for %s. Default to MSFT." \\r
1759 % self.ToolChain)\r
1760 self._ToolChainFamily = "MSFT"\r
1761 else:\r
1762 self._ToolChainFamily = ToolDefinition[TAB_TOD_DEFINES_FAMILY][self.ToolChain]\r
1763 return self._ToolChainFamily\r
1764\r
1765 def _GetBuildRuleFamily(self):\r
1766 if self._BuildRuleFamily == None:\r
1767 ToolDefinition = self.Workspace.ToolDef.ToolsDefTxtDatabase\r
1768 if TAB_TOD_DEFINES_BUILDRULEFAMILY not in ToolDefinition \\r
1769 or self.ToolChain not in ToolDefinition[TAB_TOD_DEFINES_BUILDRULEFAMILY] \\r
1770 or not ToolDefinition[TAB_TOD_DEFINES_BUILDRULEFAMILY][self.ToolChain]:\r
1771 EdkLogger.verbose("No tool chain family found in configuration for %s. Default to MSFT." \\r
1772 % self.ToolChain)\r
1773 self._BuildRuleFamily = "MSFT"\r
1774 else:\r
1775 self._BuildRuleFamily = ToolDefinition[TAB_TOD_DEFINES_BUILDRULEFAMILY][self.ToolChain]\r
1776 return self._BuildRuleFamily\r
1777\r
1778 ## Return the build options specific for all modules in this platform\r
1779 def _GetBuildOptions(self):\r
1780 if self._BuildOption == None:\r
1781 self._BuildOption = self._ExpandBuildOption(self.Platform.BuildOptions)\r
1782 return self._BuildOption\r
1783\r
1784 ## Return the build options specific for EDK modules in this platform\r
1785 def _GetEdkBuildOptions(self):\r
1786 if self._EdkBuildOption == None:\r
1787 self._EdkBuildOption = self._ExpandBuildOption(self.Platform.BuildOptions, EDK_NAME)\r
1788 return self._EdkBuildOption\r
1789\r
1790 ## Return the build options specific for EDKII modules in this platform\r
1791 def _GetEdkIIBuildOptions(self):\r
1792 if self._EdkIIBuildOption == None:\r
1793 self._EdkIIBuildOption = self._ExpandBuildOption(self.Platform.BuildOptions, EDKII_NAME)\r
1794 return self._EdkIIBuildOption\r
1795\r
97fa0ee9 1796 ## Parse build_rule.txt in Conf Directory.\r
52302d4d
LG
1797 #\r
1798 # @retval BuildRule object\r
1799 #\r
1800 def _GetBuildRule(self):\r
1801 if self._BuildRule == None:\r
1802 BuildRuleFile = None\r
1803 if TAB_TAT_DEFINES_BUILD_RULE_CONF in self.Workspace.TargetTxt.TargetTxtDictionary:\r
1804 BuildRuleFile = self.Workspace.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_BUILD_RULE_CONF]\r
1805 if BuildRuleFile in [None, '']:\r
97fa0ee9 1806 BuildRuleFile = gDefaultBuildRuleFile\r
52302d4d 1807 self._BuildRule = BuildRule(BuildRuleFile)\r
64b2609f
LG
1808 if self._BuildRule._FileVersion == "":\r
1809 self._BuildRule._FileVersion = AutoGenReqBuildRuleVerNum\r
1810 else:\r
1811 if self._BuildRule._FileVersion < AutoGenReqBuildRuleVerNum :\r
1812 # If Build Rule's version is less than the version number required by the tools, halting the build.\r
47fea6af 1813 EdkLogger.error("build", AUTOGEN_ERROR,\r
64b2609f
LG
1814 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
1815 % (self._BuildRule._FileVersion, AutoGenReqBuildRuleVerNum))\r
47fea6af 1816\r
52302d4d
LG
1817 return self._BuildRule\r
1818\r
1819 ## Summarize the packages used by modules in this platform\r
1820 def _GetPackageList(self):\r
1821 if self._PackageList == None:\r
1822 self._PackageList = set()\r
1823 for La in self.LibraryAutoGenList:\r
1824 self._PackageList.update(La.DependentPackageList)\r
1825 for Ma in self.ModuleAutoGenList:\r
1826 self._PackageList.update(Ma.DependentPackageList)\r
a0a2cd1e
FB
1827 #Collect package set information from INF of FDF\r
1828 PkgSet = set()\r
1829 for ModuleFile in self._AsBuildModuleList:\r
1830 if ModuleFile in self.Platform.Modules:\r
1831 continue\r
1832 ModuleData = self.BuildDatabase[ModuleFile, self.Arch, self.BuildTarget, self.ToolChain]\r
1833 PkgSet.update(ModuleData.Packages)\r
1834 self._PackageList = list(self._PackageList) + list (PkgSet)\r
52302d4d
LG
1835 return self._PackageList\r
1836\r
2bc3256c
LG
1837 def _GetNonDynamicPcdDict(self):\r
1838 if self._NonDynamicPcdDict:\r
1839 return self._NonDynamicPcdDict\r
1840 for Pcd in self.NonDynamicPcdList:\r
1841 self._NonDynamicPcdDict[(Pcd.TokenCName,Pcd.TokenSpaceGuidCName)] = Pcd\r
1842 return self._NonDynamicPcdDict\r
1843\r
52302d4d
LG
1844 ## Get list of non-dynamic PCDs\r
1845 def _GetNonDynamicPcdList(self):\r
e56468c0 1846 if self._NonDynamicPcdList == None:\r
1847 self.CollectPlatformDynamicPcds()\r
52302d4d
LG
1848 return self._NonDynamicPcdList\r
1849\r
1850 ## Get list of dynamic PCDs\r
1851 def _GetDynamicPcdList(self):\r
e56468c0 1852 if self._DynamicPcdList == None:\r
1853 self.CollectPlatformDynamicPcds()\r
52302d4d
LG
1854 return self._DynamicPcdList\r
1855\r
1856 ## Generate Token Number for all PCD\r
1857 def _GetPcdTokenNumbers(self):\r
1858 if self._PcdTokenNumber == None:\r
1859 self._PcdTokenNumber = sdict()\r
1860 TokenNumber = 1\r
d0acc87a
LG
1861 #\r
1862 # Make the Dynamic and DynamicEx PCD use within different TokenNumber area. \r
1863 # Such as:\r
1864 # \r
1865 # Dynamic PCD:\r
1866 # TokenNumber 0 ~ 10\r
1867 # DynamicEx PCD:\r
1868 # TokeNumber 11 ~ 20\r
1869 #\r
52302d4d
LG
1870 for Pcd in self.DynamicPcdList:\r
1871 if Pcd.Phase == "PEI":\r
d0acc87a
LG
1872 if Pcd.Type in ["Dynamic", "DynamicDefault", "DynamicVpd", "DynamicHii"]:\r
1873 EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))\r
1874 self._PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber\r
1875 TokenNumber += 1\r
47fea6af 1876\r
d0acc87a
LG
1877 for Pcd in self.DynamicPcdList:\r
1878 if Pcd.Phase == "PEI":\r
1879 if Pcd.Type in ["DynamicEx", "DynamicExDefault", "DynamicExVpd", "DynamicExHii"]:\r
1880 EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))\r
1881 self._PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber\r
1882 TokenNumber += 1\r
47fea6af 1883\r
52302d4d
LG
1884 for Pcd in self.DynamicPcdList:\r
1885 if Pcd.Phase == "DXE":\r
d0acc87a
LG
1886 if Pcd.Type in ["Dynamic", "DynamicDefault", "DynamicVpd", "DynamicHii"]:\r
1887 EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))\r
1888 self._PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber\r
1889 TokenNumber += 1\r
47fea6af 1890\r
d0acc87a
LG
1891 for Pcd in self.DynamicPcdList:\r
1892 if Pcd.Phase == "DXE":\r
1893 if Pcd.Type in ["DynamicEx", "DynamicExDefault", "DynamicExVpd", "DynamicExHii"]:\r
1894 EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))\r
1895 self._PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber\r
1896 TokenNumber += 1\r
47fea6af 1897\r
52302d4d
LG
1898 for Pcd in self.NonDynamicPcdList:\r
1899 self._PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber\r
1900 TokenNumber += 1\r
1901 return self._PcdTokenNumber\r
1902\r
1903 ## Summarize ModuleAutoGen objects of all modules/libraries to be built for this platform\r
1904 def _GetAutoGenObjectList(self):\r
1905 self._ModuleAutoGenList = []\r
1906 self._LibraryAutoGenList = []\r
1907 for ModuleFile in self.Platform.Modules:\r
1908 Ma = ModuleAutoGen(\r
1909 self.Workspace,\r
1910 ModuleFile,\r
1911 self.BuildTarget,\r
1912 self.ToolChain,\r
1913 self.Arch,\r
1914 self.MetaFile\r
1915 )\r
1916 if Ma not in self._ModuleAutoGenList:\r
1917 self._ModuleAutoGenList.append(Ma)\r
1918 for La in Ma.LibraryAutoGenList:\r
1919 if La not in self._LibraryAutoGenList:\r
1920 self._LibraryAutoGenList.append(La)\r
2bc3256c
LG
1921 if Ma not in La._ReferenceModules:\r
1922 La._ReferenceModules.append(Ma)\r
52302d4d
LG
1923\r
1924 ## Summarize ModuleAutoGen objects of all modules to be built for this platform\r
1925 def _GetModuleAutoGenList(self):\r
1926 if self._ModuleAutoGenList == None:\r
1927 self._GetAutoGenObjectList()\r
1928 return self._ModuleAutoGenList\r
1929\r
1930 ## Summarize ModuleAutoGen objects of all libraries to be built for this platform\r
1931 def _GetLibraryAutoGenList(self):\r
1932 if self._LibraryAutoGenList == None:\r
1933 self._GetAutoGenObjectList()\r
1934 return self._LibraryAutoGenList\r
1935\r
1936 ## Test if a module is supported by the platform\r
1937 #\r
1938 # An error will be raised directly if the module or its arch is not supported\r
1939 # by the platform or current configuration\r
1940 #\r
1941 def ValidModule(self, Module):\r
a0a2cd1e
FB
1942 return Module in self.Platform.Modules or Module in self.Platform.LibraryInstances \\r
1943 or Module in self._AsBuildModuleList\r
52302d4d
LG
1944\r
1945 ## Resolve the library classes in a module to library instances\r
1946 #\r
1947 # This method will not only resolve library classes but also sort the library\r
1948 # instances according to the dependency-ship.\r
1949 #\r
1950 # @param Module The module from which the library classes will be resolved\r
1951 #\r
1952 # @retval library_list List of library instances sorted\r
1953 #\r
1954 def ApplyLibraryInstance(self, Module):\r
25193a33
YZ
1955 # Cover the case that the binary INF file is list in the FDF file but not DSC file, return empty list directly\r
1956 if str(Module) not in self.Platform.Modules:\r
1957 return []\r
1958\r
52302d4d
LG
1959 ModuleType = Module.ModuleType\r
1960\r
1961 # for overridding library instances with module specific setting\r
1962 PlatformModule = self.Platform.Modules[str(Module)]\r
1963\r
1964 # add forced library instances (specified under LibraryClasses sections)\r
da92f276
LG
1965 #\r
1966 # If a module has a MODULE_TYPE of USER_DEFINED,\r
1967 # do not link in NULL library class instances from the global [LibraryClasses.*] sections.\r
1968 #\r
1969 if Module.ModuleType != SUP_MODULE_USER_DEFINED:\r
1970 for LibraryClass in self.Platform.LibraryClasses.GetKeys():\r
1971 if LibraryClass.startswith("NULL") and self.Platform.LibraryClasses[LibraryClass, Module.ModuleType]:\r
1972 Module.LibraryClasses[LibraryClass] = self.Platform.LibraryClasses[LibraryClass, Module.ModuleType]\r
52302d4d
LG
1973\r
1974 # add forced library instances (specified in module overrides)\r
1975 for LibraryClass in PlatformModule.LibraryClasses:\r
1976 if LibraryClass.startswith("NULL"):\r
1977 Module.LibraryClasses[LibraryClass] = PlatformModule.LibraryClasses[LibraryClass]\r
1978\r
b36d134f 1979 # EdkII module\r
52302d4d
LG
1980 LibraryConsumerList = [Module]\r
1981 Constructor = []\r
1982 ConsumedByList = sdict()\r
1983 LibraryInstance = sdict()\r
1984\r
1985 EdkLogger.verbose("")\r
1986 EdkLogger.verbose("Library instances of module [%s] [%s]:" % (str(Module), self.Arch))\r
1987 while len(LibraryConsumerList) > 0:\r
1988 M = LibraryConsumerList.pop()\r
1989 for LibraryClassName in M.LibraryClasses:\r
1990 if LibraryClassName not in LibraryInstance:\r
1991 # override library instance for this module\r
1992 if LibraryClassName in PlatformModule.LibraryClasses:\r
1993 LibraryPath = PlatformModule.LibraryClasses[LibraryClassName]\r
1994 else:\r
1995 LibraryPath = self.Platform.LibraryClasses[LibraryClassName, ModuleType]\r
1996 if LibraryPath == None or LibraryPath == "":\r
1997 LibraryPath = M.LibraryClasses[LibraryClassName]\r
1998 if LibraryPath == None or LibraryPath == "":\r
1999 EdkLogger.error("build", RESOURCE_NOT_AVAILABLE,\r
2000 "Instance of library class [%s] is not found" % LibraryClassName,\r
2001 File=self.MetaFile,\r
2002 ExtraData="in [%s] [%s]\n\tconsumed by module [%s]" % (str(M), self.Arch, str(Module)))\r
2003\r
0d2711a6 2004 LibraryModule = self.BuildDatabase[LibraryPath, self.Arch, self.BuildTarget, self.ToolChain]\r
52302d4d
LG
2005 # for those forced library instance (NULL library), add a fake library class\r
2006 if LibraryClassName.startswith("NULL"):\r
2007 LibraryModule.LibraryClass.append(LibraryClassObject(LibraryClassName, [ModuleType]))\r
2008 elif LibraryModule.LibraryClass == None \\r
2009 or len(LibraryModule.LibraryClass) == 0 \\r
2010 or (ModuleType != 'USER_DEFINED'\r
2011 and ModuleType not in LibraryModule.LibraryClass[0].SupModList):\r
2012 # only USER_DEFINED can link against any library instance despite of its SupModList\r
2013 EdkLogger.error("build", OPTION_MISSING,\r
2014 "Module type [%s] is not supported by library instance [%s]" \\r
2015 % (ModuleType, LibraryPath), File=self.MetaFile,\r
2016 ExtraData="consumed by [%s]" % str(Module))\r
2017\r
2018 LibraryInstance[LibraryClassName] = LibraryModule\r
2019 LibraryConsumerList.append(LibraryModule)\r
2020 EdkLogger.verbose("\t" + str(LibraryClassName) + " : " + str(LibraryModule))\r
2021 else:\r
2022 LibraryModule = LibraryInstance[LibraryClassName]\r
2023\r
2024 if LibraryModule == None:\r
2025 continue\r
2026\r
2027 if LibraryModule.ConstructorList != [] and LibraryModule not in Constructor:\r
2028 Constructor.append(LibraryModule)\r
2029\r
2030 if LibraryModule not in ConsumedByList:\r
2031 ConsumedByList[LibraryModule] = []\r
2032 # don't add current module itself to consumer list\r
2033 if M != Module:\r
2034 if M in ConsumedByList[LibraryModule]:\r
2035 continue\r
2036 ConsumedByList[LibraryModule].append(M)\r
2037 #\r
2038 # Initialize the sorted output list to the empty set\r
2039 #\r
2040 SortedLibraryList = []\r
2041 #\r
2042 # Q <- Set of all nodes with no incoming edges\r
2043 #\r
2044 LibraryList = [] #LibraryInstance.values()\r
2045 Q = []\r
2046 for LibraryClassName in LibraryInstance:\r
2047 M = LibraryInstance[LibraryClassName]\r
2048 LibraryList.append(M)\r
2049 if ConsumedByList[M] == []:\r
2050 Q.append(M)\r
2051\r
2052 #\r
2053 # start the DAG algorithm\r
2054 #\r
2055 while True:\r
2056 EdgeRemoved = True\r
2057 while Q == [] and EdgeRemoved:\r
2058 EdgeRemoved = False\r
2059 # for each node Item with a Constructor\r
2060 for Item in LibraryList:\r
2061 if Item not in Constructor:\r
2062 continue\r
2063 # for each Node without a constructor with an edge e from Item to Node\r
2064 for Node in ConsumedByList[Item]:\r
2065 if Node in Constructor:\r
2066 continue\r
2067 # remove edge e from the graph if Node has no constructor\r
2068 ConsumedByList[Item].remove(Node)\r
2069 EdgeRemoved = True\r
2070 if ConsumedByList[Item] == []:\r
2071 # insert Item into Q\r
2072 Q.insert(0, Item)\r
2073 break\r
2074 if Q != []:\r
2075 break\r
2076 # DAG is done if there's no more incoming edge for all nodes\r
2077 if Q == []:\r
2078 break\r
2079\r
2080 # remove node from Q\r
2081 Node = Q.pop()\r
2082 # output Node\r
2083 SortedLibraryList.append(Node)\r
2084\r
2085 # for each node Item with an edge e from Node to Item do\r
2086 for Item in LibraryList:\r
2087 if Node not in ConsumedByList[Item]:\r
2088 continue\r
2089 # remove edge e from the graph\r
2090 ConsumedByList[Item].remove(Node)\r
2091\r
2092 if ConsumedByList[Item] != []:\r
2093 continue\r
2094 # insert Item into Q, if Item has no other incoming edges\r
2095 Q.insert(0, Item)\r
2096\r
2097 #\r
2098 # if any remaining node Item in the graph has a constructor and an incoming edge, then the graph has a cycle\r
2099 #\r
2100 for Item in LibraryList:\r
2101 if ConsumedByList[Item] != [] and Item in Constructor and len(Constructor) > 1:\r
2102 ErrorMessage = "\tconsumed by " + "\n\tconsumed by ".join([str(L) for L in ConsumedByList[Item]])\r
2103 EdkLogger.error("build", BUILD_ERROR, 'Library [%s] with constructors has a cycle' % str(Item),\r
2104 ExtraData=ErrorMessage, File=self.MetaFile)\r
2105 if Item not in SortedLibraryList:\r
2106 SortedLibraryList.append(Item)\r
2107\r
2108 #\r
2109 # Build the list of constructor and destructir names\r
2110 # The DAG Topo sort produces the destructor order, so the list of constructors must generated in the reverse order\r
2111 #\r
2112 SortedLibraryList.reverse()\r
2113 return SortedLibraryList\r
2114\r
2115\r
2116 ## Override PCD setting (type, value, ...)\r
2117 #\r
2118 # @param ToPcd The PCD to be overrided\r
2119 # @param FromPcd The PCD overrideing from\r
2120 #\r
2121 def _OverridePcd(self, ToPcd, FromPcd, Module=""):\r
2122 #\r
2123 # in case there's PCDs coming from FDF file, which have no type given.\r
2124 # at this point, ToPcd.Type has the type found from dependent\r
2125 # package\r
2126 #\r
2a29017e
YZ
2127 TokenCName = ToPcd.TokenCName\r
2128 for PcdItem in GlobalData.MixedPcd:\r
2129 if (ToPcd.TokenCName, ToPcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
2130 TokenCName = PcdItem[0]\r
2131 break\r
52302d4d 2132 if FromPcd != None:\r
2a29017e
YZ
2133 if GlobalData.BuildOptionPcd:\r
2134 for pcd in GlobalData.BuildOptionPcd:\r
2135 if (FromPcd.TokenSpaceGuidCName, FromPcd.TokenCName) == (pcd[0], pcd[1]):\r
2136 FromPcd.DefaultValue = pcd[2]\r
2137 break\r
52302d4d
LG
2138 if ToPcd.Pending and FromPcd.Type not in [None, '']:\r
2139 ToPcd.Type = FromPcd.Type\r
e56468c0 2140 elif (ToPcd.Type not in [None, '']) and (FromPcd.Type not in [None, ''])\\r
2141 and (ToPcd.Type != FromPcd.Type) and (ToPcd.Type in FromPcd.Type):\r
2142 if ToPcd.Type.strip() == "DynamicEx":\r
47fea6af 2143 ToPcd.Type = FromPcd.Type\r
52302d4d
LG
2144 elif ToPcd.Type not in [None, ''] and FromPcd.Type not in [None, ''] \\r
2145 and ToPcd.Type != FromPcd.Type:\r
2146 EdkLogger.error("build", OPTION_CONFLICT, "Mismatched PCD type",\r
2147 ExtraData="%s.%s is defined as [%s] in module %s, but as [%s] in platform."\\r
2a29017e 2148 % (ToPcd.TokenSpaceGuidCName, TokenCName,\r
52302d4d
LG
2149 ToPcd.Type, Module, FromPcd.Type),\r
2150 File=self.MetaFile)\r
2151\r
2152 if FromPcd.MaxDatumSize not in [None, '']:\r
2153 ToPcd.MaxDatumSize = FromPcd.MaxDatumSize\r
2154 if FromPcd.DefaultValue not in [None, '']:\r
2155 ToPcd.DefaultValue = FromPcd.DefaultValue\r
2156 if FromPcd.TokenValue not in [None, '']:\r
2157 ToPcd.TokenValue = FromPcd.TokenValue\r
2158 if FromPcd.MaxDatumSize not in [None, '']:\r
2159 ToPcd.MaxDatumSize = FromPcd.MaxDatumSize\r
2160 if FromPcd.DatumType not in [None, '']:\r
2161 ToPcd.DatumType = FromPcd.DatumType\r
2162 if FromPcd.SkuInfoList not in [None, '', []]:\r
2163 ToPcd.SkuInfoList = FromPcd.SkuInfoList\r
2164\r
2165 # check the validation of datum\r
2166 IsValid, Cause = CheckPcdDatum(ToPcd.DatumType, ToPcd.DefaultValue)\r
2167 if not IsValid:\r
2168 EdkLogger.error('build', FORMAT_INVALID, Cause, File=self.MetaFile,\r
2a29017e 2169 ExtraData="%s.%s" % (ToPcd.TokenSpaceGuidCName, TokenCName))\r
82a6a960
BF
2170 ToPcd.validateranges = FromPcd.validateranges\r
2171 ToPcd.validlists = FromPcd.validlists\r
2172 ToPcd.expressions = FromPcd.expressions\r
52302d4d
LG
2173\r
2174 if ToPcd.DatumType == "VOID*" and ToPcd.MaxDatumSize in ['', None]:\r
2175 EdkLogger.debug(EdkLogger.DEBUG_9, "No MaxDatumSize specified for PCD %s.%s" \\r
2a29017e 2176 % (ToPcd.TokenSpaceGuidCName, TokenCName))\r
52302d4d
LG
2177 Value = ToPcd.DefaultValue\r
2178 if Value in [None, '']:\r
e8a47801 2179 ToPcd.MaxDatumSize = '1'\r
52302d4d 2180 elif Value[0] == 'L':\r
e8a47801 2181 ToPcd.MaxDatumSize = str((len(Value) - 2) * 2)\r
52302d4d
LG
2182 elif Value[0] == '{':\r
2183 ToPcd.MaxDatumSize = str(len(Value.split(',')))\r
2184 else:\r
e8a47801 2185 ToPcd.MaxDatumSize = str(len(Value) - 1)\r
52302d4d
LG
2186\r
2187 # apply default SKU for dynamic PCDS if specified one is not available\r
2188 if (ToPcd.Type in PCD_DYNAMIC_TYPE_LIST or ToPcd.Type in PCD_DYNAMIC_EX_TYPE_LIST) \\r
2189 and ToPcd.SkuInfoList in [None, {}, '']:\r
2190 if self.Platform.SkuName in self.Platform.SkuIds:\r
2191 SkuName = self.Platform.SkuName\r
2192 else:\r
2193 SkuName = 'DEFAULT'\r
2194 ToPcd.SkuInfoList = {\r
2195 SkuName : SkuInfoClass(SkuName, self.Platform.SkuIds[SkuName], '', '', '', '', '', ToPcd.DefaultValue)\r
2196 }\r
2197\r
2198 ## Apply PCD setting defined platform to a module\r
2199 #\r
2200 # @param Module The module from which the PCD setting will be overrided\r
2201 #\r
2202 # @retval PCD_list The list PCDs with settings from platform\r
2203 #\r
2204 def ApplyPcdSetting(self, Module, Pcds):\r
2205 # for each PCD in module\r
47fea6af
YZ
2206 for Name, Guid in Pcds:\r
2207 PcdInModule = Pcds[Name, Guid]\r
52302d4d 2208 # find out the PCD setting in platform\r
47fea6af
YZ
2209 if (Name, Guid) in self.Platform.Pcds:\r
2210 PcdInPlatform = self.Platform.Pcds[Name, Guid]\r
52302d4d
LG
2211 else:\r
2212 PcdInPlatform = None\r
2213 # then override the settings if any\r
2214 self._OverridePcd(PcdInModule, PcdInPlatform, Module)\r
2215 # resolve the VariableGuid value\r
2216 for SkuId in PcdInModule.SkuInfoList:\r
2217 Sku = PcdInModule.SkuInfoList[SkuId]\r
2218 if Sku.VariableGuid == '': continue\r
c28d2e10 2219 Sku.VariableGuidValue = GuidValue(Sku.VariableGuid, self.PackageList, self.MetaFile.Path)\r
52302d4d
LG
2220 if Sku.VariableGuidValue == None:\r
2221 PackageList = "\n\t".join([str(P) for P in self.PackageList])\r
2222 EdkLogger.error(\r
2223 'build',\r
2224 RESOURCE_NOT_AVAILABLE,\r
2225 "Value of GUID [%s] is not found in" % Sku.VariableGuid,\r
2226 ExtraData=PackageList + "\n\t(used with %s.%s from module %s)" \\r
2227 % (Guid, Name, str(Module)),\r
2228 File=self.MetaFile\r
2229 )\r
2230\r
2231 # override PCD settings with module specific setting\r
2232 if Module in self.Platform.Modules:\r
2233 PlatformModule = self.Platform.Modules[str(Module)]\r
2234 for Key in PlatformModule.Pcds:\r
2235 if Key in Pcds:\r
2236 self._OverridePcd(Pcds[Key], PlatformModule.Pcds[Key], Module)\r
2237 return Pcds.values()\r
2238\r
2239 ## Resolve library names to library modules\r
2240 #\r
b36d134f 2241 # (for Edk.x modules)\r
52302d4d
LG
2242 #\r
2243 # @param Module The module from which the library names will be resolved\r
2244 #\r
2245 # @retval library_list The list of library modules\r
2246 #\r
2247 def ResolveLibraryReference(self, Module):\r
2248 EdkLogger.verbose("")\r
2249 EdkLogger.verbose("Library instances of module [%s] [%s]:" % (str(Module), self.Arch))\r
2250 LibraryConsumerList = [Module]\r
2251\r
b36d134f 2252 # "CompilerStub" is a must for Edk modules\r
52302d4d
LG
2253 if Module.Libraries:\r
2254 Module.Libraries.append("CompilerStub")\r
2255 LibraryList = []\r
2256 while len(LibraryConsumerList) > 0:\r
2257 M = LibraryConsumerList.pop()\r
2258 for LibraryName in M.Libraries:\r
2259 Library = self.Platform.LibraryClasses[LibraryName, ':dummy:']\r
2260 if Library == None:\r
2261 for Key in self.Platform.LibraryClasses.data.keys():\r
2262 if LibraryName.upper() == Key.upper():\r
2263 Library = self.Platform.LibraryClasses[Key, ':dummy:']\r
2264 break\r
2265 if Library == None:\r
2266 EdkLogger.warn("build", "Library [%s] is not found" % LibraryName, File=str(M),\r
2267 ExtraData="\t%s [%s]" % (str(Module), self.Arch))\r
2268 continue\r
2269\r
2270 if Library not in LibraryList:\r
2271 LibraryList.append(Library)\r
2272 LibraryConsumerList.append(Library)\r
2273 EdkLogger.verbose("\t" + LibraryName + " : " + str(Library) + ' ' + str(type(Library)))\r
2274 return LibraryList\r
2275\r
6780eef1
LG
2276 ## Calculate the priority value of the build option\r
2277 #\r
2278 # @param Key Build option definition contain: TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE\r
2279 #\r
2280 # @retval Value Priority value based on the priority list.\r
2281 #\r
2282 def CalculatePriorityValue(self, Key):\r
47fea6af
YZ
2283 Target, ToolChain, Arch, CommandType, Attr = Key.split('_')\r
2284 PriorityValue = 0x11111\r
6780eef1
LG
2285 if Target == "*":\r
2286 PriorityValue &= 0x01111\r
2287 if ToolChain == "*":\r
2288 PriorityValue &= 0x10111\r
2289 if Arch == "*":\r
2290 PriorityValue &= 0x11011\r
2291 if CommandType == "*":\r
2292 PriorityValue &= 0x11101\r
2293 if Attr == "*":\r
2294 PriorityValue &= 0x11110\r
47fea6af
YZ
2295\r
2296 return self.PrioList["0x%0.5x" % PriorityValue]\r
2297\r
6780eef1 2298\r
52302d4d
LG
2299 ## Expand * in build option key\r
2300 #\r
2301 # @param Options Options to be expanded\r
2302 #\r
2303 # @retval options Options expanded\r
6780eef1 2304 # \r
52302d4d
LG
2305 def _ExpandBuildOption(self, Options, ModuleStyle=None):\r
2306 BuildOptions = {}\r
2307 FamilyMatch = False\r
2308 FamilyIsNull = True\r
47fea6af 2309\r
6780eef1
LG
2310 OverrideList = {}\r
2311 #\r
2312 # Construct a list contain the build options which need override.\r
2313 #\r
2314 for Key in Options:\r
2315 #\r
2316 # Key[0] -- tool family\r
2317 # Key[1] -- TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE\r
2318 #\r
1ba5124e
YL
2319 if (Key[0] == self.BuildRuleFamily and\r
2320 (ModuleStyle == None or len(Key) < 3 or (len(Key) > 2 and Key[2] == ModuleStyle))):\r
6780eef1
LG
2321 Target, ToolChain, Arch, CommandType, Attr = Key[1].split('_')\r
2322 if Target == self.BuildTarget or Target == "*":\r
2323 if ToolChain == self.ToolChain or ToolChain == "*":\r
2324 if Arch == self.Arch or Arch == "*":\r
2325 if Options[Key].startswith("="):\r
47fea6af 2326 if OverrideList.get(Key[1]) != None:\r
6780eef1
LG
2327 OverrideList.pop(Key[1])\r
2328 OverrideList[Key[1]] = Options[Key]\r
2329 \r
2330 #\r
2331 # Use the highest priority value. \r
2332 #\r
2333 if (len(OverrideList) >= 2):\r
47fea6af 2334 KeyList = OverrideList.keys()\r
6780eef1 2335 for Index in range(len(KeyList)):\r
47fea6af 2336 NowKey = KeyList[Index]\r
6780eef1
LG
2337 Target1, ToolChain1, Arch1, CommandType1, Attr1 = NowKey.split("_")\r
2338 for Index1 in range(len(KeyList) - Index - 1):\r
2339 NextKey = KeyList[Index1 + Index + 1]\r
2340 #\r
2341 # Compare two Key, if one is included by another, choose the higher priority one\r
2342 # \r
2343 Target2, ToolChain2, Arch2, CommandType2, Attr2 = NextKey.split("_")\r
2344 if Target1 == Target2 or Target1 == "*" or Target2 == "*":\r
2345 if ToolChain1 == ToolChain2 or ToolChain1 == "*" or ToolChain2 == "*":\r
2346 if Arch1 == Arch2 or Arch1 == "*" or Arch2 == "*":\r
2347 if CommandType1 == CommandType2 or CommandType1 == "*" or CommandType2 == "*":\r
2348 if Attr1 == Attr2 or Attr1 == "*" or Attr2 == "*":\r
2349 if self.CalculatePriorityValue(NowKey) > self.CalculatePriorityValue(NextKey):\r
47fea6af 2350 if Options.get((self.BuildRuleFamily, NextKey)) != None:\r
6780eef1
LG
2351 Options.pop((self.BuildRuleFamily, NextKey))\r
2352 else:\r
47fea6af 2353 if Options.get((self.BuildRuleFamily, NowKey)) != None:\r
6780eef1
LG
2354 Options.pop((self.BuildRuleFamily, NowKey))\r
2355 \r
52302d4d
LG
2356 for Key in Options:\r
2357 if ModuleStyle != None and len (Key) > 2:\r
2358 # Check Module style is EDK or EDKII.\r
2359 # Only append build option for the matched style module.\r
2360 if ModuleStyle == EDK_NAME and Key[2] != EDK_NAME:\r
2361 continue\r
2362 elif ModuleStyle == EDKII_NAME and Key[2] != EDKII_NAME:\r
2363 continue\r
2364 Family = Key[0]\r
2365 Target, Tag, Arch, Tool, Attr = Key[1].split("_")\r
2366 # if tool chain family doesn't match, skip it\r
2367 if Tool in self.ToolDefinition and Family != "":\r
2368 FamilyIsNull = False\r
2369 if self.ToolDefinition[Tool].get(TAB_TOD_DEFINES_BUILDRULEFAMILY, "") != "":\r
2370 if Family != self.ToolDefinition[Tool][TAB_TOD_DEFINES_BUILDRULEFAMILY]:\r
2371 continue\r
2372 elif Family != self.ToolDefinition[Tool][TAB_TOD_DEFINES_FAMILY]:\r
2373 continue\r
2374 FamilyMatch = True\r
2375 # expand any wildcard\r
2376 if Target == "*" or Target == self.BuildTarget:\r
2377 if Tag == "*" or Tag == self.ToolChain:\r
2378 if Arch == "*" or Arch == self.Arch:\r
2379 if Tool not in BuildOptions:\r
2380 BuildOptions[Tool] = {}\r
5015bee2 2381 if Attr != "FLAGS" or Attr not in BuildOptions[Tool] or Options[Key].startswith('='):\r
52302d4d
LG
2382 BuildOptions[Tool][Attr] = Options[Key]\r
2383 else:\r
2384 # append options for the same tool\r
2385 BuildOptions[Tool][Attr] += " " + Options[Key]\r
2386 # Build Option Family has been checked, which need't to be checked again for family.\r
2387 if FamilyMatch or FamilyIsNull:\r
2388 return BuildOptions\r
1ba5124e 2389\r
52302d4d
LG
2390 for Key in Options:\r
2391 if ModuleStyle != None and len (Key) > 2:\r
2392 # Check Module style is EDK or EDKII.\r
2393 # Only append build option for the matched style module.\r
2394 if ModuleStyle == EDK_NAME and Key[2] != EDK_NAME:\r
2395 continue\r
2396 elif ModuleStyle == EDKII_NAME and Key[2] != EDKII_NAME:\r
2397 continue\r
2398 Family = Key[0]\r
2399 Target, Tag, Arch, Tool, Attr = Key[1].split("_")\r
2400 # if tool chain family doesn't match, skip it\r
47fea6af 2401 if Tool not in self.ToolDefinition or Family == "":\r
52302d4d
LG
2402 continue\r
2403 # option has been added before\r
2404 if Family != self.ToolDefinition[Tool][TAB_TOD_DEFINES_FAMILY]:\r
2405 continue\r
2406\r
2407 # expand any wildcard\r
2408 if Target == "*" or Target == self.BuildTarget:\r
2409 if Tag == "*" or Tag == self.ToolChain:\r
2410 if Arch == "*" or Arch == self.Arch:\r
2411 if Tool not in BuildOptions:\r
2412 BuildOptions[Tool] = {}\r
5015bee2 2413 if Attr != "FLAGS" or Attr not in BuildOptions[Tool] or Options[Key].startswith('='):\r
52302d4d
LG
2414 BuildOptions[Tool][Attr] = Options[Key]\r
2415 else:\r
2416 # append options for the same tool\r
2417 BuildOptions[Tool][Attr] += " " + Options[Key]\r
2418 return BuildOptions\r
2419\r
2420 ## Append build options in platform to a module\r
2421 #\r
2422 # @param Module The module to which the build options will be appened\r
2423 #\r
2424 # @retval options The options appended with build options in platform\r
2425 #\r
2426 def ApplyBuildOption(self, Module):\r
2427 # Get the different options for the different style module\r
2428 if Module.AutoGenVersion < 0x00010005:\r
2429 PlatformOptions = self.EdkBuildOption\r
35f69db9 2430 ModuleTypeOptions = self.Platform.GetBuildOptionsByModuleType(EDK_NAME, Module.ModuleType)\r
52302d4d
LG
2431 else:\r
2432 PlatformOptions = self.EdkIIBuildOption\r
35f69db9
YL
2433 ModuleTypeOptions = self.Platform.GetBuildOptionsByModuleType(EDKII_NAME, Module.ModuleType)\r
2434 ModuleTypeOptions = self._ExpandBuildOption(ModuleTypeOptions)\r
52302d4d
LG
2435 ModuleOptions = self._ExpandBuildOption(Module.BuildOptions)\r
2436 if Module in self.Platform.Modules:\r
2437 PlatformModule = self.Platform.Modules[str(Module)]\r
2438 PlatformModuleOptions = self._ExpandBuildOption(PlatformModule.BuildOptions)\r
2439 else:\r
2440 PlatformModuleOptions = {}\r
2441\r
fe4bf2f9 2442 BuildRuleOrder = None\r
35f69db9 2443 for Options in [self.ToolDefinition, ModuleOptions, PlatformOptions, ModuleTypeOptions, PlatformModuleOptions]:\r
fe4bf2f9
YL
2444 for Tool in Options:\r
2445 for Attr in Options[Tool]:\r
2446 if Attr == TAB_TOD_DEFINES_BUILDRULEORDER:\r
2447 BuildRuleOrder = Options[Tool][Attr]\r
2448\r
35f69db9
YL
2449 AllTools = set(ModuleOptions.keys() + PlatformOptions.keys() +\r
2450 PlatformModuleOptions.keys() + ModuleTypeOptions.keys() +\r
2451 self.ToolDefinition.keys())\r
52302d4d
LG
2452 BuildOptions = {}\r
2453 for Tool in AllTools:\r
2454 if Tool not in BuildOptions:\r
2455 BuildOptions[Tool] = {}\r
2456\r
35f69db9 2457 for Options in [self.ToolDefinition, ModuleOptions, PlatformOptions, ModuleTypeOptions, PlatformModuleOptions]:\r
52302d4d
LG
2458 if Tool not in Options:\r
2459 continue\r
2460 for Attr in Options[Tool]:\r
2461 Value = Options[Tool][Attr]\r
fe4bf2f9
YL
2462 #\r
2463 # Do not generate it in Makefile\r
2464 #\r
2465 if Attr == TAB_TOD_DEFINES_BUILDRULEORDER:\r
2466 continue\r
52302d4d
LG
2467 if Attr not in BuildOptions[Tool]:\r
2468 BuildOptions[Tool][Attr] = ""\r
2469 # check if override is indicated\r
2470 if Value.startswith('='):\r
05cc51ad
LY
2471 ToolPath = Value[1:]\r
2472 ToolPath = mws.handleWsMacro(ToolPath)\r
2473 BuildOptions[Tool][Attr] = ToolPath\r
5015bee2 2474 else:\r
05cc51ad 2475 Value = mws.handleWsMacro(Value)\r
52302d4d 2476 BuildOptions[Tool][Attr] += " " + Value\r
f3decdc3
LG
2477 if Module.AutoGenVersion < 0x00010005 and self.Workspace.UniFlag != None:\r
2478 #\r
2479 # Override UNI flag only for EDK module.\r
2480 #\r
2481 if 'BUILD' not in BuildOptions:\r
2482 BuildOptions['BUILD'] = {}\r
2483 BuildOptions['BUILD']['FLAGS'] = self.Workspace.UniFlag\r
fe4bf2f9 2484 return BuildOptions, BuildRuleOrder\r
52302d4d
LG
2485\r
2486 Platform = property(_GetPlatform)\r
2487 Name = property(_GetName)\r
2488 Guid = property(_GetGuid)\r
2489 Version = property(_GetVersion)\r
2490\r
2491 OutputDir = property(_GetOutputDir)\r
2492 BuildDir = property(_GetBuildDir)\r
2493 MakeFileDir = property(_GetMakeFileDir)\r
2494 FdfFile = property(_GetFdfFile)\r
2495\r
2496 PcdTokenNumber = property(_GetPcdTokenNumbers) # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber\r
2497 DynamicPcdList = property(_GetDynamicPcdList) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]\r
2498 NonDynamicPcdList = property(_GetNonDynamicPcdList) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]\r
2bc3256c 2499 NonDynamicPcdDict = property(_GetNonDynamicPcdDict)\r
52302d4d
LG
2500 PackageList = property(_GetPackageList)\r
2501\r
2502 ToolDefinition = property(_GetToolDefinition) # toolcode : tool path\r
2503 ToolDefinitionFile = property(_GetToolDefFile) # toolcode : lib path\r
2504 ToolChainFamily = property(_GetToolChainFamily)\r
2505 BuildRuleFamily = property(_GetBuildRuleFamily)\r
2506 BuildOption = property(_GetBuildOptions) # toolcode : option\r
2507 EdkBuildOption = property(_GetEdkBuildOptions) # edktoolcode : option\r
2508 EdkIIBuildOption = property(_GetEdkIIBuildOptions) # edkiitoolcode : option\r
2509\r
2510 BuildCommand = property(_GetBuildCommand)\r
2511 BuildRule = property(_GetBuildRule)\r
2512 ModuleAutoGenList = property(_GetModuleAutoGenList)\r
2513 LibraryAutoGenList = property(_GetLibraryAutoGenList)\r
0923aa1c 2514 GenFdsCommand = property(_GenFdsCommand)\r
52302d4d
LG
2515\r
2516## ModuleAutoGen class\r
2517#\r
2518# This class encapsules the AutoGen behaviors for the build tools. In addition to\r
2519# the generation of AutoGen.h and AutoGen.c, it will generate *.depex file according\r
2520# to the [depex] section in module's inf file.\r
2521#\r
2522class ModuleAutoGen(AutoGen):\r
2523 ## The real constructor of ModuleAutoGen\r
2524 #\r
2525 # This method is not supposed to be called by users of ModuleAutoGen. It's\r
2526 # only used by factory method __new__() to do real initialization work for an\r
2527 # object of ModuleAutoGen\r
2528 #\r
2529 # @param Workspace EdkIIWorkspaceBuild object\r
2530 # @param ModuleFile The path of module file\r
2531 # @param Target Build target (DEBUG, RELEASE)\r
2532 # @param Toolchain Name of tool chain\r
2533 # @param Arch The arch the module supports\r
2534 # @param PlatformFile Platform meta-file\r
2535 #\r
2536 def _Init(self, Workspace, ModuleFile, Target, Toolchain, Arch, PlatformFile):\r
2537 EdkLogger.debug(EdkLogger.DEBUG_9, "AutoGen module [%s] [%s]" % (ModuleFile, Arch))\r
2538 GlobalData.gProcessingFile = "%s [%s, %s, %s]" % (ModuleFile, Arch, Toolchain, Target)\r
2539\r
2540 self.Workspace = Workspace\r
2541 self.WorkspaceDir = Workspace.WorkspaceDir\r
2542\r
2543 self.MetaFile = ModuleFile\r
2544 self.PlatformInfo = PlatformAutoGen(Workspace, PlatformFile, Target, Toolchain, Arch)\r
2545 # check if this module is employed by active platform\r
2546 if not self.PlatformInfo.ValidModule(self.MetaFile):\r
2547 EdkLogger.verbose("Module [%s] for [%s] is not employed by active platform\n" \\r
2548 % (self.MetaFile, Arch))\r
2549 return False\r
2550\r
2551 self.SourceDir = self.MetaFile.SubDir\r
05cc51ad 2552 self.SourceDir = mws.relpath(self.SourceDir, self.WorkspaceDir)\r
97fa0ee9 2553\r
52302d4d
LG
2554 self.SourceOverrideDir = None\r
2555 # use overrided path defined in DSC file\r
2556 if self.MetaFile.Key in GlobalData.gOverrideDir:\r
2557 self.SourceOverrideDir = GlobalData.gOverrideDir[self.MetaFile.Key]\r
2558\r
2559 self.ToolChain = Toolchain\r
2560 self.BuildTarget = Target\r
2561 self.Arch = Arch\r
2562 self.ToolChainFamily = self.PlatformInfo.ToolChainFamily\r
2563 self.BuildRuleFamily = self.PlatformInfo.BuildRuleFamily\r
2564\r
2565 self.IsMakeFileCreated = False\r
2566 self.IsCodeFileCreated = False\r
da92f276
LG
2567 self.IsAsBuiltInfCreated = False\r
2568 self.DepexGenerated = False\r
52302d4d
LG
2569\r
2570 self.BuildDatabase = self.Workspace.BuildDatabase\r
fe4bf2f9 2571 self.BuildRuleOrder = None\r
52302d4d
LG
2572\r
2573 self._Module = None\r
2574 self._Name = None\r
2575 self._Guid = None\r
2576 self._Version = None\r
2577 self._ModuleType = None\r
2578 self._ComponentType = None\r
2579 self._PcdIsDriver = None\r
2580 self._AutoGenVersion = None\r
2581 self._LibraryFlag = None\r
2582 self._CustomMakefile = None\r
2583 self._Macro = None\r
2584\r
2585 self._BuildDir = None\r
2586 self._OutputDir = None\r
2587 self._DebugDir = None\r
2588 self._MakeFileDir = None\r
2589\r
2590 self._IncludePathList = None\r
725cdb8f 2591 self._IncludePathLength = 0\r
52302d4d
LG
2592 self._AutoGenFileList = None\r
2593 self._UnicodeFileList = None\r
5b97eb4c 2594 self._VfrFileList = None\r
333ba578 2595 self._IdfFileList = None\r
52302d4d
LG
2596 self._SourceFileList = None\r
2597 self._ObjectFileList = None\r
2598 self._BinaryFileList = None\r
2599\r
2600 self._DependentPackageList = None\r
2601 self._DependentLibraryList = None\r
2602 self._LibraryAutoGenList = None\r
2603 self._DerivedPackageList = None\r
2604 self._ModulePcdList = None\r
2605 self._LibraryPcdList = None\r
e8a47801 2606 self._PcdComments = sdict()\r
52302d4d 2607 self._GuidList = None\r
e8a47801
LG
2608 self._GuidsUsedByPcd = None\r
2609 self._GuidComments = sdict()\r
52302d4d 2610 self._ProtocolList = None\r
e8a47801 2611 self._ProtocolComments = sdict()\r
52302d4d 2612 self._PpiList = None\r
e8a47801 2613 self._PpiComments = sdict()\r
52302d4d
LG
2614 self._DepexList = None\r
2615 self._DepexExpressionList = None\r
2616 self._BuildOption = None\r
79b74a03 2617 self._BuildOptionIncPathList = None\r
52302d4d
LG
2618 self._BuildTargets = None\r
2619 self._IntroBuildTargetList = None\r
2620 self._FinalBuildTargetList = None\r
2621 self._FileTypes = None\r
2622 self._BuildRules = None\r
2bc3256c
LG
2623 \r
2624 ## The Modules referenced to this Library\r
2625 # Only Library has this attribute\r
2626 self._ReferenceModules = [] \r
2627 \r
2628 ## Store the FixedAtBuild Pcds\r
2629 # \r
2630 self._FixedAtBuildPcds = []\r
2631 self.ConstPcd = {}\r
52302d4d
LG
2632 return True\r
2633\r
2634 def __repr__(self):\r
2635 return "%s [%s]" % (self.MetaFile, self.Arch)\r
2636\r
2bc3256c
LG
2637 # Get FixedAtBuild Pcds of this Module\r
2638 def _GetFixedAtBuildPcds(self):\r
2639 if self._FixedAtBuildPcds:\r
2640 return self._FixedAtBuildPcds\r
2641 for Pcd in self.ModulePcdList:\r
2642 if self.IsLibrary:\r
2643 if not (Pcd.Pending == False and Pcd.Type == "FixedAtBuild"):\r
2644 continue\r
2645 elif Pcd.Type != "FixedAtBuild":\r
2646 continue\r
2647 if Pcd not in self._FixedAtBuildPcds:\r
2648 self._FixedAtBuildPcds.append(Pcd)\r
2649 \r
2650 return self._FixedAtBuildPcds \r
2651\r
867d1cd4
YL
2652 def _GetUniqueBaseName(self):\r
2653 BaseName = self.Name\r
2654 for Module in self.PlatformInfo.ModuleAutoGenList:\r
2655 if Module.MetaFile == self.MetaFile:\r
2656 continue\r
2657 if Module.Name == self.Name:\r
867d1cd4
YL
2658 if uuid.UUID(Module.Guid) == uuid.UUID(self.Guid):\r
2659 EdkLogger.error("build", FILE_DUPLICATED, 'Modules have same BaseName and FILE_GUID:\n'\r
2660 ' %s\n %s' % (Module.MetaFile, self.MetaFile))\r
2661 BaseName = '%s_%s' % (self.Name, self.Guid)\r
2662 return BaseName\r
2663\r
52302d4d
LG
2664 # Macros could be used in build_rule.txt (also Makefile)\r
2665 def _GetMacros(self):\r
2666 if self._Macro == None:\r
2667 self._Macro = sdict()\r
2668 self._Macro["WORKSPACE" ] = self.WorkspaceDir\r
2669 self._Macro["MODULE_NAME" ] = self.Name\r
867d1cd4 2670 self._Macro["MODULE_NAME_GUID" ] = self._GetUniqueBaseName()\r
52302d4d
LG
2671 self._Macro["MODULE_GUID" ] = self.Guid\r
2672 self._Macro["MODULE_VERSION" ] = self.Version\r
2673 self._Macro["MODULE_TYPE" ] = self.ModuleType\r
2674 self._Macro["MODULE_FILE" ] = str(self.MetaFile)\r
2675 self._Macro["MODULE_FILE_BASE_NAME" ] = self.MetaFile.BaseName\r
2676 self._Macro["MODULE_RELATIVE_DIR" ] = self.SourceDir\r
2677 self._Macro["MODULE_DIR" ] = self.SourceDir\r
2678\r
2679 self._Macro["BASE_NAME" ] = self.Name\r
2680\r
2681 self._Macro["ARCH" ] = self.Arch\r
2682 self._Macro["TOOLCHAIN" ] = self.ToolChain\r
2683 self._Macro["TOOLCHAIN_TAG" ] = self.ToolChain\r
0d2711a6 2684 self._Macro["TOOL_CHAIN_TAG" ] = self.ToolChain\r
52302d4d
LG
2685 self._Macro["TARGET" ] = self.BuildTarget\r
2686\r
2687 self._Macro["BUILD_DIR" ] = self.PlatformInfo.BuildDir\r
2688 self._Macro["BIN_DIR" ] = os.path.join(self.PlatformInfo.BuildDir, self.Arch)\r
2689 self._Macro["LIB_DIR" ] = os.path.join(self.PlatformInfo.BuildDir, self.Arch)\r
2690 self._Macro["MODULE_BUILD_DIR" ] = self.BuildDir\r
2691 self._Macro["OUTPUT_DIR" ] = self.OutputDir\r
2692 self._Macro["DEBUG_DIR" ] = self.DebugDir\r
df1e1b63
YZ
2693 self._Macro["DEST_DIR_OUTPUT" ] = self.OutputDir\r
2694 self._Macro["DEST_DIR_DEBUG" ] = self.DebugDir\r
3570e332
YZ
2695 self._Macro["PLATFORM_NAME" ] = self.PlatformInfo.Name\r
2696 self._Macro["PLATFORM_GUID" ] = self.PlatformInfo.Guid\r
2697 self._Macro["PLATFORM_VERSION" ] = self.PlatformInfo.Version\r
2698 self._Macro["PLATFORM_RELATIVE_DIR" ] = self.PlatformInfo.SourceDir\r
2699 self._Macro["PLATFORM_DIR" ] = mws.join(self.WorkspaceDir, self.PlatformInfo.SourceDir)\r
2700 self._Macro["PLATFORM_OUTPUT_DIR" ] = self.PlatformInfo.OutputDir\r
52302d4d
LG
2701 return self._Macro\r
2702\r
2703 ## Return the module build data object\r
2704 def _GetModule(self):\r
2705 if self._Module == None:\r
0d2711a6 2706 self._Module = self.Workspace.BuildDatabase[self.MetaFile, self.Arch, self.BuildTarget, self.ToolChain]\r
52302d4d
LG
2707 return self._Module\r
2708\r
2709 ## Return the module name\r
2710 def _GetBaseName(self):\r
2711 return self.Module.BaseName\r
2712\r
b36d134f
LG
2713 ## Return the module DxsFile if exist\r
2714 def _GetDxsFile(self):\r
2715 return self.Module.DxsFile\r
2716\r
52302d4d
LG
2717 ## Return the module SourceOverridePath\r
2718 def _GetSourceOverridePath(self):\r
2719 return self.Module.SourceOverridePath\r
2720\r
2721 ## Return the module meta-file GUID\r
2722 def _GetGuid(self):\r
97fa0ee9
YL
2723 #\r
2724 # To build same module more than once, the module path with FILE_GUID overridden has\r
2725 # the file name FILE_GUIDmodule.inf, but the relative path (self.MetaFile.File) is the realy path\r
2726 # in DSC. The overridden GUID can be retrieved from file name\r
2727 #\r
2728 if os.path.basename(self.MetaFile.File) != os.path.basename(self.MetaFile.Path):\r
2729 #\r
2730 # Length of GUID is 36\r
2731 #\r
2732 return os.path.basename(self.MetaFile.Path)[:36]\r
52302d4d
LG
2733 return self.Module.Guid\r
2734\r
2735 ## Return the module version\r
2736 def _GetVersion(self):\r
2737 return self.Module.Version\r
2738\r
2739 ## Return the module type\r
2740 def _GetModuleType(self):\r
2741 return self.Module.ModuleType\r
2742\r
b36d134f 2743 ## Return the component type (for Edk.x style of module)\r
52302d4d
LG
2744 def _GetComponentType(self):\r
2745 return self.Module.ComponentType\r
2746\r
2747 ## Return the build type\r
2748 def _GetBuildType(self):\r
2749 return self.Module.BuildType\r
2750\r
2751 ## Return the PCD_IS_DRIVER setting\r
2752 def _GetPcdIsDriver(self):\r
2753 return self.Module.PcdIsDriver\r
2754\r
2755 ## Return the autogen version, i.e. module meta-file version\r
2756 def _GetAutoGenVersion(self):\r
2757 return self.Module.AutoGenVersion\r
2758\r
2759 ## Check if the module is library or not\r
2760 def _IsLibrary(self):\r
2761 if self._LibraryFlag == None:\r
2762 if self.Module.LibraryClass != None and self.Module.LibraryClass != []:\r
2763 self._LibraryFlag = True\r
2764 else:\r
2765 self._LibraryFlag = False\r
2766 return self._LibraryFlag\r
2767\r
e8a47801
LG
2768 ## Check if the module is binary module or not\r
2769 def _IsBinaryModule(self):\r
2770 return self.Module.IsBinaryModule\r
2771\r
52302d4d
LG
2772 ## Return the directory to store intermediate files of the module\r
2773 def _GetBuildDir(self):\r
2774 if self._BuildDir == None:\r
2775 self._BuildDir = path.join(\r
2776 self.PlatformInfo.BuildDir,\r
2777 self.Arch,\r
2778 self.SourceDir,\r
2779 self.MetaFile.BaseName\r
2780 )\r
2781 CreateDirectory(self._BuildDir)\r
2782 return self._BuildDir\r
2783\r
2784 ## Return the directory to store the intermediate object files of the mdoule\r
2785 def _GetOutputDir(self):\r
2786 if self._OutputDir == None:\r
2787 self._OutputDir = path.join(self.BuildDir, "OUTPUT")\r
2788 CreateDirectory(self._OutputDir)\r
2789 return self._OutputDir\r
2790\r
2791 ## Return the directory to store auto-gened source files of the mdoule\r
2792 def _GetDebugDir(self):\r
2793 if self._DebugDir == None:\r
2794 self._DebugDir = path.join(self.BuildDir, "DEBUG")\r
2795 CreateDirectory(self._DebugDir)\r
2796 return self._DebugDir\r
2797\r
2798 ## Return the path of custom file\r
2799 def _GetCustomMakefile(self):\r
2800 if self._CustomMakefile == None:\r
2801 self._CustomMakefile = {}\r
2802 for Type in self.Module.CustomMakefile:\r
2803 if Type in gMakeTypeMap:\r
2804 MakeType = gMakeTypeMap[Type]\r
2805 else:\r
2806 MakeType = 'nmake'\r
2807 if self.SourceOverrideDir != None:\r
2808 File = os.path.join(self.SourceOverrideDir, self.Module.CustomMakefile[Type])\r
2809 if not os.path.exists(File):\r
2810 File = os.path.join(self.SourceDir, self.Module.CustomMakefile[Type])\r
2811 else:\r
2812 File = os.path.join(self.SourceDir, self.Module.CustomMakefile[Type])\r
2813 self._CustomMakefile[MakeType] = File\r
2814 return self._CustomMakefile\r
2815\r
2816 ## Return the directory of the makefile\r
2817 #\r
2818 # @retval string The directory string of module's makefile\r
2819 #\r
2820 def _GetMakeFileDir(self):\r
2821 return self.BuildDir\r
2822\r
2823 ## Return build command string\r
2824 #\r
2825 # @retval string Build command string\r
2826 #\r
2827 def _GetBuildCommand(self):\r
2828 return self.PlatformInfo.BuildCommand\r
2829\r
2830 ## Get object list of all packages the module and its dependent libraries belong to\r
2831 #\r
2832 # @retval list The list of package object\r
2833 #\r
2834 def _GetDerivedPackageList(self):\r
2835 PackageList = []\r
2836 for M in [self.Module] + self.DependentLibraryList:\r
2837 for Package in M.Packages:\r
2838 if Package in PackageList:\r
2839 continue\r
2840 PackageList.append(Package)\r
2841 return PackageList\r
97fa0ee9
YL
2842 \r
2843 ## Get the depex string\r
2844 #\r
2845 # @return : a string contain all depex expresion.\r
2846 def _GetDepexExpresionString(self):\r
2847 DepexStr = ''\r
2848 DepexList = []\r
2849 ## DPX_SOURCE IN Define section.\r
2850 if self.Module.DxsFile:\r
2851 return DepexStr\r
2852 for M in [self.Module] + self.DependentLibraryList:\r
2853 Filename = M.MetaFile.Path\r
2854 InfObj = InfSectionParser.InfSectionParser(Filename)\r
2855 DepexExpresionList = InfObj.GetDepexExpresionList()\r
2856 for DepexExpresion in DepexExpresionList:\r
2857 for key in DepexExpresion.keys():\r
2858 Arch, ModuleType = key\r
518aebe2 2859 DepexExpr = [x for x in DepexExpresion[key] if not str(x).startswith('#')]\r
97fa0ee9
YL
2860 # the type of build module is USER_DEFINED.\r
2861 # All different DEPEX section tags would be copied into the As Built INF file\r
2862 # and there would be separate DEPEX section tags\r
2863 if self.ModuleType.upper() == SUP_MODULE_USER_DEFINED:\r
2864 if (Arch.upper() == self.Arch.upper()) and (ModuleType.upper() != TAB_ARCH_COMMON):\r
518aebe2 2865 DepexList.append({(Arch, ModuleType): DepexExpr})\r
97fa0ee9
YL
2866 else:\r
2867 if Arch.upper() == TAB_ARCH_COMMON or \\r
2868 (Arch.upper() == self.Arch.upper() and \\r
2869 ModuleType.upper() in [TAB_ARCH_COMMON, self.ModuleType.upper()]):\r
518aebe2 2870 DepexList.append({(Arch, ModuleType): DepexExpr})\r
97fa0ee9
YL
2871 \r
2872 #the type of build module is USER_DEFINED.\r
2873 if self.ModuleType.upper() == SUP_MODULE_USER_DEFINED:\r
2874 for Depex in DepexList:\r
2875 for key in Depex.keys():\r
2876 DepexStr += '[Depex.%s.%s]\n' % key\r
2877 DepexStr += '\n'.join(['# '+ val for val in Depex[key]])\r
2878 DepexStr += '\n\n'\r
2879 if not DepexStr:\r
2880 return '[Depex.%s]\n' % self.Arch\r
2881 return DepexStr\r
2882 \r
2883 #the type of build module not is USER_DEFINED.\r
2884 Count = 0\r
2885 for Depex in DepexList:\r
2886 Count += 1\r
2887 if DepexStr != '':\r
2888 DepexStr += ' AND '\r
2889 DepexStr += '('\r
2890 for D in Depex.values():\r
2891 DepexStr += ' '.join([val for val in D])\r
2892 Index = DepexStr.find('END')\r
2893 if Index > -1 and Index == len(DepexStr) - 3:\r
2894 DepexStr = DepexStr[:-3]\r
2895 DepexStr = DepexStr.strip()\r
2896 DepexStr += ')'\r
2897 if Count == 1:\r
2898 DepexStr = DepexStr.lstrip('(').rstrip(')').strip()\r
2899 if not DepexStr:\r
2900 return '[Depex.%s]\n' % self.Arch\r
2901 return '[Depex.%s]\n# ' % self.Arch + DepexStr\r
2902 \r
52302d4d
LG
2903 ## Merge dependency expression\r
2904 #\r
2905 # @retval list The token list of the dependency expression after parsed\r
2906 #\r
2907 def _GetDepexTokenList(self):\r
2908 if self._DepexList == None:\r
2909 self._DepexList = {}\r
b36d134f 2910 if self.DxsFile or self.IsLibrary or TAB_DEPENDENCY_EXPRESSION_FILE in self.FileTypes:\r
52302d4d
LG
2911 return self._DepexList\r
2912\r
2913 self._DepexList[self.ModuleType] = []\r
2914\r
2915 for ModuleType in self._DepexList:\r
2916 DepexList = self._DepexList[ModuleType]\r
2917 #\r
2918 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion\r
2919 #\r
2920 for M in [self.Module] + self.DependentLibraryList:\r
2921 Inherited = False\r
2922 for D in M.Depex[self.Arch, ModuleType]:\r
2923 if DepexList != []:\r
2924 DepexList.append('AND')\r
2925 DepexList.append('(')\r
2926 DepexList.extend(D)\r
2927 if DepexList[-1] == 'END': # no need of a END at this time\r
2928 DepexList.pop()\r
2929 DepexList.append(')')\r
2930 Inherited = True\r
2931 if Inherited:\r
2932 EdkLogger.verbose("DEPEX[%s] (+%s) = %s" % (self.Name, M.BaseName, DepexList))\r
2933 if 'BEFORE' in DepexList or 'AFTER' in DepexList:\r
2934 break\r
2935 if len(DepexList) > 0:\r
2936 EdkLogger.verbose('')\r
2937 return self._DepexList\r
2938\r
2939 ## Merge dependency expression\r
2940 #\r
2941 # @retval list The token list of the dependency expression after parsed\r