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