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