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