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