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