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