]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/AutoGen/AutoGen.py
BaseTools: Allow string token identifier to use lower case letters
[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
25193a33
YZ
1945 # Cover the case that the binary INF file is list in the FDF file but not DSC file, return empty list directly\r
1946 if str(Module) not in self.Platform.Modules:\r
1947 return []\r
1948\r
52302d4d
LG
1949 ModuleType = Module.ModuleType\r
1950\r
1951 # for overridding library instances with module specific setting\r
1952 PlatformModule = self.Platform.Modules[str(Module)]\r
1953\r
1954 # add forced library instances (specified under LibraryClasses sections)\r
da92f276
LG
1955 #\r
1956 # If a module has a MODULE_TYPE of USER_DEFINED,\r
1957 # do not link in NULL library class instances from the global [LibraryClasses.*] sections.\r
1958 #\r
1959 if Module.ModuleType != SUP_MODULE_USER_DEFINED:\r
1960 for LibraryClass in self.Platform.LibraryClasses.GetKeys():\r
1961 if LibraryClass.startswith("NULL") and self.Platform.LibraryClasses[LibraryClass, Module.ModuleType]:\r
1962 Module.LibraryClasses[LibraryClass] = self.Platform.LibraryClasses[LibraryClass, Module.ModuleType]\r
52302d4d
LG
1963\r
1964 # add forced library instances (specified in module overrides)\r
1965 for LibraryClass in PlatformModule.LibraryClasses:\r
1966 if LibraryClass.startswith("NULL"):\r
1967 Module.LibraryClasses[LibraryClass] = PlatformModule.LibraryClasses[LibraryClass]\r
1968\r
b36d134f 1969 # EdkII module\r
52302d4d
LG
1970 LibraryConsumerList = [Module]\r
1971 Constructor = []\r
1972 ConsumedByList = sdict()\r
1973 LibraryInstance = sdict()\r
1974\r
1975 EdkLogger.verbose("")\r
1976 EdkLogger.verbose("Library instances of module [%s] [%s]:" % (str(Module), self.Arch))\r
1977 while len(LibraryConsumerList) > 0:\r
1978 M = LibraryConsumerList.pop()\r
1979 for LibraryClassName in M.LibraryClasses:\r
1980 if LibraryClassName not in LibraryInstance:\r
1981 # override library instance for this module\r
1982 if LibraryClassName in PlatformModule.LibraryClasses:\r
1983 LibraryPath = PlatformModule.LibraryClasses[LibraryClassName]\r
1984 else:\r
1985 LibraryPath = self.Platform.LibraryClasses[LibraryClassName, ModuleType]\r
1986 if LibraryPath == None or LibraryPath == "":\r
1987 LibraryPath = M.LibraryClasses[LibraryClassName]\r
1988 if LibraryPath == None or LibraryPath == "":\r
1989 EdkLogger.error("build", RESOURCE_NOT_AVAILABLE,\r
1990 "Instance of library class [%s] is not found" % LibraryClassName,\r
1991 File=self.MetaFile,\r
1992 ExtraData="in [%s] [%s]\n\tconsumed by module [%s]" % (str(M), self.Arch, str(Module)))\r
1993\r
0d2711a6 1994 LibraryModule = self.BuildDatabase[LibraryPath, self.Arch, self.BuildTarget, self.ToolChain]\r
52302d4d
LG
1995 # for those forced library instance (NULL library), add a fake library class\r
1996 if LibraryClassName.startswith("NULL"):\r
1997 LibraryModule.LibraryClass.append(LibraryClassObject(LibraryClassName, [ModuleType]))\r
1998 elif LibraryModule.LibraryClass == None \\r
1999 or len(LibraryModule.LibraryClass) == 0 \\r
2000 or (ModuleType != 'USER_DEFINED'\r
2001 and ModuleType not in LibraryModule.LibraryClass[0].SupModList):\r
2002 # only USER_DEFINED can link against any library instance despite of its SupModList\r
2003 EdkLogger.error("build", OPTION_MISSING,\r
2004 "Module type [%s] is not supported by library instance [%s]" \\r
2005 % (ModuleType, LibraryPath), File=self.MetaFile,\r
2006 ExtraData="consumed by [%s]" % str(Module))\r
2007\r
2008 LibraryInstance[LibraryClassName] = LibraryModule\r
2009 LibraryConsumerList.append(LibraryModule)\r
2010 EdkLogger.verbose("\t" + str(LibraryClassName) + " : " + str(LibraryModule))\r
2011 else:\r
2012 LibraryModule = LibraryInstance[LibraryClassName]\r
2013\r
2014 if LibraryModule == None:\r
2015 continue\r
2016\r
2017 if LibraryModule.ConstructorList != [] and LibraryModule not in Constructor:\r
2018 Constructor.append(LibraryModule)\r
2019\r
2020 if LibraryModule not in ConsumedByList:\r
2021 ConsumedByList[LibraryModule] = []\r
2022 # don't add current module itself to consumer list\r
2023 if M != Module:\r
2024 if M in ConsumedByList[LibraryModule]:\r
2025 continue\r
2026 ConsumedByList[LibraryModule].append(M)\r
2027 #\r
2028 # Initialize the sorted output list to the empty set\r
2029 #\r
2030 SortedLibraryList = []\r
2031 #\r
2032 # Q <- Set of all nodes with no incoming edges\r
2033 #\r
2034 LibraryList = [] #LibraryInstance.values()\r
2035 Q = []\r
2036 for LibraryClassName in LibraryInstance:\r
2037 M = LibraryInstance[LibraryClassName]\r
2038 LibraryList.append(M)\r
2039 if ConsumedByList[M] == []:\r
2040 Q.append(M)\r
2041\r
2042 #\r
2043 # start the DAG algorithm\r
2044 #\r
2045 while True:\r
2046 EdgeRemoved = True\r
2047 while Q == [] and EdgeRemoved:\r
2048 EdgeRemoved = False\r
2049 # for each node Item with a Constructor\r
2050 for Item in LibraryList:\r
2051 if Item not in Constructor:\r
2052 continue\r
2053 # for each Node without a constructor with an edge e from Item to Node\r
2054 for Node in ConsumedByList[Item]:\r
2055 if Node in Constructor:\r
2056 continue\r
2057 # remove edge e from the graph if Node has no constructor\r
2058 ConsumedByList[Item].remove(Node)\r
2059 EdgeRemoved = True\r
2060 if ConsumedByList[Item] == []:\r
2061 # insert Item into Q\r
2062 Q.insert(0, Item)\r
2063 break\r
2064 if Q != []:\r
2065 break\r
2066 # DAG is done if there's no more incoming edge for all nodes\r
2067 if Q == []:\r
2068 break\r
2069\r
2070 # remove node from Q\r
2071 Node = Q.pop()\r
2072 # output Node\r
2073 SortedLibraryList.append(Node)\r
2074\r
2075 # for each node Item with an edge e from Node to Item do\r
2076 for Item in LibraryList:\r
2077 if Node not in ConsumedByList[Item]:\r
2078 continue\r
2079 # remove edge e from the graph\r
2080 ConsumedByList[Item].remove(Node)\r
2081\r
2082 if ConsumedByList[Item] != []:\r
2083 continue\r
2084 # insert Item into Q, if Item has no other incoming edges\r
2085 Q.insert(0, Item)\r
2086\r
2087 #\r
2088 # if any remaining node Item in the graph has a constructor and an incoming edge, then the graph has a cycle\r
2089 #\r
2090 for Item in LibraryList:\r
2091 if ConsumedByList[Item] != [] and Item in Constructor and len(Constructor) > 1:\r
2092 ErrorMessage = "\tconsumed by " + "\n\tconsumed by ".join([str(L) for L in ConsumedByList[Item]])\r
2093 EdkLogger.error("build", BUILD_ERROR, 'Library [%s] with constructors has a cycle' % str(Item),\r
2094 ExtraData=ErrorMessage, File=self.MetaFile)\r
2095 if Item not in SortedLibraryList:\r
2096 SortedLibraryList.append(Item)\r
2097\r
2098 #\r
2099 # Build the list of constructor and destructir names\r
2100 # The DAG Topo sort produces the destructor order, so the list of constructors must generated in the reverse order\r
2101 #\r
2102 SortedLibraryList.reverse()\r
2103 return SortedLibraryList\r
2104\r
2105\r
2106 ## Override PCD setting (type, value, ...)\r
2107 #\r
2108 # @param ToPcd The PCD to be overrided\r
2109 # @param FromPcd The PCD overrideing from\r
2110 #\r
2111 def _OverridePcd(self, ToPcd, FromPcd, Module=""):\r
2112 #\r
2113 # in case there's PCDs coming from FDF file, which have no type given.\r
2114 # at this point, ToPcd.Type has the type found from dependent\r
2115 # package\r
2116 #\r
2a29017e
YZ
2117 TokenCName = ToPcd.TokenCName\r
2118 for PcdItem in GlobalData.MixedPcd:\r
2119 if (ToPcd.TokenCName, ToPcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
2120 TokenCName = PcdItem[0]\r
2121 break\r
52302d4d 2122 if FromPcd != None:\r
2a29017e
YZ
2123 if GlobalData.BuildOptionPcd:\r
2124 for pcd in GlobalData.BuildOptionPcd:\r
2125 if (FromPcd.TokenSpaceGuidCName, FromPcd.TokenCName) == (pcd[0], pcd[1]):\r
2126 FromPcd.DefaultValue = pcd[2]\r
2127 break\r
52302d4d
LG
2128 if ToPcd.Pending and FromPcd.Type not in [None, '']:\r
2129 ToPcd.Type = FromPcd.Type\r
e56468c0 2130 elif (ToPcd.Type not in [None, '']) and (FromPcd.Type not in [None, ''])\\r
2131 and (ToPcd.Type != FromPcd.Type) and (ToPcd.Type in FromPcd.Type):\r
2132 if ToPcd.Type.strip() == "DynamicEx":\r
47fea6af 2133 ToPcd.Type = FromPcd.Type\r
52302d4d
LG
2134 elif ToPcd.Type not in [None, ''] and FromPcd.Type not in [None, ''] \\r
2135 and ToPcd.Type != FromPcd.Type:\r
2136 EdkLogger.error("build", OPTION_CONFLICT, "Mismatched PCD type",\r
2137 ExtraData="%s.%s is defined as [%s] in module %s, but as [%s] in platform."\\r
2a29017e 2138 % (ToPcd.TokenSpaceGuidCName, TokenCName,\r
52302d4d
LG
2139 ToPcd.Type, Module, FromPcd.Type),\r
2140 File=self.MetaFile)\r
2141\r
2142 if FromPcd.MaxDatumSize not in [None, '']:\r
2143 ToPcd.MaxDatumSize = FromPcd.MaxDatumSize\r
2144 if FromPcd.DefaultValue not in [None, '']:\r
2145 ToPcd.DefaultValue = FromPcd.DefaultValue\r
2146 if FromPcd.TokenValue not in [None, '']:\r
2147 ToPcd.TokenValue = FromPcd.TokenValue\r
2148 if FromPcd.MaxDatumSize not in [None, '']:\r
2149 ToPcd.MaxDatumSize = FromPcd.MaxDatumSize\r
2150 if FromPcd.DatumType not in [None, '']:\r
2151 ToPcd.DatumType = FromPcd.DatumType\r
2152 if FromPcd.SkuInfoList not in [None, '', []]:\r
2153 ToPcd.SkuInfoList = FromPcd.SkuInfoList\r
2154\r
2155 # check the validation of datum\r
2156 IsValid, Cause = CheckPcdDatum(ToPcd.DatumType, ToPcd.DefaultValue)\r
2157 if not IsValid:\r
2158 EdkLogger.error('build', FORMAT_INVALID, Cause, File=self.MetaFile,\r
2a29017e 2159 ExtraData="%s.%s" % (ToPcd.TokenSpaceGuidCName, TokenCName))\r
82a6a960
BF
2160 ToPcd.validateranges = FromPcd.validateranges\r
2161 ToPcd.validlists = FromPcd.validlists\r
2162 ToPcd.expressions = FromPcd.expressions\r
52302d4d
LG
2163\r
2164 if ToPcd.DatumType == "VOID*" and ToPcd.MaxDatumSize in ['', None]:\r
2165 EdkLogger.debug(EdkLogger.DEBUG_9, "No MaxDatumSize specified for PCD %s.%s" \\r
2a29017e 2166 % (ToPcd.TokenSpaceGuidCName, TokenCName))\r
52302d4d
LG
2167 Value = ToPcd.DefaultValue\r
2168 if Value in [None, '']:\r
e8a47801 2169 ToPcd.MaxDatumSize = '1'\r
52302d4d 2170 elif Value[0] == 'L':\r
e8a47801 2171 ToPcd.MaxDatumSize = str((len(Value) - 2) * 2)\r
52302d4d
LG
2172 elif Value[0] == '{':\r
2173 ToPcd.MaxDatumSize = str(len(Value.split(',')))\r
2174 else:\r
e8a47801 2175 ToPcd.MaxDatumSize = str(len(Value) - 1)\r
52302d4d
LG
2176\r
2177 # apply default SKU for dynamic PCDS if specified one is not available\r
2178 if (ToPcd.Type in PCD_DYNAMIC_TYPE_LIST or ToPcd.Type in PCD_DYNAMIC_EX_TYPE_LIST) \\r
2179 and ToPcd.SkuInfoList in [None, {}, '']:\r
2180 if self.Platform.SkuName in self.Platform.SkuIds:\r
2181 SkuName = self.Platform.SkuName\r
2182 else:\r
2183 SkuName = 'DEFAULT'\r
2184 ToPcd.SkuInfoList = {\r
2185 SkuName : SkuInfoClass(SkuName, self.Platform.SkuIds[SkuName], '', '', '', '', '', ToPcd.DefaultValue)\r
2186 }\r
2187\r
2188 ## Apply PCD setting defined platform to a module\r
2189 #\r
2190 # @param Module The module from which the PCD setting will be overrided\r
2191 #\r
2192 # @retval PCD_list The list PCDs with settings from platform\r
2193 #\r
2194 def ApplyPcdSetting(self, Module, Pcds):\r
2195 # for each PCD in module\r
47fea6af
YZ
2196 for Name, Guid in Pcds:\r
2197 PcdInModule = Pcds[Name, Guid]\r
52302d4d 2198 # find out the PCD setting in platform\r
47fea6af
YZ
2199 if (Name, Guid) in self.Platform.Pcds:\r
2200 PcdInPlatform = self.Platform.Pcds[Name, Guid]\r
52302d4d
LG
2201 else:\r
2202 PcdInPlatform = None\r
2203 # then override the settings if any\r
2204 self._OverridePcd(PcdInModule, PcdInPlatform, Module)\r
2205 # resolve the VariableGuid value\r
2206 for SkuId in PcdInModule.SkuInfoList:\r
2207 Sku = PcdInModule.SkuInfoList[SkuId]\r
2208 if Sku.VariableGuid == '': continue\r
c28d2e10 2209 Sku.VariableGuidValue = GuidValue(Sku.VariableGuid, self.PackageList, self.MetaFile.Path)\r
52302d4d
LG
2210 if Sku.VariableGuidValue == None:\r
2211 PackageList = "\n\t".join([str(P) for P in self.PackageList])\r
2212 EdkLogger.error(\r
2213 'build',\r
2214 RESOURCE_NOT_AVAILABLE,\r
2215 "Value of GUID [%s] is not found in" % Sku.VariableGuid,\r
2216 ExtraData=PackageList + "\n\t(used with %s.%s from module %s)" \\r
2217 % (Guid, Name, str(Module)),\r
2218 File=self.MetaFile\r
2219 )\r
2220\r
2221 # override PCD settings with module specific setting\r
2222 if Module in self.Platform.Modules:\r
2223 PlatformModule = self.Platform.Modules[str(Module)]\r
2224 for Key in PlatformModule.Pcds:\r
2225 if Key in Pcds:\r
2226 self._OverridePcd(Pcds[Key], PlatformModule.Pcds[Key], Module)\r
2227 return Pcds.values()\r
2228\r
2229 ## Resolve library names to library modules\r
2230 #\r
b36d134f 2231 # (for Edk.x modules)\r
52302d4d
LG
2232 #\r
2233 # @param Module The module from which the library names will be resolved\r
2234 #\r
2235 # @retval library_list The list of library modules\r
2236 #\r
2237 def ResolveLibraryReference(self, Module):\r
2238 EdkLogger.verbose("")\r
2239 EdkLogger.verbose("Library instances of module [%s] [%s]:" % (str(Module), self.Arch))\r
2240 LibraryConsumerList = [Module]\r
2241\r
b36d134f 2242 # "CompilerStub" is a must for Edk modules\r
52302d4d
LG
2243 if Module.Libraries:\r
2244 Module.Libraries.append("CompilerStub")\r
2245 LibraryList = []\r
2246 while len(LibraryConsumerList) > 0:\r
2247 M = LibraryConsumerList.pop()\r
2248 for LibraryName in M.Libraries:\r
2249 Library = self.Platform.LibraryClasses[LibraryName, ':dummy:']\r
2250 if Library == None:\r
2251 for Key in self.Platform.LibraryClasses.data.keys():\r
2252 if LibraryName.upper() == Key.upper():\r
2253 Library = self.Platform.LibraryClasses[Key, ':dummy:']\r
2254 break\r
2255 if Library == None:\r
2256 EdkLogger.warn("build", "Library [%s] is not found" % LibraryName, File=str(M),\r
2257 ExtraData="\t%s [%s]" % (str(Module), self.Arch))\r
2258 continue\r
2259\r
2260 if Library not in LibraryList:\r
2261 LibraryList.append(Library)\r
2262 LibraryConsumerList.append(Library)\r
2263 EdkLogger.verbose("\t" + LibraryName + " : " + str(Library) + ' ' + str(type(Library)))\r
2264 return LibraryList\r
2265\r
6780eef1
LG
2266 ## Calculate the priority value of the build option\r
2267 #\r
2268 # @param Key Build option definition contain: TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE\r
2269 #\r
2270 # @retval Value Priority value based on the priority list.\r
2271 #\r
2272 def CalculatePriorityValue(self, Key):\r
47fea6af
YZ
2273 Target, ToolChain, Arch, CommandType, Attr = Key.split('_')\r
2274 PriorityValue = 0x11111\r
6780eef1
LG
2275 if Target == "*":\r
2276 PriorityValue &= 0x01111\r
2277 if ToolChain == "*":\r
2278 PriorityValue &= 0x10111\r
2279 if Arch == "*":\r
2280 PriorityValue &= 0x11011\r
2281 if CommandType == "*":\r
2282 PriorityValue &= 0x11101\r
2283 if Attr == "*":\r
2284 PriorityValue &= 0x11110\r
47fea6af
YZ
2285\r
2286 return self.PrioList["0x%0.5x" % PriorityValue]\r
2287\r
6780eef1 2288\r
52302d4d
LG
2289 ## Expand * in build option key\r
2290 #\r
2291 # @param Options Options to be expanded\r
2292 #\r
2293 # @retval options Options expanded\r
6780eef1 2294 # \r
52302d4d
LG
2295 def _ExpandBuildOption(self, Options, ModuleStyle=None):\r
2296 BuildOptions = {}\r
2297 FamilyMatch = False\r
2298 FamilyIsNull = True\r
47fea6af 2299\r
6780eef1
LG
2300 OverrideList = {}\r
2301 #\r
2302 # Construct a list contain the build options which need override.\r
2303 #\r
2304 for Key in Options:\r
2305 #\r
2306 # Key[0] -- tool family\r
2307 # Key[1] -- TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE\r
2308 #\r
1ba5124e
YL
2309 if (Key[0] == self.BuildRuleFamily and\r
2310 (ModuleStyle == None or len(Key) < 3 or (len(Key) > 2 and Key[2] == ModuleStyle))):\r
6780eef1
LG
2311 Target, ToolChain, Arch, CommandType, Attr = Key[1].split('_')\r
2312 if Target == self.BuildTarget or Target == "*":\r
2313 if ToolChain == self.ToolChain or ToolChain == "*":\r
2314 if Arch == self.Arch or Arch == "*":\r
2315 if Options[Key].startswith("="):\r
47fea6af 2316 if OverrideList.get(Key[1]) != None:\r
6780eef1
LG
2317 OverrideList.pop(Key[1])\r
2318 OverrideList[Key[1]] = Options[Key]\r
2319 \r
2320 #\r
2321 # Use the highest priority value. \r
2322 #\r
2323 if (len(OverrideList) >= 2):\r
47fea6af 2324 KeyList = OverrideList.keys()\r
6780eef1 2325 for Index in range(len(KeyList)):\r
47fea6af 2326 NowKey = KeyList[Index]\r
6780eef1
LG
2327 Target1, ToolChain1, Arch1, CommandType1, Attr1 = NowKey.split("_")\r
2328 for Index1 in range(len(KeyList) - Index - 1):\r
2329 NextKey = KeyList[Index1 + Index + 1]\r
2330 #\r
2331 # Compare two Key, if one is included by another, choose the higher priority one\r
2332 # \r
2333 Target2, ToolChain2, Arch2, CommandType2, Attr2 = NextKey.split("_")\r
2334 if Target1 == Target2 or Target1 == "*" or Target2 == "*":\r
2335 if ToolChain1 == ToolChain2 or ToolChain1 == "*" or ToolChain2 == "*":\r
2336 if Arch1 == Arch2 or Arch1 == "*" or Arch2 == "*":\r
2337 if CommandType1 == CommandType2 or CommandType1 == "*" or CommandType2 == "*":\r
2338 if Attr1 == Attr2 or Attr1 == "*" or Attr2 == "*":\r
2339 if self.CalculatePriorityValue(NowKey) > self.CalculatePriorityValue(NextKey):\r
47fea6af 2340 if Options.get((self.BuildRuleFamily, NextKey)) != None:\r
6780eef1
LG
2341 Options.pop((self.BuildRuleFamily, NextKey))\r
2342 else:\r
47fea6af 2343 if Options.get((self.BuildRuleFamily, NowKey)) != None:\r
6780eef1
LG
2344 Options.pop((self.BuildRuleFamily, NowKey))\r
2345 \r
52302d4d
LG
2346 for Key in Options:\r
2347 if ModuleStyle != None and len (Key) > 2:\r
2348 # Check Module style is EDK or EDKII.\r
2349 # Only append build option for the matched style module.\r
2350 if ModuleStyle == EDK_NAME and Key[2] != EDK_NAME:\r
2351 continue\r
2352 elif ModuleStyle == EDKII_NAME and Key[2] != EDKII_NAME:\r
2353 continue\r
2354 Family = Key[0]\r
2355 Target, Tag, Arch, Tool, Attr = Key[1].split("_")\r
2356 # if tool chain family doesn't match, skip it\r
2357 if Tool in self.ToolDefinition and Family != "":\r
2358 FamilyIsNull = False\r
2359 if self.ToolDefinition[Tool].get(TAB_TOD_DEFINES_BUILDRULEFAMILY, "") != "":\r
2360 if Family != self.ToolDefinition[Tool][TAB_TOD_DEFINES_BUILDRULEFAMILY]:\r
2361 continue\r
2362 elif Family != self.ToolDefinition[Tool][TAB_TOD_DEFINES_FAMILY]:\r
2363 continue\r
2364 FamilyMatch = True\r
2365 # expand any wildcard\r
2366 if Target == "*" or Target == self.BuildTarget:\r
2367 if Tag == "*" or Tag == self.ToolChain:\r
2368 if Arch == "*" or Arch == self.Arch:\r
2369 if Tool not in BuildOptions:\r
2370 BuildOptions[Tool] = {}\r
5015bee2 2371 if Attr != "FLAGS" or Attr not in BuildOptions[Tool] or Options[Key].startswith('='):\r
52302d4d
LG
2372 BuildOptions[Tool][Attr] = Options[Key]\r
2373 else:\r
2374 # append options for the same tool\r
2375 BuildOptions[Tool][Attr] += " " + Options[Key]\r
2376 # Build Option Family has been checked, which need't to be checked again for family.\r
2377 if FamilyMatch or FamilyIsNull:\r
2378 return BuildOptions\r
1ba5124e 2379\r
52302d4d
LG
2380 for Key in Options:\r
2381 if ModuleStyle != None and len (Key) > 2:\r
2382 # Check Module style is EDK or EDKII.\r
2383 # Only append build option for the matched style module.\r
2384 if ModuleStyle == EDK_NAME and Key[2] != EDK_NAME:\r
2385 continue\r
2386 elif ModuleStyle == EDKII_NAME and Key[2] != EDKII_NAME:\r
2387 continue\r
2388 Family = Key[0]\r
2389 Target, Tag, Arch, Tool, Attr = Key[1].split("_")\r
2390 # if tool chain family doesn't match, skip it\r
47fea6af 2391 if Tool not in self.ToolDefinition or Family == "":\r
52302d4d
LG
2392 continue\r
2393 # option has been added before\r
2394 if Family != self.ToolDefinition[Tool][TAB_TOD_DEFINES_FAMILY]:\r
2395 continue\r
2396\r
2397 # expand any wildcard\r
2398 if Target == "*" or Target == self.BuildTarget:\r
2399 if Tag == "*" or Tag == self.ToolChain:\r
2400 if Arch == "*" or Arch == self.Arch:\r
2401 if Tool not in BuildOptions:\r
2402 BuildOptions[Tool] = {}\r
5015bee2 2403 if Attr != "FLAGS" or Attr not in BuildOptions[Tool] or Options[Key].startswith('='):\r
52302d4d
LG
2404 BuildOptions[Tool][Attr] = Options[Key]\r
2405 else:\r
2406 # append options for the same tool\r
2407 BuildOptions[Tool][Attr] += " " + Options[Key]\r
2408 return BuildOptions\r
2409\r
2410 ## Append build options in platform to a module\r
2411 #\r
2412 # @param Module The module to which the build options will be appened\r
2413 #\r
2414 # @retval options The options appended with build options in platform\r
2415 #\r
2416 def ApplyBuildOption(self, Module):\r
2417 # Get the different options for the different style module\r
2418 if Module.AutoGenVersion < 0x00010005:\r
2419 PlatformOptions = self.EdkBuildOption\r
35f69db9 2420 ModuleTypeOptions = self.Platform.GetBuildOptionsByModuleType(EDK_NAME, Module.ModuleType)\r
52302d4d
LG
2421 else:\r
2422 PlatformOptions = self.EdkIIBuildOption\r
35f69db9
YL
2423 ModuleTypeOptions = self.Platform.GetBuildOptionsByModuleType(EDKII_NAME, Module.ModuleType)\r
2424 ModuleTypeOptions = self._ExpandBuildOption(ModuleTypeOptions)\r
52302d4d
LG
2425 ModuleOptions = self._ExpandBuildOption(Module.BuildOptions)\r
2426 if Module in self.Platform.Modules:\r
2427 PlatformModule = self.Platform.Modules[str(Module)]\r
2428 PlatformModuleOptions = self._ExpandBuildOption(PlatformModule.BuildOptions)\r
2429 else:\r
2430 PlatformModuleOptions = {}\r
2431\r
fe4bf2f9 2432 BuildRuleOrder = None\r
35f69db9 2433 for Options in [self.ToolDefinition, ModuleOptions, PlatformOptions, ModuleTypeOptions, PlatformModuleOptions]:\r
fe4bf2f9
YL
2434 for Tool in Options:\r
2435 for Attr in Options[Tool]:\r
2436 if Attr == TAB_TOD_DEFINES_BUILDRULEORDER:\r
2437 BuildRuleOrder = Options[Tool][Attr]\r
2438\r
35f69db9
YL
2439 AllTools = set(ModuleOptions.keys() + PlatformOptions.keys() +\r
2440 PlatformModuleOptions.keys() + ModuleTypeOptions.keys() +\r
2441 self.ToolDefinition.keys())\r
52302d4d
LG
2442 BuildOptions = {}\r
2443 for Tool in AllTools:\r
2444 if Tool not in BuildOptions:\r
2445 BuildOptions[Tool] = {}\r
2446\r
35f69db9 2447 for Options in [self.ToolDefinition, ModuleOptions, PlatformOptions, ModuleTypeOptions, PlatformModuleOptions]:\r
52302d4d
LG
2448 if Tool not in Options:\r
2449 continue\r
2450 for Attr in Options[Tool]:\r
2451 Value = Options[Tool][Attr]\r
fe4bf2f9
YL
2452 #\r
2453 # Do not generate it in Makefile\r
2454 #\r
2455 if Attr == TAB_TOD_DEFINES_BUILDRULEORDER:\r
2456 continue\r
52302d4d
LG
2457 if Attr not in BuildOptions[Tool]:\r
2458 BuildOptions[Tool][Attr] = ""\r
2459 # check if override is indicated\r
2460 if Value.startswith('='):\r
05cc51ad
LY
2461 ToolPath = Value[1:]\r
2462 ToolPath = mws.handleWsMacro(ToolPath)\r
2463 BuildOptions[Tool][Attr] = ToolPath\r
5015bee2 2464 else:\r
05cc51ad 2465 Value = mws.handleWsMacro(Value)\r
52302d4d 2466 BuildOptions[Tool][Attr] += " " + Value\r
f3decdc3
LG
2467 if Module.AutoGenVersion < 0x00010005 and self.Workspace.UniFlag != None:\r
2468 #\r
2469 # Override UNI flag only for EDK module.\r
2470 #\r
2471 if 'BUILD' not in BuildOptions:\r
2472 BuildOptions['BUILD'] = {}\r
2473 BuildOptions['BUILD']['FLAGS'] = self.Workspace.UniFlag\r
fe4bf2f9 2474 return BuildOptions, BuildRuleOrder\r
52302d4d
LG
2475\r
2476 Platform = property(_GetPlatform)\r
2477 Name = property(_GetName)\r
2478 Guid = property(_GetGuid)\r
2479 Version = property(_GetVersion)\r
2480\r
2481 OutputDir = property(_GetOutputDir)\r
2482 BuildDir = property(_GetBuildDir)\r
2483 MakeFileDir = property(_GetMakeFileDir)\r
2484 FdfFile = property(_GetFdfFile)\r
2485\r
2486 PcdTokenNumber = property(_GetPcdTokenNumbers) # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber\r
2487 DynamicPcdList = property(_GetDynamicPcdList) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]\r
2488 NonDynamicPcdList = property(_GetNonDynamicPcdList) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]\r
2bc3256c 2489 NonDynamicPcdDict = property(_GetNonDynamicPcdDict)\r
52302d4d
LG
2490 PackageList = property(_GetPackageList)\r
2491\r
2492 ToolDefinition = property(_GetToolDefinition) # toolcode : tool path\r
2493 ToolDefinitionFile = property(_GetToolDefFile) # toolcode : lib path\r
2494 ToolChainFamily = property(_GetToolChainFamily)\r
2495 BuildRuleFamily = property(_GetBuildRuleFamily)\r
2496 BuildOption = property(_GetBuildOptions) # toolcode : option\r
2497 EdkBuildOption = property(_GetEdkBuildOptions) # edktoolcode : option\r
2498 EdkIIBuildOption = property(_GetEdkIIBuildOptions) # edkiitoolcode : option\r
2499\r
2500 BuildCommand = property(_GetBuildCommand)\r
2501 BuildRule = property(_GetBuildRule)\r
2502 ModuleAutoGenList = property(_GetModuleAutoGenList)\r
2503 LibraryAutoGenList = property(_GetLibraryAutoGenList)\r
0923aa1c 2504 GenFdsCommand = property(_GenFdsCommand)\r
52302d4d
LG
2505\r
2506## ModuleAutoGen class\r
2507#\r
2508# This class encapsules the AutoGen behaviors for the build tools. In addition to\r
2509# the generation of AutoGen.h and AutoGen.c, it will generate *.depex file according\r
2510# to the [depex] section in module's inf file.\r
2511#\r
2512class ModuleAutoGen(AutoGen):\r
2513 ## The real constructor of ModuleAutoGen\r
2514 #\r
2515 # This method is not supposed to be called by users of ModuleAutoGen. It's\r
2516 # only used by factory method __new__() to do real initialization work for an\r
2517 # object of ModuleAutoGen\r
2518 #\r
2519 # @param Workspace EdkIIWorkspaceBuild object\r
2520 # @param ModuleFile The path of module file\r
2521 # @param Target Build target (DEBUG, RELEASE)\r
2522 # @param Toolchain Name of tool chain\r
2523 # @param Arch The arch the module supports\r
2524 # @param PlatformFile Platform meta-file\r
2525 #\r
2526 def _Init(self, Workspace, ModuleFile, Target, Toolchain, Arch, PlatformFile):\r
2527 EdkLogger.debug(EdkLogger.DEBUG_9, "AutoGen module [%s] [%s]" % (ModuleFile, Arch))\r
2528 GlobalData.gProcessingFile = "%s [%s, %s, %s]" % (ModuleFile, Arch, Toolchain, Target)\r
2529\r
2530 self.Workspace = Workspace\r
2531 self.WorkspaceDir = Workspace.WorkspaceDir\r
2532\r
2533 self.MetaFile = ModuleFile\r
2534 self.PlatformInfo = PlatformAutoGen(Workspace, PlatformFile, Target, Toolchain, Arch)\r
2535 # check if this module is employed by active platform\r
2536 if not self.PlatformInfo.ValidModule(self.MetaFile):\r
2537 EdkLogger.verbose("Module [%s] for [%s] is not employed by active platform\n" \\r
2538 % (self.MetaFile, Arch))\r
2539 return False\r
2540\r
2541 self.SourceDir = self.MetaFile.SubDir\r
05cc51ad 2542 self.SourceDir = mws.relpath(self.SourceDir, self.WorkspaceDir)\r
97fa0ee9 2543\r
52302d4d
LG
2544 self.SourceOverrideDir = None\r
2545 # use overrided path defined in DSC file\r
2546 if self.MetaFile.Key in GlobalData.gOverrideDir:\r
2547 self.SourceOverrideDir = GlobalData.gOverrideDir[self.MetaFile.Key]\r
2548\r
2549 self.ToolChain = Toolchain\r
2550 self.BuildTarget = Target\r
2551 self.Arch = Arch\r
2552 self.ToolChainFamily = self.PlatformInfo.ToolChainFamily\r
2553 self.BuildRuleFamily = self.PlatformInfo.BuildRuleFamily\r
2554\r
2555 self.IsMakeFileCreated = False\r
2556 self.IsCodeFileCreated = False\r
da92f276
LG
2557 self.IsAsBuiltInfCreated = False\r
2558 self.DepexGenerated = False\r
52302d4d
LG
2559\r
2560 self.BuildDatabase = self.Workspace.BuildDatabase\r
fe4bf2f9 2561 self.BuildRuleOrder = None\r
52302d4d
LG
2562\r
2563 self._Module = None\r
2564 self._Name = None\r
2565 self._Guid = None\r
2566 self._Version = None\r
2567 self._ModuleType = None\r
2568 self._ComponentType = None\r
2569 self._PcdIsDriver = None\r
2570 self._AutoGenVersion = None\r
2571 self._LibraryFlag = None\r
2572 self._CustomMakefile = None\r
2573 self._Macro = None\r
2574\r
2575 self._BuildDir = None\r
2576 self._OutputDir = None\r
2577 self._DebugDir = None\r
2578 self._MakeFileDir = None\r
2579\r
2580 self._IncludePathList = None\r
725cdb8f 2581 self._IncludePathLength = 0\r
52302d4d
LG
2582 self._AutoGenFileList = None\r
2583 self._UnicodeFileList = None\r
2584 self._SourceFileList = None\r
2585 self._ObjectFileList = None\r
2586 self._BinaryFileList = None\r
2587\r
2588 self._DependentPackageList = None\r
2589 self._DependentLibraryList = None\r
2590 self._LibraryAutoGenList = None\r
2591 self._DerivedPackageList = None\r
2592 self._ModulePcdList = None\r
2593 self._LibraryPcdList = None\r
e8a47801 2594 self._PcdComments = sdict()\r
52302d4d 2595 self._GuidList = None\r
e8a47801
LG
2596 self._GuidsUsedByPcd = None\r
2597 self._GuidComments = sdict()\r
52302d4d 2598 self._ProtocolList = None\r
e8a47801 2599 self._ProtocolComments = sdict()\r
52302d4d 2600 self._PpiList = None\r
e8a47801 2601 self._PpiComments = sdict()\r
52302d4d
LG
2602 self._DepexList = None\r
2603 self._DepexExpressionList = None\r
2604 self._BuildOption = None\r
79b74a03 2605 self._BuildOptionIncPathList = None\r
52302d4d
LG
2606 self._BuildTargets = None\r
2607 self._IntroBuildTargetList = None\r
2608 self._FinalBuildTargetList = None\r
2609 self._FileTypes = None\r
2610 self._BuildRules = None\r
2bc3256c
LG
2611 \r
2612 ## The Modules referenced to this Library\r
2613 # Only Library has this attribute\r
2614 self._ReferenceModules = [] \r
2615 \r
2616 ## Store the FixedAtBuild Pcds\r
2617 # \r
2618 self._FixedAtBuildPcds = []\r
2619 self.ConstPcd = {}\r
52302d4d
LG
2620 return True\r
2621\r
2622 def __repr__(self):\r
2623 return "%s [%s]" % (self.MetaFile, self.Arch)\r
2624\r
2bc3256c
LG
2625 # Get FixedAtBuild Pcds of this Module\r
2626 def _GetFixedAtBuildPcds(self):\r
2627 if self._FixedAtBuildPcds:\r
2628 return self._FixedAtBuildPcds\r
2629 for Pcd in self.ModulePcdList:\r
2630 if self.IsLibrary:\r
2631 if not (Pcd.Pending == False and Pcd.Type == "FixedAtBuild"):\r
2632 continue\r
2633 elif Pcd.Type != "FixedAtBuild":\r
2634 continue\r
2635 if Pcd not in self._FixedAtBuildPcds:\r
2636 self._FixedAtBuildPcds.append(Pcd)\r
2637 \r
2638 return self._FixedAtBuildPcds \r
2639\r
867d1cd4
YL
2640 def _GetUniqueBaseName(self):\r
2641 BaseName = self.Name\r
2642 for Module in self.PlatformInfo.ModuleAutoGenList:\r
2643 if Module.MetaFile == self.MetaFile:\r
2644 continue\r
2645 if Module.Name == self.Name:\r
867d1cd4
YL
2646 if uuid.UUID(Module.Guid) == uuid.UUID(self.Guid):\r
2647 EdkLogger.error("build", FILE_DUPLICATED, 'Modules have same BaseName and FILE_GUID:\n'\r
2648 ' %s\n %s' % (Module.MetaFile, self.MetaFile))\r
2649 BaseName = '%s_%s' % (self.Name, self.Guid)\r
2650 return BaseName\r
2651\r
52302d4d
LG
2652 # Macros could be used in build_rule.txt (also Makefile)\r
2653 def _GetMacros(self):\r
2654 if self._Macro == None:\r
2655 self._Macro = sdict()\r
2656 self._Macro["WORKSPACE" ] = self.WorkspaceDir\r
2657 self._Macro["MODULE_NAME" ] = self.Name\r
867d1cd4 2658 self._Macro["MODULE_NAME_GUID" ] = self._GetUniqueBaseName()\r
52302d4d
LG
2659 self._Macro["MODULE_GUID" ] = self.Guid\r
2660 self._Macro["MODULE_VERSION" ] = self.Version\r
2661 self._Macro["MODULE_TYPE" ] = self.ModuleType\r
2662 self._Macro["MODULE_FILE" ] = str(self.MetaFile)\r
2663 self._Macro["MODULE_FILE_BASE_NAME" ] = self.MetaFile.BaseName\r
2664 self._Macro["MODULE_RELATIVE_DIR" ] = self.SourceDir\r
2665 self._Macro["MODULE_DIR" ] = self.SourceDir\r
2666\r
2667 self._Macro["BASE_NAME" ] = self.Name\r
2668\r
2669 self._Macro["ARCH" ] = self.Arch\r
2670 self._Macro["TOOLCHAIN" ] = self.ToolChain\r
2671 self._Macro["TOOLCHAIN_TAG" ] = self.ToolChain\r
0d2711a6 2672 self._Macro["TOOL_CHAIN_TAG" ] = self.ToolChain\r
52302d4d
LG
2673 self._Macro["TARGET" ] = self.BuildTarget\r
2674\r
2675 self._Macro["BUILD_DIR" ] = self.PlatformInfo.BuildDir\r
2676 self._Macro["BIN_DIR" ] = os.path.join(self.PlatformInfo.BuildDir, self.Arch)\r
2677 self._Macro["LIB_DIR" ] = os.path.join(self.PlatformInfo.BuildDir, self.Arch)\r
2678 self._Macro["MODULE_BUILD_DIR" ] = self.BuildDir\r
2679 self._Macro["OUTPUT_DIR" ] = self.OutputDir\r
2680 self._Macro["DEBUG_DIR" ] = self.DebugDir\r
df1e1b63
YZ
2681 self._Macro["DEST_DIR_OUTPUT" ] = self.OutputDir\r
2682 self._Macro["DEST_DIR_DEBUG" ] = self.DebugDir\r
3570e332
YZ
2683 self._Macro["PLATFORM_NAME" ] = self.PlatformInfo.Name\r
2684 self._Macro["PLATFORM_GUID" ] = self.PlatformInfo.Guid\r
2685 self._Macro["PLATFORM_VERSION" ] = self.PlatformInfo.Version\r
2686 self._Macro["PLATFORM_RELATIVE_DIR" ] = self.PlatformInfo.SourceDir\r
2687 self._Macro["PLATFORM_DIR" ] = mws.join(self.WorkspaceDir, self.PlatformInfo.SourceDir)\r
2688 self._Macro["PLATFORM_OUTPUT_DIR" ] = self.PlatformInfo.OutputDir\r
52302d4d
LG
2689 return self._Macro\r
2690\r
2691 ## Return the module build data object\r
2692 def _GetModule(self):\r
2693 if self._Module == None:\r
0d2711a6 2694 self._Module = self.Workspace.BuildDatabase[self.MetaFile, self.Arch, self.BuildTarget, self.ToolChain]\r
52302d4d
LG
2695 return self._Module\r
2696\r
2697 ## Return the module name\r
2698 def _GetBaseName(self):\r
2699 return self.Module.BaseName\r
2700\r
b36d134f
LG
2701 ## Return the module DxsFile if exist\r
2702 def _GetDxsFile(self):\r
2703 return self.Module.DxsFile\r
2704\r
52302d4d
LG
2705 ## Return the module SourceOverridePath\r
2706 def _GetSourceOverridePath(self):\r
2707 return self.Module.SourceOverridePath\r
2708\r
2709 ## Return the module meta-file GUID\r
2710 def _GetGuid(self):\r
97fa0ee9
YL
2711 #\r
2712 # To build same module more than once, the module path with FILE_GUID overridden has\r
2713 # the file name FILE_GUIDmodule.inf, but the relative path (self.MetaFile.File) is the realy path\r
2714 # in DSC. The overridden GUID can be retrieved from file name\r
2715 #\r
2716 if os.path.basename(self.MetaFile.File) != os.path.basename(self.MetaFile.Path):\r
2717 #\r
2718 # Length of GUID is 36\r
2719 #\r
2720 return os.path.basename(self.MetaFile.Path)[:36]\r
52302d4d
LG
2721 return self.Module.Guid\r
2722\r
2723 ## Return the module version\r
2724 def _GetVersion(self):\r
2725 return self.Module.Version\r
2726\r
2727 ## Return the module type\r
2728 def _GetModuleType(self):\r
2729 return self.Module.ModuleType\r
2730\r
b36d134f 2731 ## Return the component type (for Edk.x style of module)\r
52302d4d
LG
2732 def _GetComponentType(self):\r
2733 return self.Module.ComponentType\r
2734\r
2735 ## Return the build type\r
2736 def _GetBuildType(self):\r
2737 return self.Module.BuildType\r
2738\r
2739 ## Return the PCD_IS_DRIVER setting\r
2740 def _GetPcdIsDriver(self):\r
2741 return self.Module.PcdIsDriver\r
2742\r
2743 ## Return the autogen version, i.e. module meta-file version\r
2744 def _GetAutoGenVersion(self):\r
2745 return self.Module.AutoGenVersion\r
2746\r
2747 ## Check if the module is library or not\r
2748 def _IsLibrary(self):\r
2749 if self._LibraryFlag == None:\r
2750 if self.Module.LibraryClass != None and self.Module.LibraryClass != []:\r
2751 self._LibraryFlag = True\r
2752 else:\r
2753 self._LibraryFlag = False\r
2754 return self._LibraryFlag\r
2755\r
e8a47801
LG
2756 ## Check if the module is binary module or not\r
2757 def _IsBinaryModule(self):\r
2758 return self.Module.IsBinaryModule\r
2759\r
52302d4d
LG
2760 ## Return the directory to store intermediate files of the module\r
2761 def _GetBuildDir(self):\r
2762 if self._BuildDir == None:\r
2763 self._BuildDir = path.join(\r
2764 self.PlatformInfo.BuildDir,\r
2765 self.Arch,\r
2766 self.SourceDir,\r
2767 self.MetaFile.BaseName\r
2768 )\r
2769 CreateDirectory(self._BuildDir)\r
2770 return self._BuildDir\r
2771\r
2772 ## Return the directory to store the intermediate object files of the mdoule\r
2773 def _GetOutputDir(self):\r
2774 if self._OutputDir == None:\r
2775 self._OutputDir = path.join(self.BuildDir, "OUTPUT")\r
2776 CreateDirectory(self._OutputDir)\r
2777 return self._OutputDir\r
2778\r
2779 ## Return the directory to store auto-gened source files of the mdoule\r
2780 def _GetDebugDir(self):\r
2781 if self._DebugDir == None:\r
2782 self._DebugDir = path.join(self.BuildDir, "DEBUG")\r
2783 CreateDirectory(self._DebugDir)\r
2784 return self._DebugDir\r
2785\r
2786 ## Return the path of custom file\r
2787 def _GetCustomMakefile(self):\r
2788 if self._CustomMakefile == None:\r
2789 self._CustomMakefile = {}\r
2790 for Type in self.Module.CustomMakefile:\r
2791 if Type in gMakeTypeMap:\r
2792 MakeType = gMakeTypeMap[Type]\r
2793 else:\r
2794 MakeType = 'nmake'\r
2795 if self.SourceOverrideDir != None:\r
2796 File = os.path.join(self.SourceOverrideDir, self.Module.CustomMakefile[Type])\r
2797 if not os.path.exists(File):\r
2798 File = os.path.join(self.SourceDir, self.Module.CustomMakefile[Type])\r
2799 else:\r
2800 File = os.path.join(self.SourceDir, self.Module.CustomMakefile[Type])\r
2801 self._CustomMakefile[MakeType] = File\r
2802 return self._CustomMakefile\r
2803\r
2804 ## Return the directory of the makefile\r
2805 #\r
2806 # @retval string The directory string of module's makefile\r
2807 #\r
2808 def _GetMakeFileDir(self):\r
2809 return self.BuildDir\r
2810\r
2811 ## Return build command string\r
2812 #\r
2813 # @retval string Build command string\r
2814 #\r
2815 def _GetBuildCommand(self):\r
2816 return self.PlatformInfo.BuildCommand\r
2817\r
2818 ## Get object list of all packages the module and its dependent libraries belong to\r
2819 #\r
2820 # @retval list The list of package object\r
2821 #\r
2822 def _GetDerivedPackageList(self):\r
2823 PackageList = []\r
2824 for M in [self.Module] + self.DependentLibraryList:\r
2825 for Package in M.Packages:\r
2826 if Package in PackageList:\r
2827 continue\r
2828 PackageList.append(Package)\r
2829 return PackageList\r
97fa0ee9
YL
2830 \r
2831 ## Get the depex string\r
2832 #\r
2833 # @return : a string contain all depex expresion.\r
2834 def _GetDepexExpresionString(self):\r
2835 DepexStr = ''\r
2836 DepexList = []\r
2837 ## DPX_SOURCE IN Define section.\r
2838 if self.Module.DxsFile:\r
2839 return DepexStr\r
2840 for M in [self.Module] + self.DependentLibraryList:\r
2841 Filename = M.MetaFile.Path\r
2842 InfObj = InfSectionParser.InfSectionParser(Filename)\r
2843 DepexExpresionList = InfObj.GetDepexExpresionList()\r
2844 for DepexExpresion in DepexExpresionList:\r
2845 for key in DepexExpresion.keys():\r
2846 Arch, ModuleType = key\r
518aebe2 2847 DepexExpr = [x for x in DepexExpresion[key] if not str(x).startswith('#')]\r
97fa0ee9
YL
2848 # the type of build module is USER_DEFINED.\r
2849 # All different DEPEX section tags would be copied into the As Built INF file\r
2850 # and there would be separate DEPEX section tags\r
2851 if self.ModuleType.upper() == SUP_MODULE_USER_DEFINED:\r
2852 if (Arch.upper() == self.Arch.upper()) and (ModuleType.upper() != TAB_ARCH_COMMON):\r
518aebe2 2853 DepexList.append({(Arch, ModuleType): DepexExpr})\r
97fa0ee9
YL
2854 else:\r
2855 if Arch.upper() == TAB_ARCH_COMMON or \\r
2856 (Arch.upper() == self.Arch.upper() and \\r
2857 ModuleType.upper() in [TAB_ARCH_COMMON, self.ModuleType.upper()]):\r
518aebe2 2858 DepexList.append({(Arch, ModuleType): DepexExpr})\r
97fa0ee9
YL
2859 \r
2860 #the type of build module is USER_DEFINED.\r
2861 if self.ModuleType.upper() == SUP_MODULE_USER_DEFINED:\r
2862 for Depex in DepexList:\r
2863 for key in Depex.keys():\r
2864 DepexStr += '[Depex.%s.%s]\n' % key\r
2865 DepexStr += '\n'.join(['# '+ val for val in Depex[key]])\r
2866 DepexStr += '\n\n'\r
2867 if not DepexStr:\r
2868 return '[Depex.%s]\n' % self.Arch\r
2869 return DepexStr\r
2870 \r
2871 #the type of build module not is USER_DEFINED.\r
2872 Count = 0\r
2873 for Depex in DepexList:\r
2874 Count += 1\r
2875 if DepexStr != '':\r
2876 DepexStr += ' AND '\r
2877 DepexStr += '('\r
2878 for D in Depex.values():\r
2879 DepexStr += ' '.join([val for val in D])\r
2880 Index = DepexStr.find('END')\r
2881 if Index > -1 and Index == len(DepexStr) - 3:\r
2882 DepexStr = DepexStr[:-3]\r
2883 DepexStr = DepexStr.strip()\r
2884 DepexStr += ')'\r
2885 if Count == 1:\r
2886 DepexStr = DepexStr.lstrip('(').rstrip(')').strip()\r
2887 if not DepexStr:\r
2888 return '[Depex.%s]\n' % self.Arch\r
2889 return '[Depex.%s]\n# ' % self.Arch + DepexStr\r
2890 \r
52302d4d
LG
2891 ## Merge dependency expression\r
2892 #\r
2893 # @retval list The token list of the dependency expression after parsed\r
2894 #\r
2895 def _GetDepexTokenList(self):\r
2896 if self._DepexList == None:\r
2897 self._DepexList = {}\r
b36d134f 2898 if self.DxsFile or self.IsLibrary or TAB_DEPENDENCY_EXPRESSION_FILE in self.FileTypes:\r
52302d4d
LG
2899 return self._DepexList\r
2900\r
2901 self._DepexList[self.ModuleType] = []\r
2902\r
2903 for ModuleType in self._DepexList:\r
2904 DepexList = self._DepexList[ModuleType]\r
2905 #\r
2906 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion\r
2907 #\r
2908 for M in [self.Module] + self.DependentLibraryList:\r
2909 Inherited = False\r
2910 for D in M.Depex[self.Arch, ModuleType]:\r
2911 if DepexList != []:\r
2912 DepexList.append('AND')\r
2913 DepexList.append('(')\r
2914 DepexList.extend(D)\r
2915 if DepexList[-1] == 'END': # no need of a END at this time\r
2916 DepexList.pop()\r
2917 DepexList.append(')')\r
2918 Inherited = True\r
2919 if Inherited:\r
2920 EdkLogger.verbose("DEPEX[%s] (+%s) = %s" % (self.Name, M.BaseName, DepexList))\r
2921 if 'BEFORE' in DepexList or 'AFTER' in DepexList:\r
2922 break\r
2923 if len(DepexList) > 0:\r
2924 EdkLogger.verbose('')\r
2925 return self._DepexList\r
2926\r
2927 ## Merge dependency expression\r
2928 #\r
2929 # @retval list The token list of the dependency expression after parsed\r
2930 #\r
2931 def _GetDepexExpressionTokenList(self):\r
2932 if self._DepexExpressionList == None:\r
2933 self._DepexExpressionList = {}\r
b36d134f 2934 if self.DxsFile or self.IsLibrary or TAB_DEPENDENCY_EXPRESSION_FILE in self.FileTypes:\r
52302d4d
LG
2935 return self._DepexExpressionList\r
2936\r
2937 self._DepexExpressionList[self.ModuleType] = ''\r
2938\r
2939 for ModuleType in self._DepexExpressionList:\r
2940 DepexExpressionList = self._DepexExpressionList[ModuleType]\r
2941 #\r
2942 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion\r
2943 #\r
2944 for M in [self.Module] + self.DependentLibraryList:\r
2945 Inherited = False\r
2946 for D in M.DepexExpression[self.Arch, ModuleType]:\r
2947 if DepexExpressionList != '':\r
2948 DepexExpressionList += ' AND '\r
2949 DepexExpressionList += '('\r
2950 DepexExpressionList += D\r
2951 DepexExpressionList = DepexExpressionList.rstrip('END').strip()\r
2952 DepexExpressionList += ')'\r
2953 Inherited = True\r
2954 if Inherited:\r
2955 EdkLogger.verbose("DEPEX[%s] (+%s) = %s" % (self.Name, M.BaseName, DepexExpressionList))\r
2956 if 'BEFORE' in DepexExpressionList or 'AFTER' in DepexExpressionList:\r
2957 break\r
2958 if len(DepexExpressionList) > 0:\r
2959 EdkLogger.verbose('')\r
2960 self._DepexExpressionList[ModuleType] = DepexExpressionList\r
2961 return self._DepexExpressionList\r
2962\r
2963 ## Return the list of specification version required for the module\r
2964 #\r
2965 # @retval list The list of specification defined in module file\r
2966 #\r
2967 def _GetSpecification(self):\r
2968 return self.Module.Specification\r
2969\r
2970 ## Tool option for the module build\r
2971 #\r
2972 # @param PlatformInfo The object of PlatformBuildInfo\r
2973 # @retval dict The dict containing valid options\r
2974 #\r
2975 def _GetModuleBuildOption(self):\r
2976 if self._BuildOption == None:\r
fe4bf2f9
YL
2977 self._BuildOption, self.BuildRuleOrder = self.PlatformInfo.ApplyBuildOption(self.Module)\r
2978 if self.BuildRuleOrder:\r
2979 self.BuildRuleOrder = ['.%s' % Ext for Ext in self.BuildRuleOrder.split()]\r
52302d4d
LG
2980 return self._BuildOption\r
2981\r
79b74a03
LG
2982 ## Get include path list from tool option for the module build\r
2983 #\r
2984 # @retval list The include path list\r
2985 #\r
2986 def _GetBuildOptionIncPathList(self):\r
2987 if self._BuildOptionIncPathList == None:\r
2988 #\r
d40b2ee6 2989 # Regular expression for finding Include Directories, the difference between MSFT and INTEL/GCC/RVCT\r
79b74a03
LG
2990 # is the former use /I , the Latter used -I to specify include directories\r
2991 #\r
2992 if self.PlatformInfo.ToolChainFamily in ('MSFT'):\r
47fea6af 2993 gBuildOptIncludePattern = re.compile(r"(?:.*?)/I[ \t]*([^ ]*)", re.MULTILINE | re.DOTALL)\r
d40b2ee6 2994 elif self.PlatformInfo.ToolChainFamily in ('INTEL', 'GCC', 'RVCT'):\r
47fea6af 2995 gBuildOptIncludePattern = re.compile(r"(?:.*?)-I[ \t]*([^ ]*)", re.MULTILINE | re.DOTALL)\r
d40b2ee6
LG
2996 else:\r
2997 #\r
2998 # New ToolChainFamily, don't known whether there is option to specify include directories\r
2999 #\r
3000 self._BuildOptionIncPathList = []\r
3001 return self._BuildOptionIncPathList\r
79b74a03
LG
3002 \r
3003 BuildOptionIncPathList = []\r
3004 for Tool in ('CC', 'PP', 'VFRPP', 'ASLPP', 'ASLCC', 'APP', 'ASM'):\r
3005 Attr = 'FLAGS'\r
3006 try:\r
3007 FlagOption = self.BuildOption[Tool][Attr]\r
3008 except KeyError:\r
3009 FlagOption = ''\r
3010 \r
d40b2ee6
LG
3011 if self.PlatformInfo.ToolChainFamily != 'RVCT':\r
3012 IncPathList = [NormPath(Path, self.Macros) for Path in gBuildOptIncludePattern.findall(FlagOption)]\r
3013 else:\r
3014 #\r
3015 # RVCT may specify a list of directory seperated by commas\r
3016 #\r
3017 IncPathList = []\r
3018 for Path in gBuildOptIncludePattern.findall(FlagOption):\r
3019 PathList = GetSplitList(Path, TAB_COMMA_SPLIT)\r
3020 IncPathList += [NormPath(PathEntry, self.Macros) for PathEntry in PathList]\r
3021\r
79b74a03
LG
3022 #\r
3023 # EDK II modules must not reference header files outside of the packages they depend on or \r
3024 # within the module's directory tree. Report error if violation.\r
3025 #\r
3026 if self.AutoGenVersion >= 0x00010005 and len(IncPathList) > 0:\r
3027 for Path in IncPathList:\r
3028 if (Path not in self.IncludePathList) and (CommonPath([Path, self.MetaFile.Dir]) != self.MetaFile.Dir):\r
47fea6af
YZ
3029 ErrMsg = "The include directory for the EDK II module in this line is invalid %s specified in %s FLAGS '%s'" % (Path, Tool, FlagOption)\r
3030 EdkLogger.error("build",\r
79b74a03 3031 PARAMETER_INVALID,\r
47fea6af
YZ
3032 ExtraData=ErrMsg,\r
3033 File=str(self.MetaFile))\r
79b74a03
LG
3034\r
3035 \r
3036 BuildOptionIncPathList += IncPathList\r
3037 \r
3038 self._BuildOptionIncPathList = BuildOptionIncPathList\r
3039 \r
3040 return self._BuildOptionIncPathList\r
3041 \r
52302d4d
LG
3042 ## Return a list of files which can be built from source\r
3043 #\r
3044 # What kind of files can be built is determined by build rules in\r
97fa0ee9 3045 # $(CONF_DIRECTORY)/build_rule.txt and toolchain family.\r
52302d4d
LG
3046 #\r
3047 def _GetSourceFileList(self):\r
3048 if self._SourceFileList == None:\r
3049 self._SourceFileList = []\r
3050 for F in self.Module.Sources:\r
3051 # match tool chain\r
08dd311f 3052 if F.TagName not in ("", "*", self.ToolChain):\r
52302d4d
LG
3053 EdkLogger.debug(EdkLogger.DEBUG_9, "The toolchain [%s] for processing file [%s] is found, "\r
3054 "but [%s] is needed" % (F.TagName, str(F), self.ToolChain))\r
3055 continue\r
3056 # match tool chain family\r
08dd311f 3057 if F.ToolChainFamily not in ("", "*", self.ToolChainFamily):\r
52302d4d
LG
3058 EdkLogger.debug(\r
3059 EdkLogger.DEBUG_0,\r
3060 "The file [%s] must be built by tools of [%s], " \\r
3061 "but current toolchain family is [%s]" \\r
3062 % (str(F), F.ToolChainFamily, self.ToolChainFamily))\r
3063 continue\r
3064\r
3065 # add the file path into search path list for file including\r
3066 if F.Dir not in self.IncludePathList and self.AutoGenVersion >= 0x00010005:\r
3067 self.IncludePathList.insert(0, F.Dir)\r
3068 self._SourceFileList.append(F)\r
4cb7bade
YZ
3069\r
3070 self._MatchBuildRuleOrder(self._SourceFileList)\r
3071\r
3072 for F in self._SourceFileList:\r
52302d4d
LG
3073 self._ApplyBuildRule(F, TAB_UNKNOWN_FILE)\r
3074 return self._SourceFileList\r
3075\r
4cb7bade
YZ
3076 def _MatchBuildRuleOrder(self, FileList):\r
3077 Order_Dict = {}\r
3078 self._GetModuleBuildOption()\r
3079 for SingleFile in FileList:\r
3080 if self.BuildRuleOrder and SingleFile.Ext in self.BuildRuleOrder and SingleFile.Ext in self.BuildRules:\r
3081 key = SingleFile.Path.split(SingleFile.Ext)[0]\r
3082 if key in Order_Dict:\r
3083 Order_Dict[key].append(SingleFile.Ext)\r
3084 else:\r
3085 Order_Dict[key] = [SingleFile.Ext]\r
3086\r
3087 RemoveList = []\r
3088 for F in Order_Dict:\r
3089 if len(Order_Dict[F]) > 1:\r
3090 Order_Dict[F].sort(key=lambda i: self.BuildRuleOrder.index(i))\r
3091 for Ext in Order_Dict[F][1:]:\r
3092 RemoveList.append(F + Ext)\r
3093 \r
3094 for item in RemoveList:\r
3095 FileList.remove(item)\r
3096\r
3097 return FileList\r
3098\r
52302d4d
LG
3099 ## Return the list of unicode files\r
3100 def _GetUnicodeFileList(self):\r
3101 if self._UnicodeFileList == None:\r
3102 if TAB_UNICODE_FILE in self.FileTypes:\r
3103 self._UnicodeFileList = self.FileTypes[TAB_UNICODE_FILE]\r
3104 else:\r
3105 self._UnicodeFileList = []\r
3106 return self._UnicodeFileList\r
3107\r
3108 ## Return a list of files which can be built from binary\r
3109 #\r
3110 # "Build" binary files are just to copy them to build directory.\r
3111 #\r
3112 # @retval list The list of files which can be built later\r
3113 #\r
3114 def _GetBinaryFiles(self):\r
3115 if self._BinaryFileList == None:\r
3116 self._BinaryFileList = []\r
3117 for F in self.Module.Binaries:\r
3118 if F.Target not in ['COMMON', '*'] and F.Target != self.BuildTarget:\r
3119 continue\r
3120 self._BinaryFileList.append(F)\r
3121 self._ApplyBuildRule(F, F.Type)\r
3122 return self._BinaryFileList\r
3123\r
3124 def _GetBuildRules(self):\r
3125 if self._BuildRules == None:\r
3126 BuildRules = {}\r
3127 BuildRuleDatabase = self.PlatformInfo.BuildRule\r
3128 for Type in BuildRuleDatabase.FileTypeList:\r
3129 #first try getting build rule by BuildRuleFamily\r
3130 RuleObject = BuildRuleDatabase[Type, self.BuildType, self.Arch, self.BuildRuleFamily]\r
3131 if not RuleObject:\r
3132 # build type is always module type, but ...\r
3133 if self.ModuleType != self.BuildType:\r
3134 RuleObject = BuildRuleDatabase[Type, self.ModuleType, self.Arch, self.BuildRuleFamily]\r
3135 #second try getting build rule by ToolChainFamily\r
3136 if not RuleObject:\r
3137 RuleObject = BuildRuleDatabase[Type, self.BuildType, self.Arch, self.ToolChainFamily]\r
3138 if not RuleObject:\r
3139 # build type is always module type, but ...\r
3140 if self.ModuleType != self.BuildType:\r
3141 RuleObject = BuildRuleDatabase[Type, self.ModuleType, self.Arch, self.ToolChainFamily]\r
3142 if not RuleObject:\r
3143 continue\r
3144 RuleObject = RuleObject.Instantiate(self.Macros)\r
3145 BuildRules[Type] = RuleObject\r
3146 for Ext in RuleObject.SourceFileExtList:\r
3147 BuildRules[Ext] = RuleObject\r
3148 self._BuildRules = BuildRules\r
3149 return self._BuildRules\r
3150\r
3151 def _ApplyBuildRule(self, File, FileType):\r
3152 if self._BuildTargets == None:\r
3153 self._IntroBuildTargetList = set()\r
3154 self._FinalBuildTargetList = set()\r
3155 self._BuildTargets = {}\r
3156 self._FileTypes = {}\r
3157\r
fcd4fbf3
YL
3158 SubDirectory = os.path.join(self.OutputDir, File.SubDir)\r
3159 if not os.path.exists(SubDirectory):\r
3160 CreateDirectory(SubDirectory)\r
52302d4d
LG
3161 LastTarget = None\r
3162 RuleChain = []\r
3163 SourceList = [File]\r
3164 Index = 0\r
fe4bf2f9
YL
3165 #\r
3166 # Make sure to get build rule order value\r
3167 #\r
3168 self._GetModuleBuildOption()\r
3169\r
52302d4d
LG
3170 while Index < len(SourceList):\r
3171 Source = SourceList[Index]\r
3172 Index = Index + 1\r
3173\r
3174 if Source != File:\r
3175 CreateDirectory(Source.Dir)\r
3176\r
3177 if File.IsBinary and File == Source and self._BinaryFileList != None and File in self._BinaryFileList:\r
da92f276
LG
3178 # Skip all files that are not binary libraries\r
3179 if not self.IsLibrary:\r
47fea6af 3180 continue\r
52302d4d
LG
3181 RuleObject = self.BuildRules[TAB_DEFAULT_BINARY_FILE]\r
3182 elif FileType in self.BuildRules:\r
3183 RuleObject = self.BuildRules[FileType]\r
3184 elif Source.Ext in self.BuildRules:\r
3185 RuleObject = self.BuildRules[Source.Ext]\r
3186 else:\r
3187 # stop at no more rules\r
3188 if LastTarget:\r
3189 self._FinalBuildTargetList.add(LastTarget)\r
3190 break\r
3191\r
3192 FileType = RuleObject.SourceFileType\r
3193 if FileType not in self._FileTypes:\r
3194 self._FileTypes[FileType] = set()\r
3195 self._FileTypes[FileType].add(Source)\r
3196\r
3197 # stop at STATIC_LIBRARY for library\r
3198 if self.IsLibrary and FileType == TAB_STATIC_LIBRARY:\r
3199 if LastTarget:\r
3200 self._FinalBuildTargetList.add(LastTarget)\r
3201 break\r
3202\r
fe4bf2f9 3203 Target = RuleObject.Apply(Source, self.BuildRuleOrder)\r
52302d4d
LG
3204 if not Target:\r
3205 if LastTarget:\r
3206 self._FinalBuildTargetList.add(LastTarget)\r
3207 break\r
3208 elif not Target.Outputs:\r
3209 # Only do build for target with outputs\r
3210 self._FinalBuildTargetList.add(Target)\r
3211\r
3212 if FileType not in self._BuildTargets:\r
3213 self._BuildTargets[FileType] = set()\r
3214 self._BuildTargets[FileType].add(Target)\r
3215\r
3216 if not Source.IsBinary and Source == File:\r
3217 self._IntroBuildTargetList.add(Target)\r
3218\r
3219 # to avoid cyclic rule\r
3220 if FileType in RuleChain:\r
3221 break\r
3222\r
3223 RuleChain.append(FileType)\r
3224 SourceList.extend(Target.Outputs)\r
3225 LastTarget = Target\r
3226 FileType = TAB_UNKNOWN_FILE\r
3227\r
3228 def _GetTargets(self):\r
3229 if self._BuildTargets == None:\r
3230 self._IntroBuildTargetList = set()\r
3231 self._FinalBuildTargetList = set()\r
3232 self._BuildTargets = {}\r
3233 self._FileTypes = {}\r
3234\r
b36d134f 3235 #TRICK: call _GetSourceFileList to apply build rule for source files\r
52302d4d
LG
3236 if self.SourceFileList:\r
3237 pass\r
3238\r
3239 #TRICK: call _GetBinaryFileList to apply build rule for binary files\r
3240 if self.BinaryFileList:\r
3241 pass\r
3242\r
3243 return self._BuildTargets\r
3244\r
3245 def _GetIntroTargetList(self):\r
3246 self._GetTargets()\r
3247 return self._IntroBuildTargetList\r
3248\r
3249 def _GetFinalTargetList(self):\r
3250 self._GetTargets()\r
3251 return self._FinalBuildTargetList\r
3252\r
3253 def _GetFileTypes(self):\r
3254 self._GetTargets()\r
3255 return self._FileTypes\r
3256\r
3257 ## Get the list of package object the module depends on\r
3258 #\r
3259 # @retval list The package object list\r
3260 #\r
3261 def _GetDependentPackageList(self):\r
3262 return self.Module.Packages\r
3263\r
3264 ## Return the list of auto-generated code file\r
3265 #\r
3266 # @retval list The list of auto-generated file\r
3267 #\r
3268 def _GetAutoGenFileList(self):\r
3269 UniStringAutoGenC = True\r
4234283c 3270 UniStringBinBuffer = StringIO()\r
52302d4d 3271 if self.BuildType == 'UEFI_HII':\r
52302d4d
LG
3272 UniStringAutoGenC = False\r
3273 if self._AutoGenFileList == None:\r
3274 self._AutoGenFileList = {}\r
3275 AutoGenC = TemplateString()\r
3276 AutoGenH = TemplateString()\r
3277 StringH = TemplateString()\r
3278 GenC.CreateCode(self, AutoGenC, AutoGenH, StringH, UniStringAutoGenC, UniStringBinBuffer)\r
07b8564b
YL
3279 #\r
3280 # AutoGen.c is generated if there are library classes in inf, or there are object files\r
3281 #\r
3282 if str(AutoGenC) != "" and (len(self.Module.LibraryClasses) > 0\r
3283 or TAB_OBJECT_FILE in self.FileTypes):\r
52302d4d
LG
3284 AutoFile = PathClass(gAutoGenCodeFileName, self.DebugDir)\r
3285 self._AutoGenFileList[AutoFile] = str(AutoGenC)\r
3286 self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)\r
3287 if str(AutoGenH) != "":\r
3288 AutoFile = PathClass(gAutoGenHeaderFileName, self.DebugDir)\r
3289 self._AutoGenFileList[AutoFile] = str(AutoGenH)\r
3290 self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)\r
3291 if str(StringH) != "":\r
3292 AutoFile = PathClass(gAutoGenStringFileName % {"module_name":self.Name}, self.DebugDir)\r
3293 self._AutoGenFileList[AutoFile] = str(StringH)\r
3294 self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)\r
3295 if UniStringBinBuffer != None and UniStringBinBuffer.getvalue() != "":\r
3296 AutoFile = PathClass(gAutoGenStringFormFileName % {"module_name":self.Name}, self.OutputDir)\r
3297 self._AutoGenFileList[AutoFile] = UniStringBinBuffer.getvalue()\r
3298 AutoFile.IsBinary = True\r
3299 self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)\r
3300 if UniStringBinBuffer != None:\r
3301 UniStringBinBuffer.close()\r
3302 return self._AutoGenFileList\r
3303\r
3304 ## Return the list of library modules explicitly or implicityly used by this module\r
3305 def _GetLibraryList(self):\r
3306 if self._DependentLibraryList == None:\r
3307 # only merge library classes and PCD for non-library module\r
3308 if self.IsLibrary:\r
3309 self._DependentLibraryList = []\r
3310 else:\r
3311 if self.AutoGenVersion < 0x00010005:\r
3312 self._DependentLibraryList = self.PlatformInfo.ResolveLibraryReference(self.Module)\r
3313 else:\r
3314 self._DependentLibraryList = self.PlatformInfo.ApplyLibraryInstance(self.Module)\r
3315 return self._DependentLibraryList\r
3316\r
e8a47801
LG
3317 @staticmethod\r
3318 def UpdateComments(Recver, Src):\r
3319 for Key in Src:\r
3320 if Key not in Recver:\r
3321 Recver[Key] = []\r
3322 Recver[Key].extend(Src[Key])\r
52302d4d
LG
3323 ## Get the list of PCDs from current module\r
3324 #\r
3325 # @retval list The list of PCD\r
3326 #\r
3327 def _GetModulePcdList(self):\r
3328 if self._ModulePcdList == None:\r
3329 # apply PCD settings from platform\r
3330 self._ModulePcdList = self.PlatformInfo.ApplyPcdSetting(self.Module, self.Module.Pcds)\r
e8a47801 3331 self.UpdateComments(self._PcdComments, self.Module.PcdComments)\r
52302d4d
LG
3332 return self._ModulePcdList\r
3333\r
3334 ## Get the list of PCDs from dependent libraries\r
3335 #\r
3336 # @retval list The list of PCD\r
3337 #\r
3338 def _GetLibraryPcdList(self):\r
3339 if self._LibraryPcdList == None:\r
79b74a03 3340 Pcds = sdict()\r
52302d4d
LG
3341 if not self.IsLibrary:\r
3342 # get PCDs from dependent libraries\r
3343 for Library in self.DependentLibraryList:\r
e8a47801 3344 self.UpdateComments(self._PcdComments, Library.PcdComments)\r
52302d4d
LG
3345 for Key in Library.Pcds:\r
3346 # skip duplicated PCDs\r
3347 if Key in self.Module.Pcds or Key in Pcds:\r
3348 continue\r
3349 Pcds[Key] = copy.copy(Library.Pcds[Key])\r
3350 # apply PCD settings from platform\r
3351 self._LibraryPcdList = self.PlatformInfo.ApplyPcdSetting(self.Module, Pcds)\r
3352 else:\r
3353 self._LibraryPcdList = []\r
3354 return self._LibraryPcdList\r
3355\r
3356 ## Get the GUID value mapping\r
3357 #\r
3358 # @retval dict The mapping between GUID cname and its value\r
3359 #\r
3360 def _GetGuidList(self):\r
3361 if self._GuidList == None:\r
8200fcfe
YL
3362 self._GuidList = sdict()\r
3363 self._GuidList.update(self.Module.Guids)\r
52302d4d
LG
3364 for Library in self.DependentLibraryList:\r
3365 self._GuidList.update(Library.Guids)\r
e8a47801
LG
3366 self.UpdateComments(self._GuidComments, Library.GuidComments)\r
3367 self.UpdateComments(self._GuidComments, self.Module.GuidComments)\r
52302d4d
LG
3368 return self._GuidList\r
3369\r
e8a47801
LG
3370 def GetGuidsUsedByPcd(self):\r
3371 if self._GuidsUsedByPcd == None:\r
3372 self._GuidsUsedByPcd = sdict()\r
3373 self._GuidsUsedByPcd.update(self.Module.GetGuidsUsedByPcd())\r
3374 for Library in self.DependentLibraryList:\r
3375 self._GuidsUsedByPcd.update(Library.GetGuidsUsedByPcd())\r
3376 return self._GuidsUsedByPcd\r
52302d4d
LG
3377 ## Get the protocol value mapping\r
3378 #\r
3379 # @retval dict The mapping between protocol cname and its value\r
3380 #\r
3381 def _GetProtocolList(self):\r
3382 if self._ProtocolList == None:\r
8200fcfe
YL
3383 self._ProtocolList = sdict()\r
3384 self._ProtocolList.update(self.Module.Protocols)\r
52302d4d
LG
3385 for Library in self.DependentLibraryList:\r
3386 self._ProtocolList.update(Library.Protocols)\r
e8a47801
LG
3387 self.UpdateComments(self._ProtocolComments, Library.ProtocolComments)\r
3388 self.UpdateComments(self._ProtocolComments, self.Module.ProtocolComments)\r
52302d4d
LG
3389 return self._ProtocolList\r
3390\r
3391 ## Get the PPI value mapping\r
3392 #\r
3393 # @retval dict The mapping between PPI cname and its value\r
3394 #\r
3395 def _GetPpiList(self):\r
3396 if self._PpiList == None:\r
8200fcfe
YL
3397 self._PpiList = sdict()\r
3398 self._PpiList.update(self.Module.Ppis)\r
52302d4d
LG
3399 for Library in self.DependentLibraryList:\r
3400 self._PpiList.update(Library.Ppis)\r
e8a47801
LG
3401 self.UpdateComments(self._PpiComments, Library.PpiComments)\r
3402 self.UpdateComments(self._PpiComments, self.Module.PpiComments)\r
52302d4d
LG
3403 return self._PpiList\r
3404\r
3405 ## Get the list of include search path\r
3406 #\r
3407 # @retval list The list path\r
3408 #\r
3409 def _GetIncludePathList(self):\r
3410 if self._IncludePathList == None:\r
3411 self._IncludePathList = []\r
3412 if self.AutoGenVersion < 0x00010005:\r
3413 for Inc in self.Module.Includes:\r
3414 if Inc not in self._IncludePathList:\r
3415 self._IncludePathList.append(Inc)\r
b36d134f 3416 # for Edk modules\r
52302d4d
LG
3417 Inc = path.join(Inc, self.Arch.capitalize())\r
3418 if os.path.exists(Inc) and Inc not in self._IncludePathList:\r
3419 self._IncludePathList.append(Inc)\r
b36d134f 3420 # 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
3421 self._IncludePathList.append(self.DebugDir)\r
3422 else:\r
3423 self._IncludePathList.append(self.MetaFile.Dir)\r
3424 self._IncludePathList.append(self.DebugDir)\r
3425\r
3426 for Package in self.Module.Packages:\r
05cc51ad 3427 PackageDir = mws.join(self.WorkspaceDir, Package.MetaFile.Dir)\r
52302d4d
LG
3428 if PackageDir not in self._IncludePathList:\r
3429 self._IncludePathList.append(PackageDir)\r
c28d2e10
YZ
3430 IncludesList = Package.Includes\r
3431 if Package._PrivateIncludes:\r
3432 if not self.MetaFile.Path.startswith(PackageDir):\r
3433 IncludesList = list(set(Package.Includes).difference(set(Package._PrivateIncludes)))\r
3434 for Inc in IncludesList:\r
52302d4d
LG
3435 if Inc not in self._IncludePathList:\r
3436 self._IncludePathList.append(str(Inc))\r
3437 return self._IncludePathList\r
3438\r
725cdb8f
YZ
3439 def _GetIncludePathLength(self):\r
3440 self._IncludePathLength = 0\r
3441 if self._IncludePathList:\r
3442 for inc in self._IncludePathList:\r
3443 self._IncludePathLength += len(' ' + inc)\r
3444 return self._IncludePathLength\r
3445\r
97fa0ee9
YL
3446 ## Get HII EX PCDs which maybe used by VFR\r
3447 #\r
3448 # efivarstore used by VFR may relate with HII EX PCDs\r
3449 # Get the variable name and GUID from efivarstore and HII EX PCD\r
3450 # List the HII EX PCDs in As Built INF if both name and GUID match.\r
3451 #\r
3452 # @retval list HII EX PCDs\r
3453 #\r
3454 def _GetPcdsMaybeUsedByVfr(self):\r
3455 if not self.SourceFileList:\r
3456 return []\r
3457\r
3458 NameGuids = []\r
3459 for SrcFile in self.SourceFileList:\r
3460 if SrcFile.Ext.lower() != '.vfr':\r
3461 continue\r
3462 Vfri = os.path.join(self.OutputDir, SrcFile.BaseName + '.i')\r
3463 if not os.path.exists(Vfri):\r
3464 continue\r
3465 VfriFile = open(Vfri, 'r')\r
3466 Content = VfriFile.read()\r
3467 VfriFile.close()\r
3468 Pos = Content.find('efivarstore')\r
3469 while Pos != -1:\r
3470 #\r
3471 # Make sure 'efivarstore' is the start of efivarstore statement\r
3472 # In case of the value of 'name' (name = efivarstore) is equal to 'efivarstore'\r
3473 #\r
3474 Index = Pos - 1\r
3475 while Index >= 0 and Content[Index] in ' \t\r\n':\r
3476 Index -= 1\r
3477 if Index >= 0 and Content[Index] != ';':\r
3478 Pos = Content.find('efivarstore', Pos + len('efivarstore'))\r
3479 continue\r
3480 #\r
3481 # 'efivarstore' must be followed by name and guid\r
3482 #\r
3483 Name = gEfiVarStoreNamePattern.search(Content, Pos)\r
3484 if not Name:\r
3485 break\r
3486 Guid = gEfiVarStoreGuidPattern.search(Content, Pos)\r
3487 if not Guid:\r
3488 break\r
3489 NameArray = ConvertStringToByteArray('L"' + Name.group(1) + '"')\r
3490 NameGuids.append((NameArray, GuidStructureStringToGuidString(Guid.group(1))))\r
3491 Pos = Content.find('efivarstore', Name.end())\r
3492 if not NameGuids:\r
3493 return []\r
3494 HiiExPcds = []\r
3495 for Pcd in self.PlatformInfo.Platform.Pcds.values():\r
3496 if Pcd.Type != TAB_PCDS_DYNAMIC_EX_HII:\r
3497 continue\r
3498 for SkuName in Pcd.SkuInfoList:\r
3499 SkuInfo = Pcd.SkuInfoList[SkuName]\r
3500 Name = ConvertStringToByteArray(SkuInfo.VariableName)\r
c28d2e10 3501 Value = GuidValue(SkuInfo.VariableGuid, self.PlatformInfo.PackageList, self.MetaFile.Path)\r
97fa0ee9
YL
3502 if not Value:\r
3503 continue\r
3504 Guid = GuidStructureStringToGuidString(Value)\r
3505 if (Name, Guid) in NameGuids and Pcd not in HiiExPcds:\r
3506 HiiExPcds.append(Pcd)\r
3507 break\r
3508\r
3509 return HiiExPcds\r
3510\r
aeaaf754
YL
3511 def _GenOffsetBin(self):\r
3512 VfrUniBaseName = {}\r
3513 for SourceFile in self.Module.Sources:\r
3514 if SourceFile.Type.upper() == ".VFR" :\r
3515 #\r
3516 # search the .map file to find the offset of vfr binary in the PE32+/TE file. \r
3517 #\r
3518 VfrUniBaseName[SourceFile.BaseName] = (SourceFile.BaseName + "Bin")\r
3519 if SourceFile.Type.upper() == ".UNI" :\r
3520 #\r
3521 # search the .map file to find the offset of Uni strings binary in the PE32+/TE file. \r
3522 #\r
3523 VfrUniBaseName["UniOffsetName"] = (self.Name + "Strings")\r
3524\r
3525 if len(VfrUniBaseName) == 0:\r
3526 return None\r
3527 MapFileName = os.path.join(self.OutputDir, self.Name + ".map")\r
3528 EfiFileName = os.path.join(self.OutputDir, self.Name + ".efi")\r
3529 VfrUniOffsetList = GetVariableOffset(MapFileName, EfiFileName, VfrUniBaseName.values())\r
3530 if not VfrUniOffsetList:\r
3531 return None\r
3532\r
3533 OutputName = '%sOffset.bin' % self.Name\r
3534 UniVfrOffsetFileName = os.path.join( self.OutputDir, OutputName)\r
3535\r
3536 try:\r
3537 fInputfile = open(UniVfrOffsetFileName, "wb+", 0)\r
3538 except:\r
3539 EdkLogger.error("build", FILE_OPEN_FAILURE, "File open failed for %s" % UniVfrOffsetFileName,None)\r
3540\r
3541 # Use a instance of StringIO to cache data\r
3542 fStringIO = StringIO('') \r
3543\r
3544 for Item in VfrUniOffsetList:\r
3545 if (Item[0].find("Strings") != -1):\r
3546 #\r
3547 # UNI offset in image.\r
3548 # GUID + Offset\r
3549 # { 0x8913c5e0, 0x33f6, 0x4d86, { 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66 } }\r
3550 #\r
3551 UniGuid = [0xe0, 0xc5, 0x13, 0x89, 0xf6, 0x33, 0x86, 0x4d, 0x9b, 0xf1, 0x43, 0xef, 0x89, 0xfc, 0x6, 0x66]\r
3552 UniGuid = [chr(ItemGuid) for ItemGuid in UniGuid]\r
3553 fStringIO.write(''.join(UniGuid)) \r
3554 UniValue = pack ('Q', int (Item[1], 16))\r
3555 fStringIO.write (UniValue)\r
3556 else:\r
3557 #\r
3558 # VFR binary offset in image.\r
3559 # GUID + Offset\r
3560 # { 0xd0bc7cb4, 0x6a47, 0x495f, { 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2 } };\r
3561 #\r
3562 VfrGuid = [0xb4, 0x7c, 0xbc, 0xd0, 0x47, 0x6a, 0x5f, 0x49, 0xaa, 0x11, 0x71, 0x7, 0x46, 0xda, 0x6, 0xa2]\r
3563 VfrGuid = [chr(ItemGuid) for ItemGuid in VfrGuid]\r
3564 fStringIO.write(''.join(VfrGuid)) \r
3565 type (Item[1]) \r
3566 VfrValue = pack ('Q', int (Item[1], 16))\r
3567 fStringIO.write (VfrValue)\r
3568 #\r
3569 # write data into file.\r
3570 #\r
3571 try : \r
3572 fInputfile.write (fStringIO.getvalue())\r
3573 except:\r
3574 EdkLogger.error("build", FILE_WRITE_FAILURE, "Write data to file %s failed, please check whether the "\r
3575 "file been locked or using by other applications." %UniVfrOffsetFileName,None)\r
3576\r
3577 fStringIO.close ()\r
3578 fInputfile.close ()\r
3579 return OutputName\r
3580\r
da92f276
LG
3581 ## Create AsBuilt INF file the module\r
3582 #\r
3583 def CreateAsBuiltInf(self):\r
3584 if self.IsAsBuiltInfCreated:\r
3585 return\r
3586 \r
3587 # Skip the following code for EDK I inf\r
3588 if self.AutoGenVersion < 0x00010005:\r
3589 return\r
3590 \r
3591 # Skip the following code for libraries\r
3592 if self.IsLibrary:\r
3593 return\r
3594 \r
3595 # Skip the following code for modules with no source files\r
3596 if self.SourceFileList == None or self.SourceFileList == []:\r
3597 return\r
3598\r
3599 # Skip the following code for modules without any binary files\r
3600 if self.BinaryFileList <> None and self.BinaryFileList <> []:\r
3601 return\r
3602 \r
3603 ### TODO: How to handles mixed source and binary modules\r
3604\r
e8a47801 3605 # Find all DynamicEx and PatchableInModule PCDs used by this module and dependent libraries\r
da92f276
LG
3606 # Also find all packages that the DynamicEx PCDs depend on\r
3607 Pcds = []\r
e5cf9198 3608 PatchablePcds = []\r
47fea6af 3609 Packages = []\r
e8a47801
LG
3610 PcdCheckList = []\r
3611 PcdTokenSpaceList = []\r
da92f276 3612 for Pcd in self.ModulePcdList + self.LibraryPcdList:\r
e8a47801 3613 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r
e5cf9198 3614 PatchablePcds += [Pcd]\r
e8a47801
LG
3615 PcdCheckList.append((Pcd.TokenCName, Pcd.TokenSpaceGuidCName, 'PatchableInModule'))\r
3616 elif Pcd.Type in GenC.gDynamicExPcd:\r
3617 if Pcd not in Pcds:\r
3618 Pcds += [Pcd]\r
3619 PcdCheckList.append((Pcd.TokenCName, Pcd.TokenSpaceGuidCName, 'DynamicEx'))\r
3620 PcdCheckList.append((Pcd.TokenCName, Pcd.TokenSpaceGuidCName, 'Dynamic'))\r
3621 PcdTokenSpaceList.append(Pcd.TokenSpaceGuidCName)\r
3622 GuidList = sdict()\r
3623 GuidList.update(self.GuidList)\r
3624 for TokenSpace in self.GetGuidsUsedByPcd():\r
3625 # If token space is not referred by patch PCD or Ex PCD, remove the GUID from GUID list\r
3626 # The GUIDs in GUIDs section should really be the GUIDs in source INF or referred by Ex an patch PCDs\r
3627 if TokenSpace not in PcdTokenSpaceList and TokenSpace in GuidList:\r
3628 GuidList.pop(TokenSpace)\r
3629 CheckList = (GuidList, self.PpiList, self.ProtocolList, PcdCheckList)\r
3630 for Package in self.DerivedPackageList:\r
3631 if Package in Packages:\r
3632 continue\r
3633 BeChecked = (Package.Guids, Package.Ppis, Package.Protocols, Package.Pcds)\r
3634 Found = False\r
3635 for Index in range(len(BeChecked)):\r
3636 for Item in CheckList[Index]:\r
3637 if Item in BeChecked[Index]:\r
3638 Packages += [Package]\r
3639 Found = True\r
3640 break\r
3641 if Found: break\r
da92f276 3642\r
97fa0ee9
YL
3643 VfrPcds = self._GetPcdsMaybeUsedByVfr()\r
3644 for Pkg in self.PlatformInfo.PackageList:\r
3645 if Pkg in Packages:\r
3646 continue\r
3647 for VfrPcd in VfrPcds:\r
3648 if ((VfrPcd.TokenCName, VfrPcd.TokenSpaceGuidCName, 'DynamicEx') in Pkg.Pcds or\r
3649 (VfrPcd.TokenCName, VfrPcd.TokenSpaceGuidCName, 'Dynamic') in Pkg.Pcds):\r
3650 Packages += [Pkg]\r
3651 break\r
3652\r
da92f276
LG
3653 ModuleType = self.ModuleType\r
3654 if ModuleType == 'UEFI_DRIVER' and self.DepexGenerated:\r
e8a47801
LG
3655 ModuleType = 'DXE_DRIVER'\r
3656\r
3657 DriverType = ''\r
3658 if self.PcdIsDriver != '':\r
3659 DriverType = self.PcdIsDriver\r
da92f276 3660\r
97fa0ee9
YL
3661 Guid = self.Guid\r
3662 MDefs = self.Module.Defines\r
3663\r
da92f276
LG
3664 AsBuiltInfDict = {\r
3665 'module_name' : self.Name,\r
97fa0ee9 3666 'module_guid' : Guid,\r
da92f276 3667 'module_module_type' : ModuleType,\r
97fa0ee9 3668 'module_version_string' : [MDefs['VERSION_STRING']] if 'VERSION_STRING' in MDefs else [],\r
e8a47801 3669 'pcd_is_driver_string' : [],\r
da92f276
LG
3670 'module_uefi_specification_version' : [],\r
3671 'module_pi_specification_version' : [],\r
97fa0ee9
YL
3672 'module_entry_point' : self.Module.ModuleEntryPointList,\r
3673 'module_unload_image' : self.Module.ModuleUnloadImageList,\r
3674 'module_constructor' : self.Module.ConstructorList,\r
3675 'module_destructor' : self.Module.DestructorList,\r
3676 'module_shadow' : [MDefs['SHADOW']] if 'SHADOW' in MDefs else [],\r
3677 'module_pci_vendor_id' : [MDefs['PCI_VENDOR_ID']] if 'PCI_VENDOR_ID' in MDefs else [],\r
3678 'module_pci_device_id' : [MDefs['PCI_DEVICE_ID']] if 'PCI_DEVICE_ID' in MDefs else [],\r
3679 'module_pci_class_code' : [MDefs['PCI_CLASS_CODE']] if 'PCI_CLASS_CODE' in MDefs else [],\r
3680 'module_pci_revision' : [MDefs['PCI_REVISION']] if 'PCI_REVISION' in MDefs else [],\r
3681 'module_build_number' : [MDefs['BUILD_NUMBER']] if 'BUILD_NUMBER' in MDefs else [],\r
3682 'module_spec' : [MDefs['SPEC']] if 'SPEC' in MDefs else [],\r
3683 'module_uefi_hii_resource_section' : [MDefs['UEFI_HII_RESOURCE_SECTION']] if 'UEFI_HII_RESOURCE_SECTION' in MDefs else [],\r
3684 'module_uni_file' : [MDefs['MODULE_UNI_FILE']] if 'MODULE_UNI_FILE' in MDefs else [],\r
da92f276 3685 'module_arch' : self.Arch,\r
47fea6af 3686 'package_item' : ['%s' % (Package.MetaFile.File.replace('\\', '/')) for Package in Packages],\r
da92f276 3687 'binary_item' : [],\r
e8a47801 3688 'patchablepcd_item' : [],\r
da92f276 3689 'pcd_item' : [],\r
e8a47801
LG
3690 'protocol_item' : [],\r
3691 'ppi_item' : [],\r
3692 'guid_item' : [],\r
3693 'flags_item' : [],\r
3694 'libraryclasses_item' : []\r
da92f276 3695 }\r
97fa0ee9
YL
3696\r
3697 if self.AutoGenVersion > int(gInfSpecVersion, 0):\r
3698 AsBuiltInfDict['module_inf_version'] = '0x%08x' % self.AutoGenVersion\r
3699 else:\r
3700 AsBuiltInfDict['module_inf_version'] = gInfSpecVersion\r
3701\r
e8a47801
LG
3702 if DriverType:\r
3703 AsBuiltInfDict['pcd_is_driver_string'] += [DriverType]\r
da92f276
LG
3704\r
3705 if 'UEFI_SPECIFICATION_VERSION' in self.Specification:\r
481252bb 3706 AsBuiltInfDict['module_uefi_specification_version'] += [self.Specification['UEFI_SPECIFICATION_VERSION']]\r
da92f276 3707 if 'PI_SPECIFICATION_VERSION' in self.Specification:\r
481252bb 3708 AsBuiltInfDict['module_pi_specification_version'] += [self.Specification['PI_SPECIFICATION_VERSION']]\r
da92f276 3709\r
47fea6af 3710 OutputDir = self.OutputDir.replace('\\', '/').strip('/')\r
481252bb
YZ
3711\r
3712 for Item in self.CodaTargetList:\r
47fea6af
YZ
3713 File = Item.Target.Path.replace('\\', '/').strip('/').replace(OutputDir, '').strip('/')\r
3714 if Item.Target.Ext.lower() == '.aml':\r
481252bb 3715 AsBuiltInfDict['binary_item'] += ['ASL|' + File]\r
47fea6af 3716 elif Item.Target.Ext.lower() == '.acpi':\r
481252bb
YZ
3717 AsBuiltInfDict['binary_item'] += ['ACPI|' + File]\r
3718 elif Item.Target.Ext.lower() == '.efi':\r
3719 AsBuiltInfDict['binary_item'] += ['PE32|' + self.Name + '.efi']\r
da92f276 3720 else:\r
481252bb
YZ
3721 AsBuiltInfDict['binary_item'] += ['BIN|' + File]\r
3722 if self.DepexGenerated:\r
da92f276 3723 if self.ModuleType in ['PEIM']:\r
481252bb 3724 AsBuiltInfDict['binary_item'] += ['PEI_DEPEX|' + self.Name + '.depex']\r
47fea6af 3725 if self.ModuleType in ['DXE_DRIVER', 'DXE_RUNTIME_DRIVER', 'DXE_SAL_DRIVER', 'UEFI_DRIVER']:\r
481252bb 3726 AsBuiltInfDict['binary_item'] += ['DXE_DEPEX|' + self.Name + '.depex']\r
da92f276 3727 if self.ModuleType in ['DXE_SMM_DRIVER']:\r
481252bb 3728 AsBuiltInfDict['binary_item'] += ['SMM_DEPEX|' + self.Name + '.depex']\r
da92f276 3729\r
aeaaf754
YL
3730 Bin = self._GenOffsetBin()\r
3731 if Bin:\r
3732 AsBuiltInfDict['binary_item'] += ['BIN|%s' % Bin]\r
3733\r
e8a47801
LG
3734 for Root, Dirs, Files in os.walk(OutputDir):\r
3735 for File in Files:\r
3736 if File.lower().endswith('.pdb'):\r
3737 AsBuiltInfDict['binary_item'] += ['DISPOSABLE|' + File]\r
3738 HeaderComments = self.Module.HeaderComments\r
3739 StartPos = 0\r
3740 for Index in range(len(HeaderComments)):\r
3741 if HeaderComments[Index].find('@BinaryHeader') != -1:\r
3742 HeaderComments[Index] = HeaderComments[Index].replace('@BinaryHeader', '@file')\r
3743 StartPos = Index\r
3744 break\r
3745 AsBuiltInfDict['header_comments'] = '\n'.join(HeaderComments[StartPos:]).replace(':#', '://')\r
97fa0ee9
YL
3746 AsBuiltInfDict['tail_comments'] = '\n'.join(self.Module.TailComments)\r
3747\r
e8a47801
LG
3748 GenList = [\r
3749 (self.ProtocolList, self._ProtocolComments, 'protocol_item'),\r
3750 (self.PpiList, self._PpiComments, 'ppi_item'),\r
3751 (GuidList, self._GuidComments, 'guid_item')\r
3752 ]\r
3753 for Item in GenList:\r
3754 for CName in Item[0]:\r
3755 Comments = ''\r
3756 if CName in Item[1]:\r
3757 Comments = '\n '.join(Item[1][CName])\r
3758 Entry = CName\r
3759 if Comments:\r
3760 Entry = Comments + '\n ' + CName\r
3761 AsBuiltInfDict[Item[2]].append(Entry)\r
3762 PatchList = parsePcdInfoFromMapFile(\r
3763 os.path.join(self.OutputDir, self.Name + '.map'),\r
3764 os.path.join(self.OutputDir, self.Name + '.efi')\r
3765 )\r
3766 if PatchList:\r
e5cf9198
YZ
3767 for Pcd in PatchablePcds:\r
3768 TokenCName = Pcd.TokenCName\r
3769 for PcdItem in GlobalData.MixedPcd:\r
3770 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
3771 TokenCName = PcdItem[0]\r
3772 break\r
3773 for PatchPcd in PatchList:\r
3774 if TokenCName == PatchPcd[0]:\r
3775 break\r
2a29017e 3776 else:\r
e8a47801 3777 continue\r
e8a47801
LG
3778 PcdValue = ''\r
3779 if Pcd.DatumType != 'VOID*':\r
3780 HexFormat = '0x%02x'\r
3781 if Pcd.DatumType == 'UINT16':\r
3782 HexFormat = '0x%04x'\r
3783 elif Pcd.DatumType == 'UINT32':\r
3784 HexFormat = '0x%08x'\r
3785 elif Pcd.DatumType == 'UINT64':\r
3786 HexFormat = '0x%016x'\r
3787 PcdValue = HexFormat % int(Pcd.DefaultValue, 0)\r
3788 else:\r
3789 if Pcd.MaxDatumSize == None or Pcd.MaxDatumSize == '':\r
3790 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 3791 "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd.TokenSpaceGuidCName, TokenCName)\r
e8a47801
LG
3792 )\r
3793 ArraySize = int(Pcd.MaxDatumSize, 0)\r
3794 PcdValue = Pcd.DefaultValue\r
3795 if PcdValue[0] != '{':\r
3796 Unicode = False\r
3797 if PcdValue[0] == 'L':\r
3798 Unicode = True\r
3799 PcdValue = PcdValue.lstrip('L')\r
3800 PcdValue = eval(PcdValue)\r
3801 NewValue = '{'\r
3802 for Index in range(0, len(PcdValue)):\r
3803 if Unicode:\r
3804 CharVal = ord(PcdValue[Index])\r
3805 NewValue = NewValue + '0x%02x' % (CharVal & 0x00FF) + ', ' \\r
3806 + '0x%02x' % (CharVal >> 8) + ', '\r
3807 else:\r
3808 NewValue = NewValue + '0x%02x' % (ord(PcdValue[Index]) % 0x100) + ', '\r
3809 Padding = '0x00, '\r
3810 if Unicode:\r
3811 Padding = Padding * 2\r
3812 ArraySize = ArraySize / 2\r
3813 if ArraySize < (len(PcdValue) + 1):\r
3814 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 3815 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, TokenCName)\r
e8a47801
LG
3816 )\r
3817 if ArraySize > len(PcdValue) + 1:\r
3818 NewValue = NewValue + Padding * (ArraySize - len(PcdValue) - 1)\r
3819 PcdValue = NewValue + Padding.strip().rstrip(',') + '}'\r
3820 elif len(PcdValue.split(',')) <= ArraySize:\r
3821 PcdValue = PcdValue.rstrip('}') + ', 0x00' * (ArraySize - len(PcdValue.split(',')))\r
3822 PcdValue += '}'\r
3823 else:\r
3824 EdkLogger.error("build", AUTOGEN_ERROR,\r
2a29017e 3825 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, TokenCName)\r
e8a47801
LG
3826 )\r
3827 PcdItem = '%s.%s|%s|0x%X' % \\r
2a29017e 3828 (Pcd.TokenSpaceGuidCName, TokenCName, PcdValue, PatchPcd[1])\r
e8a47801
LG
3829 PcdComments = ''\r
3830 if (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) in self._PcdComments:\r
3831 PcdComments = '\n '.join(self._PcdComments[Pcd.TokenSpaceGuidCName, Pcd.TokenCName])\r
3832 if PcdComments:\r
3833 PcdItem = PcdComments + '\n ' + PcdItem\r
3834 AsBuiltInfDict['patchablepcd_item'].append(PcdItem)\r
97fa0ee9
YL
3835\r
3836 HiiPcds = []\r
3837 for Pcd in Pcds + VfrPcds:\r
e8a47801
LG
3838 PcdComments = ''\r
3839 PcdCommentList = []\r
3840 HiiInfo = ''\r
97fa0ee9 3841 SkuId = ''\r
2a29017e
YZ
3842 TokenCName = Pcd.TokenCName\r
3843 for PcdItem in GlobalData.MixedPcd:\r
3844 if (Pcd.TokenCName, Pcd.TokenSpaceGuidCName) in GlobalData.MixedPcd[PcdItem]:\r
3845 TokenCName = PcdItem[0]\r
3846 break\r
e8a47801
LG
3847 if Pcd.Type == TAB_PCDS_DYNAMIC_EX_HII:\r
3848 for SkuName in Pcd.SkuInfoList:\r
3849 SkuInfo = Pcd.SkuInfoList[SkuName]\r
97fa0ee9 3850 SkuId = SkuInfo.SkuId\r
e8a47801
LG
3851 HiiInfo = '## %s|%s|%s' % (SkuInfo.VariableName, SkuInfo.VariableGuid, SkuInfo.VariableOffset)\r
3852 break\r
97fa0ee9
YL
3853 if SkuId:\r
3854 #\r
3855 # Don't generate duplicated HII PCD\r
3856 #\r
3857 if (SkuId, Pcd.TokenSpaceGuidCName, Pcd.TokenCName) in HiiPcds:\r
3858 continue\r
3859 else:\r
3860 HiiPcds.append((SkuId, Pcd.TokenSpaceGuidCName, Pcd.TokenCName))\r
e8a47801
LG
3861 if (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) in self._PcdComments:\r
3862 PcdCommentList = self._PcdComments[Pcd.TokenSpaceGuidCName, Pcd.TokenCName][:]\r
3863 if HiiInfo:\r
3864 UsageIndex = -1\r
97fa0ee9 3865 UsageStr = ''\r
e8a47801
LG
3866 for Index, Comment in enumerate(PcdCommentList):\r
3867 for Usage in UsageList:\r
3868 if Comment.find(Usage) != -1:\r
97fa0ee9 3869 UsageStr = Usage\r
e8a47801
LG
3870 UsageIndex = Index\r
3871 break\r
3872 if UsageIndex != -1:\r
97fa0ee9 3873 PcdCommentList[UsageIndex] = '## %s %s %s' % (UsageStr, HiiInfo, PcdCommentList[UsageIndex].replace(UsageStr, '')) \r
e8a47801 3874 else:\r
97fa0ee9 3875 PcdCommentList.append('## UNDEFINED ' + HiiInfo)\r
e8a47801 3876 PcdComments = '\n '.join(PcdCommentList)\r
2a29017e 3877 PcdEntry = Pcd.TokenSpaceGuidCName + '.' + TokenCName\r
e8a47801
LG
3878 if PcdComments:\r
3879 PcdEntry = PcdComments + '\n ' + PcdEntry\r
3880 AsBuiltInfDict['pcd_item'] += [PcdEntry]\r
da92f276 3881 for Item in self.BuildOption:\r
481252bb
YZ
3882 if 'FLAGS' in self.BuildOption[Item]:\r
3883 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
3884\r
3885 # Generated LibraryClasses section in comments.\r
3886 for Library in self.LibraryAutoGenList:\r
3887 AsBuiltInfDict['libraryclasses_item'] += [Library.MetaFile.File.replace('\\', '/')]\r
3888 \r
3889 # Generated depex expression section in comments.\r
3890 AsBuiltInfDict['depexsection_item'] = ''\r
3891 DepexExpresion = self._GetDepexExpresionString()\r
3892 if DepexExpresion:\r
3893 AsBuiltInfDict['depexsection_item'] = DepexExpresion\r
da92f276
LG
3894 \r
3895 AsBuiltInf = TemplateString()\r
3896 AsBuiltInf.Append(gAsBuiltInfHeaderString.Replace(AsBuiltInfDict))\r
3897 \r
3898 SaveFileOnChange(os.path.join(self.OutputDir, self.Name + '.inf'), str(AsBuiltInf), False)\r
3899 \r
3900 self.IsAsBuiltInfCreated = True\r
3901 \r
52302d4d
LG
3902 ## Create makefile for the module and its dependent libraries\r
3903 #\r
3904 # @param CreateLibraryMakeFile Flag indicating if or not the makefiles of\r
3905 # dependent libraries will be created\r
3906 #\r
3907 def CreateMakeFile(self, CreateLibraryMakeFile=True):\r
fae62ff2 3908 # Ignore generating makefile when it is a binary module\r
a0a2cd1e
FB
3909 if self.IsBinaryModule:\r
3910 return\r
fae62ff2 3911\r
52302d4d
LG
3912 if self.IsMakeFileCreated:\r
3913 return\r
3914\r
3915 if not self.IsLibrary and CreateLibraryMakeFile:\r
3916 for LibraryAutoGen in self.LibraryAutoGenList:\r
3917 LibraryAutoGen.CreateMakeFile()\r
3918\r
3919 if len(self.CustomMakefile) == 0:\r
3920 Makefile = GenMake.ModuleMakefile(self)\r
3921 else:\r
3922 Makefile = GenMake.CustomMakefile(self)\r
3923 if Makefile.Generate():\r
3924 EdkLogger.debug(EdkLogger.DEBUG_9, "Generated makefile for module %s [%s]" %\r
3925 (self.Name, self.Arch))\r
3926 else:\r
3927 EdkLogger.debug(EdkLogger.DEBUG_9, "Skipped the generation of makefile for module %s [%s]" %\r
3928 (self.Name, self.Arch))\r
3929\r
3930 self.IsMakeFileCreated = True\r
3931\r
a0a2cd1e
FB
3932 def CopyBinaryFiles(self):\r
3933 for File in self.Module.Binaries:\r
3934 SrcPath = File.Path\r
3935 DstPath = os.path.join(self.OutputDir , os.path.basename(SrcPath))\r
3936 CopyLongFilePath(SrcPath, DstPath)\r
52302d4d
LG
3937 ## Create autogen code for the module and its dependent libraries\r
3938 #\r
3939 # @param CreateLibraryCodeFile Flag indicating if or not the code of\r
3940 # dependent libraries will be created\r
3941 #\r
3942 def CreateCodeFile(self, CreateLibraryCodeFile=True):\r
3943 if self.IsCodeFileCreated:\r
3944 return\r
3945\r
e8a47801
LG
3946 # Need to generate PcdDatabase even PcdDriver is binarymodule\r
3947 if self.IsBinaryModule and self.PcdIsDriver != '':\r
3948 CreatePcdDatabaseCode(self, TemplateString(), TemplateString())\r
3949 return\r
a0a2cd1e 3950 if self.IsBinaryModule:\r
49d9b71d
HC
3951 if self.IsLibrary:\r
3952 self.CopyBinaryFiles()\r
a0a2cd1e 3953 return\r
e8a47801 3954\r
52302d4d
LG
3955 if not self.IsLibrary and CreateLibraryCodeFile:\r
3956 for LibraryAutoGen in self.LibraryAutoGenList:\r
3957 LibraryAutoGen.CreateCodeFile()\r
3958\r
3959 AutoGenList = []\r
3960 IgoredAutoGenList = []\r
3961\r
3962 for File in self.AutoGenFileList:\r
3963 if GenC.Generate(File.Path, self.AutoGenFileList[File], File.IsBinary):\r
b36d134f 3964 #Ignore Edk AutoGen.c\r
52302d4d
LG
3965 if self.AutoGenVersion < 0x00010005 and File.Name == 'AutoGen.c':\r
3966 continue\r
3967\r
3968 AutoGenList.append(str(File))\r
3969 else:\r
3970 IgoredAutoGenList.append(str(File))\r
3971\r
3972 # Skip the following code for EDK I inf\r
3973 if self.AutoGenVersion < 0x00010005:\r
3974 return\r
3975\r
3976 for ModuleType in self.DepexList:\r
40d841f6
LG
3977 # Ignore empty [depex] section or [depex] section for "USER_DEFINED" module\r
3978 if len(self.DepexList[ModuleType]) == 0 or ModuleType == "USER_DEFINED":\r
52302d4d 3979 continue\r
40d841f6 3980\r
52302d4d
LG
3981 Dpx = GenDepex.DependencyExpression(self.DepexList[ModuleType], ModuleType, True)\r
3982 DpxFile = gAutoGenDepexFileName % {"module_name" : self.Name}\r
3983\r
da92f276 3984 if len(Dpx.PostfixNotation) <> 0:\r
0d2711a6 3985 self.DepexGenerated = True\r
da92f276 3986\r
52302d4d
LG
3987 if Dpx.Generate(path.join(self.OutputDir, DpxFile)):\r
3988 AutoGenList.append(str(DpxFile))\r
3989 else:\r
3990 IgoredAutoGenList.append(str(DpxFile))\r
3991\r
3992 if IgoredAutoGenList == []:\r
3993 EdkLogger.debug(EdkLogger.DEBUG_9, "Generated [%s] files for module %s [%s]" %\r
3994 (" ".join(AutoGenList), self.Name, self.Arch))\r
3995 elif AutoGenList == []:\r
3996 EdkLogger.debug(EdkLogger.DEBUG_9, "Skipped the generation of [%s] files for module %s [%s]" %\r
3997 (" ".join(IgoredAutoGenList), self.Name, self.Arch))\r
3998 else:\r
3999 EdkLogger.debug(EdkLogger.DEBUG_9, "Generated [%s] (skipped %s) files for module %s [%s]" %\r
4000 (" ".join(AutoGenList), " ".join(IgoredAutoGenList), self.Name, self.Arch))\r
4001\r
4002 self.IsCodeFileCreated = True\r
4003 return AutoGenList\r
4004\r
4005 ## Summarize the ModuleAutoGen objects of all libraries used by this module\r
4006 def _GetLibraryAutoGenList(self):\r
4007 if self._LibraryAutoGenList == None:\r
4008 self._LibraryAutoGenList = []\r
4009 for Library in self.DependentLibraryList:\r
4010 La = ModuleAutoGen(\r
4011 self.Workspace,\r
4012 Library.MetaFile,\r
4013 self.BuildTarget,\r
4014 self.ToolChain,\r
4015 self.Arch,\r
4016 self.PlatformInfo.MetaFile\r
4017 )\r
4018 if La not in self._LibraryAutoGenList:\r
4019 self._LibraryAutoGenList.append(La)\r
4020 for Lib in La.CodaTargetList:\r
4021 self._ApplyBuildRule(Lib.Target, TAB_UNKNOWN_FILE)\r
4022 return self._LibraryAutoGenList\r
4023\r
52302d4d
LG
4024 Module = property(_GetModule)\r
4025 Name = property(_GetBaseName)\r
4026 Guid = property(_GetGuid)\r
4027 Version = property(_GetVersion)\r
4028 ModuleType = property(_GetModuleType)\r
4029 ComponentType = property(_GetComponentType)\r
4030 BuildType = property(_GetBuildType)\r
4031 PcdIsDriver = property(_GetPcdIsDriver)\r
4032 AutoGenVersion = property(_GetAutoGenVersion)\r
4033 Macros = property(_GetMacros)\r
4034 Specification = property(_GetSpecification)\r
4035\r
4036 IsLibrary = property(_IsLibrary)\r
e8a47801 4037 IsBinaryModule = property(_IsBinaryModule)\r
52302d4d
LG
4038 BuildDir = property(_GetBuildDir)\r
4039 OutputDir = property(_GetOutputDir)\r
4040 DebugDir = property(_GetDebugDir)\r
4041 MakeFileDir = property(_GetMakeFileDir)\r
4042 CustomMakefile = property(_GetCustomMakefile)\r
4043\r
4044 IncludePathList = property(_GetIncludePathList)\r
725cdb8f 4045 IncludePathLength = property(_GetIncludePathLength)\r
52302d4d
LG
4046 AutoGenFileList = property(_GetAutoGenFileList)\r
4047 UnicodeFileList = property(_GetUnicodeFileList)\r
4048 SourceFileList = property(_GetSourceFileList)\r
4049 BinaryFileList = property(_GetBinaryFiles) # FileType : [File List]\r
4050 Targets = property(_GetTargets)\r
4051 IntroTargetList = property(_GetIntroTargetList)\r
4052 CodaTargetList = property(_GetFinalTargetList)\r
4053 FileTypes = property(_GetFileTypes)\r
4054 BuildRules = property(_GetBuildRules)\r
4055\r
4056 DependentPackageList = property(_GetDependentPackageList)\r
4057 DependentLibraryList = property(_GetLibraryList)\r
4058 LibraryAutoGenList = property(_GetLibraryAutoGenList)\r
4059 DerivedPackageList = property(_GetDerivedPackageList)\r
4060\r
4061 ModulePcdList = property(_GetModulePcdList)\r
4062 LibraryPcdList = property(_GetLibraryPcdList)\r
4063 GuidList = property(_GetGuidList)\r
4064 ProtocolList = property(_GetProtocolList)\r
4065 PpiList = property(_GetPpiList)\r
4066 DepexList = property(_GetDepexTokenList)\r
b36d134f 4067 DxsFile = property(_GetDxsFile)\r
52302d4d
LG
4068 DepexExpressionList = property(_GetDepexExpressionTokenList)\r
4069 BuildOption = property(_GetModuleBuildOption)\r
79b74a03 4070 BuildOptionIncPathList = property(_GetBuildOptionIncPathList)\r
52302d4d 4071 BuildCommand = property(_GetBuildCommand)\r
2bc3256c
LG
4072 \r
4073 FixedAtBuildPcds = property(_GetFixedAtBuildPcds)\r
52302d4d
LG
4074\r
4075# This acts like the main() function for the script, unless it is 'import'ed into another script.\r
4076if __name__ == '__main__':\r
4077 pass\r
4078\r