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