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