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