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