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