28972318 |
1 | #!/usr/bin/env python\r |
2 | \r |
3 | # Copyright (c) 2007, Intel Corporation\r |
4 | # All rights reserved. This program and the accompanying materials\r |
5 | # are licensed and made available under the terms and conditions of the BSD License\r |
6 | # which accompanies this distribution. The full text of the license may be found at\r |
7 | # http://opensource.org/licenses/bsd-license.php\r |
8 | #\r |
9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r |
10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r |
11 | \r |
12 | """Framework SurfaceArea Elemments"""\r |
13 | #\r |
14 | # TODO: FFS layout, Flash, FV, PCD\r |
15 | #\r |
16 | import os, sys, re, getopt, string, glob, xml.dom.minidom, pprint, time, copy, shelve\r |
17 | from XmlRoutines import *\r |
18 | import FrameworkElement\r |
19 | import BuildConfig\r |
20 | \r |
21 | ################################################################################\r |
22 | ##\r |
23 | ## Convert given list to a string in the format like: [a, b, c]\r |
24 | ##\r |
25 | ################################################################################\r |
26 | def ListString(lst):\r |
27 | return "[%s]" % ",".join(lst)\r |
28 | \r |
29 | class SurfaceAreaElement:\r |
30 | """Base class for Surface Area XML element"""\r |
31 | _ModuleTypes = ('BASE', 'SEC', 'PEI_CORE', 'PEIM', 'DXE_CORE', 'DXE_DRIVER',\r |
32 | 'DXE_RUNTIME_DRIVER', 'DXE_SAL_DRIVER', 'DXE_SMM_DRIVER',\r |
33 | 'TOOL', 'UEFI_DRIVER', 'UEFI_APPLICATION', 'USER_DEFINED')\r |
34 | _GuidTypes = ('DATA_HUB_RECORD', 'EFI_EVENT', 'EFI_SYSTEM_CONFIGURATION_TABLE',\r |
35 | 'EFI_VARIABLE', 'GUID', 'HII_PACKAGE_LIST', 'HOB', 'TOKEN_SPACE_GUID')\r |
36 | _Archs = ('EBC', 'IA32', 'X64', 'IPF', 'ARM', 'PPC')\r |
37 | _Usages = ('ALWAYS_CONSUMED', 'SOMETIMES_CONSUMED', 'ALWAYS_PRODUCED',\r |
38 | 'SOMETIMES_PRODUCED', 'TO_START', 'BY_START', 'PRIVATE')\r |
39 | _FileTypes = {\r |
40 | ".c" : "CCode",\r |
41 | ".C" : "CCode",\r |
42 | ".cpp" : "CCode",\r |
43 | ".Cpp" : "CCode",\r |
44 | ".CPP" : "CCode",\r |
45 | ".h" : "CHeader",\r |
46 | ".H" : "CHeader",\r |
47 | ".asm" : "ASM",\r |
48 | ".Asm" : "Assembly",\r |
49 | ".ASM" : "Assembly",\r |
50 | ".s" : "IpfAssembly",\r |
51 | ".S" : "GccAssembly",\r |
52 | ".uni" : "UNI",\r |
53 | ".Uni" : "Unicode",\r |
54 | ".UNI" : "Unicode",\r |
55 | ".vfr" : "VFR",\r |
56 | ".Vfr" : "VFR",\r |
57 | ".VFR" : "VFR",\r |
58 | ".dxs" : "DPX",\r |
59 | ".Dxs" : "DPX",\r |
60 | ".DXS" : "DPX",\r |
61 | ".fv" : "FirmwareVolume",\r |
62 | ".Fv" : "FirmwareVolume",\r |
63 | ".FV" : "FirmwareVolume",\r |
64 | ".efi" : "EFI",\r |
65 | ".Efi" : "EFI",\r |
66 | ".EFI" : "EFI",\r |
67 | ".SEC" : "FFS",\r |
68 | ".PEI" : "FFS",\r |
69 | ".DXE" : "FFS",\r |
70 | ".APP" : "FFS",\r |
71 | ".FYI" : "FFS",\r |
72 | ".FFS" : "FFS",\r |
73 | ".bmp" : "BMP",\r |
74 | ".i" : "PPCode",\r |
75 | ".asl" : "ASL",\r |
76 | ".Asl" : "ASL",\r |
77 | ".ASL" : "ASL",\r |
78 | }\r |
79 | _ToolMapping = {\r |
80 | "CCode" : "CC",\r |
81 | "CHeader" : "",\r |
82 | "ASM" : "ASM",\r |
83 | "Assembly" : "ASM",\r |
84 | "IpfAssembly" : "ASM",\r |
85 | "GccAssembly" : "ASM",\r |
86 | "UNI" : "",\r |
87 | "Unicode" : "",\r |
88 | "VFR" : "",\r |
89 | "DPX" : "",\r |
90 | "FirmwareVolume" : "",\r |
91 | "EFI" : "",\r |
92 | "FFS" : "",\r |
93 | "PPCode" : "PP",\r |
94 | "BMP" : "",\r |
95 | }\r |
96 | \r |
97 | _BuildableFileTypes = ("CCode", "ASM", "Assembly", "IpfAssembly", "GccAssembly", "UNI", "Unicode", "VFR", "DPX", "EFI")\r |
98 | \r |
99 | def __init__(self, workspace, owner=None, dom=None, parse=True, postprocess=True):\r |
100 | self._Workspace = workspace\r |
101 | \r |
102 | if owner == None: self._Owner = ""\r |
103 | else: self._Owner = owner\r |
104 | \r |
105 | if dom == None: self._Root = ""\r |
106 | else: self._Root = dom\r |
107 | \r |
108 | self._Elements = {}\r |
109 | \r |
110 | if parse: self.Parse()\r |
111 | if postprocess: self.Postprocess()\r |
112 | \r |
113 | def Parse(self):\r |
114 | """Parse the XML element in DOM form"""\r |
115 | pass\r |
116 | \r |
117 | def Postprocess(self):\r |
118 | """Re-organize the original information form XML DOM into a format which can be used directly"""\r |
119 | pass\r |
120 | \r |
121 | def GetArchList(self, dom):\r |
122 | """Parse the SupArchList attribute. If not spcified, return all ARCH supported"""\r |
123 | archs = XmlAttribute(dom, "SupArchList").split()\r |
124 | if archs == []:\r |
125 | if self._Owner.Archs != []:\r |
126 | archs = self._Owner.Archs\r |
127 | elif self._Workspace.ActiveArchs != []:\r |
128 | archs = self._Workspace.ActiveArchs\r |
129 | elif self._Workspace.ActivePlatform != "" and self._Workspace.ActivePlatform.Archs != []:\r |
130 | archs = self._Workspace.ActivePlatform.Archs\r |
131 | else:\r |
132 | archs = self._Archs\r |
133 | return archs\r |
134 | \r |
135 | def GetModuleTypeList(self, dom):\r |
136 | """Parse the SupModuleList attribute. If not specified, return all supported module types"""\r |
137 | moduleTypes = XmlAttribute(dom, "SupModuleList").split()\r |
138 | if moduleTypes == []:\r |
139 | moduleTypes = self._ModuleTypes\r |
140 | return moduleTypes\r |
141 | \r |
142 | def GetGuidTypeList(self, dom):\r |
143 | """Parse GuidTypeList attribute. Default to GUID if not specified"""\r |
144 | guidTypes = XmlAttribute(dom, "GuidTypeList")\r |
145 | if guidTypes == []:\r |
146 | guidTypes = ["GUID"]\r |
147 | return guidTypes\r |
148 | \r |
149 | def GetFeatureList(self, dom):\r |
150 | """Parse FeatureFlag attribute"""\r |
151 | return XmlAttribute(dom, "FeatureFlag").split()\r |
152 | \r |
153 | def GetToolchainTagList(self, dom):\r |
154 | """Parse TagName attribute. Return all defined toolchains defined in tools_def.txt if not given"""\r |
155 | toolchainTagString = XmlAttribute(dom, "TagName")\r |
156 | if toolchainTagString == "":\r |
157 | return self._Workspace.ToolConfig.Toolchains\r |
158 | return toolchainTagString.split()\r |
159 | \r |
160 | def GetToolchainFamilyList(self, dom):\r |
161 | """Parse ToolChainFamily attribute. Return all defined toolchain families in tools_def.txt if not given"""\r |
162 | familyString = XmlAttribute(dom, "ToolChainFamily")\r |
163 | if familyString != "":\r |
164 | return familyString.split()\r |
165 | return self._Workspace.ToolConfig.Families\r |
166 | \r |
167 | def GetTargetList(self, dom):\r |
168 | """Parse BuildTargets attribute. Return all build targets defined in tools_def.txt if not given"""\r |
169 | targetList = XmlAttribute(dom, "BuildTargets").split()\r |
170 | if targetList == []:\r |
171 | targetList = self._Workspace.ToolConfig.Targets\r |
172 | return targetList\r |
173 | \r |
174 | def GetUsage(self, dom):\r |
175 | """Parse Usage attribute. Default to ALWAYS_CONSUMED if not given"""\r |
176 | usageString = XmlAttribute(dom, "Usage")\r |
177 | if usageString == "":\r |
178 | return "ALWAYS_CONSUMED"\r |
179 | return usageString\r |
180 | \r |
181 | def GetBuildOptionList(self, dom):\r |
182 | """Parse Options/Option element. Return a options dictionay with keys as (toolchain, target, arch, toolcode, attr)"""\r |
183 | optionList = XmlList(dom, "/Options/Option")\r |
184 | buildOptions = {}\r |
185 | for option in optionList:\r |
186 | targets = self.GetTargetList(option)\r |
187 | toolchainFamilies = self.GetToolchainFamilyList(option)\r |
188 | toolchainTags = self.GetToolchainTagList(option)\r |
189 | toolcode = XmlAttribute(option, "ToolCode")\r |
190 | archs = self.GetArchList(option)\r |
191 | flag = XmlElementData(option)\r |
192 | # print flag\r |
193 | \r |
194 | toolchains = []\r |
195 | if toolchainTags != []:\r |
196 | toolchains = toolchainTags\r |
197 | elif toolchainFamilies != []:\r |
198 | toolchains = toolchainFamilies\r |
199 | else:\r |
200 | raise Exception("No toolchain specified for a build option: " + self._Owner.Name)\r |
201 | \r |
202 | if targets == []: targets = self._Workspace.ActiveTargets\r |
203 | if archs == []: archs = self._Workspace.ActiveArchs\r |
204 | \r |
205 | for toolchain in toolchains:\r |
206 | for target in targets:\r |
207 | for arch in archs:\r |
208 | buildOptions[(toolchain, target, arch, toolcode, "FLAGS")] = flag\r |
209 | return buildOptions\r |
210 | \r |
211 | def GetFvBindingList(self, dom):\r |
212 | """Parse FvBinding element. If not specified, return NULL FV"""\r |
213 | fvBindingList = XmlElementData(dom).split()\r |
214 | if fvBindingList == []:\r |
215 | fvBindingList = ["NULL"]\r |
216 | return fvBindingList\r |
217 | \r |
218 | def IsBuildable(self, type):\r |
219 | """Test if a file with the type can be built by a tool"""\r |
220 | return type in self._BuildableFileTypes\r |
221 | \r |
222 | def GetToolCode(self, type):\r |
223 | """Get the toolcode which must be used to build files with the type"""\r |
224 | toolcode = ""\r |
225 | if type in self._ToolMapping:\r |
226 | toolcode = self._ToolMapping[type]\r |
227 | return toolcode\r |
228 | \r |
229 | def GetBoolean(self, dom):\r |
230 | """Transate true/false in string form to python's True/False value"""\r |
231 | boolString = XmlElementData(dom).upper()\r |
232 | if boolString == "" or boolString == "FALSE" or boolString == "NO":\r |
233 | return False\r |
234 | else:\r |
235 | return True\r |
236 | \r |
237 | class LibraryDeclaration(FrameworkElement.LibraryInterface, SurfaceAreaElement):\r |
238 | def __init__(self, workspace, package, dom):\r |
239 | FrameworkElement.LibraryInterface.__init__(self)\r |
240 | self.Package = package\r |
241 | SurfaceAreaElement.__init__(self, workspace, package, dom)\r |
242 | \r |
243 | def Parse(self):\r |
244 | dom = self._Root\r |
245 | self.Name = XmlAttribute(dom, "Name")\r |
246 | self.Path = os.path.normpath(XmlElementData(XmlElement(dom, "/LibraryClass/IncludeHeader")))\r |
247 | self.Dir = os.path.dirname(self.Path)\r |
248 | \r |
249 | attribute = XmlAttribute(dom, "RecommendedInstanceGuid")\r |
250 | if attribute is not '':\r |
251 | self.FavoriteIntance = FrameworkElement.Module()\r |
252 | self.FavoriteIntance.Guid = attribute\r |
253 | \r |
254 | attribute = XmlAttribute(dom, "RecommendedInstanceVersion")\r |
255 | if attribute is not '':\r |
256 | if self.FavoriteIntance == "":\r |
257 | raise "No GUID for the recommened library instance"\r |
258 | self.FavoriteIntance.Version = attribute\r |
259 | \r |
260 | self.Archs = self.GetArchList(dom)\r |
261 | self.ModuleTypes = self.GetModuleTypeList(dom)\r |
262 | \r |
263 | class LibraryClass(FrameworkElement.LibraryClass, SurfaceAreaElement):\r |
264 | def __init__(self, workspace, module, dom):\r |
265 | FrameworkElement.LibraryClass.__init__(self)\r |
266 | SurfaceAreaElement.__init__(self, workspace, module, dom)\r |
267 | \r |
268 | def Parse(self):\r |
269 | dom = self._Root\r |
270 | \r |
271 | self.Name = XmlElementData(XmlElement(dom, "/LibraryClass/Keyword"))\r |
272 | self.Usage = self.GetUsage(dom)\r |
273 | self.Features = self.GetFeatureList(dom)\r |
274 | self.Archs = self.GetArchList(dom)\r |
275 | \r |
276 | attribute = XmlAttribute(dom, "RecommendedInstanceGuid")\r |
277 | if attribute is not '':\r |
278 | self.FavoriteIntance = FrameworkElement.Module()\r |
279 | self.FavoriteIntance.Guid = attribute\r |
280 | \r |
281 | attribute = XmlAttribute(dom, "RecommendedInstanceVersion")\r |
282 | if attribute is not '':\r |
283 | if self.FavoriteIntance == "":\r |
284 | self.FavoriteIntance = FrameworkElement.Module()\r |
285 | self.FavoriteIntance.Version = attribute\r |
286 | \r |
287 | def Postprocess(self):\r |
288 | self.Interface = self._Workspace.GetLibraryInterface(self.Name)\r |
289 | \r |
290 | class SourceFile(FrameworkElement.SourceFile, SurfaceAreaElement):\r |
291 | def __init__(self, workspace, module, dom):\r |
292 | FrameworkElement.SourceFile.__init__(self)\r |
293 | SurfaceAreaElement.__init__(self, workspace, module, dom)\r |
294 | \r |
295 | def Parse(self):\r |
296 | dom = self._Root\r |
297 | self.Path = os.path.normpath(XmlElementData(dom))\r |
298 | self.Dir = os.path.dirname(self.Path)\r |
299 | self.Type = self.GetFileType()\r |
300 | self.Toolchains = self.GetToolchainTagList(dom)\r |
301 | self.Families = self.GetToolchainFamilyList(dom)\r |
302 | self.Archs = self.GetArchList(dom)\r |
303 | self.Features = self.GetFeatureList(dom)\r |
304 | \r |
305 | def GetFileType(self):\r |
306 | type = XmlAttribute(self._Root, "ToolCode")\r |
307 | if type == "":\r |
308 | fileName = os.path.basename(self.Path)\r |
309 | self.BaseName,self.Ext = os.path.splitext(fileName)\r |
310 | if self.Ext in self._FileTypes:\r |
311 | type = self._FileTypes[self.Ext]\r |
312 | else:\r |
313 | type = ""\r |
314 | return type\r |
315 | \r |
316 | class PackageDependency(FrameworkElement.PackageDependency, SurfaceAreaElement):\r |
317 | def __init__(self, workspace, module, dom):\r |
318 | FrameworkElement.PackageDependency.__init__(self)\r |
319 | SurfaceAreaElement.__init__(self, workspace, module, dom)\r |
320 | \r |
321 | def Parse(self):\r |
322 | dom = self._Root\r |
323 | self.GuidValue = XmlAttribute(dom, "PackageGuid").upper()\r |
324 | self.Version = XmlAttribute(dom, "PackageVersion")\r |
325 | self.Archs = self.GetArchList(dom)\r |
326 | self.Features = self.GetFeatureList(dom)\r |
327 | \r |
328 | def Postprocess(self):\r |
329 | self.Package = self._Workspace.GetPackage(self.GuidValue, self.Version)\r |
330 | if self.Package == "": raise "No package with GUID=" + self.GuidValue + "VERSION=" + self.Version\r |
331 | \r |
332 | class Protocol(FrameworkElement.Protocol, SurfaceAreaElement):\r |
333 | def __init__(self, workspace, module, dom):\r |
334 | FrameworkElement.Protocol.__init__(self)\r |
335 | SurfaceAreaElement.__init__(self, workspace, module, dom)\r |
336 | \r |
337 | def Parse(self):\r |
338 | dom = self._Root\r |
339 | self.CName = XmlElementData(XmlElement(dom, "/Protocol/ProtocolCName"))\r |
340 | self.Usage = self.GetUsage(dom)\r |
341 | self.Archs = self.GetArchList(dom)\r |
342 | self.Features = self.GetFeatureList(dom)\r |
343 | \r |
344 | def Postprocess(self):\r |
345 | for pd in self._Owner._Elements["PackageDependencies"]:\r |
346 | if self.CName not in pd.Package.Protocols: continue\r |
347 | self.GuidValue = pd.Package.Protocols[self.CName]\r |
348 | \r |
349 | class ProtocolNotify(FrameworkElement.ProtocolNotify, SurfaceAreaElement):\r |
350 | def __init__(self, workspace, module, dom):\r |
351 | FrameworkElement.ProtocolNotify.__init__(self)\r |
352 | SurfaceAreaElement.__init__(self, workspace, module, dom)\r |
353 | \r |
354 | def Parse(self):\r |
355 | dom = self._Root\r |
356 | \r |
357 | self.CName = XmlElementData(XmlElement(dom, "/ProtocolNotify/ProtocolCName"))\r |
358 | self.Usage = self.GetUsage(dom)\r |
359 | self.Archs = self.GetArchList(dom)\r |
360 | self.Features = self.GetFeatureList(dom)\r |
361 | \r |
362 | def Postprocess(self):\r |
363 | for pd in self._Owner._Elements["PackageDependencies"]:\r |
364 | if self.CName not in pd.Package.Protocols: continue\r |
365 | self.GuidValue = pd.Package.Protocols[self.CName]\r |
366 | \r |
367 | class Ppi(FrameworkElement.Ppi, SurfaceAreaElement):\r |
368 | def __init__(self, workspace, module, dom):\r |
369 | FrameworkElement.Ppi.__init__(self)\r |
370 | SurfaceAreaElement.__init__(self, workspace, module, dom)\r |
371 | \r |
372 | def Parse(self):\r |
373 | dom = self._Root\r |
374 | self.CName = XmlElementData(XmlElement(dom, "/Ppi/PpiCName"))\r |
375 | self.Usage = self.GetUsage(dom)\r |
376 | self.Archs = self.GetArchList(dom)\r |
377 | self.Features = self.GetFeatureList(dom)\r |
378 | \r |
379 | def Postprocess(self):\r |
380 | for pd in self._Owner._Elements["PackageDependencies"]:\r |
381 | if self.CName not in pd.Package.Ppis: continue\r |
382 | self.GuidValue = pd.Package.Ppis[self.CName]\r |
383 | \r |
384 | class PpiNotify(FrameworkElement.PpiNotify, SurfaceAreaElement):\r |
385 | def __init__(self, workspace, module, dom):\r |
386 | FrameworkElement.PpiNotify.__init__(self)\r |
387 | SurfaceAreaElement.__init__(self, workspace, module, dom)\r |
388 | \r |
389 | def Parse(self):\r |
390 | dom = self._Root\r |
391 | self.CName = XmlElementData(XmlElement(dom, "/PpiNotify/PpiCName"))\r |
392 | self.Usage = self.GetUsage(dom)\r |
393 | self.Archs = self.GetArchList(dom)\r |
394 | self.Features = self.GetFeatureList(dom)\r |
395 | \r |
396 | def Postprocess(self):\r |
397 | for pd in self._Owner._Elements["PackageDependencies"]:\r |
398 | if self.CName not in pd.Package.Ppis: continue\r |
399 | self.GuidValue = pd.Package.Ppis[self.CName]\r |
400 | \r |
401 | class Guid(FrameworkElement.Guid, SurfaceAreaElement):\r |
402 | def __init__(self, workspace, module, dom):\r |
403 | FrameworkElement.Guid.__init__(self)\r |
404 | SurfaceAreaElement.__init__(self, workspace, module, dom)\r |
405 | \r |
406 | def Parse(self):\r |
407 | dom = self._Root\r |
408 | self.CName = XmlElementData(XmlElement(dom, "/GuidCNames/GuidCName"))\r |
409 | self.Usage = self.GetUsage(dom)\r |
410 | self.Archs = self.GetArchList(dom)\r |
411 | self.Features = self.GetFeatureList(dom)\r |
412 | \r |
413 | def Postprocess(self):\r |
414 | for pd in self._Owner._Elements["PackageDependencies"]:\r |
415 | if self.CName not in pd.Package.Guids: continue\r |
416 | self.GuidValue = pd.Package.Guids[self.CName]\r |
417 | \r |
418 | class Extern(FrameworkElement.Extern, SurfaceAreaElement):\r |
419 | def __init__(self, workspace, module, dom):\r |
420 | FrameworkElement.Extern.__init__(self)\r |
421 | SurfaceAreaElement.__init__(self, workspace, module, dom)\r |
422 | \r |
423 | def Parse(self):\r |
424 | dom = self._Root\r |
425 | self.Archs = self.GetArchList(dom)\r |
426 | self.Features = self.GetFeatureList(dom)\r |
427 | \r |
428 | extern = XmlElement(dom, "/Extern/ModuleEntryPoint")\r |
429 | if extern is not None and extern is not '':\r |
430 | self.ModuleEntryPoints.append(XmlElementData(extern))\r |
431 | \r |
432 | extern = XmlElement(dom, "/Extern/ModuleUnloadImage")\r |
433 | if extern is not None and extern is not '':\r |
434 | self.ModuleUnloadImages.append(XmlElementData(extern))\r |
435 | \r |
436 | extern = XmlElement(dom, "/Extern/Constructor")\r |
437 | if extern is not None and extern is not '':\r |
438 | self.Constructors.append(XmlElementData(extern))\r |
439 | \r |
440 | extern = XmlElement(dom, "/Extern/Destructor")\r |
441 | if extern is not None and extern is not '':\r |
442 | self.Destructors.append(XmlElementData(extern))\r |
443 | \r |
444 | extern = XmlElement(dom, "/Extern/DriverBinding")\r |
445 | if extern is not None and extern is not '':\r |
446 | self.DriverBindings.append(XmlElementData(extern))\r |
447 | \r |
448 | extern = XmlElement(dom, "/Extern/ComponentName")\r |
449 | if extern is not None and extern is not '':\r |
450 | self.ComponentNames.append(XmlElementData(extern))\r |
451 | \r |
452 | extern = XmlElement(dom, "/Extern/DriverConfig")\r |
453 | if extern is not None and extern is not '':\r |
454 | self.DriverConfigs.append(XmlElementData(extern))\r |
455 | \r |
456 | extern = XmlElement(dom, "/Extern/DriverDiag")\r |
457 | if extern is not None and extern is not '':\r |
458 | self.DriverDiags.append(XmlElementData(extern))\r |
459 | \r |
460 | extern = XmlElement(dom, "/Extern/SetVirtualAddressMapCallBacks")\r |
461 | if extern is not None and extern is not '':\r |
462 | self.SetVirtualAddressMapCallBacks.append(XmlElementData(extern))\r |
463 | \r |
464 | extern = XmlElement(dom, "/Extern/ExitBootServicesCallBack")\r |
465 | if extern is not None and extern is not '':\r |
466 | self.ExitBootServicesCallBacks.append(XmlElementData(extern))\r |
467 | \r |
468 | class IndustryStdHeader(FrameworkElement.IncludeFile, SurfaceAreaElement):\r |
469 | def __init__(self, workspace, package, dom):\r |
470 | FrameworkElement.IncludeFile.__init__(self)\r |
471 | SurfaceAreaElement.__init__(self, workspace, package, dom)\r |
472 | \r |
473 | def Parse(self):\r |
474 | dom = self._Root\r |
475 | self.Path = os.path.normpath(XmlElementData(XmlElement(dom, "/IndustryStdHeader/IncludeHeader")))\r |
476 | self.Dir = os.path.dirname(self.Path)\r |
477 | self.Archs = self.GetArchList(dom)\r |
478 | self.ModuleTypes = self.GetModuleTypeList(dom)\r |
479 | \r |
480 | class PackageHeader(FrameworkElement.IncludeFile, SurfaceAreaElement):\r |
481 | def __init__(self, workspace, package, dom):\r |
482 | FrameworkElement.IncludeFile.__init__(self)\r |
483 | SurfaceAreaElement.__init__(self, workspace, package, dom)\r |
484 | \r |
485 | def Parse(self):\r |
486 | dom = self._Root\r |
487 | self.Path = os.path.normpath(XmlElementData(dom))\r |
488 | self.Dir = os.path.dirname(self.Path)\r |
489 | self.ModuleType = XmlAttribute(dom, "ModuleType")\r |
490 | \r |
491 | class GuidDeclaration(FrameworkElement.Guid, SurfaceAreaElement):\r |
492 | def __init__(self, workspace, package, dom):\r |
493 | FrameworkElement.Guid.__init__(self)\r |
494 | SurfaceAreaElement.__init__(self, workspace, package, dom)\r |
495 | \r |
496 | def Parse(self):\r |
497 | dom = self._Root\r |
498 | self.CName = XmlElementData(XmlElement(dom, "/Entry/C_Name"))\r |
499 | self.GuidValue = XmlElementData(XmlElement(dom, "/Entry/GuidValue")).upper()\r |
500 | self.Name = XmlAttribute(dom, "Name")\r |
501 | self.Types = self.GetGuidTypeList(dom)\r |
502 | self.Archs = self.GetArchList(dom)\r |
503 | self.ModuleTypes = self.GetModuleTypeList(dom)\r |
504 | \r |
505 | def Postprocess(self):\r |
506 | pass\r |
507 | \r |
508 | class ProtocolDeclaration(GuidDeclaration, SurfaceAreaElement):\r |
509 | pass\r |
510 | \r |
511 | class PpiDeclaration(GuidDeclaration, SurfaceAreaElement):\r |
512 | pass\r |
513 | \r |
514 | class PcdDeclaration(FrameworkElement.Pcd, SurfaceAreaElement):\r |
515 | def __init__(self, workspace, package, dom):\r |
516 | FrameworkElement.Pcd.__init__(self)\r |
517 | SurfaceAreaElement.__init__(self, workspace, package, dom)\r |
518 | \r |
519 | def Parse(self):\r |
520 | dom = self._Root\r |
521 | self.Types = XmlElementData(XmlElement(dom, "/PcdEntry/ValidUsage")).split()\r |
522 | self.CName = XmlElementData(XmlElement(dom, "/PcdEntry/C_Name"))\r |
523 | self.Token = XmlElementData(XmlElement(dom, "/PcdEntry/Token"))\r |
524 | self.TokenSpace = XmlElementData(XmlElement(dom, "/PcdEntry/TokenSpaceGuidCName"))\r |
525 | self.DatumType = XmlElementData(XmlElement(dom, "/PcdEntry/DatumType"))\r |
526 | self.Default = XmlElementData(XmlElement(dom, "/PcdEntry/DefaultValue"))\r |
527 | self.Archs = self.GetArchList(dom)\r |
528 | self.ModuleTypes= self.GetModuleTypeList(dom)\r |
529 | \r |
530 | class LibraryInstance(FrameworkElement.PlatformModule, SurfaceAreaElement):\r |
531 | def __init__(self, workspace, platformModule, dom):\r |
532 | FrameworkElement.PlatformModule.__init__(self)\r |
533 | SurfaceAreaElement.__init__(self, workspace, platformModule, dom)\r |
534 | \r |
535 | def Parse(self):\r |
536 | dom = self._Root\r |
537 | self.GuidValue = XmlAttribute(dom, "ModuleGuid").upper()\r |
538 | self.Version = XmlAttribute(dom, "ModuleVersion")\r |
539 | self._Elements["PackageGuid"] = XmlAttribute(dom, "PackageGuid").upper()\r |
540 | self._Elements["PackageVersion"] = XmlAttribute(dom, "PackageVersion")\r |
541 | \r |
542 | def Postprocess(self):\r |
543 | self.Module = self._Workspace.GetModule(self.GuidValue, self.Version,\r |
544 | self._Elements["PackageGuid"], self._Elements["PackageVersion"])\r |
545 | self.Platform = self._Owner.Platform\r |
546 | self.Archs = self._Owner.Archs\r |
547 | self.Pcds = self._Owner.Pcds\r |
548 | self.BuildType = "lib"\r |
549 | \r |
550 | class PlatformModule(FrameworkElement.PlatformModule, SurfaceAreaElement):\r |
551 | def __init__(self, workspace, platform, dom):\r |
552 | FrameworkElement.PlatformModule.__init__(self)\r |
553 | self.Platform = platform\r |
554 | SurfaceAreaElement.__init__(self, workspace, platform, dom)\r |
555 | \r |
556 | def Parse(self):\r |
557 | dom = self._Root\r |
558 | self.GuidValue = XmlAttribute(dom, "ModuleGuid").upper()\r |
559 | self.Version = XmlAttribute(dom, "ModuleVersion")\r |
560 | self.Archs = self.GetArchList(dom)\r |
561 | \r |
562 | self._Elements["PackageGuid"] = XmlAttribute(dom, "PackageGuid").upper()\r |
563 | self._Elements["PackageVersion"] = XmlAttribute(dom, "PackageVersion")\r |
564 | \r |
565 | libraryList = XmlList(dom, "/ModuleSA/Libraries/Instance")\r |
566 | for lib in libraryList:\r |
567 | self.Libraries.append(LibraryInstance(self._Workspace, self, lib))\r |
568 | \r |
569 | dom = XmlElement(dom, "/ModuleSA/ModuleSaBuildOptions")\r |
570 | self.FvBindings = self.GetFvBindingList(XmlElement(dom, "/ModuleSaBuildOptions/FvBinding"))\r |
571 | self.FfsLayouts = XmlElementData(XmlElement(dom, "/ModuleSaBuildOptions/FfsFormatKey")).split()\r |
572 | self.BuildOptions = self.GetBuildOptionList(XmlElement(dom, "/ModuleSaBuildOptions/Options"))\r |
573 | \r |
574 | def Postprocess(self):\r |
575 | self.Module = self._Workspace.GetModule(self.GuidValue, self.Version,\r |
576 | self._Elements["PackageGuid"], self._Elements["PackageVersion"])\r |
577 | if self.Module == "":\r |
578 | raise Exception("No module found: \n\t\tGUID=%s \n\t\tVERSION=%s \n\t\tPACKAGE_GUID=%s \n\t\tPACKAGE_VERSION=%s" % (\r |
579 | self.GuidValue, self.Version, self._Elements["PackageGuid"], self._Elements["PackageVersion"]))\r |
580 | \r |
581 | ## def SetupEnvironment(self):\r |
582 | ## self.Environment = {\r |
583 | ## "ARCH" : "",\r |
584 | ## "MODULE_BUILD_TARGET" : "",\r |
585 | ## "SINGLE_MODULE_BUILD" : "",\r |
586 | ## "PLATFORM_PREBUILD" : "",\r |
587 | ## "PLATFORM_POSTBUILD" : "",\r |
588 | ## "LIBS" : "",\r |
589 | ## "SOURCE_FILES" : "",\r |
590 | ## "ENTRYPOINT" : "_ModuleEntryPoint",\r |
591 | ## } # name/value pairs\r |
592 | ## self.Environment["MODULE_BUILD_TARGET"] = "platform_module_build"\r |
593 | \r |
594 | class ModuleSurfaceArea(FrameworkElement.Module, SurfaceAreaElement):\r |
595 | def __init__(self, workspace, package, path):\r |
596 | FrameworkElement.Module.__init__(self)\r |
597 | \r |
598 | self.Path = os.path.normpath(path)\r |
599 | self.Dir = os.path.dirname(self.Path)\r |
600 | self.FileBaseName,_ext = os.path.splitext(os.path.basename(self.Path))\r |
601 | self.Package = package\r |
602 | SurfaceAreaElement.__init__(self, workspace, package)\r |
603 | \r |
604 | def _MsaHeader(self, xpath):\r |
605 | dom = XmlElement(self._Root, xpath)\r |
606 | if dom == '': return\r |
607 | self.Name = XmlElementData(XmlElement(dom, "/MsaHeader/ModuleName"))\r |
608 | self.Type = XmlElementData(XmlElement(dom, "/MsaHeader/ModuleType"))\r |
609 | self.GuidValue = XmlElementData(XmlElement(dom, "/MsaHeader/GuidValue")).upper()\r |
610 | self.Version = XmlElementData(XmlElement(dom, "/MsaHeader/Version"))\r |
611 | \r |
612 | def _ModuleDefinitions(self, xpath):\r |
613 | dom = XmlElement(self._Root, xpath)\r |
614 | if dom == '': return\r |
615 | self.Archs = XmlElementData(XmlElement(dom, "/ModuleDefinitions/SupportedArchitectures")).split()\r |
616 | self.IsBinary = self.GetBoolean(XmlElement(dom, "/ModuleDefinitions/BinaryModule"))\r |
617 | self.BaseName = XmlElementData(XmlElement(dom, "/ModuleDefinitions/OutputFileBasename"))\r |
618 | \r |
619 | def _LibraryClassDefinitions(self, xpath):\r |
620 | dom = XmlElement(self._Root, xpath)\r |
621 | if dom == '': return\r |
622 | lcList = []\r |
623 | for lc in XmlList(dom, "/LibraryClassDefinitions/LibraryClass"):\r |
624 | lcList.append(LibraryClass(self._Workspace, self, lc))\r |
625 | self._Elements["LibraryClassDefinitions"] = lcList\r |
626 | \r |
627 | def _SourceFiles(self, xpath):\r |
628 | dom = XmlElement(self._Root, xpath)\r |
629 | if dom == '': return\r |
630 | srcList = []\r |
631 | for f in XmlList(dom, "/SourceFiles/Filename"):\r |
632 | srcList.append(SourceFile(self._Workspace, self, f))\r |
633 | self._Elements["SourceFiles"] = srcList\r |
634 | \r |
635 | def _NonProcessedFiles(self, xpath):\r |
636 | dom = XmlElement(self._Root, xpath)\r |
637 | if dom == '': return\r |
638 | for f in XmlList(dom, "/NonProcessedFiles/Filename"):\r |
639 | self.NonProcessedFiles.append(SourceFile(self._Workspace, self, f))\r |
640 | \r |
641 | def _PackageDependencies(self, xpath):\r |
642 | dom = XmlElement(self._Root, xpath)\r |
643 | if dom == '': return\r |
644 | pdList = []\r |
645 | for pkg in XmlList(dom, "/PackageDependencies/Package"):\r |
646 | pdList.append(PackageDependency(self._Workspace, self, pkg))\r |
647 | self._Elements["PackageDependencies"] = pdList\r |
648 | \r |
649 | def _Protocols(self, xpath):\r |
650 | dom = XmlElement(self._Root, xpath)\r |
651 | if dom == '': return\r |
652 | \r |
653 | protocolList = []\r |
654 | for p in XmlList(dom, "/Protocols/Protocol"):\r |
655 | protocolList.append(Protocol(self._Workspace, self, p))\r |
656 | for p in XmlList(dom, "/Protocols/ProtocolNotify"):\r |
657 | protocolList.append(ProtocolNotify(self._Workspace, self, p))\r |
658 | \r |
659 | self._Elements["Protocols"] = protocolList\r |
660 | \r |
661 | def _Ppis(self, xpath):\r |
662 | dom = XmlElement(self._Root, xpath)\r |
663 | if dom == '': return\r |
664 | \r |
665 | ppiList = []\r |
666 | for p in XmlList(dom, "/PPIs/Ppi"):\r |
667 | ppiList.append(Ppi(self._Workspace, self, p))\r |
668 | for p in XmlList(dom, "/PPIs/PpiNotify"):\r |
669 | ppiList.append(PpiNotify(self._Workspace, self, p))\r |
670 | \r |
671 | self._Elements["PPIs"] = ppiList\r |
672 | \r |
673 | def _Guids(self, xpath):\r |
674 | dom = XmlElement(self._Root, xpath)\r |
675 | if dom == '': return\r |
676 | guidList = []\r |
677 | for g in XmlList(dom, "/Guids/GuidCNames"):\r |
678 | guidList.append(Guid(self._Workspace, self, g))\r |
679 | self._Elements["Guids"] = guidList\r |
680 | \r |
681 | def _Externs(self, xpath):\r |
682 | dom = XmlElement(self._Root, xpath)\r |
683 | if dom == '': return\r |
684 | self.PcdIsDriver = self.GetBoolean(XmlElement(dom, "/Externs/PcdIsDriver"))\r |
685 | self.NeedsFlashMap_h = self.GetBoolean(XmlElement(dom, "/Externs/TianoR8FlashMap_h"))\r |
686 | \r |
687 | externList = []\r |
688 | specs = FrameworkElement.Extern()\r |
689 | specs.Archs = self._Archs\r |
690 | externList.append(specs)\r |
691 | for spec in XmlList(dom, "/Externs/Specification"):\r |
692 | specs.Specifications.append(XmlElementData(spec))\r |
693 | for ext in XmlList(dom, "/Externs/Extern"):\r |
694 | externList.append(Extern(self._Workspace, self, ext))\r |
695 | self._Elements["Externs"] = externList\r |
696 | \r |
697 | def _ModuleBuildOptions(self, xpath):\r |
698 | dom = XmlElement(self._Root, xpath)\r |
699 | if dom == '': return\r |
700 | self.BuildOptions = self.GetBuildOptionList(XmlElement(dom, "/ModuleBuildOptions/Options"))\r |
701 | \r |
702 | def _UserExtensions(self, xpath):\r |
703 | domList = XmlList(self._Root, xpath)\r |
704 | if domList == []: return\r |
705 | for extension in domList:\r |
706 | userId = XmlAttribute(extension, "UserID")\r |
707 | identifier = XmlAttribute(extension, "Identifier")\r |
708 | if userId == '' or identifier == '':\r |
709 | raise Exception("No UserId or Identifier specified")\r |
710 | if userId != "TianoCore": continue\r |
711 | if identifier not in self.UserExtensions:\r |
712 | self.UserExtensions[identifier] = []\r |
713 | \r |
714 | contentList = self.UserExtensions[identifier]\r |
715 | for node in extension.childNodes:\r |
716 | #print node.nodeType\r |
717 | contentList.append(node.cloneNode(True))\r |
718 | \r |
719 | def Parse(self):\r |
720 | fileFullPath = self._Workspace.SubPath(os.path.dirname(self.Package.Path), self.Path)\r |
721 | self._Root = xml.dom.minidom.parse(fileFullPath)\r |
722 | assert self._Root.documentElement.tagName == "ModuleSurfaceArea"\r |
723 | \r |
724 | # print " Parsing...",self.Path\r |
725 | self._MsaHeader("/ModuleSurfaceArea/MsaHeader")\r |
726 | self._ModuleDefinitions("/ModuleSurfaceArea/ModuleDefinitions")\r |
727 | self._PackageDependencies("/ModuleSurfaceArea/PackageDependencies")\r |
728 | self._LibraryClassDefinitions("/ModuleSurfaceArea/LibraryClassDefinitions")\r |
729 | self._SourceFiles("/ModuleSurfaceArea/SourceFiles")\r |
730 | self._NonProcessedFiles("/ModuleSurfaceArea/NonProcessedFiles")\r |
731 | self._Protocols("/ModuleSurfaceArea/Protocols")\r |
732 | self._Ppis("/ModuleSurfaceArea/Ppis")\r |
733 | self._Guids("/ModuleSurfaceArea/Guids")\r |
734 | self._Externs("/ModuleSurfaceArea/Externs")\r |
735 | self._ModuleBuildOptions("/ModuleSurfaceArea/ModuleBuildOptions")\r |
736 | self._UserExtensions("/ModuleSurfaceArea/UserExtensions")\r |
737 | \r |
738 | def Postprocess(self):\r |
739 | # resolve package dependency\r |
740 | if self._Elements.has_key("PackageDependencies"):\r |
741 | for pd in self._Elements["PackageDependencies"]:\r |
742 | package = pd.Package\r |
743 | if self.Type not in package.PackageIncludes:\r |
744 | print "! Module type %s is not supported in the package %s" % (self.Type, package.Name)\r |
745 | \r |
746 | for arch in pd.Archs:\r |
747 | if arch not in self.IncludePaths:\r |
748 | self.IncludePaths[arch] = []\r |
749 | self.IncludePaths[arch].append(package.SubPath("Include"))\r |
750 | self.IncludePaths[arch].append(package.SubPath("Include", arch.capitalize()))\r |
751 | \r |
752 | if arch not in self.IncludeFiles:\r |
753 | self.IncludeFiles[arch] = []\r |
754 | if self.Type in package.PackageIncludes:\r |
755 | for path in package.PackageIncludes[self.Type]:\r |
756 | self.IncludeFiles[arch].append(package.SubPath(path))\r |
757 | \r |
758 | # resolve library class\r |
759 | if self._Elements.has_key("LibraryClassDefinitions"):\r |
760 | for lc in self._Elements["LibraryClassDefinitions"]:\r |
761 | lc.Interface = self._Workspace.GetLibraryInterface(lc.Name)\r |
762 | if "ALWAYS_PRODUCED" in lc.Usage:\r |
763 | self.IsLibrary = True\r |
764 | lc.Interface.Instances.append(self)\r |
765 | else:\r |
766 | lc.Interface.Consumers.append(self)\r |
767 | \r |
768 | for arch in lc.Archs:\r |
769 | if arch not in self.LibraryClasses:\r |
770 | self.LibraryClasses[arch] = []\r |
771 | self.LibraryClasses[arch].append(lc)\r |
772 | \r |
773 | # expand source files\r |
774 | if self._Elements.has_key("SourceFiles"):\r |
775 | for src in self._Elements["SourceFiles"]:\r |
776 | for arch in src.Archs:\r |
777 | if arch not in self.SourceFiles:\r |
778 | self.SourceFiles[arch] = {}\r |
779 | if src.Type not in self.SourceFiles[arch]:\r |
780 | self.SourceFiles[arch][src.Type] = []\r |
781 | self.SourceFiles[arch][src.Type].append(src)\r |
782 | \r |
783 | # expand guids\r |
784 | if self._Elements.has_key("Guids"):\r |
785 | for guid in self._Elements["Guids"]:\r |
786 | for arch in guid.Archs:\r |
787 | if arch not in self.Guids:\r |
788 | self.Guids[arch] = []\r |
789 | self.Guids[arch].append(guid)\r |
790 | \r |
791 | # expand protocol\r |
792 | if self._Elements.has_key("Protocols"):\r |
793 | for protocol in self._Elements["Protocols"]:\r |
794 | for arch in protocol.Archs:\r |
795 | if arch not in self.Protocols:\r |
796 | self.Protocols[arch] = []\r |
797 | self.Protocols[arch].append(protocol)\r |
798 | \r |
799 | # expand ppi\r |
800 | if self._Elements.has_key("PPIs"):\r |
801 | for ppi in self._Elements["PPIs"]:\r |
802 | for arch in ppi.Archs:\r |
803 | if arch not in self.Ppis:\r |
804 | self.Ppis[arch] = []\r |
805 | self.Ppis[arch].append(ppi)\r |
806 | \r |
807 | # expand extern\r |
808 | if self._Elements.has_key("Externs"):\r |
809 | for extern in self._Elements["Externs"]:\r |
810 | for arch in extern.Archs:\r |
811 | if arch not in self.Externs:\r |
812 | self.Externs[arch] = []\r |
813 | self.Externs[arch].append(extern)\r |
814 | ## def SetupEnvironment(self):\r |
815 | ## self.Environment["MODULE"] = self.Name\r |
816 | ## self.Environment["MODULE_GUID"] = self.GuidValue\r |
817 | ## self.Environment["MODULE_VERSION"] = self.Version\r |
818 | ## self.Environment["MODULE_TYPE"] = self.Type\r |
819 | ## self.Environment["MODULE_FILE_BASE_NAME"] = os.path.basename(self.Path).split(".")[0]\r |
820 | ## self.Environment["MODULE_RELATIVE_DIR"] = os.path.dirname(self.Path)\r |
821 | ## self.Environment["BASE_NAME"] = self.OutputName\r |
822 | \r |
823 | class Workspace(FrameworkElement.Workspace, SurfaceAreaElement):\r |
824 | _Db = "Tools/Conf/FrameworkDatabase.db"\r |
825 | _Target = "Tools/Conf/Target.txt"\r |
826 | _PlatformBuildPath = "Tools/Conf/platform_build_path.txt"\r |
827 | _ModuleBuildPath = "Tools/Conf/module_build_path.txt"\r |
828 | \r |
829 | def __init__(self, path, fpdList=None, msaList=None):\r |
830 | FrameworkElement.Workspace.__init__(self)\r |
831 | SurfaceAreaElement.__init__(self, self, None, None, False, False)\r |
832 | self.Path = os.path.normpath(path)\r |
833 | self.Dir = os.path.dirname(self.Path)\r |
834 | self._Elements["PlatformList"] = fpdList\r |
835 | self._Elements["ModuleList"] = msaList\r |
836 | self.Parse()\r |
837 | self.Postprocess()\r |
838 | \r |
839 | def _FdbHeader(self, xpath):\r |
840 | dom = XmlElement(self._Root, xpath)\r |
841 | if dom == '': return\r |
842 | self.Name = XmlElementData(XmlElement(dom, "/FdbHeader/DatabaseName"))\r |
843 | self.GuidValue = XmlElementData(XmlElement(dom, "/FdbHeader/GuidValue")).upper()\r |
844 | self.Version = XmlElementData(XmlElement(dom, "/FdbHeader/Version"))\r |
845 | \r |
846 | def _PackageList(self, xpath):\r |
847 | dom = XmlElement(self._Root, xpath)\r |
848 | if dom == '': return\r |
849 | \r |
850 | fileList = XmlList(dom, "/PackageList/Filename")\r |
851 | packages = []\r |
852 | for f in fileList:\r |
853 | packages.append(os.path.normpath(XmlElementData(f)))\r |
854 | self._Elements["PackageList"] = packages\r |
855 | \r |
856 | def _PlatformList(self, xpath):\r |
857 | if len(self._Elements["PlatformList"]) > 0:\r |
858 | return\r |
859 | \r |
860 | dom = XmlElement(self._Root, xpath)\r |
861 | if dom == '': return\r |
862 | \r |
863 | fileList = XmlList(dom, "/PlatformList/Filename")\r |
864 | platforms = []\r |
865 | for f in fileList:\r |
866 | platforms.append(os.path.normpath(XmlElementData(f)))\r |
867 | self._Elements["PlatformList"] = platforms\r |
868 | \r |
869 | def _FarList(self, xpath):\r |
870 | dom = XmlElement(self._Root, xpath)\r |
871 | if dom == '': return\r |
872 | \r |
873 | fileList = XmlList(dom, "/FarList/Filename")\r |
874 | fars = []\r |
875 | for f in fileList:\r |
876 | fars.append(os.path.normpath(XmlElementData(f)))\r |
877 | self._Elements["FarList"] = fars\r |
878 | \r |
879 | def ParseWorkspaceDatabase(self):\r |
880 | # parse frameworkdatabase.db\r |
881 | self._Root = xml.dom.minidom.parse(self.SubPath(self._Db))\r |
882 | assert self._Root.documentElement.tagName == "FrameworkDatabase"\r |
883 | \r |
884 | self._FdbHeader("/FrameworkDatabase/FdbHeader")\r |
885 | self._PackageList("/FrameworkDatabase/PackageList")\r |
886 | self._PlatformList("/FrameworkDatabase/PlatformList")\r |
887 | self._FarList("/FrameworkDatabase/FarList")\r |
888 | \r |
889 | def ParseConfig(self):\r |
890 | # parse target.txt\r |
891 | self.ParseTargetConfig()\r |
892 | # parse tools_def.txt\r |
893 | self.ParseToolConfig()\r |
894 | # parse platform/module_build_path.txt\r |
895 | \r |
896 | # active toolchain\r |
897 | # print self.TargetConfig\r |
898 | self.ActiveToolchain = self.TargetConfig["TOOL_CHAIN_TAG"]\r |
899 | if self.ActiveToolchain not in self.ToolConfig.Toolchains:\r |
900 | raise "Not supported tool chain tag %s" % self.ActiveToolchain\r |
901 | \r |
902 | # active toolchain family\r |
903 | self.ActiveFamilies = []\r |
904 | for key in self.ToolConfig:\r |
905 | if self.ActiveToolchain in key and "FAMILY" in key:\r |
906 | family = self.ToolConfig[key]\r |
907 | if family not in self.ActiveFamilies:\r |
908 | self.ActiveFamilies.append(family)\r |
909 | \r |
910 | \r |
911 | def ParsePackage(self, packagePaths=None):\r |
912 | if packagePaths == None:\r |
913 | return\r |
914 | \r |
915 | for packagePath in packagePaths:\r |
916 | self.Packages.append(PackageSurfaceArea(self, packagePath))\r |
917 | \r |
918 | def ParsePlatform(self, platformPaths=None):\r |
919 | # Only one active platform is allowed\r |
920 | activePlatformPath = ""\r |
921 | if self.TargetConfig["ACTIVE_PLATFORM"] == "":\r |
922 | if platformPaths != None and len(platformPaths) == 1:\r |
923 | activePlatformPath = platformPaths[0]\r |
924 | else:\r |
925 | raise Exception("No active platform specified or implied!")\r |
926 | else:\r |
927 | activePlatformPath = os.path.normpath(self.TargetConfig["ACTIVE_PLATFORM"])\r |
928 | \r |
929 | self.ActivePlatform = PlatformSurfaceArea(self, activePlatformPath)\r |
930 | self.Platforms.append(self.ActivePlatform)\r |
931 | \r |
932 | def ParseTargetConfig(self):\r |
933 | self.TargetConfig = BuildConfig.TargetConfig(self.SubPath(self._Target))\r |
934 | # print self.TargetConfig\r |
935 | \r |
936 | def ParseToolConfig(self):\r |
937 | self.ToolConfig = BuildConfig.ToolConfig(self.SubPath(self.TargetConfig["TOOL_CHAIN_CONF"]))\r |
938 | \r |
939 | def GetModule(self, guid, version, packageGuid, packageVersion):\r |
940 | moduleGuidIndex = self.ModuleXref["GUID"]\r |
941 | if guid not in moduleGuidIndex:\r |
942 | print "! No module has GUID=" + guid\r |
943 | return ""\r |
944 | \r |
945 | moduleVersionList = moduleGuidIndex[guid]\r |
946 | # print moduleVersionList\r |
947 | moduleList = []\r |
948 | module = ""\r |
949 | if version != "":\r |
950 | if version in moduleVersionList:\r |
951 | moduleList = moduleVersionList[version]\r |
952 | else:\r |
953 | return ""\r |
954 | else:\r |
955 | ## no version given, return the first one\r |
956 | version = "0.0"\r |
957 | for ver in moduleVersionList:\r |
958 | if ver > version: version = ver\r |
959 | moduleList = moduleVersionList[version]\r |
960 | \r |
961 | if packageGuid == "":\r |
962 | ## if no package GUID given, just return the latest one\r |
963 | version = "0.0"\r |
964 | for m in moduleList:\r |
965 | if m.Package.Version > version:\r |
966 | version = m.Package.Version\r |
967 | module = m\r |
968 | else:\r |
969 | version = "0.0"\r |
970 | for m in moduleList:\r |
971 | if m.Package.GuidValue != packageGuid: continue\r |
972 | if packageVersion == "":\r |
973 | ## if no version given, just return the latest\r |
974 | if m.Package.Version > version:\r |
975 | version = m.Package.Version\r |
976 | module = m\r |
977 | elif packageVersion == m.Package.Version:\r |
978 | module = m\r |
979 | break;\r |
980 | \r |
981 | return module\r |
982 | \r |
983 | def GetModuleByPath(self, path):\r |
984 | ownerPackage = ""\r |
985 | ownerPackageFullPath = ""\r |
986 | for package in self.Packages:\r |
987 | ownerPackageFullPath = self.SubPath(package.Path)\r |
988 | if path.startswith(packageFullPath): break\r |
989 | \r |
990 | if ownerPackage == "":\r |
991 | return ""\r |
992 | \r |
993 | for module in ownerPackage.Modules:\r |
994 | moduleFullPath = os.path.join(ownerPackageFullPath, module.Path)\r |
995 | if moduleFullPath == path:\r |
996 | return module\r |
997 | \r |
998 | return ""\r |
999 | \r |
1000 | def GetPackage(self, guid, version):\r |
1001 | packageGuidIndex = self.PackageXref["GUID"]\r |
1002 | if guid not in packageGuidIndex:\r |
1003 | # raise Exception("No package has GUID=" + guid)\r |
1004 | return ""\r |
1005 | \r |
1006 | packageList = packageGuidIndex[guid]\r |
1007 | package = ""\r |
1008 | if version != "":\r |
1009 | if version in packageList:\r |
1010 | package = packageList[version]\r |
1011 | else:\r |
1012 | ## no version given, return the latest one\r |
1013 | version = "0.0"\r |
1014 | for ver in packageList:\r |
1015 | if ver > version: version = ver\r |
1016 | package = packageList[version]\r |
1017 | \r |
1018 | return package\r |
1019 | \r |
1020 | def GetPlatform(self, guid, version):\r |
1021 | pass\r |
1022 | \r |
1023 | def GetPlatformByPath(self, path):\r |
1024 | for platform in self.Platforms:\r |
1025 | platformFullPath = self.SubPath(platform.Path)\r |
1026 | if platformFullPath == path:\r |
1027 | return platform\r |
1028 | return ""\r |
1029 | \r |
1030 | def GetLibraryInterface(self, name):\r |
1031 | if name not in self.LibraryInterfaceXref["NAME"]:\r |
1032 | return ""\r |
1033 | return self.LibraryInterfaceXref["NAME"][name]\r |
1034 | \r |
1035 | def SubPath(self, *relativePathList):\r |
1036 | return os.path.normpath(os.path.join(self.Path, *relativePathList))\r |
1037 | \r |
1038 | def SetupCrossRef(self):\r |
1039 | ##\r |
1040 | ## setup platform cross reference as nest-dict\r |
1041 | ## guid -> {version -> platform}\r |
1042 | ##\r |
1043 | ## platformList = self.Platforms\r |
1044 | ## for p in platformList:\r |
1045 | ## guid = p.GuidValue\r |
1046 | ## version = p.Version\r |
1047 | ## if guid not in self.PlatformIndex:\r |
1048 | ## self.PlatformIndex[guid] = {}\r |
1049 | ## if version in self.PlatformIndex[guid]:\r |
1050 | ## raise Exception("Duplicate platform")\r |
1051 | ## self.PlatformIndex[guid][version] = p\r |
1052 | \r |
1053 | ##\r |
1054 | ## setup package cross reference as nest-dict\r |
1055 | ## guid -> {version -> package}\r |
1056 | ## name -> [package list]\r |
1057 | ## path -> package\r |
1058 | ##\r |
1059 | packageList = self.Packages\r |
1060 | for p in packageList:\r |
1061 | guid = p.GuidValue\r |
1062 | version = p.Version\r |
1063 | packageGuidIndex = self.PackageXref["GUID"]\r |
1064 | if guid not in packageGuidIndex:\r |
1065 | packageGuidIndex[guid] = {}\r |
1066 | if version in packageGuidIndex[guid]:\r |
1067 | raise Exception("Duplicate package: %s-%s [%s]" % p.Name, version, guid)\r |
1068 | packageGuidIndex[guid][version] = p\r |
1069 | \r |
1070 | packageNameIndex = self.PackageXref["NAME"]\r |
1071 | name = p.Name\r |
1072 | if name not in packageNameIndex:\r |
1073 | packageNameIndex[name] = []\r |
1074 | packageNameIndex[name].append(p)\r |
1075 | \r |
1076 | packagePathIndex = self.PackageXref["PATH"]\r |
1077 | path = p.Path\r |
1078 | if path in packagePathIndex:\r |
1079 | raise Exception("Duplicate package: %s %s" % p.Name, p.Path)\r |
1080 | packagePathIndex[path] = p.Path\r |
1081 | \r |
1082 | ##\r |
1083 | ## setup library class cross reference as\r |
1084 | ## library class name -> library class object\r |
1085 | ##\r |
1086 | for lcname in p.LibraryInterfaces:\r |
1087 | if lcname in self.LibraryInterfaceXref["NAME"]:\r |
1088 | raise Exception("Duplicate library class: %s in package %s" % (lcname, name))\r |
1089 | lcInterface = p.LibraryInterfaces[lcname]\r |
1090 | self.LibraryInterfaceXref["NAME"][lcname] = lcInterface\r |
1091 | \r |
1092 | if lcInterface not in self.LibraryInterfaceXref["PATH"]:\r |
1093 | self.LibraryInterfaceXref["PATH"][lcInterface] = []\r |
1094 | self.LibraryInterfaceXref["PATH"][lcInterface].append(lcname)\r |
1095 | \r |
1096 | ##\r |
1097 | ## setup package cross reference as nest-dict\r |
1098 | ## guid -> {version -> [module list]}\r |
1099 | ## name -> [module list]\r |
1100 | ## path -> module\r |
1101 | for p in packageList:\r |
1102 | p.ParseMsaFile()\r |
1103 | \r |
1104 | moduleList = p.Modules\r |
1105 | for m in moduleList:\r |
1106 | name = m.Name\r |
1107 | path = m.Path\r |
1108 | guid = m.GuidValue\r |
1109 | version = m.Version\r |
1110 | moduleGuidIndex = self.ModuleXref["GUID"]\r |
1111 | if guid not in moduleGuidIndex:\r |
1112 | moduleGuidIndex[guid] = {}\r |
1113 | else:\r |
1114 | print "! Duplicate module GUID found:", guid, path\r |
1115 | \r |
1116 | if version not in moduleGuidIndex[guid]:\r |
1117 | moduleGuidIndex[guid][version] = []\r |
1118 | if m in moduleGuidIndex[guid][version]:\r |
1119 | raise Exception("Duplicate modules in the same package: %s-%s [%s]" % (name, version, guid))\r |
1120 | moduleGuidIndex[guid][version].append(m)\r |
1121 | \r |
1122 | modulePathIndex = self.ModuleXref["PATH"]\r |
1123 | path = p.SubPath(m.Path)\r |
1124 | if path in modulePathIndex:\r |
1125 | raise Exception("Duplicate modules in the same package: %s %s" % (name, path))\r |
1126 | modulePathIndex[path] = m\r |
1127 | \r |
1128 | moduleNameIndex = self.ModuleXref["NAME"]\r |
1129 | if name not in moduleNameIndex:\r |
1130 | moduleNameIndex[name] = []\r |
1131 | moduleNameIndex[name].append(m)\r |
1132 | \r |
1133 | def GetToolDef(self, toolchain, target, arch, toolcode, attr):\r |
1134 | return self.ToolConfig[(toolchain, target, arch, toolcode, attr)]\r |
1135 | \r |
1136 | def Parse(self):\r |
1137 | self.ParseConfig()\r |
1138 | self.ParseWorkspaceDatabase()\r |
1139 | \r |
1140 | def SetupBuild(self):\r |
1141 | # active archs\r |
1142 | self.ActiveArchs = self.TargetConfig["TARGET_ARCH"].split()\r |
1143 | if self.ActiveArchs == []:\r |
1144 | self.ActiveArchs = self.ActivePlatform.Archs\r |
1145 | \r |
1146 | # active targets\r |
1147 | self.ActiveTargets = self.TargetConfig["TARGET"].split()\r |
1148 | if self.ActiveTargets == []:\r |
1149 | self.ActiveTargets = self.ActivePlatform.Targets\r |
1150 | \r |
1151 | \r |
1152 | # active modules\r |
1153 | for msa in self._Elements["ModuleList"]:\r |
1154 | module = self.GetModuleByPath(msa)\r |
1155 | if module == "":\r |
1156 | raise Exception(msa + " is not in any package!")\r |
1157 | self.ActiveModules.append(module)\r |
1158 | self.IndividualModuleBuild = True\r |
1159 | if self.TargetConfig["MULTIPLE_THREAD"].upper() == "ENABLE":\r |
1160 | self.MultiThreadBuild = True\r |
1161 | if "MAX_CONCURRENT_THREAD_NUMBER" in self.TargetConfig:\r |
1162 | self.ThreadCount = self.TargetConfig["MAX_CONCURRENT_THREAD_NUMBER"]\r |
1163 | else:\r |
1164 | self.ThreadCount = "1"\r |
1165 | \r |
1166 | def Postprocess(self):\r |
1167 | self.ParsePackage(self._Elements["PackageList"])\r |
1168 | self.SetupCrossRef()\r |
1169 | self.ParsePlatform(self._Elements["PlatformList"])\r |
1170 | self.SetupBuild()\r |
1171 | \r |
1172 | ## def SetupEnvironment(self):\r |
1173 | ## config = BuildConfig.Config(self.SubPath(self._PlatformBuildPath))\r |
1174 | ## for name in config:\r |
1175 | ## self.Environment[name] = config[name]\r |
1176 | ##\r |
1177 | ## config = BuildConfig.Config(self.SubPath(self._ModuleBuildPath))\r |
1178 | ## for name in config:\r |
1179 | ## self.Environment[name] = config[name]\r |
1180 | ##\r |
1181 | ## multiThread = self.TargetConfig["MULTIPLE_THREAD"].upper()\r |
1182 | ## threadNumber = self.TargetConfig["MAX_CONCURRENT_THREAD_NUMBER"]\r |
1183 | ## if multiThread == "" or multiThread == "FALSE":\r |
1184 | ## self.Environment["MULTIPLE_THREAD"] = False\r |
1185 | ## self.Environment["MAX_CONCURRENT_THREAD_NUMBER"] = 1\r |
1186 | ## else:\r |
1187 | ## self.Environment["MULTIPLE_THREAD"] = True\r |
1188 | ## if threadNumber != "":\r |
1189 | ## self.Environment["MAX_CONCURRENT_THREAD_NUMBER"] = threadNumber\r |
1190 | ## else:\r |
1191 | ## self.Environment["MAX_CONCURRENT_THREAD_NUMBER"] = 2\r |
1192 | \r |
1193 | class PackageSurfaceArea(FrameworkElement.Package, SurfaceAreaElement):\r |
1194 | def __init__(self, workspace, path):\r |
1195 | FrameworkElement.Package.__init__(self)\r |
1196 | \r |
1197 | self.Path = os.path.normpath(path)\r |
1198 | self.Dir = os.path.dirname(self.Path)\r |
1199 | SurfaceAreaElement.__init__(self, workspace, workspace, None, True, True)\r |
1200 | \r |
1201 | def _SpdHeader(self, xpath):\r |
1202 | dom = XmlElement(self._Root, xpath)\r |
1203 | self.Name = XmlElementData(XmlElement(dom, "/SpdHeader/PackageName"))\r |
1204 | self.GuidValue = XmlElementData(XmlElement(dom, "/SpdHeader/GuidValue")).upper()\r |
1205 | self.Version = XmlElementData(XmlElement(dom, "/SpdHeader/Version"))\r |
1206 | \r |
1207 | def _PackageDefinitions(self, xpath):\r |
1208 | dom = XmlElement(self._Root, xpath)\r |
1209 | self.ReadOnly = XmlElementData(XmlElement(dom, "/PackageDefinitions/ReadOnly"))\r |
1210 | self.Repackage = XmlElementData(XmlElement(dom, "/PackageDefinitions/RePackage"))\r |
1211 | \r |
1212 | def _LibraryClassDeclarations(self, xpath):\r |
1213 | dom = XmlElement(self._Root, xpath)\r |
1214 | lcdList = XmlList(dom, "/LibraryClassDeclarations/LibraryClass")\r |
1215 | lcds = []\r |
1216 | for lc in lcdList:\r |
1217 | lcds.append(LibraryDeclaration(self._Workspace, self, lc))\r |
1218 | self._Elements["LibraryClassDeclarations"] = lcds\r |
1219 | \r |
1220 | def _IndustryStdIncludes(self, xpath):\r |
1221 | dom = XmlElement(self._Root, xpath)\r |
1222 | headerList = XmlList(dom, "/IndustryStdIncludes/IndustryStdHeader")\r |
1223 | headers = []\r |
1224 | for h in headerList:\r |
1225 | headers.append(IndustryStdHeader(self._Workspace, self, h))\r |
1226 | self._Elements["IndustryStdIncludes"] = headers\r |
1227 | \r |
1228 | def _MsaFiles(self, xpath):\r |
1229 | dom = XmlElement(self._Root, xpath)\r |
1230 | msaFileList = XmlList(dom, "/MsaFiles/Filename")\r |
1231 | msaFiles = []\r |
1232 | for msa in msaFileList:\r |
1233 | filePath = os.path.normpath(XmlElementData(msa))\r |
1234 | msaFiles.append(filePath)\r |
1235 | self._Elements["MsaFiles"] = msaFiles\r |
1236 | \r |
1237 | def _PackageHeaders(self, xpath):\r |
1238 | dom = XmlElement(self._Root, xpath)\r |
1239 | headerList = XmlList(dom, "/PackageHeaders/IncludePkgHeader")\r |
1240 | headers = []\r |
1241 | for h in headerList:\r |
1242 | headers.append(PackageHeader(self._Workspace, self, h))\r |
1243 | self._Elements["PackageHeaders"] = headers\r |
1244 | \r |
1245 | def _GuidDeclarations(self, xpath):\r |
1246 | dom = XmlElement(self._Root, xpath)\r |
1247 | guidList = XmlList(dom, "/GuidDeclarations/Entry")\r |
1248 | guids = []\r |
1249 | for guid in guidList:\r |
1250 | guids.append(GuidDeclaration(self._Workspace, self, guid))\r |
1251 | self._Elements["GuidDeclarations"] = guids\r |
1252 | \r |
1253 | def _ProtocolDeclarations(self, xpath):\r |
1254 | dom = XmlElement(self._Root, xpath)\r |
1255 | protocolList = XmlList(dom, "/ProtocolDeclarations/Entry")\r |
1256 | protocols = []\r |
1257 | for p in protocolList:\r |
1258 | protocols.append(ProtocolDeclaration(self._Workspace, self, p))\r |
1259 | self._Elements["ProtocolDeclarations"] = protocols\r |
1260 | \r |
1261 | def _PpiDeclarations(self, xpath):\r |
1262 | dom = XmlElement(self._Root, xpath)\r |
1263 | ppiList = XmlList(dom, "/PpiDeclarations/Entry")\r |
1264 | ppis = []\r |
1265 | for p in ppiList:\r |
1266 | ppis.append(PpiDeclaration(self._Workspace, self, p))\r |
1267 | self._Elements["PpiDeclarations"] = ppis\r |
1268 | \r |
1269 | def _PcdDeclarations(self, xpath):\r |
1270 | dom = XmlElement(self._Root, xpath)\r |
1271 | pcdList = XmlList(dom, "/PcdDeclarations/PcdEntry")\r |
1272 | pcds = []\r |
1273 | for p in pcdList:\r |
1274 | pcds.append(PcdDeclaration(self._Workspace, self, p))\r |
1275 | self._Elements["PcdDeclarations"] = pcds\r |
1276 | \r |
1277 | def SubPath(self, *relativePathList):\r |
1278 | return os.path.normpath(os.path.join(self.Dir, *relativePathList))\r |
1279 | \r |
1280 | def Parse(self):\r |
1281 | self._Root = xml.dom.minidom.parse(self._Workspace.SubPath(self.Path))\r |
1282 | assert self._Root.documentElement.tagName == "PackageSurfaceArea"\r |
1283 | \r |
1284 | # print "Parsing...",self.Path\r |
1285 | self._SpdHeader("/PackageSurfaceArea/SpdHeader")\r |
1286 | self._PackageDefinitions("/PackageSurfaceArea/PackageDefinitions")\r |
1287 | self._LibraryClassDeclarations("/PackageSurfaceArea/LibraryClassDeclarations")\r |
1288 | self._IndustryStdIncludes("/PackageSurfaceArea/IndustryStdIncludes")\r |
1289 | self._MsaFiles("/PackageSurfaceArea/MsaFiles")\r |
1290 | self._PackageHeaders("/PackageSurfaceArea/PackageHeaders")\r |
1291 | self._GuidDeclarations("/PackageSurfaceArea/GuidDeclarations")\r |
1292 | self._ProtocolDeclarations("/PackageSurfaceArea/ProtocolDeclarations")\r |
1293 | self._PpiDeclarations("/PackageSurfaceArea/PpiDeclarations")\r |
1294 | self._PcdDeclarations("/PackageSurfaceArea/PcdDeclarations")\r |
1295 | \r |
1296 | def Postprocess(self):\r |
1297 | # setup guid, protocol, ppi\r |
1298 | for guid in self._Elements["GuidDeclarations"]:\r |
1299 | if guid.CName in self.Guids:\r |
1300 | print "! Duplicate GUID CName (%s) in package %s" % (guid.CName, self.Path)\r |
1301 | self.Guids[guid.CName] = guid\r |
1302 | \r |
1303 | for protocol in self._Elements["ProtocolDeclarations"]:\r |
1304 | if protocol.CName in self.Protocols:\r |
1305 | print "! Duplicate Protocol CName (%s) in package %s" % (protocol.CName, self.Path)\r |
1306 | self.Protocols[protocol.CName] = protocol\r |
1307 | \r |
1308 | for ppi in self._Elements["PpiDeclarations"]:\r |
1309 | if ppi.CName in self.Ppis:\r |
1310 | print "! Duplicate PPI CName (%s) in package (%s)" % (ppi.CName, self.Path)\r |
1311 | self.Ppis[ppi.CName] = ppi\r |
1312 | \r |
1313 | # package header\r |
1314 | for inc in self._Elements["PackageHeaders"]:\r |
1315 | if inc.ModuleType not in self.PackageIncludes:\r |
1316 | self.PackageIncludes[inc.ModuleType] = []\r |
1317 | self.PackageIncludes[inc.ModuleType].append(inc.Path)\r |
1318 | \r |
1319 | # library class\r |
1320 | for lcd in self._Elements["LibraryClassDeclarations"]:\r |
1321 | if lcd.Name in self.LibraryInterfaces:\r |
1322 | raise "Duplicate library class: " + lcd.Name\r |
1323 | self.LibraryInterfaces[lcd.Name] = lcd\r |
1324 | \r |
1325 | # parse mas files\r |
1326 | # self.ParseMsaFile()\r |
1327 | # resolve RecommendedInstance\r |
1328 | \r |
1329 | def ParseMsaFile(self):\r |
1330 | for msaFilePath in self._Elements["MsaFiles"]:\r |
1331 | self.Modules.append(ModuleSurfaceArea(self._Workspace, self, msaFilePath))\r |
1332 | \r |
1333 | class PlatformSurfaceArea(FrameworkElement.Platform, SurfaceAreaElement):\r |
1334 | def __init__(self, workspace, path):\r |
1335 | FrameworkElement.Platform.__init__(self)\r |
1336 | \r |
1337 | self.Path = os.path.normpath(path)\r |
1338 | self.Dir = os.path.dirname(self.Path)\r |
1339 | SurfaceAreaElement.__init__(self, workspace)\r |
1340 | \r |
1341 | def _PlatformHeader(self, xpath):\r |
1342 | dom = XmlElement(self._Root, xpath)\r |
1343 | if dom == '': return\r |
1344 | self.Name = XmlElementData(XmlElement(dom, "/PlatformHeader/PlatformName"))\r |
1345 | self.GuidValue = XmlElementData(XmlElement(dom, "/PlatformHeader/GuidValue")).upper()\r |
1346 | self.Version = XmlElementData(XmlElement(dom, "/PlatformHeader/Version"))\r |
1347 | \r |
1348 | def _PlatformDefinitions(self, xpath):\r |
1349 | dom = XmlElement(self._Root, xpath)\r |
1350 | if dom == '': return\r |
1351 | self.Archs = XmlElementData(XmlElement(dom, "/PlatformDefinitions/SupportedArchitectures")).split()\r |
1352 | if self.Archs == []:\r |
1353 | raise Exception("No ARCH specified in platform " + self.Path)\r |
1354 | self.Targets = XmlElementData(XmlElement(dom, "/PlatformDefinitions/BuildTargets")).split()\r |
1355 | self.OutputPath = os.path.normpath(XmlElementData(XmlElement(dom, "/PlatformDefinitions/OutputDirectory")))\r |
1356 | \r |
1357 | def _Flash(self, xpath):\r |
1358 | dom = XmlElement(self._Root, xpath)\r |
1359 | if dom == '': return\r |
1360 | \r |
1361 | def _FrameworkModules(self, xpath):\r |
1362 | dom = XmlElement(self._Root, xpath)\r |
1363 | if dom == '': return\r |
1364 | moduleList = XmlList(dom, "/FrameworkModules/ModuleSA")\r |
1365 | modules = []\r |
1366 | for m in moduleList:\r |
1367 | modules.append(PlatformModule(self._Workspace, self, m))\r |
1368 | self._Elements["FrameworkModules"] = modules\r |
1369 | \r |
1370 | def _DynamicPcdBuildDefinitions(self, xpath):\r |
1371 | dom = XmlElement(self._Root, xpath)\r |
1372 | if dom == '': return\r |
1373 | \r |
1374 | def _BuildOptions(self, xpath):\r |
1375 | dom = XmlElement(self._Root, xpath)\r |
1376 | if dom == '': return\r |
1377 | self.BuildOptions = self.GetBuildOptionList(XmlElement(dom, "/BuildOptions/Options"))\r |
1378 | # print self.BuildOptions\r |
1379 | \r |
1380 | def _UserExtensions(self, xpath):\r |
1381 | domList = XmlList(self._Root, xpath)\r |
1382 | if domList == []: return\r |
1383 | for extension in domList:\r |
1384 | userId = XmlAttribute(extension, "UserID")\r |
1385 | identifier = XmlAttribute(extension, "Identifier")\r |
1386 | \r |
1387 | if userId == '' or identifier == '':\r |
1388 | raise Exception("No UserId or Identifier specified")\r |
1389 | if userId != "TianoCore": continue\r |
1390 | if identifier not in self.UserExtensions:\r |
1391 | self.UserExtensions[identifier] = []\r |
1392 | \r |
1393 | contentList = self.UserExtensions[identifier]\r |
1394 | for node in extension.childNodes:\r |
1395 | # print node.nodeType\r |
1396 | contentList.append(node.cloneNode(True))\r |
1397 | \r |
1398 | def Parse(self):\r |
1399 | self._Root = xml.dom.minidom.parse(self._Workspace.SubPath(self.Path))\r |
1400 | assert self._Root.documentElement.tagName == "PlatformSurfaceArea"\r |
1401 | \r |
1402 | self._PlatformHeader("/PlatformSurfaceArea/PlatformHeader")\r |
1403 | self._PlatformDefinitions("/PlatformSurfaceArea/PlatformDefinitions")\r |
1404 | self._Flash("/PlatformSurfaceArea/Flash")\r |
1405 | self._FrameworkModules("/PlatformSurfaceArea/FrameworkModules")\r |
1406 | self._DynamicPcdBuildDefinitions("/PlatformSurfaceArea/DynamicPcdBuildDefinitions")\r |
1407 | self._BuildOptions("/PlatformSurfaceArea/BuildOptions")\r |
1408 | self._UserExtensions("/PlatformSurfaceArea/UserExtensions")\r |
1409 | \r |
1410 | def Postprocess(self):\r |
1411 | # summarize all library modules for build\r |
1412 | for module in self._Elements["FrameworkModules"]:\r |
1413 | for arch in module.Archs:\r |
1414 | if arch not in self.Modules:\r |
1415 | self.Modules[arch] = []\r |
1416 | self.Modules[arch].append(module)\r |
1417 | \r |
1418 | if arch not in self.Libraries:\r |
1419 | self.Libraries[arch] = []\r |
1420 | for li in module.Libraries:\r |
1421 | if li in self.Libraries[arch]: continue\r |
1422 | self.Libraries[arch].append(li)\r |
1423 | \r |
1424 | # FV\r |
1425 | for fvName in module.FvBindings:\r |
1426 | if fvName not in self.Fvs:\r |
1427 | self.Fvs[fvName] = []\r |
1428 | self.Fvs[fvName].append(module)\r |
1429 | # build options\r |
1430 | # user extension\r |
1431 | \r |
1432 | ## def SetupEnvironment(self):\r |
1433 | ## self.Environment["PLATFORM"] = self.Name\r |
1434 | ## self.Environment["PLATFORM_GUID"] = self.GuidValue\r |
1435 | ## self.Environment["PLATFORM_VERSION"] = self.Version\r |
1436 | ## self.Environment["PLATFORM_RELATIVE_DIR"] = self.Path\r |
1437 | ## self.Environment["PLATFORM_OUTPUT_DIR"] = self.OutputPath\r |
1438 | \r |
1439 | def PrintWorkspace(ws):\r |
1440 | print "\nPlatforms:\n"\r |
1441 | for guid in ws.PlatformXref["GUID"]:\r |
1442 | for ver in ws.PlatformXref["GUID"][guid]:\r |
1443 | platform = ws.PlatformXref["GUID"][guid][ver]\r |
1444 | print " %s %s-%s" % (guid, platform.Name, ver)\r |
1445 | for pm in platform.Modules:\r |
1446 | print " %-40s %-10s <%s-%s>" % (pm.Module.Name+"-"+pm.Module.Version,\r |
1447 | ListString(pm.Archs), pm.Module.Package.Name,\r |
1448 | pm.Module.Package.Version)\r |
1449 | for li in pm.Libraries:\r |
1450 | print " %-47s <%s-%s>" % (li.Module.Name+"-"+li.Module.Version,\r |
1451 | li.Module.Package.Name, li.Module.Package.Version)\r |
1452 | print ""\r |
1453 | \r |
1454 | print "\nPackages:\n"\r |
1455 | for guid in ws.PackageXref["GUID"]:\r |
1456 | for ver in ws.PackageXref["GUID"][guid]:\r |
1457 | print " %s %s-%s" % (guid, ws.PackageXref["GUID"][guid][ver].Name, ver)\r |
1458 | \r |
1459 | print "\nModules:\n"\r |
1460 | for guid in ws.ModuleXref["GUID"]:\r |
1461 | for ver in ws.ModuleXref["GUID"][guid]:\r |
1462 | for module in ws.ModuleXref["GUID"][guid][ver]:\r |
1463 | print " %s %-40s [%s-%s]" % (guid, module.Name+"-"+ver, module.Package.Name, module.Package.Version)\r |
1464 | print " Depending on packages:"\r |
1465 | for arch in module.IncludePaths:\r |
1466 | print " ", arch, ":"\r |
1467 | for path in module.IncludePaths[arch]:\r |
1468 | print " ", path\r |
1469 | print "\n"\r |
1470 | \r |
1471 | for arch in module.IncludeFiles:\r |
1472 | print " ", arch, ":"\r |
1473 | for path in module.IncludeFiles[arch]:\r |
1474 | print " ", path\r |
1475 | print "\n"\r |
1476 | \r |
1477 | print " Source files:"\r |
1478 | for arch in module.SourceFiles:\r |
1479 | print " ", arch, ":"\r |
1480 | for type in module.SourceFiles[arch]:\r |
1481 | for src in module.SourceFiles[arch][type]:\r |
1482 | print " %-40s (%s)" % (src.Path, src.Type)\r |
1483 | print "\n"\r |
1484 | print "\nLibrary Classes:"\r |
1485 | for name in ws.LibraryInterfaceXref["NAME"]:\r |
1486 | lc = ws.LibraryInterfaceXref["NAME"][name]\r |
1487 | pkgPath = os.path.dirname(lc.Package.Path)\r |
1488 | print "\n [%s] <%s>" % (lc.Name, pkgPath + os.path.sep + lc.Path)\r |
1489 | \r |
1490 | print " Produced By:"\r |
1491 | for li in lc.Instances:\r |
1492 | print " %-40s <%s>" % (li.Name+"-"+li.Version, li.Package.SubPath(li.Path))\r |
1493 | \r |
1494 | print " Consumed By:"\r |
1495 | for li in lc.Consumers:\r |
1496 | print " %-40s <%s>" % (li.Name+"-"+li.Version, li.Package.SubPath(li.Path))\r |
1497 | \r |
1498 | print "\nActive Platform:"\r |
1499 | for arch in ws.ActivePlatform.Libraries:\r |
1500 | print " Library Instances (%s) (%d libraries)" % (arch , len(ws.ActivePlatform.Libraries[arch]))\r |
1501 | for li in ws.ActivePlatform.Libraries[arch]:\r |
1502 | print " %s-%s (%s-%s)" % (li.Module.Name, li.Module.Version,\r |
1503 | li.Module.Package.Name, li.Module.Package.Version)\r |
1504 | \r |
1505 | for arch in ws.ActivePlatform.Modules:\r |
1506 | print " Driver Modules (%s) (%d modules)" % (arch, len(ws.ActivePlatform.Modules[arch]))\r |
1507 | for m in ws.ActivePlatform.Modules[arch]:\r |
1508 | print " %s-%s (%s-%s)" % (m.Module.Name, m.Module.Version,\r |
1509 | m.Module.Package.Name, m.Module.Package.Version)\r |
1510 | \r |
1511 | for fv in ws.ActivePlatform.Fvs:\r |
1512 | print\r |
1513 | print " Firmware Volume (%s) (%d modules)" % (fv, len(ws.ActivePlatform.Fvs[fv]))\r |
1514 | for m in ws.ActivePlatform.Fvs[fv]:\r |
1515 | print " %s-%s (%s-%s)" % (m.Module.Name, m.Module.Version,\r |
1516 | m.Module.Package.Name, m.Module.Package.Version)\r |
1517 | \r |
1518 | # for test\r |
1519 | if __name__ == "__main__":\r |
1520 | # os.environ["WORKSPACE"]\r |
1521 | workspacePath = os.getenv("WORKSPACE", os.getcwd())\r |
1522 | saFile = ""\r |
1523 | if len(sys.argv) <= 1:\r |
1524 | saFile = os.path.join(workspacePath, "Tools/Conf/FrameworkDatabase.db")\r |
1525 | else:\r |
1526 | saFile = sys.argv[1]\r |
1527 | \r |
1528 | print "Parsing ... %s\n" % saFile\r |
1529 | \r |
1530 | startTime = time.clock()\r |
1531 | sa = Workspace(workspacePath, [], [])\r |
1532 | ## dbak = None\r |
1533 | ## if os.path.exists("workspace.bak"):\r |
1534 | ## dbak = shelve.open("workspace.bak", protocol=2)\r |
1535 | ## sa = dbak.db\r |
1536 | ## dbak.close()\r |
1537 | ## else:\r |
1538 | ## sa = FrameworkDatabase(saFile)\r |
1539 | ## dbak = shelve.open("workspace.bak", protocol=2)\r |
1540 | ## dbak.db = sa\r |
1541 | ## dbak.close()\r |
1542 | # sa = PackageSurfaceArea(saFile)\r |
1543 | # sa = PlatformSurfaceArea(saFile)\r |
1544 | # sa = ModuleSurfaceArea(saFile)\r |
1545 | # print sa\r |
1546 | \r |
1547 | PrintWorkspace(sa)\r |
1548 | print "\n[Finished in %fs]" % (time.clock() - startTime)\r |
1549 | \r |