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