MdePkg/DevicePathLib: Fix FromText bug for multi-instance devicepath
[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
95816356
YZ
1721 if Attr != 'PATH':\r
1722 Value += " " + self.BuildOption[Tool][Attr]\r
1723 else:\r
1724 Value = self.BuildOption[Tool][Attr]\r
52302d4d
LG
1725\r
1726 if Attr == "PATH":\r
1727 # Don't put MAKE definition in the file\r
1728 if Tool == "MAKE":\r
1729 MakePath = Value\r
1730 else:\r
1731 ToolsDef += "%s = %s\n" % (Tool, Value)\r
1732 elif Attr != "DLL":\r
1733 # Don't put MAKE definition in the file\r
1734 if Tool == "MAKE":\r
1735 if Attr == "FLAGS":\r
1736 MakeFlags = Value\r
1737 else:\r
1738 ToolsDef += "%s_%s = %s\n" % (Tool, Attr, Value)\r
1739 ToolsDef += "\n"\r
1740\r
1741 SaveFileOnChange(self.ToolDefinitionFile, ToolsDef)\r
1742 for DllPath in DllPathList:\r
1743 os.environ["PATH"] = DllPath + os.pathsep + os.environ["PATH"]\r
1744 os.environ["MAKE_FLAGS"] = MakeFlags\r
1745\r
1746 return self._ToolDefinitions\r
1747\r
1748 ## Return the paths of tools\r
1749 def _GetToolDefFile(self):\r
1750 if self._ToolDefFile == None:\r
1751 self._ToolDefFile = os.path.join(self.MakeFileDir, "TOOLS_DEF." + self.Arch)\r
1752 return self._ToolDefFile\r
1753\r
1754 ## Retrieve the toolchain family of given toolchain tag. Default to 'MSFT'.\r
1755 def _GetToolChainFamily(self):\r
1756 if self._ToolChainFamily == None:\r
1757 ToolDefinition = self.Workspace.ToolDef.ToolsDefTxtDatabase\r
1758 if TAB_TOD_DEFINES_FAMILY not in ToolDefinition \\r
1759 or self.ToolChain not in ToolDefinition[TAB_TOD_DEFINES_FAMILY] \\r
1760 or not ToolDefinition[TAB_TOD_DEFINES_FAMILY][self.ToolChain]:\r
1761 EdkLogger.verbose("No tool chain family found in configuration for %s. Default to MSFT." \\r
1762 % self.ToolChain)\r
1763 self._ToolChainFamily = "MSFT"\r
1764 else:\r
1765 self._ToolChainFamily = ToolDefinition[TAB_TOD_DEFINES_FAMILY][self.ToolChain]\r
1766 return self._ToolChainFamily\r
1767\r
1768 def _GetBuildRuleFamily(self):\r
1769 if self._BuildRuleFamily == None:\r
1770 ToolDefinition = self.Workspace.ToolDef.ToolsDefTxtDatabase\r
1771 if TAB_TOD_DEFINES_BUILDRULEFAMILY not in ToolDefinition \\r
1772 or self.ToolChain not in ToolDefinition[TAB_TOD_DEFINES_BUILDRULEFAMILY] \\r
1773 or not ToolDefinition[TAB_TOD_DEFINES_BUILDRULEFAMILY][self.ToolChain]:\r
1774 EdkLogger.verbose("No tool chain family found in configuration for %s. Default to MSFT." \\r
1775 % self.ToolChain)\r
1776 self._BuildRuleFamily = "MSFT"\r
1777 else:\r
1778 self._BuildRuleFamily = ToolDefinition[TAB_TOD_DEFINES_BUILDRULEFAMILY][self.ToolChain]\r
1779 return self._BuildRuleFamily\r
1780\r
1781 ## Return the build options specific for all modules in this platform\r
1782 def _GetBuildOptions(self):\r
1783 if self._BuildOption == None:\r
1784 self._BuildOption = self._ExpandBuildOption(self.Platform.BuildOptions)\r
1785 return self._BuildOption\r
1786\r
1787 ## Return the build options specific for EDK modules in this platform\r
1788 def _GetEdkBuildOptions(self):\r
1789 if self._EdkBuildOption == None:\r
1790 self._EdkBuildOption = self._ExpandBuildOption(self.Platform.BuildOptions, EDK_NAME)\r
1791 return self._EdkBuildOption\r
1792\r
1793 ## Return the build options specific for EDKII modules in this platform\r
1794 def _GetEdkIIBuildOptions(self):\r
1795 if self._EdkIIBuildOption == None:\r
1796 self._EdkIIBuildOption = self._ExpandBuildOption(self.Platform.BuildOptions, EDKII_NAME)\r
1797 return self._EdkIIBuildOption\r
1798\r
97fa0ee9 1799 ## Parse build_rule.txt in Conf Directory.\r
52302d4d
LG
1800 #\r
1801 # @retval BuildRule object\r
1802 #\r
1803 def _GetBuildRule(self):\r
1804 if self._BuildRule == None:\r
1805 BuildRuleFile = None\r
1806 if TAB_TAT_DEFINES_BUILD_RULE_CONF in self.Workspace.TargetTxt.TargetTxtDictionary:\r
1807 BuildRuleFile = self.Workspace.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_BUILD_RULE_CONF]\r
1808 if BuildRuleFile in [None, '']:\r
97fa0ee9 1809 BuildRuleFile = gDefaultBuildRuleFile\r
52302d4d 1810 self._BuildRule = BuildRule(BuildRuleFile)\r
64b2609f
LG
1811 if self._BuildRule._FileVersion == "":\r
1812 self._BuildRule._FileVersion = AutoGenReqBuildRuleVerNum\r
1813 else:\r
1814 if self._BuildRule._FileVersion < AutoGenReqBuildRuleVerNum :\r
1815 # If Build Rule's version is less than the version number required by the tools, halting the build.\r
47fea6af 1816 EdkLogger.error("build", AUTOGEN_ERROR,\r
64b2609f
LG
1817 ExtraData="The version number [%s] of build_rule.txt is less than the version number required by the AutoGen.(the minimum required version number is [%s])"\\r
1818 % (self._BuildRule._FileVersion, AutoGenReqBuildRuleVerNum))\r
47fea6af 1819\r
52302d4d
LG
1820 return self._BuildRule\r
1821\r
1822 ## Summarize the packages used by modules in this platform\r
1823 def _GetPackageList(self):\r
1824 if self._PackageList == None:\r
1825 self._PackageList = set()\r
1826 for La in self.LibraryAutoGenList:\r
1827 self._PackageList.update(La.DependentPackageList)\r
1828 for Ma in self.ModuleAutoGenList:\r
1829 self._PackageList.update(Ma.DependentPackageList)\r
a0a2cd1e
FB
1830 #Collect package set information from INF of FDF\r
1831 PkgSet = set()\r
1832 for ModuleFile in self._AsBuildModuleList:\r
1833 if ModuleFile in self.Platform.Modules:\r
1834 continue\r
1835 ModuleData = self.BuildDatabase[ModuleFile, self.Arch, self.BuildTarget, self.ToolChain]\r
1836 PkgSet.update(ModuleData.Packages)\r
1837 self._PackageList = list(self._PackageList) + list (PkgSet)\r
52302d4d
LG
1838 return self._PackageList\r
1839\r
2bc3256c
LG
1840 def _GetNonDynamicPcdDict(self):\r
1841 if self._NonDynamicPcdDict:\r
1842 return self._NonDynamicPcdDict\r
1843 for Pcd in self.NonDynamicPcdList:\r
1844 self._NonDynamicPcdDict[(Pcd.TokenCName,Pcd.TokenSpaceGuidCName)] = Pcd\r
1845 return self._NonDynamicPcdDict\r
1846\r
52302d4d
LG
1847 ## Get list of non-dynamic PCDs\r
1848 def _GetNonDynamicPcdList(self):\r
e56468c0 1849 if self._NonDynamicPcdList == None:\r
1850 self.CollectPlatformDynamicPcds()\r
52302d4d
LG
1851 return self._NonDynamicPcdList\r
1852\r
1853 ## Get list of dynamic PCDs\r
1854 def _GetDynamicPcdList(self):\r
e56468c0 1855 if self._DynamicPcdList == None:\r
1856 self.CollectPlatformDynamicPcds()\r
52302d4d
LG
1857 return self._DynamicPcdList\r
1858\r
1859 ## Generate Token Number for all PCD\r
1860 def _GetPcdTokenNumbers(self):\r
1861 if self._PcdTokenNumber == None:\r
1862 self._PcdTokenNumber = sdict()\r
1863 TokenNumber = 1\r
d0acc87a
LG
1864 #\r
1865 # Make the Dynamic and DynamicEx PCD use within different TokenNumber area. \r
1866 # Such as:\r
1867 # \r
1868 # Dynamic PCD:\r
1869 # TokenNumber 0 ~ 10\r
1870 # DynamicEx PCD:\r
1871 # TokeNumber 11 ~ 20\r
1872 #\r
52302d4d
LG
1873 for Pcd in self.DynamicPcdList:\r
1874 if Pcd.Phase == "PEI":\r
d0acc87a
LG
1875 if Pcd.Type in ["Dynamic", "DynamicDefault", "DynamicVpd", "DynamicHii"]:\r
1876 EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))\r
1877 self._PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber\r
1878 TokenNumber += 1\r
47fea6af 1879\r
d0acc87a
LG
1880 for Pcd in self.DynamicPcdList:\r
1881 if Pcd.Phase == "PEI":\r
1882 if Pcd.Type in ["DynamicEx", "DynamicExDefault", "DynamicExVpd", "DynamicExHii"]:\r
1883 EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))\r
1884 self._PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber\r
1885 TokenNumber += 1\r
47fea6af 1886\r
52302d4d
LG
1887 for Pcd in self.DynamicPcdList:\r
1888 if Pcd.Phase == "DXE":\r
d0acc87a
LG
1889 if Pcd.Type in ["Dynamic", "DynamicDefault", "DynamicVpd", "DynamicHii"]:\r
1890 EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))\r
1891 self._PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber\r
1892 TokenNumber += 1\r
47fea6af 1893\r
d0acc87a
LG
1894 for Pcd in self.DynamicPcdList:\r
1895 if Pcd.Phase == "DXE":\r
1896 if Pcd.Type in ["DynamicEx", "DynamicExDefault", "DynamicExVpd", "DynamicExHii"]:\r
1897 EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))\r
1898 self._PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber\r
1899 TokenNumber += 1\r
47fea6af 1900\r
52302d4d
LG
1901 for Pcd in self.NonDynamicPcdList:\r
1902 self._PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber\r
1903 TokenNumber += 1\r
1904 return self._PcdTokenNumber\r
1905\r
1906 ## Summarize ModuleAutoGen objects of all modules/libraries to be built for this platform\r
1907 def _GetAutoGenObjectList(self):\r
1908 self._ModuleAutoGenList = []\r
1909 self._LibraryAutoGenList = []\r
1910 for ModuleFile in self.Platform.Modules:\r
1911 Ma = ModuleAutoGen(\r
1912 self.Workspace,\r
1913 ModuleFile,\r
1914 self.BuildTarget,\r
1915 self.ToolChain,\r
1916 self.Arch,\r
1917 self.MetaFile\r
1918 )\r
1919 if Ma not in self._ModuleAutoGenList:\r
1920 self._ModuleAutoGenList.append(Ma)\r
1921 for La in Ma.LibraryAutoGenList:\r
1922 if La not in self._LibraryAutoGenList:\r
1923 self._LibraryAutoGenList.append(La)\r
2bc3256c
LG
1924 if Ma not in La._ReferenceModules:\r
1925 La._ReferenceModules.append(Ma)\r
52302d4d
LG
1926\r
1927 ## Summarize ModuleAutoGen objects of all modules to be built for this platform\r
1928 def _GetModuleAutoGenList(self):\r
1929 if self._ModuleAutoGenList == None:\r
1930 self._GetAutoGenObjectList()\r
1931 return self._ModuleAutoGenList\r
1932\r
1933 ## Summarize ModuleAutoGen objects of all libraries to be built for this platform\r
1934 def _GetLibraryAutoGenList(self):\r
1935 if self._LibraryAutoGenList == None:\r
1936 self._GetAutoGenObjectList()\r
1937 return self._LibraryAutoGenList\r
1938\r
1939 ## Test if a module is supported by the platform\r
1940 #\r
1941 # An error will be raised directly if the module or its arch is not supported\r
1942 # by the platform or current configuration\r
1943 #\r
1944 def ValidModule(self, Module):\r
a0a2cd1e
FB
1945 return Module in self.Platform.Modules or Module in self.Platform.LibraryInstances \\r
1946 or Module in self._AsBuildModuleList\r
52302d4d
LG
1947\r
1948 ## Resolve the library classes in a module to library instances\r
1949 #\r
1950 # This method will not only resolve library classes but also sort the library\r
1951 # instances according to the dependency-ship.\r
1952 #\r
1953 # @param Module The module from which the library classes will be resolved\r
1954 #\r
1955 # @retval library_list List of library instances sorted\r
1956 #\r
1957 def ApplyLibraryInstance(self, Module):\r
25193a33
YZ
1958 # Cover the case that the binary INF file is list in the FDF file but not DSC file, return empty list directly\r
1959 if str(Module) not in self.Platform.Modules:\r
1960 return []\r
1961\r
52302d4d
LG
1962 ModuleType = Module.ModuleType\r
1963\r
1964 # for overridding library instances with module specific setting\r
1965 PlatformModule = self.Platform.Modules[str(Module)]\r
1966\r
1967 # add forced library instances (specified under LibraryClasses sections)\r
da92f276
LG
1968 #\r
1969 # If a module has a MODULE_TYPE of USER_DEFINED,\r
1970 # do not link in NULL library class instances from the global [LibraryClasses.*] sections.\r
1971 #\r
1972 if Module.ModuleType != SUP_MODULE_USER_DEFINED:\r
1973 for LibraryClass in self.Platform.LibraryClasses.GetKeys():\r
1974 if LibraryClass.startswith("NULL") and self.Platform.LibraryClasses[LibraryClass, Module.ModuleType]:\r
1975 Module.LibraryClasses[LibraryClass] = self.Platform.LibraryClasses[LibraryClass, Module.ModuleType]\r
52302d4d
LG
1976\r
1977 # add forced library instances (specified in module overrides)\r
1978 for LibraryClass in PlatformModule.LibraryClasses:\r
1979 if LibraryClass.startswith("NULL"):\r
1980 Module.LibraryClasses[LibraryClass] = PlatformModule.LibraryClasses[LibraryClass]\r
1981\r
b36d134f 1982 # EdkII module\r
52302d4d
LG
1983 LibraryConsumerList = [Module]\r
1984 Constructor = []\r
1985 ConsumedByList = sdict()\r
1986 LibraryInstance = sdict()\r
1987\r
1988 EdkLogger.verbose("")\r
1989 EdkLogger.verbose("Library instances of module [%s] [%s]:" % (str(Module), self.Arch))\r
1990 while len(LibraryConsumerList) > 0:\r
1991 M = LibraryConsumerList.pop()\r
1992 for LibraryClassName in M.LibraryClasses:\r
1993 if LibraryClassName not in LibraryInstance:\r
1994 # override library instance for this module\r
1995 if LibraryClassName in PlatformModule.LibraryClasses:\r
1996 LibraryPath = PlatformModule.LibraryClasses[LibraryClassName]\r
1997 else:\r
1998 LibraryPath = self.Platform.LibraryClasses[LibraryClassName, ModuleType]\r
1999 if LibraryPath == None or LibraryPath == "":\r
2000 LibraryPath = M.LibraryClasses[LibraryClassName]\r
2001 if LibraryPath == None or LibraryPath == "":\r
2002 EdkLogger.error("build", RESOURCE_NOT_AVAILABLE,\r
2003 "Instance of library class [%s] is not found" % LibraryClassName,\r
2004 File=self.MetaFile,\r
2005 ExtraData="in [%s] [%s]\n\tconsumed by module [%s]" % (str(M), self.Arch, str(Module)))\r
2006\r
0d2711a6 2007 LibraryModule = self.BuildDatabase[LibraryPath, self.Arch, self.BuildTarget, self.ToolChain]\r
52302d4d
LG
2008 # for those forced library instance (NULL library), add a fake library class\r
2009 if LibraryClassName.startswith("NULL"):\r
2010 LibraryModule.LibraryClass.append(LibraryClassObject(LibraryClassName, [ModuleType]))\r
2011 elif LibraryModule.LibraryClass == None \\r
2012 or len(LibraryModule.LibraryClass) == 0 \\r
2013 or (ModuleType != 'USER_DEFINED'\r
2014 and ModuleType not in LibraryModule.LibraryClass[0].SupModList):\r
2015 # only USER_DEFINED can link against any library instance despite of its SupModList\r
2016 EdkLogger.error("build", OPTION_MISSING,\r
2017 "Module type [%s] is not supported by library instance [%s]" \\r
2018 % (ModuleType, LibraryPath), File=self.MetaFile,\r
2019 ExtraData="consumed by [%s]" % str(Module))\r
2020\r
2021 LibraryInstance[LibraryClassName] = LibraryModule\r
2022 LibraryConsumerList.append(LibraryModule)\r
2023 EdkLogger.verbose("\t" + str(LibraryClassName) + " : " + str(LibraryModule))\r
2024 else:\r
2025 LibraryModule = LibraryInstance[LibraryClassName]\r
2026\r
2027 if LibraryModule == None:\r
2028 continue\r
2029\r
2030 if LibraryModule.ConstructorList != [] and LibraryModule not in Constructor:\r
2031 Constructor.append(LibraryModule)\r
2032\r
2033 if LibraryModule not in ConsumedByList:\r
2034 ConsumedByList[LibraryModule] = []\r
2035 # don't add current module itself to consumer list\r
2036 if M != Module:\r
2037 if M in ConsumedByList[LibraryModule]:\r
2038 continue\r
2039 ConsumedByList[LibraryModule].append(M)\r
2040 #\r
2041 # Initialize the sorted output list to the empty set\r
2042 #\r
2043 SortedLibraryList = []\r
2044 #\r
2045 # Q <- Set of all nodes with no incoming edges\r
2046 #\r
2047 LibraryList = [] #LibraryInstance.values()\r
2048 Q = []\r
2049 for LibraryClassName in LibraryInstance:\r
2050 M = LibraryInstance[LibraryClassName]\r
2051 LibraryList.append(M)\r
2052 if ConsumedByList[M] == []:\r
2053 Q.append(M)\r
2054\r
2055 #\r
2056 # start the DAG algorithm\r
2057 #\r
2058 while True:\r
2059 EdgeRemoved = True\r
2060 while Q == [] and EdgeRemoved:\r
2061 EdgeRemoved = False\r
2062 # for each node Item with a Constructor\r
2063 for Item in LibraryList:\r
2064 if Item not in Constructor:\r
2065 continue\r
2066 # for each Node without a constructor with an edge e from Item to Node\r
2067 for Node in ConsumedByList[Item]:\r
2068 if Node in Constructor:\r
2069 continue\r
2070 # remove edge e from the graph if Node has no constructor\r
2071 ConsumedByList[Item].remove(Node)\r
2072 EdgeRemoved = True\r
2073 if ConsumedByList[Item] == []:\r
2074 # insert Item into Q\r
2075 Q.insert(0, Item)\r
2076 break\r
2077 if Q != []:\r
2078 break\r
2079 # DAG is done if there's no more incoming edge for all nodes\r
2080 if Q == []:\r
2081 break\r
2082\r
2083 # remove node from Q\r
2084 Node = Q.pop()\r
2085 # output Node\r
2086 SortedLibraryList.append(Node)\r
2087\r
2088 # for each node Item with an edge e from Node to Item do\r
2089 for Item in LibraryList:\r
2090 if Node not in ConsumedByList[Item]:\r
2091 continue\r
2092 # remove edge e from the graph\r
2093 ConsumedByList[Item].remove(Node)\r
2094\r
2095 if ConsumedByList[Item] != []:\r
2096 continue\r
2097 # insert Item into Q, if Item has no other incoming edges\r
2098 Q.insert(0, Item)\r
2099\r
2100 #\r
2101 # if any remaining node Item in the graph has a constructor and an incoming edge, then the graph has a cycle\r
2102 #\r
2103 for Item in LibraryList:\r
2104 if ConsumedByList[Item] != [] and Item in Constructor and len(Constructor) > 1:\r
2105 ErrorMessage = "\tconsumed by " + "\n\tconsumed by ".join([str(L) for L in ConsumedByList[Item]])\r
2106 EdkLogger.error("build", BUILD_ERROR, 'Library [%s] with constructors has a cycle' % str(Item),\r
2107 ExtraData=ErrorMessage, File=self.MetaFile)\r
2108 if Item not in SortedLibraryList:\r
2109 SortedLibraryList.append(Item)\r
2110\r
2111 #\r
2112 # Build the list of constructor and destructir names\r
2113 # The DAG Topo sort produces the destructor order, so the list of constructors must generated in the reverse order\r
2114 #\r
2115 SortedLibraryList.reverse()\r
2116 return SortedLibraryList\r
2117\r
2118\r
2119 ## Override PCD setting (type, value, ...)\r
2120 #\r
2121 # @param ToPcd The PCD to be overrided\r
2122 # @param FromPcd The PCD overrideing from\r
2123 #\r
2124 def _OverridePcd(self, ToPcd, FromPcd, Module=""):\r
2125 #\r
2126 # in case there's PCDs coming from FDF file, which have no type given.\r
2127 # at this point, ToPcd.Type has the type found from dependent\r
2128 # package\r
2129 #\r
2a29017e
YZ
2130 TokenCName = ToPcd.TokenCName\r
2131 for PcdItem in GlobalData.MixedPcd:\r
2132 if (ToPcd.TokenCName, ToPcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
2133 TokenCName = PcdItem[0]\r
2134 break\r
52302d4d 2135 if FromPcd != None:\r
2a29017e
YZ
2136 if GlobalData.BuildOptionPcd:\r
2137 for pcd in GlobalData.BuildOptionPcd:\r
2138 if (FromPcd.TokenSpaceGuidCName, FromPcd.TokenCName) == (pcd[0], pcd[1]):\r
2139 FromPcd.DefaultValue = pcd[2]\r
2140 break\r
52302d4d
LG
2141 if ToPcd.Pending and FromPcd.Type not in [None, '']:\r
2142 ToPcd.Type = FromPcd.Type\r
e56468c0 2143 elif (ToPcd.Type not in [None, '']) and (FromPcd.Type not in [None, ''])\\r
2144 and (ToPcd.Type != FromPcd.Type) and (ToPcd.Type in FromPcd.Type):\r
2145 if ToPcd.Type.strip() == "DynamicEx":\r
47fea6af 2146 ToPcd.Type = FromPcd.Type\r
52302d4d
LG
2147 elif ToPcd.Type not in [None, ''] and FromPcd.Type not in [None, ''] \\r
2148 and ToPcd.Type != FromPcd.Type:\r
2149 EdkLogger.error("build", OPTION_CONFLICT, "Mismatched PCD type",\r
2150 ExtraData="%s.%s is defined as [%s] in module %s, but as [%s] in platform."\\r
2a29017e 2151 % (ToPcd.TokenSpaceGuidCName, TokenCName,\r
52302d4d
LG
2152 ToPcd.Type, Module, FromPcd.Type),\r
2153 File=self.MetaFile)\r
2154\r
2155 if FromPcd.MaxDatumSize not in [None, '']:\r
2156 ToPcd.MaxDatumSize = FromPcd.MaxDatumSize\r
2157 if FromPcd.DefaultValue not in [None, '']:\r
2158 ToPcd.DefaultValue = FromPcd.DefaultValue\r
2159 if FromPcd.TokenValue not in [None, '']:\r
2160 ToPcd.TokenValue = FromPcd.TokenValue\r
2161 if FromPcd.MaxDatumSize not in [None, '']:\r
2162 ToPcd.MaxDatumSize = FromPcd.MaxDatumSize\r
2163 if FromPcd.DatumType not in [None, '']:\r
2164 ToPcd.DatumType = FromPcd.DatumType\r
2165 if FromPcd.SkuInfoList not in [None, '', []]:\r
2166 ToPcd.SkuInfoList = FromPcd.SkuInfoList\r
2167\r
2168 # check the validation of datum\r
2169 IsValid, Cause = CheckPcdDatum(ToPcd.DatumType, ToPcd.DefaultValue)\r
2170 if not IsValid:\r
2171 EdkLogger.error('build', FORMAT_INVALID, Cause, File=self.MetaFile,\r
2a29017e 2172 ExtraData="%s.%s" % (ToPcd.TokenSpaceGuidCName, TokenCName))\r
82a6a960
BF
2173 ToPcd.validateranges = FromPcd.validateranges\r
2174 ToPcd.validlists = FromPcd.validlists\r
2175 ToPcd.expressions = FromPcd.expressions\r
52302d4d
LG
2176\r
2177 if ToPcd.DatumType == "VOID*" and ToPcd.MaxDatumSize in ['', None]:\r
2178 EdkLogger.debug(EdkLogger.DEBUG_9, "No MaxDatumSize specified for PCD %s.%s" \\r
2a29017e 2179 % (ToPcd.TokenSpaceGuidCName, TokenCName))\r
52302d4d
LG
2180 Value = ToPcd.DefaultValue\r
2181 if Value in [None, '']:\r
e8a47801 2182 ToPcd.MaxDatumSize = '1'\r
52302d4d 2183 elif Value[0] == 'L':\r
e8a47801 2184 ToPcd.MaxDatumSize = str((len(Value) - 2) * 2)\r
52302d4d
LG
2185 elif Value[0] == '{':\r
2186 ToPcd.MaxDatumSize = str(len(Value.split(',')))\r
2187 else:\r
e8a47801 2188 ToPcd.MaxDatumSize = str(len(Value) - 1)\r
52302d4d
LG
2189\r
2190 # apply default SKU for dynamic PCDS if specified one is not available\r
2191 if (ToPcd.Type in PCD_DYNAMIC_TYPE_LIST or ToPcd.Type in PCD_DYNAMIC_EX_TYPE_LIST) \\r
2192 and ToPcd.SkuInfoList in [None, {}, '']:\r
2193 if self.Platform.SkuName in self.Platform.SkuIds:\r
2194 SkuName = self.Platform.SkuName\r
2195 else:\r
2196 SkuName = 'DEFAULT'\r
2197 ToPcd.SkuInfoList = {\r
2198 SkuName : SkuInfoClass(SkuName, self.Platform.SkuIds[SkuName], '', '', '', '', '', ToPcd.DefaultValue)\r
2199 }\r
2200\r
2201 ## Apply PCD setting defined platform to a module\r
2202 #\r
2203 # @param Module The module from which the PCD setting will be overrided\r
2204 #\r
2205 # @retval PCD_list The list PCDs with settings from platform\r
2206 #\r
2207 def ApplyPcdSetting(self, Module, Pcds):\r
2208 # for each PCD in module\r
47fea6af
YZ
2209 for Name, Guid in Pcds:\r
2210 PcdInModule = Pcds[Name, Guid]\r
52302d4d 2211 # find out the PCD setting in platform\r
47fea6af
YZ
2212 if (Name, Guid) in self.Platform.Pcds:\r
2213 PcdInPlatform = self.Platform.Pcds[Name, Guid]\r
52302d4d
LG
2214 else:\r
2215 PcdInPlatform = None\r
2216 # then override the settings if any\r
2217 self._OverridePcd(PcdInModule, PcdInPlatform, Module)\r
2218 # resolve the VariableGuid value\r
2219 for SkuId in PcdInModule.SkuInfoList:\r
2220 Sku = PcdInModule.SkuInfoList[SkuId]\r
2221 if Sku.VariableGuid == '': continue\r
c28d2e10 2222 Sku.VariableGuidValue = GuidValue(Sku.VariableGuid, self.PackageList, self.MetaFile.Path)\r
52302d4d
LG
2223 if Sku.VariableGuidValue == None:\r
2224 PackageList = "\n\t".join([str(P) for P in self.PackageList])\r
2225 EdkLogger.error(\r
2226 'build',\r
2227 RESOURCE_NOT_AVAILABLE,\r
2228 "Value of GUID [%s] is not found in" % Sku.VariableGuid,\r
2229 ExtraData=PackageList + "\n\t(used with %s.%s from module %s)" \\r
2230 % (Guid, Name, str(Module)),\r
2231 File=self.MetaFile\r
2232 )\r
2233\r
2234 # override PCD settings with module specific setting\r
2235 if Module in self.Platform.Modules:\r
2236 PlatformModule = self.Platform.Modules[str(Module)]\r
2237 for Key in PlatformModule.Pcds:\r
2238 if Key in Pcds:\r
2239 self._OverridePcd(Pcds[Key], PlatformModule.Pcds[Key], Module)\r
2240 return Pcds.values()\r
2241\r
2242 ## Resolve library names to library modules\r
2243 #\r
b36d134f 2244 # (for Edk.x modules)\r
52302d4d
LG
2245 #\r
2246 # @param Module The module from which the library names will be resolved\r
2247 #\r
2248 # @retval library_list The list of library modules\r
2249 #\r
2250 def ResolveLibraryReference(self, Module):\r
2251 EdkLogger.verbose("")\r
2252 EdkLogger.verbose("Library instances of module [%s] [%s]:" % (str(Module), self.Arch))\r
2253 LibraryConsumerList = [Module]\r
2254\r
b36d134f 2255 # "CompilerStub" is a must for Edk modules\r
52302d4d
LG
2256 if Module.Libraries:\r
2257 Module.Libraries.append("CompilerStub")\r
2258 LibraryList = []\r
2259 while len(LibraryConsumerList) > 0:\r
2260 M = LibraryConsumerList.pop()\r
2261 for LibraryName in M.Libraries:\r
2262 Library = self.Platform.LibraryClasses[LibraryName, ':dummy:']\r
2263 if Library == None:\r
2264 for Key in self.Platform.LibraryClasses.data.keys():\r
2265 if LibraryName.upper() == Key.upper():\r
2266 Library = self.Platform.LibraryClasses[Key, ':dummy:']\r
2267 break\r
2268 if Library == None:\r
2269 EdkLogger.warn("build", "Library [%s] is not found" % LibraryName, File=str(M),\r
2270 ExtraData="\t%s [%s]" % (str(Module), self.Arch))\r
2271 continue\r
2272\r
2273 if Library not in LibraryList:\r
2274 LibraryList.append(Library)\r
2275 LibraryConsumerList.append(Library)\r
2276 EdkLogger.verbose("\t" + LibraryName + " : " + str(Library) + ' ' + str(type(Library)))\r
2277 return LibraryList\r
2278\r
6780eef1
LG
2279 ## Calculate the priority value of the build option\r
2280 #\r
2281 # @param Key Build option definition contain: TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE\r
2282 #\r
2283 # @retval Value Priority value based on the priority list.\r
2284 #\r
2285 def CalculatePriorityValue(self, Key):\r
47fea6af
YZ
2286 Target, ToolChain, Arch, CommandType, Attr = Key.split('_')\r
2287 PriorityValue = 0x11111\r
6780eef1
LG
2288 if Target == "*":\r
2289 PriorityValue &= 0x01111\r
2290 if ToolChain == "*":\r
2291 PriorityValue &= 0x10111\r
2292 if Arch == "*":\r
2293 PriorityValue &= 0x11011\r
2294 if CommandType == "*":\r
2295 PriorityValue &= 0x11101\r
2296 if Attr == "*":\r
2297 PriorityValue &= 0x11110\r
47fea6af
YZ
2298\r
2299 return self.PrioList["0x%0.5x" % PriorityValue]\r
2300\r
6780eef1 2301\r
52302d4d
LG
2302 ## Expand * in build option key\r
2303 #\r
2304 # @param Options Options to be expanded\r
2305 #\r
2306 # @retval options Options expanded\r
6780eef1 2307 # \r
52302d4d
LG
2308 def _ExpandBuildOption(self, Options, ModuleStyle=None):\r
2309 BuildOptions = {}\r
2310 FamilyMatch = False\r
2311 FamilyIsNull = True\r
47fea6af 2312\r
6780eef1
LG
2313 OverrideList = {}\r
2314 #\r
2315 # Construct a list contain the build options which need override.\r
2316 #\r
2317 for Key in Options:\r
2318 #\r
2319 # Key[0] -- tool family\r
2320 # Key[1] -- TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE\r
2321 #\r
1ba5124e
YL
2322 if (Key[0] == self.BuildRuleFamily and\r
2323 (ModuleStyle == None or len(Key) < 3 or (len(Key) > 2 and Key[2] == ModuleStyle))):\r
6780eef1
LG
2324 Target, ToolChain, Arch, CommandType, Attr = Key[1].split('_')\r
2325 if Target == self.BuildTarget or Target == "*":\r
2326 if ToolChain == self.ToolChain or ToolChain == "*":\r
2327 if Arch == self.Arch or Arch == "*":\r
2328 if Options[Key].startswith("="):\r
47fea6af 2329 if OverrideList.get(Key[1]) != None:\r
6780eef1
LG
2330 OverrideList.pop(Key[1])\r
2331 OverrideList[Key[1]] = Options[Key]\r
2332 \r
2333 #\r
2334 # Use the highest priority value. \r
2335 #\r
2336 if (len(OverrideList) >= 2):\r
47fea6af 2337 KeyList = OverrideList.keys()\r
6780eef1 2338 for Index in range(len(KeyList)):\r
47fea6af 2339 NowKey = KeyList[Index]\r
6780eef1
LG
2340 Target1, ToolChain1, Arch1, CommandType1, Attr1 = NowKey.split("_")\r
2341 for Index1 in range(len(KeyList) - Index - 1):\r
2342 NextKey = KeyList[Index1 + Index + 1]\r
2343 #\r
2344 # Compare two Key, if one is included by another, choose the higher priority one\r
2345 # \r
2346 Target2, ToolChain2, Arch2, CommandType2, Attr2 = NextKey.split("_")\r
2347 if Target1 == Target2 or Target1 == "*" or Target2 == "*":\r
2348 if ToolChain1 == ToolChain2 or ToolChain1 == "*" or ToolChain2 == "*":\r
2349 if Arch1 == Arch2 or Arch1 == "*" or Arch2 == "*":\r
2350 if CommandType1 == CommandType2 or CommandType1 == "*" or CommandType2 == "*":\r
2351 if Attr1 == Attr2 or Attr1 == "*" or Attr2 == "*":\r
2352 if self.CalculatePriorityValue(NowKey) > self.CalculatePriorityValue(NextKey):\r
47fea6af 2353 if Options.get((self.BuildRuleFamily, NextKey)) != None:\r
6780eef1
LG
2354 Options.pop((self.BuildRuleFamily, NextKey))\r
2355 else:\r
47fea6af 2356 if Options.get((self.BuildRuleFamily, NowKey)) != None:\r
6780eef1
LG
2357 Options.pop((self.BuildRuleFamily, NowKey))\r
2358 \r
52302d4d
LG
2359 for Key in Options:\r
2360 if ModuleStyle != None and len (Key) > 2:\r
2361 # Check Module style is EDK or EDKII.\r
2362 # Only append build option for the matched style module.\r
2363 if ModuleStyle == EDK_NAME and Key[2] != EDK_NAME:\r
2364 continue\r
2365 elif ModuleStyle == EDKII_NAME and Key[2] != EDKII_NAME:\r
2366 continue\r
2367 Family = Key[0]\r
2368 Target, Tag, Arch, Tool, Attr = Key[1].split("_")\r
2369 # if tool chain family doesn't match, skip it\r
2370 if Tool in self.ToolDefinition and Family != "":\r
2371 FamilyIsNull = False\r
2372 if self.ToolDefinition[Tool].get(TAB_TOD_DEFINES_BUILDRULEFAMILY, "") != "":\r
2373 if Family != self.ToolDefinition[Tool][TAB_TOD_DEFINES_BUILDRULEFAMILY]:\r
2374 continue\r
2375 elif Family != self.ToolDefinition[Tool][TAB_TOD_DEFINES_FAMILY]:\r
2376 continue\r
2377 FamilyMatch = True\r
2378 # expand any wildcard\r
2379 if Target == "*" or Target == self.BuildTarget:\r
2380 if Tag == "*" or Tag == self.ToolChain:\r
2381 if Arch == "*" or Arch == self.Arch:\r
2382 if Tool not in BuildOptions:\r
2383 BuildOptions[Tool] = {}\r
5015bee2 2384 if Attr != "FLAGS" or Attr not in BuildOptions[Tool] or Options[Key].startswith('='):\r
52302d4d
LG
2385 BuildOptions[Tool][Attr] = Options[Key]\r
2386 else:\r
95816356
YZ
2387 # append options for the same tool except PATH\r
2388 if Attr != 'PATH':\r
2389 BuildOptions[Tool][Attr] += " " + Options[Key]\r
2390 else:\r
2391 BuildOptions[Tool][Attr] = Options[Key]\r
52302d4d
LG
2392 # Build Option Family has been checked, which need't to be checked again for family.\r
2393 if FamilyMatch or FamilyIsNull:\r
2394 return BuildOptions\r
1ba5124e 2395\r
52302d4d
LG
2396 for Key in Options:\r
2397 if ModuleStyle != None and len (Key) > 2:\r
2398 # Check Module style is EDK or EDKII.\r
2399 # Only append build option for the matched style module.\r
2400 if ModuleStyle == EDK_NAME and Key[2] != EDK_NAME:\r
2401 continue\r
2402 elif ModuleStyle == EDKII_NAME and Key[2] != EDKII_NAME:\r
2403 continue\r
2404 Family = Key[0]\r
2405 Target, Tag, Arch, Tool, Attr = Key[1].split("_")\r
2406 # if tool chain family doesn't match, skip it\r
47fea6af 2407 if Tool not in self.ToolDefinition or Family == "":\r
52302d4d
LG
2408 continue\r
2409 # option has been added before\r
2410 if Family != self.ToolDefinition[Tool][TAB_TOD_DEFINES_FAMILY]:\r
2411 continue\r
2412\r
2413 # expand any wildcard\r
2414 if Target == "*" or Target == self.BuildTarget:\r
2415 if Tag == "*" or Tag == self.ToolChain:\r
2416 if Arch == "*" or Arch == self.Arch:\r
2417 if Tool not in BuildOptions:\r
2418 BuildOptions[Tool] = {}\r
5015bee2 2419 if Attr != "FLAGS" or Attr not in BuildOptions[Tool] or Options[Key].startswith('='):\r
52302d4d
LG
2420 BuildOptions[Tool][Attr] = Options[Key]\r
2421 else:\r
95816356
YZ
2422 # append options for the same tool except PATH\r
2423 if Attr != 'PATH':\r
2424 BuildOptions[Tool][Attr] += " " + Options[Key]\r
2425 else:\r
2426 BuildOptions[Tool][Attr] = Options[Key]\r
52302d4d
LG
2427 return BuildOptions\r
2428\r
2429 ## Append build options in platform to a module\r
2430 #\r
2431 # @param Module The module to which the build options will be appened\r
2432 #\r
2433 # @retval options The options appended with build options in platform\r
2434 #\r
2435 def ApplyBuildOption(self, Module):\r
2436 # Get the different options for the different style module\r
2437 if Module.AutoGenVersion < 0x00010005:\r
2438 PlatformOptions = self.EdkBuildOption\r
35f69db9 2439 ModuleTypeOptions = self.Platform.GetBuildOptionsByModuleType(EDK_NAME, Module.ModuleType)\r
52302d4d
LG
2440 else:\r
2441 PlatformOptions = self.EdkIIBuildOption\r
35f69db9
YL
2442 ModuleTypeOptions = self.Platform.GetBuildOptionsByModuleType(EDKII_NAME, Module.ModuleType)\r
2443 ModuleTypeOptions = self._ExpandBuildOption(ModuleTypeOptions)\r
52302d4d
LG
2444 ModuleOptions = self._ExpandBuildOption(Module.BuildOptions)\r
2445 if Module in self.Platform.Modules:\r
2446 PlatformModule = self.Platform.Modules[str(Module)]\r
2447 PlatformModuleOptions = self._ExpandBuildOption(PlatformModule.BuildOptions)\r
2448 else:\r
2449 PlatformModuleOptions = {}\r
2450\r
fe4bf2f9 2451 BuildRuleOrder = None\r
35f69db9 2452 for Options in [self.ToolDefinition, ModuleOptions, PlatformOptions, ModuleTypeOptions, PlatformModuleOptions]:\r
fe4bf2f9
YL
2453 for Tool in Options:\r
2454 for Attr in Options[Tool]:\r
2455 if Attr == TAB_TOD_DEFINES_BUILDRULEORDER:\r
2456 BuildRuleOrder = Options[Tool][Attr]\r
2457\r
35f69db9
YL
2458 AllTools = set(ModuleOptions.keys() + PlatformOptions.keys() +\r
2459 PlatformModuleOptions.keys() + ModuleTypeOptions.keys() +\r
2460 self.ToolDefinition.keys())\r
52302d4d
LG
2461 BuildOptions = {}\r
2462 for Tool in AllTools:\r
2463 if Tool not in BuildOptions:\r
2464 BuildOptions[Tool] = {}\r
2465\r
35f69db9 2466 for Options in [self.ToolDefinition, ModuleOptions, PlatformOptions, ModuleTypeOptions, PlatformModuleOptions]:\r
52302d4d
LG
2467 if Tool not in Options:\r
2468 continue\r
2469 for Attr in Options[Tool]:\r
2470 Value = Options[Tool][Attr]\r
fe4bf2f9
YL
2471 #\r
2472 # Do not generate it in Makefile\r
2473 #\r
2474 if Attr == TAB_TOD_DEFINES_BUILDRULEORDER:\r
2475 continue\r
52302d4d
LG
2476 if Attr not in BuildOptions[Tool]:\r
2477 BuildOptions[Tool][Attr] = ""\r
2478 # check if override is indicated\r
2479 if Value.startswith('='):\r
05cc51ad
LY
2480 ToolPath = Value[1:]\r
2481 ToolPath = mws.handleWsMacro(ToolPath)\r
2482 BuildOptions[Tool][Attr] = ToolPath\r
5015bee2 2483 else:\r
05cc51ad 2484 Value = mws.handleWsMacro(Value)\r
95816356
YZ
2485 if Attr != 'PATH':\r
2486 BuildOptions[Tool][Attr] += " " + Value\r
2487 else:\r
2488 BuildOptions[Tool][Attr] = Value\r
f3decdc3
LG
2489 if Module.AutoGenVersion < 0x00010005 and self.Workspace.UniFlag != None:\r
2490 #\r
2491 # Override UNI flag only for EDK module.\r
2492 #\r
2493 if 'BUILD' not in BuildOptions:\r
2494 BuildOptions['BUILD'] = {}\r
2495 BuildOptions['BUILD']['FLAGS'] = self.Workspace.UniFlag\r
fe4bf2f9 2496 return BuildOptions, BuildRuleOrder\r
52302d4d
LG
2497\r
2498 Platform = property(_GetPlatform)\r
2499 Name = property(_GetName)\r
2500 Guid = property(_GetGuid)\r
2501 Version = property(_GetVersion)\r
2502\r
2503 OutputDir = property(_GetOutputDir)\r
2504 BuildDir = property(_GetBuildDir)\r
2505 MakeFileDir = property(_GetMakeFileDir)\r
2506 FdfFile = property(_GetFdfFile)\r
2507\r
2508 PcdTokenNumber = property(_GetPcdTokenNumbers) # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber\r
2509 DynamicPcdList = property(_GetDynamicPcdList) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]\r
2510 NonDynamicPcdList = property(_GetNonDynamicPcdList) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]\r
2bc3256c 2511 NonDynamicPcdDict = property(_GetNonDynamicPcdDict)\r
52302d4d
LG
2512 PackageList = property(_GetPackageList)\r
2513\r
2514 ToolDefinition = property(_GetToolDefinition) # toolcode : tool path\r
2515 ToolDefinitionFile = property(_GetToolDefFile) # toolcode : lib path\r
2516 ToolChainFamily = property(_GetToolChainFamily)\r
2517 BuildRuleFamily = property(_GetBuildRuleFamily)\r
2518 BuildOption = property(_GetBuildOptions) # toolcode : option\r
2519 EdkBuildOption = property(_GetEdkBuildOptions) # edktoolcode : option\r
2520 EdkIIBuildOption = property(_GetEdkIIBuildOptions) # edkiitoolcode : option\r
2521\r
2522 BuildCommand = property(_GetBuildCommand)\r
2523 BuildRule = property(_GetBuildRule)\r
2524 ModuleAutoGenList = property(_GetModuleAutoGenList)\r
2525 LibraryAutoGenList = property(_GetLibraryAutoGenList)\r
0923aa1c 2526 GenFdsCommand = property(_GenFdsCommand)\r
52302d4d
LG
2527\r
2528## ModuleAutoGen class\r
2529#\r
2530# This class encapsules the AutoGen behaviors for the build tools. In addition to\r
2531# the generation of AutoGen.h and AutoGen.c, it will generate *.depex file according\r
2532# to the [depex] section in module's inf file.\r
2533#\r
2534class ModuleAutoGen(AutoGen):\r
2535 ## The real constructor of ModuleAutoGen\r
2536 #\r
2537 # This method is not supposed to be called by users of ModuleAutoGen. It's\r
2538 # only used by factory method __new__() to do real initialization work for an\r
2539 # object of ModuleAutoGen\r
2540 #\r
2541 # @param Workspace EdkIIWorkspaceBuild object\r
2542 # @param ModuleFile The path of module file\r
2543 # @param Target Build target (DEBUG, RELEASE)\r
2544 # @param Toolchain Name of tool chain\r
2545 # @param Arch The arch the module supports\r
2546 # @param PlatformFile Platform meta-file\r
2547 #\r
2548 def _Init(self, Workspace, ModuleFile, Target, Toolchain, Arch, PlatformFile):\r
2549 EdkLogger.debug(EdkLogger.DEBUG_9, "AutoGen module [%s] [%s]" % (ModuleFile, Arch))\r
2550 GlobalData.gProcessingFile = "%s [%s, %s, %s]" % (ModuleFile, Arch, Toolchain, Target)\r
2551\r
2552 self.Workspace = Workspace\r
2553 self.WorkspaceDir = Workspace.WorkspaceDir\r
2554\r
2555 self.MetaFile = ModuleFile\r
2556 self.PlatformInfo = PlatformAutoGen(Workspace, PlatformFile, Target, Toolchain, Arch)\r
2557 # check if this module is employed by active platform\r
2558 if not self.PlatformInfo.ValidModule(self.MetaFile):\r
2559 EdkLogger.verbose("Module [%s] for [%s] is not employed by active platform\n" \\r
2560 % (self.MetaFile, Arch))\r
2561 return False\r
2562\r
2563 self.SourceDir = self.MetaFile.SubDir\r
05cc51ad 2564 self.SourceDir = mws.relpath(self.SourceDir, self.WorkspaceDir)\r
97fa0ee9 2565\r
52302d4d
LG
2566 self.SourceOverrideDir = None\r
2567 # use overrided path defined in DSC file\r
2568 if self.MetaFile.Key in GlobalData.gOverrideDir:\r
2569 self.SourceOverrideDir = GlobalData.gOverrideDir[self.MetaFile.Key]\r
2570\r
2571 self.ToolChain = Toolchain\r
2572 self.BuildTarget = Target\r
2573 self.Arch = Arch\r
2574 self.ToolChainFamily = self.PlatformInfo.ToolChainFamily\r
2575 self.BuildRuleFamily = self.PlatformInfo.BuildRuleFamily\r
2576\r
2577 self.IsMakeFileCreated = False\r
2578 self.IsCodeFileCreated = False\r
da92f276
LG
2579 self.IsAsBuiltInfCreated = False\r
2580 self.DepexGenerated = False\r
52302d4d
LG
2581\r
2582 self.BuildDatabase = self.Workspace.BuildDatabase\r
fe4bf2f9 2583 self.BuildRuleOrder = None\r
52302d4d
LG
2584\r
2585 self._Module = None\r
2586 self._Name = None\r
2587 self._Guid = None\r
2588 self._Version = None\r
2589 self._ModuleType = None\r
2590 self._ComponentType = None\r
2591 self._PcdIsDriver = None\r
2592 self._AutoGenVersion = None\r
2593 self._LibraryFlag = None\r
2594 self._CustomMakefile = None\r
2595 self._Macro = None\r
2596\r
2597 self._BuildDir = None\r
2598 self._OutputDir = None\r
2599 self._DebugDir = None\r
2600 self._MakeFileDir = None\r
2601\r
2602 self._IncludePathList = None\r
725cdb8f 2603 self._IncludePathLength = 0\r
52302d4d
LG
2604 self._AutoGenFileList = None\r
2605 self._UnicodeFileList = None\r
5b97eb4c 2606 self._VfrFileList = None\r
333ba578 2607 self._IdfFileList = None\r
52302d4d
LG
2608 self._SourceFileList = None\r
2609 self._ObjectFileList = None\r
2610 self._BinaryFileList = None\r
2611\r
2612 self._DependentPackageList = None\r
2613 self._DependentLibraryList = None\r
2614 self._LibraryAutoGenList = None\r
2615 self._DerivedPackageList = None\r
2616 self._ModulePcdList = None\r
2617 self._LibraryPcdList = None\r
e8a47801 2618 self._PcdComments = sdict()\r
52302d4d 2619 self._GuidList = None\r
e8a47801
LG
2620 self._GuidsUsedByPcd = None\r
2621 self._GuidComments = sdict()\r
52302d4d 2622 self._ProtocolList = None\r
e8a47801 2623 self._ProtocolComments = sdict()\r
52302d4d 2624 self._PpiList = None\r
e8a47801 2625 self._PpiComments = sdict()\r
52302d4d
LG
2626 self._DepexList = None\r
2627 self._DepexExpressionList = None\r
2628 self._BuildOption = None\r
79b74a03 2629 self._BuildOptionIncPathList = None\r
52302d4d
LG
2630 self._BuildTargets = None\r
2631 self._IntroBuildTargetList = None\r
2632 self._FinalBuildTargetList = None\r
2633 self._FileTypes = None\r
2634 self._BuildRules = None\r
2bc3256c
LG
2635 \r
2636 ## The Modules referenced to this Library\r
2637 # Only Library has this attribute\r
2638 self._ReferenceModules = [] \r
2639 \r
2640 ## Store the FixedAtBuild Pcds\r
2641 # \r
2642 self._FixedAtBuildPcds = []\r
2643 self.ConstPcd = {}\r
52302d4d
LG
2644 return True\r
2645\r
2646 def __repr__(self):\r
2647 return "%s [%s]" % (self.MetaFile, self.Arch)\r
2648\r
2bc3256c
LG
2649 # Get FixedAtBuild Pcds of this Module\r
2650 def _GetFixedAtBuildPcds(self):\r
2651 if self._FixedAtBuildPcds:\r
2652 return self._FixedAtBuildPcds\r
2653 for Pcd in self.ModulePcdList:\r
2654 if self.IsLibrary:\r
2655 if not (Pcd.Pending == False and Pcd.Type == "FixedAtBuild"):\r
2656 continue\r
2657 elif Pcd.Type != "FixedAtBuild":\r
2658 continue\r
2659 if Pcd not in self._FixedAtBuildPcds:\r
2660 self._FixedAtBuildPcds.append(Pcd)\r
2661 \r
2662 return self._FixedAtBuildPcds \r
2663\r
867d1cd4
YL
2664 def _GetUniqueBaseName(self):\r
2665 BaseName = self.Name\r
2666 for Module in self.PlatformInfo.ModuleAutoGenList:\r
2667 if Module.MetaFile == self.MetaFile:\r
2668 continue\r
2669 if Module.Name == self.Name:\r
867d1cd4
YL
2670 if uuid.UUID(Module.Guid) == uuid.UUID(self.Guid):\r
2671 EdkLogger.error("build", FILE_DUPLICATED, 'Modules have same BaseName and FILE_GUID:\n'\r
2672 ' %s\n %s' % (Module.MetaFile, self.MetaFile))\r
2673 BaseName = '%s_%s' % (self.Name, self.Guid)\r
2674 return BaseName\r
2675\r
52302d4d
LG
2676 # Macros could be used in build_rule.txt (also Makefile)\r
2677 def _GetMacros(self):\r
2678 if self._Macro == None:\r
2679 self._Macro = sdict()\r
2680 self._Macro["WORKSPACE" ] = self.WorkspaceDir\r
2681 self._Macro["MODULE_NAME" ] = self.Name\r
867d1cd4 2682 self._Macro["MODULE_NAME_GUID" ] = self._GetUniqueBaseName()\r
52302d4d
LG
2683 self._Macro["MODULE_GUID" ] = self.Guid\r
2684 self._Macro["MODULE_VERSION" ] = self.Version\r
2685 self._Macro["MODULE_TYPE" ] = self.ModuleType\r
2686 self._Macro["MODULE_FILE" ] = str(self.MetaFile)\r
2687 self._Macro["MODULE_FILE_BASE_NAME" ] = self.MetaFile.BaseName\r
2688 self._Macro["MODULE_RELATIVE_DIR" ] = self.SourceDir\r
2689 self._Macro["MODULE_DIR" ] = self.SourceDir\r
2690\r
2691 self._Macro["BASE_NAME" ] = self.Name\r
2692\r
2693 self._Macro["ARCH" ] = self.Arch\r
2694 self._Macro["TOOLCHAIN" ] = self.ToolChain\r
2695 self._Macro["TOOLCHAIN_TAG" ] = self.ToolChain\r
0d2711a6 2696 self._Macro["TOOL_CHAIN_TAG" ] = self.ToolChain\r
52302d4d
LG
2697 self._Macro["TARGET" ] = self.BuildTarget\r
2698\r
2699 self._Macro["BUILD_DIR" ] = self.PlatformInfo.BuildDir\r
2700 self._Macro["BIN_DIR" ] = os.path.join(self.PlatformInfo.BuildDir, self.Arch)\r
2701 self._Macro["LIB_DIR" ] = os.path.join(self.PlatformInfo.BuildDir, self.Arch)\r
2702 self._Macro["MODULE_BUILD_DIR" ] = self.BuildDir\r
2703 self._Macro["OUTPUT_DIR" ] = self.OutputDir\r
2704 self._Macro["DEBUG_DIR" ] = self.DebugDir\r
df1e1b63
YZ
2705 self._Macro["DEST_DIR_OUTPUT" ] = self.OutputDir\r
2706 self._Macro["DEST_DIR_DEBUG" ] = self.DebugDir\r
3570e332
YZ
2707 self._Macro["PLATFORM_NAME" ] = self.PlatformInfo.Name\r
2708 self._Macro["PLATFORM_GUID" ] = self.PlatformInfo.Guid\r
2709 self._Macro["PLATFORM_VERSION" ] = self.PlatformInfo.Version\r
2710 self._Macro["PLATFORM_RELATIVE_DIR" ] = self.PlatformInfo.SourceDir\r
2711 self._Macro["PLATFORM_DIR" ] = mws.join(self.WorkspaceDir, self.PlatformInfo.SourceDir)\r
2712 self._Macro["PLATFORM_OUTPUT_DIR" ] = self.PlatformInfo.OutputDir\r
52302d4d
LG
2713 return self._Macro\r
2714\r
2715 ## Return the module build data object\r
2716 def _GetModule(self):\r
2717 if self._Module == None:\r
0d2711a6 2718 self._Module = self.Workspace.BuildDatabase[self.MetaFile, self.Arch, self.BuildTarget, self.ToolChain]\r
52302d4d
LG
2719 return self._Module\r
2720\r
2721 ## Return the module name\r
2722 def _GetBaseName(self):\r
2723 return self.Module.BaseName\r
2724\r
b36d134f
LG
2725 ## Return the module DxsFile if exist\r
2726 def _GetDxsFile(self):\r
2727 return self.Module.DxsFile\r
2728\r
52302d4d
LG
2729 ## Return the module SourceOverridePath\r
2730 def _GetSourceOverridePath(self):\r
2731 return self.Module.SourceOverridePath\r
2732\r
2733 ## Return the module meta-file GUID\r
2734 def _GetGuid(self):\r
97fa0ee9
YL
2735 #\r
2736 # To build same module more than once, the module path with FILE_GUID overridden has\r
2737 # the file name FILE_GUIDmodule.inf, but the relative path (self.MetaFile.File) is the realy path\r
2738 # in DSC. The overridden GUID can be retrieved from file name\r
2739 #\r
2740 if os.path.basename(self.MetaFile.File) != os.path.basename(self.MetaFile.Path):\r
2741 #\r
2742 # Length of GUID is 36\r
2743 #\r
2744 return os.path.basename(self.MetaFile.Path)[:36]\r
52302d4d
LG
2745 return self.Module.Guid\r
2746\r
2747 ## Return the module version\r
2748 def _GetVersion(self):\r
2749 return self.Module.Version\r
2750\r
2751 ## Return the module type\r
2752 def _GetModuleType(self):\r
2753 return self.Module.ModuleType\r
2754\r
b36d134f 2755 ## Return the component type (for Edk.x style of module)\r
52302d4d
LG
2756 def _GetComponentType(self):\r
2757 return self.Module.ComponentType\r
2758\r
2759 ## Return the build type\r
2760 def _GetBuildType(self):\r
2761 return self.Module.BuildType\r
2762\r
2763 ## Return the PCD_IS_DRIVER setting\r
2764 def _GetPcdIsDriver(self):\r
2765 return self.Module.PcdIsDriver\r
2766\r
2767 ## Return the autogen version, i.e. module meta-file version\r
2768 def _GetAutoGenVersion(self):\r
2769 return self.Module.AutoGenVersion\r
2770\r
2771 ## Check if the module is library or not\r
2772 def _IsLibrary(self):\r
2773 if self._LibraryFlag == None:\r
2774 if self.Module.LibraryClass != None and self.Module.LibraryClass != []:\r
2775 self._LibraryFlag = True\r
2776 else:\r
2777 self._LibraryFlag = False\r
2778 return self._LibraryFlag\r
2779\r
e8a47801
LG
2780 ## Check if the module is binary module or not\r
2781 def _IsBinaryModule(self):\r
2782 return self.Module.IsBinaryModule\r
2783\r
52302d4d
LG
2784 ## Return the directory to store intermediate files of the module\r
2785 def _GetBuildDir(self):\r
2786 if self._BuildDir == None:\r
2787 self._BuildDir = path.join(\r
2788 self.PlatformInfo.BuildDir,\r
2789 self.Arch,\r
2790 self.SourceDir,\r
2791 self.MetaFile.BaseName\r
2792 )\r
2793 CreateDirectory(self._BuildDir)\r
2794 return self._BuildDir\r
2795\r
2796 ## Return the directory to store the intermediate object files of the mdoule\r
2797 def _GetOutputDir(self):\r
2798 if self._OutputDir == None:\r
2799 self._OutputDir = path.join(self.BuildDir, "OUTPUT")\r
2800 CreateDirectory(self._OutputDir)\r
2801 return self._OutputDir\r
2802\r
2803 ## Return the directory to store auto-gened source files of the mdoule\r
2804 def _GetDebugDir(self):\r
2805 if self._DebugDir == None:\r
2806 self._DebugDir = path.join(self.BuildDir, "DEBUG")\r
2807 CreateDirectory(self._DebugDir)\r
2808 return self._DebugDir\r
2809\r
2810 ## Return the path of custom file\r
2811 def _GetCustomMakefile(self):\r
2812 if self._CustomMakefile == None:\r
2813 self._CustomMakefile = {}\r
2814 for Type in self.Module.CustomMakefile:\r
2815 if Type in gMakeTypeMap:\r
2816 MakeType = gMakeTypeMap[Type]\r
2817 else:\r
2818 MakeType = 'nmake'\r
2819 if self.SourceOverrideDir != None:\r
2820 File = os.path.join(self.SourceOverrideDir, self.Module.CustomMakefile[Type])\r
2821 if not os.path.exists(File):\r
2822 File = os.path.join(self.SourceDir, self.Module.CustomMakefile[Type])\r
2823 else:\r
2824 File = os.path.join(self.SourceDir, self.Module.CustomMakefile[Type])\r
2825 self._CustomMakefile[MakeType] = File\r
2826 return self._CustomMakefile\r
2827\r
2828 ## Return the directory of the makefile\r
2829 #\r
2830 # @retval string The directory string of module's makefile\r
2831 #\r
2832 def _GetMakeFileDir(self):\r
2833 return self.BuildDir\r
2834\r
2835 ## Return build command string\r
2836 #\r
2837 # @retval string Build command string\r
2838 #\r
2839 def _GetBuildCommand(self):\r
2840 return self.PlatformInfo.BuildCommand\r
2841\r
2842 ## Get object list of all packages the module and its dependent libraries belong to\r
2843 #\r
2844 # @retval list The list of package object\r
2845 #\r
2846 def _GetDerivedPackageList(self):\r
2847 PackageList = []\r
2848 for M in [self.Module] + self.DependentLibraryList:\r
2849 for Package in M.Packages:\r
2850 if Package in PackageList:\r
2851 continue\r
2852 PackageList.append(Package)\r
2853 return PackageList\r
97fa0ee9
YL
2854 \r
2855 ## Get the depex string\r
2856 #\r
2857 # @return : a string contain all depex expresion.\r
2858 def _GetDepexExpresionString(self):\r
2859 DepexStr = ''\r
2860 DepexList = []\r
2861 ## DPX_SOURCE IN Define section.\r
2862 if self.Module.DxsFile:\r
2863 return DepexStr\r
2864 for M in [self.Module] + self.DependentLibraryList:\r
2865 Filename = M.MetaFile.Path\r
2866 InfObj = InfSectionParser.InfSectionParser(Filename)\r
2867 DepexExpresionList = InfObj.GetDepexExpresionList()\r
2868 for DepexExpresion in DepexExpresionList:\r
2869 for key in DepexExpresion.keys():\r
2870 Arch, ModuleType = key\r
518aebe2 2871 DepexExpr = [x for x in DepexExpresion[key] if not str(x).startswith('#')]\r
97fa0ee9
YL
2872 # the type of build module is USER_DEFINED.\r
2873 # All different DEPEX section tags would be copied into the As Built INF file\r
2874 # and there would be separate DEPEX section tags\r
2875 if self.ModuleType.upper() == SUP_MODULE_USER_DEFINED:\r
2876 if (Arch.upper() == self.Arch.upper()) and (ModuleType.upper() != TAB_ARCH_COMMON):\r
518aebe2 2877 DepexList.append({(Arch, ModuleType): DepexExpr})\r
97fa0ee9
YL
2878 else:\r
2879 if Arch.upper() == TAB_ARCH_COMMON or \\r
2880 (Arch.upper() == self.Arch.upper() and \\r
2881 ModuleType.upper() in [TAB_ARCH_COMMON, self.ModuleType.upper()]):\r
518aebe2 2882 DepexList.append({(Arch, ModuleType): DepexExpr})\r
97fa0ee9
YL
2883 \r
2884 #the type of build module is USER_DEFINED.\r
2885 if self.ModuleType.upper() == SUP_MODULE_USER_DEFINED:\r
2886 for Depex in DepexList:\r
2887 for key in Depex.keys():\r
2888 DepexStr += '[Depex.%s.%s]\n' % key\r
2889 DepexStr += '\n'.join(['# '+ val for val in Depex[key]])\r
2890 DepexStr += '\n\n'\r
2891 if not DepexStr:\r
2892 return '[Depex.%s]\n' % self.Arch\r
2893 return DepexStr\r
2894 \r
2895 #the type of build module not is USER_DEFINED.\r
2896 Count = 0\r
2897 for Depex in DepexList:\r
2898 Count += 1\r
2899 if DepexStr != '':\r
2900 DepexStr += ' AND '\r
2901 DepexStr += '('\r
2902 for D in Depex.values():\r
2903 DepexStr += ' '.join([val for val in D])\r
2904 Index = DepexStr.find('END')\r
2905 if Index > -1 and Index == len(DepexStr) - 3:\r
2906 DepexStr = DepexStr[:-3]\r
2907 DepexStr = DepexStr.strip()\r
2908 DepexStr += ')'\r
2909 if Count == 1:\r
2910 DepexStr = DepexStr.lstrip('(').rstrip(')').strip()\r
2911 if not DepexStr:\r
2912 return '[Depex.%s]\n' % self.Arch\r
2913 return '[Depex.%s]\n# ' % self.Arch + DepexStr\r
2914 \r
52302d4d
LG
2915 ## Merge dependency expression\r
2916 #\r
2917 # @retval list The token list of the dependency expression after parsed\r
2918 #\r
2919 def _GetDepexTokenList(self):\r
2920 if self._DepexList == None:\r
2921 self._DepexList = {}\r
b36d134f 2922 if self.DxsFile or self.IsLibrary or TAB_DEPENDENCY_EXPRESSION_FILE in self.FileTypes:\r
52302d4d
LG
2923 return self._DepexList\r
2924\r
2925 self._DepexList[self.ModuleType] = []\r
2926\r
2927 for ModuleType in self._DepexList:\r
2928 DepexList = self._DepexList[ModuleType]\r
2929 #\r
2930 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion\r
2931 #\r
2932 for M in [self.Module] + self.DependentLibraryList:\r
2933 Inherited = False\r
2934 for D in M.Depex[self.Arch, ModuleType]:\r
2935 if DepexList != []:\r
2936 DepexList.append('AND')\r
2937