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