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