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