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