]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/UPT/Xml/ModuleSurfaceAreaXml.py
51ac48aca58e02a5e52c8e5643578be09de4b472
2 # This file is used to parse a Module file of .PKG file
4 # Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
6 # This program and the accompanying materials are licensed and made available
7 # under the terms and conditions of the BSD License which accompanies this
8 # distribution. The full text of the license may be found at
9 # http://opensource.org/licenses/bsd-license.php
11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 from xml
.dom
import minidom
20 from Library
.String
import ConvertNEToNOTEQ
21 from Library
.String
import ConvertNOTEQToNE
22 from Library
.String
import GetStringOfList
23 from Library
.String
import IsMatchArch
24 from Library
.Xml
.XmlRoutines
import XmlElement
25 from Library
.Xml
.XmlRoutines
import XmlAttribute
26 from Library
.Xml
.XmlRoutines
import XmlNode
27 from Library
.Xml
.XmlRoutines
import XmlList
28 from Library
.Xml
.XmlRoutines
import CreateXmlElement
29 from Object
.POM
.CommonObject
import GuidVersionObject
30 from Object
.POM
.ModuleObject
import BootModeObject
31 from Object
.POM
.ModuleObject
import DepexObject
32 from Object
.POM
.ModuleObject
import ModuleObject
33 from Object
.POM
.ModuleObject
import EventObject
34 from Object
.POM
.ModuleObject
import HobObject
35 from Object
.POM
.ModuleObject
import SourceFileObject
36 from Object
.POM
.ModuleObject
import PackageDependencyObject
37 from Object
.POM
.ModuleObject
import ExternObject
38 from Object
.POM
.ModuleObject
import BinaryFileObject
39 from Object
.POM
.ModuleObject
import AsBuiltObject
40 from Object
.POM
.ModuleObject
import BinaryBuildFlagObject
41 from Xml
.CommonXml
import ClonedFromXml
42 from Xml
.CommonXml
import HeaderXml
43 from Xml
.CommonXml
import HelpTextXml
44 from Xml
.CommonXml
import CommonDefinesXml
45 from Xml
.CommonXml
import LibraryClassXml
46 from Xml
.CommonXml
import UserExtensionsXml
47 from Xml
.CommonXml
import MiscellaneousFileXml
48 from Xml
.CommonXml
import FilenameXml
49 from Xml
.GuidProtocolPpiXml
import GuidXml
50 from Xml
.GuidProtocolPpiXml
import ProtocolXml
51 from Xml
.GuidProtocolPpiXml
import PpiXml
52 from Xml
.PcdXml
import PcdEntryXml
53 from Xml
.XmlParserMisc
import GetHelpTextList
54 from Library
import GlobalData
55 from Library
.Misc
import GetSplitValueList
59 # represent the following XML item
63 # FileType=" FileType " {1}
64 # SupArchList=" ArchListType " {0,1}
65 # FeatureFlag=" FeatureFlagExpression " {0,1} >
68 # <AsBuilt> ... </AsBuilt> {0,}
71 class BinaryFileXml(object):
75 self
.PatchPcdValues
= ''
77 self
.LibraryInstances
= ''
80 def FromXml(self
, Item
, Key
):
83 BinaryFile
= BinaryFileObject()
85 SupArchList
= ['COMMON']
86 for SubItem
in XmlList(Item
, '%s/Filename' % Key
):
88 Bxml
= Axml
.FromXml(SubItem
, 'Filename')
89 FilenameList
.append(Bxml
)
90 BinaryFile
.SetFileNameList(FilenameList
)
91 for FileName
in FilenameList
:
92 if FileName
.GetSupArchList():
93 SupArchList
= FileName
.GetSupArchList()
94 BinaryFile
.SetSupArchList(SupArchList
)
95 if GlobalData
.gIS_BINARY_INF
:
97 for AsBuiltItem
in XmlList(Item
, '%s/AsBuilt' % Key
):
98 AsBuilt
= AsBuiltObject()
100 PatchPcdValueList
= []
101 for SubItem
in XmlList(AsBuiltItem
, 'AsBuilt/PatchPcdValue'):
103 Bxml
= Axml
.FromXml(SubItem
, 'PatchPcdValue')
104 PatchPcdValueList
.append(Bxml
)
105 AsBuilt
.SetPatchPcdList(PatchPcdValueList
)
107 for SubItem
in XmlList(AsBuiltItem
, 'AsBuilt/PcdExValue'):
109 Bxml
= Axml
.FromXml(SubItem
, 'PcdExValue')
110 PcdExValueList
.append(Bxml
)
111 AsBuilt
.SetPcdExList(PcdExValueList
)
113 for SubItem
in XmlList(Item
, '%s/AsBuilt/LibraryInstances/GUID' % Key
):
114 GuidVerObj
= GuidVersionObject()
115 GUID
= XmlElement(SubItem
, 'GUID')
116 Version
= XmlAttribute(XmlNode(SubItem
, 'GUID'), 'Version')
117 GuidVerObj
.SetGuid(GUID
)
118 GuidVerObj
.SetVersion(Version
)
119 LibraryList
.append(GuidVerObj
)
120 if XmlList(Item
, '%s/AsBuilt/LibraryInstances' % Key
) and not LibraryList
:
122 AsBuilt
.SetLibraryInstancesList(LibraryList
)
124 for SubItem
in XmlList(Item
, '%s/AsBuilt/BuildFlags' % Key
):
125 BuildFlag
= BuildFlagXml()
126 BuildFlagList
.append(BuildFlag
.FromXml2(SubItem
, 'BuildFlags'))
127 AsBuilt
.SetBuildFlagsList(BuildFlagList
)
128 AsBuiltList
.append(AsBuilt
)
129 BinaryFile
.SetAsBuiltList(AsBuiltList
)
132 def ToXml(self
, BinaryFile
, Key
):
136 FilenameList
= BinaryFile
.GetFileNameList()
138 for Filename
in FilenameList
:
140 NodeList
.append(Tmp
.ToXml(Filename
, 'Filename'))
141 SupportArch
= Filename
.SupArchList
143 AsBuildList
= BinaryFile
.GetAsBuiltList()
144 PatchPcdValueList
= AsBuildList
.GetPatchPcdList()
145 PcdExList
= AsBuildList
.GetPcdExList()
146 LibGuidVerList
= AsBuildList
.GetLibraryInstancesList()
147 BuildFlagList
= AsBuildList
.GetBuildFlagsList()
151 for Pcd
in PatchPcdValueList
:
152 if IsMatchArch(Pcd
.SupArchList
, SupportArch
):
154 AsBuiltNodeList
.append(Tmp
.ToXml4(Pcd
, 'PatchPcdValue'))
156 for Pcd
in PcdExList
:
157 if IsMatchArch(Pcd
.SupArchList
, SupportArch
):
159 AsBuiltNodeList
.append(Tmp
.ToXml4(Pcd
, 'PcdExValue'))
162 for LibGuidVer
in LibGuidVerList
:
163 if LibGuidVer
.GetLibGuid() and IsMatchArch(LibGuidVer
.GetSupArchList(), SupportArch
):
165 CreateXmlElement('GUID', LibGuidVer
.GetLibGuid(), [], [['Version', LibGuidVer
.GetLibVersion()]])
166 GuiVerElemList
.append(GuiVerElem
)
167 if len(GuiVerElemList
) > 0:
168 LibGuidVerElem
= CreateXmlElement('LibraryInstances', '', GuiVerElemList
, [])
169 AsBuiltNodeList
.append(LibGuidVerElem
)
171 for BuildFlag
in BuildFlagList
:
172 if IsMatchArch(BuildFlag
.GetSupArchList(), SupportArch
):
173 for Item
in BuildFlag
.GetAsBuildList():
175 Elem
= CreateXmlElement('BuildFlags', ''.join(Item
), [], [])
176 AsBuiltNodeList
.append(Elem
)
178 if len(AsBuiltNodeList
) > 0:
179 Element
= CreateXmlElement('AsBuilt', '', AsBuiltNodeList
, [])
180 NodeList
.append(Element
)
182 Root
= CreateXmlElement('%s' % Key
, '', NodeList
, [])
188 for Item
in self
.FileNames
:
189 Str
= Str
+ '\n\t' + str(Item
)
190 for Item
in self
.PatchPcdValues
:
191 Str
= Str
+ '\n\t' + str(Item
)
192 for Item
in self
.PcdExValues
:
193 Str
= Str
+ '\n\t' + str(Item
)
194 for Item
in self
.LibraryInstances
:
195 Str
= Str
+ '\n\t' + str(Item
)
196 for Item
in self
.BuildFlags
:
197 Str
= Str
+ '\n\t' + str(Item
)
203 class PackageXml(object):
205 self
.Description
= ''
208 self
.CommonDefines
= CommonDefinesXml()
210 def FromXml(self
, Item
, Key
):
211 self
.Description
= XmlElement(Item
, '%s/Description' % Key
)
212 self
.Guid
= XmlElement(Item
, '%s/GUID' % Key
)
213 self
.Version
= XmlAttribute(XmlNode(Item
, '%s/GUID' % Key
), 'Version')
214 self
.CommonDefines
.FromXml(XmlNode(Item
, '%s' % Key
), Key
)
216 PackageDependency
= PackageDependencyObject()
217 PackageDependency
.SetPackage(self
.Description
)
218 PackageDependency
.SetGuid(self
.Guid
)
219 PackageDependency
.SetVersion(self
.Version
)
220 PackageDependency
.SetFeatureFlag(ConvertNOTEQToNE(self
.CommonDefines
.FeatureFlag
))
221 PackageDependency
.SetSupArchList(self
.CommonDefines
.SupArchList
)
223 return PackageDependency
225 def ToXml(self
, PackageDependency
, Key
):
228 AttributeList
= [['SupArchList', GetStringOfList(PackageDependency
.GetSupArchList())],
229 ['FeatureFlag', ConvertNEToNOTEQ(PackageDependency
.GetFeatureFlag())], ]
230 Element1
= CreateXmlElement('GUID', PackageDependency
.GetGuid(), [],
231 [['Version', PackageDependency
.GetVersion()]])
232 NodeList
= [['Description', PackageDependency
.GetPackage()], Element1
, ]
233 Root
= CreateXmlElement('%s' % Key
, '', NodeList
, AttributeList
)
238 Str
= "Description = %s Guid = %s Version = %s %s" \
239 % (self
.Description
, self
.Guid
, self
.Version
, self
.CommonDefines
)
244 class ExternXml(object):
246 self
.CommonDefines
= CommonDefinesXml()
248 self
.UnloadImage
= ''
249 self
.Constructor
= ''
252 self
.SupArchList
= ''
255 def FromXml(self
, Item
, Key
):
256 self
.CommonDefines
.FromXml(Item
, Key
)
257 self
.EntryPoint
= XmlElement(Item
, '%s/EntryPoint' % Key
)
258 self
.UnloadImage
= XmlElement(Item
, '%s/UnloadImage' % Key
)
259 self
.Constructor
= XmlElement(Item
, '%s/Constructor' % Key
)
260 self
.Destructor
= XmlElement(Item
, '%s/Destructor' % Key
)
262 Extern
= ExternObject()
263 Extern
.SetEntryPoint(self
.EntryPoint
)
264 Extern
.SetUnloadImage(self
.UnloadImage
)
265 Extern
.SetConstructor(self
.Constructor
)
266 Extern
.SetDestructor(self
.Destructor
)
267 if self
.CommonDefines
.SupModList
:
268 Extern
.SetSupModList(self
.CommonDefines
.SupModList
)
269 if self
.CommonDefines
.SupArchList
:
270 Extern
.SetSupArchList(self
.CommonDefines
.SupArchList
)
273 def ToXml(self
, Extern
, Key
):
278 if Extern
.GetEntryPoint():
279 NodeList
.append(['EntryPoint', Extern
.GetEntryPoint()])
280 if Extern
.GetUnloadImage():
281 NodeList
.append(['UnloadImage', Extern
.GetUnloadImage()])
282 if Extern
.GetConstructor():
283 NodeList
.append(['Constructor', Extern
.GetConstructor()])
284 if Extern
.GetDestructor():
285 NodeList
.append(['Destructor', Extern
.GetDestructor()])
286 Root
= CreateXmlElement('%s' % Key
, '', NodeList
, [])
291 Str
= "EntryPoint = %s UnloadImage = %s Constructor = %s Destructor = %s %s" \
292 % (self
.EntryPoint
, self
.UnloadImage
, self
.Constructor
, self
.Destructor
, self
.CommonDefines
)
293 for Item
in self
.HelpText
:
294 Str
= Str
+ '\n\t' + str(Item
)
299 class DepexXml(object):
301 self
.CommonDefines
= CommonDefinesXml()
302 self
.Expression
= None
305 def FromXml(self
, Item
, Key
):
308 self
.CommonDefines
.FromXml(Item
, Key
)
309 self
.Expression
= XmlElement(Item
, '%s/Expression' % Key
)
310 for HelpTextItem
in XmlList(Item
, '%s/HelpText' % Key
):
311 HelpTextObj
= HelpTextXml()
312 HelpTextObj
.FromXml(HelpTextItem
, '%s/HelpText' % Key
)
313 self
.HelpText
.append(HelpTextObj
)
315 Depex
= DepexObject()
316 Depex
.SetDepex(self
.Expression
)
317 Depex
.SetModuleType(self
.CommonDefines
.SupModList
)
318 Depex
.SetSupArchList(self
.CommonDefines
.SupArchList
)
319 Depex
.SetFeatureFlag(self
.CommonDefines
.FeatureFlag
)
320 Depex
.SetHelpTextList(GetHelpTextList(self
.HelpText
))
324 def ToXml(self
, Depex
, Key
):
327 AttributeList
= [['SupArchList', GetStringOfList(Depex
.GetSupArchList())],
328 ['SupModList', Depex
.GetModuleType()]]
329 NodeList
= [['Expression', Depex
.GetDepex()]]
330 if Depex
.GetHelpText():
332 NodeList
.append(Tmp
.ToXml(Depex
.GetHelpText(), 'HelpText'))
334 Root
= CreateXmlElement('%s' % Key
, '', NodeList
, AttributeList
)
338 Str
= "Expression = %s" % (self
.Expression
)
339 for Item
in self
.HelpText
:
340 Str
= Str
+ '\n\t' + str(Item
)
346 class BootModeXml(object):
348 self
.SupportedBootModes
= ''
349 self
.CommonDefines
= CommonDefinesXml()
352 def FromXml(self
, Item
, Key
):
353 self
.SupportedBootModes
= \
354 XmlElement(Item
, '%s/SupportedBootModes' % Key
)
355 self
.CommonDefines
.FromXml(Item
, Key
)
356 for HelpTextItem
in XmlList(Item
, '%s/HelpText' % Key
):
357 HelpTextObj
= HelpTextXml()
358 HelpTextObj
.FromXml(HelpTextItem
, '%s/HelpText' % Key
)
359 self
.HelpText
.append(HelpTextObj
)
361 BootMode
= BootModeObject()
362 BootMode
.SetSupportedBootModes(self
.SupportedBootModes
)
363 BootMode
.SetUsage(self
.CommonDefines
.Usage
)
364 BootMode
.SetHelpTextList(GetHelpTextList(self
.HelpText
))
368 def ToXml(self
, BootMode
, Key
):
371 AttributeList
= [['Usage', BootMode
.GetUsage()], ]
372 NodeList
= [['SupportedBootModes', BootMode
.GetSupportedBootModes()]]
373 for Item
in BootMode
.GetHelpTextList():
375 NodeList
.append(Tmp
.ToXml(Item
, 'HelpText'))
376 Root
= CreateXmlElement('%s' % Key
, '', NodeList
, AttributeList
)
381 Str
= "SupportedBootModes = %s %s" % (self
.SupportedBootModes
, self
.CommonDefines
)
382 for Item
in self
.HelpText
:
383 Str
= Str
+ '\n\t' + str(Item
)
388 class EventXml(object):
392 self
.CommonDefines
= CommonDefinesXml()
395 def FromXml(self
, Item
, Key
):
396 self
.EventType
= XmlAttribute(XmlNode(Item
, '%s' % Key
), 'EventType')
397 self
.Name
= XmlElement(Item
, '%s' % Key
)
398 self
.CommonDefines
.FromXml(Item
, Key
)
399 for HelpTextItem
in XmlList(Item
, '%s/HelpText' % Key
):
400 HelpTextObj
= HelpTextXml()
401 HelpTextObj
.FromXml(HelpTextItem
, '%s/HelpText' % Key
)
402 self
.HelpText
.append(HelpTextObj
)
404 Event
= EventObject()
405 Event
.SetEventType(self
.EventType
)
406 Event
.SetUsage(self
.CommonDefines
.Usage
)
407 Event
.SetHelpTextList(GetHelpTextList(self
.HelpText
))
411 def ToXml(self
, Event
, Key
):
414 AttributeList
= [['EventType', Event
.GetEventType()],
415 ['Usage', Event
.GetUsage()],
418 for Item
in Event
.GetHelpTextList():
420 NodeList
.append(Tmp
.ToXml(Item
, 'HelpText'))
421 Root
= CreateXmlElement('%s' % Key
, '', NodeList
, AttributeList
)
426 Str
= "EventType = %s %s" % (self
.EventType
, self
.CommonDefines
)
427 for Item
in self
.HelpText
:
428 Str
= Str
+ '\n\t' + str(Item
)
433 class HobXml(object):
437 self
.CommonDefines
= CommonDefinesXml()
440 def FromXml(self
, Item
, Key
):
441 self
.HobType
= XmlAttribute(XmlNode(Item
, '%s' % Key
), 'HobType')
442 self
.Name
= XmlElement(Item
, '%s' % Key
)
443 self
.CommonDefines
.FromXml(Item
, Key
)
444 for HelpTextItem
in XmlList(Item
, '%s/HelpText' % Key
):
445 HelpTextObj
= HelpTextXml()
446 HelpTextObj
.FromXml(HelpTextItem
, '%s/HelpText' % Key
)
447 self
.HelpText
.append(HelpTextObj
)
450 Hob
.SetHobType(self
.HobType
)
451 Hob
.SetSupArchList(self
.CommonDefines
.SupArchList
)
452 Hob
.SetUsage(self
.CommonDefines
.Usage
)
453 Hob
.SetHelpTextList(GetHelpTextList(self
.HelpText
))
457 def ToXml(self
, Hob
, Key
):
460 AttributeList
= [['HobType', Hob
.GetHobType()],
461 ['Usage', Hob
.GetUsage()],
462 ['SupArchList', GetStringOfList(Hob
.GetSupArchList())], ]
464 for Item
in Hob
.GetHelpTextList():
466 NodeList
.append(Tmp
.ToXml(Item
, 'HelpText'))
467 Root
= CreateXmlElement('%s' % Key
, '', NodeList
, AttributeList
)
472 Str
= "HobType = %s %s" % (self
.HobType
, self
.CommonDefines
)
473 for Item
in self
.HelpText
:
474 Str
= Str
+ '\n\t' + str(Item
)
480 class SourceFileXml(object):
483 self
.ToolChainFamily
= ''
485 self
.CommonDefines
= CommonDefinesXml()
487 def FromXml(self
, Item
, Key
):
488 self
.ToolChainFamily
= XmlAttribute(Item
, 'Family')
489 self
.SourceFile
= XmlElement(Item
, 'Filename')
490 self
.CommonDefines
.FromXml(Item
, Key
)
492 self
.CommonDefines
.FeatureFlag
= ConvertNOTEQToNE(self
.CommonDefines
.FeatureFlag
)
494 SourceFile
= SourceFileObject()
495 SourceFile
.SetSourceFile(self
.SourceFile
)
496 SourceFile
.SetFamily(self
.ToolChainFamily
)
497 SourceFile
.SetSupArchList(self
.CommonDefines
.SupArchList
)
498 SourceFile
.SetFeatureFlag(self
.CommonDefines
.FeatureFlag
)
502 def ToXml(self
, SourceFile
, Key
):
505 FeatureFlag
= ConvertNEToNOTEQ(SourceFile
.GetFeatureFlag())
506 AttributeList
= [['SupArchList', GetStringOfList(SourceFile
.GetSupArchList())],
507 ['Family', SourceFile
.GetFamily()],
508 ['FeatureFlag', FeatureFlag
], ]
509 Root
= CreateXmlElement('%s' % Key
, SourceFile
.GetSourceFile(), [], AttributeList
)
515 class ModulePropertyXml(object):
517 self
.CommonDefines
= CommonDefinesXml()
520 self
.PcdIsDriver
= ''
521 self
.UefiSpecificationVersion
= ''
522 self
.PiSpecificationVersion
= ''
523 self
.SpecificationList
= []
524 self
.SpecificationVersion
= ''
529 def FromXml(self
, Item
, Key
, Header
=None):
530 self
.CommonDefines
.FromXml(Item
, Key
)
531 self
.ModuleType
= XmlElement(Item
, '%s/ModuleType' % Key
)
532 self
.Path
= XmlElement(Item
, '%s/Path' % Key
)
533 self
.PcdIsDriver
= XmlElement(Item
, '%s/PcdIsDriver' % Key
)
534 self
.UefiSpecificationVersion
= XmlElement(Item
, '%s/UefiSpecificationVersion' % Key
)
535 self
.PiSpecificationVersion
= XmlElement(Item
, '%s/PiSpecificationVersion' % Key
)
536 for SubItem
in XmlList(Item
, '%s/Specification' % Key
):
537 Specification
= XmlElement(SubItem
, '/Specification')
538 Version
= XmlAttribute(XmlNode(SubItem
, '/Specification'), 'Version')
539 self
.SpecificationList
.append((Specification
, Version
))
540 for SubItem
in XmlList(Item
, '%s/BootMode' % Key
):
542 BootMode
= Axml
.FromXml(SubItem
, 'BootMode')
543 self
.BootModes
.append(BootMode
)
544 for SubItem
in XmlList(Item
, '%s/Event' % Key
):
546 Event
= Axml
.FromXml(SubItem
, 'Event')
547 self
.Events
.append(Event
)
548 for SubItem
in XmlList(Item
, '%s/HOB' % Key
):
550 Hob
= Axml
.FromXml(SubItem
, 'HOB')
551 self
.HOBs
.append(Hob
)
554 Header
= ModuleObject()
556 Header
.SetModuleType(self
.ModuleType
)
557 Header
.SetSupArchList(self
.CommonDefines
.SupArchList
)
558 Header
.SetModulePath(self
.Path
)
560 Header
.SetPcdIsDriver(self
.PcdIsDriver
)
561 Header
.SetUefiSpecificationVersion(self
.UefiSpecificationVersion
)
562 Header
.SetPiSpecificationVersion(self
.PiSpecificationVersion
)
563 Header
.SetSpecList(self
.SpecificationList
)
565 return Header
, self
.BootModes
, self
.Events
, self
.HOBs
568 def ToXml(self
, Header
, BootModes
, Events
, Hobs
, Key
):
571 AttributeList
= [['SupArchList', GetStringOfList(Header
.GetSupArchList())], ]
573 NodeList
= [['ModuleType', Header
.GetModuleType()],
574 ['Path', Header
.GetModulePath()],
575 ['PcdIsDriver', Header
.GetPcdIsDriver()],
576 ['UefiSpecificationVersion', Header
.GetUefiSpecificationVersion()],
577 ['PiSpecificationVersion', Header
.GetPiSpecificationVersion()],
579 for Item
in Header
.GetSpecList():
581 SpecElem
= CreateXmlElement('Specification', Spec
, [], [['Version', Version
]])
582 NodeList
.append(SpecElem
)
584 for Item
in BootModes
:
586 NodeList
.append(Tmp
.ToXml(Item
, 'BootMode'))
589 NodeList
.append(Tmp
.ToXml(Item
, 'Event'))
592 NodeList
.append(Tmp
.ToXml(Item
, 'HOB'))
593 Root
= CreateXmlElement('%s' % Key
, '', NodeList
, AttributeList
)
598 Str
= "ModuleType = %s Path = %s PcdIsDriver = %s UefiSpecificationVersion = %s PiSpecificationVersion = %s \
599 Specification = %s SpecificationVersion = %s %s" % \
600 (self
.ModuleType
, self
.Path
, self
.PcdIsDriver
, \
601 self
.UefiSpecificationVersion
, self
.PiSpecificationVersion
, \
602 self
.SpecificationList
, self
.SpecificationVersion
, self
.CommonDefines
)
603 for Item
in self
.BootModes
:
604 Str
= Str
+ '\n\t' + str(Item
)
605 for Item
in self
.Events
:
606 Str
= Str
+ '\n\t' + str(Item
)
607 for Item
in self
.HOBs
:
608 Str
= Str
+ '\n\t' + str(Item
)
614 class ModuleSurfaceAreaXml(object):
615 def __init__(self
, Package
=''):
618 # indicate the package that this module resides in
620 self
.Package
= Package
622 def FromXml2(self
, Item
, Module
):
629 for SubItem
in XmlList(Item
, '/ModuleSurfaceArea/PeiDepex'):
631 Depex
= Tmp
.FromXml(XmlNode(SubItem
, 'PeiDepex'), 'PeiDepex')
632 PeiDepexList
.append(Depex
)
633 Module
.SetPeiDepex(PeiDepexList
)
639 for SubItem
in XmlList(Item
, '/ModuleSurfaceArea/DxeDepex'):
641 Depex
= Tmp
.FromXml(XmlNode(SubItem
, 'DxeDepex'), 'DxeDepex')
642 DxeDepexList
.append(Depex
)
643 Module
.SetDxeDepex(DxeDepexList
)
649 for SubItem
in XmlList(Item
, '/ModuleSurfaceArea/SmmDepex'):
651 Depex
= Tmp
.FromXml(XmlNode(SubItem
, 'SmmDepex'), 'SmmDepex')
652 SmmDepexList
.append(Depex
)
653 Module
.SetSmmDepex(SmmDepexList
)
657 Tmp
= MiscellaneousFileXml()
658 MiscFileList
= Tmp
.FromXml(XmlNode(Item
, '/ModuleSurfaceArea/MiscellaneousFiles'), 'MiscellaneousFiles')
660 Module
.SetMiscFileList([MiscFileList
])
662 Module
.SetMiscFileList([])
667 for Item
in XmlList(Item
, '/ModuleSurfaceArea/UserExtensions'):
668 Tmp
= UserExtensionsXml()
669 UserExtension
= Tmp
.FromXml(Item
, 'UserExtensions')
670 Module
.SetUserExtensionList(Module
.GetUserExtensionList() + [UserExtension
])
674 def FromXml(self
, Item
, Key
, IsStandAlongModule
=False):
675 IsBinaryModule
= XmlAttribute(Item
, 'BinaryModule')
680 Module
= Tmp
.FromXml(XmlNode(Item
, '/%s/Header' % Key
), 'Header', True, IsStandAlongModule
)
681 Module
.SetBinaryModule(IsBinaryModule
)
684 GlobalData
.gIS_BINARY_INF
= True
689 Tmp
= ModulePropertyXml()
690 (Module
, BootModes
, Events
, HOBs
) = \
691 Tmp
.FromXml(XmlNode(Item
, '/ModuleSurfaceArea/ModuleProperties'), 'ModuleProperties', Module
)
692 Module
.SetBootModeList(BootModes
)
693 Module
.SetEventList(Events
)
694 Module
.SetHobList(HOBs
)
698 Tmp
= ClonedFromXml()
699 ClonedFrom
= Tmp
.FromXml(XmlNode(Item
, '/ModuleSurfaceArea/ClonedFrom'), 'ClonedFrom')
701 Module
.SetClonedFrom(ClonedFrom
)
706 for SubItem
in XmlList(Item
, '/ModuleSurfaceArea/LibraryClassDefinitions/LibraryClass'):
707 Tmp
= LibraryClassXml()
708 LibraryClass
= Tmp
.FromXml(SubItem
, 'LibraryClass')
709 Module
.SetLibraryClassList(Module
.GetLibraryClassList() + [LibraryClass
])
711 if XmlList(Item
, '/ModuleSurfaceArea/LibraryClassDefinitions') and \
712 not XmlList(Item
, '/ModuleSurfaceArea/LibraryClassDefinitions/LibraryClass'):
713 Module
.SetLibraryClassList([None])
718 for SubItem
in XmlList(Item
, '/ModuleSurfaceArea/SourceFiles/Filename'):
719 Tmp
= SourceFileXml()
720 SourceFile
= Tmp
.FromXml(SubItem
, 'Filename')
721 Module
.SetSourceFileList(Module
.GetSourceFileList() + [SourceFile
])
723 if XmlList(Item
, '/ModuleSurfaceArea/SourceFiles') and \
724 not XmlList(Item
, '/ModuleSurfaceArea/SourceFiles/Filename') :
725 Module
.SetSourceFileList([None])
730 for SubItem
in XmlList(Item
, '/ModuleSurfaceArea/BinaryFiles/BinaryFile'):
731 Tmp
= BinaryFileXml()
732 BinaryFile
= Tmp
.FromXml(SubItem
, 'BinaryFile')
733 Module
.SetBinaryFileList(Module
.GetBinaryFileList() + [BinaryFile
])
735 if XmlList(Item
, '/ModuleSurfaceArea/BinaryFiles') and \
736 not XmlList(Item
, '/ModuleSurfaceArea/BinaryFiles/BinaryFile') :
737 Module
.SetBinaryFileList([None])
739 # PackageDependencies
741 for SubItem
in XmlList(Item
, '/ModuleSurfaceArea/PackageDependencies/Package'):
743 PackageDependency
= Tmp
.FromXml(SubItem
, 'Package')
744 Module
.SetPackageDependencyList(Module
.GetPackageDependencyList() + [PackageDependency
])
746 if XmlList(Item
, '/ModuleSurfaceArea/PackageDependencies') and \
747 not XmlList(Item
, '/ModuleSurfaceArea/PackageDependencies/Package'):
748 Module
.SetPackageDependencyList([None])
753 for SubItem
in XmlList(Item
, '/ModuleSurfaceArea/Guids/GuidCName'):
754 Tmp
= GuidXml('Module')
755 GuidProtocolPpi
= Tmp
.FromXml(SubItem
, 'GuidCName')
756 Module
.SetGuidList(Module
.GetGuidList() + [GuidProtocolPpi
])
758 if XmlList(Item
, '/ModuleSurfaceArea/Guids') and not XmlList(Item
, '/ModuleSurfaceArea/Guids/GuidCName'):
759 Module
.SetGuidList([None])
764 for SubItem
in XmlList(Item
, '/ModuleSurfaceArea/Protocols/Protocol'):
765 Tmp
= ProtocolXml('Module')
766 GuidProtocolPpi
= Tmp
.FromXml(SubItem
, 'Protocol')
767 Module
.SetProtocolList(Module
.GetProtocolList() + [GuidProtocolPpi
])
769 if XmlList(Item
, '/ModuleSurfaceArea/Protocols') and not XmlList(Item
, '/ModuleSurfaceArea/Protocols/Protocol'):
770 Module
.SetProtocolList([None])
775 for SubItem
in XmlList(Item
, '/ModuleSurfaceArea/PPIs/Ppi'):
776 Tmp
= PpiXml('Module')
777 GuidProtocolPpi
= Tmp
.FromXml(SubItem
, 'Ppi')
778 Module
.SetPpiList(Module
.GetPpiList() + [GuidProtocolPpi
])
780 if XmlList(Item
, '/ModuleSurfaceArea/PPIs') and not XmlList(Item
, '/ModuleSurfaceArea/PPIs/Ppi'):
781 Module
.SetPpiList([None])
786 for SubItem
in XmlList(Item
, '/ModuleSurfaceArea/Externs/Extern'):
788 Extern
= Tmp
.FromXml(SubItem
, 'Extern')
789 Module
.SetExternList(Module
.GetExternList() + [Extern
])
791 if XmlList(Item
, '/ModuleSurfaceArea/Externs') and not XmlList(Item
, '/ModuleSurfaceArea/Externs/Extern'):
792 Module
.SetExternList([None])
794 if not Module
.GetBinaryModule():
798 for SubItem
in XmlList(Item
, '/ModuleSurfaceArea/PcdCoded/PcdEntry'):
800 PcdEntry
= Tmp
.FromXml3(SubItem
, 'PcdEntry')
801 Module
.SetPcdList(Module
.GetPcdList() + [PcdEntry
])
803 if XmlList(Item
, '/ModuleSurfaceArea/PcdCoded') and \
804 not XmlList(Item
, '/ModuleSurfaceArea/PcdCoded/PcdEntry'):
805 Module
.SetPcdList([None])
807 Module
= self
.FromXml2(Item
, Module
)
809 # return the module object
814 def ToXml(self
, Module
):
818 # Create root node of module surface area
820 DomModule
= minidom
.Document().createElement('ModuleSurfaceArea')
821 if Module
.GetBinaryModule():
822 DomModule
.setAttribute('BinaryModule', 'true')
828 DomModule
.appendChild(Tmp
.ToXml(Module
, 'Header'))
832 Tmp
= ModulePropertyXml()
833 DomModule
.appendChild(Tmp
.ToXml(Module
, Module
.GetBootModeList(), Module
.GetEventList(), Module
.GetHobList(), \
838 Tmp
= ClonedFromXml()
839 if Module
.GetClonedFrom():
840 DomModule
.appendChild(Tmp
.ToXml(Module
.GetClonedFrom(), 'ClonedFrom'))
844 LibraryClassNode
= CreateXmlElement('LibraryClassDefinitions', '', [], [])
845 for LibraryClass
in Module
.GetLibraryClassList():
846 Tmp
= LibraryClassXml()
847 LibraryClassNode
.appendChild(Tmp
.ToXml2(LibraryClass
, 'LibraryClass'))
848 DomModule
.appendChild(LibraryClassNode
)
852 SourceFileNode
= CreateXmlElement('SourceFiles', '', [], [])
853 for SourceFile
in Module
.GetSourceFileList():
854 Tmp
= SourceFileXml()
855 SourceFileNode
.appendChild(Tmp
.ToXml(SourceFile
, 'Filename'))
856 DomModule
.appendChild(SourceFileNode
)
860 BinaryFileNode
= CreateXmlElement('BinaryFiles', '', [], [])
861 for BinaryFile
in Module
.GetBinaryFileList():
862 Tmp
= BinaryFileXml()
863 BinaryFileNode
.appendChild(Tmp
.ToXml(BinaryFile
, 'BinaryFile'))
864 DomModule
.appendChild(BinaryFileNode
)
866 # PackageDependencies
868 PackageDependencyNode
= CreateXmlElement('PackageDependencies', '', [], [])
869 for PackageDependency
in Module
.GetPackageDependencyList():
871 PackageDependencyNode
.appendChild(Tmp
.ToXml(PackageDependency
, 'Package'))
872 DomModule
.appendChild(PackageDependencyNode
)
877 GuidProtocolPpiNode
= CreateXmlElement('Guids', '', [], [])
878 for GuidProtocolPpi
in Module
.GetGuidList():
879 Tmp
= GuidXml('Module')
880 GuidProtocolPpiNode
.appendChild(Tmp
.ToXml(GuidProtocolPpi
, 'GuidCName'))
881 DomModule
.appendChild(GuidProtocolPpiNode
)
886 GuidProtocolPpiNode
= CreateXmlElement('Protocols', '', [], [])
887 for GuidProtocolPpi
in Module
.GetProtocolList():
888 Tmp
= ProtocolXml('Module')
889 GuidProtocolPpiNode
.appendChild(Tmp
.ToXml(GuidProtocolPpi
, 'Protocol'))
890 DomModule
.appendChild(GuidProtocolPpiNode
)
895 GuidProtocolPpiNode
= CreateXmlElement('PPIs', '', [], [])
896 for GuidProtocolPpi
in Module
.GetPpiList():
897 Tmp
= PpiXml('Module')
898 GuidProtocolPpiNode
.appendChild(Tmp
.ToXml(GuidProtocolPpi
, 'Ppi'))
899 DomModule
.appendChild(GuidProtocolPpiNode
)
903 ExternNode
= CreateXmlElement('Externs', '', [], [])
904 for Extern
in Module
.GetExternList():
906 ExternNode
.appendChild(Tmp
.ToXml(Extern
, 'Extern'))
907 DomModule
.appendChild(ExternNode
)
911 PcdEntryNode
= CreateXmlElement('PcdCoded', '', [], [])
912 for PcdEntry
in Module
.GetPcdList():
914 PcdEntryNode
.appendChild(Tmp
.ToXml3(PcdEntry
, 'PcdEntry'))
915 DomModule
.appendChild(PcdEntryNode
)
920 if Module
.GetPeiDepex():
921 for Item
in Module
.GetPeiDepex():
923 DomModule
.appendChild(Tmp
.ToXml(Item
, 'PeiDepex'))
928 if Module
.GetDxeDepex():
929 for Item
in Module
.GetDxeDepex():
931 DomModule
.appendChild(Tmp
.ToXml(Item
, 'DxeDepex'))
936 if Module
.GetSmmDepex():
937 for Item
in Module
.GetSmmDepex():
939 DomModule
.appendChild(Tmp
.ToXml(Item
, 'SmmDepex'))
944 if Module
.GetMiscFileList():
945 Tmp
= MiscellaneousFileXml()
946 DomModule
.appendChild(Tmp
.ToXml(Module
.GetMiscFileList()[0], 'MiscellaneousFiles'))
950 if Module
.GetUserExtensionList():
951 for UserExtension
in Module
.GetUserExtensionList():
952 Tmp
= UserExtensionsXml()
953 DomModule
.appendChild(Tmp
.ToXml(UserExtension
, 'UserExtensions'))
958 # BuildFlagXml used to generate BuildFlag for <AsBuilt>
960 class BuildFlagXml(object):
965 self
.AsBuiltFlags
= ''
967 def FromXml(self
, Item
, Key
):
968 self
.Target
= XmlElement(Item
, '%s/Target' % Key
)
969 self
.TagName
= XmlElement(Item
, '%s/TagName' % Key
)
970 self
.Family
= XmlElement(Item
, '%s/Family' % Key
)
972 BuildFlag
= BinaryBuildFlagObject()
974 BuildFlag
.SetTarget(self
.Target
)
975 BuildFlag
.SetTagName(self
.TagName
)
976 BuildFlag
.SetFamily(self
.Family
)
981 # For AsBuild INF usage
983 def FromXml2(self
, Item
, Key
):
984 self
.AsBuiltFlags
= XmlElement(Item
, '%s' % Key
)
986 LineList
= GetSplitValueList(self
.AsBuiltFlags
, '\n')
989 for Line
in LineList
:
991 ReturnLine
= "# " + Line
993 ReturnLine
= ReturnLine
+ '\n' + '# ' + Line
996 BuildFlag
= BinaryBuildFlagObject()
997 BuildFlag
.SetAsBuiltOptionFlags(ReturnLine
)
1001 def ToXml(self
, BuildFlag
, Key
):
1006 NodeList
.append(['BuildFlags', BuildFlag
])
1008 Root
= CreateXmlElement('%s' % Key
, '', NodeList
, AttributeList
)