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