New EdkShell binaries.
[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
e8a47801 4# Copyright (c) 2007 - 2013, 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
16import os\r
17import re\r
18import os.path as path\r
19import copy\r
20\r
21import GenC\r
22import GenMake\r
23import GenDepex\r
24from StringIO import StringIO\r
25\r
26from StrGather import *\r
27from BuildEngine import BuildRule\r
28\r
29from Common.BuildToolError import *\r
30from Common.DataType import *\r
31from Common.Misc import *\r
32from Common.String import *\r
33import Common.GlobalData as GlobalData\r
34from GenFds.FdfParser import *\r
35from CommonDataClass.CommonClass import SkuInfoClass\r
36from Workspace.BuildClassObject import *\r
e8a47801 37from GenPatchPcdTable.GenPatchPcdTable import parsePcdInfoFromMapFile\r
e56468c0 38import Common.VpdInfoFile as VpdInfoFile\r
e8a47801
LG
39from GenPcdDb import CreatePcdDatabaseCode\r
40from Workspace.MetaFileCommentParser import UsageList\r
52302d4d 41\r
e8a47801 42## Regular expression for splitting Dependency Expression string into tokens\r
52302d4d
LG
43gDepexTokenPattern = re.compile("(\(|\)|\w+| \S+\.inf)")\r
44\r
45## Mapping Makefile type\r
46gMakeTypeMap = {"MSFT":"nmake", "GCC":"gmake"}\r
47\r
48\r
49## Build rule configuration file\r
50gBuildRuleFile = 'Conf/build_rule.txt'\r
51\r
64b2609f
LG
52## Build rule default version\r
53AutoGenReqBuildRuleVerNum = "0.1"\r
54\r
52302d4d
LG
55## default file name for AutoGen\r
56gAutoGenCodeFileName = "AutoGen.c"\r
57gAutoGenHeaderFileName = "AutoGen.h"\r
58gAutoGenStringFileName = "%(module_name)sStrDefs.h"\r
59gAutoGenStringFormFileName = "%(module_name)sStrDefs.hpk"\r
60gAutoGenDepexFileName = "%(module_name)s.depex"\r
61\r
da92f276
LG
62#\r
63# Template string to generic AsBuilt INF\r
64#\r
e8a47801 65gAsBuiltInfHeaderString = TemplateString("""${header_comments}\r
da92f276
LG
66\r
67[Defines]\r
68 INF_VERSION = 0x00010016\r
69 BASE_NAME = ${module_name}\r
70 FILE_GUID = ${module_guid}\r
71 MODULE_TYPE = ${module_module_type}\r
72 VERSION_STRING = ${module_version_string}${BEGIN}\r
e8a47801 73 PCD_IS_DRIVER = ${pcd_is_driver_string}${END}${BEGIN}\r
da92f276
LG
74 UEFI_SPECIFICATION_VERSION = ${module_uefi_specification_version}${END}${BEGIN}\r
75 PI_SPECIFICATION_VERSION = ${module_pi_specification_version}${END}\r
76\r
77[Packages]${BEGIN}\r
78 ${package_item}${END}\r
79\r
80[Binaries.${module_arch}]${BEGIN}\r
81 ${binary_item}${END}\r
82\r
e8a47801
LG
83[PatchPcd.${module_arch}]${BEGIN}\r
84 ${patchablepcd_item}\r
85${END}\r
86[Protocols.${module_arch}]${BEGIN}\r
87 ${protocol_item}\r
88${END}\r
89[Ppis.${module_arch}]${BEGIN}\r
90 ${ppi_item}\r
91${END}\r
92[Guids.${module_arch}]${BEGIN}\r
93 ${guid_item}\r
94${END}\r
95[PcdEx.${module_arch}]${BEGIN}\r
96 ${pcd_item}\r
97${END}\r
da92f276
LG
98\r
99## @AsBuilt${BEGIN}\r
100## ${flags_item}${END}\r
101""")\r
102\r
52302d4d
LG
103## Base class for AutoGen\r
104#\r
105# This class just implements the cache mechanism of AutoGen objects.\r
106#\r
107class AutoGen(object):\r
108 # database to maintain the objects of xxxAutoGen\r
109 _CACHE_ = {} # (BuildTarget, ToolChain) : {ARCH : {platform file: AutoGen object}}}\r
110\r
111 ## Factory method\r
112 #\r
113 # @param Class class object of real AutoGen class\r
114 # (WorkspaceAutoGen, ModuleAutoGen or PlatformAutoGen)\r
115 # @param Workspace Workspace directory or WorkspaceAutoGen object\r
116 # @param MetaFile The path of meta file\r
117 # @param Target Build target\r
118 # @param Toolchain Tool chain name\r
119 # @param Arch Target arch\r
120 # @param *args The specific class related parameters\r
121 # @param **kwargs The specific class related dict parameters\r
122 #\r
123 def __new__(Class, Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs):\r
124 # check if the object has been created\r
125 Key = (Target, Toolchain)\r
126 if Key not in Class._CACHE_ or Arch not in Class._CACHE_[Key] \\r
127 or MetaFile not in Class._CACHE_[Key][Arch]:\r
128 AutoGenObject = super(AutoGen, Class).__new__(Class)\r
129 # call real constructor\r
130 if not AutoGenObject._Init(Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs):\r
131 return None\r
132 if Key not in Class._CACHE_:\r
133 Class._CACHE_[Key] = {}\r
134 if Arch not in Class._CACHE_[Key]:\r
135 Class._CACHE_[Key][Arch] = {}\r
136 Class._CACHE_[Key][Arch][MetaFile] = AutoGenObject\r
137 else:\r
138 AutoGenObject = Class._CACHE_[Key][Arch][MetaFile]\r
139\r
140 return AutoGenObject\r
141\r
142 ## hash() operator\r
143 #\r
144 # The file path of platform file will be used to represent hash value of this object\r
145 #\r
146 # @retval int Hash value of the file path of platform file\r
147 #\r
148 def __hash__(self):\r
149 return hash(self.MetaFile)\r
150\r
151 ## str() operator\r
152 #\r
153 # The file path of platform file will be used to represent this object\r
154 #\r
155 # @retval string String of platform file path\r
156 #\r
157 def __str__(self):\r
158 return str(self.MetaFile)\r
159\r
160 ## "==" operator\r
161 def __eq__(self, Other):\r
162 return Other and self.MetaFile == Other\r
163\r
164## Workspace AutoGen class\r
165#\r
166# This class is used mainly to control the whole platform build for different\r
167# architecture. This class will generate top level makefile.\r
168#\r
169class WorkspaceAutoGen(AutoGen):\r
170 ## Real constructor of WorkspaceAutoGen\r
171 #\r
79b74a03 172 # This method behaves the same as __init__ except that it needs explicit invoke\r
52302d4d
LG
173 # (in super class's __new__ method)\r
174 #\r
175 # @param WorkspaceDir Root directory of workspace\r
176 # @param ActivePlatform Meta-file of active platform\r
177 # @param Target Build target\r
178 # @param Toolchain Tool chain name\r
179 # @param ArchList List of architecture of current build\r
180 # @param MetaFileDb Database containing meta-files\r
181 # @param BuildConfig Configuration of build\r
182 # @param ToolDefinition Tool chain definitions\r
183 # @param FlashDefinitionFile File of flash definition\r
184 # @param Fds FD list to be generated\r
185 # @param Fvs FV list to be generated\r
4234283c 186 # @param Caps Capsule list to be generated\r
52302d4d
LG
187 # @param SkuId SKU id from command line\r
188 #\r
189 def _Init(self, WorkspaceDir, ActivePlatform, Target, Toolchain, ArchList, MetaFileDb,\r
9508d0fa
LG
190 BuildConfig, ToolDefinition, FlashDefinitionFile='', Fds=None, Fvs=None, Caps=None, SkuId='', UniFlag=None, \r
191 Progress=None, BuildModule=None):\r
4234283c
LG
192 if Fds is None:\r
193 Fds = []\r
194 if Fvs is None:\r
195 Fvs = []\r
196 if Caps is None:\r
197 Caps = []\r
0d2711a6
LG
198 self.BuildDatabase = MetaFileDb\r
199 self.MetaFile = ActivePlatform\r
52302d4d 200 self.WorkspaceDir = WorkspaceDir\r
0d2711a6 201 self.Platform = self.BuildDatabase[self.MetaFile, 'COMMON', Target, Toolchain]\r
d0acc87a 202 GlobalData.gActivePlatform = self.Platform\r
52302d4d
LG
203 self.BuildTarget = Target\r
204 self.ToolChain = Toolchain\r
205 self.ArchList = ArchList\r
206 self.SkuId = SkuId\r
f3decdc3 207 self.UniFlag = UniFlag\r
52302d4d 208\r
52302d4d
LG
209 self.TargetTxt = BuildConfig\r
210 self.ToolDef = ToolDefinition\r
211 self.FdfFile = FlashDefinitionFile\r
212 self.FdTargetList = Fds\r
213 self.FvTargetList = Fvs\r
4234283c 214 self.CapTargetList = Caps\r
52302d4d
LG
215 self.AutoGenObjectList = []\r
216\r
217 # there's many relative directory operations, so ...\r
218 os.chdir(self.WorkspaceDir)\r
219\r
0d2711a6
LG
220 #\r
221 # Merge Arch\r
222 #\r
223 if not self.ArchList:\r
224 ArchList = set(self.Platform.SupArchList)\r
225 else:\r
226 ArchList = set(self.ArchList) & set(self.Platform.SupArchList)\r
227 if not ArchList:\r
228 EdkLogger.error("build", PARAMETER_INVALID,\r
229 ExtraData = "Invalid ARCH specified. [Valid ARCH: %s]" % (" ".join(self.Platform.SupArchList)))\r
230 elif self.ArchList and len(ArchList) != len(self.ArchList):\r
231 SkippedArchList = set(self.ArchList).symmetric_difference(set(self.Platform.SupArchList))\r
232 EdkLogger.verbose("\nArch [%s] is ignored because the platform supports [%s] only!"\r
233 % (" ".join(SkippedArchList), " ".join(self.Platform.SupArchList)))\r
234 self.ArchList = tuple(ArchList)\r
235\r
236 # Validate build target\r
237 if self.BuildTarget not in self.Platform.BuildTargets:\r
238 EdkLogger.error("build", PARAMETER_INVALID, \r
239 ExtraData="Build target [%s] is not supported by the platform. [Valid target: %s]"\r
240 % (self.BuildTarget, " ".join(self.Platform.BuildTargets)))\r
241\r
52302d4d 242 # parse FDF file to get PCDs in it, if any\r
0d2711a6
LG
243 if not self.FdfFile:\r
244 self.FdfFile = self.Platform.FlashDefinition\r
9508d0fa
LG
245 \r
246 EdkLogger.info("")\r
247 if self.ArchList:\r
248 EdkLogger.info('%-16s = %s' % ("Architecture(s)", ' '.join(self.ArchList)))\r
249 EdkLogger.info('%-16s = %s' % ("Build target", self.BuildTarget))\r
250 EdkLogger.info('%-16s = %s' % ("Toolchain",self.ToolChain)) \r
251 \r
252 EdkLogger.info('\n%-24s = %s' % ("Active Platform", self.Platform))\r
253 if BuildModule:\r
254 EdkLogger.info('%-24s = %s' % ("Active Module", BuildModule))\r
255 \r
256 if self.FdfFile:\r
257 EdkLogger.info('%-24s = %s' % ("Flash Image Definition", self.FdfFile))\r
0d2711a6 258\r
9508d0fa
LG
259 EdkLogger.verbose("\nFLASH_DEFINITION = %s" % self.FdfFile)\r
260 \r
261 if Progress:\r
262 Progress.Start("\nProcessing meta-data")\r
263 \r
0d2711a6 264 if self.FdfFile:\r
df692f02
LG
265 #\r
266 # Mark now build in AutoGen Phase\r
267 #\r
0d2711a6 268 GlobalData.gAutoGenPhase = True \r
52302d4d
LG
269 Fdf = FdfParser(self.FdfFile.Path)\r
270 Fdf.ParseFile()\r
0d2711a6 271 GlobalData.gAutoGenPhase = False\r
52302d4d
LG
272 PcdSet = Fdf.Profile.PcdDict\r
273 ModuleList = Fdf.Profile.InfList\r
274 self.FdfProfile = Fdf.Profile\r
0d2711a6
LG
275 for fvname in self.FvTargetList:\r
276 if fvname.upper() not in self.FdfProfile.FvDict:\r
277 EdkLogger.error("build", OPTION_VALUE_INVALID,\r
278 "No such an FV in FDF file: %s" % fvname)\r
52302d4d
LG
279 else:\r
280 PcdSet = {}\r
281 ModuleList = []\r
282 self.FdfProfile = None\r
0d2711a6
LG
283 if self.FdTargetList:\r
284 EdkLogger.info("No flash definition file found. FD [%s] will be ignored." % " ".join(self.FdTargetList))\r
285 self.FdTargetList = []\r
286 if self.FvTargetList:\r
287 EdkLogger.info("No flash definition file found. FV [%s] will be ignored." % " ".join(self.FvTargetList))\r
288 self.FvTargetList = []\r
289 if self.CapTargetList:\r
290 EdkLogger.info("No flash definition file found. Capsule [%s] will be ignored." % " ".join(self.CapTargetList))\r
291 self.CapTargetList = []\r
52302d4d
LG
292 \r
293 # apply SKU and inject PCDs from Flash Definition file\r
294 for Arch in self.ArchList:\r
0d2711a6 295 Platform = self.BuildDatabase[self.MetaFile, Arch, Target, Toolchain]\r
64b2609f 296\r
25918452 297 DecPcds = {}\r
4afd3d04 298 DecPcdsKey = set()\r
64b2609f
LG
299 PGen = PlatformAutoGen(self, self.MetaFile, Target, Toolchain, Arch)\r
300 Pkgs = PGen.PackageList\r
301 for Pkg in Pkgs:\r
25918452
LG
302 for Pcd in Pkg.Pcds:\r
303 DecPcds[Pcd[0], Pcd[1]] = Pkg.Pcds[Pcd]\r
4afd3d04 304 DecPcdsKey.add((Pcd[0], Pcd[1], Pcd[2]))\r
64b2609f 305\r
52302d4d
LG
306 Platform.SkuName = self.SkuId\r
307 for Name, Guid in PcdSet:\r
64b2609f
LG
308 if (Name, Guid) not in DecPcds:\r
309 EdkLogger.error(\r
310 'build',\r
311 PARSER_ERROR,\r
312 "PCD (%s.%s) used in FDF is not declared in DEC files." % (Guid, Name),\r
313 File = self.FdfProfile.PcdFileLineDict[Name, Guid][0],\r
314 Line = self.FdfProfile.PcdFileLineDict[Name, Guid][1]\r
315 )\r
4afd3d04
LG
316 else:\r
317 # Check whether Dynamic or DynamicEx PCD used in FDF file. If used, build break and give a error message.\r
318 if (Name, Guid, TAB_PCDS_FIXED_AT_BUILD) in DecPcdsKey \\r
319 or (Name, Guid, TAB_PCDS_PATCHABLE_IN_MODULE) in DecPcdsKey \\r
320 or (Name, Guid, TAB_PCDS_FEATURE_FLAG) in DecPcdsKey:\r
321 Platform.AddPcd(Name, Guid, PcdSet[Name, Guid])\r
322 continue\r
323 elif (Name, Guid, TAB_PCDS_DYNAMIC) in DecPcdsKey or (Name, Guid, TAB_PCDS_DYNAMIC_EX) in DecPcdsKey:\r
324 EdkLogger.error(\r
325 'build',\r
326 PARSER_ERROR,\r
327 "Using Dynamic or DynamicEx type of PCD [%s.%s] in FDF file is not allowed." % (Guid, Name),\r
328 File = self.FdfProfile.PcdFileLineDict[Name, Guid][0],\r
329 Line = self.FdfProfile.PcdFileLineDict[Name, Guid][1]\r
330 )\r
52302d4d
LG
331\r
332 Pa = PlatformAutoGen(self, self.MetaFile, Target, Toolchain, Arch)\r
333 #\r
334 # Explicitly collect platform's dynamic PCDs\r
335 #\r
336 Pa.CollectPlatformDynamicPcds()\r
337 self.AutoGenObjectList.append(Pa)\r
6780eef1
LG
338 \r
339 #\r
340 # Check PCDs token value conflict in each DEC file.\r
341 #\r
342 self._CheckAllPcdsTokenValueConflict()\r
343 \r
4234283c
LG
344 #\r
345 # Check PCD type and definition between DSC and DEC\r
346 #\r
347 self._CheckPcdDefineAndType()\r
348 \r
79b74a03
LG
349 if self.FdfFile:\r
350 self._CheckDuplicateInFV(Fdf)\r
351 \r
52302d4d
LG
352 self._BuildDir = None\r
353 self._FvDir = None\r
354 self._MakeFileDir = None\r
355 self._BuildCommand = None\r
356\r
357 return True\r
358\r
79b74a03
LG
359 ## _CheckDuplicateInFV() method\r
360 #\r
361 # Check whether there is duplicate modules/files exist in FV section. \r
362 # The check base on the file GUID;\r
363 #\r
364 def _CheckDuplicateInFV(self, Fdf):\r
365 for Fv in Fdf.Profile.FvDict:\r
366 _GuidDict = {}\r
367 for FfsFile in Fdf.Profile.FvDict[Fv].FfsList:\r
368 if FfsFile.InfFileName and FfsFile.NameGuid == None:\r
369 #\r
370 # Get INF file GUID\r
371 #\r
372 InfFoundFlag = False \r
373 for Pa in self.AutoGenObjectList:\r
64b2609f
LG
374 if InfFoundFlag:\r
375 break\r
79b74a03
LG
376 for Module in Pa.ModuleAutoGenList:\r
377 if path.normpath(Module.MetaFile.File) == path.normpath(FfsFile.InfFileName):\r
378 InfFoundFlag = True\r
379 if not Module.Guid.upper() in _GuidDict.keys():\r
380 _GuidDict[Module.Guid.upper()] = FfsFile\r
64b2609f 381 break\r
79b74a03
LG
382 else:\r
383 EdkLogger.error("build", \r
384 FORMAT_INVALID,\r
385 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s"%(FfsFile.CurrentLineNum,\r
386 FfsFile.CurrentLineContent,\r
387 _GuidDict[Module.Guid.upper()].CurrentLineNum,\r
388 _GuidDict[Module.Guid.upper()].CurrentLineContent,\r
389 Module.Guid.upper()),\r
390 ExtraData=self.FdfFile)\r
391 #\r
392 # Some INF files not have entity in DSC file. \r
393 #\r
394 if not InfFoundFlag:\r
395 if FfsFile.InfFileName.find('$') == -1:\r
396 InfPath = NormPath(FfsFile.InfFileName)\r
397 if not os.path.exists(InfPath):\r
398 EdkLogger.error('build', GENFDS_ERROR, "Non-existant Module %s !" % (FfsFile.InfFileName))\r
399 \r
400 PathClassObj = PathClass(FfsFile.InfFileName, self.WorkspaceDir)\r
401 #\r
402 # Here we just need to get FILE_GUID from INF file, use 'COMMON' as ARCH attribute. and use \r
403 # BuildObject from one of AutoGenObjectList is enough.\r
404 #\r
405 InfObj = self.AutoGenObjectList[0].BuildDatabase.WorkspaceDb.BuildObject[PathClassObj, 'COMMON', self.BuildTarget, self.ToolChain]\r
406 if not InfObj.Guid.upper() in _GuidDict.keys():\r
407 _GuidDict[InfObj.Guid.upper()] = FfsFile\r
408 else:\r
409 EdkLogger.error("build", \r
410 FORMAT_INVALID,\r
411 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s"%(FfsFile.CurrentLineNum,\r
412 FfsFile.CurrentLineContent,\r
413 _GuidDict[InfObj.Guid.upper()].CurrentLineNum,\r
414 _GuidDict[InfObj.Guid.upper()].CurrentLineContent,\r
415 InfObj.Guid.upper()),\r
416 ExtraData=self.FdfFile)\r
417 InfFoundFlag = False\r
418 \r
419 if FfsFile.NameGuid != None:\r
420 _CheckPCDAsGuidPattern = re.compile("^PCD\(.+\..+\)$")\r
421 \r
422 #\r
423 # If the NameGuid reference a PCD name. \r
424 # The style must match: PCD(xxxx.yyy)\r
425 #\r
426 if _CheckPCDAsGuidPattern.match(FfsFile.NameGuid):\r
427 #\r
428 # Replace the PCD value.\r
429 #\r
430 _PcdName = FfsFile.NameGuid.lstrip("PCD(").rstrip(")")\r
431 PcdFoundFlag = False\r
432 for Pa in self.AutoGenObjectList:\r
433 if not PcdFoundFlag:\r
434 for PcdItem in Pa.AllPcdList:\r
435 if (PcdItem.TokenSpaceGuidCName + "." + PcdItem.TokenCName) == _PcdName:\r
436 #\r
437 # First convert from CFormatGuid to GUID string\r
438 #\r
439 _PcdGuidString = GuidStructureStringToGuidString(PcdItem.DefaultValue)\r
440 \r
441 if not _PcdGuidString:\r
442 #\r
443 # Then try Byte array.\r
444 #\r
445 _PcdGuidString = GuidStructureByteArrayToGuidString(PcdItem.DefaultValue)\r
446 \r
447 if not _PcdGuidString:\r
448 #\r
449 # Not Byte array or CFormat GUID, raise error.\r
450 #\r
451 EdkLogger.error("build",\r
452 FORMAT_INVALID,\r
453 "The format of PCD value is incorrect. PCD: %s , Value: %s\n"%(_PcdName, PcdItem.DefaultValue),\r
454 ExtraData=self.FdfFile)\r
455 \r
456 if not _PcdGuidString.upper() in _GuidDict.keys(): \r
457 _GuidDict[_PcdGuidString.upper()] = FfsFile\r
458 PcdFoundFlag = True\r
459 break\r
460 else:\r
461 EdkLogger.error("build", \r
462 FORMAT_INVALID,\r
463 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s"%(FfsFile.CurrentLineNum,\r
464 FfsFile.CurrentLineContent,\r
465 _GuidDict[_PcdGuidString.upper()].CurrentLineNum,\r
466 _GuidDict[_PcdGuidString.upper()].CurrentLineContent,\r
467 FfsFile.NameGuid.upper()),\r
468 ExtraData=self.FdfFile) \r
469 \r
470 if not FfsFile.NameGuid.upper() in _GuidDict.keys():\r
471 _GuidDict[FfsFile.NameGuid.upper()] = FfsFile\r
472 else:\r
473 #\r
474 # Two raw file GUID conflict.\r
475 #\r
476 EdkLogger.error("build", \r
477 FORMAT_INVALID,\r
478 "Duplicate GUID found for these lines: Line %d: %s and Line %d: %s. GUID: %s"%(FfsFile.CurrentLineNum,\r
479 FfsFile.CurrentLineContent,\r
480 _GuidDict[FfsFile.NameGuid.upper()].CurrentLineNum,\r
481 _GuidDict[FfsFile.NameGuid.upper()].CurrentLineContent,\r
482 FfsFile.NameGuid.upper()),\r
483 ExtraData=self.FdfFile)\r
484 \r
485\r
4234283c
LG
486 def _CheckPcdDefineAndType(self):\r
487 PcdTypeList = [\r
488 "FixedAtBuild", "PatchableInModule", "FeatureFlag",\r
489 "Dynamic", #"DynamicHii", "DynamicVpd",\r
490 "DynamicEx", # "DynamicExHii", "DynamicExVpd"\r
491 ]\r
492\r
493 # This dict store PCDs which are not used by any modules with specified arches\r
494 UnusedPcd = sdict()\r
495 for Pa in self.AutoGenObjectList:\r
496 # Key of DSC's Pcds dictionary is PcdCName, TokenSpaceGuid\r
497 for Pcd in Pa.Platform.Pcds:\r
498 PcdType = Pa.Platform.Pcds[Pcd].Type\r
499 \r
500 # If no PCD type, this PCD comes from FDF \r
501 if not PcdType:\r
502 continue\r
503 \r
504 # Try to remove Hii and Vpd suffix\r
505 if PcdType.startswith("DynamicEx"):\r
506 PcdType = "DynamicEx"\r
507 elif PcdType.startswith("Dynamic"):\r
508 PcdType = "Dynamic"\r
509 \r
510 for Package in Pa.PackageList:\r
511 # Key of DEC's Pcds dictionary is PcdCName, TokenSpaceGuid, PcdType\r
512 if (Pcd[0], Pcd[1], PcdType) in Package.Pcds:\r
513 break\r
514 for Type in PcdTypeList:\r
515 if (Pcd[0], Pcd[1], Type) in Package.Pcds:\r
516 EdkLogger.error(\r
517 'build',\r
518 FORMAT_INVALID,\r
519 "Type [%s] of PCD [%s.%s] in DSC file doesn't match the type [%s] defined in DEC file." \\r
520 % (Pa.Platform.Pcds[Pcd].Type, Pcd[1], Pcd[0], Type),\r
521 ExtraData=None\r
522 )\r
523 return\r
524 else:\r
525 UnusedPcd.setdefault(Pcd, []).append(Pa.Arch)\r
526\r
527 for Pcd in UnusedPcd:\r
528 EdkLogger.warn(\r
529 'build',\r
530 "The PCD was not specified by any INF module in the platform for the given architecture.\n"\r
531 "\tPCD: [%s.%s]\n\tPlatform: [%s]\n\tArch: %s"\r
532 % (Pcd[1], Pcd[0], os.path.basename(str(self.MetaFile)), str(UnusedPcd[Pcd])),\r
533 ExtraData=None\r
534 )\r
535\r
52302d4d
LG
536 def __repr__(self):\r
537 return "%s [%s]" % (self.MetaFile, ", ".join(self.ArchList))\r
538\r
539 ## Return the directory to store FV files\r
540 def _GetFvDir(self):\r
541 if self._FvDir == None:\r
542 self._FvDir = path.join(self.BuildDir, 'FV')\r
543 return self._FvDir\r
544\r
545 ## Return the directory to store all intermediate and final files built\r
546 def _GetBuildDir(self):\r
547 return self.AutoGenObjectList[0].BuildDir\r
548\r
549 ## Return the build output directory platform specifies\r
550 def _GetOutputDir(self):\r
551 return self.Platform.OutputDirectory\r
552\r
553 ## Return platform name\r
554 def _GetName(self):\r
555 return self.Platform.PlatformName\r
556\r
557 ## Return meta-file GUID\r
558 def _GetGuid(self):\r
559 return self.Platform.Guid\r
560\r
561 ## Return platform version\r
562 def _GetVersion(self):\r
563 return self.Platform.Version\r
564\r
565 ## Return paths of tools\r
566 def _GetToolDefinition(self):\r
567 return self.AutoGenObjectList[0].ToolDefinition\r
568\r
569 ## Return directory of platform makefile\r
570 #\r
571 # @retval string Makefile directory\r
572 #\r
573 def _GetMakeFileDir(self):\r
574 if self._MakeFileDir == None:\r
575 self._MakeFileDir = self.BuildDir\r
576 return self._MakeFileDir\r
577\r
578 ## Return build command string\r
579 #\r
580 # @retval string Build command string\r
581 #\r
582 def _GetBuildCommand(self):\r
583 if self._BuildCommand == None:\r
584 # BuildCommand should be all the same. So just get one from platform AutoGen\r
585 self._BuildCommand = self.AutoGenObjectList[0].BuildCommand\r
586 return self._BuildCommand\r
6780eef1
LG
587 \r
588 ## Check the PCDs token value conflict in each DEC file.\r
589 #\r
590 # Will cause build break and raise error message while two PCDs conflict.\r
591 # \r
592 # @return None\r
593 #\r
594 def _CheckAllPcdsTokenValueConflict(self):\r
b36d134f
LG
595 for Pa in self.AutoGenObjectList:\r
596 for Package in Pa.PackageList:\r
6780eef1
LG
597 PcdList = Package.Pcds.values()\r
598 PcdList.sort(lambda x, y: cmp(x.TokenValue, y.TokenValue)) \r
599 Count = 0\r
600 while (Count < len(PcdList) - 1) :\r
601 Item = PcdList[Count]\r
602 ItemNext = PcdList[Count + 1]\r
603 #\r
604 # Make sure in the same token space the TokenValue should be unique\r
605 #\r
606 if (Item.TokenValue == ItemNext.TokenValue):\r
607 SameTokenValuePcdList = []\r
608 SameTokenValuePcdList.append(Item)\r
609 SameTokenValuePcdList.append(ItemNext)\r
610 RemainPcdListLength = len(PcdList) - Count - 2\r
611 for ValueSameCount in range(RemainPcdListLength):\r
612 if PcdList[len(PcdList) - RemainPcdListLength + ValueSameCount].TokenValue == Item.TokenValue:\r
613 SameTokenValuePcdList.append(PcdList[len(PcdList) - RemainPcdListLength + ValueSameCount])\r
614 else:\r
615 break;\r
616 #\r
617 # Sort same token value PCD list with TokenGuid and TokenCName\r
618 #\r
619 SameTokenValuePcdList.sort(lambda x, y: cmp("%s.%s"%(x.TokenSpaceGuidCName, x.TokenCName), "%s.%s"%(y.TokenSpaceGuidCName, y.TokenCName))) \r
620 SameTokenValuePcdListCount = 0 \r
621 while (SameTokenValuePcdListCount < len(SameTokenValuePcdList) - 1):\r
622 TemListItem = SameTokenValuePcdList[SameTokenValuePcdListCount]\r
623 TemListItemNext = SameTokenValuePcdList[SameTokenValuePcdListCount + 1] \r
624 \r
625 if (TemListItem.TokenSpaceGuidCName == TemListItemNext.TokenSpaceGuidCName) and (TemListItem.TokenCName != TemListItemNext.TokenCName):\r
626 EdkLogger.error(\r
627 'build',\r
628 FORMAT_INVALID,\r
629 "The TokenValue [%s] of PCD [%s.%s] is conflict with: [%s.%s] in %s"\\r
630 % (TemListItem.TokenValue, TemListItem.TokenSpaceGuidCName, TemListItem.TokenCName, TemListItemNext.TokenSpaceGuidCName, TemListItemNext.TokenCName, Package),\r
631 ExtraData=None\r
632 )\r
633 SameTokenValuePcdListCount += 1\r
634 Count += SameTokenValuePcdListCount\r
635 Count += 1\r
636 \r
637 PcdList = Package.Pcds.values()\r
638 PcdList.sort(lambda x, y: cmp("%s.%s"%(x.TokenSpaceGuidCName, x.TokenCName), "%s.%s"%(y.TokenSpaceGuidCName, y.TokenCName)))\r
639 Count = 0\r
640 while (Count < len(PcdList) - 1) :\r
641 Item = PcdList[Count]\r
642 ItemNext = PcdList[Count + 1] \r
643 #\r
644 # Check PCDs with same TokenSpaceGuidCName.TokenCName have same token value as well.\r
645 #\r
646 if (Item.TokenSpaceGuidCName == ItemNext.TokenSpaceGuidCName) and (Item.TokenCName == ItemNext.TokenCName) and (Item.TokenValue != ItemNext.TokenValue):\r
647 EdkLogger.error(\r
648 'build',\r
649 FORMAT_INVALID,\r
650 "The TokenValue [%s] of PCD [%s.%s] in %s defined in two places should be same as well."\\r
651 % (Item.TokenValue, Item.TokenSpaceGuidCName, Item.TokenCName, Package),\r
652 ExtraData=None\r
653 )\r
654 Count += 1\r
655 \r
52302d4d 656\r
e56468c0 657 ## Create makefile for the platform and modules in it\r
52302d4d
LG
658 #\r
659 # @param CreateDepsMakeFile Flag indicating if the makefile for\r
660 # modules will be created as well\r
661 #\r
662 def CreateMakeFile(self, CreateDepsMakeFile=False):\r
663 # create makefile for platform\r
664 Makefile = GenMake.TopLevelMakefile(self)\r
665 if Makefile.Generate():\r
666 EdkLogger.debug(EdkLogger.DEBUG_9, "Generated makefile for platform [%s] %s\n" %\r
667 (self.MetaFile, self.ArchList))\r
668 else:\r
669 EdkLogger.debug(EdkLogger.DEBUG_9, "Skipped the generation of makefile for platform [%s] %s\n" %\r
670 (self.MetaFile, self.ArchList))\r
671\r
672 if CreateDepsMakeFile:\r
673 for Pa in self.AutoGenObjectList:\r
674 Pa.CreateMakeFile(CreateDepsMakeFile)\r
675\r
676 ## Create autogen code for platform and modules\r
677 #\r
678 # Since there's no autogen code for platform, this method will do nothing\r
679 # if CreateModuleCodeFile is set to False.\r
680 #\r
681 # @param CreateDepsCodeFile Flag indicating if creating module's\r
682 # autogen code file or not\r
683 #\r
684 def CreateCodeFile(self, CreateDepsCodeFile=False):\r
685 if not CreateDepsCodeFile:\r
686 return\r
687 for Pa in self.AutoGenObjectList:\r
688 Pa.CreateCodeFile(CreateDepsCodeFile)\r
689\r
7c1fd323
LG
690 ## Create AsBuilt INF file the platform\r
691 #\r
692 def CreateAsBuiltInf(self):\r
693 return\r
694\r
52302d4d
LG
695 Name = property(_GetName)\r
696 Guid = property(_GetGuid)\r
697 Version = property(_GetVersion)\r
698 OutputDir = property(_GetOutputDir)\r
699\r
700 ToolDefinition = property(_GetToolDefinition) # toolcode : tool path\r
701\r
702 BuildDir = property(_GetBuildDir)\r
703 FvDir = property(_GetFvDir)\r
704 MakeFileDir = property(_GetMakeFileDir)\r
705 BuildCommand = property(_GetBuildCommand)\r
706\r
707## AutoGen class for platform\r
708#\r
709# PlatformAutoGen class will process the original information in platform\r
710# file in order to generate makefile for platform.\r
711#\r
712class PlatformAutoGen(AutoGen):\r
713 #\r
714 # Used to store all PCDs for both PEI and DXE phase, in order to generate \r
715 # correct PCD database\r
716 # \r
717 _DynaPcdList_ = []\r
718 _NonDynaPcdList_ = []\r
6780eef1
LG
719 \r
720 #\r
721 # The priority list while override build option \r
722 #\r
723 PrioList = {"0x11111" : 16, # TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE (Highest)\r
724 "0x01111" : 15, # ******_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE\r
725 "0x10111" : 14, # TARGET_*********_ARCH_COMMANDTYPE_ATTRIBUTE\r
726 "0x00111" : 13, # ******_*********_ARCH_COMMANDTYPE_ATTRIBUTE \r
727 "0x11011" : 12, # TARGET_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE\r
728 "0x01011" : 11, # ******_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE\r
729 "0x10011" : 10, # TARGET_*********_****_COMMANDTYPE_ATTRIBUTE\r
730 "0x00011" : 9, # ******_*********_****_COMMANDTYPE_ATTRIBUTE\r
731 "0x11101" : 8, # TARGET_TOOLCHAIN_ARCH_***********_ATTRIBUTE\r
732 "0x01101" : 7, # ******_TOOLCHAIN_ARCH_***********_ATTRIBUTE\r
733 "0x10101" : 6, # TARGET_*********_ARCH_***********_ATTRIBUTE\r
734 "0x00101" : 5, # ******_*********_ARCH_***********_ATTRIBUTE\r
735 "0x11001" : 4, # TARGET_TOOLCHAIN_****_***********_ATTRIBUTE\r
736 "0x01001" : 3, # ******_TOOLCHAIN_****_***********_ATTRIBUTE\r
737 "0x10001" : 2, # TARGET_*********_****_***********_ATTRIBUTE\r
738 "0x00001" : 1} # ******_*********_****_***********_ATTRIBUTE (Lowest)\r
739 \r
52302d4d
LG
740 ## The real constructor of PlatformAutoGen\r
741 #\r
742 # This method is not supposed to be called by users of PlatformAutoGen. It's\r
743 # only used by factory method __new__() to do real initialization work for an\r
744 # object of PlatformAutoGen\r
745 #\r
746 # @param Workspace WorkspaceAutoGen object\r
747 # @param PlatformFile Platform file (DSC file)\r
748 # @param Target Build target (DEBUG, RELEASE)\r
749 # @param Toolchain Name of tool chain\r
750 # @param Arch arch of the platform supports\r
751 #\r
752 def _Init(self, Workspace, PlatformFile, Target, Toolchain, Arch):\r
753 EdkLogger.debug(EdkLogger.DEBUG_9, "AutoGen platform [%s] [%s]" % (PlatformFile, Arch))\r
754 GlobalData.gProcessingFile = "%s [%s, %s, %s]" % (PlatformFile, Arch, Toolchain, Target)\r
755\r
756 self.MetaFile = PlatformFile\r
757 self.Workspace = Workspace\r
758 self.WorkspaceDir = Workspace.WorkspaceDir\r
759 self.ToolChain = Toolchain\r
760 self.BuildTarget = Target\r
761 self.Arch = Arch\r
762 self.SourceDir = PlatformFile.SubDir\r
763 self.SourceOverrideDir = None\r
764 self.FdTargetList = self.Workspace.FdTargetList\r
765 self.FvTargetList = self.Workspace.FvTargetList\r
766 self.AllPcdList = []\r
767\r
768 # flag indicating if the makefile/C-code file has been created or not\r
769 self.IsMakeFileCreated = False\r
770 self.IsCodeFileCreated = False\r
771\r
772 self._Platform = None\r
773 self._Name = None\r
774 self._Guid = None\r
775 self._Version = None\r
776\r
777 self._BuildRule = None\r
778 self._SourceDir = None\r
779 self._BuildDir = None\r
780 self._OutputDir = None\r
781 self._FvDir = None\r
782 self._MakeFileDir = None\r
783 self._FdfFile = None\r
784\r
785 self._PcdTokenNumber = None # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber\r
786 self._DynamicPcdList = None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]\r
787 self._NonDynamicPcdList = None # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]\r
788\r
789 self._ToolDefinitions = None\r
790 self._ToolDefFile = None # toolcode : tool path\r
791 self._ToolChainFamily = None\r
792 self._BuildRuleFamily = None\r
793 self._BuildOption = None # toolcode : option\r
794 self._EdkBuildOption = None # edktoolcode : option\r
795 self._EdkIIBuildOption = None # edkiitoolcode : option\r
796 self._PackageList = None\r
797 self._ModuleAutoGenList = None\r
798 self._LibraryAutoGenList = None\r
799 self._BuildCommand = None\r
800\r
801 # get the original module/package/platform objects\r
802 self.BuildDatabase = Workspace.BuildDatabase\r
803 return True\r
804\r
805 def __repr__(self):\r
806 return "%s [%s]" % (self.MetaFile, self.Arch)\r
807\r
808 ## Create autogen code for platform and modules\r
809 #\r
810 # Since there's no autogen code for platform, this method will do nothing\r
811 # if CreateModuleCodeFile is set to False.\r
812 #\r
813 # @param CreateModuleCodeFile Flag indicating if creating module's\r
814 # autogen code file or not\r
815 #\r
816 def CreateCodeFile(self, CreateModuleCodeFile=False):\r
817 # only module has code to be greated, so do nothing if CreateModuleCodeFile is False\r
818 if self.IsCodeFileCreated or not CreateModuleCodeFile:\r
819 return\r
820\r
821 for Ma in self.ModuleAutoGenList:\r
822 Ma.CreateCodeFile(True)\r
823\r
824 # don't do this twice\r
825 self.IsCodeFileCreated = True\r
826\r
827 ## Create makefile for the platform and mdoules in it\r
828 #\r
829 # @param CreateModuleMakeFile Flag indicating if the makefile for\r
830 # modules will be created as well\r
831 #\r
832 def CreateMakeFile(self, CreateModuleMakeFile=False):\r
833 if CreateModuleMakeFile:\r
834 for ModuleFile in self.Platform.Modules:\r
835 Ma = ModuleAutoGen(self.Workspace, ModuleFile, self.BuildTarget,\r
836 self.ToolChain, self.Arch, self.MetaFile)\r
837 Ma.CreateMakeFile(True)\r
da92f276 838 Ma.CreateAsBuiltInf()\r
52302d4d
LG
839\r
840 # no need to create makefile for the platform more than once\r
841 if self.IsMakeFileCreated:\r
842 return\r
843\r
844 # create makefile for platform\r
845 Makefile = GenMake.PlatformMakefile(self)\r
846 if Makefile.Generate():\r
847 EdkLogger.debug(EdkLogger.DEBUG_9, "Generated makefile for platform [%s] [%s]\n" %\r
848 (self.MetaFile, self.Arch))\r
849 else:\r
850 EdkLogger.debug(EdkLogger.DEBUG_9, "Skipped the generation of makefile for platform [%s] [%s]\n" %\r
851 (self.MetaFile, self.Arch))\r
852 self.IsMakeFileCreated = True\r
853\r
854 ## Collect dynamic PCDs\r
855 #\r
856 # Gather dynamic PCDs list from each module and their settings from platform\r
857 # This interface should be invoked explicitly when platform action is created.\r
858 #\r
859 def CollectPlatformDynamicPcds(self):\r
860 # for gathering error information\r
861 NoDatumTypePcdList = set()\r
862\r
863 self._GuidValue = {}\r
864 for F in self.Platform.Modules.keys():\r
865 M = ModuleAutoGen(self.Workspace, F, self.BuildTarget, self.ToolChain, self.Arch, self.MetaFile)\r
866 #GuidValue.update(M.Guids)\r
867 \r
868 self.Platform.Modules[F].M = M\r
869 \r
870 for PcdFromModule in M.ModulePcdList+M.LibraryPcdList:\r
871 # make sure that the "VOID*" kind of datum has MaxDatumSize set\r
e8a47801 872 if PcdFromModule.DatumType == "VOID*" and PcdFromModule.MaxDatumSize in [None, '']:\r
52302d4d
LG
873 NoDatumTypePcdList.add("%s.%s [%s]" % (PcdFromModule.TokenSpaceGuidCName, PcdFromModule.TokenCName, F))\r
874\r
875 if PcdFromModule.Type in GenC.gDynamicPcd or PcdFromModule.Type in GenC.gDynamicExPcd:\r
876 #\r
877 # If a dynamic PCD used by a PEM module/PEI module & DXE module,\r
878 # it should be stored in Pcd PEI database, If a dynamic only\r
879 # used by DXE module, it should be stored in DXE PCD database.\r
880 # The default Phase is DXE\r
881 #\r
882 if M.ModuleType in ["PEIM", "PEI_CORE"]:\r
883 PcdFromModule.Phase = "PEI"\r
884 if PcdFromModule not in self._DynaPcdList_:\r
885 self._DynaPcdList_.append(PcdFromModule)\r
886 elif PcdFromModule.Phase == 'PEI':\r
887 # overwrite any the same PCD existing, if Phase is PEI\r
888 Index = self._DynaPcdList_.index(PcdFromModule)\r
889 self._DynaPcdList_[Index] = PcdFromModule\r
890 elif PcdFromModule not in self._NonDynaPcdList_:\r
891 self._NonDynaPcdList_.append(PcdFromModule)\r
892\r
893 # print out error information and break the build, if error found\r
894 if len(NoDatumTypePcdList) > 0:\r
895 NoDatumTypePcdListString = "\n\t\t".join(NoDatumTypePcdList)\r
896 EdkLogger.error("build", AUTOGEN_ERROR, "PCD setting error",\r
897 File=self.MetaFile,\r
898 ExtraData="\n\tPCD(s) without MaxDatumSize:\n\t\t%s\n"\r
899 % NoDatumTypePcdListString)\r
900 self._NonDynamicPcdList = self._NonDynaPcdList_\r
901 self._DynamicPcdList = self._DynaPcdList_\r
902 self.AllPcdList = self._NonDynamicPcdList + self._DynamicPcdList\r
903 \r
904 #\r
905 # Sort dynamic PCD list to:\r
906 # 1) If PCD's datum type is VOID* and value is unicode string which starts with L, the PCD item should \r
907 # try to be put header of dynamicd List\r
908 # 2) If PCD is HII type, the PCD item should be put after unicode type PCD\r
909 #\r
910 # The reason of sorting is make sure the unicode string is in double-byte alignment in string table.\r
911 #\r
912 UnicodePcdArray = []\r
913 HiiPcdArray = []\r
914 OtherPcdArray = []\r
6780eef1 915 VpdPcdDict = {}\r
e56468c0 916 VpdFile = VpdInfoFile.VpdInfoFile()\r
917 NeedProcessVpdMapFile = False \r
918 \r
919 if (self.Workspace.ArchList[-1] == self.Arch): \r
920 for Pcd in self._DynamicPcdList:\r
e56468c0 921 # just pick the a value to determine whether is unicode string type\r
922 Sku = Pcd.SkuInfoList[Pcd.SkuInfoList.keys()[0]]\r
923 Sku.VpdOffset = Sku.VpdOffset.strip()\r
924 \r
925 PcdValue = Sku.DefaultValue\r
926 if Pcd.DatumType == 'VOID*' and PcdValue.startswith("L"):\r
927 # if found PCD which datum value is unicode string the insert to left size of UnicodeIndex\r
928 UnicodePcdArray.append(Pcd)\r
929 elif len(Sku.VariableName) > 0:\r
930 # if found HII type PCD then insert to right of UnicodeIndex\r
931 HiiPcdArray.append(Pcd)\r
932 else:\r
933 OtherPcdArray.append(Pcd)\r
e56468c0 934 if Pcd.Type in [TAB_PCDS_DYNAMIC_VPD, TAB_PCDS_DYNAMIC_EX_VPD]:\r
6780eef1
LG
935 VpdPcdDict[(Pcd.TokenCName, Pcd.TokenSpaceGuidCName)] = Pcd \r
936 \r
937 PlatformPcds = self.Platform.Pcds.keys()\r
938 PlatformPcds.sort() \r
939 #\r
940 # Add VPD type PCD into VpdFile and determine whether the VPD PCD need to be fixed up.\r
941 #\r
942 for PcdKey in PlatformPcds:\r
e8a47801
LG
943 Pcd = self.Platform.Pcds[PcdKey]\r
944 if Pcd.Type in [TAB_PCDS_DYNAMIC_VPD, TAB_PCDS_DYNAMIC_EX_VPD] and \\r
945 PcdKey in VpdPcdDict:\r
946 Pcd = VpdPcdDict[PcdKey]\r
947 for (SkuName,Sku) in Pcd.SkuInfoList.items():\r
948 Sku.VpdOffset = Sku.VpdOffset.strip()\r
949 VpdFile.Add(Pcd, Sku.VpdOffset)\r
950 # if the offset of a VPD is *, then it need to be fixed up by third party tool.\r
951 if not NeedProcessVpdMapFile and Sku.VpdOffset == "*":\r
952 NeedProcessVpdMapFile = True\r
953 if self.Platform.VpdToolGuid == None or self.Platform.VpdToolGuid == '':\r
954 EdkLogger.error("Build", FILE_NOT_FOUND, \\r
955 "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
6780eef1 956 \r
e56468c0 957 \r
958 #\r
959 # Fix the PCDs define in VPD PCD section that never referenced by module.\r
960 # An example is PCD for signature usage.\r
6780eef1
LG
961 # \r
962 for DscPcd in PlatformPcds:\r
e56468c0 963 DscPcdEntry = self.Platform.Pcds[DscPcd]\r
964 if DscPcdEntry.Type in [TAB_PCDS_DYNAMIC_VPD, TAB_PCDS_DYNAMIC_EX_VPD]:\r
965 if not (self.Platform.VpdToolGuid == None or self.Platform.VpdToolGuid == ''):\r
966 FoundFlag = False\r
967 for VpdPcd in VpdFile._VpdArray.keys():\r
968 # This PCD has been referenced by module\r
969 if (VpdPcd.TokenSpaceGuidCName == DscPcdEntry.TokenSpaceGuidCName) and \\r
970 (VpdPcd.TokenCName == DscPcdEntry.TokenCName):\r
971 FoundFlag = True\r
972 \r
973 # Not found, it should be signature\r
974 if not FoundFlag :\r
975 # just pick the a value to determine whether is unicode string type\r
e8a47801
LG
976 for (SkuName,Sku) in DscPcdEntry.SkuInfoList.items():\r
977 Sku.VpdOffset = Sku.VpdOffset.strip() \r
978 \r
979 # Need to iterate DEC pcd information to get the value & datumtype\r
980 for eachDec in self.PackageList:\r
981 for DecPcd in eachDec.Pcds:\r
982 DecPcdEntry = eachDec.Pcds[DecPcd]\r
983 if (DecPcdEntry.TokenSpaceGuidCName == DscPcdEntry.TokenSpaceGuidCName) and \\r
984 (DecPcdEntry.TokenCName == DscPcdEntry.TokenCName):\r
985 # Print warning message to let the developer make a determine.\r
986 EdkLogger.warn("build", "Unreferenced vpd pcd used!",\r
987 File=self.MetaFile, \\r
988 ExtraData = "PCD: %s.%s used in the DSC file %s is unreferenced." \\r
989 %(DscPcdEntry.TokenSpaceGuidCName, DscPcdEntry.TokenCName, self.Platform.MetaFile.Path)) \r
990 \r
991 DscPcdEntry.DatumType = DecPcdEntry.DatumType\r
992 DscPcdEntry.DefaultValue = DecPcdEntry.DefaultValue\r
993 DscPcdEntry.TokenValue = DecPcdEntry.TokenValue\r
994 DscPcdEntry.TokenSpaceGuidValue = eachDec.Guids[DecPcdEntry.TokenSpaceGuidCName]\r
995 # Only fix the value while no value provided in DSC file.\r
996 if (Sku.DefaultValue == "" or Sku.DefaultValue==None):\r
997 DscPcdEntry.SkuInfoList[DscPcdEntry.SkuInfoList.keys()[0]].DefaultValue = DecPcdEntry.DefaultValue\r
998 \r
999 if DscPcdEntry not in self._DynamicPcdList:\r
1000 self._DynamicPcdList.append(DscPcdEntry)\r
1001# Sku = DscPcdEntry.SkuInfoList[DscPcdEntry.SkuInfoList.keys()[0]]\r
1002 Sku.VpdOffset = Sku.VpdOffset.strip()\r
1003 PcdValue = Sku.DefaultValue\r
1004 VpdFile.Add(DscPcdEntry, Sku.VpdOffset)\r
1005 if not NeedProcessVpdMapFile and Sku.VpdOffset == "*":\r
1006 NeedProcessVpdMapFile = True \r
1007 if DscPcdEntry.DatumType == 'VOID*' and PcdValue.startswith("L"):\r
1008 UnicodePcdArray.append(DscPcdEntry)\r
1009 elif len(Sku.VariableName) > 0:\r
1010 HiiPcdArray.append(DscPcdEntry)\r
1011 else:\r
1012 OtherPcdArray.append(DscPcdEntry)\r
1013 \r
1014 # if the offset of a VPD is *, then it need to be fixed up by third party tool.\r
e56468c0 1015 \r
e56468c0 1016 \r
1017 \r
1018 if (self.Platform.FlashDefinition == None or self.Platform.FlashDefinition == '') and \\r
1019 VpdFile.GetCount() != 0:\r
1020 EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, \r
1021 "Fail to get FLASH_DEFINITION definition in DSC file %s which is required when DSC contains VPD PCD." % str(self.Platform.MetaFile))\r
1022 \r
1023 if VpdFile.GetCount() != 0:\r
d0acc87a 1024 DscTimeStamp = self.Platform.MetaFile.TimeStamp\r
e56468c0 1025 FvPath = os.path.join(self.BuildDir, "FV")\r
1026 if not os.path.exists(FvPath):\r
1027 try:\r
1028 os.makedirs(FvPath)\r
1029 except:\r
1030 EdkLogger.error("build", FILE_WRITE_FAILURE, "Fail to create FV folder under %s" % self.BuildDir)\r
1031 \r
08dd311f
LG
1032 \r
1033 VpdFilePath = os.path.join(FvPath, "%s.txt" % self.Platform.VpdToolGuid)\r
1034\r
e56468c0 1035 \r
1036 if not os.path.exists(VpdFilePath) or os.path.getmtime(VpdFilePath) < DscTimeStamp:\r
1037 VpdFile.Write(VpdFilePath)\r
1038 \r
1039 # retrieve BPDG tool's path from tool_def.txt according to VPD_TOOL_GUID defined in DSC file.\r
1040 BPDGToolName = None\r
1041 for ToolDef in self.ToolDefinition.values():\r
1042 if ToolDef.has_key("GUID") and ToolDef["GUID"] == self.Platform.VpdToolGuid:\r
1043 if not ToolDef.has_key("PATH"):\r
1044 EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE, "PATH attribute was not provided for BPDG guid tool %s in tools_def.txt" % self.Platform.VpdToolGuid)\r
1045 BPDGToolName = ToolDef["PATH"]\r
1046 break\r
1047 # Call third party GUID BPDG tool.\r
1048 if BPDGToolName != None:\r
08dd311f 1049 VpdInfoFile.CallExtenalBPDGTool(BPDGToolName, VpdFilePath)\r
e56468c0 1050 else:\r
1051 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
1052 \r
1053 # Process VPD map file generated by third party BPDG tool\r
1054 if NeedProcessVpdMapFile:\r
08dd311f 1055 VpdMapFilePath = os.path.join(self.BuildDir, "FV", "%s.map" % self.Platform.VpdToolGuid)\r
e56468c0 1056 if os.path.exists(VpdMapFilePath):\r
1057 VpdFile.Read(VpdMapFilePath)\r
1058 \r
1059 # Fixup "*" offset\r
1060 for Pcd in self._DynamicPcdList:\r
1061 # just pick the a value to determine whether is unicode string type\r
e8a47801
LG
1062 i = 0\r
1063 for (SkuName,Sku) in Pcd.SkuInfoList.items(): \r
1064 if Sku.VpdOffset == "*":\r
1065 Sku.VpdOffset = VpdFile.GetOffset(Pcd)[i].strip()\r
1066 i += 1\r
e56468c0 1067 else:\r
1068 EdkLogger.error("build", FILE_READ_FAILURE, "Can not find VPD map file %s to fix up VPD offset." % VpdMapFilePath)\r
1069 \r
1070 # Delete the DynamicPcdList At the last time enter into this function \r
1071 del self._DynamicPcdList[:] \r
52302d4d
LG
1072 self._DynamicPcdList.extend(UnicodePcdArray)\r
1073 self._DynamicPcdList.extend(HiiPcdArray)\r
1074 self._DynamicPcdList.extend(OtherPcdArray)\r
1075 \r
1076 \r
1077 ## Return the platform build data object\r
1078 def _GetPlatform(self):\r
1079 if self._Platform == None:\r
0d2711a6 1080 self._Platform = self.BuildDatabase[self.MetaFile, self.Arch, self.BuildTarget, self.ToolChain]\r
52302d4d
LG
1081 return self._Platform\r
1082\r
1083 ## Return platform name\r
1084 def _GetName(self):\r
1085 return self.Platform.PlatformName\r
1086\r
1087 ## Return the meta file GUID\r
1088 def _GetGuid(self):\r
1089 return self.Platform.Guid\r
1090\r
1091 ## Return the platform version\r
1092 def _GetVersion(self):\r
1093 return self.Platform.Version\r
1094\r
1095 ## Return the FDF file name\r
1096 def _GetFdfFile(self):\r
1097 if self._FdfFile == None:\r
1098 if self.Workspace.FdfFile != "":\r
1099 self._FdfFile= path.join(self.WorkspaceDir, self.Workspace.FdfFile)\r
1100 else:\r
1101 self._FdfFile = ''\r
1102 return self._FdfFile\r
1103\r
1104 ## Return the build output directory platform specifies\r
1105 def _GetOutputDir(self):\r
1106 return self.Platform.OutputDirectory\r
1107\r
1108 ## Return the directory to store all intermediate and final files built\r
1109 def _GetBuildDir(self):\r
1110 if self._BuildDir == None:\r
1111 if os.path.isabs(self.OutputDir):\r
1112 self._BuildDir = path.join(\r
1113 path.abspath(self.OutputDir),\r
1114 self.BuildTarget + "_" + self.ToolChain,\r
1115 )\r
1116 else:\r
1117 self._BuildDir = path.join(\r
1118 self.WorkspaceDir,\r
1119 self.OutputDir,\r
1120 self.BuildTarget + "_" + self.ToolChain,\r
1121 )\r
1122 return self._BuildDir\r
1123\r
1124 ## Return directory of platform makefile\r
1125 #\r
1126 # @retval string Makefile directory\r
1127 #\r
1128 def _GetMakeFileDir(self):\r
1129 if self._MakeFileDir == None:\r
1130 self._MakeFileDir = path.join(self.BuildDir, self.Arch)\r
1131 return self._MakeFileDir\r
1132\r
1133 ## Return build command string\r
1134 #\r
1135 # @retval string Build command string\r
1136 #\r
1137 def _GetBuildCommand(self):\r
1138 if self._BuildCommand == None:\r
1139 self._BuildCommand = []\r
1140 if "MAKE" in self.ToolDefinition and "PATH" in self.ToolDefinition["MAKE"]:\r
1141 self._BuildCommand += SplitOption(self.ToolDefinition["MAKE"]["PATH"])\r
1142 if "FLAGS" in self.ToolDefinition["MAKE"]:\r
1143 NewOption = self.ToolDefinition["MAKE"]["FLAGS"].strip()\r
1144 if NewOption != '':\r
6780eef1 1145 self._BuildCommand += SplitOption(NewOption)\r
52302d4d
LG
1146 return self._BuildCommand\r
1147\r
1148 ## Get tool chain definition\r
1149 #\r
1150 # Get each tool defition for given tool chain from tools_def.txt and platform\r
1151 #\r
1152 def _GetToolDefinition(self):\r
1153 if self._ToolDefinitions == None:\r
1154 ToolDefinition = self.Workspace.ToolDef.ToolsDefTxtDictionary\r
1155 if TAB_TOD_DEFINES_COMMAND_TYPE not in self.Workspace.ToolDef.ToolsDefTxtDatabase:\r
1156 EdkLogger.error('build', RESOURCE_NOT_AVAILABLE, "No tools found in configuration",\r
1157 ExtraData="[%s]" % self.MetaFile)\r
1158 self._ToolDefinitions = {}\r
1159 DllPathList = set()\r
1160 for Def in ToolDefinition:\r
1161 Target, Tag, Arch, Tool, Attr = Def.split("_")\r
1162 if Target != self.BuildTarget or Tag != self.ToolChain or Arch != self.Arch:\r
1163 continue\r
1164\r
1165 Value = ToolDefinition[Def]\r
1166 # don't record the DLL\r
1167 if Attr == "DLL":\r
1168 DllPathList.add(Value)\r
1169 continue\r
1170\r
1171 if Tool not in self._ToolDefinitions:\r
1172 self._ToolDefinitions[Tool] = {}\r
1173 self._ToolDefinitions[Tool][Attr] = Value\r
1174\r
1175 ToolsDef = ''\r
1176 MakePath = ''\r
1177 if GlobalData.gOptions.SilentMode and "MAKE" in self._ToolDefinitions:\r
1178 if "FLAGS" not in self._ToolDefinitions["MAKE"]:\r
1179 self._ToolDefinitions["MAKE"]["FLAGS"] = ""\r
1180 self._ToolDefinitions["MAKE"]["FLAGS"] += " -s"\r
1181 MakeFlags = ''\r
1182 for Tool in self._ToolDefinitions:\r
1183 for Attr in self._ToolDefinitions[Tool]:\r
1184 Value = self._ToolDefinitions[Tool][Attr]\r
1185 if Tool in self.BuildOption and Attr in self.BuildOption[Tool]:\r
1186 # check if override is indicated\r
1187 if self.BuildOption[Tool][Attr].startswith('='):\r
1188 Value = self.BuildOption[Tool][Attr][1:]\r
1189 else:\r
1190 Value += " " + self.BuildOption[Tool][Attr]\r
1191\r
1192 if Attr == "PATH":\r
1193 # Don't put MAKE definition in the file\r
1194 if Tool == "MAKE":\r
1195 MakePath = Value\r
1196 else:\r
1197 ToolsDef += "%s = %s\n" % (Tool, Value)\r
1198 elif Attr != "DLL":\r
1199 # Don't put MAKE definition in the file\r
1200 if Tool == "MAKE":\r
1201 if Attr == "FLAGS":\r
1202 MakeFlags = Value\r
1203 else:\r
1204 ToolsDef += "%s_%s = %s\n" % (Tool, Attr, Value)\r
1205 ToolsDef += "\n"\r
1206\r
1207 SaveFileOnChange(self.ToolDefinitionFile, ToolsDef)\r
1208 for DllPath in DllPathList:\r
1209 os.environ["PATH"] = DllPath + os.pathsep + os.environ["PATH"]\r
1210 os.environ["MAKE_FLAGS"] = MakeFlags\r
1211\r
1212 return self._ToolDefinitions\r
1213\r
1214 ## Return the paths of tools\r
1215 def _GetToolDefFile(self):\r
1216 if self._ToolDefFile == None:\r
1217 self._ToolDefFile = os.path.join(self.MakeFileDir, "TOOLS_DEF." + self.Arch)\r
1218 return self._ToolDefFile\r
1219\r
1220 ## Retrieve the toolchain family of given toolchain tag. Default to 'MSFT'.\r
1221 def _GetToolChainFamily(self):\r
1222 if self._ToolChainFamily == None:\r
1223 ToolDefinition = self.Workspace.ToolDef.ToolsDefTxtDatabase\r
1224 if TAB_TOD_DEFINES_FAMILY not in ToolDefinition \\r
1225 or self.ToolChain not in ToolDefinition[TAB_TOD_DEFINES_FAMILY] \\r
1226 or not ToolDefinition[TAB_TOD_DEFINES_FAMILY][self.ToolChain]:\r
1227 EdkLogger.verbose("No tool chain family found in configuration for %s. Default to MSFT." \\r
1228 % self.ToolChain)\r
1229 self._ToolChainFamily = "MSFT"\r
1230 else:\r
1231 self._ToolChainFamily = ToolDefinition[TAB_TOD_DEFINES_FAMILY][self.ToolChain]\r
1232 return self._ToolChainFamily\r
1233\r
1234 def _GetBuildRuleFamily(self):\r
1235 if self._BuildRuleFamily == None:\r
1236 ToolDefinition = self.Workspace.ToolDef.ToolsDefTxtDatabase\r
1237 if TAB_TOD_DEFINES_BUILDRULEFAMILY not in ToolDefinition \\r
1238 or self.ToolChain not in ToolDefinition[TAB_TOD_DEFINES_BUILDRULEFAMILY] \\r
1239 or not ToolDefinition[TAB_TOD_DEFINES_BUILDRULEFAMILY][self.ToolChain]:\r
1240 EdkLogger.verbose("No tool chain family found in configuration for %s. Default to MSFT." \\r
1241 % self.ToolChain)\r
1242 self._BuildRuleFamily = "MSFT"\r
1243 else:\r
1244 self._BuildRuleFamily = ToolDefinition[TAB_TOD_DEFINES_BUILDRULEFAMILY][self.ToolChain]\r
1245 return self._BuildRuleFamily\r
1246\r
1247 ## Return the build options specific for all modules in this platform\r
1248 def _GetBuildOptions(self):\r
1249 if self._BuildOption == None:\r
1250 self._BuildOption = self._ExpandBuildOption(self.Platform.BuildOptions)\r
1251 return self._BuildOption\r
1252\r
1253 ## Return the build options specific for EDK modules in this platform\r
1254 def _GetEdkBuildOptions(self):\r
1255 if self._EdkBuildOption == None:\r
1256 self._EdkBuildOption = self._ExpandBuildOption(self.Platform.BuildOptions, EDK_NAME)\r
1257 return self._EdkBuildOption\r
1258\r
1259 ## Return the build options specific for EDKII modules in this platform\r
1260 def _GetEdkIIBuildOptions(self):\r
1261 if self._EdkIIBuildOption == None:\r
1262 self._EdkIIBuildOption = self._ExpandBuildOption(self.Platform.BuildOptions, EDKII_NAME)\r
1263 return self._EdkIIBuildOption\r
1264\r
1265 ## Parse build_rule.txt in $(WORKSPACE)/Conf/build_rule.txt\r
1266 #\r
1267 # @retval BuildRule object\r
1268 #\r
1269 def _GetBuildRule(self):\r
1270 if self._BuildRule == None:\r
1271 BuildRuleFile = None\r
1272 if TAB_TAT_DEFINES_BUILD_RULE_CONF in self.Workspace.TargetTxt.TargetTxtDictionary:\r
1273 BuildRuleFile = self.Workspace.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_BUILD_RULE_CONF]\r
1274 if BuildRuleFile in [None, '']:\r
1275 BuildRuleFile = gBuildRuleFile\r
1276 self._BuildRule = BuildRule(BuildRuleFile)\r
64b2609f
LG
1277 if self._BuildRule._FileVersion == "":\r
1278 self._BuildRule._FileVersion = AutoGenReqBuildRuleVerNum\r
1279 else:\r
1280 if self._BuildRule._FileVersion < AutoGenReqBuildRuleVerNum :\r
1281 # If Build Rule's version is less than the version number required by the tools, halting the build.\r
1282 EdkLogger.error("build", AUTOGEN_ERROR, \r
1283 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
1284 % (self._BuildRule._FileVersion, AutoGenReqBuildRuleVerNum))\r
1285 \r
52302d4d
LG
1286 return self._BuildRule\r
1287\r
1288 ## Summarize the packages used by modules in this platform\r
1289 def _GetPackageList(self):\r
1290 if self._PackageList == None:\r
1291 self._PackageList = set()\r
1292 for La in self.LibraryAutoGenList:\r
1293 self._PackageList.update(La.DependentPackageList)\r
1294 for Ma in self.ModuleAutoGenList:\r
1295 self._PackageList.update(Ma.DependentPackageList)\r
1296 self._PackageList = list(self._PackageList)\r
1297 return self._PackageList\r
1298\r
1299 ## Get list of non-dynamic PCDs\r
1300 def _GetNonDynamicPcdList(self):\r
e56468c0 1301 if self._NonDynamicPcdList == None:\r
1302 self.CollectPlatformDynamicPcds()\r
52302d4d
LG
1303 return self._NonDynamicPcdList\r
1304\r
1305 ## Get list of dynamic PCDs\r
1306 def _GetDynamicPcdList(self):\r
e56468c0 1307 if self._DynamicPcdList == None:\r
1308 self.CollectPlatformDynamicPcds()\r
52302d4d
LG
1309 return self._DynamicPcdList\r
1310\r
1311 ## Generate Token Number for all PCD\r
1312 def _GetPcdTokenNumbers(self):\r
1313 if self._PcdTokenNumber == None:\r
1314 self._PcdTokenNumber = sdict()\r
1315 TokenNumber = 1\r
d0acc87a
LG
1316 #\r
1317 # Make the Dynamic and DynamicEx PCD use within different TokenNumber area. \r
1318 # Such as:\r
1319 # \r
1320 # Dynamic PCD:\r
1321 # TokenNumber 0 ~ 10\r
1322 # DynamicEx PCD:\r
1323 # TokeNumber 11 ~ 20\r
1324 #\r
52302d4d
LG
1325 for Pcd in self.DynamicPcdList:\r
1326 if Pcd.Phase == "PEI":\r
d0acc87a
LG
1327 if Pcd.Type in ["Dynamic", "DynamicDefault", "DynamicVpd", "DynamicHii"]:\r
1328 EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))\r
1329 self._PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber\r
1330 TokenNumber += 1\r
1331 \r
1332 for Pcd in self.DynamicPcdList:\r
1333 if Pcd.Phase == "PEI":\r
1334 if Pcd.Type in ["DynamicEx", "DynamicExDefault", "DynamicExVpd", "DynamicExHii"]:\r
1335 EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))\r
1336 self._PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber\r
1337 TokenNumber += 1\r
1338 \r
52302d4d
LG
1339 for Pcd in self.DynamicPcdList:\r
1340 if Pcd.Phase == "DXE":\r
d0acc87a
LG
1341 if Pcd.Type in ["Dynamic", "DynamicDefault", "DynamicVpd", "DynamicHii"]:\r
1342 EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))\r
1343 self._PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber\r
1344 TokenNumber += 1\r
1345 \r
1346 for Pcd in self.DynamicPcdList:\r
1347 if Pcd.Phase == "DXE":\r
1348 if Pcd.Type in ["DynamicEx", "DynamicExDefault", "DynamicExVpd", "DynamicExHii"]:\r
1349 EdkLogger.debug(EdkLogger.DEBUG_5, "%s %s (%s) -> %d" % (Pcd.TokenCName, Pcd.TokenSpaceGuidCName, Pcd.Phase, TokenNumber))\r
1350 self._PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber\r
1351 TokenNumber += 1\r
1352 \r
52302d4d
LG
1353 for Pcd in self.NonDynamicPcdList:\r
1354 self._PcdTokenNumber[Pcd.TokenCName, Pcd.TokenSpaceGuidCName] = TokenNumber\r
1355 TokenNumber += 1\r
1356 return self._PcdTokenNumber\r
1357\r
1358 ## Summarize ModuleAutoGen objects of all modules/libraries to be built for this platform\r
1359 def _GetAutoGenObjectList(self):\r
1360 self._ModuleAutoGenList = []\r
1361 self._LibraryAutoGenList = []\r
1362 for ModuleFile in self.Platform.Modules:\r
1363 Ma = ModuleAutoGen(\r
1364 self.Workspace,\r
1365 ModuleFile,\r
1366 self.BuildTarget,\r
1367 self.ToolChain,\r
1368 self.Arch,\r
1369 self.MetaFile\r
1370 )\r
1371 if Ma not in self._ModuleAutoGenList:\r
1372 self._ModuleAutoGenList.append(Ma)\r
1373 for La in Ma.LibraryAutoGenList:\r
1374 if La not in self._LibraryAutoGenList:\r
1375 self._LibraryAutoGenList.append(La)\r
1376\r
1377 ## Summarize ModuleAutoGen objects of all modules to be built for this platform\r
1378 def _GetModuleAutoGenList(self):\r
1379 if self._ModuleAutoGenList == None:\r
1380 self._GetAutoGenObjectList()\r
1381 return self._ModuleAutoGenList\r
1382\r
1383 ## Summarize ModuleAutoGen objects of all libraries to be built for this platform\r
1384 def _GetLibraryAutoGenList(self):\r
1385 if self._LibraryAutoGenList == None:\r
1386 self._GetAutoGenObjectList()\r
1387 return self._LibraryAutoGenList\r
1388\r
1389 ## Test if a module is supported by the platform\r
1390 #\r
1391 # An error will be raised directly if the module or its arch is not supported\r
1392 # by the platform or current configuration\r
1393 #\r
1394 def ValidModule(self, Module):\r
1395 return Module in self.Platform.Modules or Module in self.Platform.LibraryInstances\r
1396\r
1397 ## Resolve the library classes in a module to library instances\r
1398 #\r
1399 # This method will not only resolve library classes but also sort the library\r
1400 # instances according to the dependency-ship.\r
1401 #\r
1402 # @param Module The module from which the library classes will be resolved\r
1403 #\r
1404 # @retval library_list List of library instances sorted\r
1405 #\r
1406 def ApplyLibraryInstance(self, Module):\r
1407 ModuleType = Module.ModuleType\r
1408\r
1409 # for overridding library instances with module specific setting\r
1410 PlatformModule = self.Platform.Modules[str(Module)]\r
1411\r
1412 # add forced library instances (specified under LibraryClasses sections)\r
da92f276
LG
1413 #\r
1414 # If a module has a MODULE_TYPE of USER_DEFINED,\r
1415 # do not link in NULL library class instances from the global [LibraryClasses.*] sections.\r
1416 #\r
1417 if Module.ModuleType != SUP_MODULE_USER_DEFINED:\r
1418 for LibraryClass in self.Platform.LibraryClasses.GetKeys():\r
1419 if LibraryClass.startswith("NULL") and self.Platform.LibraryClasses[LibraryClass, Module.ModuleType]:\r
1420 Module.LibraryClasses[LibraryClass] = self.Platform.LibraryClasses[LibraryClass, Module.ModuleType]\r
52302d4d
LG
1421\r
1422 # add forced library instances (specified in module overrides)\r
1423 for LibraryClass in PlatformModule.LibraryClasses:\r
1424 if LibraryClass.startswith("NULL"):\r
1425 Module.LibraryClasses[LibraryClass] = PlatformModule.LibraryClasses[LibraryClass]\r
1426\r
b36d134f 1427 # EdkII module\r
52302d4d
LG
1428 LibraryConsumerList = [Module]\r
1429 Constructor = []\r
1430 ConsumedByList = sdict()\r
1431 LibraryInstance = sdict()\r
1432\r
1433 EdkLogger.verbose("")\r
1434 EdkLogger.verbose("Library instances of module [%s] [%s]:" % (str(Module), self.Arch))\r
1435 while len(LibraryConsumerList) > 0:\r
1436 M = LibraryConsumerList.pop()\r
1437 for LibraryClassName in M.LibraryClasses:\r
1438 if LibraryClassName not in LibraryInstance:\r
1439 # override library instance for this module\r
1440 if LibraryClassName in PlatformModule.LibraryClasses:\r
1441 LibraryPath = PlatformModule.LibraryClasses[LibraryClassName]\r
1442 else:\r
1443 LibraryPath = self.Platform.LibraryClasses[LibraryClassName, ModuleType]\r
1444 if LibraryPath == None or LibraryPath == "":\r
1445 LibraryPath = M.LibraryClasses[LibraryClassName]\r
1446 if LibraryPath == None or LibraryPath == "":\r
1447 EdkLogger.error("build", RESOURCE_NOT_AVAILABLE,\r
1448 "Instance of library class [%s] is not found" % LibraryClassName,\r
1449 File=self.MetaFile,\r
1450 ExtraData="in [%s] [%s]\n\tconsumed by module [%s]" % (str(M), self.Arch, str(Module)))\r
1451\r
0d2711a6 1452 LibraryModule = self.BuildDatabase[LibraryPath, self.Arch, self.BuildTarget, self.ToolChain]\r
52302d4d
LG
1453 # for those forced library instance (NULL library), add a fake library class\r
1454 if LibraryClassName.startswith("NULL"):\r
1455 LibraryModule.LibraryClass.append(LibraryClassObject(LibraryClassName, [ModuleType]))\r
1456 elif LibraryModule.LibraryClass == None \\r
1457 or len(LibraryModule.LibraryClass) == 0 \\r
1458 or (ModuleType != 'USER_DEFINED'\r
1459 and ModuleType not in LibraryModule.LibraryClass[0].SupModList):\r
1460 # only USER_DEFINED can link against any library instance despite of its SupModList\r
1461 EdkLogger.error("build", OPTION_MISSING,\r
1462 "Module type [%s] is not supported by library instance [%s]" \\r
1463 % (ModuleType, LibraryPath), File=self.MetaFile,\r
1464 ExtraData="consumed by [%s]" % str(Module))\r
1465\r
1466 LibraryInstance[LibraryClassName] = LibraryModule\r
1467 LibraryConsumerList.append(LibraryModule)\r
1468 EdkLogger.verbose("\t" + str(LibraryClassName) + " : " + str(LibraryModule))\r
1469 else:\r
1470 LibraryModule = LibraryInstance[LibraryClassName]\r
1471\r
1472 if LibraryModule == None:\r
1473 continue\r
1474\r
1475 if LibraryModule.ConstructorList != [] and LibraryModule not in Constructor:\r
1476 Constructor.append(LibraryModule)\r
1477\r
1478 if LibraryModule not in ConsumedByList:\r
1479 ConsumedByList[LibraryModule] = []\r
1480 # don't add current module itself to consumer list\r
1481 if M != Module:\r
1482 if M in ConsumedByList[LibraryModule]:\r
1483 continue\r
1484 ConsumedByList[LibraryModule].append(M)\r
1485 #\r
1486 # Initialize the sorted output list to the empty set\r
1487 #\r
1488 SortedLibraryList = []\r
1489 #\r
1490 # Q <- Set of all nodes with no incoming edges\r
1491 #\r
1492 LibraryList = [] #LibraryInstance.values()\r
1493 Q = []\r
1494 for LibraryClassName in LibraryInstance:\r
1495 M = LibraryInstance[LibraryClassName]\r
1496 LibraryList.append(M)\r
1497 if ConsumedByList[M] == []:\r
1498 Q.append(M)\r
1499\r
1500 #\r
1501 # start the DAG algorithm\r
1502 #\r
1503 while True:\r
1504 EdgeRemoved = True\r
1505 while Q == [] and EdgeRemoved:\r
1506 EdgeRemoved = False\r
1507 # for each node Item with a Constructor\r
1508 for Item in LibraryList:\r
1509 if Item not in Constructor:\r
1510 continue\r
1511 # for each Node without a constructor with an edge e from Item to Node\r
1512 for Node in ConsumedByList[Item]:\r
1513 if Node in Constructor:\r
1514 continue\r
1515 # remove edge e from the graph if Node has no constructor\r
1516 ConsumedByList[Item].remove(Node)\r
1517 EdgeRemoved = True\r
1518 if ConsumedByList[Item] == []:\r
1519 # insert Item into Q\r
1520 Q.insert(0, Item)\r
1521 break\r
1522 if Q != []:\r
1523 break\r
1524 # DAG is done if there's no more incoming edge for all nodes\r
1525 if Q == []:\r
1526 break\r
1527\r
1528 # remove node from Q\r
1529 Node = Q.pop()\r
1530 # output Node\r
1531 SortedLibraryList.append(Node)\r
1532\r
1533 # for each node Item with an edge e from Node to Item do\r
1534 for Item in LibraryList:\r
1535 if Node not in ConsumedByList[Item]:\r
1536 continue\r
1537 # remove edge e from the graph\r
1538 ConsumedByList[Item].remove(Node)\r
1539\r
1540 if ConsumedByList[Item] != []:\r
1541 continue\r
1542 # insert Item into Q, if Item has no other incoming edges\r
1543 Q.insert(0, Item)\r
1544\r
1545 #\r
1546 # if any remaining node Item in the graph has a constructor and an incoming edge, then the graph has a cycle\r
1547 #\r
1548 for Item in LibraryList:\r
1549 if ConsumedByList[Item] != [] and Item in Constructor and len(Constructor) > 1:\r
1550 ErrorMessage = "\tconsumed by " + "\n\tconsumed by ".join([str(L) for L in ConsumedByList[Item]])\r
1551 EdkLogger.error("build", BUILD_ERROR, 'Library [%s] with constructors has a cycle' % str(Item),\r
1552 ExtraData=ErrorMessage, File=self.MetaFile)\r
1553 if Item not in SortedLibraryList:\r
1554 SortedLibraryList.append(Item)\r
1555\r
1556 #\r
1557 # Build the list of constructor and destructir names\r
1558 # The DAG Topo sort produces the destructor order, so the list of constructors must generated in the reverse order\r
1559 #\r
1560 SortedLibraryList.reverse()\r
1561 return SortedLibraryList\r
1562\r
1563\r
1564 ## Override PCD setting (type, value, ...)\r
1565 #\r
1566 # @param ToPcd The PCD to be overrided\r
1567 # @param FromPcd The PCD overrideing from\r
1568 #\r
1569 def _OverridePcd(self, ToPcd, FromPcd, Module=""):\r
1570 #\r
1571 # in case there's PCDs coming from FDF file, which have no type given.\r
1572 # at this point, ToPcd.Type has the type found from dependent\r
1573 # package\r
1574 #\r
1575 if FromPcd != None:\r
1576 if ToPcd.Pending and FromPcd.Type not in [None, '']:\r
1577 ToPcd.Type = FromPcd.Type\r
e56468c0 1578 elif (ToPcd.Type not in [None, '']) and (FromPcd.Type not in [None, ''])\\r
1579 and (ToPcd.Type != FromPcd.Type) and (ToPcd.Type in FromPcd.Type):\r
1580 if ToPcd.Type.strip() == "DynamicEx":\r
1581 ToPcd.Type = FromPcd.Type \r
52302d4d
LG
1582 elif ToPcd.Type not in [None, ''] and FromPcd.Type not in [None, ''] \\r
1583 and ToPcd.Type != FromPcd.Type:\r
1584 EdkLogger.error("build", OPTION_CONFLICT, "Mismatched PCD type",\r
1585 ExtraData="%s.%s is defined as [%s] in module %s, but as [%s] in platform."\\r
1586 % (ToPcd.TokenSpaceGuidCName, ToPcd.TokenCName,\r
1587 ToPcd.Type, Module, FromPcd.Type),\r
1588 File=self.MetaFile)\r
1589\r
1590 if FromPcd.MaxDatumSize not in [None, '']:\r
1591 ToPcd.MaxDatumSize = FromPcd.MaxDatumSize\r
1592 if FromPcd.DefaultValue not in [None, '']:\r
1593 ToPcd.DefaultValue = FromPcd.DefaultValue\r
1594 if FromPcd.TokenValue not in [None, '']:\r
1595 ToPcd.TokenValue = FromPcd.TokenValue\r
1596 if FromPcd.MaxDatumSize not in [None, '']:\r
1597 ToPcd.MaxDatumSize = FromPcd.MaxDatumSize\r
1598 if FromPcd.DatumType not in [None, '']:\r
1599 ToPcd.DatumType = FromPcd.DatumType\r
1600 if FromPcd.SkuInfoList not in [None, '', []]:\r
1601 ToPcd.SkuInfoList = FromPcd.SkuInfoList\r
1602\r
1603 # check the validation of datum\r
1604 IsValid, Cause = CheckPcdDatum(ToPcd.DatumType, ToPcd.DefaultValue)\r
1605 if not IsValid:\r
1606 EdkLogger.error('build', FORMAT_INVALID, Cause, File=self.MetaFile,\r
1607 ExtraData="%s.%s" % (ToPcd.TokenSpaceGuidCName, ToPcd.TokenCName))\r
1608\r
1609 if ToPcd.DatumType == "VOID*" and ToPcd.MaxDatumSize in ['', None]:\r
1610 EdkLogger.debug(EdkLogger.DEBUG_9, "No MaxDatumSize specified for PCD %s.%s" \\r
1611 % (ToPcd.TokenSpaceGuidCName, ToPcd.TokenCName))\r
1612 Value = ToPcd.DefaultValue\r
1613 if Value in [None, '']:\r
e8a47801 1614 ToPcd.MaxDatumSize = '1'\r
52302d4d 1615 elif Value[0] == 'L':\r
e8a47801 1616 ToPcd.MaxDatumSize = str((len(Value) - 2) * 2)\r
52302d4d
LG
1617 elif Value[0] == '{':\r
1618 ToPcd.MaxDatumSize = str(len(Value.split(',')))\r
1619 else:\r
e8a47801 1620 ToPcd.MaxDatumSize = str(len(Value) - 1)\r
52302d4d
LG
1621\r
1622 # apply default SKU for dynamic PCDS if specified one is not available\r
1623 if (ToPcd.Type in PCD_DYNAMIC_TYPE_LIST or ToPcd.Type in PCD_DYNAMIC_EX_TYPE_LIST) \\r
1624 and ToPcd.SkuInfoList in [None, {}, '']:\r
1625 if self.Platform.SkuName in self.Platform.SkuIds:\r
1626 SkuName = self.Platform.SkuName\r
1627 else:\r
1628 SkuName = 'DEFAULT'\r
1629 ToPcd.SkuInfoList = {\r
1630 SkuName : SkuInfoClass(SkuName, self.Platform.SkuIds[SkuName], '', '', '', '', '', ToPcd.DefaultValue)\r
1631 }\r
1632\r
1633 ## Apply PCD setting defined platform to a module\r
1634 #\r
1635 # @param Module The module from which the PCD setting will be overrided\r
1636 #\r
1637 # @retval PCD_list The list PCDs with settings from platform\r
1638 #\r
1639 def ApplyPcdSetting(self, Module, Pcds):\r
1640 # for each PCD in module\r
1641 for Name,Guid in Pcds:\r
1642 PcdInModule = Pcds[Name,Guid]\r
1643 # find out the PCD setting in platform\r
1644 if (Name,Guid) in self.Platform.Pcds:\r
1645 PcdInPlatform = self.Platform.Pcds[Name,Guid]\r
1646 else:\r
1647 PcdInPlatform = None\r
1648 # then override the settings if any\r
1649 self._OverridePcd(PcdInModule, PcdInPlatform, Module)\r
1650 # resolve the VariableGuid value\r
1651 for SkuId in PcdInModule.SkuInfoList:\r
1652 Sku = PcdInModule.SkuInfoList[SkuId]\r
1653 if Sku.VariableGuid == '': continue\r
1654 Sku.VariableGuidValue = GuidValue(Sku.VariableGuid, self.PackageList)\r
1655 if Sku.VariableGuidValue == None:\r
1656 PackageList = "\n\t".join([str(P) for P in self.PackageList])\r
1657 EdkLogger.error(\r
1658 'build',\r
1659 RESOURCE_NOT_AVAILABLE,\r
1660 "Value of GUID [%s] is not found in" % Sku.VariableGuid,\r
1661 ExtraData=PackageList + "\n\t(used with %s.%s from module %s)" \\r
1662 % (Guid, Name, str(Module)),\r
1663 File=self.MetaFile\r
1664 )\r
1665\r
1666 # override PCD settings with module specific setting\r
1667 if Module in self.Platform.Modules:\r
1668 PlatformModule = self.Platform.Modules[str(Module)]\r
1669 for Key in PlatformModule.Pcds:\r
1670 if Key in Pcds:\r
1671 self._OverridePcd(Pcds[Key], PlatformModule.Pcds[Key], Module)\r
1672 return Pcds.values()\r
1673\r
1674 ## Resolve library names to library modules\r
1675 #\r
b36d134f 1676 # (for Edk.x modules)\r
52302d4d
LG
1677 #\r
1678 # @param Module The module from which the library names will be resolved\r
1679 #\r
1680 # @retval library_list The list of library modules\r
1681 #\r
1682 def ResolveLibraryReference(self, Module):\r
1683 EdkLogger.verbose("")\r
1684 EdkLogger.verbose("Library instances of module [%s] [%s]:" % (str(Module), self.Arch))\r
1685 LibraryConsumerList = [Module]\r
1686\r
b36d134f 1687 # "CompilerStub" is a must for Edk modules\r
52302d4d
LG
1688 if Module.Libraries:\r
1689 Module.Libraries.append("CompilerStub")\r
1690 LibraryList = []\r
1691 while len(LibraryConsumerList) > 0:\r
1692 M = LibraryConsumerList.pop()\r
1693 for LibraryName in M.Libraries:\r
1694 Library = self.Platform.LibraryClasses[LibraryName, ':dummy:']\r
1695 if Library == None:\r
1696 for Key in self.Platform.LibraryClasses.data.keys():\r
1697 if LibraryName.upper() == Key.upper():\r
1698 Library = self.Platform.LibraryClasses[Key, ':dummy:']\r
1699 break\r
1700 if Library == None:\r
1701 EdkLogger.warn("build", "Library [%s] is not found" % LibraryName, File=str(M),\r
1702 ExtraData="\t%s [%s]" % (str(Module), self.Arch))\r
1703 continue\r
1704\r
1705 if Library not in LibraryList:\r
1706 LibraryList.append(Library)\r
1707 LibraryConsumerList.append(Library)\r
1708 EdkLogger.verbose("\t" + LibraryName + " : " + str(Library) + ' ' + str(type(Library)))\r
1709 return LibraryList\r
1710\r
6780eef1
LG
1711 ## Calculate the priority value of the build option\r
1712 #\r
1713 # @param Key Build option definition contain: TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE\r
1714 #\r
1715 # @retval Value Priority value based on the priority list.\r
1716 #\r
1717 def CalculatePriorityValue(self, Key):\r
1718 Target, ToolChain, Arch, CommandType, Attr = Key.split('_') \r
1719 PriorityValue = 0x11111 \r
1720 if Target == "*":\r
1721 PriorityValue &= 0x01111\r
1722 if ToolChain == "*":\r
1723 PriorityValue &= 0x10111\r
1724 if Arch == "*":\r
1725 PriorityValue &= 0x11011\r
1726 if CommandType == "*":\r
1727 PriorityValue &= 0x11101\r
1728 if Attr == "*":\r
1729 PriorityValue &= 0x11110\r
1730 \r
1731 return self.PrioList["0x%0.5x"%PriorityValue]\r
1732 \r
1733\r
52302d4d
LG
1734 ## Expand * in build option key\r
1735 #\r
1736 # @param Options Options to be expanded\r
1737 #\r
1738 # @retval options Options expanded\r
6780eef1 1739 # \r
52302d4d
LG
1740 def _ExpandBuildOption(self, Options, ModuleStyle=None):\r
1741 BuildOptions = {}\r
1742 FamilyMatch = False\r
1743 FamilyIsNull = True\r
6780eef1
LG
1744 \r
1745 OverrideList = {}\r
1746 #\r
1747 # Construct a list contain the build options which need override.\r
1748 #\r
1749 for Key in Options:\r
1750 #\r
1751 # Key[0] -- tool family\r
1752 # Key[1] -- TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE\r
1753 #\r
1754 if Key[0] == self.BuildRuleFamily :\r
1755 Target, ToolChain, Arch, CommandType, Attr = Key[1].split('_')\r
1756 if Target == self.BuildTarget or Target == "*":\r
1757 if ToolChain == self.ToolChain or ToolChain == "*":\r
1758 if Arch == self.Arch or Arch == "*":\r
1759 if Options[Key].startswith("="):\r
1760 if OverrideList.get(Key[1]) != None: \r
1761 OverrideList.pop(Key[1])\r
1762 OverrideList[Key[1]] = Options[Key]\r
1763 \r
1764 #\r
1765 # Use the highest priority value. \r
1766 #\r
1767 if (len(OverrideList) >= 2):\r
1768 KeyList = OverrideList.keys()\r
1769 for Index in range(len(KeyList)):\r
1770 NowKey = KeyList[Index]\r
1771 Target1, ToolChain1, Arch1, CommandType1, Attr1 = NowKey.split("_")\r
1772 for Index1 in range(len(KeyList) - Index - 1):\r
1773 NextKey = KeyList[Index1 + Index + 1]\r
1774 #\r
1775 # Compare two Key, if one is included by another, choose the higher priority one\r
1776 # \r
1777 Target2, ToolChain2, Arch2, CommandType2, Attr2 = NextKey.split("_")\r
1778 if Target1 == Target2 or Target1 == "*" or Target2 == "*":\r
1779 if ToolChain1 == ToolChain2 or ToolChain1 == "*" or ToolChain2 == "*":\r
1780 if Arch1 == Arch2 or Arch1 == "*" or Arch2 == "*":\r
1781 if CommandType1 == CommandType2 or CommandType1 == "*" or CommandType2 == "*":\r
1782 if Attr1 == Attr2 or Attr1 == "*" or Attr2 == "*":\r
1783 if self.CalculatePriorityValue(NowKey) > self.CalculatePriorityValue(NextKey):\r
1784 if Options.get((self.BuildRuleFamily, NextKey)) != None: \r
1785 Options.pop((self.BuildRuleFamily, NextKey))\r
1786 else:\r
1787 if Options.get((self.BuildRuleFamily, NowKey)) != None: \r
1788 Options.pop((self.BuildRuleFamily, NowKey))\r
1789 \r
1790 \r
52302d4d
LG
1791 for Key in Options:\r
1792 if ModuleStyle != None and len (Key) > 2:\r
1793 # Check Module style is EDK or EDKII.\r
1794 # Only append build option for the matched style module.\r
1795 if ModuleStyle == EDK_NAME and Key[2] != EDK_NAME:\r
1796 continue\r
1797 elif ModuleStyle == EDKII_NAME and Key[2] != EDKII_NAME:\r
1798 continue\r
1799 Family = Key[0]\r
1800 Target, Tag, Arch, Tool, Attr = Key[1].split("_")\r
1801 # if tool chain family doesn't match, skip it\r
1802 if Tool in self.ToolDefinition and Family != "":\r
1803 FamilyIsNull = False\r
1804 if self.ToolDefinition[Tool].get(TAB_TOD_DEFINES_BUILDRULEFAMILY, "") != "":\r
1805 if Family != self.ToolDefinition[Tool][TAB_TOD_DEFINES_BUILDRULEFAMILY]:\r
1806 continue\r
1807 elif Family != self.ToolDefinition[Tool][TAB_TOD_DEFINES_FAMILY]:\r
1808 continue\r
1809 FamilyMatch = True\r
1810 # expand any wildcard\r
1811 if Target == "*" or Target == self.BuildTarget:\r
1812 if Tag == "*" or Tag == self.ToolChain:\r
1813 if Arch == "*" or Arch == self.Arch:\r
1814 if Tool not in BuildOptions:\r
1815 BuildOptions[Tool] = {}\r
1816 if Attr != "FLAGS" or Attr not in BuildOptions[Tool]:\r
1817 BuildOptions[Tool][Attr] = Options[Key]\r
1818 else:\r
1819 # append options for the same tool\r
1820 BuildOptions[Tool][Attr] += " " + Options[Key]\r
1821 # Build Option Family has been checked, which need't to be checked again for family.\r
1822 if FamilyMatch or FamilyIsNull:\r
1823 return BuildOptions\r
1824 \r
1825 for Key in Options:\r
1826 if ModuleStyle != None and len (Key) > 2:\r
1827 # Check Module style is EDK or EDKII.\r
1828 # Only append build option for the matched style module.\r
1829 if ModuleStyle == EDK_NAME and Key[2] != EDK_NAME:\r
1830 continue\r
1831 elif ModuleStyle == EDKII_NAME and Key[2] != EDKII_NAME:\r
1832 continue\r
1833 Family = Key[0]\r
1834 Target, Tag, Arch, Tool, Attr = Key[1].split("_")\r
1835 # if tool chain family doesn't match, skip it\r
1836 if Tool not in self.ToolDefinition or Family =="":\r
1837 continue\r
1838 # option has been added before\r
1839 if Family != self.ToolDefinition[Tool][TAB_TOD_DEFINES_FAMILY]:\r
1840 continue\r
1841\r
1842 # expand any wildcard\r
1843 if Target == "*" or Target == self.BuildTarget:\r
1844 if Tag == "*" or Tag == self.ToolChain:\r
1845 if Arch == "*" or Arch == self.Arch:\r
1846 if Tool not in BuildOptions:\r
1847 BuildOptions[Tool] = {}\r
1848 if Attr != "FLAGS" or Attr not in BuildOptions[Tool]:\r
1849 BuildOptions[Tool][Attr] = Options[Key]\r
1850 else:\r
1851 # append options for the same tool\r
1852 BuildOptions[Tool][Attr] += " " + Options[Key]\r
1853 return BuildOptions\r
1854\r
1855 ## Append build options in platform to a module\r
1856 #\r
1857 # @param Module The module to which the build options will be appened\r
1858 #\r
1859 # @retval options The options appended with build options in platform\r
1860 #\r
1861 def ApplyBuildOption(self, Module):\r
1862 # Get the different options for the different style module\r
1863 if Module.AutoGenVersion < 0x00010005:\r
1864 PlatformOptions = self.EdkBuildOption\r
1865 else:\r
1866 PlatformOptions = self.EdkIIBuildOption\r
1867 ModuleOptions = self._ExpandBuildOption(Module.BuildOptions)\r
1868 if Module in self.Platform.Modules:\r
1869 PlatformModule = self.Platform.Modules[str(Module)]\r
1870 PlatformModuleOptions = self._ExpandBuildOption(PlatformModule.BuildOptions)\r
1871 else:\r
1872 PlatformModuleOptions = {}\r
1873\r
1874 AllTools = set(ModuleOptions.keys() + PlatformOptions.keys() + PlatformModuleOptions.keys() + self.ToolDefinition.keys())\r
1875 BuildOptions = {}\r
1876 for Tool in AllTools:\r
1877 if Tool not in BuildOptions:\r
1878 BuildOptions[Tool] = {}\r
1879\r
1880 for Options in [self.ToolDefinition, ModuleOptions, PlatformOptions, PlatformModuleOptions]:\r
1881 if Tool not in Options:\r
1882 continue\r
1883 for Attr in Options[Tool]:\r
1884 Value = Options[Tool][Attr]\r
1885 if Attr not in BuildOptions[Tool]:\r
1886 BuildOptions[Tool][Attr] = ""\r
1887 # check if override is indicated\r
1888 if Value.startswith('='):\r
1889 BuildOptions[Tool][Attr] = Value[1:]\r
1890 else:\r
1891 BuildOptions[Tool][Attr] += " " + Value\r
f3decdc3
LG
1892 if Module.AutoGenVersion < 0x00010005 and self.Workspace.UniFlag != None:\r
1893 #\r
1894 # Override UNI flag only for EDK module.\r
1895 #\r
1896 if 'BUILD' not in BuildOptions:\r
1897 BuildOptions['BUILD'] = {}\r
1898 BuildOptions['BUILD']['FLAGS'] = self.Workspace.UniFlag\r
52302d4d
LG
1899 return BuildOptions\r
1900\r
1901 Platform = property(_GetPlatform)\r
1902 Name = property(_GetName)\r
1903 Guid = property(_GetGuid)\r
1904 Version = property(_GetVersion)\r
1905\r
1906 OutputDir = property(_GetOutputDir)\r
1907 BuildDir = property(_GetBuildDir)\r
1908 MakeFileDir = property(_GetMakeFileDir)\r
1909 FdfFile = property(_GetFdfFile)\r
1910\r
1911 PcdTokenNumber = property(_GetPcdTokenNumbers) # (TokenCName, TokenSpaceGuidCName) : GeneratedTokenNumber\r
1912 DynamicPcdList = property(_GetDynamicPcdList) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]\r
1913 NonDynamicPcdList = property(_GetNonDynamicPcdList) # [(TokenCName1, TokenSpaceGuidCName1), (TokenCName2, TokenSpaceGuidCName2), ...]\r
1914 PackageList = property(_GetPackageList)\r
1915\r
1916 ToolDefinition = property(_GetToolDefinition) # toolcode : tool path\r
1917 ToolDefinitionFile = property(_GetToolDefFile) # toolcode : lib path\r
1918 ToolChainFamily = property(_GetToolChainFamily)\r
1919 BuildRuleFamily = property(_GetBuildRuleFamily)\r
1920 BuildOption = property(_GetBuildOptions) # toolcode : option\r
1921 EdkBuildOption = property(_GetEdkBuildOptions) # edktoolcode : option\r
1922 EdkIIBuildOption = property(_GetEdkIIBuildOptions) # edkiitoolcode : option\r
1923\r
1924 BuildCommand = property(_GetBuildCommand)\r
1925 BuildRule = property(_GetBuildRule)\r
1926 ModuleAutoGenList = property(_GetModuleAutoGenList)\r
1927 LibraryAutoGenList = property(_GetLibraryAutoGenList)\r
1928\r
1929## ModuleAutoGen class\r
1930#\r
1931# This class encapsules the AutoGen behaviors for the build tools. In addition to\r
1932# the generation of AutoGen.h and AutoGen.c, it will generate *.depex file according\r
1933# to the [depex] section in module's inf file.\r
1934#\r
1935class ModuleAutoGen(AutoGen):\r
1936 ## The real constructor of ModuleAutoGen\r
1937 #\r
1938 # This method is not supposed to be called by users of ModuleAutoGen. It's\r
1939 # only used by factory method __new__() to do real initialization work for an\r
1940 # object of ModuleAutoGen\r
1941 #\r
1942 # @param Workspace EdkIIWorkspaceBuild object\r
1943 # @param ModuleFile The path of module file\r
1944 # @param Target Build target (DEBUG, RELEASE)\r
1945 # @param Toolchain Name of tool chain\r
1946 # @param Arch The arch the module supports\r
1947 # @param PlatformFile Platform meta-file\r
1948 #\r
1949 def _Init(self, Workspace, ModuleFile, Target, Toolchain, Arch, PlatformFile):\r
1950 EdkLogger.debug(EdkLogger.DEBUG_9, "AutoGen module [%s] [%s]" % (ModuleFile, Arch))\r
1951 GlobalData.gProcessingFile = "%s [%s, %s, %s]" % (ModuleFile, Arch, Toolchain, Target)\r
1952\r
1953 self.Workspace = Workspace\r
1954 self.WorkspaceDir = Workspace.WorkspaceDir\r
1955\r
1956 self.MetaFile = ModuleFile\r
1957 self.PlatformInfo = PlatformAutoGen(Workspace, PlatformFile, Target, Toolchain, Arch)\r
1958 # check if this module is employed by active platform\r
1959 if not self.PlatformInfo.ValidModule(self.MetaFile):\r
1960 EdkLogger.verbose("Module [%s] for [%s] is not employed by active platform\n" \\r
1961 % (self.MetaFile, Arch))\r
1962 return False\r
1963\r
1964 self.SourceDir = self.MetaFile.SubDir\r
1965 self.SourceOverrideDir = None\r
1966 # use overrided path defined in DSC file\r
1967 if self.MetaFile.Key in GlobalData.gOverrideDir:\r
1968 self.SourceOverrideDir = GlobalData.gOverrideDir[self.MetaFile.Key]\r
1969\r
1970 self.ToolChain = Toolchain\r
1971 self.BuildTarget = Target\r
1972 self.Arch = Arch\r
1973 self.ToolChainFamily = self.PlatformInfo.ToolChainFamily\r
1974 self.BuildRuleFamily = self.PlatformInfo.BuildRuleFamily\r
1975\r
1976 self.IsMakeFileCreated = False\r
1977 self.IsCodeFileCreated = False\r
da92f276
LG
1978 self.IsAsBuiltInfCreated = False\r
1979 self.DepexGenerated = False\r
52302d4d
LG
1980\r
1981 self.BuildDatabase = self.Workspace.BuildDatabase\r
1982\r
1983 self._Module = None\r
1984 self._Name = None\r
1985 self._Guid = None\r
1986 self._Version = None\r
1987 self._ModuleType = None\r
1988 self._ComponentType = None\r
1989 self._PcdIsDriver = None\r
1990 self._AutoGenVersion = None\r
1991 self._LibraryFlag = None\r
1992 self._CustomMakefile = None\r
1993 self._Macro = None\r
1994\r
1995 self._BuildDir = None\r
1996 self._OutputDir = None\r
1997 self._DebugDir = None\r
1998 self._MakeFileDir = None\r
1999\r
2000 self._IncludePathList = None\r
2001 self._AutoGenFileList = None\r
2002 self._UnicodeFileList = None\r
2003 self._SourceFileList = None\r
2004 self._ObjectFileList = None\r
2005 self._BinaryFileList = None\r
2006\r
2007 self._DependentPackageList = None\r
2008 self._DependentLibraryList = None\r
2009 self._LibraryAutoGenList = None\r
2010 self._DerivedPackageList = None\r
2011 self._ModulePcdList = None\r
2012 self._LibraryPcdList = None\r
e8a47801 2013 self._PcdComments = sdict()\r
52302d4d 2014 self._GuidList = None\r
e8a47801
LG
2015 self._GuidsUsedByPcd = None\r
2016 self._GuidComments = sdict()\r
52302d4d 2017 self._ProtocolList = None\r
e8a47801 2018 self._ProtocolComments = sdict()\r
52302d4d 2019 self._PpiList = None\r
e8a47801 2020 self._PpiComments = sdict()\r
52302d4d
LG
2021 self._DepexList = None\r
2022 self._DepexExpressionList = None\r
2023 self._BuildOption = None\r
79b74a03 2024 self._BuildOptionIncPathList = None\r
52302d4d
LG
2025 self._BuildTargets = None\r
2026 self._IntroBuildTargetList = None\r
2027 self._FinalBuildTargetList = None\r
2028 self._FileTypes = None\r
2029 self._BuildRules = None\r
2030\r
2031 return True\r
2032\r
2033 def __repr__(self):\r
2034 return "%s [%s]" % (self.MetaFile, self.Arch)\r
2035\r
2036 # Macros could be used in build_rule.txt (also Makefile)\r
2037 def _GetMacros(self):\r
2038 if self._Macro == None:\r
2039 self._Macro = sdict()\r
2040 self._Macro["WORKSPACE" ] = self.WorkspaceDir\r
2041 self._Macro["MODULE_NAME" ] = self.Name\r
2042 self._Macro["MODULE_GUID" ] = self.Guid\r
2043 self._Macro["MODULE_VERSION" ] = self.Version\r
2044 self._Macro["MODULE_TYPE" ] = self.ModuleType\r
2045 self._Macro["MODULE_FILE" ] = str(self.MetaFile)\r
2046 self._Macro["MODULE_FILE_BASE_NAME" ] = self.MetaFile.BaseName\r
2047 self._Macro["MODULE_RELATIVE_DIR" ] = self.SourceDir\r
2048 self._Macro["MODULE_DIR" ] = self.SourceDir\r
2049\r
2050 self._Macro["BASE_NAME" ] = self.Name\r
2051\r
2052 self._Macro["ARCH" ] = self.Arch\r
2053 self._Macro["TOOLCHAIN" ] = self.ToolChain\r
2054 self._Macro["TOOLCHAIN_TAG" ] = self.ToolChain\r
0d2711a6 2055 self._Macro["TOOL_CHAIN_TAG" ] = self.ToolChain\r
52302d4d
LG
2056 self._Macro["TARGET" ] = self.BuildTarget\r
2057\r
2058 self._Macro["BUILD_DIR" ] = self.PlatformInfo.BuildDir\r
2059 self._Macro["BIN_DIR" ] = os.path.join(self.PlatformInfo.BuildDir, self.Arch)\r
2060 self._Macro["LIB_DIR" ] = os.path.join(self.PlatformInfo.BuildDir, self.Arch)\r
2061 self._Macro["MODULE_BUILD_DIR" ] = self.BuildDir\r
2062 self._Macro["OUTPUT_DIR" ] = self.OutputDir\r
2063 self._Macro["DEBUG_DIR" ] = self.DebugDir\r
2064 return self._Macro\r
2065\r
2066 ## Return the module build data object\r
2067 def _GetModule(self):\r
2068 if self._Module == None:\r
0d2711a6 2069 self._Module = self.Workspace.BuildDatabase[self.MetaFile, self.Arch, self.BuildTarget, self.ToolChain]\r
52302d4d
LG
2070 return self._Module\r
2071\r
2072 ## Return the module name\r
2073 def _GetBaseName(self):\r
2074 return self.Module.BaseName\r
2075\r
b36d134f
LG
2076 ## Return the module DxsFile if exist\r
2077 def _GetDxsFile(self):\r
2078 return self.Module.DxsFile\r
2079\r
52302d4d
LG
2080 ## Return the module SourceOverridePath\r
2081 def _GetSourceOverridePath(self):\r
2082 return self.Module.SourceOverridePath\r
2083\r
2084 ## Return the module meta-file GUID\r
2085 def _GetGuid(self):\r
2086 return self.Module.Guid\r
2087\r
2088 ## Return the module version\r
2089 def _GetVersion(self):\r
2090 return self.Module.Version\r
2091\r
2092 ## Return the module type\r
2093 def _GetModuleType(self):\r
2094 return self.Module.ModuleType\r
2095\r
b36d134f 2096 ## Return the component type (for Edk.x style of module)\r
52302d4d
LG
2097 def _GetComponentType(self):\r
2098 return self.Module.ComponentType\r
2099\r
2100 ## Return the build type\r
2101 def _GetBuildType(self):\r
2102 return self.Module.BuildType\r
2103\r
2104 ## Return the PCD_IS_DRIVER setting\r
2105 def _GetPcdIsDriver(self):\r
2106 return self.Module.PcdIsDriver\r
2107\r
2108 ## Return the autogen version, i.e. module meta-file version\r
2109 def _GetAutoGenVersion(self):\r
2110 return self.Module.AutoGenVersion\r
2111\r
2112 ## Check if the module is library or not\r
2113 def _IsLibrary(self):\r
2114 if self._LibraryFlag == None:\r
2115 if self.Module.LibraryClass != None and self.Module.LibraryClass != []:\r
2116 self._LibraryFlag = True\r
2117 else:\r
2118 self._LibraryFlag = False\r
2119 return self._LibraryFlag\r
2120\r
e8a47801
LG
2121 ## Check if the module is binary module or not\r
2122 def _IsBinaryModule(self):\r
2123 return self.Module.IsBinaryModule\r
2124\r
52302d4d
LG
2125 ## Return the directory to store intermediate files of the module\r
2126 def _GetBuildDir(self):\r
2127 if self._BuildDir == None:\r
2128 self._BuildDir = path.join(\r
2129 self.PlatformInfo.BuildDir,\r
2130 self.Arch,\r
2131 self.SourceDir,\r
2132 self.MetaFile.BaseName\r
2133 )\r
2134 CreateDirectory(self._BuildDir)\r
2135 return self._BuildDir\r
2136\r
2137 ## Return the directory to store the intermediate object files of the mdoule\r
2138 def _GetOutputDir(self):\r
2139 if self._OutputDir == None:\r
2140 self._OutputDir = path.join(self.BuildDir, "OUTPUT")\r
2141 CreateDirectory(self._OutputDir)\r
2142 return self._OutputDir\r
2143\r
2144 ## Return the directory to store auto-gened source files of the mdoule\r
2145 def _GetDebugDir(self):\r
2146 if self._DebugDir == None:\r
2147 self._DebugDir = path.join(self.BuildDir, "DEBUG")\r
2148 CreateDirectory(self._DebugDir)\r
2149 return self._DebugDir\r
2150\r
2151 ## Return the path of custom file\r
2152 def _GetCustomMakefile(self):\r
2153 if self._CustomMakefile == None:\r
2154 self._CustomMakefile = {}\r
2155 for Type in self.Module.CustomMakefile:\r
2156 if Type in gMakeTypeMap:\r
2157 MakeType = gMakeTypeMap[Type]\r
2158 else:\r
2159 MakeType = 'nmake'\r
2160 if self.SourceOverrideDir != None:\r
2161 File = os.path.join(self.SourceOverrideDir, self.Module.CustomMakefile[Type])\r
2162 if not os.path.exists(File):\r
2163 File = os.path.join(self.SourceDir, self.Module.CustomMakefile[Type])\r
2164 else:\r
2165 File = os.path.join(self.SourceDir, self.Module.CustomMakefile[Type])\r
2166 self._CustomMakefile[MakeType] = File\r
2167 return self._CustomMakefile\r
2168\r
2169 ## Return the directory of the makefile\r
2170 #\r
2171 # @retval string The directory string of module's makefile\r
2172 #\r
2173 def _GetMakeFileDir(self):\r
2174 return self.BuildDir\r
2175\r
2176 ## Return build command string\r
2177 #\r
2178 # @retval string Build command string\r
2179 #\r
2180 def _GetBuildCommand(self):\r
2181 return self.PlatformInfo.BuildCommand\r
2182\r
2183 ## Get object list of all packages the module and its dependent libraries belong to\r
2184 #\r
2185 # @retval list The list of package object\r
2186 #\r
2187 def _GetDerivedPackageList(self):\r
2188 PackageList = []\r
2189 for M in [self.Module] + self.DependentLibraryList:\r
2190 for Package in M.Packages:\r
2191 if Package in PackageList:\r
2192 continue\r
2193 PackageList.append(Package)\r
2194 return PackageList\r
2195\r
2196 ## Merge dependency expression\r
2197 #\r
2198 # @retval list The token list of the dependency expression after parsed\r
2199 #\r
2200 def _GetDepexTokenList(self):\r
2201 if self._DepexList == None:\r
2202 self._DepexList = {}\r
b36d134f 2203 if self.DxsFile or self.IsLibrary or TAB_DEPENDENCY_EXPRESSION_FILE in self.FileTypes:\r
52302d4d
LG
2204 return self._DepexList\r
2205\r
2206 self._DepexList[self.ModuleType] = []\r
2207\r
2208 for ModuleType in self._DepexList:\r
2209 DepexList = self._DepexList[ModuleType]\r
2210 #\r
2211 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion\r
2212 #\r
2213 for M in [self.Module] + self.DependentLibraryList:\r
2214 Inherited = False\r
2215 for D in M.Depex[self.Arch, ModuleType]:\r
2216 if DepexList != []:\r
2217 DepexList.append('AND')\r
2218 DepexList.append('(')\r
2219 DepexList.extend(D)\r
2220 if DepexList[-1] == 'END': # no need of a END at this time\r
2221 DepexList.pop()\r
2222 DepexList.append(')')\r
2223 Inherited = True\r
2224 if Inherited:\r
2225 EdkLogger.verbose("DEPEX[%s] (+%s) = %s" % (self.Name, M.BaseName, DepexList))\r
2226 if 'BEFORE' in DepexList or 'AFTER' in DepexList:\r
2227 break\r
2228 if len(DepexList) > 0:\r
2229 EdkLogger.verbose('')\r
2230 return self._DepexList\r
2231\r
2232 ## Merge dependency expression\r
2233 #\r
2234 # @retval list The token list of the dependency expression after parsed\r
2235 #\r
2236 def _GetDepexExpressionTokenList(self):\r
2237 if self._DepexExpressionList == None:\r
2238 self._DepexExpressionList = {}\r
b36d134f 2239 if self.DxsFile or self.IsLibrary or TAB_DEPENDENCY_EXPRESSION_FILE in self.FileTypes:\r
52302d4d
LG
2240 return self._DepexExpressionList\r
2241\r
2242 self._DepexExpressionList[self.ModuleType] = ''\r
2243\r
2244 for ModuleType in self._DepexExpressionList:\r
2245 DepexExpressionList = self._DepexExpressionList[ModuleType]\r
2246 #\r
2247 # Append depex from dependent libraries, if not "BEFORE", "AFTER" expresion\r
2248 #\r
2249 for M in [self.Module] + self.DependentLibraryList:\r
2250 Inherited = False\r
2251 for D in M.DepexExpression[self.Arch, ModuleType]:\r
2252 if DepexExpressionList != '':\r
2253 DepexExpressionList += ' AND '\r
2254 DepexExpressionList += '('\r
2255 DepexExpressionList += D\r
2256 DepexExpressionList = DepexExpressionList.rstrip('END').strip()\r
2257 DepexExpressionList += ')'\r
2258 Inherited = True\r
2259 if Inherited:\r
2260 EdkLogger.verbose("DEPEX[%s] (+%s) = %s" % (self.Name, M.BaseName, DepexExpressionList))\r
2261 if 'BEFORE' in DepexExpressionList or 'AFTER' in DepexExpressionList:\r
2262 break\r
2263 if len(DepexExpressionList) > 0:\r
2264 EdkLogger.verbose('')\r
2265 self._DepexExpressionList[ModuleType] = DepexExpressionList\r
2266 return self._DepexExpressionList\r
2267\r
2268 ## Return the list of specification version required for the module\r
2269 #\r
2270 # @retval list The list of specification defined in module file\r
2271 #\r
2272 def _GetSpecification(self):\r
2273 return self.Module.Specification\r
2274\r
2275 ## Tool option for the module build\r
2276 #\r
2277 # @param PlatformInfo The object of PlatformBuildInfo\r
2278 # @retval dict The dict containing valid options\r
2279 #\r
2280 def _GetModuleBuildOption(self):\r
2281 if self._BuildOption == None:\r
2282 self._BuildOption = self.PlatformInfo.ApplyBuildOption(self.Module)\r
2283 return self._BuildOption\r
2284\r
79b74a03
LG
2285 ## Get include path list from tool option for the module build\r
2286 #\r
2287 # @retval list The include path list\r
2288 #\r
2289 def _GetBuildOptionIncPathList(self):\r
2290 if self._BuildOptionIncPathList == None:\r
2291 #\r
d40b2ee6 2292 # Regular expression for finding Include Directories, the difference between MSFT and INTEL/GCC/RVCT\r
79b74a03
LG
2293 # is the former use /I , the Latter used -I to specify include directories\r
2294 #\r
2295 if self.PlatformInfo.ToolChainFamily in ('MSFT'):\r
2296 gBuildOptIncludePattern = re.compile(r"(?:.*?)/I[ \t]*([^ ]*)", re.MULTILINE|re.DOTALL)\r
d40b2ee6 2297 elif self.PlatformInfo.ToolChainFamily in ('INTEL', 'GCC', 'RVCT'):\r
79b74a03 2298 gBuildOptIncludePattern = re.compile(r"(?:.*?)-I[ \t]*([^ ]*)", re.MULTILINE|re.DOTALL)\r
d40b2ee6
LG
2299 else:\r
2300 #\r
2301 # New ToolChainFamily, don't known whether there is option to specify include directories\r
2302 #\r
2303 self._BuildOptionIncPathList = []\r
2304 return self._BuildOptionIncPathList\r
79b74a03
LG
2305 \r
2306 BuildOptionIncPathList = []\r
2307 for Tool in ('CC', 'PP', 'VFRPP', 'ASLPP', 'ASLCC', 'APP', 'ASM'):\r
2308 Attr = 'FLAGS'\r
2309 try:\r
2310 FlagOption = self.BuildOption[Tool][Attr]\r
2311 except KeyError:\r
2312 FlagOption = ''\r
2313 \r
d40b2ee6
LG
2314 if self.PlatformInfo.ToolChainFamily != 'RVCT':\r
2315 IncPathList = [NormPath(Path, self.Macros) for Path in gBuildOptIncludePattern.findall(FlagOption)]\r
2316 else:\r
2317 #\r
2318 # RVCT may specify a list of directory seperated by commas\r
2319 #\r
2320 IncPathList = []\r
2321 for Path in gBuildOptIncludePattern.findall(FlagOption):\r
2322 PathList = GetSplitList(Path, TAB_COMMA_SPLIT)\r
2323 IncPathList += [NormPath(PathEntry, self.Macros) for PathEntry in PathList]\r
2324\r
79b74a03
LG
2325 #\r
2326 # EDK II modules must not reference header files outside of the packages they depend on or \r
2327 # within the module's directory tree. Report error if violation.\r
2328 #\r
2329 if self.AutoGenVersion >= 0x00010005 and len(IncPathList) > 0:\r
2330 for Path in IncPathList:\r
2331 if (Path not in self.IncludePathList) and (CommonPath([Path, self.MetaFile.Dir]) != self.MetaFile.Dir):\r
2332 ErrMsg = "The include directory for the EDK II module in this line is invalid %s specified in %s FLAGS '%s'" % (Path, Tool, FlagOption) \r
2333 EdkLogger.error("build", \r
2334 PARAMETER_INVALID,\r
2335 ExtraData = ErrMsg, \r
2336 File = str(self.MetaFile))\r
2337\r
2338 \r
2339 BuildOptionIncPathList += IncPathList\r
2340 \r
2341 self._BuildOptionIncPathList = BuildOptionIncPathList\r
2342 \r
2343 return self._BuildOptionIncPathList\r
2344 \r
52302d4d
LG
2345 ## Return a list of files which can be built from source\r
2346 #\r
2347 # What kind of files can be built is determined by build rules in\r
2348 # $(WORKSPACE)/Conf/build_rule.txt and toolchain family.\r
2349 #\r
2350 def _GetSourceFileList(self):\r
2351 if self._SourceFileList == None:\r
2352 self._SourceFileList = []\r
2353 for F in self.Module.Sources:\r
2354 # match tool chain\r
08dd311f 2355 if F.TagName not in ("", "*", self.ToolChain):\r
52302d4d
LG
2356 EdkLogger.debug(EdkLogger.DEBUG_9, "The toolchain [%s] for processing file [%s] is found, "\r
2357 "but [%s] is needed" % (F.TagName, str(F), self.ToolChain))\r
2358 continue\r
2359 # match tool chain family\r
08dd311f 2360 if F.ToolChainFamily not in ("", "*", self.ToolChainFamily):\r
52302d4d
LG
2361 EdkLogger.debug(\r
2362 EdkLogger.DEBUG_0,\r
2363 "The file [%s] must be built by tools of [%s], " \\r
2364 "but current toolchain family is [%s]" \\r
2365 % (str(F), F.ToolChainFamily, self.ToolChainFamily))\r
2366 continue\r
2367\r
2368 # add the file path into search path list for file including\r
2369 if F.Dir not in self.IncludePathList and self.AutoGenVersion >= 0x00010005:\r
2370 self.IncludePathList.insert(0, F.Dir)\r
2371 self._SourceFileList.append(F)\r
2372 self._ApplyBuildRule(F, TAB_UNKNOWN_FILE)\r
2373 return self._SourceFileList\r
2374\r
2375 ## Return the list of unicode files\r
2376 def _GetUnicodeFileList(self):\r
2377 if self._UnicodeFileList == None:\r
2378 if TAB_UNICODE_FILE in self.FileTypes:\r
2379 self._UnicodeFileList = self.FileTypes[TAB_UNICODE_FILE]\r
2380 else:\r
2381 self._UnicodeFileList = []\r
2382 return self._UnicodeFileList\r
2383\r
2384 ## Return a list of files which can be built from binary\r
2385 #\r
2386 # "Build" binary files are just to copy them to build directory.\r
2387 #\r
2388 # @retval list The list of files which can be built later\r
2389 #\r
2390 def _GetBinaryFiles(self):\r
2391 if self._BinaryFileList == None:\r
2392 self._BinaryFileList = []\r
2393 for F in self.Module.Binaries:\r
2394 if F.Target not in ['COMMON', '*'] and F.Target != self.BuildTarget:\r
2395 continue\r
2396 self._BinaryFileList.append(F)\r
2397 self._ApplyBuildRule(F, F.Type)\r
2398 return self._BinaryFileList\r
2399\r
2400 def _GetBuildRules(self):\r
2401 if self._BuildRules == None:\r
2402 BuildRules = {}\r
2403 BuildRuleDatabase = self.PlatformInfo.BuildRule\r
2404 for Type in BuildRuleDatabase.FileTypeList:\r
2405 #first try getting build rule by BuildRuleFamily\r
2406 RuleObject = BuildRuleDatabase[Type, self.BuildType, self.Arch, self.BuildRuleFamily]\r
2407 if not RuleObject:\r
2408 # build type is always module type, but ...\r
2409 if self.ModuleType != self.BuildType:\r
2410 RuleObject = BuildRuleDatabase[Type, self.ModuleType, self.Arch, self.BuildRuleFamily]\r
2411 #second try getting build rule by ToolChainFamily\r
2412 if not RuleObject:\r
2413 RuleObject = BuildRuleDatabase[Type, self.BuildType, self.Arch, self.ToolChainFamily]\r
2414 if not RuleObject:\r
2415 # build type is always module type, but ...\r
2416 if self.ModuleType != self.BuildType:\r
2417 RuleObject = BuildRuleDatabase[Type, self.ModuleType, self.Arch, self.ToolChainFamily]\r
2418 if not RuleObject:\r
2419 continue\r
2420 RuleObject = RuleObject.Instantiate(self.Macros)\r
2421 BuildRules[Type] = RuleObject\r
2422 for Ext in RuleObject.SourceFileExtList:\r
2423 BuildRules[Ext] = RuleObject\r
2424 self._BuildRules = BuildRules\r
2425 return self._BuildRules\r
2426\r
2427 def _ApplyBuildRule(self, File, FileType):\r
2428 if self._BuildTargets == None:\r
2429 self._IntroBuildTargetList = set()\r
2430 self._FinalBuildTargetList = set()\r
2431 self._BuildTargets = {}\r
2432 self._FileTypes = {}\r
2433\r
2434 LastTarget = None\r
2435 RuleChain = []\r
2436 SourceList = [File]\r
2437 Index = 0\r
2438 while Index < len(SourceList):\r
2439 Source = SourceList[Index]\r
2440 Index = Index + 1\r
2441\r
2442 if Source != File:\r
2443 CreateDirectory(Source.Dir)\r
2444\r
2445 if File.IsBinary and File == Source and self._BinaryFileList != None and File in self._BinaryFileList:\r
da92f276
LG
2446 # Skip all files that are not binary libraries\r
2447 if not self.IsLibrary:\r
0d2711a6 2448 continue \r
52302d4d
LG
2449 RuleObject = self.BuildRules[TAB_DEFAULT_BINARY_FILE]\r
2450 elif FileType in self.BuildRules:\r
2451 RuleObject = self.BuildRules[FileType]\r
2452 elif Source.Ext in self.BuildRules:\r
2453 RuleObject = self.BuildRules[Source.Ext]\r
2454 else:\r
2455 # stop at no more rules\r
2456 if LastTarget:\r
2457 self._FinalBuildTargetList.add(LastTarget)\r
2458 break\r
2459\r
2460 FileType = RuleObject.SourceFileType\r
2461 if FileType not in self._FileTypes:\r
2462 self._FileTypes[FileType] = set()\r
2463 self._FileTypes[FileType].add(Source)\r
2464\r
2465 # stop at STATIC_LIBRARY for library\r
2466 if self.IsLibrary and FileType == TAB_STATIC_LIBRARY:\r
2467 if LastTarget:\r
2468 self._FinalBuildTargetList.add(LastTarget)\r
2469 break\r
2470\r
2471 Target = RuleObject.Apply(Source)\r
2472 if not Target:\r
2473 if LastTarget:\r
2474 self._FinalBuildTargetList.add(LastTarget)\r
2475 break\r
2476 elif not Target.Outputs:\r
2477 # Only do build for target with outputs\r
2478 self._FinalBuildTargetList.add(Target)\r
2479\r
2480 if FileType not in self._BuildTargets:\r
2481 self._BuildTargets[FileType] = set()\r
2482 self._BuildTargets[FileType].add(Target)\r
2483\r
2484 if not Source.IsBinary and Source == File:\r
2485 self._IntroBuildTargetList.add(Target)\r
2486\r
2487 # to avoid cyclic rule\r
2488 if FileType in RuleChain:\r
2489 break\r
2490\r
2491 RuleChain.append(FileType)\r
2492 SourceList.extend(Target.Outputs)\r
2493 LastTarget = Target\r
2494 FileType = TAB_UNKNOWN_FILE\r
2495\r
2496 def _GetTargets(self):\r
2497 if self._BuildTargets == None:\r
2498 self._IntroBuildTargetList = set()\r
2499 self._FinalBuildTargetList = set()\r
2500 self._BuildTargets = {}\r
2501 self._FileTypes = {}\r
2502\r
b36d134f 2503 #TRICK: call _GetSourceFileList to apply build rule for source files\r
52302d4d
LG
2504 if self.SourceFileList:\r
2505 pass\r
2506\r
2507 #TRICK: call _GetBinaryFileList to apply build rule for binary files\r
2508 if self.BinaryFileList:\r
2509 pass\r
2510\r
2511 return self._BuildTargets\r
2512\r
2513 def _GetIntroTargetList(self):\r
2514 self._GetTargets()\r
2515 return self._IntroBuildTargetList\r
2516\r
2517 def _GetFinalTargetList(self):\r
2518 self._GetTargets()\r
2519 return self._FinalBuildTargetList\r
2520\r
2521 def _GetFileTypes(self):\r
2522 self._GetTargets()\r
2523 return self._FileTypes\r
2524\r
2525 ## Get the list of package object the module depends on\r
2526 #\r
2527 # @retval list The package object list\r
2528 #\r
2529 def _GetDependentPackageList(self):\r
2530 return self.Module.Packages\r
2531\r
2532 ## Return the list of auto-generated code file\r
2533 #\r
2534 # @retval list The list of auto-generated file\r
2535 #\r
2536 def _GetAutoGenFileList(self):\r
2537 UniStringAutoGenC = True\r
4234283c 2538 UniStringBinBuffer = StringIO()\r
52302d4d 2539 if self.BuildType == 'UEFI_HII':\r
52302d4d
LG
2540 UniStringAutoGenC = False\r
2541 if self._AutoGenFileList == None:\r
2542 self._AutoGenFileList = {}\r
2543 AutoGenC = TemplateString()\r
2544 AutoGenH = TemplateString()\r
2545 StringH = TemplateString()\r
2546 GenC.CreateCode(self, AutoGenC, AutoGenH, StringH, UniStringAutoGenC, UniStringBinBuffer)\r
2547 if str(AutoGenC) != "" and TAB_C_CODE_FILE in self.FileTypes:\r
2548 AutoFile = PathClass(gAutoGenCodeFileName, self.DebugDir)\r
2549 self._AutoGenFileList[AutoFile] = str(AutoGenC)\r
2550 self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)\r
2551 if str(AutoGenH) != "":\r
2552 AutoFile = PathClass(gAutoGenHeaderFileName, self.DebugDir)\r
2553 self._AutoGenFileList[AutoFile] = str(AutoGenH)\r
2554 self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)\r
2555 if str(StringH) != "":\r
2556 AutoFile = PathClass(gAutoGenStringFileName % {"module_name":self.Name}, self.DebugDir)\r
2557 self._AutoGenFileList[AutoFile] = str(StringH)\r
2558 self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)\r
2559 if UniStringBinBuffer != None and UniStringBinBuffer.getvalue() != "":\r
2560 AutoFile = PathClass(gAutoGenStringFormFileName % {"module_name":self.Name}, self.OutputDir)\r
2561 self._AutoGenFileList[AutoFile] = UniStringBinBuffer.getvalue()\r
2562 AutoFile.IsBinary = True\r
2563 self._ApplyBuildRule(AutoFile, TAB_UNKNOWN_FILE)\r
2564 if UniStringBinBuffer != None:\r
2565 UniStringBinBuffer.close()\r
2566 return self._AutoGenFileList\r
2567\r
2568 ## Return the list of library modules explicitly or implicityly used by this module\r
2569 def _GetLibraryList(self):\r
2570 if self._DependentLibraryList == None:\r
2571 # only merge library classes and PCD for non-library module\r
2572 if self.IsLibrary:\r
2573 self._DependentLibraryList = []\r
2574 else:\r
2575 if self.AutoGenVersion < 0x00010005:\r
2576 self._DependentLibraryList = self.PlatformInfo.ResolveLibraryReference(self.Module)\r
2577 else:\r
2578 self._DependentLibraryList = self.PlatformInfo.ApplyLibraryInstance(self.Module)\r
2579 return self._DependentLibraryList\r
2580\r
e8a47801
LG
2581 @staticmethod\r
2582 def UpdateComments(Recver, Src):\r
2583 for Key in Src:\r
2584 if Key not in Recver:\r
2585 Recver[Key] = []\r
2586 Recver[Key].extend(Src[Key])\r
52302d4d
LG
2587 ## Get the list of PCDs from current module\r
2588 #\r
2589 # @retval list The list of PCD\r
2590 #\r
2591 def _GetModulePcdList(self):\r
2592 if self._ModulePcdList == None:\r
2593 # apply PCD settings from platform\r
2594 self._ModulePcdList = self.PlatformInfo.ApplyPcdSetting(self.Module, self.Module.Pcds)\r
e8a47801 2595 self.UpdateComments(self._PcdComments, self.Module.PcdComments)\r
52302d4d
LG
2596 return self._ModulePcdList\r
2597\r
2598 ## Get the list of PCDs from dependent libraries\r
2599 #\r
2600 # @retval list The list of PCD\r
2601 #\r
2602 def _GetLibraryPcdList(self):\r
2603 if self._LibraryPcdList == None:\r
79b74a03 2604 Pcds = sdict()\r
52302d4d
LG
2605 if not self.IsLibrary:\r
2606 # get PCDs from dependent libraries\r
2607 for Library in self.DependentLibraryList:\r
e8a47801 2608 self.UpdateComments(self._PcdComments, Library.PcdComments)\r
52302d4d
LG
2609 for Key in Library.Pcds:\r
2610 # skip duplicated PCDs\r
2611 if Key in self.Module.Pcds or Key in Pcds:\r
2612 continue\r
2613 Pcds[Key] = copy.copy(Library.Pcds[Key])\r
2614 # apply PCD settings from platform\r
2615 self._LibraryPcdList = self.PlatformInfo.ApplyPcdSetting(self.Module, Pcds)\r
2616 else:\r
2617 self._LibraryPcdList = []\r
2618 return self._LibraryPcdList\r
2619\r
2620 ## Get the GUID value mapping\r
2621 #\r
2622 # @retval dict The mapping between GUID cname and its value\r
2623 #\r
2624 def _GetGuidList(self):\r
2625 if self._GuidList == None:\r
2626 self._GuidList = self.Module.Guids\r
2627 for Library in self.DependentLibraryList:\r
2628 self._GuidList.update(Library.Guids)\r
e8a47801
LG
2629 self.UpdateComments(self._GuidComments, Library.GuidComments)\r
2630 self.UpdateComments(self._GuidComments, self.Module.GuidComments)\r
52302d4d
LG
2631 return self._GuidList\r
2632\r
e8a47801
LG
2633 def GetGuidsUsedByPcd(self):\r
2634 if self._GuidsUsedByPcd == None:\r
2635 self._GuidsUsedByPcd = sdict()\r
2636 self._GuidsUsedByPcd.update(self.Module.GetGuidsUsedByPcd())\r
2637 for Library in self.DependentLibraryList:\r
2638 self._GuidsUsedByPcd.update(Library.GetGuidsUsedByPcd())\r
2639 return self._GuidsUsedByPcd\r
52302d4d
LG
2640 ## Get the protocol value mapping\r
2641 #\r
2642 # @retval dict The mapping between protocol cname and its value\r
2643 #\r
2644 def _GetProtocolList(self):\r
2645 if self._ProtocolList == None:\r
2646 self._ProtocolList = self.Module.Protocols\r
2647 for Library in self.DependentLibraryList:\r
2648 self._ProtocolList.update(Library.Protocols)\r
e8a47801
LG
2649 self.UpdateComments(self._ProtocolComments, Library.ProtocolComments)\r
2650 self.UpdateComments(self._ProtocolComments, self.Module.ProtocolComments)\r
52302d4d
LG
2651 return self._ProtocolList\r
2652\r
2653 ## Get the PPI value mapping\r
2654 #\r
2655 # @retval dict The mapping between PPI cname and its value\r
2656 #\r
2657 def _GetPpiList(self):\r
2658 if self._PpiList == None:\r
2659 self._PpiList = self.Module.Ppis\r
2660 for Library in self.DependentLibraryList:\r
2661 self._PpiList.update(Library.Ppis)\r
e8a47801
LG
2662 self.UpdateComments(self._PpiComments, Library.PpiComments)\r
2663 self.UpdateComments(self._PpiComments, self.Module.PpiComments)\r
52302d4d
LG
2664 return self._PpiList\r
2665\r
2666 ## Get the list of include search path\r
2667 #\r
2668 # @retval list The list path\r
2669 #\r
2670 def _GetIncludePathList(self):\r
2671 if self._IncludePathList == None:\r
2672 self._IncludePathList = []\r
2673 if self.AutoGenVersion < 0x00010005:\r
2674 for Inc in self.Module.Includes:\r
2675 if Inc not in self._IncludePathList:\r
2676 self._IncludePathList.append(Inc)\r
b36d134f 2677 # for Edk modules\r
52302d4d
LG
2678 Inc = path.join(Inc, self.Arch.capitalize())\r
2679 if os.path.exists(Inc) and Inc not in self._IncludePathList:\r
2680 self._IncludePathList.append(Inc)\r
b36d134f 2681 # 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
2682 self._IncludePathList.append(self.DebugDir)\r
2683 else:\r
2684 self._IncludePathList.append(self.MetaFile.Dir)\r
2685 self._IncludePathList.append(self.DebugDir)\r
2686\r
2687 for Package in self.Module.Packages:\r
2688 PackageDir = path.join(self.WorkspaceDir, Package.MetaFile.Dir)\r
2689 if PackageDir not in self._IncludePathList:\r
2690 self._IncludePathList.append(PackageDir)\r
2691 for Inc in Package.Includes:\r
2692 if Inc not in self._IncludePathList:\r
2693 self._IncludePathList.append(str(Inc))\r
2694 return self._IncludePathList\r
2695\r
da92f276
LG
2696 ## Create AsBuilt INF file the module\r
2697 #\r
2698 def CreateAsBuiltInf(self):\r
2699 if self.IsAsBuiltInfCreated:\r
2700 return\r
2701 \r
2702 # Skip the following code for EDK I inf\r
2703 if self.AutoGenVersion < 0x00010005:\r
2704 return\r
2705 \r
2706 # Skip the following code for libraries\r
2707 if self.IsLibrary:\r
2708 return\r
2709 \r
2710 # Skip the following code for modules with no source files\r
2711 if self.SourceFileList == None or self.SourceFileList == []:\r
2712 return\r
2713\r
2714 # Skip the following code for modules without any binary files\r
2715 if self.BinaryFileList <> None and self.BinaryFileList <> []:\r
2716 return\r
2717 \r
2718 ### TODO: How to handles mixed source and binary modules\r
2719\r
e8a47801 2720 # Find all DynamicEx and PatchableInModule PCDs used by this module and dependent libraries\r
da92f276
LG
2721 # Also find all packages that the DynamicEx PCDs depend on\r
2722 Pcds = []\r
e8a47801 2723 PatchablePcds = {}\r
da92f276 2724 Packages = [] \r
e8a47801
LG
2725 PcdCheckList = []\r
2726 PcdTokenSpaceList = []\r
da92f276 2727 for Pcd in self.ModulePcdList + self.LibraryPcdList:\r
e8a47801
LG
2728 if Pcd.Type == TAB_PCDS_PATCHABLE_IN_MODULE:\r
2729 PatchablePcds[Pcd.TokenCName] = Pcd\r
2730 PcdCheckList.append((Pcd.TokenCName, Pcd.TokenSpaceGuidCName, 'PatchableInModule'))\r
2731 elif Pcd.Type in GenC.gDynamicExPcd:\r
2732 if Pcd not in Pcds:\r
2733 Pcds += [Pcd]\r
2734 PcdCheckList.append((Pcd.TokenCName, Pcd.TokenSpaceGuidCName, 'DynamicEx'))\r
2735 PcdCheckList.append((Pcd.TokenCName, Pcd.TokenSpaceGuidCName, 'Dynamic'))\r
2736 PcdTokenSpaceList.append(Pcd.TokenSpaceGuidCName)\r
2737 GuidList = sdict()\r
2738 GuidList.update(self.GuidList)\r
2739 for TokenSpace in self.GetGuidsUsedByPcd():\r
2740 # If token space is not referred by patch PCD or Ex PCD, remove the GUID from GUID list\r
2741 # The GUIDs in GUIDs section should really be the GUIDs in source INF or referred by Ex an patch PCDs\r
2742 if TokenSpace not in PcdTokenSpaceList and TokenSpace in GuidList:\r
2743 GuidList.pop(TokenSpace)\r
2744 CheckList = (GuidList, self.PpiList, self.ProtocolList, PcdCheckList)\r
2745 for Package in self.DerivedPackageList:\r
2746 if Package in Packages:\r
2747 continue\r
2748 BeChecked = (Package.Guids, Package.Ppis, Package.Protocols, Package.Pcds)\r
2749 Found = False\r
2750 for Index in range(len(BeChecked)):\r
2751 for Item in CheckList[Index]:\r
2752 if Item in BeChecked[Index]:\r
2753 Packages += [Package]\r
2754 Found = True\r
2755 break\r
2756 if Found: break\r
da92f276
LG
2757\r
2758 ModuleType = self.ModuleType\r
2759 if ModuleType == 'UEFI_DRIVER' and self.DepexGenerated:\r
e8a47801
LG
2760 ModuleType = 'DXE_DRIVER'\r
2761\r
2762 DriverType = ''\r
2763 if self.PcdIsDriver != '':\r
2764 DriverType = self.PcdIsDriver\r
da92f276
LG
2765\r
2766 AsBuiltInfDict = {\r
2767 'module_name' : self.Name,\r
2768 'module_guid' : self.Guid,\r
2769 'module_module_type' : ModuleType,\r
2770 'module_version_string' : self.Version,\r
e8a47801 2771 'pcd_is_driver_string' : [],\r
da92f276
LG
2772 'module_uefi_specification_version' : [],\r
2773 'module_pi_specification_version' : [],\r
2774 'module_arch' : self.Arch,\r
2775 'package_item' : ['%s' % (Package.MetaFile.File.replace('\\','/')) for Package in Packages],\r
2776 'binary_item' : [],\r
e8a47801 2777 'patchablepcd_item' : [],\r
da92f276 2778 'pcd_item' : [],\r
e8a47801
LG
2779 'protocol_item' : [],\r
2780 'ppi_item' : [],\r
2781 'guid_item' : [],\r
2782 'flags_item' : [],\r
2783 'libraryclasses_item' : []\r
da92f276 2784 }\r
e8a47801
LG
2785 AsBuiltInfDict['module_inf_version'] = '0x%08x' % self.AutoGenVersion\r
2786 if DriverType:\r
2787 AsBuiltInfDict['pcd_is_driver_string'] += [DriverType]\r
da92f276
LG
2788\r
2789 if 'UEFI_SPECIFICATION_VERSION' in self.Specification:\r
2790 AsBuiltInfDict['module_uefi_specification_version'] += [self.Specification['UEFI_SPECIFICATION_VERSION']]\r
2791 if 'PI_SPECIFICATION_VERSION' in self.Specification:\r
2792 AsBuiltInfDict['module_pi_specification_version'] += [self.Specification['PI_SPECIFICATION_VERSION']]\r
2793\r
2794 OutputDir = self.OutputDir.replace('\\','/').strip('/')\r
2795 if self.ModuleType in ['BASE', 'USER_DEFINED']:\r
2796 for Item in self.CodaTargetList:\r
2797 File = Item.Target.Path.replace('\\','/').strip('/').replace(OutputDir,'').strip('/')\r
2798 if Item.Target.Ext.lower() == '.aml': \r
2799 AsBuiltInfDict['binary_item'] += ['ASL|' + File]\r
2800 elif Item.Target.Ext.lower() == '.acpi': \r
2801 AsBuiltInfDict['binary_item'] += ['ACPI|' + File]\r
2802 else:\r
2803 AsBuiltInfDict['binary_item'] += ['BIN|' + File]\r
2804 else:\r
2805 for Item in self.CodaTargetList:\r
2806 File = Item.Target.Path.replace('\\','/').strip('/').replace(OutputDir,'').strip('/')\r
2807 if Item.Target.Ext.lower() == '.efi': \r
2808 AsBuiltInfDict['binary_item'] += ['PE32|' + self.Name + '.efi']\r
2809 else:\r
2810 AsBuiltInfDict['binary_item'] += ['BIN|' + File]\r
2811 if self.DepexGenerated:\r
2812 if self.ModuleType in ['PEIM']:\r
2813 AsBuiltInfDict['binary_item'] += ['PEI_DEPEX|' + self.Name + '.depex']\r
2814 if self.ModuleType in ['DXE_DRIVER','DXE_RUNTIME_DRIVER','DXE_SAL_DRIVER','UEFI_DRIVER']:\r
2815 AsBuiltInfDict['binary_item'] += ['DXE_DEPEX|' + self.Name + '.depex']\r
2816 if self.ModuleType in ['DXE_SMM_DRIVER']:\r
2817 AsBuiltInfDict['binary_item'] += ['SMM_DEPEX|' + self.Name + '.depex']\r
2818\r
e8a47801
LG
2819 for Root, Dirs, Files in os.walk(OutputDir):\r
2820 for File in Files:\r
2821 if File.lower().endswith('.pdb'):\r
2822 AsBuiltInfDict['binary_item'] += ['DISPOSABLE|' + File]\r
2823 HeaderComments = self.Module.HeaderComments\r
2824 StartPos = 0\r
2825 for Index in range(len(HeaderComments)):\r
2826 if HeaderComments[Index].find('@BinaryHeader') != -1:\r
2827 HeaderComments[Index] = HeaderComments[Index].replace('@BinaryHeader', '@file')\r
2828 StartPos = Index\r
2829 break\r
2830 AsBuiltInfDict['header_comments'] = '\n'.join(HeaderComments[StartPos:]).replace(':#', '://')\r
2831 GenList = [\r
2832 (self.ProtocolList, self._ProtocolComments, 'protocol_item'),\r
2833 (self.PpiList, self._PpiComments, 'ppi_item'),\r
2834 (GuidList, self._GuidComments, 'guid_item')\r
2835 ]\r
2836 for Item in GenList:\r
2837 for CName in Item[0]:\r
2838 Comments = ''\r
2839 if CName in Item[1]:\r
2840 Comments = '\n '.join(Item[1][CName])\r
2841 Entry = CName\r
2842 if Comments:\r
2843 Entry = Comments + '\n ' + CName\r
2844 AsBuiltInfDict[Item[2]].append(Entry)\r
2845 PatchList = parsePcdInfoFromMapFile(\r
2846 os.path.join(self.OutputDir, self.Name + '.map'),\r
2847 os.path.join(self.OutputDir, self.Name + '.efi')\r
2848 )\r
2849 if PatchList:\r
2850 for PatchPcd in PatchList:\r
2851 if PatchPcd[0] not in PatchablePcds:\r
2852 continue\r
2853 Pcd = PatchablePcds[PatchPcd[0]]\r
2854 PcdValue = ''\r
2855 if Pcd.DatumType != 'VOID*':\r
2856 HexFormat = '0x%02x'\r
2857 if Pcd.DatumType == 'UINT16':\r
2858 HexFormat = '0x%04x'\r
2859 elif Pcd.DatumType == 'UINT32':\r
2860 HexFormat = '0x%08x'\r
2861 elif Pcd.DatumType == 'UINT64':\r
2862 HexFormat = '0x%016x'\r
2863 PcdValue = HexFormat % int(Pcd.DefaultValue, 0)\r
2864 else:\r
2865 if Pcd.MaxDatumSize == None or Pcd.MaxDatumSize == '':\r
2866 EdkLogger.error("build", AUTOGEN_ERROR,\r
2867 "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)\r
2868 )\r
2869 ArraySize = int(Pcd.MaxDatumSize, 0)\r
2870 PcdValue = Pcd.DefaultValue\r
2871 if PcdValue[0] != '{':\r
2872 Unicode = False\r
2873 if PcdValue[0] == 'L':\r
2874 Unicode = True\r
2875 PcdValue = PcdValue.lstrip('L')\r
2876 PcdValue = eval(PcdValue)\r
2877 NewValue = '{'\r
2878 for Index in range(0, len(PcdValue)):\r
2879 if Unicode:\r
2880 CharVal = ord(PcdValue[Index])\r
2881 NewValue = NewValue + '0x%02x' % (CharVal & 0x00FF) + ', ' \\r
2882 + '0x%02x' % (CharVal >> 8) + ', '\r
2883 else:\r
2884 NewValue = NewValue + '0x%02x' % (ord(PcdValue[Index]) % 0x100) + ', '\r
2885 Padding = '0x00, '\r
2886 if Unicode:\r
2887 Padding = Padding * 2\r
2888 ArraySize = ArraySize / 2\r
2889 if ArraySize < (len(PcdValue) + 1):\r
2890 EdkLogger.error("build", AUTOGEN_ERROR,\r
2891 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)\r
2892 )\r
2893 if ArraySize > len(PcdValue) + 1:\r
2894 NewValue = NewValue + Padding * (ArraySize - len(PcdValue) - 1)\r
2895 PcdValue = NewValue + Padding.strip().rstrip(',') + '}'\r
2896 elif len(PcdValue.split(',')) <= ArraySize:\r
2897 PcdValue = PcdValue.rstrip('}') + ', 0x00' * (ArraySize - len(PcdValue.split(',')))\r
2898 PcdValue += '}'\r
2899 else:\r
2900 EdkLogger.error("build", AUTOGEN_ERROR,\r
2901 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd.TokenSpaceGuidCName, Pcd.TokenCName)\r
2902 )\r
2903 PcdItem = '%s.%s|%s|0x%X' % \\r
2904 (Pcd.TokenSpaceGuidCName, Pcd.TokenCName, PcdValue, PatchPcd[1])\r
2905 PcdComments = ''\r
2906 if (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) in self._PcdComments:\r
2907 PcdComments = '\n '.join(self._PcdComments[Pcd.TokenSpaceGuidCName, Pcd.TokenCName])\r
2908 if PcdComments:\r
2909 PcdItem = PcdComments + '\n ' + PcdItem\r
2910 AsBuiltInfDict['patchablepcd_item'].append(PcdItem)\r
da92f276 2911 for Pcd in Pcds:\r
e8a47801
LG
2912 PcdComments = ''\r
2913 PcdCommentList = []\r
2914 HiiInfo = ''\r
2915 if Pcd.Type == TAB_PCDS_DYNAMIC_EX_HII:\r
2916 for SkuName in Pcd.SkuInfoList:\r
2917 SkuInfo = Pcd.SkuInfoList[SkuName]\r
2918 HiiInfo = '## %s|%s|%s' % (SkuInfo.VariableName, SkuInfo.VariableGuid, SkuInfo.VariableOffset)\r
2919 break\r
2920 if (Pcd.TokenSpaceGuidCName, Pcd.TokenCName) in self._PcdComments:\r
2921 PcdCommentList = self._PcdComments[Pcd.TokenSpaceGuidCName, Pcd.TokenCName][:]\r
2922 if HiiInfo:\r
2923 UsageIndex = -1\r
2924 for Index, Comment in enumerate(PcdCommentList):\r
2925 for Usage in UsageList:\r
2926 if Comment.find(Usage) != -1:\r
2927 UsageIndex = Index\r
2928 break\r
2929 if UsageIndex != -1:\r
2930 PcdCommentList[UsageIndex] = PcdCommentList[UsageIndex] + ' ' + HiiInfo\r
2931 else:\r
2932 PcdCommentList.append('## ' + HiiInfo)\r
2933 PcdComments = '\n '.join(PcdCommentList)\r
2934 PcdEntry = Pcd.TokenSpaceGuidCName + '.' + Pcd.TokenCName\r
2935 if PcdComments:\r
2936 PcdEntry = PcdComments + '\n ' + PcdEntry\r
2937 AsBuiltInfDict['pcd_item'] += [PcdEntry]\r
da92f276
LG
2938 for Item in self.BuildOption:\r
2939 if 'FLAGS' in self.BuildOption[Item]:\r
2940 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
2941 \r
2942 AsBuiltInf = TemplateString()\r
2943 AsBuiltInf.Append(gAsBuiltInfHeaderString.Replace(AsBuiltInfDict))\r
2944 \r
2945 SaveFileOnChange(os.path.join(self.OutputDir, self.Name + '.inf'), str(AsBuiltInf), False)\r
2946 \r
2947 self.IsAsBuiltInfCreated = True\r
2948 \r
52302d4d
LG
2949 ## Create makefile for the module and its dependent libraries\r
2950 #\r
2951 # @param CreateLibraryMakeFile Flag indicating if or not the makefiles of\r
2952 # dependent libraries will be created\r
2953 #\r
2954 def CreateMakeFile(self, CreateLibraryMakeFile=True):\r
2955 if self.IsMakeFileCreated:\r
2956 return\r
2957\r
2958 if not self.IsLibrary and CreateLibraryMakeFile:\r
2959 for LibraryAutoGen in self.LibraryAutoGenList:\r
2960 LibraryAutoGen.CreateMakeFile()\r
2961\r
2962 if len(self.CustomMakefile) == 0:\r
2963 Makefile = GenMake.ModuleMakefile(self)\r
2964 else:\r
2965 Makefile = GenMake.CustomMakefile(self)\r
2966 if Makefile.Generate():\r
2967 EdkLogger.debug(EdkLogger.DEBUG_9, "Generated makefile for module %s [%s]" %\r
2968 (self.Name, self.Arch))\r
2969 else:\r
2970 EdkLogger.debug(EdkLogger.DEBUG_9, "Skipped the generation of makefile for module %s [%s]" %\r
2971 (self.Name, self.Arch))\r
2972\r
2973 self.IsMakeFileCreated = True\r
2974\r
2975 ## Create autogen code for the module and its dependent libraries\r
2976 #\r
2977 # @param CreateLibraryCodeFile Flag indicating if or not the code of\r
2978 # dependent libraries will be created\r
2979 #\r
2980 def CreateCodeFile(self, CreateLibraryCodeFile=True):\r
2981 if self.IsCodeFileCreated:\r
2982 return\r
2983\r
e8a47801
LG
2984 # Need to generate PcdDatabase even PcdDriver is binarymodule\r
2985 if self.IsBinaryModule and self.PcdIsDriver != '':\r
2986 CreatePcdDatabaseCode(self, TemplateString(), TemplateString())\r
2987 return\r
2988\r
52302d4d
LG
2989 if not self.IsLibrary and CreateLibraryCodeFile:\r
2990 for LibraryAutoGen in self.LibraryAutoGenList:\r
2991 LibraryAutoGen.CreateCodeFile()\r
2992\r
2993 AutoGenList = []\r
2994 IgoredAutoGenList = []\r
2995\r
2996 for File in self.AutoGenFileList:\r
2997 if GenC.Generate(File.Path, self.AutoGenFileList[File], File.IsBinary):\r
b36d134f 2998 #Ignore Edk AutoGen.c\r
52302d4d
LG
2999 if self.AutoGenVersion < 0x00010005 and File.Name == 'AutoGen.c':\r
3000 continue\r
3001\r
3002 AutoGenList.append(str(File))\r
3003 else:\r
3004 IgoredAutoGenList.append(str(File))\r
3005\r
3006 # Skip the following code for EDK I inf\r
3007 if self.AutoGenVersion < 0x00010005:\r
3008 return\r
3009\r
3010 for ModuleType in self.DepexList:\r
40d841f6
LG
3011 # Ignore empty [depex] section or [depex] section for "USER_DEFINED" module\r
3012 if len(self.DepexList[ModuleType]) == 0 or ModuleType == "USER_DEFINED":\r
52302d4d 3013 continue\r
40d841f6 3014\r
52302d4d
LG
3015 Dpx = GenDepex.DependencyExpression(self.DepexList[ModuleType], ModuleType, True)\r
3016 DpxFile = gAutoGenDepexFileName % {"module_name" : self.Name}\r
3017\r
da92f276 3018 if len(Dpx.PostfixNotation) <> 0:\r
0d2711a6 3019 self.DepexGenerated = True\r
da92f276 3020\r
52302d4d
LG
3021 if Dpx.Generate(path.join(self.OutputDir, DpxFile)):\r
3022 AutoGenList.append(str(DpxFile))\r
3023 else:\r
3024 IgoredAutoGenList.append(str(DpxFile))\r
3025\r
3026 if IgoredAutoGenList == []:\r
3027 EdkLogger.debug(EdkLogger.DEBUG_9, "Generated [%s] files for module %s [%s]" %\r
3028 (" ".join(AutoGenList), self.Name, self.Arch))\r
3029 elif AutoGenList == []:\r
3030 EdkLogger.debug(EdkLogger.DEBUG_9, "Skipped the generation of [%s] files for module %s [%s]" %\r
3031 (" ".join(IgoredAutoGenList), self.Name, self.Arch))\r
3032 else:\r
3033 EdkLogger.debug(EdkLogger.DEBUG_9, "Generated [%s] (skipped %s) files for module %s [%s]" %\r
3034 (" ".join(AutoGenList), " ".join(IgoredAutoGenList), self.Name, self.Arch))\r
3035\r
3036 self.IsCodeFileCreated = True\r
3037 return AutoGenList\r
3038\r
3039 ## Summarize the ModuleAutoGen objects of all libraries used by this module\r
3040 def _GetLibraryAutoGenList(self):\r
3041 if self._LibraryAutoGenList == None:\r
3042 self._LibraryAutoGenList = []\r
3043 for Library in self.DependentLibraryList:\r
3044 La = ModuleAutoGen(\r
3045 self.Workspace,\r
3046 Library.MetaFile,\r
3047 self.BuildTarget,\r
3048 self.ToolChain,\r
3049 self.Arch,\r
3050 self.PlatformInfo.MetaFile\r
3051 )\r
3052 if La not in self._LibraryAutoGenList:\r
3053 self._LibraryAutoGenList.append(La)\r
3054 for Lib in La.CodaTargetList:\r
3055 self._ApplyBuildRule(Lib.Target, TAB_UNKNOWN_FILE)\r
3056 return self._LibraryAutoGenList\r
3057\r
52302d4d
LG
3058 Module = property(_GetModule)\r
3059 Name = property(_GetBaseName)\r
3060 Guid = property(_GetGuid)\r
3061 Version = property(_GetVersion)\r
3062 ModuleType = property(_GetModuleType)\r
3063 ComponentType = property(_GetComponentType)\r
3064 BuildType = property(_GetBuildType)\r
3065 PcdIsDriver = property(_GetPcdIsDriver)\r
3066 AutoGenVersion = property(_GetAutoGenVersion)\r
3067 Macros = property(_GetMacros)\r
3068 Specification = property(_GetSpecification)\r
3069\r
3070 IsLibrary = property(_IsLibrary)\r
e8a47801 3071 IsBinaryModule = property(_IsBinaryModule)\r
52302d4d
LG
3072 BuildDir = property(_GetBuildDir)\r
3073 OutputDir = property(_GetOutputDir)\r
3074 DebugDir = property(_GetDebugDir)\r
3075 MakeFileDir = property(_GetMakeFileDir)\r
3076 CustomMakefile = property(_GetCustomMakefile)\r
3077\r
3078 IncludePathList = property(_GetIncludePathList)\r
3079 AutoGenFileList = property(_GetAutoGenFileList)\r
3080 UnicodeFileList = property(_GetUnicodeFileList)\r
3081 SourceFileList = property(_GetSourceFileList)\r
3082 BinaryFileList = property(_GetBinaryFiles) # FileType : [File List]\r
3083 Targets = property(_GetTargets)\r
3084 IntroTargetList = property(_GetIntroTargetList)\r
3085 CodaTargetList = property(_GetFinalTargetList)\r
3086 FileTypes = property(_GetFileTypes)\r
3087 BuildRules = property(_GetBuildRules)\r
3088\r
3089 DependentPackageList = property(_GetDependentPackageList)\r
3090 DependentLibraryList = property(_GetLibraryList)\r
3091 LibraryAutoGenList = property(_GetLibraryAutoGenList)\r
3092 DerivedPackageList = property(_GetDerivedPackageList)\r
3093\r
3094 ModulePcdList = property(_GetModulePcdList)\r
3095 LibraryPcdList = property(_GetLibraryPcdList)\r
3096 GuidList = property(_GetGuidList)\r
3097 ProtocolList = property(_GetProtocolList)\r
3098 PpiList = property(_GetPpiList)\r
3099 DepexList = property(_GetDepexTokenList)\r
b36d134f 3100 DxsFile = property(_GetDxsFile)\r
52302d4d
LG
3101 DepexExpressionList = property(_GetDepexExpressionTokenList)\r
3102 BuildOption = property(_GetModuleBuildOption)\r
79b74a03 3103 BuildOptionIncPathList = property(_GetBuildOptionIncPathList)\r
52302d4d
LG
3104 BuildCommand = property(_GetBuildCommand)\r
3105\r
3106# This acts like the main() function for the script, unless it is 'import'ed into another script.\r
3107if __name__ == '__main__':\r
3108 pass\r
3109\r