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