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