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