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